1995-03-26 05:04:11 +00:00
|
|
|
/*
|
2013-04-24 09:35:02 -04:00
|
|
|
* Copyright (c) 1996, 1998-2005, 2010-2012
|
2010-06-14 12:19:49 -04:00
|
|
|
* Todd C. Miller <Todd.Miller@courtesan.com>
|
1995-03-26 05:04:11 +00:00
|
|
|
*
|
2004-02-13 21:36:43 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
1999-07-31 16:19:45 +00:00
|
|
|
*
|
2004-02-13 21:36:43 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2003-04-16 00:42:10 +00:00
|
|
|
*
|
|
|
|
* Sponsored in part by the Defense Advanced Research Projects
|
|
|
|
* Agency (DARPA) and Air Force Research Laboratory, Air Force
|
|
|
|
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
1995-03-26 05:04:11 +00:00
|
|
|
*/
|
|
|
|
|
2004-11-19 18:39:14 +00:00
|
|
|
#include <config.h>
|
1995-03-26 05:04:11 +00:00
|
|
|
|
2001-12-14 19:52:47 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
1995-03-26 05:04:11 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef HAVE_STRING_H
|
2001-12-14 19:52:47 +00:00
|
|
|
# include <string.h>
|
1995-03-26 05:04:11 +00:00
|
|
|
#endif /* HAVE_STRING_H */
|
2010-06-29 13:08:05 -04:00
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif /* HAVE_STRINGS_H */
|
2001-12-14 19:52:47 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif /* HAVE_UNISTD_H */
|
1995-03-26 05:04:11 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
2010-03-14 19:58:47 -04:00
|
|
|
#include "sudoers.h"
|
1995-03-26 05:04:11 +00:00
|
|
|
|
1999-07-22 12:49:28 +00:00
|
|
|
/*
|
|
|
|
* Verify that path is a normal file and executable by root.
|
1995-03-26 05:04:11 +00:00
|
|
|
*/
|
2011-12-02 11:27:33 -05:00
|
|
|
bool
|
2010-04-22 18:09:53 -04:00
|
|
|
sudo_goodpath(const char *path, struct stat *sbp)
|
1995-03-26 05:04:11 +00:00
|
|
|
{
|
1999-07-22 12:49:28 +00:00
|
|
|
struct stat sb;
|
2011-12-02 11:27:33 -05:00
|
|
|
bool rval = false;
|
2011-10-22 14:40:21 -04:00
|
|
|
debug_decl(sudo_goodpath, SUDO_DEBUG_UTIL)
|
1995-03-26 05:04:11 +00:00
|
|
|
|
2011-11-13 12:11:00 -05:00
|
|
|
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))
|
2011-12-02 11:27:33 -05:00
|
|
|
rval = true;
|
2011-11-13 12:11:00 -05:00
|
|
|
else
|
|
|
|
errno = EACCES;
|
2011-11-17 16:33:32 -05:00
|
|
|
if (sbp)
|
|
|
|
(void) memcpy(sbp, &sb, sizeof(struct stat));
|
2011-11-13 12:11:00 -05:00
|
|
|
}
|
2011-10-22 14:40:21 -04:00
|
|
|
|
2011-12-02 11:27:33 -05:00
|
|
|
debug_return_bool(rval);
|
1995-03-26 05:04:11 +00:00
|
|
|
}
|