Przeglądaj źródła

added function to change passwords during runtime

Strobel, Stefan | Friedrich Lütze GmbH 9 miesięcy temu
rodzic
commit
c69a7d2b8f
2 zmienionych plików z 41 dodań i 0 usunięć
  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