Whamcloud - gitweb
LU-1347 build: remove the vim/emacs modelines
[fs/lustre-release.git] / lustre / utils / gss / lgss_keyring.c
index 840e14c..4091861 100644 (file)
@@ -1,29 +1,43 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *  lucall_keyring.c
- *  user-space upcall to create GSS context, using keyring interface to kernel
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
  *
- *  Copyright (c) 2007 Cluster File Systems, Inc.
- *   Author: Eric Mei <ericm@clusterfs.com>
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
  *
- *   This file is part of the Lustre file system, http://www.lustre.org
- *   Lustre is a trademark of Cluster File Systems, Inc.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
  *
- *   You may have signed or agreed to another license before downloading
- *   this software.  If so, you are bound by the terms and conditions
- *   of that agreement, and the following does not apply to you.  See the
- *   LICENSE file included with this distribution for more information.
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
  *
- *   If you did not agree to a different license, then this copy of Lustre
- *   is open source software; you can redistribute it and/or modify it
- *   under the terms of version 2 of the GNU General Public License as
- *   published by the Free Software Foundation.
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
  *
- *   In either case, Lustre is distributed in the hope that it will be
- *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   license text for more details.
+ * Copyright (c) 2011, Whamcloud, Inc.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lustre/utils/gss/lgss_keyring.c
+ *
+ * user-space upcall to create GSS context, using keyring interface to kernel
+ *
+ * Author: Eric Mei <ericm@clusterfs.com>
  */
 
 #include <unistd.h>
@@ -36,8 +50,6 @@
 #include <keyutils.h>
 #include <gssapi/gssapi.h>
 
-#include <libcfs/libcfs.h>
-
 #include "lsupport.h"
 #include "lgss_utils.h"
 #include "write_bytes.h"
@@ -93,8 +105,9 @@ struct keyring_upcall_param {
         uint64_t        kup_nid;
         char            kup_tgt[64];
         char            kup_mech[16];
-        int             kup_is_root;
-        int             kup_is_mds;
+        unsigned int    kup_is_root:1,
+                        kup_is_mdt:1,
+                        kup_is_ost:1;
 };
 
 /****************************************
@@ -461,7 +474,7 @@ static int lgssc_kr_negotiate(key_serial_t keyid, struct lgss_cred *cred,
         int                     rc = -1;
 
         logmsg(LL_TRACE, "child start on behalf of key %08x: "
-               "cred %p, uid %u, svc %u, nid %Lx, uids: %u:%u/%u:%u\n",
+               "cred %p, uid %u, svc %u, nid %llx, uids: %u:%u/%u:%u\n",
                keyid, cred, cred->lc_uid, cred->lc_tgt_svc, cred->lc_tgt_nid,
                kup->kup_uid, kup->kup_gid, kup->kup_fsuid, kup->kup_fsgid);
 
@@ -523,7 +536,7 @@ out_cred:
  *  [1]: mech_name      (string)
  *  [2]: uid            (uint)
  *  [3]: gid            (uint)
- *  [4]: flags          (chars) FMT: r-root; m-mds
+ *  [4]: flags          (string) FMT: r-root; m-mdt; o-ost
  *  [5]: lustre_svc     (uint)
  *  [6]: target_nid     (uint64)
  *  [7]: target_uuid    (string)
@@ -569,20 +582,44 @@ static int parse_callout_info(const char *coinfo,
         if (strchr(data[4], 'r'))
                 uparam->kup_is_root = 1;
         if (strchr(data[4], 'm'))
-                uparam->kup_is_mds = 1;
+                uparam->kup_is_mdt = 1;
+        if (strchr(data[4], 'o'))
+                uparam->kup_is_ost = 1;
         uparam->kup_svc = strtol(data[5], NULL, 0);
         uparam->kup_nid = strtoll(data[6], NULL, 0);
         strncpy(uparam->kup_tgt, data[7], sizeof(uparam->kup_tgt));
 
         logmsg(LL_DEBUG, "parse call out info: secid %d, mech %s, ugid %u:%u "
-               "is_root %d, is_mds %d, svc %d, nid 0x%Lx, tgt %s\n",
+               "is_root %d, is_mdt %d, is_ost %d, svc %d, nid 0x%llx, tgt %s\n",
                uparam->kup_secid, uparam->kup_mech,
                uparam->kup_uid, uparam->kup_gid,
-               uparam->kup_is_root, uparam->kup_is_mds, uparam->kup_svc,
-               uparam->kup_nid, uparam->kup_tgt);
+               uparam->kup_is_root, uparam->kup_is_mdt, uparam->kup_is_ost,
+               uparam->kup_svc, uparam->kup_nid, uparam->kup_tgt);
         return 0;
 }
 
+#define LOG_LEVEL_PATH  "/proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level"
+
+static void set_log_level()
+{
+        FILE         *file;
+        unsigned int  level;
+
+        file = fopen(LOG_LEVEL_PATH, "r");
+        if (file == NULL)
+                return;
+
+        if (fscanf(file, "%u", &level) != 1)
+                goto out;
+
+        if (level >= LL_MAX)
+                goto out;
+
+        lgss_set_loglevel(level);
+out:
+        fclose(file);
+}
+
 /****************************************
  * main process                         *
  ****************************************/
@@ -597,6 +634,9 @@ int main(int argc, char *argv[])
         struct lgss_mech_type          *mech;
         struct lgss_cred               *cred;
 
+        set_log_level();
+
+        logmsg(LL_TRACE, "start parsing parameters\n");
         /*
          * parse & sanity check upcall parameters
          * expected to be called with:
@@ -677,8 +717,9 @@ int main(int argc, char *argv[])
         }
 
         cred->lc_uid = uparam.kup_uid;
-        cred->lc_fl_root = (uparam.kup_is_root != 0);
-        cred->lc_fl_mds = (uparam.kup_is_mds != 0);
+        cred->lc_root_flags |= uparam.kup_is_root ? LGSS_ROOT_CRED_ROOT : 0;
+        cred->lc_root_flags |= uparam.kup_is_mdt ? LGSS_ROOT_CRED_MDT : 0;
+        cred->lc_root_flags |= uparam.kup_is_ost ? LGSS_ROOT_CRED_OST : 0;
         cred->lc_tgt_nid = uparam.kup_nid;
         cred->lc_tgt_svc = uparam.kup_svc;
 
@@ -694,7 +735,7 @@ int main(int argc, char *argv[])
          * on it, and share it among all root sessions; otherswise link to
          * session keyring.
          */
-        if (cred->lc_fl_root || cred->lc_fl_mds)
+        if (cred->lc_root_flags != 0)
                 inst_keyring = 0;
         else
                 inst_keyring = KEY_SPEC_SESSION_KEYRING;