From bf9f3a690ead4aa59f5dbae744503e90793f770f Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 29 May 2017 15:47:03 +0200 Subject: Support specifying custom attribute names for schema --- server.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 15 deletions(-) (limited to 'server.c') diff --git a/server.c b/server.c index 22f6085..ae6a4ae 100644 --- a/server.c +++ b/server.c @@ -63,6 +63,52 @@ void server_setPlainLdap(const char *server, const char *enabledStr) || strcmp(enabledStr, "True") == 0 || strcmp(enabledStr, "TRUE") == 0; } +static void strtolower(char *str) +{ + while (*str != '\0') { + *str = tolower(*str); + ++str; + } +} + +void server_setMap(const char *server, const char *attribute, const char *value) +{ + if (value == NULL || *value == '\0') { + printf("Warning: Ignoring empty mapping option '%s'\n", attribute); + return; + } + server_t *entry = server_create(server); + if (entry == NULL) return; + struct string *s = NULL; + BOOL lower = TRUE; + if (strcmp(attribute, "homemount") == 0) { + s = &entry->map.homemount; + } else if (strcmp(attribute, "localhome") == 0) { + s = &entry->map.localhome; + } else if (strcmp(attribute, "posixAccount") == 0) { + s = &entry->map.posixAccount; + lower = FALSE; + } else if (strcmp(attribute, "shadowAccount") == 0) { + s = &entry->map.shadowAccount; + lower = FALSE; + } else if (strcmp(attribute, "uid") == 0) { + s = &entry->map.uid; + } else if (strcmp(attribute, "uidnumber") == 0) { + s = &entry->map.uidnumber; + } + if (s == NULL) { + printf("Warning: Invalid mapping option: '%s'\n", attribute); + return; + } + free((void*)s->s); + char *tmp = strdup(value); + if (lower) { + strtolower(tmp); + } + s->s = tmp; + s->l = strlen(value); +} + void server_setBind(const char *server, const char *bind) { server_t *entry = server_create(server); @@ -126,16 +172,9 @@ void server_setHomeAttribute(const char *server, const char *homeattribute) { server_t *entry = server_create(server); if (entry == NULL || entry->sslContext != NULL) return; - free((void*)entry->homeAttr.s); - free((void*)entry->homeAttrLower.s); - entry->homeAttr.l = strlen(homeattribute); - entry->homeAttrLower.l = entry->homeAttr.l; - entry->homeAttr.s = strdup(homeattribute); - char *tmp = strdup(homeattribute); - for (size_t i = 0; i < entry->homeAttrLower.l; ++i) { - tmp[i] = tolower(tmp[i]); - } - entry->homeAttrLower.s = tmp; + free((void*)entry->map.homemount.s); + entry->map.homemount.s = strdup(homeattribute); + entry->map.homemount.l = strlen(homeattribute); } void server_setFingerprint(const char *server, const char *fingerprint) @@ -183,12 +222,24 @@ BOOL server_initServers() int i; printf("%d servers configured.\n", serverCount); for (i = 0; i < serverCount; ++i) { - if (servers[i].cabundle[0] != '\0' || memcmp(servers[i].fingerprint, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 20) != 0) { - servers[i].sslContext = ssl_newClientCtx(servers[i].cabundle); + server_t *server = &servers[i]; + if (server->cabundle[0] != '\0' || memcmp(server->fingerprint, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 20) != 0) { + // Have cabundle or fingerprint - use SSL to talk to server + server->sslContext = ssl_newClientCtx(server->cabundle); + } + printf("%s:\n Bind: %s\n Base: %s\n", server->addr, server->bind, server->base); + printf("Plain LDAP-LDAP: %d\n", (int)server->plainLdap); + // Fixup & print attribute map + proxy_initDefaultMap(server); + printf("uid: '%.*s'\n", (int)server->map.uid.l, server->map.uid.s); + printf("uidnumber: '%.*s'\n", (int)server->map.uidnumber.l, server->map.uidnumber.s); + printf("homemount: '%.*s'\n", (int)server->map.homemount.l, server->map.homemount.s); + if (server->plainLdap) { + printf("localhome: '%.*s'\n", (int)server->map.localhome.l, server->map.localhome.s); } - printf("%s:\n Bind: %s\n Base: %s\n", servers[i].addr, servers[i].bind, servers[i].base); - printf("Plain LDAP-LDAP: %d\n", (int)servers[i].plainLdap); - if (!server_ensureConnected(&servers[i])) + printf("objectClass posixAccount: '%.*s'\n", (int)server->map.posixAccount.l, server->map.posixAccount.s); + printf("objectClass shadowAccount: '%.*s'\n", (int)server->map.shadowAccount.l, server->map.shadowAccount.s); + if (!server_ensureConnected(server)) return FALSE; } connectionInitDone = TRUE; -- cgit v1.2.3-55-g7522