Sudo never iterates over the passwd or group file.
Rename sudo_set{pw,gr}ent() -> sudo_mk{pw,gr}cache() and
use sudo_free{pw,gr}cache() instead of sudo_end{pw,gr}ent().
/*
- * Copyright (c) 2009-2015 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2009-2016 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
bindtextdomain("sudoers", LOCALEDIR);
- if (sudo_setpwent() == -1 || sudo_setgrent() == -1) {
+ if (sudo_mkpwcache() == -1 || sudo_mkgrcache() == -1) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_int(-1);
}
free(tofree);
if (details.runas_pw)
sudo_pw_delref(details.runas_pw);
- sudo_endpwent();
if (details.runas_gr)
sudo_gr_delref(details.runas_gr);
- sudo_endgrent();
+ sudo_freepwcache();
+ sudo_freegrcache();
debug_return_int(rval);
}
sudoers_setlocale(SUDOERS_LOCALE_SUDOERS, NULL);
- /* Close password, group and other fds so we don't leak. */
- sudo_endpwent();
- sudo_endgrent();
+ /* Close fds so we don't leak anything. */
closefrom(STDERR_FILENO + 1);
if (pipe(pfd) == -1) {
}
int
-sudo_setpwent(void)
+sudo_mkpwcache(void)
{
- debug_decl(sudo_setpwent, SUDOERS_DEBUG_NSS)
+ debug_decl(sudo_mkpwcache, SUDOERS_DEBUG_NSS)
if (pwcache_byuid == NULL)
pwcache_byuid = rbcreate(cmp_pwuid);
if (pwcache_byuid == NULL || pwcache_byname == NULL)
debug_return_int(-1);
- setpwent();
-
debug_return_int(0);
}
debug_return;
}
-void
-sudo_endpwent(void)
-{
- debug_decl(sudo_endpwent, SUDOERS_DEBUG_NSS)
-
- endpwent();
- sudo_freepwcache();
-
- debug_return;
-}
-
/*
* Compare by gid.
*/
}
int
-sudo_setgrent(void)
+sudo_mkgrcache(void)
{
- debug_decl(sudo_setgrent, SUDOERS_DEBUG_NSS)
+ debug_decl(sudo_mkgrcache, SUDOERS_DEBUG_NSS)
if (grcache_bygid == NULL)
grcache_bygid = rbcreate(cmp_grgid);
if (grcache_bygid == NULL || grcache_byname == NULL || grlist_cache == NULL)
debug_return_int(-1);
- setgrent();
-
debug_return_int(0);
}
debug_return;
}
-void
-sudo_endgrent(void)
-{
- debug_decl(sudo_endgrent, SUDOERS_DEBUG_NSS)
-
- endgrent();
- sudo_freegrcache();
-
- debug_return;
-}
-
struct group_list *
sudo_get_grlist(const struct passwd *pw)
{
bindtextdomain("sudoers", LOCALEDIR);
- if (sudo_setpwent() == -1 || sudo_setgrent() == -1) {
+ if (sudo_mkpwcache() == -1 || sudo_mkgrcache() == -1) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_int(-1);
}
restore_nproc();
- /* Close the password and group files and free up memory. */
- sudo_endpwent();
- sudo_endgrent();
+ /* Destroy the password and group caches and free the contents. */
+ sudo_freepwcache();
+ sudo_freegrcache();
sudo_warn_set_locale_func(NULL);
}
if (def_group_plugin)
group_plugin_unload();
- sudo_endpwent();
- sudo_endgrent();
+ sudo_freepwcache();
+ sudo_freegrcache();
debug_return;
}
struct passwd *sudo_mkpwent(const char *user, uid_t uid, gid_t gid, const char *home, const char *shell);
struct passwd *sudo_getpwnam(const char *);
struct passwd *sudo_getpwuid(uid_t);
-void sudo_endgrent(void);
-void sudo_endpwent(void);
void sudo_endspent(void);
+void sudo_freegrcache(void);
+void sudo_freepwcache(void);
void sudo_grlist_addref(struct group_list *);
void sudo_grlist_delref(struct group_list *);
+int sudo_mkgrcache(void);
+int sudo_mkpwcache(void);
void sudo_pw_addref(struct passwd *);
void sudo_pw_delref(struct passwd *);
int sudo_set_grlist(struct passwd *pw, char * const *groups, char * const *gids);
-int sudo_setgrent(void);
-int sudo_setpwent(void);
void sudo_setspent(void);
/* timestr.c */
/*
- * Copyright (c) 1996, 1998-2005, 2007-2015
+ * Copyright (c) 1996, 1998-2005, 2007-2016
* Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
setgrfile(grfile);
if (pwfile)
setpwfile(pwfile);
- if (sudo_setpwent() == -1 || sudo_setgrent() == -1)
+ if (sudo_mkpwcache() == -1 || sudo_mkgrcache() == -1)
sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
if (argc < 2) {
*/
exitcode = parse_error ? 1 : (match == ALLOW ? 0 : match + 3);
done:
- sudo_endpwent();
- sudo_endgrent();
+ sudo_freepwcache();
+ sudo_freegrcache();
sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys, exitcode);
exit(exitcode);
}
/*
- * Copyright (c) 1996, 1998-2005, 2007-2015
+ * Copyright (c) 1996, 1998-2005, 2007-2016
* Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
if (argc - optind != 0)
usage(1);
- if (sudo_setpwent() == -1 || sudo_setgrent() == -1)
+ if (sudo_mkpwcache() == -1 || sudo_mkgrcache() == -1)
sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
/* Mock up a fake sudo_user struct. */
sudo_fatal(U_("unable to execute %s"), path);
break; /* NOTREACHED */
case 0:
- sudo_endpwent();
- sudo_endgrent();
+ sudo_freepwcache();
+ sudo_freegrcache();
closefrom(STDERR_FILENO + 1);
execv(path, argv);
sudo_warn(U_("unable to run %s"), path);
if (sp->tpath != NULL)
(void) unlink(sp->tpath);
}
- sudo_endpwent();
- sudo_endgrent();
+ sudo_freepwcache();
+ sudo_freegrcache();
}
/*