Whamcloud - gitweb
LU-6490 gss: handle struct key_type match replacement
[fs/lustre-release.git] / lustre / ptlrpc / gss / gss_keyring.c
index c0438e9..e722d3c 100644 (file)
@@ -73,7 +73,7 @@ static int sec_install_rctx_kr(struct ptlrpc_sec *sec,
 /*
  * the timeout is only for the case that upcall child process die abnormally.
  * in any other cases it should finally update kernel key.
- * 
+ *
  * FIXME we'd better to incorporate the client & server side upcall timeouts
  * into the framework of Adaptive Timeouts, but we need to figure out how to
  * make sure that kernel knows the upcall processes is in-progress or died
@@ -118,7 +118,11 @@ static int sec_install_rctx_kr(struct ptlrpc_sec *sec,
 }
 
 #define key_cred(tsk)   ((tsk)->cred)
+#ifdef HAVE_CRED_TGCRED
 #define key_tgcred(tsk) ((tsk)->cred->tgcred)
+#else
+#define key_tgcred(tsk) key_cred(tsk)
+#endif
 
 static inline void keyring_upcall_lock(struct gss_sec_keyring *gsec_kr)
 {
@@ -747,6 +751,17 @@ struct ptlrpc_cli_ctx * gss_sec_lookup_ctx_kr(struct ptlrpc_sec *sec,
          * encode real uid/gid into callout info.
          */
 
+       /* But first we need to make sure the obd type is supported */
+       if (strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
+           strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
+           strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_MGC_NAME) &&
+           strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_LWP_NAME) &&
+           strcmp(imp->imp_obd->obd_type->typ_name, LUSTRE_OSP_NAME)) {
+               CERROR("obd %s is not a supported device\n",
+                       imp->imp_obd->obd_name);
+               GOTO(out, ctx = NULL);
+       }
+
         construct_key_desc(desc, sizeof(desc), sec, vcred->vc_uid);
 
         /* callout info format:
@@ -1217,8 +1232,15 @@ int gss_svc_install_rctx_kr(struct obd_import *imp,
  ****************************************/
 
 static
+#ifdef HAVE_KEY_TYPE_INSTANTIATE_2ARGS
+int gss_kt_instantiate(struct key *key, struct key_preparsed_payload *prep)
+{
+       const void     *data = prep->data;
+       size_t          datalen = prep->datalen;
+#else
 int gss_kt_instantiate(struct key *key, const void *data, size_t datalen)
 {
+#endif
         int             rc;
         ENTRY;
 
@@ -1263,19 +1285,26 @@ int gss_kt_instantiate(struct key *key, const void *data, size_t datalen)
  * on the context without fear of loosing refcount.
  */
 static
+#ifdef HAVE_KEY_TYPE_INSTANTIATE_2ARGS
+int gss_kt_update(struct key *key, struct key_preparsed_payload *prep)
+{
+       const void              *data = prep->data;
+       __u32                    datalen32 = (__u32) prep->datalen;
+#else
 int gss_kt_update(struct key *key, const void *data, size_t datalen)
 {
+       __u32                    datalen32 = (__u32) datalen;
+#endif
         struct ptlrpc_cli_ctx   *ctx = key->payload.data;
         struct gss_cli_ctx      *gctx;
         rawobj_t                 tmpobj = RAWOBJ_EMPTY;
-        __u32                    datalen32 = (__u32) datalen;
         int                      rc;
         ENTRY;
 
-        if (data == NULL || datalen == 0) {
-                CWARN("invalid: data %p, len %lu\n", data, (long)datalen);
-                RETURN(-EINVAL);
-        }
+       if (data == NULL || datalen32 == 0) {
+               CWARN("invalid: data %p, len %lu\n", data, (long)datalen32);
+               RETURN(-EINVAL);
+       }
 
         /* if upcall finished negotiation too fast (mostly likely because
          * of local error happened) and call kt_update(), the ctx
@@ -1379,11 +1408,31 @@ out:
         RETURN(0);
 }
 
-static
-int gss_kt_match(const struct key *key, const void *desc)
+#ifndef HAVE_KEY_MATCH_DATA
+static int
+gss_kt_match(const struct key *key, const void *desc)
+{
+       return (strcmp(key->description, (const char *) desc) == 0);
+}
+#else /* ! HAVE_KEY_MATCH_DATA */
+static bool
+gss_kt_match(const struct key *key, const struct key_match_data *match_data)
+{
+       const char *desc = match_data->raw_data;
+
+       return (strcmp(key->description, desc) == 0);
+}
+
+/*
+ * Preparse the match criterion.
+ */
+static int gss_kt_match_preparse(struct key_match_data *match_data)
 {
-        return (strcmp(key->description, (const char *) desc) == 0);
+       match_data->lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT;
+       match_data->cmp = gss_kt_match;
+       return 0;
 }
+#endif /* HAVE_KEY_MATCH_DATA */
 
 static
 void gss_kt_destroy(struct key *key)
@@ -1405,13 +1454,17 @@ void gss_kt_describe(const struct key *key, struct seq_file *s)
 
 static struct key_type gss_key_type =
 {
-        .name           = "lgssc",
-        .def_datalen    = 0,
-        .instantiate    = gss_kt_instantiate,
-        .update         = gss_kt_update,
-        .match          = gss_kt_match,
-        .destroy        = gss_kt_destroy,
-        .describe       = gss_kt_describe,
+       .name           = "lgssc",
+       .def_datalen    = 0,
+       .instantiate    = gss_kt_instantiate,
+       .update         = gss_kt_update,
+#ifdef HAVE_KEY_MATCH_DATA
+       .match_preparse = gss_kt_match_preparse,
+#else
+       .match          = gss_kt_match,
+#endif
+       .destroy        = gss_kt_destroy,
+       .describe       = gss_kt_describe,
 };
 
 /****************************************