Use a common function for resolviong the user's editor in sudoedit

and visudo.  The find_path() function now returns a dynamically
allocated path instead of using a static string.
This commit is contained in:
Todd C. Miller
2015-06-18 09:51:36 -06:00
parent a38253b101
commit ac13264b44
8 changed files with 366 additions and 308 deletions

View File

@@ -43,18 +43,22 @@
bool
sudo_goodpath(const char *path, struct stat *sbp)
{
struct stat sb;
bool rval = false;
debug_decl(sudo_goodpath, SUDOERS_DEBUG_UTIL)
if (path != NULL && stat(path, &sb) == 0) {
/* Make sure path describes an executable regular file. */
if (S_ISREG(sb.st_mode) && ISSET(sb.st_mode, 0111))
rval = true;
else
errno = EACCES;
if (sbp)
(void) memcpy(sbp, &sb, sizeof(struct stat));
if (path != NULL) {
struct stat sb;
if (sbp == NULL)
sbp = &sb;
if (stat(path, sbp) == 0) {
/* Make sure path describes an executable regular file. */
if (S_ISREG(sbp->st_mode) && ISSET(sbp->st_mode, 0111))
rval = true;
else
errno = EACCES;
}
}
debug_return_bool(rval);