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 | |
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.
-rw-r--r-- | src/userinfo.c | 64 | ||||
-rwxr-xr-x | tests/test_bindfs.rb | 16 | ||||
-rwxr-xr-x | vagrant/test.rb | 3 |
3 files changed, 33 insertions, 50 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); diff --git a/tests/test_bindfs.rb b/tests/test_bindfs.rb index 1a407a1..738eef8 100755 --- a/tests/test_bindfs.rb +++ b/tests/test_bindfs.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby # -# Copyright 2006,2007,2008,2009,2010,2012 Martin Pärtel <martin.partel@gmail.com> +# Copyright 2006,2007,2008,2009,2010,2012,2019 Martin Pärtel <martin.partel@gmail.com> # # This file is part of bindfs. # @@ -66,6 +66,20 @@ testenv("-u nobody -g #{nobody_group}") do assert { File.stat('mnt/file').gid == nobody_gid } end +testenv("-u #{nobody_uid} -g #{nobody_gid}", :title => "numeric UID and GID") do + touch('src/file') + + assert { File.stat('mnt/file').uid == nobody_uid } + assert { File.stat('mnt/file').gid == nobody_gid } +end + +testenv("-u 55544 -g 55566", :title => "nonexistent UID and GID") do + touch('src/file') + + assert { File.stat('mnt/file').uid == 55544 } + assert { File.stat('mnt/file').gid == 55566 } +end + testenv("-p 0600:u+D") do touch('src/file') chmod(0777, 'src/file') diff --git a/vagrant/test.rb b/vagrant/test.rb index f6d068f..b49da83 100755 --- a/vagrant/test.rb +++ b/vagrant/test.rb @@ -108,7 +108,7 @@ end threads.each(&:join) if errors.empty? - puts "OK" + puts "All OK" else unless errors.empty? puts @@ -119,3 +119,4 @@ else puts end end + |