Commit 7d9784f6 authored by Ted Lemon's avatar Ted Lemon
Browse files

Patch in TSIG, just to see how to get it to work.

parent 49733f31
......@@ -43,7 +43,7 @@
#ifndef lint
static char ocopyright[] =
"$Id: auth.c,v 1.5 2000/03/17 03:59:00 mellon Exp $ Copyright 1998-2000 The Internet Software Consortium.";
"$Id: auth.c,v 1.6 2000/03/18 02:15:36 mellon Exp $ Copyright 1998-2000 The Internet Software Consortium.";
#endif
#include "dhcpd.h"
......@@ -55,7 +55,7 @@ void enter_auth_key (key_id, key)
struct auth_key *key;
{
if (!auth_key_hash)
auth_key_hash = new_hash (0, 0);
auth_key_hash = new_hash (0, 0, 0);
if (!auth_key_hash)
log_fatal ("Can't allocate authentication key hash.");
add_hash (auth_key_hash, key_id -> data, key_id -> len,
......
......@@ -34,16 +34,15 @@
* SUCH DAMAGE.
*
* This software has been written for the Internet Software Consortium
* by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
* by Ted Lemon in cooperation with Nominum, Inc.
* To learn more about the Internet Software Consortium, see
* ``http://www.isc.org/''. To learn more about Vixie Enterprises,
* see ``http://www.vix.com''. To learn more about Nominum, Inc., see
* ``http://www.isc.org/''. To learn more about Nominum, Inc., see
* ``http://www.nominum.com''.
*/
#ifndef lint
static char copyright[] =
"$Id: dns.c,v 1.18 2000/03/17 03:59:01 mellon Exp $ Copyright (c) 2000 The Internet Software Consortium. All rights reserved.\n";
"$Id: dns.c,v 1.19 2000/03/18 02:15:36 mellon Exp $ Copyright (c) 2000 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
......@@ -129,6 +128,60 @@ static char copyright[] =
struct hash_table *tsig_key_hash;
struct hash_table *dns_zone_hash;
#if defined (NSUPDATE)
isc_result_t find_tsig_key (ns_tsig_key **key, const char *zname)
{
struct dns_zone *zone;
isc_result_t status;
ns_tsig_key *tkey;
zone = (struct dns_zone *)0;
status = dns_zone_lookup (&zone, zname);
if (status != ISC_R_SUCCESS)
return status;
if (!zone -> key) {
dns_zone_dereference (&zone, MDL);
return ISC_R_KEY_UNKNOWN;
}
if ((!zone -> key -> name ||
strlen (zone -> key -> name) > NS_MAXDNAME) ||
(!zone -> key -> algorithm ||
strlen (zone -> key -> algorithm) > NS_MAXDNAME) ||
(!zone -> key -> key.len)) {
dns_zone_dereference (&zone, MDL);
return ISC_R_INVALIDKEY;
}
tkey = dmalloc (sizeof *tkey, MDL);
if (!tkey) {
nomem:
dns_zone_dereference (&zone, MDL);
return ISC_R_NOMEMORY;
}
memset (tkey, 0, sizeof *tkey);
tkey -> data = dmalloc (zone -> key -> key.len, MDL);
if (!tkey -> data) {
dfree (tkey, MDL);
goto nomem;
}
strcpy (tkey -> name, zone -> key -> name);
strcpy (tkey -> alg, zone -> key -> algorithm);
memcpy (tkey -> data,
zone -> key -> key.data, zone -> key -> key.len);
tkey -> len = zone -> key -> key.len;
*key = tkey;
return ISC_R_SUCCESS;
}
void tkey_free (ns_tsig_key **key)
{
if ((*key) -> data)
dfree ((*key) -> data, MDL);
dfree ((*key), MDL);
*key = (ns_tsig_key *)0;
}
#endif
isc_result_t enter_dns_zone (struct dns_zone *zone)
{
struct dns_zone *tz;
......@@ -142,7 +195,7 @@ isc_result_t enter_dns_zone (struct dns_zone *zone)
} else {
dns_zone_hash =
new_hash ((hash_reference)dns_zone_reference,
(hash_dereference)dns_zone_dereference);
(hash_dereference)dns_zone_dereference, 1);
if (!dns_zone_hash)
return ISC_R_NOMEMORY;
}
......@@ -176,7 +229,7 @@ isc_result_t enter_tsig_key (struct tsig_key *tkey)
} else {
tsig_key_hash =
new_hash ((hash_reference)tsig_key_reference,
(hash_dereference)tsig_key_dereference);
(hash_dereference)tsig_key_dereference, 1);
if (!tsig_key_hash)
return ISC_R_NOMEMORY;
}
......
......@@ -43,15 +43,18 @@
#ifndef lint
static char copyright[] =
"$Id: hash.c,v 1.18 2000/03/17 03:59:01 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
"$Id: hash.c,v 1.19 2000/03/18 02:15:36 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
#include <ctype.h>
static INLINE int do_hash PROTO ((const unsigned char *, unsigned, unsigned));
static int do_hash PROTO ((const unsigned char *, unsigned, unsigned));
static int do_case_hash PROTO ((const unsigned char *, unsigned, unsigned));
struct hash_table *new_hash (hash_reference referencer,
hash_dereference dereferencer)
hash_dereference dereferencer,
int casep)
{
struct hash_table *rv = new_hash_table (DEFAULT_HASH_SIZE, MDL);
if (!rv)
......@@ -60,10 +63,17 @@ struct hash_table *new_hash (hash_reference referencer,
DEFAULT_HASH_SIZE * sizeof (struct hash_bucket *));
rv -> referencer = referencer;
rv -> dereferencer = dereferencer;
if (casep) {
rv -> cmp = casecmp;
rv -> do_hash = do_case_hash;
} else {
rv -> cmp = memcmp;
rv -> do_hash = do_hash;
}
return rv;
}
static INLINE int do_hash (name, len, size)
static int do_case_hash (name, len, size)
const unsigned char *name;
unsigned len;
unsigned size;
......@@ -71,6 +81,33 @@ static INLINE int do_hash (name, len, size)
register int accum = 0;
register const unsigned char *s = (const unsigned char *)name;
int i = len;
register unsigned c;
while (i--) {
/* Make the hash case-insensitive. */
c = *s++;
if (isascii (c) && isupper (c))
c = tolower (c);
/* Add the character in... */
accum += *s++;
/* Add carry back in... */
while (accum > 255) {
accum = (accum & 255) + (accum >> 8);
}
}
return accum % size;
}
static int do_hash (name, len, size)
const unsigned char *name;
unsigned len;
unsigned size;
{
register int accum = 0;
register const unsigned char *s = (const unsigned char *)name;
int i = len;
while (i--) {
/* Add the character in... */
accum += *s++;
......@@ -98,7 +135,7 @@ void add_hash (table, name, len, pointer)
if (!len)
len = strlen ((const char *)name);
hashno = do_hash (name, len, table -> hash_count);
hashno = (*table -> do_hash) (name, len, table -> hash_count);
bp = new_hash_bucket (MDL);
if (!bp) {
......@@ -131,7 +168,7 @@ void delete_hash_entry (table, name, len)
if (!len)
len = strlen ((const char *)name);
hashno = do_hash (name, len, table -> hash_count);
hashno = (*table -> do_hash) (name, len, table -> hash_count);
/* Go through the list looking for an entry that matches;
if we find it, delete it. */
......@@ -139,7 +176,7 @@ void delete_hash_entry (table, name, len)
if ((!bp -> len &&
!strcmp ((const char *)bp -> name, (const char *)name)) ||
(bp -> len == len &&
!memcmp (bp -> name, name, len))) {
!(*table -> cmp) (bp -> name, name, len))) {
if (pbp) {
pbp -> next = bp -> next;
} else {
......@@ -169,13 +206,39 @@ void *hash_lookup (table, name, len)
if (!len)
len = strlen ((const char *)name);
hashno = do_hash (name, len, table -> hash_count);
hashno = (*table -> do_hash) (name, len, table -> hash_count);
for (bp = table -> buckets [hashno]; bp; bp = bp -> next) {
if (len == bp -> len
&& !memcmp (bp -> name, name, len))
&& !(*table -> cmp) (bp -> name, name, len))
return bp -> value;
}
return (unsigned char *)0;
}
int casecmp (const void *v1, const void *v2, unsigned len)
{
unsigned i;
const char *s = v1;
const char *t = v2;
for (i = 0; i < len; i++)
{
int c1, c2;
if (isascii (s [i]) && isupper (s [i]))
c1 = tolower (s [i]);
else
c1 = s [i];
if (isascii (t [i]) && isupper (t [i]))
c2 = tolower (t [i]);
else
c2 = t [i];
if (c1 < c2)
return -1;
if (c1 > c2)
return 1;
}
return 0;
}
......@@ -43,7 +43,7 @@
#ifndef lint
static char copyright[] =
"$Id: parse.c,v 1.66 2000/03/17 03:59:01 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
"$Id: parse.c,v 1.67 2000/03/18 02:15:37 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
......@@ -904,7 +904,7 @@ void parse_option_space_decl (cfile)
universes = ua;
}
universes [nu -> index] = nu;
nu -> hash = new_hash (0, 0);
nu -> hash = new_hash (0, 0, 1);
if (!nu -> hash)
log_fatal ("Can't allocate %s option hash table.", nu -> name);
add_hash (&universe_hash,
......
......@@ -43,7 +43,7 @@
#ifndef lint
static char copyright[] =
"$Id: tables.c,v 1.38 2000/03/17 03:59:02 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
"$Id: tables.c,v 1.39 2000/03/18 02:15:37 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
......@@ -883,7 +883,7 @@ void initialize_common_option_spaces()
dhcp_universe.store_length = putUChar;
dhcp_universe.index = universe_count++;
universes [dhcp_universe.index] = &dhcp_universe;
dhcp_universe.hash = new_hash (0, 0);
dhcp_universe.hash = new_hash (0, 0, 1);
if (!dhcp_universe.hash)
log_fatal ("Can't allocate dhcp option hash table.");
for (i = 0; i < 256; i++) {
......@@ -909,7 +909,7 @@ void initialize_common_option_spaces()
nwip_universe.store_length = putUChar;
nwip_universe.index = universe_count++;
universes [nwip_universe.index] = &nwip_universe;
nwip_universe.hash = new_hash (0, 0);
nwip_universe.hash = new_hash (0, 0, 1);
if (!nwip_universe.hash)
log_fatal ("Can't allocate dhcp option hash table.");
for (i = 0; i < 256; i++) {
......
......@@ -43,7 +43,7 @@
#ifndef lint
static char copyright[] =
"$Id: tree.c,v 1.79 2000/03/17 03:59:02 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
"$Id: tree.c,v 1.80 2000/03/18 02:15:37 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
......@@ -859,6 +859,11 @@ int evaluate_dns_expression (result, packet, lease, in_options,
expr -> op);
return 0;
case expr_function:
log_error ("Function opcode in evaluate_dns_expression: %d",
expr -> op);
return 0;
case expr_arg:
break;
}
......@@ -2135,7 +2140,7 @@ int evaluate_numeric_expression (result, packet, lease,
/* Do the update and record the error code, if there was
an error; otherwise set it to NOERROR. */
*result = minires_nupdate (&res, ISC_LIST_HEAD (uq), NULL);
*result = minires_nupdate (&res, ISC_LIST_HEAD (uq));
status = 1;
print_dns_status ((int)*result, &uq);
......
......@@ -1473,13 +1473,14 @@ struct protocol *add_protocol PROTO ((const char *, int,
void remove_protocol PROTO ((struct protocol *));
/* hash.c */
struct hash_table *new_hash PROTO ((hash_reference, hash_dereference));
struct hash_table *new_hash PROTO ((hash_reference, hash_dereference, int));
void add_hash PROTO ((struct hash_table *,
const unsigned char *, unsigned, void *));
void delete_hash_entry PROTO ((struct hash_table *,
const unsigned char *, unsigned));
void *hash_lookup PROTO ((struct hash_table *,
const unsigned char *, unsigned));
int casecmp (const void *s, const void *t, unsigned len);
/* tables.c */
extern struct universe dhcp_universe;
......@@ -1707,6 +1708,10 @@ int icmp_echorequest PROTO ((struct iaddr *));
isc_result_t icmp_echoreply PROTO ((omapi_object_t *));
/* dns.c */
#if defined (NSUPDATE)
isc_result_t find_tsig_key (ns_tsig_key **, const char *);
void tkey_free (ns_tsig_key **);
#endif
isc_result_t enter_dns_zone (struct dns_zone *);
isc_result_t dns_zone_lookup (struct dns_zone **, const char *);
isc_result_t enter_tsig_key (struct tsig_key *);
......
......@@ -58,6 +58,8 @@ struct hash_table {
struct hash_bucket *buckets [DEFAULT_HASH_SIZE];
hash_reference referencer;
hash_dereference dereferencer;
int (*cmp) (const void *, const void *, size_t);
int (*do_hash) (const unsigned char *, unsigned, unsigned);
};
struct named_hash {
......
......@@ -72,8 +72,10 @@ ISC_LANG_BEGINDECLS
#define ISC_R_KEYCONFLICT 44
#define ISC_R_BADPARSE 45
#define ISC_R_NOKEYS 46
#define ISC_R_KEY_UNKNOWN 47
#define ISC_R_INVALIDKEY 48
#define ISC_R_NRESULTS 47 /* Number of results */
#define ISC_R_NRESULTS 49 /* Number of results */
const char * isc_result_totext(isc_result_t);
isc_result_t isc_result_register(unsigned int base,
......
......@@ -32,7 +32,7 @@ ns_updrec *minires_mkupdrec (int, const char *, unsigned int,
unsigned int, unsigned long);
void minires_freeupdrec (ns_updrec *);
int minires_nmkupdate (res_state, ns_updrec *, unsigned char *, unsigned);
ns_rcode minires_nupdate (res_state, ns_updrec *, ns_tsig_key *);
ns_rcode minires_nupdate (res_state, ns_updrec *);
int minires_ninit (res_state);
#if defined (MINIRES_LIB)
......
#if !defined(lint) && !defined(SABER)
static const char rcsid[] = "$Id: res_update.c,v 1.3 2000/02/03 04:33:03 mellon Exp $";
static const char rcsid[] = "$Id: res_update.c,v 1.4 2000/03/18 02:15:49 mellon Exp $";
#endif /* not lint */
/*
......@@ -75,8 +75,11 @@ static int nscopy(struct sockaddr_in *, const struct sockaddr_in *, int);
static int nsprom(struct sockaddr_in *, const struct in_addr *, int);
static void dprintf(const char *, ...);
void tkey_free (ns_tsig_key **);
int find_tsig_key (ns_tsig_key **, const char *);
ns_rcode
res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) {
res_nupdate(res_state statp, ns_updrec *rrecp_in) {
ns_updrec *rrecp;
u_char answer[PACKETSZ], packet[2*PACKETSZ];
struct zonegrp *zptr, tgrp;
......@@ -84,6 +87,7 @@ res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) {
unsigned n;
struct sockaddr_in nsaddrs[MAXNS];
ns_rcode rcode;
ns_tsig_key *key;
/* Make sure all the updates are in the same zone, and find out
what zone they are in. */
......@@ -144,11 +148,14 @@ res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) {
zptr->z_nsaddrs, zptr->z_nscount);
/* Send the update and remember the result. */
if (key != NULL)
key = (ns_tsig_key *)0;
if (!find_tsig_key (&key, zptr->z_origin)) {
n = res_nsendsigned(statp, packet, n, key,
answer, sizeof answer);
else
tkey_free (&key);
} else {
n = res_nsend(statp, packet, n, answer, sizeof answer);
}
if (n < 0) {
rcode = -1;
goto undone;
......
......@@ -92,6 +92,8 @@ static const char *text[ISC_R_NRESULTS] = {
"key conflict", /* 44 */
"parse error(s) occurred", /* 45 */
"no key specified", /* 46 */
"zone TSIG key not known", /* 47 */
"invalid TSIG key", /* 48 */
};
const char *isc_result_totext (isc_result_t result)
......
......@@ -43,7 +43,7 @@
#ifndef lint
static char copyright[] =
"$Id: class.c,v 1.18 2000/03/17 04:00:30 mellon Exp $ Copyright (c) 1998-2000 The Internet Software Consortium. All rights reserved.\n";
"$Id: class.c,v 1.19 2000/03/18 02:15:52 mellon Exp $ Copyright (c) 1998-2000 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
......@@ -167,7 +167,7 @@ int check_collection (packet, lease, collection)
MDL);
data_string_forget (&data, MDL);
if (!class -> hash)
class -> hash = new_hash (0, 0);
class -> hash = new_hash (0, 0, 0);
add_hash (class -> hash,
nc -> hash_string.data,
nc -> hash_string.len,
......
......@@ -43,7 +43,7 @@
#ifndef lint
static char copyright[] =
"$Id: confpars.c,v 1.104 2000/03/17 04:00:31 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
"$Id: confpars.c,v 1.105 2000/03/18 02:15:52 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
......@@ -1401,7 +1401,7 @@ struct class *parse_class_declaration (cfile, group, type)
}
data_string_copy (&class -> hash_string, &data, MDL);
if (!pc -> hash)
pc -> hash = new_hash (0, 0);
pc -> hash = new_hash (0, 0, 0);
add_hash (pc -> hash,
class -> hash_string.data,
class -> hash_string.len,
......
......@@ -43,7 +43,7 @@
#ifndef lint
static char copyright[] =
"$Id: mdb.c,v 1.28 2000/03/17 04:00:31 mellon Exp $ Copyright (c) 1996-2000 The Internet Software Consortium. All rights reserved.\n";
"$Id: mdb.c,v 1.29 2000/03/18 02:15:52 mellon Exp $ Copyright (c) 1996-2000 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
......@@ -72,7 +72,7 @@ isc_result_t enter_host (hd, dynamicp, commit)
struct executable_statement *esp;
if (!host_name_hash) {
host_name_hash = new_hash (0, 0);
host_name_hash = new_hash (0, 0, 0);
if (!host_name_hash)
log_fatal ("Can't allocate host name hash");
} else {
......@@ -113,7 +113,7 @@ isc_result_t enter_host (hd, dynamicp, commit)
if (hd -> interface.hlen) {
if (!host_hw_addr_hash) {
host_hw_addr_hash = new_hash (0, 0);
host_hw_addr_hash = new_hash (0, 0, 0);
if (!host_hw_addr_hash)
log_fatal ("Can't allocate host/hw hash");
} else
......@@ -167,7 +167,7 @@ isc_result_t enter_host (hd, dynamicp, commit)
/* If there's no uid hash, make one; otherwise, see if
there's already an entry in the hash for this host. */
if (!host_uid_hash) {
host_uid_hash = new_hash (0, 0);
host_uid_hash = new_hash (0, 0, 0);
if (!host_uid_hash)
log_fatal ("Can't allocate host/uid hash");
hp = (struct host_decl *)0;
......@@ -489,7 +489,7 @@ isc_result_t supersede_group (struct group_object *group, int writep)
}
}
} else {
group_name_hash = new_hash (0, 0);
group_name_hash = new_hash (0, 0, 0);
t = (struct group_object *)0;
}
......@@ -534,17 +534,17 @@ void new_address_range (low, high, subnet, pool)
/* Initialize the hash table if it hasn't been done yet. */
if (!lease_uid_hash) {
lease_uid_hash = new_hash (0, 0);
lease_uid_hash = new_hash (0, 0, 0);
if (!lease_uid_hash)
log_fatal ("Can't allocate lease/uid hash");
}
if (!lease_ip_addr_hash) {
lease_ip_addr_hash = new_hash (0, 0);
lease_ip_addr_hash = new_hash (0, 0, 0);
if (!lease_uid_hash)
log_fatal ("Can't allocate lease/ip hash");
}
if (!lease_hw_addr_hash) {
lease_hw_addr_hash = new_hash (0, 0);
lease_hw_addr_hash = new_hash (0, 0, 0);
if (!lease_uid_hash)
log_fatal ("Can't allocate lease/hw hash");
}
......
......@@ -43,7 +43,7 @@
#ifndef lint
static char copyright[] =
"$Id: stables.c,v 1.8 2000/03/17 04:00:32 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
"$Id: stables.c,v 1.9 2000/03/18 02:15:52 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
......@@ -711,7 +711,7 @@ void initialize_server_option_spaces()
agent_universe.store_tag = putUChar;
agent_universe.store_length = putUChar;
universes [agent_universe.index] = &agent_universe;
agent_universe.hash = new_hash (0, 0);
agent_universe.hash = new_hash (0, 0, 1);
if (!agent_universe.hash)
log_fatal ("Can't allocate agent option hash table.");
for (i = 0; i < 256; i++) {
......@@ -737,7 +737,7 @@ void initialize_server_option_spaces()
server_universe.store_length = putUChar;
server_universe.index = universe_count++;
universes [server_universe.index] = &server_universe;
server_universe.hash = new_hash (0, 0);
server_universe.hash = new_hash (0, 0, 1);
if (!server_universe.hash)
log_fatal ("Can't allocate server option hash table.");
for (i = 0; i < 256; i++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment