updated to work with configure + pathnames.h

This commit is contained in:
Todd C. Miller
1994-03-12 18:36:53 +00:00
parent 51e3733974
commit 1ed1db9cf3
6 changed files with 107 additions and 58 deletions

21
check.c
View File

@@ -39,9 +39,18 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif /* lint */ #endif /* lint */
#include "config.h"
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
#include <string.h> #include <string.h>
#endif /* HAVE_STRING_H */
#ifdef HAVE_STRINGS_H
#include <strings.h> #include <strings.h>
#endif /* HAVE_STRINGS_H */
#include <fcntl.h> #include <fcntl.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/types.h> #include <sys/types.h>
@@ -109,7 +118,7 @@ static int check_timestamp()
register int timestamp_is_old = -1; register int timestamp_is_old = -1;
time_t now; time_t now;
(void) sprintf(timestampfile, "%s/%s", TIMEDIR, user); (void) sprintf(timestampfile, "%s/%s", _PATH_SUDO_TIMEDIR, user);
timestampfile_p = timestampfile; timestampfile_p = timestampfile;
timedir_is_good = 1; /* now there's an assumption for ya... */ timedir_is_good = 1; /* now there's an assumption for ya... */
@@ -120,10 +129,10 @@ static int check_timestamp()
/* /*
* walk through the path one directory at a time * walk through the path one directory at a time
*/ */
for (p = timestampfile + 1; p = index(p, '/'); *p++ = '/') { for (p = timestampfile + 1; p = strchr(p, '/'); *p++ = '/') {
*p = '\0'; *p = '\0';
if (stat(timestampfile, &statbuf) < 0) { if (stat(timestampfile, &statbuf) < 0) {
if (strcmp(timestampfile, TIMEDIR)) if (strcmp(timestampfile, _PATH_SUDO_TIMEDIR))
(void) fprintf(stderr, "Cannot stat() %s\n", timestampfile); (void) fprintf(stderr, "Cannot stat() %s\n", timestampfile);
timedir_is_good = 0; timedir_is_good = 0;
*p = '/'; *p = '/';
@@ -152,11 +161,11 @@ static int check_timestamp()
*/ */
else { else {
timestamp_is_old = 1; /* user has to enter password */ timestamp_is_old = 1; /* user has to enter password */
if (mkdir(TIMEDIR, 0700)) { /* make the TIMEDIR directory */ if (mkdir(_PATH_SUDO_TIMEDIR, 0700)) { /* make the TIMEDIR directory */
perror("check_timestamp: mkdir"); perror("check_timestamp: mkdir");
timedir_is_good = 0; timedir_is_good = 0;
} else { } else {
timedir_is_good = 1;/* TIMEDIR now exists */ timedir_is_good = 1;/* _PATH_SUDO_TIMEDIR now exists */
reminder(); reminder();
} }
} }
@@ -206,7 +215,7 @@ static void update_timestamp()
static void check_passwd() static void check_passwd()
{ {
#if !(defined (linux) && defined (SHADOW_PWD)) #if !(defined (linux) && defined (HAVE_LIBSHADOW))
char *crypt(); char *crypt();
#endif /* linux */ #endif /* linux */
struct passwd *pw_ent; struct passwd *pw_ent;

View File

@@ -48,19 +48,31 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif /* lint */ #endif /* lint */
#include "config.h"
#include <stdio.h> #include <stdio.h>
#ifdef STD_HEADERS #ifdef STDC_HEADERS
#include <stdlib.h> #include <stdlib.h>
#endif /* STD_HEADERS */ #endif /* STDC_HEADERS */
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
#include <string.h> #include <string.h>
#endif /* HAVE_STRING_H */
#ifdef HAVE_STRINGS_H
#include <strings.h> #include <strings.h>
#endif /* HAVE_STRINGS_H */
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif /* HAVE_MALLOC_H */
#include <errno.h> #include <errno.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "sudo.h" #include "sudo.h"
#ifndef STD_HEADERS #ifndef STDC_HEADERS
extern char *malloc(); extern char *malloc();
extern char *getenv(); extern char *getenv();
extern char *strcpy(); extern char *strcpy();
@@ -68,15 +80,15 @@ extern int fprintf();
extern int readlink(); extern int readlink();
extern int stat(); extern int stat();
extern int lstat(); extern int lstat();
#ifdef USE_CWD #ifdef HAVE_GETCWD
extern char *getcwd(); extern char *getcwd();
#else #else
extern char *getwd(); extern char *getwd();
#endif #endif /* HAVE_GETCWD */
#ifndef NEED_STRDUP #ifdef HAVE_STRDUP
extern char *strdup(); extern char *strdup();
#endif #endif /* HAVE_STRDUP */
#endif /* !STD_HEADERS */ #endif /* !STDC_HEADERS */
/******************************************************************* /*******************************************************************
@@ -105,7 +117,7 @@ char *find_path(file)
/* /*
* do we need to search the path? * do we need to search the path?
*/ */
if (index(file, '/')) if (strchr(file, '/'))
return (qualify(file)); return (qualify(file));
/* /*
@@ -120,7 +132,7 @@ char *find_path(file)
} }
do { do {
if ((n = index(path, ':'))) if ((n = strchr(path, ':')))
*n = '\0'; *n = '\0';
/* /*
@@ -207,11 +219,11 @@ char *qualify(n)
* if n is relative, fill full with working dir * if n is relative, fill full with working dir
*/ */
if (*n != '/') { if (*n != '/') {
#ifdef USE_CWD #ifdef HAVE_GETCWD
if (!getcwd(full, (size_t) (MAXPATHLEN + 1))) { if (!getcwd(full, (size_t) (MAXPATHLEN + 1))) {
#else #else
if (!getwd(full)) { if (!getwd(full)) {
#endif #endif /* HAVE_GETCWD */
(void) fprintf(stderr, "%s: Can't get working directory!\n", (void) fprintf(stderr, "%s: Can't get working directory!\n",
Argv[0]); Argv[0]);
exit(1); exit(1);
@@ -230,14 +242,14 @@ char *qualify(n)
/* /*
* find and terminate end of path component * find and terminate end of path component
*/ */
if ((end = index(beg, '/'))) if ((end = strchr(beg, '/')))
*end = '\0'; *end = '\0';
if (beg == end) if (beg == end)
continue; continue;
else if (!strcmp(beg, ".")); /* ignore "." */ else if (!strcmp(beg, ".")); /* ignore "." */
else if (!strcmp(beg, "..")) { else if (!strcmp(beg, "..")) {
if ((tmp = rindex(full, '/'))) if ((tmp = strrchr(full, '/')))
*tmp = '\0'; *tmp = '\0';
} else { } else {
strcat(full, "/"); strcat(full, "/");
@@ -280,8 +292,8 @@ char *qualify(n)
} }
if (newname[0] == '/') /* reset full if necesary */ if (newname[0] == '/') /* reset full if necesary */
full[0] = '\0'; full[0] = '\0';
else if ((tmp = rindex(full, '/'))) /* remove component from full */ else if ((tmp = strrchr(full, '/')))
*tmp = '\0'; *tmp = '\0'; /* remove component from full */
strcpy(name, newname); /* reset name with new path */ strcpy(name, newname); /* reset name with new path */
beg = NULL; /* since we have a new name */ beg = NULL; /* since we have a new name */
@@ -298,7 +310,7 @@ char *qualify(n)
} }
#ifdef NEED_STRDUP #ifndef HAVE_STRDUP
/****************************************************************** /******************************************************************
* *
* strdup() * strdup()
@@ -318,4 +330,4 @@ char *strdup(s1)
(void) strcpy(s, s1); (void) strcpy(s, s1);
return (s); return (s);
} }
#endif #endif /* !HAVE_STRDUP */

View File

@@ -27,17 +27,10 @@
static char sccsid[] = "@(#)getpass.c based on 5.3 (Berkeley) 9/22/88"; static char sccsid[] = "@(#)getpass.c based on 5.3 (Berkeley) 9/22/88";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
/* #include "config.h"
* HP-UX and Irix defines
*/
#if defined(sgi) || defined(hpux)
#ifndef USE_TERMIO
#define USE_TERMIO
#endif /* USE_TERMIO */
#endif /* sgi || hpux */
#include <fcntl.h> #include <fcntl.h>
#ifdef USE_TERMIO #ifdef HAVE_TERMIO_H
#include <termio.h> #include <termio.h>
#else #else
#include <sgtty.h> #include <sgtty.h>
@@ -50,7 +43,7 @@ char *
getpass(prompt) getpass(prompt)
char *prompt; char *prompt;
{ {
#ifdef USE_TERMIO #ifdef HAVE_TERMIO_H
struct termio ttyb; struct termio ttyb;
#else #else
struct sgttyb ttyb; struct sgttyb ttyb;
@@ -60,7 +53,7 @@ char *
FILE *fp, *outfp; FILE *fp, *outfp;
long omask; long omask;
int fd_tmp; int fd_tmp;
#ifdef USE_TERMIO #ifdef HAVE_TERMIO_H
tcflag_t svflagval; tcflag_t svflagval;
#else #else
int svflagval; int svflagval;
@@ -77,7 +70,7 @@ char *
outfp = stderr; outfp = stderr;
fp = stdin; fp = stdin;
} }
#ifdef USE_TERMIO #ifdef HAVE_TERMIO_H
(void) ioctl(fileno(fp), TCGETA, &ttyb); (void) ioctl(fileno(fp), TCGETA, &ttyb);
svflagval = ttyb.c_lflag; svflagval = ttyb.c_lflag;
ttyb.c_lflag &= ~ECHO; ttyb.c_lflag &= ~ECHO;
@@ -99,7 +92,7 @@ char *
*p = '\0'; *p = '\0';
(void) write(fileno(outfp), "\n", 1); (void) write(fileno(outfp), "\n", 1);
#ifdef USE_TERMIO #ifdef HAVE_TERMIO_H
ttyb.c_lflag = svflagval; ttyb.c_lflag = svflagval;
(void) ioctl(fileno(fp), TCSETA, &ttyb); (void) ioctl(fileno(fp), TCSETA, &ttyb);
#else #else

View File

@@ -40,8 +40,18 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif /* lint */ #endif /* lint */
#include "config.h"
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
#include <string.h> #include <string.h>
#endif /* HAVE_STRING_H */
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif /* HAVE_STRINGS_H */
#include <signal.h> #include <signal.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h> #include <sys/time.h>
@@ -53,7 +63,7 @@ static char rcsid[] = "$Id$";
void log_error(); void log_error();
void readchild(); void readchild();
static void send_mail(); static void send_mail();
static void reapchild(); static RETSIGTYPE reapchild();
static int appropriate(); static int appropriate();
static char logline[MAXLOGLEN + 8]; static char logline[MAXLOGLEN + 8];
@@ -99,11 +109,11 @@ void log_error(code)
/* /*
* so we know where we are... * so we know where we are...
*/ */
#ifdef USE_CWD #ifdef HAVE_GETCWD
getcwd(cwd, (size_t) (MAXPATHLEN + 1)); getcwd(cwd, (size_t) (MAXPATHLEN + 1));
#else #else
getwd(cwd); getwd(cwd);
#endif #endif /* HAVE_GETCWD */
switch (code) { switch (code) {
@@ -129,7 +139,8 @@ void log_error(code)
break; break;
case VALIDATE_ERROR: case VALIDATE_ERROR:
(void) sprintf(p, "error in %s ; PWD=%s ; command: ", SUDOERS, cwd); (void) sprintf(p, "error in %s ; PWD=%s ; command: ",
_PATH_SUDO_SUDOERS, cwd);
#ifdef SYSLOG #ifdef SYSLOG
pri = Syslog_priority_NO; pri = Syslog_priority_NO;
#endif #endif
@@ -161,7 +172,8 @@ void log_error(code)
case NO_SUDOERS_FILE: case NO_SUDOERS_FILE:
switch (errno) { switch (errno) {
case ENOENT: case ENOENT:
(void) sprintf(p, "There is no %s file. ", SUDOERS); (void) sprintf(p, "There is no %s file. ",
_PATH_SUDO_SUDOERS);
break; break;
case EACCES: case EACCES:
(void) sprintf(p, "%s needs to run setuid root. ", (void) sprintf(p, "%s needs to run setuid root. ",
@@ -169,7 +181,7 @@ void log_error(code)
break; break;
default: default:
(void) sprintf(p, "There is a problem opening %s ", (void) sprintf(p, "There is a problem opening %s ",
SUDOERS); _PATH_SUDO_SUDOERS);
break; break;
} }
#ifdef SYSLOG #ifdef SYSLOG
@@ -268,10 +280,10 @@ void log_error(code)
be_root(); be_root();
oldmask = umask(077); oldmask = umask(077);
fp = fopen(LOGFILE, "a"); fp = fopen(_PATH_SUDO_LOGFILE, "a");
(void) umask(oldmask); (void) umask(oldmask);
if (fp == NULL) { if (fp == NULL) {
(void) sprintf(logline, "Can\'t open log file: %s", LOGFILE); (void) sprintf(logline, "Can\'t open log file: %s", _PATH_SUDO_LOGFILE);
send_mail(); send_mail();
} else { } else {
char *beg, *oldend, *end; char *beg, *oldend, *end;
@@ -283,7 +295,7 @@ void log_error(code)
beg = end = logline; beg = end = logline;
while (beg) { while (beg) {
oldend = end; oldend = end;
end = index(oldend, ' '); end = strchr(oldend, ' ');
if (end) { if (end) {
*end = '\0'; *end = '\0';
@@ -427,7 +439,7 @@ static void send_mail()
* This function gets rid fo all the ugly zombies * This function gets rid fo all the ugly zombies
*/ */
static void reapchild() static RETSIGTYPE reapchild()
{ {
(void) wait(NULL); (void) wait(NULL);
} }

17
parse.c
View File

@@ -38,8 +38,21 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif /* lint */ #endif /* lint */
#include "config.h"
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
#include <string.h> #include <string.h>
#endif /* HAVE_STRING_H */
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif /* HAVE_STRINGS_H */
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif /* HAVE_MALLOC_H */
#include <ctype.h> #include <ctype.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/types.h> #include <sys/types.h>
@@ -430,8 +443,8 @@ int validate()
/* become root */ /* become root */
be_root(); be_root();
if ((sudoers_fp = fopen(SUDOERS, "r")) == NULL) { if ((sudoers_fp = fopen(_PATH_SUDO_SUDOERS, "r")) == NULL) {
perror(SUDOERS); perror(_PATH_SUDO_SUDOERS);
log_error(NO_SUDOERS_FILE); log_error(NO_SUDOERS_FILE);
exit(1); exit(1);
} }

28
sudo.c
View File

@@ -56,15 +56,24 @@ static char rcsid[] = "$Id$";
#define MAIN #define MAIN
#include "config.h"
#include <stdio.h> #include <stdio.h>
#ifdef STD_HEADERS #ifdef STDC_HEADERS
#include <stdlib.h> #include <stdlib.h>
#ifndef NeXT #endif /* STDC_HEADERS */
#ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif /* !NeXT */ #endif /* HAVE_UNISTD_H */
#endif /* STD_HEADERS */ #ifdef HAVE_STRING_H
#include <string.h> #include <string.h>
#endif /* HAVE_STRING_H */
#ifdef HAVE_STRINGS_H
#include <strings.h> #include <strings.h>
#endif /* HAVE_STRINGS_H */
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif /* HAVE_MALLOC_H */
#include <pwd.h> #include <pwd.h>
#include <netdb.h> #include <netdb.h>
#include <sys/param.h> #include <sys/param.h>
@@ -72,12 +81,13 @@ static char rcsid[] = "$Id$";
#include <sys/id.h> #include <sys/id.h>
#endif /* _AIX */ #endif /* _AIX */
#include "sudo.h" #include "sudo.h"
#ifndef STD_HEADERS
#ifndef STDC_HEADERS
extern char *malloc(); extern char *malloc();
#ifndef NEED_STRDUP #ifdef HAVE_STRDUP
extern char *strdup(); extern char *strdup();
#endif #endif /* HAVE_STRDUP */
#endif #endif /* STDC_HEADERS */
int Argc; int Argc;
@@ -248,7 +258,7 @@ static void load_globals()
* We don't want to return the fully quallified name all the time... * We don't want to return the fully quallified name all the time...
*/ */
#ifndef FQDN #ifndef FQDN
if ((p = index(host, '.'))) if ((p = strchr(host, '.')))
*p = '\0'; *p = '\0';
#endif #endif
} }