2 Unix SMB/CIFS implementation.
3 Transparent registry backend handling
4 Copyright (C) Jelmer Vernooij 2003-2004.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DBGC_CLASS DBGC_REGISTRY
26 /* Return string description of registry value type */
27 const char *str_regtype(int type)
30 case REG_SZ: return "STRING";
31 case REG_DWORD: return "DWORD";
32 case REG_BINARY: return "BINARY";
37 char *reg_val_data_string(REG_VAL *v)
43 if(reg_val_size(v) == 0) return strdup("");
45 switch (reg_val_type(v)) {
47 /* FIXME: Convert to ascii */
48 return strdup(reg_val_data_blk(v));
51 return strdup(reg_val_data_blk(v));
54 ret = malloc(reg_val_size(v) * 3 + 2);
56 for (i=0; i<reg_val_size(v); i++) {
57 int str_rem = reg_val_size(v) * 3 - (asciip - ret);
58 asciip += snprintf(asciip, str_rem, "%02x", *(unsigned char *)(reg_val_data_blk(v)+i));
59 if (i < reg_val_size(v) && str_rem > 0)
60 *asciip = ' '; asciip++;
67 if (*(int *)reg_val_data_blk(v) == 0)
70 asprintf(&ret, "0x%x", *(int *)reg_val_data_blk(v));
85 char *reg_val_description(REG_VAL *val)
87 char *ret, *ds = reg_val_data_string(val);
88 asprintf(&ret, "%s = %s : %s", reg_val_name(val)?reg_val_name(val):"<No Name>", str_regtype(reg_val_type(val)), ds);
93 BOOL reg_val_set_string(REG_VAL *val, char *str)
99 WERROR reg_key_get_subkey_val(REG_KEY *key, const char *subname, const char *valname, REG_VAL **val)
102 WERROR error = reg_key_get_subkey_by_name(key, subname, &k);
103 if(!W_ERROR_IS_OK(error)) return error;
105 return reg_key_get_value_by_name(k, valname, val);
108 WERROR reg_key_set_subkey_val(REG_KEY *key, const char *subname, const char *valname, uint32 type, uint8 *data, int real_len)
114 error = reg_key_get_subkey_by_name(key, subname, &k);
115 if(!W_ERROR_IS_OK(error)) return error;
117 error = reg_key_get_value_by_name(k, valname, &v);
118 if(!W_ERROR_IS_OK(error)) return error;
120 return reg_val_update(v, type, data, real_len);
123 /***********************************************************************
124 Utility function for splitting the base path of a registry path off
125 by setting base and new_path to the apprapriate offsets withing the
128 WARNING!! Does modify the original string!
129 ***********************************************************************/
131 BOOL reg_split_path( char *path, char **base, char **new_path )
135 *new_path = *base = NULL;
142 p = strchr( path, '\\' );
153 * Replace all \'s with /'s
155 char *reg_path_win2unix(char *path)
158 for(i = 0; path[i]; i++) {
159 if(path[i] == '\\') path[i] = '/';
164 * Replace all /'s with \'s
166 char *reg_path_unix2win(char *path)
169 for(i = 0; path[i]; i++) {
170 if(path[i] == '/') path[i] = '\\';