00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "dhcpd.h"
00030
00031 struct group *root_group;
00032 group_hash_t *group_name_hash;
00033 int (*group_write_hook) (struct group_object *);
00034
00035 isc_result_t delete_group (struct group_object *group, int writep)
00036 {
00037 struct group_object *d;
00038
00039
00040 if (group_name_hash) {
00041 d = (struct group_object *)0;
00042 group_hash_lookup (&d, group_name_hash, group -> name,
00043 strlen (group -> name), MDL);
00044 } else
00045 return DHCP_R_INVALIDARG;
00046 if (!d)
00047 return DHCP_R_INVALIDARG;
00048
00049
00050
00051 if (d != group)
00052 return DHCP_R_INVALIDARG;
00053
00054
00055
00056 if ((group -> flags & GROUP_OBJECT_DYNAMIC) &&
00057 !(group -> flags & GROUP_OBJECT_STATIC)) {
00058 group_hash_delete (group_name_hash,
00059 group -> name, strlen (group -> name), MDL);
00060 } else {
00061 group -> flags |= GROUP_OBJECT_DELETED;
00062 if (group -> group)
00063 group_dereference (&group -> group, MDL);
00064 }
00065
00066
00067 if (writep && group_write_hook) {
00068 if (!(*group_write_hook) (group))
00069 return ISC_R_IOERROR;
00070 }
00071 return ISC_R_SUCCESS;
00072 }
00073
00074 isc_result_t supersede_group (struct group_object *group, int writep)
00075 {
00076 struct group_object *t;
00077
00078
00079
00080 if (group_name_hash) {
00081 t = (struct group_object *)0;
00082 group_hash_lookup (&t, group_name_hash,
00083 group -> name,
00084 strlen (group -> name), MDL);
00085 if (t && t != group) {
00086
00087
00088
00089
00090
00091 if (!(t -> flags & GROUP_OBJECT_DYNAMIC))
00092 group -> flags |= GROUP_OBJECT_STATIC;
00093
00094
00095
00096
00097
00098
00099 if (!(t -> flags & GROUP_OBJECT_DELETED))
00100 delete_group (t, 0);
00101 else {
00102 group_hash_delete (group_name_hash,
00103 group -> name,
00104 strlen (group -> name),
00105 MDL);
00106 group_object_dereference (&t, MDL);
00107 }
00108 }
00109 } else {
00110 group_new_hash(&group_name_hash, GROUP_HASH_SIZE, MDL);
00111 t = (struct group_object *)0;
00112 }
00113
00114
00115
00116
00117 if (!t) {
00118 group_hash_add (group_name_hash, group -> name,
00119 strlen (group -> name), group, MDL);
00120 }
00121
00122
00123 if (writep && group_write_hook) {
00124 if (!(*group_write_hook) (group))
00125 return ISC_R_IOERROR;
00126 }
00127 return ISC_R_SUCCESS;
00128 }
00129
00130 int clone_group (struct group **gp, struct group *group,
00131 const char *file, int line)
00132 {
00133 struct group *g = (struct group *)0;
00134
00135
00136
00137 if (*gp && *gp != group)
00138 return 0;
00139 if (!group_allocate (&g, file, line))
00140 return 0;
00141 if (group == *gp)
00142 *gp = (struct group *)0;
00143 group_reference (gp, g, file, line);
00144 g -> authoritative = group -> authoritative;
00145 group_reference (&g -> next, group, file, line);
00146 group_dereference (&g, file, line);
00147 return 1;
00148 }