void *my_thread_process(void *arg) { CLIENT *client = NULL; struct netconfig *nconf = NULL; struct netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; enum clnt_stat cs; int var_snd = 10; int var_rec = -1; struct timeval tv; int i; if (run_mode == 1) { fprintf(stderr, "Thread %d\n", atoi(arg)); } tv.tv_sec = 0; tv.tv_usec = 100; nconf = getnetconfigent("udp"); if (nconf == (struct netconfig *)NULL) { //syslog(LOG_ERR, "getnetconfigent for udp failed"); printf("err nconf\n"); pthread_exit(1); } svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if (svcaddr.buf == NULL) { pthread_exit(1); } //printf("svcaddr reserved (%s)\n", argc[1]); if (!rpcb_getaddr(progNum + atoi(arg), VERSNUM, nconf, &svcaddr, hostname)) { fprintf(stderr, "rpcb_getaddr failed!!\n"); pthread_exit(1); } //printf("svc get\n"); client = clnt_dg_create(RPC_ANYFD, &svcaddr, progNum + atoi(arg), VERSNUM, 1024, 1024); if (client == NULL) { clnt_pcreateerror("ERR"); pthread_exit(1); } for (i = 0; i < callNb; i++) { cs = clnt_call(client, PROCNUM, (xdrproc_t) xdr_int, (char *)&var_snd, (xdrproc_t) xdr_int, (char *)&var_rec, tv); thread_array_result[atoi(arg)] += (cs == RPC_SUCCESS); } pthread_exit(0); }
void *my_thread_process(void *arg) { int i; CLIENT *client = NULL; struct netconfig *nconf = NULL; struct netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; int var_snd = 0; int var_rec = -1; struct timeval tv; if (run_mode == 1) { fprintf(stderr, "Thread %d\n", atoi(arg)); } tv.tv_sec = 0; tv.tv_usec = 100; nconf = getnetconfigent("udp"); if (nconf == (struct netconfig *)NULL) { fprintf(stderr, "err nconf\n"); printf("5\n"); exit(1); } svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if (svcaddr.buf == NULL) { printf("5\n"); exit(5); } if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, hostname)) { fprintf(stderr, "rpcb_getaddr failed!!\n"); printf("5\n"); exit(5); } client = clnt_tli_create(RPC_ANYFD, nconf, &svcaddr, progNum, VERSNUM, 0, 0); if (client == NULL) { printf("5\n"); exit(5); } for (i = 0; i < callNb; i++) { clnt_call(client, PROCNUM, (xdrproc_t) xdr_int, (char *)&var_snd, (xdrproc_t) xdr_int, (char *)&var_rec, tv); } clnt_destroy(client); pthread_exit(0); }
int main(int argn, char *argc[]) { //Program parameters : argc[1] : HostName or Host IP // argc[2] : Server Program Number // other arguments depend on test case //run_mode can switch into stand alone program or program launch by shell script //1 : stand alone, debug mode, more screen information //0 : launch by shell script as test case, only one printf -> result status int run_mode = 0; int test_status = 1; //Default test result set to FAILED int progNum = atoi(argc[2]); CLIENT *client = NULL; struct netconfig *nconf = NULL; struct netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; //Initialization if (run_mode) { printf("Before creation\n"); } nconf = getnetconfigent("udp"); if (nconf == NULL) { //syslog(LOG_ERR, "getnetconfigent for udp failed"); printf("err nconf\n"); exit(1); } svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if (svcaddr.buf == NULL) { /* if malloc() failed, print error messages and exit */ return 1; } //printf("svcaddr reserved (%s)\n", argc[1]); if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, argc[1])) { fprintf(stderr, "rpcb_getaddr failed!!\n"); exit(1); } //printf("svc get\n"); client = clnt_tli_create(RPC_ANYFD, nconf, &svcaddr, progNum, VERSNUM, 0, 0); /**/ test_status = ((CLIENT *) client != NULL) ? 0 : 1; //This last printf gives the result status to the tests suite //normally should be 0: test has passed or 1: test has failed printf("%d\n", test_status); clnt_destroy(client); return test_status; }
int main(int argn, char *argc[]) { //Program parameters : argc[1] : HostName or Host IP // argc[2] : Server Program Number // other arguments depend on test case //run_mode can switch into stand alone program or program launch by shell script //1 : stand alone, debug mode, more screen information //0 : launch by shell script as test case, only one printf -> result status int run_mode = 0; int test_status = 0; //Default test result set to PASS int progNum = atoi(argc[2]); int i; struct netconfig *nconf = NULL; struct netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; //Test initialization svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if ((nconf = getnetconfigent("udp")) == (struct netconfig *)NULL) { fprintf(stderr, "Cannot get netconfig entry for UDP\n"); printf("5\n"); exit(1); } //Call tested function using all tests cases for (i = 0; i < NBCASE; i++) { //Check result if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, argc[1])) { //test has failed test_status = 1; break; } } //This last printf gives the result status to the tests suite //normally should be 0: test has passed or 1: test has failed printf("%d\n", test_status); return test_status; }
int main(int argn, char *argc[]) { //Program parameters : argc[1] : HostName or Host IP // argc[2] : Server Program Number // other arguments depend on test case //run_mode can switch into stand alone program or program launch by shell script //1 : stand alone, debug mode, more screen information //0 : launch by shell script as test case, only one printf -> result status int run_mode = 0; int test_status = 1; //Default test result set to FAILED int progNum = atoi(argc[2]); struct netconfig *nconf = NULL; struct netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; //Initialization svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if (run_mode) { printf("Host : %s\n", argc[1]); printf("ProgNum : %d\n", progNum); } /* Returns a pointer to nconf corresponding to NETCONF */ if ((nconf = getnetconfigent("udp")) == (struct netconfig *)NULL) { fprintf(stderr, "Cannot get netconfig entry for UDP\n"); exit(1); } test_status = !rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, argc[1]); //This last printf gives the result status to the tests suite //normally should be 0: test has passed or 1: test has failed printf("%d\n", test_status); return test_status; }
int main(int argn, char *argc[]) { //Program parameters : argc[1] : HostName or Host IP // argc[2] : Server Program Number // argc[3] : Number of test call // other arguments depend on test case //run_mode can switch into stand alone program or program launch by shell script //1 : stand alone, debug mode, more screen information //0 : launch by shell script as test case, only one printf -> result status int run_mode = 0; int test_status = 0; //Default test result set to FAILED int i; double *resultTbl; struct timeval tv1,tv2; struct timezone tz; long long diff; double rslt; int progNum = atoi(argc[2]); CLIENT *client = NULL; struct netconfig *nconf = NULL; struct netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; enum clnt_stat cs; int var_snd = 0; int var_rec = -1; struct timeval tv; //Test initialisation maxIter = atoi(argc[3]); resultTbl = (double *)malloc(maxIter * sizeof(double)); if (run_mode) { printf("Before creation\n"); printf("client : %d\n", client); printf("nconf : %d\n", nconf); } tv.tv_sec = 0; tv.tv_usec = 100; nconf = getnetconfigent("udp"); if (nconf == (struct netconfig *) NULL) { fprintf(stderr, "err nconf\n"); printf("5\n"); exit(5); } svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if (svcaddr.buf == NULL) { printf("5\n"); exit(5); } if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, argc[1])) { fprintf(stderr, "rpcb_getaddr failed!!\n"); printf("5\n"); exit(5); } client = clnt_tli_create(RPC_ANYFD, nconf, &svcaddr, progNum, VERSNUM, 0, 0); if (client == NULL) { printf("5\n"); exit(1); } //Call tested function several times for (i = 0; i < maxIter; i++) { //Tic gettimeofday(&tv1, &tz); //Call function cs = clnt_call(client, PROCNUM, (xdrproc_t)xdr_int, (char *)&var_snd, (xdrproc_t)xdr_int, (char *)&var_rec, tv); //Toc gettimeofday(&tv2, &tz); //Add function execution time (toc-tic) diff = (tv2.tv_sec-tv1.tv_sec) * 1000000L + (tv2.tv_usec-tv1.tv_usec); rslt = (double)diff / 1000; if (cs == RPC_SUCCESS) { resultTbl[i] = rslt; } else { test_status = 1; break; } if (run_mode) { fprintf(stderr, "lf time = %lf usecn\n", resultTbl[i]); } } //This last printf gives the result status to the tests suite //normally should be 0: test has passed or 1: test has failed printf("%d\n", test_status); printf("%lf %d\n", average(resultTbl), maxIter); printf("%lf\n", mini(resultTbl)); printf("%lf\n", maxi(resultTbl)); return test_status; }
void *my_thread_process(void *arg) { int i; CLIENT *clnt = NULL; struct datas vars; static double result = 0; struct timeval total_timeout; struct netconfig *nconf = NULL; struct netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; total_timeout.tv_sec = 1; total_timeout.tv_usec = 1; nconf = getnetconfigent("udp"); if ((struct netconfig *)nconf == NULL) { //Test failed printf("5\n"); pthread_exit(5); } svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if (svcaddr.buf == NULL) { printf("5\n"); pthread_exit(5); } if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, hostname)) { fprintf(stderr, "rpcb_getaddr failed!!\n"); printf("5\n"); pthread_exit(5); } clnt = clnt_dg_create(RPC_ANYFD, &svcaddr, progNum, VERSNUM, 1024, 1024); if (clnt == NULL) { printf("5\n"); pthread_exit(5); } if (run_mode == 1) { fprintf(stderr, "Thread %d\n", atoi(arg)); } vars.a = getRand(); vars.b = getRand(); vars.c = getRand(); resTbl[atoi(arg)].locRes = vars.a + (vars.b * vars.c); clnt_call((CLIENT *) clnt, CALCTHREADPROC, (xdrproc_t) xdr_datas, (char *)&vars, // xdr_in (xdrproc_t) xdr_double, (char *)&resTbl[atoi(arg)].svcRes, // xdr_out total_timeout); thread_array_result[atoi(arg)] = (resTbl[atoi(arg)].svcRes == resTbl[atoi(arg)].locRes) ? 0 : 1; if (run_mode == 1) { fprintf(stderr, "Thread #%d calc : %lf, received : %lf\n", atoi(arg), resTbl[atoi(arg)].locRes, resTbl[atoi(arg)].svcRes); } pthread_exit(0); }
int main(int argn, char *argc[]) { //Program parameters : argc[1] : HostName or Host IP // argc[2] : Server Program Number // argc[3] : Number of testes function calls // other arguments depend on test case //run_mode can switch into stand alone program or program launch by shell script //1 : stand alone, debug mode, more screen information //0 : launch by shell script as test case, only one printf -> result status int run_mode = 0; int test_status = 1; //Default test result set to FAILED int progNum = atoi(argc[2]); CLIENT *client = NULL; struct netconfig *nconf = NULL; struct netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; enum clnt_stat cs; int var_snd = 0; int var_rec = -1; struct timeval tv; int nbCall = atoi(argc[3]); int nbOk = 0; int i; //Initialization if (run_mode) { printf("Before creation\n"); printf("client : %d\n", client); printf("nconf : %d\n", nconf); } tv.tv_sec = 0; tv.tv_usec = 100; nconf = getnetconfigent("udp"); if (nconf == (struct netconfig *) NULL) { //syslog(LOG_ERR, "getnetconfigent for udp failed"); fprintf(stderr, "err nconf\n"); printf("5\n"); exit(5); } svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if (svcaddr.buf == NULL) { printf("5\n"); exit(5); } //printf("svcaddr reserved (%s)\n", argc[1]); if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, argc[1])) { fprintf(stderr, "rpcb_getaddr failed!!\n"); printf("5\n"); exit(5); } for (i = 0; i < nbCall; i++) { cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, PROCNUM, (xdrproc_t)xdr_int, (char *)&var_snd, (xdrproc_t)xdr_int, (char *)&var_rec, tv, &svcaddr); if (cs == RPC_SUCCESS) nbOk++; } if (run_mode == 1) { printf("Aimed : %d\n", nbCall); printf("Got : %d\n", nbOk); } test_status = (nbOk == nbCall) ? 0 : 1; //This last printf gives the result status to the tests suite //normally should be 0: test has passed or 1: test has failed printf("%d\n", test_status); return test_status; }
int main(int argn, char *argc[]) { //Program parameters : argc[1] : HostName or Host IP // argc[2] : Server Program Number // other arguments depend on test case //run_mode can switch into stand alone program or program launch by shell script //1 : stand alone, debug mode, more screen information //0 : launch by shell script as test case, only one printf -> result status int run_mode = 0; int test_status = 0; //Default test result set to PASS int progNum = atoi(argc[2]); int i; params paramList[NBCASE]; CLIENT *client = NULL; struct netconfig *nconf = NULL; struct netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; bool_t rpcb_rslt; //Test initialization nconf = getnetconfigent("udp"); if (nconf == (struct netconfig *)NULL) { //syslog(LOG_ERR, "getnetconfigent for udp failed"); fprintf(stderr, "err nconf\n"); printf("5\n"); exit(1); } svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if (svcaddr.buf == NULL) { /* if malloc() failed, print error messages and exit */ printf("5\n"); return 1; } if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, argc[1])) { fprintf(stderr, "rpcb_getaddr failed!!\n"); printf("5\n"); exit(1); } //Test arguments initialization paramList[0].bufsnd = 0; paramList[0].bufrec = 0; paramList[1].bufsnd = 0; paramList[1].bufrec = 2147483647; paramList[2].bufsnd = 2147483647; paramList[2].bufrec = 0; paramList[3].bufsnd = 2147483647; paramList[3].bufrec = 2147483647; //Call tested function using all tests cases for (i = 0; i < NBCASE; i++) { //Debug mode prints if (run_mode == 1) { printf("Test using values : %d ", paramList[i].bufsnd); printf("%d", paramList[i].bufrec); printf("\n"); } //Call function client = clnt_dg_create(RPC_ANYFD, &svcaddr, progNum, VERSNUM, paramList[i].bufsnd, paramList[i].bufrec); //Check result if (client == NULL) { //test has failed test_status = 1; break; } } //This last printf gives the result status to the tests suite //normally should be 0: test has passed or 1: test has failed printf("%d\n", test_status); return test_status; }
int main(int argn, char *argc[]) { //Program parameters : argc[1] : HostName or Host IP // argc[2] : Server Program Number // other arguments depend on test case //run_mode can switch into stand alone program or program launch by shell script //1 : stand alone, debug mode, more screen information //0 : launch by shell script as test case, only one printf -> result status int run_mode = 0; int test_status = 0; //Default test result set to PASSED int progNum = atoi(argc[2]); CLIENT *client = NULL; struct netconfig *nconf = NULL; struct netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; enum clnt_stat cs; struct timeval tv; //Sent variables int intSnd; double dblSnd; long lngSnd; char *strSnd; //Received variables int intRec; double dblRec; long lngRec; char *strRec; //Test initialization tv.tv_sec = 0; tv.tv_usec = 100; nconf = getnetconfigent("udp"); if (nconf == (struct netconfig *) NULL) { fprintf(stderr, "err nconf\n"); printf("5\n"); exit(5); } svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if (svcaddr.buf == NULL) { printf("5\n"); exit(5); } if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, argc[1])) { fprintf(stderr, "rpcb_getaddr failed!!\n"); printf("5\n"); exit(1); } //Call tested procedure several times //Int test : call INTPROCNUM RPC intSnd = -65536; cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, INTPROCNUM, (xdrproc_t) xdr_int, (char *)&intSnd, (xdrproc_t) xdr_int, (char *)&intRec, tv, &svcaddr); if (intSnd != intRec) test_status = 1; if (run_mode == 1) printf("Send (int) : %d, Received : %d\n", intSnd, intRec); //Test positive number intSnd = 16777216; cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, INTPROCNUM, (xdrproc_t) xdr_int, (char *)&intSnd, (xdrproc_t) xdr_int, (char *)&intRec, tv, &svcaddr); if (intSnd != intRec) test_status = 1; if (run_mode == 1) printf("Send (int) : %d, Received : %d\n", intSnd, intRec); //Long test : call LNGPROCNUM RPC lngSnd = -430000; cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, LNGPROCNUM, (xdrproc_t) xdr_long, (char *)&lngSnd, (xdrproc_t) xdr_long, (char *)&lngRec, tv, &svcaddr); if (lngSnd != lngRec) test_status = 1; if (run_mode == 1) printf("Send (long) : %ld, Received : %ld\n", lngSnd, lngRec); //Double test : call DBLPROCNUM RPC dblSnd = -1735.63000f; cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, DBLPROCNUM, (xdrproc_t) xdr_double, (char *)&dblSnd, (xdrproc_t) xdr_double, (char *)&dblRec, tv, &svcaddr); if (dblSnd != dblRec) test_status = 1; if (run_mode == 1) printf("Send (double) : %lf, Received : %lf\n", dblSnd, dblRec); //String test : call STRPROCNUM RPC strSnd = "text to send."; strRec = (char *)malloc(64 * sizeof(char)); cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, STRPROCNUM, (xdrproc_t) xdr_wrapstring, (char *)&strSnd, (xdrproc_t) xdr_wrapstring, (char *)&strRec, tv, &svcaddr); if (strcmp(strSnd, strRec)) test_status = 1; if (run_mode == 1) printf("Send (string) : %s, Received : %s\n", strSnd, strRec); //This last printf gives the result status to the tests suite //normally should be 0: test has passed or 1: test has failed printf("%d\n", test_status); return test_status; }
/* * Create an rpc client attached to the mount daemon. */ CLIENT * get_mount_client(char *host, struct sockaddr_in *unused_sin, struct timeval *tv, int *sock, u_long mnt_version) { CLIENT *client; struct netbuf nb; struct netconfig *nc = NULL; struct sockaddr_in sin; nb.maxlen = sizeof(sin); nb.buf = (char *) &sin; /* * First try a TCP handler */ /* * Find mountd address on TCP */ if ((nc = getnetconfigent(NC_TCP)) == NULL) { plog(XLOG_ERROR, "getnetconfig for tcp failed: %s", nc_sperror()); goto tryudp; } if (!rpcb_getaddr(MOUNTPROG, mnt_version, nc, &nb, host)) { /* * don't print error messages here, since mountd might legitimately * serve udp only */ goto tryudp; } /* * Create privileged TCP socket */ *sock = t_open(nc->nc_device, O_RDWR, 0); if (*sock < 0) { plog(XLOG_ERROR, "t_open %s: %m", nc->nc_device); goto tryudp; } if (bind_resv_port(*sock, (u_short *) 0) < 0) plog(XLOG_ERROR, "couldn't bind mountd socket to privileged port"); if ((client = clnt_vc_create(*sock, &nb, MOUNTPROG, mnt_version, 0, 0)) == (CLIENT *) NULL) { plog(XLOG_ERROR, "clnt_vc_create failed"); t_close(*sock); goto tryudp; } /* tcp succeeded */ dlog("get_mount_client: using tcp, port %d", sin.sin_port); if (nc) freenetconfigent(nc); return client; tryudp: /* first free possibly previously allocated netconfig entry */ if (nc) freenetconfigent(nc); /* * TCP failed so try UDP */ /* * Find mountd address on UDP */ if ((nc = getnetconfigent(NC_UDP)) == NULL) { plog(XLOG_ERROR, "getnetconfig for udp failed: %s", nc_sperror()); goto badout; } if (!rpcb_getaddr(MOUNTPROG, mnt_version, nc, &nb, host)) { plog(XLOG_ERROR, "%s", clnt_spcreateerror("couldn't get mountd address on udp")); goto badout; } /* * Create privileged UDP socket */ *sock = t_open(nc->nc_device, O_RDWR, 0); if (*sock < 0) { plog(XLOG_ERROR, "t_open %s: %m", nc->nc_device); goto badout; /* neither tcp not udp succeeded */ } if (bind_resv_port(*sock, (u_short *) 0) < 0) plog(XLOG_ERROR, "couldn't bind mountd socket to privileged port"); if ((client = clnt_dg_create(*sock, &nb, MOUNTPROG, mnt_version, 0, 0)) == (CLIENT *) NULL) { plog(XLOG_ERROR, "clnt_dg_create failed"); t_close(*sock); goto badout; /* neither tcp not udp succeeded */ } if (clnt_control(client, CLSET_RETRY_TIMEOUT, (char *) tv) == FALSE) { plog(XLOG_ERROR, "clnt_control CLSET_RETRY_TIMEOUT for udp failed"); clnt_destroy(client); goto badout; /* neither tcp not udp succeeded */ } /* udp succeeded */ dlog("get_mount_client: using udp, port %d", sin.sin_port); return client; badout: /* failed */ if (nc) freenetconfigent(nc); return NULL; }
/* * We use our own private version of svc_create() which registers our services * only on loopback transports and enables an option whereby Solaris ucreds * are associated with each connection, permitting us to check privilege bits. */ static int fmd_rpc_svc_create_local(void (*disp)(struct svc_req *, SVCXPRT *), rpcprog_t prog, rpcvers_t vers, uint_t ssz, uint_t rsz, int force) { struct netconfig *ncp; struct netbuf buf; SVCXPRT *xprt; void *hdl; int fd, n = 0; char door[PATH_MAX]; time_t tm; if ((hdl = setnetconfig()) == NULL) { fmd_error(EFMD_RPC_REG, "failed to iterate over " "netconfig database: %s\n", nc_sperror()); return (fmd_set_errno(EFMD_RPC_REG)); } if (force) svc_unreg(prog, vers); /* clear stale rpcbind registrations */ buf.buf = alloca(_SS_MAXSIZE); buf.maxlen = _SS_MAXSIZE; buf.len = 0; while ((ncp = getnetconfig(hdl)) != NULL) { if (strcmp(ncp->nc_protofmly, NC_LOOPBACK) != 0) continue; if (!force && rpcb_getaddr(prog, vers, ncp, &buf, HOST_SELF)) { (void) endnetconfig(hdl); return (fmd_set_errno(EFMD_RPC_BOUND)); } if ((fd = t_open(ncp->nc_device, O_RDWR, NULL)) == -1) { fmd_error(EFMD_RPC_REG, "failed to open %s: %s\n", ncp->nc_device, t_strerror(t_errno)); continue; } svc_fd_negotiate_ucred(fd); /* enable ucred option on xprt */ if ((xprt = svc_tli_create(fd, ncp, NULL, ssz, rsz)) == NULL) { (void) t_close(fd); continue; } if (svc_reg(xprt, prog, vers, disp, ncp) == FALSE) { fmd_error(EFMD_RPC_REG, "failed to register " "rpc service on %s\n", ncp->nc_netid); svc_destroy(xprt); continue; } n++; } (void) endnetconfig(hdl); /* * If we failed to register services (n == 0) because rpcbind is down, * then check to see if the RPC door file exists before attempting an * svc_door_create(), which cleverly destroys any existing door file. * The RPC APIs have no stable errnos, so we use rpcb_gettime() as a * hack to determine if rpcbind itself is down. */ if (!force && n == 0 && rpcb_gettime(HOST_SELF, &tm) == FALSE && snprintf(door, sizeof (door), RPC_DOOR_RENDEZVOUS, prog, vers) > 0 && access(door, F_OK) == 0) return (fmd_set_errno(EFMD_RPC_BOUND)); /* * Attempt to create a door server for the RPC program as well. Limit * the maximum request size for the door transport to the receive size. */ if ((xprt = svc_door_create(disp, prog, vers, ssz)) == NULL) { fmd_error(EFMD_RPC_REG, "failed to create door for " "rpc service 0x%lx/0x%lx\n", prog, vers); } else { (void) svc_control(xprt, SVCSET_CONNMAXREC, &rsz); n++; } return (n); }
static int ypxfrd_transfer (char *host, char *map, char *domain, char *tmpname) { CLIENT *clnt; struct ypxfr_mapname req; struct xfr resp; struct timeval timeout = {25, 0}; int port = 0; #if defined(HAVE_RPCB_GETADDR) struct netconfig *nconf; struct netbuf svcaddr; char addrbuf[INET6_ADDRSTRLEN]; void *handle; int found; #endif if (debug_flag) fprintf (stderr, "Trying ypxfrd ..."); #ifdef HAVE_RPCB_GETADDR svcaddr.len = 0; svcaddr.maxlen = sizeof (addrbuf); svcaddr.buf = addrbuf; found = 0; handle = setnetconfig(); while ((nconf = getnetconfig(handle)) != NULL) { if (!strcmp(nconf->nc_proto, "udp")) { if (rpcb_getaddr(YPXFRD_FREEBSD_PROG, YPXFRD_FREEBSD_VERS, nconf, &svcaddr, host)) { port = __taddr2port (nconf, &svcaddr); endnetconfig (handle); found=1; break; } if (rpc_createerr.cf_stat != RPC_UNKNOWNHOST) { clnt_pcreateerror (host); log_msg ("rpcb_getaddr (%s) failed!", host); return 1; } } } if (!found) { log_msg ("Cannot find suitable transport for protocol 'udp'"); return 1; } #else port = getrpcport (host, YPXFRD_FREEBSD_PROG, YPXFRD_FREEBSD_VERS, IPPROTO_TCP)) #endif if (port == 0) { if (debug_flag) log_msg (" not running"); return 1; } req.xfrmap = map; req.xfrdomain = domain; req.xfrmap_filename = map; #if defined(HAVE_LIBGDBM) #if SIZEOF_LONG == 8 req.xfr_db_type = XFR_DB_GNU_GDBM64; #else req.xfr_db_type = XFR_DB_GNU_GDBM; #endif #if defined(WORDS_BIGENDIAN) req.xfr_byte_order = XFR_ENDIAN_BIG; #else req.xfr_byte_order = XFR_ENDIAN_LITTLE; #endif #elif defined (HAVE_NDBM) #if defined(__sun__) || defined (sun) req.xfr_db_type = XFR_DB_NDBM; #if defined(WORDS_BIGENDIAN) req.xfr_byte_order = XFR_ENDIAN_BIG; #else req.xfr_byte_order = XFR_ENDIAN_LITTLE; #endif #else req.xfr_db_type = XFR_DB_BSD_NDBM; req.xfr_byte_order = XFR_ENDIAN_ANY; #endif #elif defined (HAVE_LIBQDBM) req.xfr_db_type = XFR_DB_QDBM; #if defined(WORDS_BIGENDIAN) req.xfr_byte_order = XFR_ENDIAN_BIG; #else req.xfr_byte_order = XFR_ENDIAN_LITTLE; #endif #elif defined (HAVE_LIBTC) req.xfr_db_type = XFR_DB_TC; req.xfr_byte_order = XFR_ENDIAN_ANY; #endif memset (&resp, 0, sizeof (resp)); if ((clnt = clnt_create (host, YPXFRD_FREEBSD_PROG, YPXFRD_FREEBSD_VERS, "tcp")) == NULL) goto error; if ((ypxfrd_file = open (tmpname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) == -1) { clnt_destroy (clnt); log_msg ("couldn't open %s: %s", tmpname, strerror (errno)); goto error; } if (clnt_call (clnt, YPXFRD_GETMAP, (xdrproc_t) xdr_ypxfr_mapname, (caddr_t) &req, (xdrproc_t) xdr_ypxfr_xfr, (caddr_t) &resp, timeout) != RPC_SUCCESS) { log_msg ("%s", clnt_sperror (clnt, "call to rpc.ypxfrd failed")); unlink (tmpname); clnt_destroy (clnt); close (ypxfrd_file); goto error; } clnt_destroy (clnt); close (ypxfrd_file); if (debug_flag) log_msg (" success\n"); return 0; error: if (debug_flag) log_msg (" (failed, fallback to enumeration)\n"); return 1; }