From 5b15e435d101f87a0833625f217643acae5a7a75 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 22 Aug 2005 11:37:20 +0000 Subject: r9472: Add read-only version of Samba3 registry database (doesn't compile yet) (This used to be commit 77cbb6299847bab1272cc681f4b8f54a9fca1339) --- source4/lib/samba3/registry.c | 172 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 source4/lib/samba3/registry.c (limited to 'source4') diff --git a/source4/lib/samba3/registry.c b/source4/lib/samba3/registry.c new file mode 100644 index 0000000000..22fa2b2636 --- /dev/null +++ b/source4/lib/samba3/registry.c @@ -0,0 +1,172 @@ +/* + * Unix SMB/CIFS implementation. + * Virtual Windows Registry Layer + * Copyright (C) Gerald Carter 2002-2005 + * Copyright (C) Jelmer Vernooij 2005 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* Implementation of internal registry database functions. */ + +#include "includes.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