void ippool_api_init(void) { int result; /* Register RPC interface */ ippool_rpc_xprt = svcudp_create(RPC_ANYSOCK); if (ippool_rpc_xprt == NULL) { ippool_log(LOG_ERR, "unable to register with RPC"); exit(1); } /* FIXME: is this really required? */ svc_unregister(IPPOOL_PROG, IPPOOL_VERSION); /* Note: must call this or the registration fails every other time * the daemon is started. */ (void) pmap_unset(IPPOOL_PROG, IPPOOL_VERSION); result = svc_register(ippool_rpc_xprt, IPPOOL_PROG, IPPOOL_VERSION, ippool_prog_1, IPPROTO_UDP); if (result == 0) { /* UNIX is nice and consistent about error codes ;-) */ ippool_log(LOG_ERR, "unable to register RPC program"); exit(1); } result = usl_fd_add_fd(ippool_rpc_xprt->xp_sock, ippool_api_rpc_msg, ippool_rpc_xprt); if (result < 0) { ippool_log(LOG_ERR, "unable to register RPC handler"); exit(1); } }
bool_t ippool_test_log_1_svc(char *message, int *result, struct svc_req *req) { #ifdef IPPOOL_TEST ippool_log(LOG_INFO, "APP: %s", message); *result = 0; return TRUE; #else /* IPPOOL_TEST */ return FALSE; #endif /* IPPOOL_TEST */ }
void ippool_api_init(void) { int result; /* Register RPC interface */ ippool_rpc_xprt = svcudp_create(RPC_ANYSOCK); if (ippool_rpc_xprt == NULL) { ippool_log(LOG_ERR, "unable to register with RPC"); exit(1); } result = usl_fd_add_fd(ippool_rpc_xprt->xp_sock, ippool_api_rpc_msg, ippool_rpc_xprt); if (result < 0) { ippool_log(LOG_ERR, "unable to register RPC handler"); exit(1); } svc_unregister(IPPOOL_PROG, IPPOOL_VERSION); result = svc_register(ippool_rpc_xprt, IPPOOL_PROG, IPPOOL_VERSION, ippool_prog_1, IPPROTO_UDP); if (result == 0) { /* UNIX is nice and consistent about error codes ;-) */ ippool_log(LOG_ERR, "unable to register RPC program"); exit(1); } }
/* This function is called by the RPC mechanism to free memory * allocated when sending RPC messages. We are passed a pointer * to the XDR parse function so we use that to derive the type * of the structure to be freed. We use a lookup table and separate * free() functions per structure type because a switch() statement * can't be used to case on pointers and an if-then-else block * was error-prone. */ int ippool_prog_1_freeresult (SVCXPRT *xprt, xdrproc_t proc, caddr_t addr) { const struct ippool_api_xdr_free_entry *entry = &ippool_api_xdr_free_table[0]; while (entry->xdr_proc != NULL) { if (entry->xdr_proc == proc) { (*entry->free_fn)(addr); return TRUE; } entry++; } ippool_log(LOG_ERR, "Unimplemented XDR free_result() proc: %p", proc); return FALSE; }
/* Server callback to check that the request comes from an allowed IP * address. A call to here is inserted in the rpcgen-generated * server-side dispatch code by the build process. */ int ippool_api_rpc_check_request(SVCXPRT *xprt) { /* If remote RPC is not enabled and the request is from a * non-loopback interface, reject the request. */ if ((!ippool_opt_remote_rpc) && ((xprt->xp_raddr.sin_addr.s_addr != htonl(INADDR_LOOPBACK)) && (xprt->xp_raddr.sin_addr.s_addr != htonl(INADDR_ANY)))) { if (ippool_opt_debug) { ippool_log(LOG_ERR, "Rejecting RPC request from %s", inet_ntoa(xprt->xp_raddr.sin_addr)); } svcerr_auth(xprt, AUTH_TOOWEAK); return -EPERM; } return 0; }