Whamcloud - gitweb
LU-9243 gss: fix GSS struct definition badness
[fs/lustre-release.git] / lustre / utils / gss / lgss_keyring.c
index 6748f7c..f34981c 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lustre/utils/gss/lgss_keyring.c
  *
@@ -53,6 +52,7 @@
 
 #include <libcfs/util/param.h>
 #include <libcfs/util/string.h>
+#include <uapi/linux/lustre/lgss.h>
 #include "lsupport.h"
 #include "lgss_utils.h"
 #include "write_bytes.h"
@@ -261,7 +261,7 @@ int do_nego_rpc(struct lgss_nego_data *lnd,
        logmsg(LL_TRACE, "do_nego_rpc: to parse reply\n");
        if (param.status) {
                logmsg(LL_ERR, "status: %ld (%s)\n",
-                      param.status, strerror((int)(-param.status)));
+                      (long int)param.status, strerror((int)(-param.status)));
                return param.status;
        }
 
@@ -902,7 +902,6 @@ out:
 
 static int associate_with_ns(char *path)
 {
-#ifdef HAVE_SETNS
        int fd, rc = -1;
 
        fd = open(path, O_RDONLY);
@@ -912,9 +911,6 @@ static int associate_with_ns(char *path)
        }
 
        return rc;
-#else
-       return -1;
-#endif /* HAVE_SETNS */
 }
 
 static int prepare_and_instantiate(struct lgss_cred *cred, key_serial_t keyid,
@@ -967,10 +963,8 @@ int main(int argc, char *argv[])
        char                          path[PATH_MAX] = "";
        int                           other_ns = 0;
        int                           rc = 0;
-#ifdef HAVE_SETNS
        struct stat                   parent_ns = { .st_ino = 0 };
        struct stat                   caller_ns = { .st_ino = 0 };
-#endif
 
        set_log_level();
 
@@ -1064,25 +1058,32 @@ int main(int argc, char *argv[])
        cred->lc_svc_type = uparam.kup_svc_type;
        cred->lc_self_nid = uparam.kup_selfnid;
 
-#ifdef HAVE_SETNS
        /* Is caller in different namespace? */
-       snprintf(path, sizeof(path), "/proc/%d/ns/mnt", getpid());
-       if (stat(path, &parent_ns))
-               logmsg(LL_ERR, "cannot stat %s: %s\n", path, strerror(errno));
-       snprintf(path, sizeof(path), "/proc/%d/ns/mnt", uparam.kup_pid);
-       if (stat(path, &caller_ns))
-               logmsg(LL_ERR, "cannot stat %s: %s\n", path, strerror(errno));
-       if (caller_ns.st_ino != parent_ns.st_ino) {
-               other_ns = 1;
+       /* If passed caller's pid is 0, it means we have to stick
+        * with current namespace.
+        */
+       if (uparam.kup_pid) {
+               snprintf(path, sizeof(path), "/proc/%d/ns/mnt", getpid());
+               if (stat(path, &parent_ns)) {
+                       logmsg(LL_DEBUG, "cannot stat %s: %s\n",
+                              path, strerror(errno));
+               } else {
+                       snprintf(path, sizeof(path), "/proc/%d/ns/mnt",
+                                uparam.kup_pid);
+                       if (stat(path, &caller_ns))
+                               logmsg(LL_DEBUG, "cannot stat %s: %s\n",
+                                      path, strerror(errno));
+                       else if (caller_ns.st_ino != parent_ns.st_ino)
+                               other_ns = 1;
+               }
        }
-#endif /* HAVE_SETNS */
 
        /*
         * if caller's namespace is different, fork a child and associate it
         * with caller's namespace to do credentials preparation
         */
        if (other_ns) {
-               logmsg(LL_TRACE, "caller's namespace is diffent\n");
+               logmsg(LL_TRACE, "caller's namespace is different\n");
 
                /* use pipes to pass info between child and parent processes */
                if (pipe(req_fd) == -1) {
@@ -1228,7 +1229,10 @@ out_pipe:
                close(reply_fd[1]);
                return rc;
        } else {
-               logmsg(LL_TRACE, "caller's namespace is the same\n");
+               if (uparam.kup_pid)
+                       logmsg(LL_TRACE, "caller's namespace is the same\n");
+               else
+                       logmsg(LL_TRACE, "stick with current namespace\n");
 
                rc = prepare_and_instantiate(cred, keyid, uparam.kup_uid);
                if (rc != 0)