1995-11-29 07:40:04 +00:00
|
|
|
/* memory.c
|
|
|
|
|
|
|
|
Memory-resident database... */
|
|
|
|
|
|
|
|
/*
|
2022-01-25 16:24:16 +01:00
|
|
|
* Copyright (C) 2004-2022 Internet Systems Consortium, Inc. ("ISC")
|
2005-03-17 20:15:29 +00:00
|
|
|
* Copyright (c) 1995-2003 by Internet Software Consortium
|
1995-11-29 07:40:04 +00:00
|
|
|
*
|
2017-07-12 09:23:23 -04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
1995-11-29 07:40:04 +00:00
|
|
|
*
|
2005-03-17 20:15:29 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
|
|
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
1995-11-29 07:40:04 +00:00
|
|
|
*
|
2005-03-17 20:15:29 +00:00
|
|
|
* Internet Systems Consortium, Inc.
|
2022-01-19 20:13:19 +01:00
|
|
|
* PO Box 360
|
|
|
|
* Newmarket, NH 03857 USA
|
2005-03-17 20:15:29 +00:00
|
|
|
* <info@isc.org>
|
2009-07-23 18:52:21 +00:00
|
|
|
* https://www.isc.org/
|
2000-03-17 04:00:32 +00:00
|
|
|
*
|
1995-11-29 07:40:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dhcpd.h"
|
|
|
|
|
2000-05-16 23:03:49 +00:00
|
|
|
struct group *root_group;
|
2005-03-17 20:15:29 +00:00
|
|
|
group_hash_t *group_name_hash;
|
2000-05-16 23:03:49 +00:00
|
|
|
int (*group_write_hook) (struct group_object *);
|
|
|
|
|
|
|
|
isc_result_t delete_group (struct group_object *group, int writep)
|
1996-08-27 09:51:24 +00:00
|
|
|
{
|
2000-05-16 23:03:49 +00:00
|
|
|
struct group_object *d;
|
|
|
|
|
|
|
|
/* The group should exist and be hashed - if not, it's invalid. */
|
|
|
|
if (group_name_hash) {
|
|
|
|
d = (struct group_object *)0;
|
|
|
|
group_hash_lookup (&d, group_name_hash, group -> name,
|
|
|
|
strlen (group -> name), MDL);
|
|
|
|
} else
|
2009-10-28 04:12:30 +00:00
|
|
|
return DHCP_R_INVALIDARG;
|
2000-05-16 23:03:49 +00:00
|
|
|
if (!d)
|
2009-10-28 04:12:30 +00:00
|
|
|
return DHCP_R_INVALIDARG;
|
2000-05-16 23:03:49 +00:00
|
|
|
|
|
|
|
/* Also not okay to delete a group that's not the one in
|
|
|
|
the hash table. */
|
|
|
|
if (d != group)
|
2009-10-28 04:12:30 +00:00
|
|
|
return DHCP_R_INVALIDARG;
|
2000-05-16 23:03:49 +00:00
|
|
|
|
|
|
|
/* If it's dynamic, and we're deleting it, we can just blow away the
|
|
|
|
hash table entry. */
|
|
|
|
if ((group -> flags & GROUP_OBJECT_DYNAMIC) &&
|
|
|
|
!(group -> flags & GROUP_OBJECT_STATIC)) {
|
|
|
|
group_hash_delete (group_name_hash,
|
|
|
|
group -> name, strlen (group -> name), MDL);
|
|
|
|
} else {
|
|
|
|
group -> flags |= GROUP_OBJECT_DELETED;
|
|
|
|
if (group -> group)
|
|
|
|
group_dereference (&group -> group, MDL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store the group declaration in the lease file. */
|
|
|
|
if (writep && group_write_hook) {
|
|
|
|
if (!(*group_write_hook) (group))
|
|
|
|
return ISC_R_IOERROR;
|
|
|
|
}
|
|
|
|
return ISC_R_SUCCESS;
|
1996-08-27 09:51:24 +00:00
|
|
|
}
|
|
|
|
|
2000-05-16 23:03:49 +00:00
|
|
|
isc_result_t supersede_group (struct group_object *group, int writep)
|
|
|
|
{
|
2007-07-13 06:43:43 +00:00
|
|
|
struct group_object *t;
|
2000-05-16 23:03:49 +00:00
|
|
|
|
|
|
|
/* Register the group in the group name hash table,
|
|
|
|
so we can look it up later. */
|
|
|
|
if (group_name_hash) {
|
|
|
|
t = (struct group_object *)0;
|
|
|
|
group_hash_lookup (&t, group_name_hash,
|
|
|
|
group -> name,
|
|
|
|
strlen (group -> name), MDL);
|
|
|
|
if (t && t != group) {
|
|
|
|
/* If this isn't a dynamic entry, then we need to flag
|
|
|
|
the replacement as not dynamic either - otherwise,
|
|
|
|
if the dynamic entry is deleted later, the static
|
|
|
|
entry will come back next time the server is stopped
|
|
|
|
and restarted. */
|
|
|
|
if (!(t -> flags & GROUP_OBJECT_DYNAMIC))
|
|
|
|
group -> flags |= GROUP_OBJECT_STATIC;
|
|
|
|
|
|
|
|
/* Delete the old object if it hasn't already been
|
|
|
|
deleted. If it has already been deleted, get rid of
|
|
|
|
the hash table entry. This is a legitimate
|
|
|
|
situation - a deleted static object needs to be kept
|
|
|
|
around so we remember it's deleted. */
|
|
|
|
if (!(t -> flags & GROUP_OBJECT_DELETED))
|
|
|
|
delete_group (t, 0);
|
|
|
|
else {
|
|
|
|
group_hash_delete (group_name_hash,
|
|
|
|
group -> name,
|
|
|
|
strlen (group -> name),
|
|
|
|
MDL);
|
|
|
|
group_object_dereference (&t, MDL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2006-06-01 20:23:18 +00:00
|
|
|
group_new_hash(&group_name_hash, GROUP_HASH_SIZE, MDL);
|
2000-05-16 23:03:49 +00:00
|
|
|
t = (struct group_object *)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the group to the group name hash if it's not
|
|
|
|
already there, and also thread it into the list of
|
|
|
|
dynamic groups if appropriate. */
|
|
|
|
if (!t) {
|
|
|
|
group_hash_add (group_name_hash, group -> name,
|
|
|
|
strlen (group -> name), group, MDL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store the group declaration in the lease file. */
|
|
|
|
if (writep && group_write_hook) {
|
|
|
|
if (!(*group_write_hook) (group))
|
|
|
|
return ISC_R_IOERROR;
|
|
|
|
}
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int clone_group (struct group **gp, struct group *group,
|
|
|
|
const char *file, int line)
|
|
|
|
{
|
|
|
|
struct group *g = (struct group *)0;
|
|
|
|
|
|
|
|
/* Normally gp should contain the null pointer, but for convenience
|
|
|
|
it's permissible to clone a group into itself. */
|
|
|
|
if (*gp && *gp != group)
|
|
|
|
return 0;
|
|
|
|
if (!group_allocate (&g, file, line))
|
|
|
|
return 0;
|
|
|
|
if (group == *gp)
|
|
|
|
*gp = (struct group *)0;
|
2001-06-27 00:31:20 +00:00
|
|
|
group_reference (gp, g, file, line);
|
2000-05-16 23:03:49 +00:00
|
|
|
g -> authoritative = group -> authoritative;
|
2001-06-27 00:31:20 +00:00
|
|
|
group_reference (&g -> next, group, file, line);
|
|
|
|
group_dereference (&g, file, line);
|
2000-05-16 23:03:49 +00:00
|
|
|
return 1;
|
|
|
|
}
|