Deleted Added
sdiff udiff text old ( 115394 ) new ( 116391 )
full compact
1/* $NetBSD: svc_vc.c,v 1.7 2000/08/03 00:01:53 fvdl Exp $ */
2
3/*
4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5 * unrestricted use provided that this legend is included on all tape
6 * media and as a part of the software program in whole or part. Users
7 * may copy or modify Sun RPC without charge, but are not authorized
8 * to license or distribute it to anyone else except as part of a product or

--- 20 unchanged lines hidden (view full) ---

29 * Mountain View, California 94043
30 */
31
32#if defined(LIBC_SCCS) && !defined(lint)
33static char *sccsid = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro";
34static char *sccsid = "@(#)svc_tcp.c 2.2 88/08/01 4.0 RPCSRC";
35#endif
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/lib/libc/rpc/svc_vc.c 116391 2003-06-15 10:32:01Z mbr $");
38
39/*
40 * svc_vc.c, Server side for Connection Oriented based RPC.
41 *
42 * Actually implements two flavors of transporter -
43 * a tcp rendezvouser (a listner and connection establisher)
44 * and a record/tcp stream.
45 */

--- 19 unchanged lines hidden (view full) ---

65#include <string.h>
66#include <unistd.h>
67
68#include <rpc/rpc.h>
69
70#include "rpc_com.h"
71#include "un-namespace.h"
72
73extern rwlock_t svc_fd_lock;
74
75static SVCXPRT *makefd_xprt(int, u_int, u_int);
76static bool_t rendezvous_request(SVCXPRT *, struct rpc_msg *);
77static enum xprt_stat rendezvous_stat(SVCXPRT *);
78static void svc_vc_destroy(SVCXPRT *);
79static void __svc_vc_dodestroy (SVCXPRT *);
80static int read_vc(void *, void *, int);
81static int write_vc(void *, void *, int);
82static enum xprt_stat svc_vc_stat(SVCXPRT *);
83static bool_t svc_vc_recv(SVCXPRT *, struct rpc_msg *);
84static bool_t svc_vc_getargs(SVCXPRT *, xdrproc_t, void *);
85static bool_t svc_vc_freeargs(SVCXPRT *, xdrproc_t, void *);
86static bool_t svc_vc_reply(SVCXPRT *, struct rpc_msg *);
87static void svc_vc_rendezvous_ops(SVCXPRT *);
88static void svc_vc_ops(SVCXPRT *);
89static bool_t svc_vc_control(SVCXPRT *xprt, const u_int rq, void *in);
90static bool_t svc_vc_rendezvous_control (SVCXPRT *xprt, const u_int rq,
91 void *in);
92static int __msgwrite(int, void *, size_t);
93
94struct cf_rendezvous { /* kept in xprt->xp_p1 for rendezvouser */
95 u_int sendsize;
96 u_int recvsize;
97 int maxrec;
98};
99

--- 365 unchanged lines hidden (view full) ---

465 void *xprtp;
466 void *buf;
467 int len;
468{
469 SVCXPRT *xprt;
470 int sock;
471 int milliseconds = 35 * 1000;
472 struct pollfd pollfd;
473 struct cf_conn *cfp;
474
475 xprt = (SVCXPRT *)xprtp;
476 assert(xprt != NULL);
477
478 sock = xprt->xp_fd;
479
480 cfp = (struct cf_conn *)xprt->xp_p1;
481
482 if (cfp->nonblock) {
483 len = _read(sock, buf, (size_t)len);
484 if (len < 0) {
485 if (errno == EAGAIN)
486 len = 0;
487 else
488 goto fatal_err;
489 }
490 if (len != 0)
491 gettimeofday(&cfp->last_recv_time, NULL);

--- 12 unchanged lines hidden (view full) ---

504 case 0:
505 goto fatal_err;
506
507 default:
508 break;
509 }
510 } while ((pollfd.revents & POLLIN) == 0);
511
512 if ((len = _read(sock, buf, (size_t)len)) > 0) {
513 gettimeofday(&cfp->last_recv_time, NULL);
514 return (len);
515 }
516
517fatal_err:
518 ((struct cf_conn *)(xprt->xp_p1))->strm_stat = XPRT_DIED;
519 return (-1);
520}
521
522/*
523 * writes data to the tcp connection.
524 * Any error is fatal and the connection is closed.
525 */
526static int
527write_vc(xprtp, buf, len)
528 void *xprtp;
529 void *buf;
530 int len;
531{
532 SVCXPRT *xprt;
533 int i, cnt;
534 struct cf_conn *cd;
535 struct timeval tv0, tv1;
536
537 xprt = (SVCXPRT *)xprtp;
538 assert(xprt != NULL);
539
540 cd = (struct cf_conn *)xprt->xp_p1;
541
542 if (cd->nonblock)
543 gettimeofday(&tv0, NULL);
544
545 for (cnt = len; cnt > 0; cnt -= i, buf += i) {
546 i = _write(xprt->xp_fd, buf, (size_t)cnt);
547 if (i < 0) {
548 if (errno != EAGAIN || !cd->nonblock) {
549 cd->strm_stat = XPRT_DIED;
550 return (-1);
551 }
552 if (cd->nonblock && i != cnt) {
553 /*
554 * For non-blocking connections, do not

--- 158 unchanged lines hidden (view full) ---

713 ops.xp_destroy = svc_vc_destroy;
714 ops2.xp_control = svc_vc_rendezvous_control;
715 }
716 xprt->xp_ops = &ops;
717 xprt->xp_ops2 = &ops2;
718 mutex_unlock(&ops_lock);
719}
720
721/*
722 * Get the effective UID of the sending process. Used by rpcbind, keyserv
723 * and rpc.yppasswdd on AF_LOCAL.
724 */
725int
726__rpc_get_local_uid(SVCXPRT *transp, uid_t *uid) {
727 int sock, ret;
728 gid_t egid;
729 uid_t euid;
730 struct sockaddr *sa;
731
732 sock = transp->xp_fd;
733 sa = (struct sockaddr *)transp->xp_rtaddr.buf;
734 if (sa->sa_family == AF_LOCAL) {
735 ret = getpeereid(sock, &euid, &egid);
736 if (ret == 0)
737 *uid = euid;
738 return (ret);
739 } else
740 return (-1);
741}
742
743/*
744 * Destroy xprts that have not have had any activity in 'timeout' seconds.
745 * If 'cleanblock' is true, blocking connections (the default) are also
746 * cleaned. If timeout is 0, the least active connection is picked.
747 */
748bool_t

--- 43 unchanged lines hidden ---