Ver Fonte

adding login/logout command dynamically on auth init - the former approach failed when the command list was reordered - might have deleted a command when auth init was called with commands already added

stefan há 9 meses atrás
pai
commit
f40aca95f6

+ 0 - 2
src/shellmatta.c

@@ -97,9 +97,7 @@ shellmatta_retCode_t shellmatta_doInit(
 #ifdef SHELLMATTA_AUTHENTICATION
         /** -# copy the auth commands to the instance */
         memcpy(&(inst->loginCmd), &shellmatta_auth_loginCmd, sizeof(shellmatta_cmd_t));
-        inst->helpCmd.next = &(inst->loginCmd);
         memcpy(&(inst->logoutCmd), &shellmatta_auth_logoutCmd, sizeof(shellmatta_cmd_t));
-        inst->loginCmd.next = &(inst->logoutCmd);
 #endif
 
         if(NULL != cmdList)

+ 7 - 6
src/shellmatta_auth.c

@@ -213,9 +213,9 @@ static shellmatta_retCode_t loginCmdFct(const shellmatta_handle_t handle, const
                 inst->tmpUserId = getUserIdFromName(inst, username);
                 checkPassword(handle, inst->tmpUserId, password);
             }
+            /** -# user passed username and start interactive password input */
             else if(NULL != username)
             {
-                /** -# reinitialize input */
                 inst->inputCount = 0u;
                 inst->cursor = 0u;
 
@@ -231,10 +231,9 @@ static shellmatta_retCode_t loginCmdFct(const shellmatta_handle_t handle, const
             }
             else
             {
-                /** -# no credentials are passed with the command - start the input */
+                /** -# no credentials are passed with the command - start the interactive input */
                 inst->inputCount = 0u;
                 inst->cursor = 0u;
-                /** -# store pointer to username in buffer */
                 shellmatta_write(handle, "enter username:\r\n", 17);
                 inst->loginState = SHELLMATTA_AUTH_USERNAME;
                 ret = SHELLMATTA_CONTINUE;
@@ -288,7 +287,7 @@ static shellmatta_retCode_t loginCmdFct(const shellmatta_handle_t handle, const
 const shellmatta_cmd_t shellmatta_auth_loginCmd = {"login"
                                                  , "li"
                                                  , "Login command"
-                                                 , "interactive or use -u <username> -p <password>"
+                                                 , "login interactively or use -u <username> -p <password>"
                                                  , loginCmdFct
                                                  , NULL
                                                  , NULL};
@@ -330,6 +329,7 @@ const shellmatta_cmd_t shellmatta_auth_logoutCmd = {"logout"
  * @param[in]   checkFct        pointer to custom credential check function of type shellmatta_check_t
  * @param[in]   logFct          pointer to login log function of type shellmatta_auth_log_t
  * @return      errorcode   #SHELLMATTA_OK
+ *                          #SHELLMATTA_DUPLICATE (login/logout commands already existed)
  *                          #SHELLMATTA_USE_FAULT (param err)
  */
 shellmatta_retCode_t shellmatta_auth_init(shellmatta_handle_t       handle,
@@ -362,9 +362,10 @@ shellmatta_retCode_t shellmatta_auth_init(shellmatta_handle_t       handle,
         inst->userListLength = userListLength;
         inst->permList = permList;
         inst->permListLength = permListLength;
-        if(customLogin)
+        SHELLMATTA_RET(ret, shellmatta_addCmd(handle, &inst->logoutCmd));
+        if(!customLogin)
         {
-            inst->helpCmd.next = &inst->logoutCmd;
+            SHELLMATTA_RET(ret, shellmatta_addCmd(handle, &inst->loginCmd));
         }
         inst->checkFct  = checkFct;
         inst->logFct    = logFct;

+ 1 - 3
test/integrationtest_auth/test_integration_auth.cpp

@@ -128,9 +128,7 @@ SCENARIO("Check help auth uninitialized") {
             THEN("The help command prints all commands.") {
 
                 char *dummyData =   (char*) "help\r\n"
-                                            "help     ?   help [command] - print help or usage information\r\n"
-                                            "login    li  Login command\r\n"
-                                            "logout   lo  Logout command\r\n"
+                                            "help     ?  help [command] - print help or usage information\r\n"
                                             "private  r\r\n"
                                             "public   p\r\n"
                                             "\r\n"