Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:40

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include <bsp.h>
0034 #include <pmacros.h>
0035 #include <sys/types.h>
0036 #include <pwd.h>
0037 #include <grp.h>
0038 
0039 const char rtems_test_name[] = "PSXPASSWD 1";
0040 
0041 /* forward declarations to avoid warnings */
0042 rtems_task Init(rtems_task_argument ignored);
0043 void print_passwd(struct passwd *pw);
0044 void print_group(struct group *gr);
0045 
0046 void print_passwd(
0047   struct passwd *pw
0048 )
0049 {
0050   printf( 
0051     "  username: %s\n"
0052     "  user password: %s\n"
0053     "  user ID: %d\n"
0054     "  group ID: %d\n"
0055     "  real name: %s\n"
0056     "  home directory: %s\n"
0057     "  shell program: %s\n",
0058     pw->pw_name,
0059     pw->pw_passwd,
0060     pw->pw_uid,
0061     pw->pw_gid,
0062     pw->pw_gecos,
0063     pw->pw_dir,
0064     pw->pw_shell
0065   );
0066 }
0067   
0068 void print_group(
0069   struct group *gr
0070 )
0071 {
0072   printf( 
0073     "  group name: %s\n"
0074     "  group  password: %s\n"
0075     "  group  ID: %d\n",
0076     gr->gr_name,
0077     gr->gr_passwd,
0078     gr->gr_gid
0079   );
0080 
0081   /* TBD print users in group */
0082 }
0083   
0084 rtems_task Init(
0085   rtems_task_argument ignored
0086 )
0087 {
0088   struct passwd *pw;
0089   struct group  *gr;
0090 
0091   TEST_BEGIN();
0092 
0093   /* getpwent */
0094   puts( "Init - getpwent() -- OK, result should be NULL" );
0095   pw = getpwent();
0096   rtems_test_assert( !pw );
0097 
0098   /* getgrent */
0099   puts( "Init - getgrent() -- OK, result should be NULL" );
0100   gr = getgrent();
0101   rtems_test_assert( !gr );
0102 
0103   /* setpwent */
0104 
0105   puts( "Init - setpwent() -- OK" );
0106   setpwent();
0107 
0108   /* setgrent */
0109 
0110   puts( "Init - setgrent() -- OK" );
0111   setgrent();
0112 
0113   /* getpwent */
0114 
0115   puts( "Init - getpwent() (1) -- OK" );
0116   pw = getpwent();
0117   rtems_test_assert( pw );
0118   print_passwd( pw );
0119 
0120   puts( "Init - getpwent() (2) -- result should be NULL" );
0121   pw = getpwent();
0122   rtems_test_assert( !pw );
0123 
0124   /* getgrent */
0125 
0126   puts( "Init - getgrent() (1) -- OK" );
0127   gr = getgrent();
0128   rtems_test_assert( gr );
0129   print_group( gr );
0130 
0131   puts( "Init - getgrent() (2) -- result should be NULL" );
0132   gr = getgrent();
0133   rtems_test_assert( !gr );
0134 
0135   /* getpwnam */
0136   puts( "Init - getpwnam(\"root\") -- OK" );
0137   pw = getpwnam( "root" );
0138   rtems_test_assert( pw );
0139   print_passwd( pw );
0140 
0141   puts( "Init - getpwnam(\"suser\") -- result should be NULL" );
0142   pw = getpwnam( "suser" );
0143   rtems_test_assert( !pw );
0144 
0145   /* getpwuid */
0146   puts( "Init - getpwuid(0) -- OK" );
0147   pw = getpwuid( 0 );
0148   rtems_test_assert( pw );
0149   print_passwd( pw );
0150 
0151   rtems_test_assert( strcmp(pw->pw_name, "root") == 0 );
0152   rtems_test_assert( strcmp(pw->pw_passwd, "") == 0 );
0153   rtems_test_assert( pw->pw_uid == 0 );
0154   rtems_test_assert( pw->pw_gid == 0 );
0155   rtems_test_assert( strcmp(pw->pw_comment, "") == 0 );
0156   rtems_test_assert( strcmp(pw->pw_gecos, "") == 0 );
0157   rtems_test_assert( strcmp(pw->pw_dir, "") == 0 );
0158   rtems_test_assert( strcmp(pw->pw_shell, "") == 0 );
0159 
0160   puts( "Init - getpwuid(4) -- result should be NULL" );
0161   pw = getpwuid( 4 );
0162   rtems_test_assert( !pw );
0163 
0164   /* getgrnam */
0165   puts( "Init - getgrnam(\"root\") -- OK" );
0166   gr = getgrnam("root");
0167   rtems_test_assert( gr );
0168   print_group( gr );
0169 
0170   /* getgrgid */
0171   puts( "Init - getgrgid(0) -- OK" );
0172   gr = getgrgid(0);
0173   rtems_test_assert( gr );
0174   print_group( gr );
0175 
0176   rtems_test_assert( strcmp(gr->gr_name, "root") == 0 );
0177   rtems_test_assert( strcmp(gr->gr_passwd, "") == 0 );
0178   rtems_test_assert( gr->gr_gid == 0 );
0179   rtems_test_assert( gr->gr_mem[0] == NULL );
0180 
0181   puts( "Init - getgrgid(4) -- result should be NULL");
0182   gr = getgrgid( 4 );
0183   rtems_test_assert( !gr );
0184 
0185   /* endpwent */
0186   puts( "Init - endpwent() -- OK" );
0187   endpwent();
0188 
0189   /* endgrent */
0190   puts( "Init - endgrent() -- OK" );
0191   endgrent();
0192 
0193   TEST_END();
0194   rtems_test_exit( 0 );
0195 }
0196 
0197 /* configuration information */
0198 
0199 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0200 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0201 
0202 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 6
0203 
0204 #define CONFIGURE_MAXIMUM_TASKS 1
0205 #define CONFIGURE_MAXIMUM_POSIX_KEYS 1
0206 #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 1
0207 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0208 
0209 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0210 
0211 #define CONFIGURE_INIT
0212 #include <rtems/confdefs.h>
0213 /* end of file */