source: rtems/testsuites/libtests/shell01/init.c @ acf9a8d

4.115
Last change on this file since acf9a8d was acf9a8d, checked in by Sebastian Huber <sebastian.huber@…>, on 11/14/14 at 13:31:54

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.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <sys/stat.h>
20#include <sys/types.h>
21#include <errno.h>
22#include <grp.h>
23#include <pwd.h>
24#include <stdio.h>
25#include <unistd.h>
26
27#include <rtems/shell.h>
28
29#include "tmacros.h"
30
31const char rtems_test_name[] = "SHELL 1";
32
33static void create_file(const char *name, const char *content)
34{
35  FILE *fp;
36  int rv;
37
38  fp = fopen(name, "wx");
39  rtems_test_assert(fp != NULL);
40
41  rv = fputs(content, fp);
42  rtems_test_assert(rv == 0);
43
44  rv = fclose(fp);
45  rtems_test_assert(rv == 0);
46}
47
48static void test(void)
49{
50  bool ok;
51  int rv;
52
53  rv = mkdir("/etc", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
54  rtems_test_assert(rv == 0);
55
56  create_file(
57    "/etc/passwd",
58    "moop:foo:1:3:blob:a::c\n"
59    "no:*:2:4::::\n"
60    "zero::3:5::::\n"
61    "shadow:x:4:6::::\n"
62  );
63
64  create_file(
65    "/etc/group",
66    "A::1:moop,u,v,w,zero\n"
67    "B::2:moop\n"
68    "blub:bar:3:moop\n"
69    "C::4:l,m,n,moop\n"
70    "D::5:moop,moop\n"
71    "E::6:x\n"
72    "E::7:y,z\n"
73    "F::8:s,moop,t\n"
74  );
75
76  rv = setuid(0);
77  rtems_test_assert(rv == 0);
78
79  rv = seteuid(0);
80  rtems_test_assert(rv == 0);
81
82  ok = rtems_shell_login_check("inv", NULL);
83  rtems_test_assert(!ok);
84
85  ok = rtems_shell_login_check("no", NULL);
86  rtems_test_assert(!ok);
87
88  ok = rtems_shell_login_check("shadow", NULL);
89  rtems_test_assert(!ok);
90
91  ok = rtems_shell_login_check("moop", "false");
92  rtems_test_assert(!ok);
93
94  rtems_test_assert(getuid() == 0);
95  rtems_test_assert(geteuid() == 0);
96  rtems_test_assert(getgid() == 0);
97  rtems_test_assert(getegid() == 0);
98
99  ok = rtems_shell_login_check("zero", NULL);
100  rtems_test_assert(ok);
101  rtems_test_assert(getuid() == 3);
102  rtems_test_assert(geteuid() == 3);
103  rtems_test_assert(getgid() == 5);
104  rtems_test_assert(getegid() == 5);
105
106  ok = rtems_shell_login_check("moop", "foo");
107  rtems_test_assert(ok);
108  rtems_test_assert(getuid() == 1);
109  rtems_test_assert(geteuid() == 1);
110  rtems_test_assert(getgid() == 3);
111  rtems_test_assert(getegid() == 3);
112}
113
114static void Init(rtems_task_argument arg)
115{
116  TEST_BEGIN();
117
118  test();
119
120  TEST_END();
121  rtems_test_exit(0);
122}
123
124#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
125#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
126
127#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
128
129#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
130
131#define CONFIGURE_MAXIMUM_TASKS 1
132#define CONFIGURE_MAXIMUM_POSIX_KEYS 1
133#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 1
134
135#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
136
137#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
138
139#define CONFIGURE_INIT
140
141#include <rtems/confdefs.h>
142
143#define CONFIGURE_SHELL_COMMANDS_INIT
144
145#include <rtems/shellconfig.h>
Note: See TracBrowser for help on using the repository browser.