Changeset 988 for vendor/current/source3/registry
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- Location:
- vendor/current/source3/registry
- Files:
-
- 33 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/registry/reg_api.c
r746 r988 71 71 #include "reg_objects.h" 72 72 #include "../librpc/gen_ndr/ndr_security.h" 73 #include "reg_parse_internal.h" 73 74 74 75 #undef DBGC_CLASS … … 112 113 } 113 114 115 TALLOC_FREE(key->subkeys); 114 116 werr = regsubkey_ctr_init(key, &(key->subkeys)); 115 117 W_ERROR_NOT_OK_RETURN(werr); … … 132 134 const char *name, 133 135 const struct security_token *token, 134 uint32 access_desired,136 uint32_t access_desired, 135 137 struct registry_key **pregkey) 136 138 { … … 143 145 SMB_ASSERT(strchr(name, '\\') == NULL); 144 146 145 if (!(regkey = TALLOC_ZERO_P(mem_ctx, struct registry_key)) ||147 if (!(regkey = talloc_zero(mem_ctx, struct registry_key)) || 146 148 !(regkey->token = dup_nt_token(regkey, token)) || 147 !(regkey->key = TALLOC_ZERO_P(regkey, struct registry_key_handle)))149 !(regkey->key = talloc_zero(regkey, struct registry_key_handle))) 148 150 { 149 151 result = WERR_NOMEM; … … 190 192 /* Tag this as a Performance Counter Key */ 191 193 192 if( StrnCaseCmp(key->name, KEY_HKPD, strlen(KEY_HKPD)) == 0 )194 if( strncasecmp_m(key->name, KEY_HKPD, strlen(KEY_HKPD)) == 0 ) 193 195 key->type = REG_KEY_HKPD; 194 196 … … 228 230 229 231 WERROR reg_openhive(TALLOC_CTX *mem_ctx, const char *hive, 230 uint32 desired_access,232 uint32_t desired_access, 231 233 const struct security_token *token, 232 234 struct registry_key **pkey) 233 235 { 236 const struct hive_info *hi; 234 237 SMB_ASSERT(hive != NULL); 235 SMB_ASSERT(hive[0] != '\0');236 238 SMB_ASSERT(strchr(hive, '\\') == NULL); 237 239 238 return regkey_open_onelevel(mem_ctx, NULL, hive, token, desired_access, 239 pkey); 240 hi = hive_info(hive); 241 if (hi == NULL) { 242 return WERR_BADFILE; 243 } 244 245 return regkey_open_onelevel(mem_ctx, NULL, hi->short_name, token, 246 desired_access, pkey); 240 247 } 241 248 … … 246 253 247 254 WERROR reg_openkey(TALLOC_CTX *mem_ctx, struct registry_key *parent, 248 const char *name, uint32 desired_access,255 const char *name, uint32_t desired_access, 249 256 struct registry_key **pkey) 250 257 { … … 298 305 299 306 WERROR reg_enumkey(TALLOC_CTX *mem_ctx, struct registry_key *key, 300 uint32 idx, char **name, NTTIME *last_write_time)307 uint32_t idx, char **name, NTTIME *last_write_time) 301 308 { 302 309 WERROR err; … … 306 313 } 307 314 308 if (!W_ERROR_IS_OK(err = fill_subkey_cache(key))) { 315 err = fill_subkey_cache(key); 316 if (!W_ERROR_IS_OK(err)) { 309 317 return err; 310 318 } … … 328 336 329 337 WERROR reg_enumvalue(TALLOC_CTX *mem_ctx, struct registry_key *key, 330 uint32 idx, char **pname, struct registry_value **pval)338 uint32_t idx, char **pname, struct registry_value **pval) 331 339 { 332 340 struct registry_value *val; … … 338 346 } 339 347 340 if (!(W_ERROR_IS_OK(err = fill_value_cache(key)))) { 348 err = fill_value_cache(key); 349 if (!(W_ERROR_IS_OK(err))) { 341 350 return err; 342 351 } … … 369 378 static WERROR reg_enumvalue_nocachefill(TALLOC_CTX *mem_ctx, 370 379 struct registry_key *key, 371 uint32 idx, char **pname,380 uint32_t idx, char **pname, 372 381 struct registry_value **pval) 373 382 { … … 408 417 { 409 418 WERROR err; 410 uint32 i;419 uint32_t i; 411 420 412 421 if (!(key->key->access_granted & KEY_QUERY_VALUE)) { … … 492 501 NTTIME *last_changed_time) 493 502 { 494 uint32 i, max_size;503 uint32_t i, max_size; 495 504 size_t max_len; 496 505 TALLOC_CTX *mem_ctx; … … 549 558 550 559 WERROR reg_createkey(TALLOC_CTX *ctx, struct registry_key *parent, 551 const char *subkeypath, uint32 desired_access,560 const char *subkeypath, uint32_t desired_access, 552 561 struct registry_key **pkey, 553 562 enum winreg_CreateAction *paction) 554 563 { 555 564 struct registry_key *key = parent; 556 struct registry_key *create_parent;557 565 TALLOC_CTX *mem_ctx; 558 566 char *path, *end; … … 627 635 { 628 636 err = WERR_ACCESS_DENIED; 629 goto done;637 goto trans_done; 630 638 } 631 639 … … 666 674 } 667 675 668 WERROR reg_deletekey(struct registry_key *parent, const char *path) 676 static WERROR reg_deletekey_internal(TALLOC_CTX *mem_ctx, 677 struct registry_key *parent, 678 const char *path, bool lazy) 669 679 { 670 680 WERROR err; 671 681 char *name, *end; 672 struct registry_key *tmp_key, *key; 673 TALLOC_CTX *mem_ctx = talloc_stackframe(); 674 682 struct registry_key *key; 675 683 name = talloc_strdup(mem_ctx, path); 676 684 if (name == NULL) { … … 679 687 } 680 688 689 /* no subkeys - proceed with delete */ 690 end = strrchr(name, '\\'); 691 if (end != NULL) { 692 *end = '\0'; 693 694 err = reg_openkey(mem_ctx, parent, name, 695 KEY_CREATE_SUB_KEY, &key); 696 W_ERROR_NOT_OK_GOTO_DONE(err); 697 698 parent = key; 699 name = end+1; 700 } 701 702 if (name[0] == '\0') { 703 err = WERR_INVALID_PARAM; 704 goto done; 705 } 706 707 err = delete_reg_subkey(parent->key, name, lazy); 708 709 done: 710 return err; 711 } 712 713 WERROR reg_deletekey(struct registry_key *parent, const char *path) 714 { 715 WERROR err; 716 struct registry_key *key; 717 TALLOC_CTX *mem_ctx = talloc_stackframe(); 718 681 719 /* check if the key has subkeys */ 682 err = reg_openkey(mem_ctx, parent, name, REG_KEY_READ, &key);720 err = reg_openkey(mem_ctx, parent, path, REG_KEY_READ, &key); 683 721 W_ERROR_NOT_OK_GOTO_DONE(err); 684 722 … … 691 729 692 730 err = fill_subkey_cache(key); 693 W_ERROR_NOT_OK_GOTO(err, trans_done); 731 if (!W_ERROR_IS_OK(err)) { 732 goto trans_done; 733 } 694 734 695 735 if (regsubkey_ctr_numkeys(key->subkeys) > 0) { … … 697 737 goto trans_done; 698 738 } 699 700 /* no subkeys - proceed with delete */ 701 end = strrchr(name, '\\'); 702 if (end != NULL) { 703 *end = '\0'; 704 705 err = reg_openkey(mem_ctx, parent, name, 706 KEY_CREATE_SUB_KEY, &tmp_key); 707 W_ERROR_NOT_OK_GOTO(err, trans_done); 708 709 parent = tmp_key; 710 name = end+1; 711 } 712 713 if (name[0] == '\0') { 714 err = WERR_INVALID_PARAM; 715 goto trans_done; 716 } 717 718 err = delete_reg_subkey(parent->key, name); 739 err = reg_deletekey_internal(mem_ctx, parent, path, false); 719 740 720 741 trans_done: … … 735 756 return err; 736 757 } 758 737 759 738 760 WERROR reg_setvalue(struct registry_key *key, const char *name, … … 932 954 static WERROR reg_deletekey_recursive_internal(struct registry_key *parent, 933 955 const char *path, 934 bool del_key )956 bool del_key, bool lazy) 935 957 { 936 958 WERROR werr = WERR_OK; 937 959 struct registry_key *key; 938 960 char *subkey_name = NULL; 939 uint32 i;961 uint32_t i; 940 962 TALLOC_CTX *mem_ctx = talloc_stackframe(); 963 964 DEBUG(5, ("reg_deletekey_recursive_internal: deleting '%s' from '%s'\n", 965 path, parent->key->name)); 941 966 942 967 /* recurse through subkeys first */ 943 968 werr = reg_openkey(mem_ctx, parent, path, REG_KEY_ALL, &key); 944 969 if (!W_ERROR_IS_OK(werr)) { 970 DEBUG(3, ("reg_deletekey_recursive_internal: error opening " 971 "subkey '%s' of '%s': '%s'\n", 972 path, parent->key->name, win_errstr(werr))); 945 973 goto done; 946 974 } … … 955 983 for (i = regsubkey_ctr_numkeys(key->subkeys) ; i > 0; i--) { 956 984 subkey_name = regsubkey_ctr_specific_key(key->subkeys, i-1); 957 werr = reg_deletekey_recursive_internal(key, subkey_name, true );985 werr = reg_deletekey_recursive_internal(key, subkey_name, true, del_key); 958 986 W_ERROR_NOT_OK_GOTO_DONE(werr); 959 987 } … … 961 989 if (del_key) { 962 990 /* now delete the actual key */ 963 werr = reg_deletekey (parent, path);991 werr = reg_deletekey_internal(mem_ctx, parent, path, lazy); 964 992 } 965 993 966 994 done: 995 996 DEBUG(5, ("reg_deletekey_recursive_internal: done deleting '%s' from " 997 "'%s': %s\n", 998 path, parent->key->name, win_errstr(werr))); 967 999 TALLOC_FREE(mem_ctx); 968 1000 return werr; … … 983 1015 } 984 1016 985 werr = reg_deletekey_recursive_internal(parent, path, del_key );1017 werr = reg_deletekey_recursive_internal(parent, path, del_key, false); 986 1018 987 1019 if (!W_ERROR_IS_OK(werr)) { 988 1020 WERROR werr2; 989 990 DEBUG(1, (__location__ "failed to delete key '%s' from key "991 992 1021 DEBUG(W_ERROR_EQUAL(werr, WERR_BADFILE) ? 5 : 1, 1022 (__location__ ": failed to delete key '%s' from key " 1023 "'%s': %s\n", path, parent->key->name, 1024 win_errstr(werr))); 993 1025 994 1026 werr2 = regdb_transaction_cancel(); … … 1008 1040 "error committing transaction: %s\n", 1009 1041 win_errstr(werr))); 1042 } else { 1043 DEBUG(5, ("reg_deletekey_recursive_trans: deleted key '%s' from '%s'\n", 1044 path, parent->key->name)); 1045 1010 1046 } 1011 1047 } -
vendor/current/source3/registry/reg_api.h
r740 r988 25 25 26 26 WERROR reg_openhive(TALLOC_CTX *mem_ctx, const char *hive, 27 uint32 desired_access,27 uint32_t desired_access, 28 28 const struct security_token *token, 29 29 struct registry_key **pkey); 30 30 WERROR reg_openkey(TALLOC_CTX *mem_ctx, struct registry_key *parent, 31 const char *name, uint32 desired_access,31 const char *name, uint32_t desired_access, 32 32 struct registry_key **pkey); 33 33 WERROR reg_enumkey(TALLOC_CTX *mem_ctx, struct registry_key *key, 34 uint32 idx, char **name, NTTIME *last_write_time);34 uint32_t idx, char **name, NTTIME *last_write_time); 35 35 WERROR reg_enumvalue(TALLOC_CTX *mem_ctx, struct registry_key *key, 36 uint32 idx, char **pname, struct registry_value **pval);36 uint32_t idx, char **pname, struct registry_value **pval); 37 37 WERROR reg_queryvalue(TALLOC_CTX *mem_ctx, struct registry_key *key, 38 38 const char *name, struct registry_value **pval); … … 49 49 NTTIME *last_changed_time); 50 50 WERROR reg_createkey(TALLOC_CTX *ctx, struct registry_key *parent, 51 const char *subkeypath, uint32 desired_access,51 const char *subkeypath, uint32_t desired_access, 52 52 struct registry_key **pkey, 53 53 enum winreg_CreateAction *paction); -
vendor/current/source3/registry/reg_api_util.c
r740 r988 27 27 #include "reg_api.h" 28 28 #include "reg_api_util.h" 29 #include "libcli/registry/util_reg.h" 29 30 30 31 /** … … 32 33 */ 33 34 WERROR reg_open_path(TALLOC_CTX *mem_ctx, const char *orig_path, 34 uint32 desired_access, const struct security_token *token,35 uint32_t desired_access, const struct security_token *token, 35 36 struct registry_key **pkey) 36 37 { … … 83 84 } 84 85 85 #if 086 /* these two functions are unused. */87 88 86 /** 89 87 * Utility function to create a registry key without opening the hive … … 92 90 93 91 WERROR reg_create_path(TALLOC_CTX *mem_ctx, const char *orig_path, 94 uint32 desired_access,92 uint32_t desired_access, 95 93 const struct security_token *token, 96 94 enum winreg_CreateAction *paction, … … 142 140 143 141 /* 144 * Utility function to create a registry key without opening the hive145 * before. Will not delete a hive.142 * Utility function to recursively delete a registry key without opening the 143 * hive before. Will not delete a hive. 146 144 */ 147 145 … … 175 173 } 176 174 177 err = reg_deletekey (hive, p+1);175 err = reg_deletekey_recursive(hive, p+1); 178 176 SAFE_FREE(path); 179 177 TALLOC_FREE(hive); 180 178 return err; 181 179 } 182 #endif /* #if 0 */ 180 181 struct registry_value *registry_value_dw(TALLOC_CTX *mem_ctx, uint32_t dw) 182 { 183 struct registry_value *ret; 184 185 ret = talloc_zero(mem_ctx, struct registry_value); 186 if (ret == NULL) { 187 return NULL; 188 } 189 190 ret->data = data_blob_talloc(ret, NULL, sizeof(uint32_t)); 191 if (ret->data.data == NULL) { 192 talloc_free(ret); 193 return NULL; 194 } 195 196 ret->type = REG_DWORD; 197 198 SIVAL(ret->data.data, 0, dw); 199 200 return ret; 201 } 202 203 struct registry_value *registry_value_sz(TALLOC_CTX *mem_ctx, const char *str) 204 { 205 struct registry_value *ret; 206 207 ret = talloc_zero(mem_ctx, struct registry_value); 208 if (ret == NULL) { 209 return NULL; 210 } 211 212 if (!push_reg_sz(ret, &ret->data, str)) { 213 talloc_free(ret); 214 return NULL; 215 } 216 217 ret->type = REG_SZ; 218 219 return ret; 220 } 221 222 struct registry_value *registry_value_multi_sz(TALLOC_CTX *mem_ctx, const char **str) 223 { 224 struct registry_value *ret; 225 226 ret = talloc_zero(mem_ctx, struct registry_value); 227 if (ret == NULL) { 228 return NULL; 229 } 230 231 if (!push_reg_multi_sz(ret, &ret->data, str)) { 232 talloc_free(ret); 233 return NULL; 234 } 235 236 ret->type = REG_MULTI_SZ; 237 238 return ret; 239 } 240 241 int registry_value_cmp(const struct registry_value* v1, const struct registry_value* v2) 242 { 243 if (v1->type == v2->type) { 244 return data_blob_cmp(&v1->data, &v2->data); 245 } 246 return v1->type - v2->type; 247 } -
vendor/current/source3/registry/reg_api_util.h
r740 r988 30 30 */ 31 31 WERROR reg_open_path(TALLOC_CTX *mem_ctx, const char *orig_path, 32 uint32 desired_access, const struct security_token *token,32 uint32_t desired_access, const struct security_token *token, 33 33 struct registry_key **pkey); 34 34 35 #if 036 /* currently unused */37 35 WERROR reg_create_path(TALLOC_CTX *mem_ctx, const char *orig_path, 38 uint32 desired_access,36 uint32_t desired_access, 39 37 const struct security_token *token, 40 38 enum winreg_CreateAction *paction, … … 42 40 WERROR reg_delete_path(const struct security_token *token, 43 41 const char *orig_path); 44 #endif 42 43 struct registry_value *registry_value_dw(TALLOC_CTX *mem_ctx, uint32_t dw); 44 struct registry_value *registry_value_sz(TALLOC_CTX *mem_ctx, const char *str); 45 struct registry_value *registry_value_multi_sz(TALLOC_CTX *mem_ctx, const char **str); 46 47 int registry_value_cmp(const struct registry_value *v1, const struct registry_value *v2); 45 48 46 49 #endif /* _REG_API_UTIL_H */ -
vendor/current/source3/registry/reg_backend_current_version.c
r740 r988 59 59 regval_ctr_addvalue_sz(values, "SystemRoot", sysroot_string); 60 60 61 fstr_sprintf(sysversion, "%d.%d", lp_major_announce_version(),62 lp_minor_announce_version());61 fstr_sprintf(sysversion, "%d.%d", SAMBA_MAJOR_NBT_ANNOUNCE_VERSION, 62 SAMBA_MINOR_NBT_ANNOUNCE_VERSION); 63 63 64 64 regval_ctr_addvalue_sz(values, "CurrentVersion", sysversion); -
vendor/current/source3/registry/reg_backend_db.c
r746 r988 3 3 * Virtual Windows Registry Layer 4 4 * Copyright (C) Gerald Carter 2002-2005 5 * Copyright (C) Michael Adam 2007-2009 5 * Copyright (C) Michael Adam 2007-2011 6 * Copyright (C) Gregor Beck 2011 6 7 * 7 8 * This program is free software; you can redistribute it and/or modify … … 26 27 #include "reg_db.h" 27 28 #include "reg_util_internal.h" 29 #include "reg_parse_internal.h" 28 30 #include "reg_backend_db.h" 29 31 #include "reg_objects.h" 30 32 #include "nt_printing.h" 31 33 #include "util_tdb.h" 32 #include "dbwrap.h" 34 #include "dbwrap/dbwrap.h" 35 #include "dbwrap/dbwrap_open.h" 36 #include "../libcli/security/secdesc.h" 33 37 34 38 #undef DBGC_CLASS 35 39 #define DBGC_CLASS DBGC_REGISTRY 36 40 41 #define REGDB_VERSION_KEYNAME "INFO/version" 42 37 43 static struct db_context *regdb = NULL; 38 44 static int regdb_refcount; 39 45 40 46 static bool regdb_key_exists(struct db_context *db, const char *key); 41 static bool regdb_key_is_base_key(const char *key);42 47 static WERROR regdb_fetch_keys_internal(struct db_context *db, const char *key, 43 48 struct regsubkey_ctr *ctr); … … 46 51 static int regdb_fetch_values_internal(struct db_context *db, const char* key, 47 52 struct regval_ctr *values); 48 static bool regdb_store_values_internal(struct db_context *db, const char *key, 49 struct regval_ctr *values); 50 51 static NTSTATUS create_sorted_subkeys(const char *key); 53 static NTSTATUS regdb_store_values_internal(struct db_context *db, const char *key, 54 struct regval_ctr *values); 55 static WERROR regdb_store_subkey_list(struct db_context *db, const char *parent, 56 const char *key); 57 58 static WERROR regdb_create_basekey(struct db_context *db, const char *key); 59 static WERROR regdb_create_subkey_internal(struct db_context *db, 60 const char *key, 61 const char *subkey); 62 63 64 struct regdb_trans_ctx { 65 NTSTATUS (*action)(struct db_context *, void *); 66 void *private_data; 67 }; 68 69 static NTSTATUS regdb_trans_do_action(struct db_context *db, void *private_data) 70 { 71 NTSTATUS status; 72 int32_t version_id; 73 struct regdb_trans_ctx *ctx = (struct regdb_trans_ctx *)private_data; 74 75 status = dbwrap_fetch_int32_bystring(db, REGDB_VERSION_KEYNAME, 76 &version_id); 77 78 if (!NT_STATUS_IS_OK(status)) { 79 DEBUG(0, ("ERROR: could not fetch registry db version: %s. " 80 "Denying access.\n", nt_errstr(status))); 81 return NT_STATUS_ACCESS_DENIED; 82 } 83 84 if (version_id != REGDB_CODE_VERSION) { 85 DEBUG(0, ("ERROR: changed registry version %d found while " 86 "trying to write to the registry. Version %d " 87 "expected. Denying access.\n", 88 version_id, REGDB_CODE_VERSION)); 89 return NT_STATUS_ACCESS_DENIED; 90 } 91 92 status = ctx->action(db, ctx->private_data); 93 return status; 94 } 95 96 static WERROR regdb_trans_do(struct db_context *db, 97 NTSTATUS (*action)(struct db_context *, void *), 98 void *private_data) 99 { 100 NTSTATUS status; 101 struct regdb_trans_ctx ctx; 102 103 104 ctx.action = action; 105 ctx.private_data = private_data; 106 107 status = dbwrap_trans_do(db, regdb_trans_do_action, &ctx); 108 109 return ntstatus_to_werror(status); 110 } 52 111 53 112 /* List the deepest path into the registry. All part components will be created.*/ … … 95 154 const char *path; 96 155 const char *valuename; 97 uint32 type;156 uint32_t type; 98 157 union { 99 158 const char *string; 100 uint32 dw_value;159 uint32_t dw_value; 101 160 } data; 102 161 }; … … 114 173 }; 115 174 175 static WERROR create_key_recursive(struct db_context *db, 176 char *path, 177 const char *subkey) 178 { 179 WERROR werr; 180 char *p; 181 182 if (subkey == NULL) { 183 return WERR_INVALID_PARAM; 184 } 185 186 if (path == NULL) { 187 return regdb_create_basekey(db, subkey); 188 } 189 190 p = strrchr_m(path, '\\'); 191 192 if (p == NULL) { 193 werr = create_key_recursive(db, NULL, path); 194 } else { 195 *p = '\0'; 196 werr = create_key_recursive(db, path, p+1); 197 *p = '\\'; 198 } 199 200 if (!W_ERROR_IS_OK(werr)) { 201 goto done; 202 } 203 204 werr = regdb_create_subkey_internal(db, path, subkey); 205 206 done: 207 return werr; 208 } 209 116 210 /** 117 211 * Initialize a key in the registry: … … 121 215 const char *add_path) 122 216 { 217 char *subkey, *key; 123 218 WERROR werr; 124 219 TALLOC_CTX *frame = talloc_stackframe(); 125 char *path = NULL; 126 char *base = NULL; 127 char *remaining = NULL; 128 char *keyname; 129 char *subkeyname; 130 struct regsubkey_ctr *subkeys; 131 const char *p, *p2; 132 133 DEBUG(6, ("init_registry_key: Adding [%s]\n", add_path)); 134 135 path = talloc_strdup(frame, add_path); 136 base = talloc_strdup(frame, ""); 137 if (!path || !base) { 138 werr = WERR_NOMEM; 139 goto fail; 140 } 141 p = path; 142 143 while (next_token_talloc(frame, &p, &keyname, "\\")) { 144 145 /* build up the registry path from the components */ 146 147 if (*base) { 148 base = talloc_asprintf(frame, "%s\\", base); 149 if (!base) { 150 werr = WERR_NOMEM; 151 goto fail; 152 } 153 } 154 base = talloc_asprintf_append(base, "%s", keyname); 155 if (!base) { 156 werr = WERR_NOMEM; 157 goto fail; 158 } 159 160 /* get the immediate subkeyname (if we have one ) */ 161 162 subkeyname = talloc_strdup(frame, ""); 163 if (!subkeyname) { 164 werr = WERR_NOMEM; 165 goto fail; 166 } 167 if (*p) { 168 remaining = talloc_strdup(frame, p); 169 if (!remaining) { 170 werr = WERR_NOMEM; 171 goto fail; 172 } 173 p2 = remaining; 174 175 if (!next_token_talloc(frame, &p2, 176 &subkeyname, "\\")) 177 { 178 subkeyname = talloc_strdup(frame,p2); 179 if (!subkeyname) { 180 werr = WERR_NOMEM; 181 goto fail; 182 } 183 } 184 } 185 186 DEBUG(10,("init_registry_key: Storing key [%s] with " 187 "subkey [%s]\n", base, 188 *subkeyname ? subkeyname : "NULL")); 189 190 /* we don't really care if the lookup succeeds or not 191 * since we are about to update the record. 192 * We just want any subkeys already present */ 193 194 werr = regsubkey_ctr_init(frame, &subkeys); 195 if (!W_ERROR_IS_OK(werr)) { 196 DEBUG(0,("talloc() failure!\n")); 197 goto fail; 198 } 199 200 werr = regdb_fetch_keys_internal(db, base, subkeys); 201 if (!W_ERROR_IS_OK(werr) && 202 !W_ERROR_EQUAL(werr, WERR_NOT_FOUND)) 203 { 204 goto fail; 205 } 206 207 if (*subkeyname) { 208 werr = regsubkey_ctr_addkey(subkeys, subkeyname); 209 if (!W_ERROR_IS_OK(werr)) { 210 goto fail; 211 } 212 } 213 if (!regdb_store_keys_internal(db, base, subkeys)) { 214 werr = WERR_CAN_NOT_COMPLETE; 215 goto fail; 216 } 217 } 218 219 werr = WERR_OK; 220 221 fail: 222 TALLOC_FREE(frame); 220 221 if (add_path == NULL) { 222 werr = WERR_INVALID_PARAM; 223 goto done; 224 } 225 226 key = talloc_strdup(frame, add_path); 227 228 subkey = strrchr_m(key, '\\'); 229 if (subkey == NULL) { 230 subkey = key; 231 key = NULL; 232 } else { 233 *subkey = '\0'; 234 subkey++; 235 } 236 237 werr = create_key_recursive(db, key, subkey); 238 239 done: 240 talloc_free(frame); 223 241 return werr; 224 242 } … … 253 271 init_ctx.add_path = add_path; 254 272 255 return ntstatus_to_werror(dbwrap_trans_do(regdb,256 257 &init_ctx));273 return regdb_trans_do(regdb, 274 init_registry_key_action, 275 &init_ctx); 258 276 } 259 277 … … 269 287 regval_ctr_addvalue(ctr, value->valuename, REG_DWORD, 270 288 (uint8_t *)&value->data.dw_value, 271 sizeof(uint32 ));289 sizeof(uint32_t)); 272 290 break; 273 291 … … 326 344 regdb_ctr_add_value(values, 327 345 &builtin_registry_values[i]); 328 regdb_store_values_internal(db,346 status = regdb_store_values_internal(db, 329 347 builtin_registry_values[i].path, 330 348 values); 349 if (!NT_STATUS_IS_OK(status)) { 350 goto done; 351 } 331 352 } 332 353 TALLOC_FREE(values); … … 388 409 */ 389 410 390 werr = ntstatus_to_werror(dbwrap_trans_do(regdb,391 392 NULL));411 werr = regdb_trans_do(regdb, 412 init_registry_data_action, 413 NULL); 393 414 394 415 done: … … 403 424 const char *keyname; 404 425 NTSTATUS status; 405 406 if (rec->key.dptr == NULL || rec->key.dsize == 0) { 426 TDB_DATA key; 427 TDB_DATA value; 428 struct db_context *db = (struct db_context *)private_data; 429 430 key = dbwrap_record_get_key(rec); 431 if (key.dptr == NULL || key.dsize == 0) { 407 432 return 0; 408 433 } 409 434 410 keyname = strchr((const char *) rec->key.dptr, '/'); 435 value = dbwrap_record_get_value(rec); 436 437 if (db == NULL) { 438 DEBUG(0, ("regdb_normalize_keynames_fn: ERROR: " 439 "NULL db context handed in via private_data\n")); 440 return 1; 441 } 442 443 if (strncmp((const char *)key.dptr, REGDB_VERSION_KEYNAME, 444 strlen(REGDB_VERSION_KEYNAME)) == 0) 445 { 446 return 0; 447 } 448 449 keyname = strchr((const char *)key.dptr, '/'); 411 450 if (keyname) { 412 struct db_record new_rec;413 414 451 keyname = talloc_string_sub(mem_ctx, 415 (const char *) rec->key.dptr,452 (const char *)key.dptr, 416 453 "/", 417 454 "\\"); 418 455 419 456 DEBUG(2, ("regdb_normalize_keynames_fn: Convert %s to %s\n", 420 (const char *) rec->key.dptr,457 (const char *)key.dptr, 421 458 keyname)); 422 459 423 new_rec.value = rec->value;424 new_rec.key = string_term_tdb_data(keyname);425 new_rec.private_data = rec->private_data;426 427 460 /* Delete the original record and store the normalized key */ 428 status = rec->delete_rec(rec);461 status = dbwrap_record_delete(rec); 429 462 if (!NT_STATUS_IS_OK(status)) { 430 463 DEBUG(0,("regdb_normalize_keynames_fn: " 431 464 "tdb_delete for [%s] failed!\n", 432 rec->key.dptr));465 (const char *)key.dptr)); 433 466 return 1; 434 467 } 435 468 436 status = rec->store(&new_rec, new_rec.value, TDB_REPLACE);469 status = dbwrap_store_bystring(db, keyname, value, TDB_REPLACE); 437 470 if (!NT_STATUS_IS_OK(status)) { 438 471 DEBUG(0,("regdb_normalize_keynames_fn: " … … 446 479 } 447 480 448 static WERROR regdb_store_regdb_version( uint32_t version)481 static WERROR regdb_store_regdb_version(struct db_context *db, uint32_t version) 449 482 { 450 483 NTSTATUS status; 451 const char *version_keyname = "INFO/version"; 452 453 if (!regdb) { 484 if (db == NULL) { 454 485 return WERR_CAN_NOT_COMPLETE; 455 486 } 456 487 457 status = dbwrap_trans_store_int32(regdb, version_keyname, version); 488 status = dbwrap_trans_store_int32_bystring(db, REGDB_VERSION_KEYNAME, 489 version); 458 490 if (!NT_STATUS_IS_OK(status)) { 459 491 DEBUG(1, ("regdb_store_regdb_version: error storing %s = %d: %s\n", 460 version_keyname, version, nt_errstr(status)));492 REGDB_VERSION_KEYNAME, version, nt_errstr(status))); 461 493 return ntstatus_to_werror(status); 462 494 } else { 463 495 DEBUG(10, ("regdb_store_regdb_version: stored %s = %d\n", 464 version_keyname, version));496 REGDB_VERSION_KEYNAME, version)); 465 497 return WERR_OK; 466 498 } 467 499 } 468 500 469 static WERROR regdb_upgrade_v1_to_v2( void)501 static WERROR regdb_upgrade_v1_to_v2(struct db_context *db) 470 502 { 471 503 TALLOC_CTX *mem_ctx; 472 int rc;504 NTSTATUS status; 473 505 WERROR werr; 474 506 475 507 mem_ctx = talloc_stackframe(); 476 if (mem_ctx == NULL) { 477 return WERR_NOMEM; 478 } 479 480 rc = regdb->traverse(regdb, regdb_normalize_keynames_fn, mem_ctx); 481 482 talloc_destroy(mem_ctx); 483 484 if (rc == -1) { 485 return WERR_REG_IO_FAILURE; 486 } 487 488 werr = regdb_store_regdb_version(REGVER_V2); 508 509 status = dbwrap_traverse(db, regdb_normalize_keynames_fn, db, NULL); 510 if (!NT_STATUS_IS_OK(status)) { 511 werr = WERR_REG_IO_FAILURE; 512 goto done; 513 } 514 515 werr = regdb_store_regdb_version(db, REGDB_VERSION_V2); 516 517 done: 518 talloc_free(mem_ctx); 519 return werr; 520 } 521 522 static bool tdb_data_read_uint32(TDB_DATA *buf, uint32_t *result) 523 { 524 const size_t len = sizeof(uint32_t); 525 if (buf->dsize >= len) { 526 *result = IVAL(buf->dptr, 0); 527 buf->dptr += len; 528 buf->dsize -= len; 529 return true; 530 } 531 return false; 532 } 533 534 static bool tdb_data_read_cstr(TDB_DATA *buf, char **result) 535 { 536 const size_t len = strnlen((char*)buf->dptr, buf->dsize) + 1; 537 if (buf->dsize >= len) { 538 *result = (char*)buf->dptr; 539 buf->dptr += len; 540 buf->dsize -= len; 541 return true; 542 } 543 return false; 544 } 545 546 static bool tdb_data_is_cstr(TDB_DATA d) { 547 if (tdb_data_is_empty(d) || (d.dptr[d.dsize-1] != '\0')) { 548 return false; 549 } 550 return strlen((char *)d.dptr) == (d.dsize-1); 551 } 552 553 static bool upgrade_v2_to_v3_check_subkeylist(struct db_context *db, 554 const char *key, 555 const char *subkey) 556 { 557 static uint32_t zero = 0; 558 static TDB_DATA empty_subkey_list = { 559 .dptr = (unsigned char*)&zero, 560 .dsize = sizeof(uint32_t), 561 }; 562 bool success = false; 563 char *path = talloc_asprintf(talloc_tos(), "%s\\%s", key, subkey); 564 if (!strupper_m(path)) { 565 goto done; 566 } 567 568 if (!dbwrap_exists(db, string_term_tdb_data(path))) { 569 NTSTATUS status; 570 571 DEBUG(10, ("regdb_upgrade_v2_to_v3: writing subkey list [%s]\n", 572 path)); 573 574 status = dbwrap_store_bystring(db, path, empty_subkey_list, 575 TDB_INSERT); 576 if (!NT_STATUS_IS_OK(status)) { 577 DEBUG(0, ("regdb_upgrade_v2_to_v3: writing subkey list " 578 "[%s] failed\n", path)); 579 goto done; 580 } 581 } 582 success = true; 583 done: 584 talloc_free(path); 585 return success; 586 } 587 588 static bool upgrade_v2_to_v3_check_parent(struct db_context *db, 589 const char *key) 590 { 591 const char *sep = strrchr_m(key, '\\'); 592 if (sep != NULL) { 593 char *pkey = talloc_strndup(talloc_tos(), key, sep-key); 594 if (!dbwrap_exists(db, string_term_tdb_data(pkey))) { 595 DEBUG(0, ("regdb_upgrade_v2_to_v3: missing subkey list " 596 "[%s]\nrun \"net registry check\"\n", pkey)); 597 } 598 talloc_free(pkey); 599 } 600 return true; 601 } 602 603 604 #define IS_EQUAL(d,s) (((d).dsize == strlen(s)+1) && \ 605 (strcmp((char*)(d).dptr, (s)) == 0)) 606 #define STARTS_WITH(d,s) (((d).dsize > strlen(s)) && \ 607 (strncmp((char*)(d).dptr, (s), strlen(s)) == 0)) 608 #define SSTR(d) (int)(d).dsize , (char*)(d).dptr 609 610 611 static int regdb_upgrade_v2_to_v3_fn(struct db_record *rec, void *private_data) 612 { 613 struct db_context *db = (struct db_context *)private_data; 614 TDB_DATA key = dbwrap_record_get_key(rec); 615 TDB_DATA val = dbwrap_record_get_value(rec); 616 617 if (tdb_data_is_empty(key)) { 618 return 0; 619 } 620 621 if (db == NULL) { 622 DEBUG(0, ("regdb_upgrade_v2_to_v3_fn: ERROR: " 623 "NULL db context handed in via private_data\n")); 624 return 1; 625 } 626 627 if (IS_EQUAL(key, REGDB_VERSION_KEYNAME) || 628 STARTS_WITH(key, REG_VALUE_PREFIX) || 629 STARTS_WITH(key, REG_SECDESC_PREFIX)) 630 { 631 DEBUG(10, ("regdb_upgrade_v2_to_v3: skipping [%.*s]\n", 632 SSTR(key))); 633 return 0; 634 } 635 636 if (STARTS_WITH(key, REG_SORTED_SUBKEYS_PREFIX)) { 637 NTSTATUS status; 638 /* Delete the deprecated sorted subkeys cache. */ 639 640 DEBUG(10, ("regdb_upgrade_v2_to_v3: deleting [%.*s]\n", 641 SSTR(key))); 642 643 status = dbwrap_record_delete(rec); 644 if (!NT_STATUS_IS_OK(status)) { 645 DEBUG(0, ("regdb_upgrade_v2_to_v3: deleting [%.*s] " 646 "failed!\n", SSTR(key))); 647 return 1; 648 } 649 650 return 0; 651 } 652 653 if ( tdb_data_is_cstr(key) && 654 hive_info((char*)key.dptr) != NULL ) 655 { 656 /* 657 * Found a regular subkey list record. 658 * Walk the list and create the list record for those 659 * subkeys that don't already have one. 660 */ 661 TDB_DATA pos = val; 662 char *subkey, *path = (char*)key.dptr; 663 uint32_t num_items, found_items = 0; 664 665 666 DEBUG(10, ("regdb_upgrade_v2_to_v3: scanning subkeylist of " 667 "[%s]\n", path)); 668 669 if (!tdb_data_read_uint32(&pos, &num_items)) { 670 /* invalid or empty - skip */ 671 return 0; 672 } 673 674 while (tdb_data_read_cstr(&pos, &subkey)) { 675 found_items++; 676 677 if (!upgrade_v2_to_v3_check_subkeylist(db, path, subkey)) 678 { 679 return 1; 680 } 681 682 if (!upgrade_v2_to_v3_check_parent(db, path)) { 683 return 1; 684 } 685 } 686 if (found_items != num_items) { 687 DEBUG(0, ("regdb_upgrade_v2_to_v3: inconsistent subkey " 688 "list [%s]\nrun \"net registry check\"\n", 689 path)); 690 } 691 } else { 692 DEBUG(10, ("regdb_upgrade_v2_to_v3: skipping invalid [%.*s]\n" 693 "run \"net registry check\"\n", SSTR(key))); 694 } 695 696 return 0; 697 } 698 699 static WERROR regdb_upgrade_v2_to_v3(struct db_context *db) 700 { 701 NTSTATUS status; 702 WERROR werr; 703 704 status = dbwrap_traverse(db, regdb_upgrade_v2_to_v3_fn, db, NULL); 705 if (!NT_STATUS_IS_OK(status)) { 706 werr = WERR_REG_IO_FAILURE; 707 goto done; 708 } 709 710 werr = regdb_store_regdb_version(db, REGDB_VERSION_V3); 711 712 done: 489 713 return werr; 490 714 } … … 496 720 WERROR regdb_init(void) 497 721 { 498 const char *vstring = "INFO/version"; 499 uint32 vers_id, expected_version; 722 int32_t vers_id; 500 723 WERROR werr; 724 NTSTATUS status; 725 char *db_path; 501 726 502 727 if (regdb) { … … 507 732 } 508 733 509 regdb = db_open(NULL, state_path("registry.tdb"), 0, 510 REG_TDB_FLAGS, O_RDWR, 0600); 734 db_path = state_path("registry.tdb"); 735 if (db_path == NULL) { 736 return WERR_NOMEM; 737 } 738 739 regdb = db_open(NULL, db_path, 0, 740 REG_TDB_FLAGS, O_RDWR, 0600, 741 DBWRAP_LOCK_ORDER_1, REG_DBWRAP_FLAGS); 511 742 if (!regdb) { 512 regdb = db_open(NULL, state_path("registry.tdb"), 0, 513 REG_TDB_FLAGS, O_RDWR|O_CREAT, 0600); 743 regdb = db_open(NULL, db_path, 0, 744 REG_TDB_FLAGS, O_RDWR|O_CREAT, 0600, 745 DBWRAP_LOCK_ORDER_1, REG_DBWRAP_FLAGS); 514 746 if (!regdb) { 515 747 werr = ntstatus_to_werror(map_nt_error_from_unix(errno)); 516 748 DEBUG(1,("regdb_init: Failed to open registry %s (%s)\n", 517 state_path("registry.tdb"), strerror(errno) )); 749 db_path, strerror(errno) )); 750 TALLOC_FREE(db_path); 518 751 return werr; 519 752 } 520 753 754 werr = regdb_store_regdb_version(regdb, REGDB_CODE_VERSION); 755 if (!W_ERROR_IS_OK(werr)) { 756 DEBUG(1, ("regdb_init: Failed to store version: %s\n", 757 win_errstr(werr))); 758 TALLOC_FREE(db_path); 759 return werr; 760 } 761 521 762 DEBUG(10,("regdb_init: Successfully created registry tdb\n")); 522 763 } 764 TALLOC_FREE(db_path); 523 765 524 766 regdb_refcount = 1; … … 526 768 regdb_refcount)); 527 769 528 expected_version = REGVER_V2; 529 530 vers_id = dbwrap_fetch_int32(regdb, vstring); 531 if (vers_id == -1) { 770 status = dbwrap_fetch_int32_bystring(regdb, REGDB_VERSION_KEYNAME, 771 &vers_id); 772 if (!NT_STATUS_IS_OK(status)) { 532 773 DEBUG(10, ("regdb_init: registry version uninitialized " 533 774 "(got %d), initializing to version %d\n", 534 vers_id, expected_version)); 535 536 werr = regdb_store_regdb_version(expected_version); 537 return werr; 538 } 539 540 if (vers_id > expected_version || vers_id == 0) { 541 DEBUG(1, ("regdb_init: unknown registry version %d " 775 vers_id, REGDB_VERSION_V1)); 776 777 /* 778 * There was a regdb format version prior to version 1 779 * which did not store a INFO/version key. The format 780 * of this version was identical to version 1 except for 781 * the lack of the sorted subkey cache records. 782 * Since these are disposable, we can safely assume version 783 * 1 if no INFO/version key is found and run the db through 784 * the whole chain of upgrade. If the database was not 785 * initialized, this does not harm. If it was the unversioned 786 * version ("0"), then it do the right thing with the records. 787 */ 788 werr = regdb_store_regdb_version(regdb, REGDB_VERSION_V1); 789 if (!W_ERROR_IS_OK(werr)) { 790 return werr; 791 } 792 vers_id = REGDB_VERSION_V1; 793 } 794 795 if (vers_id == REGDB_CODE_VERSION) { 796 return WERR_OK; 797 } 798 799 if (vers_id > REGDB_CODE_VERSION || vers_id == 0) { 800 DEBUG(0, ("regdb_init: unknown registry version %d " 542 801 "(code version = %d), refusing initialization\n", 543 vers_id, expected_version));802 vers_id, REGDB_CODE_VERSION)); 544 803 return WERR_CAN_NOT_COMPLETE; 545 804 } 546 805 547 if ( vers_id == REGVER_V1) {548 DEBUG(10, ("regdb_init: got registry db version %d, upgrading "549 "to version %d\n", REGVER_V1, REGVER_V2));550 551 if (regdb->transaction_start(regdb) != 0) {552 return WERR_REG_IO_FAILURE;553 }554 555 werr = regdb_upgrade_v1_to_v2( );806 if (dbwrap_transaction_start(regdb) != 0) { 807 return WERR_REG_IO_FAILURE; 808 } 809 810 if (vers_id == REGDB_VERSION_V1) { 811 DEBUG(10, ("regdb_init: upgrading registry from version %d " 812 "to %d\n", REGDB_VERSION_V1, REGDB_VERSION_V2)); 813 814 werr = regdb_upgrade_v1_to_v2(regdb); 556 815 if (!W_ERROR_IS_OK(werr)) { 557 regdb->transaction_cancel(regdb);816 dbwrap_transaction_cancel(regdb); 558 817 return werr; 559 818 } 560 819 561 if (regdb->transaction_commit(regdb) != 0) { 562 return WERR_REG_IO_FAILURE; 563 } 564 565 vers_id = REGVER_V2; 820 vers_id = REGDB_VERSION_V2; 821 } 822 823 if (vers_id == REGDB_VERSION_V2) { 824 DEBUG(10, ("regdb_init: upgrading registry from version %d " 825 "to %d\n", REGDB_VERSION_V2, REGDB_VERSION_V3)); 826 827 werr = regdb_upgrade_v2_to_v3(regdb); 828 if (!W_ERROR_IS_OK(werr)) { 829 dbwrap_transaction_cancel(regdb); 830 return werr; 831 } 832 833 vers_id = REGDB_VERSION_V3; 566 834 } 567 835 568 836 /* future upgrade code should go here */ 837 838 if (dbwrap_transaction_commit(regdb) != 0) { 839 return WERR_REG_IO_FAILURE; 840 } 569 841 570 842 return WERR_OK; … … 578 850 { 579 851 WERROR result = WERR_OK; 852 char *db_path; 853 int saved_errno; 580 854 581 855 if ( regdb ) { … … 586 860 } 587 861 862 db_path = state_path("registry.tdb"); 863 if (db_path == NULL) { 864 return WERR_NOMEM; 865 } 866 588 867 become_root(); 589 868 590 regdb = db_open(NULL, state_path("registry.tdb"), 0, 591 REG_TDB_FLAGS, O_RDWR, 0600); 869 regdb = db_open(NULL, db_path, 0, 870 REG_TDB_FLAGS, O_RDWR, 0600, 871 DBWRAP_LOCK_ORDER_1, REG_DBWRAP_FLAGS); 872 saved_errno = errno; 873 unbecome_root(); 592 874 if ( !regdb ) { 593 result = ntstatus_to_werror( map_nt_error_from_unix( errno ));875 result = ntstatus_to_werror(map_nt_error_from_unix(saved_errno)); 594 876 DEBUG(0,("regdb_open: Failed to open %s! (%s)\n", 595 state_path("registry.tdb"), strerror(errno) )); 596 } 597 598 unbecome_root(); 877 db_path, strerror(saved_errno))); 878 TALLOC_FREE(db_path); 879 return result; 880 } 881 TALLOC_FREE(db_path); 599 882 600 883 regdb_refcount = 1; … … 602 885 regdb_refcount)); 603 886 604 return result;887 return WERR_OK; 605 888 } 606 889 … … 630 913 WERROR regdb_transaction_start(void) 631 914 { 632 return ( regdb->transaction_start(regdb) == 0) ?915 return (dbwrap_transaction_start(regdb) == 0) ? 633 916 WERR_OK : WERR_REG_IO_FAILURE; 634 917 } … … 636 919 WERROR regdb_transaction_commit(void) 637 920 { 638 return ( regdb->transaction_commit(regdb) == 0) ?921 return (dbwrap_transaction_commit(regdb) == 0) ? 639 922 WERR_OK : WERR_REG_IO_FAILURE; 640 923 } … … 642 925 WERROR regdb_transaction_cancel(void) 643 926 { 644 return ( regdb->transaction_cancel(regdb) == 0) ?927 return (dbwrap_transaction_cancel(regdb) == 0) ? 645 928 WERR_OK : WERR_REG_IO_FAILURE; 646 929 } … … 653 936 int regdb_get_seqnum(void) 654 937 { 655 return regdb->get_seqnum(regdb);938 return dbwrap_get_seqnum(regdb); 656 939 } 657 940 … … 684 967 } 685 968 686 werr = ntstatus_to_werror(dbwrap_delete_bystring(db, path)); 687 688 /* treat "not" found" as ok */ 689 if (W_ERROR_EQUAL(werr, WERR_NOT_FOUND)) { 690 werr = WERR_OK; 691 } 969 werr = ntstatus_to_werror(dbwrap_purge_bystring(db, path)); 692 970 693 971 done: … … 711 989 return regdb_delete_key_with_prefix(db, keyname, NULL); 712 990 } 991 713 992 714 993 static WERROR regdb_delete_key_lists(struct db_context *db, const char *keyname) … … 752 1031 { 753 1032 TDB_DATA dbuf; 754 uint8 *buffer = NULL;1033 uint8_t *buffer = NULL; 755 1034 int i = 0; 756 uint32 len, buflen;757 uint32 num_subkeys = regsubkey_ctr_numkeys(ctr);1035 uint32_t len, buflen; 1036 uint32_t num_subkeys = regsubkey_ctr_numkeys(ctr); 758 1037 char *keyname = NULL; 759 1038 TALLOC_CTX *ctx = talloc_stackframe(); … … 779 1058 /* allocate some initial memory */ 780 1059 781 buffer = (uint8 *)SMB_MALLOC(1024);1060 buffer = (uint8_t *)SMB_MALLOC(1024); 782 1061 if (buffer == NULL) { 783 1062 werr = WERR_NOMEM; … … 832 1111 werr = ntstatus_to_werror(dbwrap_store_bystring(db, keyname, dbuf, 833 1112 TDB_REPLACE)); 834 W_ERROR_NOT_OK_GOTO_DONE(werr);835 836 /*837 * recreate the sorted subkey cache for regdb_key_exists()838 */839 werr = ntstatus_to_werror(create_sorted_subkeys(keyname));840 1113 841 1114 done: 842 1115 TALLOC_FREE(ctx); 843 1116 SAFE_FREE(buffer); 1117 return werr; 1118 } 1119 1120 /** 1121 * Utility function to store a new empty list of 1122 * subkeys of given key specified as parent and subkey name 1123 * (thereby creating the key). 1124 * If the parent keyname is NULL, then the "subkey" is 1125 * interpreted as a base key. 1126 * If the subkey list does already exist, it is not modified. 1127 * 1128 * Must be called from within a transaction. 1129 */ 1130 static WERROR regdb_store_subkey_list(struct db_context *db, const char *parent, 1131 const char *key) 1132 { 1133 WERROR werr; 1134 char *path = NULL; 1135 struct regsubkey_ctr *subkeys = NULL; 1136 TALLOC_CTX *frame = talloc_stackframe(); 1137 1138 if (parent == NULL) { 1139 path = talloc_strdup(frame, key); 1140 } else { 1141 path = talloc_asprintf(frame, "%s\\%s", parent, key); 1142 } 1143 if (!path) { 1144 werr = WERR_NOMEM; 1145 goto done; 1146 } 1147 1148 werr = regsubkey_ctr_init(frame, &subkeys); 1149 W_ERROR_NOT_OK_GOTO_DONE(werr); 1150 1151 werr = regdb_fetch_keys_internal(db, path, subkeys); 1152 if (W_ERROR_IS_OK(werr)) { 1153 /* subkey list exists already - don't modify */ 1154 goto done; 1155 } 1156 1157 werr = regsubkey_ctr_reinit(subkeys); 1158 W_ERROR_NOT_OK_GOTO_DONE(werr); 1159 1160 /* create a record with 0 subkeys */ 1161 werr = regdb_store_keys_internal2(db, path, subkeys); 1162 if (!W_ERROR_IS_OK(werr)) { 1163 DEBUG(0, ("regdb_store_keys: Failed to store new record for " 1164 "key [%s]: %s\n", path, win_errstr(werr))); 1165 goto done; 1166 } 1167 1168 done: 1169 talloc_free(frame); 844 1170 return werr; 845 1171 } … … 862 1188 int num_subkeys, i; 863 1189 char *path = NULL; 864 struct regsubkey_ctr * subkeys = NULL, *old_subkeys = NULL;1190 struct regsubkey_ctr *old_subkeys = NULL; 865 1191 char *oldkeyname = NULL; 866 1192 TALLOC_CTX *mem_ctx = talloc_stackframe(); … … 945 1271 num_subkeys = regsubkey_ctr_numkeys(store_ctx->ctr); 946 1272 947 if (num_subkeys == 0) { 948 werr = regsubkey_ctr_init(mem_ctx, &subkeys); 1273 for (i=0; i<num_subkeys; i++) { 1274 const char *subkey; 1275 1276 subkey = regsubkey_ctr_specific_key(store_ctx->ctr, i); 1277 1278 werr = regdb_store_subkey_list(db, store_ctx->key, subkey); 949 1279 W_ERROR_NOT_OK_GOTO_DONE(werr); 950 951 werr = regdb_store_keys_internal2(db, store_ctx->key, subkeys);952 if (!W_ERROR_IS_OK(werr)) {953 DEBUG(0,("regdb_store_keys: Failed to store "954 "new record for key [%s]: %s\n",955 store_ctx->key, win_errstr(werr)));956 goto done;957 }958 TALLOC_FREE(subkeys);959 }960 961 for (i=0; i<num_subkeys; i++) {962 path = talloc_asprintf(mem_ctx, "%s\\%s", store_ctx->key,963 regsubkey_ctr_specific_key(store_ctx->ctr, i));964 if (!path) {965 werr = WERR_NOMEM;966 goto done;967 }968 werr = regsubkey_ctr_init(mem_ctx, &subkeys);969 W_ERROR_NOT_OK_GOTO_DONE(werr);970 971 werr = regdb_fetch_keys_internal(db, path, subkeys);972 if (!W_ERROR_IS_OK(werr)) {973 /* create a record with 0 subkeys */974 werr = regdb_store_keys_internal2(db, path, subkeys);975 if (!W_ERROR_IS_OK(werr)) {976 DEBUG(0,("regdb_store_keys: Failed to store "977 "new record for key [%s]: %s\n", path,978 win_errstr(werr)));979 goto done;980 }981 }982 983 TALLOC_FREE(subkeys);984 TALLOC_FREE(path);985 1280 } 986 1281 … … 989 1284 * prevent next read from going to disk 990 1285 */ 991 werr = regsubkey_ctr_set_seqnum(store_ctx->ctr, db ->get_seqnum(db));1286 werr = regsubkey_ctr_set_seqnum(store_ctx->ctr, dbwrap_get_seqnum(db)); 992 1287 993 1288 done: … … 1006 1301 struct regdb_store_keys_context store_ctx; 1007 1302 1008 if (!regdb_key_ is_base_key(key) && !regdb_key_exists(db, key)) {1303 if (!regdb_key_exists(db, key)) { 1009 1304 goto done; 1010 1305 } … … 1057 1352 store_ctx.ctr = ctr; 1058 1353 1059 werr = ntstatus_to_werror(dbwrap_trans_do(db,1060 1061 &store_ctx));1354 werr = regdb_trans_do(db, 1355 regdb_store_keys_action, 1356 &store_ctx); 1062 1357 1063 1358 ret = W_ERROR_IS_OK(werr); … … 1069 1364 } 1070 1365 1071 bool regdb_store_keys(const char *key, struct regsubkey_ctr *ctr)1366 static bool regdb_store_keys(const char *key, struct regsubkey_ctr *ctr) 1072 1367 { 1073 1368 return regdb_store_keys_internal(regdb, key, ctr); … … 1109 1404 } 1110 1405 1406 werr = regdb_store_subkey_list(db, create_ctx->key, create_ctx->subkey); 1407 1111 1408 done: 1112 1409 talloc_free(mem_ctx); … … 1114 1411 } 1115 1412 1116 static WERROR regdb_create_subkey(const char *key, const char *subkey) 1413 static WERROR regdb_create_subkey_internal(struct db_context *db, 1414 const char *key, 1415 const char *subkey) 1117 1416 { 1118 1417 WERROR werr; … … 1121 1420 struct regdb_create_subkey_context create_ctx; 1122 1421 1123 if (!regdb_key_ is_base_key(key) && !regdb_key_exists(regdb, key)) {1422 if (!regdb_key_exists(db, key)) { 1124 1423 werr = WERR_NOT_FOUND; 1125 1424 goto done; … … 1129 1428 W_ERROR_NOT_OK_GOTO_DONE(werr); 1130 1429 1131 werr = regdb_fetch_keys_internal( regdb, key, subkeys);1430 werr = regdb_fetch_keys_internal(db, key, subkeys); 1132 1431 W_ERROR_NOT_OK_GOTO_DONE(werr); 1133 1432 1134 1433 if (regsubkey_ctr_key_exists(subkeys, subkey)) { 1135 werr = WERR_OK; 1136 goto done; 1434 char *newkey; 1435 1436 newkey = talloc_asprintf(mem_ctx, "%s\\%s", key, subkey); 1437 if (newkey == NULL) { 1438 werr = WERR_NOMEM; 1439 goto done; 1440 } 1441 1442 if (regdb_key_exists(db, newkey)) { 1443 werr = WERR_OK; 1444 goto done; 1445 } 1137 1446 } 1138 1447 … … 1142 1451 create_ctx.subkey = subkey; 1143 1452 1144 werr = ntstatus_to_werror(dbwrap_trans_do(regdb,1145 1146 &create_ctx));1453 werr = regdb_trans_do(db, 1454 regdb_create_subkey_action, 1455 &create_ctx); 1147 1456 1148 1457 done: 1149 1458 talloc_free(mem_ctx); 1459 return werr; 1460 } 1461 1462 static WERROR regdb_create_subkey(const char *key, const char *subkey) 1463 { 1464 return regdb_create_subkey_internal(regdb, key, subkey); 1465 } 1466 1467 /** 1468 * create a base key 1469 */ 1470 1471 struct regdb_create_basekey_context { 1472 const char *key; 1473 }; 1474 1475 static NTSTATUS regdb_create_basekey_action(struct db_context *db, 1476 void *private_data) 1477 { 1478 WERROR werr; 1479 struct regdb_create_basekey_context *create_ctx; 1480 1481 create_ctx = (struct regdb_create_basekey_context *)private_data; 1482 1483 werr = regdb_store_subkey_list(db, NULL, create_ctx->key); 1484 1485 return werror_to_ntstatus(werr); 1486 } 1487 1488 static WERROR regdb_create_basekey(struct db_context *db, const char *key) 1489 { 1490 WERROR werr; 1491 struct regdb_create_subkey_context create_ctx; 1492 1493 create_ctx.key = key; 1494 1495 werr = regdb_trans_do(db, 1496 regdb_create_basekey_action, 1497 &create_ctx); 1498 1150 1499 return werr; 1151 1500 } … … 1159 1508 const char *subkey; 1160 1509 const char *path; 1510 bool lazy; 1161 1511 }; 1162 1512 … … 1173 1523 werr = regdb_delete_key_lists(db, delete_ctx->path); 1174 1524 W_ERROR_NOT_OK_GOTO_DONE(werr); 1525 1526 if (delete_ctx->lazy) { 1527 goto done; 1528 } 1175 1529 1176 1530 werr = regsubkey_ctr_init(mem_ctx, &subkeys); … … 1195 1549 } 1196 1550 1197 static WERROR regdb_delete_subkey(const char *key, const char *subkey )1551 static WERROR regdb_delete_subkey(const char *key, const char *subkey, bool lazy) 1198 1552 { 1199 1553 WERROR werr; … … 1202 1556 TALLOC_CTX *mem_ctx = talloc_stackframe(); 1203 1557 1204 if (!regdb_key_ is_base_key(key) && !regdb_key_exists(regdb, key)) {1558 if (!regdb_key_exists(regdb, key)) { 1205 1559 werr = WERR_NOT_FOUND; 1206 1560 goto done; … … 1221 1575 delete_ctx.subkey = subkey; 1222 1576 delete_ctx.path = path; 1223 1224 werr = ntstatus_to_werror(dbwrap_trans_do(regdb, 1225 regdb_delete_subkey_action, 1226 &delete_ctx)); 1577 delete_ctx.lazy = lazy; 1578 1579 werr = regdb_trans_do(regdb, 1580 regdb_delete_subkey_action, 1581 &delete_ctx); 1227 1582 1228 1583 done: … … 1236 1591 char *path = NULL; 1237 1592 TDB_DATA data; 1593 NTSTATUS status; 1238 1594 1239 1595 path = normalize_reg_path(mem_ctx, key); … … 1242 1598 } 1243 1599 1244 data = dbwrap_fetch_bystring(db, mem_ctx, path); 1600 status = dbwrap_fetch_bystring(db, mem_ctx, path, &data); 1601 if (!NT_STATUS_IS_OK(status)) { 1602 data = tdb_null; 1603 } 1245 1604 1246 1605 TALLOC_FREE(path); … … 1250 1609 1251 1610 /** 1252 * check whether a given key name represents a base key, 1253 * i.e one without a subkey separator ('\'). 1611 * Check for the existence of a key. 1612 * 1613 * Existence of a key is authoritatively defined by 1614 * the existence of the record that contains the list 1615 * of its subkeys. 1616 * 1617 * Return false, if the record does not match the correct 1618 * structure of an initial 4-byte counter and then a 1619 * list of the corresponding number of zero-terminated 1620 * strings. 1254 1621 */ 1255 static bool regdb_key_ is_base_key(const char *key)1622 static bool regdb_key_exists(struct db_context *db, const char *key) 1256 1623 { 1257 1624 TALLOC_CTX *mem_ctx = talloc_stackframe(); 1625 TDB_DATA value; 1258 1626 bool ret = false; 1259 1627 char *path; 1628 uint32_t buflen; 1629 const char *buf; 1630 uint32_t num_items, i; 1631 int32_t len; 1260 1632 1261 1633 if (key == NULL) { … … 1273 1645 } 1274 1646 1275 ret = (strrchr(path, '\\') == NULL); 1276 1277 done: 1278 TALLOC_FREE(mem_ctx); 1279 return ret; 1280 } 1281 1282 /* 1283 * regdb_key_exists() is a very frequent operation. It can be quite 1284 * time-consuming to fully fetch the parent's subkey list, talloc_strdup all 1285 * subkeys and then compare the keyname linearly to all the parent's subkeys. 1286 * 1287 * The following code tries to make this operation as efficient as possible: 1288 * Per registry key we create a list of subkeys that is very efficient to 1289 * search for existence of a subkey. Its format is: 1290 * 1291 * 4 bytes num_subkeys 1292 * 4*num_subkey bytes offset into the string array 1293 * then follows a sorted list of subkeys in uppercase 1294 * 1295 * This record is created by create_sorted_subkeys() on demand if it does not 1296 * exist. scan_parent_subkeys() uses regdb->parse_record to search the sorted 1297 * list, the parsing code and the binary search can be found in 1298 * parent_subkey_scanner. The code uses parse_record() to avoid a memcpy of 1299 * the potentially large subkey record. 1300 * 1301 * The sorted subkey record is deleted in regdb_store_keys_internal2 and 1302 * recreated on demand. 1303 */ 1304 1305 static int cmp_keynames(char **p1, char **p2) 1306 { 1307 return StrCaseCmp(*p1, *p2); 1308 } 1309 1310 struct create_sorted_subkeys_context { 1311 const char *key; 1312 const char *sorted_keyname; 1313 }; 1314 1315 static NTSTATUS create_sorted_subkeys_action(struct db_context *db, 1316 void *private_data) 1317 { 1318 char **sorted_subkeys; 1319 struct regsubkey_ctr *ctr; 1320 NTSTATUS status; 1321 char *buf; 1322 char *p; 1323 int i; 1324 size_t len; 1325 int num_subkeys; 1326 struct create_sorted_subkeys_context *sorted_ctx; 1327 1328 sorted_ctx = (struct create_sorted_subkeys_context *)private_data; 1647 value = regdb_fetch_key_internal(db, mem_ctx, path); 1648 if (value.dptr == NULL) { 1649 goto done; 1650 } 1651 1652 if (value.dsize == 0) { 1653 DEBUG(10, ("regdb_key_exists: subkeylist-record for key " 1654 "[%s] is empty: Could be a deleted record in a " 1655 "clustered (ctdb) environment?\n", 1656 path)); 1657 goto done; 1658 } 1659 1660 len = tdb_unpack(value.dptr, value.dsize, "d", &num_items); 1661 if (len == (int32_t)-1) { 1662 DEBUG(1, ("regdb_key_exists: ERROR: subkeylist-record for key " 1663 "[%s] is invalid: Could not parse initial 4-byte " 1664 "counter. record data length is %u.\n", 1665 path, (unsigned int)value.dsize)); 1666 goto done; 1667 } 1329 1668 1330 1669 /* 1331 * In this function, we only treat failing of the actual write to 1332 * the db as a real error. All preliminary errors, at a stage when 1333 * nothing has been written to the DB yet are treated as success 1334 * to be committed (as an empty transaction). 1335 * 1336 * The reason is that this (disposable) call might be nested in other 1337 * transactions. Doing a cancel here would destroy the possibility of 1338 * a transaction_commit for transactions that we might be wrapped in. 1670 * Note: the tdb_unpack check above implies that len <= value.dsize 1339 1671 */ 1340 1341 status = werror_to_ntstatus(regsubkey_ctr_init(talloc_tos(), &ctr)); 1342 if (!NT_STATUS_IS_OK(status)) { 1343 /* don't treat this as an error */ 1344 status = NT_STATUS_OK; 1345 goto done; 1346 } 1347 1348 status = werror_to_ntstatus(regdb_fetch_keys_internal(db, 1349 sorted_ctx->key, 1350 ctr)); 1351 if (!NT_STATUS_IS_OK(status)) { 1352 /* don't treat this as an error */ 1353 status = NT_STATUS_OK; 1354 goto done; 1355 } 1356 1357 num_subkeys = regsubkey_ctr_numkeys(ctr); 1358 sorted_subkeys = talloc_array(ctr, char *, num_subkeys); 1359 if (sorted_subkeys == NULL) { 1360 /* don't treat this as an error */ 1361 goto done; 1362 } 1363 1364 len = 4 + 4*num_subkeys; 1365 1366 for (i = 0; i < num_subkeys; i++) { 1367 sorted_subkeys[i] = talloc_strdup_upper(sorted_subkeys, 1368 regsubkey_ctr_specific_key(ctr, i)); 1369 if (sorted_subkeys[i] == NULL) { 1370 /* don't treat this as an error */ 1672 buflen = value.dsize - len; 1673 buf = (const char *)value.dptr + len; 1674 1675 len = 0; 1676 1677 for (i = 0; i < num_items; i++) { 1678 if (buflen == 0) { 1679 break; 1680 } 1681 len = strnlen(buf, buflen) + 1; 1682 if (buflen < len) { 1683 DEBUG(1, ("regdb_key_exists: ERROR: subkeylist-record " 1684 "for key [%s] is corrupt: %u items expected, " 1685 "item number %u is not zero terminated.\n", 1686 path, num_items, i+1)); 1371 1687 goto done; 1372 1688 } 1373 len += strlen(sorted_subkeys[i])+1; 1374 } 1375 1376 TYPESAFE_QSORT(sorted_subkeys, num_subkeys, cmp_keynames); 1377 1378 buf = talloc_array(ctr, char, len); 1379 if (buf == NULL) { 1380 /* don't treat this as an error */ 1381 goto done; 1382 } 1383 p = buf + 4 + 4*num_subkeys; 1384 1385 SIVAL(buf, 0, num_subkeys); 1386 1387 for (i=0; i < num_subkeys; i++) { 1388 ptrdiff_t offset = p - buf; 1389 SIVAL(buf, 4 + 4*i, offset); 1390 strlcpy(p, sorted_subkeys[i], len-offset); 1391 p += strlen(sorted_subkeys[i]) + 1; 1392 } 1393 1394 status = dbwrap_store_bystring( 1395 db, sorted_ctx->sorted_keyname, make_tdb_data((uint8_t *)buf, 1396 len), 1397 TDB_REPLACE); 1398 1399 done: 1400 talloc_free(ctr); 1401 return status; 1402 } 1403 1404 static NTSTATUS create_sorted_subkeys_internal(const char *key, 1405 const char *sorted_keyname) 1406 { 1407 NTSTATUS status; 1408 struct create_sorted_subkeys_context sorted_ctx; 1409 1410 sorted_ctx.key = key; 1411 sorted_ctx.sorted_keyname = sorted_keyname; 1412 1413 status = dbwrap_trans_do(regdb, 1414 create_sorted_subkeys_action, 1415 &sorted_ctx); 1416 1417 return status; 1418 } 1419 1420 static NTSTATUS create_sorted_subkeys(const char *key) 1421 { 1422 char *sorted_subkeys_keyname; 1423 NTSTATUS status; 1424 1425 sorted_subkeys_keyname = talloc_asprintf(talloc_tos(), "%s\\%s", 1426 REG_SORTED_SUBKEYS_PREFIX, 1427 key); 1428 if (sorted_subkeys_keyname == NULL) { 1429 status = NT_STATUS_NO_MEMORY; 1430 goto done; 1431 } 1432 1433 status = create_sorted_subkeys_internal(key, sorted_subkeys_keyname); 1434 1435 done: 1436 return status; 1437 } 1438 1439 struct scan_subkey_state { 1440 char *name; 1441 bool scanned; 1442 bool found; 1443 }; 1444 1445 static int parent_subkey_scanner(TDB_DATA key, TDB_DATA data, 1446 void *private_data) 1447 { 1448 struct scan_subkey_state *state = 1449 (struct scan_subkey_state *)private_data; 1450 uint32_t num_subkeys; 1451 uint32_t l, u; 1452 1453 if (data.dsize < sizeof(uint32_t)) { 1454 return -1; 1455 } 1456 1457 state->scanned = true; 1458 state->found = false; 1459 1460 tdb_unpack(data.dptr, data.dsize, "d", &num_subkeys); 1461 1462 l = 0; 1463 u = num_subkeys; 1464 1465 while (l < u) { 1466 uint32_t idx = (l+u)/2; 1467 char *s = (char *)data.dptr + IVAL(data.dptr, 4 + 4*idx); 1468 int comparison = strcmp(state->name, s); 1469 1470 if (comparison < 0) { 1471 u = idx; 1472 } else if (comparison > 0) { 1473 l = idx + 1; 1474 } else { 1475 state->found = true; 1476 return 0; 1477 } 1478 } 1479 return 0; 1480 } 1481 1482 static bool scan_parent_subkeys(struct db_context *db, const char *parent, 1483 const char *name) 1484 { 1485 char *path = NULL; 1486 char *key = NULL; 1487 struct scan_subkey_state state = { 0, }; 1488 bool result = false; 1489 int res; 1490 1491 state.name = NULL; 1492 1493 path = normalize_reg_path(talloc_tos(), parent); 1494 if (path == NULL) { 1495 goto fail; 1496 } 1497 1498 key = talloc_asprintf(talloc_tos(), "%s\\%s", 1499 REG_SORTED_SUBKEYS_PREFIX, path); 1500 if (key == NULL) { 1501 goto fail; 1502 } 1503 1504 state.name = talloc_strdup_upper(talloc_tos(), name); 1505 if (state.name == NULL) { 1506 goto fail; 1507 } 1508 state.scanned = false; 1509 1510 res = db->parse_record(db, string_term_tdb_data(key), 1511 parent_subkey_scanner, &state); 1512 1513 if (state.scanned) { 1514 result = state.found; 1515 } else { 1516 NTSTATUS status; 1517 1518 res = db->transaction_start(db); 1519 if (res != 0) { 1520 DEBUG(0, ("error starting transaction\n")); 1521 goto fail; 1522 } 1523 1524 DEBUG(2, (__location__ " WARNING: recreating the sorted " 1525 "subkeys cache for key '%s' from scan_parent_subkeys " 1526 "this should not happen (too frequently)...\n", 1527 path)); 1528 1529 status = create_sorted_subkeys_internal(path, key); 1530 if (!NT_STATUS_IS_OK(status)) { 1531 res = db->transaction_cancel(db); 1532 if (res != 0) { 1533 smb_panic("Failed to cancel transaction."); 1534 } 1535 goto fail; 1536 } 1537 1538 res = db->parse_record(db, string_term_tdb_data(key), 1539 parent_subkey_scanner, &state); 1540 if ((res == 0) && (state.scanned)) { 1541 result = state.found; 1542 } 1543 1544 res = db->transaction_commit(db); 1545 if (res != 0) { 1546 DEBUG(0, ("error committing transaction\n")); 1547 result = false; 1548 } 1549 } 1550 1551 fail: 1552 TALLOC_FREE(path); 1553 TALLOC_FREE(state.name); 1554 return result; 1555 } 1556 1557 /** 1558 * Check for the existence of a key. 1559 * 1560 * Existence of a key is authoritatively defined by its 1561 * existence in the list of subkeys of its parent key. 1562 * The exeption of this are keys without a parent key, 1563 * i.e. the "base" keys (HKLM, HKCU, ...). 1564 */ 1565 static bool regdb_key_exists(struct db_context *db, const char *key) 1566 { 1567 TALLOC_CTX *mem_ctx = talloc_stackframe(); 1568 TDB_DATA value; 1569 bool ret = false; 1570 char *path, *p; 1571 1572 if (key == NULL) { 1573 goto done; 1574 } 1575 1576 path = normalize_reg_path(mem_ctx, key); 1577 if (path == NULL) { 1578 DEBUG(0, ("out of memory! (talloc failed)\n")); 1579 goto done; 1580 } 1581 1582 if (*path == '\0') { 1583 goto done; 1584 } 1585 1586 p = strrchr(path, '\\'); 1587 if (p == NULL) { 1588 /* this is a base key */ 1589 value = regdb_fetch_key_internal(db, mem_ctx, path); 1590 ret = (value.dptr != NULL); 1591 } else { 1592 *p = '\0'; 1593 ret = scan_parent_subkeys(db, path, p+1); 1594 } 1689 1690 buf += len; 1691 buflen -= len; 1692 } 1693 1694 if (buflen > 0) { 1695 DEBUG(1, ("regdb_key_exists: ERROR: subkeylist-record for key " 1696 "[%s] is corrupt: %u items expected and found, but " 1697 "the record contains additional %u bytes\n", 1698 path, num_items, buflen)); 1699 goto done; 1700 } 1701 1702 if (i < num_items) { 1703 DEBUG(1, ("regdb_key_exists: ERROR: subkeylist-record for key " 1704 "[%s] is corrupt: %u items expected, but only %u " 1705 "items found.\n", 1706 path, num_items, i+1)); 1707 goto done; 1708 } 1709 1710 ret = true; 1595 1711 1596 1712 done: … … 1610 1726 WERROR werr; 1611 1727 uint32_t num_items; 1612 uint8 *buf;1613 uint32 buflen, len;1728 uint8_t *buf; 1729 uint32_t buflen, len; 1614 1730 int i; 1615 1731 fstring subkeyname; … … 1631 1747 count = 0; 1632 1748 ZERO_STRUCT(value); 1633 seqnum[0] = db ->get_seqnum(db);1749 seqnum[0] = dbwrap_get_seqnum(db); 1634 1750 1635 1751 do { … … 1637 1753 TALLOC_FREE(value.dptr); 1638 1754 value = regdb_fetch_key_internal(db, frame, key); 1639 seqnum[count % 2] = db ->get_seqnum(db);1755 seqnum[count % 2] = dbwrap_get_seqnum(db); 1640 1756 1641 1757 } while (seqnum[0] != seqnum[1]); … … 1684 1800 } 1685 1801 1686 int regdb_fetch_keys(const char *key, struct regsubkey_ctr *ctr)1802 static int regdb_fetch_keys(const char *key, struct regsubkey_ctr *ctr) 1687 1803 { 1688 1804 WERROR werr; … … 1700 1816 ***************************************************************************/ 1701 1817 1702 static int regdb_unpack_values(struct regval_ctr *values, uint8 *buf, int buflen)1818 static int regdb_unpack_values(struct regval_ctr *values, uint8_t *buf, int buflen) 1703 1819 { 1704 1820 int len = 0; 1705 uint32 1821 uint32_t type; 1706 1822 fstring valuename; 1707 uint32 1708 uint8 *data_p;1709 uint32 1823 uint32_t size; 1824 uint8_t *data_p; 1825 uint32_t num_values = 0; 1710 1826 int i; 1711 1827 … … 1742 1858 ***************************************************************************/ 1743 1859 1744 static int regdb_pack_values(struct regval_ctr *values, uint8 *buf, int buflen)1860 static int regdb_pack_values(struct regval_ctr *values, uint8_t *buf, int buflen) 1745 1861 { 1746 1862 int len = 0; … … 1803 1919 ZERO_STRUCT(value); 1804 1920 count = 0; 1805 seqnum[0] = db ->get_seqnum(db);1921 seqnum[0] = dbwrap_get_seqnum(db); 1806 1922 1807 1923 do { … … 1809 1925 TALLOC_FREE(value.dptr); 1810 1926 value = regdb_fetch_key_internal(db, ctx, keystr); 1811 seqnum[count % 2] = db ->get_seqnum(db);1927 seqnum[count % 2] = dbwrap_get_seqnum(db); 1812 1928 } while (seqnum[0] != seqnum[1]); 1813 1929 … … 1836 1952 } 1837 1953 1838 int regdb_fetch_values(const char* key, struct regval_ctr *values)1954 static int regdb_fetch_values(const char* key, struct regval_ctr *values) 1839 1955 { 1840 1956 return regdb_fetch_values_internal(regdb, key, values); 1841 1957 } 1842 1958 1843 static bool regdb_store_values_internal(struct db_context *db, const char *key, 1844 struct regval_ctr *values) 1959 static NTSTATUS regdb_store_values_internal(struct db_context *db, 1960 const char *key, 1961 struct regval_ctr *values) 1845 1962 { 1846 1963 TDB_DATA old_data, data; … … 1849 1966 int len; 1850 1967 NTSTATUS status; 1851 bool result = false;1852 1968 WERROR werr; 1853 1969 … … 1855 1971 1856 1972 if (!regdb_key_exists(db, key)) { 1973 status = NT_STATUS_NOT_FOUND; 1974 goto done; 1975 } 1976 1977 if (regval_ctr_numvals(values) == 0) { 1978 werr = regdb_delete_values(db, key); 1979 if (!W_ERROR_IS_OK(werr)) { 1980 status = werror_to_ntstatus(werr); 1981 goto done; 1982 } 1983 1984 /* 1985 * update the seqnum in the cache to prevent the next read 1986 * from going to disk 1987 */ 1988 werr = regval_ctr_set_seqnum(values, dbwrap_get_seqnum(db)); 1989 status = werror_to_ntstatus(werr); 1857 1990 goto done; 1858 1991 } … … 1863 1996 if (len <= 0) { 1864 1997 DEBUG(0,("regdb_store_values: unable to pack values. len <= 0\n")); 1865 goto done; 1866 } 1867 1868 data.dptr = TALLOC_ARRAY(ctx, uint8, len); 1998 status = NT_STATUS_UNSUCCESSFUL; 1999 goto done; 2000 } 2001 2002 data.dptr = talloc_array(ctx, uint8_t, len); 1869 2003 data.dsize = len; 1870 2004 … … 1875 2009 keystr = talloc_asprintf(ctx, "%s\\%s", REG_VALUE_PREFIX, key ); 1876 2010 if (!keystr) { 2011 status = NT_STATUS_NO_MEMORY; 1877 2012 goto done; 1878 2013 } 1879 2014 keystr = normalize_reg_path(ctx, keystr); 1880 2015 if (!keystr) { 1881 goto done; 1882 } 1883 1884 old_data = dbwrap_fetch_bystring(db, ctx, keystr); 1885 1886 if ((old_data.dptr != NULL) 2016 status = NT_STATUS_NO_MEMORY; 2017 goto done; 2018 } 2019 2020 status = dbwrap_fetch_bystring(db, ctx, keystr, &old_data); 2021 2022 if (NT_STATUS_IS_OK(status) 2023 && (old_data.dptr != NULL) 1887 2024 && (old_data.dsize == data.dsize) 1888 2025 && (memcmp(old_data.dptr, data.dptr, data.dsize) == 0)) 1889 2026 { 1890 result = true;2027 status = NT_STATUS_OK; 1891 2028 goto done; 1892 2029 } … … 1902 2039 * from going to disk 1903 2040 */ 1904 werr = regval_ctr_set_seqnum(values, db ->get_seqnum(db));1905 result = W_ERROR_IS_OK(status);2041 werr = regval_ctr_set_seqnum(values, dbwrap_get_seqnum(db)); 2042 status = werror_to_ntstatus(werr); 1906 2043 1907 2044 done: 1908 2045 TALLOC_FREE(ctx); 1909 return result; 1910 } 1911 1912 bool regdb_store_values(const char *key, struct regval_ctr *values) 1913 { 1914 return regdb_store_values_internal(regdb, key, values); 2046 return status; 2047 } 2048 2049 struct regdb_store_values_ctx { 2050 const char *key; 2051 struct regval_ctr *values; 2052 }; 2053 2054 static NTSTATUS regdb_store_values_action(struct db_context *db, 2055 void *private_data) 2056 { 2057 NTSTATUS status; 2058 struct regdb_store_values_ctx *ctx = 2059 (struct regdb_store_values_ctx *)private_data; 2060 2061 status = regdb_store_values_internal(db, ctx->key, ctx->values); 2062 2063 return status; 2064 } 2065 2066 static bool regdb_store_values(const char *key, struct regval_ctr *values) 2067 { 2068 WERROR werr; 2069 struct regdb_store_values_ctx ctx; 2070 2071 ctx.key = key; 2072 ctx.values = values; 2073 2074 werr = regdb_trans_do(regdb, regdb_store_values_action, &ctx); 2075 2076 return W_ERROR_IS_OK(werr); 1915 2077 } 1916 2078 … … 1943 2105 } 1944 2106 1945 data = dbwrap_fetch_bystring(regdb, tmp_ctx, tdbkey);1946 if ( data.dptr == NULL) {2107 status = dbwrap_fetch_bystring(regdb, tmp_ctx, tdbkey, &data); 2108 if (!NT_STATUS_IS_OK(status)) { 1947 2109 err = WERR_BADFILE; 1948 2110 goto done; 1949 2111 } 1950 2112 1951 status = unmarshall_sec_desc(mem_ctx, (uint8 *)data.dptr, data.dsize,2113 status = unmarshall_sec_desc(mem_ctx, (uint8_t *)data.dptr, data.dsize, 1952 2114 psecdesc); 1953 2115 … … 1963 2125 } 1964 2126 2127 struct regdb_set_secdesc_ctx { 2128 const char *key; 2129 struct security_descriptor *secdesc; 2130 }; 2131 2132 static NTSTATUS regdb_set_secdesc_action(struct db_context *db, 2133 void *private_data) 2134 { 2135 char *tdbkey; 2136 NTSTATUS status; 2137 TDB_DATA tdbdata; 2138 struct regdb_set_secdesc_ctx *ctx = 2139 (struct regdb_set_secdesc_ctx *)private_data; 2140 TALLOC_CTX *frame = talloc_stackframe(); 2141 2142 tdbkey = talloc_asprintf(frame, "%s\\%s", REG_SECDESC_PREFIX, ctx->key); 2143 if (tdbkey == NULL) { 2144 status = NT_STATUS_NO_MEMORY; 2145 goto done; 2146 } 2147 2148 tdbkey = normalize_reg_path(frame, tdbkey); 2149 if (tdbkey == NULL) { 2150 status = NT_STATUS_NO_MEMORY; 2151 goto done; 2152 } 2153 2154 if (ctx->secdesc == NULL) { 2155 /* assuming a delete */ 2156 status = dbwrap_delete_bystring(db, tdbkey); 2157 goto done; 2158 } 2159 2160 status = marshall_sec_desc(frame, ctx->secdesc, &tdbdata.dptr, 2161 &tdbdata.dsize); 2162 if (!NT_STATUS_IS_OK(status)) { 2163 goto done; 2164 } 2165 2166 status = dbwrap_store_bystring(db, tdbkey, tdbdata, 0); 2167 2168 done: 2169 TALLOC_FREE(frame); 2170 return status; 2171 } 2172 1965 2173 static WERROR regdb_set_secdesc(const char *key, 1966 2174 struct security_descriptor *secdesc) 1967 2175 { 1968 TALLOC_CTX *mem_ctx = talloc_stackframe(); 1969 char *tdbkey; 1970 WERROR err = WERR_NOMEM; 1971 TDB_DATA tdbdata; 2176 WERROR err; 2177 struct regdb_set_secdesc_ctx ctx; 1972 2178 1973 2179 if (!regdb_key_exists(regdb, key)) { … … 1976 2182 } 1977 2183 1978 tdbkey = talloc_asprintf(mem_ctx, "%s\\%s", REG_SECDESC_PREFIX, key); 1979 if (tdbkey == NULL) { 1980 goto done; 1981 } 1982 1983 tdbkey = normalize_reg_path(mem_ctx, tdbkey); 1984 if (tdbkey == NULL) { 1985 err = WERR_NOMEM; 1986 goto done; 1987 } 1988 1989 if (secdesc == NULL) { 1990 /* assuming a delete */ 1991 err = ntstatus_to_werror(dbwrap_trans_delete_bystring(regdb, 1992 tdbkey)); 1993 goto done; 1994 } 1995 1996 err = ntstatus_to_werror(marshall_sec_desc(mem_ctx, secdesc, 1997 &tdbdata.dptr, 1998 &tdbdata.dsize)); 1999 W_ERROR_NOT_OK_GOTO_DONE(err); 2000 2001 err = ntstatus_to_werror(dbwrap_trans_store_bystring(regdb, tdbkey, 2002 tdbdata, 0)); 2003 2004 done: 2005 TALLOC_FREE(mem_ctx); 2184 ctx.key = key; 2185 ctx.secdesc = secdesc; 2186 2187 err = regdb_trans_do(regdb, regdb_set_secdesc_action, &ctx); 2188 2189 done: 2006 2190 return err; 2007 2191 } 2008 2192 2009 bool regdb_subkeys_need_update(struct regsubkey_ctr *subkeys)2193 static bool regdb_subkeys_need_update(struct regsubkey_ctr *subkeys) 2010 2194 { 2011 2195 return (regdb_get_seqnum() != regsubkey_ctr_get_seqnum(subkeys)); 2012 2196 } 2013 2197 2014 bool regdb_values_need_update(struct regval_ctr *values)2198 static bool regdb_values_need_update(struct regval_ctr *values) 2015 2199 { 2016 2200 return (regdb_get_seqnum() != regval_ctr_get_seqnum(values)); -
vendor/current/source3/registry/reg_backend_db.h
r740 r988 33 33 WERROR regdb_transaction_cancel(void); 34 34 int regdb_get_seqnum(void); 35 bool regdb_store_keys(const char *key, struct regsubkey_ctr *ctr);36 int regdb_fetch_keys(const char *key, struct regsubkey_ctr *ctr);37 int regdb_fetch_values(const char* key, struct regval_ctr *values);38 bool regdb_store_values(const char *key, struct regval_ctr *values);39 bool regdb_subkeys_need_update(struct regsubkey_ctr *subkeys);40 bool regdb_values_need_update(struct regval_ctr *values);41 35 42 36 #endif /* _REG_BACKEND_DB_H */ -
vendor/current/source3/registry/reg_backend_hkpt_params.c
r740 r988 37 37 static int hkpt_params_fetch_values(const char *key, struct regval_ctr *regvals) 38 38 { 39 uint32 base_index;40 uint32 buffer_size;39 uint32_t base_index; 40 uint32_t buffer_size; 41 41 char *buffer = NULL; 42 42 … … 46 46 base_index = reg_perfcount_get_base_index(); 47 47 buffer_size = reg_perfcount_get_counter_names(base_index, &buffer); 48 regval_ctr_addvalue(regvals, "Counters", REG_MULTI_SZ, (uint8 *)buffer,48 regval_ctr_addvalue(regvals, "Counters", REG_MULTI_SZ, (uint8_t *)buffer, 49 49 buffer_size); 50 50 … … 54 54 55 55 buffer_size = reg_perfcount_get_counter_help(base_index, &buffer); 56 regval_ctr_addvalue(regvals, "Help", REG_MULTI_SZ, (uint8 *)buffer, buffer_size);56 regval_ctr_addvalue(regvals, "Help", REG_MULTI_SZ, (uint8_t *)buffer, buffer_size); 57 57 if(buffer_size > 0) { 58 58 SAFE_FREE(buffer); -
vendor/current/source3/registry/reg_backend_netlogon_params.c
r740 r988 37 37 static int netlogon_params_fetch_values(const char *key, struct regval_ctr *regvals) 38 38 { 39 uint32 dwValue;39 uint32_t dwValue; 40 40 41 41 if (!pdb_get_account_policy(PDB_POLICY_REFUSE_MACHINE_PW_CHANGE, &dwValue)) { -
vendor/current/source3/registry/reg_backend_printing.c
r740 r988 24 24 #include "registry.h" 25 25 #include "reg_util_internal.h" 26 #include "reg_backend_db.h"27 26 28 27 #undef DBGC_CLASS 29 28 #define DBGC_CLASS DBGC_REGISTRY 29 30 extern struct registry_ops regdb_ops; 30 31 31 32 /* registry paths used in the print_registry[] */ … … 89 90 if (printers_key == NULL) { 90 91 /* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */ 91 return regdb_ fetch_keys(KEY_WINNT_PRINTERS, subkeys);92 } 93 94 return regdb_ fetch_keys(printers_key, subkeys);92 return regdb_ops.fetch_subkeys(KEY_WINNT_PRINTERS, subkeys); 93 } 94 95 return regdb_ops.fetch_subkeys(printers_key, subkeys); 95 96 } 96 97 … … 106 107 if (printers_key == NULL) { 107 108 /* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */ 108 return regdb_ store_keys(KEY_WINNT_PRINTERS, subkeys);109 } 110 111 return regdb_ store_keys(printers_key, subkeys);109 return regdb_ops.store_subkeys(KEY_WINNT_PRINTERS, subkeys); 110 } 111 112 return regdb_ops.store_subkeys(printers_key, subkeys); 112 113 } 113 114 … … 123 124 if (printers_key == NULL) { 124 125 /* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */ 125 return regdb_ fetch_values(KEY_WINNT_PRINTERS, values);126 } 127 128 return regdb_ fetch_values(printers_key, values);126 return regdb_ops.fetch_values(KEY_WINNT_PRINTERS, values); 127 } 128 129 return regdb_ops.fetch_values(printers_key, values); 129 130 } 130 131 … … 140 141 if (printers_key == NULL) { 141 142 /* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */ 142 return regdb_ store_values(KEY_WINNT_PRINTERS, values);143 } 144 145 return regdb_ store_values(printers_key, values);143 return regdb_ops.store_values(KEY_WINNT_PRINTERS, values); 144 } 145 146 return regdb_ops.store_values(printers_key, values); 146 147 } 147 148 -
vendor/current/source3/registry/reg_backend_shares.c
r740 r988 39 39 { 40 40 const char *p; 41 uint16 key_len = strlen(KEY_SHARES);41 uint16_t key_len = strlen(KEY_SHARES); 42 42 43 43 /* -
vendor/current/source3/registry/reg_backend_smbconf.c
r746 r988 43 43 } 44 44 45 static WERROR smbconf_delete_subkey(const char *key, const char *subkey )45 static WERROR smbconf_delete_subkey(const char *key, const char *subkey, bool lazy) 46 46 { 47 return regdb_ops.delete_subkey(key, subkey );47 return regdb_ops.delete_subkey(key, subkey, lazy); 48 48 } 49 49 … … 58 58 } 59 59 60 static bool smbconf_reg_access_check(const char *keyname, uint32 requested,61 uint32 *granted,60 static bool smbconf_reg_access_check(const char *keyname, uint32_t requested, 61 uint32_t *granted, 62 62 const struct security_token *token) 63 63 { -
vendor/current/source3/registry/reg_cachehook.c
r740 r988 94 94 (void *)ops, key)); 95 95 96 werr = pathtree_add(cache_tree, key, ops); 96 if (!pathtree_add(cache_tree, key, ops)) 97 werr = WERR_NOMEM; 98 else 99 werr = WERR_OK; 97 100 98 101 done: -
vendor/current/source3/registry/reg_db.h
r740 r988 22 22 23 23 #define REG_TDB_FLAGS TDB_SEQNUM 24 #define REG_DBWRAP_FLAGS DBWRAP_FLAG_NONE 24 25 25 #define REGVER_V1 1 /* first db version with write support */ 26 #define REGVER_V2 2 /* version 2 with normalized keys */ 26 #define REGDB_VERSION_V1 1 /* first db version with write support */ 27 #define REGDB_VERSION_V2 2 /* version 2 with normalized keys */ 28 #define REGDB_VERSION_V3 3 /* different definition of key existence, */ 29 /* sorted subkeys cache removed. */ 30 31 #define REGDB_CODE_VERSION REGDB_VERSION_V3 27 32 28 33 #define REG_VALUE_PREFIX "SAMBA_REGVAL" -
vendor/current/source3/registry/reg_dispatcher.c
r740 r988 25 25 26 26 #include "includes.h" 27 #include "system/passwd.h" /* uid_wrapper */ 27 28 #include "registry.h" 28 29 #include "reg_dispatcher.h" … … 114 115 } 115 116 116 WERROR delete_reg_subkey(struct registry_key_handle *key, const char *subkey )117 WERROR delete_reg_subkey(struct registry_key_handle *key, const char *subkey, bool lazy) 117 118 { 118 119 if (key->ops && key->ops->delete_subkey) { 119 return key->ops->delete_subkey(key->name, subkey );120 return key->ops->delete_subkey(key->name, subkey, lazy); 120 121 } 121 122 … … 161 162 ***********************************************************************/ 162 163 163 bool regkey_access_check(struct registry_key_handle *key, uint32 requested,164 uint32 *granted,164 bool regkey_access_check(struct registry_key_handle *key, uint32_t requested, 165 uint32_t *granted, 165 166 const struct security_token *token ) 166 167 { … … 170 171 171 172 /* root free-pass, like we have on all other pipes like samr, lsa, etc. */ 172 if ( geteuid() == sec_initial_uid()) {173 if (root_mode()) { 173 174 *granted = REG_KEY_ALL; 174 175 return true; … … 244 245 } 245 246 246 return false;247 return true; 247 248 } 248 249 … … 259 260 } 260 261 261 return false;262 } 263 262 return true; 263 } 264 -
vendor/current/source3/registry/reg_dispatcher.h
r740 r988 26 26 bool store_reg_values(struct registry_key_handle *key, struct regval_ctr *val); 27 27 WERROR create_reg_subkey(struct registry_key_handle *key, const char *subkey); 28 WERROR delete_reg_subkey(struct registry_key_handle *key, const char *subkey );28 WERROR delete_reg_subkey(struct registry_key_handle *key, const char *subkey, bool lazy); 29 29 int fetch_reg_keys(struct registry_key_handle *key, 30 30 struct regsubkey_ctr *subkey_ctr); 31 31 int fetch_reg_values(struct registry_key_handle *key, struct regval_ctr *val); 32 bool regkey_access_check(struct registry_key_handle *key, uint32 requested,33 uint32 *granted,32 bool regkey_access_check(struct registry_key_handle *key, uint32_t requested, 33 uint32_t *granted, 34 34 const struct security_token *token); 35 35 WERROR regkey_get_secdesc(TALLOC_CTX *mem_ctx, struct registry_key_handle *key, -
vendor/current/source3/registry/reg_format.c
r746 r988 94 94 { 95 95 if (fmt->hive_fmt != FMT_HIVE_PRESERVE) { 96 const struct hive_info* hinfo = hive_info(hive , len);96 const struct hive_info* hinfo = hive_info(hive); 97 97 if (hinfo == NULL) { 98 98 DEBUG(0, ("Unknown hive %*s", len, hive)); … … 568 568 bool del) 569 569 { 570 return reg_format_key(f, (const char**)&key->key->name, 1, del); 570 const char *knames[1]; 571 knames[0] = key->key->name; 572 return reg_format_key(f, knames, 1, del); 571 573 } 572 574 -
vendor/current/source3/registry/reg_import.c
r740 r988 29 29 static const int TL = 2; 30 30 31 struct reg_import 32 { 31 struct reg_import { 33 32 struct reg_parse_callback reg_parse_callback; 34 33 struct reg_import_callback call; 35 void *open_key;34 void *open_key; 36 35 }; 37 36 38 static int 39 reg_parse_callback_key(struct reg_import* cb_private, 40 const char* key[], size_t n, 41 bool del); 42 43 static int 44 reg_parse_callback_val(struct reg_import* cb_private, 45 const char* name, uint32_t type, 46 const uint8_t* data, uint32_t len); 47 48 static int 49 reg_parse_callback_val_registry_value(struct reg_import* cb_private, 50 const char* name, uint32_t type, 51 const uint8_t* data, uint32_t len); 52 53 static int 54 reg_parse_callback_val_regval_blob(struct reg_import* cb_private, 55 const char* name, uint32_t type, 56 const uint8_t* data, uint32_t len); 57 58 static int 59 reg_parse_callback_val_del(struct reg_import* cb_private, 60 const char* name); 61 62 static int 63 reg_parse_callback_comment(struct reg_import* cb_private, 64 const char* txt); 37 static int reg_parse_callback_key(struct reg_import *cb_private, 38 const char *key[], size_t n, bool del); 39 40 static int reg_parse_callback_val(struct reg_import *cb_private, 41 const char *name, uint32_t type, 42 const uint8_t *data, uint32_t len); 43 44 static int reg_parse_callback_val_registry_value(struct reg_import *cb_private, 45 const char *name, 46 uint32_t type, 47 const uint8_t *data, 48 uint32_t len); 49 50 static int reg_parse_callback_val_regval_blob(struct reg_import *cb_private, 51 const char *name, uint32_t type, 52 const uint8_t *data, 53 uint32_t len); 54 55 static int reg_parse_callback_val_del(struct reg_import *cb_private, 56 const char *name); 57 58 static int reg_parse_callback_comment(struct reg_import *cb_private, 59 const char *txt); 65 60 66 61 67 62 /*******************************************************************************/ 68 63 69 int reg_parse_callback_key(struct reg_import *p,70 const char *key[], size_t n, bool del)64 int reg_parse_callback_key(struct reg_import *p, 65 const char *key[], size_t n, bool del) 71 66 { 72 67 WERROR werr = WERR_OK; … … 74 69 DEBUG(TL, ("%s: %s\n", __FUNCTION__, key[0])); 75 70 76 if (p->open_key != NULL 71 if (p->open_key != NULL) { 77 72 werr = p->call.closekey(p->call.data, p->open_key); 73 p->open_key = NULL; 78 74 if (!W_ERROR_IS_OK(werr)) { 79 75 DEBUG(0, ("closekey failed: %s\n", win_errstr(werr))); … … 91 87 key[0], win_errstr(werr))); 92 88 } 93 } 94 else { 89 } else { 95 90 bool existing; 96 91 werr = p->call.createkey(p->call.data, NULL, key[0], … … 122 117 123 118 /*----------------------------------------------------------------------------*/ 124 int reg_parse_callback_val(struct reg_import *p,125 const char *name, uint32_t type,126 const uint8_t *data, uint32_t len)119 int reg_parse_callback_val(struct reg_import *p, 120 const char *name, uint32_t type, 121 const uint8_t *data, uint32_t len) 127 122 { 128 123 WERROR werr = WERR_OK; … … 142 137 143 138 /*----------------------------------------------------------------------------*/ 144 int reg_parse_callback_val_registry_value(struct reg_import *p,145 const char *name, uint32_t type,146 const uint8_t *data, uint32_t len)139 int reg_parse_callback_val_registry_value(struct reg_import *p, 140 const char *name, uint32_t type, 141 const uint8_t *data, uint32_t len) 147 142 { 148 143 WERROR werr = WERR_OK; … … 167 162 168 163 /*----------------------------------------------------------------------------*/ 169 int reg_parse_callback_val_regval_blob(struct reg_import *p,170 const char *name, uint32_t type,171 const uint8_t *data, uint32_t len)164 int reg_parse_callback_val_regval_blob(struct reg_import *p, 165 const char *name, uint32_t type, 166 const uint8_t *data, uint32_t len) 172 167 { 173 168 WERROR werr = WERR_OK; 174 169 void* mem_ctx = talloc_new(p); 175 struct regval_blob *v = NULL;170 struct regval_blob *v = NULL; 176 171 177 172 DEBUG(TL, ("%s(%x): >%s< = [%x]\n", __FUNCTION__, type, name, len)); … … 200 195 /*----------------------------------------------------------------------------*/ 201 196 202 int reg_parse_callback_val_del(struct reg_import *p,203 const char *name)197 int reg_parse_callback_val_del(struct reg_import *p, 198 const char *name) 204 199 { 205 200 WERROR werr = WERR_OK; … … 217 212 218 213 219 int reg_parse_callback_comment(struct reg_import *cb_private,220 const char *txt)214 int reg_parse_callback_comment(struct reg_import *cb_private, 215 const char *txt) 221 216 { 222 217 DEBUG(TL, ("%s: %s\n", __FUNCTION__, txt)); … … 225 220 226 221 /******************************************************************************/ 227 static int nop(void *data)222 static int nop(void *data) 228 223 { 229 224 return 0; … … 231 226 232 227 233 struct reg_parse_callback * reg_import_adapter(const void*talloc_ctx,228 struct reg_parse_callback *reg_import_adapter(TALLOC_CTX *talloc_ctx, 234 229 struct reg_import_callback cb) 235 230 { 236 struct reg_parse_callback *ret;237 struct reg_import *p = talloc_zero(talloc_ctx, struct reg_import);231 struct reg_parse_callback *ret; 232 struct reg_import *p = talloc_zero(talloc_ctx, struct reg_import); 238 233 if (p == NULL) { 239 234 goto fail; 240 235 } 241 if (cb.openkey == NULL 236 if (cb.openkey == NULL) { 242 237 cb.openkey = (reg_import_callback_openkey_t)&nop; 243 238 } 244 if (cb.closekey == NULL 239 if (cb.closekey == NULL) { 245 240 cb.closekey = (reg_import_callback_closekey_t)&nop; 246 241 } 247 if (cb.createkey == NULL 242 if (cb.createkey == NULL) { 248 243 cb.createkey = (reg_import_callback_createkey_t)&nop; 249 244 } 250 if (cb.deletekey == NULL 245 if (cb.deletekey == NULL) { 251 246 cb.deletekey = (reg_import_callback_deletekey_t)&nop; 252 247 } 253 if (cb.deleteval == NULL 248 if (cb.deleteval == NULL) { 254 249 cb.deleteval = (reg_import_callback_deleteval_t)&nop; 255 250 } … … 283 278 } 284 279 285 assert((struct reg_parse_callback *)p == ret);280 assert((struct reg_parse_callback *)p == ret); 286 281 return ret; 287 282 fail: -
vendor/current/source3/registry/reg_import.h
r740 r988 195 195 * @return a talloc'ed reg_import object, NULL on error 196 196 */ 197 struct reg_parse_callback* reg_import_adapter( const void*talloc_ctx,197 struct reg_parse_callback* reg_import_adapter(TALLOC_CTX *talloc_ctx, 198 198 struct reg_import_callback cb); 199 199 #endif -
vendor/current/source3/registry/reg_init_full.c
r740 r988 70 70 /*********************************************************************** 71 71 Open the registry database and initialize the registry_hook cache 72 with all available backen s.72 with all available backends. 73 73 ***********************************************************************/ 74 74 -
vendor/current/source3/registry/reg_objects.c
r746 r988 25 25 #include "reg_objects.h" 26 26 #include "util_tdb.h" 27 #include "dbwrap.h" 27 #include "dbwrap/dbwrap.h" 28 #include "dbwrap/dbwrap_rbt.h" 28 29 #include "../libcli/registry/util_reg.h" 29 30 … … 63 64 64 65 There is no longer a regval_ctr_intit() and regval_ctr_destroy() 65 pair of functions. Simply TALLOC_ZERO_P() and TALLOC_FREE() the66 pair of functions. Simply talloc_zero() and TALLOC_FREE() the 66 67 object. 67 68 … … 170 171 { 171 172 TDB_DATA data; 173 NTSTATUS status; 172 174 173 175 if ((ctr == NULL) || (keyname == NULL)) { … … 175 177 } 176 178 177 data = dbwrap_fetch_bystring_upper(ctr->subkeys_hash, ctr, keyname); 178 if (data.dptr == NULL) { 179 status = dbwrap_fetch_bystring_upper(ctr->subkeys_hash, ctr, keyname, 180 &data); 181 if (!NT_STATUS_IS_OK(status)) { 179 182 return WERR_NOT_FOUND; 180 183 } … … 186 189 187 190 if (idx != NULL) { 188 *idx = *(uint32_t *)data.dptr;191 memcpy(idx, data.dptr, sizeof(*idx)); 189 192 } 190 193 … … 212 215 } 213 216 214 if (!(newkeys = TALLOC_REALLOC_ARRAY(ctr, ctr->subkeys, char *,217 if (!(newkeys = talloc_realloc(ctr, ctr->subkeys, char *, 215 218 ctr->num_subkeys+1))) { 216 219 return WERR_NOMEM; … … 302 305 303 306 /*********************************************************************** 304 Retr eive a specific key string307 Retrieve a specific key string 305 308 **********************************************************************/ 306 309 … … 343 346 } 344 347 345 /***********************************************************************346 allocate memory for and duplicate a struct regval_blob.347 This is malloc'd memory so the caller should free it when done348 **********************************************************************/349 350 struct regval_blob* dup_registry_value(struct regval_blob *val)351 {352 struct regval_blob *copy = NULL;353 354 if ( !val )355 return NULL;356 357 if ( !(copy = SMB_MALLOC_P( struct regval_blob)) ) {358 DEBUG(0,("dup_registry_value: malloc() failed!\n"));359 return NULL;360 }361 362 /* copy all the non-pointer initial data */363 364 memcpy( copy, val, sizeof(struct regval_blob) );365 366 copy->size = 0;367 copy->data_p = NULL;368 369 if ( val->data_p && val->size )370 {371 if ( !(copy->data_p = (uint8_t *)memdup( val->data_p,372 val->size )) ) {373 DEBUG(0,("dup_registry_value: memdup() failed for [%d] "374 "bytes!\n", val->size));375 SAFE_FREE( copy );376 return NULL;377 }378 copy->size = val->size;379 }380 381 return copy;382 }383 384 /**********************************************************************385 free the memory allocated to a struct regval_blob386 *********************************************************************/387 388 void free_registry_value(struct regval_blob *val)389 {390 if ( !val )391 return;392 393 SAFE_FREE( val->data_p );394 SAFE_FREE( val );395 396 return;397 }398 399 348 /********************************************************************** 400 349 *********************************************************************/ … … 430 379 431 380 /*********************************************************************** 432 Retr eive a pointer to a specific value. Caller shoud dup the structure381 Retrieve a pointer to a specific value. Caller shoud dup the structure 433 382 since this memory will go away when the ctr is free()'d 434 383 **********************************************************************/ … … 467 416 int i; 468 417 469 for (i =0; i<ctr->num_values; i++) {470 if (strequal(ctr->values[i]->valuename, value)) {418 for (i = 0; i < ctr->num_values; i++) { 419 if (strequal(ctr->values[i]->valuename, value)) { 471 420 return ctr->values[i]; 472 421 } … … 485 434 const uint8_t *data_p, size_t size) 486 435 { 487 struct regval_blob *regval = TALLOC_P(ctx, struct regval_blob);436 struct regval_blob *regval = talloc(ctx, struct regval_blob); 488 437 489 438 if (regval == NULL) { … … 494 443 regval->type = type; 495 444 if (size) { 496 regval->data_p = (uint8_t *) TALLOC_MEMDUP(regval, data_p, size);445 regval->data_p = (uint8_t *)talloc_memdup(regval, data_p, size); 497 446 if (!regval->data_p) { 498 447 TALLOC_FREE(regval); … … 524 473 525 474 if ( ctr->num_values == 0 ) { 526 ctr->values = TALLOC_P( ctr, struct regval_blob *);475 ctr->values = talloc( ctr, struct regval_blob *); 527 476 } else { 528 ctr->values = TALLOC_REALLOC_ARRAY(ctr, ctr->values,477 ctr->values = talloc_realloc(ctr, ctr->values, 529 478 struct regval_blob *, 530 479 ctr->num_values+1); … … 664 613 return WERR_OK; 665 614 } 666 667 /***********************************************************************668 return the data_p as a uint32_t669 **********************************************************************/670 671 uint32_t regval_dword(struct regval_blob *val)672 {673 uint32_t data;674 675 data = IVAL( regval_data_p(val), 0 );676 677 return data;678 }679 680 /***********************************************************************681 return the data_p as a character string682 **********************************************************************/683 684 const char *regval_sz(struct regval_blob *val)685 {686 const char *data = NULL;687 DATA_BLOB blob = data_blob_const(regval_data_p(val), regval_size(val));688 689 pull_reg_sz(talloc_tos(), &blob, &data);690 691 return data;692 } -
vendor/current/source3/registry/reg_objects.h
r746 r988 48 48 WERROR regval_ctr_init(TALLOC_CTX *mem_ctx, struct regval_ctr **ctr); 49 49 int regval_ctr_numvals(struct regval_ctr *ctr); 50 struct regval_blob* dup_registry_value(struct regval_blob *val);51 void free_registry_value(struct regval_blob *val);52 50 uint8_t* regval_data_p(struct regval_blob *val); 53 51 uint32_t regval_size(struct regval_blob *val); … … 72 70 int regval_ctr_get_seqnum(struct regval_ctr *ctr); 73 71 WERROR regval_ctr_set_seqnum(struct regval_ctr *ctr, int seqnum); 74 uint32_t regval_dword(struct regval_blob *val);75 const char *regval_sz(struct regval_blob *val);76 72 77 73 -
vendor/current/source3/registry/reg_parse.c
r746 r988 35 35 36 36 #include <stdio.h> 37 #include <unistd.h>38 #include <wchar.h>39 37 #include <talloc.h> 40 38 #include <stdbool.h> 41 39 #include <string.h> 42 #include <sys/types.h>43 40 #include <regex.h> 44 41 #include <assert.h> … … 164 161 if (convert_string_talloc(p->valblob, CH_UNIX, CH_UTF16LE, 165 162 src, strlen(src)+1, 166 &dst, &dlen , true))163 &dst, &dlen)) 167 164 { 168 165 cbuf_swapptr(p->valblob, &dst, dlen); … … 623 620 624 621 size_t l = MIN(len/2, 64); 625 uint16_t* u = (uint16_t*)line;622 const uint16_t* u = (const uint16_t*)line; 626 623 int i; 627 624 … … 937 934 fd = open(fname, O_RDONLY); 938 935 if (fd < 0) { 939 DEBUG(0, ("reg_parse_file: open failed: %s\n", strerror(errno))); 936 DEBUG(0, ("reg_parse_file: open %s failed: %s\n", fname, 937 strerror(errno))); 940 938 return -1; 941 939 } -
vendor/current/source3/registry/reg_parse_internal.c
r740 r988 115 115 #endif 116 116 117 #define HIVE_INFO_ENTRY(SHORT,LONG) 118 staticconst struct hive_info HIVE_INFO_##SHORT = { \119 .handle = LONG, 120 .short_name = #SHORT, 121 .short_name_len = sizeof(#SHORT)-1, 122 .long_name = #LONG, 123 .long_name_len = sizeof(#LONG)-1, 117 #define HIVE_INFO_ENTRY(SHORT,LONG) \ 118 const struct hive_info HIVE_INFO_##SHORT = { \ 119 .handle = LONG, \ 120 .short_name = #SHORT, \ 121 .short_name_len = sizeof(#SHORT)-1, \ 122 .long_name = #LONG, \ 123 .long_name_len = sizeof(#LONG)-1, \ 124 124 } 125 125 … … 135 135 #undef HIVE_INFO_ENTRY 136 136 137 staticconst struct hive_info* HIVE_INFO[] = {137 const struct hive_info* HIVE_INFO[] = { 138 138 &HIVE_INFO_HKLM, &HIVE_INFO_HKCU, &HIVE_INFO_HKCR, &HIVE_INFO_HKU, 139 139 &HIVE_INFO_HKCC, &HIVE_INFO_HKDD, &HIVE_INFO_HKPD, &HIVE_INFO_HKPT, … … 141 141 }; 142 142 143 const struct hive_info* hive_info(const char* name, int nlen) 144 { 145 const struct hive_info** info; 146 char buf[32]; 147 int s; 148 149 if (nlen >= sizeof(buf)) { 150 return NULL; 151 } 152 for (s=0; s<nlen; s++) { 153 buf[s] = toupper(name[s]); 154 } 155 buf[s] = '\0'; 156 157 if ((s < 3) || (strncmp(buf, "HK", 2) != 0)) { 158 return NULL; 159 } 160 161 if (s <= 4) { 162 for(info = HIVE_INFO; *info; info++) { 163 if (strcmp(buf+2, (*info)->short_name+2) == 0) { 164 return *info; 143 #define TOINT(A,B) ((int)(A) << 8) + (int)(B) 144 145 bool srprs_hive(const char** ptr, const struct hive_info** result) 146 { 147 const char* str = *ptr; 148 const struct hive_info* info = NULL; 149 bool long_hive = false; 150 151 if ((toupper(str[0]) != 'H') || (toupper(str[1]) != 'K') 152 || (str[2] == '\0') ) 153 { 154 return false; 155 } 156 157 switch ( TOINT(toupper(str[2]), toupper(str[3])) ) { 158 case TOINT('E', 'Y'): 159 if (str[4] == '_') { 160 int i; 161 for (i=0; (info = HIVE_INFO[i]); i++) { 162 if (strncmp(&str[5], &info->long_name[5], 163 info->long_name_len-5) == 0) 164 { 165 long_hive = true; 166 break; 167 } 165 168 } 166 169 } 167 return NULL; 168 } 169 170 if ((s < 10) || (strncmp(buf, "HKEY_", 5)) != 0) { 171 return NULL; 172 } 173 174 for(info = HIVE_INFO; *info; info++) { 175 if (strcmp(buf+5, (*info)->long_name+5) == 0) { 176 return *info; 177 } 178 } 179 return NULL; 170 break; 171 case TOINT('L', 'M'): 172 info = &HIVE_INFO_HKLM; 173 break; 174 case TOINT('C', 'U'): 175 info = &HIVE_INFO_HKCU; 176 break; 177 case TOINT('C', 'R'): 178 info = &HIVE_INFO_HKCR; 179 break; 180 case TOINT('C', 'C'): 181 info = &HIVE_INFO_HKCC; 182 break; 183 case TOINT('D', 'D'): 184 info = &HIVE_INFO_HKDD; 185 break; 186 case TOINT('P', 'D'): 187 info = &HIVE_INFO_HKPD; 188 break; 189 case TOINT('P', 'T'): 190 info = &HIVE_INFO_HKPT; 191 break; 192 case TOINT('P', 'N'): 193 info = &HIVE_INFO_HKPN; 194 break; 195 default: 196 if (toupper(str[2]) == 'U') { 197 info = &HIVE_INFO_HKU; 198 } 199 break; 200 } 201 if (info != NULL) { 202 if (result != NULL) { 203 *result = info; 204 } 205 *ptr += long_hive ? info->long_name_len : info->short_name_len; 206 return true; 207 } 208 return false; 209 } 210 211 const struct hive_info* hive_info(const char* name) 212 { 213 const struct hive_info* info = NULL; 214 srprs_hive(&name, &info); 215 return info; 180 216 } 181 217 … … 265 301 charset_t ctype; 266 302 int len; 267 charseq[4];303 uint8_t seq[4]; 268 304 } BOM[] = { 269 305 {"UTF-8", CH_UTF8, 3, {0xEF, 0xBB, 0xBF}}, … … 314 350 } else { 315 351 for (i=0; BOM[i].name; i++) { 316 if ( StrCaseCmp(BOM[i].name, charset) == 0) {352 if (strcasecmp_m(BOM[i].name, charset) == 0) { 317 353 return fwrite(BOM[i].seq, 1, BOM[i].len, file); 318 354 } -
vendor/current/source3/registry/reg_parse_internal.h
r740 r988 39 39 # define smb_iconv_t iconv_t 40 40 # define smb_iconv(CD, IPTR, ILEN, OPTR, OLEN) \ 41 iconv(CD, (char**)(IPTR), ILEN, OPTR, OLEN)41 iconv(CD, discard_const_p(char*, (IPTR)), ILEN, OPTR, OLEN) 42 42 # define smb_iconv_open iconv_open 43 43 # define smb_iconv_close iconv_close … … 57 57 }; 58 58 59 const struct hive_info* hive_info(const char* name, int nlen); 59 extern const struct hive_info HIVE_INFO_HKLM; 60 extern const struct hive_info HIVE_INFO_HKCU; 61 extern const struct hive_info HIVE_INFO_HKCR; 62 extern const struct hive_info HIVE_INFO_HKU; 63 extern const struct hive_info HIVE_INFO_HKCC; 64 extern const struct hive_info HIVE_INFO_HKDD; 65 extern const struct hive_info HIVE_INFO_HKPD; 66 extern const struct hive_info HIVE_INFO_HKPT; 67 extern const struct hive_info HIVE_INFO_HKPN; 68 69 extern const struct hive_info* HIVE_INFO[]; 70 71 const struct hive_info* hive_info(const char* name); 72 bool srprs_hive(const char** ptr, const struct hive_info** result); 73 74 60 75 61 76 const char* get_charset(const char* c); -
vendor/current/source3/registry/reg_parse_prs.c
r740 r988 49 49 **/ 50 50 51 bool prs_init(prs_struct *ps, uint32 size, TALLOC_CTX *ctx, bool io)51 bool prs_init(prs_struct *ps, uint32_t size, TALLOC_CTX *ctx, bool io) 52 52 { 53 53 ZERO_STRUCTP(ps); … … 132 132 ********************************************************************/ 133 133 134 bool prs_grow(prs_struct *ps, uint32 extra_space)135 { 136 uint32 new_size;134 bool prs_grow(prs_struct *ps, uint32_t extra_space) 135 { 136 uint32_t new_size; 137 137 138 138 ps->grow_size = MAX(ps->grow_size, ps->data_offset + extra_space); … … 210 210 ********************************************************************/ 211 211 212 uint32 prs_data_size(prs_struct *ps)212 uint32_t prs_data_size(prs_struct *ps) 213 213 { 214 214 return ps->buffer_size; … … 219 219 ********************************************************************/ 220 220 221 uint32 prs_offset(prs_struct *ps)221 uint32_t prs_offset(prs_struct *ps) 222 222 { 223 223 return ps->data_offset; … … 228 228 ********************************************************************/ 229 229 230 bool prs_set_offset(prs_struct *ps, uint32 offset)230 bool prs_set_offset(prs_struct *ps, uint32_t offset) 231 231 { 232 232 if ((offset > ps->data_offset) … … 243 243 ********************************************************************/ 244 244 245 bool prs_copy_data_in(prs_struct *dst, const char *src, uint32 len)245 bool prs_copy_data_in(prs_struct *dst, const char *src, uint32_t len) 246 246 { 247 247 if (len == 0) … … 264 264 bool prs_align(prs_struct *ps) 265 265 { 266 uint32 mod = ps->data_offset & (ps->align-1);266 uint32_t mod = ps->data_offset & (ps->align-1); 267 267 268 268 if (ps->align != 0 && mod != 0) { 269 uint32 extra_space = (ps->align - mod);269 uint32_t extra_space = (ps->align - mod); 270 270 if(!prs_grow(ps, extra_space)) 271 271 return False; … … 284 284 { 285 285 bool ret; 286 uint8 old_align = ps->align;286 uint8_t old_align = ps->align; 287 287 288 288 ps->align = 8; … … 297 297 ********************************************************************/ 298 298 299 char *prs_mem_get(prs_struct *ps, uint32 extra_size)299 char *prs_mem_get(prs_struct *ps, uint32_t extra_size) 300 300 { 301 301 if(UNMARSHALLING(ps)) { … … 331 331 332 332 /******************************************************************* 333 Stream a uint8.334 ********************************************************************/335 336 bool prs_uint8(const char *name, prs_struct *ps, int depth, uint8 *data8)337 {338 char *q = prs_mem_get(ps, 1);339 if (q == NULL)340 return False;341 342 if (UNMARSHALLING(ps))343 *data8 = CVAL(q,0);344 else345 SCVAL(q,0,*data8);346 347 DEBUGADD(5,("%s%04x %s: %02x\n", tab_depth(5,depth), ps->data_offset, name, *data8));348 349 ps->data_offset += 1;350 351 return True;352 }353 354 /*******************************************************************355 333 Stream a uint16. 356 334 ********************************************************************/ 357 335 358 bool prs_uint16(const char *name, prs_struct *ps, int depth, uint16 *data16)359 { 360 char *q = prs_mem_get(ps, sizeof(uint16 ));336 bool prs_uint16(const char *name, prs_struct *ps, int depth, uint16_t *data16) 337 { 338 char *q = prs_mem_get(ps, sizeof(uint16_t)); 361 339 if (q == NULL) 362 340 return False; … … 376 354 DEBUGADD(5,("%s%04x %s: %04x\n", tab_depth(5,depth), ps->data_offset, name, *data16)); 377 355 378 ps->data_offset += sizeof(uint16 );356 ps->data_offset += sizeof(uint16_t); 379 357 380 358 return True; … … 385 363 ********************************************************************/ 386 364 387 bool prs_uint32(const char *name, prs_struct *ps, int depth, uint32 *data32)388 { 389 char *q = prs_mem_get(ps, sizeof(uint32 ));365 bool prs_uint32(const char *name, prs_struct *ps, int depth, uint32_t *data32) 366 { 367 char *q = prs_mem_get(ps, sizeof(uint32_t)); 390 368 if (q == NULL) 391 369 return False; … … 405 383 DEBUGADD(5,("%s%04x %s: %08x\n", tab_depth(5,depth), ps->data_offset, name, *data32)); 406 384 407 ps->data_offset += sizeof(uint32 );385 ps->data_offset += sizeof(uint32_t); 408 386 409 387 return True; … … 413 391 Stream a uint64_struct 414 392 ********************************************************************/ 415 bool prs_uint64(const char *name, prs_struct *ps, int depth, uint64 *data64)393 bool prs_uint64(const char *name, prs_struct *ps, int depth, uint64_t *data64) 416 394 { 417 395 if (UNMARSHALLING(ps)) { 418 uint32 high, low;396 uint32_t high, low; 419 397 420 398 if (!prs_uint32(name, ps, depth+1, &low)) … … 428 406 return True; 429 407 } else { 430 uint32 high = (*data64) >> 32, low = (*data64) & 0xFFFFFFFF;408 uint32_t high = (*data64) >> 32, low = (*data64) & 0xFFFFFFFF; 431 409 return prs_uint32(name, ps, depth+1, &low) && 432 410 prs_uint32(name, ps, depth+1, &high); … … 438 416 ********************************************************************/ 439 417 440 bool prs_uint8s(bool charmode, const char *name, prs_struct *ps, int depth, uint8 *data8s, int len)418 bool prs_uint8s(bool charmode, const char *name, prs_struct *ps, int depth, uint8_t *data8s, int len) 441 419 { 442 420 int i; -
vendor/current/source3/registry/reg_parse_prs.h
r740 r988 34 34 */ 35 35 bool bigendian_data; 36 uint8 align; /* data alignment */36 uint8_t align; /* data alignment */ 37 37 bool is_dynamic; /* Do we own this memory or not ? */ 38 uint32 data_offset; /* Current working offset into data. */39 uint32 buffer_size; /* Current allocated size of the buffer. */40 uint32 grow_size; /* size requested via prs_grow() calls */38 uint32_t data_offset; /* Current working offset into data. */ 39 uint32_t buffer_size; /* Current allocated size of the buffer. */ 40 uint32_t grow_size; /* size requested via prs_grow() calls */ 41 41 /* The buffer itself. If "is_dynamic" is true this 42 42 * MUST BE TALLOC'ed off mem_ctx. */ … … 58 58 59 59 void prs_debug(prs_struct *ps, int depth, const char *desc, const char *fn_name); 60 bool prs_init(prs_struct *ps, uint32 size, TALLOC_CTX *ctx, bool io);60 bool prs_init(prs_struct *ps, uint32_t size, TALLOC_CTX *ctx, bool io); 61 61 void prs_mem_free(prs_struct *ps); 62 62 char *prs_alloc_mem_(prs_struct *ps, size_t size, unsigned int count); 63 63 char *prs_alloc_mem(prs_struct *ps, size_t size, unsigned int count); 64 64 TALLOC_CTX *prs_get_mem_context(prs_struct *ps); 65 bool prs_grow(prs_struct *ps, uint32 extra_space);65 bool prs_grow(prs_struct *ps, uint32_t extra_space); 66 66 char *prs_data_p(prs_struct *ps); 67 uint32 prs_data_size(prs_struct *ps);68 uint32 prs_offset(prs_struct *ps);69 bool prs_set_offset(prs_struct *ps, uint32 offset);70 bool prs_copy_data_in(prs_struct *dst, const char *src, uint32 len);67 uint32_t prs_data_size(prs_struct *ps); 68 uint32_t prs_offset(prs_struct *ps); 69 bool prs_set_offset(prs_struct *ps, uint32_t offset); 70 bool prs_copy_data_in(prs_struct *dst, const char *src, uint32_t len); 71 71 bool prs_align(prs_struct *ps); 72 72 bool prs_align_uint64(prs_struct *ps); 73 char *prs_mem_get(prs_struct *ps, uint32 extra_size);73 char *prs_mem_get(prs_struct *ps, uint32_t extra_size); 74 74 void prs_switch_type(prs_struct *ps, bool io); 75 bool prs_uint8(const char *name, prs_struct *ps, int depth, uint8 *data8); 76 bool prs_uint16(const char *name, prs_struct *ps, int depth, uint16 *data16); 77 bool prs_uint32(const char *name, prs_struct *ps, int depth, uint32 *data32); 78 bool prs_uint64(const char *name, prs_struct *ps, int depth, uint64 *data64); 79 bool prs_uint8s(bool charmode, const char *name, prs_struct *ps, int depth, uint8 *data8s, int len); 75 bool prs_uint16(const char *name, prs_struct *ps, int depth, uint16_t *data16); 76 bool prs_uint32(const char *name, prs_struct *ps, int depth, uint32_t *data32); 77 bool prs_uint64(const char *name, prs_struct *ps, int depth, uint64_t *data64); 78 bool prs_uint8s(bool charmode, const char *name, prs_struct *ps, int depth, uint8_t *data8s, int len); 80 79 81 80 #endif -
vendor/current/source3/registry/reg_perfcount.c
r740 r988 42 42 *********************************************************************/ 43 43 44 /* returns perfcount path for dbname allocated on talloc_tos */ 44 45 static char *counters_directory(const char *dbname) 45 46 { 46 char *path = NULL; 47 char *dir_path = NULL; 48 char *db_subpath = NULL; 47 49 char *ret = NULL; 48 TALLOC_CTX *ctx = talloc_tos(); 49 50 path = state_path(PERFCOUNTDIR); 51 if (!directory_exist(path)) { 52 mkdir(path, 0755); 53 } 54 55 path = talloc_asprintf(ctx, "%s/%s", PERFCOUNTDIR, dbname); 56 if (!path) { 50 51 dir_path = state_path(PERFCOUNTDIR); 52 if (dir_path == NULL) { 57 53 return NULL; 58 54 } 59 55 60 ret = talloc_strdup(ctx, state_path(path)); 61 TALLOC_FREE(path); 56 if (!directory_create_or_exist(dir_path, 0755)) { 57 TALLOC_FREE(dir_path); 58 return NULL; 59 } 60 61 db_subpath = talloc_asprintf(dir_path, "%s/%s", PERFCOUNTDIR, dbname); 62 if (db_subpath == NULL) { 63 TALLOC_FREE(dir_path); 64 return NULL; 65 } 66 67 ret = state_path(db_subpath); 68 TALLOC_FREE(dir_path); 62 69 return ret; 63 70 } … … 66 73 *********************************************************************/ 67 74 68 uint32 reg_perfcount_get_base_index(void)69 { 70 c onst char *fname = counters_directory( NAMES_DB );75 uint32_t reg_perfcount_get_base_index(void) 76 { 77 char *fname; 71 78 TDB_CONTEXT *names; 72 79 TDB_DATA kbuf, dbuf; 73 80 char key[] = "1"; 74 uint32 retval = 0;81 uint32_t retval = 0; 75 82 char buf[PERFCOUNT_MAX_LEN]; 76 83 84 fname = counters_directory(NAMES_DB); 85 if (fname == NULL) { 86 return 0; 87 } 88 77 89 names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444); 78 90 79 91 if ( !names ) { 80 DEBUG(1, ("reg_perfcount_get_base_index: unable to open [%s].\n", fname)); 92 DEBUG(2, ("reg_perfcount_get_base_index: unable to open [%s].\n", fname)); 93 TALLOC_FREE(fname); 81 94 return 0; 82 } 95 } 83 96 /* needs to read the value of key "1" from the counter_names.tdb file, as that is 84 97 where the total number of counters is stored. We're assuming no holes in the … … 101 114 DEBUG(1, ("reg_perfcount_get_base_index: failed to find key \'1\' in [%s].\n", fname)); 102 115 tdb_close(names); 116 TALLOC_FREE(fname); 103 117 return 0; 104 118 } 105 else 106 { 107 tdb_close(names); 108 memset(buf, 0, PERFCOUNT_MAX_LEN); 109 memcpy(buf, dbuf.dptr, dbuf.dsize); 110 retval = (uint32)atoi(buf); 111 SAFE_FREE(dbuf.dptr); 112 return retval; 113 } 114 return 0; 115 } 116 117 /********************************************************************* 118 *********************************************************************/ 119 120 uint32 reg_perfcount_get_last_counter(uint32 base_index) 121 { 122 uint32 retval; 119 120 tdb_close(names); 121 TALLOC_FREE(fname); 122 memset(buf, 0, PERFCOUNT_MAX_LEN); 123 memcpy(buf, dbuf.dptr, dbuf.dsize); 124 retval = (uint32_t)atoi(buf); 125 SAFE_FREE(dbuf.dptr); 126 return retval; 127 } 128 129 /********************************************************************* 130 *********************************************************************/ 131 132 uint32_t reg_perfcount_get_last_counter(uint32_t base_index) 133 { 134 uint32_t retval; 123 135 124 136 if(base_index == 0) … … 133 145 *********************************************************************/ 134 146 135 uint32 reg_perfcount_get_last_help(uint32last_counter)136 { 137 uint32 retval;147 uint32_t reg_perfcount_get_last_help(uint32_t last_counter) 148 { 149 uint32_t retval; 138 150 139 151 if(last_counter == 0) … … 149 161 *********************************************************************/ 150 162 151 static uint32 _reg_perfcount_multi_sz_from_tdb(TDB_CONTEXT *tdb,163 static uint32_t _reg_perfcount_multi_sz_from_tdb(TDB_CONTEXT *tdb, 152 164 int keyval, 153 165 char **retbuf, 154 uint32 buffer_size)166 uint32_t buffer_size) 155 167 { 156 168 TDB_DATA kbuf, dbuf; 157 169 char temp[256]; 158 170 char *buf1 = *retbuf; 159 uint32 working_size = 0;171 uint32_t working_size = 0; 160 172 DATA_BLOB name_index, name; 173 bool ok; 161 174 162 175 memset(temp, 0, sizeof(temp)); … … 173 186 } 174 187 /* First encode the name_index */ 175 working_size = (kbuf.dsize + 1)*sizeof(uint16 );188 working_size = (kbuf.dsize + 1)*sizeof(uint16_t); 176 189 buf1 = (char *)SMB_REALLOC(buf1, buffer_size + working_size); 177 190 if(!buf1) { … … 179 192 return buffer_size; 180 193 } 181 push_reg_sz(talloc_tos(), &name_index, (const char *)kbuf.dptr); 194 ok = push_reg_sz(talloc_tos(), &name_index, (const char *)kbuf.dptr); 195 if (!ok) { 196 buffer_size = 0; 197 return buffer_size; 198 } 182 199 memcpy(buf1+buffer_size, (char *)name_index.data, working_size); 183 200 buffer_size += working_size; 184 201 /* Now encode the actual name */ 185 working_size = (dbuf.dsize + 1)*sizeof(uint16 );202 working_size = (dbuf.dsize + 1)*sizeof(uint16_t); 186 203 buf1 = (char *)SMB_REALLOC(buf1, buffer_size + working_size); 187 204 if(!buf1) { … … 192 209 memcpy(temp, dbuf.dptr, dbuf.dsize); 193 210 SAFE_FREE(dbuf.dptr); 194 push_reg_sz(talloc_tos(), &name, temp); 211 ok = push_reg_sz(talloc_tos(), &name, temp); 212 if (!ok) { 213 buffer_size = 0; 214 return buffer_size; 215 } 195 216 memcpy(buf1+buffer_size, (char *)name.data, working_size); 196 217 buffer_size += working_size; … … 204 225 *********************************************************************/ 205 226 206 uint32 reg_perfcount_get_counter_help(uint32base_index, char **retbuf)227 uint32_t reg_perfcount_get_counter_help(uint32_t base_index, char **retbuf) 207 228 { 208 229 char *buf1 = NULL; 209 uint32 buffer_size = 0;230 uint32_t buffer_size = 0; 210 231 TDB_CONTEXT *names; 211 c onst char *fname = counters_directory( NAMES_DB );232 char *fname; 212 233 int i; 213 234 214 if (base_index == 0)235 if (base_index == 0) { 215 236 return 0; 237 } 238 239 fname = counters_directory(NAMES_DB); 240 if (fname == NULL) { 241 return 0; 242 } 216 243 217 244 names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444); 218 245 219 if(names == NULL) 220 { 246 if (names == NULL) { 221 247 DEBUG(1, ("reg_perfcount_get_counter_help: unable to open [%s].\n", fname)); 248 TALLOC_FREE(fname); 222 249 return 0; 223 } 250 } 251 TALLOC_FREE(fname); 224 252 225 253 for(i = 1; i <= base_index; i++) … … 247 275 *********************************************************************/ 248 276 249 uint32 reg_perfcount_get_counter_names(uint32base_index, char **retbuf)277 uint32_t reg_perfcount_get_counter_names(uint32_t base_index, char **retbuf) 250 278 { 251 279 char *buf1 = NULL; 252 uint32 buffer_size = 0;280 uint32_t buffer_size = 0; 253 281 TDB_CONTEXT *names; 254 c onst char *fname = counters_directory( NAMES_DB );282 char *fname; 255 283 int i; 256 284 257 if (base_index == 0)285 if (base_index == 0) { 258 286 return 0; 287 } 288 289 fname = counters_directory(NAMES_DB); 290 if (fname == NULL) { 291 return 0; 292 } 259 293 260 294 names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444); 261 295 262 if(names == NULL) 263 { 296 if (names == NULL) { 264 297 DEBUG(1, ("reg_perfcount_get_counter_names: unable to open [%s].\n", fname)); 298 TALLOC_FREE(fname); 265 299 return 0; 266 } 300 } 301 TALLOC_FREE(fname); 267 302 268 303 buffer_size = _reg_perfcount_multi_sz_from_tdb(names, 1, retbuf, buffer_size); … … 342 377 *********************************************************************/ 343 378 344 static uint32 _reg_perfcount_get_numinst(int objInd, TDB_CONTEXT *names)379 static uint32_t _reg_perfcount_get_numinst(int objInd, TDB_CONTEXT *names) 345 380 { 346 381 TDB_DATA key, data; … … 351 386 352 387 if(data.dptr == NULL) 353 return (uint32 )PERF_NO_INSTANCES;388 return (uint32_t)PERF_NO_INSTANCES; 354 389 355 390 memset(buf, 0, PERFCOUNT_MAX_LEN); 356 391 memcpy(buf, data.dptr, data.dsize); 357 392 SAFE_FREE(data.dptr); 358 return (uint32 )atoi(buf);393 return (uint32_t)atoi(buf); 359 394 } 360 395 … … 377 412 struct PERF_OBJECT_TYPE *obj; 378 413 379 block->objects = (struct PERF_OBJECT_TYPE *) TALLOC_REALLOC_ARRAY(mem_ctx,414 block->objects = (struct PERF_OBJECT_TYPE *)talloc_realloc(mem_ctx, 380 415 block->objects, 381 416 struct PERF_OBJECT_TYPE, … … 394 429 block->objects[block->NumObjectTypes].counters = NULL; 395 430 block->objects[block->NumObjectTypes].instances = NULL; 396 block->objects[block->NumObjectTypes].counter_data.ByteLength = sizeof(uint32 );431 block->objects[block->NumObjectTypes].counter_data.ByteLength = sizeof(uint32_t); 397 432 block->objects[block->NumObjectTypes].counter_data.data = NULL; 398 433 block->objects[block->NumObjectTypes].DetailLevel = PERF_DETAIL_NOVICE; … … 412 447 { 413 448 TDB_CONTEXT *counters; 414 const char *fname = counters_directory( DATA_DB ); 449 char *fname; 450 451 fname = counters_directory(DATA_DB); 452 if (fname == NULL) { 453 return false; 454 } 415 455 416 456 counters = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444); 417 457 418 if(counters == NULL) 419 { 458 if (counters == NULL) { 420 459 DEBUG(1, ("reg_perfcount_get_counter_data: unable to open [%s].\n", fname)); 421 return False; 422 } 460 TALLOC_FREE(fname); 461 return False; 462 } 463 TALLOC_FREE(fname); 423 464 424 465 *data = tdb_fetch(counters, key); … … 432 473 *********************************************************************/ 433 474 434 static uint32 _reg_perfcount_get_size_field(uint32CounterType)435 { 436 uint32 retval;475 static uint32_t _reg_perfcount_get_size_field(uint32_t CounterType) 476 { 477 uint32_t retval; 437 478 438 479 retval = CounterType; … … 449 490 *********************************************************************/ 450 491 451 static uint32 _reg_perfcount_compute_scale(int64_t data)492 static uint32_t _reg_perfcount_compute_scale(int64_t data) 452 493 { 453 494 int scale = 0; … … 465 506 } 466 507 467 return (uint32 )scale;508 return (uint32_t)scale; 468 509 } 469 510 … … 482 523 long int data32, dbuf[2]; 483 524 int64_t data64; 484 uint32 counter_size;525 uint32_t counter_size; 485 526 486 527 obj->counters[obj->NumCounters].DefaultScale = 0; … … 548 589 549 590 obj->counter_data.ByteLength += dsize + padding; 550 obj->counter_data.data = TALLOC_REALLOC_ARRAY(mem_ctx,591 obj->counter_data.data = talloc_realloc(mem_ctx, 551 592 obj->counter_data.data, 552 uint8 ,553 obj->counter_data.ByteLength - sizeof(uint32 ));593 uint8_t, 594 obj->counter_data.ByteLength - sizeof(uint32_t)); 554 595 if(obj->counter_data.data == NULL) 555 596 return False; … … 557 598 { 558 599 memcpy((void *)(obj->counter_data.data + 559 (obj->counter_data.ByteLength - (sizeof(uint32 ) + dsize))),600 (obj->counter_data.ByteLength - (sizeof(uint32_t) + dsize))), 560 601 (const void *)dbuf, dsize); 561 602 } … … 564 605 /* Handling PERF_SIZE_VARIABLE_LEN */ 565 606 memcpy((void *)(obj->counter_data.data + 566 (obj->counter_data.ByteLength - (sizeof(uint32 ) + dsize))),607 (obj->counter_data.ByteLength - (sizeof(uint32_t) + dsize))), 567 608 (const void *)buf, dsize); 568 609 } … … 636 677 return False; 637 678 } 638 obj->counters = (struct PERF_COUNTER_DEFINITION *) TALLOC_REALLOC_ARRAY(mem_ctx,679 obj->counters = (struct PERF_COUNTER_DEFINITION *)talloc_realloc(mem_ctx, 639 680 obj->counters, 640 681 struct PERF_COUNTER_DEFINITION, … … 688 729 } 689 730 inst->counter_data.ByteLength = data.dsize + sizeof(inst->counter_data.ByteLength); 690 inst->counter_data.data = TALLOC_REALLOC_ARRAY(mem_ctx,731 inst->counter_data.data = talloc_realloc(mem_ctx, 691 732 inst->counter_data.data, 692 uint8 ,733 uint8_t, 693 734 data.dsize); 694 735 if(inst->counter_data.data == NULL) … … 720 761 return False; 721 762 } 722 inst->data = TALLOC_REALLOC_ARRAY(mem_ctx,763 inst->data = talloc_realloc(mem_ctx, 723 764 inst->data, 724 uint8 ,765 uint8_t, 725 766 inst->NameLength); 726 767 if (inst->data == NULL) { … … 735 776 inst->ParentObjectTitlePointer = 0; 736 777 inst->UniqueID = PERF_NO_UNIQUE_ID; 737 inst->NameOffset = 6 * sizeof(uint32 );778 inst->NameOffset = 6 * sizeof(uint32_t); 738 779 739 780 inst->ByteLength = inst->NameOffset + inst->NameLength; … … 742 783 { 743 784 pad = 8 - pad; 744 inst->data = TALLOC_REALLOC_ARRAY(mem_ctx,785 inst->data = talloc_realloc(mem_ctx, 745 786 inst->data, 746 uint8 ,787 uint8_t, 747 788 inst->NameLength + pad); 748 789 memset(inst->data + inst->NameLength, 0, pad); … … 764 805 765 806 if(obj->instances == NULL) { 766 obj->instances = TALLOC_REALLOC_ARRAY(mem_ctx,807 obj->instances = talloc_realloc(mem_ctx, 767 808 obj->instances, 768 809 struct PERF_INSTANCE_DEFINITION, … … 857 898 TDB_CONTEXT *counters; 858 899 bool status = False; 859 const char *fname = counters_directory( DATA_DB ); 900 char *fname; 901 902 fname = counters_directory(DATA_DB); 903 if (fname == NULL) { 904 return false; 905 } 860 906 861 907 counters = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444); 862 908 863 if(counters == NULL) 864 { 909 if (counters == NULL) { 865 910 DEBUG(1, ("reg_perfcount_init_data_block_perf: unable to open [%s].\n", fname)); 866 return False; 867 } 911 TALLOC_FREE(fname); 912 return False; 913 } 914 TALLOC_FREE(fname); 868 915 869 916 status = _reg_perfcount_get_64(&PerfFreq, names, 0, "PerfFreq"); … … 920 967 { 921 968 smb_ucs2_t *temp = NULL; 969 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); 922 970 time_t tm; 923 924 if (rpcstr_push_talloc(mem_ctx, &temp, "PERF")==(size_t)-1) { 925 return false; 926 } 927 if (!temp) { 928 return false; 971 size_t sz; 972 973 sz = rpcstr_push_talloc(tmp_ctx, &temp, "PERF"); 974 if ((sz == -1) || (temp == NULL)) { 975 goto err_out; 929 976 } 930 977 memcpy(block->Signature, temp, strlen_w(temp) *2); … … 943 990 make_systemtime(&(block->SystemTime), gmtime(&tm)); 944 991 _reg_perfcount_init_data_block_perf(block, names); 945 memset(temp, 0, sizeof(temp)); 946 rpcstr_push((void *)temp, global_myname(), sizeof(temp), STR_TERMINATE); 992 993 sz = rpcstr_push_talloc(tmp_ctx, &temp, lp_netbios_name()); 994 if ((sz == -1) || (temp == NULL)) { 995 goto err_out; 996 } 947 997 block->SystemNameLength = (strlen_w(temp) * 2) + 2; 948 block->data = TALLOC_ZERO_ARRAY(mem_ctx, uint8, block->SystemNameLength + (8 - (block->SystemNameLength % 8)));998 block->data = talloc_zero_array(mem_ctx, uint8_t, block->SystemNameLength + (8 - (block->SystemNameLength % 8))); 949 999 if (block->data == NULL) { 950 return False;1000 goto err_out; 951 1001 } 952 1002 memcpy(block->data, temp, block->SystemNameLength); … … 956 1006 so that the PERF_OBJECT_TYPE struct comes out 64-bit aligned */ 957 1007 block->HeaderLength += 8 - (block->HeaderLength % 8); 958 959 return True; 960 } 961 962 /********************************************************************* 963 *********************************************************************/ 964 965 static uint32 _reg_perfcount_perf_data_block_fixup(struct PERF_DATA_BLOCK *block, TALLOC_CTX *mem_ctx) 1008 talloc_free(tmp_ctx); 1009 1010 return true; 1011 1012 err_out: 1013 talloc_free(tmp_ctx); 1014 return false; 1015 } 1016 1017 /********************************************************************* 1018 *********************************************************************/ 1019 1020 static uint32_t _reg_perfcount_perf_data_block_fixup(struct PERF_DATA_BLOCK *block, TALLOC_CTX *mem_ctx) 966 1021 { 967 1022 int obj, cnt, inst, pad, i; … … 994 1049 counter = &(object[obj].counters[object[obj].NumCounters - 1]); 995 1050 counter_data->ByteLength = counter->CounterOffset + counter->CounterSize + sizeof(counter_data->ByteLength); 996 temp = TALLOC_REALLOC_ARRAY(mem_ctx,1051 temp = talloc_realloc(mem_ctx, 997 1052 temp, 998 1053 char, … … 1015 1070 pad = 8 - pad; 1016 1071 } 1017 counter_data->data = TALLOC_REALLOC_ARRAY(mem_ctx,1072 counter_data->data = talloc_realloc(mem_ctx, 1018 1073 counter_data->data, 1019 uint8 ,1074 uint8_t, 1020 1075 counter_data->ByteLength - sizeof(counter_data->ByteLength) + pad); 1021 1076 if (counter_data->data == NULL) { … … 1035 1090 { 1036 1091 pad = 8 - pad; 1037 object[obj].counter_data.data = TALLOC_REALLOC_ARRAY(mem_ctx,1092 object[obj].counter_data.data = talloc_realloc(mem_ctx, 1038 1093 object[obj].counter_data.data, 1039 uint8 ,1094 uint8_t, 1040 1095 object[obj].counter_data.ByteLength + pad); 1041 1096 memset((void *)(object[obj].counter_data.data + object[obj].counter_data.ByteLength), 0, pad); … … 1057 1112 *********************************************************************/ 1058 1113 1059 static uint32 reg_perfcount_get_perf_data_block(uint32base_index,1114 static uint32_t reg_perfcount_get_perf_data_block(uint32_t base_index, 1060 1115 TALLOC_CTX *mem_ctx, 1061 1116 struct PERF_DATA_BLOCK *block, … … 1063 1118 bool bigendian_data) 1064 1119 { 1065 uint32 buffer_size = 0;1066 c onst char *fname = counters_directory( NAMES_DB );1120 uint32_t buffer_size = 0; 1121 char *fname; 1067 1122 TDB_CONTEXT *names; 1068 1123 int retval = 0; 1069 1124 1125 fname = counters_directory(NAMES_DB); 1126 if (fname == NULL) { 1127 return 0; 1128 } 1129 1070 1130 names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444); 1071 1131 … … 1073 1133 { 1074 1134 DEBUG(1, ("reg_perfcount_get_perf_data_block: unable to open [%s].\n", fname)); 1135 TALLOC_FREE(fname); 1075 1136 return 0; 1076 1137 } 1138 TALLOC_FREE(fname); 1077 1139 1078 1140 if (!_reg_perfcount_init_data_block(block, mem_ctx, names, bigendian_data)) { … … 1082 1144 } 1083 1145 1084 reg_perfcount_get_last_counter(base_index); 1085 1086 if(object_ids == NULL) 1087 { 1088 /* we're getting a request for "Global" here */ 1089 retval = _reg_perfcount_assemble_global(block, mem_ctx, base_index, names); 1090 } 1091 else 1092 { 1093 /* we're getting a request for a specific set of PERF_OBJECT_TYPES */ 1094 retval = _reg_perfcount_assemble_global(block, mem_ctx, base_index, names); 1095 } 1146 retval = _reg_perfcount_assemble_global(block, mem_ctx, base_index, names); 1147 1096 1148 buffer_size = _reg_perfcount_perf_data_block_fixup(block, mem_ctx); 1097 1149 … … 1243 1295 if(!prs_uint32("ByteLength", ps, depth, &counter_data.ByteLength)) 1244 1296 return False; 1245 if(!prs_uint8s(False, "CounterData", ps, depth, counter_data.data, counter_data.ByteLength - sizeof(uint32 )))1297 if(!prs_uint8s(False, "CounterData", ps, depth, counter_data.data, counter_data.ByteLength - sizeof(uint32_t))) 1246 1298 return False; 1247 1299 if(!prs_align_uint64(ps)) … … 1365 1417 *********************************************************************/ 1366 1418 1367 WERROR reg_perfcount_get_hkpd(prs_struct *ps, uint32 max_buf_size, uint32*outbuf_len, const char *object_ids)1419 WERROR reg_perfcount_get_hkpd(prs_struct *ps, uint32_t max_buf_size, uint32_t *outbuf_len, const char *object_ids) 1368 1420 { 1369 1421 /* … … 1376 1428 */ 1377 1429 struct PERF_DATA_BLOCK block; 1378 uint32 buffer_size, base_index;1430 uint32_t buffer_size, base_index; 1379 1431 1380 1432 buffer_size = 0; -
vendor/current/source3/registry/reg_perfcount.h
r740 r988 25 25 #include "reg_parse_prs.h" 26 26 27 uint32 reg_perfcount_get_base_index(void);28 uint32 reg_perfcount_get_last_counter(uint32base_index);29 uint32 reg_perfcount_get_last_help(uint32last_counter);30 uint32 reg_perfcount_get_counter_help(uint32base_index, char **retbuf);31 uint32 reg_perfcount_get_counter_names(uint32base_index, char **retbuf);32 WERROR reg_perfcount_get_hkpd(prs_struct *ps, uint32 max_buf_size, uint32*outbuf_len, const char *object_ids);27 uint32_t reg_perfcount_get_base_index(void); 28 uint32_t reg_perfcount_get_last_counter(uint32_t base_index); 29 uint32_t reg_perfcount_get_last_help(uint32_t last_counter); 30 uint32_t reg_perfcount_get_counter_help(uint32_t base_index, char **retbuf); 31 uint32_t reg_perfcount_get_counter_names(uint32_t base_index, char **retbuf); 32 WERROR reg_perfcount_get_hkpd(prs_struct *ps, uint32_t max_buf_size, uint32_t *outbuf_len, const char *object_ids); 33 33 34 34 #endif /* _REG_PERFCOUNT_H */ -
vendor/current/source3/registry/reg_util_internal.c
r740 r988 98 98 99 99 /* skip leading '\' chars */ 100 p = (char *)keyname; 101 while (*p == '\\') { 102 p++; 100 while (*keyname == '\\') { 101 keyname++; 103 102 } 104 103 105 nkeyname = talloc_strdup(ctx, p);104 nkeyname = talloc_strdup(ctx, keyname); 106 105 if (nkeyname == NULL) { 107 106 return NULL; … … 115 114 } 116 115 117 strupper_m(nkeyname); 116 if (!strupper_m(nkeyname)) { 117 TALLOC_FREE(nkeyname); 118 return NULL; 119 } 118 120 119 121 return nkeyname; -
vendor/current/source3/registry/reg_util_token.c
r740 r988 39 39 } 40 40 41 token = TALLOC_ZERO_P(mem_ctx, struct security_token);41 token = talloc_zero(mem_ctx, struct security_token); 42 42 if (token == NULL) { 43 43 DEBUG(1, ("talloc failed\n")); -
vendor/current/source3/registry/regfio.c
r746 r988 23 23 #include "../librpc/gen_ndr/ndr_security.h" 24 24 #include "../libcli/security/security_descriptor.h" 25 #include "../libcli/security/secdesc.h" 25 26 26 27 #undef DBGC_CLASS … … 45 46 static bool smb_io_time(const char *desc, NTTIME *nttime, prs_struct *ps, int depth) 46 47 { 47 uint32 low, high;48 uint32_t low, high; 48 49 if (nttime == NULL) 49 50 return False; … … 75 76 *******************************************************************/ 76 77 77 static int write_block( REGF_FILE *file, prs_struct *ps, uint32 offset )78 static int write_block( REGF_FILE *file, prs_struct *ps, uint32_t offset ) 78 79 { 79 80 int bytes_written, returned; 80 81 char *buffer = prs_data_p( ps ); 81 uint32 buffer_size = prs_data_size( ps );82 uint32_t buffer_size = prs_data_size( ps ); 82 83 SMB_STRUCT_STAT sbuf; 83 84 … … 113 114 *******************************************************************/ 114 115 115 static int read_block( REGF_FILE *file, prs_struct *ps, uint32 file_offset, uint32block_size )116 static int read_block( REGF_FILE *file, prs_struct *ps, uint32_t file_offset, uint32_t block_size ) 116 117 { 117 118 int bytes_read, returned; … … 199 200 200 201 if ( hbin->free_off != REGF_OFFSET_NONE ) { 201 uint32 header = 0xffffffff;202 203 if ( !prs_set_offset( &hbin->ps, hbin->free_off-sizeof(uint32 ) ) )202 uint32_t header = 0xffffffff; 203 204 if ( !prs_set_offset( &hbin->ps, hbin->free_off-sizeof(uint32_t) ) ) 204 205 return False; 205 206 if ( !prs_uint32( "free_size", &hbin->ps, 0, &hbin->free_size ) ) … … 224 225 225 226 for ( p=file->block_list; p && p!=hbin; p=p->next ) 226 ; ;227 ; 227 228 228 229 if ( p == hbin ) { … … 246 247 depth++; 247 248 248 if ( !prs_uint8s( True, "header", ps, depth, (uint8 *)file->header, sizeof( file->header )) )249 if ( !prs_uint8s( True, "header", ps, depth, (uint8_t *)file->header, sizeof( file->header )) ) 249 250 return False; 250 251 … … 303 304 static bool prs_hbin_block( const char *desc, prs_struct *ps, int depth, REGF_HBIN *hbin ) 304 305 { 305 uint32 block_size2;306 uint32_t block_size2; 306 307 307 308 prs_debug(ps, depth, desc, "prs_regf_block"); 308 309 depth++; 309 310 310 if ( !prs_uint8s( True, "header", ps, depth, (uint8 *)hbin->header, sizeof( hbin->header )) )311 if ( !prs_uint8s( True, "header", ps, depth, (uint8_t*)hbin->header, sizeof( hbin->header )) ) 311 312 return False; 312 313 … … 338 339 static bool prs_nk_rec( const char *desc, prs_struct *ps, int depth, REGF_NK_REC *nk ) 339 340 { 340 uint16 class_length, name_length;341 uint32 start;342 uint32 data_size, start_off, end_off;343 uint32 unknown_off = REGF_OFFSET_NONE;341 uint16_t class_length, name_length; 342 uint32_t start; 343 uint32_t data_size, start_off, end_off; 344 uint32_t unknown_off = REGF_OFFSET_NONE; 344 345 345 346 nk->hbin_off = prs_offset( ps ); … … 351 352 /* back up and get the data_size */ 352 353 353 if ( !prs_set_offset( ps, prs_offset(ps)-sizeof(uint32 )) )354 if ( !prs_set_offset( ps, prs_offset(ps)-sizeof(uint32_t)) ) 354 355 return False; 355 356 start_off = prs_offset( ps ); … … 357 358 return False; 358 359 359 if ( !prs_uint8s( True, "header", ps, depth, (uint8 *)nk->header, sizeof( nk->header )) )360 if ( !prs_uint8s( True, "header", ps, depth, (uint8_t *)nk->header, sizeof( nk->header )) ) 360 361 return False; 361 362 … … 418 419 } 419 420 420 if ( !prs_uint8s( True, "name", ps, depth, (uint8 *)nk->keyname, name_length) )421 if ( !prs_uint8s( True, "name", ps, depth, (uint8_t *)nk->keyname, name_length) ) 421 422 return False; 422 423 … … 442 443 *******************************************************************/ 443 444 444 static uint32 regf_block_checksum( prs_struct *ps )445 static uint32_t regf_block_checksum( prs_struct *ps ) 445 446 { 446 447 char *buffer = prs_data_p( ps ); 447 uint32 checksum, x;448 uint32_t checksum, x; 448 449 int i; 449 450 … … 466 467 { 467 468 prs_struct ps; 468 uint32 checksum;469 uint32_t checksum; 469 470 470 471 /* grab the first block from the file */ … … 496 497 { 497 498 REGF_HBIN *hbin; 498 uint32 record_size, curr_off, block_size, header;499 500 if ( !(hbin = TALLOC_ZERO_P(file->mem_ctx, REGF_HBIN)) )499 uint32_t record_size, curr_off, block_size, header; 500 501 if ( !(hbin = talloc_zero(file->mem_ctx, REGF_HBIN)) ) 501 502 return NULL; 502 503 hbin->file_off = offset; … … 521 522 /* remember that the record_size is in the 4 bytes preceeding the record itself */ 522 523 523 if ( !prs_set_offset( &hbin->ps, file->data_offset+HBIN_HDR_SIZE-sizeof(uint32 ) ) )524 return False;524 if ( !prs_set_offset( &hbin->ps, file->data_offset+HBIN_HDR_SIZE-sizeof(uint32_t) ) ) 525 return NULL; 525 526 526 527 record_size = 0; … … 545 546 546 547 if ( !prs_set_offset( &hbin->ps, curr_off) ) 547 return False;548 return NULL; 548 549 549 550 if ( !prs_uint32( "rec_size", &hbin->ps, 0, &record_size ) ) 550 return False;551 return NULL; 551 552 if ( !prs_uint32( "header", &hbin->ps, 0, &header ) ) 552 return False;553 return NULL; 553 554 554 555 SMB_ASSERT( record_size != 0 ); … … 567 568 record header */ 568 569 569 hbin->free_off = curr_off + sizeof(uint32 );570 hbin->free_off = curr_off + sizeof(uint32_t); 570 571 hbin->free_size = record_size; 571 572 } … … 574 575 575 576 if ( !prs_set_offset( &hbin->ps, file->data_offset+HBIN_HDR_SIZE ) ) 576 return False;577 return NULL; 577 578 578 579 return hbin; … … 584 585 *******************************************************************/ 585 586 586 static bool hbin_contains_offset( REGF_HBIN *hbin, uint32 offset )587 static bool hbin_contains_offset( REGF_HBIN *hbin, uint32_t offset ) 587 588 { 588 589 if ( !hbin ) … … 600 601 *******************************************************************/ 601 602 602 static REGF_HBIN* lookup_hbin_block( REGF_FILE *file, uint32 offset )603 static REGF_HBIN* lookup_hbin_block( REGF_FILE *file, uint32_t offset ) 603 604 { 604 605 REGF_HBIN *hbin = NULL; 605 uint32 block_off;606 uint32_t block_off; 606 607 607 608 /* start with the open list */ … … 659 660 int i; 660 661 REGF_LF_REC *lf = &nk->subkeys; 661 uint32 data_size, start_off, end_off;662 uint32_t data_size, start_off, end_off; 662 663 663 664 prs_debug(&hbin->ps, depth, desc, "prs_lf_records"); … … 676 677 /* backup and get the data_size */ 677 678 678 if ( !prs_set_offset( &hbin->ps, prs_offset(&hbin->ps)-sizeof(uint32 )) )679 if ( !prs_set_offset( &hbin->ps, prs_offset(&hbin->ps)-sizeof(uint32_t)) ) 679 680 return False; 680 681 start_off = prs_offset( &hbin->ps ); … … 682 683 return False; 683 684 684 if ( !prs_uint8s( True, "header", &hbin->ps, depth, (uint8 *)lf->header, sizeof( lf->header )) )685 if ( !prs_uint8s( True, "header", &hbin->ps, depth, (uint8_t *)lf->header, sizeof( lf->header )) ) 685 686 return False; 686 687 … … 722 723 { 723 724 prs_struct *ps = &hbin->ps; 724 uint16 tag = 0xFFFF;725 uint32 data_size, start_off, end_off;725 uint16_t tag = 0xFFFF; 726 uint32_t data_size, start_off, end_off; 726 727 727 728 … … 734 735 /* backup and get the data_size */ 735 736 736 if ( !prs_set_offset( &hbin->ps, prs_offset(&hbin->ps)-sizeof(uint32 )) )737 if ( !prs_set_offset( &hbin->ps, prs_offset(&hbin->ps)-sizeof(uint32_t)) ) 737 738 return False; 738 739 start_off = prs_offset( &hbin->ps ); … … 740 741 return False; 741 742 742 if ( !prs_uint8s( True, "header", ps, depth, (uint8 *)sk->header, sizeof( sk->header )) )743 if ( !prs_uint8s( True, "header", ps, depth, (uint8_t *)sk->header, sizeof( sk->header )) ) 743 744 return False; 744 745 if ( !prs_uint16( "tag", ps, depth, &tag)) … … 768 769 return False; 769 770 } else { 770 blob = data_blob_const(prs_data_p(&hbin->ps), 771 prs_data_size(&hbin->ps)); 771 blob = data_blob_const( 772 prs_data_p(&hbin->ps) + prs_offset(&hbin->ps), 773 prs_data_size(&hbin->ps) - prs_offset(&hbin->ps) 774 ); 772 775 status = unmarshall_sec_desc(mem_ctx, 773 776 blob.data, blob.length, … … 798 801 static bool hbin_prs_vk_rec( const char *desc, REGF_HBIN *hbin, int depth, REGF_VK_REC *vk, REGF_FILE *file ) 799 802 { 800 uint32 offset;801 uint16 name_length;803 uint32_t offset; 804 uint16_t name_length; 802 805 prs_struct *ps = &hbin->ps; 803 uint32 data_size, start_off, end_off;806 uint32_t data_size, start_off, end_off; 804 807 805 808 prs_debug(ps, depth, desc, "prs_vk_rec"); … … 808 811 /* backup and get the data_size */ 809 812 810 if ( !prs_set_offset( &hbin->ps, prs_offset(&hbin->ps)-sizeof(uint32 )) )813 if ( !prs_set_offset( &hbin->ps, prs_offset(&hbin->ps)-sizeof(uint32_t)) ) 811 814 return False; 812 815 start_off = prs_offset( &hbin->ps ); … … 814 817 return False; 815 818 816 if ( !prs_uint8s( True, "header", ps, depth, (uint8 *)vk->header, sizeof( vk->header )) )819 if ( !prs_uint8s( True, "header", ps, depth, (uint8_t *)vk->header, sizeof( vk->header )) ) 817 820 return False; 818 821 … … 843 846 return False; 844 847 } 845 if ( !prs_uint8s( True, "name", ps, depth, (uint8 *)vk->valuename, name_length ) )848 if ( !prs_uint8s( True, "name", ps, depth, (uint8_t *)vk->valuename, name_length ) ) 846 849 return False; 847 850 } … … 861 864 if ( !(vk->data_size & VK_DATA_IN_OFFSET) ) { 862 865 REGF_HBIN *hblock = hbin; 863 uint32 data_rec_size;866 uint32_t data_rec_size; 864 867 865 868 if ( UNMARSHALLING(&hbin->ps) ) { 866 if ( !(vk->data = PRS_ALLOC_MEM( ps, uint8 , vk->data_size) ) )869 if ( !(vk->data = PRS_ALLOC_MEM( ps, uint8_t, vk->data_size) ) ) 867 870 return False; 868 871 } … … 873 876 return False; 874 877 } 875 if ( !(prs_set_offset( &hblock->ps, (vk->data_off+HBIN_HDR_SIZE-hblock->first_hbin_off)-sizeof(uint32 ) )) )878 if ( !(prs_set_offset( &hblock->ps, (vk->data_off+HBIN_HDR_SIZE-hblock->first_hbin_off)-sizeof(uint32_t) )) ) 876 879 return False; 877 880 878 881 if ( MARSHALLING(&hblock->ps) ) { 879 data_rec_size = ( (vk->data_size+sizeof(uint32 )) & 0xfffffff8 ) + 8;882 data_rec_size = ( (vk->data_size+sizeof(uint32_t)) & 0xfffffff8 ) + 8; 880 883 data_rec_size = ( data_rec_size - 1 ) ^ 0xFFFFFFFF; 881 884 } … … 889 892 } 890 893 else { 891 if ( !(vk->data = PRS_ALLOC_MEM( ps, uint8 , 4 ) ) )894 if ( !(vk->data = PRS_ALLOC_MEM( ps, uint8_t, 4 ) ) ) 892 895 return False; 893 896 SIVAL( vk->data, 0, vk->data_off ); … … 916 919 { 917 920 int i; 918 uint32 record_size;921 uint32_t record_size; 919 922 920 923 prs_debug(&hbin->ps, depth, desc, "prs_vk_records"); … … 933 936 /* convert the offset to something relative to this HBIN block */ 934 937 935 if ( !prs_set_offset( &hbin->ps, nk->values_off+HBIN_HDR_SIZE-hbin->first_hbin_off-sizeof(uint32 )) )938 if ( !prs_set_offset( &hbin->ps, nk->values_off+HBIN_HDR_SIZE-hbin->first_hbin_off-sizeof(uint32_t)) ) 936 939 return False; 937 940 938 941 if ( MARSHALLING( &hbin->ps) ) { 939 record_size = ( ( nk->num_values * sizeof(uint32 ) ) & 0xfffffff8 ) + 8;942 record_size = ( ( nk->num_values * sizeof(uint32_t) ) & 0xfffffff8 ) + 8; 940 943 record_size = (record_size - 1) ^ 0xFFFFFFFF; 941 944 } … … 951 954 for ( i=0; i<nk->num_values; i++ ) { 952 955 REGF_HBIN *sub_hbin = hbin; 953 uint32 new_offset;956 uint32_t new_offset; 954 957 955 958 if ( !hbin_contains_offset( hbin, nk->values[i].rec_off ) ) { … … 980 983 *******************************************************************/ 981 984 982 static REGF_SK_REC* find_sk_record_by_offset( REGF_FILE *file, uint32 offset )985 static REGF_SK_REC* find_sk_record_by_offset( REGF_FILE *file, uint32_t offset ) 983 986 { 984 987 REGF_SK_REC *p_sk; … … 1067 1070 sub_hbin = lookup_hbin_block( file, nk->sk_off ); 1068 1071 if ( !sub_hbin ) { 1069 DEBUG(0,("hbin_prs_key: Failed to find HBIN block containing sk_off set [0x%x]\n",1070 nk->s ubkeys_off));1072 DEBUG(0,("hbin_prs_key: Failed to find HBIN block containing sk_off [0x%x]\n", 1073 nk->sk_off)); 1071 1074 return False; 1072 1075 } 1073 1076 } 1074 1077 1075 if ( !(nk->sec_desc = TALLOC_ZERO_P( file->mem_ctx, REGF_SK_REC )) )1078 if ( !(nk->sec_desc = talloc_zero( file->mem_ctx, REGF_SK_REC )) ) 1076 1079 return False; 1077 1080 nk->sec_desc->sk_off = nk->sk_off; … … 1093 1096 static bool next_record( REGF_HBIN *hbin, const char *hdr, bool *eob ) 1094 1097 { 1095 uint8 header[REC_HDR_SIZE];1096 uint32 record_size;1097 uint32 curr_off, block_size;1098 uint8_t header[REC_HDR_SIZE]; 1099 uint32_t record_size; 1100 uint32_t curr_off, block_size; 1098 1101 bool found = False; 1099 1102 prs_struct *ps = &hbin->ps; … … 1106 1109 and we need to backup to read the record size */ 1107 1110 1108 curr_off -= sizeof(uint32 );1111 curr_off -= sizeof(uint32_t); 1109 1112 1110 1113 block_size = prs_data_size( ps ); 1111 1114 record_size = 0; 1112 memset( header, 0x0, sizeof(uint8 )*REC_HDR_SIZE );1115 memset( header, 0x0, sizeof(uint8_t)*REC_HDR_SIZE ); 1113 1116 while ( !found ) { 1114 1117 … … 1132 1135 if ( memcmp( header, hdr, REC_HDR_SIZE ) == 0 ) { 1133 1136 found = True; 1134 curr_off += sizeof(uint32 );1137 curr_off += sizeof(uint32_t); 1135 1138 } 1136 1139 } … … 1372 1375 REGF_NK_REC *nk; 1373 1376 REGF_HBIN *hbin; 1374 uint32 offset = REGF_BLOCKSIZE;1377 uint32_t offset = REGF_BLOCKSIZE; 1375 1378 bool found = False; 1376 1379 bool eob; … … 1379 1382 return NULL; 1380 1383 1381 if ( !(nk = TALLOC_ZERO_P( file->mem_ctx, REGF_NK_REC )) ) {1384 if ( !(nk = talloc_zero( file->mem_ctx, REGF_NK_REC )) ) { 1382 1385 DEBUG(0,("regfio_rootkey: talloc() failed!\n")); 1383 1386 return NULL; … … 1427 1430 REGF_NK_REC *subkey; 1428 1431 REGF_HBIN *hbin; 1429 uint32 nk_offset;1432 uint32_t nk_offset; 1430 1433 1431 1434 /* see if there is anything left to report */ … … 1447 1450 1448 1451 nk->subkey_index++; 1449 if ( !(subkey = TALLOC_ZERO_P( file->mem_ctx, REGF_NK_REC )) )1452 if ( !(subkey = talloc_zero( file->mem_ctx, REGF_NK_REC )) ) 1450 1453 return NULL; 1451 1454 … … 1460 1463 *******************************************************************/ 1461 1464 1462 static REGF_HBIN* regf_hbin_allocate( REGF_FILE *file, uint32 block_size )1465 static REGF_HBIN* regf_hbin_allocate( REGF_FILE *file, uint32_t block_size ) 1463 1466 { 1464 1467 REGF_HBIN *hbin; 1465 1468 SMB_STRUCT_STAT sbuf; 1466 1469 1467 if ( !(hbin = TALLOC_ZERO_P( file->mem_ctx, REGF_HBIN )) )1470 if ( !(hbin = talloc_zero( file->mem_ctx, REGF_HBIN )) ) 1468 1471 return NULL; 1469 1472 … … 1479 1482 1480 1483 hbin->free_off = HBIN_HEADER_REC_SIZE; 1481 hbin->free_size = block_size - hbin->free_off + sizeof(uint32 );1484 hbin->free_size = block_size - hbin->free_off + sizeof(uint32_t); 1482 1485 1483 1486 hbin->block_size = block_size; … … 1501 1504 *******************************************************************/ 1502 1505 1503 static void update_free_space( REGF_HBIN *hbin, uint32 size_used )1506 static void update_free_space( REGF_HBIN *hbin, uint32_t size_used ) 1504 1507 { 1505 1508 hbin->free_off += size_used; … … 1516 1519 *******************************************************************/ 1517 1520 1518 static REGF_HBIN* find_free_space( REGF_FILE *file, uint32 size )1521 static REGF_HBIN* find_free_space( REGF_FILE *file, uint32_t size ) 1519 1522 { 1520 1523 REGF_HBIN *hbin, *p_hbin; 1521 uint32 block_off;1524 uint32_t block_off; 1522 1525 bool cached; 1523 1526 … … 1575 1578 1576 1579 if ( !hbin ) { 1577 uint32 alloc_size;1580 uint32_t alloc_size; 1578 1581 1579 1582 /* allocate in multiples of REGF_ALLOC_BLOCK; make sure (size + hbin_header) fits */ … … 1591 1594 /* set the offset to be ready to write */ 1592 1595 1593 if ( !prs_set_offset( &hbin->ps, hbin->free_off-sizeof(uint32 ) ) )1596 if ( !prs_set_offset( &hbin->ps, hbin->free_off-sizeof(uint32_t) ) ) 1594 1597 return NULL; 1595 1598 … … 1599 1602 1600 1603 if ( !prs_uint32("allocated_size", &hbin->ps, 0, &size) ) 1601 return False;1604 return NULL; 1602 1605 1603 1606 update_free_space( hbin, size ); … … 1609 1612 *******************************************************************/ 1610 1613 1611 static uint32 sk_record_data_size( struct security_descriptor * sd )1612 { 1613 uint32 size, size_mod8;1614 static uint32_t sk_record_data_size( struct security_descriptor * sd ) 1615 { 1616 uint32_t size, size_mod8; 1614 1617 1615 1618 size_mod8 = 0; … … 1617 1620 /* the record size is sizeof(hdr) + name + static members + data_size_field */ 1618 1621 1619 size = sizeof(uint32 )*5 + ndr_size_security_descriptor(sd, 0) + sizeof(uint32);1622 size = sizeof(uint32_t)*5 + ndr_size_security_descriptor(sd, 0) + sizeof(uint32_t); 1620 1623 1621 1624 /* multiple of 8 */ … … 1630 1633 *******************************************************************/ 1631 1634 1632 static uint32 vk_record_data_size( REGF_VK_REC *vk )1633 { 1634 uint32 size, size_mod8;1635 static uint32_t vk_record_data_size( REGF_VK_REC *vk ) 1636 { 1637 uint32_t size, size_mod8; 1635 1638 1636 1639 size_mod8 = 0; … … 1638 1641 /* the record size is sizeof(hdr) + name + static members + data_size_field */ 1639 1642 1640 size = REC_HDR_SIZE + (sizeof(uint16 )*3) + (sizeof(uint32)*3) + sizeof(uint32);1643 size = REC_HDR_SIZE + (sizeof(uint16_t)*3) + (sizeof(uint32_t)*3) + sizeof(uint32_t); 1641 1644 1642 1645 if ( vk->valuename ) … … 1654 1657 *******************************************************************/ 1655 1658 1656 static uint32 lf_record_data_size( uint32num_keys )1657 { 1658 uint32 size, size_mod8;1659 static uint32_t lf_record_data_size( uint32_t num_keys ) 1660 { 1661 uint32_t size, size_mod8; 1659 1662 1660 1663 size_mod8 = 0; 1661 1664 1662 /* the record size is sizeof(hdr) + num_keys + sizeof of hash_array + data_size_uint32 */1663 1664 size = REC_HDR_SIZE + sizeof(uint16 ) + (sizeof(REGF_HASH_REC) * num_keys) + sizeof(uint32);1665 /* the record size is sizeof(hdr) + num_keys + sizeof of hash_array + data_size_uint32_t */ 1666 1667 size = REC_HDR_SIZE + sizeof(uint16_t) + (sizeof(REGF_HASH_REC) * num_keys) + sizeof(uint32_t); 1665 1668 1666 1669 /* multiple of 8 */ … … 1675 1678 *******************************************************************/ 1676 1679 1677 static uint32 nk_record_data_size( REGF_NK_REC *nk )1678 { 1679 uint32 size, size_mod8;1680 static uint32_t nk_record_data_size( REGF_NK_REC *nk ) 1681 { 1682 uint32_t size, size_mod8; 1680 1683 1681 1684 size_mod8 = 0; 1682 1685 1683 /* the record size is static + length_of_keyname + length_of_classname + data_size_uint32 */1684 1685 size = 0x4c + strlen(nk->keyname) + sizeof(uint32 );1686 /* the record size is static + length_of_keyname + length_of_classname + data_size_uint32_t */ 1687 1688 size = 0x4c + strlen(nk->keyname) + sizeof(uint32_t); 1686 1689 1687 1690 if ( nk->classname ) … … 1717 1720 vk->type = regval_type( value ); 1718 1721 1719 if ( vk->data_size > sizeof(uint32 ) ) {1720 uint32 data_size = ( (vk->data_size+sizeof(uint32)) & 0xfffffff8 ) + 8;1721 1722 vk->data = (uint8 *)TALLOC_MEMDUP( file->mem_ctx,1722 if ( vk->data_size > sizeof(uint32_t) ) { 1723 uint32_t data_size = ( (vk->data_size+sizeof(uint32_t)) & 0xfffffff8 ) + 8; 1724 1725 vk->data = (uint8_t *)talloc_memdup( file->mem_ctx, 1723 1726 regval_data_p(value), 1724 1727 vk->data_size ); … … 1739 1742 1740 1743 if ( vk->data_size != 0 ) 1741 memcpy( &vk->data_off, regval_data_p(value), sizeof(uint32));1744 memcpy( &vk->data_off, regval_data_p(value), vk->data_size); 1742 1745 vk->data_size |= VK_DATA_IN_OFFSET; 1743 1746 } … … 1751 1754 static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 ) 1752 1755 { 1753 return StrCaseCmp( h1->fullname, h2->fullname );1756 return strcasecmp_m( h1->fullname, h2->fullname ); 1754 1757 } 1755 1758 … … 1763 1766 REGF_NK_REC *nk; 1764 1767 REGF_HBIN *vlist_hbin = NULL; 1765 uint32 size;1766 1767 if ( !(nk = TALLOC_ZERO_P( file->mem_ctx, REGF_NK_REC )) )1768 uint32_t size; 1769 1770 if ( !(nk = talloc_zero( file->mem_ctx, REGF_NK_REC )) ) 1768 1771 return NULL; 1769 1772 … … 1804 1807 1805 1808 hash->nk_off = prs_offset( &nk->hbin->ps ) + nk->hbin->first_hbin_off - HBIN_HDR_SIZE; 1806 memcpy( hash->keycheck, name, sizeof(uint32));1809 memcpy(hash->keycheck, name, MIN(strlen(name),sizeof(uint32_t))); 1807 1810 hash->fullname = talloc_strdup( file->mem_ctx, name ); 1808 1811 parent->subkey_index++; … … 1812 1815 1813 1816 if ( !hbin_prs_lf_records( "lf_rec", parent->subkeys.hbin, 0, parent ) ) 1814 return False;1817 return NULL; 1815 1818 } 1816 1819 … … 1819 1822 nk->sk_off = REGF_OFFSET_NONE; 1820 1823 if ( sec_desc ) { 1821 uint32 sk_size = sk_record_data_size( sec_desc );1824 uint32_t sk_size = sk_record_data_size( sec_desc ); 1822 1825 REGF_HBIN *sk_hbin; 1823 1826 … … 1831 1834 } 1832 1835 1833 if ( !(nk->sec_desc = TALLOC_ZERO_P( file->mem_ctx, REGF_SK_REC )) )1836 if ( !(nk->sec_desc = talloc_zero( file->mem_ctx, REGF_SK_REC )) ) 1834 1837 return NULL; 1835 1838 … … 1848 1851 /* size value must be self-inclusive */ 1849 1852 nk->sec_desc->size = ndr_size_security_descriptor(sec_desc, 0) 1850 + sizeof(uint32 );1851 1852 DLIST_ADD_END( file->sec_desc_list, nk->sec_desc , REGF_SK_REC *);1853 + sizeof(uint32_t); 1854 1855 DLIST_ADD_END( file->sec_desc_list, nk->sec_desc); 1853 1856 1854 1857 /* update the offsets for us and the previous sd in the list. … … 1883 1886 nk->subkeys_off = REGF_OFFSET_NONE; 1884 1887 if ( (nk->num_subkeys = regsubkey_ctr_numkeys( subkeys )) != 0 ) { 1885 uint32 lf_size = lf_record_data_size( nk->num_subkeys );1886 uint32 namelen;1888 uint32_t lf_size = lf_record_data_size( nk->num_subkeys ); 1889 uint32_t namelen; 1887 1890 int i; 1888 1891 … … 1898 1901 nk->subkeys.num_keys = nk->num_subkeys; 1899 1902 if (nk->subkeys.num_keys) { 1900 if ( !(nk->subkeys.hashes = TALLOC_ZERO_ARRAY( file->mem_ctx, REGF_HASH_REC, nk->subkeys.num_keys )) )1903 if ( !(nk->subkeys.hashes = talloc_zero_array( file->mem_ctx, REGF_HASH_REC, nk->subkeys.num_keys )) ) 1901 1904 return NULL; 1902 1905 } else { … … 1917 1920 nk->values_off = REGF_OFFSET_NONE; 1918 1921 if ( (nk->num_values = regval_ctr_numvals( values )) != 0 ) { 1919 uint32 vlist_size = ( ( nk->num_values * sizeof(uint32) ) & 0xfffffff8 ) + 8;1922 uint32_t vlist_size = ( ( nk->num_values * sizeof(uint32_t) ) & 0xfffffff8 ) + 8; 1920 1923 int i; 1921 1924 … … 1926 1929 1927 1930 if (nk->num_values) { 1928 if ( !(nk->values = TALLOC_ARRAY( file->mem_ctx, REGF_VK_REC, nk->num_values )) )1931 if ( !(nk->values = talloc_array( file->mem_ctx, REGF_VK_REC, nk->num_values )) ) 1929 1932 return NULL; 1930 1933 } else { … … 1935 1938 1936 1939 for ( i=0; i<nk->num_values; i++ ) { 1937 uint32 vk_size, namelen, datalen;1940 uint32_t vk_size, namelen, datalen; 1938 1941 struct regval_blob *r; 1939 1942 … … 1964 1967 prs_set_offset( &nk->hbin->ps, nk->hbin_off ); 1965 1968 if ( !prs_nk_rec( "nk_rec", &nk->hbin->ps, 0, nk ) ) 1966 return False;1969 return NULL; 1967 1970 1968 1971 if ( nk->num_values ) { 1969 1972 if ( !hbin_prs_vk_records( "vk_records", vlist_hbin, 0, nk, file ) ) 1970 return False;1973 return NULL; 1971 1974 } 1972 1975 -
vendor/current/source3/registry/regfio.h
r740 r988 65 65 typedef struct regf_hbin { 66 66 struct regf_hbin *prev, *next; 67 uint32 file_off; /* my offset in the registry file */68 uint32 free_off; /* offset to free space within the hbin record */69 uint32 free_size; /* amount of data left in the block */67 uint32_t file_off; /* my offset in the registry file */ 68 uint32_t free_off; /* offset to free space within the hbin record */ 69 uint32_t free_size; /* amount of data left in the block */ 70 70 int ref_count; /* how many active records are pointing to this block (not used currently) */ 71 71 72 72 char header[HBIN_HDR_SIZE]; /* "hbin" */ 73 uint32 first_hbin_off; /* offset from first hbin block */74 uint32 block_size; /* block size of this blockually a multiple of 4096Kb) */73 uint32_t first_hbin_off; /* offset from first hbin block */ 74 uint32_t block_size; /* block size of this blockually a multiple of 4096Kb) */ 75 75 76 76 prs_struct ps; /* data */ … … 82 82 83 83 typedef struct { 84 uint32 nk_off;85 uint8 keycheck[sizeof(uint32)];84 uint32_t nk_off; 85 uint8_t keycheck[sizeof(uint32_t)]; 86 86 char *fullname; 87 87 } REGF_HASH_REC; … … 89 89 typedef struct { 90 90 REGF_HBIN *hbin; /* pointer to HBIN record (in memory) containing this nk record */ 91 uint32 hbin_off; /* offset from beginning of this hbin block */92 uint32 rec_size; /* ((start_offset - end_offset) & 0xfffffff8) */93 94 char header[REC_HDR_SIZE]; 95 uint16 num_keys;91 uint32_t hbin_off; /* offset from beginning of this hbin block */ 92 uint32_t rec_size; /* ((start_offset - end_offset) & 0xfffffff8) */ 93 94 char header[REC_HDR_SIZE]; 95 uint16_t num_keys; 96 96 REGF_HASH_REC *hashes; 97 97 } REGF_LF_REC; … … 101 101 typedef struct { 102 102 REGF_HBIN *hbin; /* pointer to HBIN record (in memory) containing this nk record */ 103 uint32 hbin_off; /* offset from beginning of this hbin block */104 uint32 rec_size; /* ((start_offset - end_offset) & 0xfffffff8) */105 uint32 rec_off; /* offset stored in the value list */103 uint32_t hbin_off; /* offset from beginning of this hbin block */ 104 uint32_t rec_size; /* ((start_offset - end_offset) & 0xfffffff8) */ 105 uint32_t rec_off; /* offset stored in the value list */ 106 106 107 107 char header[REC_HDR_SIZE]; 108 108 char *valuename; 109 uint32 data_size;110 uint32 data_off;111 uint8 *data;112 uint32 type;113 uint16 flag;109 uint32_t data_size; 110 uint32_t data_off; 111 uint8_t *data; 112 uint32_t type; 113 uint16_t flag; 114 114 } REGF_VK_REC; 115 115 … … 121 121 struct _regf_sk_rec *next, *prev; 122 122 REGF_HBIN *hbin; /* pointer to HBIN record (in memory) containing this nk record */ 123 uint32 hbin_off; /* offset from beginning of this hbin block */124 uint32 rec_size; /* ((start_offset - end_offset) & 0xfffffff8) */125 126 uint32 sk_off; /* offset parsed from NK record used as a key123 uint32_t hbin_off; /* offset from beginning of this hbin block */ 124 uint32_t rec_size; /* ((start_offset - end_offset) & 0xfffffff8) */ 125 126 uint32_t sk_off; /* offset parsed from NK record used as a key 127 127 to lookup reference to this SK record */ 128 128 129 129 char header[REC_HDR_SIZE]; 130 uint32 prev_sk_off;131 uint32 next_sk_off;132 uint32 ref_count;133 uint32 size;130 uint32_t prev_sk_off; 131 uint32_t next_sk_off; 132 uint32_t ref_count; 133 uint32_t size; 134 134 struct security_descriptor *sec_desc; 135 135 } REGF_SK_REC; … … 139 139 typedef struct { 140 140 REGF_HBIN *hbin; /* pointer to HBIN record (in memory) containing this nk record */ 141 uint32 hbin_off; /* offset from beginning of this hbin block */142 uint32 subkey_index; /* index to next subkey record to return */143 uint32 rec_size; /* ((start_offset - end_offset) & 0xfffffff8) */141 uint32_t hbin_off; /* offset from beginning of this hbin block */ 142 uint32_t subkey_index; /* index to next subkey record to return */ 143 uint32_t rec_size; /* ((start_offset - end_offset) & 0xfffffff8) */ 144 144 145 145 /* header information */ 146 146 147 147 char header[REC_HDR_SIZE]; 148 uint16 key_type;148 uint16_t key_type; 149 149 NTTIME mtime; 150 uint32 parent_off; /* back pointer in registry hive */151 uint32 classname_off;150 uint32_t parent_off; /* back pointer in registry hive */ 151 uint32_t classname_off; 152 152 char *classname; 153 153 char *keyname; … … 155 155 /* max lengths */ 156 156 157 uint32 max_bytes_subkeyname; /* max subkey name * 2 */158 uint32 max_bytes_subkeyclassname; /* max subkey classname length (as if) */159 uint32 max_bytes_valuename; /* max valuename * 2 */160 uint32 max_bytes_value; /* max value data size */157 uint32_t max_bytes_subkeyname; /* max subkey name * 2 */ 158 uint32_t max_bytes_subkeyclassname; /* max subkey classname length (as if) */ 159 uint32_t max_bytes_valuename; /* max valuename * 2 */ 160 uint32_t max_bytes_value; /* max value data size */ 161 161 162 162 /* unknowns */ 163 163 164 uint32 unk_index; /* nigel says run time index ? */164 uint32_t unk_index; /* nigel says run time index ? */ 165 165 166 166 /* children */ 167 167 168 uint32 num_subkeys;169 uint32 subkeys_off; /* hash records that point to NK records */170 uint32 num_values;171 uint32 values_off; /* value lists which point to VK records */172 uint32 sk_off; /* offset to SK record */168 uint32_t num_subkeys; 169 uint32_t subkeys_off; /* hash records that point to NK records */ 170 uint32_t num_values; 171 uint32_t values_off; /* value lists which point to VK records */ 172 uint32_t sk_off; /* offset to SK record */ 173 173 174 174 /* link in the other records here */ … … 193 193 194 194 char header[REGF_HDR_SIZE]; /* "regf" */ 195 uint32 data_offset; /* offset to record in the first (or any?) hbin block */196 uint32 last_block; /* offset to last hbin block in file */197 uint32 checksum; /* XOR of bytes 0x0000 - 0x01FB */195 uint32_t data_offset; /* offset to record in the first (or any?) hbin block */ 196 uint32_t last_block; /* offset to last hbin block in file */ 197 uint32_t checksum; /* XOR of bytes 0x0000 - 0x01FB */ 198 198 NTTIME mtime; 199 199 … … 202 202 /* unknowns used to simply writing */ 203 203 204 uint32 unknown1;205 uint32 unknown2;206 uint32 unknown3;207 uint32 unknown4;208 uint32 unknown5;209 uint32 unknown6;204 uint32_t unknown1; 205 uint32_t unknown2; 206 uint32_t unknown3; 207 uint32_t unknown4; 208 uint32_t unknown5; 209 uint32_t unknown6; 210 210 211 211 } REGF_FILE;
Note:
See TracChangeset
for help on using the changeset viewer.