Line data Source code
1 : /* 2 : * Unix SMB/CIFS implementation. 3 : * Virtual Windows Registry Layer (utility functions) 4 : * Copyright (C) Gerald Carter 2002-2005 5 : * 6 : * This program is free software; you can redistribute it and/or modify 7 : * it under the terms of the GNU General Public License as published by 8 : * the Free Software Foundation; either version 3 of the License, or 9 : * (at your option) any later version. 10 : * 11 : * This program is distributed in the hope that it will be useful, 12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 : * GNU General Public License for more details. 15 : * 16 : * You should have received a copy of the GNU General Public License 17 : * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 : */ 19 : 20 : /* Implementation of registry frontend view functions. */ 21 : 22 : #include "includes.h" 23 : #include "registry.h" 24 : #include "reg_util_internal.h" 25 : 26 : #undef DBGC_CLASS 27 : #define DBGC_CLASS DBGC_REGISTRY 28 : 29 : /*********************************************************************** 30 : Utility function for splitting the base path of a registry path off 31 : by setting base and new_path to the apprapriate offsets within the 32 : path. 33 : 34 : WARNING!! Does modify the original string! 35 : ***********************************************************************/ 36 : 37 0 : bool reg_split_path(char *path, char **base, char **new_path) 38 : { 39 0 : char *p; 40 : 41 0 : *new_path = *base = NULL; 42 : 43 0 : if (!path) { 44 0 : return false; 45 : } 46 0 : *base = path; 47 : 48 0 : p = strchr(path, '\\'); 49 : 50 0 : if ( p ) { 51 0 : *p = '\0'; 52 0 : *new_path = p+1; 53 : } 54 : 55 0 : return true; 56 : } 57 : 58 : /*********************************************************************** 59 : Utility function for splitting the base path of a registry path off 60 : by setting base and new_path to the appropriate offsets within the 61 : path. 62 : 63 : WARNING!! Does modify the original string! 64 : ***********************************************************************/ 65 : 66 0 : bool reg_split_key(char *path, char **base, char **key) 67 : { 68 0 : char *p; 69 : 70 0 : *key = *base = NULL; 71 : 72 0 : if (!path) { 73 0 : return false; 74 : } 75 : 76 0 : *base = path; 77 : 78 0 : p = strrchr(path, '\\'); 79 : 80 0 : if (p) { 81 0 : *p = '\0'; 82 0 : *key = p+1; 83 : } 84 : 85 0 : return true; 86 : } 87 : 88 : /** 89 : * The full path to the registry key is used as database key. 90 : * Leading and trailing '\' characters are stripped. 91 : * Key string is also normalized to UPPER case. 92 : */ 93 : 94 7467634 : char *normalize_reg_path(TALLOC_CTX *ctx, const char *keyname ) 95 : { 96 3444 : char *p; 97 3444 : char *nkeyname; 98 : 99 : /* skip leading '\' chars */ 100 7467634 : while (*keyname == '\\') { 101 0 : keyname++; 102 : } 103 : 104 7467634 : nkeyname = talloc_strdup(ctx, keyname); 105 7467634 : if (nkeyname == NULL) { 106 0 : return NULL; 107 : } 108 : 109 : /* strip trailing '\' chars */ 110 7467634 : p = strrchr(nkeyname, '\\'); 111 7467634 : while ((p != NULL) && (p[1] == '\0')) { 112 0 : *p = '\0'; 113 0 : p = strrchr(nkeyname, '\\'); 114 : } 115 : 116 7467634 : if (!strupper_m(nkeyname)) { 117 0 : TALLOC_FREE(nkeyname); 118 0 : return NULL; 119 : } 120 : 121 7464190 : return nkeyname; 122 : } 123 : 124 : /********************************************************************** 125 : move to next non-delimter character 126 : *********************************************************************/ 127 : 128 240 : char *reg_remaining_path(TALLOC_CTX *ctx, const char *key) 129 : { 130 240 : char *new_path = NULL; 131 240 : char *p = NULL; 132 : 133 240 : if (!key || !*key) { 134 8 : return NULL; 135 : } 136 : 137 232 : new_path = talloc_strdup(ctx, key); 138 232 : if (!new_path) { 139 0 : return NULL; 140 : } 141 : /* normalize_reg_path( new_path ); */ 142 232 : if (!(p = strchr(new_path, '\\')) ) { 143 0 : p = new_path; 144 : } else { 145 232 : p++; 146 : } 147 : 148 232 : return p; 149 : }