]> granicus.if.org Git - sudo/commitdiff
fixed a bug that caused directory specs in a Cmnd_Alias to fail if the
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 13 Aug 1994 01:22:10 +0000 (01:22 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 13 Aug 1994 01:22:10 +0000 (01:22 +0000)
last entry in the spec failed (ie: it was only looking at the last entry).
CLeaned things up by adding the cmndcmp() function--all neat & tidy

parse.c

diff --git a/parse.c b/parse.c
index 8526022e89709bfbe37ea11f8125e541d1df2c3f..fb7c6d7964f1c6c9152f2a63aba433fde6014c80 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -81,6 +81,7 @@ LINK tmp_ptr, reset_ptr, save_ptr, list_ptr[NUM_LISTS];
  * Prototypes
  */
 static int hostcmp     __P((char *));
+static int cmndcmp     __P((char *, char *));
 
 
 /*
@@ -351,19 +352,9 @@ int cmnd_type_ok()
                list_ptr[CMND_LIST] = tmp_ptr -> next;
                while (next_type == TYPE3) {
                    /*
-                    * Check to see if a directory is being permitted
+                    * Match cmnd to the data (directory or file)
                     */
-                   if (list_ptr[CMND_LIST]->
-                       data[strlen(list_ptr[CMND_LIST]->data)-1] == '/' ) {
-                           /* we have a directory spec */
-                           if (strncmp(list_ptr[CMND_LIST]->data, cmnd,
-                               strlen(list_ptr[CMND_LIST]->data)) == 0)
-                               return(MATCH);
-                           else
-                               return(NO_MATCH);
-                   }
-
-                   if (strcmp(list_ptr[CMND_LIST] -> data, cmnd) == 0) {
+                   if (cmndcmp(cmnd, list_ptr[CMND_LIST] -> data) == 0) {
                        if (list_ptr[USER_LIST] -> op == '!') {
                            list_ptr[CMND_LIST] = save_ptr;
                            return (QUIT_NOW);
@@ -535,3 +526,26 @@ static int hostcmp(target)
        return(strcmp(target, host));
     }
 }
+
+
+
+/*
+ * this routine is called from cmnd_type_ok() and tries to match a cmnd
+ * to a data entry from the sudoers file.
+ */
+
+static int cmndcmp(cmnd, data)
+    char *cmnd;                                /* command the user is attempting */
+    char *data;                                /* data we are checking against */
+{
+    int len = strlen(data);
+
+    /*
+     * If the data is a directory, match based on len,
+     * otherwise do a normal strcmp(3)
+     */
+    if (*(data + len - 1) == '/')
+       return(strncmp(data, cmnd, len));
+    else
+       return(strcmp(data, cmnd));
+}