0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/types.h>
0011 #include <linux/module.h>
0012 #include <linux/sunrpc/clnt.h>
0013
0014 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
0015 # define RPCDBG_FACILITY RPCDBG_AUTH
0016 #endif
0017
0018 static struct rpc_auth null_auth;
0019 static struct rpc_cred null_cred;
0020
0021 static struct rpc_auth *
0022 nul_create(const struct rpc_auth_create_args *args, struct rpc_clnt *clnt)
0023 {
0024 refcount_inc(&null_auth.au_count);
0025 return &null_auth;
0026 }
0027
0028 static void
0029 nul_destroy(struct rpc_auth *auth)
0030 {
0031 }
0032
0033
0034
0035
0036 static struct rpc_cred *
0037 nul_lookup_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
0038 {
0039 return get_rpccred(&null_cred);
0040 }
0041
0042
0043
0044
0045 static void
0046 nul_destroy_cred(struct rpc_cred *cred)
0047 {
0048 }
0049
0050
0051
0052
0053 static int
0054 nul_match(struct auth_cred *acred, struct rpc_cred *cred, int taskflags)
0055 {
0056 return 1;
0057 }
0058
0059
0060
0061
0062 static int
0063 nul_marshal(struct rpc_task *task, struct xdr_stream *xdr)
0064 {
0065 __be32 *p;
0066
0067 p = xdr_reserve_space(xdr, 4 * sizeof(*p));
0068 if (!p)
0069 return -EMSGSIZE;
0070
0071 *p++ = rpc_auth_null;
0072 *p++ = xdr_zero;
0073
0074 *p++ = rpc_auth_null;
0075 *p = xdr_zero;
0076 return 0;
0077 }
0078
0079
0080
0081
0082 static int
0083 nul_refresh(struct rpc_task *task)
0084 {
0085 set_bit(RPCAUTH_CRED_UPTODATE, &task->tk_rqstp->rq_cred->cr_flags);
0086 return 0;
0087 }
0088
0089 static int
0090 nul_validate(struct rpc_task *task, struct xdr_stream *xdr)
0091 {
0092 __be32 *p;
0093
0094 p = xdr_inline_decode(xdr, 2 * sizeof(*p));
0095 if (!p)
0096 return -EIO;
0097 if (*p++ != rpc_auth_null)
0098 return -EIO;
0099 if (*p != xdr_zero)
0100 return -EIO;
0101 return 0;
0102 }
0103
0104 const struct rpc_authops authnull_ops = {
0105 .owner = THIS_MODULE,
0106 .au_flavor = RPC_AUTH_NULL,
0107 .au_name = "NULL",
0108 .create = nul_create,
0109 .destroy = nul_destroy,
0110 .lookup_cred = nul_lookup_cred,
0111 };
0112
0113 static
0114 struct rpc_auth null_auth = {
0115 .au_cslack = NUL_CALLSLACK,
0116 .au_rslack = NUL_REPLYSLACK,
0117 .au_verfsize = NUL_REPLYSLACK,
0118 .au_ralign = NUL_REPLYSLACK,
0119 .au_ops = &authnull_ops,
0120 .au_flavor = RPC_AUTH_NULL,
0121 .au_count = REFCOUNT_INIT(1),
0122 };
0123
0124 static
0125 const struct rpc_credops null_credops = {
0126 .cr_name = "AUTH_NULL",
0127 .crdestroy = nul_destroy_cred,
0128 .crmatch = nul_match,
0129 .crmarshal = nul_marshal,
0130 .crwrap_req = rpcauth_wrap_req_encode,
0131 .crrefresh = nul_refresh,
0132 .crvalidate = nul_validate,
0133 .crunwrap_resp = rpcauth_unwrap_resp_decode,
0134 };
0135
0136 static
0137 struct rpc_cred null_cred = {
0138 .cr_lru = LIST_HEAD_INIT(null_cred.cr_lru),
0139 .cr_auth = &null_auth,
0140 .cr_ops = &null_credops,
0141 .cr_count = REFCOUNT_INIT(2),
0142 .cr_flags = 1UL << RPCAUTH_CRED_UPTODATE,
0143 };