summaryrefslogtreecommitdiff
path: root/source4/lib/registry/common/reg_util.c
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2004-04-04 16:24:08 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:50:33 -0500
commitc424c2b857fe08587eb81a5c5e3625545119d1c2 (patch)
tree03505d09ccd72cdfd1218066d355e2d01d403bd0 /source4/lib/registry/common/reg_util.c
parent3855ee0164d1c8ff3c3c4ba8a5556d8cfb6546b3 (diff)
downloadsamba-c424c2b857fe08587eb81a5c5e3625545119d1c2.tar.gz
samba-c424c2b857fe08587eb81a5c5e3625545119d1c2.tar.bz2
samba-c424c2b857fe08587eb81a5c5e3625545119d1c2.zip
r20: Add the registry library. Still needs a lot of work,
see source/lib/registry/TODO for details. (This used to be commit 7cab3a00d7b4b1d95a3bfa6b28f318b4aaa5d493)
Diffstat (limited to 'source4/lib/registry/common/reg_util.c')
-rw-r--r--source4/lib/registry/common/reg_util.c164
1 files changed, 164 insertions, 0 deletions
diff --git a/source4/lib/registry/common/reg_util.c b/source4/lib/registry/common/reg_util.c
new file mode 100644
index 0000000000..2941c38cf4
--- /dev/null
+++ b/source4/lib/registry/common/reg_util.c
@@ -0,0 +1,164 @@
+/*
+ Unix SMB/CIFS implementation.
+ Transparent registry backend handling
+ Copyright (C) Jelmer Vernooij 2003-2004.
+
+ 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.
+*/
+
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_REGISTRY
+
+/* Return string description of registry value type */
+const char *str_regtype(int type)
+{
+ switch(type) {
+ case REG_SZ: return "STRING";
+ case REG_DWORD: return "DWORD";
+ case REG_BINARY: return "BINARY";
+ }
+ return "Unknown";
+}
+
+char *reg_val_data_string(REG_VAL *v)
+{
+ char *asciip;
+ char *ret = NULL;
+ int i;
+
+ if(reg_val_size(v) == 0) return strdup("");
+
+ switch (reg_val_type(v)) {
+ case REG_SZ:
+ /* FIXME: Convert to ascii */
+ return strdup(reg_val_data_blk(v));
+
+ case REG_EXPAND_SZ:
+ return strdup(reg_val_data_blk(v));
+
+ case REG_BINARY:
+ ret = malloc(reg_val_size(v) * 3 + 2);
+ asciip = ret;
+ for (i=0; i<reg_val_size(v); i++) {
+ int str_rem = reg_val_size(v) * 3 - (asciip - ret);
+ asciip += snprintf(asciip, str_rem, "%02x", *(unsigned char *)(reg_val_data_blk(v)+i));
+ if (i < reg_val_size(v) && str_rem > 0)
+ *asciip = ' '; asciip++;
+ }
+ *asciip = '\0';
+ return ret;
+ break;
+
+ case REG_DWORD:
+ if (*(int *)reg_val_data_blk(v) == 0)
+ ret = strdup("0");
+ else
+ asprintf(&ret, "0x%x", *(int *)reg_val_data_blk(v));
+ break;
+
+ case REG_MULTI_SZ:
+ /* FIXME */
+ break;
+
+ default:
+ return 0;
+ break;
+ }
+
+ return ret;
+}
+
+const char *reg_val_description(REG_VAL *val)
+{
+ char *ret, *ds = reg_val_data_string(val);
+ asprintf(&ret, "%s = %s : %s", reg_val_name(val)?reg_val_name(val):"<No Name>", str_regtype(reg_val_type(val)), ds);
+ free(ds);
+ return ret;
+}
+
+BOOL reg_val_set_string(REG_VAL *val, char *str)
+{
+ /* FIXME */
+ return False;
+}
+
+REG_VAL *reg_key_get_subkey_val(REG_KEY *key, const char *subname, const char *valname)
+{
+ REG_KEY *k = reg_key_get_subkey_by_name(key, subname);
+ if(!k) return NULL;
+
+ return reg_key_get_value_by_name(k, valname);
+}
+
+BOOL reg_key_set_subkey_val(REG_KEY *key, const char *subname, const char *valname, uint32 type, uint8 *data, int real_len)
+{
+ REG_KEY *k = reg_key_get_subkey_by_name(key, subname);
+ REG_VAL *v;
+ if(!k) return False;
+
+ v = reg_key_get_value_by_name(k, valname);
+ if(!v) return False;
+
+ return reg_val_update(v, type, data, real_len);
+}
+
+/***********************************************************************
+ Utility function for splitting the base path of a registry path off
+ by setting base and new_path to the apprapriate offsets withing the
+ path.
+
+ WARNING!! Does modify the original string!
+ ***********************************************************************/
+
+BOOL reg_split_path( char *path, char **base, char **new_path )
+{
+ char *p;
+
+ *new_path = *base = NULL;
+
+ if ( !path)
+ return False;
+
+ *base = path;
+
+ p = strchr( path, '\\' );
+
+ if ( p ) {
+ *p = '\0';
+ *new_path = p+1;
+ }
+
+ return True;
+}
+
+char *reg_path_win2unix(char *path)
+{
+ int i;
+ for(i = 0; path[i]; i++) {
+ if(path[i] == '\\') path[i] = '/';
+ }
+ return path;
+}
+
+char *reg_path_unix2win(char *path)
+{
+ int i;
+ for(i = 0; path[i]; i++) {
+ if(path[i] == '/') path[i] = '\\';
+ }
+ return path;
+}