summaryrefslogtreecommitdiffstats
path: root/testsuites/libtests/shell01
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-14 14:31:54 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-20 10:30:22 +0100
commitacf9a8dd54d1b1cb01e361784146a062a29e1487 (patch)
treec3f16482ba4bbbf827b137186086b7f21eafb451 /testsuites/libtests/shell01
parentlibcsupport: Minimal /etc/passwd and /etc/group (diff)
downloadrtems-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/shell01')
-rw-r--r--testsuites/libtests/shell01/Makefile.am19
-rw-r--r--testsuites/libtests/shell01/init.c145
-rw-r--r--testsuites/libtests/shell01/shell01.doc11
-rw-r--r--testsuites/libtests/shell01/shell01.scn2
4 files changed, 177 insertions, 0 deletions
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 ***