diff options
author | Jonathan Matthew <jmatthew@cvs.openbsd.org> | 2016-04-10 09:59:22 +0000 |
---|---|---|
committer | Jonathan Matthew <jmatthew@cvs.openbsd.org> | 2016-04-10 09:59:22 +0000 |
commit | d214125c5b96da9ab6be83f7767887ce527e4d1d (patch) | |
tree | 7c61bd5bc0f120846b649f36fc123c3bb92350f7 /usr.sbin | |
parent | b90b42426a0e63962918f8a593a047a032a7b6ad (diff) |
convert ypldap_addr list to a tailq
ok dlg@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ypldap/ldapclient.c | 39 | ||||
-rw-r--r-- | usr.sbin/ypldap/ypldap.h | 7 | ||||
-rw-r--r-- | usr.sbin/ypldap/ypldap_dns.c | 23 |
3 files changed, 28 insertions, 41 deletions
diff --git a/usr.sbin/ypldap/ldapclient.c b/usr.sbin/ypldap/ldapclient.c index 5cd2571714e..4b21803ab19 100644 --- a/usr.sbin/ypldap/ldapclient.c +++ b/usr.sbin/ypldap/ldapclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldapclient.c,v 1.35 2015/12/05 13:15:06 claudio Exp $ */ +/* $OpenBSD: ldapclient.c,v 1.36 2016/04/10 09:59:21 jmatthew Exp $ */ /* * Copyright (c) 2008 Alexander Schrijver <aschrijver@openbsd.org> @@ -56,18 +56,18 @@ int client_try_idm(struct env *, struct idm *); int client_addr_init(struct idm *); int client_addr_free(struct idm *); -struct aldap *client_aldap_open(struct ypldap_addr *); +struct aldap *client_aldap_open(struct ypldap_addr_list *); /* * dummy wrapper to provide aldap_init with its fd's. */ struct aldap * -client_aldap_open(struct ypldap_addr *addr) +client_aldap_open(struct ypldap_addr_list *addr) { int fd = -1; struct ypldap_addr *p; - for (p = addr; p != NULL; p = p->next) { + TAILQ_FOREACH(p, addr, next) { char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; struct sockaddr *sa = (struct sockaddr *)&p->ss; @@ -98,7 +98,7 @@ client_addr_init(struct idm *idm) struct sockaddr_in6 *sa_in6; struct ypldap_addr *h; - for (h = idm->idm_addr; h != NULL; h = h->next) { + TAILQ_FOREACH(h, &idm->idm_addr, next) { switch (h->ss.ss_family) { case AF_INET: sa_in = (struct sockaddr_in *)&h->ss; @@ -124,18 +124,14 @@ client_addr_init(struct idm *idm) int client_addr_free(struct idm *idm) { - struct ypldap_addr *h, *p; + struct ypldap_addr *h; - if (idm->idm_addr == NULL) - return (-1); - - for (h = idm->idm_addr; h != NULL; h = p) { - p = h->next; + while (!TAILQ_EMPTY(&idm->idm_addr)) { + h = TAILQ_FIRST(&idm->idm_addr); + TAILQ_REMOVE(&idm->idm_addr, h, next); free(h); } - idm->idm_addr = NULL; - return (0); } @@ -199,8 +195,8 @@ client_dispatch_dns(int fd, short events, void *p) log_warnx("IMSG_HOST_DNS with invalid peerID"); break; } - if (idm->idm_addr != NULL) { - log_warnx("IMSG_HOST_DNS but addr != NULL!"); + if (!TAILQ_EMPTY(&idm->idm_addr)) { + log_warnx("IMSG_HOST_DNS but addrs set!"); break; } @@ -212,17 +208,10 @@ client_dispatch_dns(int fd, short events, void *p) data = (u_char *)imsg.data; while (dlen >= sizeof(struct sockaddr_storage)) { - if ((h = calloc(1, sizeof(struct ypldap_addr))) == - NULL) + if ((h = calloc(1, sizeof(*h))) == 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; + TAILQ_INSERT_HEAD(&idm->idm_addr, h, next); data += sizeof(h->ss); dlen -= sizeof(h->ss); @@ -590,7 +579,7 @@ client_try_idm(struct env *env, struct idm *idm) struct aldap *al; where = "connect"; - if ((al = client_aldap_open(idm->idm_addr)) == NULL) + if ((al = client_aldap_open(&idm->idm_addr)) == NULL) return (-1); if (idm->idm_flags & F_NEEDAUTH) { diff --git a/usr.sbin/ypldap/ypldap.h b/usr.sbin/ypldap/ypldap.h index 177e8fda4f2..d12eaa90024 100644 --- a/usr.sbin/ypldap/ypldap.h +++ b/usr.sbin/ypldap/ypldap.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ypldap.h,v 1.16 2015/01/16 06:40:22 deraadt Exp $ */ +/* $OpenBSD: ypldap.h,v 1.17 2016/04/10 09:59:21 jmatthew Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -41,9 +41,10 @@ enum imsg_type { }; struct ypldap_addr { - struct ypldap_addr *next; + TAILQ_ENTRY(ypldap_addr) next; struct sockaddr_storage ss; }; +TAILQ_HEAD(ypldap_addr_list, ypldap_addr); enum { PROC_MAIN, @@ -90,7 +91,7 @@ struct idm { enum client_state idm_state; u_int32_t idm_flags; /* lower 20 reserved */ u_int32_t idm_list; - struct ypldap_addr *idm_addr; + struct ypldap_addr_list idm_addr; in_port_t idm_port; char idm_binddn[LINE_WIDTH]; char idm_bindcred[LINE_WIDTH]; diff --git a/usr.sbin/ypldap/ypldap_dns.c b/usr.sbin/ypldap/ypldap_dns.c index a545642aa88..ced711a67c2 100644 --- a/usr.sbin/ypldap/ypldap_dns.c +++ b/usr.sbin/ypldap/ypldap_dns.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ypldap_dns.c,v 1.10 2015/12/05 13:15:06 claudio Exp $ */ +/* $OpenBSD: ypldap_dns.c,v 1.11 2016/04/10 09:59:21 jmatthew Exp $ */ /* * Copyright (c) 2003-2008 Henning Brauer <henning@openbsd.org> @@ -46,7 +46,7 @@ struct imsgev *iev_dns; void dns_dispatch_imsg(int, short, void *); void dns_sig_handler(int, short, void *); void dns_shutdown(void); -int host_dns(const char *s, struct ypldap_addr **hn); +int host_dns(const char *, struct ypldap_addr_list *); void dns_sig_handler(int sig, short event, void *p) @@ -130,7 +130,8 @@ dns_dispatch_imsg(int fd, short events, void *p) struct imsg imsg; int n, cnt; char *name; - struct ypldap_addr *h, *hn; + struct ypldap_addr_list hn = TAILQ_HEAD_INITIALIZER(hn); + struct ypldap_addr *h; struct ibuf *buf; struct env *env = p; struct imsgev *iev = env->sc_iev; @@ -177,12 +178,11 @@ dns_dispatch_imsg(int fd, short events, void *p) if (buf == NULL) break; if (cnt > 0) { - h = hn; - while (h != NULL) { + while (!TAILQ_EMPTY(&hn)) { + h = TAILQ_FIRST(&hn); + TAILQ_REMOVE(&hn, h, next); imsg_add(buf, &h->ss, sizeof(h->ss)); - hn = h->next; free(h); - h = hn; } } @@ -205,13 +205,13 @@ done: } int -host_dns(const char *s, struct ypldap_addr **hn) +host_dns(const char *s, struct ypldap_addr_list *hn) { struct addrinfo hints, *res0, *res; int error, cnt = 0; struct sockaddr_in *sa_in; struct sockaddr_in6 *sa_in6; - struct ypldap_addr *h, *hh = NULL; + struct ypldap_addr *h; bzero(&hints, sizeof(hints)); hints.ai_family = PF_UNSPEC; @@ -244,12 +244,9 @@ host_dns(const char *s, struct ypldap_addr **hn) res->ai_addr)->sin6_addr, sizeof(struct in6_addr)); } - h->next = hh; - hh = h; + TAILQ_INSERT_HEAD(hn, h, next); cnt++; } freeaddrinfo(res0); - - *hn = hh; return (cnt); } |