Changeset 223 for branches/samba-3.3.x/source/registry/reg_objects.c
- Timestamp:
- May 24, 2009, 7:51:24 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/samba-3.3.x/source/registry/reg_objects.c
r206 r223 25 25 #define DBGC_CLASS DBGC_REGISTRY 26 26 27 struct regsubkey_ctr { 28 uint32_t num_subkeys; 29 char **subkeys; 30 struct db_context *subkeys_hash; 31 int seqnum; 32 }; 33 27 34 /********************************************************************** 28 35 29 Note that the REGSUB_CTR and REGVAL_CTR objects *must* be talloc()'d30 since the methods use the object pointer as the talloc context for31 internal private data.32 33 There is no longer a reg XXX_ctr_intit() and regXXX_ctr_destroy()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. 39 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 35 42 object. … … 37 44 **********************************************************************/ 38 45 46 WERROR regsubkey_ctr_init(TALLOC_CTX *mem_ctx, struct regsubkey_ctr **ctr) 47 { 48 if (ctr == NULL) { 49 return WERR_INVALID_PARAM; 50 } 51 52 *ctr = talloc_zero(mem_ctx, struct regsubkey_ctr); 53 if (*ctr == NULL) { 54 return WERR_NOMEM; 55 } 56 57 (*ctr)->subkeys_hash = db_open_rbt(*ctr); 58 if ((*ctr)->subkeys_hash == NULL) { 59 talloc_free(*ctr); 60 return WERR_NOMEM; 61 } 62 63 return WERR_OK; 64 } 65 66 WERROR regsubkey_ctr_set_seqnum(struct regsubkey_ctr *ctr, int seqnum) 67 { 68 if (ctr == NULL) { 69 return WERR_INVALID_PARAM; 70 } 71 72 ctr->seqnum = seqnum; 73 74 return WERR_OK; 75 } 76 77 int regsubkey_ctr_get_seqnum(struct regsubkey_ctr *ctr) 78 { 79 if (ctr == NULL) { 80 return -1; 81 } 82 83 return ctr->seqnum; 84 } 85 86 static WERROR regsubkey_ctr_hash_keyname(struct regsubkey_ctr *ctr, 87 const char *keyname, 88 uint32 idx) 89 { 90 WERROR werr; 91 92 werr = ntstatus_to_werror(dbwrap_store_bystring(ctr->subkeys_hash, 93 keyname, 94 make_tdb_data((uint8 *)&idx, 95 sizeof(idx)), 96 TDB_REPLACE)); 97 if (!W_ERROR_IS_OK(werr)) { 98 DEBUG(1, ("error hashing new key '%s' in container: %s\n", 99 keyname, dos_errstr(werr))); 100 } 101 102 return werr; 103 } 104 105 static WERROR regsubkey_ctr_unhash_keyname(struct regsubkey_ctr *ctr, 106 const char *keyname) 107 { 108 WERROR werr; 109 110 werr = ntstatus_to_werror(dbwrap_delete_bystring(ctr->subkeys_hash, 111 keyname)); 112 if (!W_ERROR_IS_OK(werr)) { 113 DEBUG(1, ("error unhashing key '%s' in container: %s\n", 114 keyname, dos_errstr(werr))); 115 } 116 117 return werr; 118 } 119 120 static WERROR regsubkey_ctr_index_for_keyname(struct regsubkey_ctr *ctr, 121 const char *keyname, 122 uint32 *idx) 123 { 124 TDB_DATA data; 125 126 if ((ctr == NULL) || (keyname == NULL)) { 127 return WERR_INVALID_PARAM; 128 } 129 130 data = dbwrap_fetch_bystring(ctr->subkeys_hash, ctr, keyname); 131 if (data.dptr == NULL) { 132 return WERR_NOT_FOUND; 133 } 134 135 if (data.dsize != sizeof(*idx)) { 136 talloc_free(data.dptr); 137 return WERR_INVALID_DATATYPE; 138 } 139 140 if (idx != NULL) { 141 *idx = *(uint32 *)data.dptr; 142 } 143 144 talloc_free(data.dptr); 145 return WERR_OK; 146 } 147 39 148 /*********************************************************************** 40 149 Add a new key to the array 41 150 **********************************************************************/ 42 151 43 WERROR regsubkey_ctr_addkey( REGSUBKEY_CTR*ctr, const char *keyname )152 WERROR regsubkey_ctr_addkey( struct regsubkey_ctr *ctr, const char *keyname ) 44 153 { 45 154 char **newkeys; 155 WERROR werr; 46 156 47 157 if ( !keyname ) { … … 69 179 return WERR_NOMEM; 70 180 } 181 182 werr = regsubkey_ctr_hash_keyname(ctr, keyname, ctr->num_subkeys); 183 W_ERROR_NOT_OK_RETURN(werr); 184 71 185 ctr->num_subkeys++; 72 186 … … 78 192 **********************************************************************/ 79 193 80 int regsubkey_ctr_delkey( REGSUBKEY_CTR *ctr, const char *keyname ) 81 { 82 int i; 83 84 if ( !keyname ) 85 return ctr->num_subkeys; 194 WERROR regsubkey_ctr_delkey( struct regsubkey_ctr *ctr, const char *keyname ) 195 { 196 WERROR werr; 197 uint32 idx, j; 198 199 if (keyname == NULL) { 200 return WERR_INVALID_PARAM; 201 } 86 202 87 203 /* make sure the keyname is actually already there */ 88 204 89 for ( i=0; i<ctr->num_subkeys; i++ ) { 90 if ( strequal( ctr->subkeys[i], keyname ) ) 91 break; 92 } 93 94 if ( i == ctr->num_subkeys ) 95 return ctr->num_subkeys; 205 werr = regsubkey_ctr_index_for_keyname(ctr, keyname, &idx); 206 W_ERROR_NOT_OK_RETURN(werr); 207 208 werr = regsubkey_ctr_unhash_keyname(ctr, keyname); 209 W_ERROR_NOT_OK_RETURN(werr); 96 210 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)); 102 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)); 216 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); 221 } 222 } 223 224 return WERR_OK; 104 225 } 105 226 … … 108 229 **********************************************************************/ 109 230 110 bool regsubkey_ctr_key_exists( REGSUBKEY_CTR*ctr, const char *keyname )111 { 112 int i;231 bool regsubkey_ctr_key_exists( struct regsubkey_ctr *ctr, const char *keyname ) 232 { 233 WERROR werr; 113 234 114 235 if (!ctr->subkeys) { … … 116 237 } 117 238 118 for ( i=0; i<ctr->num_subkeys; i++ ) {119 if ( strequal( ctr->subkeys[i],keyname ) )120 return True;121 } 122 123 return False;239 werr = regsubkey_ctr_index_for_keyname(ctr, keyname, NULL); 240 if (!W_ERROR_IS_OK(werr)) { 241 return false; 242 } 243 244 return true; 124 245 } 125 246 … … 128 249 **********************************************************************/ 129 250 130 int regsubkey_ctr_numkeys( REGSUBKEY_CTR*ctr )251 int regsubkey_ctr_numkeys( struct regsubkey_ctr *ctr ) 131 252 { 132 253 return ctr->num_subkeys; … … 137 258 **********************************************************************/ 138 259 139 char* regsubkey_ctr_specific_key( REGSUBKEY_CTR *ctr, uint32key_index )260 char* regsubkey_ctr_specific_key( struct regsubkey_ctr *ctr, uint32_t key_index ) 140 261 { 141 262 if ( ! (key_index < ctr->num_subkeys) )
Note:
See TracChangeset
for help on using the changeset viewer.