diff options
Diffstat (limited to 'usr.sbin/ypldap/ldapclient.c')
-rw-r--r-- | usr.sbin/ypldap/ldapclient.c | 576 |
1 files changed, 286 insertions, 290 deletions
diff --git a/usr.sbin/ypldap/ldapclient.c b/usr.sbin/ypldap/ldapclient.c index c707523b191..98e74becc1c 100644 --- a/usr.sbin/ypldap/ldapclient.c +++ b/usr.sbin/ypldap/ldapclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldapclient.c,v 1.8 2008/10/21 11:33:36 aschrijver Exp $ */ +/* $OpenBSD: ldapclient.c,v 1.9 2008/10/28 13:47:22 aschrijver Exp $ */ /* * Copyright (c) 2008 Alexander Schrijver <aschrijver@openbsd.org> @@ -41,26 +41,20 @@ #include "ypldap.h" void client_sig_handler(int, short, void *); +void client_dispatch_dns(int, short, void *); void client_dispatch_parent(int, short, void *); void client_shutdown(void); void client_connect(int, short, void *); void client_configure(struct env *); -void client_configure_wrapper(int, short, void *); +void client_periodic_update(int, short, void *); int client_try_idm(struct env *, struct idm *); void client_try_idm_wrapper(int, short, void *); void client_try_server_wrapper(int, short, void *); +int client_addr_init(struct idm *); +int client_addr_free(struct idm *); -int do_build_group(struct env *, struct idm *, struct aldap *, char *, enum - scope, char *); -int do_build_passwd(struct env *, struct idm *, struct aldap *, char *, enum - scope, char *); - -struct aldap *aldap_openidm(struct idm *idm); +struct aldap *aldap_open(struct ypldap_addr *); int aldap_close(struct aldap *); -#ifdef REFERRALS -struct aldap *connect_to_referral(struct aldap_message *, struct aldap_url *); -struct aldap *aldap_openhost(char *, char *); -#endif int aldap_close(struct aldap *al) @@ -74,31 +68,28 @@ aldap_close(struct aldap *al) } struct aldap * -aldap_openidm(struct idm *idm) +aldap_open(struct ypldap_addr *addr) { - int fd; - struct addrinfo *res0; + int fd = -1; + struct ypldap_addr *p; - res0 = idm->idm_addrinfo; - do { - char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; + for(p = addr; p != NULL; p = p->next) { + char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; + struct sockaddr *sa = (struct sockaddr *)&p->ss; - if (getnameinfo(res0->ai_addr, res0->ai_addrlen, hbuf, sizeof(hbuf), sbuf, + if (getnameinfo(sa, SA_LEN(sa), hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) errx(1, "could not get numeric hostname"); - if ((fd = socket(res0->ai_family, res0->ai_socktype, - res0->ai_protocol)) < 0) - continue; + if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) + return NULL; - if (connect(fd, res0->ai_addr, res0->ai_addrlen) == 0) + if (connect(fd, sa, SA_LEN(sa)) == 0) break; - else - warn("connect to %s port %s (%s) failed", hbuf, sbuf, "tcp"); + warn("connect to %s port %s (%s) failed", hbuf, sbuf, "tcp"); close(fd); - fd = -1; - } while ((res0 = res0->ai_next) != NULL); + } if(fd == -1) return NULL; @@ -106,6 +97,51 @@ aldap_openidm(struct idm *idm) return aldap_init(fd); } +int +client_addr_init(struct idm *idm) +{ + struct sockaddr_in *sa_in; + struct sockaddr_in6 *sa_in6; + struct ypldap_addr *h; + + for (h = idm->idm_addr; h != NULL; h = h->next) { + switch (h->ss.ss_family) { + case AF_INET: + sa_in = (struct sockaddr_in *)&h->ss; + if (ntohs(sa_in->sin_port) == 0) + sa_in->sin_port = htons(389); + idm->idm_state = STATE_DNS_DONE; + break; + case AF_INET6: + sa_in6 = (struct sockaddr_in6 *)&h->ss; + if (ntohs(sa_in6->sin6_port) == 0) + sa_in6->sin6_port = htons(389); + idm->idm_state = STATE_DNS_DONE; + break; + default: + fatalx("king bula sez: wrong AF in client_addr_init"); + /* not reached */ + } + } + + return (0); +} + +int +client_addr_free(struct idm *idm) +{ + struct ypldap_addr *h; + + if(idm->idm_addr == NULL) + return (-1); + + for (h = idm->idm_addr; h != NULL; h = h->next) + free(h); + + idm->idm_addr = NULL; + + return (0); +} void client_sig_handler(int sig, short event, void *p) @@ -121,6 +157,110 @@ client_sig_handler(int sig, short event, void *p) } void +client_dispatch_dns(int fd, short event, void *p) +{ + struct imsg imsg; + u_int16_t dlen; + u_char *data; + struct ypldap_addr *h; + int n, wait_cnt = 0; + struct idm *idm; + int shut = 0; + + struct env *env = p; + struct imsgbuf *ibuf = env->sc_ibuf_dns; + + switch (event) { + case EV_READ: + if ((n = imsg_read(ibuf)) == -1) + fatal("imsg_read error"); + if (n == 0) + shut = 1; + break; + case EV_WRITE: + if (msgbuf_write(&ibuf->w) == -1) + fatal("msgbuf_write"); + imsg_event_add(ibuf); + return; + default: + fatalx("unknown event"); + } + + for (;;) { + if ((n = imsg_get(ibuf, &imsg)) == -1) + fatal("client_dispatch_parent: imsg_read_error"); + if (n == 0) + break; + + switch (imsg.hdr.type) { + case IMSG_HOST_DNS: + TAILQ_FOREACH(idm, &env->sc_idms, idm_entry) + if (idm->idm_id == imsg.hdr.peerid) + break; + if (idm == NULL) { + log_warnx("IMSG_HOST_DNS with invalid peerID"); + break; + } + if (idm->idm_addr != NULL) { + log_warnx("IMSG_HOST_DNS but addr != NULL!"); + break; + } + + dlen = imsg.hdr.len - IMSG_HEADER_SIZE; + if (dlen == 0) { /* no data -> temp error */ + idm->idm_state = STATE_DNS_TEMPFAIL; + break; + } + + data = (u_char *)imsg.data; + while (dlen >= sizeof(struct sockaddr_storage)) { + if ((h = calloc(1, sizeof(struct ypldap_addr))) == + NULL) + fatal(NULL); + memcpy(&h->ss, data, sizeof(h->ss)); + + if(idm->idm_addr == NULL) + h->next = NULL; + else + h->next = idm->idm_addr; + + idm->idm_addr = h; + + data += sizeof(h->ss); + dlen -= sizeof(h->ss); + } + if (dlen != 0) + fatalx("IMSG_HOST_DNS: dlen != 0"); + + client_addr_init(idm); + + break; + default: + break; + } + imsg_free(&imsg); + } + + TAILQ_FOREACH(idm, &env->sc_idms, idm_entry) { + if(client_try_idm(env, idm) == -1) + idm->idm_state = STATE_LDAP_FAIL; + + if(idm->idm_state < STATE_LDAP_DONE) + wait_cnt++; + } + if(wait_cnt == 0) + imsg_compose(env->sc_ibuf, IMSG_END_UPDATE, 0, 0, NULL, 0); + + if (!shut) + imsg_event_add(ibuf); + else { + /* this pipe is dead, so remove the event handler */ + event_del(&ibuf->ev); + event_loopexit(NULL); + } +} + +void client_dispatch_parent(int fd, short event, void *p) { int n; @@ -213,7 +353,8 @@ client_shutdown(void) pid_t ldapclient(int pipe_main2client[2]) { - pid_t pid; + pid_t pid, dns_pid; + int pipe_dns[2]; struct passwd *pw; struct event ev_sigint; struct event ev_sigterm; @@ -235,6 +376,11 @@ ldapclient(int pipe_main2client[2]) if ((pw = getpwnam(YPLDAP_USER)) == NULL) fatal("getpwnam"); + if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_dns) == -1) + fatal("socketpair"); + dns_pid = ypldap_dns(pipe_dns, pw); + close(pipe_dns[1]); + #ifndef DEBUG if (chroot(pw->pw_dir) == -1) fatal("chroot"); @@ -264,6 +410,8 @@ ldapclient(int pipe_main2client[2]) close(pipe_main2client[0]); if ((env.sc_ibuf = calloc(1, sizeof(*env.sc_ibuf))) == NULL) fatal(NULL); + if ((env.sc_ibuf_dns = calloc(1, sizeof(*env.sc_ibuf_dns))) == NULL) + fatal(NULL); env.sc_ibuf->events = EV_READ; env.sc_ibuf->data = &env; @@ -272,6 +420,13 @@ ldapclient(int pipe_main2client[2]) env.sc_ibuf->handler, &env); event_add(&env.sc_ibuf->ev, NULL); + env.sc_ibuf_dns->events = EV_READ; + env.sc_ibuf_dns->data = &env; + imsg_init(env.sc_ibuf_dns, pipe_dns[0], client_dispatch_dns); + event_set(&env.sc_ibuf_dns->ev, env.sc_ibuf_dns->fd, env.sc_ibuf_dns->events, + env.sc_ibuf_dns->handler, &env); + event_add(&env.sc_ibuf_dns->ev, NULL); + event_dispatch(); client_shutdown(); @@ -279,105 +434,39 @@ ldapclient(int pipe_main2client[2]) } -void -client_configure_wrapper(int fd, short event, void *p) -{ - struct env *env = p; - - client_configure(env); -} - -#ifdef REFERRALS -struct aldap * -aldap_openhost(char *host, char *port) +int +client_try_idm(struct env *env, struct idm *idm) { - struct addrinfo hints; + const char *where; + char *attrs[ATTR_MAX+1]; + char **ldap_attrs; + int i, j, k; + struct idm_req ir; + struct aldap_message *m; struct aldap *al; - int fd; - - struct addrinfo *res, *res0; - int error; - - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - log_debug("trying directory: %s", host); - - if ((error = getaddrinfo(host, port, &hints, &res))) - errx(1, "getaddrinfo: %s", gai_strerror(error)); - - res0 = res; - do { - if ((fd = socket(res0->ai_family, res0->ai_socktype, - res0->ai_protocol)) < 0) - continue; - - if (connect(fd, res0->ai_addr, res0->ai_addrlen) == 0) - break; - else - warn("connect to %s port %s (%s) failed", host, port, "tcp"); - - close(fd); - fd = -1; - } while ((res0 = res0->ai_next) != NULL); - - freeaddrinfo(res); - - if(fd == -1) - return NULL; - - return aldap_init(fd); -} - -struct aldap * -connect_to_referral(struct aldap_message *m, struct aldap_url *lu) -{ - int i; - char **refs, *port; - struct aldap *al = NULL; - - if((refs = aldap_get_references(m)) == NULL) - return NULL; + where = "connect"; + if((al = aldap_open(idm->idm_addr)) == NULL) + return (-1); - for(i = 0; i >= 0 && refs[i] != NULL; i++) { - aldap_parse_url(refs[i], lu); - asprintf(&port, "%d", lu->port ? lu->port : 389); + if (idm->idm_flags & F_NEEDAUTH) { + where = "binding"; + if(aldap_bind(al, idm->idm_binddn, idm->idm_bindcred) == -1) + goto bad; - if((al = aldap_openhost(lu->host, port)) != NULL) { - free(port); - break; + where = "parsing"; + if((m = aldap_parse(al)) == NULL) + goto bad; + where = "verifying msgid"; + if(al->msgid != m->msgid) { + aldap_freemsg(m); + goto bad; } - - free(port); + aldap_freemsg(m); } - aldap_free_references(refs); - - return al; -} -#endif - -#define MAX_REFERRALS 10 -int -do_build_group(struct env *env, struct idm *idm, struct aldap *al, char - *basedn, enum scope scope, char *filter) -{ - char *attrs[ATTR_MAX+1]; - char **ldap_attrs; - struct idm_req ir; - struct aldap_message *m; - int i, j, k; - const char *where; -#ifdef REFERRALS - static int refcnt = 0; - struct aldap_url lu; - struct aldap *al_ref; -#endif - bzero(attrs, sizeof(attrs)); - for (i = ATTR_GR_MIN, j = 0; i < ATTR_GR_MAX; i++) { + for (i = 0, j = 0; i < ATTR_MAX; i++) { if (idm->idm_flags & F_FIXED_ATTR(i)) continue; attrs[j++] = idm->idm_attrs[i]; @@ -385,11 +474,12 @@ do_build_group(struct env *env, struct idm *idm, struct aldap *al, char attrs[j] = NULL; where = "search"; - if(aldap_search(al, basedn, scope, filter, attrs, 0, 0, 0) == -1) + if(aldap_search(al, idm->idm_basedn, LDAP_SCOPE_SUBTREE, + idm->idm_filters[FILTER_USER], attrs, 0, 0, 0) == -1) goto bad; /* - * build group line. + * build password line. */ while((m = aldap_parse(al)) != NULL) { where = "verifying msgid"; @@ -397,36 +487,6 @@ do_build_group(struct env *env, struct idm *idm, struct aldap *al, char aldap_freemsg(m); goto bad; } -#ifdef REFERRALS - /* continuation referral */ - if (m->message_type == LDAP_RES_SEARCH_REFERENCE) { - if(refcnt++ >= MAX_REFERRALS) - goto next_entry; - - if((al_ref = connect_to_referral(m, &lu)) == NULL) - goto next_entry; - do_build_group(env, idm, al_ref, lu.dn, - lu.scope, idm->idm_filters[FILTER_GROUP]); - aldap_close(al_ref); - goto next_entry; - } - /* normal referral */ - if(m->message_type == LDAP_RES_SEARCH_RESULT && - aldap_get_resultcode(m) == LDAP_REFERRAL) { - if(refcnt++ == MAX_REFERRALS) { - aldap_freemsg(m); - break; - } - - if((al_ref = connect_to_referral(m, &lu)) == NULL) { - aldap_freemsg(m); - break; - } - do_build_group(env, idm, al_ref, lu.dn, - lu.scope, idm->idm_filters[FILTER_GROUP]); - aldap_close(al_ref); - } -#endif /* end of the search result chain */ if (m->message_type == LDAP_RES_SEARCH_RESULT) { aldap_freemsg(m); @@ -440,24 +500,24 @@ do_build_group(struct env *env, struct idm *idm, struct aldap *al, char } /* search entry */ bzero(&ir, sizeof(ir)); - for (i = ATTR_GR_MIN, j = 0; i < ATTR_GR_MAX; i++) { + for (i = 0, j = 0; i < ATTR_MAX; i++) { if (idm->idm_flags & F_FIXED_ATTR(i)) { if (strlcat(ir.ir_line, idm->idm_attrs[i], sizeof(ir.ir_line)) >= sizeof(ir.ir_line)) /* * entry yields a line > 1024, trash it. */ - goto next_entry; - if (i == ATTR_GR_GID) { - ir.ir_key.ik_gid = strtonum( + goto next_pwdentry; + if (i == ATTR_UID) { + ir.ir_key.ik_uid = strtonum( idm->idm_attrs[i], 0, - GID_MAX, NULL); + UID_MAX, NULL); } } else if (idm->idm_list & F_LIST(i)) { if (aldap_match_entry(m, attrs[j++], &ldap_attrs) == -1) - goto next_entry; - if (ldap_attrs == NULL || ldap_attrs[0] == NULL) - goto next_entry; + goto next_pwdentry; + if (ldap_attrs[0] == NULL) + goto next_pwdentry; for(k = 0; k >= 0 && ldap_attrs[k] != NULL; k++) { if (strlcat(ir.ir_line, ldap_attrs[k], sizeof(ir.ir_line)) >= sizeof(ir.ir_line)) @@ -467,61 +527,39 @@ do_build_group(struct env *env, struct idm *idm, struct aldap *al, char sizeof(ir.ir_line)) >= sizeof(ir.ir_line)) { aldap_free_entry(ldap_attrs); - goto next_entry; + goto next_pwdentry; } } aldap_free_entry(ldap_attrs); } else { - if(aldap_match_entry(m, attrs[j++], &ldap_attrs) == -1) - goto next_entry; - if (ldap_attrs == NULL || ldap_attrs[0] == NULL) - goto next_entry; + if (aldap_match_entry(m, attrs[j++], &ldap_attrs) == -1) + goto next_pwdentry; + if (ldap_attrs[0] == NULL) + goto next_pwdentry; if (strlcat(ir.ir_line, ldap_attrs[0], sizeof(ir.ir_line)) >= sizeof(ir.ir_line)) { aldap_free_entry(ldap_attrs); - goto next_entry; + goto next_pwdentry; } - if (i == ATTR_GR_GID) { + if (i == ATTR_UID) { ir.ir_key.ik_uid = strtonum( - ldap_attrs[0], 0, GID_MAX, NULL); + ldap_attrs[0], 0, UID_MAX, NULL); } aldap_free_entry(ldap_attrs); } - if (i != ATTR_GR_MEMBERS) + if (i != ATTR_SHELL) if (strlcat(ir.ir_line, ":", sizeof(ir.ir_line)) >= sizeof(ir.ir_line)) - goto next_entry; + goto next_pwdentry; } - imsg_compose(env->sc_ibuf, IMSG_GRP_ENTRY, 0, 0, + imsg_compose(env->sc_ibuf, IMSG_PW_ENTRY, 0, 0, &ir, sizeof(ir)); -next_entry: +next_pwdentry: aldap_freemsg(m); } - return (0); -bad: - log_debug("directory %s errored out in %s", idm->idm_name, where); - return (-1); -} - -int -do_build_passwd(struct env *env, struct idm *idm, struct aldap *al, char - *basedn, enum scope scope, char *filter) -{ - char *attrs[ATTR_MAX+1]; - char **ldap_attrs; - struct idm_req ir; - struct aldap_message *m; - int i, j, k; - const char *where; -#ifdef REFERRALS - static int refcnt = 0; - struct aldap_url lu; - struct aldap *al_ref; -#endif - bzero(attrs, sizeof(attrs)); - for (i = 0, j = 0; i < ATTR_MAX; i++) { + for (i = ATTR_GR_MIN, j = 0; i < ATTR_GR_MAX; i++) { if (idm->idm_flags & F_FIXED_ATTR(i)) continue; attrs[j++] = idm->idm_attrs[i]; @@ -529,11 +567,12 @@ do_build_passwd(struct env *env, struct idm *idm, struct aldap *al, char attrs[j] = NULL; where = "search"; - if(aldap_search(al, basedn, scope, filter, attrs, 0, 0, 0) == -1) + if(aldap_search(al, idm->idm_basedn, LDAP_SCOPE_SUBTREE, + idm->idm_filters[FILTER_GROUP], attrs, 0, 0, 0) == -1) goto bad; /* - * build password line. + * build group line. */ while((m = aldap_parse(al)) != NULL) { where = "verifying msgid"; @@ -541,36 +580,6 @@ do_build_passwd(struct env *env, struct idm *idm, struct aldap *al, char aldap_freemsg(m); goto bad; } -#ifdef REFERRALS - /* continuation referral */ - if (m->message_type == LDAP_RES_SEARCH_REFERENCE) { - if(refcnt++ >= MAX_REFERRALS) - goto next_entry; - - if((al_ref = connect_to_referral(m, &lu)) == NULL) - goto next_entry; - do_build_passwd(env, idm, al_ref, lu.dn, - lu.scope, idm->idm_filters[FILTER_USER]); - aldap_close(al_ref); - goto next_entry; - } - /* normal referral */ - if(m->message_type == LDAP_RES_SEARCH_RESULT && - aldap_get_resultcode(m) == LDAP_REFERRAL) { - if(refcnt++ == MAX_REFERRALS) { - aldap_freemsg(m); - break; - } - - if((al_ref = connect_to_referral(m, &lu)) == NULL) { - aldap_freemsg(m); - break; - } - do_build_passwd(env, idm, al_ref, lu.dn, - lu.scope, idm->idm_filters[FILTER_USER]); - aldap_close(al_ref); - } -#endif /* end of the search result chain */ if (m->message_type == LDAP_RES_SEARCH_RESULT) { aldap_freemsg(m); @@ -584,24 +593,24 @@ do_build_passwd(struct env *env, struct idm *idm, struct aldap *al, char } /* search entry */ bzero(&ir, sizeof(ir)); - for (i = 0, j = 0; i < ATTR_MAX; i++) { + for (i = ATTR_GR_MIN, j = 0; i < ATTR_GR_MAX; i++) { if (idm->idm_flags & F_FIXED_ATTR(i)) { if (strlcat(ir.ir_line, idm->idm_attrs[i], sizeof(ir.ir_line)) >= sizeof(ir.ir_line)) /* * entry yields a line > 1024, trash it. */ - goto next_entry; - if (i == ATTR_UID) { - ir.ir_key.ik_uid = strtonum( + goto next_grpentry; + if (i == ATTR_GR_GID) { + ir.ir_key.ik_gid = strtonum( idm->idm_attrs[i], 0, - UID_MAX, NULL); + GID_MAX, NULL); } } else if (idm->idm_list & F_LIST(i)) { if (aldap_match_entry(m, attrs[j++], &ldap_attrs) == -1) - goto next_entry; - if (ldap_attrs == NULL || ldap_attrs[0] == NULL) - goto next_entry; + goto next_grpentry; + if (ldap_attrs[0] == NULL) + goto next_grpentry; for(k = 0; k >= 0 && ldap_attrs[k] != NULL; k++) { if (strlcat(ir.ir_line, ldap_attrs[k], sizeof(ir.ir_line)) >= sizeof(ir.ir_line)) @@ -611,106 +620,93 @@ do_build_passwd(struct env *env, struct idm *idm, struct aldap *al, char sizeof(ir.ir_line)) >= sizeof(ir.ir_line)) { aldap_free_entry(ldap_attrs); - goto next_entry; + goto next_grpentry; } } aldap_free_entry(ldap_attrs); } else { - if (aldap_match_entry(m, attrs[j++], &ldap_attrs) == -1) - goto next_entry; - if (ldap_attrs == NULL || ldap_attrs[0] == NULL) - goto next_entry; + if(aldap_match_entry(m, attrs[j++], &ldap_attrs) == -1) + goto next_grpentry; + if (ldap_attrs[0] == NULL) + goto next_grpentry; if (strlcat(ir.ir_line, ldap_attrs[0], sizeof(ir.ir_line)) >= sizeof(ir.ir_line)) { aldap_free_entry(ldap_attrs); - goto next_entry; + goto next_grpentry; } - if (i == ATTR_UID) { + if (i == ATTR_GR_GID) { ir.ir_key.ik_uid = strtonum( - ldap_attrs[0], 0, UID_MAX, NULL); + ldap_attrs[0], 0, GID_MAX, NULL); } aldap_free_entry(ldap_attrs); } - if (i != ATTR_SHELL) + if (i != ATTR_GR_MEMBERS) if (strlcat(ir.ir_line, ":", sizeof(ir.ir_line)) >= sizeof(ir.ir_line)) - goto next_entry; + goto next_grpentry; } - imsg_compose(env->sc_ibuf, IMSG_PW_ENTRY, 0, 0, + imsg_compose(env->sc_ibuf, IMSG_GRP_ENTRY, 0, 0, &ir, sizeof(ir)); -next_entry: +next_grpentry: aldap_freemsg(m); } + aldap_close(al); + + idm->idm_state = STATE_LDAP_DONE; + return (0); bad: log_debug("directory %s errored out in %s", idm->idm_name, where); return (-1); } - -int -client_try_idm(struct env *env, struct idm *idm) +void +client_periodic_update(int fd, short event, void *p) { - const char *where; - struct idm_req ir; - struct aldap_message *m; - struct aldap *al; + struct env *env = p; - bzero(&ir, sizeof(ir)); - imsg_compose(env->sc_ibuf, IMSG_START_UPDATE, 0, 0, &ir, sizeof(ir)); + struct idm *idm; + int fail_cnt = 0; - where = "connect"; - if((al = aldap_openidm(idm)) == NULL) - goto bad; + /* If LDAP isn't finished, notify the master process to trash the + * update. */ + TAILQ_FOREACH(idm, &env->sc_idms, idm_entry) { + if(idm->idm_state < STATE_LDAP_DONE) + fail_cnt++; - if (idm->idm_flags & F_NEEDAUTH) { - where = "binding"; - if(aldap_bind(al, idm->idm_binddn, idm->idm_bindcred) == -1) - goto bad; + idm->idm_state = STATE_NONE; - where = "parsing"; - if((m = aldap_parse(al)) == NULL) - goto bad; - where = "verifying msgid"; - if(al->msgid != m->msgid) { - aldap_freemsg(m); - goto bad; - } - aldap_freemsg(m); + client_addr_free(idm); + } + if(fail_cnt > 0) { + log_debug("trash the update"); + imsg_compose(env->sc_ibuf, IMSG_TRASH_UPDATE, 0, 0, NULL, 0); } - do_build_passwd(env, idm, al, idm->idm_basedn, LDAP_SCOPE_SUBTREE, - idm->idm_filters[FILTER_USER]); - do_build_group(env, idm, al, idm->idm_basedn, LDAP_SCOPE_SUBTREE, - idm->idm_filters[FILTER_GROUP]); - - aldap_close(al); - - return (0); -bad: - log_debug("directory %s errored out in %s", idm->idm_name, where); - return (-1); + client_configure(env); } void client_configure(struct env *env) { - enum imsg_type finish; struct timeval tv; struct idm *idm; + u_int16_t dlen; log_debug("connecting to directories"); - finish = IMSG_END_UPDATE; + imsg_compose(env->sc_ibuf, IMSG_START_UPDATE, 0, 0, NULL, 0); - TAILQ_FOREACH(idm, &env->sc_idms, idm_entry) - if (client_try_idm(env, idm) == -1) { - finish = IMSG_TRASH_UPDATE; - break; - } - imsg_compose(env->sc_ibuf, finish, 0, 0, NULL, 0); + + /* Start the DNS lookups */ + TAILQ_FOREACH(idm, &env->sc_idms, idm_entry) { + dlen = strlen(idm->idm_name) + 1; + imsg_compose(env->sc_ibuf_dns, IMSG_HOST_DNS, idm->idm_id, 0, + idm->idm_name, dlen); + } + tv.tv_sec = env->sc_conf_tv.tv_sec; tv.tv_usec = env->sc_conf_tv.tv_usec; - evtimer_set(&env->sc_conf_ev, client_configure_wrapper, env); + evtimer_set(&env->sc_conf_ev, client_periodic_update, env); evtimer_add(&env->sc_conf_ev, &tv); } |