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