1 /*
2  * linux/include/linux/auth.h
3  *
4  * Declarations for the RPC authentication machinery.
5  *
6  * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
7  */
8 
9 #ifndef _LINUX_SUNRPC_AUTH_H
10 #define _LINUX_SUNRPC_AUTH_H
11 
12 #ifdef __KERNEL__
13 
14 #include <linux/config.h>
15 #include <linux/sunrpc/sched.h>
16 
17 #include <asm/atomic.h>
18 
19 /* size of the nodename buffer */
20 #define UNX_MAXNODENAME	32
21 
22 /*
23  * Client user credentials
24  */
25 struct rpc_cred {
26 	struct rpc_cred *	cr_next;	/* linked list */
27 	struct rpc_auth *	cr_auth;
28 	struct rpc_credops *	cr_ops;
29 	unsigned long		cr_expire;	/* when to gc */
30 	atomic_t		cr_count;	/* ref count */
31 	unsigned short		cr_flags;	/* various flags */
32 #ifdef RPC_DEBUG
33 	unsigned long		cr_magic;	/* 0x0f4aa4f0 */
34 #endif
35 
36 	uid_t			cr_uid;
37 
38 	/* per-flavor data */
39 };
40 #define RPCAUTH_CRED_LOCKED	0x0001
41 #define RPCAUTH_CRED_UPTODATE	0x0002
42 #define RPCAUTH_CRED_DEAD	0x0004
43 
44 #define RPCAUTH_CRED_MAGIC	0x0f4aa4f0
45 
46 /*
47  * Client authentication handle
48  */
49 #define RPC_CREDCACHE_NR	8
50 #define RPC_CREDCACHE_MASK	(RPC_CREDCACHE_NR - 1)
51 struct rpc_auth {
52 	struct rpc_cred *	au_credcache[RPC_CREDCACHE_NR];
53 	unsigned long		au_expire;	/* cache expiry interval */
54 	unsigned long		au_nextgc;	/* next garbage collection */
55 	unsigned int		au_cslack;	/* call cred size estimate */
56 	unsigned int		au_rslack;	/* reply verf size guess */
57 	unsigned int		au_flags;	/* various flags */
58 	struct rpc_authops *	au_ops;		/* operations */
59 
60 	/* per-flavor data */
61 };
62 #define RPC_AUTH_PROC_CREDS	0x0010		/* process creds (including
63 						 * uid/gid, fs[ug]id, gids)
64 						 */
65 
66 /*
67  * Client authentication ops
68  */
69 struct rpc_authops {
70 	unsigned int		au_flavor;	/* flavor (RPC_AUTH_*) */
71 #ifdef RPC_DEBUG
72 	char *			au_name;
73 #endif
74 	struct rpc_auth *	(*create)(struct rpc_clnt *);
75 	void			(*destroy)(struct rpc_auth *);
76 
77 	struct rpc_cred *	(*crcreate)(int);
78 };
79 
80 struct rpc_credops {
81 	void			(*crdestroy)(struct rpc_cred *);
82 
83 	int			(*crmatch)(struct rpc_cred *, int);
84 	u32 *			(*crmarshal)(struct rpc_task *, u32 *, int);
85 	int			(*crrefresh)(struct rpc_task *);
86 	u32 *			(*crvalidate)(struct rpc_task *, u32 *);
87 };
88 
89 extern struct rpc_authops	authunix_ops;
90 extern struct rpc_authops	authnull_ops;
91 #ifdef CONFIG_SUNRPC_SECURE
92 extern struct rpc_authops	authdes_ops;
93 #endif
94 
95 int			rpcauth_register(struct rpc_authops *);
96 int			rpcauth_unregister(struct rpc_authops *);
97 struct rpc_auth *	rpcauth_create(unsigned int, struct rpc_clnt *);
98 void			rpcauth_destroy(struct rpc_auth *);
99 struct rpc_cred *	rpcauth_lookupcred(struct rpc_auth *, int);
100 struct rpc_cred *	rpcauth_bindcred(struct rpc_task *);
101 void			rpcauth_holdcred(struct rpc_task *);
102 void			put_rpccred(struct rpc_cred *);
103 void			rpcauth_unbindcred(struct rpc_task *);
104 int			rpcauth_matchcred(struct rpc_auth *,
105 					  struct rpc_cred *, int);
106 u32 *			rpcauth_marshcred(struct rpc_task *, u32 *);
107 u32 *			rpcauth_checkverf(struct rpc_task *, u32 *);
108 int			rpcauth_refreshcred(struct rpc_task *);
109 void			rpcauth_invalcred(struct rpc_task *);
110 int			rpcauth_uptodatecred(struct rpc_task *);
111 void			rpcauth_init_credcache(struct rpc_auth *);
112 void			rpcauth_free_credcache(struct rpc_auth *);
113 void			rpcauth_insert_credcache(struct rpc_auth *,
114 						struct rpc_cred *);
115 
116 static inline
get_rpccred(struct rpc_cred * cred)117 struct rpc_cred *	get_rpccred(struct rpc_cred *cred)
118 {
119 	atomic_inc(&cred->cr_count);
120 	return cred;
121 }
122 
123 #endif /* __KERNEL__ */
124 #endif /* _LINUX_SUNRPC_AUTH_H */
125