int regdb_fetch_values( const char* key, REGVAL_CTR *values ) { TDB_DATA data; pstring keystr; DEBUG(10,("regdb_fetch_values: Looking for value of key [%s] \n", key)); pstr_sprintf( keystr, "%s/%s", VALUE_PREFIX, key ); normalize_reg_path( keystr ); data = tdb_fetch_bystring( tdb_reg, keystr ); if ( !data.dptr ) { /* all keys have zero values by default */ return 0; } regdb_unpack_values( values, data.dptr, data.dsize ); SAFE_FREE( data.dptr ); return regval_ctr_numvals(values); }
NTSTATUS samba3_read_regdb ( const char *fn, TALLOC_CTX *ctx, struct samba3_regdb *db ) { uint32_t vers_id; TDB_CONTEXT *tdb; TDB_DATA kbuf, vbuf; /* placeholder tdb; reinit upon startup */ if ( !(tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0600)) ) { DEBUG(0, ("Unable to open registry database %s\n", fn)); return NT_STATUS_UNSUCCESSFUL; } vers_id = tdb_fetch_int32(tdb, "INFO/version"); db->key_count = 0; db->keys = NULL; if (vers_id != -1 && vers_id >= REGVER_V1) { DEBUG(0, ("Registry version mismatch: %d\n", vers_id)); return NT_STATUS_UNSUCCESSFUL; } for (kbuf = tdb_firstkey(tdb); kbuf.dptr; kbuf = tdb_nextkey(tdb, kbuf)) { uint32_t len; int i; struct samba3_regkey key; char *skey; if (strncmp((char *)kbuf.dptr, VALUE_PREFIX, strlen(VALUE_PREFIX)) == 0) continue; vbuf = tdb_fetch(tdb, kbuf); key.name = talloc_strdup(ctx, (char *)kbuf.dptr); len = tdb_unpack(tdb, (char *)vbuf.dptr, vbuf.dsize, "d", &key.subkey_count); key.value_count = 0; key.values = NULL; key.subkeys = talloc_array(ctx, char *, key.subkey_count); for (i = 0; i < key.subkey_count; i++) { fstring tmp; len += tdb_unpack( tdb, (char *)vbuf.dptr+len, vbuf.dsize-len, "f", tmp ); key.subkeys[i] = talloc_strdup(ctx, tmp); } skey = talloc_asprintf(ctx, "%s/%s", VALUE_PREFIX, kbuf.dptr ); vbuf = tdb_fetch_bystring( tdb, skey ); if ( vbuf.dptr ) { regdb_unpack_values( tdb, ctx, &key, vbuf ); } db->keys = talloc_realloc(ctx, db->keys, struct samba3_regkey, db->key_count+1); db->keys[db->key_count] = key; db->key_count++; } tdb_close(tdb); return NT_STATUS_OK; }