void dce_rpc_server_main () { unsigned32 status; int ret; strcpy(pszProtocolSequence,"ncacn_ip_tcp"); pszEndpoint = NULL; cMaxCalls = 1; pbvBindings = NULL; pthread_mutex_init(&mutex,pthread_mutexattr_default); /* No RPCs now! */ pthread_mutex_lock(&mutex); /* Initialize DCE RPC */ rpc_server_use_protseq(pszProtocolSequence,cMaxCalls,&status); CHECK_DCE_ERROR(status,ABORT); rpc_server_inq_bindings(&pbvBindings,&status); CHECK_DCE_ERROR(status,ABORT); rpc_ep_register(xgobi_goes_dce_v1_0_s_ifspec,pbvBindings,0,0,&status); CHECK_DCE_ERROR(status,ABORT); rpc_server_register_if(xgobi_goes_dce_v1_0_s_ifspec,0,0,&status); CHECK_DCE_ERROR(status,ABORT); /* p-Thread to rpc_server_listen */ ret = pthread_create(&t_handle,pthread_attr_default, (void *(*)(void *)) dce_rpc_server_listen,NULL); }
DWORD VmDnsRpcServerInqBindings( rpc_binding_vector_p_t* ppServerBindings ) { DWORD dwError = 0; DCETHREAD_TRY { rpc_server_inq_bindings(ppServerBindings, (unsigned32*)&dwError); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if ( dwError == rpc_s_ok ) { dwError = dcethread_exc_getstatus(THIS_CATCH); if (!dwError) { dwError = RPC_S_INTERNAL_ERROR; } } } DCETHREAD_ENDTRY; BAIL_ON_VMDNS_ERROR(dwError); error: return dwError; }
static DWORD bind_server( rpc_binding_vector_p_t * server_binding, rpc_if_handle_t interface_spec, PENDPOINT pEndPoints ) { DWORD dwError = 0; DWORD dwRpcStatus = 0; DWORD i; /* * Prepare the server binding handle * use all avail protocols (UDP and TCP). This basically allocates * new sockets for us and associates the interface UUID and * object UUID of with those communications endpoints. */ for (i = 0; pEndPoints[i].protocol != NULL; i++) { if (!pEndPoints[i].endpoint) { rpc_server_use_protseq((unsigned char*) pEndPoints[i].protocol, rpc_c_protseq_max_calls_default, (unsigned32*)&dwRpcStatus); BAIL_ON_DCE_ERROR(dwError, dwRpcStatus); } else { if (!strcmp(pEndPoints[i].protocol, "ncalrpc") && pEndPoints[i].endpoint[0] == '/') { dwError = prepare_domain_socket(pEndPoints[i].endpoint); BAIL_ON_SRVSVC_ERROR(dwError); } rpc_server_use_protseq_ep((unsigned char*) pEndPoints[i].protocol, rpc_c_protseq_max_calls_default, (unsigned char*) pEndPoints[i].endpoint, (unsigned32*)&dwRpcStatus); BAIL_ON_DCE_ERROR(dwError, dwRpcStatus); } } rpc_server_inq_bindings(server_binding, (unsigned32*)&dwRpcStatus); BAIL_ON_DCE_ERROR(dwError, dwRpcStatus); error: return dwError; }
static void bind_server( rpc_binding_vector_p_t * server_binding, rpc_if_handle_t interface_spec ATTRIBUTE_UNUSED, const char * protocol, const char * endpoint) { const char * function = "n/a"; unsigned32 status; /* * Prepare the server binding handle * use all avail protocols (UDP and TCP). This basically allocates * new sockets for us and associates the interface UUID and * object UUID of with those communications endpoints. */ #if 0 rpc_server_use_all_protseqs_if(0, interface_spec, &status); #else if (!endpoint) { if (!protocol) { function = "rpc_server_use_all_protseqs()"; rpc_server_use_all_protseqs(rpc_c_protseq_max_calls_default, &status); } else { function = "rpc_server_use_protseq()"; rpc_server_use_protseq((unsigned_char_p_t)protocol, rpc_c_protseq_max_calls_default, &status); } } else { function = "rpc_server_use_protseq_ep()"; rpc_server_use_protseq_ep((unsigned_char_p_t)protocol, rpc_c_protseq_max_calls_default, (unsigned_char_p_t)endpoint, &status); } #endif chk_dce_err(status, function, "", 1); rpc_server_inq_bindings(server_binding, &status); chk_dce_err(status, "rpc_server_inq_bindings()", "", 1); }
int main ( int argc, char *argv[] ) { rpc_binding_vector_t *bv_p; unsigned32 status; /* Register interface/epv associations with RPC runtime. */ printf("Registering server interface with RPC runtime...\n"); rpc_server_register_if ( mathb_v1_0_s_ifspec, NULL, NULL, &status ); ERRCHK ( status ); /* Inform RPC runtime to use a supported protocol sequences. */ rpc_server_use_protseq ( "ncadg_ip_udp", MAX_CONC_CALLS_PROTSEQ, &status ); ERRCHK ( status ); /* Get the binding handle vector from RPC runtime. */ rpc_server_inq_bindings ( &bv_p, &status ); ERRCHK ( status ); /* Register binding information with endpoint map. */ printf("Registering server endpoints with endpoint mapper (RPCD)...\n"); rpc_ep_register ( mathb_v1_0_s_ifspec, bv_p, NULL, ( unsigned_char_t * )"Basic math server, version 1.0", &status ); ERRCHK ( status ); /* Export binding information to the namespace. */ printf("Exporting server bindings into CDS namespace...\n"); rpc_ns_binding_export ( rpc_c_ns_syntax_dce, ENTRY_NAME, mathb_v1_0_s_ifspec, bv_p, NULL, &status ); ERRCHK ( status ); /* Listen for service requests. */ printf ( "Server %s listening...\n", ENTRY_NAME ); rpc_server_listen ( MAX_CONC_CALLS_TOTAL, &status ); ERRCHK ( status ); }
int main( int argc, char *argv[] ) { unsigned32 st; rpc_binding_vector_t *bvec; #ifndef _WINDOWS sigset_t sigset; pthread_t this_thread = pthread_self(); #endif #ifdef IBMOS2 pthread_inst_exception_handler(); #endif /* Register interface/epv associations with rpc runtime. */ printf("Registering server interface with RPC runtime...\n"); rpc_server_register_if( MyError_v1_0_s_ifspec, NULL, NULL, &st ); ERRORCK( "rpc_server_register_if", st ); rpc_server_use_protseq ( "ncadg_ip_udp", MAX_CALL_REQUESTS, &st ); ERRORCK( "rpc_server_use_protseq", st ); rpc_server_inq_bindings( &bvec, &st ); ERRORCK( "rpc_server_inq_binding", st ); /* Register binding information with endpoint map */ printf("Registering server endpoints with endpoint mapper (RPCD)...\n"); rpc_ep_register( MyError_v1_0_s_ifspec, bvec, NULL, (unsigned_char_t *)"MyError3, version 1.0", &st ); ERRORCK( "rpc_ep_register", st ); /* Export binding info to the namespace. */ printf("Exporting server bindings into CDS namespace...\n"); rpc_ns_binding_export( rpc_c_ns_syntax_dce, ENTRY_NAME, MyError_v1_0_s_ifspec, bvec, NULL, &st ); ERRORCK( "rpc_ns_binding_export", st ); #ifndef _WINDOWS sigemptyset ( &sigset ); sigaddset ( &sigset, SIGINT ); sigaddset ( &sigset, SIGTERM); pthread_signal_to_cancel_np ( &sigset, &this_thread ); #endif TRY /* Listen for service requests. */ printf( "Server %s listening...\n", ENTRY_NAME ); rpc_server_listen( MAX_CALL_REQUESTS, &st ); FINALLY printf("Unexporting server bindings from CDS namespace...\n"); rpc_ns_binding_unexport( rpc_c_ns_syntax_dce, ENTRY_NAME, MyError_v1_0_s_ifspec, NULL, &st ); ERRORCK( "rpc_ns_binding_unexport", st ); printf("Unregistering server interface with RPC runtime...\n"); rpc_server_unregister_if( MyError_v1_0_s_ifspec, NULL, &st ); ERRORCK( "rpc_server_unregister_if", st ); printf("Unregistering server endpoints with endpoint mapper (RPCD)...\n"); rpc_ep_unregister( MyError_v1_0_s_ifspec, bvec, NULL, &st ); ERRORCK( "rpc_ep_unregister", st ); #ifdef IBMOS2 pthread_dinst_exception_handler(); #endif exit( 0 ); ENDTRY; }
INTERNAL int is_unpriv_handle( handle_t h, error_status_t *st ) { error_status_t status,status1; rpc_binding_vector_p_t bv; handle_t binding; unsigned_char_p_t stb,our_netaddr,client_netaddr; unsigned32 i; static unsigned_char_p_t *local_netaddr = NULL; static unsigned32 addr_count = 0; unsigned32 prot_seq = 0; rpc_transport_info_handle_t info; unsigned32 uid = (unsigned32) -1; unsigned32 gid = (unsigned32) -1; rpc_binding_inq_prot_seq(h, &prot_seq, &status); if (! STATUS_OK(&status)) { *st = status; return(1); } if (prot_seq == rpc_c_protseq_id_ncalrpc) { rpc_binding_inq_transport_info(h, &info, &status); if (! STATUS_OK(&status)) { *st = status; return(1); } rpc_lrpc_transport_info_inq_peer_eid(info, &uid, &gid); *st = rpc_s_ok; return (uid != 0); } /* Get client network address from binding handle (client_netaddr) */ rpc_binding_server_from_client(h,&binding,&status); if (! STATUS_OK(&status)) { *st = status; return(1); } rpc_binding_to_string_binding(binding,&stb,&status); if (! STATUS_OK(&status)) { rpc_binding_free(&binding,&status1); *st = status; return(1); } rpc_binding_free(&binding,&status1); rpc_string_binding_parse(stb,NULL,NULL,&client_netaddr,NULL,NULL,&status); if (! STATUS_OK(&status)) { rpc_string_free(&stb,&status1); *st = status; return(1); } rpc_string_free(&stb,&status1); /* * Lookup all of the addresses which this node answers to. * Cache these in static storage so we only do this work once. */ if (addr_count == 0) { rpc_server_inq_bindings(&bv,&status); if (! STATUS_OK(&status)) { rpc_string_free(&client_netaddr,&status1); *st = status; return(1); } addr_count = bv->count; local_netaddr = (unsigned_char_p_t *) malloc( (size_t) (addr_count * sizeof(unsigned_char_p_t))); if (local_netaddr == NULL) { rpc_string_free(&client_netaddr,&status1); rpc_binding_vector_free(&bv,&status1); *st = ept_s_no_memory; return(1); } for ( i=0; i < bv->count; i++ ) { rpc_binding_to_string_binding(bv->binding_h[i],&stb,&status); if (! STATUS_OK(&status)) { rpc_binding_vector_free(&bv,&status1); rpc_string_free(&client_netaddr,&status1); *st = status; return(1); } rpc_string_binding_parse(stb,NULL,NULL, &our_netaddr,NULL,NULL,&status); if (! STATUS_OK(&status)) { rpc_binding_vector_free(&bv,&status1); rpc_string_free(&stb,&status1); rpc_string_free(&client_netaddr,&status1); *st = status; return(1); } local_netaddr[i] = our_netaddr; rpc_string_free(&stb,&status1); } rpc_binding_vector_free(&bv,&status1); } /* * Compare the addresses with the client address */ *st = rpc_s_ok; for ( i=0; i < addr_count; i++ ) { if(strcmp((char*) client_netaddr, (char*) local_netaddr[i]) == 0) { rpc_string_free(&client_netaddr,&status1); return(0); } } rpc_string_free(&client_netaddr,&status1); return(1); }
int main ( int argc, char *argv[] ) { unsigned_char_t *server_name; rpc_binding_vector_t *bind_vector_p; unsigned32 status; # ifndef _WINDOWS sigset_t sigset; pthread_t this_thread = pthread_self(); # endif # ifdef IBMOS2 pthread_inst_exception_handler(); # endif /* Register the authentification level which will be used */ printf("Registering authentication level with RPC runtime...\n"); rpc_server_register_auth_info( PRINCIPAL_NAME, rpc_c_authn_default, NULL, NULL, &status ); ERRCHK( status ); /* Register interface/epv associations with rpc runtime. */ printf("Registering server interface with RPC runtime...\n"); rpc_server_register_if ( IF_HANDLE, NULL, NULL, &status ); ERRCHK( status ); /* Inform rpc runtime of a protocol sequence to use. */ switch ( (( argc > 1 ) ? *argv[1] | ' ' : 'a') ) { case 't': rpc_server_use_protseq ("ncacn_ip_tcp", MAX_CONC_CALLS_PROTSEQ, &status ); break; case 'u': rpc_server_use_protseq ("ncadg_ip_udp", MAX_CONC_CALLS_PROTSEQ, &status ); break; case 'a': default: rpc_server_use_all_protseqs ( MAX_CONC_CALLS_PROTSEQ, &status ); } ERRCHK( status ); /* Ask the runtime which binding handle will be used. */ rpc_server_inq_bindings( &bind_vector_p, &status ); ERRCHK( status ); /* Register binding information with endpoint map */ printf("Registering server endpoints with endpoint mapper (RPCD)...\n"); rpc_ep_register( IF_HANDLE, bind_vector_p, NULL, "Message Box server, version 2.0", &status ); ERRCHK( status ); /* Export binding info to the namespace. */ printf("Exporting server bindings into CDS namespace...\n"); rpc_ns_binding_export ( rpc_c_ns_syntax_default, ENTRY_NAME, IF_HANDLE, bind_vector_p, NULL, &status ); ERRCHK( status ); # ifndef _WINDOWS /* baggage to handle ctrl-C */ sigemptyset(&sigset); sigaddset(&sigset, SIGINT); sigaddset(&sigset, SIGTERM); if (pthread_signal_to_cancel_np(&sigset, &this_thread) != 0) { printf("pthread_signal_to_cancel_np failed\n"); exit(1); } # endif /* Import the mbox structure from file FNAME */ mbox_import(FNAME); TRY { /* Listen for service requests. */ printf( "Server %s listening...\n", ENTRY_NAME ); rpc_server_listen ( MAX_CONC_CALLS_TOTAL, &status ); ERRCHK( status ); } FINALLY { /* Export the mbox structure to file FNAME */ mbox_export(FNAME); /* Unexport the binding information from the namespace. */ printf("Unexporting server bindings from CDS namespace...\n"); rpc_ns_binding_unexport ( rpc_c_ns_syntax_default, ENTRY_NAME, IF_HANDLE, NULL, &status ); ERRCHK( status ); /* Unregister interface from RPC runtime */ printf("Unregistering server interface with RPC runtime...\n"); rpc_server_unregister_if ( IF_HANDLE, NULL, &status ); ERRCHK( status ); /* Unregister interface from EPV */ printf("Unregistering server endpoints with endpoint mapper (RPCD)...\n"); rpc_ep_unregister ( IF_HANDLE, bind_vector_p, NULL, &status ); ERRCHK( status ); # ifdef IBMOS2 pthread_dinst_exception_handler(); # endif exit ( 0 ); } ENDTRY; }
int main( int argc, char *argv[] ) { unsigned32 st; rpc_binding_vector_t *bvec; #ifndef _WINDOWS sigset_t sigset; pthread_t this_thread = pthread_self(); #endif #ifdef IBMOS2 pthread_inst_exception_handler(); #endif printf("Registering server interface with RPC runtime...\n"); rpc_server_register_if( Database_v1_0_s_ifspec, NULL, NULL, &st ); ERRORCK( "rpc_server_register_if", st ); switch ( (( argc > 1 ) ? *argv[1] | ' ' : 'a') ) { case 't': rpc_server_use_protseq ("ncacn_ip_tcp", MAX_CONC_CALLS_PROTSEQ, &st ); break; case 'u': rpc_server_use_protseq ("ncadg_ip_udp", MAX_CONC_CALLS_PROTSEQ, &st ); break; case 'a': default: rpc_server_use_all_protseqs ( MAX_CONC_CALLS_PROTSEQ, &st ); } ERRORCK( "rpc_server_use_all_protseqs", st ); rpc_server_inq_bindings( &bvec, &st ); ERRORCK( "rpc_server_inq_binding", st ); printf("Registering server endpoints with endpoint mapper (RPCD)...\n"); rpc_ep_register( Database_v1_0_s_ifspec, bvec, NULL, ( unsigned_char_t * )"Database server, version 1.0" , &st ); ERRORCK( "rpc_ep_register", st ); rpc_ns_binding_export( rpc_c_ns_syntax_dce, ENTRY_NAME, Database_v1_0_s_ifspec, bvec, NULL, &st ); ERRORCK( "rpc_ns_binding_export", st ); #ifndef _WINDOWS sigemptyset ( &sigset ); sigaddset ( &sigset, SIGINT ); sigaddset ( &sigset, SIGTERM ); pthread_signal_to_cancel_np ( &sigset, &this_thread ); #endif TRY { printf ( "Server %s listening...\n", ENTRY_NAME ); rpc_server_listen( MAX_CALL_REQUESTS, &st ); } FINALLY { printf("Unexporting server bindings from CDS namespace...\n"); rpc_ns_binding_unexport( rpc_c_ns_syntax_dce, ENTRY_NAME, Database_v1_0_s_ifspec, NULL, &st ); ERRORCK( "rpc_ns_binding_unexport", st ); printf("Unregistering server interface with RPC runtime...\n"); rpc_server_unregister_if( Database_v1_0_s_ifspec, NULL, &st ); ERRORCK( "rpc_server_unregister_if", st ); printf("Unregistering server endpoints with endpoint mapper (RPCD)...\n"); rpc_ep_unregister( Database_v1_0_s_ifspec, bvec, NULL, &st ); ERRORCK( "rpc_ep_unregister", st ); #ifdef IBMOS2 pthread_dinst_exception_handler(); #endif exit( 0 ); } ENDTRY }