Whamcloud - gitweb
LU-6158 mdt: always shrink_capsule in getxattr_all
[fs/lustre-release.git] / lustre / include / lustre_sec.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef _LUSTRE_SEC_H_
38 #define _LUSTRE_SEC_H_
39
40 /** \defgroup sptlrpc sptlrpc
41  *
42  * @{
43  */
44
45 /*
46  * to avoid include
47  */
48 struct obd_import;
49 struct obd_export;
50 struct ptlrpc_request;
51 struct ptlrpc_reply_state;
52 struct ptlrpc_bulk_desc;
53 struct brw_page;
54 /* Linux specific */
55 struct key;
56 struct seq_file;
57
58 /*
59  * forward declaration
60  */
61 struct ptlrpc_sec_policy;
62 struct ptlrpc_sec_cops;
63 struct ptlrpc_sec_sops;
64 struct ptlrpc_sec;
65 struct ptlrpc_svc_ctx;
66 struct ptlrpc_cli_ctx;
67 struct ptlrpc_ctx_ops;
68
69 /**
70  * \addtogroup flavor flavor
71  *
72  * RPC flavor is represented by a 32 bits integer. Currently the high 12 bits
73  * are unused, must be set to 0 for future expansion.
74  * <pre>
75  * ------------------------------------------------------------------------
76  * | 4b (bulk svc) | 4b (bulk type) | 4b (svc) | 4b (mech)  | 4b (policy) |
77  * ------------------------------------------------------------------------
78  * </pre>
79  *
80  * @{
81  */
82
83 /*
84  * flavor constants
85  */
86 enum sptlrpc_policy {
87         SPTLRPC_POLICY_NULL             = 0,
88         SPTLRPC_POLICY_PLAIN            = 1,
89         SPTLRPC_POLICY_GSS              = 2,
90         SPTLRPC_POLICY_MAX,
91 };
92
93 enum sptlrpc_mech_null {
94         SPTLRPC_MECH_NULL               = 0,
95         SPTLRPC_MECH_NULL_MAX,
96 };
97
98 enum sptlrpc_mech_plain {
99         SPTLRPC_MECH_PLAIN              = 0,
100         SPTLRPC_MECH_PLAIN_MAX,
101 };
102
103 enum sptlrpc_mech_gss {
104         SPTLRPC_MECH_GSS_NULL           = 0,
105         SPTLRPC_MECH_GSS_KRB5           = 1,
106         SPTLRPC_MECH_GSS_SK             = 2,
107         SPTLRPC_MECH_GSS_MAX,
108 };
109
110 enum sptlrpc_service_type {
111         SPTLRPC_SVC_NULL                = 0,    /**< no security */
112         SPTLRPC_SVC_AUTH                = 1,    /**< authentication only */
113         SPTLRPC_SVC_INTG                = 2,    /**< integrity */
114         SPTLRPC_SVC_PRIV                = 3,    /**< privacy */
115         SPTLRPC_SVC_MAX,
116 };
117
118 enum sptlrpc_bulk_type {
119         SPTLRPC_BULK_DEFAULT            = 0,    /**< follow rpc flavor */
120         SPTLRPC_BULK_HASH               = 1,    /**< hash integrity */
121         SPTLRPC_BULK_MAX,
122 };
123
124 enum sptlrpc_bulk_service {
125         SPTLRPC_BULK_SVC_NULL           = 0,    /**< no security */
126         SPTLRPC_BULK_SVC_AUTH           = 1,    /**< authentication only */
127         SPTLRPC_BULK_SVC_INTG           = 2,    /**< integrity */
128         SPTLRPC_BULK_SVC_PRIV           = 3,    /**< privacy */
129         SPTLRPC_BULK_SVC_MAX,
130 };
131
132 /*
133  * compose/extract macros
134  */
135 #define FLVR_POLICY_OFFSET              (0)
136 #define FLVR_MECH_OFFSET                (4)
137 #define FLVR_SVC_OFFSET                 (8)
138 #define FLVR_BULK_TYPE_OFFSET           (12)
139 #define FLVR_BULK_SVC_OFFSET            (16)
140
141 #define MAKE_FLVR(policy, mech, svc, btype, bsvc)                       \
142         (((__u32)(policy) << FLVR_POLICY_OFFSET) |                      \
143          ((__u32)(mech) << FLVR_MECH_OFFSET) |                          \
144          ((__u32)(svc) << FLVR_SVC_OFFSET) |                            \
145          ((__u32)(btype) << FLVR_BULK_TYPE_OFFSET) |                    \
146          ((__u32)(bsvc) << FLVR_BULK_SVC_OFFSET))
147
148 /*
149  * extraction
150  */
151 #define SPTLRPC_FLVR_POLICY(flavor)                                     \
152         ((((__u32)(flavor)) >> FLVR_POLICY_OFFSET) & 0xF)
153 #define SPTLRPC_FLVR_MECH(flavor)                                       \
154         ((((__u32)(flavor)) >> FLVR_MECH_OFFSET) & 0xF)
155 #define SPTLRPC_FLVR_SVC(flavor)                                        \
156         ((((__u32)(flavor)) >> FLVR_SVC_OFFSET) & 0xF)
157 #define SPTLRPC_FLVR_BULK_TYPE(flavor)                                  \
158         ((((__u32)(flavor)) >> FLVR_BULK_TYPE_OFFSET) & 0xF)
159 #define SPTLRPC_FLVR_BULK_SVC(flavor)                                   \
160         ((((__u32)(flavor)) >> FLVR_BULK_SVC_OFFSET) & 0xF)
161
162 #define SPTLRPC_FLVR_BASE(flavor)                                       \
163         ((((__u32)(flavor)) >> FLVR_POLICY_OFFSET) & 0xFFF)
164 #define SPTLRPC_FLVR_BASE_SUB(flavor)                                   \
165         ((((__u32)(flavor)) >> FLVR_MECH_OFFSET) & 0xFF)
166
167 /*
168  * gss subflavors
169  */
170 #define MAKE_BASE_SUBFLVR(mech, svc)                                    \
171         ((__u32)(mech) |                                                \
172          ((__u32)(svc) << (FLVR_SVC_OFFSET - FLVR_MECH_OFFSET)))
173
174 #define SPTLRPC_SUBFLVR_GSSNULL                                         \
175         MAKE_BASE_SUBFLVR(SPTLRPC_MECH_GSS_NULL, SPTLRPC_SVC_NULL)
176 #define SPTLRPC_SUBFLVR_KRB5N                                           \
177         MAKE_BASE_SUBFLVR(SPTLRPC_MECH_GSS_KRB5, SPTLRPC_SVC_NULL)
178 #define SPTLRPC_SUBFLVR_KRB5A                                           \
179         MAKE_BASE_SUBFLVR(SPTLRPC_MECH_GSS_KRB5, SPTLRPC_SVC_AUTH)
180 #define SPTLRPC_SUBFLVR_KRB5I                                           \
181         MAKE_BASE_SUBFLVR(SPTLRPC_MECH_GSS_KRB5, SPTLRPC_SVC_INTG)
182 #define SPTLRPC_SUBFLVR_KRB5P                                           \
183         MAKE_BASE_SUBFLVR(SPTLRPC_MECH_GSS_KRB5, SPTLRPC_SVC_PRIV)
184 #define SPTLRPC_SUBFLVR_SKI                                             \
185         MAKE_BASE_SUBFLVR(SPTLRPC_MECH_GSS_SK, SPTLRPC_SVC_INTG)
186 #define SPTLRPC_SUBFLVR_SKPI                                            \
187         MAKE_BASE_SUBFLVR(SPTLRPC_MECH_GSS_SK, SPTLRPC_SVC_PRIV)
188
189 /*
190  * "end user" flavors
191  */
192 #define SPTLRPC_FLVR_NULL                               \
193         MAKE_FLVR(SPTLRPC_POLICY_NULL,                  \
194                   SPTLRPC_MECH_NULL,                    \
195                   SPTLRPC_SVC_NULL,                     \
196                   SPTLRPC_BULK_DEFAULT,                 \
197                   SPTLRPC_BULK_SVC_NULL)
198 #define SPTLRPC_FLVR_PLAIN                              \
199         MAKE_FLVR(SPTLRPC_POLICY_PLAIN,                 \
200                   SPTLRPC_MECH_PLAIN,                   \
201                   SPTLRPC_SVC_NULL,                     \
202                   SPTLRPC_BULK_HASH,                    \
203                   SPTLRPC_BULK_SVC_INTG)
204 #define SPTLRPC_FLVR_GSSNULL                            \
205         MAKE_FLVR(SPTLRPC_POLICY_GSS,                   \
206                   SPTLRPC_MECH_GSS_NULL,                \
207                   SPTLRPC_SVC_NULL,                     \
208                   SPTLRPC_BULK_DEFAULT,                 \
209                   SPTLRPC_BULK_SVC_NULL)
210 #define SPTLRPC_FLVR_KRB5N                              \
211         MAKE_FLVR(SPTLRPC_POLICY_GSS,                   \
212                   SPTLRPC_MECH_GSS_KRB5,                \
213                   SPTLRPC_SVC_NULL,                     \
214                   SPTLRPC_BULK_DEFAULT,                 \
215                   SPTLRPC_BULK_SVC_NULL)
216 #define SPTLRPC_FLVR_KRB5A                              \
217         MAKE_FLVR(SPTLRPC_POLICY_GSS,                   \
218                   SPTLRPC_MECH_GSS_KRB5,                \
219                   SPTLRPC_SVC_AUTH,                     \
220                   SPTLRPC_BULK_DEFAULT,                 \
221                   SPTLRPC_BULK_SVC_NULL)
222 #define SPTLRPC_FLVR_KRB5I                              \
223         MAKE_FLVR(SPTLRPC_POLICY_GSS,                   \
224                   SPTLRPC_MECH_GSS_KRB5,                \
225                   SPTLRPC_SVC_INTG,                     \
226                   SPTLRPC_BULK_DEFAULT,                 \
227                   SPTLRPC_BULK_SVC_INTG)
228 #define SPTLRPC_FLVR_KRB5P                              \
229         MAKE_FLVR(SPTLRPC_POLICY_GSS,                   \
230                   SPTLRPC_MECH_GSS_KRB5,                \
231                   SPTLRPC_SVC_PRIV,                     \
232                   SPTLRPC_BULK_DEFAULT,                 \
233                   SPTLRPC_BULK_SVC_PRIV)
234 #define SPTLRPC_FLVR_SKI                                \
235         MAKE_FLVR(SPTLRPC_POLICY_GSS,                   \
236                   SPTLRPC_MECH_GSS_SK,                  \
237                   SPTLRPC_SVC_INTG,                     \
238                   SPTLRPC_BULK_DEFAULT,                 \
239                   SPTLRPC_BULK_SVC_PRIV)
240 #define SPTLRPC_FLVR_SKPI                               \
241         MAKE_FLVR(SPTLRPC_POLICY_GSS,                   \
242                   SPTLRPC_MECH_GSS_SK,                  \
243                   SPTLRPC_SVC_PRIV,                     \
244                   SPTLRPC_BULK_DEFAULT,                 \
245                   SPTLRPC_BULK_SVC_PRIV)
246
247 #define SPTLRPC_FLVR_DEFAULT            SPTLRPC_FLVR_NULL
248
249 #define SPTLRPC_FLVR_INVALID            ((__u32) 0xFFFFFFFF)
250 #define SPTLRPC_FLVR_ANY                ((__u32) 0xFFF00000)
251
252 /**
253  * extract the useful part from wire flavor
254  */
255 #define WIRE_FLVR(wflvr)                (((__u32) (wflvr)) & 0x000FFFFF)
256
257 /** @} flavor */
258
259 static inline void flvr_set_svc(__u32 *flvr, __u32 svc)
260 {
261         LASSERT(svc < SPTLRPC_SVC_MAX);
262         *flvr = MAKE_FLVR(SPTLRPC_FLVR_POLICY(*flvr),
263                           SPTLRPC_FLVR_MECH(*flvr),
264                           svc,
265                           SPTLRPC_FLVR_BULK_TYPE(*flvr),
266                           SPTLRPC_FLVR_BULK_SVC(*flvr));
267 }
268
269 static inline void flvr_set_bulk_svc(__u32 *flvr, __u32 svc)
270 {
271         LASSERT(svc < SPTLRPC_BULK_SVC_MAX);
272         *flvr = MAKE_FLVR(SPTLRPC_FLVR_POLICY(*flvr),
273                           SPTLRPC_FLVR_MECH(*flvr),
274                           SPTLRPC_FLVR_SVC(*flvr),
275                           SPTLRPC_FLVR_BULK_TYPE(*flvr),
276                           svc);
277 }
278
279 struct bulk_spec_hash {
280         __u8    hash_alg;
281 };
282
283 /**
284  * Full description of flavors being used on a ptlrpc connection, include
285  * both regular RPC and bulk transfer parts.
286  */
287 struct sptlrpc_flavor {
288         /**
289          * wire flavor, should be renamed to sf_wire.
290          */
291         __u32   sf_rpc;
292         /**
293          * general flags of PTLRPC_SEC_FL_*
294          */
295         __u32   sf_flags;
296         /**
297          * rpc flavor specification
298          */
299         union {
300                 /* nothing for now */
301         } u_rpc;
302         /**
303          * bulk flavor specification
304          */
305         union {
306                 struct bulk_spec_hash hash;
307         } u_bulk;
308 };
309
310 /**
311  * identify the RPC is generated from what part of Lustre. It's encoded into
312  * RPC requests and to be checked by ptlrpc service.
313  */
314 enum lustre_sec_part {
315         LUSTRE_SP_CLI           = 0,
316         LUSTRE_SP_MDT,
317         LUSTRE_SP_OST,
318         LUSTRE_SP_MGC,
319         LUSTRE_SP_MGS,
320         LUSTRE_SP_ANY           = 0xFF
321 };
322
323 const char *sptlrpc_part2name(enum lustre_sec_part sp);
324 enum lustre_sec_part sptlrpc_target_sec_part(struct obd_device *obd);
325
326 /**
327  * A rule specifies a flavor to be used by a ptlrpc connection between
328  * two Lustre parts.
329  */
330 struct sptlrpc_rule {
331         __u32                   sr_netid;   /* LNET network ID */
332         __u8                    sr_from;    /* sec_part */
333         __u8                    sr_to;      /* sec_part */
334         __u16                   sr_padding;
335         struct sptlrpc_flavor   sr_flvr;
336 };
337
338 /**
339  * A set of rules in memory.
340  *
341  * Rules are generated and stored on MGS, and propagated to MDT, OST,
342  * and client when needed.
343  */
344 struct sptlrpc_rule_set {
345         int                     srs_nslot;
346         int                     srs_nrule;
347         struct sptlrpc_rule    *srs_rules;
348 };
349
350 int sptlrpc_parse_flavor(const char *str, struct sptlrpc_flavor *flvr);
351 int sptlrpc_flavor_has_bulk(struct sptlrpc_flavor *flvr);
352
353 static inline void sptlrpc_rule_set_init(struct sptlrpc_rule_set *set)
354 {
355         memset(set, 0, sizeof(*set));
356 }
357
358 void sptlrpc_rule_set_free(struct sptlrpc_rule_set *set);
359 int  sptlrpc_rule_set_expand(struct sptlrpc_rule_set *set);
360 int  sptlrpc_rule_set_merge(struct sptlrpc_rule_set *set,
361                             struct sptlrpc_rule *rule);
362 int sptlrpc_rule_set_choose(struct sptlrpc_rule_set *rset,
363                             enum lustre_sec_part from,
364                             enum lustre_sec_part to,
365                             lnet_nid_t nid,
366                             struct sptlrpc_flavor *sf);
367 void sptlrpc_rule_set_dump(struct sptlrpc_rule_set *set);
368
369 int  sptlrpc_process_config(struct lustre_cfg *lcfg);
370 void sptlrpc_conf_log_start(const char *logname);
371 void sptlrpc_conf_log_stop(const char *logname);
372 void sptlrpc_conf_log_update_begin(const char *logname);
373 void sptlrpc_conf_log_update_end(const char *logname);
374 void sptlrpc_conf_client_adapt(struct obd_device *obd);
375 int  sptlrpc_conf_target_get_rules(struct obd_device *obd,
376                                    struct sptlrpc_rule_set *rset,
377                                    int initial);
378 void sptlrpc_target_choose_flavor(struct sptlrpc_rule_set *rset,
379                                   enum lustre_sec_part from,
380                                   lnet_nid_t nid,
381                                   struct sptlrpc_flavor *flavor);
382
383 /* The maximum length of security payload. 1024 is enough for Kerberos 5,
384  * and should be enough for other future mechanisms but not sure.
385  * Only used by pre-allocated request/reply pool.
386  */
387 #define SPTLRPC_MAX_PAYLOAD     (1024)
388
389
390 struct vfs_cred {
391         uint32_t        vc_uid;
392         uint32_t        vc_gid;
393 };
394
395 struct ptlrpc_ctx_ops {
396         /**
397          * To determine whether it's suitable to use the \a ctx for \a vcred.
398          */
399         int     (*match)       (struct ptlrpc_cli_ctx *ctx,
400                                 struct vfs_cred *vcred);
401
402         /**
403          * To bring the \a ctx uptodate.
404          */
405         int     (*refresh)     (struct ptlrpc_cli_ctx *ctx);
406
407         /**
408          * Validate the \a ctx.
409          */
410         int     (*validate)    (struct ptlrpc_cli_ctx *ctx);
411
412         /**
413          * Force the \a ctx to die.
414          */
415         void    (*die)         (struct ptlrpc_cli_ctx *ctx,
416                                 int grace);
417         int     (*display)     (struct ptlrpc_cli_ctx *ctx,
418                                 char *buf, int bufsize);
419
420         /**
421          * Sign the request message using \a ctx.
422          *
423          * \pre req->rq_reqmsg point to request message.
424          * \pre req->rq_reqlen is the request message length.
425          * \post req->rq_reqbuf point to request message with signature.
426          * \post req->rq_reqdata_len is set to the final request message size.
427          *
428          * \see null_ctx_sign(), plain_ctx_sign(), gss_cli_ctx_sign().
429          */
430         int     (*sign)        (struct ptlrpc_cli_ctx *ctx,
431                                 struct ptlrpc_request *req);
432
433         /**
434          * Verify the reply message using \a ctx.
435          *
436          * \pre req->rq_repdata point to reply message with signature.
437          * \pre req->rq_repdata_len is the total reply message length.
438          * \post req->rq_repmsg point to reply message without signature.
439          * \post req->rq_replen is the reply message length.
440          *
441          * \see null_ctx_verify(), plain_ctx_verify(), gss_cli_ctx_verify().
442          */
443         int     (*verify)      (struct ptlrpc_cli_ctx *ctx,
444                                 struct ptlrpc_request *req);
445
446         /**
447          * Encrypt the request message using \a ctx.
448          *
449          * \pre req->rq_reqmsg point to request message in clear text.
450          * \pre req->rq_reqlen is the request message length.
451          * \post req->rq_reqbuf point to request message.
452          * \post req->rq_reqdata_len is set to the final request message size.
453          *
454          * \see gss_cli_ctx_seal().
455          */
456         int     (*seal)        (struct ptlrpc_cli_ctx *ctx,
457                                 struct ptlrpc_request *req);
458
459         /**
460          * Decrypt the reply message using \a ctx.
461          *
462          * \pre req->rq_repdata point to encrypted reply message.
463          * \pre req->rq_repdata_len is the total cipher text length.
464          * \post req->rq_repmsg point to reply message in clear text.
465          * \post req->rq_replen is the reply message length in clear text.
466          *
467          * \see gss_cli_ctx_unseal().
468          */
469         int     (*unseal)      (struct ptlrpc_cli_ctx *ctx,
470                                 struct ptlrpc_request *req);
471
472         /**
473          * Wrap bulk request data. This is called before wrapping RPC
474          * request message.
475          *
476          * \pre bulk buffer is descripted by desc->bd_iov and
477          * desc->bd_iov_count. note for read it's just buffer, no data
478          * need to be sent;  for write it contains data in clear text.
479          * \post when necessary, ptlrpc_bulk_sec_desc was properly prepared
480          * (usually inside of RPC request message).
481          * - encryption: cipher text bulk buffer is descripted by
482          *   desc->bd_enc_iov and desc->bd_iov_count (currently assume iov
483          *   count remains the same).
484          * - otherwise: bulk buffer is still desc->bd_iov and
485          *   desc->bd_iov_count.
486          *
487          * \return 0: success.
488          * \return -ev: error code.
489          *
490          * \see plain_cli_wrap_bulk(), gss_cli_ctx_wrap_bulk().
491          */
492         int     (*wrap_bulk)   (struct ptlrpc_cli_ctx *ctx,
493                                 struct ptlrpc_request *req,
494                                 struct ptlrpc_bulk_desc *desc);
495
496         /**
497          * Unwrap bulk reply data. This is called after wrapping RPC
498          * reply message.
499          *
500          * \pre bulk buffer is descripted by desc->bd_iov/desc->bd_enc_iov and
501          * desc->bd_iov_count, according to wrap_bulk().
502          * \post final bulk data in clear text is placed in buffer described
503          * by desc->bd_iov and desc->bd_iov_count.
504          * \return +ve nob of actual bulk data in clear text.
505          * \return -ve error code.
506          *
507          * \see plain_cli_unwrap_bulk(), gss_cli_ctx_unwrap_bulk().
508          */
509         int     (*unwrap_bulk) (struct ptlrpc_cli_ctx *ctx,
510                                 struct ptlrpc_request *req,
511                                 struct ptlrpc_bulk_desc *desc);
512 };
513
514 #define PTLRPC_CTX_NEW_BIT             (0)  /* newly created */
515 #define PTLRPC_CTX_UPTODATE_BIT        (1)  /* uptodate */
516 #define PTLRPC_CTX_DEAD_BIT            (2)  /* mark expired gracefully */
517 #define PTLRPC_CTX_ERROR_BIT           (3)  /* fatal error (refresh, etc.) */
518 #define PTLRPC_CTX_CACHED_BIT          (8)  /* in ctx cache (hash etc.) */
519 #define PTLRPC_CTX_ETERNAL_BIT         (9)  /* always valid */
520
521 #define PTLRPC_CTX_NEW                 (1 << PTLRPC_CTX_NEW_BIT)
522 #define PTLRPC_CTX_UPTODATE            (1 << PTLRPC_CTX_UPTODATE_BIT)
523 #define PTLRPC_CTX_DEAD                (1 << PTLRPC_CTX_DEAD_BIT)
524 #define PTLRPC_CTX_ERROR               (1 << PTLRPC_CTX_ERROR_BIT)
525 #define PTLRPC_CTX_CACHED              (1 << PTLRPC_CTX_CACHED_BIT)
526 #define PTLRPC_CTX_ETERNAL             (1 << PTLRPC_CTX_ETERNAL_BIT)
527
528 #define PTLRPC_CTX_STATUS_MASK         (PTLRPC_CTX_NEW_BIT    |       \
529                                         PTLRPC_CTX_UPTODATE   |       \
530                                         PTLRPC_CTX_DEAD       |       \
531                                         PTLRPC_CTX_ERROR)
532
533 struct ptlrpc_cli_ctx {
534         struct hlist_node       cc_cache;       /* linked into ctx cache */
535         atomic_t                cc_refcount;
536         struct ptlrpc_sec      *cc_sec;
537         struct ptlrpc_ctx_ops  *cc_ops;
538         cfs_time_t              cc_expire;      /* in seconds */
539         unsigned int            cc_early_expire:1;
540         unsigned long           cc_flags;
541         struct vfs_cred         cc_vcred;
542         spinlock_t              cc_lock;
543         struct list_head        cc_req_list;    /* waiting reqs linked here */
544         struct list_head        cc_gc_chain;    /* linked to gc chain */
545 };
546
547 /**
548  * client side policy operation vector.
549  */
550 struct ptlrpc_sec_cops {
551         /**
552          * Given an \a imp, create and initialize a ptlrpc_sec structure.
553          * \param ctx service context:
554          * - regular import: \a ctx should be NULL;
555          * - reverse import: \a ctx is obtained from incoming request.
556          * \param flavor specify what flavor to use.
557          *
558          * When necessary, policy module is responsible for taking reference
559          * on the import.
560          *
561          * \see null_create_sec(), plain_create_sec(), gss_sec_create_kr().
562          */
563         struct ptlrpc_sec *     (*create_sec)  (struct obd_import *imp,
564                                                 struct ptlrpc_svc_ctx *ctx,
565                                                 struct sptlrpc_flavor *flavor);
566
567         /**
568          * Destructor of ptlrpc_sec. When called, refcount has been dropped
569          * to 0 and all contexts has been destroyed.
570          *
571          * \see null_destroy_sec(), plain_destroy_sec(), gss_sec_destroy_kr().
572          */
573         void                    (*destroy_sec) (struct ptlrpc_sec *sec);
574
575         /**
576          * Notify that this ptlrpc_sec is going to die. Optionally, policy
577          * module is supposed to set sec->ps_dying and whatever necessary
578          * actions.
579          *
580          * \see plain_kill_sec(), gss_sec_kill().
581          */
582         void                    (*kill_sec)    (struct ptlrpc_sec *sec);
583
584         /**
585          * Given \a vcred, lookup and/or create its context. The policy module
586          * is supposed to maintain its own context cache.
587          * XXX currently \a create and \a remove_dead is always 1, perhaps
588          * should be removed completely.
589          *
590          * \see null_lookup_ctx(), plain_lookup_ctx(), gss_sec_lookup_ctx_kr().
591          */
592         struct ptlrpc_cli_ctx * (*lookup_ctx)  (struct ptlrpc_sec *sec,
593                                                 struct vfs_cred *vcred,
594                                                 int create,
595                                                 int remove_dead);
596
597         /**
598          * Called then the reference of \a ctx dropped to 0. The policy module
599          * is supposed to destroy this context or whatever else according to
600          * its cache maintainance mechamism.
601          *
602          * \param sync if zero, we shouldn't wait for the context being
603          * destroyed completely.
604          *
605          * \see plain_release_ctx(), gss_sec_release_ctx_kr().
606          */
607         void                    (*release_ctx) (struct ptlrpc_sec *sec,
608                                                 struct ptlrpc_cli_ctx *ctx,
609                                                 int sync);
610
611         /**
612          * Flush the context cache.
613          *
614          * \param uid context of which user, -1 means all contexts.
615          * \param grace if zero, the PTLRPC_CTX_UPTODATE_BIT of affected
616          * contexts should be cleared immediately.
617          * \param force if zero, only idle contexts will be flushed.
618          *
619          * \see plain_flush_ctx_cache(), gss_sec_flush_ctx_cache_kr().
620          */
621         int                     (*flush_ctx_cache)
622                                                (struct ptlrpc_sec *sec,
623                                                 uid_t uid,
624                                                 int grace,
625                                                 int force);
626
627         /**
628          * Called periodically by garbage collector to remove dead contexts
629          * from cache.
630          *
631          * \see gss_sec_gc_ctx_kr().
632          */
633         void                    (*gc_ctx)      (struct ptlrpc_sec *sec);
634
635         /**
636          * Given an context \a ctx, install a corresponding reverse service
637          * context on client side.
638          * XXX currently it's only used by GSS module, maybe we should remove
639          * this from general API.
640          */
641         int                     (*install_rctx)(struct obd_import *imp,
642                                                 struct ptlrpc_sec *sec,
643                                                 struct ptlrpc_cli_ctx *ctx);
644
645         /**
646          * To allocate request buffer for \a req.
647          *
648          * \pre req->rq_reqmsg == NULL.
649          * \pre req->rq_reqbuf == NULL, otherwise it must be pre-allocated,
650          * we are not supposed to free it.
651          * \post if success, req->rq_reqmsg point to a buffer with size
652          * at least \a lustre_msg_size.
653          *
654          * \see null_alloc_reqbuf(), plain_alloc_reqbuf(), gss_alloc_reqbuf().
655          */
656         int                     (*alloc_reqbuf)(struct ptlrpc_sec *sec,
657                                                 struct ptlrpc_request *req,
658                                                 int lustre_msg_size);
659
660         /**
661          * To free request buffer for \a req.
662          *
663          * \pre req->rq_reqbuf != NULL.
664          *
665          * \see null_free_reqbuf(), plain_free_reqbuf(), gss_free_reqbuf().
666          */
667         void                    (*free_reqbuf) (struct ptlrpc_sec *sec,
668                                                 struct ptlrpc_request *req);
669
670         /**
671          * To allocate reply buffer for \a req.
672          *
673          * \pre req->rq_repbuf == NULL.
674          * \post if success, req->rq_repbuf point to a buffer with size
675          * req->rq_repbuf_len, the size should be large enough to receive
676          * reply which be transformed from \a lustre_msg_size of clear text.
677          *
678          * \see null_alloc_repbuf(), plain_alloc_repbuf(), gss_alloc_repbuf().
679          */
680         int                     (*alloc_repbuf)(struct ptlrpc_sec *sec,
681                                                 struct ptlrpc_request *req,
682                                                 int lustre_msg_size);
683
684         /**
685          * To free reply buffer for \a req.
686          *
687          * \pre req->rq_repbuf != NULL.
688          * \post req->rq_repbuf == NULL.
689          * \post req->rq_repbuf_len == 0.
690          *
691          * \see null_free_repbuf(), plain_free_repbuf(), gss_free_repbuf().
692          */
693         void                    (*free_repbuf) (struct ptlrpc_sec *sec,
694                                                 struct ptlrpc_request *req);
695
696         /**
697          * To expand the request buffer of \a req, thus the \a segment in
698          * the request message pointed by req->rq_reqmsg can accommodate
699          * at least \a newsize of data.
700          *
701          * \pre req->rq_reqmsg->lm_buflens[segment] < newsize.
702          *
703          * \see null_enlarge_reqbuf(), plain_enlarge_reqbuf(),
704          * gss_enlarge_reqbuf().
705          */
706         int                     (*enlarge_reqbuf)
707                                                (struct ptlrpc_sec *sec,
708                                                 struct ptlrpc_request *req,
709                                                 int segment, int newsize);
710         /*
711          * misc
712          */
713         int                     (*display)     (struct ptlrpc_sec *sec,
714                                                 struct seq_file *seq);
715 };
716
717 /**
718  * server side policy operation vector.
719  */
720 struct ptlrpc_sec_sops {
721         /**
722          * verify an incoming request.
723          *
724          * \pre request message is pointed by req->rq_reqbuf, size is
725          * req->rq_reqdata_len; and the message has been unpacked to
726          * host byte order.
727          *
728          * \retval SECSVC_OK success, req->rq_reqmsg point to request message
729          * in clear text, size is req->rq_reqlen; req->rq_svc_ctx is set;
730          * req->rq_sp_from is decoded from request.
731          * \retval SECSVC_COMPLETE success, the request has been fully
732          * processed, and reply message has been prepared; req->rq_sp_from is
733          * decoded from request.
734          * \retval SECSVC_DROP failed, this request should be dropped.
735          *
736          * \see null_accept(), plain_accept(), gss_svc_accept_kr().
737          */
738         int                     (*accept)      (struct ptlrpc_request *req);
739
740         /**
741          * Perform security transformation upon reply message.
742          *
743          * \pre reply message is pointed by req->rq_reply_state->rs_msg, size
744          * is req->rq_replen.
745          * \post req->rs_repdata_len is the final message size.
746          * \post req->rq_reply_off is set.
747          *
748          * \see null_authorize(), plain_authorize(), gss_svc_authorize().
749          */
750         int                     (*authorize)   (struct ptlrpc_request *req);
751
752         /**
753          * Invalidate server context \a ctx.
754          *
755          * \see gss_svc_invalidate_ctx().
756          */
757         void                    (*invalidate_ctx)
758                                                (struct ptlrpc_svc_ctx *ctx);
759
760         /**
761          * Allocate a ptlrpc_reply_state.
762          *
763          * \param msgsize size of the reply message in clear text.
764          * \pre if req->rq_reply_state != NULL, then it's pre-allocated, we
765          * should simply use it; otherwise we'll responsible for allocating
766          * a new one.
767          * \post req->rq_reply_state != NULL;
768          * \post req->rq_reply_state->rs_msg != NULL;
769          *
770          * \see null_alloc_rs(), plain_alloc_rs(), gss_svc_alloc_rs().
771          */
772         int                     (*alloc_rs)    (struct ptlrpc_request *req,
773                                                 int msgsize);
774
775         /**
776          * Free a ptlrpc_reply_state.
777          */
778         void                    (*free_rs)     (struct ptlrpc_reply_state *rs);
779
780         /**
781          * Release the server context \a ctx.
782          *
783          * \see gss_svc_free_ctx().
784          */
785         void                    (*free_ctx)    (struct ptlrpc_svc_ctx *ctx);
786
787         /**
788          * Install a reverse context based on the server context \a ctx.
789          *
790          * \see gss_svc_install_rctx_kr().
791          */
792         int                     (*install_rctx)(struct obd_import *imp,
793                                                 struct ptlrpc_svc_ctx *ctx);
794
795         /**
796          * Prepare buffer for incoming bulk write.
797          *
798          * \pre desc->bd_iov and desc->bd_iov_count describes the buffer
799          * intended to receive the write.
800          *
801          * \see gss_svc_prep_bulk().
802          */
803         int                     (*prep_bulk)   (struct ptlrpc_request *req,
804                                                 struct ptlrpc_bulk_desc *desc);
805
806         /**
807          * Unwrap the bulk write data.
808          *
809          * \see plain_svc_unwrap_bulk(), gss_svc_unwrap_bulk().
810          */
811         int                     (*unwrap_bulk) (struct ptlrpc_request *req,
812                                                 struct ptlrpc_bulk_desc *desc);
813
814         /**
815          * Wrap the bulk read data.
816          *
817          * \see plain_svc_wrap_bulk(), gss_svc_wrap_bulk().
818          */
819         int                     (*wrap_bulk)   (struct ptlrpc_request *req,
820                                                 struct ptlrpc_bulk_desc *desc);
821 };
822
823 struct ptlrpc_sec_policy {
824         struct module                  *sp_owner;
825         char                           *sp_name;
826         __u16                           sp_policy; /* policy number */
827         struct ptlrpc_sec_cops         *sp_cops;   /* client ops */
828         struct ptlrpc_sec_sops         *sp_sops;   /* server ops */
829 };
830
831 #define PTLRPC_SEC_FL_REVERSE           0x0001 /* reverse sec */
832 #define PTLRPC_SEC_FL_ROOTONLY          0x0002 /* treat everyone as root */
833 #define PTLRPC_SEC_FL_UDESC             0x0004 /* ship udesc */
834 #define PTLRPC_SEC_FL_BULK              0x0008 /* intensive bulk i/o expected */
835 #define PTLRPC_SEC_FL_PAG               0x0010 /* PAG mode */
836
837 /**
838  * The ptlrpc_sec represents the client side ptlrpc security facilities,
839  * each obd_import (both regular and reverse import) must associate with
840  * a ptlrpc_sec.
841  *
842  * \see sptlrpc_import_sec_adapt().
843  */
844 struct ptlrpc_sec {
845         struct ptlrpc_sec_policy       *ps_policy;
846         atomic_t                        ps_refcount;
847         /** statistic only */
848         atomic_t                        ps_nctx;
849         /** unique identifier */
850         int                             ps_id;
851         struct sptlrpc_flavor           ps_flvr;
852         enum lustre_sec_part            ps_part;
853         /** after set, no more new context will be created */
854         unsigned int                    ps_dying:1;
855         /** owning import */
856         struct obd_import              *ps_import;
857         spinlock_t                      ps_lock;
858
859         /*
860          * garbage collection
861          */
862         struct list_head                ps_gc_list;
863         cfs_time_t                      ps_gc_interval; /* in seconds */
864         cfs_time_t                      ps_gc_next;     /* in seconds */
865 };
866
867 static inline int sec_is_reverse(struct ptlrpc_sec *sec)
868 {
869         return (sec->ps_flvr.sf_flags & PTLRPC_SEC_FL_REVERSE);
870 }
871
872 static inline int sec_is_rootonly(struct ptlrpc_sec *sec)
873 {
874         return (sec->ps_flvr.sf_flags & PTLRPC_SEC_FL_ROOTONLY);
875 }
876
877
878 struct ptlrpc_svc_ctx {
879         atomic_t                        sc_refcount;
880         struct ptlrpc_sec_policy       *sc_policy;
881 };
882
883 /*
884  * user identity descriptor
885  */
886 #define LUSTRE_MAX_GROUPS               (128)
887
888 struct ptlrpc_user_desc {
889         __u32           pud_uid;
890         __u32           pud_gid;
891         __u32           pud_fsuid;
892         __u32           pud_fsgid;
893         __u32           pud_cap;
894         __u32           pud_ngroups;
895         __u32           pud_groups[0];
896 };
897
898 /*
899  * bulk flavors
900  */
901 enum sptlrpc_bulk_hash_alg {
902         BULK_HASH_ALG_NULL      = 0,
903         BULK_HASH_ALG_ADLER32,
904         BULK_HASH_ALG_CRC32,
905         BULK_HASH_ALG_MD5,
906         BULK_HASH_ALG_SHA1,
907         BULK_HASH_ALG_SHA256,
908         BULK_HASH_ALG_SHA384,
909         BULK_HASH_ALG_SHA512,
910         BULK_HASH_ALG_MAX
911 };
912
913 const char * sptlrpc_get_hash_name(__u8 hash_alg);
914 __u8 sptlrpc_get_hash_alg(const char *algname);
915
916 enum {
917         BSD_FL_ERR      = 1,
918 };
919
920 struct ptlrpc_bulk_sec_desc {
921         __u8            bsd_version;    /* 0 */
922         __u8            bsd_type;       /* SPTLRPC_BULK_XXX */
923         __u8            bsd_svc;        /* SPTLRPC_BULK_SVC_XXXX */
924         __u8            bsd_flags;      /* flags */
925         __u32           bsd_nob;        /* nob of bulk data */
926         __u8            bsd_data[0];    /* policy-specific token */
927 };
928
929
930 /*
931  * lprocfs
932  */
933 struct proc_dir_entry;
934 extern struct proc_dir_entry *sptlrpc_proc_root;
935
936 /*
937  * round size up to next power of 2, for slab allocation.
938  * @size must be sane (can't overflow after round up)
939  */
940 static inline int size_roundup_power2(int size)
941 {
942         size--;
943         size |= size >> 1;
944         size |= size >> 2;
945         size |= size >> 4;
946         size |= size >> 8;
947         size |= size >> 16;
948         size++;
949         return size;
950 }
951
952 /*
953  * internal support libraries
954  */
955 void _sptlrpc_enlarge_msg_inplace(struct lustre_msg *msg,
956                                   int segment, int newsize);
957
958 /*
959  * security policies
960  */
961 int sptlrpc_register_policy(struct ptlrpc_sec_policy *policy);
962 int sptlrpc_unregister_policy(struct ptlrpc_sec_policy *policy);
963
964 __u32 sptlrpc_name2flavor_base(const char *name);
965 const char *sptlrpc_flavor2name_base(__u32 flvr);
966 char *sptlrpc_flavor2name_bulk(struct sptlrpc_flavor *sf,
967                                char *buf, int bufsize);
968 char *sptlrpc_flavor2name(struct sptlrpc_flavor *sf, char *buf, int bufsize);
969 char *sptlrpc_secflags2str(__u32 flags, char *buf, int bufsize);
970
971 static inline struct ptlrpc_sec_policy *
972 sptlrpc_policy_get(struct ptlrpc_sec_policy *policy)
973 {
974         __module_get(policy->sp_owner);
975         return policy;
976 }
977
978 static inline void
979 sptlrpc_policy_put(struct ptlrpc_sec_policy *policy)
980 {
981         module_put(policy->sp_owner);
982 }
983
984 /*
985  * client credential
986  */
987 static inline
988 unsigned long cli_ctx_status(struct ptlrpc_cli_ctx *ctx)
989 {
990         return (ctx->cc_flags & PTLRPC_CTX_STATUS_MASK);
991 }
992
993 static inline
994 int cli_ctx_is_ready(struct ptlrpc_cli_ctx *ctx)
995 {
996         return (cli_ctx_status(ctx) == PTLRPC_CTX_UPTODATE);
997 }
998
999 static inline
1000 int cli_ctx_is_refreshed(struct ptlrpc_cli_ctx *ctx)
1001 {
1002         return (cli_ctx_status(ctx) != 0);
1003 }
1004
1005 static inline
1006 int cli_ctx_is_uptodate(struct ptlrpc_cli_ctx *ctx)
1007 {
1008         return ((ctx->cc_flags & PTLRPC_CTX_UPTODATE) != 0);
1009 }
1010
1011 static inline
1012 int cli_ctx_is_error(struct ptlrpc_cli_ctx *ctx)
1013 {
1014         return ((ctx->cc_flags & PTLRPC_CTX_ERROR) != 0);
1015 }
1016
1017 static inline
1018 int cli_ctx_is_dead(struct ptlrpc_cli_ctx *ctx)
1019 {
1020         return ((ctx->cc_flags & (PTLRPC_CTX_DEAD | PTLRPC_CTX_ERROR)) != 0);
1021 }
1022
1023 static inline
1024 int cli_ctx_is_eternal(struct ptlrpc_cli_ctx *ctx)
1025 {
1026         return ((ctx->cc_flags & PTLRPC_CTX_ETERNAL) != 0);
1027 }
1028
1029 /*
1030  * sec get/put
1031  */
1032 struct ptlrpc_sec *sptlrpc_sec_get(struct ptlrpc_sec *sec);
1033 void sptlrpc_sec_put(struct ptlrpc_sec *sec);
1034
1035 /*
1036  * internal apis which only used by policy impelentation
1037  */
1038 int  sptlrpc_get_next_secid(void);
1039 void sptlrpc_sec_destroy(struct ptlrpc_sec *sec);
1040
1041 /*
1042  * exported client context api
1043  */
1044 struct ptlrpc_cli_ctx *sptlrpc_cli_ctx_get(struct ptlrpc_cli_ctx *ctx);
1045 void sptlrpc_cli_ctx_put(struct ptlrpc_cli_ctx *ctx, int sync);
1046 void sptlrpc_cli_ctx_expire(struct ptlrpc_cli_ctx *ctx);
1047 void sptlrpc_cli_ctx_wakeup(struct ptlrpc_cli_ctx *ctx);
1048 int sptlrpc_cli_ctx_display(struct ptlrpc_cli_ctx *ctx, char *buf, int bufsize);
1049
1050 /*
1051  * exported client context wrap/buffers
1052  */
1053 int sptlrpc_cli_wrap_request(struct ptlrpc_request *req);
1054 int sptlrpc_cli_unwrap_reply(struct ptlrpc_request *req);
1055 int sptlrpc_cli_alloc_reqbuf(struct ptlrpc_request *req, int msgsize);
1056 void sptlrpc_cli_free_reqbuf(struct ptlrpc_request *req);
1057 int sptlrpc_cli_alloc_repbuf(struct ptlrpc_request *req, int msgsize);
1058 void sptlrpc_cli_free_repbuf(struct ptlrpc_request *req);
1059 int sptlrpc_cli_enlarge_reqbuf(struct ptlrpc_request *req,
1060                                int segment, int newsize);
1061 int  sptlrpc_cli_unwrap_early_reply(struct ptlrpc_request *req,
1062                                     struct ptlrpc_request **req_ret);
1063 void sptlrpc_cli_finish_early_reply(struct ptlrpc_request *early_req);
1064
1065 void sptlrpc_request_out_callback(struct ptlrpc_request *req);
1066
1067 /*
1068  * exported higher interface of import & request
1069  */
1070 int sptlrpc_import_sec_adapt(struct obd_import *imp,
1071                              struct ptlrpc_svc_ctx *ctx,
1072                              struct sptlrpc_flavor *flvr);
1073 struct ptlrpc_sec *sptlrpc_import_sec_ref(struct obd_import *imp);
1074 void sptlrpc_import_sec_put(struct obd_import *imp);
1075
1076 int  sptlrpc_import_check_ctx(struct obd_import *imp);
1077 void sptlrpc_import_flush_root_ctx(struct obd_import *imp);
1078 void sptlrpc_import_flush_my_ctx(struct obd_import *imp);
1079 void sptlrpc_import_flush_all_ctx(struct obd_import *imp);
1080 int  sptlrpc_req_get_ctx(struct ptlrpc_request *req);
1081 void sptlrpc_req_put_ctx(struct ptlrpc_request *req, int sync);
1082 int  sptlrpc_req_refresh_ctx(struct ptlrpc_request *req, long timeout);
1083 int  sptlrpc_req_replace_dead_ctx(struct ptlrpc_request *req);
1084 void sptlrpc_req_set_flavor(struct ptlrpc_request *req, int opcode);
1085
1086 int sptlrpc_parse_rule(char *param, struct sptlrpc_rule *rule);
1087
1088 /* gc */
1089 void sptlrpc_gc_add_sec(struct ptlrpc_sec *sec);
1090 void sptlrpc_gc_del_sec(struct ptlrpc_sec *sec);
1091 void sptlrpc_gc_add_ctx(struct ptlrpc_cli_ctx *ctx);
1092
1093 /* misc */
1094 const char * sec2target_str(struct ptlrpc_sec *sec);
1095 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev);
1096
1097 /*
1098  * server side
1099  */
1100 enum secsvc_accept_res {
1101         SECSVC_OK       = 0,
1102         SECSVC_COMPLETE,
1103         SECSVC_DROP,
1104 };
1105
1106 int  sptlrpc_svc_unwrap_request(struct ptlrpc_request *req);
1107 int  sptlrpc_svc_alloc_rs(struct ptlrpc_request *req, int msglen);
1108 int  sptlrpc_svc_wrap_reply(struct ptlrpc_request *req);
1109 void sptlrpc_svc_free_rs(struct ptlrpc_reply_state *rs);
1110 void sptlrpc_svc_ctx_addref(struct ptlrpc_request *req);
1111 void sptlrpc_svc_ctx_decref(struct ptlrpc_request *req);
1112 void sptlrpc_svc_ctx_invalidate(struct ptlrpc_request *req);
1113
1114 int  sptlrpc_target_export_check(struct obd_export *exp,
1115                                  struct ptlrpc_request *req);
1116 void sptlrpc_target_update_exp_flavor(struct obd_device *obd,
1117                                       struct sptlrpc_rule_set *rset);
1118
1119 /*
1120  * reverse context
1121  */
1122 int sptlrpc_svc_install_rvs_ctx(struct obd_import *imp,
1123                                 struct ptlrpc_svc_ctx *ctx);
1124 int sptlrpc_cli_install_rvs_ctx(struct obd_import *imp,
1125                                 struct ptlrpc_cli_ctx *ctx);
1126
1127 /* bulk security api */
1128 int sptlrpc_enc_pool_add_user(void);
1129 int sptlrpc_enc_pool_del_user(void);
1130 int  sptlrpc_enc_pool_get_pages(struct ptlrpc_bulk_desc *desc);
1131 void sptlrpc_enc_pool_put_pages(struct ptlrpc_bulk_desc *desc);
1132 int get_free_pages_in_pool(void);
1133 int pool_is_at_full_capacity(void);
1134
1135 int sptlrpc_cli_wrap_bulk(struct ptlrpc_request *req,
1136                           struct ptlrpc_bulk_desc *desc);
1137 int sptlrpc_cli_unwrap_bulk_read(struct ptlrpc_request *req,
1138                                  struct ptlrpc_bulk_desc *desc,
1139                                  int nob);
1140 int sptlrpc_cli_unwrap_bulk_write(struct ptlrpc_request *req,
1141                                   struct ptlrpc_bulk_desc *desc);
1142 #ifdef HAVE_SERVER_SUPPORT
1143 int sptlrpc_svc_prep_bulk(struct ptlrpc_request *req,
1144                           struct ptlrpc_bulk_desc *desc);
1145 int sptlrpc_svc_wrap_bulk(struct ptlrpc_request *req,
1146                           struct ptlrpc_bulk_desc *desc);
1147 int sptlrpc_svc_unwrap_bulk(struct ptlrpc_request *req,
1148                             struct ptlrpc_bulk_desc *desc);
1149 #endif
1150
1151 /* bulk helpers (internal use only by policies) */
1152 int sptlrpc_get_bulk_checksum(struct ptlrpc_bulk_desc *desc, __u8 alg,
1153                               void *buf, int buflen);
1154
1155 int bulk_sec_desc_unpack(struct lustre_msg *msg, int offset, int swabbed);
1156
1157 /* user descriptor helpers */
1158 static inline int sptlrpc_user_desc_size(int ngroups)
1159 {
1160         return sizeof(struct ptlrpc_user_desc) + ngroups * sizeof(__u32);
1161 }
1162
1163 int sptlrpc_current_user_desc_size(void);
1164 int sptlrpc_pack_user_desc(struct lustre_msg *msg, int offset);
1165 int sptlrpc_unpack_user_desc(struct lustre_msg *req, int offset, int swabbed);
1166
1167
1168 #define CFS_CAP_CHOWN_MASK (1 << CFS_CAP_CHOWN)
1169 #define CFS_CAP_SYS_RESOURCE_MASK (1 << CFS_CAP_SYS_RESOURCE)
1170
1171 enum {
1172         LUSTRE_SEC_NONE         = 0,
1173         LUSTRE_SEC_REMOTE       = 1,
1174         LUSTRE_SEC_SPECIFY      = 2,
1175         LUSTRE_SEC_ALL          = 3
1176 };
1177
1178 /** @} sptlrpc */
1179
1180 #endif /* _LUSTRE_SEC_H_ */