diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-11-14 14:31:54 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-11-20 10:30:22 +0100 |
commit | acf9a8dd54d1b1cb01e361784146a062a29e1487 (patch) | |
tree | c3f16482ba4bbbf827b137186086b7f21eafb451 /testsuites/libtests | |
parent | libcsupport: Minimal /etc/passwd and /etc/group (diff) | |
download | rtems-acf9a8dd54d1b1cb01e361784146a062a29e1487.tar.bz2 |
shell: Use crypt_r() in rtems_shell_login_check()
Use '*" to disable shell login instead of '!' according to the Linux man
page. Use getpwnam_r() instead of getpwnam(). Do not access the user
environment directly. Update the user environment only after a
successful login check.
Diffstat (limited to 'testsuites/libtests')
-rw-r--r-- | testsuites/libtests/Makefile.am | 1 | ||||
-rw-r--r-- | testsuites/libtests/configure.ac | 1 | ||||
-rw-r--r-- | testsuites/libtests/shell01/Makefile.am | 19 | ||||
-rw-r--r-- | testsuites/libtests/shell01/init.c | 145 | ||||
-rw-r--r-- | testsuites/libtests/shell01/shell01.doc | 11 | ||||
-rw-r--r-- | testsuites/libtests/shell01/shell01.scn | 2 |
6 files changed, 179 insertions, 0 deletions
diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am index b04535c927..a5261a484b 100644 --- a/testsuites/libtests/Makefile.am +++ b/testsuites/libtests/Makefile.am @@ -1,6 +1,7 @@ ACLOCAL_AMFLAGS = -I ../aclocal _SUBDIRS = POSIX +_SUBDIRS += shell01 _SUBDIRS += pwdgrp01 _SUBDIRS += crypt01 _SUBDIRS += sha diff --git a/testsuites/libtests/configure.ac b/testsuites/libtests/configure.ac index b1a7277948..80245f9c64 100644 --- a/testsuites/libtests/configure.ac +++ b/testsuites/libtests/configure.ac @@ -66,6 +66,7 @@ AS_IF([test x"$HAVE_LIBDL" = x"yes"],[ # Explicitly list all Makefiles here AC_CONFIG_FILES([Makefile +shell01/Makefile pwdgrp01/Makefile crypt01/Makefile sha/Makefile diff --git a/testsuites/libtests/shell01/Makefile.am b/testsuites/libtests/shell01/Makefile.am new file mode 100644 index 0000000000..c44ba8fda0 --- /dev/null +++ b/testsuites/libtests/shell01/Makefile.am @@ -0,0 +1,19 @@ +rtems_tests_PROGRAMS = shell01 +shell01_SOURCES = init.c + +dist_rtems_tests_DATA = shell01.scn shell01.doc + +include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg +include $(top_srcdir)/../automake/compile.am +include $(top_srcdir)/../automake/leaf.am + +AM_CPPFLAGS += -I$(top_srcdir)/../support/include + +LINK_OBJS = $(shell01_OBJECTS) +LINK_LIBS = $(shell01_LDLIBS) + +shell01$(EXEEXT): $(shell01_OBJECTS) $(shell01_DEPENDENCIES) + @rm -f shell01$(EXEEXT) + $(make-exe) + +include $(top_srcdir)/../automake/local.am diff --git a/testsuites/libtests/shell01/init.c b/testsuites/libtests/shell01/init.c new file mode 100644 index 0000000000..413ce6ebb6 --- /dev/null +++ b/testsuites/libtests/shell01/init.c @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2014 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * <rtems@embedded-brains.de> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include <sys/stat.h> +#include <sys/types.h> +#include <errno.h> +#include <grp.h> +#include <pwd.h> +#include <stdio.h> +#include <unistd.h> + +#include <rtems/shell.h> + +#include "tmacros.h" + +const char rtems_test_name[] = "SHELL 1"; + +static void create_file(const char *name, const char *content) +{ + FILE *fp; + int rv; + + fp = fopen(name, "wx"); + rtems_test_assert(fp != NULL); + + rv = fputs(content, fp); + rtems_test_assert(rv == 0); + + rv = fclose(fp); + rtems_test_assert(rv == 0); +} + +static void test(void) +{ + bool ok; + int rv; + + rv = mkdir("/etc", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + rtems_test_assert(rv == 0); + + create_file( + "/etc/passwd", + "moop:foo:1:3:blob:a::c\n" + "no:*:2:4::::\n" + "zero::3:5::::\n" + "shadow:x:4:6::::\n" + ); + + create_file( + "/etc/group", + "A::1:moop,u,v,w,zero\n" + "B::2:moop\n" + "blub:bar:3:moop\n" + "C::4:l,m,n,moop\n" + "D::5:moop,moop\n" + "E::6:x\n" + "E::7:y,z\n" + "F::8:s,moop,t\n" + ); + + rv = setuid(0); + rtems_test_assert(rv == 0); + + rv = seteuid(0); + rtems_test_assert(rv == 0); + + ok = rtems_shell_login_check("inv", NULL); + rtems_test_assert(!ok); + + ok = rtems_shell_login_check("no", NULL); + rtems_test_assert(!ok); + + ok = rtems_shell_login_check("shadow", NULL); + rtems_test_assert(!ok); + + ok = rtems_shell_login_check("moop", "false"); + rtems_test_assert(!ok); + + rtems_test_assert(getuid() == 0); + rtems_test_assert(geteuid() == 0); + rtems_test_assert(getgid() == 0); + rtems_test_assert(getegid() == 0); + + ok = rtems_shell_login_check("zero", NULL); + rtems_test_assert(ok); + rtems_test_assert(getuid() == 3); + rtems_test_assert(geteuid() == 3); + rtems_test_assert(getgid() == 5); + rtems_test_assert(getegid() == 5); + + ok = rtems_shell_login_check("moop", "foo"); + rtems_test_assert(ok); + rtems_test_assert(getuid() == 1); + rtems_test_assert(geteuid() == 1); + rtems_test_assert(getgid() == 3); + rtems_test_assert(getegid() == 3); +} + +static void Init(rtems_task_argument arg) +{ + TEST_BEGIN(); + + test(); + + TEST_END(); + rtems_test_exit(0); +} + +#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + +#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM + +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4 + +#define CONFIGURE_MAXIMUM_TASKS 1 +#define CONFIGURE_MAXIMUM_POSIX_KEYS 1 +#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 1 + +#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#define CONFIGURE_INIT + +#include <rtems/confdefs.h> + +#define CONFIGURE_SHELL_COMMANDS_INIT + +#include <rtems/shellconfig.h> diff --git a/testsuites/libtests/shell01/shell01.doc b/testsuites/libtests/shell01/shell01.doc new file mode 100644 index 0000000000..e3b004478b --- /dev/null +++ b/testsuites/libtests/shell01/shell01.doc @@ -0,0 +1,11 @@ +This file describes the directives and concepts tested by this test set. + +test set name: shell01 + +directives: + + - rtems_shell_login_check + +concepts: + + - Ensure that rtems_shell_login_check() works as expected. diff --git a/testsuites/libtests/shell01/shell01.scn b/testsuites/libtests/shell01/shell01.scn new file mode 100644 index 0000000000..cf6082fbf8 --- /dev/null +++ b/testsuites/libtests/shell01/shell01.scn @@ -0,0 +1,2 @@ +*** BEGIN OF TEST SHELL 1 *** +*** END OF TEST SHELL 1 *** |