Password and group routines added by Ralf Corsepius <corsepiu@faw.uni-ulm.de>.

This commit is contained in:
Joel Sherrill
1999-07-02 17:13:27 +00:00
parent fcee56c0b1
commit 258fd794fd
7 changed files with 749 additions and 1 deletions

View File

@@ -0,0 +1,119 @@
/*
* $Id$
*/
#include <stdio.h>
#include <sys/types.h>
#include <grp.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
static struct group gr_group; /* password structure */
static FILE *group_fp;
static char groupname[8];
static char password[1024];
static char groups[1024];
static char *gr_mem[16] = { } ;
struct group *
getgrnam (name)
const char *name;
{
FILE *fp;
char buf[1024];
if ((fp = fopen ("/etc/group", "r")) == NULL)
{
return NULL;
}
while (fgets (buf, sizeof (buf), fp))
{
sscanf (buf, "%[^:]:%[^:]:%d:%s\n",
groupname, password, &gr_group.gr_gid,
groups);
gr_group.gr_name = groupname;
gr_group.gr_passwd = password;
gr_group.gr_mem = gr_mem ;
if (!strcmp (groupname, name))
{
fclose (fp);
return &gr_group;
}
}
fclose (fp);
return NULL;
}
struct group *
getgrgid (gid_t gid)
{
FILE *fp;
char buf[1024];
if ((fp = fopen ("/etc/group", "r")) == NULL)
{
return NULL;
}
while (fgets (buf, sizeof (buf), fp))
{
sscanf (buf, "%[^:]:%[^:]:%d:%s\n",
groupname, password, &gr_group.gr_gid,
groups);
gr_group.gr_name = groupname;
gr_group.gr_passwd = password;
gr_group.gr_mem = gr_mem ;
if (gid == gr_group.gr_gid)
{
fclose (fp);
return &gr_group;
}
}
fclose (fp);
return NULL;
}
struct group *
getgrent ()
{
char buf[1024];
if (group_fp == NULL)
return NULL;
if (fgets (buf, sizeof (buf), group_fp) == NULL)
return NULL;
sscanf (buf, "%[^:]:%[^:]:%d:%s\n",
groupname, password, &gr_group.gr_gid,
groups);
gr_group.gr_name = groupname;
gr_group.gr_passwd = password;
gr_group.gr_mem = gr_mem ;
return &gr_group;
}
void
setgrent ()
{
if (group_fp != NULL)
fclose (group_fp);
group_fp = fopen ("/etc/group", "r");
}
void
endgrent ()
{
if (group_fp != NULL)
fclose (group_fp);
}

View File

@@ -0,0 +1,129 @@
#include <stdio.h>
#include <sys/types.h>
#include <pwd.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
static struct passwd pw_passwd; /* password structure */
static FILE *passwd_fp;
static char logname[8];
static char password[1024];
static char comment[1024];
static char gecos[1024];
static char dir[1024];
static char shell[1024];
struct passwd *
getpwnam (name)
const char *name;
{
FILE *fp;
int uid, gid;
char buf[1024];
if ((fp = fopen ("/etc/passwd", "r")) == NULL)
{
return NULL;
}
while (fgets (buf, sizeof (buf), fp))
{
sscanf (buf, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",
logname, password, &pw_passwd.pw_uid,
&pw_passwd.pw_gid, comment, gecos,
dir, shell);
pw_passwd.pw_name = logname;
pw_passwd.pw_passwd = password;
pw_passwd.pw_comment = comment;
pw_passwd.pw_gecos = gecos;
pw_passwd.pw_dir = dir;
pw_passwd.pw_shell = shell;
if (!strcmp (logname, name))
{
fclose (fp);
return &pw_passwd;
}
}
fclose (fp);
return NULL;
}
struct passwd *
getpwuid (uid_t uid)
{
FILE *fp;
char buf[1024];
if ((fp = fopen ("/etc/passwd", "r")) == NULL)
{
return NULL;
}
while (fgets (buf, sizeof (buf), fp))
{
sscanf (buf, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",
logname, password, &pw_passwd.pw_uid,
&pw_passwd.pw_gid, comment, gecos,
dir, shell);
pw_passwd.pw_name = logname;
pw_passwd.pw_passwd = password;
pw_passwd.pw_comment = comment;
pw_passwd.pw_gecos = gecos;
pw_passwd.pw_dir = dir;
pw_passwd.pw_shell = shell;
if (uid == pw_passwd.pw_uid)
{
fclose (fp);
return &pw_passwd;
}
}
fclose (fp);
return NULL;
}
struct passwd *
getpwent ()
{
char buf[1024];
if (passwd_fp == NULL)
return NULL;
if (fgets (buf, sizeof (buf), passwd_fp) == NULL)
return NULL;
sscanf (buf, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",
logname, password, &pw_passwd.pw_uid,
&pw_passwd.pw_gid, comment, gecos,
dir, shell);
pw_passwd.pw_name = logname;
pw_passwd.pw_passwd = password;
pw_passwd.pw_comment = comment;
pw_passwd.pw_gecos = gecos;
pw_passwd.pw_dir = dir;
pw_passwd.pw_shell = shell;
return &pw_passwd;
}
void
setpwent ()
{
if (passwd_fp != NULL)
fclose (passwd_fp);
passwd_fp = fopen ("/etc/passwd", "r");
}
void
endpwent ()
{
if (passwd_fp != NULL)
fclose (passwd_fp);
}

View File

@@ -44,7 +44,10 @@ DIRECTORY_SCAN_PIECES=\
opendir closedir readdir rewinddir scandir seekdir telldir getcwd opendir closedir readdir rewinddir scandir seekdir telldir getcwd
MALLOC_PIECES=\ MALLOC_PIECES=\
malloc __brk __sbrk \ malloc __brk __sbrk
PASSWORD_GROUP_PIECES=\
getpwent getgwent
LIBC_GLUE_PIECES=\ LIBC_GLUE_PIECES=\
__gettod __times \ __gettod __times \
@@ -78,6 +81,7 @@ C_PIECES=\
$(LIBC_GLUE_PIECES) \ $(LIBC_GLUE_PIECES) \
$(BASE_FS_PIECES) \ $(BASE_FS_PIECES) \
$(MALLOC_PIECES) \ $(MALLOC_PIECES) \
$(PASSWORD_GROUP_PIECES) \
$(TERMIOS_PIECES) \ $(TERMIOS_PIECES) \
$(SYSTEM_CALL_PIECES) \ $(SYSTEM_CALL_PIECES) \
$(DIRECTORY_SCAN_PIECES) \ $(DIRECTORY_SCAN_PIECES) \

119
c/src/lib/libc/getgrent.c Normal file
View File

@@ -0,0 +1,119 @@
/*
* $Id$
*/
#include <stdio.h>
#include <sys/types.h>
#include <grp.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
static struct group gr_group; /* password structure */
static FILE *group_fp;
static char groupname[8];
static char password[1024];
static char groups[1024];
static char *gr_mem[16] = { } ;
struct group *
getgrnam (name)
const char *name;
{
FILE *fp;
char buf[1024];
if ((fp = fopen ("/etc/group", "r")) == NULL)
{
return NULL;
}
while (fgets (buf, sizeof (buf), fp))
{
sscanf (buf, "%[^:]:%[^:]:%d:%s\n",
groupname, password, &gr_group.gr_gid,
groups);
gr_group.gr_name = groupname;
gr_group.gr_passwd = password;
gr_group.gr_mem = gr_mem ;
if (!strcmp (groupname, name))
{
fclose (fp);
return &gr_group;
}
}
fclose (fp);
return NULL;
}
struct group *
getgrgid (gid_t gid)
{
FILE *fp;
char buf[1024];
if ((fp = fopen ("/etc/group", "r")) == NULL)
{
return NULL;
}
while (fgets (buf, sizeof (buf), fp))
{
sscanf (buf, "%[^:]:%[^:]:%d:%s\n",
groupname, password, &gr_group.gr_gid,
groups);
gr_group.gr_name = groupname;
gr_group.gr_passwd = password;
gr_group.gr_mem = gr_mem ;
if (gid == gr_group.gr_gid)
{
fclose (fp);
return &gr_group;
}
}
fclose (fp);
return NULL;
}
struct group *
getgrent ()
{
char buf[1024];
if (group_fp == NULL)
return NULL;
if (fgets (buf, sizeof (buf), group_fp) == NULL)
return NULL;
sscanf (buf, "%[^:]:%[^:]:%d:%s\n",
groupname, password, &gr_group.gr_gid,
groups);
gr_group.gr_name = groupname;
gr_group.gr_passwd = password;
gr_group.gr_mem = gr_mem ;
return &gr_group;
}
void
setgrent ()
{
if (group_fp != NULL)
fclose (group_fp);
group_fp = fopen ("/etc/group", "r");
}
void
endgrent ()
{
if (group_fp != NULL)
fclose (group_fp);
}

129
c/src/lib/libc/getpwent.c Normal file
View File

@@ -0,0 +1,129 @@
#include <stdio.h>
#include <sys/types.h>
#include <pwd.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
static struct passwd pw_passwd; /* password structure */
static FILE *passwd_fp;
static char logname[8];
static char password[1024];
static char comment[1024];
static char gecos[1024];
static char dir[1024];
static char shell[1024];
struct passwd *
getpwnam (name)
const char *name;
{
FILE *fp;
int uid, gid;
char buf[1024];
if ((fp = fopen ("/etc/passwd", "r")) == NULL)
{
return NULL;
}
while (fgets (buf, sizeof (buf), fp))
{
sscanf (buf, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",
logname, password, &pw_passwd.pw_uid,
&pw_passwd.pw_gid, comment, gecos,
dir, shell);
pw_passwd.pw_name = logname;
pw_passwd.pw_passwd = password;
pw_passwd.pw_comment = comment;
pw_passwd.pw_gecos = gecos;
pw_passwd.pw_dir = dir;
pw_passwd.pw_shell = shell;
if (!strcmp (logname, name))
{
fclose (fp);
return &pw_passwd;
}
}
fclose (fp);
return NULL;
}
struct passwd *
getpwuid (uid_t uid)
{
FILE *fp;
char buf[1024];
if ((fp = fopen ("/etc/passwd", "r")) == NULL)
{
return NULL;
}
while (fgets (buf, sizeof (buf), fp))
{
sscanf (buf, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",
logname, password, &pw_passwd.pw_uid,
&pw_passwd.pw_gid, comment, gecos,
dir, shell);
pw_passwd.pw_name = logname;
pw_passwd.pw_passwd = password;
pw_passwd.pw_comment = comment;
pw_passwd.pw_gecos = gecos;
pw_passwd.pw_dir = dir;
pw_passwd.pw_shell = shell;
if (uid == pw_passwd.pw_uid)
{
fclose (fp);
return &pw_passwd;
}
}
fclose (fp);
return NULL;
}
struct passwd *
getpwent ()
{
char buf[1024];
if (passwd_fp == NULL)
return NULL;
if (fgets (buf, sizeof (buf), passwd_fp) == NULL)
return NULL;
sscanf (buf, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",
logname, password, &pw_passwd.pw_uid,
&pw_passwd.pw_gid, comment, gecos,
dir, shell);
pw_passwd.pw_name = logname;
pw_passwd.pw_passwd = password;
pw_passwd.pw_comment = comment;
pw_passwd.pw_gecos = gecos;
pw_passwd.pw_dir = dir;
pw_passwd.pw_shell = shell;
return &pw_passwd;
}
void
setpwent ()
{
if (passwd_fp != NULL)
fclose (passwd_fp);
passwd_fp = fopen ("/etc/passwd", "r");
}
void
endpwent ()
{
if (passwd_fp != NULL)
fclose (passwd_fp);
}

View File

@@ -0,0 +1,119 @@
/*
* $Id$
*/
#include <stdio.h>
#include <sys/types.h>
#include <grp.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
static struct group gr_group; /* password structure */
static FILE *group_fp;
static char groupname[8];
static char password[1024];
static char groups[1024];
static char *gr_mem[16] = { } ;
struct group *
getgrnam (name)
const char *name;
{
FILE *fp;
char buf[1024];
if ((fp = fopen ("/etc/group", "r")) == NULL)
{
return NULL;
}
while (fgets (buf, sizeof (buf), fp))
{
sscanf (buf, "%[^:]:%[^:]:%d:%s\n",
groupname, password, &gr_group.gr_gid,
groups);
gr_group.gr_name = groupname;
gr_group.gr_passwd = password;
gr_group.gr_mem = gr_mem ;
if (!strcmp (groupname, name))
{
fclose (fp);
return &gr_group;
}
}
fclose (fp);
return NULL;
}
struct group *
getgrgid (gid_t gid)
{
FILE *fp;
char buf[1024];
if ((fp = fopen ("/etc/group", "r")) == NULL)
{
return NULL;
}
while (fgets (buf, sizeof (buf), fp))
{
sscanf (buf, "%[^:]:%[^:]:%d:%s\n",
groupname, password, &gr_group.gr_gid,
groups);
gr_group.gr_name = groupname;
gr_group.gr_passwd = password;
gr_group.gr_mem = gr_mem ;
if (gid == gr_group.gr_gid)
{
fclose (fp);
return &gr_group;
}
}
fclose (fp);
return NULL;
}
struct group *
getgrent ()
{
char buf[1024];
if (group_fp == NULL)
return NULL;
if (fgets (buf, sizeof (buf), group_fp) == NULL)
return NULL;
sscanf (buf, "%[^:]:%[^:]:%d:%s\n",
groupname, password, &gr_group.gr_gid,
groups);
gr_group.gr_name = groupname;
gr_group.gr_passwd = password;
gr_group.gr_mem = gr_mem ;
return &gr_group;
}
void
setgrent ()
{
if (group_fp != NULL)
fclose (group_fp);
group_fp = fopen ("/etc/group", "r");
}
void
endgrent ()
{
if (group_fp != NULL)
fclose (group_fp);
}

View File

@@ -0,0 +1,129 @@
#include <stdio.h>
#include <sys/types.h>
#include <pwd.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
static struct passwd pw_passwd; /* password structure */
static FILE *passwd_fp;
static char logname[8];
static char password[1024];
static char comment[1024];
static char gecos[1024];
static char dir[1024];
static char shell[1024];
struct passwd *
getpwnam (name)
const char *name;
{
FILE *fp;
int uid, gid;
char buf[1024];
if ((fp = fopen ("/etc/passwd", "r")) == NULL)
{
return NULL;
}
while (fgets (buf, sizeof (buf), fp))
{
sscanf (buf, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",
logname, password, &pw_passwd.pw_uid,
&pw_passwd.pw_gid, comment, gecos,
dir, shell);
pw_passwd.pw_name = logname;
pw_passwd.pw_passwd = password;
pw_passwd.pw_comment = comment;
pw_passwd.pw_gecos = gecos;
pw_passwd.pw_dir = dir;
pw_passwd.pw_shell = shell;
if (!strcmp (logname, name))
{
fclose (fp);
return &pw_passwd;
}
}
fclose (fp);
return NULL;
}
struct passwd *
getpwuid (uid_t uid)
{
FILE *fp;
char buf[1024];
if ((fp = fopen ("/etc/passwd", "r")) == NULL)
{
return NULL;
}
while (fgets (buf, sizeof (buf), fp))
{
sscanf (buf, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",
logname, password, &pw_passwd.pw_uid,
&pw_passwd.pw_gid, comment, gecos,
dir, shell);
pw_passwd.pw_name = logname;
pw_passwd.pw_passwd = password;
pw_passwd.pw_comment = comment;
pw_passwd.pw_gecos = gecos;
pw_passwd.pw_dir = dir;
pw_passwd.pw_shell = shell;
if (uid == pw_passwd.pw_uid)
{
fclose (fp);
return &pw_passwd;
}
}
fclose (fp);
return NULL;
}
struct passwd *
getpwent ()
{
char buf[1024];
if (passwd_fp == NULL)
return NULL;
if (fgets (buf, sizeof (buf), passwd_fp) == NULL)
return NULL;
sscanf (buf, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",
logname, password, &pw_passwd.pw_uid,
&pw_passwd.pw_gid, comment, gecos,
dir, shell);
pw_passwd.pw_name = logname;
pw_passwd.pw_passwd = password;
pw_passwd.pw_comment = comment;
pw_passwd.pw_gecos = gecos;
pw_passwd.pw_dir = dir;
pw_passwd.pw_shell = shell;
return &pw_passwd;
}
void
setpwent ()
{
if (passwd_fp != NULL)
fclose (passwd_fp);
passwd_fp = fopen ("/etc/passwd", "r");
}
void
endpwent ()
{
if (passwd_fp != NULL)
fclose (passwd_fp);
}