Make sudo_goodpath() return value bolean
This commit is contained in:
@@ -60,8 +60,8 @@ find_path(char *infile, char **outfile, struct stat *sbp, char *path,
|
|||||||
static char command[PATH_MAX]; /* qualified filename */
|
static char command[PATH_MAX]; /* qualified filename */
|
||||||
char *n; /* for traversing path */
|
char *n; /* for traversing path */
|
||||||
char *origpath; /* so we can free path later */
|
char *origpath; /* so we can free path later */
|
||||||
char *result = NULL; /* result of path/file lookup */
|
int found = FALSE; /* did we find the command? */
|
||||||
int checkdot = 0; /* check current dir? */
|
int checkdot = FALSE; /* check current dir? */
|
||||||
int len; /* length parameter */
|
int len; /* length parameter */
|
||||||
debug_decl(find_path, SUDO_DEBUG_UTIL)
|
debug_decl(find_path, SUDO_DEBUG_UTIL)
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ find_path(char *infile, char **outfile, struct stat *sbp, char *path,
|
|||||||
len = snprintf(command, sizeof(command), "%s/%s", path, infile);
|
len = snprintf(command, sizeof(command), "%s/%s", path, infile);
|
||||||
if (len <= 0 || len >= sizeof(command))
|
if (len <= 0 || len >= sizeof(command))
|
||||||
errorx(1, _("%s: %s"), infile, strerror(ENAMETOOLONG));
|
errorx(1, _("%s: %s"), infile, strerror(ENAMETOOLONG));
|
||||||
if ((result = sudo_goodpath(command, sbp)))
|
if ((found = sudo_goodpath(command, sbp)))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
path = n + 1;
|
path = n + 1;
|
||||||
@@ -117,17 +117,17 @@ find_path(char *infile, char **outfile, struct stat *sbp, char *path,
|
|||||||
/*
|
/*
|
||||||
* Check current dir if dot was in the PATH
|
* Check current dir if dot was in the PATH
|
||||||
*/
|
*/
|
||||||
if (!result && checkdot) {
|
if (!found && checkdot) {
|
||||||
len = snprintf(command, sizeof(command), "./%s", infile);
|
len = snprintf(command, sizeof(command), "./%s", infile);
|
||||||
if (len <= 0 || len >= sizeof(command))
|
if (len <= 0 || len >= sizeof(command))
|
||||||
errorx(1, _("%s: %s"), infile, strerror(ENAMETOOLONG));
|
errorx(1, _("%s: %s"), infile, strerror(ENAMETOOLONG));
|
||||||
result = sudo_goodpath(command, sbp);
|
found = sudo_goodpath(command, sbp);
|
||||||
if (result && ignore_dot)
|
if (found && ignore_dot)
|
||||||
debug_return_int(NOT_FOUND_DOT);
|
debug_return_int(NOT_FOUND_DOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (found) {
|
||||||
*outfile = result;
|
*outfile = command;
|
||||||
debug_return_int(FOUND);
|
debug_return_int(FOUND);
|
||||||
} else
|
} else
|
||||||
debug_return_int(NOT_FOUND);
|
debug_return_int(NOT_FOUND);
|
||||||
|
@@ -41,27 +41,21 @@
|
|||||||
/*
|
/*
|
||||||
* Verify that path is a normal file and executable by root.
|
* Verify that path is a normal file and executable by root.
|
||||||
*/
|
*/
|
||||||
char *
|
int
|
||||||
sudo_goodpath(const char *path, struct stat *sbp)
|
sudo_goodpath(const char *path, struct stat *sbp)
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
int rval = FALSE;
|
||||||
debug_decl(sudo_goodpath, SUDO_DEBUG_UTIL)
|
debug_decl(sudo_goodpath, SUDO_DEBUG_UTIL)
|
||||||
|
|
||||||
/* Check for brain damage */
|
if (path != NULL && stat(path, &sb) == 0) {
|
||||||
if (path == NULL || path[0] == '\0')
|
/* Make sure path describes an executable regular file. */
|
||||||
debug_return_str(NULL);
|
if (S_ISREG(sb.st_mode) && ISSET(sb.st_mode, 0111))
|
||||||
|
rval = TRUE;
|
||||||
if (stat(path, &sb))
|
else
|
||||||
debug_return_str(NULL);
|
errno = EACCES;
|
||||||
|
(void) memcpy(sbp, &sb, sizeof(struct stat));
|
||||||
/* Make sure path describes an executable regular file. */
|
|
||||||
if (!S_ISREG(sb.st_mode) || !(sb.st_mode & 0000111)) {
|
|
||||||
errno = EACCES;
|
|
||||||
debug_return_str(NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sbp != NULL)
|
debug_return_int(rval);
|
||||||
(void) memcpy(sbp, &sb, sizeof(struct stat));
|
|
||||||
|
|
||||||
debug_return_str((char *)path);
|
|
||||||
}
|
}
|
||||||
|
@@ -207,7 +207,7 @@ struct timeval;
|
|||||||
#define YY_DECL int yylex(void)
|
#define YY_DECL int yylex(void)
|
||||||
|
|
||||||
/* goodpath.c */
|
/* goodpath.c */
|
||||||
char *sudo_goodpath(const char *, struct stat *);
|
int sudo_goodpath(const char *, struct stat *);
|
||||||
|
|
||||||
/* findpath.c */
|
/* findpath.c */
|
||||||
int find_path(char *, char **, struct stat *, char *, int);
|
int find_path(char *, char **, struct stat *, char *, int);
|
||||||
|
Reference in New Issue
Block a user