Browse Source

pretending cmd does not exist when not permitted

stefan 1 year ago
parent
commit
337c9f01df
3 changed files with 41 additions and 0 deletions
  1. 11 0
      src/shellmatta.c
  2. 27 0
      src/shellmatta_auth.c
  3. 3 0
      src/shellmatta_auth.h

+ 11 - 0
src/shellmatta.c

@@ -622,8 +622,19 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t     handle,
                         {
                             utils_writeEcho(inst, "\r\n", 2u);
                             shellmatta_opt_init(inst, cmdLen + 1u);
+
+#ifdef SHELLMATTA_AUTHENTICATION
+                            cmdRet = SHELLMATTA_OK;
+                            if (SHELLMATTA_OK == shellmatta_auth_is_cmd_permitted(handle, cmd))
+                            {
+                                cmdExecuted = 1u;
+                                cmdRet = cmd->cmdFct(handle, inst->buffer, inst->inputCount);
+                            }
+
+#else
                             cmdExecuted = 1u;
                             cmdRet = cmd->cmdFct(handle, inst->buffer, inst->inputCount);
+#endif
 
                             switch(cmdRet)
                             {

+ 27 - 0
src/shellmatta_auth.c

@@ -348,6 +348,33 @@ shellmatta_retCode_t shellmatta_auth_init(shellmatta_handle_t   handle,
     return ret;
 }
 
+shellmatta_retCode_t shellmatta_auth_is_cmd_permitted(shellmatta_handle_t handle, shellmatta_cmd_t *cmd)
+{
+    shellmatta_retCode_t    ret     = SHELLMATTA_ERROR;
+    shellmatta_instance_t   *inst   = (shellmatta_instance_t*)handle;
+    shellmatta_auth_perm_t  *permList;
+    uint32_t                i;
+
+    if (NULL == cmd->authLink)
+    {
+        ret = SHELLMATTA_OK;
+    }
+    else
+    {
+        permList = cmd->authLink;
+        for (i = 0u; i < permList->userIdslength; i++)
+        {
+            if (inst->userId == permList->userIds[i])
+            {
+                ret = SHELLMATTA_OK;
+                break;
+            }
+        }
+    }
+
+    return ret;
+}
+
 /**
  * @}
  */

+ 3 - 0
src/shellmatta_auth.h

@@ -29,6 +29,9 @@ extern const shellmatta_cmd_t shellmatta_auth_loginCmd;
 extern const shellmatta_cmd_t shellmatta_auth_logoutCmd;
 
 
+extern shellmatta_retCode_t shellmatta_auth_is_cmd_permitted(shellmatta_handle_t    handle,
+                                                             shellmatta_cmd_t       *cmd);
+
 #endif
 
 /** @} */