/** Size of lines read from the dictionary file */
#define DICT_BUFFER_SIZE 8196
+static void
+free_dict(struct ip_user_dict *head) {
+ while (head) {
+ struct ip_user_dict *next = head->next_entry;
+ safe_free(head->username);
+ xfree(head);
+ head = next;
+ }
+}
+
/** This function parses the dictionary file and loads it
* in memory. All IP addresses are processed with a bitwise AND
* with their netmasks before they are stored.
bitwise AND */
/* the pointer to the first entry in the linked list */
- first_entry = static_cast<struct ip_user_dict*>(xmalloc(sizeof(struct ip_user_dict)));
+ first_entry = static_cast<struct ip_user_dict*>(xcalloc(1, sizeof(struct ip_user_dict)));
current_entry = first_entry;
unsigned int lineCount = 0;
/* get space and point current_entry to the new entry */
current_entry->next_entry =
- static_cast<struct ip_user_dict*>(xmalloc(sizeof(struct ip_user_dict)));
+ static_cast<struct ip_user_dict*>(xcalloc(1, sizeof(struct ip_user_dict)));
current_entry = current_entry->next_entry;
}
/* Move the pointer to the first entry of the linked list. */
struct ip_user_dict *current_entry = first_entry;
- while (current_entry->username != nullptr) {
+ while (current_entry && current_entry->username) {
debug("user: %s\naddr: %lu\nmask: %lu\n\n",
current_entry->username, current_entry->address,
current_entry->netmask);
so we rip it off by incrementing
* the pointer by one */
- if ((g = getgrnam(dict_group)) == nullptr) {
- debug("Group does not exist '%s'\n", dict_group);
+ g = getgrnam(dict_group);
+ if (!g || !g->gr_mem) {
+ debug("Group does not exist or has no members '%s'\n", dict_group);
return 0;
- } else {
- while (*(g->gr_mem) != nullptr) {
- if (strcmp(*((g->gr_mem)++), username) == 0) {
- return 1;
- }
- }
}
- return 0;
+ for (char * const *m = g->gr_mem; *m; ++m) {
+ if (strcmp(*m, username) == 0)
+ return 1;
+ }
+ return 0;
}
static void
}
fclose (FH);
+ free_dict(current_entry);
return EXIT_SUCCESS;
}