2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 18:08:23 +00:00
sudo/goodpath.c

73 lines
1.9 KiB
C
Raw Normal View History

1995-03-26 05:04:11 +00:00
/*
* Copyright (c) 1996, 1998, 1999, 2001
* Todd C. Miller <Todd.Miller@courtesan.com>.
1995-03-26 05:04:11 +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.
*
* 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
*/
#include <config.h>
1995-03-26 05:04:11 +00:00
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
1995-03-26 05:04:11 +00:00
#include <stdio.h>
#ifdef HAVE_STRING_H
# include <string.h>
#else
# ifdef HAVE_STRINGS_H
# include <strings.h>
# endif
1995-03-26 05:04:11 +00:00
#endif /* HAVE_STRING_H */
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
1995-03-26 05:04:11 +00:00
#include <errno.h>
#include "sudo.h"
1998-11-18 04:16:13 +00:00
#ifndef lint
1999-01-17 23:16:20 +00:00
static const char rcsid[] = "$Sudo$";
1998-11-18 04:16:13 +00:00
#endif /* lint */
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
*/
char *
sudo_goodpath(path, sbp)
1999-07-22 12:49:28 +00:00
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;
1995-03-26 05:04:11 +00:00
1999-07-22 12:49:28 +00:00
/* Check for brain damage */
1995-03-26 05:04:11 +00:00
if (path == NULL || path[0] == '\0')
return(NULL);
if (stat(path, &sb))
return(NULL);
1999-07-22 12:49:28 +00:00
/* Make sure path describes an executable regular file. */
if (!S_ISREG(sb.st_mode) || !(sb.st_mode & 0000111)) {
errno = EACCES;
1995-03-26 05:04:11 +00:00
return(NULL);
}
1999-07-22 12:49:28 +00:00
if (sbp != NULL)
(void) memcpy(sbp, &sb, sizeof(struct stat));
1999-07-22 12:49:28 +00:00
return((char *)path);
1995-03-26 05:04:11 +00:00
}