Mercurial > masqmail-0.2
comparison src/permissions.c @ 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 |
parents | f671821d8222 |
children | 3cbcc46c7d49 |
comparison
equal
deleted
inserted
replaced
83:085d6cd44462 | 84:ffeff2c33799 |
---|---|
24 /* is there really no function in libc for this? */ | 24 /* is there really no function in libc for this? */ |
25 gboolean | 25 gboolean |
26 is_ingroup(uid_t uid, gid_t gid) | 26 is_ingroup(uid_t uid, gid_t gid) |
27 { | 27 { |
28 struct group *grent = getgrgid(gid); | 28 struct group *grent = getgrgid(gid); |
29 struct passwd *pwent = getpwuid(uid); | |
30 char *entry; | |
31 int i = 0; | |
29 | 32 |
30 if (grent) { | 33 if (!grent) { |
31 struct passwd *pwent = getpwuid(uid); | 34 return FALSE; |
32 if (pwent) { | 35 } |
33 char *entry; | 36 if (!pwent) { |
34 int i = 0; | 37 return FALSE; |
35 while ((entry = grent->gr_mem[i++])) { | 38 } |
36 if (strcmp(pwent->pw_name, entry) == 0) | 39 /* check primary group */ |
37 return TRUE; | 40 if (pwent->pw_gid == gid) { |
38 } | 41 return TRUE; |
39 } | 42 } |
43 /* check secondary groups */ | |
44 while ((entry = grent->gr_mem[i++])) { | |
45 if (strcmp(pwent->pw_name, entry) == 0) | |
46 return TRUE; | |
40 } | 47 } |
41 return FALSE; | 48 return FALSE; |
42 } | 49 } |
43 | 50 |
44 gboolean | 51 gboolean |