Changeset 740 for vendor/current/source4/lib/registry
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- Location:
- vendor/current/source4/lib/registry
- Files:
-
- 1 added
- 2 deleted
- 28 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source4/lib/registry/dir.c
r414 r740 41 41 42 42 path = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name); 43 W_ERROR_HAVE_NO_MEMORY(path); 43 44 ret = mkdir(path, 0700); 44 45 if (ret == 0) { 45 46 struct dir_key *key = talloc(mem_ctx, struct dir_key); 47 W_ERROR_HAVE_NO_MEMORY(key); 46 48 key->key.ops = ®_backend_dir; 47 49 key->path = talloc_steal(key, path); … … 77 79 78 80 path = talloc_asprintf(name, "%s/%s", name, e->d_name); 79 if (!path) 80 return WERR_NOMEM; 81 W_ERROR_HAVE_NO_MEMORY(path); 81 82 82 83 stat(path, &stbuf); … … 109 110 } 110 111 111 static WERROR reg_dir_del_key(const struct hive_key *k, const char *name) 112 static WERROR reg_dir_del_key(TALLOC_CTX *mem_ctx, const struct hive_key *k, 113 const char *name) 112 114 { 113 115 struct dir_key *dk = talloc_get_type(k, struct dir_key); 114 char *child = talloc_asprintf(NULL, "%s/%s", dk->path, name);116 char *child; 115 117 WERROR ret; 118 119 child = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name); 120 W_ERROR_HAVE_NO_MEMORY(child); 116 121 117 122 ret = reg_dir_delete_recursive(child); … … 137 142 138 143 fullpath = talloc_asprintf(mem_ctx, "%s/%s", p->path, name); 144 W_ERROR_HAVE_NO_MEMORY(fullpath); 139 145 140 146 d = opendir(fullpath); … … 142 148 DEBUG(3,("Unable to open '%s': %s\n", fullpath, 143 149 strerror(errno))); 150 talloc_free(fullpath); 144 151 return WERR_BADFILE; 145 152 } … … 160 167 struct dirent *e; 161 168 const struct dir_key *dk = talloc_get_type(k, struct dir_key); 162 int i = 0;169 unsigned int i = 0; 163 170 DIR *d; 164 171 … … 174 181 175 182 /* Check if file is a directory */ 176 asprintf(&thispath, "%s/%s", dk->path, e->d_name); 183 thispath = talloc_asprintf(mem_ctx, "%s/%s", dk->path, 184 e->d_name); 185 W_ERROR_HAVE_NO_MEMORY(thispath); 177 186 stat(thispath, &stbuf); 178 187 179 188 if (!S_ISDIR(stbuf.st_mode)) { 180 SAFE_FREE(thispath);189 talloc_free(thispath); 181 190 continue; 182 191 } … … 185 194 struct stat st; 186 195 *name = talloc_strdup(mem_ctx, e->d_name); 196 W_ERROR_HAVE_NO_MEMORY(*name); 187 197 *classname = NULL; 188 198 stat(thispath, &st); 189 199 unix_to_nt_time(last_mod_time, st.st_mtime); 190 SAFE_FREE(thispath);200 talloc_free(thispath); 191 201 closedir(d); 192 202 return WERR_OK; … … 194 204 i++; 195 205 196 SAFE_FREE(thispath);206 talloc_free(thispath); 197 207 } 198 208 } … … 212 222 213 223 dk = talloc(parent_ctx, struct dir_key); 224 W_ERROR_HAVE_NO_MEMORY(dk); 214 225 dk->key.ops = ®_backend_dir; 215 226 dk->path = talloc_strdup(dk, location); … … 271 282 char *path = talloc_asprintf(ctx, "%s/%s", 272 283 dk->path, e->d_name); 284 W_ERROR_HAVE_NO_MEMORY(path); 273 285 274 286 if (stat(path, &st) < 0) { 275 287 DEBUG(0, ("Error statting %s: %s\n", path, 276 288 strerror(errno))); 289 talloc_free(path); 277 290 continue; 278 291 } … … 309 322 { 310 323 const struct dir_key *dk = talloc_get_type(key, struct dir_key); 311 char *path = talloc_asprintf(dk, "%s/%s", dk->path, name); 312 313 if (!file_save(path, data.data, data.length)) 324 char *path; 325 bool ret; 326 327 path = talloc_asprintf(dk, "%s/%s", dk->path, name); 328 W_ERROR_HAVE_NO_MEMORY(path); 329 330 ret = file_save(path, data.data, data.length); 331 332 talloc_free(path); 333 334 if (!ret) { 314 335 return WERR_GENERAL_FAILURE; 336 } 315 337 316 338 /* FIXME: Type */ … … 324 346 { 325 347 const struct dir_key *dk = talloc_get_type(key, struct dir_key); 326 char *path = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name);348 char *path; 327 349 size_t size; 328 350 char *contents; 329 351 352 path = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name); 353 W_ERROR_HAVE_NO_MEMORY(path); 354 330 355 contents = file_load(path, &size, 0, mem_ctx); 356 331 357 talloc_free(path); 358 332 359 if (contents == NULL) 333 360 return WERR_BADFILE; … … 343 370 344 371 static WERROR reg_dir_enum_value(TALLOC_CTX *mem_ctx, 345 struct hive_key *key, int idx,372 struct hive_key *key, uint32_t idx, 346 373 const char **name, 347 374 uint32_t *type, DATA_BLOB *data) … … 350 377 DIR *d; 351 378 struct dirent *e; 352 int i;379 unsigned int i; 353 380 354 381 d = opendir(dk->path); … … 365 392 366 393 if (i == idx) { 367 if (name != NULL) 394 if (name != NULL) { 368 395 *name = talloc_strdup(mem_ctx, e->d_name); 396 W_ERROR_HAVE_NO_MEMORY(*name); 397 } 369 398 W_ERROR_NOT_OK_RETURN(reg_dir_get_value(mem_ctx, key, 370 399 *name, type, … … 381 410 382 411 383 static WERROR reg_dir_del_value (struct hive_key *key, const char *name) 412 static WERROR reg_dir_del_value(TALLOC_CTX *mem_ctx, 413 struct hive_key *key, const char *name) 384 414 { 385 415 const struct dir_key *dk = talloc_get_type(key, struct dir_key); 386 char *path = talloc_asprintf(key, "%s/%s", dk->path, name); 387 if (unlink(path) < 0) { 388 talloc_free(path); 416 char *path; 417 int ret; 418 419 path = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name); 420 W_ERROR_HAVE_NO_MEMORY(path); 421 422 ret = unlink(path); 423 424 talloc_free(path); 425 426 if (ret < 0) { 389 427 if (errno == ENOENT) 390 428 return WERR_BADFILE; 391 429 return WERR_GENERAL_FAILURE; 392 430 } 393 talloc_free(path);394 431 395 432 return WERR_OK; -
vendor/current/source4/lib/registry/hive.c
r414 r740 55 55 if (!strncmp(peek, "regf", 4)) { 56 56 close(fd); 57 return reg_open_regf_file(parent_ctx, location, lp_iconv_convenience(lp_ctx),root);57 return reg_open_regf_file(parent_ctx, location, root); 58 58 } else if (!strncmp(peek, "TDB file", 8)) { 59 59 close(fd); … … 92 92 } 93 93 94 _PUBLIC_ WERROR hive_key_del(const struct hive_key *key, const char *name) 94 _PUBLIC_ WERROR hive_key_del(TALLOC_CTX *mem_ctx, const struct hive_key *key, 95 const char *name) 95 96 { 96 return key->ops->del_key( key, name);97 return key->ops->del_key(mem_ctx, key, name); 97 98 } 98 99 … … 164 165 } 165 166 166 WERROR hive_key_del_value(struct hive_key *key, const char *name) 167 WERROR hive_key_del_value(TALLOC_CTX *mem_ctx, struct hive_key *key, 168 const char *name) 167 169 { 168 170 if (key->ops->delete_value == NULL) 169 171 return WERR_NOT_SUPPORTED; 170 172 171 return key->ops->delete_value( key, name);173 return key->ops->delete_value(mem_ctx, key, name); 172 174 } 173 175 -
vendor/current/source4/lib/registry/interface.c
r414 r740 45 45 _PUBLIC_ const char *reg_get_predef_name(uint32_t hkey) 46 46 { 47 int i;47 unsigned int i; 48 48 for (i = 0; reg_predefined_keys[i].name; i++) { 49 49 if (reg_predefined_keys[i].handle == hkey) … … 59 59 struct registry_key **key) 60 60 { 61 int i;61 unsigned int i; 62 62 63 63 for (i = 0; reg_predefined_keys[i].name; i++) { … … 151 151 _PUBLIC_ WERROR reg_key_get_subkey_by_index(TALLOC_CTX *mem_ctx, 152 152 const struct registry_key *key, 153 int idx, const char **name,153 uint32_t idx, const char **name, 154 154 const char **keyclass, 155 155 NTTIME *last_changed_time) … … 186 186 * Delete a key. 187 187 */ 188 _PUBLIC_ WERROR reg_key_del(struct registry_key *parent, const char *name) 188 _PUBLIC_ WERROR reg_key_del(TALLOC_CTX *mem_ctx, struct registry_key *parent, 189 const char *name) 189 190 { 190 191 if (parent == NULL) … … 194 195 return WERR_NOT_SUPPORTED; 195 196 196 return parent->context->ops->delete_key( parent, name);197 return parent->context->ops->delete_key(mem_ctx, parent, name); 197 198 } 198 199 … … 202 203 _PUBLIC_ WERROR reg_key_add_name(TALLOC_CTX *mem_ctx, 203 204 struct registry_key *parent, 204 const char * name, const char *key_class,205 const char *path, const char *key_class, 205 206 struct security_descriptor *desc, 206 207 struct registry_key **newkey) … … 215 216 } 216 217 217 return parent->context->ops->create_key(mem_ctx, parent, name,218 return parent->context->ops->create_key(mem_ctx, parent, path, 218 219 key_class, desc, newkey); 219 220 } … … 258 259 * Delete a value. 259 260 */ 260 _PUBLIC_ WERROR reg_del_value(struct registry_key *key, const char *valname) 261 _PUBLIC_ WERROR reg_del_value(TALLOC_CTX *mem_ctx, struct registry_key *key, 262 const char *valname) 261 263 { 262 264 if (key == NULL) … … 266 268 return WERR_NOT_SUPPORTED; 267 269 268 return key->context->ops->delete_value( key, valname);270 return key->context->ops->delete_value(mem_ctx, key, valname); 269 271 } 270 272 -
vendor/current/source4/lib/registry/ldb.c
r414 r740 3 3 Registry interface 4 4 Copyright (C) 2004-2007, Jelmer Vernooij, jelmer@samba.org 5 Copyright (C) 2008 Matthias Dieter Wallnöfer, mwallnoefer@yahoo.de5 Copyright (C) 2008-2010, Matthias Dieter Wallnöfer, mdw@samba.org 6 6 7 7 This program is free software; you can redistribute it and/or modify … … 21 21 #include "includes.h" 22 22 #include "registry.h" 23 #include "lib/ldb/include/ldb.h"24 #include "lib/ldb/include/ldb_errors.h"23 #include <ldb.h> 24 #include <ldb_errors.h> 25 25 #include "ldb_wrap.h" 26 26 #include "librpc/gen_ndr/winreg.h" … … 35 35 struct ldb_dn *dn; 36 36 struct ldb_message **subkeys, **values; 37 int subkey_count, value_count; 37 unsigned int subkey_count, value_count; 38 const char *classname; 38 39 }; 39 40 40 static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx, 41 static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx, 41 42 struct ldb_message *msg, 42 43 const char **name, uint32_t *type, … … 46 47 uint32_t value_type; 47 48 48 if (name != NULL) 49 if (name != NULL) { 49 50 *name = talloc_strdup(mem_ctx, 50 51 ldb_msg_find_attr_as_string(msg, "value", 51 NULL)); 52 "")); 53 } 52 54 53 55 value_type = ldb_msg_find_attr_as_uint(msg, "type", 0); 54 *type = value_type; 56 *type = value_type; 55 57 56 58 val = ldb_msg_find_ldb_val(msg, "data"); … … 60 62 case REG_SZ: 61 63 case REG_EXPAND_SZ: 62 if (val != NULL) 64 if (val != NULL) { 65 /* The data should be provided as UTF16 string */ 63 66 convert_string_talloc(mem_ctx, CH_UTF8, CH_UTF16, 64 65 66 else {67 val->data, val->length, 68 (void **)&data->data, &data->length, false); 69 } else { 67 70 data->data = NULL; 68 71 data->length = 0; … … 70 73 break; 71 74 72 case REG_BINARY: 73 if (val != NULL) 74 *data = data_blob_talloc(mem_ctx, val->data, val->length); 75 else { 75 case REG_DWORD: 76 case REG_DWORD_BIG_ENDIAN: 77 if (val != NULL) { 78 /* The data is a plain DWORD */ 79 uint32_t tmp = strtoul((char *)val->data, NULL, 0); 80 data->data = talloc_size(mem_ctx, sizeof(uint32_t)); 81 if (data->data != NULL) { 82 SIVAL(data->data, 0, tmp); 83 } 84 data->length = sizeof(uint32_t); 85 } else { 76 86 data->data = NULL; 77 87 data->length = 0; … … 79 89 break; 80 90 81 case REG_DWORD: { 82 uint32_t tmp = strtoul((char *)val->data, NULL, 0); 83 *data = data_blob_talloc(mem_ctx, &tmp, 4); 91 case REG_QWORD: 92 if (val != NULL) { 93 /* The data is a plain QWORD */ 94 uint64_t tmp = strtoull((char *)val->data, NULL, 0); 95 data->data = talloc_size(mem_ctx, sizeof(uint64_t)); 96 if (data->data != NULL) { 97 SBVAL(data->data, 0, tmp); 98 } 99 data->length = sizeof(uint64_t); 100 } else { 101 data->data = NULL; 102 data->length = 0; 84 103 } 85 104 break; 86 105 106 case REG_BINARY: 87 107 default: 88 *data = data_blob_talloc(mem_ctx, val->data, val->length); 108 if (val != NULL) { 109 data->data = talloc_memdup(mem_ctx, val->data, 110 val->length); 111 data->length = val->length; 112 } else { 113 data->data = NULL; 114 data->length = 0; 115 } 89 116 break; 90 117 } … … 96 123 uint32_t type, DATA_BLOB data) 97 124 { 98 struct ldb_val val; 99 struct ldb_message *msg = talloc_zero(mem_ctx, struct ldb_message); 100 char *type_s; 101 102 ldb_msg_add_string(msg, "value", talloc_strdup(mem_ctx, name)); 125 struct ldb_message *msg; 126 char *name_dup, *type_str; 127 int ret; 128 129 msg = talloc_zero(mem_ctx, struct ldb_message); 130 if (msg == NULL) { 131 return NULL; 132 } 133 134 name_dup = talloc_strdup(msg, name); 135 if (name_dup == NULL) { 136 talloc_free(msg); 137 return NULL; 138 } 139 140 ret = ldb_msg_add_string(msg, "value", name_dup); 141 if (ret != LDB_SUCCESS) { 142 talloc_free(msg); 143 return NULL; 144 } 103 145 104 146 switch (type) { 105 147 case REG_SZ: 106 148 case REG_EXPAND_SZ: 107 if (data.data[0] != '\0') { 108 convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8, 109 (void *)data.data, 110 data.length, 111 (void **)&val.data, &val.length, false); 112 ldb_msg_add_value(msg, "data", &val, NULL); 149 if ((data.length > 0) && (data.data != NULL)) { 150 struct ldb_val *val; 151 bool ret2 = false; 152 153 val = talloc_zero(msg, struct ldb_val); 154 if (val == NULL) { 155 talloc_free(msg); 156 return NULL; 157 } 158 159 /* The data is provided as UTF16 string */ 160 ret2 = convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8, 161 (void *)data.data, data.length, 162 (void **)&val->data, &val->length, 163 false); 164 if (ret2) { 165 ret = ldb_msg_add_value(msg, "data", val, NULL); 166 } else { 167 /* workaround for non-standard data */ 168 ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL); 169 } 113 170 } else { 114 ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);171 ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL); 115 172 } 116 173 break; 117 174 175 case REG_DWORD: 176 case REG_DWORD_BIG_ENDIAN: 177 if ((data.length > 0) && (data.data != NULL)) { 178 if (data.length == sizeof(uint32_t)) { 179 char *conv_str; 180 181 conv_str = talloc_asprintf(msg, "0x%8.8x", 182 IVAL(data.data, 0)); 183 if (conv_str == NULL) { 184 talloc_free(msg); 185 return NULL; 186 } 187 ret = ldb_msg_add_string(msg, "data", conv_str); 188 } else { 189 /* workaround for non-standard data */ 190 talloc_free(msg); 191 return NULL; 192 } 193 } else { 194 ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL); 195 } 196 break; 197 198 case REG_QWORD: 199 if ((data.length > 0) && (data.data != NULL)) { 200 if (data.length == sizeof(uint64_t)) { 201 char *conv_str; 202 203 conv_str = talloc_asprintf(msg, "0x%16.16llx", 204 (unsigned long long)BVAL(data.data, 0)); 205 if (conv_str == NULL) { 206 talloc_free(msg); 207 return NULL; 208 } 209 ret = ldb_msg_add_string(msg, "data", conv_str); 210 } else { 211 /* workaround for non-standard data */ 212 talloc_free(msg); 213 return NULL; 214 215 } 216 } else { 217 ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL); 218 } 219 break; 220 118 221 case REG_BINARY: 119 if (data.length > 0) 120 ldb_msg_add_value(msg, "data", &data, NULL); 121 else 122 ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL); 222 default: 223 if ((data.length > 0) && (data.data != NULL)) { 224 ret = ldb_msg_add_value(msg, "data", &data, NULL); 225 } else { 226 ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL); 227 } 123 228 break; 124 125 case REG_DWORD: 126 ldb_msg_add_string(msg, "data", 127 talloc_asprintf(mem_ctx, "0x%x", 128 IVAL(data.data, 0))); 129 break; 130 default: 131 ldb_msg_add_value(msg, "data", &data, NULL); 132 } 133 134 135 type_s = talloc_asprintf(mem_ctx, "%u", type); 136 ldb_msg_add_string(msg, "type", type_s); 229 } 230 231 if (ret != LDB_SUCCESS) { 232 talloc_free(msg); 233 return NULL; 234 } 235 236 type_str = talloc_asprintf(mem_ctx, "%u", type); 237 if (type_str == NULL) { 238 talloc_free(msg); 239 return NULL; 240 } 241 242 ret = ldb_msg_add_string(msg, "type", type_str); 243 if (ret != LDB_SUCCESS) { 244 talloc_free(msg); 245 return NULL; 246 } 137 247 138 248 return msg; … … 167 277 const char *path, const char *add) 168 278 { 169 TALLOC_CTX *local_ctx;170 279 struct ldb_dn *ret; 171 char *mypath = talloc_strdup(mem_ctx, path);280 char *mypath; 172 281 char *begin; 173 282 struct ldb_key_data *kd = talloc_get_type(from, struct ldb_key_data); 174 283 struct ldb_context *ldb = kd->ldb; 175 284 176 local_ctx = talloc_new(mem_ctx); 177 178 if (add) { 179 ret = ldb_dn_new(mem_ctx, ldb, add); 180 } else { 181 ret = ldb_dn_new(mem_ctx, ldb, NULL); 182 } 285 mypath = talloc_strdup(mem_ctx, path); 286 if (mypath == NULL) { 287 return NULL; 288 } 289 290 ret = ldb_dn_new(mem_ctx, ldb, add); 183 291 if (!ldb_dn_validate(ret)) { 184 292 talloc_free(ret); 185 talloc_free(local_ctx);186 293 return NULL; 187 294 } 188 295 189 while (mypath) { 190 char *keyname; 191 192 begin = strrchr(mypath, '\\'); 193 194 if (begin) keyname = begin + 1; 195 else keyname = mypath; 196 197 if(strlen(keyname)) { 198 if (!ldb_dn_add_base_fmt(ret, "key=%s", 199 reg_ldb_escape(local_ctx, 200 keyname))) 201 { 202 talloc_free(local_ctx); 203 return NULL; 204 } 205 } 206 207 if(begin) { 296 if (!ldb_dn_add_base(ret, kd->dn)) { 297 talloc_free(ret); 298 return NULL; 299 } 300 301 while (mypath[0] != '\0') { 302 begin = strchr(mypath, '\\'); 303 if (begin != NULL) { 208 304 *begin = '\0'; 305 } 306 307 if (!ldb_dn_add_child_fmt(ret, "key=%s", 308 reg_ldb_escape(mem_ctx, mypath))) { 309 talloc_free(ret); 310 return NULL; 311 } 312 313 if (begin != NULL) { 314 mypath = begin + 1; 209 315 } else { 210 316 break; 211 317 } 212 318 } 213 214 ldb_dn_add_base(ret, kd->dn);215 216 talloc_free(local_ctx);217 319 218 320 return ret; … … 225 327 int ret; 226 328 227 ret = ldb_search(c, c, &res, kd->dn, LDB_SCOPE_ONELEVEL, NULL, "(key=*)");228 329 ret = ldb_search(c, c, &res, kd->dn, LDB_SCOPE_ONELEVEL, 330 NULL, "(key=*)"); 229 331 if (ret != LDB_SUCCESS) { 230 332 DEBUG(0, ("Error getting subkeys for '%s': %s\n", … … 248 350 ret = ldb_search(c, c, &res, kd->dn, LDB_SCOPE_ONELEVEL, 249 351 NULL, "(value=*)"); 250 251 352 if (ret != LDB_SUCCESS) { 252 353 DEBUG(0, ("Error getting values for '%s': %s\n", … … 269 370 NTTIME *last_mod_time) 270 371 { 271 struct ldb_message_element *el;272 372 struct ldb_key_data *kd = talloc_get_type(k, struct ldb_key_data); 273 373 274 374 /* Initialization */ 275 375 if (name != NULL) 276 376 *name = NULL; 277 377 if (classname != NULL) 278 *classname = NULL; /* TODO: Store properly */378 *classname = NULL; 279 379 if (last_mod_time != NULL) 280 380 *last_mod_time = 0; /* TODO: we need to add this to the … … 289 389 return WERR_NO_MORE_ITEMS; 290 390 291 el = ldb_msg_find_element(kd->subkeys[idx], "key");292 SMB_ASSERT(el != NULL);293 SMB_ASSERT(el->num_values != 0);294 295 391 if (name != NULL) 296 *name = talloc_strdup(mem_ctx, (char *)el->values[0].data); 297 298 return WERR_OK; 299 } 300 301 static WERROR ldb_get_default_value(TALLOC_CTX *mem_ctx, struct hive_key *k, 302 const char **name, uint32_t *data_type, 303 DATA_BLOB *data) 392 *name = talloc_strdup(mem_ctx, 393 ldb_msg_find_attr_as_string(kd->subkeys[idx], "key", NULL)); 394 if (classname != NULL) 395 *classname = talloc_strdup(mem_ctx, 396 ldb_msg_find_attr_as_string(kd->subkeys[idx], "classname", NULL)); 397 398 return WERR_OK; 399 } 400 401 static WERROR ldb_get_default_value(TALLOC_CTX *mem_ctx, 402 const struct hive_key *k, 403 const char **name, uint32_t *data_type, 404 DATA_BLOB *data) 304 405 { 305 406 struct ldb_key_data *kd = talloc_get_type(k, struct ldb_key_data); … … 309 410 int ret; 310 411 311 ret = ldb_search(c, mem_ctx, &res, kd->dn, LDB_SCOPE_BASE, attrs, " %s", "");412 ret = ldb_search(c, mem_ctx, &res, kd->dn, LDB_SCOPE_BASE, attrs, "(dn=*)"); 312 413 313 414 if (ret != LDB_SUCCESS) { … … 317 418 } 318 419 319 if (res->count == 0 || res->msgs[0]->num_elements == 0) 420 if (res->count == 0 || res->msgs[0]->num_elements == 0) { 421 talloc_free(res); 320 422 return WERR_BADFILE; 321 322 reg_ldb_unpack_value(mem_ctx, 323 res->msgs[0], name, data_type, data); 423 } 424 425 if ((data_type != NULL) && (data != NULL)) { 426 reg_ldb_unpack_value(mem_ctx, res->msgs[0], name, data_type, 427 data); 428 } 324 429 325 430 talloc_free(res); … … 329 434 330 435 static WERROR ldb_get_value_by_id(TALLOC_CTX *mem_ctx, struct hive_key *k, 331 int idx, const char **name,436 uint32_t idx, const char **name, 332 437 uint32_t *data_type, DATA_BLOB *data) 333 438 { 334 439 struct ldb_key_data *kd = talloc_get_type(k, struct ldb_key_data); 335 440 336 /* if default value exists, give it back */441 /* if the default value exists, give it back */ 337 442 if (W_ERROR_IS_OK(ldb_get_default_value(mem_ctx, k, name, data_type, 338 443 data))) { … … 361 466 { 362 467 struct ldb_key_data *kd = talloc_get_type(k, struct ldb_key_data); 363 struct ldb_context *c = kd->ldb; 364 struct ldb_result *res; 365 int ret; 366 char *query; 367 368 if (strlen(name) == 0) { 369 /* default value */ 468 const char *res_name; 469 uint32_t idx; 470 471 /* the default value was requested, give it back */ 472 if (name[0] == '\0') { 370 473 return ldb_get_default_value(mem_ctx, k, NULL, data_type, data); 371 } else { 372 /* normal value */ 373 query = talloc_asprintf(mem_ctx, "(value=%s)", name); 374 ret = ldb_search(c, mem_ctx, &res, kd->dn, LDB_SCOPE_ONELEVEL, NULL, "%s", query); 375 talloc_free(query); 376 377 if (ret != LDB_SUCCESS) { 378 DEBUG(0, ("Error getting values for '%s': %s\n", 379 ldb_dn_get_linearized(kd->dn), ldb_errstring(c))); 380 return WERR_FOOBAR; 381 } 382 383 if (res->count == 0) 384 return WERR_BADFILE; 385 386 reg_ldb_unpack_value(mem_ctx, res->msgs[0], NULL, data_type, data); 387 388 talloc_free(res); 389 } 390 391 return WERR_OK; 474 } 475 476 /* Do the search if necessary */ 477 if (kd->values == NULL) { 478 W_ERROR_NOT_OK_RETURN(cache_values(kd)); 479 } 480 481 for (idx = 0; idx < kd->value_count; idx++) { 482 res_name = ldb_msg_find_attr_as_string(kd->values[idx], "value", 483 ""); 484 if (ldb_attr_cmp(name, res_name) == 0) { 485 reg_ldb_unpack_value(mem_ctx, kd->values[idx], NULL, 486 data_type, data); 487 return WERR_OK; 488 } 489 } 490 491 return WERR_BADFILE; 392 492 } 393 493 … … 396 496 { 397 497 struct ldb_result *res; 398 struct ldb_dn *ld ap_path;498 struct ldb_dn *ldb_path; 399 499 int ret; 400 500 struct ldb_key_data *newkd; … … 402 502 struct ldb_context *c = kd->ldb; 403 503 404 ldap_path = reg_path_to_ldb(mem_ctx, h, name, NULL); 405 406 ret = ldb_search(c, mem_ctx, &res, ldap_path, LDB_SCOPE_BASE, NULL, "(key=*)"); 504 ldb_path = reg_path_to_ldb(mem_ctx, h, name, NULL); 505 W_ERROR_HAVE_NO_MEMORY(ldb_path); 506 507 ret = ldb_search(c, mem_ctx, &res, ldb_path, LDB_SCOPE_BASE, NULL, "(key=*)"); 407 508 408 509 if (ret != LDB_SUCCESS) { 409 510 DEBUG(3, ("Error opening key '%s': %s\n", 410 ldb_dn_get_linearized(ld ap_path), ldb_errstring(c)));511 ldb_dn_get_linearized(ldb_path), ldb_errstring(c))); 411 512 return WERR_FOOBAR; 412 513 } else if (res->count == 0) { 413 514 DEBUG(3, ("Key '%s' not found\n", 414 ldb_dn_get_linearized(ld ap_path)));515 ldb_dn_get_linearized(ldb_path))); 415 516 talloc_free(res); 416 517 return WERR_BADFILE; … … 418 519 419 520 newkd = talloc_zero(mem_ctx, struct ldb_key_data); 521 W_ERROR_HAVE_NO_MEMORY(newkd); 420 522 newkd->key.ops = ®_backend_ldb; 421 523 newkd->ldb = talloc_reference(newkd, kd->ldb); 422 newkd->dn = ldb_dn_copy(mem_ctx, res->msgs[0]->dn); 524 newkd->dn = ldb_dn_copy(newkd, res->msgs[0]->dn); 525 newkd->classname = talloc_steal(newkd, 526 ldb_msg_find_attr_as_string(res->msgs[0], "classname", NULL)); 527 528 talloc_free(res); 423 529 424 530 *key = (struct hive_key *)newkd; … … 442 548 443 549 wrap = ldb_wrap_connect(parent_ctx, ev_ctx, lp_ctx, 444 location, session_info, credentials, 0 , NULL);550 location, session_info, credentials, 0); 445 551 446 552 if (wrap == NULL) { … … 477 583 { 478 584 struct ldb_key_data *parentkd = discard_const_p(struct ldb_key_data, parent); 585 struct ldb_dn *ldb_path; 479 586 struct ldb_message *msg; 480 587 struct ldb_key_data *newkd; 481 588 int ret; 482 589 590 ldb_path = reg_path_to_ldb(mem_ctx, parent, name, NULL); 591 W_ERROR_HAVE_NO_MEMORY(ldb_path); 592 483 593 msg = ldb_msg_new(mem_ctx); 484 485 msg->dn = reg_path_to_ldb(msg, parent, name, NULL); 486 487 ldb_msg_add_string(msg, "key", talloc_strdup(mem_ctx, name)); 488 if (classname != NULL) 489 ldb_msg_add_string(msg, "classname", 490 talloc_strdup(mem_ctx, classname)); 594 W_ERROR_HAVE_NO_MEMORY(msg); 595 596 msg->dn = ldb_path; 597 598 ldb_msg_add_string(msg, "key", name); 599 if (classname != NULL) { 600 ldb_msg_add_string(msg, "classname", classname); 601 } 491 602 492 603 ret = ldb_add(parentkd->ldb, msg); 604 605 talloc_free(msg); 606 493 607 if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) { 494 608 return WERR_ALREADY_EXISTS; … … 500 614 } 501 615 502 DEBUG(2, ("key added: %s\n", ldb_dn_get_linearized( msg->dn)));616 DEBUG(2, ("key added: %s\n", ldb_dn_get_linearized(ldb_path))); 503 617 504 618 newkd = talloc_zero(mem_ctx, struct ldb_key_data); 619 W_ERROR_HAVE_NO_MEMORY(newkd); 505 620 newkd->ldb = talloc_reference(newkd, parentkd->ldb); 506 621 newkd->key.ops = ®_backend_ldb; 507 newkd->dn = talloc_steal(newkd, msg->dn); 622 newkd->dn = talloc_steal(newkd, ldb_path); 623 newkd->classname = talloc_steal(newkd, classname); 508 624 509 625 *newkey = (struct hive_key *)newkd; … … 516 632 } 517 633 518 static WERROR ldb_del_value (struct hive_key *key, const char *child) 634 static WERROR ldb_del_value(TALLOC_CTX *mem_ctx, struct hive_key *key, 635 const char *child) 519 636 { 520 637 int ret; 521 638 struct ldb_key_data *kd = talloc_get_type(key, struct ldb_key_data); 522 TALLOC_CTX *mem_ctx;523 639 struct ldb_message *msg; 524 640 struct ldb_dn *childdn; 525 641 526 if ( strlen(child) == 0) {642 if (child[0] == '\0') { 527 643 /* default value */ 528 mem_ctx = talloc_init("ldb_del_value");529 530 644 msg = talloc_zero(mem_ctx, struct ldb_message); 645 W_ERROR_HAVE_NO_MEMORY(msg); 531 646 msg->dn = ldb_dn_copy(msg, kd->dn); 647 W_ERROR_HAVE_NO_MEMORY(msg->dn); 532 648 ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL); 533 649 ldb_msg_add_empty(msg, "type", LDB_FLAG_MOD_DELETE, NULL); 534 650 535 651 ret = ldb_modify(kd->ldb, msg); 652 653 talloc_free(msg); 654 536 655 if (ret != LDB_SUCCESS) { 537 656 DEBUG(1, ("ldb_del_value: %s\n", ldb_errstring(kd->ldb))); 538 talloc_free(mem_ctx);539 657 return WERR_FOOBAR; 540 658 } 541 542 talloc_free(mem_ctx);543 659 } else { 544 660 /* normal value */ … … 570 686 } 571 687 572 static WERROR ldb_del_key(const struct hive_key *key, const char *name) 573 { 574 int i, ret; 688 static WERROR ldb_del_key(TALLOC_CTX *mem_ctx, const struct hive_key *key, 689 const char *name) 690 { 691 unsigned int i; 692 int ret; 575 693 struct ldb_key_data *parentkd = talloc_get_type(key, struct ldb_key_data); 576 struct ldb_dn *ldap_path; 577 TALLOC_CTX *mem_ctx = talloc_init("ldb_del_key"); 694 struct ldb_dn *ldb_path; 578 695 struct ldb_context *c = parentkd->ldb; 579 696 struct ldb_result *res_keys; … … 585 702 werr = ldb_open_key(mem_ctx, key, name, &hk); 586 703 if (!W_ERROR_IS_OK(werr)) { 587 talloc_free(mem_ctx);588 704 return werr; 589 705 } 590 706 591 ldap_path = reg_path_to_ldb(mem_ctx, key, name, NULL); 592 if (!ldap_path) { 593 talloc_free(mem_ctx); 594 return WERR_FOOBAR; 595 } 707 ldb_path = reg_path_to_ldb(mem_ctx, key, name, NULL); 708 W_ERROR_HAVE_NO_MEMORY(ldb_path); 596 709 597 710 /* Search for subkeys */ 598 ret = ldb_search(c, mem_ctx, &res_keys, ld ap_path, LDB_SCOPE_ONELEVEL,711 ret = ldb_search(c, mem_ctx, &res_keys, ldb_path, LDB_SCOPE_ONELEVEL, 599 712 NULL, "(key=*)"); 600 713 601 714 if (ret != LDB_SUCCESS) { 602 715 DEBUG(0, ("Error getting subkeys for '%s': %s\n", 603 ldb_dn_get_linearized(ldap_path), ldb_errstring(c))); 604 talloc_free(mem_ctx); 716 ldb_dn_get_linearized(ldb_path), ldb_errstring(c))); 605 717 return WERR_FOOBAR; 606 718 } 607 719 608 720 /* Search for values */ 609 ret = ldb_search(c, mem_ctx, &res_vals, ld ap_path, LDB_SCOPE_ONELEVEL,721 ret = ldb_search(c, mem_ctx, &res_vals, ldb_path, LDB_SCOPE_ONELEVEL, 610 722 NULL, "(value=*)"); 611 723 612 724 if (ret != LDB_SUCCESS) { 613 725 DEBUG(0, ("Error getting values for '%s': %s\n", 614 ldb_dn_get_linearized(ldap_path), ldb_errstring(c))); 615 talloc_free(mem_ctx); 726 ldb_dn_get_linearized(ldb_path), ldb_errstring(c))); 616 727 return WERR_FOOBAR; 617 728 } … … 622 733 if (ret != LDB_SUCCESS) { 623 734 DEBUG(0, ("ldb_transaction_start: %s\n", ldb_errstring(c))); 624 talloc_free(mem_ctx);625 735 return WERR_FOOBAR; 626 736 } … … 631 741 for (i = 0; i < res_keys->count; i++) 632 742 { 633 werr = ldb_del_key(hk, ldb_msg_find_attr_as_string( 743 werr = ldb_del_key(mem_ctx, hk, 744 ldb_msg_find_attr_as_string( 634 745 res_keys->msgs[i], 635 746 "key", NULL)); 636 747 if (!W_ERROR_IS_OK(werr)) { 637 748 ret = ldb_transaction_cancel(c); 638 talloc_free(mem_ctx);639 749 return werr; 640 750 } … … 644 754 for (i = 0; i < res_vals->count; i++) 645 755 { 646 werr = ldb_del_value(hk, ldb_msg_find_attr_as_string( 756 werr = ldb_del_value(mem_ctx, hk, 757 ldb_msg_find_attr_as_string( 647 758 res_vals->msgs[i], 648 759 "value", NULL)); 649 760 if (!W_ERROR_IS_OK(werr)) { 650 761 ret = ldb_transaction_cancel(c); 651 talloc_free(mem_ctx);652 762 return werr; 653 763 } 654 764 } 655 765 } 766 talloc_free(res_keys); 767 talloc_free(res_vals); 656 768 657 769 /* Delete the key itself */ 658 ret = ldb_delete(c, ld ap_path);770 ret = ldb_delete(c, ldb_path); 659 771 660 772 if (ret != LDB_SUCCESS) … … 662 774 DEBUG(1, ("ldb_del_key: %s\n", ldb_errstring(c))); 663 775 ret = ldb_transaction_cancel(c); 664 talloc_free(mem_ctx);665 776 return WERR_FOOBAR; 666 777 } … … 673 784 DEBUG(0, ("ldb_transaction_commit: %s\n", ldb_errstring(c))); 674 785 ret = ldb_transaction_cancel(c); 675 talloc_free(mem_ctx); 676 return WERR_FOOBAR; 677 } 678 679 talloc_free(mem_ctx); 786 return WERR_FOOBAR; 787 } 680 788 681 789 /* reset cache */ … … 692 800 struct ldb_message *msg; 693 801 struct ldb_key_data *kd = talloc_get_type(parent, struct ldb_key_data); 802 unsigned int i; 694 803 int ret; 695 804 TALLOC_CTX *mem_ctx = talloc_init("ldb_set_value"); 696 805 697 806 msg = reg_ldb_pack_value(kd->ldb, mem_ctx, name, type, data); 807 W_ERROR_HAVE_NO_MEMORY(msg); 808 698 809 msg->dn = ldb_dn_copy(msg, kd->dn); 699 700 if (strlen(name) > 0) { 810 W_ERROR_HAVE_NO_MEMORY(msg->dn); 811 812 if (name[0] != '\0') { 701 813 /* For a default value, we add/overwrite the attributes to/of the hive. 702 For a normal value, we create new childs. */814 For a normal value, we create a new child. */ 703 815 if (!ldb_dn_add_child_fmt(msg->dn, "value=%s", 704 816 reg_ldb_escape(mem_ctx, name))) … … 709 821 } 710 822 711 ret = ldb_add(kd->ldb, msg); 712 if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) { 713 int i; 714 for (i = 0; i < msg->num_elements; i++) { 715 if (msg->elements[i].flags != LDB_FLAG_MOD_DELETE) 716 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE; 717 } 718 ret = ldb_modify(kd->ldb, msg); 719 } 823 /* Try first a "modify" and if this doesn't work do try an "add" */ 824 for (i = 0; i < msg->num_elements; i++) { 825 if (msg->elements[i].flags != LDB_FLAG_MOD_DELETE) { 826 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE; 827 } 828 } 829 ret = ldb_modify(kd->ldb, msg); 830 if (ret == LDB_ERR_NO_SUCH_OBJECT) { 831 i = 0; 832 while (i < msg->num_elements) { 833 if (LDB_FLAG_MOD_TYPE(msg->elements[i].flags) == LDB_FLAG_MOD_DELETE) { 834 ldb_msg_remove_element(msg, &msg->elements[i]); 835 } else { 836 ++i; 837 } 838 } 839 ret = ldb_add(kd->ldb, msg); 840 } 841 if (ret == LDB_ERR_NO_SUCH_ATTRIBUTE) { 842 /* ignore this -> the value didn't exist and also now doesn't */ 843 ret = LDB_SUCCESS; 844 } 845 846 talloc_free(msg); 720 847 721 848 if (ret != LDB_SUCCESS) { … … 744 871 { 745 872 struct ldb_key_data *kd = talloc_get_type(key, struct ldb_key_data); 873 uint32_t default_value_type = REG_NONE; 874 DATA_BLOB default_value = { NULL, 0 }; 875 WERROR werr; 746 876 747 877 /* Initialization */ … … 761 891 *max_valbufsize = 0; 762 892 893 /* We need this to get the default value (if it exists) for counting 894 * the values under the key and for finding out the longest value buffer 895 * size. If no default value exists the DATA_BLOB "default_value" will 896 * remain { NULL, 0 }. */ 897 werr = ldb_get_default_value(mem_ctx, key, NULL, &default_value_type, 898 &default_value); 899 if ((!W_ERROR_IS_OK(werr)) && (!W_ERROR_EQUAL(werr, WERR_BADFILE))) { 900 return werr; 901 } 902 763 903 if (kd->subkeys == NULL) { 764 904 W_ERROR_NOT_OK_RETURN(cache_subkeys(kd)); 765 905 } 766 767 906 if (kd->values == NULL) { 768 907 W_ERROR_NOT_OK_RETURN(cache_values(kd)); 769 908 } 770 909 910 if (classname != NULL) { 911 *classname = kd->classname; 912 } 913 771 914 if (num_subkeys != NULL) { 772 915 *num_subkeys = kd->subkey_count; … … 774 917 if (num_values != NULL) { 775 918 *num_values = kd->value_count; 919 /* also consider the default value if it exists */ 920 if (default_value.data != NULL) { 921 ++(*num_values); 922 } 776 923 } 777 924 778 925 779 926 if (max_subkeynamelen != NULL) { 780 int i;927 unsigned int i; 781 928 struct ldb_message_element *el; 782 783 *max_subkeynamelen = 0;784 929 785 930 for (i = 0; i < kd->subkey_count; i++) { … … 790 935 791 936 if (max_valnamelen != NULL || max_valbufsize != NULL) { 792 int i;937 unsigned int i; 793 938 struct ldb_message_element *el; 794 939 W_ERROR_NOT_OK_RETURN(cache_values(kd)); 795 940 796 if (max_valbufsize != NULL)797 *max_valbufsize = 0;798 799 if (max_valnamelen != NULL)800 *max_valnamelen = 0;941 /* also consider the default value if it exists */ 942 if ((max_valbufsize != NULL) && (default_value.data != NULL)) { 943 *max_valbufsize = MAX(*max_valbufsize, 944 default_value.length); 945 } 801 946 802 947 for (i = 0; i < kd->value_count; i++) { … … 809 954 uint32_t data_type; 810 955 DATA_BLOB data; 811 reg_ldb_unpack_value(mem_ctx, 812 kd->values[i], NULL, 956 reg_ldb_unpack_value(mem_ctx, 957 kd->values[i], NULL, 813 958 &data_type, &data); 814 959 *max_valbufsize = MAX(*max_valbufsize, data.length); … … 817 962 } 818 963 } 964 965 talloc_free(default_value.data); 819 966 820 967 return WERR_OK; -
vendor/current/source4/lib/registry/local.c
r414 r740 58 58 59 59 local_key = talloc(ctx, struct local_key); 60 local_key->hive_key = talloc_steal(local_key, hive); 61 local_key->global.context = talloc_reference(local_key, ctx); 62 local_key->path = parent_path; 60 if (local_key != NULL) { 61 local_key->hive_key = talloc_reference(local_key, hive); 62 local_key->global.context = talloc_reference(local_key, ctx); 63 local_key->path = parent_path; 64 } 63 65 64 66 return (struct registry_key *)local_key; … … 71 73 struct registry_key **result) 72 74 { 73 char *orig = talloc_strdup(mem_ctx, path), 74 *curbegin = orig, 75 *curend = strchr(orig, '\\'); 75 char *orig, *curbegin, *curend; 76 76 struct local_key *local_parent = talloc_get_type(parent, 77 77 struct local_key); … … 81 81 int el; 82 82 83 if (path == NULL) { 84 return WERR_INVALID_PARAM; 85 } 86 87 orig = talloc_strdup(mem_ctx, path); 88 W_ERROR_HAVE_NO_MEMORY(orig); 89 curbegin = orig; 90 curend = strchr(orig, '\\'); 91 83 92 if (local_parent->path.elements != NULL) { 84 93 elements = talloc_array(mem_ctx, const char *, 85 94 str_list_length(local_parent->path.elements) + 1); 95 W_ERROR_HAVE_NO_MEMORY(elements); 86 96 for (el = 0; local_parent->path.elements[el] != NULL; el++) { 87 97 elements[el] = talloc_reference(elements, … … 98 108 *curend = '\0'; 99 109 elements = talloc_realloc(mem_ctx, elements, const char *, el+2); 110 W_ERROR_HAVE_NO_MEMORY(elements); 100 111 elements[el] = talloc_strdup(elements, curbegin); 112 W_ERROR_HAVE_NO_MEMORY(elements[el]); 101 113 el++; 102 114 elements[el] = NULL; … … 159 171 160 172 static WERROR local_create_key(TALLOC_CTX *mem_ctx, 161 struct registry_key *parent _key,162 const char * name,173 struct registry_key *parent, 174 const char *path, 163 175 const char *key_class, 164 176 struct security_descriptor *security, 165 struct registry_key **key) 166 { 167 struct local_key *local_parent; 168 struct hive_key *hivekey; 169 const char **elements; 170 int i; 171 const char *last_part; 172 173 last_part = strrchr(name, '\\'); 174 if (last_part == NULL) { 175 last_part = name; 176 local_parent = (struct local_key *)parent_key; 177 struct registry_key **result) 178 { 179 char *orig, *curbegin, *curend; 180 struct local_key *local_parent = talloc_get_type(parent, 181 struct local_key); 182 struct hive_key *curkey = local_parent->hive_key; 183 WERROR error; 184 const char **elements = NULL; 185 int el; 186 187 if (path == NULL) { 188 return WERR_INVALID_PARAM; 189 } 190 191 orig = talloc_strdup(mem_ctx, path); 192 W_ERROR_HAVE_NO_MEMORY(orig); 193 curbegin = orig; 194 curend = strchr(orig, '\\'); 195 196 if (local_parent->path.elements != NULL) { 197 elements = talloc_array(mem_ctx, const char *, 198 str_list_length(local_parent->path.elements) + 1); 199 W_ERROR_HAVE_NO_MEMORY(elements); 200 for (el = 0; local_parent->path.elements[el] != NULL; el++) { 201 elements[el] = talloc_reference(elements, 202 local_parent->path.elements[el]); 203 } 204 elements[el] = NULL; 177 205 } else { 178 W_ERROR_NOT_OK_RETURN(reg_open_key(mem_ctx, parent_key, 179 talloc_strndup(mem_ctx, name, last_part-name), 180 (struct registry_key **)&local_parent)); 181 last_part++; 182 } 183 184 W_ERROR_NOT_OK_RETURN(hive_key_add_name(mem_ctx, local_parent->hive_key, 185 last_part, key_class, security, 186 &hivekey)); 187 188 if (local_parent->path.elements != NULL) { 189 elements = talloc_array(hivekey, const char *, 190 str_list_length(local_parent->path.elements)+2); 191 for (i = 0; local_parent->path.elements[i] != NULL; i++) { 192 elements[i] = talloc_reference(elements, 193 local_parent->path.elements[i]); 194 } 195 } else { 196 elements = talloc_array(hivekey, const char *, 2); 197 i = 0; 198 } 199 200 elements[i] = talloc_strdup(elements, name); 201 elements[i+1] = NULL; 202 203 *key = reg_import_hive_key(local_parent->global.context, hivekey, 204 local_parent->path.predefined_key, 205 elements); 206 elements = NULL; 207 el = 0; 208 } 209 210 while (curbegin != NULL && *curbegin) { 211 if (curend != NULL) 212 *curend = '\0'; 213 elements = talloc_realloc(mem_ctx, elements, const char *, el+2); 214 W_ERROR_HAVE_NO_MEMORY(elements); 215 elements[el] = talloc_strdup(elements, curbegin); 216 W_ERROR_HAVE_NO_MEMORY(elements[el]); 217 el++; 218 elements[el] = NULL; 219 error = hive_get_key_by_name(mem_ctx, curkey, 220 curbegin, &curkey); 221 if (W_ERROR_EQUAL(error, WERR_BADFILE)) { 222 error = hive_key_add_name(mem_ctx, curkey, curbegin, 223 key_class, security, 224 &curkey); 225 } 226 if (!W_ERROR_IS_OK(error)) { 227 DEBUG(2, ("Open/Creation of key %s failed: %s\n", 228 curbegin, win_errstr(error))); 229 talloc_free(orig); 230 return error; 231 } 232 if (curend == NULL) 233 break; 234 curbegin = curend + 1; 235 curend = strchr(curbegin, '\\'); 236 } 237 talloc_free(orig); 238 239 *result = reg_import_hive_key(local_parent->global.context, curkey, 240 local_parent->path.predefined_key, 241 talloc_steal(curkey, elements)); 206 242 207 243 return WERR_OK; … … 212 248 { 213 249 struct local_key *local = (struct local_key *)key; 250 251 if (name == NULL) { 252 return WERR_INVALID_PARAM; 253 } 214 254 215 255 return hive_key_set_value(local->hive_key, name, type, data); … … 221 261 { 222 262 const struct local_key *local = (const struct local_key *)key; 263 264 if (name == NULL) { 265 return WERR_INVALID_PARAM; 266 } 223 267 224 268 return hive_get_value(mem_ctx, local->hive_key, name, type, data); … … 237 281 } 238 282 239 static WERROR local_delete_key(struct registry_key *key, const char *name) 240 { 241 const struct local_key *local = (const struct local_key *)key; 242 243 return hive_key_del(local->hive_key, name); 244 } 245 246 static WERROR local_delete_value(struct registry_key *key, const char *name) 247 { 248 const struct local_key *local = (const struct local_key *)key; 249 250 return hive_key_del_value(local->hive_key, name); 283 static WERROR local_delete_key(TALLOC_CTX *mem_ctx, struct registry_key *key, 284 const char *name) 285 { 286 const struct local_key *local = (const struct local_key *)key; 287 288 if (name == NULL) { 289 return WERR_INVALID_PARAM; 290 } 291 292 return hive_key_del(mem_ctx, local->hive_key, name); 293 } 294 295 static WERROR local_delete_value(TALLOC_CTX *mem_ctx, struct registry_key *key, 296 const char *name) 297 { 298 const struct local_key *local = (const struct local_key *)key; 299 300 if (name == NULL) { 301 return WERR_INVALID_PARAM; 302 } 303 304 return hive_key_del_value(mem_ctx, local->hive_key, name); 251 305 } 252 306 … … 328 382 struct registry_local *reg_local = talloc_get_type(rctx, 329 383 struct registry_local); 330 struct mountpoint *mp = talloc(rctx, struct mountpoint); 331 int i = 0; 332 384 struct mountpoint *mp; 385 unsigned int i = 0; 386 387 mp = talloc(rctx, struct mountpoint); 388 W_ERROR_HAVE_NO_MEMORY(mp); 333 389 mp->path.predefined_key = key_id; 334 390 mp->prev = mp->next = NULL; … … 337 393 mp->path.elements = talloc_array(mp, const char *, 338 394 str_list_length(elements)); 395 W_ERROR_HAVE_NO_MEMORY(mp->path.elements); 339 396 for (i = 0; elements[i] != NULL; i++) { 340 397 mp->path.elements[i] = talloc_reference(mp->path.elements, -
vendor/current/source4/lib/registry/man/regdiff.1.xml
r414 r740 1 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 <!DOCTYPE refentry PUBLIC "-// Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> 3 3 <refentry id="regdiff.1"> 4 4 -
vendor/current/source4/lib/registry/man/regpatch.1.xml
r414 r740 1 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 <!DOCTYPE refentry PUBLIC "-// Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> 3 3 <refentry id="regpatch.1"> 4 4 -
vendor/current/source4/lib/registry/man/regshell.1.xml
r414 r740 1 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 <!DOCTYPE refentry PUBLIC "-// Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> 3 3 <refentry id="regshell.1"> 4 4 -
vendor/current/source4/lib/registry/man/regtree.1.xml
r414 r740 1 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 <!DOCTYPE refentry PUBLIC "-// Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> 3 3 <refentry id="regtree.1"> 4 4 -
vendor/current/source4/lib/registry/patchfile.c
r414 r740 5 5 Copyright (C) Jelmer Vernooij 2004-2007 6 6 Copyright (C) Wilco Baan Hofman 2006 7 Copyright (C) Matthias Dieter Wallnöfer 2008 7 Copyright (C) Matthias Dieter Wallnöfer 2008-2010 8 8 9 9 This program is free software; you can redistribute it and/or modify … … 27 27 28 28 _PUBLIC_ WERROR reg_preg_diff_load(int fd, 29 struct smb_iconv_convenience *iconv_convenience,30 29 const struct reg_diff_callbacks *callbacks, 31 30 void *callback_data); 32 31 33 32 _PUBLIC_ WERROR reg_dotreg_diff_load(int fd, 34 struct smb_iconv_convenience *iconv_convenience,35 33 const struct reg_diff_callbacks *callbacks, 36 34 void *callback_data); … … 45 43 void *callback_data) 46 44 { 47 int i;45 unsigned int i; 48 46 struct registry_key *t1 = NULL, *t2 = NULL; 49 47 char *tmppath; … … 87 85 88 86 if (!W_ERROR_IS_OK(error2) && !W_ERROR_EQUAL(error2, WERR_BADFILE)) { 89 DEBUG(0, ("Error occur ed while getting subkey by name: %s\n",87 DEBUG(0, ("Error occurred while getting subkey by name: %s\n", 90 88 win_errstr(error2))); 91 89 talloc_free(mem_ctx); … … 96 94 /* didn't have such a subkey and therefore add a del diff */ 97 95 tmppath = talloc_asprintf(mem_ctx, "%s\\%s", path, keyname1); 96 if (tmppath == NULL) { 97 DEBUG(0, ("Out of memory\n")); 98 talloc_free(mem_ctx); 99 return WERR_NOMEM; 100 } 98 101 if (!W_ERROR_IS_OK(error2)) 99 102 callbacks->del_key(callback_data, tmppath); … … 102 105 error1 = reg_open_key(mem_ctx, oldkey, keyname1, &t1); 103 106 if (!W_ERROR_IS_OK(error1)) { 104 DEBUG(0, ("Error occur ed while getting subkey by name: %s\n",107 DEBUG(0, ("Error occurred while getting subkey by name: %s\n", 105 108 win_errstr(error1))); 106 109 talloc_free(mem_ctx); … … 155 158 } 156 159 157 /* oldkey didn't have such a subkey, add a dd diff */160 /* oldkey didn't have such a subkey, add a add diff */ 158 161 tmppath = talloc_asprintf(mem_ctx, "%s\\%s", path, keyname1); 162 if (tmppath == NULL) { 163 DEBUG(0, ("Out of memory\n")); 164 talloc_free(mem_ctx); 165 return WERR_NOMEM; 166 } 159 167 callbacks->add_key(callback_data, tmppath); 160 168 … … 162 170 error1 = reg_open_key(mem_ctx, newkey, keyname1, &t2); 163 171 if (!W_ERROR_IS_OK(error1)) { 164 DEBUG(0, ("Error occur ed while getting subkey by name: %s\n",172 DEBUG(0, ("Error occurred while getting subkey by name: %s\n", 165 173 win_errstr(error1))); 166 174 talloc_free(mem_ctx); … … 176 184 const char *name; 177 185 uint32_t type1, type2; 178 DATA_BLOB contents1 , contents2;186 DATA_BLOB contents1 = { NULL, 0 }, contents2 = { NULL, 0 }; 179 187 180 188 error1 = reg_key_get_value_by_index(mem_ctx, newkey, i, … … 203 211 204 212 if (W_ERROR_IS_OK(error2) 205 && (data_blob_cmp(&contents1, &contents2) == 0) 206 && (type1 == type2)) 213 && (data_blob_cmp(&contents1, &contents2) == 0) 214 && (type1 == type2)) { 215 talloc_free(discard_const_p(char, name)); 216 talloc_free(contents1.data); 217 talloc_free(contents2.data); 207 218 continue; 219 } 208 220 209 221 callbacks->set_value(callback_data, path, name, 210 222 type1, contents1); 223 224 talloc_free(discard_const_p(char, name)); 225 talloc_free(contents1.data); 226 talloc_free(contents2.data); 211 227 } 212 228 … … 215 231 const char *name; 216 232 uint32_t type; 217 DATA_BLOB contents ;233 DATA_BLOB contents = { NULL, 0 }; 218 234 219 235 error1 = reg_key_get_value_by_index(mem_ctx, oldkey, i, &name, … … 232 248 error2 = WERR_BADFILE; 233 249 234 if (W_ERROR_IS_OK(error2)) 250 if (W_ERROR_IS_OK(error2)) { 251 talloc_free(discard_const_p(char, name)); 252 talloc_free(contents.data); 235 253 continue; 254 } 236 255 237 256 if (!W_ERROR_EQUAL(error2, WERR_BADFILE)) { … … 243 262 244 263 callbacks->del_value(callback_data, path, name); 264 265 talloc_free(discard_const_p(char, name)); 266 talloc_free(contents.data); 245 267 } 246 268 … … 257 279 void *callback_data) 258 280 { 259 int i;281 unsigned int i; 260 282 WERROR error; 261 283 … … 281 303 } 282 304 305 /* if "r1" is NULL (old hive) and "r2" isn't (new hive) then 306 * the hive doesn't exist yet and we have to generate an add 307 * diff */ 308 if ((r1 == NULL) && (r2 != NULL)) { 309 callbacks->add_key(callback_data, 310 reg_predefined_keys[i].name); 311 } 312 /* if "r1" isn't NULL (old hive) and "r2" is (new hive) then 313 * the hive shouldn't exist anymore and we have to generate a 314 * del diff */ 315 if ((r1 != NULL) && (r2 == NULL)) { 316 callbacks->del_key(callback_data, 317 reg_predefined_keys[i].name); 318 } 319 283 320 error = reg_generate_diff_key(r1, r2, 284 321 reg_predefined_keys[i].name, callbacks, … … 300 337 */ 301 338 _PUBLIC_ WERROR reg_diff_load(const char *filename, 302 struct smb_iconv_convenience *iconv_convenience,303 339 const struct reg_diff_callbacks *callbacks, 304 340 void *callback_data) … … 334 370 if (strncmp(hdr, "PReg", 4) == 0) { 335 371 /* Must be a GPO Registry.pol file */ 336 return reg_preg_diff_load(fd, iconv_convenience,callbacks, callback_data);372 return reg_preg_diff_load(fd, callbacks, callback_data); 337 373 } else { 338 374 /* Must be a normal .REG file */ 339 return reg_dotreg_diff_load(fd, iconv_convenience,callbacks, callback_data);375 return reg_dotreg_diff_load(fd, callbacks, callback_data); 340 376 } 341 377 } … … 353 389 /* Recursively create the path */ 354 390 buf = talloc_strdup(ctx, key_name); 391 W_ERROR_HAVE_NO_MEMORY(buf); 355 392 buf_ptr = buf; 356 393 … … 367 404 } 368 405 *buf_ptr++ = '\\'; 369 } 370 } 406 talloc_free(tmp); 407 } 408 } 409 410 talloc_free(buf); 371 411 372 412 /* Add the key */ … … 379 419 return error; 380 420 } 421 talloc_free(tmp); 422 381 423 return WERR_OK; 382 424 } … … 388 430 /* We can't proof here for success, because a common superkey could */ 389 431 /* have been deleted before the subkey's (diff order). This removed */ 390 /* therefore all child srecursively and the "WERR_BADFILE" result is */432 /* therefore all children recursively and the "WERR_BADFILE" result is */ 391 433 /* expected. */ 392 434 … … 420 462 } 421 463 464 talloc_free(tmp); 465 422 466 return WERR_OK; 423 467 } … … 438 482 } 439 483 440 error = reg_del_value( tmp, value_name);484 error = reg_del_value(ctx, tmp, value_name); 441 485 if (!W_ERROR_IS_OK(error)) { 442 486 DEBUG(0, ("Error deleting value '%s'\n", value_name)); … … 444 488 } 445 489 490 talloc_free(tmp); 446 491 447 492 return WERR_OK; … … 453 498 struct registry_key *key; 454 499 WERROR error; 455 const char *value_name;500 const char *value_name; 456 501 457 502 error = reg_open_key_abs(ctx, ctx, key_name, &key); … … 467 512 while (W_ERROR_IS_OK(reg_key_get_value_by_index( 468 513 ctx, key, 0, &value_name, NULL, NULL))) { 469 error = reg_del_value( key, value_name);514 error = reg_del_value(ctx, key, value_name); 470 515 if (!W_ERROR_IS_OK(error)) { 471 516 DEBUG(0, ("Error deleting value '%s'\n", value_name)); 472 517 return error; 473 518 } 474 } 519 talloc_free(discard_const_p(char, value_name)); 520 } 521 522 talloc_free(key); 475 523 476 524 return WERR_OK; … … 481 529 */ 482 530 _PUBLIC_ WERROR reg_diff_apply(struct registry_context *ctx, 483 struct smb_iconv_convenience *iconv_convenience,484 531 const char *filename) 485 532 { … … 493 540 callbacks.done = NULL; 494 541 495 return reg_diff_load(filename, iconv_convenience, 496 &callbacks, ctx); 497 } 542 return reg_diff_load(filename, &callbacks, ctx); 543 } -
vendor/current/source4/lib/registry/patchfile_dotreg.c
r414 r740 4 4 5 5 Copyright (C) Jelmer Vernooij 2004-2007 6 Copyright (C) Wilco Baan Hofman 2006-20 086 Copyright (C) Wilco Baan Hofman 2006-2010 7 7 8 8 This program is free software; you can redistribute it and/or modify … … 21 21 */ 22 22 23 /* FIXME Newer .REG files, created by Windows XP and above use unicode UCS-2 */ 23 /* FIXME: 24 * - Newer .REG files, created by Windows XP and above use unicode UCS-2 25 * - @="" constructions should write value with empty name. 26 */ 24 27 25 28 #include "includes.h" … … 36 39 struct dotreg_data { 37 40 int fd; 38 struct smb_iconv_convenience *iconv_convenience;39 41 }; 42 43 /* 44 * This is basically a copy of data_blob_hex_string_upper, but with comma's 45 * between the bytes in hex. 46 */ 47 static char *dotreg_data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob) 48 { 49 size_t i; 50 char *hex_string; 51 52 hex_string = talloc_array(mem_ctx, char, (blob->length*3)+1); 53 if (!hex_string) { 54 return NULL; 55 } 56 57 for (i = 0; i < blob->length; i++) 58 slprintf(&hex_string[i*3], 4, "%02X,", blob->data[i]); 59 60 /* Remove last comma and NULL-terminate the string */ 61 hex_string[(blob->length*3)-1] = '\0'; 62 return hex_string; 63 } 64 65 /* 66 * This is basically a copy of reg_val_data_string, except that this function 67 * has no 0x for dwords, everything else is regarded as binary, and binary 68 * strings are represented with bytes comma-separated. 69 */ 70 static char *reg_val_dotreg_string(TALLOC_CTX *mem_ctx, uint32_t type, 71 const DATA_BLOB data) 72 { 73 char *ret = NULL; 74 75 if (data.length == 0) 76 return talloc_strdup(mem_ctx, ""); 77 78 switch (type) { 79 case REG_EXPAND_SZ: 80 case REG_SZ: 81 convert_string_talloc(mem_ctx, 82 CH_UTF16, CH_UNIX, data.data, data.length, 83 (void **)&ret, NULL, false); 84 break; 85 case REG_DWORD: 86 case REG_DWORD_BIG_ENDIAN: 87 SMB_ASSERT(data.length == sizeof(uint32_t)); 88 ret = talloc_asprintf(mem_ctx, "%08x", 89 IVAL(data.data, 0)); 90 break; 91 default: /* default means treat as binary */ 92 case REG_BINARY: 93 ret = dotreg_data_blob_hex_string(mem_ctx, &data); 94 break; 95 } 96 97 return ret; 98 } 40 99 41 100 static WERROR reg_dotreg_diff_add_key(void *_data, const char *key_name) … … 62 121 { 63 122 struct dotreg_data *data = (struct dotreg_data *)_data; 64 65 fdprintf(data->fd, "\"%s\"=%s:%s\n", 66 value_name, str_regtype(value_type), 67 reg_val_data_string(NULL, data->iconv_convenience, value_type, value)); 123 char *data_string = reg_val_dotreg_string(NULL, 124 value_type, value); 125 char *data_incl_type; 126 127 W_ERROR_HAVE_NO_MEMORY(data_string); 128 129 switch (value_type) { 130 case REG_SZ: 131 data_incl_type = talloc_asprintf(data_string, "\"%s\"", 132 data_string); 133 break; 134 case REG_DWORD: 135 data_incl_type = talloc_asprintf(data_string, 136 "dword:%s", data_string); 137 break; 138 case REG_BINARY: 139 data_incl_type = talloc_asprintf(data_string, "hex:%s", 140 data_string); 141 break; 142 default: 143 data_incl_type = talloc_asprintf(data_string, "hex(%x):%s", 144 value_type, data_string); 145 break; 146 } 147 148 if (value_name[0] == '\0') { 149 fdprintf(data->fd, "@=%s\n", data_incl_type); 150 } else { 151 fdprintf(data->fd, "\"%s\"=%s\n", 152 value_name, data_incl_type); 153 } 154 155 talloc_free(data_string); 68 156 69 157 return WERR_OK; … … 100 188 */ 101 189 _PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename, 102 struct smb_iconv_convenience *iconv_convenience,103 190 struct reg_diff_callbacks **callbacks, 104 191 void **callback_data) … … 108 195 data = talloc_zero(ctx, struct dotreg_data); 109 196 *callback_data = data; 110 111 data->iconv_convenience = iconv_convenience;112 197 113 198 if (filename) { … … 139 224 */ 140 225 _PUBLIC_ WERROR reg_dotreg_diff_load(int fd, 141 struct smb_iconv_convenience *iconv_convenience,142 226 const struct reg_diff_callbacks *callbacks, 143 227 void *callback_data) … … 148 232 WERROR error; 149 233 uint32_t value_type; 150 DATA_BLOB value; 234 DATA_BLOB data; 235 bool result; 236 char *type_str = NULL; 237 char *data_str; 238 char *value; 239 bool continue_next_line = 0; 151 240 152 241 line = afdgets(fd, mem_ctx, 0); … … 159 248 160 249 while ((line = afdgets(fd, mem_ctx, 0))) { 250 /* Remove '\r' if it's a Windows text file */ 251 if (line[strlen(line)-1] == '\r') { 252 line[strlen(line)-1] = '\0'; 253 } 254 161 255 /* Ignore comments and empty lines */ 162 256 if (strlen(line) == 0 || line[0] == ';') { … … 172 266 /* Start of key */ 173 267 if (line[0] == '[') { 174 p = strchr_m(line, ']'); 175 if (p[strlen(p)-1] != ']') { 176 DEBUG(0, ("Missing ']'\n")); 177 return WERR_GENERAL_FAILURE; 178 } 268 if (line[strlen(line)-1] != ']') { 269 DEBUG(0, ("Missing ']' on line: %s\n", line)); 270 talloc_free(line); 271 continue; 272 } 273 179 274 /* Deleting key */ 180 275 if (line[1] == '-') { 181 276 curkey = talloc_strndup(line, line+2, strlen(line)-3); 277 W_ERROR_HAVE_NO_MEMORY(curkey); 182 278 183 279 error = callbacks->del_key(callback_data, 184 280 curkey); 281 185 282 if (!W_ERROR_IS_OK(error)) { 186 283 DEBUG(0,("Error deleting key %s\n", … … 195 292 } 196 293 curkey = talloc_strndup(mem_ctx, line+1, strlen(line)-2); 294 W_ERROR_HAVE_NO_MEMORY(curkey); 197 295 198 296 error = callbacks->add_key(callback_data, curkey); … … 208 306 209 307 /* Deleting/Changing value */ 210 p = strchr_m(line, '='); 211 if (p == NULL) { 212 DEBUG(0, ("Malformed line\n")); 213 talloc_free(line); 214 continue; 215 } 216 217 *p = '\0'; p++; 218 219 if (curkey == NULL) { 220 DEBUG(0, ("Value change without key\n")); 221 talloc_free(line); 222 continue; 223 } 224 225 /* Delete value */ 226 if (strcmp(p, "-") == 0) { 227 error = callbacks->del_value(callback_data, 228 curkey, line); 229 if (!W_ERROR_IS_OK(error)) { 230 DEBUG(0, ("Error deleting value %s in key %s\n", 231 line, curkey)); 232 talloc_free(mem_ctx); 233 return error; 234 } 235 236 talloc_free(line); 237 continue; 238 } 239 240 q = strchr_m(p, ':'); 241 if (q) { 242 *q = '\0'; 243 q++; 244 } 245 246 reg_string_to_val(line, iconv_convenience, 247 q?p:"REG_SZ", q?q:p, 248 &value_type, &value); 249 250 error = callbacks->set_value(callback_data, curkey, line, 251 value_type, value); 308 if (continue_next_line) { 309 continue_next_line = 0; 310 311 /* Continued data start with two whitespaces */ 312 if (line[0] != ' ' || line[1] != ' ') { 313 DEBUG(0, ("Malformed line: %s\n", line)); 314 talloc_free(line); 315 continue; 316 } 317 p = line + 2; 318 319 /* Continue again if line ends with a backslash */ 320 if (line[strlen(line)-1] == '\\') { 321 line[strlen(line)-1] = '\0'; 322 continue_next_line = 1; 323 data_str = talloc_strdup_append(data_str, p); 324 talloc_free(line); 325 continue; 326 } 327 data_str = talloc_strdup_append(data_str, p); 328 } else { 329 p = strchr_m(line, '='); 330 if (p == NULL) { 331 DEBUG(0, ("Malformed line: %s\n", line)); 332 talloc_free(line); 333 continue; 334 } 335 336 *p = '\0'; p++; 337 338 339 if (curkey == NULL) { 340 DEBUG(0, ("Value change without key\n")); 341 talloc_free(line); 342 continue; 343 } 344 345 /* Values should be double-quoted */ 346 if (line[0] != '"') { 347 DEBUG(0, ("Malformed line\n")); 348 talloc_free(line); 349 continue; 350 } 351 352 /* Chop of the quotes and store as value */ 353 value = talloc_strndup(mem_ctx, line+1,strlen(line)-2); 354 355 /* Delete value */ 356 if (p[0] == '-') { 357 error = callbacks->del_value(callback_data, 358 curkey, value); 359 360 /* Ignore if key does not exist (WERR_BADFILE) 361 * Consistent with Windows behaviour */ 362 if (!W_ERROR_IS_OK(error) && 363 !W_ERROR_EQUAL(error, WERR_BADFILE)) { 364 DEBUG(0, ("Error deleting value %s in key %s\n", 365 value, curkey)); 366 talloc_free(mem_ctx); 367 return error; 368 } 369 370 talloc_free(line); 371 talloc_free(value); 372 continue; 373 } 374 375 /* Do not look for colons in strings */ 376 if (p[0] == '"') { 377 q = NULL; 378 data_str = talloc_strndup(mem_ctx, p+1,strlen(p)-2); 379 } else { 380 /* Split the value type from the data */ 381 q = strchr_m(p, ':'); 382 if (q) { 383 *q = '\0'; 384 q++; 385 type_str = talloc_strdup(mem_ctx, p); 386 data_str = talloc_strdup(mem_ctx, q); 387 } else { 388 data_str = talloc_strdup(mem_ctx, p); 389 } 390 } 391 392 /* Backslash before the CRLF means continue on next line */ 393 if (data_str[strlen(data_str)-1] == '\\') { 394 data_str[strlen(data_str)-1] = '\0'; 395 talloc_free(line); 396 continue_next_line = 1; 397 continue; 398 } 399 } 400 DEBUG(9, ("About to write %s with type %s, length %ld: %s\n", value, type_str, (long) strlen(data_str), data_str)); 401 result = reg_string_to_val(value, 402 type_str?type_str:"REG_SZ", data_str, 403 &value_type, &data); 404 if (!result) { 405 DEBUG(0, ("Error converting string to value for line:\n%s\n", 406 line)); 407 return WERR_GENERAL_FAILURE; 408 } 409 410 error = callbacks->set_value(callback_data, curkey, value, 411 value_type, data); 252 412 if (!W_ERROR_IS_OK(error)) { 253 413 DEBUG(0, ("Error setting value for %s in %s\n", 254 line, curkey));414 value, curkey)); 255 415 talloc_free(mem_ctx); 256 416 return error; 257 417 } 258 418 419 /* Clean up buffers */ 420 if (type_str != NULL) { 421 talloc_free(type_str); 422 type_str = NULL; 423 } 424 talloc_free(data_str); 425 talloc_free(value); 259 426 talloc_free(line); 260 427 } … … 262 429 close(fd); 263 430 264 return WERR_OK; 265 } 431 talloc_free(mem_ctx); 432 433 return WERR_OK; 434 } -
vendor/current/source4/lib/registry/patchfile_preg.c
r414 r740 34 34 uint16_t v; 35 35 36 if (read(fd, &v, 2) < 2) {36 if (read(fd, &v, sizeof(uint16_t)) < sizeof(uint16_t)) { 37 37 return WERR_GENERAL_FAILURE; 38 38 } … … 42 42 static WERROR preg_write_utf16(int fd, const char *string) 43 43 { 44 codepoint_t v; 45 uint16_t i; 46 size_t size; 44 uint16_t v; 45 size_t i, size; 47 46 48 47 for (i = 0; i < strlen(string); i+=size) { 49 48 v = next_codepoint(&string[i], &size); 50 if (write(fd, &v, 2) < 2) {49 if (write(fd, &v, sizeof(uint16_t)) < sizeof(uint16_t)) { 51 50 return WERR_GENERAL_FAILURE; 52 51 } … … 89 88 char *parent_name; 90 89 DATA_BLOB blob; 91 92 parent_name = talloc_strndup(data->ctx, key_name, strrchr(key_name, '\\')-key_name); 93 blob.data = (uint8_t *)talloc_strndup(data->ctx, key_name+(strrchr(key_name, '\\')-key_name)+1, 94 strlen(key_name)-(strrchr(key_name, '\\')-key_name)); 90 WERROR werr; 91 92 parent_name = talloc_strndup(data->ctx, key_name, 93 strrchr(key_name, '\\')-key_name); 94 W_ERROR_HAVE_NO_MEMORY(parent_name); 95 blob.data = (uint8_t*)talloc_strndup(data->ctx, 96 key_name+(strrchr(key_name, '\\')-key_name)+1, 97 strlen(key_name)-(strrchr(key_name, '\\')-key_name)); 98 W_ERROR_HAVE_NO_MEMORY(blob.data); 95 99 blob.length = strlen((char *)blob.data)+1; 96 100 97 101 98 102 /* FIXME: These values should be accumulated to be written at done(). */ 99 return reg_preg_diff_set_value(data, parent_name, "**DeleteKeys", REG_SZ, blob); 103 werr = reg_preg_diff_set_value(data, parent_name, "**DeleteKeys", 104 REG_SZ, blob); 105 106 talloc_free(parent_name); 107 talloc_free(blob.data); 108 109 return werr; 100 110 } 101 111 … … 106 116 char *val; 107 117 DATA_BLOB blob; 118 WERROR werr; 108 119 109 120 val = talloc_asprintf(data->ctx, "**Del.%s", value_name); 110 121 W_ERROR_HAVE_NO_MEMORY(val); 111 122 blob.data = (uint8_t *)talloc(data->ctx, uint32_t); 112 *(uint32_t *)blob.data = 0; 113 blob.length = 4; 114 return reg_preg_diff_set_value(data, key_name, val, REG_DWORD, blob); 123 W_ERROR_HAVE_NO_MEMORY(blob.data); 124 SIVAL(blob.data, 0, 0); 125 blob.length = sizeof(uint32_t); 126 127 werr = reg_preg_diff_set_value(data, key_name, val, REG_DWORD, blob); 128 129 talloc_free(val); 130 talloc_free(blob.data); 131 132 return werr; 115 133 } 116 134 … … 119 137 struct preg_data *data = (struct preg_data *)_data; 120 138 DATA_BLOB blob; 139 WERROR werr; 121 140 122 141 blob.data = (uint8_t *)talloc(data->ctx, uint32_t); 123 *(uint32_t *)blob.data = 0; 124 blob.length = 4; 125 126 return reg_preg_diff_set_value(data, key_name, "**DelVals.", REG_DWORD, blob); 142 W_ERROR_HAVE_NO_MEMORY(blob.data); 143 SIVAL(blob.data, 0, 0); 144 blob.length = sizeof(uint32_t); 145 146 werr = reg_preg_diff_set_value(data, key_name, "**DelVals.", REG_DWORD, 147 blob); 148 149 talloc_free(blob.data); 150 151 return werr; 127 152 } 128 153 … … 140 165 */ 141 166 _PUBLIC_ WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename, 142 struct smb_iconv_convenience *ic,143 167 struct reg_diff_callbacks **callbacks, 144 168 void **callback_data) … … 165 189 166 190 strncpy(preg_header.hdr, "PReg", 4); 167 SIVAL(&preg_header , 4, 1);168 write(data->fd, (uint8_t *)&preg_header, 8);191 SIVAL(&preg_header.version, 0, 1); 192 write(data->fd, (uint8_t *)&preg_header, sizeof(preg_header)); 169 193 170 194 data->ctx = ctx; … … 185 209 */ 186 210 _PUBLIC_ WERROR reg_preg_diff_load(int fd, 187 struct smb_iconv_convenience *iconv_convenience,188 211 const struct reg_diff_callbacks *callbacks, 189 212 void *callback_data) … … 206 229 207 230 /* Read first 8 bytes (the header) */ 208 if (read(fd, &preg_header, 8) != 8) {231 if (read(fd, &preg_header, sizeof(preg_header)) != sizeof(preg_header)) { 209 232 DEBUG(0, ("Could not read PReg file: %s\n", 210 233 strerror(errno))); … … 255 278 256 279 /* Get the type */ 257 if (read(fd, &value_type, 4) < 4) {280 if (read(fd, &value_type, sizeof(uint32_t)) < sizeof(uint32_t)) { 258 281 DEBUG(0, ("Error while reading PReg\n")); 259 282 ret = WERR_GENERAL_FAILURE; … … 270 293 goto cleanup; 271 294 } 295 272 296 /* Get data length */ 273 if (read(fd, &length, 4) < 4) {297 if (read(fd, &length, sizeof(uint32_t)) < sizeof(uint32_t)) { 274 298 DEBUG(0, ("Error while reading PReg\n")); 275 299 ret = WERR_GENERAL_FAILURE; 276 300 goto cleanup; 277 301 } 302 length = IVAL(&length, 0); 303 278 304 /* Read past delimiter */ 279 305 buf_ptr = buf; … … 284 310 goto cleanup; 285 311 } 312 286 313 /* Get the data */ 287 314 buf_ptr = buf; -
vendor/current/source4/lib/registry/pyregistry.c
r414 r740 3 3 Samba utility functions 4 4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008 5 Copyright (C) Wilco Baan Hofman <wilco@baanhofman.nl> 2010 5 6 6 7 This program is free software; you can redistribute it and/or modify … … 18 19 */ 19 20 21 #include <Python.h> 20 22 #include "includes.h" 21 #include <tevent.h>22 #include <Python.h>23 23 #include "libcli/util/pyerrors.h" 24 24 #include "lib/registry/registry.h" 25 #include " scripting/python/modules.h" /* for py_iconv_convenience() */26 #include <pytalloc.h>25 #include "lib/talloc/pytalloc.h" 26 #include "lib/events/events.h" 27 27 #include "auth/credentials/pycredentials.h" 28 28 #include "param/pyparam.h" 29 29 30 #ifndef Py_RETURN_NONE 31 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None 32 #endif 33 34 PyAPI_DATA(PyTypeObject) PyRegistryKey; 35 PyAPI_DATA(PyTypeObject) PyRegistry; 36 PyAPI_DATA(PyTypeObject) PyHiveKey; 30 extern PyTypeObject PyRegistryKey; 31 extern PyTypeObject PyRegistry; 32 extern PyTypeObject PyHiveKey; 37 33 38 34 /*#define PyRegistryKey_AsRegistryKey(obj) py_talloc_get_type(obj, struct registry_key)*/ … … 96 92 return NULL; 97 93 98 result = reg_diff_apply(ctx, py_iconv_convenience(NULL),filename);94 result = reg_diff_apply(ctx, filename); 99 95 PyErr_WERROR_IS_ERR_RAISE(result); 100 96 … … 164 160 .tp_new = registry_new, 165 161 .tp_basicsize = sizeof(py_talloc_Object), 166 .tp_dealloc = py_talloc_dealloc,167 162 .tp_flags = Py_TPFLAGS_DEFAULT, 168 163 }; … … 177 172 return NULL; 178 173 179 result = hive_key_del( key, name);174 result = hive_key_del(NULL, key, name); 180 175 181 176 PyErr_WERROR_IS_ERR_RAISE(result); … … 204 199 return NULL; 205 200 206 result = hive_key_del_value( key, name);201 result = hive_key_del_value(NULL, key, name); 207 202 208 203 PyErr_WERROR_IS_ERR_RAISE(result); … … 225 220 result = hive_key_set_value(key, name, type, value); 226 221 else 227 result = hive_key_del_value( key, name);222 result = hive_key_del_value(NULL, key, name); 228 223 229 224 PyErr_WERROR_IS_ERR_RAISE(result); … … 244 239 }; 245 240 246 static PyObject *hive_open(PyTypeObject *type, PyObject *args, PyObject *kwargs) 247 { 248 /* reg_open_hive */ 241 static PyObject *hive_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { 249 242 Py_RETURN_NONE; 243 } 244 245 static PyObject *py_open_hive(PyTypeObject *type, PyObject *args, PyObject *kwargs) 246 { 247 const char *kwnames[] = { "location", "lp_ctx", "session_info", "credentials", NULL }; 248 WERROR result; 249 struct loadparm_context *lp_ctx; 250 PyObject *py_lp_ctx, *py_session_info, *py_credentials; 251 struct auth_session_info *session_info; 252 struct cli_credentials *credentials; 253 char *location; 254 struct hive_key *hive_key; 255 TALLOC_CTX *mem_ctx; 256 257 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO", 258 discard_const_p(char *, kwnames), 259 &location, 260 &py_lp_ctx, &py_session_info, 261 &py_credentials)) 262 return NULL; 263 264 mem_ctx = talloc_new(NULL); 265 if (mem_ctx == NULL) { 266 PyErr_NoMemory(); 267 return NULL; 268 } 269 270 lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx); 271 if (lp_ctx == NULL) { 272 PyErr_SetString(PyExc_TypeError, "Expected loadparm context"); 273 talloc_free(mem_ctx); 274 return NULL; 275 } 276 277 credentials = cli_credentials_from_py_object(py_credentials); 278 if (credentials == NULL) { 279 PyErr_SetString(PyExc_TypeError, "Expected credentials"); 280 talloc_free(mem_ctx); 281 return NULL; 282 } 283 session_info = NULL; 284 285 result = reg_open_hive(NULL, location, session_info, credentials, 286 tevent_context_init(NULL), 287 lp_ctx, &hive_key); 288 talloc_free(mem_ctx); 289 PyErr_WERROR_IS_ERR_RAISE(result); 290 291 return py_talloc_steal(&PyHiveKey, hive_key); 250 292 } 251 293 … … 253 295 .tp_name = "HiveKey", 254 296 .tp_methods = hive_key_methods, 255 .tp_new = hive_ open,297 .tp_new = hive_new, 256 298 .tp_basicsize = sizeof(py_talloc_Object), 257 .tp_dealloc = py_talloc_dealloc,258 299 .tp_flags = Py_TPFLAGS_DEFAULT, 259 300 }; … … 262 303 .tp_name = "RegistryKey", 263 304 .tp_basicsize = sizeof(py_talloc_Object), 264 .tp_dealloc = py_talloc_dealloc,265 305 .tp_flags = Py_TPFLAGS_DEFAULT, 266 306 }; … … 271 311 struct registry_context *reg_ctx; 272 312 WERROR result; 273 313 struct loadparm_context *lp_ctx; 274 314 PyObject *py_lp_ctx, *py_session_info, *py_credentials; 275 315 struct auth_session_info *session_info; 276 struct cli_credentials *credentials; 277 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOO", discard_const_p(char *, kwnames), 278 &py_lp_ctx, &py_session_info, &py_credentials)) 279 return NULL; 280 281 lp_ctx = lp_from_py_object(py_lp_ctx); 282 if (lp_ctx == NULL) { 316 struct cli_credentials *credentials; 317 TALLOC_CTX *mem_ctx; 318 319 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOO", 320 discard_const_p(char *, kwnames), 321 &py_lp_ctx, &py_session_info, 322 &py_credentials)) 323 return NULL; 324 325 mem_ctx = talloc_new(NULL); 326 if (mem_ctx == NULL) { 327 PyErr_NoMemory(); 328 return NULL; 329 } 330 331 lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx); 332 if (lp_ctx == NULL) { 283 333 PyErr_SetString(PyExc_TypeError, "Expected loadparm context"); 284 return NULL; 285 } 334 talloc_free(mem_ctx); 335 return NULL; 336 } 286 337 287 338 credentials = cli_credentials_from_py_object(py_credentials); 288 339 if (credentials == NULL) { 289 340 PyErr_SetString(PyExc_TypeError, "Expected credentials"); 341 talloc_free(mem_ctx); 290 342 return NULL; 291 343 } … … 295 347 result = reg_open_samba(NULL, ®_ctx, NULL, 296 348 lp_ctx, session_info, credentials); 349 talloc_free(mem_ctx); 297 350 if (!W_ERROR_IS_OK(result)) { 298 351 PyErr_SetWERROR(result); 299 352 return NULL; 300 353 } 301 354 302 355 return py_talloc_steal(&PyRegistry, reg_ctx); 303 356 } … … 339 392 WERROR result; 340 393 char *location; 341 342 394 struct loadparm_context *lp_ctx; 395 struct cli_credentials *credentials; 343 396 struct hive_key *key; 344 397 struct auth_session_info *session_info; 398 TALLOC_CTX *mem_ctx; 345 399 346 400 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO", 347 discard_const_p(char *, kwnames), 348 &location, 349 &py_session_info, &py_credentials, 350 &py_lp_ctx)) 351 return NULL; 352 353 lp_ctx = lp_from_py_object(py_lp_ctx); 354 if (lp_ctx == NULL) { 401 discard_const_p(char *, kwnames), 402 &location, &py_session_info, 403 &py_credentials, &py_lp_ctx)) 404 return NULL; 405 406 mem_ctx = talloc_new(NULL); 407 if (mem_ctx == NULL) { 408 PyErr_NoMemory(); 409 return NULL; 410 } 411 412 lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx); 413 if (lp_ctx == NULL) { 355 414 PyErr_SetString(PyExc_TypeError, "Expected loadparm context"); 356 return NULL; 357 } 415 talloc_free(mem_ctx); 416 return NULL; 417 } 358 418 359 419 credentials = cli_credentials_from_py_object(py_credentials); 360 420 if (credentials == NULL) { 361 421 PyErr_SetString(PyExc_TypeError, "Expected credentials"); 422 talloc_free(mem_ctx); 362 423 return NULL; 363 424 } … … 366 427 367 428 result = reg_open_ldb_file(NULL, location, session_info, credentials, 368 tevent_context_init(NULL), lp_ctx, &key); 429 s4_event_context_init(NULL), lp_ctx, &key); 430 talloc_free(mem_ctx); 369 431 PyErr_WERROR_IS_ERR_RAISE(result); 370 432 … … 401 463 { "create_directory", py_create_directory, METH_VARARGS, "create_dir(location) -> key" }, 402 464 { "open_ldb", (PyCFunction)py_open_ldb_file, METH_VARARGS|METH_KEYWORDS, "open_ldb(location, session_info=None, credentials=None, loadparm_context=None) -> key" }, 465 { "open_hive", (PyCFunction)py_open_hive, METH_VARARGS|METH_KEYWORDS, "open_hive(location, session_info=None, credentials=None, loadparm_context=None) -> key" }, 403 466 { "str_regtype", py_str_regtype, METH_VARARGS, "str_regtype(int) -> str" }, 404 467 { "get_predef_name", py_get_predef_name, METH_VARARGS, "get_predef_name(hkey) -> str" }, … … 409 472 { 410 473 PyObject *m; 474 PyTypeObject *talloc_type = PyTalloc_GetObjectType(); 475 476 if (talloc_type == NULL) 477 return; 478 479 PyHiveKey.tp_base = talloc_type; 480 PyRegistry.tp_base = talloc_type; 481 PyRegistryKey.tp_base = talloc_type; 411 482 412 483 if (PyType_Ready(&PyHiveKey) < 0) -
vendor/current/source4/lib/registry/regf.c
r414 r740 3 3 Registry backend for REGF files 4 4 Copyright (C) 2005-2007 Jelmer Vernooij, jelmer@samba.org 5 Copyright (C) 2006 Wilco Baan Hofman, wilco@baanhofman.nl5 Copyright (C) 2006-2010 Wilco Baan Hofman, wilco@baanhofman.nl 6 6 7 7 This program is free software; you can redistribute it and/or modify … … 50 50 struct hbin_block **hbins; 51 51 struct regf_hdr *header; 52 struct smb_iconv_convenience *iconv_convenience;52 time_t last_write; 53 53 }; 54 54 55 static WERROR regf_save_hbin(struct regf_data *data );55 static WERROR regf_save_hbin(struct regf_data *data, bool flush); 56 56 57 57 struct regf_key_data { … … 65 65 uint32_t offset, uint32_t *rel_offset) 66 66 { 67 int i;67 unsigned int i; 68 68 69 69 for (i = 0; data->hbins[i]; i++) { … … 87 87 { 88 88 uint32_t checksum = 0, x; 89 int i;89 unsigned int i; 90 90 91 91 for (i = 0; i < 0x01FB; i+= 4) { … … 112 112 113 113 if (hbin == NULL) { 114 DEBUG(1, ("Can't find HBIN containing0x%04x\n", offset));114 DEBUG(1, ("Can't find HBIN at 0x%04x\n", offset)); 115 115 return ret; 116 116 } … … 135 135 TALLOC_CTX *ctx, tdr_pull_fn_t pull_fn, void *p) 136 136 { 137 struct tdr_pull *pull = tdr_pull_init(regf , regf->iconv_convenience);137 struct tdr_pull *pull = tdr_pull_init(regf); 138 138 139 139 pull->data = hbin_get(regf, offset); … … 160 160 { 161 161 DATA_BLOB ret; 162 uint32_t rel_offset = -1; /* Relative offset ! */162 uint32_t rel_offset = (uint32_t) -1; /* Relative offset ! */ 163 163 struct hbin_block *hbin = NULL; 164 int i;164 unsigned int i; 165 165 166 166 *offset = 0; … … 218 218 DEBUG(4, ("No space available in other HBINs for block of size %d, allocating new HBIN\n", 219 219 size)); 220 221 /* Add extra hbin block */ 220 222 data->hbins = talloc_realloc(data, data->hbins, 221 223 struct hbin_block *, i+2); … … 226 228 data->hbins[i+1] = NULL; 227 229 230 /* Set hbin data */ 228 231 hbin->HBIN_ID = talloc_strdup(hbin, "hbin"); 229 232 hbin->offset_from_first = (i == 0?0:data->hbins[i-1]->offset_from_first+data->hbins[i-1]->offset_to_next); 230 233 hbin->offset_to_next = 0x1000; 231 234 hbin->unknown[0] = 0; 232 hbin->unknown[ 0] = 0;235 hbin->unknown[1] = 0; 233 236 unix_to_nt_time(&hbin->last_change, time(NULL)); 234 237 hbin->block_size = hbin->offset_to_next; 235 238 hbin->data = talloc_zero_array(hbin, uint8_t, hbin->block_size - 0x20); 236 239 /* Update the regf header */ 240 data->header->last_block += hbin->offset_to_next; 241 242 /* Set the next block to it's proper size and set the 243 * rel_offset for this block */ 244 SIVAL(hbin->data, size, hbin->block_size - size - 0x20); 237 245 rel_offset = 0x0; 238 SIVAL(hbin->data, size, hbin->block_size - size - 0x20);239 246 } 240 247 … … 262 269 memcpy(dest.data, blob.data, blob.length); 263 270 271 /* Make sure that we have no tailing garbage in the block */ 272 if (dest.length > blob.length) { 273 memset(dest.data + blob.length, 0, dest.length - blob.length); 274 } 275 264 276 return ret; 265 277 } … … 268 280 tdr_push_fn_t push_fn, void *p) 269 281 { 270 struct tdr_push *push = tdr_push_init(data , data->iconv_convenience);282 struct tdr_push *push = tdr_push_init(data); 271 283 uint32_t ret; 272 284 … … 311 323 312 324 /* If the next block is free, merge into big free block */ 313 if (rel_offset + size < hbin->offset_to_next ) {325 if (rel_offset + size < hbin->offset_to_next - 0x20) { 314 326 next_size = IVALS(hbin->data, rel_offset+size); 315 327 if (next_size > 0) { … … 336 348 int32_t needed_size; 337 349 int32_t possible_size; 338 int i;350 unsigned int i; 339 351 340 352 SMB_ASSERT(orig_offset > 0); … … 395 407 uint32_t orig_offset, void *p) 396 408 { 397 struct tdr_push *push = tdr_push_init(regf , regf->iconv_convenience);409 struct tdr_push *push = tdr_push_init(regf); 398 410 uint32_t ret; 399 411 … … 451 463 (char*)data.data, 452 464 private_data->nk->clsname_length); 465 W_ERROR_HAVE_NO_MEMORY(*classname); 453 466 } else 454 467 *classname = NULL; … … 485 498 if (!hbin_get_tdr(regf, offset, nk, 486 499 (tdr_pull_fn_t)tdr_pull_nk_block, nk)) { 487 DEBUG(0, ("Unable to find HBIN data for offset %d\n", offset));500 DEBUG(0, ("Unable to find HBIN data for offset 0x%x\n", offset)); 488 501 return NULL; 489 502 } … … 500 513 501 514 static WERROR regf_get_value(TALLOC_CTX *ctx, struct hive_key *key, 502 int idx, const char **name,515 uint32_t idx, const char **name, 503 516 uint32_t *data_type, DATA_BLOB *data) 504 517 { … … 515 528 tmp = hbin_get(regf, private_data->nk->values_offset); 516 529 if (!tmp.data) { 517 DEBUG(0, ("Unable to find value list\n")); 530 DEBUG(0, ("Unable to find value list at 0x%x\n", 531 private_data->nk->values_offset)); 518 532 return WERR_GENERAL_FAILURE; 519 533 } … … 530 544 if (!hbin_get_tdr(regf, vk_offset, vk, 531 545 (tdr_pull_fn_t)tdr_pull_vk_block, vk)) { 532 DEBUG(0, ("Unable to get VK block at %d\n", vk_offset));546 DEBUG(0, ("Unable to get VK block at 0x%x\n", vk_offset)); 533 547 talloc_free(vk); 534 548 return WERR_GENERAL_FAILURE; … … 536 550 537 551 /* FIXME: name character set ?*/ 538 if (name != NULL) 552 if (name != NULL) { 539 553 *name = talloc_strndup(ctx, vk->data_name, vk->name_length); 554 W_ERROR_HAVE_NO_MEMORY(*name); 555 } 540 556 541 557 if (data_type != NULL) … … 543 559 544 560 if (vk->data_length & 0x80000000) { 545 vk->data_length &=~0x80000000; 546 data->data = (uint8_t *)talloc_memdup(ctx, (uint8_t *)&vk->data_offset, vk->data_length); 547 data->length = vk->data_length; 561 /* this is data of type "REG_DWORD" or "REG_DWORD_BIG_ENDIAN" */ 562 data->data = talloc_size(ctx, sizeof(uint32_t)); 563 W_ERROR_HAVE_NO_MEMORY(data->data); 564 SIVAL(data->data, 0, vk->data_offset); 565 data->length = sizeof(uint32_t); 548 566 } else { 549 567 *data = hbin_get(regf, vk->data_offset); … … 563 581 uint32_t *type, DATA_BLOB *data) 564 582 { 565 int i;583 unsigned int i; 566 584 const char *vname; 567 585 WERROR error; … … 598 616 return WERR_NO_MORE_ITEMS; 599 617 618 /* Make sure that we don't crash if the key is empty */ 619 if (nk->subkeys_offset == -1) { 620 return WERR_NO_MORE_ITEMS; 621 } 622 600 623 data = hbin_get(private_data->hive, nk->subkeys_offset); 601 624 if (!data.data) { 602 DEBUG(0, ("Unable to find subkey list\n")); 625 DEBUG(0, ("Unable to find subkey list at 0x%x\n", 626 nk->subkeys_offset)); 603 627 return WERR_GENERAL_FAILURE; 604 628 } … … 606 630 if (!strncmp((char *)data.data, "li", 2)) { 607 631 struct li_block li; 608 struct tdr_pull *pull = tdr_pull_init(private_data->hive , private_data->hive->iconv_convenience);632 struct tdr_pull *pull = tdr_pull_init(private_data->hive); 609 633 610 634 DEBUG(10, ("Subkeys in LI list\n")); … … 627 651 } else if (!strncmp((char *)data.data, "lf", 2)) { 628 652 struct lf_block lf; 629 struct tdr_pull *pull = tdr_pull_init(private_data->hive , private_data->hive->iconv_convenience);653 struct tdr_pull *pull = tdr_pull_init(private_data->hive); 630 654 631 655 DEBUG(10, ("Subkeys in LF list\n")); … … 648 672 } else if (!strncmp((char *)data.data, "lh", 2)) { 649 673 struct lh_block lh; 650 struct tdr_pull *pull = tdr_pull_init(private_data->hive , private_data->hive->iconv_convenience);674 struct tdr_pull *pull = tdr_pull_init(private_data->hive); 651 675 652 676 DEBUG(10, ("Subkeys in LH list\n")); … … 668 692 } else if (!strncmp((char *)data.data, "ri", 2)) { 669 693 struct ri_block ri; 670 struct tdr_pull *pull = tdr_pull_init(ctx , private_data->hive->iconv_convenience);694 struct tdr_pull *pull = tdr_pull_init(ctx); 671 695 uint16_t i; 672 696 uint16_t sublist_count = 0; … … 769 793 (char*)db.data, 770 794 ret->nk->clsname_length); 795 W_ERROR_HAVE_NO_MEMORY(*classname); 771 796 } else 772 797 *classname = NULL; … … 801 826 } 802 827 803 pull = tdr_pull_init(ctx , private_data->hive->iconv_convenience);828 pull = tdr_pull_init(ctx); 804 829 805 830 pull->data = subkey_data; … … 836 861 uint32_t key_off = 0; 837 862 863 /* Make sure that we don't crash if the key is empty */ 864 if (nk->subkeys_offset == -1) { 865 return WERR_BADFILE; 866 } 867 838 868 data = hbin_get(private_data->hive, nk->subkeys_offset); 839 869 if (!data.data) { … … 844 874 if (!strncmp((char *)data.data, "li", 2)) { 845 875 struct li_block li; 846 struct tdr_pull *pull = tdr_pull_init(ctx , private_data->hive->iconv_convenience);876 struct tdr_pull *pull = tdr_pull_init(ctx); 847 877 uint16_t i; 848 878 … … 875 905 } else if (!strncmp((char *)data.data, "lf", 2)) { 876 906 struct lf_block lf; 877 struct tdr_pull *pull = tdr_pull_init(ctx , private_data->hive->iconv_convenience);907 struct tdr_pull *pull = tdr_pull_init(ctx); 878 908 uint16_t i; 879 909 … … 910 940 } else if (!strncmp((char *)data.data, "lh", 2)) { 911 941 struct lh_block lh; 912 struct tdr_pull *pull = tdr_pull_init(ctx , private_data->hive->iconv_convenience);942 struct tdr_pull *pull = tdr_pull_init(ctx); 913 943 uint16_t i; 914 944 uint32_t hash; … … 947 977 } else if (!strncmp((char *)data.data, "ri", 2)) { 948 978 struct ri_block ri; 949 struct tdr_pull *pull = tdr_pull_init(ctx , private_data->hive->iconv_convenience);979 struct tdr_pull *pull = tdr_pull_init(ctx); 950 980 uint16_t i, j; 951 981 … … 1052 1082 1053 1083 /* Push the security descriptor to a blob */ 1054 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_struct_blob(&data, regf, NULL,1084 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_struct_blob(&data, regf, 1055 1085 sec_desc, (ndr_push_flags_fn_t)ndr_push_security_descriptor))) { 1056 1086 DEBUG(0, ("Unable to push security descriptor\n")); … … 1205 1235 data.data = sk.sec_desc; 1206 1236 data.length = sk.rec_size; 1207 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_struct_blob(&data, ctx, NULL,*sd,1237 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_struct_blob(&data, ctx, *sd, 1208 1238 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor))) { 1209 1239 DEBUG(0, ("Error parsing security descriptor\n")); … … 1289 1319 1290 1320 if (!strncmp((char *)data.data, "li", 2)) { 1291 struct tdr_pull *pull = tdr_pull_init(regf , regf->iconv_convenience);1321 struct tdr_pull *pull = tdr_pull_init(regf); 1292 1322 struct li_block li; 1323 struct nk_block sub_nk; 1324 int32_t i, j; 1293 1325 1294 1326 pull->data = data; … … 1307 1339 } 1308 1340 1341 /* 1342 * Find the position to store the pointer 1343 * Extensive testing reveils that at least on windows 7 subkeys 1344 * *MUST* be stored in alphabetical order 1345 */ 1346 for (i = 0; i < li.key_count; i++) { 1347 /* Get the nk */ 1348 hbin_get_tdr(regf, li.nk_offset[i], regf, 1349 (tdr_pull_fn_t) tdr_pull_nk_block, &sub_nk); 1350 if (strcasecmp(name, sub_nk.key_name) < 0) { 1351 break; 1352 } 1353 } 1354 1309 1355 li.nk_offset = talloc_realloc(regf, li.nk_offset, 1310 1356 uint32_t, li.key_count+1); 1311 1357 W_ERROR_HAVE_NO_MEMORY(li.nk_offset); 1312 li.nk_offset[li.key_count] = key_offset; 1358 1359 /* Move everything behind this offset */ 1360 for (j = li.key_count - 1; j >= i; j--) { 1361 li.nk_offset[j+1] = li.nk_offset[j]; 1362 } 1363 1364 li.nk_offset[i] = key_offset; 1313 1365 li.key_count++; 1314 1366 *ret = hbin_store_tdr_resize(regf, … … 1318 1370 talloc_free(li.nk_offset); 1319 1371 } else if (!strncmp((char *)data.data, "lf", 2)) { 1320 struct tdr_pull *pull = tdr_pull_init(regf , regf->iconv_convenience);1372 struct tdr_pull *pull = tdr_pull_init(regf); 1321 1373 struct lf_block lf; 1374 struct nk_block sub_nk; 1375 int32_t i, j; 1322 1376 1323 1377 pull->data = data; … … 1331 1385 SMB_ASSERT(!strncmp(lf.header, "lf", 2)); 1332 1386 1387 /* 1388 * Find the position to store the hash record 1389 * Extensive testing reveils that at least on windows 7 subkeys 1390 * *MUST* be stored in alphabetical order 1391 */ 1392 for (i = 0; i < lf.key_count; i++) { 1393 /* Get the nk */ 1394 hbin_get_tdr(regf, lf.hr[i].nk_offset, regf, 1395 (tdr_pull_fn_t) tdr_pull_nk_block, &sub_nk); 1396 if (strcasecmp(name, sub_nk.key_name) < 0) { 1397 break; 1398 } 1399 } 1400 1333 1401 lf.hr = talloc_realloc(regf, lf.hr, struct hash_record, 1334 1402 lf.key_count+1); 1335 1403 W_ERROR_HAVE_NO_MEMORY(lf.hr); 1336 lf.hr[lf.key_count].nk_offset = key_offset; 1337 lf.hr[lf.key_count].hash = talloc_strndup(lf.hr, name, 4); 1404 1405 /* Move everything behind this hash record */ 1406 for (j = lf.key_count - 1; j >= i; j--) { 1407 lf.hr[j+1] = lf.hr[j]; 1408 } 1409 1410 lf.hr[i].nk_offset = key_offset; 1411 lf.hr[i].hash = talloc_strndup(lf.hr, name, 4); 1338 1412 W_ERROR_HAVE_NO_MEMORY(lf.hr[lf.key_count].hash); 1339 1413 lf.key_count++; … … 1344 1418 talloc_free(lf.hr); 1345 1419 } else if (!strncmp((char *)data.data, "lh", 2)) { 1346 struct tdr_pull *pull = tdr_pull_init(regf , regf->iconv_convenience);1420 struct tdr_pull *pull = tdr_pull_init(regf); 1347 1421 struct lh_block lh; 1422 struct nk_block sub_nk; 1423 int32_t i, j; 1348 1424 1349 1425 pull->data = data; … … 1357 1433 SMB_ASSERT(!strncmp(lh.header, "lh", 2)); 1358 1434 1435 /* 1436 * Find the position to store the hash record 1437 * Extensive testing reveils that at least on windows 7 subkeys 1438 * *MUST* be stored in alphabetical order 1439 */ 1440 for (i = 0; i < lh.key_count; i++) { 1441 /* Get the nk */ 1442 hbin_get_tdr(regf, lh.hr[i].nk_offset, regf, 1443 (tdr_pull_fn_t) tdr_pull_nk_block, &sub_nk); 1444 if (strcasecmp(name, sub_nk.key_name) < 0) { 1445 break; 1446 } 1447 } 1448 1359 1449 lh.hr = talloc_realloc(regf, lh.hr, struct lh_hash, 1360 1450 lh.key_count+1); 1361 1451 W_ERROR_HAVE_NO_MEMORY(lh.hr); 1362 lh.hr[lh.key_count].nk_offset = key_offset; 1363 lh.hr[lh.key_count].base37 = regf_create_lh_hash(name); 1452 1453 /* Move everything behind this hash record */ 1454 for (j = lh.key_count - 1; j >= i; j--) { 1455 lh.hr[j+1] = lh.hr[j]; 1456 } 1457 1458 lh.hr[i].nk_offset = key_offset; 1459 lh.hr[i].base37 = regf_create_lh_hash(name); 1364 1460 lh.key_count++; 1365 1461 *ret = hbin_store_tdr_resize(regf, … … 1393 1489 if (strncmp((char *)data.data, "li", 2) == 0) { 1394 1490 struct li_block li; 1395 struct tdr_pull *pull = tdr_pull_init(regf , regf->iconv_convenience);1491 struct tdr_pull *pull = tdr_pull_init(regf); 1396 1492 uint16_t i; 1397 1493 bool found_offset = false; … … 1437 1533 } else if (strncmp((char *)data.data, "lf", 2) == 0) { 1438 1534 struct lf_block lf; 1439 struct tdr_pull *pull = tdr_pull_init(regf , regf->iconv_convenience);1535 struct tdr_pull *pull = tdr_pull_init(regf); 1440 1536 uint16_t i; 1441 1537 bool found_offset = false; … … 1483 1579 } else if (strncmp((char *)data.data, "lh", 2) == 0) { 1484 1580 struct lh_block lh; 1485 struct tdr_pull *pull = tdr_pull_init(regf , regf->iconv_convenience);1581 struct tdr_pull *pull = tdr_pull_init(regf); 1486 1582 uint16_t i; 1487 1583 bool found_offset = false; … … 1538 1634 } 1539 1635 1540 static WERROR regf_del_value (struct hive_key *key, const char *name) 1636 static WERROR regf_del_value(TALLOC_CTX *mem_ctx, struct hive_key *key, 1637 const char *name) 1541 1638 { 1542 1639 struct regf_key_data *private_data = (struct regf_key_data *)key; … … 1547 1644 bool found_offset = false; 1548 1645 DATA_BLOB values; 1549 u int32_t i;1646 unsigned int i; 1550 1647 1551 1648 if (nk->values_offset == -1) { … … 1592 1689 private_data->offset, nk); 1593 1690 1594 return regf_save_hbin(private_data->hive); 1595 } 1596 1597 1598 static WERROR regf_del_key(const struct hive_key *parent, const char *name) 1691 return regf_save_hbin(private_data->hive, 0); 1692 } 1693 1694 1695 static WERROR regf_del_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent, 1696 const char *name) 1599 1697 { 1600 1698 const struct regf_key_data *private_data = … … 1623 1721 char *sk_name; 1624 1722 struct hive_key *sk = (struct hive_key *)key; 1625 int i = key->nk->num_subkeys;1723 unsigned int i = key->nk->num_subkeys; 1626 1724 while (i--) { 1627 1725 /* Get subkey information. */ … … 1635 1733 1636 1734 /* Delete subkey. */ 1637 error = regf_del_key( sk, sk_name);1735 error = regf_del_key(NULL, sk, sk_name); 1638 1736 if (!W_ERROR_IS_OK(error)) { 1639 1737 DEBUG(0, ("Can't delete key '%s'.\n", sk_name)); … … 1649 1747 struct hive_key *sk = (struct hive_key *)key; 1650 1748 DATA_BLOB data; 1651 int i = key->nk->num_values;1749 unsigned int i = key->nk->num_values; 1652 1750 while (i--) { 1653 1751 /* Get value information. */ … … 1661 1759 1662 1760 /* Delete value. */ 1663 error = regf_del_value( sk, val_name);1761 error = regf_del_value(NULL, sk, val_name); 1664 1762 if (!W_ERROR_IS_OK(error)) { 1665 1763 DEBUG(0, ("Can't delete value '%s'.\n", val_name)); … … 1690 1788 hbin_free(private_data->hive, key->offset); 1691 1789 1692 return regf_save_hbin(private_data->hive );1790 return regf_save_hbin(private_data->hive, 0); 1693 1791 } 1694 1792 … … 1717 1815 nk.num_values = 0; 1718 1816 nk.values_offset = -1; 1719 memset(nk.unk3, 0, 5);1817 memset(nk.unk3, 0, sizeof(nk.unk3)); 1720 1818 nk.clsname_offset = -1; /* FIXME: fill in */ 1721 1819 nk.clsname_length = 0; … … 1728 1826 if (!hbin_get_tdr(regf, regf->header->data_offset, root, 1729 1827 (tdr_pull_fn_t)tdr_pull_nk_block, root)) { 1730 DEBUG(0, ("Unable to find HBIN data for offset %d\n",1828 DEBUG(0, ("Unable to find HBIN data for offset 0x%x\n", 1731 1829 regf->header->data_offset)); 1732 1830 return WERR_GENERAL_FAILURE; … … 1753 1851 *ret = (struct hive_key *)regf_get_key(ctx, regf, offset); 1754 1852 1755 return regf_save_hbin(private_data->hive); 1853 DEBUG(9, ("Storing key %s\n", name)); 1854 return regf_save_hbin(private_data->hive, 0); 1756 1855 } 1757 1856 … … 1764 1863 struct vk_block vk; 1765 1864 uint32_t i; 1766 uint32_t tmp_vk_offset, vk_offset, old_vk_offset = -1;1865 uint32_t tmp_vk_offset, vk_offset, old_vk_offset = (uint32_t) -1; 1767 1866 DATA_BLOB values; 1768 1867 … … 1778 1877 (tdr_pull_fn_t)tdr_pull_vk_block, 1779 1878 &vk)) { 1780 DEBUG(0, ("Unable to get VK block at %d\n",1879 DEBUG(0, ("Unable to get VK block at 0x%x\n", 1781 1880 tmp_vk_offset)); 1782 1881 return WERR_GENERAL_FAILURE; … … 1787 1886 } 1788 1887 } 1789 /* Free data, if any */ 1790 if (!(vk.data_length & 0x80000000)) { 1791 hbin_free(regf, vk.data_offset); 1792 } 1793 } 1888 } 1889 1890 /* If it's new, create the vk struct, if it's old, free the old data. */ 1794 1891 if (old_vk_offset == -1) { 1795 1892 vk.header = "vk"; … … 1802 1899 vk.flag = 0; 1803 1900 } 1804 } 1901 } else { 1902 /* Free data, if any */ 1903 if (!(vk.data_length & 0x80000000)) { 1904 hbin_free(regf, vk.data_offset); 1905 } 1906 } 1907 1805 1908 /* Set the type and data */ 1806 1909 vk.data_length = data.length; 1807 1910 vk.data_type = type; 1808 if (type == REG_DWORD) { 1911 if ((type == REG_DWORD) || (type == REG_DWORD_BIG_ENDIAN)) { 1912 if (vk.data_length != sizeof(uint32_t)) { 1913 DEBUG(0, ("DWORD or DWORD_BIG_ENDIAN value with size other than 4 byte!\n")); 1914 return WERR_NOT_SUPPORTED; 1915 } 1809 1916 vk.data_length |= 0x80000000; 1810 vk.data_offset = *(uint32_t *)data.data;1917 vk.data_offset = IVAL(data.data, 0); 1811 1918 } else { 1812 1919 /* Store data somewhere */ … … 1864 1971 (tdr_push_fn_t) tdr_push_nk_block, 1865 1972 private_data->offset, nk); 1866 return regf_save_hbin(private_data->hive );1867 } 1868 1869 static WERROR regf_save_hbin(struct regf_data *regf )1870 { 1871 struct tdr_push *push = tdr_push_init(regf , regf->iconv_convenience);1872 int i;1973 return regf_save_hbin(private_data->hive, 0); 1974 } 1975 1976 static WERROR regf_save_hbin(struct regf_data *regf, bool flush) 1977 { 1978 struct tdr_push *push = tdr_push_init(regf); 1979 unsigned int i; 1873 1980 1874 1981 W_ERROR_HAVE_NO_MEMORY(push); 1982 1983 /* Only write once every 5 seconds, or when flush is set */ 1984 if (!flush && regf->last_write + 5 >= time(NULL)) { 1985 return WERR_OK; 1986 } 1987 1988 regf->last_write = time(NULL); 1875 1989 1876 1990 if (lseek(regf->fd, 0, SEEK_SET) == -1) { … … 1887 2001 talloc_free(push); 1888 2002 1889 if (NT_STATUS_IS_ERR(tdr_push_to_fd(regf->fd, regf->iconv_convenience,2003 if (NT_STATUS_IS_ERR(tdr_push_to_fd(regf->fd, 1890 2004 (tdr_push_fn_t)tdr_push_regf_hdr, 1891 2005 regf->header))) { … … 1900 2014 1901 2015 for (i = 0; regf->hbins[i]; i++) { 1902 if (NT_STATUS_IS_ERR(tdr_push_to_fd(regf->fd, regf->iconv_convenience,2016 if (NT_STATUS_IS_ERR(tdr_push_to_fd(regf->fd, 1903 2017 (tdr_push_fn_t)tdr_push_hbin_block, 1904 2018 regf->hbins[i]))) { … … 1912 2026 1913 2027 WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, 1914 struct smb_iconv_convenience *iconv_convenience,1915 2028 const char *location, 1916 2029 int minor_version, struct hive_key **key) … … 1926 2039 1927 2040 regf = (struct regf_data *)talloc_zero(NULL, struct regf_data); 1928 1929 regf->iconv_convenience = iconv_convenience;1930 2041 1931 2042 W_ERROR_HAVE_NO_MEMORY(regf); … … 1963 2074 1964 2075 nk.header = "nk"; 1965 nk.type = REG_ SUB_KEY;2076 nk.type = REG_ROOT_KEY; 1966 2077 unix_to_nt_time(&nk.last_change, time(NULL)); 1967 2078 nk.uk1 = 0; … … 1997 2108 1998 2109 /* Push the security descriptor to a blob */ 1999 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_struct_blob(&data, regf, NULL,2110 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_struct_blob(&data, regf, 2000 2111 sd, (ndr_push_flags_fn_t)ndr_push_security_descriptor))) { 2001 2112 DEBUG(0, ("Unable to push security descriptor\n")); … … 2028 2139 regf->header->data_offset); 2029 2140 2030 error = regf_save_hbin(regf );2141 error = regf_save_hbin(regf, 1); 2031 2142 if (!W_ERROR_IS_OK(error)) { 2032 2143 return error; … … 2034 2145 2035 2146 /* We can drop our own reference now that *key will have created one */ 2036 talloc_ free(regf);2147 talloc_unlink(NULL, regf); 2037 2148 2038 2149 return WERR_OK; 2039 2150 } 2040 2151 2152 static WERROR regf_flush_key(struct hive_key *key) 2153 { 2154 struct regf_key_data *private_data = (struct regf_key_data *)key; 2155 struct regf_data *regf = private_data->hive; 2156 WERROR error; 2157 2158 error = regf_save_hbin(regf, 1); 2159 if (!W_ERROR_IS_OK(error)) { 2160 DEBUG(0, ("Failed to flush regf to disk\n")); 2161 return error; 2162 } 2163 2164 return WERR_OK; 2165 } 2166 2167 static int regf_destruct(struct regf_data *regf) 2168 { 2169 WERROR error; 2170 2171 /* Write to disk */ 2172 error = regf_save_hbin(regf, 1); 2173 if (!W_ERROR_IS_OK(error)) { 2174 DEBUG(0, ("Failed to flush registry to disk\n")); 2175 return -1; 2176 } 2177 2178 /* Close file descriptor */ 2179 close(regf->fd); 2180 2181 return 0; 2182 } 2183 2041 2184 WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, const char *location, 2042 struct smb_iconv_convenience *iconv_convenience, structhive_key **key)2185 struct hive_key **key) 2043 2186 { 2044 2187 struct regf_data *regf; 2045 2188 struct regf_hdr *regf_hdr; 2046 2189 struct tdr_pull *pull; 2047 int i;2190 unsigned int i; 2048 2191 2049 2192 regf = (struct regf_data *)talloc_zero(parent_ctx, struct regf_data); 2050 2051 regf->iconv_convenience = iconv_convenience;2052 2053 2193 W_ERROR_HAVE_NO_MEMORY(regf); 2194 2195 talloc_set_destructor(regf, regf_destruct); 2054 2196 2055 2197 DEBUG(5, ("Attempting to load registry file\n")); … … 2065 2207 } 2066 2208 2067 pull = tdr_pull_init(regf , regf->iconv_convenience);2209 pull = tdr_pull_init(regf); 2068 2210 2069 2211 pull->data.data = (uint8_t*)fd_load(regf->fd, &pull->data.length, 0, regf); … … 2163 2305 .del_key = regf_del_key, 2164 2306 .delete_value = regf_del_value, 2307 .flush_key = regf_flush_key 2165 2308 }; -
vendor/current/source4/lib/registry/regf.idl
r414 r740 25 25 [noprint] struct regf_version { 26 26 [value(1)] uint32 major; 27 [value(3)]uint32 minor;27 uint32 minor; 28 28 [value(0)] uint32 release; 29 29 [value(1)] uint32 build; … … 75 75 76 76 [noprint] enum reg_key_type { 77 REG_ROOT_KEY = 0x2 0,78 REG_SUB_KEY = 0x2 C,77 REG_ROOT_KEY = 0x2C, 78 REG_SUB_KEY = 0x20, 79 79 REG_SYM_LINK = 0x10 80 80 }; -
vendor/current/source4/lib/registry/registry.h
r414 r740 24 24 struct registry_context; 25 25 struct loadparm_context; 26 struct smb_iconv_convenience;27 26 28 27 #include <talloc.h> … … 71 70 */ 72 71 WERROR (*add_key) (TALLOC_CTX *ctx, 73 const struct hive_key *parent_key, const char * name,72 const struct hive_key *parent_key, const char *path, 74 73 const char *classname, 75 74 struct security_descriptor *desc, … … 78 77 * Remove an existing key. 79 78 */ 80 WERROR (*del_key) (const struct hive_key *key, const char *name); 79 WERROR (*del_key) (TALLOC_CTX *mem_ctx, 80 const struct hive_key *key, const char *name); 81 81 82 82 /** … … 89 89 */ 90 90 WERROR (*enum_value) (TALLOC_CTX *mem_ctx, 91 struct hive_key *key, int idx,91 struct hive_key *key, uint32_t idx, 92 92 const char **name, uint32_t *type, 93 93 DATA_BLOB *data); … … 109 109 * Remove a value. 110 110 */ 111 WERROR (*delete_value) (struct hive_key *key, const char *name); 111 WERROR (*delete_value) (TALLOC_CTX *mem_ctx, 112 struct hive_key *key, const char *name); 112 113 113 114 /* Security Descriptors */ … … 167 168 struct security_descriptor *desc, 168 169 struct hive_key **key); 169 WERROR hive_key_del(const struct hive_key *key, const char *name); 170 WERROR hive_key_del(TALLOC_CTX *mem_ctx, 171 const struct hive_key *key, const char *name); 170 172 WERROR hive_get_key_by_name(TALLOC_CTX *mem_ctx, 171 173 const struct hive_key *key, const char *name, … … 194 196 const struct security_descriptor *security); 195 197 196 WERROR hive_key_del_value(struct hive_key *key, const char *name); 198 WERROR hive_key_del_value(TALLOC_CTX *mem_ctx, 199 struct hive_key *key, const char *name); 197 200 198 201 WERROR hive_key_flush(struct hive_key *key); … … 203 206 const char *location, struct hive_key **key); 204 207 WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, 205 const char *location, struct smb_iconv_convenience *iconv_convenience, 206 struct hive_key **key); 208 const char *location, struct hive_key **key); 207 209 WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location, 208 210 struct auth_session_info *session_info, … … 216 218 const char *location, struct hive_key **key); 217 219 WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, 218 struct smb_iconv_convenience *iconv_convenience,219 220 const char *location, 220 221 int major_version, … … 305 306 struct registry_key **key); 306 307 307 WERROR (*delete_key) (struct registry_key *key, const char *name); 308 309 WERROR (*delete_value) (struct registry_key *key, const char *name); 308 WERROR (*delete_key) (TALLOC_CTX *mem_ctx, 309 struct registry_key *key, const char *name); 310 311 WERROR (*delete_value) (TALLOC_CTX *mem_ctx, 312 struct registry_key *key, const char *name); 310 313 311 314 WERROR (*enum_key) (TALLOC_CTX *mem_ctx, … … 412 415 WERROR reg_key_get_subkey_by_index(TALLOC_CTX *mem_ctx, 413 416 const struct registry_key *key, 414 int idx,417 uint32_t idx, 415 418 const char **name, 416 419 const char **classname, … … 425 428 uint32_t *type, 426 429 DATA_BLOB *data); 427 WERROR reg_key_del(struct registry_key *parent, const char *name); 430 WERROR reg_key_del(TALLOC_CTX *mem_ctx, 431 struct registry_key *parent, const char *name); 428 432 WERROR reg_key_add_name(TALLOC_CTX *mem_ctx, 429 433 struct registry_key *parent, const char *name, … … 435 439 WERROR reg_get_sec_desc(TALLOC_CTX *ctx, const struct registry_key *key, 436 440 struct security_descriptor **secdesc); 437 WERROR reg_del_value(struct registry_key *key, const char *valname); 441 WERROR reg_del_value(TALLOC_CTX *mem_ctx, 442 struct registry_key *key, const char *valname); 438 443 WERROR reg_key_flush(struct registry_key *key); 439 444 WERROR reg_create_key(TALLOC_CTX *mem_ctx, … … 446 451 /* Utility functions */ 447 452 const char *str_regtype(int type); 448 char *reg_val_data_string(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, uint32_t type, const DATA_BLOB data); 449 char *reg_val_description(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, const char *name, 453 bool push_reg_sz(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *s); 454 bool push_reg_multi_sz(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char **a); 455 bool pull_reg_sz(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, const char **s); 456 bool pull_reg_multi_sz(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, const char ***a); 457 int regtype_by_string(const char *str); 458 char *reg_val_data_string(TALLOC_CTX *mem_ctx, uint32_t type, const DATA_BLOB data); 459 char *reg_val_description(TALLOC_CTX *mem_ctx, const char *name, 450 460 uint32_t type, const DATA_BLOB data); 451 bool reg_string_to_val(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience,const char *type_str,461 bool reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str, 452 462 const char *data_str, uint32_t *type, DATA_BLOB *data); 453 463 WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle, … … 486 496 487 497 WERROR reg_diff_apply(struct registry_context *ctx, 488 struct smb_iconv_convenience *ic,const char *filename);498 const char *filename); 489 499 490 500 WERROR reg_generate_diff(struct registry_context *ctx1, … … 493 503 void *callback_data); 494 504 WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename, 495 struct smb_iconv_convenience *iconv_convenience,496 505 struct reg_diff_callbacks **callbacks, 497 506 void **callback_data); 498 507 WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename, 499 struct smb_iconv_convenience *ic,500 508 struct reg_diff_callbacks **callbacks, 501 509 void **callback_data); … … 506 514 void *callback_data); 507 515 WERROR reg_diff_load(const char *filename, 508 struct smb_iconv_convenience *iconv_convenience,509 516 const struct reg_diff_callbacks *callbacks, 510 517 void *callback_data); 511 518 512 519 WERROR reg_dotreg_diff_load(int fd, 513 struct smb_iconv_convenience *iconv_convenience,514 520 const struct reg_diff_callbacks *callbacks, 515 521 void *callback_data); 516 522 517 523 WERROR reg_preg_diff_load(int fd, 518 struct smb_iconv_convenience *iconv_convenience,519 524 const struct reg_diff_callbacks *callbacks, 520 525 void *callback_data); -
vendor/current/source4/lib/registry/registry.pc.in
r414 r740 8 8 Requires: talloc 9 9 Requires.private: ldb 10 Version: 0.0.111 Libs: -L${libdir} -lregistry10 Version: @PACKAGE_VERSION@ 11 Libs: @LIB_RPATH@ -L${libdir} -lregistry 12 12 Cflags: -I${includedir} -DHAVE_IMMEDIATE_STRUCTURES=1 -
vendor/current/source4/lib/registry/rpc.c
r414 r740 28 28 struct registry_key key; 29 29 struct policy_handle pol; 30 struct dcerpc_pipe *pipe; 31 30 struct dcerpc_binding_handle *binding_handle; 32 31 const char* classname; 33 32 uint32_t num_subkeys; … … 44 43 struct registry_context context; 45 44 struct dcerpc_pipe *pipe; 45 struct dcerpc_binding_handle *binding_handle; 46 46 }; 47 47 … … 52 52 */ 53 53 54 #define openhive(u) static WERROR open_ ## u(struct dcerpc_ pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *hnd) \54 #define openhive(u) static WERROR open_ ## u(struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx, struct policy_handle *hnd) \ 55 55 { \ 56 56 struct winreg_Open ## u r; \ … … 62 62 r.out.handle = hnd;\ 63 63 \ 64 status = dcerpc_winreg_Open ## u (p, mem_ctx, &r); \64 status = dcerpc_winreg_Open ## u ## _r(b, mem_ctx, &r); \ 65 65 \ 66 66 if (!NT_STATUS_IS_OK(status)) { \ … … 82 82 static struct { 83 83 uint32_t hkey; 84 WERROR (*open) (struct dcerpc_ pipe *p, TALLOC_CTX *,84 WERROR (*open) (struct dcerpc_binding_handle *b, TALLOC_CTX *, 85 85 struct policy_handle *h); 86 86 } known_hives[] = { … … 118 118 119 119 mykeydata = talloc_zero(ctx, struct rpc_key); 120 W_ERROR_HAVE_NO_MEMORY(mykeydata); 120 121 mykeydata->key.context = ctx; 121 mykeydata-> pipe = talloc_reference(mykeydata, rctx->pipe);122 mykeydata->binding_handle = rctx->binding_handle; 122 123 mykeydata->num_values = -1; 123 124 mykeydata->num_subkeys = -1; 124 125 *k = (struct registry_key *)mykeydata; 125 return known_hives[n].open(mykeydata-> pipe, mykeydata, &(mykeydata->pol));126 return known_hives[n].open(mykeydata->binding_handle, mykeydata, &mykeydata->pol); 126 127 } 127 128 … … 161 162 162 163 mykeydata = talloc_zero(mem_ctx, struct rpc_key); 164 W_ERROR_HAVE_NO_MEMORY(mykeydata); 163 165 mykeydata->key.context = parentkeydata->key.context; 164 mykeydata-> pipe = talloc_reference(mykeydata, parentkeydata->pipe);166 mykeydata->binding_handle = parentkeydata->binding_handle; 165 167 mykeydata->num_values = -1; 166 168 mykeydata->num_subkeys = -1; … … 171 173 r.in.parent_handle = &parentkeydata->pol; 172 174 r.in.keyname.name = name; 173 r.in. unknown= 0x00000000;175 r.in.options = 0x00000000; 174 176 r.in.access_mask = 0x02000000; 175 177 r.out.handle = &mykeydata->pol; 176 178 177 status = dcerpc_winreg_OpenKey (mykeydata->pipe, mem_ctx, &r);179 status = dcerpc_winreg_OpenKey_r(mykeydata->binding_handle, mem_ctx, &r); 178 180 179 181 if (!NT_STATUS_IS_OK(status)) { … … 213 215 r.in.enum_index = n; 214 216 r.in.name = &name; 215 r.in.type = type;217 r.in.type = (enum winreg_Type *) type; 216 218 r.in.value = &value; 217 219 r.in.size = &val_size; 218 220 r.in.length = &zero; 219 221 r.out.name = &name; 220 r.out.type = type;222 r.out.type = (enum winreg_Type *) type; 221 223 r.out.value = &value; 222 224 r.out.size = &val_size; 223 225 r.out.length = &zero; 224 226 225 status = dcerpc_winreg_EnumValue (mykeydata->pipe, mem_ctx, &r);227 status = dcerpc_winreg_EnumValue_r(mykeydata->binding_handle, mem_ctx, &r); 226 228 227 229 if (!NT_STATUS_IS_OK(status)) { … … 230 232 } 231 233 232 *value_name = talloc_ reference(mem_ctx, r.out.name->name);234 *value_name = talloc_steal(mem_ctx, r.out.name->name); 233 235 *type = *(r.out.type); 234 236 *data = data_blob_talloc(mem_ctx, r.out.value, *r.out.length); … … 262 264 r.in.handle = &mykeydata->pol; 263 265 r.in.value_name = &name; 264 r.in.type = type;266 r.in.type = (enum winreg_Type *) type; 265 267 r.in.data = &value; 266 268 r.in.data_size = &val_size; 267 269 r.in.data_length = &zero; 268 r.out.type = type;270 r.out.type = (enum winreg_Type *) type; 269 271 r.out.data = &value; 270 272 r.out.data_size = &val_size; 271 273 r.out.data_length = &zero; 272 274 273 status = dcerpc_winreg_QueryValue (mykeydata->pipe, mem_ctx, &r);275 status = dcerpc_winreg_QueryValue_r(mykeydata->binding_handle, mem_ctx, &r); 274 276 275 277 if (!NT_STATUS_IS_OK(status)) { … … 312 314 r.out.last_changed_time = &change_time; 313 315 314 status = dcerpc_winreg_EnumKey (mykeydata->pipe, mem_ctx, &r);316 status = dcerpc_winreg_EnumKey_r(mykeydata->binding_handle, mem_ctx, &r); 315 317 316 318 if (!NT_STATUS_IS_OK(status)) { … … 320 322 321 323 if (name != NULL) 322 *name = talloc_ reference(mem_ctx, r.out.name->name);324 *name = talloc_steal(mem_ctx, r.out.name->name); 323 325 if (keyclass != NULL) 324 *keyclass = talloc_ reference(mem_ctx, r.out.keyclass->name);326 *keyclass = talloc_steal(mem_ctx, r.out.keyclass->name); 325 327 if (last_changed_time != NULL) 326 328 *last_changed_time = *(r.out.last_changed_time); … … 330 332 331 333 static WERROR rpc_add_key(TALLOC_CTX *mem_ctx, 332 struct registry_key *parent, const char * name,334 struct registry_key *parent, const char *path, 333 335 const char *key_class, 334 336 struct security_descriptor *sec, … … 343 345 ZERO_STRUCT(r); 344 346 r.in.handle = &parentkd->pol; 345 r.in.name.name = name;347 r.in.name.name = path; 346 348 r.in.keyclass.name = NULL; 347 349 r.in.options = 0; … … 352 354 r.out.action_taken = NULL; 353 355 354 status = dcerpc_winreg_CreateKey (parentkd->pipe, mem_ctx, &r);356 status = dcerpc_winreg_CreateKey_r(parentkd->binding_handle, mem_ctx, &r); 355 357 356 358 if (!NT_STATUS_IS_OK(status)) { … … 360 362 } 361 363 362 rpck-> pipe = talloc_reference(rpck, parentkd->pipe);364 rpck->binding_handle = parentkd->binding_handle; 363 365 *key = (struct registry_key *)rpck; 364 366 … … 388 390 r.out.last_changed_time = &mykeydata->last_changed_time; 389 391 390 status = dcerpc_winreg_QueryInfoKey (mykeydata->pipe, mem_ctx, &r);392 status = dcerpc_winreg_QueryInfoKey_r(mykeydata->binding_handle, mem_ctx, &r); 391 393 392 394 if (!NT_STATUS_IS_OK(status)) { … … 395 397 } 396 398 397 mykeydata->classname = talloc_reference(mem_ctx, r.out.classname->name); 398 399 return r.out.result; 400 } 401 402 static WERROR rpc_del_key(struct registry_key *parent, const char *name) 399 mykeydata->classname = talloc_steal(mem_ctx, r.out.classname->name); 400 401 return r.out.result; 402 } 403 404 static WERROR rpc_del_key(TALLOC_CTX *mem_ctx, struct registry_key *parent, 405 const char *name) 403 406 { 404 407 NTSTATUS status; 405 408 struct rpc_key *mykeydata = talloc_get_type(parent, struct rpc_key); 406 409 struct winreg_DeleteKey r; 407 TALLOC_CTX *mem_ctx = talloc_init("del_key");408 410 409 411 ZERO_STRUCT(r); … … 411 413 r.in.key.name = name; 412 414 413 status = dcerpc_winreg_DeleteKey(mykeydata->pipe, mem_ctx, &r); 414 415 talloc_free(mem_ctx); 415 status = dcerpc_winreg_DeleteKey_r(mykeydata->binding_handle, mem_ctx, &r); 416 416 417 417 if (!NT_STATUS_IS_OK(status)) { … … 474 474 .delete_key = rpc_del_key, 475 475 .get_key_info = rpc_get_info, 476 .get_predefined_key = rpc_get_predefined_key,477 476 }; 478 477 … … 490 489 491 490 rctx = talloc(NULL, struct rpc_registry_context); 491 W_ERROR_HAVE_NO_MEMORY(rctx); 492 492 493 493 /* Default to local smbd if no connection is specified */ … … 498 498 status = dcerpc_pipe_connect(rctx /* TALLOC_CTX */, 499 499 &p, location, 500 500 &ndr_table_winreg, 501 501 credentials, ev, lp_ctx); 502 rctx->pipe = p;503 504 502 if(NT_STATUS_IS_ERR(status)) { 505 503 DEBUG(1, ("Unable to open '%s': %s\n", location, … … 510 508 } 511 509 510 rctx->pipe = p; 511 rctx->binding_handle = p->binding_handle; 512 512 513 *ctx = (struct registry_context *)rctx; 513 514 (*ctx)->ops = ®_backend_rpc; -
vendor/current/source4/lib/registry/samba.c
r414 r740 39 39 40 40 location = talloc_asprintf(ctx, "%s/%s.ldb", 41 lp _private_dir(lp_ctx),41 lpcfg_private_dir(lp_ctx), 42 42 name); 43 W_ERROR_HAVE_NO_MEMORY(location); 43 44 44 45 error = reg_open_hive(ctx, location, auth_info, creds, event_ctx, lp_ctx, &hive); … … 47 48 error = reg_open_ldb_file(ctx, location, auth_info, 48 49 creds, event_ctx, lp_ctx, &hive); 50 51 talloc_free(discard_const_p(char, location)); 49 52 50 53 if (!W_ERROR_IS_OK(error)) -
vendor/current/source4/lib/registry/tests/diff.c
r414 r740 53 53 { 54 54 struct diff_tcase_data *td = tcase_data; 55 struct smb_iconv_convenience *ic;56 55 struct reg_diff_callbacks *callbacks; 57 56 void *data; 58 57 WERROR error; 59 58 60 ic = lp_iconv_convenience(tctx->lp_ctx); 61 62 error = reg_diff_load(td->filename, iconv_convenience, callbacks, data); 59 error = reg_diff_load(td->filename, callbacks, data); 63 60 torture_assert_werr_ok(tctx, error, "reg_diff_load"); 64 61 … … 72 69 WERROR error; 73 70 74 error = reg_diff_apply(td->r1_ctx, lp_iconv_convenience(tctx->lp_ctx),td->filename);71 error = reg_diff_apply(td->r1_ctx, td->filename); 75 72 torture_assert_werr_ok(tctx, error, "reg_diff_apply"); 76 73 … … 228 225 torture_assert_werr_ok(tctx, error, "Creating HKLM\\..\\Policies\\Explorer failed"); 229 226 230 231 blob.data = (void *)talloc(r2_ctx, uint32_t); 232 SIVAL(blob.data, 0, 0x03ffffff); 233 blob.length = sizeof(uint32_t); 227 blob.data = talloc_array(r2_ctx, uint8_t, 4); 228 /* set "0x03FFFFFF" in little endian format */ 229 blob.data[0] = 0xFF; blob.data[1] = 0xFF; 230 blob.data[2] = 0xFF; blob.data[3] = 0x03; 231 blob.length = 4; 234 232 235 233 r1_ctx->ops->set_value(newkey, "NoDrives", REG_DWORD, blob); … … 247 245 { 248 246 struct diff_tcase_data *td; 249 struct smb_iconv_convenience *ic;250 247 WERROR error; 251 248 … … 253 250 td = *data; 254 251 255 ic = lp_iconv_convenience(tctx->lp_ctx);256 257 252 td->filename = talloc_asprintf(tctx, "%s/test.pol", td->tempdir); 258 error = reg_preg_diff_save(tctx, td->filename, ic, &td->callbacks, &td->callback_data); 253 error = reg_preg_diff_save(tctx, td->filename, &td->callbacks, 254 &td->callback_data); 259 255 torture_assert_werr_ok(tctx, error, "reg_preg_diff_save"); 260 256 … … 265 261 { 266 262 struct diff_tcase_data *td; 267 struct smb_iconv_convenience *ic;268 263 WERROR error; 269 264 … … 271 266 td = *data; 272 267 273 ic = lp_iconv_convenience(tctx->lp_ctx);274 275 268 td->filename = talloc_asprintf(tctx, "%s/test.reg", td->tempdir); 276 error = reg_dotreg_diff_save(tctx, td->filename, ic, &td->callbacks, &td->callback_data); 269 error = reg_dotreg_diff_save(tctx, td->filename, &td->callbacks, 270 &td->callback_data); 277 271 torture_assert_werr_ok(tctx, error, "reg_dotreg_diff_save"); 278 272 … … 283 277 { 284 278 struct torture_tcase *tcase; 285 struct torture_suite *suite = torture_suite_create(mem_ctx, " DIFF");279 struct torture_suite *suite = torture_suite_create(mem_ctx, "diff"); 286 280 287 281 tcase = torture_suite_add_tcase(suite, "PReg"); -
vendor/current/source4/lib/registry/tests/generic.c
r414 r740 32 32 static bool test_str_regtype(struct torture_context *ctx) 33 33 { 34 torture_assert_str_equal(ctx, str_regtype(0), 35 "REG_NONE", "REG_NONE failed"); 34 36 torture_assert_str_equal(ctx, str_regtype(1), 35 37 "REG_SZ", "REG_SZ failed"); 38 torture_assert_str_equal(ctx, str_regtype(2), 39 "REG_EXPAND_SZ", "REG_EXPAND_SZ failed"); 40 torture_assert_str_equal(ctx, str_regtype(3), 41 "REG_BINARY", "REG_BINARY failed"); 36 42 torture_assert_str_equal(ctx, str_regtype(4), 37 43 "REG_DWORD", "REG_DWORD failed"); 44 torture_assert_str_equal(ctx, str_regtype(5), 45 "REG_DWORD_BIG_ENDIAN", "REG_DWORD_BIG_ENDIAN failed"); 46 torture_assert_str_equal(ctx, str_regtype(6), 47 "REG_LINK", "REG_LINK failed"); 48 torture_assert_str_equal(ctx, str_regtype(7), 49 "REG_MULTI_SZ", "REG_MULTI_SZ failed"); 50 torture_assert_str_equal(ctx, str_regtype(8), 51 "REG_RESOURCE_LIST", "REG_RESOURCE_LIST failed"); 52 torture_assert_str_equal(ctx, str_regtype(9), 53 "REG_FULL_RESOURCE_DESCRIPTOR", "REG_FULL_RESOURCE_DESCRIPTOR failed"); 54 torture_assert_str_equal(ctx, str_regtype(10), 55 "REG_RESOURCE_REQUIREMENTS_LIST", "REG_RESOURCE_REQUIREMENTS_LIST failed"); 56 torture_assert_str_equal(ctx, str_regtype(11), 57 "REG_QWORD", "REG_QWORD failed"); 38 58 39 59 return true; … … 43 63 static bool test_reg_val_data_string_dword(struct torture_context *ctx) 44 64 { 45 uint 32_t d = 0x20;46 DATA_BLOB db = { (uint8_t *)&d, sizeof(d)};47 torture_assert_str_equal(ctx, "0x 20",48 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx),REG_DWORD, db),65 uint8_t d[] = { 0x20, 0x00, 0x00, 0x00 }; 66 DATA_BLOB db = { d, 4 }; 67 torture_assert_str_equal(ctx, "0x00000020", 68 reg_val_data_string(ctx, REG_DWORD, db), 49 69 "dword failed"); 70 return true; 71 } 72 73 static bool test_reg_val_data_string_dword_big_endian(struct torture_context *ctx) 74 { 75 uint8_t d[] = { 0x20, 0x00, 0x00, 0x00 }; 76 DATA_BLOB db = { d, 4 }; 77 torture_assert_str_equal(ctx, "0x00000020", 78 reg_val_data_string(ctx, REG_DWORD_BIG_ENDIAN, db), 79 "dword failed"); 80 return true; 81 } 82 83 static bool test_reg_val_data_string_qword(struct torture_context *ctx) 84 { 85 uint8_t d[] = { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 86 DATA_BLOB db = { d, 8 }; 87 torture_assert_str_equal(ctx, "0x0000000000000020", 88 reg_val_data_string(ctx, REG_QWORD, db), 89 "qword failed"); 50 90 return true; 51 91 } … … 54 94 { 55 95 DATA_BLOB db; 56 convert_string_talloc _convenience(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16,96 convert_string_talloc(ctx, CH_UTF8, CH_UTF16, 57 97 "bla", 3, (void **)&db.data, &db.length, false); 58 98 torture_assert_str_equal(ctx, "bla", 59 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx),REG_SZ, db),99 reg_val_data_string(ctx, REG_SZ, db), 60 100 "sz failed"); 61 101 db.length = 4; 62 102 torture_assert_str_equal(ctx, "bl", 63 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx),REG_SZ, db),103 reg_val_data_string(ctx, REG_SZ, db), 64 104 "sz failed"); 65 105 return true; … … 71 111 DATA_BLOB db = { x, 4 }; 72 112 torture_assert_str_equal(ctx, "01020304", 73 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx),REG_BINARY, db),113 reg_val_data_string(ctx, REG_BINARY, db), 74 114 "binary failed"); 75 115 return true; … … 81 121 DATA_BLOB db = { NULL, 0 }; 82 122 torture_assert_str_equal(ctx, "", 83 reg_val_data_string(ctx, lp_iconv_convenience(ctx->lp_ctx),REG_BINARY, db),123 reg_val_data_string(ctx, REG_BINARY, db), 84 124 "empty failed"); 85 125 return true; … … 89 129 { 90 130 DATA_BLOB data; 91 convert_string_talloc _convenience(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16,131 convert_string_talloc(ctx, CH_UTF8, CH_UTF16, 92 132 "stationary traveller", 93 133 strlen("stationary traveller"), 94 134 (void **)&data.data, &data.length, false); 95 135 torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller", 96 reg_val_description(ctx, lp_iconv_convenience(ctx->lp_ctx),"camel", REG_SZ, data),136 reg_val_description(ctx, "camel", REG_SZ, data), 97 137 "reg_val_description failed"); 98 138 return true; … … 103 143 { 104 144 DATA_BLOB data; 105 convert_string_talloc _convenience(ctx, lp_iconv_convenience(ctx->lp_ctx), CH_UTF8, CH_UTF16,145 convert_string_talloc(ctx, CH_UTF8, CH_UTF16, 106 146 "west berlin", 107 147 strlen("west berlin"), 108 148 (void **)&data.data, &data.length, false); 109 149 torture_assert_str_equal(ctx, "<No Name> = REG_SZ : west berlin", 110 reg_val_description(ctx, lp_iconv_convenience(ctx->lp_ctx),NULL, REG_SZ, data),150 reg_val_description(ctx, NULL, REG_SZ, data), 111 151 "description with null name failed"); 112 152 return true; … … 115 155 struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx) 116 156 { 117 struct torture_suite *suite = torture_suite_create(mem_ctx, " REGISTRY");157 struct torture_suite *suite = torture_suite_create(mem_ctx, "registry"); 118 158 torture_suite_add_simple_test(suite, "str_regtype", 119 159 test_str_regtype); 120 160 torture_suite_add_simple_test(suite, "reg_val_data_string dword", 121 161 test_reg_val_data_string_dword); 162 torture_suite_add_simple_test(suite, "reg_val_data_string dword_big_endian", 163 test_reg_val_data_string_dword_big_endian); 164 torture_suite_add_simple_test(suite, "reg_val_data_string qword", 165 test_reg_val_data_string_qword); 122 166 torture_suite_add_simple_test(suite, "reg_val_data_string sz", 123 167 test_reg_val_data_string_sz); -
vendor/current/source4/lib/registry/tests/hive.c
r414 r740 33 33 { 34 34 const struct hive_key *root = (const struct hive_key *)test_data; 35 WERROR error = hive_key_del( root, "bla");35 WERROR error = hive_key_del(tctx, root, "bla"); 36 36 torture_assert_werr_equal(tctx, error, WERR_BADFILE, 37 37 "invalid return code"); … … 70 70 WERROR error; 71 71 struct hive_key *subkey; 72 char data[4];73 SIVAL(data, 0, 42);72 uint8_t d[] = { 0x42, 0x00, 0x00, 0x00 }; 73 DATA_BLOB db = { d, 4 }; 74 74 75 75 error = hive_key_add_name(tctx, root, "Nested Keyll", NULL, … … 77 77 torture_assert_werr_ok(tctx, error, "hive_key_add_name"); 78 78 79 error = hive_key_set_value(root, "Answer", REG_DWORD, 80 data_blob_talloc(tctx, data, sizeof(data))); 79 error = hive_key_set_value(root, "Answer", REG_DWORD, db); 81 80 torture_assert_werr_ok(tctx, error, "hive_key_set_value"); 82 81 … … 108 107 torture_assert_werr_ok(tctx, error, "hive_key_add_name"); 109 108 110 error = hive_key_del( root, "Nested Key");109 error = hive_key_del(mem_ctx, root, "Nested Key"); 111 110 torture_assert_werr_ok(tctx, error, "reg_key_del"); 112 111 … … 122 121 const struct hive_key *root = (const struct hive_key *)test_data; 123 122 TALLOC_CTX *mem_ctx = tctx; 124 char data[4];125 SIVAL(data, 0, 42);123 uint8_t d[] = { 0x42, 0x00, 0x00, 0x00 }; 124 DATA_BLOB db = { d, 4 }; 126 125 127 126 /* Create a new key under the root */ … … 136 135 137 136 /* Create a new value under "Child Key" */ 138 error = hive_key_set_value(subkey2, "Answer Recursive", REG_DWORD, 139 data_blob_talloc(mem_ctx, data, sizeof(data))); 137 error = hive_key_set_value(subkey2, "Answer Recursive", REG_DWORD, db); 140 138 torture_assert_werr_ok(tctx, error, "hive_key_set_value"); 141 139 142 140 /* Deleting "Parent Key" will also delete "Child Key" and the value. */ 143 error = hive_key_del( root, "Parent Key");141 error = hive_key_del(mem_ctx, root, "Parent Key"); 144 142 torture_assert_werr_ok(tctx, error, "hive_key_del"); 145 143 … … 167 165 torture_assert_werr_ok(tctx, error, "hive_key_add_name"); 168 166 169 error = hive_key_del( root, "Nested Key");167 error = hive_key_del(mem_ctx, root, "Nested Key"); 170 168 torture_assert_werr_ok(tctx, error, "reg_key_del"); 171 169 172 error = hive_key_del( root, "Nested Key");170 error = hive_key_del(mem_ctx, root, "Nested Key"); 173 171 torture_assert_werr_equal(tctx, error, WERR_BADFILE, "reg_key_del"); 174 172 … … 183 181 const struct hive_key *root = (const struct hive_key *)test_data; 184 182 TALLOC_CTX *mem_ctx = tctx; 185 char data[4];186 SIVAL(data, 0, 42);183 uint8_t d[] = { 0x42, 0x00, 0x00, 0x00 }; 184 DATA_BLOB db = { d, 4 }; 187 185 188 186 error = hive_key_add_name(mem_ctx, root, "YA Nested Key", NULL, … … 190 188 torture_assert_werr_ok(tctx, error, "hive_key_add_name"); 191 189 192 error = hive_key_set_value(subkey, "Answer", REG_DWORD, 193 data_blob_talloc(mem_ctx, data, sizeof(data))); 190 error = hive_key_set_value(subkey, "Answer", REG_DWORD, db); 194 191 torture_assert_werr_ok(tctx, error, "hive_key_set_value"); 195 192 … … 203 200 const struct hive_key *root = (const struct hive_key *)test_data; 204 201 TALLOC_CTX *mem_ctx = tctx; 205 char data[4];206 202 uint32_t type; 207 DATA_BLOB value; 208 209 SIVAL(data, 0, 42); 203 uint8_t d[] = { 0x42, 0x00, 0x00, 0x00 }; 204 DATA_BLOB db = { d, 4 }, data; 210 205 211 206 error = hive_key_add_name(mem_ctx, root, "EYA Nested Key", NULL, … … 213 208 torture_assert_werr_ok(tctx, error, "hive_key_add_name"); 214 209 215 error = hive_get_value(mem_ctx, subkey, "Answer", &type, & value);210 error = hive_get_value(mem_ctx, subkey, "Answer", &type, &data); 216 211 torture_assert_werr_equal(tctx, error, WERR_BADFILE, 217 212 "getting missing value"); 218 213 219 error = hive_key_set_value(subkey, "Answer", REG_DWORD, 220 data_blob_talloc(mem_ctx, data, sizeof(data))); 221 torture_assert_werr_ok(tctx, error, "hive_key_set_value"); 222 223 error = hive_get_value(mem_ctx, subkey, "Answer", &type, &value); 214 error = hive_key_set_value(subkey, "Answer", REG_DWORD, db); 215 torture_assert_werr_ok(tctx, error, "hive_key_set_value"); 216 217 error = hive_get_value(mem_ctx, subkey, "Answer", &type, &data); 224 218 torture_assert_werr_ok(tctx, error, "getting value"); 225 219 226 torture_assert_int_equal(tctx, value.length, 4, "value length");220 torture_assert_int_equal(tctx, data.length, 4, "value length"); 227 221 torture_assert_int_equal(tctx, type, REG_DWORD, "value type"); 228 222 229 torture_assert_mem_equal(tctx, &data, value.data, sizeof(uint32_t), 230 "value data"); 223 torture_assert_mem_equal(tctx, data.data, db.data, 4, "value data"); 231 224 232 225 return true; … … 239 232 const struct hive_key *root = (const struct hive_key *)test_data; 240 233 TALLOC_CTX *mem_ctx = tctx; 241 char data[4];242 234 uint32_t type; 243 DATA_BLOB value; 244 245 SIVAL(data, 0, 42); 235 uint8_t d[] = { 0x42, 0x00, 0x00, 0x00 }; 236 DATA_BLOB db = { d, 4 }; 246 237 247 238 error = hive_key_add_name(mem_ctx, root, "EEYA Nested Key", NULL, … … 249 240 torture_assert_werr_ok(tctx, error, "hive_key_add_name"); 250 241 251 error = hive_key_set_value(subkey, "Answer", REG_DWORD, 252 data_blob_talloc(mem_ctx, data, sizeof(data))); 253 torture_assert_werr_ok(tctx, error, "hive_key_set_value"); 254 255 error = hive_key_del_value(subkey, "Answer"); 242 error = hive_key_set_value(subkey, "Answer", REG_DWORD, db); 243 torture_assert_werr_ok(tctx, error, "hive_key_set_value"); 244 245 error = hive_key_del_value(mem_ctx, subkey, "Answer"); 256 246 torture_assert_werr_ok(tctx, error, "deleting value"); 257 247 258 error = hive_get_value(mem_ctx, subkey, "Answer", &type, & value);248 error = hive_get_value(mem_ctx, subkey, "Answer", &type, &db); 259 249 torture_assert_werr_equal(tctx, error, WERR_BADFILE, "getting value"); 260 250 261 error = hive_key_del_value( subkey, "Answer");251 error = hive_key_del_value(mem_ctx, subkey, "Answer"); 262 252 torture_assert_werr_equal(tctx, error, WERR_BADFILE, 263 253 "deleting value"); … … 273 263 const struct hive_key *root = (const struct hive_key *)test_data; 274 264 TALLOC_CTX *mem_ctx = tctx; 275 char data[4];276 265 uint32_t type; 277 DATA_BLOB value; 266 uint8_t d[] = { 0x42, 0x00, 0x00, 0x00 }; 267 DATA_BLOB db = { d, 4 }, data; 278 268 const char *name; 279 int data_val = 42;280 SIVAL(data, 0, data_val);281 269 282 270 error = hive_key_add_name(mem_ctx, root, "AYAYA Nested Key", NULL, … … 284 272 torture_assert_werr_ok(tctx, error, "hive_key_add_name"); 285 273 286 error = hive_key_set_value(subkey, "Answer", REG_DWORD, 287 data_blob_talloc(mem_ctx, data, sizeof(data))); 274 error = hive_key_set_value(subkey, "Answer", REG_DWORD, db); 288 275 torture_assert_werr_ok(tctx, error, "hive_key_set_value"); 289 276 290 277 error = hive_get_value_by_index(mem_ctx, subkey, 0, &name, 291 &type, & value);278 &type, &data); 292 279 torture_assert_werr_ok(tctx, error, "getting value"); 293 280 294 281 torture_assert_str_equal(tctx, name, "Answer", "value name"); 295 282 296 torture_assert_int_equal(tctx, value.length, 4, "value length");283 torture_assert_int_equal(tctx, data.length, 4, "value length"); 297 284 torture_assert_int_equal(tctx, type, REG_DWORD, "value type"); 298 285 286 torture_assert_mem_equal(tctx, data.data, db.data, 4, "value data"); 299 287 300 torture_assert_int_equal(tctx, data_val, IVAL(value.data, 0), "value data");301 302 288 error = hive_get_value_by_index(mem_ctx, subkey, 1, &name, 303 &type, & value);289 &type, &data); 304 290 torture_assert_werr_equal(tctx, error, WERR_NO_MORE_ITEMS, 305 291 "getting missing value"); … … 450 436 rmdir(dirname); 451 437 452 error = reg_create_regf_file(tctx, lp_iconv_convenience(tctx->lp_ctx), 453 dirname, 5, &key); 438 error = reg_create_regf_file(tctx, dirname, 5, &key); 454 439 if (!W_ERROR_IS_OK(error)) { 455 440 fprintf(stderr, "Unable to create new regf file\n"); … … 473 458 { 474 459 struct torture_tcase *tcase; 475 struct torture_suite *suite = torture_suite_create(mem_ctx, " HIVE");460 struct torture_suite *suite = torture_suite_create(mem_ctx, "hive"); 476 461 477 462 torture_suite_add_simple_test(suite, "dir-refuses-null-location", -
vendor/current/source4/lib/registry/tests/registry.c
r414 r740 118 118 { 119 119 struct registry_context *rctx = (struct registry_context *)_data; 120 struct registry_key *root, *newkey 1, *newkey2;120 struct registry_key *root, *newkey; 121 121 WERROR error; 122 122 … … 125 125 "getting predefined key failed"); 126 126 127 error = reg_key_add_name(rctx, root, "Hamburg ", NULL, NULL,128 &newkey 1);127 error = reg_key_add_name(rctx, root, "Hamburg\\Hamburg", NULL, NULL, 128 &newkey); 129 129 torture_assert_werr_ok(tctx, error, "Creating key return code"); 130 torture_assert(tctx, newkey1 != NULL, "Creating new key"); 131 132 error = reg_key_add_name(rctx, root, "Hamburg\\Hamburg", NULL, NULL, 133 &newkey2); 134 torture_assert_werr_ok(tctx, error, "Creating key return code"); 135 torture_assert(tctx, newkey2 != NULL, "Creating new key"); 130 torture_assert(tctx, newkey != NULL, "Creating new key"); 136 131 137 132 return true; … … 201 196 torture_assert(tctx, newkey != NULL, "Creating new key"); 202 197 203 error = reg_key_del( root, "Polen");198 error = reg_key_del(tctx, root, "Polen"); 204 199 torture_assert_werr_ok(tctx, error, "Delete key"); 205 200 206 error = reg_key_del( root, "Polen");201 error = reg_key_del(tctx, root, "Polen"); 207 202 torture_assert_werr_equal(tctx, error, WERR_BADFILE, 208 203 "Delete missing key"); … … 465 460 torture_assert_werr_ok (tctx, error, "setting value"); 466 461 467 error = reg_del_value( subkey, __FUNCTION__);462 error = reg_del_value(tctx, subkey, __FUNCTION__); 468 463 torture_assert_werr_ok (tctx, error, "unsetting value"); 469 464 … … 585 580 { 586 581 struct torture_tcase *tcase; 587 struct torture_suite *suite = torture_suite_create(mem_ctx, " REGISTRY");582 struct torture_suite *suite = torture_suite_create(mem_ctx, "registry"); 588 583 589 584 tcase = torture_suite_add_tcase(suite, "local"); -
vendor/current/source4/lib/registry/tools/regdiff.c
r414 r740 131 131 poptFreeContext(pc); 132 132 133 error = reg_dotreg_diff_save(ctx, outputfile, lp_iconv_convenience(cmdline_lp_ctx), &callbacks, 134 &callback_data); 133 error = reg_dotreg_diff_save(ctx, outputfile, &callbacks, &callback_data); 135 134 if (!W_ERROR_IS_OK(error)) { 136 135 fprintf(stderr, "Problem saving registry diff to '%s': %s\n", -
vendor/current/source4/lib/registry/tools/regpatch.c
r414 r740 69 69 poptFreeContext(pc); 70 70 71 reg_diff_apply(h, lp_iconv_convenience(cmdline_lp_ctx),patch);71 reg_diff_apply(h, patch); 72 72 73 73 return 0; -
vendor/current/source4/lib/registry/tools/regshell.c
r414 r740 25 25 #include "lib/events/events.h" 26 26 #include "system/time.h" 27 #include " lib/smbreadline/smbreadline.h"27 #include "../libcli/smbreadline/smbreadline.h" 28 28 #include "librpc/gen_ndr/ndr_security.h" 29 29 #include "lib/registry/tools/common.h" … … 126 126 printf("Key Class: %s\n", classname); 127 127 last_mod = nt_time_to_unix(last_change); 128 printf("Time Last Modified: %s \n", ctime(&last_mod));128 printf("Time Last Modified: %s", ctime(&last_mod)); 129 129 printf("Number of subkeys: %d\n", num_subkeys); 130 130 printf("Number of values: %d\n", num_values); … … 141 141 error = reg_get_sec_desc(ctx, ctx->current, &sec_desc); 142 142 if (!W_ERROR_IS_OK(error)) { 143 printf("Error getting security descriptor \n");144 return error;143 printf("Error getting security descriptor: %s\n", win_errstr(error)); 144 return WERR_OK; 145 145 } 146 146 ndr_print_debug((ndr_print_fn_t)ndr_print_security_descriptor, … … 196 196 } 197 197 198 if (!reg_string_to_val(ctx, lp_iconv_convenience(cmdline_lp_ctx), 199 argv[2], argv[3], &val.data_type, 200 &val.data)) { 198 if (!reg_string_to_val(ctx, argv[2], argv[3], &val.data_type, &val.data)) { 201 199 fprintf(stderr, "Unable to interpret data\n"); 202 200 return WERR_INVALID_PARAM; … … 260 258 261 259 printf("%s\n%s\n", str_regtype(value_type), 262 reg_val_data_string(ctx, lp_iconv_convenience(cmdline_lp_ctx),value_type, value_data));260 reg_val_data_string(ctx, value_type, value_data)); 263 261 264 262 return WERR_OK; … … 267 265 static WERROR cmd_ls(struct regshell_context *ctx, int argc, char **argv) 268 266 { 269 int i;267 unsigned int i; 270 268 WERROR error; 271 269 uint32_t valuetype; … … 283 281 284 282 if (!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) { 285 fprintf(stderr, "Error occur ed while browsing thrukeys: %s\n",283 fprintf(stderr, "Error occurred while browsing through keys: %s\n", 286 284 win_errstr(error)); 287 285 return error; … … 291 289 ctx->current, i, &name, &valuetype, &valuedata)); i++) 292 290 printf("V \"%s\" %s %s\n", name, str_regtype(valuetype), 293 reg_val_data_string(ctx, lp_iconv_convenience(cmdline_lp_ctx),valuetype, valuedata));291 reg_val_data_string(ctx, valuetype, valuedata)); 294 292 295 293 return WERR_OK; … … 326 324 } 327 325 328 error = reg_key_del(ctx ->current, argv[1]);326 error = reg_key_del(ctx, ctx->current, argv[1]); 329 327 if(!W_ERROR_IS_OK(error)) { 330 328 fprintf(stderr, "Error deleting '%s'\n", argv[1]); … … 346 344 } 347 345 348 error = reg_del_value(ctx ->current, argv[1]);346 error = reg_del_value(ctx, ctx->current, argv[1]); 349 347 if(!W_ERROR_IS_OK(error)) { 350 348 fprintf(stderr, "Error deleting value '%s'\n", argv[1]); … … 389 387 int argc, char **argv) 390 388 { 391 int i;389 unsigned int i; 392 390 printf("Available commands:\n"); 393 391 for(i = 0; regshell_cmds[i].name; i++) { … … 430 428 /* Complete command */ 431 429 char **matches; 432 int i, len, samelen=0, count=1; 430 size_t len, samelen=0; 431 unsigned int i, count=1; 433 432 434 433 matches = malloc_array_p(char *, MAX_COMPLETIONS); … … 478 477 struct registry_key *base; 479 478 const char *subkeyname; 480 int i, j = 1; 481 int samelen = 0; 482 int len; 479 unsigned int i, j = 1; 480 size_t len, samelen = 0; 483 481 char **matches; 484 482 const char *base_n = ""; … … 594 592 595 593 if (ctx->current == NULL) { 596 int i;594 unsigned int i; 597 595 598 596 for (i = 0; (reg_predefined_keys[i].handle != 0) && … … 617 615 if (ctx->current == NULL) { 618 616 fprintf(stderr, "Unable to access any of the predefined keys\n"); 619 return -1;617 return 1; 620 618 } 621 619 … … 625 623 char *line, *prompt; 626 624 627 asprintf(&prompt, "%s\\%s> ", ctx->predef?ctx->predef:"", ctx->path); 625 if (asprintf(&prompt, "%s\\%s> ", ctx->predef?ctx->predef:"", 626 ctx->path) < 0) { 627 ret = false; 628 break; 629 } 628 630 629 631 current_key = ctx->current; /* No way to pass a void * pointer -
vendor/current/source4/lib/registry/tools/regtree.c
r414 r740 34 34 * @param novals Whether values should not be printed 35 35 */ 36 static void print_tree( int level, struct registry_key *p,36 static void print_tree(unsigned int level, struct registry_key *p, 37 37 const char *name, 38 38 bool fullpath, bool novals) … … 44 44 struct security_descriptor *sec_desc; 45 45 WERROR error; 46 int i;46 unsigned int i; 47 47 TALLOC_CTX *mem_ctx; 48 48 … … 70 70 71 71 if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) { 72 DEBUG(0, ("Error occur ed while fetching subkeys for '%s': %s\n",72 DEBUG(0, ("Error occurred while fetching subkeys for '%s': %s\n", 73 73 name, win_errstr(error))); 74 74 } … … 79 79 mem_ctx, p, i, &valuename, &valuetype, &valuedata)); 80 80 i++) { 81 int j;81 unsigned int j; 82 82 for(j = 0; j < level+1; j++) putchar(' '); 83 83 printf("%s\n", reg_val_description(mem_ctx, 84 lp_iconv_convenience(cmdline_lp_ctx), valuename, 85 valuetype, valuedata)); 84 valuename, valuetype, valuedata)); 86 85 } 87 86 talloc_free(mem_ctx); 88 87 89 88 if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) { 90 DEBUG(0, ("Error occur ed while fetching values for '%s': %s\n",89 DEBUG(0, ("Error occurred while fetching values for '%s': %s\n", 91 90 name, win_errstr(error))); 92 91 } … … 102 101 int main(int argc, char **argv) 103 102 { 104 int opt, i; 103 int opt; 104 unsigned int i; 105 105 const char *file = NULL; 106 106 const char *remote = NULL; -
vendor/current/source4/lib/registry/util.c
r414 r740 3 3 Transparent registry backend handling 4 4 Copyright (C) Jelmer Vernooij 2003-2007. 5 Copyright (C) Wilco Baan Hofman 2010. 5 6 6 7 This program is free software; you can redistribute it and/or modify … … 21 22 #include "lib/registry/registry.h" 22 23 #include "librpc/gen_ndr/winreg.h" 23 24 /** 25 * @file 26 * @brief Registry utility functions 27 */ 28 29 static const struct { 30 uint32_t id; 31 const char *name; 32 } reg_value_types[] = { 33 { REG_SZ, "REG_SZ" }, 34 { REG_DWORD, "REG_DWORD" }, 35 { REG_BINARY, "REG_BINARY" }, 36 { REG_EXPAND_SZ, "REG_EXPAND_SZ" }, 37 { REG_NONE, "REG_NONE" }, 38 { 0, NULL } 39 }; 40 41 /** Return string description of registry value type */ 42 _PUBLIC_ const char *str_regtype(int type) 43 { 44 int i; 45 for (i = 0; reg_value_types[i].name; i++) { 46 if (reg_value_types[i].id == type) 47 return reg_value_types[i].name; 48 } 49 50 return "Unknown"; 51 } 52 53 _PUBLIC_ char *reg_val_data_string(TALLOC_CTX *mem_ctx, 54 struct smb_iconv_convenience *iconv_convenience, 55 uint32_t type, 24 #include "lib/util/data_blob.h" 25 26 _PUBLIC_ char *reg_val_data_string(TALLOC_CTX *mem_ctx, uint32_t type, 56 27 const DATA_BLOB data) 57 28 { … … 64 35 case REG_EXPAND_SZ: 65 36 case REG_SZ: 66 convert_string_talloc_convenience(mem_ctx, iconv_convenience, CH_UTF16, CH_UNIX, 37 convert_string_talloc(mem_ctx, 38 CH_UTF16, CH_UNIX, 67 39 data.data, data.length, 68 40 (void **)&ret, NULL, false); 69 return ret; 41 break; 42 case REG_DWORD: 43 case REG_DWORD_BIG_ENDIAN: 44 SMB_ASSERT(data.length == sizeof(uint32_t)); 45 ret = talloc_asprintf(mem_ctx, "0x%8.8x", 46 IVAL(data.data, 0)); 47 break; 48 case REG_QWORD: 49 SMB_ASSERT(data.length == sizeof(uint64_t)); 50 ret = talloc_asprintf(mem_ctx, "0x%16.16llx", 51 (long long)BVAL(data.data, 0)); 52 break; 70 53 case REG_BINARY: 71 ret = data_blob_hex_string(mem_ctx, &data); 72 return ret; 73 case REG_DWORD: 74 if (*(int *)data.data == 0) 75 return talloc_strdup(mem_ctx, "0"); 76 return talloc_asprintf(mem_ctx, "0x%x", 77 *(int *)data.data); 54 ret = data_blob_hex_string_upper(mem_ctx, &data); 55 break; 56 case REG_NONE: 57 /* "NULL" is the right return value */ 58 break; 78 59 case REG_MULTI_SZ: 60 /* FIXME: We don't support this yet */ 61 break; 62 default: 79 63 /* FIXME */ 80 break; 81 default: 64 /* Other datatypes aren't supported -> return "NULL" */ 82 65 break; 83 66 } … … 87 70 88 71 /** Generate a string that describes a registry value */ 89 _PUBLIC_ char *reg_val_description(TALLOC_CTX *mem_ctx, 90 struct smb_iconv_convenience *iconv_convenience, 72 _PUBLIC_ char *reg_val_description(TALLOC_CTX *mem_ctx, 91 73 const char *name, 92 74 uint32_t data_type, … … 95 77 return talloc_asprintf(mem_ctx, "%s = %s : %s", name?name:"<No Name>", 96 78 str_regtype(data_type), 97 reg_val_data_string(mem_ctx, iconv_convenience, data_type, data)); 98 } 99 100 _PUBLIC_ bool reg_string_to_val(TALLOC_CTX *mem_ctx, 101 struct smb_iconv_convenience *iconv_convenience, 102 const char *type_str, 103 const char *data_str, uint32_t *type, 104 DATA_BLOB *data) 105 { 106 int i; 107 *type = -1; 108 109 /* Find the correct type */ 110 for (i = 0; reg_value_types[i].name; i++) { 111 if (!strcmp(reg_value_types[i].name, type_str)) { 112 *type = reg_value_types[i].id; 113 break; 79 reg_val_data_string(mem_ctx, data_type, data)); 80 } 81 82 /* 83 * This implements reading hex bytes that include comma's. 84 * It was previously handled by strhex_to_data_blob, but that did not cover 85 * the format used by windows. 86 */ 87 static DATA_BLOB reg_strhex_to_data_blob(TALLOC_CTX *mem_ctx, const char *str) 88 { 89 DATA_BLOB ret; 90 const char *HEXCHARS = "0123456789ABCDEF"; 91 size_t i, j; 92 char *hi, *lo; 93 94 ret = data_blob_talloc_zero(mem_ctx, (strlen(str)+(strlen(str) % 3))/3); 95 j = 0; 96 for (i = 0; i < strlen(str); i++) { 97 hi = strchr(HEXCHARS, toupper(str[i])); 98 if (hi == NULL) 99 continue; 100 101 i++; 102 lo = strchr(HEXCHARS, toupper(str[i])); 103 if (lo == NULL) 104 break; 105 106 ret.data[j] = PTR_DIFF(hi, HEXCHARS) << 4; 107 ret.data[j] += PTR_DIFF(lo, HEXCHARS); 108 j++; 109 110 if (j > ret.length) { 111 DEBUG(0, ("Trouble converting hex string to bin\n")); 112 break; 113 } 114 } 115 return ret; 116 } 117 118 119 _PUBLIC_ bool reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str, 120 const char *data_str, uint32_t *type, DATA_BLOB *data) 121 { 122 char *tmp_type_str, *p, *q; 123 int result; 124 125 *type = regtype_by_string(type_str); 126 127 if (*type == -1) { 128 /* Normal windows format is hex, hex(type int as string), 129 dword or just a string. */ 130 if (strncmp(type_str, "hex(", 4) == 0) { 131 /* there is a hex string with the value type between 132 the braces */ 133 tmp_type_str = talloc_strdup(mem_ctx, type_str); 134 q = p = tmp_type_str + strlen("hex("); 135 136 /* Go to the closing brace or end of the string */ 137 while (*q != ')' && *q != '\0') q++; 138 *q = '\0'; 139 140 /* Convert hex string to int, store it in type */ 141 result = sscanf(p, "%x", type); 142 if (!result) { 143 DEBUG(0, ("Could not convert hex to int\n")); 144 return false; 145 } 146 talloc_free(tmp_type_str); 147 } else if (strcmp(type_str, "hex") == 0) { 148 *type = REG_BINARY; 149 } else if (strcmp(type_str, "dword") == 0) { 150 *type = REG_DWORD; 114 151 } 115 152 } … … 120 157 /* Convert data appropriately */ 121 158 122 switch (*type) 123 { 159 switch (*type) { 124 160 case REG_SZ: 161 return convert_string_talloc(mem_ctx, 162 CH_UNIX, CH_UTF16, 163 data_str, strlen(data_str)+1, 164 (void **)&data->data, 165 &data->length, false); 166 break; 167 case REG_MULTI_SZ: 125 168 case REG_EXPAND_SZ: 126 convert_string_talloc_convenience(mem_ctx, iconv_convenience, CH_UNIX, CH_UTF16, 127 data_str, strlen(data_str), 128 (void **)&data->data, &data->length, false); 129 break; 130 131 case REG_DWORD: { 132 uint32_t tmp = strtol(data_str, NULL, 0); 133 *data = data_blob_talloc(mem_ctx, &tmp, 4); 169 case REG_BINARY: 170 *data = reg_strhex_to_data_blob(mem_ctx, data_str); 171 break; 172 case REG_DWORD: 173 case REG_DWORD_BIG_ENDIAN: { 174 uint32_t tmp = strtol(data_str, NULL, 16); 175 *data = data_blob_talloc(mem_ctx, NULL, sizeof(uint32_t)); 176 if (data->data == NULL) return false; 177 SIVAL(data->data, 0, tmp); 134 178 } 135 179 break; 136 180 case REG_QWORD: { 181 uint64_t tmp = strtoll(data_str, NULL, 16); 182 *data = data_blob_talloc(mem_ctx, NULL, sizeof(uint64_t)); 183 if (data->data == NULL) return false; 184 SBVAL(data->data, 0, tmp); 185 } 186 break; 137 187 case REG_NONE: 138 188 ZERO_STRUCTP(data); 139 189 break; 140 141 case REG_BINARY:142 *data = strhex_to_data_blob(mem_ctx, data_str);143 break;144 145 190 default: 146 191 /* FIXME */ 192 /* Other datatypes aren't supported -> return no success */ 147 193 return false; 148 194 } … … 156 202 struct registry_key *predef; 157 203 WERROR error; 158 int predeflength;204 size_t predeflength; 159 205 char *predefname; 160 206 … … 165 211 166 212 predefname = talloc_strndup(mem_ctx, name, predeflength); 213 W_ERROR_HAVE_NO_MEMORY(predefname); 167 214 error = reg_get_predefined_key_by_name(handle, predefname, &predef); 168 215 talloc_free(predefname); … … 193 240 194 241 parent_name = talloc_strndup(mem_ctx, path, strrchr(path, '\\')-path); 195 242 W_ERROR_HAVE_NO_MEMORY(parent_name); 196 243 error = reg_open_key_abs(mem_ctx, ctx, parent_name, parent); 244 talloc_free(parent_name); 197 245 if (!W_ERROR_IS_OK(error)) { 198 246 return error; … … 200 248 201 249 *name = talloc_strdup(mem_ctx, strrchr(path, '\\')+1); 250 W_ERROR_HAVE_NO_MEMORY(*name); 202 251 203 252 return WERR_OK; … … 217 266 error = get_abs_parent(mem_ctx, ctx, path, &parent, &n); 218 267 if (W_ERROR_IS_OK(error)) { 219 error = reg_key_del( parent, n);268 error = reg_key_del(mem_ctx, parent, n); 220 269 } 221 270 … … 233 282 const char *n; 234 283 WERROR error; 284 285 *result = NULL; 235 286 236 287 if (!strchr(path, '\\')) {
Note:
See TracChangeset
for help on using the changeset viewer.