source: rtems/testsuites/psxtests/psxpasswd02/init.c @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 5.4 KB
Line 
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
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <bsp.h>
15#include <pmacros.h>
16#include <sys/types.h>
17#include <pwd.h>
18#include <grp.h>
19#include <unistd.h>
20#include <fcntl.h>
21#include <errno.h>
22#include <limits.h>
23
24void print_passwd(
25  struct passwd *pw
26)
27{
28  printf(
29    "  username: %s\n"
30    "  user password: %s\n"
31    "  user ID: %d\n"
32    "  group ID: %d\n"
33    "  real name: %s\n"
34    "  home directory: %s\n"
35    "  shell program: %s\n",
36    pw->pw_name,
37    pw->pw_passwd,
38    pw->pw_uid,
39    pw->pw_gid,
40    pw->pw_gecos,
41    pw->pw_dir,
42    pw->pw_shell
43  );
44}
45 
46void print_group(
47  struct group *gr
48)
49{
50  printf(
51    "  group name: %s\n"
52    "  group  password: %s\n"
53    "  group  ID: %d\n",
54    gr->gr_name,
55    gr->gr_passwd,
56    gr->gr_gid
57  );
58
59  /* TBD print users in group */
60}
61 
62rtems_task Init(
63  rtems_task_argument ignored
64)
65{
66  struct passwd *pw;
67  struct group  *gr;
68  int status = -1;
69  char str[100] = {0};
70  int max_int = INT_MAX;
71
72  FILE *fp = NULL;
73
74  puts( "*** PASSWORD/GROUP TEST - 02 ***" );
75
76  puts( "Init - Creating /etc" );
77  status = mkdir( "/etc", 0777 );
78  rtems_test_assert( status == 0 );
79 
80  puts( "Init - Creating /etc/passwd" );
81  status = mknod( "/etc/passwd", (S_IFREG | S_IRWXU), 0LL );
82  rtems_test_assert( status != -1 );
83
84  fp = fopen( "/etc/passwd", "w" );
85  rtems_test_assert( fp != NULL );
86  fprintf( fp, "bharath:x:-1:-a:Dummy::/:/bin/bash\n" );
87  fclose( fp );
88
89  puts( "Init - Creating /etc/group" );
90  status = mknod( "/etc/group", (S_IFREG | S_IRWXU), 0LL );
91  rtems_test_assert( status != -1);
92
93  fp = fopen( "/etc/group", "w" );
94  rtems_test_assert( fp != NULL );
95  fprintf( fp, "admin::1:root,su,super-user\n" );
96  fclose( fp );
97
98  puts( "Init - setpwent() -- OK" );
99  setpwent();
100
101  puts( "Init - setpwent() -- OK" );
102  setpwent();
103
104  puts( "Init - setgrent() -- OK" );
105  setgrent();
106
107  puts( "Init - setgrent() -- OK" );
108  setgrent(); 
109 
110  puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
111  pw = getpwnam( "root" );
112  rtems_test_assert( !pw );
113  rtems_test_assert( errno == EINVAL );
114
115  fp = fopen( "/etc/passwd", "w" );
116  rtems_test_assert( fp != NULL );
117  fprintf( fp, "rtems:x:1:1:dummy::/:/bin/bash:" );
118  fclose( fp );
119
120  puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
121  pw = getpwnam( "root" );
122  rtems_test_assert( !pw );
123  rtems_test_assert( errno == EINVAL );
124
125  fp = fopen( "/etc/passwd", "w" );
126  rtems_test_assert( fp != NULL );
127  fprintf( fp, "user\n:x:2:2:dummy::/:/bin/sh\n" );
128  fclose( fp );
129
130  puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
131  pw = getpwnam( "root" );
132  rtems_test_assert( !pw );
133  rtems_test_assert( errno == EINVAL );
134
135  fp = fopen( "/etc/passwd", "w" );
136  rtems_test_assert( fp != NULL );
137  fprintf( fp, "user:x:999999999999:1:dummy::/:/bin/sh\n" );
138  fclose( fp );
139
140  puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
141  pw = getpwnam( "root" );
142  rtems_test_assert( !pw );
143  rtems_test_assert( errno == EINVAL );
144
145  sprintf( str, "user:x:%d%d:1:dummy::/:/bin/sh\n", max_int/10, max_int%10+1 );
146
147  fp = fopen( "/etc/passwd", "w" );
148  rtems_test_assert( fp != NULL );
149  fprintf( fp, str );
150  fclose( fp );
151
152  puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
153  pw = getpwnam( "root" );
154  rtems_test_assert( !pw );
155  rtems_test_assert( errno == EINVAL );
156
157  fp = fopen( "/etc/passwd", "w" );
158  rtems_test_assert( fp != NULL );
159  fprintf( fp, "\
160    ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\
161    ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\
162    ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\
163    ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\
164    ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\
165    ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\
166    :x:999999999999:1:dummy::/:/bin/sh\n" );
167  fclose( fp );
168
169  puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
170  pw = getpwnam( "root" );
171  rtems_test_assert( !pw );
172  rtems_test_assert( errno == EINVAL );
173
174  puts( "Init - getgrent() -- OK" );
175  gr = getgrent();
176  rtems_test_assert( gr != NULL );
177  print_group( gr );
178
179  puts( "Init - endpwent() -- OK" );
180  endpwent();
181
182  puts( "Init - endpwent() -- OK" );
183  endpwent();
184
185  puts( "Init - endgrent() -- OK" );
186  endgrent();
187
188  puts( "Init - endgrent() -- OK" );
189  endgrent();
190
191  puts( "Removing /etc/passwd" );
192  status = unlink( "/etc/passwd" );
193  rtems_test_assert( status == 0 );
194
195  puts( "Removing /etc/group" );
196  status = unlink( "/etc/group" );
197  rtems_test_assert( status == 0 );
198
199  puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
200  pw = getpwnam( "root" );
201  rtems_test_assert( !pw );
202  rtems_test_assert( errno == EINVAL );
203
204  puts( "Init - getgrnam(\"root\") -- expected EINVAL" );
205  gr = getgrnam( "root" );
206  rtems_test_assert( !gr );
207  rtems_test_assert( errno == EINVAL );
208 
209  puts( "*** END OF PASSWORD/GROUP TEST - 02 ***" );
210  rtems_test_exit( 0 );
211}
212
213/* configuration information */
214
215#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
216#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
217
218#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
219#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
220
221#define CONFIGURE_MAXIMUM_TASKS 1
222#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
223
224#define CONFIGURE_INIT
225#include <rtems/confdefs.h>
226/* end of file */
Note: See TracBrowser for help on using the repository browser.