^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/net/sunrpc/auth_null.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * AUTH_NULL authentication. Really :-)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/sunrpc/clnt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) # define RPCDBG_FACILITY RPCDBG_AUTH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) static struct rpc_auth null_auth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static struct rpc_cred null_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static struct rpc_auth *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) nul_create(const struct rpc_auth_create_args *args, struct rpc_clnt *clnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) refcount_inc(&null_auth.au_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) return &null_auth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) nul_destroy(struct rpc_auth *auth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Lookup NULL creds for current process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static struct rpc_cred *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) nul_lookup_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return get_rpccred(&null_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * Destroy cred handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) nul_destroy_cred(struct rpc_cred *cred)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * Match cred handle against current process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) nul_match(struct auth_cred *acred, struct rpc_cred *cred, int taskflags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * Marshal credential.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) nul_marshal(struct rpc_task *task, struct xdr_stream *xdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) __be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) p = xdr_reserve_space(xdr, 4 * sizeof(*p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* Credential */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) *p++ = rpc_auth_null;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) *p++ = xdr_zero;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* Verifier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *p++ = rpc_auth_null;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *p = xdr_zero;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * Refresh credential. This is a no-op for AUTH_NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) nul_refresh(struct rpc_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) set_bit(RPCAUTH_CRED_UPTODATE, &task->tk_rqstp->rq_cred->cr_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) nul_validate(struct rpc_task *task, struct xdr_stream *xdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) __be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) p = xdr_inline_decode(xdr, 2 * sizeof(*p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (*p++ != rpc_auth_null)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (*p != xdr_zero)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) const struct rpc_authops authnull_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .au_flavor = RPC_AUTH_NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .au_name = "NULL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .create = nul_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .destroy = nul_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .lookup_cred = nul_lookup_cred,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct rpc_auth null_auth = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .au_cslack = NUL_CALLSLACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .au_rslack = NUL_REPLYSLACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .au_verfsize = NUL_REPLYSLACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .au_ralign = NUL_REPLYSLACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .au_ops = &authnull_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .au_flavor = RPC_AUTH_NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .au_count = REFCOUNT_INIT(1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) const struct rpc_credops null_credops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) .cr_name = "AUTH_NULL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) .crdestroy = nul_destroy_cred,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) .crmatch = nul_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) .crmarshal = nul_marshal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .crwrap_req = rpcauth_wrap_req_encode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .crrefresh = nul_refresh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .crvalidate = nul_validate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .crunwrap_resp = rpcauth_unwrap_resp_decode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct rpc_cred null_cred = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .cr_lru = LIST_HEAD_INIT(null_cred.cr_lru),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .cr_auth = &null_auth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .cr_ops = &null_credops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .cr_count = REFCOUNT_INIT(2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .cr_flags = 1UL << RPCAUTH_CRED_UPTODATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) };