Просмотр исходного кода

removed shellmatta_printf from intrinsic functions, added option to only set username via options in login command

stefan 9 месяцев назад
Родитель
Сommit
c942d184dd
2 измененных файлов с 23 добавлено и 2 удалено
  1. 4 0
      doc/shellmatta_auth.dox
  2. 19 2
      src/shellmatta_auth.c

+ 4 - 0
doc/shellmatta_auth.dox

@@ -37,6 +37,10 @@
 
     Every command can get a permission matrix - the perm lists can be reused for
     multiple users with the same permissions.
+    When no entry is found for a command in the permission list the command
+    default to be public.
+
+    It is also possible to use the userID 0 to hide a command when logged in.
 
         uint32_t exampleCmdPerms[] = {1};
         shellmatta_auth_perm_t permList[] = {

+ 19 - 2
src/shellmatta_auth.c

@@ -202,7 +202,8 @@ static shellmatta_retCode_t loginCmdFct(const shellmatta_handle_t handle, const
                         }
                         break;
                     default:
-                        shellmatta_printf(handle, "Unknown option: %c\r\n", option);
+                        shellmatta_write(handle, "Unknown option\r\n", 16);
+                        return SHELLMATTA_USE_FAULT;
                         break;
                 }
                 ret = shellmatta_opt_long(handle, options, &option, &argument, &argLen);
@@ -213,6 +214,22 @@ static shellmatta_retCode_t loginCmdFct(const shellmatta_handle_t handle, const
                 inst->tmpUserId = getUserIdFromName(inst, username);
                 checkPassword(handle, inst->tmpUserId, password);
             }
+            else if(NULL != username)
+            {
+                /** -# reinitialize input */
+                inst->inputCount = 0u;
+                inst->cursor = 0u;
+
+                inst->tmpUserId = getUserIdFromName(handle, username);
+                shellmatta_write(handle, "\r\nenter password:\r\n", 19);
+                inst->loginState = SHELLMATTA_AUTH_PASSWORD;
+                ret = SHELLMATTA_CONTINUE;
+            }
+            else if (NULL != password)
+            {
+                shellmatta_write(handle, "Missing username\r\n", 18);
+                ret = SHELLMATTA_USE_FAULT;
+            }
             else
             {
                 /** -# no credentials are passed with the command - start the input */
@@ -221,7 +238,7 @@ static shellmatta_retCode_t loginCmdFct(const shellmatta_handle_t handle, const
                 /** -# store pointer to username in buffer */
                 shellmatta_write(handle, "enter username:\r\n", 17);
                 inst->loginState = SHELLMATTA_AUTH_USERNAME;
-                return SHELLMATTA_CONTINUE;
+                ret = SHELLMATTA_CONTINUE;
             }
             break;