source: rtems/testsuites/psxtests/psxpasswd02/init.c @ 1fe4042

4.115
Last change on this file since 1fe4042 was 1fe4042, checked in by Joel Sherrill <joel.sherrill@…>, on 07/01/10 at 17:26:37

2010-07-01 Bharath Suri <bharath.s.jois@…>

PR 1598/testing

  • Makefile.am, configure.ac, psxpasswd01/init.c, psxpasswd01/psxpasswd01.doc, psxpasswd01/psxpasswd01.scn: Add testing for POSIX user database (e.g. /etc/group and /etc/passwd) access routines which are implemented in libcsupport/src/getpwent.c.
  • psxpasswd02/.cvsignore, psxpasswd02/Makefile.am, psxpasswd02/init.c, psxpasswd02/psxpasswd02.doc, psxpasswd02/psxpasswd02.scn: New files.
  • Property mode set to 100644
File size: 4.0 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 *  $Id$
10 */
11
12#include <bsp.h>
13#include <pmacros.h>
14#include <sys/types.h>
15#include <pwd.h>
16#include <grp.h>
17#include <unistd.h>
18#include <fcntl.h>
19#include <errno.h>
20
21void print_passwd(
22  struct passwd *pw
23)
24{
25  printf(
26    "  username: %s\n"
27    "  user password: %s\n"
28    "  user ID: %d\n"
29    "  group ID: %d\n"
30    "  real name: %s\n"
31    "  home directory: %s\n"
32    "  shell program: %s\n",
33    pw->pw_name,
34    pw->pw_passwd,
35    pw->pw_uid,
36    pw->pw_gid,
37    pw->pw_gecos,
38    pw->pw_dir,
39    pw->pw_shell
40  );
41}
42 
43void print_group(
44  struct group *gr
45)
46{
47  printf(
48    "  group name: %s\n"
49    "  group  password: %s\n"
50    "  group  ID: %d\n",
51    gr->gr_name,
52    gr->gr_passwd,
53    gr->gr_gid
54  );
55
56  /* TBD print users in group */
57}
58 
59rtems_task Init(
60  rtems_task_argument ignored
61)
62{
63  struct passwd *pw;
64  struct group  *gr;
65  int status = -1;
66
67  FILE *fp = NULL;
68
69  puts( "*** PASSWORD/GROUP TEST - 02 ***" );
70
71  puts( "Init - Creating /etc" );
72  status = mkdir( "/etc", 0777 );
73  rtems_test_assert( status == 0 );
74 
75  puts( "Init - Creating /etc/passwd" );
76  status = mknod( "/etc/passwd", (S_IFREG | S_IRWXU), 0LL );
77  rtems_test_assert( status != -1 );
78
79  fp = fopen( "/etc/passwd", "w" );
80  rtems_test_assert( fp != NULL );
81  fprintf( fp, "bharath:x:-1:-a:Dummy::/:/bin/bash\n" );
82  fclose( fp );
83
84  puts( "Init - Creating /etc/group" );
85  status = mknod( "/etc/group", (S_IFREG | S_IRWXU), 0LL );
86  rtems_test_assert( status != -1);
87
88  fp = fopen( "/etc/group", "w" );
89  rtems_test_assert( fp != NULL );
90  fprintf( fp, "admin::1:root,su,super-user\n" );
91  fclose( fp );
92
93  puts( "Init - setpwent() -- OK" );
94  setpwent();
95
96  puts( "Init - setpwent() -- OK" );
97  setpwent();
98
99  puts( "Init - setgrent() -- OK" );
100  setgrent();
101
102  puts( "Init - setgrent() -- OK" );
103  setgrent(); 
104 
105  puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
106  pw = getpwnam( "root" );
107  rtems_test_assert( !pw );
108  rtems_test_assert( errno == EINVAL );
109
110  fp = fopen( "/etc/passwd", "w" );
111  rtems_test_assert( fp != NULL );
112  fprintf( fp, "rtems:x:1:1:dummy::/:/bin/bash:" );
113  fclose( fp );
114
115  puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
116  pw = getpwnam( "root" );
117  rtems_test_assert( !pw );
118  rtems_test_assert( errno == EINVAL );
119
120  fp = fopen( "/etc/passwd", "w" );
121  rtems_test_assert( fp != NULL );
122  fprintf( fp, "user\n:x:2:2:dummy::/:/bin/sh\n" );
123  fclose( fp );
124
125  puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
126  pw = getpwnam( "root" );
127  rtems_test_assert( !pw );
128  rtems_test_assert( errno == EINVAL );
129
130  puts( "Init - getgrent() -- OK" );
131  gr = getgrent();
132  rtems_test_assert( gr != NULL );
133  print_group( gr );
134
135  puts( "Init - endpwent() -- OK" );
136  endpwent();
137
138  puts( "Init - endpwent() -- OK" );
139  endpwent();
140
141  puts( "Init - endgrent() -- OK" );
142  endgrent();
143
144  puts( "Init - endgrent() -- OK" );
145  endgrent();
146
147  puts( "Removing /etc/passwd" );
148  status = unlink( "/etc/passwd" );
149  rtems_test_assert( status == 0 );
150
151  puts( "Removing /etc/group" );
152  status = unlink( "/etc/group" );
153  rtems_test_assert( status == 0 );
154
155  puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
156  pw = getpwnam( "root" );
157  rtems_test_assert( !pw );
158  rtems_test_assert( errno == EINVAL );
159
160  puts( "Init - getgrnam(\"root\") -- expected EINVAL" );
161  gr = getgrnam( "root" );
162  rtems_test_assert( !gr );
163  rtems_test_assert( errno == EINVAL );
164 
165  puts( "*** END OF PASSWORD/GROUP TEST - 02 ***" );
166  rtems_test_exit( 0 );
167}
168
169/* configuration information */
170
171#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
172#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
173
174#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
175#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
176
177#define CONFIGURE_MAXIMUM_TASKS 1
178#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
179
180#define CONFIGURE_INIT
181#include <rtems/confdefs.h>
182/* end of file */
Note: See TracBrowser for help on using the repository browser.