| 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 |
|
|---|
| 24 | #undef DBGC_CLASS
|
|---|
| 25 | #define DBGC_CLASS DBGC_REGISTRY
|
|---|
| 26 |
|
|---|
| 27 | /***********************************************************************
|
|---|
| 28 | Utility function for splitting the base path of a registry path off
|
|---|
| 29 | by setting base and new_path to the apprapriate offsets withing the
|
|---|
| 30 | path.
|
|---|
| 31 |
|
|---|
| 32 | WARNING!! Does modify the original string!
|
|---|
| 33 | ***********************************************************************/
|
|---|
| 34 |
|
|---|
| 35 | bool reg_split_path(char *path, char **base, char **new_path)
|
|---|
| 36 | {
|
|---|
| 37 | char *p;
|
|---|
| 38 |
|
|---|
| 39 | *new_path = *base = NULL;
|
|---|
| 40 |
|
|---|
| 41 | if (!path) {
|
|---|
| 42 | return false;
|
|---|
| 43 | }
|
|---|
| 44 | *base = path;
|
|---|
| 45 |
|
|---|
| 46 | p = strchr(path, '\\');
|
|---|
| 47 |
|
|---|
| 48 | if ( p ) {
|
|---|
| 49 | *p = '\0';
|
|---|
| 50 | *new_path = p+1;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | return true;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | /***********************************************************************
|
|---|
| 57 | Utility function for splitting the base path of a registry path off
|
|---|
| 58 | by setting base and new_path to the appropriate offsets withing the
|
|---|
| 59 | path.
|
|---|
| 60 |
|
|---|
| 61 | WARNING!! Does modify the original string!
|
|---|
| 62 | ***********************************************************************/
|
|---|
| 63 |
|
|---|
| 64 | bool reg_split_key(char *path, char **base, char **key)
|
|---|
| 65 | {
|
|---|
| 66 | char *p;
|
|---|
| 67 |
|
|---|
| 68 | *key = *base = NULL;
|
|---|
| 69 |
|
|---|
| 70 | if (!path) {
|
|---|
| 71 | return false;
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | *base = path;
|
|---|
| 75 |
|
|---|
| 76 | p = strrchr(path, '\\');
|
|---|
| 77 |
|
|---|
| 78 | if (p) {
|
|---|
| 79 | *p = '\0';
|
|---|
| 80 | *key = p+1;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | return true;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | /**
|
|---|
| 87 | * The full path to the registry key is used as database key
|
|---|
| 88 | * after the \'s are converted to /'s.
|
|---|
| 89 | * Leading and trailing '/' and '\' characters are stripped.
|
|---|
| 90 | * Key string is also normalized to UPPER case.
|
|---|
| 91 | */
|
|---|
| 92 |
|
|---|
| 93 | char *normalize_reg_path(TALLOC_CTX *ctx, const char *keyname )
|
|---|
| 94 | {
|
|---|
| 95 | char *p;
|
|---|
| 96 | char *nkeyname;
|
|---|
| 97 |
|
|---|
| 98 | /* skip leading '/' and '\' chars */
|
|---|
| 99 | p = (char *)keyname;
|
|---|
| 100 | while ((*p == '/') || (*p == '\\')) {
|
|---|
| 101 | p++;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | nkeyname = talloc_string_sub(ctx, p, "\\", "/");
|
|---|
| 105 | if (nkeyname == NULL) {
|
|---|
| 106 | return NULL;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | /* strip trailing '/' chars */
|
|---|
| 110 | p = strrchr(nkeyname, '/');
|
|---|
| 111 | while ((p != NULL) && (p[1] == '\0')) {
|
|---|
| 112 | *p = '\0';
|
|---|
| 113 | p = strrchr(nkeyname, '/');
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | strupper_m(nkeyname);
|
|---|
| 117 |
|
|---|
| 118 | return nkeyname;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | /**
|
|---|
| 122 | * normalize ther registry path in place.
|
|---|
| 123 | */
|
|---|
| 124 | void normalize_dbkey(char *key)
|
|---|
| 125 | {
|
|---|
| 126 | size_t len = strlen(key);
|
|---|
| 127 | string_sub(key, "\\", "/", len+1);
|
|---|
| 128 | strupper_m(key);
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | /**********************************************************************
|
|---|
| 132 | move to next non-delimter character
|
|---|
| 133 | *********************************************************************/
|
|---|
| 134 |
|
|---|
| 135 | char *reg_remaining_path(TALLOC_CTX *ctx, const char *key)
|
|---|
| 136 | {
|
|---|
| 137 | char *new_path = NULL;
|
|---|
| 138 | char *p = NULL;
|
|---|
| 139 |
|
|---|
| 140 | if (!key || !*key) {
|
|---|
| 141 | return NULL;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | new_path = talloc_strdup(ctx, key);
|
|---|
| 145 | if (!new_path) {
|
|---|
| 146 | return NULL;
|
|---|
| 147 | }
|
|---|
| 148 | /* normalize_reg_path( new_path ); */
|
|---|
| 149 | if (!(p = strchr(new_path, '\\')) ) {
|
|---|
| 150 | if (!(p = strchr( new_path, '/'))) {
|
|---|
| 151 | p = new_path;
|
|---|
| 152 | } else {
|
|---|
| 153 | p++;
|
|---|
| 154 | }
|
|---|
| 155 | } else {
|
|---|
| 156 | p++;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | return p;
|
|---|
| 160 | }
|
|---|