| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
#include <pthread.h> |
| 41 |
#include <reentrant.h> |
| 42 |
#include <rpc/rpc.h> |
| 43 |
#include <sys/types.h> |
| 44 |
#include <rpc/raw.h> |
| 45 |
#include <stdlib.h> |
| 46 |
|
| 47 |
#ifndef UDPMSGSIZE |
| 48 |
#define UDPMSGSIZE 8800 |
| 49 |
#endif |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
static struct svc_raw_private { |
| 55 |
char *raw_buf; |
| 56 |
SVCXPRT server; |
| 57 |
XDR xdr_stream; |
| 58 |
char verf_body[MAX_AUTH_BYTES]; |
| 59 |
} *svc_raw_private; |
| 60 |
|
| 61 |
extern mutex_t svcraw_lock; |
| 62 |
|
| 63 |
static enum xprt_stat svc_raw_stat(SVCXPRT *); |
| 64 |
static bool_t svc_raw_recv(SVCXPRT *, struct rpc_msg *); |
| 65 |
static bool_t svc_raw_reply(SVCXPRT *, struct rpc_msg *); |
| 66 |
static bool_t svc_raw_getargs(SVCXPRT *, xdrproc_t, void *); |
| 67 |
static bool_t svc_raw_freeargs(SVCXPRT *, xdrproc_t, void *); |
| 68 |
static void svc_raw_destroy(SVCXPRT *); |
| 69 |
static void svc_raw_ops(SVCXPRT *); |
| 70 |
static bool_t svc_raw_control(SVCXPRT *, const u_int, void *); |
| 71 |
|
| 72 |
char *__rpc_rawcombuf = NULL; |
| 73 |
|
| 74 |
SVCXPRT * |
| 75 |
svc_raw_create() |
| 76 |
{ |
| 77 |
struct svc_raw_private *srp; |
| 78 |
SVCXPRT_EXT *ext = NULL; |
| 79 |
|
| 80 |
|
| 81 |
mutex_lock(&svcraw_lock); |
| 82 |
srp = svc_raw_private; |
| 83 |
if (srp == NULL) { |
| 84 |
srp = (struct svc_raw_private *)calloc(1, sizeof (*srp)); |
| 85 |
if (srp == NULL) { |
| 86 |
mutex_unlock(&svcraw_lock); |
| 87 |
return (NULL); |
| 88 |
} |
| 89 |
ext = mem_alloc(sizeof (*ext)); |
| 90 |
if (ext == NULL) { |
| 91 |
free(srp); |
| 92 |
mutex_unlock(&svcraw_lock); |
| 93 |
return (NULL); |
| 94 |
} |
| 95 |
memset(ext, 0, sizeof (*ext)); |
| 96 |
srp->server.xp_p3 = ext; |
| 97 |
if (__rpc_rawcombuf == NULL) |
| 98 |
__rpc_rawcombuf = calloc(UDPMSGSIZE, sizeof (char)); |
| 99 |
srp->raw_buf = __rpc_rawcombuf; |
| 100 |
svc_raw_private = srp; |
| 101 |
} |
| 102 |
srp->server.xp_fd = FD_SETSIZE; |
| 103 |
srp->server.xp_port = 0; |
| 104 |
svc_flags(&srp->server) = 0; |
| 105 |
svc_raw_ops(&srp->server); |
| 106 |
srp->server.xp_verf.oa_base = srp->verf_body; |
| 107 |
xdrmem_create(&srp->xdr_stream, srp->raw_buf, UDPMSGSIZE, XDR_DECODE); |
| 108 |
xprt_register(&srp->server); |
| 109 |
mutex_unlock(&svcraw_lock); |
| 110 |
return (&srp->server); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
static enum xprt_stat |
| 115 |
svc_raw_stat(xprt) |
| 116 |
SVCXPRT *xprt; |
| 117 |
{ |
| 118 |
return (XPRT_IDLE); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
static bool_t |
| 123 |
svc_raw_recv(xprt, msg) |
| 124 |
SVCXPRT *xprt; |
| 125 |
struct rpc_msg *msg; |
| 126 |
{ |
| 127 |
struct svc_raw_private *srp; |
| 128 |
XDR *xdrs; |
| 129 |
|
| 130 |
mutex_lock(&svcraw_lock); |
| 131 |
srp = svc_raw_private; |
| 132 |
if (srp == NULL) { |
| 133 |
mutex_unlock(&svcraw_lock); |
| 134 |
return (FALSE); |
| 135 |
} |
| 136 |
mutex_unlock(&svcraw_lock); |
| 137 |
|
| 138 |
xdrs = &srp->xdr_stream; |
| 139 |
xdrs->x_op = XDR_DECODE; |
| 140 |
(void) XDR_SETPOS(xdrs, 0); |
| 141 |
if (! xdr_callmsg(xdrs, msg)) { |
| 142 |
return (FALSE); |
| 143 |
} |
| 144 |
return (TRUE); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
static bool_t |
| 149 |
svc_raw_reply(xprt, msg) |
| 150 |
SVCXPRT *xprt; |
| 151 |
struct rpc_msg *msg; |
| 152 |
{ |
| 153 |
struct svc_raw_private *srp; |
| 154 |
XDR *xdrs; |
| 155 |
|
| 156 |
mutex_lock(&svcraw_lock); |
| 157 |
srp = svc_raw_private; |
| 158 |
if (srp == NULL) { |
| 159 |
mutex_unlock(&svcraw_lock); |
| 160 |
return (FALSE); |
| 161 |
} |
| 162 |
mutex_unlock(&svcraw_lock); |
| 163 |
|
| 164 |
xdrs = &srp->xdr_stream; |
| 165 |
xdrs->x_op = XDR_ENCODE; |
| 166 |
(void) XDR_SETPOS(xdrs, 0); |
| 167 |
if (! xdr_replymsg(xdrs, msg)) { |
| 168 |
return (FALSE); |
| 169 |
} |
| 170 |
(void) XDR_GETPOS(xdrs); |
| 171 |
return (TRUE); |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
static bool_t |
| 176 |
svc_raw_getargs(xprt, xdr_args, args_ptr) |
| 177 |
SVCXPRT *xprt; |
| 178 |
xdrproc_t xdr_args; |
| 179 |
void *args_ptr; |
| 180 |
{ |
| 181 |
struct svc_raw_private *srp; |
| 182 |
|
| 183 |
mutex_lock(&svcraw_lock); |
| 184 |
srp = svc_raw_private; |
| 185 |
if (srp == NULL) { |
| 186 |
mutex_unlock(&svcraw_lock); |
| 187 |
return (FALSE); |
| 188 |
} |
| 189 |
mutex_unlock(&svcraw_lock); |
| 190 |
return (*xdr_args)(&srp->xdr_stream, args_ptr); |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
static bool_t |
| 195 |
svc_raw_freeargs(xprt, xdr_args, args_ptr) |
| 196 |
SVCXPRT *xprt; |
| 197 |
xdrproc_t xdr_args; |
| 198 |
void *args_ptr; |
| 199 |
{ |
| 200 |
struct svc_raw_private *srp; |
| 201 |
XDR *xdrs; |
| 202 |
|
| 203 |
mutex_lock(&svcraw_lock); |
| 204 |
srp = svc_raw_private; |
| 205 |
if (srp == NULL) { |
| 206 |
mutex_unlock(&svcraw_lock); |
| 207 |
return (FALSE); |
| 208 |
} |
| 209 |
mutex_unlock(&svcraw_lock); |
| 210 |
|
| 211 |
xdrs = &srp->xdr_stream; |
| 212 |
xdrs->x_op = XDR_FREE; |
| 213 |
return (*xdr_args)(xdrs, args_ptr); |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
static void |
| 218 |
svc_raw_destroy(xprt) |
| 219 |
SVCXPRT *xprt; |
| 220 |
{ |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
static bool_t |
| 225 |
svc_raw_control(xprt, rq, in) |
| 226 |
SVCXPRT *xprt; |
| 227 |
const u_int rq; |
| 228 |
void *in; |
| 229 |
{ |
| 230 |
return (FALSE); |
| 231 |
} |
| 232 |
|
| 233 |
static void |
| 234 |
svc_raw_ops(xprt) |
| 235 |
SVCXPRT *xprt; |
| 236 |
{ |
| 237 |
static struct xp_ops ops; |
| 238 |
static struct xp_ops2 ops2; |
| 239 |
extern mutex_t ops_lock; |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
mutex_lock(&ops_lock); |
| 244 |
if (ops.xp_recv == NULL) { |
| 245 |
ops.xp_recv = svc_raw_recv; |
| 246 |
ops.xp_stat = svc_raw_stat; |
| 247 |
ops.xp_getargs = svc_raw_getargs; |
| 248 |
ops.xp_reply = svc_raw_reply; |
| 249 |
ops.xp_freeargs = svc_raw_freeargs; |
| 250 |
ops.xp_destroy = svc_raw_destroy; |
| 251 |
ops2.xp_control = svc_raw_control; |
| 252 |
} |
| 253 |
xprt->xp_ops = &ops; |
| 254 |
xprt->xp_ops2 = &ops2; |
| 255 |
mutex_unlock(&ops_lock); |
| 256 |
} |