diff --git a/.gitignore b/.gitignore index c284319fd3d50e4dc3c1617b64ce7538728e7fbc..ffb8e810f203d8e5b5076b3d1c0a6637f305b408 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ *~ *.spec *.src.rpm +*.tar.gz +*.o +libtest # Automake stuff .deps/ @@ -23,4 +26,4 @@ install-sh libtool ltmain.sh m4/ -missing \ No newline at end of file +missing diff --git a/Makefile.am b/Makefile.am index 0bd54976801821e2b0e1befcc808e64364d14c59..f38f4e29e3c5dfba772d437484294560cfa0e168 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,8 +34,10 @@ clean-local: echo CLEAN test: libtest - ./libtest andersb@control.lth.se andersb@CONTROL.LTH.SE - ./libtest regler@control.lth.se regler@CONTROL.LTH.SE + ./libtest -u user1@test.domain user1@test.domain + ./libtest -u user2@test2.domain user2@test2.domain + ./libtest -g group11@test1.domain + ./libtest -g group21@test2.domain nodist_libtest_SOURCES = libtest.c libtest_LDADD = -lnfsidmap diff --git a/files.c b/files.c index 3c48fe1b8851a4d251fc0d133069859bd6683f75..1939aaf8314f5a95faa79e1cc94d6af33012bc77 100644 --- a/files.c +++ b/files.c @@ -463,7 +463,7 @@ static struct domain *domain_init(char *domain) char *patterns = strdup_or_null(config_get("Files", "Patterns-", domain)); if (!patterns) { - warnx("files_init: Patterns for user mapping missing"); + warnx("files_init: Patterns-%s missing", domain); goto no_patterns; } #define SPECIAL ",%^.[$()|*+?{\\" @@ -477,8 +477,8 @@ static struct domain *domain_init(char *domain) p = strpbrk(p+1, SPECIAL)) { if (p[0] == ',') { if (percents != 1) { - warnx("files_init: Group %d has wrong number of wildcards '%s'", - groups, result->pattern); + warnx("files_init: Group %d has wrong number of wildcards '%s' [%s]", + groups, result->pattern, domain); goto invalid_pattern; } percents = 0; diff --git a/libtest.c b/libtest.c new file mode 100644 index 0000000000000000000000000000000000000000..c48e009375d99fff69c02782b0aaad2830a8fb68 --- /dev/null +++ b/libtest.c @@ -0,0 +1,131 @@ +/* + * libtest.c + * + * nfs idmapping library, primarily for nfs4 client/server kernel idmapping + * and for userland nfs4 idmapping by acl libraries. + * + * Copyright (c) 2004 The Regents of the University of Michigan. + * All rights reserved. + * + * Andy Adamson <andros@umich.edu> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + * libtest: Test the translation table functions + * Reads /etc/idmapd.conf + * + * To compile: + * gcc -g libtest.c -lnfsidmap -o libtest + * + */ + +#include <stdarg.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <sys/types.h> +#include <nfsidmap.h> + +#define QUIT_ON_ERROR 1 +#define PATH_IDMAPDCONF "./testfiles/idmapd.conf" +char *conf_path = PATH_IDMAPDCONF; + +#define TEST(RESULT, ERR, OK) \ + { \ + int err = RESULT; \ + if (err != 0) \ + printf ERR ; \ + else \ + printf OK ; \ + } + +int main(int ac, char **av) +{ + char *mode, *name, *princ; + int uid = 0, gid = 0; + char name_buf[32]; + int gids[1000]; + int i, ngids; + + if (ac == 4 && strcmp(av[1], "-u") == 0) { + mode = av[1]; + name = av[2]; + princ = av[3]; + } else if (ac == 3 && strcmp(av[1], "-g") == 0) { + mode = av[1]; + name = av[2]; + } else { + printf("Usage: %s -u <user@nfsv4domain> <k5princ@REALM>\n",av[0]); + printf("Usage: %s -g <group@nfsv4domain>\n",av[0]); + return 1; + } + + nfs4_set_debug(0, NULL); + + TEST(nfs4_init_name_mapping(PATH_IDMAPDCONF), + ("nfs4_init_name_mapping: error %d\n", err), + ("")); + + if (strcmp(mode, "-u") == 0) { + + TEST(nfs4_gss_princ_to_ids("krb5", princ, &uid, &gid), + ( "nfs4_gss_princ_to_ids: error %d\n", err), + ( "nfs4_gss_princ_to_ids: princ %s has uid %d gid %d\n", + princ, uid, gid)); + + ngids = 1000; + TEST(nfs4_gss_princ_to_grouplist("krb5", princ, gids, &ngids), + (" nfs4_gss_princ_to_grouplist: error %d\n", err), + (" nfs4_gss_princ_to_grouplist: princ %s has gids ", princ)); + for (i = 0; i < ngids; i++) printf("%d ", gids[i]); + printf("\n"); + + TEST(nfs4_name_to_uid(name, &uid), + ("nfs4_name_to_uid: error %d\n", err), + ("nfs4_name_to_uid: name %s has uid %d\n", name, uid)); + + /* uid is set by nfs4_name_to_uid() */ + memset(name_buf, 0, 32); + TEST(nfs4_uid_to_name(uid, NULL, name_buf, 32), + ("nfs4_uid_to_name: error %d\n", err), + ("nfs4_uid_to_name: uid %d has name %s\n", uid, name_buf)); + + } else if (strcmp(mode, "-g") == 0) { + + TEST(nfs4_name_to_gid(name, &gid), + ("nfs4_name_to_gid: error %d\n", err), + ("nfs4_name_to_gid: name %s has gid %d\n", name, gid)); + + /* gid is set by nfs4_name_to_gid() */ + memset(name_buf, 0, 32); + TEST(nfs4_gid_to_name(gid, NULL, name_buf, 32), + ("nfs4_gid_to_name: error %d\n", err), + ("nfs4_gid_to_name: gid %d has name %s\n", gid, name_buf)); + } + return 0; +} diff --git a/make_srpm.sh b/make_srpm.sh index ef3191d7600d0991cd3915336eab75e525ac97de..ba8e619b54b89b886068ed8aa3f34666e3a2421c 100755 --- a/make_srpm.sh +++ b/make_srpm.sh @@ -41,6 +41,8 @@ mkdir -p %{buildroot}/%{_mandir}/man5 /usr/bin/install .libs/files.so %{buildroot}/%{_libdir}/libnfsidmap/ /usr/bin/install libnfsidmap-files.5 %{buildroot}/%{_mandir}/man5/ +%check +make test %files %{_libdir}/libnfsidmap/files.so diff --git a/testfiles/group.test1 b/testfiles/group.test1 new file mode 100644 index 0000000000000000000000000000000000000000..92fccf0ffab7acdb4a1f694343fa8b17ab290d04 --- /dev/null +++ b/testfiles/group.test1 @@ -0,0 +1,4 @@ +user1_group:*:1000: +group11:*:2001:user1 +group12:*:2002:user1,user2 +group13:*:2003:user1,user2,user3 diff --git a/testfiles/group.test2 b/testfiles/group.test2 new file mode 100644 index 0000000000000000000000000000000000000000..377877dbd1d306ce44da976dcd75fa28ee340307 --- /dev/null +++ b/testfiles/group.test2 @@ -0,0 +1,4 @@ +user2_group:*:1100: +group21:*:2101:user1,user2 +group22:*:2102:user1,user2 +group23:*:2103:user1,user2 diff --git a/testfiles/idmapd.conf b/testfiles/idmapd.conf new file mode 100644 index 0000000000000000000000000000000000000000..f76b065b05f61a43adbdc7e580060667f868759d --- /dev/null +++ b/testfiles/idmapd.conf @@ -0,0 +1,26 @@ +[General] + +Domain = test.domain + +[Mapping] + +Nobody-User = nobody +Nobody-Group = nobody + +[Translation] + +Method = files + +[Files] + +Domains = test1,test2 + +Patterns-test1 = %,%@test.domain +User-test1 = testfiles/passwd.test1 +Group-test1 = testfiles/group.test1 +Domain-test1 = test.domain + +Patterns-test2 = %@test2.domain +User-test2 = testfiles/passwd.test2 +Group-test2 = testfiles/group.test2 +Domain-test2 = test2.domain diff --git a/testfiles/passwd.test1 b/testfiles/passwd.test1 new file mode 100644 index 0000000000000000000000000000000000000000..615f54d80fc4acc4f9fb7a5b37f2496abbe3b1e8 --- /dev/null +++ b/testfiles/passwd.test1 @@ -0,0 +1 @@ +user1:*:1000:1000:User # 1:/home/user1:/bin/bash diff --git a/testfiles/passwd.test2 b/testfiles/passwd.test2 new file mode 100644 index 0000000000000000000000000000000000000000..688e7ff1700bbd9eb2ff5d62c73498d9b9d9c5a2 --- /dev/null +++ b/testfiles/passwd.test2 @@ -0,0 +1 @@ +user2:*:1100:1100:User # 2:/home/user2:/bin/bash