diff options
author | Simon Rettberg | 2014-03-19 15:58:53 +0100 |
---|---|---|
committer | Simon Rettberg | 2014-03-19 15:58:53 +0100 |
commit | 43f4c737ad2e27a0d0e05a43a8b955b19d9bd46d (patch) | |
tree | b8b1b2fe63a5bef08da4917749b120ad74877e47 | |
parent | Fixed compilation warnings about pointer mismatch on 32bit (diff) | |
download | ldadp-43f4c737ad2e27a0d0e05a43a8b955b19d9bd46d.tar.gz ldadp-43f4c737ad2e27a0d0e05a43a8b955b19d9bd46d.tar.xz ldadp-43f4c737ad2e27a0d0e05a43a8b955b19d9bd46d.zip |
Make code more good and less bad
-rw-r--r-- | proxy.c | 31 |
1 files changed, 16 insertions, 15 deletions
@@ -342,19 +342,18 @@ static void request_replaceAttribute(server_t *server, struct string *attribute, static void response_replacePal(server_t *server, struct PartialAttributeList **pal, attr_t *attr); static void response_replaceAdl(server_t *server, struct string *type, struct AttributeDescriptionList **adl, attr_t *attr); static void response_replaceAttribute(server_t *server, struct string *attribute, struct string *value); -static struct PartialAttributeList* response_filterHomeDir(struct PartialAttributeList *pal); +static BOOL response_filterHomeDir(struct PartialAttributeList *pal); static struct PartialAttributeList* response_addPal(struct PartialAttributeList *pal, struct string *attribute, const char *format, ...); -#define ADDATTR(x,...) do { if (attr->x) last = response_addPal(last, &s_ ## x, __VA_ARGS__); } while (0) -#define elifDELATTR(x) else if (equals(&(*pal)->type, &s_ ## x)) next = (*pal)->next +#define ADDATTR(x,...) do { if (attr->x) *pal = response_addPal(*pal, &s_ ## x, __VA_ARGS__); } while (0) +#define elifDELATTR(x) else if (equals(&(*pal)->type, &s_ ## x)) next = (*pal)->next, del = TRUE static void response_replacePal(server_t *server, struct PartialAttributeList **pal, attr_t *attr) { struct string *username = NULL; - struct PartialAttributeList *last = NULL; struct AttributeDescriptionList *lastObjectClass = NULL; + struct PartialAttributeList *next = NULL; while (*pal != NULL) { - last = *pal; - struct PartialAttributeList *next = NULL; + BOOL del = FALSE; if (0) { } // Remove fields we don't want from AD elifDELATTR(gidNumber); elifDELATTR(gecos); @@ -364,11 +363,14 @@ static void response_replacePal(server_t *server, struct PartialAttributeList ** else if (equals(&(*pal)->type, &s_homeDirectory)) { // homeDirectory is set in AD - it can either be a local path (in which case it's useless) // or a UNC path, which we can easily mount via mount.cifs - next = response_filterHomeDir(*pal); - if (next == NULL) attr->homeMount = FALSE; + if (response_filterHomeDir(*pal)) { + del = TRUE; + attr->homeMount = FALSE; + next = (*pal)->next; + } } // Entry should be removed, free structs - if (next != NULL) { + if (del) { free_ldapadl((*pal)->values); free(*pal); *pal = next; @@ -393,7 +395,7 @@ static void response_replacePal(server_t *server, struct PartialAttributeList ** char *user = tmpbuffer_get(); snprintf(user, TMPLEN, "%.*s", (int)username->l, username->s); ADDATTR(homeDirectory, "/home/%s", user); - ADDATTR(gecos, "%.*s,,,", user); + ADDATTR(gecos, "%s,,,", user); if (attr->homeMount && server->homeTemplate[0] != '\0') { ADDATTR(homeMount, server->homeTemplate, user, user, user, user, user, user); } @@ -446,7 +448,7 @@ static void response_replaceAttribute(server_t *server, struct string *attribute } } -static struct PartialAttributeList* response_filterHomeDir(struct PartialAttributeList *pal) +static BOOL response_filterHomeDir(struct PartialAttributeList *pal) { for (struct AttributeDescriptionList *adl = pal->values; adl != NULL; adl = pal->values /* sic */) { if (adl->a.l > 2 && adl->a.s[0] == '\\' && adl->a.s[1] == '\\') { @@ -454,12 +456,12 @@ static struct PartialAttributeList* response_filterHomeDir(struct PartialAttribu free_ldapadl(adl->next); adl->next = NULL; pal->type = s_homeMount; - return NULL; + return FALSE; } pal->values = adl->next; free(adl); } - return pal->next; + return TRUE; } static struct PartialAttributeList* response_addPal(struct PartialAttributeList *pal, struct string *attribute, const char *format, ...) @@ -467,8 +469,7 @@ static struct PartialAttributeList* response_addPal(struct PartialAttributeList struct PartialAttributeList *next = malloc(sizeof(struct PartialAttributeList)); va_list args; va_start(args, format); - pal->next = next; - next->next = NULL; + next->next = pal; next->type = *attribute; next->values = malloc(sizeof(struct AttributeDescriptionList)); tmpbuffer_formatva(&next->values->a, format, args); |