diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2013-03-11 20:50:55 +0100 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2013-03-11 20:52:32 +0100 |
commit | 83c5788daeec43929088f745238f8c9c31b4d6a8 (patch) | |
tree | 83dfd45c22ee9ac777cdf5f4321861d86cff1984 /tests | |
parent | fa27d94a73be50c2730401279663ee41081137dd (diff) |
implement a lookup_shadow test command for use on systems that don't allow querying shadow via getent
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 5 | ||||
-rw-r--r-- | tests/lookup_shadow.c | 97 |
2 files changed, 101 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 082e80d..b8990a9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -22,7 +22,8 @@ TESTS = test_dict test_set test_tio test_expr test_getpeercred test_cfg \ test_myldap.sh test_common test_nsscmds.sh test_pamcmds.sh check_PROGRAMS = test_dict test_set test_tio test_expr test_getpeercred \ - test_cfg test_myldap test_common lookup_netgroup + test_cfg test_myldap test_common \ + lookup_netgroup lookup_shadow EXTRA_DIST = nslcd-test.conf test_myldap.sh test_nsscmds.sh test_pamcmds.sh \ in_testenv.sh test_pamcmds.expect usernames.txt @@ -74,3 +75,5 @@ test_common_SOURCES = test_common.c ../nslcd/common.h test_common_LDADD = ../nslcd/cfg.o $(common_nslcd_LDADD) lookup_netgroup_SOURCES = lookup_netgroup.c + +lookup_shadow_SOURCES = lookup_shadow.c diff --git a/tests/lookup_shadow.c b/tests/lookup_shadow.c new file mode 100644 index 0000000..5c96108 --- /dev/null +++ b/tests/lookup_shadow.c @@ -0,0 +1,97 @@ +/* + lookup_shadow.c - simple lookup code for shadow entries + + Copyright (C) 2013 Arthur de Jong + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA +*/ + +#include "config.h" + +#include <string.h> +#include <stdio.h> +#include <errno.h> +#include <stdlib.h> + +#ifndef HAVE_SHADOW_H +/* dummy implementation that does nothing for FreeBSD */ +int main(int argc,char *argv[]) +{ + fprintf(stderr, "%s: shadow lookups unsupported\n", argv[0]); + return 1; +} +#else /* HAVE_SHADOW_H */ + +#include <shadow.h> + +static void print_shadow(struct spwd *result) +{ + printf("%s:%s:", result->sp_namp, result->sp_pwdp); + if (result->sp_lstchg >= 0) + printf("%d", result->sp_lstchg); + printf(":"); + if (result->sp_min >= 0) + printf("%d", (int)result->sp_min); + printf(":"); + if (result->sp_max >= 0) + printf("%d", (int)result->sp_max); + printf(":"); + if (result->sp_warn >= 0) + printf("%d", (int)result->sp_warn); + printf(":"); + if (result->sp_inact >= 0) + printf("%d", (int)result->sp_inact); + printf(":"); + if (result->sp_expire >= 0) + printf("%d", (int)result->sp_expire); + printf(":"); + if (result->sp_flag >= 0) + printf("%x", (int)result->sp_flag); + printf("\n"); +} + +/* the main program... */ +int main(int argc,char *argv[]) +{ + struct spwd *result; + /* check arguments */ + if ((argc != 1) && (argc != 2)) + { + fprintf(stderr, "Usage: %s [USERNAME]\n", argv[0]); + exit(EXIT_FAILURE); + } + /* start lookup */ + if (argc == 2) + { + /* get entry by name */ + errno = 0; + result = getspnam(argv[1]); + if (result == NULL) + exit(EXIT_FAILURE); + print_shadow(result); + } + else /* argc == 1 */ + { + /* get all entries */ + setspent(); + while ((result = getspent()) != NULL) + print_shadow(result); + endspent(); + } + return 0; +} + +#endif /* HAVE_SHADOW_H */ |