25
25
#define DBGC_CLASS DBGC_REGISTRY
27
struct regsubkey_ctr {
30
struct db_context *subkeys_hash;
27
34
/**********************************************************************
29
Note that the REGSUB_CTR and REGVAL_CTR objects *must* be talloc()'d
30
since the methods use the object pointer as the talloc context for
31
internal private data.
36
Note that the struct regsubkey_ctr and REGVAL_CTR objects *must* be
37
talloc()'d since the methods use the object pointer as the talloc
38
context for internal private data.
33
There is no longer a regXXX_ctr_intit() and regXXX_ctr_destroy()
40
There is no longer a regval_ctr_intit() and regval_ctr_destroy()
34
41
pair of functions. Simply TALLOC_ZERO_P() and TALLOC_FREE() the
37
44
**********************************************************************/
46
WERROR regsubkey_ctr_init(TALLOC_CTX *mem_ctx, struct regsubkey_ctr **ctr)
49
return WERR_INVALID_PARAM;
52
*ctr = talloc_zero(mem_ctx, struct regsubkey_ctr);
57
(*ctr)->subkeys_hash = db_open_rbt(*ctr);
58
if ((*ctr)->subkeys_hash == NULL) {
66
WERROR regsubkey_ctr_set_seqnum(struct regsubkey_ctr *ctr, int seqnum)
69
return WERR_INVALID_PARAM;
77
int regsubkey_ctr_get_seqnum(struct regsubkey_ctr *ctr)
86
static WERROR regsubkey_ctr_hash_keyname(struct regsubkey_ctr *ctr,
92
werr = ntstatus_to_werror(dbwrap_store_bystring(ctr->subkeys_hash,
94
make_tdb_data((uint8 *)&idx,
97
if (!W_ERROR_IS_OK(werr)) {
98
DEBUG(1, ("error hashing new key '%s' in container: %s\n",
99
keyname, dos_errstr(werr)));
105
static WERROR regsubkey_ctr_unhash_keyname(struct regsubkey_ctr *ctr,
110
werr = ntstatus_to_werror(dbwrap_delete_bystring(ctr->subkeys_hash,
112
if (!W_ERROR_IS_OK(werr)) {
113
DEBUG(1, ("error unhashing key '%s' in container: %s\n",
114
keyname, dos_errstr(werr)));
120
static WERROR regsubkey_ctr_index_for_keyname(struct regsubkey_ctr *ctr,
126
if ((ctr == NULL) || (keyname == NULL)) {
127
return WERR_INVALID_PARAM;
130
data = dbwrap_fetch_bystring(ctr->subkeys_hash, ctr, keyname);
131
if (data.dptr == NULL) {
132
return WERR_NOT_FOUND;
135
if (data.dsize != sizeof(*idx)) {
136
talloc_free(data.dptr);
137
return WERR_INVALID_DATATYPE;
141
*idx = *(uint32 *)data.dptr;
144
talloc_free(data.dptr);
39
148
/***********************************************************************
40
149
Add a new key to the array
41
150
**********************************************************************/
43
WERROR regsubkey_ctr_addkey( REGSUBKEY_CTR *ctr, const char *keyname )
152
WERROR regsubkey_ctr_addkey( struct regsubkey_ctr *ctr, const char *keyname )
77
191
Delete a key from the array
78
192
**********************************************************************/
80
int regsubkey_ctr_delkey( REGSUBKEY_CTR *ctr, const char *keyname )
194
WERROR regsubkey_ctr_delkey( struct regsubkey_ctr *ctr, const char *keyname )
85
return ctr->num_subkeys;
199
if (keyname == NULL) {
200
return WERR_INVALID_PARAM;
87
203
/* make sure the keyname is actually already there */
89
for ( i=0; i<ctr->num_subkeys; i++ ) {
90
if ( strequal( ctr->subkeys[i], keyname ) )
205
werr = regsubkey_ctr_index_for_keyname(ctr, keyname, &idx);
206
W_ERROR_NOT_OK_RETURN(werr);
94
if ( i == ctr->num_subkeys )
95
return ctr->num_subkeys;
208
werr = regsubkey_ctr_unhash_keyname(ctr, keyname);
209
W_ERROR_NOT_OK_RETURN(werr);
97
211
/* update if we have any keys left */
98
212
ctr->num_subkeys--;
99
if ( i < ctr->num_subkeys )
100
memmove(&ctr->subkeys[i], &ctr->subkeys[i+1],
101
sizeof(char*) * (ctr->num_subkeys-i));
103
return ctr->num_subkeys;
213
if (idx < ctr->num_subkeys) {
214
memmove(&ctr->subkeys[idx], &ctr->subkeys[idx+1],
215
sizeof(char *) * (ctr->num_subkeys - idx));
217
/* we have to re-hash rest of the array... :-( */
218
for (j = idx; j < ctr->num_subkeys; j++) {
219
werr = regsubkey_ctr_hash_keyname(ctr, ctr->subkeys[j], j);
220
W_ERROR_NOT_OK_RETURN(werr);
106
227
/***********************************************************************
107
228
Check for the existance of a key
108
229
**********************************************************************/
110
bool regsubkey_ctr_key_exists( REGSUBKEY_CTR *ctr, const char *keyname )
231
bool regsubkey_ctr_key_exists( struct regsubkey_ctr *ctr, const char *keyname )
114
235
if (!ctr->subkeys) {
118
for ( i=0; i<ctr->num_subkeys; i++ ) {
119
if ( strequal( ctr->subkeys[i],keyname ) )
239
werr = regsubkey_ctr_index_for_keyname(ctr, keyname, NULL);
240
if (!W_ERROR_IS_OK(werr)) {
126
247
/***********************************************************************
127
248
How many keys does the container hold ?
128
249
**********************************************************************/
130
int regsubkey_ctr_numkeys( REGSUBKEY_CTR *ctr )
251
int regsubkey_ctr_numkeys( struct regsubkey_ctr *ctr )
132
253
return ctr->num_subkeys;