summaryrefslogtreecommitdiff
path: root/source4/lib/samba3
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-08-24 12:21:19 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:34:31 -0500
commitca71549d5af608a280645f69016749ae9da89747 (patch)
tree731e56a85a4284aedd81242701aa1d29532bfd21 /source4/lib/samba3
parent10dcfca9f18648f3fb32f0810d36af4e1eaf76e0 (diff)
downloadsamba-ca71549d5af608a280645f69016749ae9da89747.tar.gz
samba-ca71549d5af608a280645f69016749ae9da89747.tar.bz2
samba-ca71549d5af608a280645f69016749ae9da89747.zip
r9581: Registry db
(This used to be commit b264e9f56a434400277bb73898484aff93522fe8)
Diffstat (limited to 'source4/lib/samba3')
-rw-r--r--source4/lib/samba3/config.mk3
-rw-r--r--source4/lib/samba3/registry.c182
-rw-r--r--source4/lib/samba3/samba3.c4
-rw-r--r--source4/lib/samba3/samba3.h40
4 files changed, 107 insertions, 122 deletions
diff --git a/source4/lib/samba3/config.mk b/source4/lib/samba3/config.mk
index 64a2293614..23f07106f0 100644
--- a/source4/lib/samba3/config.mk
+++ b/source4/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/source4/lib/samba3/registry.c b/source4/lib/samba3/registry.c
index 22fa2b2636..82a08c9088 100644
--- a/source4/lib/samba3/registry.c
+++ b/source4/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; i<num_items; i++) {
- len += tdb_unpack( buf+len, buflen-len, "f", subkeyname );
- regsubkey_ctr_addkey( ctr, subkeyname );
- }
-
- SAFE_FREE( dbuf.dptr );
-
- DEBUG(11,("regdb_fetch_keys: Exit [%d] items\n", num_items));
-
- return num_items;
-}
/****************************************************************************
- Unpack a list of registry values frem the TDB
+ Unpack a list of registry values from the TDB
***************************************************************************/
-static int regdb_unpack_values(REGVAL_CTR *values, char *buf, int buflen)
+static int regdb_unpack_values(TDB_CONTEXT *tdb, TALLOC_CTX *ctx, struct samba3_regkey *key, TDB_DATA data )
{
int len = 0;
uint32_t type;
- char *valuename;
uint32_t size;
uint8_t *data_p;
uint32_t num_values = 0;
int i;
+ fstring valuename;
/* loop and unpack the rest of the registry values */
- len += tdb_unpack(buf+len, buflen-len, "d", &num_values);
+ len += tdb_unpack(tdb, data.dptr+len, data.dsize-len, "d", &num_values);
for ( i=0; i<num_values; i++ ) {
+ struct samba3_regval val;
/* unpack the next regval */
type = REG_NONE;
size = 0;
data_p = NULL;
- len += tdb_unpack(buf+len, buflen-len, "fdB",
+ len += tdb_unpack(tdb, data.dptr+len, data.dsize-len, "fdB",
valuename,
- &type,
+ &val.type,
&size,
&data_p);
-
- /* add the new value. Paranoid protective code -- make sure data_p is valid */
-
- if ( size && data_p ) {
- regval_ctr_addvalue( values, valuename, type, (const char *)data_p, size );
- SAFE_FREE(data_p); /* 'B' option to tdb_unpack does a malloc() */
- }
+ val.name = talloc_strdup(ctx, valuename);
+ val.data = data_blob_talloc(ctx, data_p, size);
- DEBUG(8,("specific: [%s], len: %d\n", valuename, size));
+ key->values = 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/source4/lib/samba3/samba3.c b/source4/lib/samba3/samba3.c
index 37576a8642..c74b1b5279 100644
--- a/source4/lib/samba3/samba3.c
+++ b/source4/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/source4/lib/samba3/samba3.h b/source4/lib/samba3/samba3.h
index adb7b8973a..bebd120704 100644
--- a/source4/lib/samba3/samba3.h
+++ b/source4/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 */