diff options
author | Todd C. Miller <Todd.Miller@sudo.ws> | 2023-03-16 15:01:41 -0600 |
---|---|---|
committer | Todd C. Miller <Todd.Miller@sudo.ws> | 2023-03-16 15:01:41 -0600 |
commit | af61b1e4a91edd239d106b7f6b44a1b3e3e39c9b (patch) | |
tree | 53f4eda64ee389b80ecd94534d27a4c678e1e14e | |
parent | 69e9ba21117f85868b583973ebc6970326593753 (diff) | |
download | sudo-af61b1e4a91edd239d106b7f6b44a1b3e3e39c9b.tar.gz |
Remove portable getcwd.c, nothing uses it anymore.
Any operating system supported by sudo already includes getcwd(3).
-rw-r--r-- | MANIFEST | 1 | ||||
-rw-r--r-- | config.h.in | 3 | ||||
-rwxr-xr-x | configure | 1 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | include/sudo_compat.h | 5 | ||||
-rw-r--r-- | lib/util/Makefile.in | 6 | ||||
-rw-r--r-- | lib/util/getcwd.c | 244 | ||||
-rwxr-xr-x | scripts/mkdep.pl | 2 |
8 files changed, 1 insertions, 262 deletions
@@ -251,7 +251,6 @@ lib/util/fnmatch.c lib/util/freezero.c lib/util/fstatat.c lib/util/getaddrinfo.c -lib/util/getcwd.c lib/util/getdelim.c lib/util/getentropy.c lib/util/getgrouplist.c diff --git a/config.h.in b/config.h.in index c1fcad17d..fa1b431d4 100644 --- a/config.h.in +++ b/config.h.in @@ -1240,9 +1240,6 @@ /* The passwd prompt timeout (in minutes). */ #undef PASSWORD_TIMEOUT -/* Define to 1 to enable replacement getcwd if system getcwd is broken. */ -#undef PREFER_PORTABLE_GETCWD - /* Enable replacement (v)snprintf if system (v)snprintf is broken. */ #undef PREFER_PORTABLE_SNPRINTF @@ -37927,4 +37927,3 @@ fi - diff --git a/configure.ac b/configure.ac index be408d2e9..15fa04395 100644 --- a/configure.ac +++ b/configure.ac @@ -4623,7 +4623,6 @@ AH_TEMPLATE(NO_ROOT_MAILER, [Define to avoid running the mailer as root.]) AH_TEMPLATE(NO_ROOT_SUDO, [Define to 1 if root should not be allowed to use sudo.]) AH_TEMPLATE(TIMESTAMP_TYPE, [Define to global, ppid or tty to set the default timestamp record type.]) AH_TEMPLATE(OFFENSIVE_INSULTS, [Define to 1 to include offensive insults from the classic version of sudo.]) -AH_TEMPLATE(PREFER_PORTABLE_GETCWD, [Define to 1 to enable replacement getcwd if system getcwd is broken.]) AH_TEMPLATE(SECURE_PATH, [A colon-separated list of directories to override the user's PATH with.]) AH_TEMPLATE(SEND_MAIL_WHEN_NOT_OK, [Define to 1 to send mail when the user is not allowed to run a command.]) AH_TEMPLATE(SEND_MAIL_WHEN_NO_HOST, [Define to 1 to send mail when the user is not allowed to run sudo on this host.]) diff --git a/include/sudo_compat.h b/include/sudo_compat.h index 45adec591..9361ff422 100644 --- a/include/sudo_compat.h +++ b/include/sudo_compat.h @@ -359,11 +359,6 @@ sudo_dso_public void sudo_freezero(void *p, size_t n); # undef freezero # define freezero(_a, _b) sudo_freezero((_a), (_b)) #endif /* HAVE_FREEZERO */ -#ifdef PREFER_PORTABLE_GETCWD -sudo_dso_public char *sudo_getcwd(char *, size_t size); -# undef getcwd -# define getcwd(_a, _b) sudo_getcwd((_a), (_b)) -#endif /* PREFER_PORTABLE_GETCWD */ #ifndef HAVE_GETGROUPLIST sudo_dso_public int sudo_getgrouplist(const char *name, GETGROUPS_T basegid, GETGROUPS_T *groups, int *ngroupsp); # undef getgrouplist diff --git a/lib/util/Makefile.in b/lib/util/Makefile.in index ed8067309..1b7eb11c9 100644 --- a/lib/util/Makefile.in +++ b/lib/util/Makefile.in @@ -813,12 +813,6 @@ getaddrinfo.i: $(srcdir)/getaddrinfo.c $(incdir)/compat/getaddrinfo.h \ $(CC) -E -o $@ $(CPPFLAGS) $< getaddrinfo.plog: getaddrinfo.i rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/getaddrinfo.c --i-file $< --output-file $@ -getcwd.lo: $(srcdir)/getcwd.c $(incdir)/sudo_compat.h $(top_builddir)/config.h - $(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(HARDENING_CFLAGS) $(srcdir)/getcwd.c -getcwd.i: $(srcdir)/getcwd.c $(incdir)/sudo_compat.h $(top_builddir)/config.h - $(CC) -E -o $@ $(CPPFLAGS) $< -getcwd.plog: getcwd.i - rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/getcwd.c --i-file $< --output-file $@ getdelim.lo: $(srcdir)/getdelim.c $(incdir)/sudo_compat.h \ $(top_builddir)/config.h $(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(HARDENING_CFLAGS) $(srcdir)/getdelim.c diff --git a/lib/util/getcwd.c b/lib/util/getcwd.c deleted file mode 100644 index 7cfc068b5..000000000 --- a/lib/util/getcwd.c +++ /dev/null @@ -1,244 +0,0 @@ -/* - * SPDX-License-Identifier: BSD-3-Clause - * - * Copyright (c) 1989, 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <config.h> - -#ifndef HAVE_GETCWD - -#include <sys/types.h> -#include <sys/stat.h> - -#include <errno.h> -#include <stdlib.h> -#include <string.h> -#include <dirent.h> -#include <limits.h> - -#include "sudo_compat.h" - -#define ISDOT(dp) \ - (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \ - (dp->d_name[1] == '.' && dp->d_name[2] == '\0'))) - -#if defined(HAVE_STRUCT_DIRENT_D_NAMLEN) && HAVE_STRUCT_DIRENT_D_NAMLEN -# define NAMLEN(dirent) (dirent)->d_namlen -#else -# define NAMLEN(dirent) strlen((dirent)->d_name) -#endif - -char * -sudo_getcwd(char *pt, size_t size) -{ - struct dirent *dp; - DIR *dir = NULL; - dev_t dev; - ino_t ino; - int first; - char *bpt, *bup; - struct stat s; - dev_t root_dev; - ino_t root_ino; - size_t ptsize, upsize; - int save_errno; - char *ept, *eup, *up; - - /* - * If no buffer specified by the user, allocate one as necessary. - * If a buffer is specified, the size has to be non-zero. The path - * is built from the end of the buffer backwards. - */ - if (pt) { - ptsize = 0; - if (!size) { - errno = EINVAL; - return NULL; - } - ept = pt + size; - } else { - if ((pt = malloc(ptsize = 1024 - 4)) == NULL) - return NULL; - ept = pt + ptsize; - } - bpt = ept - 1; - *bpt = '\0'; - - /* - * Allocate bytes (1024 - malloc space) for the string of "../"'s. - * Should always be enough (it's 340 levels). If it's not, allocate - * as necessary. Special * case the first stat, it's ".", not "..". - */ - if ((up = malloc(upsize = 1024 - 4)) == NULL) - goto err; - eup = up + PATH_MAX; - bup = up; - up[0] = '.'; - up[1] = '\0'; - - /* Save root values, so know when to stop. */ - if (stat("/", &s)) - goto err; - root_dev = s.st_dev; - root_ino = s.st_ino; - - errno = 0; /* XXX readdir has no error return. */ - - for (first = 1;; first = 0) { - /* Stat the current level. */ - if (lstat(up, &s)) - goto err; - - /* Save current node values. */ - ino = s.st_ino; - dev = s.st_dev; - - /* Check for reaching root. */ - if (root_dev == dev && root_ino == ino) { - *--bpt = '/'; - /* - * It's unclear that it's a requirement to copy the - * path to the beginning of the buffer, but it's always - * been that way and stuff would probably break. - */ - memcpy(pt, bpt, ept - bpt); - free(up); - return pt; - } - - /* - * Build pointer to the parent directory, allocating memory - * as necessary. Max length is 3 for "../", the largest - * possible component name, plus a trailing NULL. - */ - if (bup + 3 + NAME_MAX + 1 >= eup) { - char *nup; - - if ((nup = reallocarray(up, upsize, 2)) == NULL) - goto err; - upsize *= 2; - up = nup; - bup = up; - eup = up + upsize; - } - *bup++ = '.'; - *bup++ = '.'; - *bup = '\0'; - - /* Open and stat parent directory. */ - if (!(dir = opendir(up)) || fstat(dirfd(dir), &s)) - goto err; - - /* Add trailing slash for next directory. */ - *bup++ = '/'; - - /* - * If it's a mount point, have to stat each element because - * the inode number in the directory is for the entry in the - * parent directory, not the inode number of the mounted file. - */ - save_errno = 0; - if (s.st_dev == dev) { - for (;;) { - if (!(dp = readdir(dir))) - goto notfound; - if (dp->d_fileno == ino) - break; - } - } else - for (;;) { - if (!(dp = readdir(dir))) - goto notfound; - if (ISDOT(dp)) - continue; - memcpy(bup, dp->d_name, NAMLEN(dp) + 1); - - /* Save the first error for later. */ - if (lstat(up, &s)) { - if (!save_errno) - save_errno = errno; - errno = 0; - continue; - } - if (s.st_dev == dev && s.st_ino == ino) - break; - } - - /* - * Check for length of the current name, preceding slash, - * leading slash. - */ - if (bpt - pt <= NAMLEN(dp) + (first ? 1 : 2)) { - size_t len, off; - char *npt; - - if (!ptsize) { - errno = ERANGE; - goto err; - } - off = bpt - pt; - len = ept - bpt; - if ((npt = reallocarray(pt, ptsize, 2)) == NULL) - goto err; - ptsize *= 2; - pt = npt; - bpt = pt + off; - ept = pt + ptsize; - memcpy(ept - len, bpt, len); - bpt = ept - len; - } - if (!first) - *--bpt = '/'; - bpt -= NAMLEN(dp); - memcpy(bpt, dp->d_name, NAMLEN(dp)); - (void)closedir(dir); - - /* Truncate any file name. */ - *bup = '\0'; - } - -notfound: - /* - * If readdir set errno, use it, not any saved error; otherwise, - * didn't find the current directory in its parent directory, set - * errno to ENOENT. - */ - if (!errno) - errno = save_errno ? save_errno : ENOENT; - /* FALLTHROUGH */ -err: - if (ptsize) - free(pt); - if (up) - free(up); - if (dir) - (void)closedir(dir); - return NULL; -} -#endif /* HAVE_GETCWD */ diff --git a/scripts/mkdep.pl b/scripts/mkdep.pl index df4f39fb1..ebd98606d 100755 --- a/scripts/mkdep.pl +++ b/scripts/mkdep.pl @@ -120,7 +120,7 @@ sub mkdep { # XXX - fill in AUTH_OBJS from contents of the auth dir instead $makefile =~ s:\@AUTH_OBJS\@:afs.lo aix_auth.lo bsdauth.lo dce.lo fwtk.lo getspwuid.lo kerb5.lo pam.lo passwd.lo rfc1938.lo secureware.lo securid5.lo sia.lo:; $makefile =~ s:\@DIGEST\@:digest.lo digest_openssl.lo digest_gcrypt.lo:; - $makefile =~ s:\@LTLIBOBJS\@:arc4random.lo arc4random_buf.lo arc4random_uniform.lo cfmakeraw.lo closefrom.lo dup3.lo explicit_bzero.lo fchmodat.lo fchownat.lo freezero.lo fstatat.lo fnmatch.lo getaddrinfo.lo getcwd.lo getentropy.lo getgrouplist.lo getdelim.lo getopt_long.lo getusershell.lo glob.lo gmtime_r.lo inet_ntop_lo inet_pton.lo isblank.lo localtime_r.lo memrchr.lo mkdirat.lo mksiglist.lo mksigname.lo mktemp.lo nanosleep.lo openat.lo pipe2.lo pread.lo pwrite.lo pw_dup.lo reallocarray.lo realpath.lo sha2.lo sig2str.lo siglist.lo signame.lo snprintf.lo str2sig.lo strlcat.lo strlcpy.lo strndup.lo strnlen.lo strsignal.lo timegm.lo unlinkat.lo utimens.lo:; + $makefile =~ s:\@LTLIBOBJS\@:arc4random.lo arc4random_buf.lo arc4random_uniform.lo cfmakeraw.lo closefrom.lo dup3.lo explicit_bzero.lo fchmodat.lo fchownat.lo freezero.lo fstatat.lo fnmatch.lo getaddrinfo.lo getentropy.lo getgrouplist.lo getdelim.lo getopt_long.lo getusershell.lo glob.lo gmtime_r.lo inet_ntop_lo inet_pton.lo isblank.lo localtime_r.lo memrchr.lo mkdirat.lo mksiglist.lo mksigname.lo mktemp.lo nanosleep.lo openat.lo pipe2.lo pread.lo pwrite.lo pw_dup.lo reallocarray.lo realpath.lo sha2.lo sig2str.lo siglist.lo signame.lo snprintf.lo str2sig.lo strlcat.lo strlcpy.lo strndup.lo strnlen.lo strsignal.lo timegm.lo unlinkat.lo utimens.lo:; # Parse OBJS lines my %objs; |