shishi-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CVS shishi/lib


From: shishi-commit
Subject: CVS shishi/lib
Date: Fri, 17 Sep 2004 16:58:42 +0200

Update of /home/cvs/shishi/lib
In directory dopio:/tmp/cvs-serv23399

Modified Files:
        shishi.h.in resolv.c realm.c netio.c Makefile.am 
Removed Files:
        resolver.h 
Log Message:
Make resolver API public.
Cleanup resolver.


--- /home/cvs/shishi/lib/shishi.h.in    2004/09/17 13:30:20     1.251
+++ /home/cvs/shishi/lib/shishi.h.in    2004/09/17 14:58:41     1.252
@@ -564,6 +564,32 @@
 };
 typedef struct Shishi_tkts_hint Shishi_tkts_hint;
 
+/* resolv.c */
+#define SHISHI_DNS_TXT 16
+#define SHISHI_DNS_SRV 33
+
+struct Shishi_dns_st
+{
+  struct Shishi_dns_st *next;
+
+  uint16_t class;
+  uint16_t type;
+  uint32_t ttl;
+
+  void *rr;
+};
+typedef struct Shishi_dns_st *Shishi_dns;
+
+struct Shishi_dns_srv_st
+{
+  uint16_t priority;
+  uint16_t weight;
+  uint16_t port;
+
+  char name[256];
+};
+typedef struct Shishi_dns_srv_st *Shishi_dns_srv;
+
 typedef struct Shishi Shishi;
 typedef struct Shishi_tkt Shishi_tkt;
 typedef struct Shishi_tkts Shishi_tkts;
@@ -668,8 +694,9 @@
                                    Shishi_name_type name_type,
                                    char *sname[]);
 extern int shishi_ticket_srealmserver_set (Shishi * handle,
-                                          Shishi_asn1 ticket, char *realm,
-                                          char *server);
+                                          Shishi_asn1 ticket,
+                                          const char *realm,
+                                          const char *server);
 extern int shishi_ticket_set_server (Shishi * handle, Shishi_asn1 ticket,
                                     const char *server);
 extern int shishi_ticket_realm_get (Shishi * handle,
@@ -2085,4 +2112,8 @@
 /* utils.c */
 extern time_t shishi_get_date (const char *p, const time_t * now);
 
+/* resolv.c */
+Shishi_dns shishi_resolv (const char *zone, uint16_t querytype);
+void shishi_resolv_free (Shishi_dns rrs);
+
 #endif
--- /home/cvs/shishi/lib/resolv.c       2004/09/17 14:09:25     1.9
+++ /home/cvs/shishi/lib/resolv.c       2004/09/17 14:58:41     1.10
@@ -1,6 +1,6 @@
 /* resolv.c --- Resolver glue.
  * Copyright (C) 2003, 2004  Simon Josefsson
- * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney,
+ * Copyright (C) 2002 Jeremie Miller, Thomas Muldowney,
  *                    Ryan Eatmon, Robert Norris
  *
  * This file is part of Shishi.
@@ -21,13 +21,13 @@
  *
  */
 
-#include "internal.h"
-
-/* This file comes from jabberd - Jabber Open Source Server, licensed
-   under GPL. http://www.jabberstudio.org/cgi-bin/viewcvs.cgi/jabberd2/ */
+/* This file is based on resolver.h from jabberd - Jabber Open Source
+ * Server, licensed under GPL.  See:
+ *
+ * http://www.jabberstudio.org/cgi-bin/viewcvs.cgi/jabberd2/resolver/
+ */
 
-/* Get prototypes. */
-#include "resolver.h"
+#include "internal.h"
 
 #ifdef HAVE_LIBRESOLV
 
@@ -45,12 +45,26 @@
 } dns_packet_t;
 
 static void *
-_srv_rr (dns_packet_t packet, unsigned char *eom, unsigned char **scan)
+txt_rr (dns_packet_t packet, unsigned char *eom, unsigned char **scan)
+{
+  size_t len = (size_t) ** scan;
+  char *p;
+
+  p = xmalloc (len + 1);
+  memcpy (p, *scan + 1, len);
+  p[len] = '\0';
+  *scan += (unsigned char) (len + 1);
+
+  return p;
+}
+
+static void *
+srv_rr (dns_packet_t packet, unsigned char *eom, unsigned char **scan)
 {
   unsigned int priority, weight, port;
   int len;
   char host[256];
-  dns_srv_t srv;
+  Shishi_dns_srv srv;
 
   GETSHORT (priority, *scan);
   GETSHORT (weight, *scan);
@@ -61,80 +75,69 @@
     return NULL;
   *scan = (unsigned char *) (*scan + len);
 
-  srv = (dns_srv_t) xmalloc (sizeof (struct dns_srv_st));
+  srv = xmalloc (sizeof (*srv));
 
   srv->priority = priority;
   srv->weight = weight;
   srv->port = port;
 
-  /* figure out the randomised weight */
-  /* !!! this seems wrong, but I don't have the RFC on hand */
-  if (weight != 0)
-    srv->rweight = 1 + random () % (10000 * weight);
-  else
-    srv->rweight = 0;
-
   strcpy (srv->name, host);
 
   return (void *) srv;
 }
 
-static void *
-_txt_rr (dns_packet_t packet, unsigned char *eom, unsigned char **scan)
-{
-  size_t len = (size_t) ** scan;
-  char *p;
-
-  p = xmalloc (len + 1);
-  memcpy (p, *scan + 1, len);
-  p[len] = '\0';
-  *scan += (unsigned char) (len + 1);
-
-  return p;
-}
-
 /* compare two srv structures, order by priority then by randomised weight */
 static int
-_srv_compare (const void *a, const void *b)
+srv_compare (const void *a, const void *b)
 {
-  dns_srv_t aa, bb;
+  Shishi_dns_srv aa, bb;
 
   if (a == NULL)
     return 1;
   if (b == NULL)
     return -1;
 
-  aa = (dns_srv_t) (*((dnshost_t *) a))->rr;
-  bb = (dns_srv_t) (*((dnshost_t *) b))->rr;
+  aa = (*((Shishi_dns *) a))->rr;
+  bb = (*((Shishi_dns *) b))->rr;
 
   if (aa->priority > bb->priority)
     return 1;
   if (aa->priority < bb->priority)
     return -1;
 
-  if (aa->rweight > bb->rweight)
+  if (aa->weight > bb->weight)
     return -1;
-  if (aa->rweight < bb->rweight)
+  if (aa->weight < bb->weight)
     return 1;
 
   return 0;
 }
 
-/* the actual resolver function */
-dnshost_t
-_shishi_resolv (const char *zone, unsigned int query_type)
+/**
+ * shishi_resolv:
+ * @zone: owner name of data, e.g. "EXAMPLE.ORG"
+ * @querytype: type of data to query for, e.g., SHISHI_DNS_TXT.
+ *
+ * Query DNS resolver for data of type @querytype at owner name @zone.
+ * Currently TXT and SRV types are supported.
+ *
+ * Return value: Returns linked list of DNS records, or NULL if query
+ *   failed.
+ **/
+Shishi_dns
+shishi_resolv (const char *zone, uint16_t querytype)
 {
   char host[256];
   dns_packet_t packet;
   int len, qdcount, ancount, an, n;
   unsigned char *eom, *scan;
-  dnshost_t *reply, first;
-  unsigned int type, class, ttl;
+  Shishi_dns *reply, first;
+  uint16_t type, class, ttl;
 
   if (zone == NULL || *zone == '\0')
     return NULL;
 
-  switch (query_type)
+  switch (querytype)
     {
     case T_TXT:
     case T_SRV:
@@ -145,7 +148,7 @@
     }
 
   /* do the actual query */
-  if ((len = res_query (zone, C_IN, query_type, packet.buf, MAX_PACKET)) < 0
+  if ((len = res_query (zone, C_IN, querytype, packet.buf, MAX_PACKET)) < 0
       || len < (int) sizeof (HEADER))
     return NULL;
 
@@ -172,8 +175,7 @@
     }
 
   /* create an array to store the replies in */
-  reply = (dnshost_t *) xmalloc (sizeof (dnshost_t) * ancount);
-  memset (reply, 0, sizeof (dnshost_t) * ancount);
+  reply = xcalloc (ancount, sizeof (Shishi_dns));
 
   an = 0;
   /* loop through the answer buffer and extract SRV records */
@@ -198,14 +200,14 @@
       GETSHORT (len, scan);
 
       /* skip records we're not interested in */
-      if (type != query_type)
+      if (type != querytype)
        {
          scan = (unsigned char *) (scan + len);
          continue;
        }
 
       /* create a new reply structure to save it in */
-      reply[an] = (dnshost_t) xmalloc (sizeof (struct dnshost_st));
+      reply[an] = xmalloc (sizeof (reply[0]));
 
       reply[an]->type = type;
       reply[an]->class = class;
@@ -217,11 +219,11 @@
       switch (type)
        {
        case T_TXT:
-         reply[an]->rr = _txt_rr (packet, eom, &scan);
+         reply[an]->rr = txt_rr (packet, eom, &scan);
          break;
 
        case T_SRV:
-         reply[an]->rr = _srv_rr (packet, eom, &scan);
+         reply[an]->rr = srv_rr (packet, eom, &scan);
          break;
 
        default:
@@ -242,8 +244,8 @@
     }
 
   /* sort srv records them */
-  if (query_type == T_SRV)
-    qsort (reply, an, sizeof (dnshost_t), _srv_compare);
+  if (querytype == T_SRV)
+    qsort (reply, an, sizeof (Shishi_dns), srv_compare);
 
   /* build a linked list out of the array elements */
   for (n = 0; n < an - 1; n++)
@@ -256,11 +258,26 @@
   return first;
 }
 
-/* free an srv structure */
+#else
+
+Shishi_dns
+shishi_resolv (const char *zone, uint16_t querytype)
+{
+  return NULL;
+}
+
+#endif
+
+/**
+ * shishi_resolv_free:
+ * @dns: list of DNS RR as returned by shishi_resolv().
+ *
+ * Deallocate list of DNS RR as returned by shishi_resolv().
+ **/
 void
-_shishi_resolv_free (dnshost_t dns)
+shishi_resolv_free (Shishi_dns dns)
 {
-  dnshost_t next;
+  Shishi_dns next;
 
   while (dns != NULL)
     {
@@ -271,17 +288,3 @@
     }
 }
 
-#else
-
-dnshost_t
-_shishi_resolv (const char *zone, unsigned int query_type)
-{
-  return NULL;
-}
-
-void
-_shishi_resolv_free (dnshost_t dns)
-{
-}
-
-#endif
--- /home/cvs/shishi/lib/realm.c        2004/09/02 20:04:17     1.17
+++ /home/cvs/shishi/lib/realm.c        2004/09/17 14:58:41     1.18
@@ -21,9 +21,6 @@
 
 #include "internal.h"
 
-/* Get _shishi_resolv, etc. */
-#include "resolver.h"
-
 /**
  * shishi_realm_default_guess:
  *
@@ -152,14 +149,14 @@
 char *
 shishi_realm_for_server_dns (Shishi * handle, char *server)
 {
-  dnshost_t rrs;
+  Shishi_dns rrs;
   char *tmp = NULL;
   char *p = server;
 
   do
     {
       asprintf (&tmp, "_kerberos.%s", p);
-      rrs = _shishi_resolv (tmp, T_TXT);
+      rrs = shishi_resolv (tmp, SHISHI_DNS_TXT);
       free (tmp);
       p = strchr (p, '.');
       if (p)
@@ -177,8 +174,7 @@
     }
 
   shishi_warn (handle, "DNS maps '%s' to '%s'.", server, (char *) rrs->rr);
-  shishi_warn (handle,
-              "Consider using a 'server-realm' configuration token.");
+  shishi_warn (handle, "Consider using a 'server-realm' configuration token.");
 
   return rrs->rr;
 }
--- /home/cvs/shishi/lib/netio.c        2004/09/10 10:00:00     1.37
+++ /home/cvs/shishi/lib/netio.c        2004/09/17 14:58:41     1.38
@@ -24,9 +24,6 @@
 /* Get _shishi_sendrecv_tls, etc. */
 #include "starttls.h"
 
-/* Get _shishi_resolv, etc. */
-#include "resolver.h"
-
 /* Get _shishi_realminfo, etc. */
 #include "diskio.h"
 
@@ -286,13 +283,14 @@
 static int
 shishi_kdc_sendrecv_srv_1 (Shishi * handle, char *realm,
                           const char *indata, size_t inlen,
-                          char **outdata, size_t * outlen, dnshost_t rrs)
+                          char **outdata, size_t * outlen,
+                          Shishi_dns rrs)
 {
   int rc;
 
   for (; rrs; rrs = rrs->next)
     {
-      dns_srv_t srv = (dns_srv_t) rrs->rr;
+      Shishi_dns_srv srv = rrs->rr;
       struct addrinfo hints;
       struct addrinfo *ai;
       char *port;
@@ -340,7 +338,7 @@
                         const char *indata, size_t inlen,
                         char **outdata, size_t * outlen)
 {
-  dnshost_t rrs;
+  Shishi_dns rrs;
   char *tmp;
   int rc;
 
@@ -348,7 +346,7 @@
     printf ("Finding SRV RRs for %s...\n", realm);
 
   asprintf (&tmp, "_kerberos._udp.%s", realm);
-  rrs = _shishi_resolv (tmp, T_SRV);
+  rrs = shishi_resolv (tmp, SHISHI_DNS_SRV);
   free (tmp);
 
   if (rrs)
@@ -360,7 +358,7 @@
       rc = SHISHI_KDC_NOT_KNOWN_FOR_REALM;
     }
 
-  _shishi_resolv_free (rrs);
+  shishi_resolv_free (rrs);
 
   return rc;
 }
--- /home/cvs/shishi/lib/Makefile.am    2004/08/07 14:46:26     1.65
+++ /home/cvs/shishi/lib/Makefile.am    2004/09/17 14:58:41     1.66
@@ -46,7 +46,7 @@
        netio.c key.c keys.c hostkeys.c crypto.c crypto.h crypto-ctx.c \
        asn1.c asn1.h kerberos5.c \
        version.c password.c \
-       utils.c utils.h resolv.c resolver.h
+       utils.c utils.h resolv.c
 if NULL
 libshishi_la_SOURCES += crypto-null.c
 endif





reply via email to

[Prev in Thread] Current Thread [Next in Thread]