From: Todd C. Miller Date: Sat, 13 Aug 1994 01:22:10 +0000 (+0000) Subject: fixed a bug that caused directory specs in a Cmnd_Alias to fail if the X-Git-Tag: SUDO_1_3_1~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=971a69bb261d48dba089d8ba1ebdf0fda62ec268;p=sudo fixed a bug that caused directory specs in a Cmnd_Alias to fail if the 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 --- diff --git a/parse.c b/parse.c index 8526022e8..fb7c6d796 100644 --- 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)); +}