1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2010. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #include <tmacros.h> |
---|
13 | #include "test_support.h" |
---|
14 | |
---|
15 | #include <unistd.h> |
---|
16 | #include <errno.h> |
---|
17 | #include <sys/types.h> |
---|
18 | |
---|
19 | void test_gid(void) |
---|
20 | { |
---|
21 | gid_t gid; |
---|
22 | int sc; |
---|
23 | |
---|
24 | gid = getegid(); |
---|
25 | printf( "getegid = %d\n", gid ); |
---|
26 | |
---|
27 | gid = getgid(); |
---|
28 | printf( "getgid = %d\n", gid ); |
---|
29 | |
---|
30 | puts( "setgid(5)" ); |
---|
31 | sc = setgid(5); |
---|
32 | rtems_test_assert( sc == 0 ); |
---|
33 | |
---|
34 | gid = getegid(); |
---|
35 | printf( "getegid = %d\n", gid ); |
---|
36 | |
---|
37 | gid = getgid(); |
---|
38 | printf( "getgid = %d\n", gid ); |
---|
39 | |
---|
40 | puts( "setpgid(getpid(), 10) - ENOSYS" ); |
---|
41 | sc = setpgid( getpid(), 10 ); |
---|
42 | rtems_test_assert( sc == -1 ); |
---|
43 | rtems_test_assert( errno == ENOSYS ); |
---|
44 | } |
---|
45 | |
---|
46 | void test_uid(void) |
---|
47 | { |
---|
48 | uid_t uid; |
---|
49 | int sc; |
---|
50 | |
---|
51 | uid = geteuid(); |
---|
52 | printf( "geteuid = %d\n", uid ); |
---|
53 | |
---|
54 | uid = getuid(); |
---|
55 | printf( "getuid = %d\n", uid ); |
---|
56 | |
---|
57 | puts( "setuid(5)" ); |
---|
58 | sc = setuid(5); |
---|
59 | rtems_test_assert( sc == 0 ); |
---|
60 | |
---|
61 | uid = geteuid(); |
---|
62 | printf( "geteuid = %d\n", uid ); |
---|
63 | |
---|
64 | uid = getuid(); |
---|
65 | printf( "getuid = %d\n", uid ); |
---|
66 | |
---|
67 | } |
---|
68 | |
---|
69 | pid_t __getpid(void); |
---|
70 | int issetugid(void); |
---|
71 | |
---|
72 | void test_pid(void) |
---|
73 | { |
---|
74 | pid_t pid; |
---|
75 | int sc; |
---|
76 | |
---|
77 | pid = getpid(); |
---|
78 | printf( "getpid = %d\n", pid ); |
---|
79 | |
---|
80 | pid = __getpid(); |
---|
81 | printf( "__getpid = %d\n", pid ); |
---|
82 | |
---|
83 | pid = getppid(); |
---|
84 | printf( "getppid = %d\n", pid ); |
---|
85 | |
---|
86 | puts( "setsid - EPERM" ); |
---|
87 | pid = setsid(); |
---|
88 | rtems_test_assert( pid == -1 ); |
---|
89 | rtems_test_assert( errno == EPERM ); |
---|
90 | |
---|
91 | sc = issetugid(); |
---|
92 | rtems_test_assert( sc == 0 ); |
---|
93 | |
---|
94 | puts( "getpgrp - return local node - OK" ); |
---|
95 | pid = getpgrp(); |
---|
96 | printf( "getpgrp returned %d\n", pid ); |
---|
97 | |
---|
98 | puts( "getgroups - return 0 - OK" ); |
---|
99 | sc = getgroups( 0, NULL ); |
---|
100 | rtems_test_assert( sc == 0 ); |
---|
101 | |
---|
102 | } |
---|
103 | |
---|
104 | void test_getlogin(void) |
---|
105 | { |
---|
106 | int sc; |
---|
107 | char ch; |
---|
108 | |
---|
109 | puts( "setuid(5)" ); |
---|
110 | sc = setuid(5); |
---|
111 | rtems_test_assert( sc == 0 ); |
---|
112 | printf( "getlogin() -- (%s)\n", getlogin() ); |
---|
113 | |
---|
114 | puts( "setuid(0)" ); |
---|
115 | sc = setuid(0); |
---|
116 | rtems_test_assert( sc == 0 ); |
---|
117 | printf( "getlogin() -- (%s)\n", getlogin() ); |
---|
118 | |
---|
119 | puts( "getlogin_r(NULL, LOGIN_NAME_MAX) -- EFAULT" ); |
---|
120 | sc = getlogin_r( NULL, LOGIN_NAME_MAX ); |
---|
121 | rtems_test_assert( sc == EFAULT ); |
---|
122 | |
---|
123 | puts( "getlogin_r(buffer, 0) -- ERANGE" ); |
---|
124 | sc = getlogin_r( &ch, 0 ); |
---|
125 | rtems_test_assert( sc == ERANGE ); |
---|
126 | |
---|
127 | |
---|
128 | } |
---|
129 | |
---|
130 | rtems_task Init( |
---|
131 | rtems_task_argument argument |
---|
132 | ) |
---|
133 | { |
---|
134 | puts( "\n\n*** TEST ID 01 ***" ); |
---|
135 | |
---|
136 | test_gid(); |
---|
137 | puts( "" ); |
---|
138 | |
---|
139 | test_uid(); |
---|
140 | puts( "" ); |
---|
141 | |
---|
142 | test_pid(); |
---|
143 | puts( "" ); |
---|
144 | |
---|
145 | test_getlogin(); |
---|
146 | |
---|
147 | puts( "*** END OF TEST ID 01 ***" ); |
---|
148 | |
---|
149 | rtems_test_exit(0); |
---|
150 | } |
---|
151 | |
---|
152 | /* configuration information */ |
---|
153 | |
---|
154 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
155 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
156 | |
---|
157 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
158 | /* so we can write /etc/passwd and /etc/group */ |
---|
159 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4 |
---|
160 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
161 | |
---|
162 | #define CONFIGURE_INIT |
---|
163 | |
---|
164 | #include <rtems/confdefs.h> |
---|
165 | /* end of file */ |
---|