source: rtems/testsuites/psxtests/psxpasswd01/init.c

Last change on this file was 5594854, checked in by Joel Sherrill <joel@…>, on 04/07/22 at 15:05:28

testsuites/psxtests/psx[n-z]*: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 *  COPYRIGHT (c) 1989-2012.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <bsp.h>
34#include <pmacros.h>
35#include <sys/types.h>
36#include <pwd.h>
37#include <grp.h>
38
39const char rtems_test_name[] = "PSXPASSWD 1";
40
41/* forward declarations to avoid warnings */
42rtems_task Init(rtems_task_argument ignored);
43void print_passwd(struct passwd *pw);
44void print_group(struct group *gr);
45
46void print_passwd(
47  struct passwd *pw
48)
49{
50  printf(
51    "  username: %s\n"
52    "  user password: %s\n"
53    "  user ID: %d\n"
54    "  group ID: %d\n"
55    "  real name: %s\n"
56    "  home directory: %s\n"
57    "  shell program: %s\n",
58    pw->pw_name,
59    pw->pw_passwd,
60    pw->pw_uid,
61    pw->pw_gid,
62    pw->pw_gecos,
63    pw->pw_dir,
64    pw->pw_shell
65  );
66}
67 
68void print_group(
69  struct group *gr
70)
71{
72  printf(
73    "  group name: %s\n"
74    "  group  password: %s\n"
75    "  group  ID: %d\n",
76    gr->gr_name,
77    gr->gr_passwd,
78    gr->gr_gid
79  );
80
81  /* TBD print users in group */
82}
83 
84rtems_task Init(
85  rtems_task_argument ignored
86)
87{
88  struct passwd *pw;
89  struct group  *gr;
90
91  TEST_BEGIN();
92
93  /* getpwent */
94  puts( "Init - getpwent() -- OK, result should be NULL" );
95  pw = getpwent();
96  rtems_test_assert( !pw );
97
98  /* getgrent */
99  puts( "Init - getgrent() -- OK, result should be NULL" );
100  gr = getgrent();
101  rtems_test_assert( !gr );
102
103  /* setpwent */
104
105  puts( "Init - setpwent() -- OK" );
106  setpwent();
107
108  /* setgrent */
109
110  puts( "Init - setgrent() -- OK" );
111  setgrent();
112
113  /* getpwent */
114
115  puts( "Init - getpwent() (1) -- OK" );
116  pw = getpwent();
117  rtems_test_assert( pw );
118  print_passwd( pw );
119
120  puts( "Init - getpwent() (2) -- result should be NULL" );
121  pw = getpwent();
122  rtems_test_assert( !pw );
123
124  /* getgrent */
125
126  puts( "Init - getgrent() (1) -- OK" );
127  gr = getgrent();
128  rtems_test_assert( gr );
129  print_group( gr );
130
131  puts( "Init - getgrent() (2) -- result should be NULL" );
132  gr = getgrent();
133  rtems_test_assert( !gr );
134
135  /* getpwnam */
136  puts( "Init - getpwnam(\"root\") -- OK" );
137  pw = getpwnam( "root" );
138  rtems_test_assert( pw );
139  print_passwd( pw );
140
141  puts( "Init - getpwnam(\"suser\") -- result should be NULL" );
142  pw = getpwnam( "suser" );
143  rtems_test_assert( !pw );
144
145  /* getpwuid */
146  puts( "Init - getpwuid(0) -- OK" );
147  pw = getpwuid( 0 );
148  rtems_test_assert( pw );
149  print_passwd( pw );
150
151  rtems_test_assert( strcmp(pw->pw_name, "root") == 0 );
152  rtems_test_assert( strcmp(pw->pw_passwd, "") == 0 );
153  rtems_test_assert( pw->pw_uid == 0 );
154  rtems_test_assert( pw->pw_gid == 0 );
155  rtems_test_assert( strcmp(pw->pw_comment, "") == 0 );
156  rtems_test_assert( strcmp(pw->pw_gecos, "") == 0 );
157  rtems_test_assert( strcmp(pw->pw_dir, "") == 0 );
158  rtems_test_assert( strcmp(pw->pw_shell, "") == 0 );
159
160  puts( "Init - getpwuid(4) -- result should be NULL" );
161  pw = getpwuid( 4 );
162  rtems_test_assert( !pw );
163
164  /* getgrnam */
165  puts( "Init - getgrnam(\"root\") -- OK" );
166  gr = getgrnam("root");
167  rtems_test_assert( gr );
168  print_group( gr );
169
170  /* getgrgid */
171  puts( "Init - getgrgid(0) -- OK" );
172  gr = getgrgid(0);
173  rtems_test_assert( gr );
174  print_group( gr );
175
176  rtems_test_assert( strcmp(gr->gr_name, "root") == 0 );
177  rtems_test_assert( strcmp(gr->gr_passwd, "") == 0 );
178  rtems_test_assert( gr->gr_gid == 0 );
179  rtems_test_assert( gr->gr_mem[0] == NULL );
180
181  puts( "Init - getgrgid(4) -- result should be NULL");
182  gr = getgrgid( 4 );
183  rtems_test_assert( !gr );
184
185  /* endpwent */
186  puts( "Init - endpwent() -- OK" );
187  endpwent();
188
189  /* endgrent */
190  puts( "Init - endgrent() -- OK" );
191  endgrent();
192
193  TEST_END();
194  rtems_test_exit( 0 );
195}
196
197/* configuration information */
198
199#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
200#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
201
202#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 6
203
204#define CONFIGURE_MAXIMUM_TASKS 1
205#define CONFIGURE_MAXIMUM_POSIX_KEYS 1
206#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 1
207#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
208
209#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
210
211#define CONFIGURE_INIT
212#include <rtems/confdefs.h>
213/* end of file */
Note: See TracBrowser for help on using the repository browser.