1 /*
2 test_common.c - simple test for the common module
3 This file is part of the nss-pam-ldapd library.
4
5 Copyright (C) 2008, 2009, 2011, 2012, 2013 Arthur de Jong
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA
21 */
22
23 #include "config.h"
24
25 #include <stdio.h>
26 #include <assert.h>
27 #include <sys/stat.h>
28
29 #include "nslcd/common.h"
30 #include "nslcd/cfg.h"
31 #include "nslcd/log.h"
32
test_isvalidname(void)33 static void test_isvalidname(void)
34 {
35 assert(isvalidname("arthur"));
36 assert(!isvalidname("-arthur"));
37 assert(isvalidname("arthur-is-nice"));
38 assert(isvalidname("sambamachine$"));
39 assert(isvalidname("foo\\bar"));
40 assert(!isvalidname("\\foo\\bar"));
41 assert(!isvalidname("foo\\bar\\"));
42 assert(isvalidname("me")); /* try short name */
43 assert(isvalidname("f"));
44 assert(isvalidname("(foo bar)"));
45 }
46
47 /* the main program... */
main(int UNUSED (argc),char UNUSED (* argv[]))48 int main(int UNUSED(argc), char UNUSED(*argv[]))
49 {
50 char *srcdir;
51 char fname[100];
52 /* build the name of the file */
53 srcdir = getenv("srcdir");
54 if (srcdir == NULL)
55 srcdir = ".";
56 snprintf(fname, sizeof(fname), "%s/nslcd-test.conf", srcdir);
57 fname[sizeof(fname) - 1] = '\0';
58 /* ensure that file is not world readable for configuration parsing to
59 succeed */
60 (void)chmod(fname, (mode_t)0660);
61 /* initialize configuration */
62 cfg_init(fname);
63 /* partially initialize logging */
64 log_setdefaultloglevel(LOG_DEBUG);
65 /* run the tests */
66 test_isvalidname();
67 return 0;
68 }
69