Skip to content
Snippets Groups Projects
Commit 7813287a authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Add tests

parent 17a96a66
No related branches found
No related tags found
No related merge requests found
*~
*.spec
*.src.rpm
*.tar.gz
*.o
libtest
# Automake stuff
.deps/
......
......@@ -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
......
......@@ -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;
......
libtest.c 0 → 100644
/*
* 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;
}
......@@ -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
......
user1_group:*:1000:
group11:*:2001:user1
group12:*:2002:user1,user2
group13:*:2003:user1,user2,user3
user2_group:*:1100:
group21:*:2101:user1,user2
group22:*:2102:user1,user2
group23:*:2103:user1,user2
[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
user1:*:1000:1000:User # 1:/home/user1:/bin/bash
user2:*:1100:1100:User # 2:/home/user2:/bin/bash
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment