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

4.11
Last change on this file since 1fe4042 was 1fe4042, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 1, 2010 at 5:26:37 PM

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.2 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
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
18void print_passwd(
19  struct passwd *pw
20)
21{
22  printf( 
23    "  username: %s\n"
24    "  user password: %s\n"
25    "  user ID: %d\n"
26    "  group ID: %d\n"
27    "  real name: %s\n"
28    "  home directory: %s\n"
29    "  shell program: %s\n",
30    pw->pw_name,
31    pw->pw_passwd,
32    pw->pw_uid,
33    pw->pw_gid,
34    pw->pw_gecos,
35    pw->pw_dir,
36    pw->pw_shell
37  );
38}
39 
40void print_group(
41  struct group *gr
42)
43{
44  printf( 
45    "  group name: %s\n"
46    "  group  password: %s\n"
47    "  group  ID: %d\n",
48    gr->gr_name,
49    gr->gr_passwd,
50    gr->gr_gid
51  );
52
53  /* TBD print users in group */
54}
55 
56rtems_task Init(
57  rtems_task_argument ignored
58)
59{
60  struct passwd *pw;
61  struct group  *gr;
62
63  puts( "*** PASSWORD/GROUP TEST - 01 ***" );
64
65  /* getpwent */
66  puts( "Init - getpwent() -- OK, result should be NULL" );
67  pw = getpwent();
68  rtems_test_assert( !pw );
69
70  /* getgrent */
71  puts( "Init - getgrent() -- OK, result should be NULL" );
72  gr = getgrent();
73  rtems_test_assert( !gr );
74
75  /* setpwent */
76
77  puts( "Init - setpwent() -- OK" );
78  setpwent();
79
80  /* setgrent */
81
82  puts( "Init - setgrent() -- OK" );
83  setgrent();
84
85  /* getpwent */
86
87  puts( "Init - getpwent() (1) -- OK" );
88  pw = getpwent();
89  rtems_test_assert( pw );
90  print_passwd( pw );
91
92  puts( "Init - getpwent() (2) -- OK" );
93  pw = getpwent();
94  rtems_test_assert( pw );
95  print_passwd( pw );
96
97  puts( "Init - getpwent() (3) -- OK" );
98  pw = getpwent();
99  rtems_test_assert( pw );
100  print_passwd( pw );
101
102  puts( "Init - getpwent() (4) -- result should be NULL" );
103  pw = getpwent();
104  rtems_test_assert( !pw );
105
106  /* getgrent */
107
108  puts( "Init - getgrent() (1) -- OK" );
109  gr = getgrent();
110  rtems_test_assert( gr );
111  print_group( gr );
112
113  puts( "Init - getgrent() (2) -- OK" );
114  gr = getgrent();
115  rtems_test_assert( gr );
116  print_group( gr );
117
118  puts( "Init - getgrent() (3) -- OK" );
119  gr = getgrent();
120  rtems_test_assert( gr );
121  print_group( gr );
122
123  puts( "Init - getgrent() (4) -- result should be NULL" );
124  gr = getgrent();
125  rtems_test_assert( !gr );
126
127  /* getpwnam */
128  puts( "Init - getpwnam(\"root\") -- OK" );
129  pw = getpwnam( "root" );
130  rtems_test_assert( pw );
131  print_passwd( pw );
132
133  puts( "Init - getpwnam(\"rtems\") -- OK" );
134  pw = getpwnam( "rtems" );
135  rtems_test_assert( pw );
136  print_passwd( pw );
137
138  puts( "Init - getpwnam(\"suser\") -- result should be NULL" );
139  pw = getpwnam( "suser" );
140  rtems_test_assert( !pw );
141
142  /* getpwuid */
143  puts( "Init - getpwuid(0) -- OK" );
144  pw = getpwuid( 0 );
145  rtems_test_assert( pw );
146  print_passwd( pw );
147
148  puts( "Init - getpwuid(1) -- OK" );
149  pw = getpwuid( 1 );
150  rtems_test_assert( pw );
151  print_passwd( pw );
152
153  puts( "Init - getpwuid(4) -- result should be NULL" );
154  pw = getpwuid( 4 );
155  rtems_test_assert( !pw );
156
157  /* getgrnam */
158  puts( "Init - getgrnam(\"root\") -- OK" );
159  gr = getgrnam("root");
160  rtems_test_assert( gr );
161  print_group( gr );
162
163  puts( "Init - getgrnam(\"rtems\") -- OK" );
164  gr = getgrnam("rtems");
165  rtems_test_assert( gr );
166  print_group( gr );
167
168  /* getgrgid */
169  puts( "Init - getgrgid(0) -- OK" );
170  gr = getgrgid(0);
171  rtems_test_assert( gr );
172  print_group( gr );
173
174  puts( "Init - getgrgid(1) -- OK" );
175  gr = getgrgid(1);
176  rtems_test_assert( gr );
177  print_group( gr );
178
179  puts( "Init - getgrgid(4) -- result should be NULL");
180  gr = getgrgid( 4 );
181  rtems_test_assert( !gr );
182
183  /* endpwent */
184  puts( "Init - endpwent() -- OK" );
185  endpwent();
186
187  /* endgrent */
188  puts( "Init - endgrent() -- OK" );
189  endgrent();
190
191  puts( "*** END OF PASSWORD/GROUP TEST - 01 ***" );
192  rtems_test_exit( 0 );
193}
194
195/* configuration information */
196
197#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
198#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
199
200#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
201#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
202
203#define CONFIGURE_MAXIMUM_TASKS 1
204#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
205
206#define CONFIGURE_INIT
207#include <rtems/confdefs.h>
208/* end of file */
Note: See TracBrowser for help on using the repository browser.