DWORD VMCAGetClientName(handle_t IDL_handle) { #if DEBUG_RPC rpc_binding_handle_t Srv; PSTR pszBinding = NULL; PSTR pszObjUUID = NULL; PSTR pszProtoSeq = NULL; PSTR pszNetworkAddress = NULL; PSTR pszEndPoint = NULL; PSTR pszNetworkOptions = NULL; unsigned32 rs = 0; rpc_binding_server_from_client (IDL_handle, &Srv, &rs); BAIL_ON_VMCA_ERROR(rs); rpc_binding_to_string_binding(Srv, (unsigned char **) &pszBinding, &rs); printf("Binding Info : %s\n", pszBinding); rpc_binding_free(&Srv, &rs); rpc_string_binding_parse(pszBinding, (unsigned_char_t **) &pszObjUUID, (unsigned_char_t **) &pszProtoSeq, (unsigned_char_t **) &pszNetworkAddress, (unsigned_char_t **) &pszEndPoint, (unsigned_char_t **) &pszNetworkOptions, &rs); printf("Obj UUID : %s, Proto : %s, Network : %s, \ EndPoint %s, Network Options : %s \n", pszObjUUID, pszProtoSeq, pszNetworkAddress, pszEndPoint, pszNetworkOptions); rpc_string_free((unsigned_char_t **) &pszBinding, &rs); rpc_string_free((unsigned_char_t **) &pszObjUUID, &rs); rpc_string_free((unsigned_char_t **) &pszProtoSeq, &rs); rpc_string_free((unsigned_char_t **) &pszNetworkAddress, &rs); rpc_string_free((unsigned_char_t **) &pszEndPoint, &rs); rpc_string_free((unsigned_char_t **) &pszNetworkOptions, &rs); #endif return 0; }
/* * Create or update an LDAP server binding entry. */ static void rpc_ns__ldap_export_server_element_ext(LDAP *ld, char *dn, rpc_if_handle_t if_spec, rpc_binding_vector_p_t vec, int modop, unsigned32 *status ) { unsigned_char_p_t uuid = NULL; unsigned_char_p_t interfaceID = NULL; rpc_if_id_t if_id; LDAPMod *modV[4]; LDAPMod modRpcNsInterfaceID, modRpcNsBindings, modObjectClass; char **valueRpcNsBindings = NULL; char *valueRpcNsInterfaceID[2], *valueObjectClass[3]; int rc; unsigned i; rpc_if_inq_id(if_spec, &if_id, status); if (*status != rpc_s_ok) { goto out; } /* Get the interface ID */ uuid_to_string(&if_id.uuid, &uuid, status); if (*status != rpc_s_ok) { goto out; } RPC_MEM_ALLOC(interfaceID, unsigned_char_p_t, strlen(uuid) + sizeof(",65535.65535"), RPC_C_MEM_NSRESOLUTION, RPC_C_MEM_WAITOK); sprintf(interfaceID, "%s,%hu.%hu", uuid, if_id.vers_major, if_id.vers_minor); valueRpcNsInterfaceID[0] = interfaceID; valueRpcNsInterfaceID[1] = NULL; modRpcNsInterfaceID.mod_op = LDAP_MOD_ADD; modRpcNsInterfaceID.mod_type = "rpcNsInterfaceID"; modRpcNsInterfaceID.mod_values = valueRpcNsInterfaceID; RPC_MEM_ALLOC(valueRpcNsBindings, char **, (vec->count * sizeof(char *)), RPC_C_MEM_NSRESOLUTION, RPC_C_MEM_WAITOK); memset(valueRpcNsBindings, 0, (vec->count * sizeof(unsigned_char_p_t))); for (i = 0; i < vec->count; i++) { rpc_binding_to_string_binding(vec->binding_h[i], (unsigned_char_p_t *)&valueRpcNsBindings[i], status); if (*status != rpc_s_ok) { goto out; } } valueRpcNsBindings[vec->count] = NULL; modRpcNsBindings.mod_op = modop; modRpcNsBindings.mod_type = "rpcNsBindings"; modRpcNsBindings.mod_values = valueRpcNsBindings; valueObjectClass[0] = "rpcServerElement"; valueObjectClass[1] = "rpcEntry"; valueObjectClass[2] = "top"; modObjectClass.mod_op = modop; modObjectClass.mod_type = "objectClass"; modObjectClass.mod_values = valueObjectClass; modV[0] = &modRpcNsInterfaceID; modV[1] = &modRpcNsBindings; modV[2] = &modObjectClass; modV[3] = NULL; if (modop == LDAP_MOD_ADD) { rc = ldap_add_s(ld, dn, modV); } else { rc = ldap_modify_s(ld, dn, modV); } *status = (rc == LDAP_SUCCESS) ? rpc_s_ok : rpc_s_update_failed; out: if (uuid != NULL) free(uuid); if (interfaceID != NULL) free(interfaceID); if (valueRpcNsBindings != NULL) { char **p; for (p = valueRpcNsBindings; *valueRpcNsBindings != NULL; p++) { unsigned_char_p_t tmp = (unsigned_char_p_t)*p; rpc_string_free(&tmp, status); } RPC_MEM_FREE(valueRpcNsBindings, RPC_C_MEM_NSRESOLUTION); } }
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); }
idl_boolean ReverseIt( rpc_binding_handle_t h, args * in_text, args ** out_text, error_status_t * status ) { char * binding_info; error_status_t e; unsigned result_size; args * result; unsigned32 i,j,l; rpc_transport_info_handle_t transport_info = NULL; unsigned32 rpcstatus = 0; #if 0 unsigned char* sesskey = NULL; unsigned32 sesskey_len = 0; unsigned char* principal_name = NULL; #endif /* * Get some info about the client binding */ rpc_binding_to_string_binding(h, (unsigned char **)&binding_info, &e); if (e == rpc_s_ok) { printf ("ReverseIt() called by client: %s\n", binding_info); } rpc_binding_inq_transport_info(h, &transport_info, &rpcstatus); /* SMB transport session calls temporarily disabled */ #if 0 if (transport_info) { rpc_smb_transport_info_inq_peer_principal_name(transport_info, &principal_name); rpc_smb_transport_info_inq_session_key(transport_info, &sesskey, &sesskey_len); printf ("Client principal name: %s\n", (char*) principal_name); printf ("Session key: "); for (i = 0; i < sesskey_len; i++) { printf("%X", sesskey[i]); } printf ("\n"); } #endif /* 0 */ if (in_text == NULL) return 0; /* * Print the in_text */ printf("\n\nFunction ReverseIt() -- input argments\n"); for (i=0; i<in_text->argc; i++) printf("\t[arg %d]: %s\n", i, in_text->argv[i]); printf ("\n=========================================\n"); /* * Allocate the output args as dynamic storage bound * to this RPC. The output args are the same size as the * input args since we are simply reversing strings. */ result_size = sizeof(args) + in_text->argc * sizeof(string_t *); result = (args * )rpc_ss_allocate(result_size); result->argc = in_text->argc; for (i=0; i < in_text->argc; i++) { result->argv[i] = (string_t)rpc_ss_allocate(strlen((const char *)in_text->argv[i]) + 1); } /* * do the string reversal */ for (i=0; i < in_text->argc; i++) { l = strlen((const char *)in_text->argv[i]); for (j=0; j<l; j++) { result->argv[i][j] = in_text->argv[i][l-j-1]; } result->argv[i][l]=0; /* make sure its null terminated! */ } *out_text = result; *status = error_status_ok; return 1; }
int main(int argc, char *argv[]) { unsigned32 status; rpc_binding_vector_p_t server_binding; char * string_binding; unsigned32 i; const char * protocol = NULL; const char * endpoint = NULL; int c; /* * Process the cmd line args */ while ((c = getopt(argc, argv, "e:nut")) != EOF) { switch (c) { case 'e': endpoint = optarg; break; case 'n': protocol = PROTOCOL_NP; break; case 'u': protocol = PROTOCOL_UDP; break; case 't': protocol = PROTOCOL_TCP; break; default: usage(); } } #if 0 if (endpoint && !protocol) { printf("ERROR: protocol is required when endpoint is specified\n"); exit(1); } #else if(!endpoint || !protocol) { usage(); exit(1); } #endif #ifndef _WIN32 /* Temporarily disable using all protocols because something is currently busted on Unix */ if (!protocol) { protocol = PROTOCOL_TCP; } #endif /* * Register the Interface with the local endpoint mapper (rpcd) */ printf ("Registering server.... \n"); rpc_server_register_if(echo_v1_0_s_ifspec, NULL, NULL, &status); chk_dce_err(status, "rpc_server_register_if()", "", 1); printf("registered.\nPreparing binding handle...\n"); bind_server(&server_binding, echo_v1_0_s_ifspec, protocol, endpoint); if(!endpoint) { /* * Register bindings with the endpoint mapper */ printf("registering bindings with endpoint mapper\n"); rpc_ep_register(echo_v1_0_s_ifspec, server_binding, NULL, (unsigned char *)"QDA application server", &status); chk_dce_err(status, "rpc_ep_register()", "", 1); } printf("registered.\n"); /* * Print out the servers endpoints (TCP and UDP port numbers) */ printf ("Server's communications endpoints are:\n"); for (i=0; i<RPC_FIELD_COUNT(server_binding); i++) { rpc_binding_to_string_binding(RPC_FIELD_BINDING_H(server_binding)[i], (unsigned char **)&string_binding, &status); if (string_binding) printf("\t%s\n", string_binding); } #ifndef _WIN32 /* * Start the signal waiting thread in background. This thread will * Catch SIGINT and gracefully shutdown the server. */ wait_for_signals(); #endif /* * Begin listening for calls */ printf ("listening for calls....\n"); DCETHREAD_TRY { rpc_server_listen(rpc_c_listen_max_calls_default, &status); } DCETHREAD_CATCH_ALL(THIS_CATCH) { printf ("Server stoppped listening\n"); } DCETHREAD_ENDTRY; /* * If we reached this point, then the server was stopped, most likely * by the signal handler thread called rpc_mgmt_stop_server(). * gracefully cleanup and unregister the bindings from the * endpoint mapper. */ #ifndef _WIN32 /* * Kill the signal handling thread */ #endif if (!endpoint) { printf ("Unregistering server from the endpoint mapper....\n"); rpc_ep_unregister(echo_v1_0_s_ifspec, server_binding, NULL, &status); chk_dce_err(status, "rpc_ep_unregister()", "", 0); } /* * retire the binding information */ printf("Cleaning up communications endpoints...\n"); rpc_server_unregister_if(echo_v1_0_s_ifspec, NULL, &status); chk_dce_err(status, "rpc_server_unregister_if()", "", 0); exit(0); }