registry/reg_util.c

説明を見る。
00001 /* 
00002  *  Unix SMB/CIFS implementation.
00003  *  Virtual Windows Registry Layer (utility functions)
00004  *  Copyright (C) Gerald Carter                     2002-2005
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *  
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *  
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 /* Implementation of registry frontend view functions. */
00022 
00023 #include "includes.h"
00024 
00025 #undef DBGC_CLASS
00026 #define DBGC_CLASS DBGC_RPC_SRV
00027 
00028 /***********************************************************************
00029  Utility function for splitting the base path of a registry path off
00030  by setting base and new_path to the apprapriate offsets withing the
00031  path.
00032  
00033  WARNING!!  Does modify the original string!
00034  ***********************************************************************/
00035 
00036 BOOL reg_split_path( char *path, char **base, char **new_path )
00037 {
00038         char *p;
00039         
00040         *new_path = *base = NULL;
00041         
00042         if ( !path)
00043                 return False;
00044         
00045         *base = path;
00046         
00047         p = strchr( path, '\\' );
00048         
00049         if ( p ) {
00050                 *p = '\0';
00051                 *new_path = p+1;
00052         }
00053         
00054         return True;
00055 }
00056 
00057 
00058 /***********************************************************************
00059  Utility function for splitting the base path of a registry path off
00060  by setting base and new_path to the appropriate offsets withing the
00061  path.
00062  
00063  WARNING!!  Does modify the original string!
00064  ***********************************************************************/
00065 
00066 BOOL reg_split_key( char *path, char **base, char **key )
00067 {
00068         char *p;
00069         
00070         *key = *base = NULL;
00071         
00072         if ( !path)
00073                 return False;
00074         
00075         *base = path;
00076         
00077         p = strrchr( path, '\\' );
00078         
00079         if ( p ) {
00080                 *p = '\0';
00081                 *key = p+1;
00082         }
00083         
00084         return True;
00085 }
00086 
00087 
00088 /**********************************************************************
00089  The full path to the registry key is used as database after the 
00090  \'s are converted to /'s.  Key string is also normalized to UPPER
00091  case. 
00092 **********************************************************************/
00093 
00094 void normalize_reg_path( pstring keyname )
00095 {
00096         pstring_sub( keyname, "\\", "/" );
00097         strupper_m( keyname  );
00098 }
00099 
00100 /**********************************************************************
00101  move to next non-delimter character
00102 *********************************************************************/
00103 
00104 char* reg_remaining_path( const char *key )
00105 {
00106         static pstring new_path;
00107         char *p;
00108         
00109         if ( !key || !*key )
00110                 return NULL;
00111 
00112         pstrcpy( new_path, key );
00113         /* normalize_reg_path( new_path ); */
00114         
00115         if ( !(p = strchr( new_path, '\\' )) ) 
00116         {
00117                 if ( !(p = strchr( new_path, '/' )) )
00118                         p = new_path;
00119                 else 
00120                         p++;
00121         }
00122         else
00123                 p++;
00124                 
00125         return p;
00126 }
00127 
00128 /**********************************************************************
00129 *********************************************************************/
00130 
00131 int regval_convert_multi_sz( uint16 *multi_string, size_t byte_len, char ***values )
00132 {
00133         char **sz;
00134         int i;
00135         int num_strings = 0;
00136         fstring buffer;
00137         uint16 *wp;
00138         size_t multi_len = byte_len / 2;
00139         
00140         if ( !multi_string || !values )
00141                 return 0;
00142 
00143         *values = NULL;
00144 
00145         /* just count the NULLs */
00146         
00147         for ( i=0; (i<multi_len-1) && !(multi_string[i]==0x0 && multi_string[i+1]==0x0); i++ ) {
00148                 /* peek ahead */
00149                 if ( multi_string[i+1] == 0x0 )
00150                         num_strings++;
00151         }
00152 
00153         if ( num_strings == 0 )
00154                 return 0;
00155         
00156         if ( !(sz = TALLOC_ARRAY( NULL, char*, num_strings+1 )) ) {
00157                 DEBUG(0,("reg_convert_multi_sz: talloc() failed!\n"));
00158                 return -1;
00159         }
00160 
00161         wp = multi_string;
00162         
00163         for ( i=0; i<num_strings; i++ ) {
00164                 rpcstr_pull( buffer, wp, sizeof(buffer), -1, STR_TERMINATE );
00165                 sz[i] = talloc_strdup( sz, buffer );
00166                 
00167                 /* skip to the next string NULL and then one more */
00168                 while ( *wp )
00169                         wp++;
00170                 wp++;
00171         }
00172         
00173         /* tag the array off with an empty string */
00174         sz[i] = '\0';
00175         
00176         *values = sz;
00177         
00178         return num_strings;
00179 }
00180 
00181 /**********************************************************************
00182  Returns number of bytes, not number of unicode characters
00183 *********************************************************************/
00184 
00185 size_t regval_build_multi_sz( char **values, uint16 **buffer )
00186 {
00187         int i;
00188         size_t buf_size = 0;
00189         uint16 *buf, *b;
00190         UNISTR2 sz;
00191 
00192         if ( !values || !buffer )
00193                 return 0;
00194         
00195         /* go ahead and alloc some space */
00196         
00197         if ( !(buf = TALLOC_ARRAY( NULL, uint16, 2 )) ) {
00198                 DEBUG(0,("regval_build_multi_sz: talloc() failed!\n"));
00199                 return 0;
00200         }
00201         
00202         for ( i=0; values[i]; i++ ) {
00203                 ZERO_STRUCT( sz );
00204                 /* DEBUG(0,("regval_build_multi_sz: building [%s]\n",values[i])); */
00205                 init_unistr2( &sz, values[i], UNI_STR_TERMINATE );
00206                 
00207                 /* Alloc some more memory.  Always add one one to account for the 
00208                    double NULL termination */
00209                    
00210                 b = TALLOC_REALLOC_ARRAY( NULL, buf, uint16, buf_size+sz.uni_str_len+1 );
00211                 if ( !b ) {
00212                         DEBUG(0,("regval_build_multi_sz: talloc() reallocation error!\n"));
00213                         TALLOC_FREE( buffer );
00214                         return 0;
00215                 }
00216                 buf = b;
00217 
00218                 /* copy the unistring2 buffer and increment the size */ 
00219                 /* dump_data(1,sz.buffer,sz.uni_str_len*2); */
00220                 memcpy( buf+buf_size, sz.buffer, sz.uni_str_len*2 );
00221                 buf_size += sz.uni_str_len;
00222                 
00223                 /* cleanup rather than leaving memory hanging around */
00224                 TALLOC_FREE( sz.buffer );
00225         }
00226         
00227         buf[buf_size++] = 0x0;
00228 
00229         *buffer = buf;
00230 
00231         /* return number of bytes */
00232         return buf_size*2;
00233 }
00234 
00235 

Sambaに対してSat Aug 29 21:23:15 2009に生成されました。  doxygen 1.4.7