Mercurial > masqmail
changeset 84:ffeff2c33799
is_ingroup(): check for the primary group of a user too
also some refactoring
author | meillo@marmaro.de |
---|---|
date | Sat, 19 Jun 2010 18:08:55 +0200 (2010-06-19) |
parents | 085d6cd44462 |
children | 0707a9ae145d |
files | src/permissions.c |
diffstat | 1 files changed, 17 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/permissions.c Sat Jun 19 18:07:31 2010 +0200 +++ b/src/permissions.c Sat Jun 19 18:08:55 2010 +0200 @@ -26,17 +26,24 @@ is_ingroup(uid_t uid, gid_t gid) { struct group *grent = getgrgid(gid); + struct passwd *pwent = getpwuid(uid); + char *entry; + int i = 0; - if (grent) { - struct passwd *pwent = getpwuid(uid); - if (pwent) { - char *entry; - int i = 0; - while ((entry = grent->gr_mem[i++])) { - if (strcmp(pwent->pw_name, entry) == 0) - return TRUE; - } - } + if (!grent) { + return FALSE; + } + if (!pwent) { + return FALSE; + } + /* check primary group */ + if (pwent->pw_gid == gid) { + return TRUE; + } + /* check secondary groups */ + while ((entry = grent->gr_mem[i++])) { + if (strcmp(pwent->pw_name, entry) == 0) + return TRUE; } return FALSE; }