From ffbade154129a703e113b708d9e6be72c4d483f6 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 1 Sep 1995 02:54:08 +0000 Subject: [PATCH] don't try to stat() "pseudo commands" like "validate" --- parse.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/parse.c b/parse.c index 20eec7305..756c9acba 100644 --- a/parse.c +++ b/parse.c @@ -157,8 +157,7 @@ int validate(check_cmnd) * If path doesn't end in /, return TRUE iff cmnd & path name the same inode; * otherwise, return TRUE if cmnd names one of the inodes in path */ -int -path_matches(cmnd, path) +int path_matches(cmnd, path) char *cmnd, *path; { int plen; @@ -169,6 +168,10 @@ path_matches(cmnd, path) static char *c; char *args; + /* don't bother with pseudo commands like "validate" */ + if (*cmnd != '/') + return(FALSE); + /* only need to stat cmnd once since it never changes */ if (cmnd_st.st_dev == 0) { if (stat(cmnd, &cmnd_st) < 0) @@ -180,9 +183,8 @@ path_matches(cmnd, path) } /* if the given path has command line args, split them out */ - if ((args = strchr(path, ' '))) { + if ((args = strchr(path, ' '))) *args++ = '\0'; - } plen = strlen(path); if (path[plen - 1] != '/') { @@ -201,10 +203,15 @@ path_matches(cmnd, path) if (stat(path, &pst) < 0) return(FALSE); - /* XXX - clean up this monstrosity! */ + /* put things back the way we found 'em */ if (args) *(args - 1) = ' '; + /* + * Return true if inode/device matches and there are no args + * (in sudoers or command) or if the args match; + * else return false. + */ if (cmnd_st.st_dev == pst.st_dev && cmnd_st.st_ino == pst.st_ino) { if (!cmnd_args && !args) return(TRUE); @@ -216,7 +223,9 @@ path_matches(cmnd, path) return(FALSE); } - /* grot through path's directory entries, looking for cmnd */ + /* + * Grot through path's directory entries, looking for cmnd. + */ dirp = opendir(path); if (dirp == NULL) return(FALSE); @@ -241,8 +250,7 @@ path_matches(cmnd, path) -int -addr_matches(n) +int addr_matches(n) char *n; { int i; @@ -261,8 +269,7 @@ addr_matches(n) -int -netgr_matches(netgr, host, user) +int netgr_matches(netgr, host, user) char *netgr; char *host; char *user; -- 2.40.0