]>
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.
25 submit_dns_answer(void *userdata
, struct DNSReply
*reply
)
27 struct dns_request
*req
= userdata
;
28 char response
[64] = "*";
33 rb_helper_write(authd_helper
, "E %s E %c *", req
->reqid
, req
->type
);
40 if (GET_SS_FAMILY(&reply
->addr
) == AF_INET
)
43 rb_inet_ntop_sock((struct sockaddr
*) &reply
->addr
, response
, sizeof(response
));
48 if (GET_SS_FAMILY(&reply
->addr
) == AF_INET6
)
51 rb_inet_ntop_sock((struct sockaddr
*) &reply
->addr
, tmpres
, sizeof(tmpres
));
55 rb_strlcpy(response
, "0", sizeof(response
));
56 rb_strlcat(response
, tmpres
, sizeof(response
));
59 rb_strlcpy(response
, tmpres
, sizeof(response
));
67 struct sockaddr_in
*ip
, *ip_fwd
;
68 ip
= (struct sockaddr_in
*) &req
->addr
;
69 ip_fwd
= (struct sockaddr_in
*) &reply
->addr
;
71 if(ip
->sin_addr
.s_addr
== ip_fwd
->sin_addr
.s_addr
&& strlen(reply
->h_name
) < 63)
73 rb_strlcpy(response
, reply
->h_name
, sizeof(response
));
81 struct sockaddr_in6
*ip
, *ip_fwd
;
82 ip
= (struct sockaddr_in6
*) &req
->addr
;
83 ip_fwd
= (struct sockaddr_in6
*) &reply
->addr
;
85 if(memcmp(&ip
->sin6_addr
, &ip_fwd
->sin6_addr
, sizeof(struct in6_addr
)) == 0 && strlen(reply
->h_name
) < 63)
87 rb_strlcpy(response
, reply
->h_name
, sizeof(response
));
97 rb_helper_write(authd_helper
, "E %s %c %c %s", req
->reqid
, status
, req
->type
, response
);
103 resolve_dns(int parc
, char *parv
[])
105 struct dns_request
*req
;
106 char *requestid
= parv
[1];
107 char *qtype
= parv
[2];
111 req
= rb_malloc(sizeof(*req
));
112 rb_strlcpy(req
->reqid
, requestid
, sizeof(req
->reqid
));
125 if(!rb_inet_pton_sock(rec
, (struct sockaddr
*) &req
->addr
))
131 req
->query
.ptr
= req
;
132 req
->query
.callback
= submit_dns_answer
;
135 gethost_byname_type(rec
, &req
->query
, type
);
137 gethost_byaddr(&req
->addr
, &req
->query
);