diff options
author | Martin Pärtel <martin.partel@gmail.com> | 2019-12-21 14:18:24 +0200 |
---|---|---|
committer | Martin Pärtel <martin.partel@gmail.com> | 2019-12-21 14:18:24 +0200 |
commit | e07c09db52caeca249f998edd9f47483e4cb97fb (patch) | |
tree | 836b5278bdc6f6314e6ecb0827b2e0f0ed605d0d /src | |
parent | 28f248803a7fec4dc212d1d261ddc7549fcea8b4 (diff) | |
download | bindfs-e07c09db52caeca249f998edd9f47483e4cb97fb.tar.gz |
Don't check that numeric UIDs and GIDs exist in user database.
A user database is not always available.
For #79.
Diffstat (limited to 'src')
-rw-r--r-- | src/userinfo.c | 64 |
1 files changed, 16 insertions, 48 deletions
diff --git a/src/userinfo.c b/src/userinfo.c index 23c54c1..a085ff0 100644 --- a/src/userinfo.c +++ b/src/userinfo.c @@ -243,37 +243,21 @@ static int gid_cache_gid_searchcmp(const void *key, const void *entry) int user_uid(const char *username, uid_t *ret) { - struct passwd pwbuf, *pwbufp = NULL; - char *buf; - size_t buflen; - int res; - - uid_t uid; - char *endptr; - /* Check whether the string is a numerical UID */ - uid = strtol(username, &endptr, 10); + char *endptr; + uid_t uid = strtol(username, &endptr, 10); if (*endptr == '\0') { - buflen = 1024; - buf = malloc(buflen); - res = getpwuid_r(uid, &pwbuf, buf, buflen, &pwbufp); - if (res != 0) { - if (res != ERANGE) { /* don't care if buffer was too small */ - free(buf); - return 0; - } - } - free(buf); *ret = uid; return 1; } - /* Process user name */ - buflen = 1024; - buf = malloc(buflen); + /* Handle as textual user name */ + size_t buflen = 1024; + char *buf = malloc(buflen); - res = getpwnam_r(username, &pwbuf, buf, buflen, &pwbufp); - while(res == ERANGE) { + struct passwd pwbuf, *pwbufp = NULL; + int res = getpwnam_r(username, &pwbuf, buf, buflen, &pwbufp); + while (res == ERANGE) { buflen *= 2; buf = realloc(buf, buflen); res = getpwnam_r(username, &pwbuf, buf, buflen, &pwbufp); @@ -292,37 +276,21 @@ int user_uid(const char *username, uid_t *ret) int group_gid(const char *groupname, gid_t *ret) { - struct group gbuf, *gbufp = NULL; - char *buf; - size_t buflen; - int res; - - gid_t gid; - char *endptr; - /* Check whether the string is a numerical GID */ - gid = strtol(groupname, &endptr, 10); + char *endptr; + gid_t gid = strtol(groupname, &endptr, 10); if (*endptr == '\0') { - buflen = 1024; - buf = malloc(buflen); - res = getgrgid_r(gid, &gbuf, buf, buflen, &gbufp); - if (res != 0) { - if (res != ERANGE) { /* don't care if buffer was too small */ - free(buf); - return 0; - } - } - free(buf); *ret = gid; return 1; } - /* Process group name */ - buflen = 1024; - buf = malloc(buflen); + /* Handle as textual group name */ + size_t buflen = 1024; + char *buf = malloc(buflen); - res = getgrnam_r(groupname, &gbuf, buf, buflen, &gbufp); - while(res == ERANGE) { + struct group gbuf, *gbufp = NULL; + int res = getgrnam_r(groupname, &gbuf, buf, buflen, &gbufp); + while (res == ERANGE) { buflen *= 2; buf = realloc(buf, buflen); res = getgrnam_r(groupname, &gbuf, buf, buflen, &gbufp); |