Use sudo_basename() instead of doing the equivalent manually.
This commit is contained in:
@@ -361,10 +361,7 @@ exec_mailer(int pipein)
|
||||
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
|
||||
_exit(127);
|
||||
}
|
||||
if ((argv[0] = strrchr(mpath, '/')))
|
||||
argv[0]++;
|
||||
else
|
||||
argv[0] = (char *)mpath;
|
||||
argv[0] = sudo_basename(mpath);
|
||||
|
||||
i = 1;
|
||||
if ((p = strtok_r(mflags, " \t", &last))) {
|
||||
|
@@ -136,7 +136,7 @@ MKTEMP_TEST_OBJS = mktemp_test.lo mktemp.lo
|
||||
|
||||
PARSELN_TEST_OBJS = parseln_test.lo parseln.lo
|
||||
|
||||
PROGNAME_TEST_OBJS = progname_test.lo progname.lo
|
||||
PROGNAME_TEST_OBJS = progname_test.lo progname.lo basename.lo
|
||||
|
||||
CONF_TEST_OBJS = conf_test.lo sudo_conf.lo
|
||||
|
||||
|
@@ -53,8 +53,7 @@ sudo_getprogname(void)
|
||||
void
|
||||
sudo_setprogname(const char *name)
|
||||
{
|
||||
const char *slash = strrchr(name, '/');
|
||||
__progname = slash ? slash + 1 : name;
|
||||
__progname = sudo_basename(name);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -69,9 +68,7 @@ initprogname2(const char *name, const char * const * allowed)
|
||||
name = progname;
|
||||
} else {
|
||||
/* Make sure user-specified name is relative. */
|
||||
const char *slash = strrchr(name, '/');
|
||||
if (slash != NULL)
|
||||
name = slash + 1;
|
||||
name = sudo_basename(name);
|
||||
}
|
||||
|
||||
/* Check for libtool prefix and strip it if present. */
|
||||
|
@@ -37,12 +37,8 @@ main(int argc, char *argv[])
|
||||
{
|
||||
char *progbase = "progname_test";
|
||||
|
||||
if (argc > 0) {
|
||||
if ((progbase = strrchr(argv[0], '/')) != NULL)
|
||||
progbase++;
|
||||
else
|
||||
progbase = argv[0];
|
||||
}
|
||||
if (argc > 0)
|
||||
progbase = sudo_basename(argv[0]);
|
||||
initprogname(progbase);
|
||||
|
||||
/* Make sure getprogname() matches basename of argv[0]. */
|
||||
|
@@ -516,34 +516,26 @@ struct sudo_conf_debug_file_list *
|
||||
sudo_conf_debug_files_v1(const char *progname)
|
||||
{
|
||||
struct sudo_conf_debug *debug_spec;
|
||||
size_t prognamelen, progbaselen;
|
||||
const char *progbase = progname;
|
||||
const char *progbase;
|
||||
debug_decl(sudo_conf_debug_files, SUDO_DEBUG_UTIL);
|
||||
|
||||
/* Determine basename if program is fully qualified (like for plugins). */
|
||||
prognamelen = progbaselen = strlen(progname);
|
||||
if (*progname == '/') {
|
||||
progbase = strrchr(progname, '/');
|
||||
progbaselen = strlen(++progbase);
|
||||
}
|
||||
progbase = progname[0] == '/' ? sudo_basename(progname) : progname;
|
||||
|
||||
/* Convert sudoedit -> sudo. */
|
||||
if (progbaselen > 4 && strcmp(progbase + 4, "edit") == 0) {
|
||||
progbaselen -= 4;
|
||||
}
|
||||
if (strcmp(progbase, "sudoedit") == 0)
|
||||
progbase = "sudo";
|
||||
|
||||
TAILQ_FOREACH(debug_spec, &sudo_conf_data.debugging, entries) {
|
||||
const char *prog = progbase;
|
||||
size_t len = progbaselen;
|
||||
|
||||
if (debug_spec->progname[0] == '/') {
|
||||
/* Match fully-qualified name, if possible. */
|
||||
prog = progname;
|
||||
len = prognamelen;
|
||||
}
|
||||
if (strncmp(debug_spec->progname, prog, len) == 0 &&
|
||||
debug_spec->progname[len] == '\0') {
|
||||
if (strcmp(debug_spec->progname, prog) == 0)
|
||||
debug_return_ptr(&debug_spec->debug_files);
|
||||
}
|
||||
}
|
||||
debug_return_ptr(NULL);
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
@COMPAT_EXP@initprogname
|
||||
initprogname2
|
||||
sudo_basename
|
||||
sudo_basename_v1
|
||||
sudo_conf_askpass_path_v1
|
||||
sudo_conf_clear_paths_v1
|
||||
sudo_conf_debug_files_v1
|
||||
|
@@ -225,9 +225,7 @@ audit_to_eventlog(struct eventlog *evlog, char * const command_info[],
|
||||
case 'i':
|
||||
if (strncmp(*cur, "iolog_path=", sizeof("iolog_path=") - 1) == 0) {
|
||||
evlog->iolog_path = *cur + sizeof("iolog_path=") - 1;
|
||||
evlog->iolog_file = strrchr(evlog->iolog_path, '/');
|
||||
if (evlog->iolog_file != NULL)
|
||||
evlog->iolog_file++;
|
||||
evlog->iolog_file = sudo_basename(evlog->iolog_path);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
@@ -57,18 +57,13 @@ cmnd_allowed(char *cmnd, size_t cmnd_size, const char *runchroot,
|
||||
debug_return_bool(true); /* nothing to check */
|
||||
|
||||
/* We compare the base names to avoid excessive stat()ing. */
|
||||
if ((cmnd_base = strrchr(cmnd, '/')) == NULL)
|
||||
debug_return_bool(false); /* can't happen */
|
||||
cmnd_base++;
|
||||
cmnd_base = sudo_basename(cmnd);
|
||||
|
||||
for (al = allowlist; *al != NULL; al++) {
|
||||
const char *base, *path = *al;
|
||||
struct stat sb;
|
||||
|
||||
if ((base = strrchr(path, '/')) == NULL)
|
||||
continue; /* XXX - warn? */
|
||||
base++;
|
||||
|
||||
base = sudo_basename(path);
|
||||
if (strcmp(cmnd_base, base) != 0)
|
||||
continue;
|
||||
|
||||
|
@@ -352,9 +352,7 @@ iolog_deserialize_info(struct log_details *details, char * const user_info[],
|
||||
evlog->iolog_path = strdup(*cur + sizeof("iolog_path=") - 1);
|
||||
if (evlog->iolog_path == NULL)
|
||||
goto oom;
|
||||
evlog->iolog_file = strrchr(evlog->iolog_path, '/');
|
||||
if (evlog->iolog_file != NULL)
|
||||
evlog->iolog_file++;
|
||||
evlog->iolog_file = sudo_basename(evlog->iolog_path);
|
||||
continue;
|
||||
}
|
||||
if (strncmp(*cur, "iolog_stdin=", sizeof("iolog_stdin=") - 1) == 0) {
|
||||
|
@@ -384,12 +384,10 @@ command_matches_glob(const char *sudoers_cmnd, const char *sudoers_args,
|
||||
*/
|
||||
dlen = strlen(sudoers_cmnd);
|
||||
if (sudoers_cmnd[dlen - 1] != '/') {
|
||||
if ((base = strrchr(sudoers_cmnd, '/')) != NULL) {
|
||||
base++;
|
||||
base = sudo_basename(sudoers_cmnd);
|
||||
if (!has_meta(base) && strcmp(user_base, base) != 0)
|
||||
debug_return_bool(false);
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sudoers_cmnd relative to the new root, if any. */
|
||||
if (runchroot != NULL) {
|
||||
@@ -472,10 +470,7 @@ command_matches_glob(const char *sudoers_cmnd, const char *sudoers_args,
|
||||
}
|
||||
|
||||
/* Only proceed if user_base and basename(cp) match */
|
||||
if ((base = strrchr(cp, '/')) != NULL)
|
||||
base++;
|
||||
else
|
||||
base = cp;
|
||||
base = sudo_basename(cp);
|
||||
if (strcmp(user_base, base) != 0)
|
||||
continue;
|
||||
|
||||
@@ -531,10 +526,7 @@ command_matches_normal(const char *sudoers_cmnd, const char *sudoers_args,
|
||||
}
|
||||
|
||||
/* Only proceed if user_base and basename(sudoers_cmnd) match */
|
||||
if ((base = strrchr(sudoers_cmnd, '/')) == NULL)
|
||||
base = sudoers_cmnd;
|
||||
else
|
||||
base++;
|
||||
base = sudo_basename(sudoers_cmnd);
|
||||
if (strcmp(user_base, base) != 0)
|
||||
debug_return_bool(false);
|
||||
|
||||
|
@@ -928,7 +928,7 @@ set_cmnd(void)
|
||||
debug_return_int(NOT_FOUND_ERROR);
|
||||
}
|
||||
|
||||
/* Default value for cmnd, overridden below. */
|
||||
/* Default value for cmnd, overridden by set_cmnd_path() below. */
|
||||
if (user_cmnd == NULL)
|
||||
user_cmnd = NewArgv[0];
|
||||
|
||||
@@ -966,11 +966,7 @@ set_cmnd(void)
|
||||
debug_return_int(NOT_FOUND_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
if ((user_base = strrchr(user_cmnd, '/')) != NULL)
|
||||
user_base++;
|
||||
else
|
||||
user_base = user_cmnd;
|
||||
user_base = sudo_basename(user_cmnd);
|
||||
|
||||
/* Convert "sudo sudoedit" -> "sudoedit" */
|
||||
if (ISSET(sudo_mode, MODE_RUN) && strcmp(user_base, "sudoedit") == 0) {
|
||||
|
@@ -209,10 +209,7 @@ main(int argc, char *argv[])
|
||||
} else {
|
||||
user_name = *argv++;
|
||||
user_cmnd = *argv++;
|
||||
if ((p = strrchr(user_cmnd, '/')) != NULL)
|
||||
user_base = p + 1;
|
||||
else
|
||||
user_base = user_cmnd;
|
||||
user_base = sudo_basename(user_cmnd);
|
||||
argc -= 2;
|
||||
}
|
||||
if ((sudo_user.pw = sudo_getpwnam(user_name)) == NULL)
|
||||
@@ -447,12 +444,8 @@ open_sudoers(const char *file, bool doedit, bool *keepopen)
|
||||
const char *base;
|
||||
debug_decl(open_sudoers, SUDOERS_DEBUG_UTIL);
|
||||
|
||||
base = strrchr(file, '/');
|
||||
if (base != NULL)
|
||||
base++;
|
||||
else
|
||||
base = file;
|
||||
|
||||
/* Report errors using the basename for consistent test output. */
|
||||
base = sudo_basename(file);
|
||||
switch (sudo_secure_file(file, sudoers_uid, sudoers_gid, &sb)) {
|
||||
case SUDO_PATH_SECURE:
|
||||
fp = fopen(file, "r");
|
||||
|
@@ -381,15 +381,11 @@ static char *lineno_editors[] = {
|
||||
static bool
|
||||
editor_supports_plus(const char *editor)
|
||||
{
|
||||
const char *editor_base = strrchr(editor, '/');
|
||||
const char *cp;
|
||||
const char *cp, *editor_base;
|
||||
char **av;
|
||||
debug_decl(editor_supports_plus, SUDOERS_DEBUG_UTIL);
|
||||
|
||||
if (editor_base != NULL)
|
||||
editor_base++;
|
||||
else
|
||||
editor_base = editor;
|
||||
editor_base = sudo_basename(editor);
|
||||
if (*editor_base == 'r')
|
||||
editor_base++;
|
||||
|
||||
@@ -760,10 +756,7 @@ install_sudoers(struct sudoersfile *sp, bool oldperms)
|
||||
sp->tpath, sp->path);
|
||||
|
||||
/* Build up argument vector for the command */
|
||||
if ((av[0] = strrchr(_PATH_MV, '/')) != NULL)
|
||||
av[0]++;
|
||||
else
|
||||
av[0] = _PATH_MV;
|
||||
av[0] = sudo_basename(_PATH_MV);
|
||||
av[1] = sp->tpath;
|
||||
av[2] = sp->path;
|
||||
av[3] = NULL;
|
||||
|
@@ -132,20 +132,17 @@ set_tmpdir(struct sudo_cred *user_cred)
|
||||
static int
|
||||
sudo_edit_mktemp(const char *ofile, char **tfile)
|
||||
{
|
||||
const char *cp, *suff;
|
||||
const char *base, *suff;
|
||||
int len, tfd;
|
||||
debug_decl(sudo_edit_mktemp, SUDO_DEBUG_EDIT);
|
||||
|
||||
if ((cp = strrchr(ofile, '/')) != NULL)
|
||||
cp++;
|
||||
else
|
||||
cp = ofile;
|
||||
suff = strrchr(cp, '.');
|
||||
base = sudo_basename(ofile);
|
||||
suff = strrchr(base, '.');
|
||||
if (suff != NULL) {
|
||||
len = asprintf(tfile, "%s/%.*sXXXXXXXX%s", edit_tmpdir,
|
||||
(int)(size_t)(suff - cp), cp, suff);
|
||||
(int)(size_t)(suff - base), base, suff);
|
||||
} else {
|
||||
len = asprintf(tfile, "%s/%s.XXXXXXXX", edit_tmpdir, cp);
|
||||
len = asprintf(tfile, "%s/%s.XXXXXXXX", edit_tmpdir, base);
|
||||
}
|
||||
if (len == -1) {
|
||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
|
@@ -188,17 +188,10 @@ FN_NAME(wordexp)(const char *words, wordexp_t *we, int flags)
|
||||
void *fn = NULL;
|
||||
int idx = 0;
|
||||
|
||||
name = strrchr(myname, '/');
|
||||
if (name != NULL)
|
||||
myname = name + 1;
|
||||
|
||||
/* Search for wordexp() but skip this shared object. */
|
||||
myname = sudo_basename(myname);
|
||||
while (shl_get(idx++, &desc) == 0) {
|
||||
name = strrchr(desc->filename, '/');
|
||||
if (name == NULL)
|
||||
name = desc->filename;
|
||||
else
|
||||
name++;
|
||||
name = sudo_basename(desc->filename);
|
||||
if (strcmp(name, myname) == 0)
|
||||
continue;
|
||||
if (shl_findsym(&desc->handle, "wordexp", TYPE_PROCEDURE, &fn) == 0)
|
||||
|
Reference in New Issue
Block a user