3 Memory-resident database... */
6 * Copyright (c) 1995-2002 Internet Software Consortium.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of The Internet Software Consortium nor the names
19 * of its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
23 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * This software has been written for the Internet Software Consortium
37 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
38 * To learn more about the Internet Software Consortium, see
39 * ``http://www.isc.org/''. To learn more about Vixie Enterprises,
40 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
41 * ``http://www.nominum.com''.
45 static char copyright[] =
46 "$Id: memory.c,v 1.66.2.4 2002/11/17 02:26:58 dhankins Exp $ Copyright (c) 1995-2002 The Internet Software Consortium. All rights reserved.\n";
51 struct group *root_group;
52 group_hash_t *group_name_hash;
53 int (*group_write_hook) (struct group_object *);
55 isc_result_t delete_group (struct group_object *group, int writep)
57 struct group_object *d;
59 /* The group should exist and be hashed - if not, it's invalid. */
60 if (group_name_hash) {
61 d = (struct group_object *)0;
62 group_hash_lookup (&d, group_name_hash, group -> name,
63 strlen (group -> name), MDL);
65 return ISC_R_INVALIDARG;
67 return ISC_R_INVALIDARG;
69 /* Also not okay to delete a group that's not the one in
72 return ISC_R_INVALIDARG;
74 /* If it's dynamic, and we're deleting it, we can just blow away the
76 if ((group -> flags & GROUP_OBJECT_DYNAMIC) &&
77 !(group -> flags & GROUP_OBJECT_STATIC)) {
78 group_hash_delete (group_name_hash,
79 group -> name, strlen (group -> name), MDL);
81 group -> flags |= GROUP_OBJECT_DELETED;
83 group_dereference (&group -> group, MDL);
86 /* Store the group declaration in the lease file. */
87 if (writep && group_write_hook) {
88 if (!(*group_write_hook) (group))
94 isc_result_t supersede_group (struct group_object *group, int writep)
96 struct group_object *t, *u;
99 /* Register the group in the group name hash table,
100 so we can look it up later. */
101 if (group_name_hash) {
102 t = (struct group_object *)0;
103 group_hash_lookup (&t, group_name_hash,
105 strlen (group -> name), MDL);
106 if (t && t != group) {
107 /* If this isn't a dynamic entry, then we need to flag
108 the replacement as not dynamic either - otherwise,
109 if the dynamic entry is deleted later, the static
110 entry will come back next time the server is stopped
112 if (!(t -> flags & GROUP_OBJECT_DYNAMIC))
113 group -> flags |= GROUP_OBJECT_STATIC;
115 /* Delete the old object if it hasn't already been
116 deleted. If it has already been deleted, get rid of
117 the hash table entry. This is a legitimate
118 situation - a deleted static object needs to be kept
119 around so we remember it's deleted. */
120 if (!(t -> flags & GROUP_OBJECT_DELETED))
123 group_hash_delete (group_name_hash,
125 strlen (group -> name),
127 group_object_dereference (&t, MDL);
131 group_new_hash (&group_name_hash, 0, MDL);
132 t = (struct group_object *)0;
135 /* Add the group to the group name hash if it's not
136 already there, and also thread it into the list of
137 dynamic groups if appropriate. */
139 group_hash_add (group_name_hash, group -> name,
140 strlen (group -> name), group, MDL);
143 /* Store the group declaration in the lease file. */
144 if (writep && group_write_hook) {
145 if (!(*group_write_hook) (group))
146 return ISC_R_IOERROR;
148 return ISC_R_SUCCESS;
151 int clone_group (struct group **gp, struct group *group,
152 const char *file, int line)
155 struct group *g = (struct group *)0;
157 /* Normally gp should contain the null pointer, but for convenience
158 it's permissible to clone a group into itself. */
159 if (*gp && *gp != group)
161 if (!group_allocate (&g, file, line))
164 *gp = (struct group *)0;
165 group_reference (gp, g, file, line);
166 g -> authoritative = group -> authoritative;
167 group_reference (&g -> next, group, file, line);
168 group_dereference (&g, file, line);