struct group *gr;
ngroups = getgroups(0, NULL);
+
+ if (ngroups == -1) {
+ fprintf(stderr, "Failed to get number of groups user belongs to\n");
+ return NULL;
+ }
+
group_ids = (gid_t *)malloc(sizeof(gid_t)*ngroups);
ret = getgroups(ngroups, group_ids);
free(group_names[j]);
}
free(group_names);
- return NULL;
+ return NULL;
}
}
struct alloted_s *next;
};
-static struct alloted_s *append_alloted(struct alloted_s **head, char *name, int n)
+static struct alloted_s *append_alloted(struct alloted_s **head, char *name, int n)
{
struct alloted_s *cur, *al;
if (head == NULL || name == NULL) {
- // sanity check. parameters should not be null
+ // sanity check. parameters should not be null
return NULL;
}
if (strcmp(link, br) != 0)
continue;
+ /* found the user with the appropriate settings, therefore finish the search.
+ * what to do if there are more than one applicable lines? not specified in the docs.
+ * since getline is implemented with realloc, we don't need to free line until exiting func.
+ */
append_alloted(alloted, me, n);
count += n;
- break; // found the user with the appropriate settings, therefore finish the search.
- // what to do if there are more than one applicable lines? not specified in the docs.
- // since getline is implemented with realloc, we don't need to free line until exiting func.
+ break;
}
- // now parse any possible groups specified
+ // now parse any possible groups specified
groups = get_groupnames();
if (groups != NULL) {
static char *find_line(char *p, char *e, char *u, char *t, char *l)
{
char *p1, *p2, *ret;
-
+
while (p<e && (p1 = get_eol(p, e)) < e) {
ret = p;
if (*p == '#')
owner = NULL;
for (n=names; n!=NULL; n=n->next) {
count = count_entries(buf, len, n->name, intype, br);
-
+
if (count >= n->allowed)
continue;