struct auth_cred
struct auth_cred
记录着uid,gid,是最基本的cred信息。
通过current_cred()
得到当前进程的struct auth_cred
struct rpc_auth
用来描述RPC传输时候使用哪种方式鉴权, Linux内核提供了4个unix_auth,null_auth,generic_auth,gss_auth,其中unix_auth是默认使用的。
struct rpc_auth {
unsigned int au_cslack; /* call cred size estimate */
/* guess at number of u32's auth adds before
* reply data; normally the verifier size: */
unsigned int au_rslack;
/* for gss, used to calculate au_rslack: */
unsigned int au_verfsize;
unsigned int au_flags; /* various flags */
const struct rpc_authops *au_ops; /* operations */
rpc_authflavor_t au_flavor; /* pseudoflavor (note may
* differ from the flavor in
* au_ops->au_flavor in gss
* case) */
atomic_t au_count; /* Reference counter */
struct rpc_cred_cache * au_credcache;
/* per-flavor data */
};
rpc auth flavors
鉴权方式,mount时候参数sec=xx,默认是sys,对应RPC_AUTH_UNIX。还可以为krb5,krb5i,krb5p等。
enum rpc_auth_flavors {
RPC_AUTH_NULL = 0,
RPC_AUTH_UNIX = 1,
RPC_AUTH_SHORT = 2,
RPC_AUTH_DES = 3,
RPC_AUTH_KRB = 4,
RPC_AUTH_GSS = 6,
RPC_AUTH_MAXFLAVOR = 8,
/* pseudoflavors: */
RPC_AUTH_GSS_KRB5 = 390003,
RPC_AUTH_GSS_KRB5I = 390004,
RPC_AUTH_GSS_KRB5P = 390005,
RPC_AUTH_GSS_LKEY = 390006,
RPC_AUTH_GSS_LKEYI = 390007,
RPC_AUTH_GSS_LKEYP = 390008,
RPC_AUTH_GSS_SPKM = 390009,
RPC_AUTH_GSS_SPKMI = 390010,
RPC_AUTH_GSS_SPKMP = 390011,
};
struct rpc_cred
struct rpc_cred {
struct hlist_node cr_hash; /* hash chain */
struct list_head cr_lru; /* lru garbage collection */
struct rcu_head cr_rcu;
struct rpc_auth * cr_auth;
const struct rpc_credops *cr_ops;
unsigned long cr_expire; /* when to gc */
unsigned long cr_flags; /* various flags */
atomic_t cr_count; /* ref count */
kuid_t cr_uid;
/* per-flavor data */
};
设置rpc_cred
Linux Kernel每次通过RPC发送NFS数据的时候,都会走一个状态机。当走到call_refresh状态时候,
每次发RPC命令时候,都会准备类似的message,其中包括了设置cred
struct rpc_message msg = {
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
.rpc_argp = o_arg,
.rpc_resp = o_res,
.rpc_cred = data->owner->so_cred,
};
不同的NFS请求,cred来自不同的地方。
exchange_id命令是来自
int nfs4_discover_server_trunking(struct nfs_client *clp,
struct nfs_client **result)
{
...
//来自于unix_auth
cred = nfs4_get_clid_cred(clp);
...
}
open命令
struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode)
{
...
//来自于gss_auth
struct rpc_cred *cred = rpc_lookup_cred();
...
}
``