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 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)); |
88static int __msgread_withcred(int, void *, size_t, struct cmessage *); |
89static int __msgwrite(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 |
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*/ |
418 case 0: 419 goto fatal_err; 420 421 default: 422 break; |
423 } 424 } while ((pollfd.revents & POLLIN) == 0); 425 426 sa = (struct sockaddr *)xprt->xp_rtaddr.buf; 427 if (sa->sa_family == AF_LOCAL) { |
428 cm = (struct cmessage *)xprt->xp_verf.oa_base; 429 if ((len = __msgread_withcred(sock, buf, len, cm)) > 0) { |
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 |
630int 631__msgread_withcred(sock, buf, cnt, cmp) |
632 int sock; 633 void *buf; 634 size_t cnt; |
635 struct cmessage *cmp; |
636{ 637 struct iovec iov[1]; 638 struct msghdr msg; |
639 |
640 bzero(cmp, sizeof(*cmp)); |
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; |
648 msg.msg_control = cmp; |
649 msg.msg_controllen = sizeof(struct cmessage); 650 msg.msg_flags = 0; 651 652 return(_recvmsg(sock, &msg, 0)); 653} |
654 |
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} |