diff --git a/src/rpcb_svc_com.c b/src/rpcb_svc_com.c index ff9ce6b..148fe42 100644 --- a/src/rpcb_svc_com.c +++ b/src/rpcb_svc_com.c @@ -536,10 +536,6 @@ create_rmtcall_fd(struct netconfig *nconf) rmttail->next = rmt; rmttail = rmt; } - /* XXX not threadsafe */ - if (fd > svc_maxfd) - svc_maxfd = fd; - FD_SET(fd, &svc_fdset); return (fd); } @@ -1056,9 +1052,6 @@ free_slot_by_index(int index) fi = &FINFO[index]; if (fi->flag & FINFO_ACTIVE) { netbuffree(fi->caller_addr); - /* XXX may be too big, but can't access xprt array here */ - if (fi->forward_fd >= svc_maxfd) - svc_maxfd--; free(fi->uaddr); fi->flag &= ~FINFO_ACTIVE; rpcb_rmtcalls--; @@ -1097,35 +1090,28 @@ netbuffree(struct netbuf *ap) } -#define MASKVAL (POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND) -extern bool_t __svc_clean_idle(fd_set *, int, bool_t); - void my_svc_run() { - size_t nfds; - struct pollfd pollfds[FD_SETSIZE]; int poll_ret, check_ret; int n; -#ifdef SVC_RUN_DEBUG - int i; -#endif - register struct pollfd *p; - fd_set cleanfds; for (;;) { - p = pollfds; - for (n = 0; n <= svc_maxfd; n++) { - if (FD_ISSET(n, &svc_fdset)) { - p->fd = n; - p->events = MASKVAL; - p++; - } - } - nfds = p - pollfds; - poll_ret = 0; + struct pollfd my_pollfd[svc_max_pollfd]; + int i; + + if (svc_max_pollfd == 0 && svc_pollfd == NULL) + return; - switch (poll_ret = poll(pollfds, nfds, 30 * 1000)) { + + for (i = 0; i < svc_max_pollfd; ++i) + { + my_pollfd[i].fd = svc_pollfd[i].fd; + my_pollfd[i].events = svc_pollfd[i].events; + my_pollfd[i].revents = 0; + } + + switch (poll_ret = poll(my_pollfd, svc_max_pollfd, 30 * 1000)) { case -1: /* * We ignore all errors, continuing with the assumption @@ -1133,8 +1119,6 @@ my_svc_run() * other outside event) and not caused by poll(). */ case 0: - cleanfds = svc_fdset; - __svc_clean_idle(&cleanfds, 30, FALSE); continue; default: /* @@ -1144,10 +1128,10 @@ my_svc_run() * don't call svc_getreq_poll. Otherwise, there * must be another so we must call svc_getreq_poll. */ - if ((check_ret = check_rmtcalls(pollfds, nfds)) == + if ((check_ret = check_rmtcalls(my_pollfd, svc_max_pollfd)) == poll_ret) continue; - svc_getreq_poll(pollfds, poll_ret-check_ret); + svc_getreq_poll(my_pollfd, poll_ret-check_ret); } } } @@ -1183,12 +1167,33 @@ check_rmtcalls(struct pollfd *pfds, int nfds) return (ncallbacks_found); } +/* + * This is really a helper function defined in libtirpc, + * but unfortunately, it hasn't been exported yet. + */ +static struct netbuf * +__rpc_set_netbuf(struct netbuf *nb, const void *ptr, size_t len) +{ + if (nb->len != len) { + if (nb->len) + mem_free(nb->buf, nb->len); + nb->buf = mem_alloc(len); + if (nb->buf == NULL) + return NULL; + + nb->maxlen = nb->len = len; + } + memcpy(nb->buf, ptr, len); + return nb; +} + static void xprt_set_caller(SVCXPRT *xprt, struct finfo *fi) { + const struct netbuf *caller = fi->caller_addr; u_int32_t *xidp; - *(svc_getrpccaller(xprt)) = *(fi->caller_addr); + __rpc_set_netbuf(svc_getrpccaller(xprt), caller->buf, caller->len); xidp = __rpcb_get_dg_xidp(xprt); *xidp = fi->caller_xid; } @@ -1274,10 +1279,17 @@ handle_reply(int fd, SVCXPRT *xprt) a.rmt_localvers = fi->versnum; xprt_set_caller(xprt, fi); +#if defined(SVC_XP_AUTH) + SVC_XP_AUTH(xprt) = svc_auth_none; +#else xprt->xp_auth = &svc_auth_none; +#endif svc_sendreply(xprt, (xdrproc_t) xdr_rmtcall_result, (char *) &a); +#if !defined(SVC_XP_AUTH) SVCAUTH_DESTROY(xprt->xp_auth); xprt->xp_auth = NULL; +#endif + done: if (buffer) free(buffer); diff --git a/src/rpcbind.c b/src/rpcbind.c index 045daa1..c4265cd 100644 --- a/src/rpcbind.c +++ b/src/rpcbind.c @@ -87,6 +87,7 @@ static inline void __nss_configure_lookup(const char *db, const char *s) {} int debugging = 0; /* Tell me what's going on */ int doabort = 0; /* When debugging, do an abort on errors */ int dofork = 1; /* fork? */ +int createdsocket = 0; /* Did I create the socket or systemd did it for me? */ rpcblist_ptr list_rbl; /* A list of version 3/4 rpcbind services */ @@ -445,6 +446,7 @@ init_transport(struct netconfig *nconf) memset(&sun, 0, sizeof sun); sun.sun_family = AF_LOCAL; unlink(_PATH_RPCBINDSOCK); + createdsocket = 1; /* We are now in the process of creating the unix socket */ strcpy(sun.sun_path, _PATH_RPCBINDSOCK); addrlen = SUN_LEN(&sun); sa = (struct sockaddr *)&sun; @@ -846,7 +848,8 @@ static void terminate(int dummy /*__unused*/) { close(rpcbindlockfd); - unlink(_PATH_RPCBINDSOCK); + if(createdsocket) + unlink(_PATH_RPCBINDSOCK); unlink(RPCBINDDLOCK); #ifdef WARMSTART write_warmstart(); /* Dump yourself */ diff --git a/src/security.c b/src/security.c index 0c9453f..c54ce26 100644 --- a/src/security.c +++ b/src/security.c @@ -17,6 +17,8 @@ #include #include +#include "xlog.h" + /* * XXX for special case checks in check_callit. */