]>
jfr.im git - solanum.git/blob - authd/dns.c
1 /* authd/dns.h - header for authd DNS functions
2 * Copyright (c) 2016 William Pitcock <nenolod@dereferenced.org>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice is present in all copies.
8 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
9 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
11 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
12 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
14 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
15 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
16 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
17 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
18 * POSSIBILITY OF SUCH DAMAGE.
26 submit_dns_answer(void *userdata
, struct DNSReply
*reply
)
28 struct dns_request
*req
= userdata
;
29 char response
[64] = "*";
34 rb_helper_write(authd_helper
, "E %s E %c *", req
->reqid
, req
->type
);
41 if (GET_SS_FAMILY(&reply
->addr
) == AF_INET
)
44 rb_inet_ntop_sock((struct sockaddr
*) &reply
->addr
, response
, sizeof(response
));
49 if (GET_SS_FAMILY(&reply
->addr
) == AF_INET6
)
52 rb_inet_ntop_sock((struct sockaddr
*) &reply
->addr
, tmpres
, sizeof(tmpres
));
56 rb_strlcpy(response
, "0", sizeof(response
));
57 rb_strlcat(response
, tmpres
, sizeof(response
));
60 rb_strlcpy(response
, tmpres
, sizeof(response
));
68 struct sockaddr_in
*ip
, *ip_fwd
;
69 ip
= (struct sockaddr_in
*) &req
->addr
;
70 ip_fwd
= (struct sockaddr_in
*) &reply
->addr
;
72 if(ip
->sin_addr
.s_addr
== ip_fwd
->sin_addr
.s_addr
&& strlen(reply
->h_name
) < 63)
74 rb_strlcpy(response
, reply
->h_name
, sizeof(response
));
82 struct sockaddr_in6
*ip
, *ip_fwd
;
83 ip
= (struct sockaddr_in6
*) &req
->addr
;
84 ip_fwd
= (struct sockaddr_in6
*) &reply
->addr
;
86 if(memcmp(&ip
->sin6_addr
, &ip_fwd
->sin6_addr
, sizeof(struct in6_addr
)) == 0 && strlen(reply
->h_name
) < 63)
88 rb_strlcpy(response
, reply
->h_name
, sizeof(response
));
98 rb_helper_write(authd_helper
, "E %s %c %c %s", req
->reqid
, status
, req
->type
, response
);
104 resolve_dns(int parc
, char *parv
[])
106 struct dns_request
*req
;
107 char *requestid
= parv
[1];
108 char *qtype
= parv
[2];
112 req
= rb_malloc(sizeof(*req
));
113 rb_strlcpy(req
->reqid
, requestid
, sizeof(req
->reqid
));
126 if(!rb_inet_pton_sock(rec
, (struct sockaddr
*) &req
->addr
))
132 req
->query
.ptr
= req
;
133 req
->query
.callback
= submit_dns_answer
;
136 gethost_byname_type(rec
, &req
->query
, type
);
138 gethost_byaddr(&req
->addr
, &req
->query
);
142 enumerate_nameservers(const char *rid
, const char letter
)
144 char buf
[40 * IRCD_MAXNS
]; /* Plenty */
150 /* Shouldn't happen */
151 rb_helper_write(authd_helper
, "X %s %c NONAMESERVERS", rid
, letter
);
155 for(i
= 0; i
< irc_nscount
; i
++)
160 rb_inet_ntop_sock((struct sockaddr
*)&irc_nsaddr_list
[i
], addr
, sizeof(addr
));
164 /* Shouldn't happen */
165 rb_helper_write(authd_helper
, "X %s %c INVALIDNAMESERVER", rid
, letter
);
169 ret
= snprintf(c
, 40, "%s ", addr
);
175 rb_helper_write(authd_helper
, "Y %s %c %s", rid
, letter
, buf
);