Library/Utility Functions


関数

void cac_Init (int debug)
 Initializes the library - do not need to call this function.
CacServerHandlecac_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.c30 行で定義されています。

参照先 DEBUGLEVELsetup_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
戻り値:
- un-initialized server handle
  • NULL if no memory could be allocated

libmsrpc.c76 行で定義されています。

参照先 _CACSERVERHANDLE::_internal_SMBCCTX::_smbc_callbacks::auth_fncac_FreeHandle()cac_GetAuthDataFn()cac_InitHandleMem()_SMBCCTX::callbacksCacServerHandleInternal::ctx_CACSERVERHANDLE::debugerrnosmbc_new_context()CacServerHandleInternal::srv_levelCacServerHandleInternal::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.c143 行で定義されています。

参照先 _CACSERVERHANDLE::_internal_SMBCCTX::_smbc_callbacks::auth_fn_SMBCCTX::callbacksCacServerHandleInternal::ctx.

00144 {
00145         hnd->_internal.ctx->callbacks.auth_fn = auth_fn;
00146 }

void cac_SetSmbcContext ( CacServerHandle hnd,
SMBCCTX ctx 
)

Use your own libsmbclient context - not necessary.

覚え書き:
You must still call cac_Connect() after specifying your own libsmbclient context
引数:
hnd Initialized, but not connected CacServerHandle
ctx The libsmbclient context you would like to use.

libmsrpc.c148 行で定義されています。

参照先 _CACSERVERHANDLE::_internalCacServerHandleInternal::ctxctxCacServerHandleInternal::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_FAILURE if the operation could not be completed successfully (hnd->status will also be set with a NTSTATUS code)

CAC_SUCCESS if the operation succeeded

libmsrpc.c183 行で定義されています。

参照先 smbc_internal_data::_initialized_CACSERVERHANDLE::_internalcac_GetServer()cac_InitHandleData()CacServerHandleInternal::ctx_SMBCCTX::debug_CACSERVERHANDLE::debug_CACSERVERHANDLE::domain_SMBCCTX::internal_CACSERVERHANDLE::netbios_name_CACSERVERHANDLE::serversmbc_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.c230 行で定義されています。

参照先 _CACSERVERHANDLE::_internalCacServerHandleInternal::ctx_CACSERVERHANDLE::domain_CACSERVERHANDLE::netbios_name_CACSERVERHANDLE::password_CACSERVERHANDLE::serversmbc_free_context()CacServerHandleInternal::user_supplied_ctx_CACSERVERHANDLE::username.

参照元 cac_NewServerHandle().

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 }

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

libmsrpc.c249 行で定義されています。

参照先 _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_FAILURE Memory could not be allocated

CAC_SUCCESS Memory was allocated

libmsrpc.c40 行で定義されています。

参照先 _CACSERVERHANDLE::domain_CACSERVERHANDLE::netbios_name_CACSERVERHANDLE::password_CACSERVERHANDLE::server_CACSERVERHANDLE::username.

参照元 cac_NewServerHandle().

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.

参照:
cac_SetAuthDataFn()
引数:
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.c288 行で定義されています。

参照先 d_printf().

参照元 cac_NewServerHandle().

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 }


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