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$";
#endif /* lint */
#include "config.h"
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif /* HAVE_STRINGS_H */
#include <fcntl.h>
#include <sys/param.h>
#include <sys/types.h>
@@ -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;

View File

@@ -48,19 +48,31 @@
static char rcsid[] = "$Id$";
#endif /* lint */
#include "config.h"
#include <stdio.h>
#ifdef STD_HEADERS
#ifdef STDC_HEADERS
#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>
#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 <errno.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#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 */

View File

@@ -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 <fcntl.h>
#ifdef USE_TERMIO
#ifdef HAVE_TERMIO_H
#include <termio.h>
#else
#include <sgtty.h>
@@ -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

View File

@@ -40,8 +40,18 @@
static char rcsid[] = "$Id$";
#endif /* lint */
#include "config.h"
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif /* HAVE_STRINGS_H */
#include <signal.h>
#include <sys/types.h>
#include <sys/time.h>
@@ -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);
}

17
parse.c
View File

@@ -38,8 +38,21 @@
static char rcsid[] = "$Id$";
#endif /* lint */
#include "config.h"
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_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 <sys/param.h>
#include <sys/types.h>
@@ -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);
}

28
sudo.c
View File

@@ -56,15 +56,24 @@ static char rcsid[] = "$Id$";
#define MAIN
#include "config.h"
#include <stdio.h>
#ifdef STD_HEADERS
#ifdef STDC_HEADERS
#include <stdlib.h>
#ifndef NeXT
#endif /* STDC_HEADERS */
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* !NeXT */
#endif /* STD_HEADERS */
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_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 <pwd.h>
#include <netdb.h>
#include <sys/param.h>
@@ -72,12 +81,13 @@ static char rcsid[] = "$Id$";
#include <sys/id.h>
#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
}