]>
git.ipfire.org Git - thirdparty/dhcp.git/blob - common/memory.c
8e31154aa5d1bacf6b0fab1b21cb73f8ebcfa6d9
3 Memory-resident database... */
6 * Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
7 * Copyright (c) 1995-2003 by Internet Software Consortium
9 * This Source Code Form is subject to the terms of the Mozilla Public
10 * License, v. 2.0. If a copy of the MPL was not distributed with this
11 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 * Internet Systems Consortium, Inc.
23 * Newmarket, NH 03857 USA
25 * https://www.isc.org/
31 struct group
*root_group
;
32 group_hash_t
*group_name_hash
;
33 int (*group_write_hook
) (struct group_object
*);
35 isc_result_t
delete_group (struct group_object
*group
, int writep
)
37 struct group_object
*d
;
39 /* The group should exist and be hashed - if not, it's invalid. */
40 if (group_name_hash
) {
41 d
= (struct group_object
*)0;
42 group_hash_lookup (&d
, group_name_hash
, group
-> name
,
43 strlen (group
-> name
), MDL
);
45 return DHCP_R_INVALIDARG
;
47 return DHCP_R_INVALIDARG
;
49 /* Also not okay to delete a group that's not the one in
52 return DHCP_R_INVALIDARG
;
54 /* If it's dynamic, and we're deleting it, we can just blow away the
56 if ((group
-> flags
& GROUP_OBJECT_DYNAMIC
) &&
57 !(group
-> flags
& GROUP_OBJECT_STATIC
)) {
58 group_hash_delete (group_name_hash
,
59 group
-> name
, strlen (group
-> name
), MDL
);
61 group
-> flags
|= GROUP_OBJECT_DELETED
;
63 group_dereference (&group
-> group
, MDL
);
66 /* Store the group declaration in the lease file. */
67 if (writep
&& group_write_hook
) {
68 if (!(*group_write_hook
) (group
))
74 isc_result_t
supersede_group (struct group_object
*group
, int writep
)
76 struct group_object
*t
;
78 /* Register the group in the group name hash table,
79 so we can look it up later. */
80 if (group_name_hash
) {
81 t
= (struct group_object
*)0;
82 group_hash_lookup (&t
, group_name_hash
,
84 strlen (group
-> name
), MDL
);
85 if (t
&& t
!= group
) {
86 /* If this isn't a dynamic entry, then we need to flag
87 the replacement as not dynamic either - otherwise,
88 if the dynamic entry is deleted later, the static
89 entry will come back next time the server is stopped
91 if (!(t
-> flags
& GROUP_OBJECT_DYNAMIC
))
92 group
-> flags
|= GROUP_OBJECT_STATIC
;
94 /* Delete the old object if it hasn't already been
95 deleted. If it has already been deleted, get rid of
96 the hash table entry. This is a legitimate
97 situation - a deleted static object needs to be kept
98 around so we remember it's deleted. */
99 if (!(t
-> flags
& GROUP_OBJECT_DELETED
))
102 group_hash_delete (group_name_hash
,
104 strlen (group
-> name
),
106 group_object_dereference (&t
, MDL
);
110 group_new_hash(&group_name_hash
, GROUP_HASH_SIZE
, MDL
);
111 t
= (struct group_object
*)0;
114 /* Add the group to the group name hash if it's not
115 already there, and also thread it into the list of
116 dynamic groups if appropriate. */
118 group_hash_add (group_name_hash
, group
-> name
,
119 strlen (group
-> name
), group
, MDL
);
122 /* Store the group declaration in the lease file. */
123 if (writep
&& group_write_hook
) {
124 if (!(*group_write_hook
) (group
))
125 return ISC_R_IOERROR
;
127 return ISC_R_SUCCESS
;
130 int clone_group (struct group
**gp
, struct group
*group
,
131 const char *file
, int line
)
133 struct group
*g
= (struct group
*)0;
135 /* Normally gp should contain the null pointer, but for convenience
136 it's permissible to clone a group into itself. */
137 if (*gp
&& *gp
!= group
)
139 if (!group_allocate (&g
, file
, line
))
142 *gp
= (struct group
*)0;
143 group_reference (gp
, g
, file
, line
);
144 g
-> authoritative
= group
-> authoritative
;
145 group_reference (&g
-> next
, group
, file
, line
);
146 group_dereference (&g
, file
, line
);