]> jfr.im git - solanum.git/commitdiff
res: expose rDNS building functions
authorElizabeth Myers <redacted>
Wed, 23 Mar 2016 21:40:31 +0000 (16:40 -0500)
committerElizabeth Myers <redacted>
Wed, 23 Mar 2016 21:40:31 +0000 (16:40 -0500)
This will be used by the blacklist code to avoid duplication of code.

authd/res.c
authd/res.h

index f9db7afdc9bccfd287bd4ccb1bf6c1ef3e2a1a8b..d68e402a6ebd93fede262e1fd27c21d35270edd3 100644 (file)
@@ -465,28 +465,22 @@ static void do_query_name(struct DNSQuery *query, const char *name, struct resli
        query_name(request);
 }
 
-/*
- * do_query_number - Use this to do reverse IP# lookups.
- */
-static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_storage *addr,
-                           struct reslist *request)
+/* Build an rDNS style query - if suffix is NULL, use the appropriate .arpa zone */
+void build_rdns(char *buf, size_t size, const struct rb_sockaddr_storage *addr, const char *suffix)
 {
        const unsigned char *cp;
 
-       if (request == NULL)
-       {
-               request = make_request(query);
-               memcpy(&request->addr, addr, sizeof(struct rb_sockaddr_storage));
-               request->name = (char *)rb_malloc(IRCD_RES_HOSTLEN + 1);
-       }
-
        if (GET_SS_FAMILY(addr) == AF_INET)
        {
                const struct sockaddr_in *v4 = (const struct sockaddr_in *)addr;
                cp = (const unsigned char *)&v4->sin_addr.s_addr;
 
-               sprintf(request->queryname, "%u.%u.%u.%u.in-addr.arpa", (unsigned int)(cp[3]),
-                          (unsigned int)(cp[2]), (unsigned int)(cp[1]), (unsigned int)(cp[0]));
+               (void) snprintf(buf, size, "%u.%u.%u.%u.%s",
+                       (unsigned int)(cp[3]),
+                       (unsigned int)(cp[2]),
+                       (unsigned int)(cp[1]),
+                       (unsigned int)(cp[0]),
+                       suffix == NULL ? "in-addr.arpa" : suffix);
        }
 #ifdef RB_IPV6
        else if (GET_SS_FAMILY(addr) == AF_INET6)
@@ -494,26 +488,45 @@ static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_sto
                const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr;
                cp = (const unsigned char *)&v6->sin6_addr.s6_addr;
 
-               (void)sprintf(request->queryname, "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x."
-                             "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa",
-                             (unsigned int)(cp[15] & 0xf), (unsigned int)(cp[15] >> 4),
-                             (unsigned int)(cp[14] & 0xf), (unsigned int)(cp[14] >> 4),
-                             (unsigned int)(cp[13] & 0xf), (unsigned int)(cp[13] >> 4),
-                             (unsigned int)(cp[12] & 0xf), (unsigned int)(cp[12] >> 4),
-                             (unsigned int)(cp[11] & 0xf), (unsigned int)(cp[11] >> 4),
-                             (unsigned int)(cp[10] & 0xf), (unsigned int)(cp[10] >> 4),
-                             (unsigned int)(cp[9] & 0xf), (unsigned int)(cp[9] >> 4),
-                             (unsigned int)(cp[8] & 0xf), (unsigned int)(cp[8] >> 4),
-                             (unsigned int)(cp[7] & 0xf), (unsigned int)(cp[7] >> 4),
-                             (unsigned int)(cp[6] & 0xf), (unsigned int)(cp[6] >> 4),
-                             (unsigned int)(cp[5] & 0xf), (unsigned int)(cp[5] >> 4),
-                             (unsigned int)(cp[4] & 0xf), (unsigned int)(cp[4] >> 4),
-                             (unsigned int)(cp[3] & 0xf), (unsigned int)(cp[3] >> 4),
-                             (unsigned int)(cp[2] & 0xf), (unsigned int)(cp[2] >> 4),
-                             (unsigned int)(cp[1] & 0xf), (unsigned int)(cp[1] >> 4),
-                             (unsigned int)(cp[0] & 0xf), (unsigned int)(cp[0] >> 4));
+               (void) snprintf(buf, size,
+                       "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%s",
+                       (unsigned int)(cp[15] & 0xf), (unsigned int)(cp[15] >> 4),
+                       (unsigned int)(cp[14] & 0xf), (unsigned int)(cp[14] >> 4),
+                       (unsigned int)(cp[13] & 0xf), (unsigned int)(cp[13] >> 4),
+                       (unsigned int)(cp[12] & 0xf), (unsigned int)(cp[12] >> 4),
+                       (unsigned int)(cp[11] & 0xf), (unsigned int)(cp[11] >> 4),
+                       (unsigned int)(cp[10] & 0xf), (unsigned int)(cp[10] >> 4),
+                       (unsigned int)(cp[9] & 0xf), (unsigned int)(cp[9] >> 4),
+                       (unsigned int)(cp[8] & 0xf), (unsigned int)(cp[8] >> 4),
+                       (unsigned int)(cp[7] & 0xf), (unsigned int)(cp[7] >> 4),
+                       (unsigned int)(cp[6] & 0xf), (unsigned int)(cp[6] >> 4),
+                       (unsigned int)(cp[5] & 0xf), (unsigned int)(cp[5] >> 4),
+                       (unsigned int)(cp[4] & 0xf), (unsigned int)(cp[4] >> 4),
+                       (unsigned int)(cp[3] & 0xf), (unsigned int)(cp[3] >> 4),
+                       (unsigned int)(cp[2] & 0xf), (unsigned int)(cp[2] >> 4),
+                       (unsigned int)(cp[1] & 0xf), (unsigned int)(cp[1] >> 4),
+                       (unsigned int)(cp[0] & 0xf), (unsigned int)(cp[0] >> 4),
+                       suffix == NULL ? "ip6.arpa" : suffix);
        }
 #endif
+}
+
+/*
+ * do_query_number - Use this to do reverse IP# lookups.
+ */
+static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_storage *addr,
+                           struct reslist *request)
+{
+       const unsigned char *cp;
+
+       if (request == NULL)
+       {
+               request = make_request(query);
+               memcpy(&request->addr, addr, sizeof(struct rb_sockaddr_storage));
+               request->name = (char *)rb_malloc(IRCD_RES_HOSTLEN + 1);
+       }
+
+       build_rdns(request->queryname, IRCD_RES_HOSTLEN + 1, addr, NULL);
 
        request->type = T_PTR;
        query_name(request);
index 5a177257027d426c9b24d5f8db8b0b1584a315ee..1fabe0b22e2123244dbb10926367270fee118c97 100644 (file)
@@ -32,5 +32,6 @@ extern void init_resolver(void);
 extern void restart_resolver(void);
 extern void gethost_byname_type(const char *, struct DNSQuery *, int);
 extern void gethost_byaddr(const struct rb_sockaddr_storage *, struct DNSQuery *);
+extern void build_rdns(char *, size_t, const struct rb_sockaddr_storage *, const char *);
 
 #endif