From 1ed1db9cf3f5c4feb2c3d48b36fd81be1ab4785c Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sat, 12 Mar 1994 18:36:53 +0000 Subject: [PATCH] updated to work with configure + pathnames.h --- check.c | 21 +++++++++++++++------ find_path.c | 48 ++++++++++++++++++++++++++++++------------------ getpass.c | 19 ++++++------------- logging.c | 32 ++++++++++++++++++++++---------- parse.c | 17 +++++++++++++++-- sudo.c | 28 +++++++++++++++++++--------- 6 files changed, 107 insertions(+), 58 deletions(-) diff --git a/check.c b/check.c index 74bf0e41f..f3bbc1d41 100644 --- a/check.c +++ b/check.c @@ -39,9 +39,18 @@ static char rcsid[] = "$Id$"; #endif /* lint */ +#include "config.h" + #include +#ifdef HAVE_UNISTD_H +#include +#endif /* HAVE_UNISTD_H */ +#ifdef HAVE_STRING_H #include +#endif /* HAVE_STRING_H */ +#ifdef HAVE_STRINGS_H #include +#endif /* HAVE_STRINGS_H */ #include #include #include @@ -109,7 +118,7 @@ static int check_timestamp() register int timestamp_is_old = -1; time_t now; - (void) sprintf(timestampfile, "%s/%s", TIMEDIR, user); + (void) sprintf(timestampfile, "%s/%s", _PATH_SUDO_TIMEDIR, user); timestampfile_p = timestampfile; 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 */ - for (p = timestampfile + 1; p = index(p, '/'); *p++ = '/') { + for (p = timestampfile + 1; p = strchr(p, '/'); *p++ = '/') { *p = '\0'; if (stat(timestampfile, &statbuf) < 0) { - if (strcmp(timestampfile, TIMEDIR)) + if (strcmp(timestampfile, _PATH_SUDO_TIMEDIR)) (void) fprintf(stderr, "Cannot stat() %s\n", timestampfile); timedir_is_good = 0; *p = '/'; @@ -152,11 +161,11 @@ static int check_timestamp() */ else { 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"); timedir_is_good = 0; } else { - timedir_is_good = 1;/* TIMEDIR now exists */ + timedir_is_good = 1;/* _PATH_SUDO_TIMEDIR now exists */ reminder(); } } @@ -206,7 +215,7 @@ static void update_timestamp() static void check_passwd() { -#if !(defined (linux) && defined (SHADOW_PWD)) +#if !(defined (linux) && defined (HAVE_LIBSHADOW)) char *crypt(); #endif /* linux */ struct passwd *pw_ent; diff --git a/find_path.c b/find_path.c index 516db4175..bbc81b6e1 100644 --- a/find_path.c +++ b/find_path.c @@ -48,19 +48,31 @@ static char rcsid[] = "$Id$"; #endif /* lint */ +#include "config.h" + #include -#ifdef STD_HEADERS +#ifdef STDC_HEADERS #include -#endif /* STD_HEADERS */ +#endif /* STDC_HEADERS */ +#ifdef HAVE_UNISTD_H +#include +#endif /* HAVE_UNISTD_H */ +#ifdef HAVE_STRING_H #include +#endif /* HAVE_STRING_H */ +#ifdef HAVE_STRINGS_H #include +#endif /* HAVE_STRINGS_H */ +#ifdef HAVE_MALLOC_H +#include +#endif /* HAVE_MALLOC_H */ #include #include #include #include #include "sudo.h" -#ifndef STD_HEADERS +#ifndef STDC_HEADERS extern char *malloc(); extern char *getenv(); extern char *strcpy(); @@ -68,15 +80,15 @@ extern int fprintf(); extern int readlink(); extern int stat(); extern int lstat(); -#ifdef USE_CWD +#ifdef HAVE_GETCWD extern char *getcwd(); #else extern char *getwd(); -#endif -#ifndef NEED_STRDUP +#endif /* HAVE_GETCWD */ +#ifdef HAVE_STRDUP extern char *strdup(); -#endif -#endif /* !STD_HEADERS */ +#endif /* HAVE_STRDUP */ +#endif /* !STDC_HEADERS */ /******************************************************************* @@ -105,7 +117,7 @@ char *find_path(file) /* * do we need to search the path? */ - if (index(file, '/')) + if (strchr(file, '/')) return (qualify(file)); /* @@ -120,7 +132,7 @@ char *find_path(file) } do { - if ((n = index(path, ':'))) + if ((n = strchr(path, ':'))) *n = '\0'; /* @@ -207,11 +219,11 @@ char *qualify(n) * if n is relative, fill full with working dir */ if (*n != '/') { -#ifdef USE_CWD +#ifdef HAVE_GETCWD if (!getcwd(full, (size_t) (MAXPATHLEN + 1))) { #else if (!getwd(full)) { -#endif +#endif /* HAVE_GETCWD */ (void) fprintf(stderr, "%s: Can't get working directory!\n", Argv[0]); exit(1); @@ -230,14 +242,14 @@ char *qualify(n) /* * find and terminate end of path component */ - if ((end = index(beg, '/'))) + if ((end = strchr(beg, '/'))) *end = '\0'; if (beg == end) continue; else if (!strcmp(beg, ".")); /* ignore "." */ else if (!strcmp(beg, "..")) { - if ((tmp = rindex(full, '/'))) + if ((tmp = strrchr(full, '/'))) *tmp = '\0'; } else { strcat(full, "/"); @@ -280,8 +292,8 @@ char *qualify(n) } if (newname[0] == '/') /* reset full if necesary */ full[0] = '\0'; - else if ((tmp = rindex(full, '/'))) /* remove component from full */ - *tmp = '\0'; + else if ((tmp = strrchr(full, '/'))) + *tmp = '\0'; /* remove component from full */ strcpy(name, newname); /* reset name with new path */ beg = NULL; /* since we have a new name */ @@ -298,7 +310,7 @@ char *qualify(n) } -#ifdef NEED_STRDUP +#ifndef HAVE_STRDUP /****************************************************************** * * strdup() @@ -318,4 +330,4 @@ char *strdup(s1) (void) strcpy(s, s1); return (s); } -#endif +#endif /* !HAVE_STRDUP */ diff --git a/getpass.c b/getpass.c index 03f3aa66b..ea9524256 100644 --- a/getpass.c +++ b/getpass.c @@ -27,17 +27,10 @@ static char sccsid[] = "@(#)getpass.c based on 5.3 (Berkeley) 9/22/88"; #endif /* LIBC_SCCS and not lint */ -/* - * HP-UX and Irix defines -*/ -#if defined(sgi) || defined(hpux) -#ifndef USE_TERMIO -#define USE_TERMIO -#endif /* USE_TERMIO */ -#endif /* sgi || hpux */ +#include "config.h" #include -#ifdef USE_TERMIO +#ifdef HAVE_TERMIO_H #include #else #include @@ -50,7 +43,7 @@ char * getpass(prompt) char *prompt; { -#ifdef USE_TERMIO +#ifdef HAVE_TERMIO_H struct termio ttyb; #else struct sgttyb ttyb; @@ -60,7 +53,7 @@ char * FILE *fp, *outfp; long omask; int fd_tmp; -#ifdef USE_TERMIO +#ifdef HAVE_TERMIO_H tcflag_t svflagval; #else int svflagval; @@ -77,7 +70,7 @@ char * outfp = stderr; fp = stdin; } -#ifdef USE_TERMIO +#ifdef HAVE_TERMIO_H (void) ioctl(fileno(fp), TCGETA, &ttyb); svflagval = ttyb.c_lflag; ttyb.c_lflag &= ~ECHO; @@ -99,7 +92,7 @@ char * *p = '\0'; (void) write(fileno(outfp), "\n", 1); -#ifdef USE_TERMIO +#ifdef HAVE_TERMIO_H ttyb.c_lflag = svflagval; (void) ioctl(fileno(fp), TCSETA, &ttyb); #else diff --git a/logging.c b/logging.c index dcd4d3f74..7fef6370b 100644 --- a/logging.c +++ b/logging.c @@ -40,8 +40,18 @@ static char rcsid[] = "$Id$"; #endif /* lint */ +#include "config.h" + #include +#ifdef HAVE_UNISTD_H +#include +#endif /* HAVE_UNISTD_H */ +#ifdef HAVE_STRING_H #include +#endif /* HAVE_STRING_H */ +#ifdef HAVE_STRINGS_H +#include +#endif /* HAVE_STRINGS_H */ #include #include #include @@ -53,7 +63,7 @@ static char rcsid[] = "$Id$"; void log_error(); void readchild(); static void send_mail(); -static void reapchild(); +static RETSIGTYPE reapchild(); static int appropriate(); static char logline[MAXLOGLEN + 8]; @@ -99,11 +109,11 @@ void log_error(code) /* * so we know where we are... */ -#ifdef USE_CWD +#ifdef HAVE_GETCWD getcwd(cwd, (size_t) (MAXPATHLEN + 1)); #else getwd(cwd); -#endif +#endif /* HAVE_GETCWD */ switch (code) { @@ -129,7 +139,8 @@ void log_error(code) break; 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 pri = Syslog_priority_NO; #endif @@ -161,7 +172,8 @@ void log_error(code) case NO_SUDOERS_FILE: switch (errno) { case ENOENT: - (void) sprintf(p, "There is no %s file. ", SUDOERS); + (void) sprintf(p, "There is no %s file. ", + _PATH_SUDO_SUDOERS); break; case EACCES: (void) sprintf(p, "%s needs to run setuid root. ", @@ -169,7 +181,7 @@ void log_error(code) break; default: (void) sprintf(p, "There is a problem opening %s ", - SUDOERS); + _PATH_SUDO_SUDOERS); break; } #ifdef SYSLOG @@ -268,10 +280,10 @@ void log_error(code) be_root(); oldmask = umask(077); - fp = fopen(LOGFILE, "a"); + fp = fopen(_PATH_SUDO_LOGFILE, "a"); (void) umask(oldmask); 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(); } else { char *beg, *oldend, *end; @@ -283,7 +295,7 @@ void log_error(code) beg = end = logline; while (beg) { oldend = end; - end = index(oldend, ' '); + end = strchr(oldend, ' '); if (end) { *end = '\0'; @@ -427,7 +439,7 @@ static void send_mail() * This function gets rid fo all the ugly zombies */ -static void reapchild() +static RETSIGTYPE reapchild() { (void) wait(NULL); } diff --git a/parse.c b/parse.c index ab7c99a06..f20a91d19 100644 --- a/parse.c +++ b/parse.c @@ -38,8 +38,21 @@ static char rcsid[] = "$Id$"; #endif /* lint */ +#include "config.h" + #include +#ifdef HAVE_UNISTD_H +#include +#endif /* HAVE_UNISTD_H */ +#ifdef HAVE_STRING_H #include +#endif /* HAVE_STRING_H */ +#ifdef HAVE_STRINGS_H +#include +#endif /* HAVE_STRINGS_H */ +#ifdef HAVE_MALLOC_H +#include +#endif /* HAVE_MALLOC_H */ #include #include #include @@ -430,8 +443,8 @@ int validate() /* become root */ be_root(); - if ((sudoers_fp = fopen(SUDOERS, "r")) == NULL) { - perror(SUDOERS); + if ((sudoers_fp = fopen(_PATH_SUDO_SUDOERS, "r")) == NULL) { + perror(_PATH_SUDO_SUDOERS); log_error(NO_SUDOERS_FILE); exit(1); } diff --git a/sudo.c b/sudo.c index 1f5b88d4c..b5be38513 100644 --- a/sudo.c +++ b/sudo.c @@ -56,15 +56,24 @@ static char rcsid[] = "$Id$"; #define MAIN +#include "config.h" + #include -#ifdef STD_HEADERS +#ifdef STDC_HEADERS #include -#ifndef NeXT +#endif /* STDC_HEADERS */ +#ifdef HAVE_UNISTD_H #include -#endif /* !NeXT */ -#endif /* STD_HEADERS */ +#endif /* HAVE_UNISTD_H */ +#ifdef HAVE_STRING_H #include +#endif /* HAVE_STRING_H */ +#ifdef HAVE_STRINGS_H #include +#endif /* HAVE_STRINGS_H */ +#ifdef HAVE_MALLOC_H +#include +#endif /* HAVE_MALLOC_H */ #include #include #include @@ -72,12 +81,13 @@ static char rcsid[] = "$Id$"; #include #endif /* _AIX */ #include "sudo.h" -#ifndef STD_HEADERS + +#ifndef STDC_HEADERS extern char *malloc(); -#ifndef NEED_STRDUP +#ifdef HAVE_STRDUP extern char *strdup(); -#endif -#endif +#endif /* HAVE_STRDUP */ +#endif /* STDC_HEADERS */ int Argc; @@ -248,7 +258,7 @@ static void load_globals() * We don't want to return the fully quallified name all the time... */ #ifndef FQDN - if ((p = index(host, '.'))) + if ((p = strchr(host, '.'))) *p = '\0'; #endif }