From: Jelmer Vernooij Date: Wed, 24 Aug 2005 12:21:19 +0000 (+0000) Subject: r9581: Registry db X-Git-Tag: initial-v4-0-unstable~7508 X-Git-Url: http://git.samba.org/samba.git/?p=jra%2Fsamba%2F.git;a=commitdiff_plain;h=b264e9f56a434400277bb73898484aff93522fe8 r9581: Registry db --- diff --git a/source/include/structs.h b/source/include/structs.h index 3399ecbd3fc..6d060fb22f8 100644 --- a/source/include/structs.h +++ b/source/include/structs.h @@ -277,4 +277,5 @@ struct samba3_idmapdb; struct samba3_groupdb; struct samba3_winsdb_entry; struct samba3_policy; +struct samba3_regdb; struct samba3; diff --git a/source/lib/samba3/config.mk b/source/lib/samba3/config.mk index 64a2293614b..23f07106f04 100644 --- a/source/lib/samba3/config.mk +++ b/source/lib/samba3/config.mk @@ -8,7 +8,8 @@ ADD_OBJ_FILES = \ lib/samba3/idmap.o \ lib/samba3/winsdb.o \ lib/samba3/samba3.o \ - lib/samba3/group.o + lib/samba3/group.o \ + lib/samba3/registry.o # lib/samba3/secrets.o # End SUBSYSTEM LIBSAMBA3 ################################################ diff --git a/source/lib/samba3/registry.c b/source/lib/samba3/registry.c index 22fa2b26362..82a08c90887 100644 --- a/source/lib/samba3/registry.c +++ b/source/lib/samba3/registry.c @@ -22,151 +22,123 @@ /* Implementation of internal registry database functions. */ #include "includes.h" +#include "lib/samba3/samba3.h" +#include "librpc/gen_ndr/winreg.h" +#include "lib/tdb/include/tdbutil.h" +#include "system/filesys.h" +#include "pstring.h" #define VALUE_PREFIX "SAMBA_REGVAL" #define REGVER_V1 1 /* first db version with write support */ - -/*********************************************************************** - Open the registry database - ***********************************************************************/ - -static TDB_CONTEXT *samba3_open_registry ( const char *fn ) -{ - uint32_t vers_id; - - /* placeholder tdb; reinit upon startup */ - - if ( !(tdb = tdb_open_log(lock_path("registry.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0600)) ) - { - return NULL; - } - - vers_id = tdb_fetch_int32(tdb, "INFO/version"); - - if (vers_id > REGVER_V1) - return NULL; - - return True; -} - -/*********************************************************************** - Retrieve an array of strings containing subkeys. Memory should be - released by the caller. - ***********************************************************************/ - -int regdb_fetch_keys( TDB_CONTEXT *tdb, const char* key, REGSUBKEY_CTR *ctr ) -{ - char *path; - uint32_t num_items; - TDB_DATA dbuf; - char *buf; - uint32_t buflen, len; - int i; - fstring subkeyname; - - DEBUG(11,("regdb_fetch_keys: Enter key => [%s]\n", key ? key : "NULL")); - - path = talloc_strdup(key); - - /* convert to key format */ - for ( i = 0; path[i]; i++) { - if ( path[i] == '\\' ) - path[i] = '/'; - } - strupper_m( path ); - - dbuf = tdb_fetch_bystring( tdb, path ); - - buf = dbuf.dptr; - buflen = dbuf.dsize; - - if ( !buf ) { - DEBUG(5,("regdb_fetch_keys: tdb lookup failed to locate key [%s]\n", key)); - return -1; - } - - len = tdb_unpack( buf, buflen, "d", &num_items); - - for (i=0; ivalues = talloc_realloc(ctx, key->values, struct samba3_regval, key->value_count+1); + key->values[key->value_count] = val; + key->value_count++; } return len; } + + /*********************************************************************** - Retrieve an array of strings containing subkeys. Memory should be - released by the caller. + Open the registry database ***********************************************************************/ - -int regdb_fetch_values( TDB_CONTEXT *tdb, const char* key, REGVAL_CTR *values ) + +NTSTATUS samba3_read_regdb ( const char *fn, TALLOC_CTX *ctx, struct samba3_regdb *db ) { - TDB_DATA data; - pstring keystr; + uint32_t vers_id; + TDB_CONTEXT *tdb; + TDB_DATA kbuf, vbuf; - 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, keystr ); + /* placeholder tdb; reinit upon startup */ - if ( !data.dptr ) { - /* all keys have zero values by default */ - return 0; + if ( !(tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0600)) ) + { + return NT_STATUS_UNSUCCESSFUL; } + + vers_id = tdb_fetch_int32(tdb, "INFO/version"); + + db->key_count = 0; + db->keys = NULL; + + if (vers_id > REGVER_V1) + 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(kbuf.dptr, VALUE_PREFIX, strlen(VALUE_PREFIX))) + continue; + + vbuf = tdb_fetch(tdb, kbuf); + + key.name = talloc_strdup(ctx, kbuf.dptr); + + len = tdb_unpack(tdb, vbuf.dptr, vbuf.dsize, "d", &key.subkey_count); + + key.value_count = 0; + key.values = NULL; + key.subkeys = talloc_array(ctx, char *, key.subkey_count); - regdb_unpack_values( values, data.dptr, data.dsize ); + for (i = 0; i < key.subkey_count; i++) { + fstring tmp; + len += tdb_unpack( tdb, 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 ); - SAFE_FREE( data.dptr ); + vbuf = tdb_fetch_bystring( tdb, skey ); - return regval_ctr_numvals(values); + 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[i] = key; + db->key_count++; + } + + tdb_close(tdb); + + return NT_STATUS_OK; } diff --git a/source/lib/samba3/samba3.c b/source/lib/samba3/samba3.c index 37576a8642a..c74b1b5279e 100644 --- a/source/lib/samba3/samba3.c +++ b/source/lib/samba3/samba3.c @@ -47,5 +47,9 @@ struct samba3 *samba3_read(const char *libdir, TALLOC_CTX *ctx) samba3_read_account_policy(dbfile, ctx, &ret->policy); SAFE_FREE(dbfile); + asprintf(&dbfile, "%s/registry.tdb", libdir); + samba3_read_regdb(dbfile, ctx, &ret->registry); + SAFE_FREE(dbfile); + return ret; } diff --git a/source/lib/samba3/samba3.h b/source/lib/samba3/samba3.h index adb7b8973ab..bebd1207048 100644 --- a/source/lib/samba3/samba3.h +++ b/source/lib/samba3/samba3.h @@ -51,26 +51,11 @@ struct samba3_samaccount { uint8_t *hours; }; -/* SID Types */ -enum SID_NAME_USE -{ - SID_NAME_USE_NONE = 0, - SID_NAME_USER = 1, /* user */ - SID_NAME_DOM_GRP, /* domain group */ - SID_NAME_DOMAIN, /* domain sid */ - SID_NAME_ALIAS, /* local group */ - SID_NAME_WKN_GRP, /* well-known group */ - SID_NAME_DELETED, /* deleted account: needed for c2 rating */ - SID_NAME_INVALID, /* invalid account */ - SID_NAME_UNKNOWN, /* unknown sid type */ - SID_NAME_COMPUTER /* sid for a computer */ -}; - struct samba3_groupmapping { struct pdb_methods *methods; gid_t gid; struct dom_sid *sid; - enum SID_NAME_USE sid_name_use; + int sid_name_use; const char *nt_name; const char *comment; }; @@ -130,6 +115,28 @@ struct samba3_policy uint32_t refuse_machine_password_change; }; +struct samba3_regval { + char *name; + uint16_t type; + DATA_BLOB data; +}; + +struct samba3_regkey { + char *name; + + uint32_t value_count; + struct samba3_regval *values; + + uint32_t subkey_count; + char **subkeys; +}; + +struct samba3_regdb +{ + uint32_t key_count; + struct samba3_regkey *keys; +}; + struct samba3 { uint32_t winsdb_count; @@ -141,6 +148,7 @@ struct samba3 struct samba3_groupdb group; struct samba3_idmapdb idmap; struct samba3_policy policy; + struct samba3_regdb registry; }; #endif /* _SAMBA3_H */