diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2015-09-16 11:02:19 -0400 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2015-09-16 11:21:41 -0400 |
commit | 49f6c29fcfd924b2b964cce75623463c0d1c0d59 (patch) | |
tree | c589ac1c09ea0d77e62924dd3e35b52f1f8f475a /utils/nfsidmap/nfsidmap.c | |
parent | 43bcaca81740cbe78f4f97cf8b0fc39350a17a68 (diff) | |
download | nfs-utils-49f6c29fcfd924b2b964cce75623463c0d1c0d59.tar.gz nfs-utils-49f6c29fcfd924b2b964cce75623463c0d1c0d59.tar.xz nfs-utils-49f6c29fcfd924b2b964cce75623463c0d1c0d59.zip |
nfsidmap: Fix error handling in id_lookup()
As near as I can tell, the exit status of nfsidmap is supposed to be
zero (success) or one (failure).
The return value of id_lookup() becomes the exit status, so it
should return only zero or one.
The libnfsidmap calls return a signed integer, either 0 or negative
errno values. These have to be translated to an exit status.
libkeyutils calls return a signed long, either 0 or -1. These also
have to be translated to an exit status.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'utils/nfsidmap/nfsidmap.c')
-rw-r--r-- | utils/nfsidmap/nfsidmap.c | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/utils/nfsidmap/nfsidmap.c b/utils/nfsidmap/nfsidmap.c index 41672b2..d356806 100644 --- a/utils/nfsidmap/nfsidmap.c +++ b/utils/nfsidmap/nfsidmap.c @@ -189,7 +189,7 @@ static int list_keyring(const char *keyring) /* * Find either a user or group id based on the name@domain string */ -int id_lookup(char *name_at_domain, key_serial_t key, int type) +static int id_lookup(char *name_at_domain, key_serial_t key, int type) { char id[MAX_ID_LEN]; uid_t uid = 0; @@ -203,30 +203,33 @@ 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) + if (rc < 0) { xlog_errno(rc, "id_lookup: %s: failed: %m", (type == USER ? "nfs4_owner_to_uid" : "nfs4_group_owner_to_gid")); + return EXIT_FAILURE; + } - 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: + rc = EXIT_SUCCESS; + if (keyctl_instantiate(key, id, strlen(id) + 1, 0)) { + switch (errno) { + case EDQUOT: + case ENFILE: + case ENOMEM: + /* + * The keyring is full. Clear the keyring and try again + */ + rc = keyring_clear(DEFAULT_KEYRING); + if (rc) break; + if (keyctl_instantiate(key, id, strlen(id) + 1, 0)) { + rc = EXIT_FAILURE; + xlog_err("id_lookup: keyctl_instantiate failed: %m"); } + break; + default: + rc = EXIT_FAILURE; + break; } - if (rc < 0) - xlog_err("id_lookup: keyctl_instantiate failed: %m"); } return rc; |