ldapclient.c (292273) | ldapclient.c (297907) |
---|---|
1/* $OpenBSD: ldapclient.c,v 1.31 2014/11/16 23:24:44 tedu Exp $ */ | 1/* $OpenBSD: ldapclient.c,v 1.31 2014/11/16 23:24:44 tedu Exp $ */ |
2/* $FreeBSD: head/usr.sbin/ypldap/ldapclient.c 292273 2015-12-15 15:46:14Z araujo $ */ | 2/* $FreeBSD: head/usr.sbin/ypldap/ldapclient.c 297907 2016-04-13 03:36:34Z araujo $ */ |
3 4/* 5 * Copyright (c) 2008 Alexander Schrijver <aschrijver@openbsd.org> 6 * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> 7 * 8 * Permission to use, copy, modify, and distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above 10 * copyright notice and this permission notice appear in all copies. --- 41 unchanged lines hidden (view full) --- 52int client_build_req(struct idm *, struct idm_req *, struct aldap_message *, 53 int, int); 54int client_search_idm(struct env *, struct idm *, struct aldap *, 55 char **, char *, int, int, enum imsg_type); 56int client_try_idm(struct env *, struct idm *); 57int client_addr_init(struct idm *); 58int client_addr_free(struct idm *); 59 | 3 4/* 5 * Copyright (c) 2008 Alexander Schrijver <aschrijver@openbsd.org> 6 * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> 7 * 8 * Permission to use, copy, modify, and distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above 10 * copyright notice and this permission notice appear in all copies. --- 41 unchanged lines hidden (view full) --- 52int client_build_req(struct idm *, struct idm_req *, struct aldap_message *, 53 int, int); 54int client_search_idm(struct env *, struct idm *, struct aldap *, 55 char **, char *, int, int, enum imsg_type); 56int client_try_idm(struct env *, struct idm *); 57int client_addr_init(struct idm *); 58int client_addr_free(struct idm *); 59 |
60struct aldap *client_aldap_open(struct ypldap_addr *); | 60struct aldap *client_aldap_open(struct ypldap_addr_list *); |
61 62/* 63 * dummy wrapper to provide aldap_init with its fd's. 64 */ 65struct aldap * | 61 62/* 63 * dummy wrapper to provide aldap_init with its fd's. 64 */ 65struct aldap * |
66client_aldap_open(struct ypldap_addr *addr) | 66client_aldap_open(struct ypldap_addr_list *addr) |
67{ 68 int fd = -1; 69 struct ypldap_addr *p; 70 | 67{ 68 int fd = -1; 69 struct ypldap_addr *p; 70 |
71 for (p = addr; p != NULL; p = p->next) { | 71 TAILQ_FOREACH(p, addr, next) { |
72 char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; 73 struct sockaddr *sa = (struct sockaddr *)&p->ss; 74 75 if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf, 76 sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) 77 errx(1, "could not get numeric hostname"); 78 79 if ((fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) --- 14 unchanged lines hidden (view full) --- 94 95int 96client_addr_init(struct idm *idm) 97{ 98 struct sockaddr_in *sa_in; 99 struct sockaddr_in6 *sa_in6; 100 struct ypldap_addr *h; 101 | 72 char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; 73 struct sockaddr *sa = (struct sockaddr *)&p->ss; 74 75 if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf, 76 sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) 77 errx(1, "could not get numeric hostname"); 78 79 if ((fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) --- 14 unchanged lines hidden (view full) --- 94 95int 96client_addr_init(struct idm *idm) 97{ 98 struct sockaddr_in *sa_in; 99 struct sockaddr_in6 *sa_in6; 100 struct ypldap_addr *h; 101 |
102 for (h = idm->idm_addr; h != NULL; h = h->next) { | 102 TAILQ_FOREACH(h, &idm->idm_addr, next) { |
103 switch (h->ss.ss_family) { 104 case AF_INET: 105 sa_in = (struct sockaddr_in *)&h->ss; 106 if (ntohs(sa_in->sin_port) == 0) 107 sa_in->sin_port = htons(LDAP_PORT); 108 idm->idm_state = STATE_DNS_DONE; 109 break; 110 case AF_INET6: --- 9 unchanged lines hidden (view full) --- 120 } 121 122 return (0); 123} 124 125int 126client_addr_free(struct idm *idm) 127{ | 103 switch (h->ss.ss_family) { 104 case AF_INET: 105 sa_in = (struct sockaddr_in *)&h->ss; 106 if (ntohs(sa_in->sin_port) == 0) 107 sa_in->sin_port = htons(LDAP_PORT); 108 idm->idm_state = STATE_DNS_DONE; 109 break; 110 case AF_INET6: --- 9 unchanged lines hidden (view full) --- 120 } 121 122 return (0); 123} 124 125int 126client_addr_free(struct idm *idm) 127{ |
128 struct ypldap_addr *h, *p; | 128 struct ypldap_addr *h; |
129 | 129 |
130 if (idm->idm_addr == NULL) 131 return (-1); 132 133 for (h = idm->idm_addr; h != NULL; h = p) { 134 p = h->next; | 130 while (!TAILQ_EMPTY(&idm->idm_addr)) { 131 h = TAILQ_FIRST(&idm->idm_addr); 132 TAILQ_REMOVE(&idm->idm_addr, h, next); |
135 free(h); 136 } 137 | 133 free(h); 134 } 135 |
138 idm->idm_addr = NULL; 139 | |
140 return (0); 141} 142 143void 144client_sig_handler(int sig, short event, void *p) 145{ 146 switch (sig) { 147 case SIGINT: --- 47 unchanged lines hidden (view full) --- 195 case IMSG_HOST_DNS: 196 TAILQ_FOREACH(idm, &env->sc_idms, idm_entry) 197 if (idm->idm_id == imsg.hdr.peerid) 198 break; 199 if (idm == NULL) { 200 log_warnx("IMSG_HOST_DNS with invalid peerID"); 201 break; 202 } | 136 return (0); 137} 138 139void 140client_sig_handler(int sig, short event, void *p) 141{ 142 switch (sig) { 143 case SIGINT: --- 47 unchanged lines hidden (view full) --- 191 case IMSG_HOST_DNS: 192 TAILQ_FOREACH(idm, &env->sc_idms, idm_entry) 193 if (idm->idm_id == imsg.hdr.peerid) 194 break; 195 if (idm == NULL) { 196 log_warnx("IMSG_HOST_DNS with invalid peerID"); 197 break; 198 } |
203 if (idm->idm_addr != NULL) { 204 log_warnx("IMSG_HOST_DNS but addr != NULL!"); | 199 if (!TAILQ_EMPTY(&idm->idm_addr)) { 200 log_warnx("IMSG_HOST_DNS but addrs set!"); |
205 break; 206 } 207 208 dlen = imsg.hdr.len - IMSG_HEADER_SIZE; 209 if (dlen == 0) { /* no data -> temp error */ 210 idm->idm_state = STATE_DNS_TEMPFAIL; 211 break; 212 } 213 214 data = (u_char *)imsg.data; 215 while (dlen >= sizeof(struct sockaddr_storage)) { | 201 break; 202 } 203 204 dlen = imsg.hdr.len - IMSG_HEADER_SIZE; 205 if (dlen == 0) { /* no data -> temp error */ 206 idm->idm_state = STATE_DNS_TEMPFAIL; 207 break; 208 } 209 210 data = (u_char *)imsg.data; 211 while (dlen >= sizeof(struct sockaddr_storage)) { |
216 if ((h = calloc(1, sizeof(struct ypldap_addr))) == 217 NULL) | 212 if ((h = calloc(1, sizeof(*h))) == NULL) |
218 fatal(NULL); 219 memcpy(&h->ss, data, sizeof(h->ss)); | 213 fatal(NULL); 214 memcpy(&h->ss, data, sizeof(h->ss)); |
215 TAILQ_INSERT_HEAD(&idm->idm_addr, h, next); |
|
220 | 216 |
221 if (idm->idm_addr == NULL) 222 h->next = NULL; 223 else 224 h->next = idm->idm_addr; 225 226 idm->idm_addr = h; 227 | |
228 data += sizeof(h->ss); 229 dlen -= sizeof(h->ss); 230 } 231 if (dlen != 0) 232 fatalx("IMSG_HOST_DNS: dlen != 0"); 233 234 client_addr_init(idm); 235 --- 347 unchanged lines hidden (view full) --- 583{ 584 const char *where; 585 char *attrs[ATTR_MAX+1]; 586 int i, j; 587 struct aldap_message *m; 588 struct aldap *al; 589 590 where = "connect"; | 217 data += sizeof(h->ss); 218 dlen -= sizeof(h->ss); 219 } 220 if (dlen != 0) 221 fatalx("IMSG_HOST_DNS: dlen != 0"); 222 223 client_addr_init(idm); 224 --- 347 unchanged lines hidden (view full) --- 572{ 573 const char *where; 574 char *attrs[ATTR_MAX+1]; 575 int i, j; 576 struct aldap_message *m; 577 struct aldap *al; 578 579 where = "connect"; |
591 if ((al = client_aldap_open(idm->idm_addr)) == NULL) | 580 if ((al = client_aldap_open(&idm->idm_addr)) == NULL) |
592 return (-1); 593 594 if (idm->idm_flags & F_NEEDAUTH) { 595 where = "binding"; 596 if (aldap_bind(al, idm->idm_binddn, idm->idm_bindcred) == -1) 597 goto bad; 598 599 where = "parsing"; --- 106 unchanged lines hidden --- | 581 return (-1); 582 583 if (idm->idm_flags & F_NEEDAUTH) { 584 where = "binding"; 585 if (aldap_bind(al, idm->idm_binddn, idm->idm_bindcred) == -1) 586 goto bad; 587 588 where = "parsing"; --- 106 unchanged lines hidden --- |