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.
This commit is contained in:
Joel Sherrill
2010-07-01 17:26:37 +00:00
parent c40d3c4b02
commit 1fe4042000
11 changed files with 462 additions and 9 deletions
+10
View File
@@ -1,3 +1,13 @@
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>
PR 1597/cpukit
+1 -1
View File
@@ -20,7 +20,7 @@ endif
## 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
## enabled to support readv and writev. Hopefully this is a temporary
+1
View File
@@ -105,6 +105,7 @@ psxmsgq04/Makefile
psxmutexattr01/Makefile
psxobj01/Makefile
psxpasswd01/Makefile
psxpasswd02/Makefile
psxreaddir/Makefile
psxrdwrv/Makefile
psxrwlock01/Makefile
+108 -4
View File
@@ -60,19 +60,100 @@ rtems_task Init(
struct passwd *pw;
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");
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 */
puts( "Init - getgrnam(\"root\") -- OK" );
gr = getgrnam("root");
@@ -84,7 +165,30 @@ rtems_task Init(
rtems_test_assert( gr );
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 );
}
@@ -18,11 +18,17 @@ directives:
getpwuid
getpwnam_r
getpwuid_r
getpwent
setpwent
endpwent
getgrnam
getgrgid
getgrnam_r
getgrgid_r
getgrent
setgrent
endgrent
concepts:
@@ -1,4 +1,48 @@
*** 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
user password: *
@@ -15,7 +59,24 @@ Init - getpwnam("rtems") -- OK
real name:
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
group password: x
@@ -24,5 +85,15 @@ Init - getgrnam("rtems") -- OK
group name: rtems
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 ***
@@ -0,0 +1,2 @@
Makefile
Makefile.in
@@ -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
+182
View File
@@ -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 */
@@ -0,0 +1,26 @@
#
# $Id$
#
# 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.
#
This file describes the directives and concepts tested by this test set.
test set name: POSIX PASSWD/GROUP TEST
directives:
+ setpwent
+ setgrent
+ getpwnam
+ endpwent
+ endgrent
concepts:
+ Exercise error paths in /etc/passwd and /etc/group.
@@ -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 ***