X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fnfsidmap%2Fnfsidmap.c;h=e14543c85770d5dd9f167d55c4517486cde302ed;hp=ce8cf3e3982705811304730ed91f66ca68976089;hb=HEAD;hpb=b4901af20f67730cc63e38dcfd70d66c8ccd677b diff --git a/utils/nfsidmap/nfsidmap.c b/utils/nfsidmap/nfsidmap.c index ce8cf3e..e14543c 100644 --- a/utils/nfsidmap/nfsidmap.c +++ b/utils/nfsidmap/nfsidmap.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -11,6 +12,7 @@ #include #include "xlog.h" +#include "conffile.h" 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 +#ifndef PATH_IDMAPDCONF +#define PATH_IDMAPDCONF "/etc/idmapd.conf" +#endif + +static int keyring_clear(char *keyring); #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) { + 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"); } @@ -105,7 +128,6 @@ static int keyring_clear(char *keyring) char buf[BUFSIZ]; key_serial_t key; - xlog_syslog(0); if (keyring == NULL) keyring = DEFAULT_KEYRING; @@ -172,7 +194,7 @@ static int key_revoke(char *keystr, int keymask) if ((keymask & mask) == 0) continue; - if (strncmp(ptr+4, keystr, strlen(keystr)) != NULL) + if (strncmp(ptr+4, keystr, strlen(keystr)) != 0) 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) { + xlog_syslog(0); rc = keyring_clear(DEFAULT_KEYRING); return rc; } @@ -280,7 +310,7 @@ int main(int argc, char **argv) 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); }