]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/nfsidmap/nfsidmap.c
Merge branch 'sid'
[nfs-utils.git] / utils / nfsidmap / nfsidmap.c
index ce8cf3e3982705811304730ed91f66ca68976089..e14543c85770d5dd9f167d55c4517486cde302ed 100644 (file)
@@ -3,6 +3,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 
 #include <pwd.h>
 #include <grp.h>
 
 #include <pwd.h>
 #include <grp.h>
@@ -11,6 +12,7 @@
 
 #include <unistd.h>
 #include "xlog.h"
 
 #include <unistd.h>
 #include "xlog.h"
+#include "conffile.h"
 
 int verbose = 0;
 char *usage="Usage: %s [-v] [-c || [-u|-g|-r key] || [-t timeout] key desc]";
 
 int verbose = 0;
 char *usage="Usage: %s [-v] [-c || [-u|-g|-r key] || [-t timeout] key desc]";
@@ -25,6 +27,11 @@ char *usage="Usage: %s [-v] [-c || [-u|-g|-r key] || [-t timeout] key desc]";
 #define DEFAULT_KEYRING "id_resolver"
 #endif
 
 #define DEFAULT_KEYRING "id_resolver"
 #endif
 
+#ifndef PATH_IDMAPDCONF
+#define PATH_IDMAPDCONF "/etc/idmapd.conf"
+#endif
+
+static int keyring_clear(char *keyring);
 
 #define UIDKEYS 0x1
 #define GIDKEYS 0x2
 
 #define UIDKEYS 0x1
 #define GIDKEYS 0x2
@@ -52,6 +59,22 @@ int id_lookup(char *name_at_domain, key_serial_t key, int type)
 
        if (rc == 0) {
                rc = keyctl_instantiate(key, id, strlen(id) + 1, 0);
 
        if (rc == 0) {
                rc = keyctl_instantiate(key, id, strlen(id) + 1, 0);
+               if (rc < 0) {
+                       switch(rc) {
+                       case -EDQUOT:
+                       case -ENFILE:
+                       case -ENOMEM:
+                               /*
+                                * The keyring is full. Clear the keyring and try again
+                                */
+                               rc = keyring_clear(DEFAULT_KEYRING);
+                               if (rc == 0)
+                                       rc = keyctl_instantiate(key, id, strlen(id) + 1, 0);
+                               break;
+                       default:
+                               break;
+                       }
+               }
                if (rc < 0)
                        xlog_err("id_lookup: keyctl_instantiate failed: %m");
        }
                if (rc < 0)
                        xlog_err("id_lookup: keyctl_instantiate failed: %m");
        }
@@ -105,7 +128,6 @@ static int keyring_clear(char *keyring)
        char buf[BUFSIZ];
        key_serial_t key;
 
        char buf[BUFSIZ];
        key_serial_t key;
 
-       xlog_syslog(0);
        if (keyring == NULL)
                keyring = DEFAULT_KEYRING;
 
        if (keyring == NULL)
                keyring = DEFAULT_KEYRING;
 
@@ -172,7 +194,7 @@ static int key_revoke(char *keystr, int keymask)
                if ((keymask & mask) == 0)
                        continue;
 
                if ((keymask & mask) == 0)
                        continue;
 
-               if (strncmp(ptr+4, keystr, strlen(keystr)) != NULL)
+               if (strncmp(ptr+4, keystr, strlen(keystr)) != 0)
                        continue;
 
                if (verbose) {
                        continue;
 
                if (verbose) {
@@ -250,11 +272,19 @@ int main(int argc, char **argv)
                }
        }
 
                }
        }
 
+       if (nfs4_init_name_mapping(PATH_IDMAPDCONF))  {
+               xlog_err("Unable to create name to user id mappings.");
+               return 1;
+       }
+       if (!verbose)
+               verbose = conf_get_num("General", "Verbosity", 0);
+
        if (keystr) {
                rc = key_revoke(keystr, keymask);
                return rc;              
        }
        if (clearing) {
        if (keystr) {
                rc = key_revoke(keystr, keymask);
                return rc;              
        }
        if (clearing) {
+               xlog_syslog(0);
                rc = keyring_clear(DEFAULT_KEYRING);
                return rc;              
        }
                rc = keyring_clear(DEFAULT_KEYRING);
                return rc;              
        }
@@ -280,7 +310,7 @@ int main(int argc, char **argv)
        value = strtok(NULL, ":");
 
        if (verbose) {
        value = strtok(NULL, ":");
 
        if (verbose) {
-               xlog_warn("key: %ld type: %s value: %s timeout %ld",
+               xlog_warn("key: 0x%lx type: %s value: %s timeout %ld",
                        key, type, value, timeout);
        }
 
                        key, type, value, timeout);
        }