fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / include / linux / sunrpc / auth.h
1 /*
2  * linux/include/linux/sunrpc/auth.h
3  *
4  * Declarations for the RPC client 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/sunrpc/sched.h>
15 #include <linux/sunrpc/msg_prot.h>
16 #include <linux/sunrpc/xdr.h>
17
18 #include <asm/atomic.h>
19
20 /* size of the nodename buffer */
21 #define UNX_MAXNODENAME 32
22
23 /* Work around the lack of a VFS credential */
24 struct auth_cred {
25         uid_t   uid;
26         gid_t   gid;
27         tag_t   tag;
28         struct group_info *group_info;
29 };
30
31 /*
32  * Client user credentials
33  */
34 struct rpc_cred {
35         struct hlist_node       cr_hash;        /* hash chain */
36         struct rpc_credops *    cr_ops;
37         unsigned long           cr_expire;      /* when to gc */
38         atomic_t                cr_count;       /* ref count */
39         unsigned short          cr_flags;       /* various flags */
40 #ifdef RPC_DEBUG
41         unsigned long           cr_magic;       /* 0x0f4aa4f0 */
42 #endif
43
44         uid_t                   cr_uid;
45
46         /* per-flavor data */
47 };
48 #define RPCAUTH_CRED_NEW        0x0001
49 #define RPCAUTH_CRED_UPTODATE   0x0002
50
51 #define RPCAUTH_CRED_MAGIC      0x0f4aa4f0
52
53 /*
54  * Client authentication handle
55  */
56 #define RPC_CREDCACHE_NR        8
57 #define RPC_CREDCACHE_MASK      (RPC_CREDCACHE_NR - 1)
58 struct rpc_cred_cache {
59         struct hlist_head       hashtable[RPC_CREDCACHE_NR];
60         unsigned long           nextgc;         /* next garbage collection */
61         unsigned long           expire;         /* cache expiry interval */
62 };
63
64 struct rpc_auth {
65         unsigned int            au_cslack;      /* call cred size estimate */
66                                 /* guess at number of u32's auth adds before
67                                  * reply data; normally the verifier size: */
68         unsigned int            au_rslack;
69                                 /* for gss, used to calculate au_rslack: */
70         unsigned int            au_verfsize;
71
72         unsigned int            au_flags;       /* various flags */
73         struct rpc_authops *    au_ops;         /* operations */
74         rpc_authflavor_t        au_flavor;      /* pseudoflavor (note may
75                                                  * differ from the flavor in
76                                                  * au_ops->au_flavor in gss
77                                                  * case) */
78         atomic_t                au_count;       /* Reference counter */
79
80         struct rpc_cred_cache * au_credcache;
81         /* per-flavor data */
82 };
83
84 /* Flags for rpcauth_lookupcred() */
85 #define RPCAUTH_LOOKUP_NEW              0x01    /* Accept an uninitialised cred */
86 #define RPCAUTH_LOOKUP_ROOTCREDS        0x02    /* This really ought to go! */
87
88 /*
89  * Client authentication ops
90  */
91 struct rpc_authops {
92         struct module           *owner;
93         rpc_authflavor_t        au_flavor;      /* flavor (RPC_AUTH_*) */
94 #ifdef RPC_DEBUG
95         char *                  au_name;
96 #endif
97         struct rpc_auth *       (*create)(struct rpc_clnt *, rpc_authflavor_t);
98         void                    (*destroy)(struct rpc_auth *);
99
100         struct rpc_cred *       (*lookup_cred)(struct rpc_auth *, struct auth_cred *, int);
101         struct rpc_cred *       (*crcreate)(struct rpc_auth*, struct auth_cred *, int);
102 };
103
104 struct rpc_credops {
105         const char *            cr_name;        /* Name of the auth flavour */
106         int                     (*cr_init)(struct rpc_auth *, struct rpc_cred *);
107         void                    (*crdestroy)(struct rpc_cred *);
108
109         int                     (*crmatch)(struct auth_cred *, struct rpc_cred *, int);
110         __be32 *                (*crmarshal)(struct rpc_task *, __be32 *);
111         int                     (*crrefresh)(struct rpc_task *);
112         __be32 *                (*crvalidate)(struct rpc_task *, __be32 *);
113         int                     (*crwrap_req)(struct rpc_task *, kxdrproc_t,
114                                                 void *, __be32 *, void *);
115         int                     (*crunwrap_resp)(struct rpc_task *, kxdrproc_t,
116                                                 void *, __be32 *, void *);
117 };
118
119 extern struct rpc_authops       authunix_ops;
120 extern struct rpc_authops       authnull_ops;
121 #ifdef CONFIG_SUNRPC_SECURE
122 extern struct rpc_authops       authdes_ops;
123 #endif
124
125 int                     rpcauth_register(struct rpc_authops *);
126 int                     rpcauth_unregister(struct rpc_authops *);
127 struct rpc_auth *       rpcauth_create(rpc_authflavor_t, struct rpc_clnt *);
128 void                    rpcauth_destroy(struct rpc_auth *);
129 struct rpc_cred *       rpcauth_lookup_credcache(struct rpc_auth *, struct auth_cred *, int);
130 struct rpc_cred *       rpcauth_lookupcred(struct rpc_auth *, int);
131 struct rpc_cred *       rpcauth_bindcred(struct rpc_task *);
132 void                    rpcauth_holdcred(struct rpc_task *);
133 void                    put_rpccred(struct rpc_cred *);
134 void                    rpcauth_unbindcred(struct rpc_task *);
135 __be32 *                rpcauth_marshcred(struct rpc_task *, __be32 *);
136 __be32 *                rpcauth_checkverf(struct rpc_task *, __be32 *);
137 int                     rpcauth_wrap_req(struct rpc_task *task, kxdrproc_t encode, void *rqstp, __be32 *data, void *obj);
138 int                     rpcauth_unwrap_resp(struct rpc_task *task, kxdrproc_t decode, void *rqstp, __be32 *data, void *obj);
139 int                     rpcauth_refreshcred(struct rpc_task *);
140 void                    rpcauth_invalcred(struct rpc_task *);
141 int                     rpcauth_uptodatecred(struct rpc_task *);
142 int                     rpcauth_init_credcache(struct rpc_auth *, unsigned long);
143 void                    rpcauth_free_credcache(struct rpc_auth *);
144
145 static inline
146 struct rpc_cred *       get_rpccred(struct rpc_cred *cred)
147 {
148         atomic_inc(&cred->cr_count);
149         return cred;
150 }
151
152 #endif /* __KERNEL__ */
153 #endif /* _LINUX_SUNRPC_AUTH_H */