net/sunrpc/auth_unix.c
Source file repositories/reference/linux-study-clean/net/sunrpc/auth_unix.c
File Facts
- System
- Linux kernel
- Corpus path
net/sunrpc/auth_unix.c- Extension
.c- Size
- 5604 bytes
- Lines
- 244
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/slab.hlinux/types.hlinux/sched.hlinux/module.hlinux/mempool.hlinux/sunrpc/clnt.hlinux/sunrpc/auth.hlinux/user_namespace.h
Detected Declarations
function unx_createfunction unx_destroyfunction unx_free_cred_callbackfunction unx_destroy_credfunction unx_matchfunction unx_marshalfunction unx_refreshfunction unx_validatefunction rpc_init_authunixfunction rpc_destroy_authunix
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* linux/net/sunrpc/auth_unix.c
*
* UNIX-style authentication; no AUTH_SHORT support
*
* Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
*/
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/module.h>
#include <linux/mempool.h>
#include <linux/sunrpc/clnt.h>
#include <linux/sunrpc/auth.h>
#include <linux/user_namespace.h>
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
# define RPCDBG_FACILITY RPCDBG_AUTH
#endif
static struct rpc_auth unix_auth;
static const struct rpc_credops unix_credops;
static mempool_t *unix_pool;
static struct rpc_auth *
unx_create(const struct rpc_auth_create_args *args, struct rpc_clnt *clnt)
{
refcount_inc(&unix_auth.au_count);
return &unix_auth;
}
static void
unx_destroy(struct rpc_auth *auth)
{
}
/*
* Lookup AUTH_UNIX creds for current process
*/
static struct rpc_cred *unx_lookup_cred(struct rpc_auth *auth,
struct auth_cred *acred, int flags)
{
struct rpc_cred *ret;
ret = kmalloc_obj(*ret, rpc_task_gfp_mask());
if (!ret) {
if (!(flags & RPCAUTH_LOOKUP_ASYNC))
return ERR_PTR(-ENOMEM);
ret = mempool_alloc(unix_pool, GFP_NOWAIT);
if (!ret)
return ERR_PTR(-ENOMEM);
}
rpcauth_init_cred(ret, acred, auth, &unix_credops);
ret->cr_flags = 1UL << RPCAUTH_CRED_UPTODATE;
return ret;
}
static void
unx_free_cred_callback(struct rcu_head *head)
{
struct rpc_cred *rpc_cred = container_of(head, struct rpc_cred, cr_rcu);
put_cred(rpc_cred->cr_cred);
mempool_free(rpc_cred, unix_pool);
}
static void
unx_destroy_cred(struct rpc_cred *cred)
{
call_rcu(&cred->cr_rcu, unx_free_cred_callback);
}
/*
* Match credentials against current the auth_cred.
*/
static int
unx_match(struct auth_cred *acred, struct rpc_cred *cred, int flags)
{
unsigned int groups = 0;
unsigned int i;
if (cred->cr_cred == acred->cred)
return 1;
if (!uid_eq(cred->cr_cred->fsuid, acred->cred->fsuid) || !gid_eq(cred->cr_cred->fsgid, acred->cred->fsgid))
return 0;
Annotation
- Immediate include surface: `linux/slab.h`, `linux/types.h`, `linux/sched.h`, `linux/module.h`, `linux/mempool.h`, `linux/sunrpc/clnt.h`, `linux/sunrpc/auth.h`, `linux/user_namespace.h`.
- Detected declarations: `function unx_create`, `function unx_destroy`, `function unx_free_cred_callback`, `function unx_destroy_cred`, `function unx_match`, `function unx_marshal`, `function unx_refresh`, `function unx_validate`, `function rpc_init_authunix`, `function rpc_destroy_authunix`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.