summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1999-07-02 18:50:40 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1999-07-02 18:50:40 +0000
commita0a225f4aaa36461554db637edf24291acb17da6 (patch)
tree806481bed03264acdd0a65fe92952f2e239d9c30
parentFixed format strings and warnings. (diff)
downloadrtems-a0a225f4aaa36461554db637edf24291acb17da6.tar.bz2
Added code to initialize the /etc/group and /etc/passwd files.
-rw-r--r--c/src/exec/libcsupport/src/getgrent.c22
-rw-r--r--c/src/exec/libcsupport/src/getpwent.c69
-rw-r--r--c/src/lib/libc/getgrent.c22
-rw-r--r--c/src/lib/libc/getpwent.c69
-rw-r--r--cpukit/libcsupport/src/getgrent.c22
-rw-r--r--cpukit/libcsupport/src/getpwent.c69
6 files changed, 273 insertions, 0 deletions
diff --git a/c/src/exec/libcsupport/src/getgrent.c b/c/src/exec/libcsupport/src/getgrent.c
index b47ece8283..da339718a0 100644
--- a/c/src/exec/libcsupport/src/getgrent.c
+++ b/c/src/exec/libcsupport/src/getgrent.c
@@ -1,7 +1,14 @@
/*
+ * POSIX 1003.1b - 9.2.1 - Group Database Access Routines
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
* $Id$
*/
+
#include <stdio.h>
#include <sys/types.h>
#include <grp.h>
@@ -14,11 +21,20 @@
static struct group gr_group; /* password structure */
static FILE *group_fp;
+/*
+ * The size of these buffers is arbitrary and there is no provision
+ * to protect any of them from overflowing. The scanf patterns
+ * need to be changed to prevent overflowing. In addition,
+ * the limits on these needs to be examined.
+ */
+
static char groupname[8];
static char password[1024];
static char groups[1024];
static char *gr_mem[16] = { } ;
+extern void init_etc_passwd_group(void);
+
int getgrnam_r(
const char *name,
struct group *grp,
@@ -29,6 +45,8 @@ int getgrnam_r(
{
FILE *fp;
+ init_etc_passwd_group();
+
if ((fp = fopen ("/etc/group", "r")) == NULL) {
errno = EINVAL;
return -1;
@@ -76,6 +94,8 @@ int getgrgid_r(
{
FILE *fp;
+ init_etc_passwd_group();
+
if ((fp = fopen ("/etc/group", "r")) == NULL) {
errno = EINVAL;
return -1;
@@ -137,6 +157,8 @@ struct group *getgrent( void )
void
setgrent ()
{
+ init_etc_passwd_group();
+
if (group_fp != NULL)
fclose (group_fp);
diff --git a/c/src/exec/libcsupport/src/getpwent.c b/c/src/exec/libcsupport/src/getpwent.c
index 5a9b0f96c6..06f7318d27 100644
--- a/c/src/exec/libcsupport/src/getpwent.c
+++ b/c/src/exec/libcsupport/src/getpwent.c
@@ -1,3 +1,13 @@
+/*
+ * POSIX 1003.1b - 9.2.2 - User Database Access Routines
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
+ * $Id$
+ */
+
#include <stdio.h>
#include <sys/types.h>
#include <pwd.h>
@@ -6,10 +16,19 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include <fcntl.h>
+#include <unistd.h>
static struct passwd pw_passwd; /* password structure */
static FILE *passwd_fp;
+/*
+ * The size of these buffers is arbitrary and there is no provision
+ * to protect any of them from overflowing. The scanf patterns
+ * need to be changed to prevent overflowing. In addition,
+ * the limits on these needs to be examined.
+ */
+
static char logname[8];
static char password[1024];
static char comment[1024];
@@ -17,6 +36,50 @@ static char gecos[1024];
static char dir[1024];
static char shell[1024];
+/*
+ * Initialize a useable but dummy /etc/passwd
+ *
+ * NOTE: Ignore all errors.
+ *
+ */
+
+static char etc_passwd_initted = 0;
+
+void init_etc_passwd_group(void)
+{
+ FILE *fp;
+
+ if ( etc_passwd_initted )
+ return;
+ etc_passwd_initted = 1;
+
+ (void) mkdir( "/etc", S_IRWXU | S_IRWXG | S_IRWXO );
+
+ /*
+ * Initialize /etc/passwd
+ */
+
+ if ((fp = fopen ("/etc/passwd", "w")) == NULL)
+ return;
+
+ fprintf( fp, "root:*:0:0:root,,,,:/tmp:/bin/false\n"
+ "rtems:*:1:1:RTEMS Application,,,,:/tmp:/bin/false\n" );
+
+ fclose( fp );
+
+ /*
+ * Initialize /etc/group
+ */
+
+ if ((fp = fopen ("/etc/group", "w")) == NULL)
+ return;
+
+ fprintf( fp, "root::0:root\n"
+ "rtems::0:rtems\n" );
+
+ fclose( fp );
+}
+
int getpwnam_r(
const char *name,
struct passwd *pwd,
@@ -27,6 +90,8 @@ int getpwnam_r(
{
FILE *fp;
+ init_etc_passwd_group();
+
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
errno = EINVAL;
return -1;
@@ -78,6 +143,8 @@ int getpwuid_r(
{
FILE *fp;
+ init_etc_passwd_group();
+
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
errno = EINVAL;
return -1;
@@ -145,6 +212,8 @@ struct passwd *getpwent()
void setpwent( void )
{
+ init_etc_passwd_group();
+
if (passwd_fp != NULL)
fclose (passwd_fp);
diff --git a/c/src/lib/libc/getgrent.c b/c/src/lib/libc/getgrent.c
index b47ece8283..da339718a0 100644
--- a/c/src/lib/libc/getgrent.c
+++ b/c/src/lib/libc/getgrent.c
@@ -1,7 +1,14 @@
/*
+ * POSIX 1003.1b - 9.2.1 - Group Database Access Routines
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
* $Id$
*/
+
#include <stdio.h>
#include <sys/types.h>
#include <grp.h>
@@ -14,11 +21,20 @@
static struct group gr_group; /* password structure */
static FILE *group_fp;
+/*
+ * The size of these buffers is arbitrary and there is no provision
+ * to protect any of them from overflowing. The scanf patterns
+ * need to be changed to prevent overflowing. In addition,
+ * the limits on these needs to be examined.
+ */
+
static char groupname[8];
static char password[1024];
static char groups[1024];
static char *gr_mem[16] = { } ;
+extern void init_etc_passwd_group(void);
+
int getgrnam_r(
const char *name,
struct group *grp,
@@ -29,6 +45,8 @@ int getgrnam_r(
{
FILE *fp;
+ init_etc_passwd_group();
+
if ((fp = fopen ("/etc/group", "r")) == NULL) {
errno = EINVAL;
return -1;
@@ -76,6 +94,8 @@ int getgrgid_r(
{
FILE *fp;
+ init_etc_passwd_group();
+
if ((fp = fopen ("/etc/group", "r")) == NULL) {
errno = EINVAL;
return -1;
@@ -137,6 +157,8 @@ struct group *getgrent( void )
void
setgrent ()
{
+ init_etc_passwd_group();
+
if (group_fp != NULL)
fclose (group_fp);
diff --git a/c/src/lib/libc/getpwent.c b/c/src/lib/libc/getpwent.c
index 5a9b0f96c6..06f7318d27 100644
--- a/c/src/lib/libc/getpwent.c
+++ b/c/src/lib/libc/getpwent.c
@@ -1,3 +1,13 @@
+/*
+ * POSIX 1003.1b - 9.2.2 - User Database Access Routines
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
+ * $Id$
+ */
+
#include <stdio.h>
#include <sys/types.h>
#include <pwd.h>
@@ -6,10 +16,19 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include <fcntl.h>
+#include <unistd.h>
static struct passwd pw_passwd; /* password structure */
static FILE *passwd_fp;
+/*
+ * The size of these buffers is arbitrary and there is no provision
+ * to protect any of them from overflowing. The scanf patterns
+ * need to be changed to prevent overflowing. In addition,
+ * the limits on these needs to be examined.
+ */
+
static char logname[8];
static char password[1024];
static char comment[1024];
@@ -17,6 +36,50 @@ static char gecos[1024];
static char dir[1024];
static char shell[1024];
+/*
+ * Initialize a useable but dummy /etc/passwd
+ *
+ * NOTE: Ignore all errors.
+ *
+ */
+
+static char etc_passwd_initted = 0;
+
+void init_etc_passwd_group(void)
+{
+ FILE *fp;
+
+ if ( etc_passwd_initted )
+ return;
+ etc_passwd_initted = 1;
+
+ (void) mkdir( "/etc", S_IRWXU | S_IRWXG | S_IRWXO );
+
+ /*
+ * Initialize /etc/passwd
+ */
+
+ if ((fp = fopen ("/etc/passwd", "w")) == NULL)
+ return;
+
+ fprintf( fp, "root:*:0:0:root,,,,:/tmp:/bin/false\n"
+ "rtems:*:1:1:RTEMS Application,,,,:/tmp:/bin/false\n" );
+
+ fclose( fp );
+
+ /*
+ * Initialize /etc/group
+ */
+
+ if ((fp = fopen ("/etc/group", "w")) == NULL)
+ return;
+
+ fprintf( fp, "root::0:root\n"
+ "rtems::0:rtems\n" );
+
+ fclose( fp );
+}
+
int getpwnam_r(
const char *name,
struct passwd *pwd,
@@ -27,6 +90,8 @@ int getpwnam_r(
{
FILE *fp;
+ init_etc_passwd_group();
+
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
errno = EINVAL;
return -1;
@@ -78,6 +143,8 @@ int getpwuid_r(
{
FILE *fp;
+ init_etc_passwd_group();
+
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
errno = EINVAL;
return -1;
@@ -145,6 +212,8 @@ struct passwd *getpwent()
void setpwent( void )
{
+ init_etc_passwd_group();
+
if (passwd_fp != NULL)
fclose (passwd_fp);
diff --git a/cpukit/libcsupport/src/getgrent.c b/cpukit/libcsupport/src/getgrent.c
index b47ece8283..da339718a0 100644
--- a/cpukit/libcsupport/src/getgrent.c
+++ b/cpukit/libcsupport/src/getgrent.c
@@ -1,7 +1,14 @@
/*
+ * POSIX 1003.1b - 9.2.1 - Group Database Access Routines
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
* $Id$
*/
+
#include <stdio.h>
#include <sys/types.h>
#include <grp.h>
@@ -14,11 +21,20 @@
static struct group gr_group; /* password structure */
static FILE *group_fp;
+/*
+ * The size of these buffers is arbitrary and there is no provision
+ * to protect any of them from overflowing. The scanf patterns
+ * need to be changed to prevent overflowing. In addition,
+ * the limits on these needs to be examined.
+ */
+
static char groupname[8];
static char password[1024];
static char groups[1024];
static char *gr_mem[16] = { } ;
+extern void init_etc_passwd_group(void);
+
int getgrnam_r(
const char *name,
struct group *grp,
@@ -29,6 +45,8 @@ int getgrnam_r(
{
FILE *fp;
+ init_etc_passwd_group();
+
if ((fp = fopen ("/etc/group", "r")) == NULL) {
errno = EINVAL;
return -1;
@@ -76,6 +94,8 @@ int getgrgid_r(
{
FILE *fp;
+ init_etc_passwd_group();
+
if ((fp = fopen ("/etc/group", "r")) == NULL) {
errno = EINVAL;
return -1;
@@ -137,6 +157,8 @@ struct group *getgrent( void )
void
setgrent ()
{
+ init_etc_passwd_group();
+
if (group_fp != NULL)
fclose (group_fp);
diff --git a/cpukit/libcsupport/src/getpwent.c b/cpukit/libcsupport/src/getpwent.c
index 5a9b0f96c6..06f7318d27 100644
--- a/cpukit/libcsupport/src/getpwent.c
+++ b/cpukit/libcsupport/src/getpwent.c
@@ -1,3 +1,13 @@
+/*
+ * POSIX 1003.1b - 9.2.2 - User Database Access Routines
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
+ * $Id$
+ */
+
#include <stdio.h>
#include <sys/types.h>
#include <pwd.h>
@@ -6,10 +16,19 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include <fcntl.h>
+#include <unistd.h>
static struct passwd pw_passwd; /* password structure */
static FILE *passwd_fp;
+/*
+ * The size of these buffers is arbitrary and there is no provision
+ * to protect any of them from overflowing. The scanf patterns
+ * need to be changed to prevent overflowing. In addition,
+ * the limits on these needs to be examined.
+ */
+
static char logname[8];
static char password[1024];
static char comment[1024];
@@ -17,6 +36,50 @@ static char gecos[1024];
static char dir[1024];
static char shell[1024];
+/*
+ * Initialize a useable but dummy /etc/passwd
+ *
+ * NOTE: Ignore all errors.
+ *
+ */
+
+static char etc_passwd_initted = 0;
+
+void init_etc_passwd_group(void)
+{
+ FILE *fp;
+
+ if ( etc_passwd_initted )
+ return;
+ etc_passwd_initted = 1;
+
+ (void) mkdir( "/etc", S_IRWXU | S_IRWXG | S_IRWXO );
+
+ /*
+ * Initialize /etc/passwd
+ */
+
+ if ((fp = fopen ("/etc/passwd", "w")) == NULL)
+ return;
+
+ fprintf( fp, "root:*:0:0:root,,,,:/tmp:/bin/false\n"
+ "rtems:*:1:1:RTEMS Application,,,,:/tmp:/bin/false\n" );
+
+ fclose( fp );
+
+ /*
+ * Initialize /etc/group
+ */
+
+ if ((fp = fopen ("/etc/group", "w")) == NULL)
+ return;
+
+ fprintf( fp, "root::0:root\n"
+ "rtems::0:rtems\n" );
+
+ fclose( fp );
+}
+
int getpwnam_r(
const char *name,
struct passwd *pwd,
@@ -27,6 +90,8 @@ int getpwnam_r(
{
FILE *fp;
+ init_etc_passwd_group();
+
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
errno = EINVAL;
return -1;
@@ -78,6 +143,8 @@ int getpwuid_r(
{
FILE *fp;
+ init_etc_passwd_group();
+
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
errno = EINVAL;
return -1;
@@ -145,6 +212,8 @@ struct passwd *getpwent()
void setpwent( void )
{
+ init_etc_passwd_group();
+
if (passwd_fp != NULL)
fclose (passwd_fp);