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 2 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, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 /* Implementation of registry frontend view functions. */
26 #define DBGC_CLASS DBGC_RPC_SRV
28 /***********************************************************************
29 Utility function for splitting the base path of a registry path off
30 by setting base and new_path to the apprapriate offsets withing the
33 WARNING!! Does modify the original string!
34 ***********************************************************************/
36 BOOL reg_split_path( char *path, char **base, char **new_path )
40 *new_path = *base = NULL;
47 p = strchr( path, '\\' );
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
63 WARNING!! Does modify the original string!
64 ***********************************************************************/
66 BOOL reg_split_key( char *path, char **base, char **key )
77 p = strrchr( path, '\\' );
88 /**********************************************************************
89 The full path to the registry key is used as database after the
90 \'s are converted to /'s. Key string is also normalized to UPPER
92 **********************************************************************/
94 void normalize_reg_path( pstring keyname )
96 pstring_sub( keyname, "\\", "/" );
97 strupper_m( keyname );
100 /**********************************************************************
101 move to next non-delimter character
102 *********************************************************************/
104 char* reg_remaining_path( const char *key )
106 static pstring new_path;
112 pstrcpy( new_path, key );
113 /* normalize_reg_path( new_path ); */
115 if ( !(p = strchr( new_path, '\\' )) )
117 if ( !(p = strchr( new_path, '/' )) )
128 /**********************************************************************
129 *********************************************************************/
131 int regval_convert_multi_sz( uint16 *multi_string, size_t multi_len, char ***values )
141 if ( !multi_string || !*values )
144 /* just count the NULLs */
146 for ( i=0; (i<multi_len-1) && !(multi_string[i]==0x0 && multi_string[i+1]==0x0); i++ ) {
147 if ( multi_string[i] == 0x0 )
151 if ( num_strings == 0 )
154 if ( !(sz = TALLOC_ARRAY( NULL, char*, num_strings+1 )) ) {
155 DEBUG(0,("reg_convert_multi_sz: talloc() failed!\n"));
161 for ( i=0; i<num_strings; i++ ) {
162 rpcstr_pull( buffer, wp, sizeof(buffer), -1, STR_TERMINATE );
163 sz[i] = talloc_strdup( sz, buffer );
165 /* skip to the next string NULL and then one more */
171 /* tag the array off with an empty string */
179 /**********************************************************************
180 Returns number of bytes, not number of unicode characters
181 *********************************************************************/
183 size_t regval_build_multi_sz( char **values, uint16 **buffer )
190 if ( !values || !*buffer )
193 /* go ahead and alloc some space */
195 if ( !(buf = TALLOC_ARRAY( NULL, uint16, 2 )) ) {
196 DEBUG(0,("regval_build_multi_sz: talloc() failed!\n"));
200 for ( i=0; values[i]; i++ ) {
203 init_unistr2( &sz, values[i], UNI_STR_TERMINATE );
205 /* Alloc some more memory. Always add one one to account for the
206 double NULL termination */
208 b = TALLOC_REALLOC_ARRAY( NULL, buf, uint16, buf_size+sz.uni_str_len+1 );
210 DEBUG(0,("regval_build_multi_sz: talloc() reallocation error!\n"));
211 TALLOC_FREE( buffer );
216 /* copy the unistring2 buffer and increment the size */
218 memcpy( buf+buf_size, sz.buffer, sz.uni_str_len );
219 buf_size += sz.uni_str_len;
221 /* cleanup rather than leaving memory hanging around */
222 TALLOC_FREE( sz.buffer );
225 buf[buf_size++] = 0x0;
229 /* return number of bytes */