| 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 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
#include <pthread.h> |
| 46 |
#include <reentrant.h> |
| 47 |
#include <assert.h> |
| 48 |
#include <stdlib.h> |
| 49 |
#include <rpc/types.h> |
| 50 |
#include <rpc/xdr.h> |
| 51 |
#include <rpc/auth.h> |
| 52 |
|
| 53 |
#define MAX_MARSHAL_SIZE 20 |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
static bool_t authnone_marshal (AUTH *, XDR *); |
| 60 |
static void authnone_verf (AUTH *); |
| 61 |
static bool_t authnone_validate (AUTH *, struct opaque_auth *); |
| 62 |
static bool_t authnone_refresh (AUTH *, void *); |
| 63 |
static void authnone_destroy (AUTH *); |
| 64 |
|
| 65 |
extern bool_t xdr_opaque_auth(); |
| 66 |
|
| 67 |
static struct auth_ops *authnone_ops(); |
| 68 |
|
| 69 |
static struct authnone_private { |
| 70 |
AUTH no_client; |
| 71 |
char marshalled_client[MAX_MARSHAL_SIZE]; |
| 72 |
u_int mcnt; |
| 73 |
} *authnone_private; |
| 74 |
|
| 75 |
AUTH * |
| 76 |
authnone_create() |
| 77 |
{ |
| 78 |
struct authnone_private *ap = authnone_private; |
| 79 |
XDR xdr_stream; |
| 80 |
XDR *xdrs; |
| 81 |
extern mutex_t authnone_lock; |
| 82 |
|
| 83 |
mutex_lock(&authnone_lock); |
| 84 |
if (ap == 0) { |
| 85 |
ap = (struct authnone_private *)calloc(1, sizeof (*ap)); |
| 86 |
if (ap == 0) { |
| 87 |
mutex_unlock(&authnone_lock); |
| 88 |
return (0); |
| 89 |
} |
| 90 |
authnone_private = ap; |
| 91 |
} |
| 92 |
if (!ap->mcnt) { |
| 93 |
ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth; |
| 94 |
ap->no_client.ah_ops = authnone_ops(); |
| 95 |
xdrs = &xdr_stream; |
| 96 |
xdrmem_create(xdrs, ap->marshalled_client, |
| 97 |
(u_int)MAX_MARSHAL_SIZE, XDR_ENCODE); |
| 98 |
(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred); |
| 99 |
(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf); |
| 100 |
ap->mcnt = XDR_GETPOS(xdrs); |
| 101 |
XDR_DESTROY(xdrs); |
| 102 |
} |
| 103 |
mutex_unlock(&authnone_lock); |
| 104 |
return (&ap->no_client); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
static bool_t |
| 109 |
authnone_marshal(AUTH *client, XDR *xdrs) |
| 110 |
{ |
| 111 |
struct authnone_private *ap; |
| 112 |
bool_t rv = FALSE; |
| 113 |
extern mutex_t authnone_lock; |
| 114 |
|
| 115 |
assert(xdrs != NULL); |
| 116 |
|
| 117 |
mutex_lock(&authnone_lock); |
| 118 |
ap = authnone_private; |
| 119 |
if (ap) { |
| 120 |
rv = (*xdrs->x_ops->x_putbytes)(xdrs, ap->marshalled_client, |
| 121 |
ap->mcnt); |
| 122 |
} |
| 123 |
mutex_unlock(&authnone_lock); |
| 124 |
return (rv); |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
static void |
| 130 |
authnone_verf(AUTH *client) |
| 131 |
{ |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
static bool_t |
| 136 |
authnone_validate(AUTH *client, struct opaque_auth *opaque) |
| 137 |
{ |
| 138 |
|
| 139 |
return (TRUE); |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
static bool_t |
| 144 |
authnone_refresh(AUTH *client, void *dummy) |
| 145 |
{ |
| 146 |
|
| 147 |
return (FALSE); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
static void |
| 152 |
authnone_destroy(AUTH *client) |
| 153 |
{ |
| 154 |
} |
| 155 |
|
| 156 |
static bool_t |
| 157 |
authnone_wrap(AUTH *auth, XDR *xdrs, xdrproc_t xfunc, caddr_t xwhere) |
| 158 |
{ |
| 159 |
return ((*xfunc)(xdrs, xwhere)); |
| 160 |
} |
| 161 |
|
| 162 |
static struct auth_ops * |
| 163 |
authnone_ops() |
| 164 |
{ |
| 165 |
static struct auth_ops ops; |
| 166 |
extern mutex_t ops_lock; |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
mutex_lock(&ops_lock); |
| 171 |
if (ops.ah_nextverf == NULL) { |
| 172 |
ops.ah_nextverf = authnone_verf; |
| 173 |
ops.ah_marshal = authnone_marshal; |
| 174 |
ops.ah_validate = authnone_validate; |
| 175 |
ops.ah_refresh = authnone_refresh; |
| 176 |
ops.ah_destroy = authnone_destroy; |
| 177 |
ops.ah_wrap = authnone_wrap; |
| 178 |
ops.ah_unwrap = authnone_wrap; |
| 179 |
} |
| 180 |
mutex_unlock(&ops_lock); |
| 181 |
return (&ops); |
| 182 |
} |