summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2001-08-09 22:11:19 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2001-08-09 22:11:19 +0000
commitccb13cfe7c506159412f124b17e1bba61a035913 (patch)
tree7f70143c9f4053445c1fdd672394fc873379c6df
parentb6a2d2fa5d0fedd509584e3faa4c88e1982900b7 (diff)
downloadrtems-ccb13cfe7c506159412f124b17e1bba61a035913.tar.bz2
2001-08-09 Fernando-Ruiz Casas <correo@fernando-ruiz.com>
* libc/getgrent.c, libc/getpwent.c: the 'ls' and more related command previous failed after a chroot(). (unknown user & group)
-rw-r--r--c/src/exec/libcsupport/src/getgrent.c17
-rw-r--r--c/src/exec/libcsupport/src/getpwent.c19
-rw-r--r--c/src/lib/ChangeLog5
-rw-r--r--c/src/lib/libc/getgrent.c17
-rw-r--r--c/src/lib/libc/getpwent.c19
-rw-r--r--cpukit/libcsupport/src/getgrent.c17
-rw-r--r--cpukit/libcsupport/src/getpwent.c19
7 files changed, 107 insertions, 6 deletions
diff --git a/c/src/exec/libcsupport/src/getgrent.c b/c/src/exec/libcsupport/src/getgrent.c
index e4fc0fe474..104b0a317f 100644
--- a/c/src/exec/libcsupport/src/getgrent.c
+++ b/c/src/exec/libcsupport/src/getgrent.c
@@ -21,6 +21,9 @@
#include <string.h>
#include <limits.h>
+#include <rtems/libio_.h>
+
+
static struct group gr_group; /* password structure */
static FILE *group_fp;
@@ -47,11 +50,14 @@ int getgrnam_r(
)
{
FILE *fp;
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if ((fp = fopen ("/etc/group", "r")) == NULL) {
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -66,11 +72,13 @@ int getgrnam_r(
if (!strcmp (groupname, name)) {
fclose (fp);
*result = grp;
+ rtems_current_user_env=aux; /* restore */
return 0;
}
}
fclose (fp);
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -96,11 +104,15 @@ int getgrgid_r(
)
{
FILE *fp;
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
+
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if ((fp = fopen ("/etc/group", "r")) == NULL) {
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -116,11 +128,13 @@ int getgrgid_r(
if (gid == gr_group.gr_gid) {
fclose (fp);
*result = grp;
+ rtems_current_user_env=aux; /* restore */
return 0;
}
}
fclose (fp);
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -160,12 +174,15 @@ struct group *getgrent( void )
void
setgrent ()
{
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if (group_fp != NULL)
fclose (group_fp);
group_fp = fopen ("/etc/group", "r");
+ rtems_current_user_env=aux; /* restore */
}
void
diff --git a/c/src/exec/libcsupport/src/getpwent.c b/c/src/exec/libcsupport/src/getpwent.c
index 7b56e26228..91b6550f59 100644
--- a/c/src/exec/libcsupport/src/getpwent.c
+++ b/c/src/exec/libcsupport/src/getpwent.c
@@ -23,6 +23,8 @@
#include <fcntl.h>
#include <unistd.h>
+#include <rtems/libio_.h>
+
static struct passwd pw_passwd; /* password structure */
static FILE *passwd_fp;
@@ -56,7 +58,7 @@ void init_etc_passwd_group(void)
if ( etc_passwd_initted )
return;
etc_passwd_initted = 1;
-
+
(void) mkdir( "/etc", 0777);
/*
@@ -80,7 +82,7 @@ void init_etc_passwd_group(void)
return;
fprintf( fp, "root:x:0:root\n"
- "rtems:x:1:rtems\n"
+ "rtems:x:1:rtems\n"
"tty:x:2:tty\n" );
fclose( fp );
@@ -95,11 +97,14 @@ int getpwnam_r(
)
{
FILE *fp;
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -118,11 +123,13 @@ int getpwnam_r(
if (!strcmp (logname, name)) {
fclose (fp);
*result = pwd;
+ rtems_current_user_env=aux; /* restore */
return 0;
}
}
fclose (fp);
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -148,11 +155,14 @@ int getpwuid_r(
)
{
FILE *fp;
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -171,11 +181,13 @@ int getpwuid_r(
if (uid == pwd->pw_uid) {
fclose (fp);
*result = pwd;
+ rtems_current_user_env=aux; /* restore */
return 0;
}
}
fclose (fp);
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -218,12 +230,15 @@ struct passwd *getpwent()
void setpwent( void )
{
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if (passwd_fp != NULL)
fclose (passwd_fp);
passwd_fp = fopen ("/etc/passwd", "r");
+ rtems_current_user_env=aux; /* restore */
}
void endpwent( void )
diff --git a/c/src/lib/ChangeLog b/c/src/lib/ChangeLog
index ac0322b7bf..a4d4064130 100644
--- a/c/src/lib/ChangeLog
+++ b/c/src/lib/ChangeLog
@@ -1,3 +1,8 @@
+2001-08-09 Fernando-Ruiz Casas <correo@fernando-ruiz.com>
+
+ * libc/getgrent.c, libc/getpwent.c: the 'ls' and more related command
+ previous failed after a chroot(). (unknown user & group)
+
2001-08-03 Joel Sherrill <joel@OARcorp.com>
* libc/libio_sockets.c (rtems_bsdnet_fdToSocket): Per bug
diff --git a/c/src/lib/libc/getgrent.c b/c/src/lib/libc/getgrent.c
index e4fc0fe474..104b0a317f 100644
--- a/c/src/lib/libc/getgrent.c
+++ b/c/src/lib/libc/getgrent.c
@@ -21,6 +21,9 @@
#include <string.h>
#include <limits.h>
+#include <rtems/libio_.h>
+
+
static struct group gr_group; /* password structure */
static FILE *group_fp;
@@ -47,11 +50,14 @@ int getgrnam_r(
)
{
FILE *fp;
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if ((fp = fopen ("/etc/group", "r")) == NULL) {
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -66,11 +72,13 @@ int getgrnam_r(
if (!strcmp (groupname, name)) {
fclose (fp);
*result = grp;
+ rtems_current_user_env=aux; /* restore */
return 0;
}
}
fclose (fp);
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -96,11 +104,15 @@ int getgrgid_r(
)
{
FILE *fp;
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
+
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if ((fp = fopen ("/etc/group", "r")) == NULL) {
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -116,11 +128,13 @@ int getgrgid_r(
if (gid == gr_group.gr_gid) {
fclose (fp);
*result = grp;
+ rtems_current_user_env=aux; /* restore */
return 0;
}
}
fclose (fp);
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -160,12 +174,15 @@ struct group *getgrent( void )
void
setgrent ()
{
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if (group_fp != NULL)
fclose (group_fp);
group_fp = fopen ("/etc/group", "r");
+ rtems_current_user_env=aux; /* restore */
}
void
diff --git a/c/src/lib/libc/getpwent.c b/c/src/lib/libc/getpwent.c
index 7b56e26228..91b6550f59 100644
--- a/c/src/lib/libc/getpwent.c
+++ b/c/src/lib/libc/getpwent.c
@@ -23,6 +23,8 @@
#include <fcntl.h>
#include <unistd.h>
+#include <rtems/libio_.h>
+
static struct passwd pw_passwd; /* password structure */
static FILE *passwd_fp;
@@ -56,7 +58,7 @@ void init_etc_passwd_group(void)
if ( etc_passwd_initted )
return;
etc_passwd_initted = 1;
-
+
(void) mkdir( "/etc", 0777);
/*
@@ -80,7 +82,7 @@ void init_etc_passwd_group(void)
return;
fprintf( fp, "root:x:0:root\n"
- "rtems:x:1:rtems\n"
+ "rtems:x:1:rtems\n"
"tty:x:2:tty\n" );
fclose( fp );
@@ -95,11 +97,14 @@ int getpwnam_r(
)
{
FILE *fp;
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -118,11 +123,13 @@ int getpwnam_r(
if (!strcmp (logname, name)) {
fclose (fp);
*result = pwd;
+ rtems_current_user_env=aux; /* restore */
return 0;
}
}
fclose (fp);
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -148,11 +155,14 @@ int getpwuid_r(
)
{
FILE *fp;
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -171,11 +181,13 @@ int getpwuid_r(
if (uid == pwd->pw_uid) {
fclose (fp);
*result = pwd;
+ rtems_current_user_env=aux; /* restore */
return 0;
}
}
fclose (fp);
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -218,12 +230,15 @@ struct passwd *getpwent()
void setpwent( void )
{
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if (passwd_fp != NULL)
fclose (passwd_fp);
passwd_fp = fopen ("/etc/passwd", "r");
+ rtems_current_user_env=aux; /* restore */
}
void endpwent( void )
diff --git a/cpukit/libcsupport/src/getgrent.c b/cpukit/libcsupport/src/getgrent.c
index e4fc0fe474..104b0a317f 100644
--- a/cpukit/libcsupport/src/getgrent.c
+++ b/cpukit/libcsupport/src/getgrent.c
@@ -21,6 +21,9 @@
#include <string.h>
#include <limits.h>
+#include <rtems/libio_.h>
+
+
static struct group gr_group; /* password structure */
static FILE *group_fp;
@@ -47,11 +50,14 @@ int getgrnam_r(
)
{
FILE *fp;
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if ((fp = fopen ("/etc/group", "r")) == NULL) {
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -66,11 +72,13 @@ int getgrnam_r(
if (!strcmp (groupname, name)) {
fclose (fp);
*result = grp;
+ rtems_current_user_env=aux; /* restore */
return 0;
}
}
fclose (fp);
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -96,11 +104,15 @@ int getgrgid_r(
)
{
FILE *fp;
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
+
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if ((fp = fopen ("/etc/group", "r")) == NULL) {
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -116,11 +128,13 @@ int getgrgid_r(
if (gid == gr_group.gr_gid) {
fclose (fp);
*result = grp;
+ rtems_current_user_env=aux; /* restore */
return 0;
}
}
fclose (fp);
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -160,12 +174,15 @@ struct group *getgrent( void )
void
setgrent ()
{
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if (group_fp != NULL)
fclose (group_fp);
group_fp = fopen ("/etc/group", "r");
+ rtems_current_user_env=aux; /* restore */
}
void
diff --git a/cpukit/libcsupport/src/getpwent.c b/cpukit/libcsupport/src/getpwent.c
index 7b56e26228..91b6550f59 100644
--- a/cpukit/libcsupport/src/getpwent.c
+++ b/cpukit/libcsupport/src/getpwent.c
@@ -23,6 +23,8 @@
#include <fcntl.h>
#include <unistd.h>
+#include <rtems/libio_.h>
+
static struct passwd pw_passwd; /* password structure */
static FILE *passwd_fp;
@@ -56,7 +58,7 @@ void init_etc_passwd_group(void)
if ( etc_passwd_initted )
return;
etc_passwd_initted = 1;
-
+
(void) mkdir( "/etc", 0777);
/*
@@ -80,7 +82,7 @@ void init_etc_passwd_group(void)
return;
fprintf( fp, "root:x:0:root\n"
- "rtems:x:1:rtems\n"
+ "rtems:x:1:rtems\n"
"tty:x:2:tty\n" );
fclose( fp );
@@ -95,11 +97,14 @@ int getpwnam_r(
)
{
FILE *fp;
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -118,11 +123,13 @@ int getpwnam_r(
if (!strcmp (logname, name)) {
fclose (fp);
*result = pwd;
+ rtems_current_user_env=aux; /* restore */
return 0;
}
}
fclose (fp);
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -148,11 +155,14 @@ int getpwuid_r(
)
{
FILE *fp;
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -171,11 +181,13 @@ int getpwuid_r(
if (uid == pwd->pw_uid) {
fclose (fp);
*result = pwd;
+ rtems_current_user_env=aux; /* restore */
return 0;
}
}
fclose (fp);
errno = EINVAL;
+ rtems_current_user_env=aux; /* restore */
return -1;
}
@@ -218,12 +230,15 @@ struct passwd *getpwent()
void setpwent( void )
{
+ rtems_user_env_t * aux=rtems_current_user_env; /* save */
init_etc_passwd_group();
+ rtems_current_user_env=&rtems_global_user_env; /* set root */
if (passwd_fp != NULL)
fclose (passwd_fp);
passwd_fp = fopen ("/etc/passwd", "r");
+ rtems_current_user_env=aux; /* restore */
}
void endpwent( void )