Use dns_lookup

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@932 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1996-11-04 20:30:06 +00:00
parent 810d6ff85c
commit dc4a8b72ef

View File

@@ -73,6 +73,8 @@ RCSID("$Id$");
#include <krb.h> #include <krb.h>
#include <kafs.h> #include <kafs.h>
#include <resolve.h>
#include "afssysdefs.h" #include "afssysdefs.h"
#define AUTH_SUPERUSER "afs" #define AUTH_SUPERUSER "afs"
@@ -117,75 +119,42 @@ get_cred(char *princ, char *inst, char *krealm, CREDENTIALS *c, KTEXT_ST *tkt)
static u_int32_t ip_aton(char *ip) static u_int32_t ip_aton(char *ip)
{ {
u_int32_t addr; u_int32_t addr;
int a, b, c, d; unsigned int a, b, c, d;
if(sscanf(ip, "%d.%d.%d.%d", &a, &b, &c, &d) != 4) if(sscanf(ip, "%u.%u.%u.%u", &a, &b, &c, &d) != 4)
return 0; return 0;
if(a < 0 || a > 255 || if((a | b | c | d) > 255)
b < 0 || b > 255 || return 0;
c < 0 || c > 255 ||
d < 0 || d > 255)
return 0;
addr = (a << 24) | (b << 16) | (c << 8) | d; addr = (a << 24) | (b << 16) | (c << 8) | d;
addr = htonl(addr); addr = htonl(addr);
return addr; return addr;
} }
/* Try to get a db-server for an AFS cell from a AFSDB record */ /* Try to get a db-server for an AFS cell from a AFSDB record */
static int static int
dns_find_cell(char *cell, char *dbserver) dns_find_cell(char *cell, char *dbserver)
{ {
#if defined(HAVE_DN_EXPAND) && defined(HAVE_RES_SEARCH) struct dns_reply *r;
#ifndef T_AFSDB int ok = -1;
#define T_AFSDB 18 r = dns_lookup(cell, "afsdb");
#endif if(r){
unsigned char data[1024]; struct resource_record *rr = r->head;
unsigned char host[MaxHostNameLen]; struct mx_record *afsdb; /* afsdb and mx are identical */
int len; while(rr){
if(rr->type == T_AFSDB && rr->u.afsdb->preference == 1){
int status; strncpy(dbserver, rr->u.afsdb->domain, MaxHostNameLen);
unsigned char *p; dbserver[MaxHostNameLen - 1] = 0;
ok = 0;
len = res_search(cell, C_IN, T_AFSDB, data, sizeof(data)); break;
if(len < 0)
return -1;
p = data + sizeof(HEADER);
status = dn_expand(data, data + len, p, host, sizeof(host));
if(status < 0)
return -1;
p += status;
p += 4; /* type and class */
while(p < data + len){
int type, subtype, class, ttl, size;
status = dn_expand(data, data + len, p, host, sizeof(host));
if(status < 0)
return -1;
p += status;
type = (p[0] << 8) | p[1];
p += 2;
class = (p[0] << 8) | p[1];
p += 2;
ttl = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
p += 4;
size = (p[0] << 8) | p[1];
p += 2;
if(type == T_AFSDB){
subtype = (p[0] << 8) | p[1];
if(subtype == 1){
p += 2;
status = dn_expand(data, data + len, p, host, sizeof(host));
if(status < 0)
return -1;
strncpy(dbserver, (char*)host, MaxHostNameLen);
dbserver[MaxHostNameLen] = 0;
return 0;
} }
rr = rr->next;
} }
p += size; dns_free_data(r);
} }
#endif return ok;
return -1;
} }
/* Find the realm associated with cell. Do this by opening /* Find the realm associated with cell. Do this by opening
/usr/vice/etc/CellServDB and getting the realm-of-host for the /usr/vice/etc/CellServDB and getting the realm-of-host for the
first VL-server for the cell. first VL-server for the cell.