static int get_manifest_channel_locked(struct NaClSrpcChannel **result) { int status; int manifest; int manifest_conn; if (manifest_channel_initialized) { *result = &manifest_channel; return 0; } *result = NULL; status = irt_nameservice_lookup("ManifestNameService", O_RDWR, &manifest); if (NACL_NAME_SERVICE_SUCCESS != status) { print_error("ManifestNameService lookup failed\n"); return EIO; } if (-1 == manifest) { print_error("Manifest descriptor is invalid\n"); return EIO; } manifest_conn = imc_connect(manifest); close(manifest); if (-1 == manifest_conn) { print_error("Can't connect to manifest service\n"); return EIO; } if (!NaClSrpcClientCtor(&manifest_channel, manifest_conn)) { print_error("Can't create manifest srpc channel\n"); return EIO; } *result = &manifest_channel; manifest_channel_initialized = 1; return 0; }
unsigned long get_good_seed(void) { int ns; int connected_socket; NaClSrpcChannel ns_channel; NaClSrpcError rpc_result; int status; int rng; unsigned long seed; ns = -1; if (-1 == nacl_nameservice(&ns)) { fprintf(stderr, "nacl_nameservice failed\n"); abort(); } connected_socket = imc_connect(ns); assert(-1 != connected_socket); if (!NaClSrpcClientCtor(&ns_channel, connected_socket)) { fprintf(stderr, "SRPC client channel ctor failed\n"); abort(); } (void) close(ns); rpc_result = NaClSrpcInvokeBySignature(&ns_channel, NACL_NAME_SERVICE_LOOKUP, "SecureRandom", O_RDONLY, &status, &rng); assert(NACL_SRPC_RESULT_OK == rpc_result); assert(NACL_NAME_SERVICE_SUCCESS == status); assert(sizeof seed == read(rng, &seed, sizeof seed)); close(rng); NaClSrpcDtor(&ns_channel); return seed; }
int main(void) { int ns; int connected_socket; if (!NaClSrpcModuleInit()) { return 1; } ns = -1; nacl_nameservice(&ns); assert(-1 != ns); connected_socket = imc_connect(ns); assert(-1 != connected_socket); if (!NaClSrpcClientCtor(&ns_channel, connected_socket)) { fprintf(stderr, "Srpc client channel ctor failed\n"); return 1; } close(ns); if (!NaClSrpcAcceptClientConnection(srpc_methods)) { return 1; } NaClSrpcModuleFini(); return 0; }
void NaClManifestProxyConnectionRevHandleConnect( struct NaClManifestProxyConnection *self, struct NaClDesc *rev) { NaClLog(4, "Entered NaClManifestProxyConnectionRevHandleConnect\n"); NaClXMutexLock(&self->mu); if (self->channel_initialized) { NaClLog(LOG_FATAL, "NaClManifestProxyConnectionRevHandleConnect: double connect?\n"); } /* * If NaClSrpcClientCtor proves to take too long, we should spin off * another thread to do the initialization so that the reverse * client can accept additional reverse channels. */ NaClLog(4, "NaClManifestProxyConnectionRevHandleConnect: Creating SrpcClient\n"); if (NaClSrpcClientCtor(&self->client_channel, rev)) { NaClLog(4, ("NaClManifestProxyConnectionRevHandleConnect: SrpcClientCtor" " succeded, announcing.\n")); self->channel_initialized = 1; NaClXCondVarBroadcast(&self->cv); /* ownership of rev taken */ } else { NaClLog(4, ("NaClManifestProxyConnectionRevHandleConnect: NaClSrpcClientCtor" " failed\n")); } NaClXMutexUnlock(&self->mu); NaClLog(4, "Leaving NaClManifestProxyConnectionRevHandleConnect\n"); }
void ManifestTest(NaClSrpcRpc *rpc, NaClSrpcArg **in_args, NaClSrpcArg **out_args, NaClSrpcClosure *done) { struct StringBuffer sb; NaClSrpcError rpc_result; int status; int manifest; int manifest_conn; struct NaClSrpcChannel manifest_channel; /* just get the descriptor for now */ StringBufferCtor(&sb); if (NACL_SRPC_RESULT_OK != (rpc_result = NaClSrpcInvokeBySignature(&ns_channel, NACL_NAME_SERVICE_LOOKUP, "ManifestNameService", O_RDWR, &status, &manifest))) { StringBufferPrintf(&sb, "nameservice lookup RPC failed (%d)\n", rpc_result); goto done; } StringBufferPrintf(&sb, "Got manifest descriptor %d\n", manifest); if (-1 == manifest) { fprintf(stderr, "nameservice lookup failed, status %d\n", status); goto done; } /* connect to manifest name server */ manifest_conn = imc_connect(manifest); StringBufferPrintf(&sb, "got manifest connection %d\n", manifest_conn); if (-1 == manifest_conn) { StringBufferPrintf(&sb, "could not connect\n"); goto done; } close(manifest); if (!NaClSrpcClientCtor(&manifest_channel, manifest_conn)) { StringBufferPrintf(&sb, "could not build srpc client\n"); goto done; } StringBufferDiscardOutput(&sb); StringBufferPrintf(&sb, "ManifestTest: basic connectivity ok\n"); done: out_args[0]->arrays.str = strdup(sb.buffer); rpc->result = NACL_SRPC_RESULT_OK; done->Run(done); StringBufferDtor(&sb); }
/* * nacl_multimedia_bridge() is initialized at discovery. * It is a once-only event between plugin and native client. */ void nacl_multimedia_bridge(NaClSrpcRpc *rpc, NaClSrpcArg **in_args, NaClSrpcArg **out_args, NaClSrpcClosure *done) { struct stat st; rpc->result = NACL_SRPC_RESULT_INTERNAL; nacl_multimedia.channel = (NaClSrpcChannel*) malloc(sizeof(NaClSrpcChannel)); nacl_multimedia.display_shm_desc = in_args[0]->u.hval; nacl_multimedia.connected_socket = in_args[1]->u.hval; /* Start the SRPC client to communicate over the connected socket. */ if (!NaClSrpcClientCtor(nacl_multimedia.channel, nacl_multimedia.connected_socket)) { Log("nacl_av: SRPC constructor FAILED\n"); done->Run(done); return; } /* Determine the size of the region. */ if (fstat(nacl_multimedia.display_shm_desc, &st)) { Log("nacl_av: fstat failed\n"); done->Run(done); return; } /* Map the shared memory region into the NaCl module's address space. */ nacl_multimedia.video_size = (size_t) st.st_size; nacl_multimedia.video_data = (struct NaClVideoShare*) mmap(NULL, nacl_multimedia.video_size, PROT_READ | PROT_WRITE, MAP_SHARED, nacl_multimedia.display_shm_desc, 0); if (MAP_FAILED == nacl_multimedia.video_data) { Log("nacl_av: mmap failed\n"); nacl_multimedia.video_size = 0; nacl_multimedia.video_data = NULL; nacl_multimedia.embedded = 0; done->Run(done); return; } /* Tell main to proceed allowing further processing */ mark_multimedia_init_done(); rpc->result = NACL_SRPC_RESULT_OK; done->Run(done); }
int main(void) { int ns; NaClSrpcChannel channel; int connected_socket; int status; int rng; if (!NaClSrpcModuleInit()) { fprintf(stderr, "srpc module init failed\n"); return 1; } printf("Hello world\n"); ns = -1; nacl_nameservice(&ns); printf("ns = %d\n", ns); assert(-1 != ns); connected_socket = imc_connect(ns); assert(-1 != connected_socket); if (!NaClSrpcClientCtor(&channel, connected_socket)) { fprintf(stderr, "Srpc client channel ctor failed\n"); return 1; } printf("NaClSrpcClientCtor succeeded\n"); if (!EnumerateNames(&channel)) { fprintf(stderr, "Could not enumerate names\n"); return 1; } printf("EnumerateNames succeeded\n"); if (NACL_SRPC_RESULT_OK != NaClSrpcInvokeBySignature(&channel, NACL_NAME_SERVICE_LOOKUP, "SecureRandom", O_RDONLY, &status, &rng)) { fprintf(stderr, "nameservice lookup failed, status %d\n", status); return 1; } printf("rpc status %d\n", status); assert(NACL_NAME_SERVICE_SUCCESS == status); printf("rng descriptor %d\n", rng); dump_output(rng, RNG_OUTPUT_BYTES); return 0; }
int main(int argc, char* argv[]) { int result; NaClHandle pair[2]; #ifdef __native_client__ int imc_desc[2]; #else struct NaClDescImcDesc* imc_desc[2]; #endif struct NaClThread thr; NaClSrpcChannel channel; NaClSrpcError error; struct ServiceThreadArgs* threadArg; UNREFERENCED_PARAMETER(argc); UNREFERENCED_PARAMETER(argv); NaClSrpcModuleInit(); if (0 != NaClSocketPair(pair)) { failWithErrno("SocketPair"); } #ifdef __native_client__ imc_desc[0] = pair[0]; imc_desc[1] = pair[1]; #else NaClNrdAllModulesInit(); imc_desc[0] = (struct NaClDescImcDesc*) calloc(1, sizeof(*imc_desc[0])); if (0 == imc_desc[0]) { failWithErrno("calloc"); } imc_desc[1] = (struct NaClDescImcDesc*) calloc(1, sizeof(*imc_desc[1])); if (0 == imc_desc[1]) { failWithErrno("calloc"); } if (!NaClDescImcDescCtor(imc_desc[0], pair[0])) { failWithErrno("NaClDescImcDescCtor"); } if (!NaClDescImcDescCtor(imc_desc[1], pair[1])) { failWithErrno("NaClDescImcDescCtor"); } #endif threadArg = (struct ServiceThreadArgs*) calloc(1, sizeof(*threadArg)); if (NULL == threadArg) { failWithErrno("calloc for threadArg"); } threadArg->desc = (NaClSrpcImcDescType)imc_desc[0]; if (!NaClThreadCreateJoinable(&thr, serviceThread, threadArg, 128*1024)) { failWithErrno("NaClThreadCtor"); } if (!NaClSrpcClientCtor(&channel, (NaClSrpcImcDescType) imc_desc[1])) { failWithErrno("NaClSrpcClientCtor"); } error = NaClSrpcInvokeBySignature(&channel, "getNum::i", &result); if (NACL_SRPC_RESULT_OK != error) { fprintf(stderr, "SRPC call to getNum::i failed: %s\n", NaClSrpcErrorString(error)); exit(EXIT_FAILURE); } if (TEST_NUM != result) { fprintf(stderr, "expected: %d, got: %d\n", TEST_NUM, result); exit(EXIT_FAILURE); } NaClSrpcDtor(&channel); #ifdef __native_client__ close(imc_desc[1]); #else NaClDescUnref((NaClSrpcImcDescType)imc_desc[1]); #endif NaClThreadJoin(&thr); NaClSrpcModuleFini(); return 0; }
int main(int argc, char* argv[]) { nacl_abi_size_t char_array_count; char* char_array_carr; NaClHandle pair[2]; #ifdef __native_client__ int imc_desc[2]; #else struct NaClDescImcDesc* imc_desc[2]; #endif struct NaClThread thr; NaClSrpcChannel channel; NaClSrpcError error; struct ServiceThreadArgs* threadArg; UNREFERENCED_PARAMETER(argc); UNREFERENCED_PARAMETER(argv); NaClSrpcModuleInit(); if (0 != NaClSocketPair(pair)) { failWithErrno("SocketPair"); } #ifdef __native_client__ imc_desc[0] = pair[0]; imc_desc[1] = pair[1]; #else NaClNrdAllModulesInit(); imc_desc[0] = (struct NaClDescImcDesc*) calloc(1, sizeof(*imc_desc[0])); if (0 == imc_desc[0]) { failWithErrno("calloc"); } imc_desc[1] = (struct NaClDescImcDesc*) calloc(1, sizeof(*imc_desc[1])); if (0 == imc_desc[1]) { failWithErrno("calloc"); } if (!NaClDescImcDescCtor(imc_desc[0], pair[0])) { failWithErrno("NaClDescImcDescCtor"); } if (!NaClDescImcDescCtor(imc_desc[1], pair[1])) { failWithErrno("NaClDescImcDescCtor"); } #endif threadArg = (struct ServiceThreadArgs*) calloc(1, sizeof(*threadArg)); if (NULL == threadArg) { failWithErrno("calloc for threadArg"); } threadArg->desc = (NaClSrpcImcDescType)imc_desc[0]; if (!NaClThreadCreateJoinable(&thr, serviceThread, threadArg, 128*1024)) { failWithErrno("NaClThreadCtor"); } if (!NaClSrpcClientCtor(&channel, (NaClSrpcImcDescType) imc_desc[1])) { failWithErrno("NaClSrpcClientCtor"); } char_array_count = TEST_ARRAY_LENGTH; char_array_carr = (char*) calloc(TEST_ARRAY_LENGTH, sizeof(char)); if (!char_array_carr) { failWithErrno("calloc for char_array"); } memset(char_array_carr, TEST_NUM, TEST_ARRAY_LENGTH); error = NaClSrpcInvokeBySignature(&channel, "putArr:C:", char_array_count, char_array_carr); if (NACL_SRPC_RESULT_OK != error) { fprintf(stderr, "SRPC call to putArr:C: failed: %s\n", NaClSrpcErrorString(error)); exit(EXIT_FAILURE); } free(char_array_carr); NaClSrpcDtor(&channel); #ifdef __native_client__ close(imc_desc[1]); #else NaClDescUnref((NaClSrpcImcDescType)imc_desc[1]); #endif NaClThreadJoin(&thr); NaClSrpcModuleFini(); return 0; }
void NaClPluginLowLevelInitializationCompleteInternal(void) { int nameservice_conn_desc; int kernel_service_conn_cap_desc = -1; int kernel_service_desc; struct NaClSrpcChannel srpc_channel; int status; NaClLog(4, "Entered NaClPluginLowLevelInitializationComplete\n"); if (-1 != gNaClNameServiceConnCapDesc) { NaClLog(LOG_ERROR, "Double call to NaClPluginLowLevelInitializationComplete?\n"); return; } /* * The existence of the bootstrap nameservice is independent of * whether NaCl is running as a standalone application or running as * a untrusted Pepper plugin, browser extension environment. */ if (-1 == nacl_nameservice(&gNaClNameServiceConnCapDesc)) { NaClLog(LOG_FATAL, "NaClPluginLowLevelInitializationComplete: no name service?!?\n"); } nameservice_conn_desc = imc_connect(gNaClNameServiceConnCapDesc); if (-1 == nameservice_conn_desc) { NaClLog(LOG_FATAL, "Could not connect to bootstrap name service\n"); } if (!NaClSrpcClientCtor(&srpc_channel, nameservice_conn_desc)) { (void) close(nameservice_conn_desc); NaClLog(LOG_FATAL, "SRPC channel ctor to name service failed\n"); } if (NACL_SRPC_RESULT_OK != NaClSrpcInvokeBySignature( &srpc_channel, NACL_NAME_SERVICE_LOOKUP, "KernelService", O_RDWR, &status, &kernel_service_conn_cap_desc)) { NaClSrpcDtor(&srpc_channel); NaClLog(LOG_FATAL, "Name service lookup RPC for KernelService failed\n"); } NaClSrpcDtor(&srpc_channel); if (-1 == kernel_service_conn_cap_desc) { NaClLog(LOG_FATAL, "Name service lookup for KernelService failed, %d\n", status); } if (-1 == (kernel_service_desc = imc_connect(kernel_service_conn_cap_desc))) { (void) close(kernel_service_conn_cap_desc); NaClLog(LOG_FATAL, "Connect to KernelService failed\n"); } (void) close(kernel_service_conn_cap_desc); if (!NaClSrpcClientCtor(&srpc_channel, kernel_service_desc)) { (void) close(kernel_service_desc); NaClLog(LOG_FATAL, "SRPC channel ctor to KernelService failed\n"); } if (NACL_SRPC_RESULT_OK != NaClSrpcInvokeBySignature( &srpc_channel, NACL_KERNEL_SERVICE_INITIALIZATION_COMPLETE)) { NaClLog(LOG_FATAL, "KernelService init_done RPC failed!\n"); } NaClSrpcDtor(&srpc_channel); }