source: trunk/server/source3/registry/reg_util_internal.c

Last change on this file was 745, checked in by Silvan Scherrer, 13 years ago

Samba Server: updated trunk to 3.6.0

File size: 3.4 KB
Line 
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 withing the
32 path.
33
34 WARNING!! Does modify the original string!
35 ***********************************************************************/
36
37bool reg_split_path(char *path, char **base, char **new_path)
38{
39 char *p;
40
41 *new_path = *base = NULL;
42
43 if (!path) {
44 return false;
45 }
46 *base = path;
47
48 p = strchr(path, '\\');
49
50 if ( p ) {
51 *p = '\0';
52 *new_path = p+1;
53 }
54
55 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 withing the
61 path.
62
63 WARNING!! Does modify the original string!
64 ***********************************************************************/
65
66bool reg_split_key(char *path, char **base, char **key)
67{
68 char *p;
69
70 *key = *base = NULL;
71
72 if (!path) {
73 return false;
74 }
75
76 *base = path;
77
78 p = strrchr(path, '\\');
79
80 if (p) {
81 *p = '\0';
82 *key = p+1;
83 }
84
85 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
94char *normalize_reg_path(TALLOC_CTX *ctx, const char *keyname )
95{
96 char *p;
97 char *nkeyname;
98
99 /* skip leading '\' chars */
100 p = (char *)keyname;
101 while (*p == '\\') {
102 p++;
103 }
104
105 nkeyname = talloc_strdup(ctx, p);
106 if (nkeyname == NULL) {
107 return NULL;
108 }
109
110 /* strip trailing '\' chars */
111 p = strrchr(nkeyname, '\\');
112 while ((p != NULL) && (p[1] == '\0')) {
113 *p = '\0';
114 p = strrchr(nkeyname, '\\');
115 }
116
117 strupper_m(nkeyname);
118
119 return nkeyname;
120}
121
122/**********************************************************************
123 move to next non-delimter character
124*********************************************************************/
125
126char *reg_remaining_path(TALLOC_CTX *ctx, const char *key)
127{
128 char *new_path = NULL;
129 char *p = NULL;
130
131 if (!key || !*key) {
132 return NULL;
133 }
134
135 new_path = talloc_strdup(ctx, key);
136 if (!new_path) {
137 return NULL;
138 }
139 /* normalize_reg_path( new_path ); */
140 if (!(p = strchr(new_path, '\\')) ) {
141 p = new_path;
142 } else {
143 p++;
144 }
145
146 return p;
147}
Note: See TracBrowser for help on using the repository browser.