diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-10-22 23:03:24 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-10-23 00:42:30 +0300 |
commit | 21ffba77b92f79a59c62728ede4ad7a4ecb5a0ee (patch) | |
tree | c3204285a3ba57d590d815c682f1113b6f48d834 /src/userprivs.c | |
parent | eb8797c9a28f3f4e238bad89b56d331492df7828 (diff) | |
download | pies-21ffba77b92f79a59c62728ede4ad7a4ecb5a0ee.tar.gz pies-21ffba77b92f79a59c62728ede4ad7a4ecb5a0ee.tar.bz2 |
Switch to the latest Grecs.
* Makefile.am (ChangeLog): Use git2chg.awk to build it.
* NEWS: Update.
* bootstrap.conf (gnulib_modules): Grecs does not depend on gnulib any more.
* configure.ac: Version 1.2.90.
Define GRECS_HOST_PROJECT_INCLUDES, remove grecs Makefiles from
AC_CONFIG_FILES: it is now done by GRECS_SETUP itself.
* gnulib.modules (gitlog-to-changelog,argp): Remove.
(configmake): New module.
* grecs: Update to a52ab6c6.
* lib/libpies.h: Remove redefinitions of _() and N_().
* src/Makefile.am: Update for the recent grecs.
* src/acl.c: Rewrite using Grecs support for lists and symtabs.
* src/acl.h: Likewise.
* src/diag.c: Likewise.
* src/inetd.c: Likewise.
* src/meta1gram.y: Likewise.
* src/meta1lex.h: Likewise.
* src/meta1lex.l: Likewise.
* src/pies.c: Likewise.
* src/pies.h: Likewise.
* src/progman.c: Likewise.
* src/userprivs.c: Likewise.
Diffstat (limited to 'src/userprivs.c')
-rw-r--r-- | src/userprivs.c | 49 |
1 files changed, 20 insertions, 29 deletions
diff --git a/src/userprivs.c b/src/userprivs.c index b224a00..3270905 100644 --- a/src/userprivs.c +++ b/src/userprivs.c @@ -1,8 +1,8 @@ /* This file is part of GNU Pies. - Copyright (C) 2007, 2008, 2009, 2010 Sergey Poznyakoff + Copyright (C) 2007, 2008, 2009, 2010, 2011 Sergey Poznyakoff GNU Pies is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. @@ -35,84 +35,75 @@ str_eq (const void *elt1, const void *elt2) void str_dispose (const void *elt) { free ((void*)elt); } -gl_list_t -get_user_groups (gl_list_t init_list, const char *user) +struct grecs_list * +get_user_groups (struct grecs_list *init_list, const char *user) { int rc; struct group *gr; - gl_list_t list; + struct grecs_list *list; - list = gl_list_create_empty(&gl_linked_list_implementation, - str_eq, - NULL, - str_dispose, - false); + list = grecs_list_create(); if (init_list) { - const void *p; - gl_list_iterator_t itr = gl_list_iterator (init_list); - while (gl_list_iterator_next (&itr, &p, NULL)) + struct grecs_list_entry *ep; + + for (ep = init_list->head; ep; ep = ep->next) { - char *s = xstrdup (p); - if (!gl_list_add_last (list, s)) - free (s); + grecs_list_append (list, xstrdup ((char*)ep->data)); } - gl_list_iterator_free (&itr); } setgrent (); for (rc = 0; rc == 0 && (gr = getgrent ());) { char **p; for (p = gr->gr_mem; *p; p++) if (strcmp (*p, user) == 0) { - char *s = xstrdup (gr->gr_name); - if (!gl_list_add_last (list, s)) - free (s); + grecs_list_append (list, xstrdup (gr->gr_name)); break; } } endgrent (); return list; } /* Switch to the given UID/GID */ int -switch_to_privs (uid_t uid, gid_t gid, gl_list_t retain_groups) +switch_to_privs (uid_t uid, gid_t gid, struct grecs_list *retain_groups) { int rc = 0; gid_t *emptygidset; size_t size = 1, j = 1; /* Create a list of supplementary groups */ - size = 1 + (retain_groups ? gl_list_size (retain_groups) : 0); + size = 1 + (retain_groups ? grecs_list_size (retain_groups) : 0); emptygidset = xcalloc (size, sizeof emptygidset[0]); emptygidset[0] = gid ? gid : getegid (); if (retain_groups) { - const void *p; - gl_list_iterator_t itr = gl_list_iterator (retain_groups); - while (gl_list_iterator_next (&itr, &p, NULL)) + struct grecs_list_entry *ep; + + for (ep = retain_groups->head; ep; ep = ep->next) { - struct group *group = getgrnam ((const char*)p); + const char *grname = ep->data; + struct group *group = getgrnam (grname); if (!group) { - logmsg (LOG_ERR, _("unknown group: %s"), (const char*)p); + logmsg (LOG_ERR, _("unknown group: %s"), grname); free (emptygidset); return 1; } emptygidset[j++] = group->gr_gid; } - gl_list_iterator_free (&itr); } /* Reset group permissions */ if (geteuid () == 0 && setgroups (j, emptygidset)) { logmsg (LOG_ERR, _("setgroups(1, %lu) failed: %s"), @@ -206,13 +197,13 @@ switch_to_privs (uid_t uid, gid_t gid, gl_list_t retain_groups) void pies_priv_setup (struct pies_privs *privs) { struct passwd *pw; - gl_list_t grplist = 0; + struct grecs_list *grplist = 0; if (!privs || !privs->user) return; pw = getpwnam (privs->user); if (!pw) @@ -224,13 +215,13 @@ pies_priv_setup (struct pies_privs *privs) if (privs->allgroups) grplist = get_user_groups (privs->groups, privs->user); if (switch_to_privs (pw->pw_uid, pw->pw_gid, grplist ? grplist : privs->groups)) exit (EX_SOFTWARE); if (grplist) - gl_list_free (grplist); + grecs_list_free (grplist); } void pies_epriv_setup (struct pies_privs *privs) { |