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.
25 #define DBGC_CLASS DBGC_REGISTRY
27 /* Return string description of registry value type */
28 const char *str_regtype(int type)
31 case REG_SZ: return "STRING";
32 case REG_DWORD: return "DWORD";
33 case REG_BINARY: return "BINARY";
38 char *reg_val_data_string(TALLOC_CTX *mem_ctx, struct registry_value *v)
44 if(v->data_len == 0) return talloc_strdup(mem_ctx, "");
46 switch (v->data_type) {
48 return talloc_strndup(mem_ctx, v->data_blk, v->data_len);
51 return talloc_strndup(mem_ctx, v->data_blk, v->data_len);
54 ret = talloc(mem_ctx, v->data_len * 3 + 2);
56 for (i=0; i<v->data_len; i++) {
57 int str_rem = v->data_len * 3 - (asciip - ret);
58 asciip += snprintf(asciip, str_rem, "%02x", *(uint8_t *)(((char *)v->data_blk)+i));
59 if (i < v->data_len && str_rem > 0)
60 *asciip = ' '; asciip++;
66 if (*(int *)v->data_blk == 0)
67 return talloc_strdup(mem_ctx, "0");
69 return talloc_asprintf(mem_ctx, "0x%x", *(int *)v->data_blk);
82 char *reg_val_description(TALLOC_CTX *mem_ctx, struct registry_value *val)
84 return talloc_asprintf(mem_ctx, "%s = %s : %s", val->name?val->name:"<No Name>", str_regtype(val->data_type), reg_val_data_string(mem_ctx, val));
87 BOOL reg_val_set_string(struct registry_value *val, char *str)
93 WERROR reg_key_get_subkey_val(TALLOC_CTX *mem_ctx, struct registry_key *key, const char *subname, const char *valname, struct registry_value **val)
95 struct registry_key *k;
96 WERROR error = reg_key_get_subkey_by_name(mem_ctx, key, subname, &k);
97 if(!W_ERROR_IS_OK(error)) return error;
99 return reg_key_get_value_by_name(mem_ctx, k, valname, val);
102 /***********************************************************************
103 Utility function for splitting the base path of a registry path off
104 by setting base and new_path to the apprapriate offsets withing the
107 WARNING!! Does modify the original string!
108 ***********************************************************************/
110 BOOL reg_split_path( char *path, char **base, char **new_path )
114 *new_path = *base = NULL;
121 p = strchr( path, '\\' );
132 * Replace all \'s with /'s
134 char *reg_path_win2unix(char *path)
137 for(i = 0; path[i]; i++) {
138 if(path[i] == '\\') path[i] = '/';
143 * Replace all /'s with \'s
145 char *reg_path_unix2win(char *path)
148 for(i = 0; path[i]; i++) {
149 if(path[i] == '/') path[i] = '\\';