svc_vc.c (74536) | svc_vc.c (74627) |
---|---|
1/* $NetBSD: svc_vc.c,v 1.7 2000/08/03 00:01:53 fvdl Exp $ */ | 1/* $NetBSD: svc_vc.c,v 1.7 2000/08/03 00:01:53 fvdl Exp $ */ |
2/* $FreeBSD: head/lib/libc/rpc/svc_vc.c 74536 2001-03-20 20:28:09Z alfred $ */ | 2/* $FreeBSD: head/lib/libc/rpc/svc_vc.c 74627 2001-03-22 04:31:30Z alfred $ */ |
3 4/* 5 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 6 * unrestricted use provided that this legend is included on all tape 7 * media and as a part of the software program in whole or part. Users 8 * may copy or modify Sun RPC without charge, but are not authorized 9 * to license or distribute it to anyone else except as part of a product or 10 * program developed by the user. --- 69 unchanged lines hidden (view full) --- 80static enum xprt_stat svc_vc_stat __P((SVCXPRT *)); 81static bool_t svc_vc_recv __P((SVCXPRT *, struct rpc_msg *)); 82static bool_t svc_vc_getargs __P((SVCXPRT *, xdrproc_t, caddr_t)); 83static bool_t svc_vc_freeargs __P((SVCXPRT *, xdrproc_t, caddr_t)); 84static bool_t svc_vc_reply __P((SVCXPRT *, struct rpc_msg *)); 85static void svc_vc_rendezvous_ops __P((SVCXPRT *)); 86static void svc_vc_ops __P((SVCXPRT *)); 87static bool_t svc_vc_control __P((SVCXPRT *xprt, const u_int rq, void *in)); | 3 4/* 5 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 6 * unrestricted use provided that this legend is included on all tape 7 * media and as a part of the software program in whole or part. Users 8 * may copy or modify Sun RPC without charge, but are not authorized 9 * to license or distribute it to anyone else except as part of a product or 10 * program developed by the user. --- 69 unchanged lines hidden (view full) --- 80static enum xprt_stat svc_vc_stat __P((SVCXPRT *)); 81static bool_t svc_vc_recv __P((SVCXPRT *, struct rpc_msg *)); 82static bool_t svc_vc_getargs __P((SVCXPRT *, xdrproc_t, caddr_t)); 83static bool_t svc_vc_freeargs __P((SVCXPRT *, xdrproc_t, caddr_t)); 84static bool_t svc_vc_reply __P((SVCXPRT *, struct rpc_msg *)); 85static void svc_vc_rendezvous_ops __P((SVCXPRT *)); 86static void svc_vc_ops __P((SVCXPRT *)); 87static bool_t svc_vc_control __P((SVCXPRT *xprt, const u_int rq, void *in)); |
88static int __msgread_withcred(int, void *, size_t, struct cmessage *); |
|
88static int __msgwrite(int, void *, size_t); | 89static int __msgwrite(int, void *, size_t); |
89static int __msgread(int, void *, size_t); | |
90 91struct cf_rendezvous { /* kept in xprt->xp_p1 for rendezvouser */ 92 u_int sendsize; 93 u_int recvsize; 94}; 95 96struct cf_conn { /* kept in xprt->xp_p1 for actual connection */ 97 enum xprt_stat strm_stat; 98 u_int32_t x_id; 99 XDR xdrs; 100 char verf_body[MAX_AUTH_BYTES]; 101}; 102 | 90 91struct cf_rendezvous { /* kept in xprt->xp_p1 for rendezvouser */ 92 u_int sendsize; 93 u_int recvsize; 94}; 95 96struct cf_conn { /* kept in xprt->xp_p1 for actual connection */ 97 enum xprt_stat strm_stat; 98 u_int32_t x_id; 99 XDR xdrs; 100 char verf_body[MAX_AUTH_BYTES]; 101}; 102 |
103struct cmessage { 104 struct cmsghdr cmsg; 105 struct cmsgcred cmcred; 106}; 107 108 | |
109/* 110 * Usage: 111 * xprt = svc_vc_create(sock, send_buf_size, recv_buf_size); 112 * 113 * Creates, registers, and returns a (rpc) tcp based transporter. 114 * Once *xprt is initialized, it is registered as a transporter 115 * see (svc.h, xprt_register). This routine returns 116 * a NULL if a problem occurred. --- 299 unchanged lines hidden (view full) --- 416 pollfd.fd = sock; 417 pollfd.events = POLLIN; 418 pollfd.revents = 0; 419 switch (_poll(&pollfd, 1, milliseconds)) { 420 case -1: 421 if (errno == EINTR) 422 continue; 423 /*FALLTHROUGH*/ | 103/* 104 * Usage: 105 * xprt = svc_vc_create(sock, send_buf_size, recv_buf_size); 106 * 107 * Creates, registers, and returns a (rpc) tcp based transporter. 108 * Once *xprt is initialized, it is registered as a transporter 109 * see (svc.h, xprt_register). This routine returns 110 * a NULL if a problem occurred. --- 299 unchanged lines hidden (view full) --- 410 pollfd.fd = sock; 411 pollfd.events = POLLIN; 412 pollfd.revents = 0; 413 switch (_poll(&pollfd, 1, milliseconds)) { 414 case -1: 415 if (errno == EINTR) 416 continue; 417 /*FALLTHROUGH*/ |
424 case 0: 425 goto fatal_err; 426 default: 427 break; | 418 case 0: 419 goto fatal_err; 420 421 default: 422 break; |
428 } 429 } while ((pollfd.revents & POLLIN) == 0); 430 431 sa = (struct sockaddr *)xprt->xp_rtaddr.buf; 432 if (sa->sa_family == AF_LOCAL) { | 423 } 424 } while ((pollfd.revents & POLLIN) == 0); 425 426 sa = (struct sockaddr *)xprt->xp_rtaddr.buf; 427 if (sa->sa_family == AF_LOCAL) { |
433 if ((len = __msgread(sock, buf, len)) > 0) { 434 cm = (struct cmessage *)xprt->xp_verf.oa_base; | 428 cm = (struct cmessage *)xprt->xp_verf.oa_base; 429 if ((len = __msgread_withcred(sock, buf, len, cm)) > 0) { |
435 cmp = &cm->cmsg; 436 sc = (struct sockcred *)(void *)CMSG_DATA(cmp); 437 xprt->xp_p2 = sc; 438 return (len); 439 } 440 } else { 441 if ((len = _read(sock, buf, (size_t)len)) > 0) 442 return (len); --- 184 unchanged lines hidden (view full) --- 627 ops.xp_destroy = svc_vc_destroy; 628 ops2.xp_control = svc_vc_control; 629 } 630 xprt->xp_ops = &ops; 631 xprt->xp_ops2 = &ops2; 632 mutex_unlock(&ops_lock); 633} 634 | 430 cmp = &cm->cmsg; 431 sc = (struct sockcred *)(void *)CMSG_DATA(cmp); 432 xprt->xp_p2 = sc; 433 return (len); 434 } 435 } else { 436 if ((len = _read(sock, buf, (size_t)len)) > 0) 437 return (len); --- 184 unchanged lines hidden (view full) --- 622 ops.xp_destroy = svc_vc_destroy; 623 ops2.xp_control = svc_vc_control; 624 } 625 xprt->xp_ops = &ops; 626 xprt->xp_ops2 = &ops2; 627 mutex_unlock(&ops_lock); 628} 629 |
635static int 636__msgread(sock, buf, cnt) | 630int 631__msgread_withcred(sock, buf, cnt, cmp) |
637 int sock; 638 void *buf; 639 size_t cnt; | 632 int sock; 633 void *buf; 634 size_t cnt; |
635 struct cmessage *cmp; |
|
640{ 641 struct iovec iov[1]; 642 struct msghdr msg; | 636{ 637 struct iovec iov[1]; 638 struct msghdr msg; |
643 struct cmessage cm; | |
644 | 639 |
645 bzero((char *)&cm, sizeof(cm)); | 640 bzero(cmp, sizeof(*cmp)); |
646 iov[0].iov_base = buf; 647 iov[0].iov_len = cnt; 648 649 msg.msg_iov = iov; 650 msg.msg_iovlen = 1; 651 msg.msg_name = NULL; 652 msg.msg_namelen = 0; | 641 iov[0].iov_base = buf; 642 iov[0].iov_len = cnt; 643 644 msg.msg_iov = iov; 645 msg.msg_iovlen = 1; 646 msg.msg_name = NULL; 647 msg.msg_namelen = 0; |
653 msg.msg_control = (caddr_t)&cm; | 648 msg.msg_control = cmp; |
654 msg.msg_controllen = sizeof(struct cmessage); 655 msg.msg_flags = 0; 656 657 return(_recvmsg(sock, &msg, 0)); 658} | 649 msg.msg_controllen = sizeof(struct cmessage); 650 msg.msg_flags = 0; 651 652 return(_recvmsg(sock, &msg, 0)); 653} |
659 | 654 |
660static int 661__msgwrite(sock, buf, cnt) 662 int sock; 663 void *buf; 664 size_t cnt; 665{ 666 struct iovec iov[1]; 667 struct msghdr msg; --- 12 unchanged lines hidden (view full) --- 680 msg.msg_name = NULL; 681 msg.msg_namelen = 0; 682 msg.msg_control = (caddr_t)&cm; 683 msg.msg_controllen = sizeof(struct cmessage); 684 msg.msg_flags = 0; 685 686 return(_sendmsg(sock, &msg, 0)); 687} | 655static int 656__msgwrite(sock, buf, cnt) 657 int sock; 658 void *buf; 659 size_t cnt; 660{ 661 struct iovec iov[1]; 662 struct msghdr msg; --- 12 unchanged lines hidden (view full) --- 675 msg.msg_name = NULL; 676 msg.msg_namelen = 0; 677 msg.msg_control = (caddr_t)&cm; 678 msg.msg_controllen = sizeof(struct cmessage); 679 msg.msg_flags = 0; 680 681 return(_sendmsg(sock, &msg, 0)); 682} |
683 684/* 685 * Get the effective UID of the sending process. Used by rpcbind and keyserv 686 * (AF_LOCAL). 687 */ 688int 689__rpc_get_local_uid(SVCXPRT *transp, uid_t *uid) 690{ 691 struct cmsgcred *cmcred; 692 693 cmcred = __svc_getcallercreds(transp); 694 if (cmcred == NULL) 695 return(-1); 696 *uid = cmcred->cmcred_euid; 697 return(0); 698} |
|