Convert ypldap_addr list to a tailq(queue(3)).
Obtained from: OpenBSD r1.11, r1.17 and r1.36
This commit is contained in:
parent
074e77e66e
commit
eaf209de36
@ -57,18 +57,18 @@ int client_try_idm(struct env *, struct idm *);
|
|||||||
int client_addr_init(struct idm *);
|
int client_addr_init(struct idm *);
|
||||||
int client_addr_free(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.
|
* dummy wrapper to provide aldap_init with its fd's.
|
||||||
*/
|
*/
|
||||||
struct aldap *
|
struct aldap *
|
||||||
client_aldap_open(struct ypldap_addr *addr)
|
client_aldap_open(struct ypldap_addr_list *addr)
|
||||||
{
|
{
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
struct ypldap_addr *p;
|
struct ypldap_addr *p;
|
||||||
|
|
||||||
for (p = addr; p != NULL; p = p->next) {
|
TAILQ_FOREACH(p, addr, next) {
|
||||||
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
|
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
|
||||||
struct sockaddr *sa = (struct sockaddr *)&p->ss;
|
struct sockaddr *sa = (struct sockaddr *)&p->ss;
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ client_addr_init(struct idm *idm)
|
|||||||
struct sockaddr_in6 *sa_in6;
|
struct sockaddr_in6 *sa_in6;
|
||||||
struct ypldap_addr *h;
|
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) {
|
switch (h->ss.ss_family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
sa_in = (struct sockaddr_in *)&h->ss;
|
sa_in = (struct sockaddr_in *)&h->ss;
|
||||||
@ -125,18 +125,14 @@ client_addr_init(struct idm *idm)
|
|||||||
int
|
int
|
||||||
client_addr_free(struct idm *idm)
|
client_addr_free(struct idm *idm)
|
||||||
{
|
{
|
||||||
struct ypldap_addr *h, *p;
|
struct ypldap_addr *h;
|
||||||
|
|
||||||
if (idm->idm_addr == NULL)
|
while (!TAILQ_EMPTY(&idm->idm_addr)) {
|
||||||
return (-1);
|
h = TAILQ_FIRST(&idm->idm_addr);
|
||||||
|
TAILQ_REMOVE(&idm->idm_addr, h, next);
|
||||||
for (h = idm->idm_addr; h != NULL; h = p) {
|
|
||||||
p = h->next;
|
|
||||||
free(h);
|
free(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
idm->idm_addr = NULL;
|
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,8 +196,8 @@ client_dispatch_dns(int fd, short events, void *p)
|
|||||||
log_warnx("IMSG_HOST_DNS with invalid peerID");
|
log_warnx("IMSG_HOST_DNS with invalid peerID");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (idm->idm_addr != NULL) {
|
if (!TAILQ_EMPTY(&idm->idm_addr)) {
|
||||||
log_warnx("IMSG_HOST_DNS but addr != NULL!");
|
log_warnx("IMSG_HOST_DNS but addrs set!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,17 +209,10 @@ client_dispatch_dns(int fd, short events, void *p)
|
|||||||
|
|
||||||
data = (u_char *)imsg.data;
|
data = (u_char *)imsg.data;
|
||||||
while (dlen >= sizeof(struct sockaddr_storage)) {
|
while (dlen >= sizeof(struct sockaddr_storage)) {
|
||||||
if ((h = calloc(1, sizeof(struct ypldap_addr))) ==
|
if ((h = calloc(1, sizeof(*h))) == NULL)
|
||||||
NULL)
|
|
||||||
fatal(NULL);
|
fatal(NULL);
|
||||||
memcpy(&h->ss, data, sizeof(h->ss));
|
memcpy(&h->ss, data, sizeof(h->ss));
|
||||||
|
TAILQ_INSERT_HEAD(&idm->idm_addr, h, next);
|
||||||
if (idm->idm_addr == NULL)
|
|
||||||
h->next = NULL;
|
|
||||||
else
|
|
||||||
h->next = idm->idm_addr;
|
|
||||||
|
|
||||||
idm->idm_addr = h;
|
|
||||||
|
|
||||||
data += sizeof(h->ss);
|
data += sizeof(h->ss);
|
||||||
dlen -= sizeof(h->ss);
|
dlen -= sizeof(h->ss);
|
||||||
@ -588,7 +577,7 @@ client_try_idm(struct env *env, struct idm *idm)
|
|||||||
struct aldap *al;
|
struct aldap *al;
|
||||||
|
|
||||||
where = "connect";
|
where = "connect";
|
||||||
if ((al = client_aldap_open(idm->idm_addr)) == NULL)
|
if ((al = client_aldap_open(&idm->idm_addr)) == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
if (idm->idm_flags & F_NEEDAUTH) {
|
if (idm->idm_flags & F_NEEDAUTH) {
|
||||||
|
@ -42,9 +42,10 @@ enum imsg_type {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ypldap_addr {
|
struct ypldap_addr {
|
||||||
struct ypldap_addr *next;
|
TAILQ_ENTRY(ypldap_addr) next;
|
||||||
struct sockaddr_storage ss;
|
struct sockaddr_storage ss;
|
||||||
};
|
};
|
||||||
|
TAILQ_HEAD(ypldap_addr_list, ypldap_addr);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROC_MAIN,
|
PROC_MAIN,
|
||||||
@ -91,7 +92,7 @@ struct idm {
|
|||||||
enum client_state idm_state;
|
enum client_state idm_state;
|
||||||
u_int32_t idm_flags; /* lower 20 reserved */
|
u_int32_t idm_flags; /* lower 20 reserved */
|
||||||
u_int32_t idm_list;
|
u_int32_t idm_list;
|
||||||
struct ypldap_addr *idm_addr;
|
struct ypldap_addr_list idm_addr;
|
||||||
in_port_t idm_port;
|
in_port_t idm_port;
|
||||||
char idm_binddn[LINE_WIDTH];
|
char idm_binddn[LINE_WIDTH];
|
||||||
char idm_bindcred[LINE_WIDTH];
|
char idm_bindcred[LINE_WIDTH];
|
||||||
|
@ -48,7 +48,7 @@ struct imsgev *iev_dns;
|
|||||||
void dns_dispatch_imsg(int, short, void *);
|
void dns_dispatch_imsg(int, short, void *);
|
||||||
void dns_sig_handler(int, short, void *);
|
void dns_sig_handler(int, short, void *);
|
||||||
void dns_shutdown(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
|
void
|
||||||
dns_sig_handler(int sig, short event, void *p)
|
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;
|
struct imsg imsg;
|
||||||
int n, cnt;
|
int n, cnt;
|
||||||
char *name;
|
char *name;
|
||||||
struct ypldap_addr *h, *hn;
|
struct ypldap_addr_list hn = TAILQ_HEAD_INITIALIZER(hn);
|
||||||
|
struct ypldap_addr *h;
|
||||||
struct ibuf *buf;
|
struct ibuf *buf;
|
||||||
struct env *env = p;
|
struct env *env = p;
|
||||||
struct imsgev *iev = env->sc_iev;
|
struct imsgev *iev = env->sc_iev;
|
||||||
@ -176,12 +177,11 @@ dns_dispatch_imsg(int fd, short events, void *p)
|
|||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
break;
|
break;
|
||||||
if (cnt > 0) {
|
if (cnt > 0) {
|
||||||
h = hn;
|
while(!TAILQ_EMPTY(&hn)) {
|
||||||
while (h != NULL) {
|
h = TAILQ_FIRST(&hn);
|
||||||
|
TAILQ_REMOVE(&hn, h, next);
|
||||||
imsg_add(buf, &h->ss, sizeof(h->ss));
|
imsg_add(buf, &h->ss, sizeof(h->ss));
|
||||||
hn = h->next;
|
|
||||||
free(h);
|
free(h);
|
||||||
h = hn;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,13 +204,13 @@ done:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
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;
|
struct addrinfo hints, *res0, *res;
|
||||||
int error, cnt = 0;
|
int error, cnt = 0;
|
||||||
struct sockaddr_in *sa_in;
|
struct sockaddr_in *sa_in;
|
||||||
struct sockaddr_in6 *sa_in6;
|
struct sockaddr_in6 *sa_in6;
|
||||||
struct ypldap_addr *h, *hh = NULL;
|
struct ypldap_addr *h;
|
||||||
|
|
||||||
bzero(&hints, sizeof(hints));
|
bzero(&hints, sizeof(hints));
|
||||||
hints.ai_family = PF_UNSPEC;
|
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));
|
res->ai_addr)->sin6_addr, sizeof(struct in6_addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
h->next = hh;
|
TAILQ_INSERT_HEAD(hn, h, next);
|
||||||
hh = h;
|
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
freeaddrinfo(res0);
|
freeaddrinfo(res0);
|
||||||
|
|
||||||
*hn = hh;
|
|
||||||
return (cnt);
|
return (cnt);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user