Index: testsuites/psxtests/ChangeLog
===================================================================
--- testsuites/psxtests/ChangeLog	(revision c40d3c4b02ba66dbc99ad7fd01813e42f1b99c6a)
+++ testsuites/psxtests/ChangeLog	(revision 0d923d9705d89c78190dea017ccbab37e5724fce)
@@ -1,2 +1,12 @@
+2010-07-01	Bharath Suri <bharath.s.jois@gmail.com>
+
+	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.
+
 2010-07-01	Vinu Rajashekhar <vinutheraj@gmail.com>
 
Index: testsuites/psxtests/Makefile.am
===================================================================
--- testsuites/psxtests/Makefile.am	(revision c40d3c4b02ba66dbc99ad7fd01813e42f1b99c6a)
+++ testsuites/psxtests/Makefile.am	(revision 0d923d9705d89c78190dea017ccbab37e5724fce)
@@ -21,5 +21,5 @@
 ## File IO tests
 SUBDIRS += psxfile01 psxfile02 psxfilelock01 psxid01 psximfs01 psxreaddir \
-    psxstat psxmount psx13 psxchroot01 psxpasswd01
+    psxstat psxmount psx13 psxchroot01 psxpasswd01 psxpasswd02
 
 ## Until sys/uio.h is moved to libcsupport, we have to have networking
Index: testsuites/psxtests/configure.ac
===================================================================
--- testsuites/psxtests/configure.ac	(revision c40d3c4b02ba66dbc99ad7fd01813e42f1b99c6a)
+++ testsuites/psxtests/configure.ac	(revision 0d923d9705d89c78190dea017ccbab37e5724fce)
@@ -106,4 +106,5 @@
 psxobj01/Makefile
 psxpasswd01/Makefile
+psxpasswd02/Makefile
 psxreaddir/Makefile
 psxrdwrv/Makefile
Index: testsuites/psxtests/psxpasswd01/init.c
===================================================================
--- testsuites/psxtests/psxpasswd01/init.c	(revision c40d3c4b02ba66dbc99ad7fd01813e42f1b99c6a)
+++ testsuites/psxtests/psxpasswd01/init.c	(revision 0d923d9705d89c78190dea017ccbab37e5724fce)
@@ -61,16 +61,97 @@
   struct group  *gr;
 
-  puts( "*** PASSWORD/GROUP TEST ***" );
+  puts( "*** PASSWORD/GROUP TEST - 01 ***" );
+
+  /* getpwent */
+  puts( "Init - getpwent() -- OK, result should be NULL" );
+  pw = getpwent();
+  rtems_test_assert( !pw );
+
+  /* getgrent */
+  puts( "Init - getgrent() -- OK, result should be NULL" );
+  gr = getgrent();
+  rtems_test_assert( !gr );
+
+  /* setpwent */
+
+  puts( "Init - setpwent() -- OK" );
+  setpwent();
+
+  /* setgrent */
+
+  puts( "Init - setgrent() -- OK" );
+  setgrent();
+
+  /* getpwent */
+
+  puts( "Init - getpwent() (1) -- OK" );
+  pw = getpwent();
+  rtems_test_assert( pw );
+  print_passwd( pw );
+
+  puts( "Init - getpwent() (2) -- OK" );
+  pw = getpwent();
+  rtems_test_assert( pw );
+  print_passwd( pw );
+
+  puts( "Init - getpwent() (3) -- OK" );
+  pw = getpwent();
+  rtems_test_assert( pw );
+  print_passwd( pw );
+
+  puts( "Init - getpwent() (4) -- result should be NULL" );
+  pw = getpwent();
+  rtems_test_assert( !pw );
+
+  /* getgrent */
+
+  puts( "Init - getgrent() (1) -- OK" );
+  gr = getgrent();
+  rtems_test_assert( gr );
+  print_group( gr );
+
+  puts( "Init - getgrent() (2) -- OK" );
+  gr = getgrent();
+  rtems_test_assert( gr );
+  print_group( gr );
+
+  puts( "Init - getgrent() (3) -- OK" );
+  gr = getgrent();
+  rtems_test_assert( gr );
+  print_group( gr );
+
+  puts( "Init - getgrent() (4) -- result should be NULL" );
+  gr = getgrent();
+  rtems_test_assert( !gr );
 
   /* getpwnam */
   puts( "Init - getpwnam(\"root\") -- OK" );
-  pw = getpwnam("root");
+  pw = getpwnam( "root" );
   rtems_test_assert( pw );
   print_passwd( pw );
 
   puts( "Init - getpwnam(\"rtems\") -- OK" );
-  pw = getpwnam("rtems");
-  rtems_test_assert( pw );
-  print_passwd( pw );
+  pw = getpwnam( "rtems" );
+  rtems_test_assert( pw );
+  print_passwd( pw );
+
+  puts( "Init - getpwnam(\"suser\") -- result should be NULL" );
+  pw = getpwnam( "suser" );
+  rtems_test_assert( !pw );
+
+  /* getpwuid */
+  puts( "Init - getpwuid(0) -- OK" );
+  pw = getpwuid( 0 );
+  rtems_test_assert( pw );
+  print_passwd( pw );
+
+  puts( "Init - getpwuid(1) -- OK" );
+  pw = getpwuid( 1 );
+  rtems_test_assert( pw );
+  print_passwd( pw );
+
+  puts( "Init - getpwuid(4) -- result should be NULL" );
+  pw = getpwuid( 4 );
+  rtems_test_assert( !pw );
 
   /* getgrnam */
@@ -85,5 +166,28 @@
   print_group( gr );
 
-  puts( "*** END OF PASSWORD/GROUP TEST ***" );
+  /* getgrgid */
+  puts( "Init - getgrgid(0) -- OK" );
+  gr = getgrgid(0);
+  rtems_test_assert( gr );
+  print_group( gr );
+
+  puts( "Init - getgrgid(1) -- OK" );
+  gr = getgrgid(1);
+  rtems_test_assert( gr );
+  print_group( gr );
+
+  puts( "Init - getgrgid(4) -- result should be NULL");
+  gr = getgrgid( 4 );
+  rtems_test_assert( !gr );
+
+  /* endpwent */
+  puts( "Init - endpwent() -- OK" );
+  endpwent();
+
+  /* endgrent */
+  puts( "Init - endgrent() -- OK" );
+  endgrent();
+
+  puts( "*** END OF PASSWORD/GROUP TEST - 01 ***" );
   rtems_test_exit( 0 );
 }
Index: testsuites/psxtests/psxpasswd01/psxpasswd01.scn
===================================================================
--- testsuites/psxtests/psxpasswd01/psxpasswd01.scn	(revision c40d3c4b02ba66dbc99ad7fd01813e42f1b99c6a)
+++ testsuites/psxtests/psxpasswd01/psxpasswd01.scn	(revision 0d923d9705d89c78190dea017ccbab37e5724fce)
@@ -1,3 +1,47 @@
-*** PASSWORD/GROUP TEST ***
+Initialized console on port COM1 9600-8-N-1
+
+*** PASSWORD/GROUP TEST - 01 ***
+Init - getpwent() -- OK, result should be NULL
+Init - getgrent() -- OK, result should be NULL
+Init - setpwent() -- OK
+Init - setgrent() -- OK
+Init - getpwent() (1) -- OK
+  username: root
+  user password: *
+  user ID: 0
+  group ID: 0
+  real name: 
+  home directory: /
+  shell program: /bin/sh
+Init - getpwent() (2) -- OK
+  username: rtems
+  user password: *
+  user ID: 1
+  group ID: 1
+  real name: 
+  home directory: /
+  shell program: /bin/sh
+Init - getpwent() (3) -- OK
+  username: tty
+  user password: !
+  user ID: 2
+  group ID: 2
+  real name: 
+  home directory: /
+  shell program: /bin/false
+Init - getpwent() (4) -- result should be NULL
+Init - getgrent() (1) -- OK
+  group name: root
+  group  password: x
+  group  ID: 0
+Init - getgrent() (2) -- OK
+  group name: rtems
+  group  password: x
+  group  ID: 1
+Init - getgrent() (3) -- OK
+  group name: tty
+  group  password: x
+  group  ID: 2
+Init - getgrent() (4) -- result should be NULL
 Init - getpwnam("root") -- OK
   username: root
@@ -16,5 +60,22 @@
   home directory: /
   shell program: /bin/sh
-
+Init - getpwnam("suser") -- result should be NULL
+Init - getpwuid(0) -- OK
+  username: root
+  user password: *
+  user ID: 0
+  group ID: 0
+  real name: 
+  home directory: /
+  shell program: /bin/sh
+Init - getpwuid(1) -- OK
+  username: rtems
+  user password: *
+  user ID: 1
+  group ID: 1
+  real name: 
+  home directory: /
+  shell program: /bin/sh
+Init - getpwuid(4) -- result should be NULL
 Init - getgrnam("root") -- OK
   group name: root
@@ -25,4 +86,14 @@
   group  password: x
   group  ID: 1
-*** END OF PASSWORD/GROUP TEST ***
-
+Init - getgrgid(0) -- OK
+  group name: root
+  group  password: x
+  group  ID: 0
+Init - getgrgid(1) -- OK
+  group name: rtems
+  group  password: x
+  group  ID: 1
+Init - getgrgid(4) -- result should be NULL
+Init - endpwent() -- OK
+Init - endgrent() -- OK
+*** END OF PASSWORD/GROUP TEST - 01 ***
Index: testsuites/psxtests/psxpasswd02/.cvsignore
===================================================================
--- testsuites/psxtests/psxpasswd02/.cvsignore	(revision 0d923d9705d89c78190dea017ccbab37e5724fce)
+++ testsuites/psxtests/psxpasswd02/.cvsignore	(revision 0d923d9705d89c78190dea017ccbab37e5724fce)
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
Index: testsuites/psxtests/psxpasswd02/Makefile.am
===================================================================
--- testsuites/psxtests/psxpasswd02/Makefile.am	(revision 0d923d9705d89c78190dea017ccbab37e5724fce)
+++ testsuites/psxtests/psxpasswd02/Makefile.am	(revision 0d923d9705d89c78190dea017ccbab37e5724fce)
@@ -0,0 +1,27 @@
+##
+## $Id$
+##
+
+MANAGERS = all
+
+rtems_tests_PROGRAMS = psxpasswd02
+psxpasswd02_SOURCES = init.c ../include/pmacros.h
+
+dist_rtems_tests_DATA = psxpasswd02.scn
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+
+AM_CPPFLAGS += -I$(top_srcdir)/include
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(psxpasswd02_OBJECTS) $(psxpasswd02_LDADD)
+LINK_LIBS = $(psxpasswd02_LDLIBS)
+
+psxpasswd02$(EXEEXT): $(psxpasswd02_OBJECTS) $(psxpasswd02_DEPENDENCIES)
+	@rm -f psxpasswd02$(EXEEXT)
+	$(make-exe)
+
+include $(top_srcdir)/../automake/local.am
Index: testsuites/psxtests/psxpasswd02/init.c
===================================================================
--- testsuites/psxtests/psxpasswd02/init.c	(revision 0d923d9705d89c78190dea017ccbab37e5724fce)
+++ testsuites/psxtests/psxpasswd02/init.c	(revision 0d923d9705d89c78190dea017ccbab37e5724fce)
@@ -0,0 +1,182 @@
+/*
+ *  COPYRIGHT (c) 1989-2010.
+ *  On-Line Applications Research Corporation (OAR).
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.com/license/LICENSE.
+ *
+ *  $Id$
+ */
+
+#include <bsp.h>
+#include <pmacros.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include <grp.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+void print_passwd(
+  struct passwd *pw
+)
+{
+  printf( 
+    "  username: %s\n"
+    "  user password: %s\n"
+    "  user ID: %d\n"
+    "  group ID: %d\n"
+    "  real name: %s\n"
+    "  home directory: %s\n"
+    "  shell program: %s\n",
+    pw->pw_name,
+    pw->pw_passwd,
+    pw->pw_uid,
+    pw->pw_gid,
+    pw->pw_gecos,
+    pw->pw_dir,
+    pw->pw_shell
+  );
+}
+  
+void print_group(
+  struct group *gr
+)
+{
+  printf( 
+    "  group name: %s\n"
+    "  group  password: %s\n"
+    "  group  ID: %d\n",
+    gr->gr_name,
+    gr->gr_passwd,
+    gr->gr_gid
+  );
+
+  /* TBD print users in group */
+}
+  
+rtems_task Init(
+  rtems_task_argument ignored
+)
+{
+  struct passwd *pw;
+  struct group  *gr;
+  int status = -1;
+
+  FILE *fp = NULL;
+
+  puts( "*** PASSWORD/GROUP TEST - 02 ***" );
+
+  puts( "Init - Creating /etc" );
+  status = mkdir( "/etc", 0777 );
+  rtems_test_assert( status == 0 );
+  
+  puts( "Init - Creating /etc/passwd" );
+  status = mknod( "/etc/passwd", (S_IFREG | S_IRWXU), 0LL );
+  rtems_test_assert( status != -1 );
+
+  fp = fopen( "/etc/passwd", "w" );
+  rtems_test_assert( fp != NULL );
+  fprintf( fp, "bharath:x:-1:-a:Dummy::/:/bin/bash\n" );
+  fclose( fp );
+
+  puts( "Init - Creating /etc/group" );
+  status = mknod( "/etc/group", (S_IFREG | S_IRWXU), 0LL );
+  rtems_test_assert( status != -1);
+
+  fp = fopen( "/etc/group", "w" );
+  rtems_test_assert( fp != NULL );
+  fprintf( fp, "admin::1:root,su,super-user\n" );
+  fclose( fp );
+
+  puts( "Init - setpwent() -- OK" );
+  setpwent();
+
+  puts( "Init - setpwent() -- OK" );
+  setpwent();
+
+  puts( "Init - setgrent() -- OK" );
+  setgrent();
+
+  puts( "Init - setgrent() -- OK" );
+  setgrent();  
+ 
+  puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
+  pw = getpwnam( "root" );
+  rtems_test_assert( !pw );
+  rtems_test_assert( errno == EINVAL );
+
+  fp = fopen( "/etc/passwd", "w" );
+  rtems_test_assert( fp != NULL );
+  fprintf( fp, "rtems:x:1:1:dummy::/:/bin/bash:" );
+  fclose( fp );
+
+  puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
+  pw = getpwnam( "root" );
+  rtems_test_assert( !pw ); 
+  rtems_test_assert( errno == EINVAL );
+
+  fp = fopen( "/etc/passwd", "w" );
+  rtems_test_assert( fp != NULL );
+  fprintf( fp, "user\n:x:2:2:dummy::/:/bin/sh\n" );
+  fclose( fp );
+
+  puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
+  pw = getpwnam( "root" );
+  rtems_test_assert( !pw ); 
+  rtems_test_assert( errno == EINVAL );
+
+  puts( "Init - getgrent() -- OK" );
+  gr = getgrent();
+  rtems_test_assert( gr != NULL );
+  print_group( gr );
+
+  puts( "Init - endpwent() -- OK" );
+  endpwent();
+
+  puts( "Init - endpwent() -- OK" );
+  endpwent();
+
+  puts( "Init - endgrent() -- OK" );
+  endgrent();
+
+  puts( "Init - endgrent() -- OK" );
+  endgrent();
+
+  puts( "Removing /etc/passwd" );
+  status = unlink( "/etc/passwd" );
+  rtems_test_assert( status == 0 );
+
+  puts( "Removing /etc/group" );
+  status = unlink( "/etc/group" );
+  rtems_test_assert( status == 0 );
+
+  puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
+  pw = getpwnam( "root" );
+  rtems_test_assert( !pw );
+  rtems_test_assert( errno == EINVAL );
+
+  puts( "Init - getgrnam(\"root\") -- expected EINVAL" );
+  gr = getgrnam( "root" );
+  rtems_test_assert( !gr );
+  rtems_test_assert( errno == EINVAL );
+  
+  puts( "*** END OF PASSWORD/GROUP TEST - 02 ***" );
+  rtems_test_exit( 0 );
+}
+
+/* configuration information */
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
+/* end of file */
Index: testsuites/psxtests/psxpasswd02/psxpasswd02.scn
===================================================================
--- testsuites/psxtests/psxpasswd02/psxpasswd02.scn	(revision 0d923d9705d89c78190dea017ccbab37e5724fce)
+++ testsuites/psxtests/psxpasswd02/psxpasswd02.scn	(revision 0d923d9705d89c78190dea017ccbab37e5724fce)
@@ -0,0 +1,24 @@
+*** PASSWORD/GROUP TEST - 02 ***
+Init - Creating /etc
+Init - Creating /etc/passwd
+Init - Creating /etc/group
+Init - setpwent() -- OK
+Init - setpwent() -- OK
+Init - setgrent() -- OK
+Init - setgrent() -- OK
+Init - getpwnam("root") -- expected EINVAL
+Init - getpwnam("root") -- expected EINVAL
+Init - getpwnam("root") -- expected EINVAL
+Init - getgrent() -- OK
+  group name: admin
+  group  password: 
+  group  ID: 1
+Init - endpwent() -- OK
+Init - endpwent() -- OK
+Init - endgrent() -- OK
+Init - endgrent() -- OK
+Removing /etc/passwd
+Removing /etc/group
+Init - getpwnam("root") -- expected EINVAL
+Init - getgrnam("root") -- expected EINVAL
+*** END OF PASSWORD/GROUP TEST - 02 ***
