Whamcloud - gitweb
Branch: HEAD
[fs/lustre-release.git] / lustre / ptlrpc / gss / gss_internal.h
index 0202d94..66afd61 100644 (file)
@@ -2,8 +2,9 @@
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
  * Modified from NFSv4 project for Lustre
- * Copyright 2004 - 2006, Cluster File Systems, Inc.
- * All rights reserved
+ *
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ *
  * Author: Eric Mei <ericm@clusterfs.com>
  */
 
@@ -36,6 +37,7 @@ typedef struct rawobj_buf_s {
         __u8           *buf;
 } rawobj_buf_t;
 
+int rawobj_empty(rawobj_t *obj);
 int rawobj_alloc(rawobj_t *obj, char *buf, int len);
 void rawobj_free(rawobj_t *obj);
 int rawobj_equal(rawobj_t *a, rawobj_t *b);
@@ -82,27 +84,6 @@ unsigned long gss_round_ctx_expiry(unsigned long expiry,
         return expiry;
 }
 
-/* we try to force reconnect import 20m eariler than real expiry.
- * kerberos 5 usually allow 5m time skew, but which is adjustable,
- * so if we set krb5 to allow > 20m time skew, we have chance that
- * server's reverse ctx expired but client still hasn't start to
- * refresh it -- it's BAD. So here we actually put a limit on the
- * enviroment of krb5 (or other authentication mechanism)
- */
-#define GSS_MAX_TIME_SKEW       (20 * 60)
-
-static inline
-unsigned long gss_round_imp_reconnect(unsigned long expiry)
-{
-        unsigned long now = get_seconds();
-        unsigned long nice = GSS_MAX_TIME_SKEW + __TIMEOUT_DELTA;
-
-        while (nice && (now + nice >= expiry))
-                nice = nice / 2;
-
-        return (expiry - nice);
-}
-
 /*
  * Max encryption element in block cipher algorithms.
  */
@@ -124,15 +105,15 @@ enum ptlrpc_gss_proc {
         PTLRPC_GSS_PROC_ERR             = 4,
 };
 
-enum ptlrpc_gss_svc {
-        PTLRPC_GSS_SVC_NONE             = 1,
-        PTLRPC_GSS_SVC_INTEGRITY        = 2,
-        PTLRPC_GSS_SVC_PRIVACY          = 3,
+enum ptlrpc_gss_tgt {
+        LUSTRE_GSS_TGT_MGS              = 0,
+        LUSTRE_GSS_TGT_MDS              = 1,
+        LUSTRE_GSS_TGT_OSS              = 2,
 };
 
-enum ptlrpc_gss_tgt {
-        LUSTRE_GSS_TGT_MDS              = 0,
-        LUSTRE_GSS_TGT_OSS              = 1,
+enum ptlrpc_gss_header_flags {
+        LUSTRE_GSS_PACK_BULK            = 1,
+        LUSTRE_GSS_PACK_USER            = 2,
 };
 
 static inline
@@ -140,6 +121,8 @@ __u32 import_to_gss_svc(struct obd_import *imp)
 {
         const char *name = imp->imp_obd->obd_type->typ_name;
 
+        if (!strcmp(name, LUSTRE_MGC_NAME))
+                return LUSTRE_GSS_TGT_MGS;
         if (!strcmp(name, LUSTRE_MDC_NAME))
                 return LUSTRE_GSS_TGT_MDS;
         if (!strcmp(name, LUSTRE_OSC_NAME))
@@ -152,7 +135,9 @@ __u32 import_to_gss_svc(struct obd_import *imp)
  * following 3 header must have the same size and offset
  */
 struct gss_header {
-        __u32                   gh_version;     /* gss version */
+        __u8                    gh_version;     /* gss version */
+        __u8                    gh_sp;          /* sec part */
+        __u16                   gh_pad0;
         __u32                   gh_flags;       /* wrap flags */
         __u32                   gh_proc;        /* proc */
         __u32                   gh_seq;         /* sequence */
@@ -164,7 +149,9 @@ struct gss_header {
 };
 
 struct gss_rep_header {
-        __u32                   gh_version;
+        __u8                    gh_version;
+        __u8                    gh_sp;
+        __u16                   gh_pad0;
         __u32                   gh_flags;
         __u32                   gh_proc;
         __u32                   gh_major;
@@ -176,7 +163,9 @@ struct gss_rep_header {
 };
 
 struct gss_err_header {
-        __u32                   gh_version;
+        __u8                    gh_version;
+        __u8                    gh_sp;
+        __u16                   gh_pad0;
         __u32                   gh_flags;
         __u32                   gh_proc;
         __u32                   gh_major;
@@ -192,6 +181,7 @@ struct gss_err_header {
  * used later by server.
  */
 struct gss_wire_ctx {
+        __u32                   gw_flags;
         __u32                   gw_proc;
         __u32                   gw_seq;
         __u32                   gw_svc;
@@ -203,6 +193,13 @@ struct gss_wire_ctx {
                                          PTLRPC_GSS_MAX_HANDLE_SIZE)
 
 
+static inline __u64 gss_handle_to_u64(rawobj_t *handle)
+{
+        if (handle->len != PTLRPC_GSS_MAX_HANDLE_SIZE)
+                return -1;
+        return *((__u64 *) handle->data);
+}
+
 #define GSS_SEQ_WIN                     (2048)
 #define GSS_SEQ_WIN_MAIN                GSS_SEQ_WIN
 #define GSS_SEQ_WIN_BACK                (128)
@@ -226,25 +223,40 @@ struct gss_svc_seq_data {
 };
 
 struct gss_svc_ctx {
-        unsigned int            gsc_usr_root:1,
-                                gsc_usr_mds:1,
-                                gsc_remote:1;
+        struct gss_ctx         *gsc_mechctx;
+        struct gss_svc_seq_data gsc_seqdata;
+        rawobj_t                gsc_rvs_hdl;
+        __u32                   gsc_rvs_seq;
         uid_t                   gsc_uid;
         gid_t                   gsc_gid;
         uid_t                   gsc_mapped_uid;
-        rawobj_t                gsc_rvs_hdl;
-        struct gss_svc_seq_data gsc_seqdata;
-        struct gss_ctx         *gsc_mechctx;
+        unsigned int            gsc_usr_root:1,
+                                gsc_usr_mds:1,
+                                gsc_remote:1,
+                                gsc_reverse:1;
 };
 
 struct gss_svc_reqctx {
-        struct ptlrpc_svc_ctx   src_base;
-        struct gss_wire_ctx     src_wirectx;
-        struct gss_svc_ctx     *src_ctx;
-        unsigned int            src_init:1,
-                                src_init_continue:1,
-                                src_err_notify:1;
-        int                     src_reserve_len;
+        struct ptlrpc_svc_ctx           src_base;
+        /*
+         * context
+         */
+        struct gss_wire_ctx             src_wirectx;
+        struct gss_svc_ctx             *src_ctx;
+        /*
+         * record place of bulk_sec_desc in request/reply buffer
+         */
+        struct ptlrpc_bulk_sec_desc    *src_reqbsd;
+        int                             src_reqbsd_size;
+        struct ptlrpc_bulk_sec_desc    *src_repbsd;
+        int                             src_repbsd_size;
+        /*
+         * flags
+         */
+        unsigned int                    src_init:1,
+                                        src_init_continue:1,
+                                        src_err_notify:1;
+        int                             src_reserve_len;
 };
 
 struct gss_cli_ctx {
@@ -255,6 +267,8 @@ struct gss_cli_ctx {
         atomic_t                gc_seq;
         rawobj_t                gc_handle;
         struct gss_ctx         *gc_mechctx;
+        /* handle for the buddy svc ctx */
+        rawobj_t                gc_svc_handle;
 };
 
 struct gss_cli_ctx_keyring {
@@ -284,10 +298,6 @@ struct gss_sec_pipefs {
 struct gss_sec_keyring {
         struct gss_sec          gsk_base;
         /*
-         * unique sec_id.
-         */
-        int                     gsk_id;
-        /*
          * all contexts listed here. access is protected by sec spinlock.
          */
         struct hlist_head       gsk_clist;
@@ -350,6 +360,13 @@ struct gss_svc_reqctx *gss_svc_ctx2reqctx(struct ptlrpc_svc_ctx *ctx)
         return container_of(ctx, struct gss_svc_reqctx, src_base);
 }
 
+static inline
+struct gss_svc_ctx *gss_svc_ctx2gssctx(struct ptlrpc_svc_ctx *ctx)
+{
+        LASSERT(ctx);
+        return gss_svc_ctx2reqctx(ctx)->src_ctx;
+}
+
 /* sec_gss.c */
 int gss_cli_ctx_match(struct ptlrpc_cli_ctx *ctx, struct vfs_cred *vcred);
 int gss_cli_ctx_display(struct ptlrpc_cli_ctx *ctx, char *buf, int bufsize);
@@ -394,9 +411,9 @@ int gss_sec_create_common(struct gss_sec *gsec,
                           struct ptlrpc_sec_policy *policy,
                           struct obd_import *imp,
                           struct ptlrpc_svc_ctx *ctx,
-                          __u32 flavor,
-                          unsigned long flags);
+                          struct sptlrpc_flavor *sf);
 void gss_sec_destroy_common(struct gss_sec *gsec);
+void gss_sec_kill(struct ptlrpc_sec *sec);
 
 int gss_cli_ctx_init_common(struct ptlrpc_sec *sec,
                             struct ptlrpc_cli_ctx *ctx,
@@ -405,8 +422,9 @@ int gss_cli_ctx_init_common(struct ptlrpc_sec *sec,
 int gss_cli_ctx_fini_common(struct ptlrpc_sec *sec,
                             struct ptlrpc_cli_ctx *ctx);
 
+void gss_cli_ctx_flags2str(unsigned long flags, char *buf, int bufsize);
+
 /* gss_keyring.c */
-extern struct ptlrpc_sec_policy gss_policy_keyring;
 int  __init gss_init_keyring(void);
 void __exit gss_exit_keyring(void);
 
@@ -415,12 +433,16 @@ int  __init gss_init_pipefs(void);
 void __exit gss_exit_pipefs(void);
 
 /* gss_bulk.c */
+int gss_cli_prep_bulk(struct ptlrpc_request *req,
+                      struct ptlrpc_bulk_desc *desc);
 int gss_cli_ctx_wrap_bulk(struct ptlrpc_cli_ctx *ctx,
                           struct ptlrpc_request *req,
                           struct ptlrpc_bulk_desc *desc);
 int gss_cli_ctx_unwrap_bulk(struct ptlrpc_cli_ctx *ctx,
                             struct ptlrpc_request *req,
                             struct ptlrpc_bulk_desc *desc);
+int gss_svc_prep_bulk(struct ptlrpc_request *req,
+                      struct ptlrpc_bulk_desc *desc);
 int gss_svc_unwrap_bulk(struct ptlrpc_request *req,
                         struct ptlrpc_bulk_desc *desc);
 int gss_svc_wrap_bulk(struct ptlrpc_request *req,
@@ -449,6 +471,9 @@ __u64 gss_get_next_ctx_index(void);
 int gss_svc_upcall_install_rvs_ctx(struct obd_import *imp,
                                    struct gss_sec *gsec,
                                    struct gss_cli_ctx *gctx);
+int gss_svc_upcall_expire_rvs_ctx(rawobj_t *handle);
+int gss_svc_upcall_dup_handle(rawobj_t *handle, struct gss_svc_ctx *ctx);
+int gss_svc_upcall_update_sequence(rawobj_t *handle, __u32 seq);
 int gss_svc_upcall_handle_init(struct ptlrpc_request *req,
                                struct gss_svc_reqctx *grctx,
                                struct gss_wire_ctx *gw,
@@ -485,14 +510,14 @@ void __dbg_memdump(char *name, void *ptr, int size)
 
         OBD_ALLOC(buf, bufsize);
         if (!buf) {
-                printk("DUMP ERROR: can't alloc %d bytes\n", bufsize);
+                CDEBUG(D_ERROR, "DUMP ERROR: can't alloc %d bytes\n", bufsize);
                 return;
         }
 
         for (i = 0; i < size; i++)
                 sprintf(&buf[i+i], "%02x", (__u8) p[i]);
         buf[size + size] = '\0';
-        printk("DUMP %s@%p(%d): %s\n", name, ptr, size, buf);
+        LCONSOLE_INFO("DUMP %s@%p(%d): %s\n", name, ptr, size, buf);
         OBD_FREE(buf, bufsize);
 }