Whamcloud - gitweb
LU-5030 utils: migrate most lustre utils to use cfs_get_paths()
[fs/lustre-release.git] / lustre / utils / gss / svcgssd_proc.c
index 22f2f17..588b524 100644 (file)
@@ -6,6 +6,8 @@
 
   Copyright (c) 2002 Bruce Fields <bfields@UMICH.EDU>
 
+  Copyright (c) 2014, Intel Corporation.
+
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:
@@ -36,6 +38,7 @@
 #include <sys/param.h>
 #include <sys/stat.h>
 
+#include <inttypes.h>
 #include <pwd.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -43,7 +46,9 @@
 #include <string.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <netdb.h>
+#ifdef HAVE_NETDB_H
+# include <netdb.h>
+#endif
 
 #include "svcgssd.h"
 #include "gss_util.h"
@@ -269,15 +274,15 @@ print_hexl(int pri, unsigned char *cp, int length)
        printerr(pri, "\n");
 
        for (i = 0; i < length; i += 0x10) {
-               printerr(pri, "  %04x: ", (u_int)i);
+               printerr(pri, "  %04x: ", (unsigned int)i);
                jm = length - i;
                jm = jm > 16 ? 16 : jm;
 
                for (j = 0; j < jm; j++) {
                        if ((j % 2) == 1)
-                               printerr(pri,"%02x ", (u_int)cp[i+j]);
+                               printerr(pri, "%02x ", (unsigned int)cp[i+j]);
                        else
-                               printerr(pri,"%02x", (u_int)cp[i+j]);
+                               printerr(pri, "%02x", (unsigned int)cp[i+j]);
                }
                for (; j < 16; j++) {
                        if ((j % 2) == 1)
@@ -322,12 +327,13 @@ get_ids(gss_name_t client_name, gss_OID mech, struct svc_cred *cred,
        }
        if (name.length >= 0xffff || /* be certain name.length+1 doesn't overflow */
            !(sname = calloc(name.length + 1, 1))) {
-               printerr(0, "WARNING: get_ids: error allocating %d bytes "
+               printerr(0, "WARNING: get_ids: error allocating %zu bytes "
                        "for sname\n", name.length + 1);
                gss_release_buffer(&min_stat, &name);
                return -1;
        }
        memcpy(sname, name.value, name.length);
+       sname[name.length] = '\0';
        gss_release_buffer(&min_stat, &name);
 
        if (lustre_svc == LUSTRE_GSS_SVC_MDS)
@@ -398,9 +404,8 @@ get_ids(gss_name_t client_name, gss_OID mech, struct svc_cred *cred,
                                cred->cr_uid = 0;
                                cred->cr_usr_mds = 1;
                        } else if (!strcmp(sname, GSSD_SERVICE_OSS)) {
-                               printerr(0, "ERROR: MDS doesn't accept "
-                                        "user "GSSD_SERVICE_OSS"\n");
-                               break;
+                               cred->cr_uid = 0;
+                               cred->cr_usr_oss = 1;
                        } else {
                                pw = getpwnam(sname);
                                if (pw != NULL) {
@@ -435,8 +440,9 @@ get_ids(gss_name_t client_name, gss_OID mech, struct svc_cred *cred,
                } else if (!strcmp(sname, GSSD_SERVICE_MDS)) {
                        cred->cr_uid = 0;
                        cred->cr_usr_mds = 1;
-               } else {
-                       printerr(0, "ERROR: svc %d doesn't accept user %s"
+               }
+               if (cred->cr_uid == -1) {
+                       printerr(0, "ERROR: svc %d doesn't accept user %s "
                                 "from %016llx\n", lustre_svc, sname, nid);
                        break;
                }
@@ -506,7 +512,7 @@ handle_nullreq(FILE *f) {
        qword_get(&cp, (char *) &lustre_svc, sizeof(lustre_svc));
        qword_get(&cp, (char *) &nid, sizeof(nid));
        qword_get(&cp, (char *) &handle_seq, sizeof(handle_seq));
-       printerr(2, "handling req: svc %u, nid %016llx, idx %llx\n",
+       printerr(2, "handling req: svc %u, nid %016llx, idx %"PRIx64"\n",
                 lustre_svc, nid, handle_seq);
 
        get_len = qword_get(&cp, in_handle.value, sizeof(in_handle_buf));
@@ -534,7 +540,7 @@ handle_nullreq(FILE *f) {
        if (in_handle.length != 0) { /* CONTINUE_INIT case */
                if (in_handle.length != sizeof(ctx)) {
                        printerr(0, "WARNING: handle_nullreq: "
-                                   "input handle has unexpected length %d\n",
+                                   "input handle has unexpected length %zu\n",
                                    in_handle.length);
                        goto out_err;
                }