summaryrefslogtreecommitdiff
path: root/source3/libmsrpc/libmsrpc.c
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2006-09-27 14:32:18 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:14:50 -0500
commit94c9d528721a25c4faad08a188d86e05d939e559 (patch)
treed0f4d495e2ac81e5dc1aa608065dd2f1794d1f72 /source3/libmsrpc/libmsrpc.c
parent6aed2cd44e33cb10f52a41acd06c99d8b23df501 (diff)
downloadsamba-94c9d528721a25c4faad08a188d86e05d939e559.tar.gz
samba-94c9d528721a25c4faad08a188d86e05d939e559.tar.bz2
samba-94c9d528721a25c4faad08a188d86e05d939e559.zip
r18959: reformat using indent
(This used to be commit 69c298f85d44ac3138d11de2db34923a3328e119)
Diffstat (limited to 'source3/libmsrpc/libmsrpc.c')
-rw-r--r--source3/libmsrpc/libmsrpc.c495
1 files changed, 253 insertions, 242 deletions
diff --git a/source3/libmsrpc/libmsrpc.c b/source3/libmsrpc/libmsrpc.c
index d96eaf5916..adaf89d0fe 100644
--- a/source3/libmsrpc/libmsrpc.c
+++ b/source3/libmsrpc/libmsrpc.c
@@ -1,3 +1,4 @@
+
/*
* Unix SMB/CIFS implementation.
* MS-RPC client library implementation
@@ -24,314 +25,324 @@
#include "libsmb_internal.h"
/*this function is based on code found in smbc_init_context() (libsmb/libsmbclient.c)*/
-void cac_Init(int debug) {
- if(debug < 0 || debug > 99)
- debug = 0;
+void cac_Init( int debug )
+{
+ if ( debug < 0 || debug > 99 )
+ debug = 0;
- DEBUGLEVEL = debug;
+ DEBUGLEVEL = debug;
- setup_logging("libmsrpc", True);
+ setup_logging( "libmsrpc", True );
}
-int cac_InitHandleMem(CacServerHandle *hnd) {
- hnd->username = SMB_MALLOC_ARRAY(char, sizeof(fstring));
- if(!hnd->username)
- return CAC_FAILURE;
+int cac_InitHandleMem( CacServerHandle * hnd )
+{
+ hnd->username = SMB_MALLOC_ARRAY( char, sizeof( fstring ) );
+
+ if ( !hnd->username )
+ return CAC_FAILURE;
+
+ hnd->username[0] = '\0';
- hnd->username[0] = '\0';
+ hnd->domain = SMB_MALLOC_ARRAY( char, sizeof( fstring ) );
+ if ( !hnd->domain )
+ return CAC_FAILURE;
- hnd->domain = SMB_MALLOC_ARRAY(char, sizeof(fstring));
- if(!hnd->domain)
- return CAC_FAILURE;
-
- hnd->domain[0] = '\0';
+ hnd->domain[0] = '\0';
- hnd->netbios_name = SMB_MALLOC_ARRAY(char, sizeof(fstring));
- if(!hnd->netbios_name)
- return CAC_FAILURE;
+ hnd->netbios_name = SMB_MALLOC_ARRAY( char, sizeof( fstring ) );
+ if ( !hnd->netbios_name )
+ return CAC_FAILURE;
- hnd->netbios_name[0] = '\0';
+ hnd->netbios_name[0] = '\0';
- hnd->password = SMB_MALLOC_ARRAY(char, sizeof(fstring));
- if(!hnd->password)
- return CAC_FAILURE;
+ hnd->password = SMB_MALLOC_ARRAY( char, sizeof( fstring ) );
+ if ( !hnd->password )
+ return CAC_FAILURE;
- hnd->password[0] = '\0';
+ hnd->password[0] = '\0';
- hnd->server = SMB_MALLOC_ARRAY(char, sizeof(fstring));
- if(!hnd->server)
- return CAC_FAILURE;
+ hnd->server = SMB_MALLOC_ARRAY( char, sizeof( fstring ) );
+ if ( !hnd->server )
+ return CAC_FAILURE;
- hnd->server[0] = '\0';
+ hnd->server[0] = '\0';
- return CAC_SUCCESS;
+ return CAC_SUCCESS;
}
-CacServerHandle *cac_NewServerHandle(BOOL allocate_fields) {
- CacServerHandle * hnd;
+CacServerHandle *cac_NewServerHandle( BOOL allocate_fields )
+{
+ CacServerHandle *hnd;
+
+ hnd = SMB_MALLOC_P( CacServerHandle );
+
+ if ( !hnd ) {
+ errno = ENOMEM;
+ return NULL;
+ }
- hnd = SMB_MALLOC_P(CacServerHandle);
+ ZERO_STRUCTP( hnd );
- if(!hnd) {
- errno = ENOMEM;
- return NULL;
- }
-
- ZERO_STRUCTP(hnd);
+ if ( allocate_fields == True ) {
+ if ( !cac_InitHandleMem( hnd ) ) {
+ SAFE_FREE( hnd );
+ return NULL;
+ }
+ }
- if(allocate_fields == True) {
- if(!cac_InitHandleMem(hnd)) {
- SAFE_FREE(hnd);
- return NULL;
- }
- }
+ hnd->_internal.ctx = smbc_new_context( );
+ if ( !hnd->_internal.ctx ) {
+ cac_FreeHandle( hnd );
+ return NULL;
+ }
- hnd->_internal.ctx = smbc_new_context();
- if(!hnd->_internal.ctx) {
- cac_FreeHandle(hnd);
- return NULL;
- }
+ hnd->_internal.ctx->callbacks.auth_fn = cac_GetAuthDataFn;
- hnd->_internal.ctx->callbacks.auth_fn = cac_GetAuthDataFn;
-
- /*add defaults*/
- hnd->debug = 0;
+ /*add defaults */
+ hnd->debug = 0;
- /*start at the highest and it will fall down after trying the functions*/
- hnd->_internal.srv_level = SRV_WIN_2K3;
+ /*start at the highest and it will fall down after trying the functions */
+ hnd->_internal.srv_level = SRV_WIN_2K3;
- hnd->_internal.user_supplied_ctx = False;
+ hnd->_internal.user_supplied_ctx = False;
- return hnd;
+ return hnd;
}
-int cac_InitHandleData(CacServerHandle *hnd) {
- /*store any automatically initialized values*/
- if(!hnd->netbios_name) {
- hnd->netbios_name = SMB_STRDUP(hnd->_internal.ctx->netbios_name);
- }
- else if(hnd->netbios_name[0] == '\0') {
- strncpy(hnd->netbios_name, hnd->_internal.ctx->netbios_name, sizeof(fstring));
- }
-
- if(!hnd->username) {
- hnd->username = SMB_STRDUP(hnd->_internal.ctx->user);
- }
- else if(hnd->username[0] == '\0') {
- strncpy(hnd->username, hnd->_internal.ctx->user, sizeof(fstring));
- }
-
- if(!hnd->domain) {
- hnd->domain = SMB_STRDUP(hnd->_internal.ctx->workgroup);
- }
- else if(hnd->domain[0] == '\0') {
- strncpy(hnd->domain, hnd->_internal.ctx->workgroup, sizeof(fstring));
- }
-
- return CAC_SUCCESS;
+int cac_InitHandleData( CacServerHandle * hnd )
+{
+ /*store any automatically initialized values */
+ if ( !hnd->netbios_name ) {
+ hnd->netbios_name =
+ SMB_STRDUP( hnd->_internal.ctx->netbios_name );
+ } else if ( hnd->netbios_name[0] == '\0' ) {
+ strncpy( hnd->netbios_name, hnd->_internal.ctx->netbios_name,
+ sizeof( fstring ) );
+ }
+
+ if ( !hnd->username ) {
+ hnd->username = SMB_STRDUP( hnd->_internal.ctx->user );
+ } else if ( hnd->username[0] == '\0' ) {
+ strncpy( hnd->username, hnd->_internal.ctx->user,
+ sizeof( fstring ) );
+ }
+
+ if ( !hnd->domain ) {
+ hnd->domain = SMB_STRDUP( hnd->_internal.ctx->workgroup );
+ } else if ( hnd->domain[0] == '\0' ) {
+ strncpy( hnd->domain, hnd->_internal.ctx->workgroup,
+ sizeof( fstring ) );
+ }
+
+ return CAC_SUCCESS;
}
-void cac_SetAuthDataFn(CacServerHandle *hnd, smbc_get_auth_data_fn auth_fn) {
- hnd->_internal.ctx->callbacks.auth_fn = auth_fn;
+void cac_SetAuthDataFn( CacServerHandle * hnd, smbc_get_auth_data_fn auth_fn )
+{
+ hnd->_internal.ctx->callbacks.auth_fn = auth_fn;
}
-void cac_SetSmbcContext(CacServerHandle *hnd, SMBCCTX *ctx) {
+void cac_SetSmbcContext( CacServerHandle * hnd, SMBCCTX * ctx )
+{
- SAFE_FREE(hnd->_internal.ctx);
+ SAFE_FREE( hnd->_internal.ctx );
- hnd->_internal.user_supplied_ctx = True;
+ hnd->_internal.user_supplied_ctx = True;
- hnd->_internal.ctx = ctx;
+ hnd->_internal.ctx = ctx;
/*_try_ to avoid any problems that might occur if cac_Connect() isn't called*/
- /*cac_InitHandleData(hnd);*/
+ /*cac_InitHandleData(hnd); */
}
/*used internally*/
-SMBCSRV *cac_GetServer(CacServerHandle *hnd) {
- SMBCSRV *srv;
-
- if(!hnd || !hnd->_internal.ctx) {
- return NULL;
- }
+SMBCSRV *cac_GetServer( CacServerHandle * hnd )
+{
+ SMBCSRV *srv;
+
+ if ( !hnd || !hnd->_internal.ctx ) {
+ return NULL;
+ }
+
+ srv = smbc_attr_server( hnd->_internal.ctx, hnd->server, "IPC$",
+ hnd->domain, hnd->username, hnd->password,
+ NULL );
+ if ( !srv ) {
+ hnd->status = NT_STATUS_UNSUCCESSFUL;
+ DEBUG( 1,
+ ( "cac_GetServer: Could not find server connection.\n" ) );
+ }
+
+ return srv;
+}
- srv = smbc_attr_server(hnd->_internal.ctx, hnd->server, "IPC$", hnd->domain, hnd->username, hnd->password, NULL);
- if(!srv) {
- hnd->status=NT_STATUS_UNSUCCESSFUL;
- DEBUG(1, ("cac_GetServer: Could not find server connection.\n"));
- }
- return srv;
-}
+int cac_Connect( CacServerHandle * hnd, const char *srv )
+{
+ if ( !hnd ) {
+ return CAC_FAILURE;
+ }
+ /*these values should be initialized by the user */
+ if ( !hnd->server && !srv ) {
+ return CAC_FAILURE;
+ }
-int cac_Connect(CacServerHandle *hnd, const char *srv) {
- if(!hnd) {
- return CAC_FAILURE;
- }
- /*these values should be initialized by the user*/
- if(!hnd->server && !srv) {
- return CAC_FAILURE;
- }
+ /*change the server name in the server handle if necessary */
+ if ( srv && hnd->server && strcmp( hnd->server, srv ) == 0 ) {
+ SAFE_FREE( hnd->server );
+ hnd->server = SMB_STRDUP( srv );
+ }
- /*change the server name in the server handle if necessary*/
- if(srv && hnd->server && strcmp(hnd->server, srv) == 0) {
- SAFE_FREE(hnd->server);
- hnd->server = SMB_STRDUP(srv);
- }
+ /*first see if the context has already been setup */
+ if ( !( hnd->_internal.ctx->internal->_initialized ) ) {
+ hnd->_internal.ctx->debug = hnd->debug;
+ /*initialize the context */
+ if ( !smbc_init_context( hnd->_internal.ctx ) ) {
+ return CAC_FAILURE;
+ }
+ }
- /*first see if the context has already been setup*/
- if( !(hnd->_internal.ctx->internal->_initialized) ) {
- hnd->_internal.ctx->debug = hnd->debug;
+ /*copy any uninitialized values out of the smbc context into the handle */
+ if ( !cac_InitHandleData( hnd ) ) {
+ return CAC_FAILURE;
+ }
- /*initialize the context*/
- if(!smbc_init_context(hnd->_internal.ctx)) {
- return CAC_FAILURE;
- }
- }
+ DEBUG( 3, ( "cac_Connect: Username: %s\n", hnd->username ) );
+ DEBUG( 3, ( "cac_Connect: Domain: %s\n", hnd->domain ) );
+ DEBUG( 3, ( "cac_Connect: Netbios Name: %s\n", hnd->netbios_name ) );
- /*copy any uninitialized values out of the smbc context into the handle*/
- if(!cac_InitHandleData(hnd)) {
- return CAC_FAILURE;
- }
+ if ( !cac_GetServer( hnd ) ) {
+ return CAC_FAILURE;
+ }
- DEBUG(3, ("cac_Connect: Username: %s\n", hnd->username));
- DEBUG(3, ("cac_Connect: Domain: %s\n", hnd->domain));
- DEBUG(3, ("cac_Connect: Netbios Name: %s\n", hnd->netbios_name));
+ return CAC_SUCCESS;
- if(!cac_GetServer(hnd)) {
- return CAC_FAILURE;
- }
-
- return CAC_SUCCESS;
-
}
-void cac_FreeHandle(CacServerHandle * hnd) {
- if(!hnd)
- return;
+void cac_FreeHandle( CacServerHandle * hnd )
+{
+ if ( !hnd )
+ return;
- /*only free the context if we created it*/
- if(!hnd->_internal.user_supplied_ctx) {
- smbc_free_context(hnd->_internal.ctx, True);
- }
+ /*only free the context if we created it */
+ if ( !hnd->_internal.user_supplied_ctx ) {
+ smbc_free_context( hnd->_internal.ctx, True );
+ }
- SAFE_FREE(hnd->netbios_name);
- SAFE_FREE(hnd->domain);
- SAFE_FREE(hnd->username);
- SAFE_FREE(hnd->password);
- SAFE_FREE(hnd->server);
- SAFE_FREE(hnd);
+ SAFE_FREE( hnd->netbios_name );
+ SAFE_FREE( hnd->domain );
+ SAFE_FREE( hnd->username );
+ SAFE_FREE( hnd->password );
+ SAFE_FREE( hnd->server );
+ SAFE_FREE( hnd );
}
-void cac_InitCacTime(CacTime *cactime, NTTIME nttime) {
- float high, low;
- uint32 sec;
+void cac_InitCacTime( CacTime * cactime, NTTIME nttime )
+{
+ float high, low;
+ uint32 sec;
- if(!cactime)
- return;
+ if ( !cactime )
+ return;
- ZERO_STRUCTP(cactime);
+ ZERO_STRUCTP( cactime );
- /*this code is taken from display_time() found in rpcclient/cmd_samr.c*/
- if (nttime==0)
+ /*this code is taken from display_time() found in rpcclient/cmd_samr.c */
+ if ( nttime == 0 )
return;
- if (nttime==0x80000000000000LL)
+ if ( nttime == 0x80000000000000LL )
return;
- high = 65536;
- high = high/10000;
- high = high*65536;
- high = high/1000;
- high = high * (~(nttime >> 32));
-
- low = ~(nttime & 0xFFFFFFFF);
- low = low/(1000*1000*10);
-
- sec=high+low;
-
- cactime->days=sec/(60*60*24);
- cactime->hours=(sec - (cactime->days*60*60*24)) / (60*60);
- cactime->minutes=(sec - (cactime->days*60*60*24) - (cactime->hours*60*60) ) / 60;
- cactime->seconds=sec - (cactime->days*60*60*24) - (cactime->hours*60*60) - (cactime->minutes*60);
+ high = 65536;
+ high = high / 10000;
+ high = high * 65536;
+ high = high / 1000;
+ high = high * ( ~( nttime >> 32 ) );
+
+ low = ~( nttime & 0xFFFFFFFF );
+ low = low / ( 1000 * 1000 * 10 );
+
+ sec = high + low;
+
+ cactime->days = sec / ( 60 * 60 * 24 );
+ cactime->hours =
+ ( sec - ( cactime->days * 60 * 60 * 24 ) ) / ( 60 * 60 );
+ cactime->minutes =
+ ( sec - ( cactime->days * 60 * 60 * 24 ) -
+ ( cactime->hours * 60 * 60 ) ) / 60;
+ cactime->seconds =
+ sec - ( cactime->days * 60 * 60 * 24 ) -
+ ( cactime->hours * 60 * 60 ) - ( cactime->minutes * 60 );
}
-void cac_GetAuthDataFn(const char * pServer,
- const char * pShare,
- char * pWorkgroup,
- int maxLenWorkgroup,
- char * pUsername,
- int maxLenUsername,
- char * pPassword,
- int maxLenPassword)
-
+void cac_GetAuthDataFn( const char *pServer,
+ const char *pShare,
+ char *pWorkgroup,
+ int maxLenWorkgroup,
+ char *pUsername,
+ int maxLenUsername,
+ char *pPassword, int maxLenPassword )
{
- char temp[sizeof(fstring)];
-
- static char authUsername[sizeof(fstring)];
- static char authWorkgroup[sizeof(fstring)];
- static char authPassword[sizeof(fstring)];
- static char authSet = 0;
-
- char *pass = NULL;
-
-
- if (authSet)
- {
- strncpy(pWorkgroup, authWorkgroup, maxLenWorkgroup - 1);
- strncpy(pUsername, authUsername, maxLenUsername - 1);
- strncpy(pPassword, authPassword, maxLenPassword - 1);
- }
- else
- {
- d_printf("Domain: [%s] ", pWorkgroup);
- fgets(temp, sizeof(fstring), stdin);
-
- if (temp[strlen(temp) - 1] == '\n') /* A new line? */
- {
- temp[strlen(temp) - 1] = '\0';
- }
-
-
- if (temp[0] != '\0')
- {
- strncpy(pWorkgroup, temp, maxLenWorkgroup - 1);
- strncpy(authWorkgroup, temp, maxLenWorkgroup - 1);
- }
-
- d_printf("Username: [%s] ", pUsername);
- fgets(temp, sizeof(fstring), stdin);
-
- if (temp[strlen(temp) - 1] == '\n') /* A new line? */
- {
- temp[strlen(temp) - 1] = '\0';
- }
-
- if (temp[0] != '\0')
- {
- strncpy(pUsername, temp, maxLenUsername - 1);
- strncpy(authUsername, pUsername, maxLenUsername - 1);
- }
-
- pass = getpass("Password: ");
- if (pass)
- fstrcpy(temp, pass);
- if (temp[strlen(temp) - 1] == '\n') /* A new line? */
- {
- temp[strlen(temp) - 1] = '\0';
- }
- if (temp[0] != '\0')
- {
- strncpy(pPassword, temp, maxLenPassword - 1);
- strncpy(authPassword, pPassword, maxLenPassword - 1);
- }
- authSet = 1;
- }
+ char temp[sizeof( fstring )];
+
+ static char authUsername[sizeof( fstring )];
+ static char authWorkgroup[sizeof( fstring )];
+ static char authPassword[sizeof( fstring )];
+ static char authSet = 0;
+
+ char *pass = NULL;
+
+
+ if ( authSet ) {
+ strncpy( pWorkgroup, authWorkgroup, maxLenWorkgroup - 1 );
+ strncpy( pUsername, authUsername, maxLenUsername - 1 );
+ strncpy( pPassword, authPassword, maxLenPassword - 1 );
+ } else {
+ d_printf( "Domain: [%s] ", pWorkgroup );
+ fgets( temp, sizeof( fstring ), stdin );
+
+ if ( temp[strlen( temp ) - 1] == '\n' ) { /* A new line? */
+ temp[strlen( temp ) - 1] = '\0';
+ }
+
+
+ if ( temp[0] != '\0' ) {
+ strncpy( pWorkgroup, temp, maxLenWorkgroup - 1 );
+ strncpy( authWorkgroup, temp, maxLenWorkgroup - 1 );
+ }
+
+ d_printf( "Username: [%s] ", pUsername );
+ fgets( temp, sizeof( fstring ), stdin );
+
+ if ( temp[strlen( temp ) - 1] == '\n' ) { /* A new line? */
+ temp[strlen( temp ) - 1] = '\0';
+ }
+
+ if ( temp[0] != '\0' ) {
+ strncpy( pUsername, temp, maxLenUsername - 1 );
+ strncpy( authUsername, pUsername,
+ maxLenUsername - 1 );
+ }
+
+ pass = getpass( "Password: " );
+ if ( pass )
+ fstrcpy( temp, pass );
+ if ( temp[strlen( temp ) - 1] == '\n' ) { /* A new line? */
+ temp[strlen( temp ) - 1] = '\0';
+ }
+ if ( temp[0] != '\0' ) {
+ strncpy( pPassword, temp, maxLenPassword - 1 );
+ strncpy( authPassword, pPassword,
+ maxLenPassword - 1 );
+ }
+ authSet = 1;
+ }
}
-