version 1.1.1.1, 2012/02/21 16:23:02
|
version 1.1.1.3, 2013/07/22 10:46:12
|
Line 1
|
Line 1
|
/* |
/* |
* Copyright (c) 1996, 1998-2005, 2010-2011 | * Copyright (c) 1996, 1998-2005, 2010-2012 |
* Todd C. Miller <Todd.Miller@courtesan.com> |
* Todd C. Miller <Todd.Miller@courtesan.com> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
Line 23
|
Line 23
|
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
#include <sys/param.h> |
|
#include <stdio.h> |
#include <stdio.h> |
#ifdef HAVE_STRING_H |
#ifdef HAVE_STRING_H |
# include <string.h> |
# include <string.h> |
Line 41
|
Line 40
|
/* |
/* |
* Verify that path is a normal file and executable by root. |
* Verify that path is a normal file and executable by root. |
*/ |
*/ |
char * | bool |
sudo_goodpath(const char *path, struct stat *sbp) |
sudo_goodpath(const char *path, struct stat *sbp) |
{ |
{ |
struct stat sb; |
struct stat sb; |
|
bool rval = false; |
|
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. */ |
return NULL; | if (S_ISREG(sb.st_mode) && ISSET(sb.st_mode, 0111)) |
| rval = true; |
if (stat(path, &sb)) | else |
return NULL; | errno = EACCES; |
| if (sbp) |
/* Make sure path describes an executable regular file. */ | (void) memcpy(sbp, &sb, sizeof(struct stat)); |
if (!S_ISREG(sb.st_mode) || !(sb.st_mode & 0000111)) { | |
errno = EACCES; | |
return NULL; | |
} |
} |
|
|
if (sbp != NULL) | debug_return_bool(rval); |
(void) memcpy(sbp, &sb, sizeof(struct stat)); | |
return (char *)path; | |
} |
} |