18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22
23 /*
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27 /*
28 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
29 */
30
31 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
32 /* All Rights Reserved */
33 /*
34 * Portions of this source code were derived from Berkeley
35 * 4.3 BSD under license from the Regents of the University of
36 * California.
37 */
38
39 /*
40 * Implements a connectionless client side RPC.
41 */
42
43 #include "mt.h"
44 #include "rpc_mt.h"
45 #include <assert.h>
46 #include <rpc/rpc.h>
47 #include <errno.h>
48 #include <sys/poll.h>
49 #include <syslog.h>
50 #include <sys/types.h>
51 #include <sys/kstat.h>
52 #include <sys/time.h>
53 #include <stdlib.h>
54 #include <unistd.h>
55 #include <sys/types.h>
56 #include <sys/stat.h>
57 #include <strings.h>
58
59
60 extern int __rpc_timeval_to_msec(struct timeval *);
61 extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
62 extern bool_t __rpc_gss_wrap(AUTH *, char *, uint_t, XDR *, bool_t (*)(),
63 caddr_t);
64 extern bool_t __rpc_gss_unwrap(AUTH *, XDR *, bool_t (*)(), caddr_t);
65
66
67 static struct clnt_ops *clnt_dg_ops(void);
68 static bool_t time_not_ok(struct timeval *);
69
70 /*
71 * This machinery implements per-fd locks for MT-safety. It is not
72 * sufficient to do per-CLIENT handle locks for MT-safety because a
73 * user may create more than one CLIENT handle with the same fd behind
74 * it.
75 *
76 * The current implementation holds locks across the entire RPC and reply,
77 * including retransmissions. Yes, this is silly, and as soon as this
78 * code is proven to work, this should be the first thing fixed. One step
79 * at a time.
665 }
666 outlen = (int)XDR_GETPOS(xdrs);
667
668 tu_data.udata.buf = cu->cu_outbuf_start;
669 tu_data.udata.len = outlen;
670 tu_data.opt.len = 0;
671 if (t_sndudata(cu->cu_fd, &tu_data) == -1) {
672 rpc_callerr.re_terrno = t_errno;
673 rpc_callerr.re_errno = errno;
674 rpc_fd_unlock(dgtbl, cu->cu_fd);
675 return (rpc_callerr.re_status = RPC_CANTSEND);
676 }
677
678 rpc_fd_unlock(dgtbl, cu->cu_fd);
679 return (rpc_callerr.re_status = RPC_SUCCESS);
680 }
681
682 static void
683 clnt_dg_geterr(CLIENT *cl, struct rpc_err *errp)
684 {
685 /* LINTED pointer alignment */
686 struct cu_data *cu = (struct cu_data *)cl->cl_private;
687
688 *errp = rpc_callerr;
689 }
690
691 static bool_t
692 clnt_dg_freeres(CLIENT *cl, xdrproc_t xdr_res, caddr_t res_ptr)
693 {
694 /* LINTED pointer alignment */
695 struct cu_data *cu = (struct cu_data *)cl->cl_private;
696 XDR *xdrs = &(cu->cu_outxdrs);
697 bool_t stat;
698
699 (void) rpc_fd_lock(dgtbl, cu->cu_fd);
700 xdrs->x_op = XDR_FREE;
701 stat = (*xdr_res)(xdrs, res_ptr);
702 rpc_fd_unlock(dgtbl, cu->cu_fd);
703 return (stat);
704 }
705
706 /* ARGSUSED */
707 static void
|
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22
23 /*
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27 /*
28 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
29 */
30
31 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
32 /* All Rights Reserved */
33 /*
34 * Portions of this source code were derived from Berkeley
35 * 4.3 BSD under license from the Regents of the University of
36 * California.
37 */
38 /*
39 * Copyright 2014 Shruti V Sampat <shrutisampat@gmail.com>
40 */
41
42 /*
43 * Implements a connectionless client side RPC.
44 */
45
46 #include "mt.h"
47 #include "rpc_mt.h"
48 #include <assert.h>
49 #include <rpc/rpc.h>
50 #include <errno.h>
51 #include <sys/poll.h>
52 #include <syslog.h>
53 #include <sys/types.h>
54 #include <sys/kstat.h>
55 #include <sys/time.h>
56 #include <stdlib.h>
57 #include <unistd.h>
58 #include <sys/types.h>
59 #include <sys/stat.h>
60 #include <strings.h>
61 #include <note.h>
62
63 extern int __rpc_timeval_to_msec(struct timeval *);
64 extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
65 extern bool_t __rpc_gss_wrap(AUTH *, char *, uint_t, XDR *, bool_t (*)(),
66 caddr_t);
67 extern bool_t __rpc_gss_unwrap(AUTH *, XDR *, bool_t (*)(), caddr_t);
68
69
70 static struct clnt_ops *clnt_dg_ops(void);
71 static bool_t time_not_ok(struct timeval *);
72
73 /*
74 * This machinery implements per-fd locks for MT-safety. It is not
75 * sufficient to do per-CLIENT handle locks for MT-safety because a
76 * user may create more than one CLIENT handle with the same fd behind
77 * it.
78 *
79 * The current implementation holds locks across the entire RPC and reply,
80 * including retransmissions. Yes, this is silly, and as soon as this
81 * code is proven to work, this should be the first thing fixed. One step
82 * at a time.
668 }
669 outlen = (int)XDR_GETPOS(xdrs);
670
671 tu_data.udata.buf = cu->cu_outbuf_start;
672 tu_data.udata.len = outlen;
673 tu_data.opt.len = 0;
674 if (t_sndudata(cu->cu_fd, &tu_data) == -1) {
675 rpc_callerr.re_terrno = t_errno;
676 rpc_callerr.re_errno = errno;
677 rpc_fd_unlock(dgtbl, cu->cu_fd);
678 return (rpc_callerr.re_status = RPC_CANTSEND);
679 }
680
681 rpc_fd_unlock(dgtbl, cu->cu_fd);
682 return (rpc_callerr.re_status = RPC_SUCCESS);
683 }
684
685 static void
686 clnt_dg_geterr(CLIENT *cl, struct rpc_err *errp)
687 {
688 NOTE(ARGUNUSED(cl))
689 *errp = rpc_callerr;
690 }
691
692 static bool_t
693 clnt_dg_freeres(CLIENT *cl, xdrproc_t xdr_res, caddr_t res_ptr)
694 {
695 /* LINTED pointer alignment */
696 struct cu_data *cu = (struct cu_data *)cl->cl_private;
697 XDR *xdrs = &(cu->cu_outxdrs);
698 bool_t stat;
699
700 (void) rpc_fd_lock(dgtbl, cu->cu_fd);
701 xdrs->x_op = XDR_FREE;
702 stat = (*xdr_res)(xdrs, res_ptr);
703 rpc_fd_unlock(dgtbl, cu->cu_fd);
704 return (stat);
705 }
706
707 /* ARGSUSED */
708 static void
|