Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 55537 | Differences between
and this patch

Collapse All | Expand All

(-)lib/auth_unix.c (-14 / +37 lines)
Lines 50-55 Link Here
50
#include <grp.h>
50
#include <grp.h>
51
#include <ctype.h>
51
#include <ctype.h>
52
#include <string.h>
52
#include <string.h>
53
#include <stdio.h>
53
54
54
#include "auth.h"
55
#include "auth.h"
55
#include "xmalloc.h"
56
#include "xmalloc.h"
Lines 143-148 Link Here
143
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
144
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
144
};
145
};
145
146
147
static struct group* fgetgrnam(const char* name)
148
{
149
	struct group *grp;
150
	FILE *groupfile;
151
152
	groupfile = fopen("/etc/imapd.group","r");
153
	if (!groupfile) groupfile = fopen("/etc/group", "r");
154
	if (groupfile) {
155
		while ((grp = fgetgrent(groupfile))) {
156
			if (strcmp(grp->gr_name, name) == 0) {
157
				fclose(groupfile);
158
				return grp;
159
			}
160
		}
161
	} 
162
	if (groupfile) fclose(groupfile);
163
	return NULL;
164
} 
146
/*
165
/*
147
 * Convert 'identifier' into canonical form.
166
 * Convert 'identifier' into canonical form.
148
 * Returns a pointer to a static buffer containing the canonical form
167
 * Returns a pointer to a static buffer containing the canonical form
Lines 185-191 Link Here
185
     */
204
     */
186
    
205
    
187
    if (!strncmp(retbuf, "group:", 6)) {
206
    if (!strncmp(retbuf, "group:", 6)) {
188
	grp = getgrnam(retbuf+6);
207
	grp = fgetgrnam(retbuf+6);
189
	if (!grp) return 0;
208
	if (!grp) return 0;
190
	strcpy(retbuf+6, grp->gr_name);
209
	strcpy(retbuf+6, grp->gr_name);
191
	return retbuf;
210
	return retbuf;
Lines 228-233 Link Here
228
    struct passwd *pwd;
247
    struct passwd *pwd;
229
    struct group *grp;
248
    struct group *grp;
230
    char **mem;
249
    char **mem;
250
	FILE *groupfile; 
231
251
232
    identifier = auth_canonifyid(identifier, 0);
252
    identifier = auth_canonifyid(identifier, 0);
233
    if (!identifier) return 0;
253
    if (!identifier) return 0;
Lines 241-260 Link Here
241
    newstate->ngroups = 0;
261
    newstate->ngroups = 0;
242
    newstate->group = (char **) 0;
262
    newstate->group = (char **) 0;
243
263
244
    setgrent();
264
	groupfile = fopen("/etc/imapd.group", "r");
245
    while ((grp = getgrent())) {
265
	if (!groupfile) groupfile = fopen("/etc/group","r");
246
	for (mem = grp->gr_mem; *mem; mem++) {
266
	if (groupfile) {
247
	    if (!strcmp(*mem, identifier)) break;
267
		while ((grp = fgetgrent(groupfile))) {
248
	}
268
			for (mem = grp->gr_mem; *mem; mem++) {
249
269
				if (!strcmp(*mem, identifier)) break;
250
	if (*mem || (pwd && pwd->pw_gid == grp->gr_gid)) {
270
			}
251
	    newstate->ngroups++;
271
252
	    newstate->group = (char **)xrealloc((char *)newstate->group,
272
			if (*mem || (pwd && pwd->pw_gid == grp->gr_gid)) {
273
				newstate->ngroups++;
274
				newstate->group = (char **)xrealloc((char *)newstate->group,
253
						newstate->ngroups * sizeof(char *));
275
						newstate->ngroups * sizeof(char *));
254
	    newstate->group[newstate->ngroups-1] = xstrdup(grp->gr_name);
276
				newstate->group[newstate->ngroups-1] = xstrdup(grp->gr_name);
255
	}
277
			}
256
    }
278
		}
257
    endgrent();
279
		fclose(groupfile);
280
	} 
258
    return newstate;
281
    return newstate;
259
}
282
}
260
283

Return to bug 55537