diff options
author | Todd C. Miller <Todd.Miller@courtesan.com> | 1994-07-25 22:33:25 +0000 |
---|---|---|
committer | Todd C. Miller <Todd.Miller@courtesan.com> | 1994-07-25 22:33:25 +0000 |
commit | 085c4e39f0d09927271602482e974708a6f5cc76 (patch) | |
tree | 1e5da9e01849d01d7774bfa5c53cb2202cc754cd /sudo_realpath.c | |
parent | 55a55e6860f79b5d4fa1ca35f6d59162753bb2a8 (diff) | |
download | sudo-085c4e39f0d09927271602482e974708a6f5cc76.tar.gz |
took out stuff not needed for sudo
now does be_root/be_user itself
now uses cwd global
Diffstat (limited to 'sudo_realpath.c')
-rw-r--r-- | sudo_realpath.c | 49 |
1 files changed, 14 insertions, 35 deletions
diff --git a/sudo_realpath.c b/sudo_realpath.c index 76ec3e629..76b8041a4 100644 --- a/sudo_realpath.c +++ b/sudo_realpath.c @@ -19,8 +19,11 @@ * ******************************************************************* * - * This module contains realpath(3) for those systems that lack it. - * realpath(3) takes a path to qualify and a pointer to a string + * This module contains sudo_realpath(3), a customized version of + * realpath(3). It is necesary to do the final chdir(2) as the + * uid of the invoking user. + * + * sudo_realpath(3) takes a path to qualify and a pointer to a string * as a copyout parameter. This string should be of size MAXPATHLEN. * * Todd C. Miller (millert@colorado.edu) Fri Jun 3 18:32:19 MDT 1994 @@ -47,6 +50,8 @@ static char rcsid[] = "$Id$"; #include <sys/stat.h> #include <sys/param.h> +#include "sudo.h" + #ifndef STDC_HEADERS extern char *strcpy(); extern int readlink(); @@ -68,11 +73,7 @@ extern int lstat(); /* * Prototypes */ -#ifdef HAVE_FCHDIR -static void realpath_restore __P((FILE *)); -#else static void realpath_restore __P((char *)); -#endif /* HAVE_FCHDIR */ /* @@ -83,22 +84,17 @@ extern int errno; /****************************************************************** * - * realpath() + * sudo_realpath() * * this function takes a path and makes it fully qualified and resolves * all symbolic links, returning the fully qualfied path. */ -char * realpath(old, new) +char * sudo_realpath(old, new) const char * old; char * new; { char buf[MAXPATHLEN]; /* generic path buffer */ -#ifdef HAVE_FCHDIR - FILE * cwd; /* current working dir */ -#else - char cwd[MAXPATHLEN]; /* old working dir */ -#endif /* HAVE_FCHDIR */ struct stat statbuf; /* for lstat() */ char * temp; /* temporary ptr */ int len; /* length parameter */ @@ -107,18 +103,12 @@ char * realpath(old, new) if (old == NULL || old[0] == NULL) return(NULL); - /* save old cwd so we can get back */ -#ifdef HAVE_FCHDIR - if (!(cwd = fopen(".", "r"))) - return(NULL); -#else - if (!getcwd(cwd, sizeof(cwd))) - return(NULL); -#endif /* HAVE_FCHDIR */ - new[MAXPATHLEN - 1] = '\0'; (void) strncpy(new, old, MAXPATHLEN - 1); + /* we need to be root for this section */ + be_root(); + /* * Resolve the last component of the path if it is a link * until it is a non-link. @@ -211,25 +201,14 @@ char * realpath(old, new) * this function cd's to cwd, closes it, and returns path. */ -#ifdef HAVE_FCHDIR -static void realpath_restore(cwd) - FILE * cwd; -{ - int old_errno = errno; /* so we can restore errno... */ - - (void) fchdir(fileno(cwd)); - (void) fclose(cwd); - - errno = old_errno; -} -#else static void realpath_restore(cwd) char * cwd; { int old_errno = errno; /* so we can restore errno... */ + /* relinquish root privs and chdir to where we started... */ + be_user(); (void) chdir(cwd); errno = old_errno; } -#endif /* HAVE_FCHDIR */ |