s3-passdb: Fix typo in comment.
[Samba.git] / source3 / registry / reg_util_internal.c
blob4cf8e2886bd4d02bb0ba76c41952a0119df0d765
1 /*
2 * Unix SMB/CIFS implementation.
3 * Virtual Windows Registry Layer (utility functions)
4 * Copyright (C) Gerald Carter 2002-2005
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.
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.
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/>.
20 /* Implementation of registry frontend view functions. */
22 #include "includes.h"
23 #include "registry.h"
24 #include "reg_util_internal.h"
26 #undef DBGC_CLASS
27 #define DBGC_CLASS DBGC_REGISTRY
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 withing the
32 path.
34 WARNING!! Does modify the original string!
35 ***********************************************************************/
37 bool reg_split_path(char *path, char **base, char **new_path)
39 char *p;
41 *new_path = *base = NULL;
43 if (!path) {
44 return false;
46 *base = path;
48 p = strchr(path, '\\');
50 if ( p ) {
51 *p = '\0';
52 *new_path = p+1;
55 return true;
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 withing the
61 path.
63 WARNING!! Does modify the original string!
64 ***********************************************************************/
66 bool reg_split_key(char *path, char **base, char **key)
68 char *p;
70 *key = *base = NULL;
72 if (!path) {
73 return false;
76 *base = path;
78 p = strrchr(path, '\\');
80 if (p) {
81 *p = '\0';
82 *key = p+1;
85 return true;
88 /**
89 * The full path to the registry key is used as database key
90 * after the \'s are converted to /'s.
91 * Leading and trailing '/' and '\' characters are stripped.
92 * Key string is also normalized to UPPER case.
95 char *normalize_reg_path(TALLOC_CTX *ctx, const char *keyname )
97 char *p;
98 char *nkeyname;
100 /* skip leading '/' and '\' chars */
101 p = (char *)keyname;
102 while ((*p == '/') || (*p == '\\')) {
103 p++;
106 nkeyname = talloc_string_sub(ctx, p, "\\", "/");
107 if (nkeyname == NULL) {
108 return NULL;
111 /* strip trailing '/' chars */
112 p = strrchr(nkeyname, '/');
113 while ((p != NULL) && (p[1] == '\0')) {
114 *p = '\0';
115 p = strrchr(nkeyname, '/');
118 strupper_m(nkeyname);
120 return nkeyname;
124 * normalize ther registry path in place.
126 void normalize_dbkey(char *key)
128 size_t len = strlen(key);
129 string_sub(key, "\\", "/", len+1);
130 strupper_m(key);
133 /**********************************************************************
134 move to next non-delimter character
135 *********************************************************************/
137 char *reg_remaining_path(TALLOC_CTX *ctx, const char *key)
139 char *new_path = NULL;
140 char *p = NULL;
142 if (!key || !*key) {
143 return NULL;
146 new_path = talloc_strdup(ctx, key);
147 if (!new_path) {
148 return NULL;
150 /* normalize_reg_path( new_path ); */
151 if (!(p = strchr(new_path, '\\')) ) {
152 if (!(p = strchr( new_path, '/'))) {
153 p = new_path;
154 } else {
155 p++;
157 } else {
158 p++;
161 return p;