소스 검색

added function to change passwords during runtime

Strobel, Stefan | Friedrich Lütze GmbH 9 달 전
부모
커밋
c69a7d2b8f
2개의 변경된 파일41개의 추가작업 그리고 0개의 파일을 삭제
  1. 3 0
      api/shellmatta.h
  2. 38 0
      src/shellmatta_auth.c

+ 3 - 0
api/shellmatta.h

@@ -294,6 +294,9 @@ uint32_t             shellmatta_auth_getLoggedInUserId(     shellmatta_handle_t
 shellmatta_retCode_t shellmatta_auth_getLoggedInUserName(   shellmatta_handle_t     handle,
                                                             char                    *data,
                                                             uint32_t                *length);
+shellmatta_retCode_t shellmatta_auth_chpasswd(              shellmatta_handle_t     handle,
+                                                            const char              *username,
+                                                            const char              *password);
 
 #endif
 

+ 38 - 0
src/shellmatta_auth.c

@@ -541,6 +541,44 @@ shellmatta_retCode_t shellmatta_auth_getLoggedInUserName(shellmatta_handle_t han
     return ret;
 }
 
+/**
+ * @brief           changes the password of the passed username
+ * @param[in]       handle      shellmatta instance handle
+ * @param[in]       username    username to change the password of
+ * @param[in]       password    password to be set for the user
+ * @return          errorcode   #SHELLMATTA_OK
+ *                              #SHELLMATTA_ERROR (user not found)
+ *                              #SHELLMATTA_USE_FAULT (param err)
+ */
+shellmatta_retCode_t shellmatta_auth_chpasswd(shellmatta_handle_t handle, const char *username, const char *password)
+{
+    shellmatta_retCode_t    ret     = SHELLMATTA_ERROR;
+    shellmatta_instance_t   *inst   = (shellmatta_instance_t*)handle;
+    uint32_t                i;
+
+    /** -# check parameters for plausibility  */
+    if(     (NULL               != inst)
+        &&  (SHELLMATTA_MAGIC   == inst->magic)
+        &&  (username           != NULL)
+        &&  (password           != NULL))
+    {
+        for (i = 0u; i < inst->userListLength; i++)
+        {
+            /** -# search for user */
+            if (0 == strcmp(inst->userList[i].username, username))
+            {
+                inst->userList[i].password = password;
+                return SHELLMATTA_OK;
+            }
+        }
+    }
+    else
+    {
+        ret = SHELLMATTA_USE_FAULT;
+    }
+    return ret;
+}
+
 /**
  * @brief       checks if a command is accessible by the logged in user
  * @param[in]   inst    shellmatta instance to work with