Convert ypldap_addr list to a tailq(queue(3)).

Obtained from:	OpenBSD r1.11, r1.17 and r1.36
This commit is contained in:
Marcelo Araujo 2016-04-13 03:36:34 +00:00
parent 074e77e66e
commit eaf209de36
3 changed files with 26 additions and 39 deletions

View File

@ -57,18 +57,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;
@ -99,7 +99,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;
@ -125,18 +125,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);
}
@ -200,8 +196,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;
}
@ -213,17 +209,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);
@ -588,7 +577,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) {

View File

@ -42,9 +42,10 @@ enum imsg_type {
};
struct ypldap_addr {
struct ypldap_addr *next;
struct sockaddr_storage ss;
TAILQ_ENTRY(ypldap_addr) next;
struct sockaddr_storage ss;
};
TAILQ_HEAD(ypldap_addr_list, ypldap_addr);
enum {
PROC_MAIN,
@ -91,7 +92,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];

View File

@ -48,7 +48,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)
@ -129,7 +129,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;
@ -176,12 +177,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;
}
}
@ -204,13 +204,13 @@ dns_dispatch_imsg(int fd, short events, void *p)
}
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;
@ -243,12 +243,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);
}