From 6e50087010fb77b8ad2551534959ea0080ba4307 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 26 Mar 2013 13:27:51 -0400 Subject: [PATCH] Add sudo_set_grlist(), currently unused by the back end. --- plugins/sudoers/pwutil.c | 25 +++++++++++++++++++++++-- plugins/sudoers/pwutil.h | 2 +- plugins/sudoers/pwutil_impl.c | 9 +++++---- plugins/sudoers/sudoers.h | 2 ++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/plugins/sudoers/pwutil.c b/plugins/sudoers/pwutil.c index 6ecb0b430..14f364352 100644 --- a/plugins/sudoers/pwutil.c +++ b/plugins/sudoers/pwutil.c @@ -550,8 +550,8 @@ sudo_get_grlist(struct passwd *pw) /* * Cache group db entry if it exists or a negative response if not. */ - item = sudo_make_grlist_item(pw); - if (item == NULL) { + item = sudo_make_grlist_item(pw, NULL, NULL); + if (item == NULL) { /* Should not happen. */ len = strlen(pw->pw_name) + 1; item = ecalloc(1, sizeof(*item) + len); @@ -568,6 +568,27 @@ done: debug_return_ptr(item->d.grlist); } +void +sudo_set_grlist(struct passwd *pw, char * const *groups, char * const *gids) +{ + struct cache_item key, *item; + struct rbnode *node; + debug_decl(sudo_set_grlist, SUDO_DEBUG_NSS) + + /* + * Cache group db entry if it doesn't already exist + */ + key.k.name = pw->pw_name; + if ((node = rbfind(grlist_cache, &key)) == NULL) { + if ((item = sudo_make_grlist_item(pw, groups, gids)) == NULL) + errorx(1, _("unable to parse groups for %s"), pw->pw_name); + if (rbinsert(grlist_cache, item) != NULL) + errorx(1, _("unable to cache group list for %s, already exists"), + pw->pw_name); + } + debug_return; +} + bool user_in_group(struct passwd *pw, const char *group) { diff --git a/plugins/sudoers/pwutil.h b/plugins/sudoers/pwutil.h index fc61a31af..58d14a062 100644 --- a/plugins/sudoers/pwutil.h +++ b/plugins/sudoers/pwutil.h @@ -60,7 +60,7 @@ struct cache_item_grlist { }; struct cache_item *sudo_make_gritem(gid_t gid, const char *group); -struct cache_item *sudo_make_grlist_item(struct passwd *pw); +struct cache_item *sudo_make_grlist_item(struct passwd *pw, char * const *groups, char * const *gids); struct cache_item *sudo_make_pwitem(uid_t uid, const char *user); #endif /* _SUDOERS_PWUTIL_H */ diff --git a/plugins/sudoers/pwutil_impl.c b/plugins/sudoers/pwutil_impl.c index fb77d931c..0ea3e2959 100644 --- a/plugins/sudoers/pwutil_impl.c +++ b/plugins/sudoers/pwutil_impl.c @@ -88,7 +88,7 @@ sudo_make_pwitem(uid_t uid, const char *name) size_t nsize, psize, csize, gsize, dsize, ssize, total; struct cache_item_pw *pwitem; struct passwd *pw, *newpw; - debug_decl(make_pwitem, SUDO_DEBUG_NSS) + debug_decl(sudo_make_pwitem, SUDO_DEBUG_NSS) /* Look up by name or uid. */ pw = name ? getpwnam(name) : getpwuid(uid); @@ -162,7 +162,7 @@ sudo_make_gritem(gid_t gid, const char *name) size_t nsize, psize, nmem, total, len; struct cache_item_gr *gritem; struct group *gr, *newgr; - debug_decl(make_gritem, SUDO_DEBUG_NSS) + debug_decl(sudo_make_gritem, SUDO_DEBUG_NSS) /* Look up by name or gid. */ gr = name ? getgrnam(name) : getgrgid(gid); @@ -225,7 +225,8 @@ sudo_make_gritem(gid_t gid, const char *name) * elements. Fills in datum from user_gids or from getgrouplist(3). */ struct cache_item * -sudo_make_grlist_item(struct passwd *pw) +sudo_make_grlist_item(struct passwd *pw, char * const *unused1, + char * const *unused2) { char *cp; size_t i, nsize, ngroups, total, len; @@ -234,7 +235,7 @@ sudo_make_grlist_item(struct passwd *pw) GETGROUPS_T *gids; struct group *grp; int ngids, groupname_len; - debug_decl(make_grlist_item, SUDO_DEBUG_NSS) + debug_decl(sudo_make_grlist_item, SUDO_DEBUG_NSS) if (pw == sudo_user.pw && sudo_user.gids != NULL) { gids = user_gids; diff --git a/plugins/sudoers/sudoers.h b/plugins/sudoers/sudoers.h index 8ba79e502..c65ba1823 100644 --- a/plugins/sudoers/sudoers.h +++ b/plugins/sudoers/sudoers.h @@ -311,6 +311,8 @@ void sudo_grlist_addref(struct group_list *); void sudo_grlist_delref(struct group_list *); void sudo_pw_addref(struct passwd *); void sudo_pw_delref(struct passwd *); +void sudo_set_grlist(struct passwd *pw, char * const *groups, + char * const *gids); void sudo_setgrent(void); void sudo_setpwent(void); void sudo_setspent(void); -- 2.40.0