Whamcloud - gitweb
land b_hd_sec_client_oss onto HEAD.
[fs/lustre-release.git] / lustre / sec / gss / gss_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Modified from NFSv4 project for Lustre
5  * Copyright 2004, Cluster File Systems, Inc.
6  * All rights reserved
7  * Author: Eric Mei <ericm@clusterfs.com>
8  */
9
10 #include <linux/lustre_sec.h>
11 #ifndef __SEC_GSS_GSS_INTERNAL_H_
12 #define __SEC_GSS_GSS_INTERNAL_H_
13
14 /* remove this mess when libkcrypt is ready --umka */
15 #ifndef __KERNEL__
16 /*
17  * Algorithm masks and types.
18  */
19 #define CRYPTO_ALG_TYPE_MASK            0x000000ff
20 #define CRYPTO_ALG_TYPE_CIPHER          0x00000001
21 #define CRYPTO_ALG_TYPE_DIGEST          0x00000002
22 #define CRYPTO_ALG_TYPE_COMPRESS        0x00000004
23
24 /*
25  * Transform masks and values (for crt_flags).
26  */
27 #define CRYPTO_TFM_MODE_MASK            0x000000ff
28 #define CRYPTO_TFM_REQ_MASK             0x000fff00
29 #define CRYPTO_TFM_RES_MASK             0xfff00000
30
31 #define CRYPTO_TFM_MODE_ECB             0x00000001
32 #define CRYPTO_TFM_MODE_CBC             0x00000002
33 #define CRYPTO_TFM_MODE_CFB             0x00000004
34 #define CRYPTO_TFM_MODE_CTR             0x00000008
35
36 #define CRYPTO_TFM_REQ_WEAK_KEY         0x00000100
37 #define CRYPTO_TFM_RES_WEAK_KEY         0x00100000
38 #define CRYPTO_TFM_RES_BAD_KEY_LEN      0x00200000
39 #define CRYPTO_TFM_RES_BAD_KEY_SCHED    0x00400000
40 #define CRYPTO_TFM_RES_BAD_BLOCK_LEN    0x00800000
41 #define CRYPTO_TFM_RES_BAD_FLAGS        0x01000000
42
43 /*
44  * Miscellaneous stuff.
45  */
46 #define CRYPTO_UNSPEC                   0
47 #define CRYPTO_MAX_ALG_NAME             64
48
49 struct scatterlist {
50     struct page         *page;
51     unsigned int        offset;
52     __u32               dma_address;
53     unsigned int        length;
54 };
55
56 static inline struct crypto_tfm *
57 crypto_alloc_tfm(const char *name, __u32 flags)
58 {
59         return NULL;
60 }
61
62 static inline void 
63 crypto_free_tfm(struct crypto_tfm *tfm)
64 {
65         return;
66 }
67
68 static inline int 
69 crypto_digest_setkey(struct crypto_tfm *tfm,
70                      const __u8 *key, unsigned int keylen)
71 {
72         return -ENOSYS;
73 }
74
75 static inline unsigned int 
76 crypto_tfm_alg_blocksize(struct crypto_tfm *tfm)
77 {
78         return 0;
79 }
80
81 static inline unsigned int 
82 crypto_tfm_alg_ivsize(struct crypto_tfm *tfm)
83 {
84         return 0;
85 }
86
87 #endif /* __KERNEL__ */
88
89 struct ptlrpc_sec;
90 struct ptlrpc_cred;
91
92 /* rawobj stuff */
93 int rawobj_alloc(rawobj_t *obj, char *buf, int len);
94 void rawobj_free(rawobj_t *obj);
95 int rawobj_equal(rawobj_t *a, rawobj_t *b);
96 int rawobj_dup(rawobj_t *dest, rawobj_t *src);
97 int rawobj_serialize(rawobj_t *obj, __u32 **buf, __u32 *buflen);
98 int rawobj_extract(rawobj_t *obj, __u32 **buf, __u32 *buflen);
99 int rawobj_extract_local(rawobj_t *obj, __u32 **buf, __u32 *buflen);
100
101 typedef struct rawobj_buf_s {
102         __u32           dataoff;
103         __u32           datalen;
104         __u32           buflen;
105         __u8           *buf;
106 } rawobj_buf_t;
107
108 /*
109  * mark of the interface between kernel and lgssd/lsvcgssd
110  */
111 #define GSSD_INTERFACE_VERSION  (1)
112
113 /*
114  * target of gss request
115  */
116 #define LUSTRE_GSS_SVC_MDS      0
117 #define LUSTRE_GSS_SVC_OSS      1
118
119 /*
120  * data types in gss header
121  */
122 #define MAXSEQ 0x80000000 /* maximum legal sequence number, from rfc 2203 */
123
124 enum rpc_gss_proc {
125         RPC_GSS_PROC_DATA =             0,
126         RPC_GSS_PROC_INIT =             1,
127         RPC_GSS_PROC_CONTINUE_INIT =    2,
128         RPC_GSS_PROC_DESTROY =          3,
129 };
130
131 enum rpc_gss_svc {
132         RPC_GSS_SVC_NONE =              1,
133         RPC_GSS_SVC_INTEGRITY =         2,
134         RPC_GSS_SVC_PRIVACY =           3,
135 };
136
137 /* on-the-wire gss verifier: */
138 struct rpc_gss_wire_verf {
139         __u32                   gv_flavor;
140         rawobj_t                gv_verf;
141 };
142
143 struct gss_cl_ctx {
144         atomic_t                gc_refcount;
145         __u32                   gc_proc;
146         __u32                   gc_seq;
147         spinlock_t              gc_seq_lock;
148         struct gss_ctx         *gc_gss_ctx;
149         rawobj_t                gc_wire_ctx;
150         __u32                   gc_win;
151 };
152
153 struct gss_cred {
154         struct ptlrpc_cred      gc_base;
155         ptlrpcs_flavor_t        gc_flavor;
156         struct gss_cl_ctx      *gc_ctx;
157 };
158
159 /*
160  * This only guaranteed be enough for current krb5 des-cbc-crc . We might
161  * adjust this when new enc type or mech added in.
162  */
163 #define GSS_PRIVBUF_PREFIX_LEN         (32)
164 #define GSS_PRIVBUF_SUFFIX_LEN         (32)
165
166 /* This is too coarse. We'll let mech determine it */
167 #define GSS_MAX_AUTH_PAYLOAD    (128)
168
169 /* gss_mech_switch.c */
170 int init_kerberos_module(void);
171 void cleanup_kerberos_module(void);
172
173 /* gss_generic_token.c */
174 int g_token_size(rawobj_t *mech, unsigned int body_size);
175 void g_make_token_header(rawobj_t *mech, int body_size, unsigned char **buf);
176 __u32 g_verify_token_header(rawobj_t *mech, int *body_size,
177                             unsigned char **buf_in, int toksize);
178
179 /* svcsec_gss.c */
180 int gss_svc_init(void);
181 void gss_svc_exit(void);
182
183 #endif /* __SEC_GSS_GSS_INTERNAL_H_ */