]> granicus.if.org Git - sudo/commitdiff
added code to support command listings
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 20 Sep 1994 21:52:47 +0000 (21:52 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 20 Sep 1994 21:52:47 +0000 (21:52 +0000)
parse.c

diff --git a/parse.c b/parse.c
index 58c80b24380531fbb9a9b330e60317e6db818c5f..8db050768d0ba929985f35450e0e6b2d417ee403 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -82,6 +82,7 @@ LINK tmp_ptr, reset_ptr, save_ptr, list_ptr[NUM_LISTS];
  */
 static int hostcmp     __P((char *));
 static int cmndcmp     __P((char *, char *));
+static void print_cmnds        __P((void));
 
 
 /*
@@ -383,6 +384,69 @@ int cmnd_type_ok()
 
 
 
+/*
+ * this routine is called from cmnd_list() to print the actual commands
+ * that a user is allowed or forbidden to run on the already.
+ * established host.
+ */
+
+static void print_cmnds()
+{
+    /*
+     * If we have a command or special keyword "ALL", print it out
+     */
+    if (list_ptr[USER_LIST] -> data[0] == '/' ||
+       !strcmp(list_ptr[USER_LIST]->data, "ALL")) {
+       /*
+        * print the allowed/forbidden command
+        */
+       if (list_ptr[USER_LIST] -> op == '!')
+           (void) printf("forbidden: ");
+       else
+           (void) printf("  allowed: ");
+       (void) printf("%s\n", list_ptr[USER_LIST] -> data);
+    }
+    /*
+     * by now we have a Cmnd_Alias that will have to be expanded
+     */
+    else {
+       save_ptr = list_ptr[CMND_LIST];
+       while (list_ptr[CMND_LIST] != NULL) {
+           if ((list_ptr[CMND_LIST] -> type == TYPE2) &&
+               (strcmp(list_ptr[CMND_LIST] -> data,
+                       list_ptr[USER_LIST] -> data) == 0)) {
+               next_type = list_ptr[CMND_LIST] -> next -> type;
+               tmp_ptr = list_ptr[CMND_LIST];
+               list_ptr[CMND_LIST] = tmp_ptr -> next;
+               while (next_type == TYPE3) {
+                   /*
+                    * print the allowed/forbidden command
+                    */
+                   if (list_ptr[USER_LIST] -> op == '!')
+                       (void) printf("forbidden: ");
+                   else
+                       (void) printf("  allowed: ");
+                   (void) printf("%s\n", list_ptr[CMND_LIST] -> data);
+
+                   if (list_ptr[CMND_LIST] -> next != NULL) {
+                       next_type = list_ptr[CMND_LIST] -> next -> type;
+                       tmp_ptr = list_ptr[CMND_LIST];
+                       list_ptr[CMND_LIST] = tmp_ptr -> next;
+                   } else {
+                       next_type = ~TYPE3;
+                   }
+               }
+           } else {
+               tmp_ptr = list_ptr[CMND_LIST];
+               list_ptr[CMND_LIST] = tmp_ptr -> next;
+           }
+       }
+       list_ptr[CMND_LIST] = save_ptr;
+    }
+}
+
+
+
 /*
  * this routine is called from validate() after the call_back() routine
  * has built all the possible lists. this routine steps thru the user list
@@ -424,6 +488,39 @@ int cmnd_check()
 
 
 
+/*
+ * list commands for a user if got -l
+ */
+
+int cmnd_list()
+{
+
+    while (list_ptr[USER_LIST] != NULL) {
+       if ((list_ptr[USER_LIST] -> type == TYPE2) && host_type_ok()) {
+           next_type = list_ptr[USER_LIST] -> next -> type;
+           tmp_ptr = list_ptr[USER_LIST];
+           list_ptr[USER_LIST] = tmp_ptr -> next;
+           while (next_type == TYPE3) {
+               /* print out the available commands */
+               print_cmnds();
+               if (list_ptr[USER_LIST] -> next != NULL) {
+                   next_type = list_ptr[USER_LIST] -> next -> type;
+                   tmp_ptr = list_ptr[USER_LIST];
+                   list_ptr[USER_LIST] = tmp_ptr -> next;
+               } else {
+                   next_type = ~TYPE3;
+               }
+           }
+       } else {
+           tmp_ptr = list_ptr[USER_LIST];
+           list_ptr[USER_LIST] = tmp_ptr -> next;
+       }
+    }
+    return (VALIDATE_NOT_OK);
+}
+
+
+
 /*
  * this routine is called from the sudo.c module and tries to validate
  * the user, host and command triplet.
@@ -480,7 +577,11 @@ int validate()
      */
     switch (return_code) {
     case FOUND_USER:
-       return_code = cmnd_check();
+       /* do we want to list available commands or check a given command? */
+       if (strcmp(cmnd, "list") == 0)
+           return_code = cmnd_list();
+       else
+           return_code = cmnd_check();
        delete_list(USER_LIST);
        delete_list(HOST_LIST);
        delete_list(CMND_LIST);