-: 0:Source:clnt_raw.c -: 0:Graph:/var/tsitkova/Sources/v10/trunk/src/lib/rpc/clnt_raw.so.gcno -: 0:Data:/var/tsitkova/Sources/v10/trunk/src/lib/rpc/clnt_raw.so.gcda -: 0:Runs:959 -: 0:Programs:1 -: 1:/* @(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC */ -: 2:/* -: 3: * Copyright (c) 2010, Oracle America, Inc. -: 4: * -: 5: * All rights reserved. -: 6: * -: 7: * Redistribution and use in source and binary forms, with or without -: 8: * modification, are permitted provided that the following conditions are met: -: 9: * -: 10: * * Redistributions of source code must retain the above copyright -: 11: * notice, this list of conditions and the following disclaimer. -: 12: * -: 13: * * Redistributions in binary form must reproduce the above copyright -: 14: * notice, this list of conditions and the following disclaimer in -: 15: * the documentation and/or other materials provided with the -: 16: * distribution. -: 17: * -: 18: * * Neither the name of the "Oracle America, Inc." nor the names of -: 19: * its contributors may be used to endorse or promote products -: 20: * derived from this software without specific prior written permission. -: 21: * -: 22: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -: 23: * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -: 24: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -: 25: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -: 26: * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -: 27: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -: 28: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -: 29: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -: 30: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -: 31: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -: 32: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -: 33: */ -: 34:#if !defined(lint) && defined(SCCSIDS) -: 35:static char sccsid[] = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro"; -: 36:#endif -: 37: -: 38:/* -: 39: * clnt_raw.c -: 40: * -: 41: * Memory based rpc for simple testing and timing. -: 42: * Interface to create an rpc client and server in the same process. -: 43: * This lets us similate rpc and get round trip overhead, without -: 44: * any interference from the kernal. -: 45: */ -: 46: -: 47:#include -: 48: -: 49:#define MCALL_MSG_SIZE 24 -: 50: -: 51:/* -: 52: * This is the "network" we will be moving stuff over. -: 53: */ -: 54:static struct clntraw_private { -: 55: CLIENT client_object; -: 56: XDR xdr_stream; -: 57: char _raw_buf[UDPMSGSIZE]; -: 58: union { -: 59: struct rpc_msg mashl_rpcmsg; -: 60: char mashl_callmsg[MCALL_MSG_SIZE]; -: 61: } u; -: 62: u_int mcnt; -: 63:} *clntraw_private; -: 64: -: 65:static enum clnt_stat clntraw_call(CLIENT *, rpcproc_t, xdrproc_t, -: 66: void *, xdrproc_t, void *, -: 67: struct timeval); -: 68:static void clntraw_abort(CLIENT *); -: 69:static void clntraw_geterr(CLIENT *, struct rpc_err *); -: 70:static bool_t clntraw_freeres(CLIENT *, xdrproc_t, void *); -: 71:static bool_t clntraw_control(CLIENT *, int, void *); -: 72:static void clntraw_destroy(CLIENT *); -: 73: -: 74:static struct clnt_ops client_ops = { -: 75: clntraw_call, -: 76: clntraw_abort, -: 77: clntraw_geterr, -: 78: clntraw_freeres, -: 79: clntraw_destroy, -: 80: clntraw_control -: 81:}; -: 82: -: 83:void svc_getreq(); -: 84: -: 85:/* -: 86: * Create a client handle for memory based rpc. -: 87: */ -: 88:CLIENT * #####: 89:clntraw_create( -: 90: rpcprog_t prog, -: 91: rpcvers_t vers) -: 92:{ #####: 93: register struct clntraw_private *clp = clntraw_private; -: 94: struct rpc_msg call_msg; #####: 95: XDR *xdrs = &clp->xdr_stream; #####: 96: CLIENT *client = &clp->client_object; -: 97: #####: 98: if (clp == 0) { #####: 99: clp = (struct clntraw_private *)calloc(1, sizeof (*clp)); #####: 100: if (clp == 0) #####: 101: return (0); #####: 102: clntraw_private = clp; -: 103: } -: 104: /* -: 105: * pre-serialize the staic part of the call msg and stash it away -: 106: */ #####: 107: call_msg.rm_direction = CALL; #####: 108: call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION; #####: 109: call_msg.rm_call.cb_prog = prog; #####: 110: call_msg.rm_call.cb_vers = vers; #####: 111: xdrmem_create(xdrs, clp->u.mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE); #####: 112: if (! xdr_callhdr(xdrs, &call_msg)) { #####: 113: perror("clnt_raw.c - Fatal header serialization error."); -: 114: } #####: 115: clp->mcnt = XDR_GETPOS(xdrs); #####: 116: XDR_DESTROY(xdrs); -: 117: -: 118: /* -: 119: * Set xdrmem for client/server shared buffer -: 120: */ #####: 121: xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE); -: 122: -: 123: /* -: 124: * create client handle -: 125: */ #####: 126: client->cl_ops = &client_ops; #####: 127: client->cl_auth = authnone_create(); #####: 128: return (client); -: 129:} -: 130: -: 131:static enum clnt_stat #####: 132:clntraw_call( -: 133: CLIENT *h, -: 134: rpcproc_t proc, -: 135: xdrproc_t xargs, -: 136: void * argsp, -: 137: xdrproc_t xresults, -: 138: void * resultsp, -: 139: struct timeval timeout) -: 140:{ #####: 141: register struct clntraw_private *clp = clntraw_private; #####: 142: register XDR *xdrs = &clp->xdr_stream; -: 143: struct rpc_msg msg; -: 144: enum clnt_stat status; -: 145: struct rpc_err error; #####: 146: long procl = proc; -: 147: #####: 148: if (clp == 0) #####: 149: return (RPC_FAILED); -: 150:call_again: -: 151: /* -: 152: * send request -: 153: */ #####: 154: xdrs->x_op = XDR_ENCODE; #####: 155: XDR_SETPOS(xdrs, 0); #####: 156: clp->u.mashl_rpcmsg.rm_xid ++ ; #####: 157: if ((! XDR_PUTBYTES(xdrs, clp->u.mashl_callmsg, clp->mcnt)) || #####: 158: (! XDR_PUTLONG(xdrs, &procl)) || #####: 159: (! AUTH_MARSHALL(h->cl_auth, xdrs)) || #####: 160: (! (*xargs)(xdrs, argsp))) { #####: 161: return (RPC_CANTENCODEARGS); -: 162: } #####: 163: (void)XDR_GETPOS(xdrs); /* called just to cause overhead */ -: 164: -: 165: /* -: 166: * We have to call server input routine here because this is -: 167: * all going on in one process. Yuk. -: 168: */ #####: 169: svc_getreq(1); -: 170: -: 171: /* -: 172: * get results -: 173: */ #####: 174: xdrs->x_op = XDR_DECODE; #####: 175: XDR_SETPOS(xdrs, 0); #####: 176: msg.acpted_rply.ar_verf = gssrpc__null_auth; #####: 177: msg.acpted_rply.ar_results.where = resultsp; #####: 178: msg.acpted_rply.ar_results.proc = xresults; #####: 179: if (! xdr_replymsg(xdrs, &msg)) { -: 180: /* -: 181: * It's possible for xdr_replymsg() to fail partway -: 182: * through its attempt to decode the result from the -: 183: * server. If this happens, it will leave the reply -: 184: * structure partially populated with dynamically -: 185: * allocated memory. (This can happen if someone uses -: 186: * clntudp_bufcreate() to create a CLIENT handle and -: 187: * specifies a receive buffer size that is too small.) -: 188: * This memory must be free()ed to avoid a leak. -: 189: */ #####: 190: enum xdr_op op = xdrs->x_op; #####: 191: xdrs->x_op = XDR_FREE; #####: 192: xdr_replymsg(xdrs, &msg); #####: 193: xdrs->x_op = op; #####: 194: return (RPC_CANTDECODERES); -: 195: } #####: 196: gssrpc__seterr_reply(&msg, &error); #####: 197: status = error.re_status; -: 198: #####: 199: if (status == RPC_SUCCESS) { #####: 200: if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) { #####: 201: status = RPC_AUTHERROR; -: 202: } -: 203: } /* end successful completion */ -: 204: else { #####: 205: if (AUTH_REFRESH(h->cl_auth, &msg)) #####: 206: goto call_again; -: 207: } /* end of unsuccessful completion */ -: 208: #####: 209: if (status == RPC_SUCCESS) { #####: 210: if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) { #####: 211: status = RPC_AUTHERROR; -: 212: } #####: 213: if (msg.acpted_rply.ar_verf.oa_base != NULL) { #####: 214: xdrs->x_op = XDR_FREE; #####: 215: (void)xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf)); -: 216: } -: 217: } -: 218: #####: 219: return (status); -: 220:} -: 221: -: 222:/*ARGSUSED*/ -: 223:static void #####: 224:clntraw_geterr( -: 225: CLIENT *cl, -: 226: struct rpc_err *err) -: 227:{ #####: 228:} -: 229: -: 230: -: 231:static bool_t #####: 232:clntraw_freeres( -: 233: CLIENT *cl, -: 234: xdrproc_t xdr_res, -: 235: void *res_ptr) -: 236:{ #####: 237: register struct clntraw_private *clp = clntraw_private; #####: 238: register XDR *xdrs = &clp->xdr_stream; -: 239: bool_t rval; -: 240: #####: 241: if (clp == 0) -: 242: { #####: 243: rval = (bool_t) RPC_FAILED; #####: 244: return (rval); -: 245: } #####: 246: xdrs->x_op = XDR_FREE; #####: 247: return ((*xdr_res)(xdrs, res_ptr)); -: 248:} -: 249: -: 250:/*ARGSUSED*/ -: 251:static void #####: 252:clntraw_abort(CLIENT *cl) -: 253:{ #####: 254:} -: 255: -: 256:/*ARGSUSED*/ -: 257:static bool_t #####: 258:clntraw_control( -: 259: CLIENT *cl, -: 260: int request, -: 261: void *info) -: 262:{ #####: 263: return (FALSE); -: 264:} -: 265: -: 266:/*ARGSUSED*/ -: 267:static void #####: 268:clntraw_destroy(CLIENT *cl) -: 269:{ #####: 270:}