Sfoglia il codice sorgente

Added superuser flag to auth user.
When setting the superuser flag to true you allow this user to acces all commands without further permission lists.

Strobel, Stefan | Friedrich Lütze GmbH 9 mesi fa
parent
commit
fdb07f12c7

+ 1 - 0
api/shellmatta.h

@@ -108,6 +108,7 @@ typedef shellmatta_retCode_t (*shellmatta_write_t)(const char* data, uint32_t le
 typedef struct
 {
     uint32_t    userId;     /**< id of the user (!= 0)                              */
+    bool        superuser;  /**< allow the user to access all commands              */
     const char  *username;  /**< name of the user role                              */
     const char  *password;  /**< password of the user role or NULL (custom auth)    */
 } shellmatta_auth_user_t;

+ 8 - 5
doc/shellmatta_auth.dox

@@ -28,11 +28,14 @@
                                         NULL};
 
     After initializing the shellmatta instance you have to setup users with
-    username and password:
+    username and password.
+    By enabling the user to be superuser you grant this user access to all
+    commands without the need of setting a permission list.
 
         shellmatta_auth_user_t userList[] = {
-            {1, "shimatta", "12345678"},
-            {2, "not_shimatta", "87654321"}
+            {1, true, "root", "rootpw"},
+            {2, false, "shimatta", "12345678"},
+            {3, false, "not_shimatta", "87654321"}
         };
 
     Every command can get a permission matrix - the perm lists can be reused for
@@ -42,7 +45,7 @@
 
     It is also possible to use the userID 0 to hide a command when logged in.
 
-        uint32_t exampleCmdPerms[] = {1};
+        uint32_t exampleCmdPerms[] = {2};
         shellmatta_auth_perm_t permList[] = {
             {"adoSome2", exampleCmdPerms, sizeof(exampleCmdPerms)/sizeof(exampleCmdPerms[0])}
         };
@@ -52,7 +55,7 @@
     It is possible to register optional callbacks for a custom password check
     and a log function which is called on every authentication event.
 
-        shellmatta_auth_init(handle, userList, 2, permList, 2, false, NULL, NULL);
+        shellmatta_auth_init(handle, userList, 3, permList, 2, false, NULL, NULL);
 
 
     @section shellmatta_auth_custom_login Custom login

+ 2 - 2
example/main.c

@@ -223,8 +223,8 @@ int main(int argc, char **argv)
 
 
     shellmatta_auth_user_t userList[] = {
-        {1, "shimatta", "12345678"},
-        {2, "not_shimatta", "87654321"}
+        {1, false, "shimatta", "12345678"},
+        {2, false, "not_shimatta", "87654321"}
     };
 
     uint32_t doSomeCmdPerms[] = {1, 2};

+ 6 - 0
src/shellmatta_auth.c

@@ -550,10 +550,16 @@ shellmatta_retCode_t shellmatta_auth_is_cmd_permitted(const shellmatta_instance_
     shellmatta_auth_perm_t  *permList;
     uint32_t                i;
 
+    /**! -# commands without an authentication set are public */
     if (NULL == cmd->authLink)
     {
         ret = SHELLMATTA_OK;
     }
+    /**! -# allow superuser to access all commands */
+    else if ((NULL != inst->userPointer) && (true == inst->userPointer->superuser))
+    {
+        ret = SHELLMATTA_OK;
+    }
     else
     {
         permList = cmd->authLink;

+ 6 - 6
test/integrationtest_auth/test_integration_auth.cpp

@@ -50,8 +50,8 @@ static bool successTemp;
                                 shellmatta_addCmd(handle, &privateCmd);
 
 #define TEST_SHELLMATTA_AUTH_SETUP  shellmatta_auth_user_t userList[] = {                                                   \
-                                        {1, "shimatta", "12345678"},                                                        \
-                                        {2, "not_shimatta", "87654321"}                                                     \
+                                        {1, false, "shimatta", "12345678"},                                                 \
+                                        {2, false, "not_shimatta", "87654321"}                                              \
                                     };                                                                                      \
                                                                                                                             \
                                     uint32_t privateCmdPerms[] = {1};                                                       \
@@ -501,8 +501,8 @@ SCENARIO("Check custom login") {
         TEST_SHELLMATTA_SETUP;
 
         shellmatta_auth_user_t userList[] = {
-            {1, "shimatta", "12345678"},
-            {2, "not_shimatta", "87654321"}
+            {1, false, "shimatta", "12345678"},
+            {2, false, "not_shimatta", "87654321"}
         };
 
         uint32_t privateCmdPerms[] = {1};
@@ -551,8 +551,8 @@ SCENARIO("Check custom login with custom login function") {
         TEST_SHELLMATTA_SETUP;
 
         shellmatta_auth_user_t userList[] = {
-            {1, "shimatta", "12345678"},
-            {2, "not_shimatta", "87654321"}
+            {1, false, "shimatta", "12345678"},
+            {2, false, "not_shimatta", "87654321"}
         };
 
         uint32_t privateCmdPerms[] = {1};