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

4.115
Last change on this file since a0b1b5ed was a0b1b5ed, checked in by Sebastian Huber <sebastian.huber@…>, on 12/15/14 at 13:19:43

Delete CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM

This define was superfluous, undocumented and used inconsistently.

  • Property mode set to 100644
File size: 4.3 KB
RevLine 
[acf9a8d]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>
[065d72ce]28#include <rtems/userenv.h>
[acf9a8d]29
30#include "tmacros.h"
31
32const char rtems_test_name[] = "SHELL 1";
33
34static void create_file(const char *name, const char *content)
35{
36  FILE *fp;
37  int rv;
38
39  fp = fopen(name, "wx");
40  rtems_test_assert(fp != NULL);
41
42  rv = fputs(content, fp);
43  rtems_test_assert(rv == 0);
44
45  rv = fclose(fp);
46  rtems_test_assert(rv == 0);
47}
48
49static void test(void)
50{
[065d72ce]51  rtems_user_env_t *uenv;
[fa028bb]52  rtems_status_code sc;
53  struct stat st_chroot;
54  struct stat st_workdir;
[acf9a8d]55  bool ok;
56  int rv;
57
58  rv = mkdir("/etc", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
59  rtems_test_assert(rv == 0);
60
[fa028bb]61  rv = mkdir("/chroot", S_IRWXU | S_IRWXG | S_IRWXO);
62  rtems_test_assert(rv == 0);
63
64  rv = lstat("/chroot", &st_chroot);
65  rtems_test_assert(rv == 0);
66
[acf9a8d]67  create_file(
68    "/etc/passwd",
69    "moop:foo:1:3:blob:a::c\n"
70    "no:*:2:4::::\n"
71    "zero::3:5::::\n"
72    "shadow:x:4:6::::\n"
[fa028bb]73    "invchroot::5:7:::/inv:\n"
74    "chroot::6:8:::/chroot:\n"
[acf9a8d]75  );
76
77  create_file(
78    "/etc/group",
79    "A::1:moop,u,v,w,zero\n"
80    "B::2:moop\n"
81    "blub:bar:3:moop\n"
82    "C::4:l,m,n,moop\n"
83    "D::5:moop,moop\n"
84    "E::6:x\n"
85    "E::7:y,z\n"
86    "F::8:s,moop,t\n"
87  );
88
[fa028bb]89  sc = rtems_libio_set_private_env();
90  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
91
[065d72ce]92  uenv = rtems_current_user_env_get();
93
[acf9a8d]94  rv = setuid(0);
95  rtems_test_assert(rv == 0);
96
97  rv = seteuid(0);
98  rtems_test_assert(rv == 0);
99
100  ok = rtems_shell_login_check("inv", NULL);
101  rtems_test_assert(!ok);
102
103  ok = rtems_shell_login_check("no", NULL);
104  rtems_test_assert(!ok);
105
106  ok = rtems_shell_login_check("shadow", NULL);
107  rtems_test_assert(!ok);
108
109  ok = rtems_shell_login_check("moop", "false");
110  rtems_test_assert(!ok);
111
[fa028bb]112  ok = rtems_shell_login_check("invchroot", NULL);
113  rtems_test_assert(!ok);
114
[acf9a8d]115  rtems_test_assert(getuid() == 0);
116  rtems_test_assert(geteuid() == 0);
117  rtems_test_assert(getgid() == 0);
118  rtems_test_assert(getegid() == 0);
[065d72ce]119  rtems_test_assert(uenv->ngroups == 0);
[acf9a8d]120
121  ok = rtems_shell_login_check("zero", NULL);
122  rtems_test_assert(ok);
123  rtems_test_assert(getuid() == 3);
124  rtems_test_assert(geteuid() == 3);
125  rtems_test_assert(getgid() == 5);
126  rtems_test_assert(getegid() == 5);
[065d72ce]127  rtems_test_assert(uenv->ngroups == 1);
128  rtems_test_assert(uenv->groups[0] == 1);
[acf9a8d]129
130  ok = rtems_shell_login_check("moop", "foo");
131  rtems_test_assert(ok);
132  rtems_test_assert(getuid() == 1);
133  rtems_test_assert(geteuid() == 1);
134  rtems_test_assert(getgid() == 3);
135  rtems_test_assert(getegid() == 3);
[065d72ce]136  rtems_test_assert(uenv->ngroups == 5);
137  rtems_test_assert(uenv->groups[0] == 1);
138  rtems_test_assert(uenv->groups[1] == 2);
139  rtems_test_assert(uenv->groups[2] == 4);
140  rtems_test_assert(uenv->groups[3] == 5);
141  rtems_test_assert(uenv->groups[4] == 8);
[fa028bb]142
143  rv = setuid(0);
144  rtems_test_assert(rv == 0);
145
146  rv = seteuid(0);
147  rtems_test_assert(rv == 0);
148
149  ok = rtems_shell_login_check("chroot", NULL);
150  rtems_test_assert(ok);
151  rtems_test_assert(getuid() == 6);
152  rtems_test_assert(geteuid() == 6);
153  rtems_test_assert(getgid() == 8);
154  rtems_test_assert(getegid() == 8);
155
156  rv = lstat(".", &st_workdir);
157  rtems_test_assert(rv == 0);
158  rtems_test_assert(memcmp(&st_chroot, &st_workdir, sizeof(st_chroot)) == 0);
159
160  rtems_libio_use_global_env();
[acf9a8d]161}
162
163static void Init(rtems_task_argument arg)
164{
165  TEST_BEGIN();
166
167  test();
168
169  TEST_END();
170  rtems_test_exit(0);
171}
172
173#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
174#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
175
176#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
177
178#define CONFIGURE_MAXIMUM_TASKS 1
179#define CONFIGURE_MAXIMUM_POSIX_KEYS 1
[fa028bb]180#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 2
[acf9a8d]181
182#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
183
184#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
185
186#define CONFIGURE_INIT
187
188#include <rtems/confdefs.h>
189
190#define CONFIGURE_SHELL_COMMANDS_INIT
191
192#include <rtems/shellconfig.h>
Note: See TracBrowser for help on using the repository browser.