Added code to initialize the /etc/group and /etc/passwd files.

This commit is contained in:
Joel Sherrill
1999-07-02 18:50:40 +00:00
parent c51917f304
commit a0a225f4aa
6 changed files with 273 additions and 0 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);