Move struct passwd pointer into struct command details.

This commit is contained in:
Todd C. Miller
2012-04-21 13:37:46 -04:00
parent cc07164d92
commit 886ee33603
2 changed files with 17 additions and 17 deletions

View File

@@ -731,6 +731,16 @@ command_info_to_details(char * const info[], struct command_details *details)
if (!ISSET(details->flags, CD_SET_EUID)) if (!ISSET(details->flags, CD_SET_EUID))
details->euid = details->uid; details->euid = details->uid;
#ifdef HAVE_SETAUTHDB
aix_setauthdb(IDtouser(details->euid));
#endif
details->pw = getpwuid(details->euid);
if (details->pw != NULL && (details->pw = pw_dup(details->pw)) == NULL)
errorx(1, _("unable to allocate memory"));
#ifdef HAVE_SETAUTHDB
aix_restoreauthdb();
#endif
#ifdef HAVE_SELINUX #ifdef HAVE_SELINUX
if (details->selinux_role != NULL && is_selinux_enabled() > 0) if (details->selinux_role != NULL && is_selinux_enabled() > 0)
SET(details->flags, CD_RBAC_ENABLED); SET(details->flags, CD_RBAC_ENABLED);
@@ -878,23 +888,13 @@ bool
exec_setup(struct command_details *details, const char *ptyname, int ptyfd) exec_setup(struct command_details *details, const char *ptyname, int ptyfd)
{ {
bool rval = false; bool rval = false;
struct passwd *pw;
debug_decl(exec_setup, SUDO_DEBUG_EXEC) debug_decl(exec_setup, SUDO_DEBUG_EXEC)
#ifdef HAVE_SETAUTHDB
aix_setauthdb(IDtouser(details->euid));
#endif
if ((pw = getpwuid(details->euid)) != NULL && (pw = pw_dup(pw)) == NULL)
errorx(1, _("unable to allocate memory"));
#ifdef HAVE_SETAUTHDB
aix_restoreauthdb();
#endif
/* /*
* Call policy plugin's session init before other setup occurs. * Call policy plugin's session init before other setup occurs.
* The session init code is expected to print an error as needed. * The session init code is expected to print an error as needed.
*/ */
if (policy_init_session(&policy_plugin, pw, &details->envp) != true) if (policy_init_session(&policy_plugin, details->pw, &details->envp) != true)
goto done; goto done;
#ifdef HAVE_SELINUX #ifdef HAVE_SELINUX
@@ -905,12 +905,12 @@ exec_setup(struct command_details *details, const char *ptyname, int ptyfd)
} }
#endif #endif
if (pw != NULL) { if (details->pw != NULL) {
#ifdef HAVE_PROJECT_H #ifdef HAVE_PROJECT_H
set_project(pw); set_project(details->pw);
#endif #endif
#ifdef HAVE_GETUSERATTR #ifdef HAVE_GETUSERATTR
aix_prep_user(pw->pw_name, ptyname ? ptyname : user_details.tty); aix_prep_user(details->pw->pw_name, ptyname ? ptyname : user_details.tty);
#endif #endif
#ifdef HAVE_LOGIN_CAP_H #ifdef HAVE_LOGIN_CAP_H
if (details->login_class) { if (details->login_class) {
@@ -935,8 +935,8 @@ exec_setup(struct command_details *details, const char *ptyname, int ptyfd)
} else { } else {
flags = LOGIN_SETRESOURCES|LOGIN_SETPRIORITY; flags = LOGIN_SETRESOURCES|LOGIN_SETPRIORITY;
} }
if (setusercontext(lc, pw, pw->pw_uid, flags)) { if (setusercontext(lc, details->pw, details->pw->pw_uid, flags)) {
if (pw->pw_uid != ROOT_UID) { if (details->pw->pw_uid != ROOT_UID) {
warning(_("unable to set user context")); warning(_("unable to set user context"));
goto done; goto done;
} else } else
@@ -1037,7 +1037,6 @@ exec_setup(struct command_details *details, const char *ptyname, int ptyfd)
rval = true; rval = true;
done: done:
efree(pw);
debug_return_bool(rval); debug_return_bool(rval);
} }

View File

@@ -138,6 +138,7 @@ struct command_details {
int ngroups; int ngroups;
int closefrom; int closefrom;
int flags; int flags;
struct passwd *pw;
GETGROUPS_T *groups; GETGROUPS_T *groups;
const char *command; const char *command;
const char *cwd; const char *cwd;