関数 | |
void | cac_Init (int debug) |
Initializes the library - do not need to call this function. | |
CacServerHandle * | cac_NewServerHandle (BOOL allocate_fields) |
Creates an un-initialized CacServerHandle | |
void | cac_SetAuthDataFn (CacServerHandle *hnd, smbc_get_auth_data_fn auth_fn) |
Specifies the smbc_get_auth_data_fn to use if you do not want to use the default. | |
void | cac_SetSmbcContext (CacServerHandle *hnd, SMBCCTX *ctx) |
Use your own libsmbclient context - not necessary. | |
int | cac_Connect (CacServerHandle *hnd, const char *srv) |
Connects to a specified server. | |
void | cac_FreeHandle (CacServerHandle *hnd) |
Cleans up any data used by the CacServerHandle. | |
void | cac_InitCacTime (CacTime *cactime, NTTIME nttime) |
Initializes a CacTime structure based on an NTTIME structure If the function fails, then the CacTime structure will be zero'd out | |
int | cac_InitHandleMem (CacServerHandle *hnd) |
Called by cac_NewServerHandle() if allocate_fields = True. | |
void | cac_GetAuthDataFn (const char *pServer, const char *pShare, char *pWorkgroup, int maxLenWorkgroup, char *pUsername, int maxLenUsername, char *pPassword, int maxLenPassword) |
Default smbc_get_auth_data_fn for libmsrpc. |
void cac_Init | ( | int | debug | ) |
Initializes the library - do not need to call this function.
Open's smb.conf as well as initializes logging.
debug | Debug level for library to use |
libmsrpc.c の 30 行で定義されています。
参照先 DEBUGLEVEL・setup_logging().
00031 { 00032 if ( debug < 0 || debug > 99 ) 00033 debug = 0; 00034 00035 DEBUGLEVEL = debug; 00036 00037 setup_logging( "libmsrpc", True ); 00038 }
CacServerHandle* cac_NewServerHandle | ( | BOOL | allocate_fields | ) |
Creates an un-initialized CacServerHandle
allocate_fields | If True, the function will allocate sizeof(fstring) bytes for all char * fields in the handle |
libmsrpc.c の 76 行で定義されています。
参照先 _CACSERVERHANDLE::_internal・_SMBCCTX::_smbc_callbacks::auth_fn・cac_FreeHandle()・cac_GetAuthDataFn()・cac_InitHandleMem()・_SMBCCTX::callbacks・CacServerHandleInternal::ctx・_CACSERVERHANDLE::debug・errno・smbc_new_context()・CacServerHandleInternal::srv_level・CacServerHandleInternal::user_supplied_ctx.
00077 { 00078 CacServerHandle *hnd; 00079 00080 hnd = SMB_MALLOC_P( CacServerHandle ); 00081 00082 if ( !hnd ) { 00083 errno = ENOMEM; 00084 return NULL; 00085 } 00086 00087 ZERO_STRUCTP( hnd ); 00088 00089 if ( allocate_fields == True ) { 00090 if ( !cac_InitHandleMem( hnd ) ) { 00091 SAFE_FREE( hnd ); 00092 return NULL; 00093 } 00094 } 00095 00096 hnd->_internal.ctx = smbc_new_context( ); 00097 if ( !hnd->_internal.ctx ) { 00098 cac_FreeHandle( hnd ); 00099 return NULL; 00100 } 00101 00102 hnd->_internal.ctx->callbacks.auth_fn = cac_GetAuthDataFn; 00103 00104 /*add defaults */ 00105 hnd->debug = 0; 00106 00107 /*start at the highest and it will fall down after trying the functions */ 00108 hnd->_internal.srv_level = SRV_WIN_2K3; 00109 00110 hnd->_internal.user_supplied_ctx = False; 00111 00112 return hnd; 00113 }
void cac_SetAuthDataFn | ( | CacServerHandle * | hnd, | |
smbc_get_auth_data_fn | auth_fn | |||
) |
Specifies the smbc_get_auth_data_fn to use if you do not want to use the default.
hnd | non-NULL server handle | |
auth_fn | auth_data_fn to set in server handle |
libmsrpc.c の 143 行で定義されています。
参照先 _CACSERVERHANDLE::_internal・_SMBCCTX::_smbc_callbacks::auth_fn・_SMBCCTX::callbacks・CacServerHandleInternal::ctx.
void cac_SetSmbcContext | ( | CacServerHandle * | hnd, | |
SMBCCTX * | ctx | |||
) |
Use your own libsmbclient context - not necessary.
hnd | Initialized, but not connected CacServerHandle | |
ctx | The libsmbclient context you would like to use. |
libmsrpc.c の 148 行で定義されています。
参照先 _CACSERVERHANDLE::_internal・CacServerHandleInternal::ctx・ctx・CacServerHandleInternal::user_supplied_ctx.
00149 { 00150 00151 SAFE_FREE( hnd->_internal.ctx ); 00152 00153 hnd->_internal.user_supplied_ctx = True; 00154 00155 hnd->_internal.ctx = ctx; 00156 00157 /*_try_ to avoid any problems that might occur if cac_Connect() isn't called*/ 00158 /*cac_InitHandleData(hnd); */ 00159 }
int cac_Connect | ( | CacServerHandle * | hnd, | |
const char * | srv | |||
) |
Connects to a specified server.
If there is already a connection to a different server, it will be cleaned up before connecting to the new server.
hnd | Pre-initialized CacServerHandle | |
srv | (Optional) Name or IP of the server to connect to. If NULL, server from the CacServerHandle will be used. |
CAC_SUCCESS if the operation succeeded
libmsrpc.c の 183 行で定義されています。
参照先 smbc_internal_data::_initialized・_CACSERVERHANDLE::_internal・cac_GetServer()・cac_InitHandleData()・CacServerHandleInternal::ctx・_SMBCCTX::debug・_CACSERVERHANDLE::debug・_CACSERVERHANDLE::domain・_SMBCCTX::internal・_CACSERVERHANDLE::netbios_name・_CACSERVERHANDLE::server・smbc_init_context()・_CACSERVERHANDLE::username.
00184 { 00185 if ( !hnd ) { 00186 return CAC_FAILURE; 00187 } 00188 00189 /*these values should be initialized by the user */ 00190 if ( !hnd->server && !srv ) { 00191 return CAC_FAILURE; 00192 } 00193 00194 00195 /*change the server name in the server handle if necessary */ 00196 if ( srv && hnd->server && strcmp( hnd->server, srv ) == 0 ) { 00197 SAFE_FREE( hnd->server ); 00198 hnd->server = SMB_STRDUP( srv ); 00199 } 00200 00201 00202 /*first see if the context has already been setup */ 00203 if ( !( hnd->_internal.ctx->internal->_initialized ) ) { 00204 hnd->_internal.ctx->debug = hnd->debug; 00205 00206 /*initialize the context */ 00207 if ( !smbc_init_context( hnd->_internal.ctx ) ) { 00208 return CAC_FAILURE; 00209 } 00210 } 00211 00212 /*copy any uninitialized values out of the smbc context into the handle */ 00213 if ( !cac_InitHandleData( hnd ) ) { 00214 return CAC_FAILURE; 00215 } 00216 00217 DEBUG( 3, ( "cac_Connect: Username: %s\n", hnd->username ) ); 00218 DEBUG( 3, ( "cac_Connect: Domain: %s\n", hnd->domain ) ); 00219 DEBUG( 3, ( "cac_Connect: Netbios Name: %s\n", hnd->netbios_name ) ); 00220 00221 if ( !cac_GetServer( hnd ) ) { 00222 return CAC_FAILURE; 00223 } 00224 00225 return CAC_SUCCESS; 00226 00227 }
void cac_FreeHandle | ( | CacServerHandle * | hnd | ) |
Cleans up any data used by the CacServerHandle.
If the libsmbclient context was set using cac_SetSmbcContext(), it will not be free'd.
hnd | the CacServerHandle to destroy |
libmsrpc.c の 230 行で定義されています。
参照先 _CACSERVERHANDLE::_internal・CacServerHandleInternal::ctx・_CACSERVERHANDLE::domain・_CACSERVERHANDLE::netbios_name・_CACSERVERHANDLE::password・_CACSERVERHANDLE::server・smbc_free_context()・CacServerHandleInternal::user_supplied_ctx・_CACSERVERHANDLE::username.
00231 { 00232 if ( !hnd ) 00233 return; 00234 00235 /*only free the context if we created it */ 00236 if ( !hnd->_internal.user_supplied_ctx ) { 00237 smbc_free_context( hnd->_internal.ctx, True ); 00238 } 00239 00240 SAFE_FREE( hnd->netbios_name ); 00241 SAFE_FREE( hnd->domain ); 00242 SAFE_FREE( hnd->username ); 00243 SAFE_FREE( hnd->password ); 00244 SAFE_FREE( hnd->server ); 00245 SAFE_FREE( hnd ); 00246 00247 }
Initializes a CacTime structure based on an NTTIME structure If the function fails, then the CacTime structure will be zero'd out
libmsrpc.c の 249 行で定義されています。
参照先 _CACTIME::days・_CACTIME::hours・_CACTIME::minutes・_CACTIME::seconds.
参照元 cac_MakeDomainInfo().
00250 { 00251 float high, low; 00252 uint32 sec; 00253 00254 if ( !cactime ) 00255 return; 00256 00257 ZERO_STRUCTP( cactime ); 00258 00259 /*this code is taken from display_time() found in rpcclient/cmd_samr.c */ 00260 if ( nttime == 0 ) 00261 return; 00262 00263 if ( nttime == 0x80000000000000LL ) 00264 return; 00265 00266 high = 65536; 00267 high = high / 10000; 00268 high = high * 65536; 00269 high = high / 1000; 00270 high = high * ( ~( nttime >> 32 ) ); 00271 00272 low = ~( nttime & 0xFFFFFFFF ); 00273 low = low / ( 1000 * 1000 * 10 ); 00274 00275 sec = high + low; 00276 00277 cactime->days = sec / ( 60 * 60 * 24 ); 00278 cactime->hours = 00279 ( sec - ( cactime->days * 60 * 60 * 24 ) ) / ( 60 * 60 ); 00280 cactime->minutes = 00281 ( sec - ( cactime->days * 60 * 60 * 24 ) - 00282 ( cactime->hours * 60 * 60 ) ) / 60; 00283 cactime->seconds = 00284 sec - ( cactime->days * 60 * 60 * 24 ) - 00285 ( cactime->hours * 60 * 60 ) - ( cactime->minutes * 60 ); 00286 }
int cac_InitHandleMem | ( | CacServerHandle * | hnd | ) |
Called by cac_NewServerHandle() if allocate_fields = True.
You can call this if you want to, allocates sizeof(fstring) char's for every char * field
hnd | Uninitialized server handle |
CAC_SUCCESS Memory was allocated
libmsrpc.c の 40 行で定義されています。
参照先 _CACSERVERHANDLE::domain・_CACSERVERHANDLE::netbios_name・_CACSERVERHANDLE::password・_CACSERVERHANDLE::server・_CACSERVERHANDLE::username.
00041 { 00042 hnd->username = SMB_MALLOC_ARRAY( char, sizeof( fstring ) ); 00043 00044 if ( !hnd->username ) 00045 return CAC_FAILURE; 00046 00047 hnd->username[0] = '\0'; 00048 00049 hnd->domain = SMB_MALLOC_ARRAY( char, sizeof( fstring ) ); 00050 if ( !hnd->domain ) 00051 return CAC_FAILURE; 00052 00053 hnd->domain[0] = '\0'; 00054 00055 hnd->netbios_name = SMB_MALLOC_ARRAY( char, sizeof( fstring ) ); 00056 if ( !hnd->netbios_name ) 00057 return CAC_FAILURE; 00058 00059 hnd->netbios_name[0] = '\0'; 00060 00061 hnd->password = SMB_MALLOC_ARRAY( char, sizeof( fstring ) ); 00062 if ( !hnd->password ) 00063 return CAC_FAILURE; 00064 00065 hnd->password[0] = '\0'; 00066 00067 hnd->server = SMB_MALLOC_ARRAY( char, sizeof( fstring ) ); 00068 if ( !hnd->server ) 00069 return CAC_FAILURE; 00070 00071 hnd->server[0] = '\0'; 00072 00073 return CAC_SUCCESS; 00074 }
void cac_GetAuthDataFn | ( | const char * | pServer, | |
const char * | pShare, | |||
char * | pWorkgroup, | |||
int | maxLenWorkgroup, | |||
char * | pUsername, | |||
int | maxLenUsername, | |||
char * | pPassword, | |||
int | maxLenPassword | |||
) |
Default smbc_get_auth_data_fn for libmsrpc.
This function is called when libmsrpc needs to get more information about the client (username/password, workgroup). This function provides simple prompts to the user to enter the information. This description his here so you know how to re-define this function.
pServer | Name/IP of the server to connect to. | |
pShare | Share name to connect to | |
pWorkgroup | libmsrpc passes in the workgroup/domain name from hnd->domain. It can be modified in the function. | |
maxLenWorkgroup | The maximum length of a string pWogroup can hold. | |
pUsername | libmsrpc passes in the username from hnd->username. It can be modified in the function. | |
maxLenUsername | The maximum length of a string pUsername can hold. | |
pPassword | libmsrpc pass in the password from hnd->password. It can be modified in the function. | |
maxLenPassword | The maximum length of a string pPassword can hold. |
libmsrpc.c の 288 行で定義されています。
参照先 d_printf().
00295 { 00296 char temp[sizeof( fstring )]; 00297 00298 static char authUsername[sizeof( fstring )]; 00299 static char authWorkgroup[sizeof( fstring )]; 00300 static char authPassword[sizeof( fstring )]; 00301 static char authSet = 0; 00302 00303 char *pass = NULL; 00304 00305 00306 if ( authSet ) { 00307 strncpy( pWorkgroup, authWorkgroup, maxLenWorkgroup - 1 ); 00308 strncpy( pUsername, authUsername, maxLenUsername - 1 ); 00309 strncpy( pPassword, authPassword, maxLenPassword - 1 ); 00310 } else { 00311 d_printf( "Domain: [%s] ", pWorkgroup ); 00312 fgets( temp, sizeof( fstring ), stdin ); 00313 00314 if ( temp[strlen( temp ) - 1] == '\n' ) { /* A new line? */ 00315 temp[strlen( temp ) - 1] = '\0'; 00316 } 00317 00318 00319 if ( temp[0] != '\0' ) { 00320 strncpy( pWorkgroup, temp, maxLenWorkgroup - 1 ); 00321 strncpy( authWorkgroup, temp, maxLenWorkgroup - 1 ); 00322 } 00323 00324 d_printf( "Username: [%s] ", pUsername ); 00325 fgets( temp, sizeof( fstring ), stdin ); 00326 00327 if ( temp[strlen( temp ) - 1] == '\n' ) { /* A new line? */ 00328 temp[strlen( temp ) - 1] = '\0'; 00329 } 00330 00331 if ( temp[0] != '\0' ) { 00332 strncpy( pUsername, temp, maxLenUsername - 1 ); 00333 strncpy( authUsername, pUsername, 00334 maxLenUsername - 1 ); 00335 } 00336 00337 pass = getpass( "Password: " ); 00338 if ( pass ) 00339 fstrcpy( temp, pass ); 00340 if ( temp[strlen( temp ) - 1] == '\n' ) { /* A new line? */ 00341 temp[strlen( temp ) - 1] = '\0'; 00342 } 00343 if ( temp[0] != '\0' ) { 00344 strncpy( pPassword, temp, maxLenPassword - 1 ); 00345 strncpy( authPassword, pPassword, 00346 maxLenPassword - 1 ); 00347 } 00348 authSet = 1; 00349 } 00350 }