aboutsummaryrefslogtreecommitdiff
path: root/src/userprivs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/userprivs.c')
-rw-r--r--src/userprivs.c49
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,5 +1,5 @@
/* 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
@@ -38,30 +38,23 @@ 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 ();
@@ -71,9 +64,7 @@ get_user_groups (gl_list_t init_list, const char *user)
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;
}
}
@@ -83,33 +74,33 @@ get_user_groups (gl_list_t init_list, const char *user)
/* 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 */
@@ -209,7 +200,7 @@ 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;
@@ -227,7 +218,7 @@ pies_priv_setup (struct pies_privs *privs)
grplist ? grplist : privs->groups))
exit (EX_SOFTWARE);
if (grplist)
- gl_list_free (grplist);
+ grecs_list_free (grplist);
}

Return to:

Send suggestions and report system problems to the System administrator.