Line data Source code
1 : /* 2 : * Unix SMB/CIFS implementation. 3 : * Virtual Windows Registry Layer 4 : * Copyright (C) Volker Lendecke 2006 5 : * Copyright (C) Michael Adam 2007-2010 6 : * 7 : * This program is free software; you can redistribute it and/or modify 8 : * it under the terms of the GNU General Public License as published by 9 : * the Free Software Foundation; either version 3 of the License, or 10 : * (at your option) any later version. 11 : * 12 : * This program is distributed in the hope that it will be useful, 13 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 : * GNU General Public License for more details. 16 : * 17 : * You should have received a copy of the GNU General Public License 18 : * along with this program; if not, see <http://www.gnu.org/licenses/>. 19 : */ 20 : 21 : /* 22 : * Higher level utility functions on top of reg_api.c 23 : */ 24 : 25 : #include "includes.h" 26 : #include "registry.h" 27 : #include "reg_api.h" 28 : #include "reg_api_util.h" 29 : #include "libcli/registry/util_reg.h" 30 : 31 : /** 32 : * Utility function to open a complete registry path including the hive prefix. 33 : */ 34 1094 : WERROR reg_open_path(TALLOC_CTX *mem_ctx, const char *orig_path, 35 : uint32_t desired_access, const struct security_token *token, 36 : struct registry_key **pkey) 37 : { 38 23 : struct registry_key *hive, *key; 39 23 : char *path, *p; 40 23 : WERROR err; 41 : 42 1094 : if (!(path = SMB_STRDUP(orig_path))) { 43 0 : return WERR_NOT_ENOUGH_MEMORY; 44 : } 45 : 46 1094 : p = strchr(path, '\\'); 47 : 48 1094 : if ((p == NULL) || (p[1] == '\0')) { 49 : /* 50 : * No key behind the hive, just return the hive 51 : */ 52 : 53 0 : err = reg_openhive(mem_ctx, path, desired_access, token, 54 : &hive); 55 0 : if (!W_ERROR_IS_OK(err)) { 56 0 : SAFE_FREE(path); 57 0 : return err; 58 : } 59 0 : SAFE_FREE(path); 60 0 : *pkey = hive; 61 0 : return WERR_OK; 62 : } 63 : 64 1094 : *p = '\0'; 65 : 66 1094 : err = reg_openhive(mem_ctx, path, KEY_ENUMERATE_SUB_KEYS, token, 67 : &hive); 68 1094 : if (!W_ERROR_IS_OK(err)) { 69 0 : SAFE_FREE(path); 70 0 : return err; 71 : } 72 : 73 1094 : err = reg_openkey(mem_ctx, hive, p+1, desired_access, &key); 74 : 75 1094 : TALLOC_FREE(hive); 76 1094 : SAFE_FREE(path); 77 : 78 1094 : if (!W_ERROR_IS_OK(err)) { 79 0 : return err; 80 : } 81 : 82 1094 : *pkey = key; 83 1094 : return WERR_OK; 84 : }