mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-22 09:57:41 +00:00
Simplify iolog_set_user and iolog_set_group
This commit is contained in:
parent
56c21243d7
commit
13e3eaad5f
@ -134,9 +134,9 @@ void iolog_rewind(struct iolog_file *iol);
|
||||
void iolog_set_compress(bool);
|
||||
void iolog_set_defaults(void);
|
||||
void iolog_set_flush(bool);
|
||||
void iolog_set_group(const struct group *gr);
|
||||
void iolog_set_gid(gid_t gid);
|
||||
void iolog_set_maxseq(unsigned int maxval);
|
||||
void iolog_set_mode(mode_t mode);
|
||||
void iolog_set_user(const struct passwd *pw);
|
||||
void iolog_set_owner(uid_t uid, uid_t gid);
|
||||
|
||||
#endif /* SUDO_IOLOG_H */
|
||||
|
@ -310,23 +310,16 @@ iolog_set_maxseq(unsigned int newval)
|
||||
}
|
||||
|
||||
/*
|
||||
* Set iolog_uid (and iolog_gid if iolog_group not specified).
|
||||
* Set iolog_uid (and iolog_gid if gid not explicitly set).
|
||||
*/
|
||||
void
|
||||
iolog_set_user(const struct passwd *pw)
|
||||
iolog_set_owner(uid_t uid, gid_t gid)
|
||||
{
|
||||
debug_decl(iolog_set_user, SUDO_DEBUG_UTIL)
|
||||
debug_decl(iolog_set_owner, SUDO_DEBUG_UTIL)
|
||||
|
||||
if (pw != NULL) {
|
||||
iolog_uid = pw->pw_uid;
|
||||
if (!iolog_gid_set)
|
||||
iolog_gid = pw->pw_gid;
|
||||
} else {
|
||||
/* Reset to default. */
|
||||
iolog_uid = ROOT_UID;
|
||||
if (!iolog_gid_set)
|
||||
iolog_gid = ROOT_GID;
|
||||
}
|
||||
iolog_uid = uid;
|
||||
if (!iolog_gid_set)
|
||||
iolog_gid = gid;
|
||||
|
||||
debug_return;
|
||||
}
|
||||
@ -335,18 +328,12 @@ iolog_set_user(const struct passwd *pw)
|
||||
* Set iolog_gid.
|
||||
*/
|
||||
void
|
||||
iolog_set_group(const struct group *gr)
|
||||
iolog_set_gid(gid_t gid)
|
||||
{
|
||||
debug_decl(iolog_set_group, SUDO_DEBUG_UTIL)
|
||||
debug_decl(iolog_set_gid, SUDO_DEBUG_UTIL)
|
||||
|
||||
if (gr != NULL) {
|
||||
iolog_gid = gr->gr_gid;
|
||||
iolog_gid_set = true;
|
||||
} else {
|
||||
/* Reset to default. */
|
||||
iolog_gid = ROOT_GID;
|
||||
iolog_gid_set = false;
|
||||
}
|
||||
iolog_gid = gid;
|
||||
iolog_gid_set = true;
|
||||
|
||||
debug_return;
|
||||
}
|
||||
|
@ -72,12 +72,13 @@ static struct logsrvd_config {
|
||||
struct logsrvd_config_iolog {
|
||||
bool compress;
|
||||
bool flush;
|
||||
bool gid_set;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
mode_t mode;
|
||||
unsigned int maxseq;
|
||||
char *iolog_dir;
|
||||
char *iolog_file;
|
||||
struct passwd user;
|
||||
struct group group;
|
||||
} iolog;
|
||||
struct logsrvd_config_eventlog {
|
||||
enum logsrvd_eventlog_type log_type;
|
||||
@ -237,8 +238,9 @@ cb_iolog_user(struct logsrvd_config *config, const char *user)
|
||||
"unknown user %s", user);
|
||||
debug_return_bool(false);
|
||||
}
|
||||
config->iolog.user.pw_uid = pw->pw_uid;
|
||||
config->iolog.user.pw_gid = pw->pw_gid;
|
||||
config->iolog.uid = pw->pw_uid;
|
||||
if (!config->iolog.gid_set)
|
||||
config->iolog.gid = pw->pw_gid;
|
||||
|
||||
debug_return_bool(true);
|
||||
}
|
||||
@ -254,7 +256,8 @@ cb_iolog_group(struct logsrvd_config *config, const char *group)
|
||||
"unknown group %s", group);
|
||||
debug_return_bool(false);
|
||||
}
|
||||
config->iolog.group.gr_gid = gr->gr_gid;
|
||||
config->iolog.gid = gr->gr_gid;
|
||||
config->iolog.gid_set = true;
|
||||
|
||||
debug_return_bool(true);
|
||||
}
|
||||
@ -707,9 +710,9 @@ logsrvd_conf_alloc(void)
|
||||
goto bad;
|
||||
if (!cb_iolog_file(config, "%{seq}"))
|
||||
goto bad;
|
||||
config->iolog.user.pw_uid = ROOT_UID;
|
||||
config->iolog.user.pw_gid = ROOT_GID;
|
||||
config->iolog.group.gr_gid = ROOT_GID;
|
||||
config->iolog.uid = ROOT_UID;
|
||||
config->iolog.gid = ROOT_GID;
|
||||
config->iolog.gid_set = false;
|
||||
|
||||
/* Event log defaults */
|
||||
config->eventlog.log_type = EVLOG_SYSLOG;
|
||||
@ -761,8 +764,7 @@ logsrvd_conf_apply(struct logsrvd_config *config)
|
||||
iolog_set_defaults();
|
||||
iolog_set_compress(config->iolog.compress);
|
||||
iolog_set_flush(config->iolog.flush);
|
||||
iolog_set_user(&config->iolog.user);
|
||||
iolog_set_group(&config->iolog.group);
|
||||
iolog_set_owner(config->iolog.uid, config->iolog.gid);
|
||||
iolog_set_mode(config->iolog.mode);
|
||||
iolog_set_maxseq(config->iolog.maxseq);
|
||||
|
||||
|
@ -108,19 +108,20 @@ bool
|
||||
cb_iolog_user(const union sudo_defs_val *sd_un)
|
||||
{
|
||||
const char *name = sd_un->str;
|
||||
struct passwd *pw = NULL;
|
||||
struct passwd *pw;
|
||||
debug_decl(cb_iolog_user, SUDOERS_DEBUG_UTIL)
|
||||
|
||||
/* NULL name means reset to default. */
|
||||
if (name != NULL) {
|
||||
if (name == NULL) {
|
||||
iolog_set_owner(ROOT_UID, ROOT_GID);
|
||||
} else {
|
||||
if ((pw = sudo_getpwnam(name)) == NULL) {
|
||||
log_warningx(SLOG_SEND_MAIL, N_("unknown user: %s"), name);
|
||||
debug_return_bool(false);
|
||||
}
|
||||
}
|
||||
iolog_set_user(pw);
|
||||
if (pw != NULL)
|
||||
iolog_set_owner(pw->pw_uid, pw->pw_gid);
|
||||
sudo_pw_delref(pw);
|
||||
}
|
||||
|
||||
debug_return_bool(true);
|
||||
}
|
||||
@ -132,19 +133,20 @@ bool
|
||||
cb_iolog_group(const union sudo_defs_val *sd_un)
|
||||
{
|
||||
const char *name = sd_un->str;
|
||||
struct group *gr = NULL;
|
||||
struct group *gr;
|
||||
debug_decl(cb_iolog_group, SUDOERS_DEBUG_UTIL)
|
||||
|
||||
/* NULL name means reset to default. */
|
||||
if (name != NULL) {
|
||||
if (name == NULL) {
|
||||
iolog_set_gid(ROOT_GID);
|
||||
} else {
|
||||
if ((gr = sudo_getgrnam(name)) == NULL) {
|
||||
log_warningx(SLOG_SEND_MAIL, N_("unknown group: %s"), name);
|
||||
debug_return_bool(false);
|
||||
}
|
||||
}
|
||||
iolog_set_group(gr);
|
||||
if (gr != NULL)
|
||||
iolog_set_gid(gr->gr_gid);
|
||||
sudo_gr_delref(gr);
|
||||
}
|
||||
|
||||
debug_return_bool(true);
|
||||
}
|
||||
@ -299,7 +301,7 @@ iolog_deserialize_info(struct iolog_details *details, char * const user_info[],
|
||||
sudo_debug_printf(SUDO_DEBUG_WARN, "%s: unknown group %s",
|
||||
__func__, *cur + sizeof("iolog_group=") - 1);
|
||||
} else {
|
||||
iolog_set_group(gr);
|
||||
iolog_set_gid(gr->gr_gid);
|
||||
sudo_gr_delref(gr);
|
||||
}
|
||||
continue;
|
||||
@ -311,7 +313,7 @@ iolog_deserialize_info(struct iolog_details *details, char * const user_info[],
|
||||
sudo_debug_printf(SUDO_DEBUG_WARN, "%s: unknown user %s",
|
||||
__func__, *cur + sizeof("iolog_user=") - 1);
|
||||
} else {
|
||||
iolog_set_user(pw);
|
||||
iolog_set_owner(pw->pw_uid, pw->pw_gid);
|
||||
sudo_pw_delref(pw);
|
||||
}
|
||||
continue;
|
||||
|
@ -367,7 +367,7 @@ main(int argc, char *argv[], char *envp[])
|
||||
sudo_user.pw = pw_dup(tpw);
|
||||
|
||||
/* Set iolog uid/gid to invoking user. */
|
||||
iolog_set_user(sudo_user.pw);
|
||||
iolog_set_owner(sudo_user.pw->pw_uid, sudo_user.pw->pw_gid);
|
||||
|
||||
test_endpoints(&tests, &errors, iolog_dir, envp);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user