]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
nfsidmap: Added Error Logging
authorSteve Dickson <steved@redhat.com>
Fri, 11 Nov 2011 18:11:17 +0000 (13:11 -0500)
committerSteve Dickson <steved@redhat.com>
Mon, 14 Nov 2011 21:08:12 +0000 (16:08 -0500)
Since this binary is being called by the kernel, errors
need to be logged to the syslog for help in debugging problems.

Signed-off-by: Steve Dickson <steved@redhat.com>
utils/nfsidmap/Makefile.am
utils/nfsidmap/nfsidmap.c

index f837b913d1a83a2b5163c33168c2c1f3397dc232..037aa7979c10e6fe50c6f34d4993a55630f2985e 100644 (file)
@@ -4,6 +4,6 @@ man8_MANS = nfsidmap.man
 
 sbin_PROGRAMS  = nfsidmap
 nfsidmap_SOURCES = nfsidmap.c
-nfsidmap_LDADD = -lnfsidmap -lkeyutils
+nfsidmap_LDADD = -lnfsidmap -lkeyutils ../../support/nfs/libnfs.a
 
 MAINTAINERCLEANFILES = Makefile.in
index 2d87381b7a9e646c5505c52052f3c2b997e9fbc6..134d9bcc21904fcb0cebd4da9452507158678e49 100644 (file)
@@ -10,6 +10,7 @@
 #include <nfsidmap.h>
 
 #include <syslog.h>
+#include "xlog.h"
 
 /* gcc nfsidmap.c -o nfsidmap -l nfsidmap -l keyutils */
 
@@ -36,9 +37,15 @@ int id_lookup(char *name_at_domain, key_serial_t key, int type)
                rc = nfs4_group_owner_to_gid(name_at_domain, &gid);
                sprintf(id, "%u", gid);
        }
+       if (rc < 0)
+               xlog_err("id_lookup: %s: failed: %m",
+                       (type == USER ? "nfs4_owner_to_uid" : "nfs4_group_owner_to_gid"));
 
-       if (rc == 0)
+       if (rc == 0) {
                rc = keyctl_instantiate(key, id, strlen(id) + 1, 0);
+               if (rc < 0)
+                       xlog_err("id_lookup: keyctl_instantiate failed: %m");
+       }
 
        return rc;
 }
@@ -57,6 +64,7 @@ int name_lookup(char *id, key_serial_t key, int type)
        rc = nfs4_get_default_domain(NULL, domain, NFS4_MAX_DOMAIN_LEN);
        if (rc != 0) {
                rc = -1;
+               xlog_err("name_lookup: nfs4_get_default_domain failed: %m");
                goto out;
        }
 
@@ -67,10 +75,15 @@ int name_lookup(char *id, key_serial_t key, int type)
                gid = atoi(id);
                rc = nfs4_gid_to_name(gid, domain, name, IDMAP_NAMESZ);
        }
+       if (rc < 0)
+               xlog_err("name_lookup: %s: failed: %m",
+                       (type == USER ? "nfs4_uid_to_name" : "nfs4_gid_to_name"));
 
-       if (rc == 0)
+       if (rc == 0) {
                rc = keyctl_instantiate(key, &name, strlen(name), 0);
-
+               if (rc < 0)
+                       xlog_err("name_lookup: keyctl_instantiate failed: %m");
+       }
 out:
        return rc;
 }
@@ -83,9 +96,22 @@ int main(int argc, char **argv)
        int rc = 1;
        int timeout = 600;
        key_serial_t key;
+       char *progname;
+
+       /* Set the basename */
+       if ((progname = strrchr(argv[0], '/')) != NULL)
+               progname++;
+       else
+               progname = argv[0];
 
-       if (argc < 3)
+       xlog_open(progname);
+       xlog_syslog(1);
+       xlog_stderr(0);
+
+       if (argc < 3) {
+               xlog_err("Bad arg count. Check /etc/request-key.conf");
                return 1;
+       }
 
        arg = malloc(sizeof(char) * strlen(argv[2]) + 1);
        strcpy(arg, argv[2]);