libmsrpc/libmsrpc_internal.c

説明を見る。
00001 
00002 /* 
00003  *  Unix SMB/CIFS implementation.
00004  *  MS-RPC client internal functions
00005  *  Copyright (C) Chris Nicholls              2005.
00006  *  
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *  
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *  
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020  */
00021 
00022 
00023 #include "libmsrpc.h"
00024 #include "libmsrpc_internal.h"
00025 
00026 char *cac_unistr_to_str( TALLOC_CTX * mem_ctx, uint16 * src, int num_bytes );
00027 char *talloc_unistr2_to_ascii( TALLOC_CTX * mem_ctx, UNISTR2 str );
00028 char *cac_unistr_ascii( TALLOC_CTX * mem_ctx, UNISTR src );
00029 
00030 /*used to get a struct rpc_pipe_client* to be passed into rpccli* calls*/
00031 struct rpc_pipe_client *cac_GetPipe( CacServerHandle * hnd, int pi_idx )
00032 {
00033         SMBCSRV *srv = NULL;
00034         struct rpc_pipe_client *pipe_hnd = NULL;
00035 
00036         if ( !hnd ) {
00037                 return NULL;
00038         }
00039 
00040         if ( hnd->_internal.pipes[pi_idx] == False ) {
00041                 hnd->status = NT_STATUS_INVALID_HANDLE;
00042                 return NULL;
00043         }
00044 
00045         srv = cac_GetServer( hnd );
00046         if ( !srv ) {
00047                 hnd->status = NT_STATUS_INVALID_CONNECTION;
00048                 return NULL;
00049         }
00050 
00051         pipe_hnd = srv->cli->pipe_list;
00052 
00053         while ( pipe_hnd != NULL && pipe_hnd->pipe_idx != pi_idx ) {
00054                 pipe_hnd = pipe_hnd->next;
00055         }
00056 
00057         return pipe_hnd;
00058 }
00059 
00060 /*takes a string like HKEY_LOCAL_MACHINE\HARDWARE\ACPI and returns the reg_type code and then a pointer to the start of the path (HARDWARE)*/
00061 int cac_ParseRegPath( char *path, uint32 * reg_type, char **key_name )
00062 {
00063 
00064         if ( !path )
00065                 return CAC_FAILURE;
00066 
00067         if ( strncmp( path, "HKLM", 4 ) == 0 ) {
00068                 *reg_type = HKEY_LOCAL_MACHINE;
00069                 *key_name = ( path[4] == '\\' ) ? path + 5 : NULL;
00070         } else if ( strncmp( path, "HKEY_LOCAL_MACHINE", 18 ) == 0 ) {
00071                 *reg_type = HKEY_LOCAL_MACHINE;
00072                 *key_name = ( path[18] == '\\' ) ? path + 19 : NULL;
00073         } else if ( strncmp( path, "HKCR", 4 ) == 0 ) {
00074                 *reg_type = HKEY_CLASSES_ROOT;
00075                 *key_name = ( path[4] == '\\' ) ? path + 5 : NULL;
00076         } else if ( strncmp( path, "HKEY_CLASSES_ROOT", 17 ) == 0 ) {
00077                 *reg_type = HKEY_CLASSES_ROOT;
00078                 *key_name = ( path[17] == '\\' ) ? path + 18 : NULL;
00079         } else if ( strncmp( path, "HKU", 3 ) == 0 ) {
00080                 *reg_type = HKEY_USERS;
00081                 *key_name = ( path[3] == '\\' ) ? path + 4 : NULL;
00082         } else if ( strncmp( path, "HKEY_USERS", 10 ) == 0 ) {
00083                 *reg_type = HKEY_USERS;
00084                 *key_name = ( path[10] == '\\' ) ? path + 11 : NULL;
00085         } else if ( strncmp( path, "HKPD", 4 ) == 0 ) {
00086                 *reg_type = HKEY_PERFORMANCE_DATA;
00087                 *key_name = ( path[4] == '\\' ) ? path + 5 : NULL;
00088         } else if ( strncmp( path, "HKEY_PERFORMANCE_DATA", 21 ) == 0 ) {
00089                 *reg_type = HKEY_PERFORMANCE_DATA;
00090                 *key_name = ( path[21] == '\\' ) ? path + 22 : NULL;
00091         } else {
00092                 return CAC_FAILURE;
00093         }
00094 
00095         return CAC_SUCCESS;
00096 }
00097 
00098 
00099 
00100 RPC_DATA_BLOB *cac_MakeRpcDataBlob( TALLOC_CTX * mem_ctx, uint32 data_type,
00101                                     REG_VALUE_DATA data )
00102 {
00103         RPC_DATA_BLOB *blob = NULL;
00104         int i;
00105         uint32 size = 0;
00106         uint8 *multi = NULL;
00107         uint32 multi_idx = 0;
00108 
00109         blob = talloc( mem_ctx, RPC_DATA_BLOB );
00110 
00111         if ( !blob ) {
00112                 errno = ENOMEM;
00113                 return NULL;
00114         }
00115 
00116         switch ( data_type ) {
00117         case REG_SZ:
00118                 init_rpc_blob_str( blob, data.reg_sz,
00119                                    strlen( data.reg_sz ) + 1 );
00120                 break;
00121 
00122         case REG_EXPAND_SZ:
00123                 init_rpc_blob_str( blob, data.reg_expand_sz,
00124                                    strlen( data.reg_sz ) + 1 );
00125                 break;
00126 
00127         case REG_BINARY:
00128                 init_rpc_blob_bytes( blob, data.reg_binary.data,
00129                                      data.reg_binary.data_length );
00130                 break;
00131 
00132         case REG_DWORD:
00133                 init_rpc_blob_uint32( blob, data.reg_dword );
00134                 break;
00135 
00136         case REG_DWORD_BE:
00137                 init_rpc_blob_uint32( blob, data.reg_dword_be );
00138                 break;
00139 
00140         case REG_MULTI_SZ:
00141                 /*need to find the size */
00142                 for ( i = 0; i < data.reg_multi_sz.num_strings; i++ ) {
00143                         size += strlen( data.reg_multi_sz.strings[i] ) + 1;
00144                 }
00145 
00146          /**need a whole bunch of unicode strings in a row (seperated by null characters), with an extra null-character on the end*/
00147 
00148                 multi = TALLOC_ZERO_ARRAY( mem_ctx, uint8, ( size + 1 ) * 2 );  /*size +1 for the extra null character */
00149                 if ( !multi ) {
00150                         errno = ENOMEM;
00151                         break;
00152                 }
00153 
00154                 /*do it using rpcstr_push() */
00155                 multi_idx = 0;
00156                 for ( i = 0; i < data.reg_multi_sz.num_strings; i++ ) {
00157                         size_t len =
00158                                 strlen( data.reg_multi_sz.strings[i] ) + 1;
00159 
00160                         rpcstr_push( ( multi + multi_idx ),
00161                                      data.reg_multi_sz.strings[i], len * 2,
00162                                      STR_TERMINATE );
00163 
00164                         /* x2 becuase it is a uint8 buffer */
00165                         multi_idx += len * 2;
00166                 }
00167 
00168                 /*now initialize the buffer as binary data */
00169                 init_rpc_blob_bytes( blob, multi, ( size + 1 ) * 2 );
00170 
00171                 break;
00172 
00173         default:
00174                 TALLOC_FREE( blob );
00175                 blob = NULL;
00176                 return NULL;
00177         }
00178 
00179         if ( !( blob->buffer ) ) {
00180                 TALLOC_FREE( blob );
00181                 return NULL;
00182         }
00183 
00184         return blob;
00185 }
00186 
00187 /*turns a string in a uint16 array to a char array*/
00188 char *cac_unistr_to_str( TALLOC_CTX * mem_ctx, uint16 * src, int num_bytes )
00189 {
00190         char *buf;
00191 
00192         int i = 0;
00193 
00194         uint32 str_len = 0;
00195 
00196         /*don't allocate more space than we need */
00197         while ( ( str_len ) < num_bytes / 2 && src[str_len] != 0x0000 )
00198                 str_len++;
00199 
00200         /*need room for a '\0' */
00201         str_len++;
00202 
00203         buf = TALLOC_ARRAY( mem_ctx, char, str_len );
00204 
00205         if ( !buf ) {
00206                 return NULL;
00207         }
00208 
00209         for ( i = 0; i < num_bytes / 2; i++ ) {
00210                 buf[i] = ( ( char * ) src )[2 * i];
00211         }
00212 
00213         buf[str_len - 1] = '\0';
00214 
00215         return buf;
00216 }
00217 
00218 REG_VALUE_DATA *cac_MakeRegValueData( TALLOC_CTX * mem_ctx, uint32 data_type,
00219                                       REGVAL_BUFFER buf )
00220 {
00221         REG_VALUE_DATA *data;
00222 
00223         uint32 i;
00224 
00225         /*all of the following used for MULTI_SZ data */
00226         uint32 size = 0;
00227         uint32 len = 0;
00228         uint32 multi_idx = 0;
00229         uint32 num_strings = 0;
00230         char **strings = NULL;
00231 
00232         data = talloc( mem_ctx, REG_VALUE_DATA );
00233         if ( !data ) {
00234                 errno = ENOMEM;
00235                 return NULL;
00236         }
00237 
00238         switch ( data_type ) {
00239         case REG_SZ:
00240                 data->reg_sz =
00241                         cac_unistr_to_str( mem_ctx, buf.buffer, buf.buf_len );
00242                 if ( !data->reg_sz ) {
00243                         TALLOC_FREE( data );
00244                         errno = ENOMEM;
00245                         data = NULL;
00246                 }
00247 
00248                 break;
00249 
00250         case REG_EXPAND_SZ:
00251                 data->reg_expand_sz =
00252                         cac_unistr_to_str( mem_ctx, buf.buffer, buf.buf_len );
00253 
00254                 if ( !data->reg_expand_sz ) {
00255                         TALLOC_FREE( data );
00256                         errno = ENOMEM;
00257                         data = NULL;
00258                 }
00259 
00260                 break;
00261 
00262         case REG_BINARY:
00263                 size = buf.buf_len;
00264 
00265                 data->reg_binary.data_length = size;
00266 
00267                 if (size) {
00268                         data->reg_binary.data =
00269                                 ( uint8 * ) TALLOC_MEMDUP( mem_ctx, buf.buffer, size );
00270                         if ( !data->reg_binary.data ) {
00271                                 TALLOC_FREE( data );
00272                                 errno = ENOMEM;
00273                                 data = NULL;
00274                         }
00275                 } else {
00276                         data->reg_binary.data = NULL;
00277                 }
00278                 break;
00279 
00280         case REG_DWORD:
00281                 data->reg_dword = *( ( uint32 * ) buf.buffer );
00282                 break;
00283 
00284         case REG_DWORD_BE:
00285                 data->reg_dword_be = *( ( uint32 * ) buf.buffer );
00286                 break;
00287 
00288         case REG_MULTI_SZ:
00289                 size = buf.buf_len;
00290 
00291                 /*find out how many strings there are. size is # of bytes and we want to work uint16 */
00292                 for ( i = 0; i < ( size / 2 - 1 ); i++ ) {
00293                         if ( buf.buffer[i] == 0x0000 )
00294                                 num_strings++;
00295 
00296                         /*buffer is suppsed to be terminated with \0\0, but it might not be */
00297                         if ( buf.buffer[i] == 0x0000
00298                              && buf.buffer[i + 1] == 0x0000 )
00299                                 break;
00300                 }
00301 
00302                 if (num_strings) {
00303                         strings = TALLOC_ARRAY( mem_ctx, char *, num_strings );
00304 
00305                         if ( !strings ) {
00306                                 errno = ENOMEM;
00307                                 TALLOC_FREE( data );
00308                                 break;
00309                         }
00310                 } else {
00311                         strings = NULL;
00312                 }
00313 
00314                 if ( num_strings == 0 ) /*then our work here is done */
00315                         break;
00316 
00317                 for ( i = 0; i < num_strings; i++ ) {
00318                         /*find out how many characters are in this string */
00319                         len = 0;
00320                         /*make sure we don't go past the end of the buffer and keep looping until we have a uni \0 */
00321                         while ( multi_idx + len < size / 2
00322                                 && buf.buffer[multi_idx + len] != 0x0000 )
00323                                 len++;
00324 
00325                         /*stay aware of the \0\0 */
00326                         len++;
00327 
00328                         strings[i] = TALLOC_ZERO_ARRAY( mem_ctx, char, len );
00329 
00330                         /*pull out the unicode string */
00331                         rpcstr_pull( strings[i], ( buf.buffer + multi_idx ),
00332                                      len, -1, STR_TERMINATE );
00333 
00334                         /*keep track of where we are in the bigger array */
00335                         multi_idx += len;
00336                 }
00337 
00338                 data->reg_multi_sz.num_strings = num_strings;
00339                 data->reg_multi_sz.strings = strings;
00340 
00341                 break;
00342 
00343         default:
00344                 TALLOC_FREE( data );
00345                 data = NULL;
00346         }
00347 
00348         return data;
00349 }
00350 
00351 SAM_USERINFO_CTR *cac_MakeUserInfoCtr( TALLOC_CTX * mem_ctx,
00352                                        CacUserInfo * info )
00353 {
00354         SAM_USERINFO_CTR *ctr = NULL;
00355 
00356         /*the flags we are 'setting'- include/passdb.h */
00357         uint32 flags =
00358                 ACCT_USERNAME | ACCT_FULL_NAME | ACCT_PRIMARY_GID |
00359                 ACCT_DESCRIPTION | ACCT_COMMENT | ACCT_HOME_DIR |
00360                 ACCT_HOME_DRIVE | ACCT_LOGON_SCRIPT | ACCT_PROFILE |
00361                 ACCT_WORKSTATIONS | ACCT_FLAGS;
00362 
00363         NTTIME logon_time;
00364         NTTIME logoff_time;
00365         NTTIME kickoff_time;
00366         NTTIME pass_last_set_time;
00367         NTTIME pass_can_change_time;
00368         NTTIME pass_must_change_time;
00369 
00370         UNISTR2 user_name;
00371         UNISTR2 full_name;
00372         UNISTR2 home_dir;
00373         UNISTR2 dir_drive;
00374         UNISTR2 log_scr;
00375         UNISTR2 prof_path;
00376         UNISTR2 desc;
00377         UNISTR2 wkstas;
00378         UNISTR2 mung_dial;
00379         UNISTR2 unk;
00380 
00381         ctr = talloc( mem_ctx, SAM_USERINFO_CTR );
00382         if ( !ctr )
00383                 return NULL;
00384 
00385         ZERO_STRUCTP( ctr->info.id23 );
00386 
00387         ctr->info.id21 = talloc( mem_ctx, SAM_USER_INFO_21 );
00388         if ( !ctr->info.id21 )
00389                 return NULL;
00390 
00391         ctr->switch_value = 21;
00392 
00393         ZERO_STRUCTP( ctr->info.id21 );
00394 
00395         unix_to_nt_time( &logon_time, info->logon_time );
00396         unix_to_nt_time( &logoff_time, info->logoff_time );
00397         unix_to_nt_time( &kickoff_time, info->kickoff_time );
00398         unix_to_nt_time( &pass_last_set_time, info->pass_last_set_time );
00399         unix_to_nt_time( &pass_can_change_time, info->pass_can_change_time );
00400         unix_to_nt_time( &pass_must_change_time,
00401                          info->pass_must_change_time );
00402 
00403         /*initialize the strings */
00404         init_unistr2( &user_name, info->username, UNI_STR_TERMINATE );
00405         init_unistr2( &full_name, info->full_name, UNI_STR_TERMINATE );
00406         init_unistr2( &home_dir, info->home_dir, UNI_STR_TERMINATE );
00407         init_unistr2( &dir_drive, info->home_drive, UNI_STR_TERMINATE );
00408         init_unistr2( &log_scr, info->logon_script, UNI_STR_TERMINATE );
00409         init_unistr2( &prof_path, info->profile_path, UNI_STR_TERMINATE );
00410         init_unistr2( &desc, info->description, UNI_STR_TERMINATE );
00411         init_unistr2( &wkstas, info->workstations, UNI_STR_TERMINATE );
00412         init_unistr2( &unk, "\0", UNI_STR_TERMINATE );
00413         init_unistr2( &mung_dial, info->dial, UNI_STR_TERMINATE );
00414 
00415         /*manually set passmustchange */
00416         ctr->info.id21->passmustchange =
00417                 ( info->pass_must_change ) ? 0x01 : 0x00;
00418 
00419         init_sam_user_info21W( ctr->info.id21, &logon_time, &logoff_time, &kickoff_time, &pass_last_set_time, &pass_can_change_time, &pass_must_change_time, &user_name, &full_name, &home_dir, &dir_drive, &log_scr, &prof_path, &desc, &wkstas, &unk, &mung_dial, info->lm_password, info->nt_password, info->rid, info->group_rid, info->acb_mask, flags, 168,       /*logon divs */
00420                                info->logon_hours,
00421                                info->bad_passwd_count, info->logon_count );
00422 
00423         return ctr;
00424 
00425 }
00426 
00427 char *talloc_unistr2_to_ascii( TALLOC_CTX * mem_ctx, UNISTR2 str )
00428 {
00429         char *buf = NULL;
00430 
00431         if ( !mem_ctx )
00432                 return NULL;
00433 
00434         buf = TALLOC_ARRAY( mem_ctx, char, ( str.uni_str_len + 1 ) );
00435         if ( !buf )
00436                 return NULL;
00437 
00438         unistr2_to_ascii( buf, &str, str.uni_str_len + 1 );
00439 
00440         return buf;
00441 }
00442 
00443 CacUserInfo *cac_MakeUserInfo( TALLOC_CTX * mem_ctx, SAM_USERINFO_CTR * ctr )
00444 {
00445         CacUserInfo *info = NULL;
00446         SAM_USER_INFO_21 *id21 = NULL;
00447 
00448         if ( !ctr || ctr->switch_value != 21 )
00449                 return NULL;
00450 
00451         info = talloc( mem_ctx, CacUserInfo );
00452         if ( !info )
00453                 return NULL;
00454 
00455         id21 = ctr->info.id21;
00456 
00457         ZERO_STRUCTP( info );
00458 
00459         info->logon_time = nt_time_to_unix( id21->logon_time );
00460         info->logoff_time = nt_time_to_unix( id21->logoff_time );
00461         info->kickoff_time = nt_time_to_unix( id21->kickoff_time );
00462         info->pass_last_set_time =
00463                 nt_time_to_unix( id21->pass_last_set_time );
00464         info->pass_can_change_time =
00465                 nt_time_to_unix( id21->pass_can_change_time );
00466         info->pass_must_change_time =
00467                 nt_time_to_unix( id21->pass_must_change_time );
00468 
00469         info->username =
00470                 talloc_unistr2_to_ascii( mem_ctx, id21->uni_user_name );
00471         if ( !info->username )
00472                 return NULL;
00473 
00474         info->full_name =
00475                 talloc_unistr2_to_ascii( mem_ctx, id21->uni_full_name );
00476         if ( !info->full_name )
00477                 return NULL;
00478 
00479         info->home_dir =
00480                 talloc_unistr2_to_ascii( mem_ctx, id21->uni_home_dir );
00481         if ( !info->home_dir )
00482                 return NULL;
00483 
00484         info->home_drive =
00485                 talloc_unistr2_to_ascii( mem_ctx, id21->uni_dir_drive );
00486         if ( !info->home_drive )
00487                 return NULL;
00488 
00489         info->logon_script =
00490                 talloc_unistr2_to_ascii( mem_ctx, id21->uni_logon_script );
00491         if ( !info->logon_script )
00492                 return NULL;
00493 
00494         info->profile_path =
00495                 talloc_unistr2_to_ascii( mem_ctx, id21->uni_profile_path );
00496         if ( !info->profile_path )
00497                 return NULL;
00498 
00499         info->description =
00500                 talloc_unistr2_to_ascii( mem_ctx, id21->uni_acct_desc );
00501         if ( !info->description )
00502                 return NULL;
00503 
00504         info->workstations =
00505                 talloc_unistr2_to_ascii( mem_ctx, id21->uni_workstations );
00506         if ( !info->workstations )
00507                 return NULL;
00508 
00509         info->dial =
00510                 talloc_unistr2_to_ascii( mem_ctx, id21->uni_munged_dial );
00511         if ( !info->dial )
00512                 return NULL;
00513 
00514         info->rid = id21->user_rid;
00515         info->group_rid = id21->group_rid;
00516         info->acb_mask = id21->acb_info;
00517         info->bad_passwd_count = id21->bad_password_count;
00518         info->logon_count = id21->logon_count;
00519 
00520         memcpy( info->nt_password, id21->nt_pwd, 8 );
00521         memcpy( info->lm_password, id21->lm_pwd, 8 );
00522 
00523         info->logon_hours =
00524                 ( LOGON_HRS * ) TALLOC_MEMDUP( mem_ctx, &( id21->logon_hrs ),
00525                                                sizeof( LOGON_HRS ) );
00526         if ( !info->logon_hours )
00527                 return NULL;
00528 
00529         info->pass_must_change = ( id21->passmustchange ) ? True : False;
00530 
00531         return info;
00532 }
00533 
00534 CacGroupInfo *cac_MakeGroupInfo( TALLOC_CTX * mem_ctx, GROUP_INFO_CTR * ctr )
00535 {
00536         CacGroupInfo *info = NULL;
00537 
00538         if ( !mem_ctx || !ctr || ctr->switch_value1 != 1 )
00539                 return NULL;
00540 
00541         info = talloc( mem_ctx, CacGroupInfo );
00542         if ( !info )
00543                 return NULL;
00544 
00545         info->name =
00546                 talloc_unistr2_to_ascii( mem_ctx,
00547                                          ctr->group.info1.uni_acct_name );
00548         if ( !info->name )
00549                 return NULL;
00550 
00551         info->description =
00552                 talloc_unistr2_to_ascii( mem_ctx,
00553                                          ctr->group.info1.uni_acct_desc );
00554         if ( !info->description )
00555                 return NULL;
00556 
00557         info->num_members = ctr->group.info1.num_members;
00558 
00559         return info;
00560 }
00561 
00562 GROUP_INFO_CTR *cac_MakeGroupInfoCtr( TALLOC_CTX * mem_ctx,
00563                                       CacGroupInfo * info )
00564 {
00565         GROUP_INFO_CTR *ctr = NULL;
00566 
00567         if ( !mem_ctx || !info )
00568                 return NULL;
00569 
00570         ctr = talloc( mem_ctx, GROUP_INFO_CTR );
00571         if ( !ctr )
00572                 return NULL;
00573 
00574         ctr->switch_value1 = 1;
00575 
00576         init_samr_group_info1( &( ctr->group.info1 ), info->name,
00577                                info->description, info->num_members );
00578 
00579         return ctr;
00580 }
00581 
00582 CacAliasInfo *cac_MakeAliasInfo( TALLOC_CTX * mem_ctx, ALIAS_INFO_CTR ctr )
00583 {
00584         CacGroupInfo *info = NULL;
00585 
00586         if ( !mem_ctx || ctr.level != 1 )
00587                 return NULL;
00588 
00589         info = talloc( mem_ctx, CacAliasInfo );
00590         if ( !info )
00591                 return NULL;
00592 
00593         info->name =
00594                 talloc_unistr2_to_ascii( mem_ctx,
00595                                          *( ctr.alias.info1.name.string ) );
00596         if ( !info->name )
00597                 return NULL;
00598 
00599         info->description =
00600                 talloc_unistr2_to_ascii( mem_ctx,
00601                                          *( ctr.alias.info1.description.
00602                                             string ) );
00603         if ( !info->name )
00604                 return NULL;
00605 
00606         info->num_members = ctr.alias.info1.num_member;
00607 
00608         return info;
00609 }
00610 
00611 ALIAS_INFO_CTR *cac_MakeAliasInfoCtr( TALLOC_CTX * mem_ctx,
00612                                       CacAliasInfo * info )
00613 {
00614         ALIAS_INFO_CTR *ctr = NULL;
00615 
00616         if ( !mem_ctx || !info )
00617                 return NULL;
00618 
00619         ctr = talloc( mem_ctx, ALIAS_INFO_CTR );
00620         if ( !ctr )
00621                 return NULL;
00622 
00623         ctr->level = 1;
00624 
00625         init_samr_alias_info1( &( ctr->alias.info1 ), info->name,
00626                                info->num_members, info->description );
00627 
00628         return ctr;
00629 }
00630 
00631 CacDomainInfo *cac_MakeDomainInfo( TALLOC_CTX * mem_ctx,
00632                                    SAM_UNK_INFO_1 * info1,
00633                                    SAM_UNK_INFO_2 * info2,
00634                                    SAM_UNK_INFO_12 * info12 )
00635 {
00636         CacDomainInfo *info = NULL;
00637 
00638         if ( !mem_ctx || !info1 || !info2 || !info12 )
00639                 return NULL;
00640 
00641         info = talloc( mem_ctx, CacDomainInfo );
00642         if ( !info )
00643                 return NULL;
00644 
00645         info->min_pass_length = info1->min_length_password;
00646         info->pass_history = info1->password_history;
00647 
00648         cac_InitCacTime( &( info->expire ), info1->expire );
00649         cac_InitCacTime( &( info->min_pass_age ), info1->min_passwordage );
00650 
00651         info->server_role = info2->server_role;
00652         info->num_users = info2->num_domain_usrs;
00653         info->num_domain_groups = info2->num_domain_grps;
00654         info->num_local_groups = info2->num_local_grps;
00655 
00656         /*if these have been ZERO'd out we need to know. uni_str_len will be 0 */
00657         if ( info2->uni_comment.uni_str_len == 0 ) {
00658                 info->comment = talloc_strdup( mem_ctx, "\0" );
00659         } else {
00660                 info->comment =
00661                         talloc_unistr2_to_ascii( mem_ctx,
00662                                                  info2->uni_comment );
00663         }
00664 
00665         if ( info2->uni_domain.uni_str_len == 0 ) {
00666                 info->domain_name = talloc_strdup( mem_ctx, "\0" );
00667         } else {
00668                 info->domain_name =
00669                         talloc_unistr2_to_ascii( mem_ctx, info2->uni_domain );
00670         }
00671 
00672         if ( info2->uni_server.uni_str_len == 0 ) {
00673                 info->server_name = talloc_strdup( mem_ctx, "\0" );
00674         } else {
00675                 info->server_name =
00676                         talloc_unistr2_to_ascii( mem_ctx, info2->uni_server );
00677         }
00678 
00679 
00680         cac_InitCacTime( &( info->lockout_duration ), info12->duration );
00681         cac_InitCacTime( &( info->lockout_reset ), info12->reset_count );
00682         info->num_bad_attempts = info12->bad_attempt_lockout;
00683 
00684         return info;
00685 }
00686 
00687 char *cac_unistr_ascii( TALLOC_CTX * mem_ctx, UNISTR src )
00688 {
00689         char *buf;
00690         uint32 len;
00691 
00692         if ( !mem_ctx || !src.buffer )
00693                 return NULL;
00694 
00695         len = unistrlen( src.buffer ) + 1;
00696 
00697         buf = TALLOC_ZERO_ARRAY( mem_ctx, char, len );
00698         if ( !buf )
00699                 return NULL;
00700 
00701         rpcstr_pull( buf, src.buffer, len, -1, STR_TERMINATE );
00702 
00703         return buf;
00704 }
00705 
00706 CacService *cac_MakeServiceArray( TALLOC_CTX * mem_ctx,
00707                                   ENUM_SERVICES_STATUS * svc,
00708                                   uint32 num_services )
00709 {
00710         int i;
00711         CacService *services = NULL;
00712 
00713         if ( !mem_ctx || !svc )
00714                 return NULL;
00715 
00716         if (num_services) {
00717                 services = TALLOC_ZERO_ARRAY( mem_ctx, CacService, num_services );
00718                 if ( !services )
00719                         return NULL;
00720         } else {
00721                 services = NULL;
00722         }
00723 
00724         for ( i = 0; i < num_services; i++ ) {
00725                 services[i].service_name =
00726                         cac_unistr_ascii( mem_ctx, svc[i].servicename );
00727                 services[i].display_name =
00728                         cac_unistr_ascii( mem_ctx, svc[i].displayname );
00729 
00730                 if ( !services[i].service_name || !services[i].display_name )
00731                         return NULL;
00732 
00733                 services[i].status = svc[i].status;
00734         }
00735 
00736         return services;
00737 }
00738 
00739 int cac_InitCacServiceConfig( TALLOC_CTX * mem_ctx, SERVICE_CONFIG * src,
00740                               CacServiceConfig * dest )
00741 {
00742         if ( !src || !dest )
00743                 return CAC_FAILURE;
00744 
00745         dest->exe_path =
00746                 talloc_unistr2_to_ascii( mem_ctx, *src->executablepath );
00747         if ( !dest->exe_path )
00748                 return CAC_FAILURE;
00749 
00750         dest->load_order_group =
00751                 talloc_unistr2_to_ascii( mem_ctx, *src->loadordergroup );
00752         if ( !dest->load_order_group )
00753                 return CAC_FAILURE;
00754 
00755         dest->dependencies =
00756                 talloc_unistr2_to_ascii( mem_ctx, *src->dependencies );
00757         if ( !dest->dependencies )
00758                 return CAC_FAILURE;
00759 
00760         dest->start_name =
00761                 talloc_unistr2_to_ascii( mem_ctx, *src->startname );
00762         if ( !dest->start_name )
00763                 return CAC_FAILURE;
00764 
00765         dest->display_name =
00766                 talloc_unistr2_to_ascii( mem_ctx, *src->displayname );
00767         if ( !dest->display_name )
00768                 return CAC_FAILURE;
00769 
00770         dest->type = src->service_type;
00771         dest->start_type = src->start_type;
00772         dest->error_control = src->error_control;
00773         dest->tag_id = src->tag_id;
00774 
00775         return CAC_SUCCESS;
00776 }

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