1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Modified from NFSv4 project for Lustre
5 * Copyright 2004 - 2006, Cluster File Systems, Inc.
7 * Author: Eric Mei <ericm@clusterfs.com>
10 #ifndef __PTLRPC_GSS_GSS_INTERNAL_H_
11 #define __PTLRPC_GSS_GSS_INTERNAL_H_
13 #include <lustre_sec.h>
18 typedef struct netobj_s {
23 #define NETOBJ_EMPTY ((netobj_t) { 0 })
25 typedef struct rawobj_s {
30 #define RAWOBJ_EMPTY ((rawobj_t) { 0, NULL })
32 typedef struct rawobj_buf_s {
39 int rawobj_alloc(rawobj_t *obj, char *buf, int len);
40 void rawobj_free(rawobj_t *obj);
41 int rawobj_equal(rawobj_t *a, rawobj_t *b);
42 int rawobj_dup(rawobj_t *dest, rawobj_t *src);
43 int rawobj_serialize(rawobj_t *obj, __u32 **buf, __u32 *buflen);
44 int rawobj_extract(rawobj_t *obj, __u32 **buf, __u32 *buflen);
45 int rawobj_extract_alloc(rawobj_t *obj, __u32 **buf, __u32 *buflen);
46 int rawobj_extract_local(rawobj_t *obj, __u32 **buf, __u32 *buflen);
47 int rawobj_extract_local_alloc(rawobj_t *obj, __u32 **buf, __u32 *buflen);
48 int rawobj_from_netobj(rawobj_t *rawobj, netobj_t *netobj);
49 int rawobj_from_netobj_alloc(rawobj_t *obj, netobj_t *netobj);
51 int buffer_extract_bytes(const void **buf, __u32 *buflen,
52 void *res, __u32 reslen);
55 * several timeout values. client refresh upcall timeout we using
56 * default in pipefs implemnetation.
58 #define __TIMEOUT_DELTA (10)
60 #define GSS_SECINIT_RPC_TIMEOUT \
61 (obd_timeout < __TIMEOUT_DELTA ? \
62 __TIMEOUT_DELTA : obd_timeout - __TIMEOUT_DELTA)
64 #define GSS_SECFINI_RPC_TIMEOUT (__TIMEOUT_DELTA)
65 #define GSS_SECSVC_UPCALL_TIMEOUT (GSS_SECINIT_RPC_TIMEOUT)
70 #define GSS_GC_INTERVAL (60 * 60) /* 60 minutes */
73 unsigned long gss_round_ctx_expiry(unsigned long expiry,
74 unsigned long sec_flags)
76 if (sec_flags & PTLRPC_SEC_FL_REVERSE)
79 if (get_seconds() + __TIMEOUT_DELTA <= expiry)
80 return expiry - __TIMEOUT_DELTA;
86 * Max encryption element in block cipher algorithms.
88 #define GSS_MAX_CIPHER_BLOCK (16)
91 * XXX make it visible of kernel and lgssd/lsvcgssd
93 #define GSSD_INTERFACE_VERSION (1)
95 #define PTLRPC_GSS_VERSION (1)
98 enum ptlrpc_gss_proc {
99 PTLRPC_GSS_PROC_DATA = 0,
100 PTLRPC_GSS_PROC_INIT = 1,
101 PTLRPC_GSS_PROC_CONTINUE_INIT = 2,
102 PTLRPC_GSS_PROC_DESTROY = 3,
103 PTLRPC_GSS_PROC_ERR = 4,
106 enum ptlrpc_gss_tgt {
107 LUSTRE_GSS_TGT_MDS = 0,
108 LUSTRE_GSS_TGT_OSS = 1,
109 LUSTRE_GSS_TGT_MGS = 2,
113 __u32 import_to_gss_svc(struct obd_import *imp)
115 const char *name = imp->imp_obd->obd_type->typ_name;
117 if (!strcmp(name, LUSTRE_MDC_NAME))
118 return LUSTRE_GSS_TGT_MDS;
119 if (!strcmp(name, LUSTRE_OSC_NAME))
120 return LUSTRE_GSS_TGT_OSS;
126 * following 3 header must have the same size and offset
129 __u32 gh_version; /* gss version */
130 __u32 gh_flags; /* wrap flags */
131 __u32 gh_proc; /* proc */
132 __u32 gh_seq; /* sequence */
133 __u32 gh_svc; /* service */
137 netobj_t gh_handle; /* context handle */
140 struct gss_rep_header {
152 struct gss_err_header {
165 * part of wire context information send from client which be saved and
166 * used later by server.
168 struct gss_wire_ctx {
175 #define PTLRPC_GSS_MAX_HANDLE_SIZE (8)
176 #define PTLRPC_GSS_HEADER_SIZE (sizeof(struct gss_header) + \
177 PTLRPC_GSS_MAX_HANDLE_SIZE)
180 #define GSS_SEQ_WIN (2048)
181 #define GSS_SEQ_WIN_MAIN GSS_SEQ_WIN
182 #define GSS_SEQ_WIN_BACK (128)
183 #define GSS_SEQ_REPACK_THRESHOLD (GSS_SEQ_WIN_MAIN / 2 + \
184 GSS_SEQ_WIN_MAIN / 4)
186 struct gss_svc_seq_data {
189 * highest sequence number seen so far, for main and back window
194 * main and back window
195 * for i such that ssd_max - GSS_SEQ_WIN < i <= ssd_max, the i-th bit
196 * of ssd_win is nonzero iff sequence number i has been seen already.
198 unsigned long ssd_win_main[GSS_SEQ_WIN_MAIN/BITS_PER_LONG];
199 unsigned long ssd_win_back[GSS_SEQ_WIN_BACK/BITS_PER_LONG];
203 unsigned int gsc_usr_root:1,
208 uid_t gsc_mapped_uid;
209 rawobj_t gsc_rvs_hdl;
210 struct gss_svc_seq_data gsc_seqdata;
211 struct gss_ctx *gsc_mechctx;
214 struct gss_svc_reqctx {
215 struct ptlrpc_svc_ctx src_base;
219 struct gss_wire_ctx src_wirectx;
220 struct gss_svc_ctx *src_ctx;
222 * record place of bulk_sec_desc in request/reply buffer
224 struct ptlrpc_bulk_sec_desc *src_reqbsd;
226 struct ptlrpc_bulk_sec_desc *src_repbsd;
231 unsigned int src_init:1,
238 struct ptlrpc_cli_ctx gc_base;
244 struct gss_ctx *gc_mechctx;
247 struct gss_cli_ctx_keyring {
248 struct gss_cli_ctx gck_base;
250 struct timer_list *gck_timer;
254 struct ptlrpc_sec gs_base;
255 struct gss_api_mech *gs_mech;
260 struct gss_sec_pipefs {
261 struct gss_sec gsp_base;
262 int gsp_chash_size; /* must be 2^n */
263 struct hlist_head gsp_chash[0];
267 * FIXME cleanup the keyring upcall mutexes
269 #define HAVE_KEYRING_UPCALL_SERIALIZED 1
271 struct gss_sec_keyring {
272 struct gss_sec gsk_base;
278 * all contexts listed here. access is protected by sec spinlock.
280 struct hlist_head gsk_clist;
282 * specially point to root ctx (only one at a time). access is
283 * protected by sec spinlock.
285 struct ptlrpc_cli_ctx *gsk_root_ctx;
287 * specially serialize upcalls for root context.
289 struct mutex gsk_root_uc_lock;
291 #ifdef HAVE_KEYRING_UPCALL_SERIALIZED
292 struct mutex gsk_uc_lock; /* serialize upcalls */
296 static inline struct gss_cli_ctx *ctx2gctx(struct ptlrpc_cli_ctx *ctx)
298 return container_of(ctx, struct gss_cli_ctx, gc_base);
302 struct gss_cli_ctx_keyring *ctx2gctx_keyring(struct ptlrpc_cli_ctx *ctx)
304 return container_of(ctx2gctx(ctx),
305 struct gss_cli_ctx_keyring, gck_base);
308 static inline struct gss_sec *sec2gsec(struct ptlrpc_sec *sec)
310 return container_of(sec, struct gss_sec, gs_base);
313 static inline struct gss_sec_pipefs *sec2gsec_pipefs(struct ptlrpc_sec *sec)
315 return container_of(sec2gsec(sec), struct gss_sec_pipefs, gsp_base);
318 static inline struct gss_sec_keyring *sec2gsec_keyring(struct ptlrpc_sec *sec)
320 return container_of(sec2gsec(sec), struct gss_sec_keyring, gsk_base);
324 #define GSS_CTX_INIT_MAX_LEN (1024)
327 * This only guaranteed be enough for current krb5 des-cbc-crc . We might
328 * adjust this when new enc type or mech added in.
330 #define GSS_PRIVBUF_PREFIX_LEN (32)
331 #define GSS_PRIVBUF_SUFFIX_LEN (32)
334 struct gss_svc_reqctx *gss_svc_ctx2reqctx(struct ptlrpc_svc_ctx *ctx)
337 return container_of(ctx, struct gss_svc_reqctx, src_base);
341 int gss_cli_ctx_match(struct ptlrpc_cli_ctx *ctx, struct vfs_cred *vcred);
342 int gss_cli_ctx_display(struct ptlrpc_cli_ctx *ctx, char *buf, int bufsize);
343 int gss_cli_ctx_sign(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req);
344 int gss_cli_ctx_verify(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req);
345 int gss_cli_ctx_seal(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req);
346 int gss_cli_ctx_unseal(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req);
348 int gss_sec_install_rctx(struct obd_import *imp, struct ptlrpc_sec *sec,
349 struct ptlrpc_cli_ctx *ctx);
350 int gss_alloc_reqbuf(struct ptlrpc_sec *sec, struct ptlrpc_request *req,
352 void gss_free_reqbuf(struct ptlrpc_sec *sec, struct ptlrpc_request *req);
353 int gss_alloc_repbuf(struct ptlrpc_sec *sec, struct ptlrpc_request *req,
355 void gss_free_repbuf(struct ptlrpc_sec *sec, struct ptlrpc_request *req);
356 int gss_enlarge_reqbuf(struct ptlrpc_sec *sec, struct ptlrpc_request *req,
357 int segment, int newsize);
359 int gss_svc_accept(struct ptlrpc_sec_policy *policy,
360 struct ptlrpc_request *req);
361 void gss_svc_invalidate_ctx(struct ptlrpc_svc_ctx *svc_ctx);
362 int gss_svc_alloc_rs(struct ptlrpc_request *req, int msglen);
363 int gss_svc_authorize(struct ptlrpc_request *req);
364 void gss_svc_free_rs(struct ptlrpc_reply_state *rs);
365 void gss_svc_free_ctx(struct ptlrpc_svc_ctx *ctx);
367 int cli_ctx_expire(struct ptlrpc_cli_ctx *ctx);
368 int cli_ctx_check_death(struct ptlrpc_cli_ctx *ctx);
370 int gss_copy_rvc_cli_ctx(struct ptlrpc_cli_ctx *cli_ctx,
371 struct ptlrpc_svc_ctx *svc_ctx);
373 struct gss_header *gss_swab_header(struct lustre_msg *msg, int segment);
374 netobj_t *gss_swab_netobj(struct lustre_msg *msg, int segment);
376 void gss_cli_ctx_uptodate(struct gss_cli_ctx *gctx);
377 int gss_pack_err_notify(struct ptlrpc_request *req, __u32 major, __u32 minor);
378 int gss_check_seq_num(struct gss_svc_seq_data *sd, __u32 seq_num, int set);
380 int gss_sec_create_common(struct gss_sec *gsec,
381 struct ptlrpc_sec_policy *policy,
382 struct obd_import *imp,
383 struct ptlrpc_svc_ctx *ctx,
385 unsigned long flags);
386 void gss_sec_destroy_common(struct gss_sec *gsec);
388 int gss_cli_ctx_init_common(struct ptlrpc_sec *sec,
389 struct ptlrpc_cli_ctx *ctx,
390 struct ptlrpc_ctx_ops *ctxops,
391 struct vfs_cred *vcred);
392 int gss_cli_ctx_fini_common(struct ptlrpc_sec *sec,
393 struct ptlrpc_cli_ctx *ctx);
395 void gss_cli_ctx_flags2str(unsigned long flags, char *buf, int bufsize);
398 extern struct ptlrpc_sec_policy gss_policy_keyring;
399 int __init gss_init_keyring(void);
400 void __exit gss_exit_keyring(void);
403 int __init gss_init_pipefs(void);
404 void __exit gss_exit_pipefs(void);
407 int gss_cli_ctx_wrap_bulk(struct ptlrpc_cli_ctx *ctx,
408 struct ptlrpc_request *req,
409 struct ptlrpc_bulk_desc *desc);
410 int gss_cli_ctx_unwrap_bulk(struct ptlrpc_cli_ctx *ctx,
411 struct ptlrpc_request *req,
412 struct ptlrpc_bulk_desc *desc);
413 int gss_svc_unwrap_bulk(struct ptlrpc_request *req,
414 struct ptlrpc_bulk_desc *desc);
415 int gss_svc_wrap_bulk(struct ptlrpc_request *req,
416 struct ptlrpc_bulk_desc *desc);
418 /* gss_mech_switch.c */
419 int init_kerberos_module(void);
420 void cleanup_kerberos_module(void);
422 /* gss_generic_token.c */
423 int g_token_size(rawobj_t *mech, unsigned int body_size);
424 void g_make_token_header(rawobj_t *mech, int body_size, unsigned char **buf);
425 __u32 g_verify_token_header(rawobj_t *mech, int *body_size,
426 unsigned char **buf_in, int toksize);
429 /* gss_cli_upcall.c */
430 int gss_do_ctx_init_rpc(char *buffer, unsigned long count);
431 int gss_do_ctx_fini_rpc(struct gss_cli_ctx *gctx);
433 int __init gss_init_cli_upcall(void);
434 void __exit gss_exit_cli_upcall(void);
436 /* gss_svc_upcall.c */
437 __u64 gss_get_next_ctx_index(void);
438 int gss_svc_upcall_install_rvs_ctx(struct obd_import *imp,
439 struct gss_sec *gsec,
440 struct gss_cli_ctx *gctx);
441 int gss_svc_upcall_handle_init(struct ptlrpc_request *req,
442 struct gss_svc_reqctx *grctx,
443 struct gss_wire_ctx *gw,
444 struct obd_device *target,
448 struct gss_svc_ctx *gss_svc_upcall_get_ctx(struct ptlrpc_request *req,
449 struct gss_wire_ctx *gw);
450 void gss_svc_upcall_put_ctx(struct gss_svc_ctx *ctx);
451 void gss_svc_upcall_destroy_ctx(struct gss_svc_ctx *ctx);
453 int __init gss_init_svc_upcall(void);
454 void __exit gss_exit_svc_upcall(void);
457 void gss_stat_oos_record_cli(int behind);
458 void gss_stat_oos_record_svc(int phase, int replay);
460 int __init gss_init_lproc(void);
461 void __exit gss_exit_lproc(void);
463 /* gss_krb5_mech.c */
464 int __init init_kerberos_module(void);
465 void __exit cleanup_kerberos_module(void);
470 void __dbg_memdump(char *name, void *ptr, int size)
472 char *buf, *p = (char *) ptr;
473 int bufsize = size * 2 + 1, i;
475 OBD_ALLOC(buf, bufsize);
477 printk("DUMP ERROR: can't alloc %d bytes\n", bufsize);
481 for (i = 0; i < size; i++)
482 sprintf(&buf[i+i], "%02x", (__u8) p[i]);
483 buf[size + size] = '\0';
484 printk("DUMP %s@%p(%d): %s\n", name, ptr, size, buf);
485 OBD_FREE(buf, bufsize);
488 #endif /* __PTLRPC_GSS_GSS_INTERNAL_H_ */