masqmail-0.2

diff 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
line diff
     1.1 --- a/src/permissions.c	Sat Jun 19 18:07:31 2010 +0200
     1.2 +++ b/src/permissions.c	Sat Jun 19 18:08:55 2010 +0200
     1.3 @@ -26,17 +26,24 @@
     1.4  is_ingroup(uid_t uid, gid_t gid)
     1.5  {
     1.6  	struct group *grent = getgrgid(gid);
     1.7 +	struct passwd *pwent = getpwuid(uid);
     1.8 +	char *entry;
     1.9 +	int i = 0;
    1.10  
    1.11 -	if (grent) {
    1.12 -		struct passwd *pwent = getpwuid(uid);
    1.13 -		if (pwent) {
    1.14 -			char *entry;
    1.15 -			int i = 0;
    1.16 -			while ((entry = grent->gr_mem[i++])) {
    1.17 -				if (strcmp(pwent->pw_name, entry) == 0)
    1.18 -					return TRUE;
    1.19 -			}
    1.20 -		}
    1.21 +	if (!grent) {
    1.22 +		return FALSE;
    1.23 +	}
    1.24 +	if (!pwent) {
    1.25 +		return FALSE;
    1.26 +	}
    1.27 +	/* check primary group */
    1.28 +	if (pwent->pw_gid == gid) {
    1.29 +		return TRUE;
    1.30 +	}
    1.31 +	/* check secondary groups */
    1.32 +	while ((entry = grent->gr_mem[i++])) {
    1.33 +		if (strcmp(pwent->pw_name, entry) == 0)
    1.34 +			return TRUE;
    1.35  	}
    1.36  	return FALSE;
    1.37  }