forked from Imagelibrary/rtems
Reentrant versions added by Joel. Signficant formatting cleanup.
This commit is contained in:
@@ -19,51 +19,70 @@ static char password[1024];
|
||||
static char groups[1024];
|
||||
static char *gr_mem[16] = { } ;
|
||||
|
||||
struct group *
|
||||
getgrnam (name)
|
||||
const char *name;
|
||||
int getgrnam_r(
|
||||
const char *name,
|
||||
struct group *grp,
|
||||
char *buffer,
|
||||
size_t bufsize,
|
||||
struct group **result
|
||||
)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[1024];
|
||||
|
||||
if ((fp = fopen ("/etc/group", "r")) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
if ((fp = fopen ("/etc/group", "r")) == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets (buf, sizeof (buf), fp))
|
||||
{
|
||||
sscanf (buf, "%[^:]:%[^:]:%d:%s\n",
|
||||
groupname, password, &gr_group.gr_gid,
|
||||
while (fgets (buffer, bufsize, fp)) {
|
||||
sscanf (buffer, "%[^:]:%[^:]:%d:%s\n",
|
||||
groupname, password, &grp->gr_gid,
|
||||
groups);
|
||||
gr_group.gr_name = groupname;
|
||||
gr_group.gr_passwd = password;
|
||||
gr_group.gr_mem = gr_mem ;
|
||||
grp->gr_name = groupname;
|
||||
grp->gr_passwd = password;
|
||||
grp->gr_mem = gr_mem ;
|
||||
|
||||
if (!strcmp (groupname, name))
|
||||
{
|
||||
if (!strcmp (groupname, name)) {
|
||||
fclose (fp);
|
||||
return &gr_group;
|
||||
*result = grp;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
return NULL;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct group *
|
||||
getgrgid (gid_t gid)
|
||||
struct group *getgrnam(
|
||||
const char *name
|
||||
)
|
||||
{
|
||||
char buf[1024];
|
||||
struct group *g;
|
||||
|
||||
if ( getgrnam_r( name, &gr_group, buf, 1024, &g ) )
|
||||
return NULL;
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
int getgrgid_r(
|
||||
gid_t gid,
|
||||
struct group *grp,
|
||||
char *buffer,
|
||||
size_t bufsize,
|
||||
struct group **result
|
||||
)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[1024];
|
||||
|
||||
if ((fp = fopen ("/etc/group", "r")) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
if ((fp = fopen ("/etc/group", "r")) == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets (buf, sizeof (buf), fp))
|
||||
{
|
||||
sscanf (buf, "%[^:]:%[^:]:%d:%s\n",
|
||||
while (fgets (buffer, bufsize, fp)) {
|
||||
sscanf (buffer, "%[^:]:%[^:]:%d:%s\n",
|
||||
groupname, password, &gr_group.gr_gid,
|
||||
groups);
|
||||
gr_group.gr_name = groupname;
|
||||
@@ -71,18 +90,31 @@ getgrgid (gid_t gid)
|
||||
gr_group.gr_mem = gr_mem ;
|
||||
|
||||
|
||||
if (gid == gr_group.gr_gid)
|
||||
{
|
||||
if (gid == gr_group.gr_gid) {
|
||||
fclose (fp);
|
||||
return &gr_group;
|
||||
*result = grp;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
return NULL;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct group *
|
||||
getgrent ()
|
||||
struct group *getgrgid (
|
||||
gid_t gid
|
||||
)
|
||||
{
|
||||
char buf[1024];
|
||||
struct group *g;
|
||||
|
||||
if ( getgrgid_r( gid, &gr_group, buf, 1024, &g ) )
|
||||
return NULL;
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
struct group *getgrent( void )
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
|
||||
@@ -17,78 +17,109 @@ static char gecos[1024];
|
||||
static char dir[1024];
|
||||
static char shell[1024];
|
||||
|
||||
struct passwd *
|
||||
getpwnam (name)
|
||||
const char *name;
|
||||
int getpwnam_r(
|
||||
const char *name,
|
||||
struct passwd *pwd,
|
||||
char *buffer,
|
||||
size_t bufsize,
|
||||
struct passwd **result
|
||||
)
|
||||
{
|
||||
FILE *fp;
|
||||
int uid, gid;
|
||||
char buf[1024];
|
||||
|
||||
if ((fp = fopen ("/etc/passwd", "r")) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets (buf, sizeof (buf), fp))
|
||||
{
|
||||
sscanf (buf, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",
|
||||
while (fgets (buffer, bufsize, fp)) {
|
||||
sscanf (buffer, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",
|
||||
logname, password, &pwd->pw_uid,
|
||||
&pwd->pw_gid, comment, gecos,
|
||||
dir, shell);
|
||||
pwd->pw_name = logname;
|
||||
pwd->pw_passwd = password;
|
||||
pwd->pw_comment = comment;
|
||||
pwd->pw_gecos = gecos;
|
||||
pwd->pw_dir = dir;
|
||||
pwd->pw_shell = shell;
|
||||
|
||||
if (!strcmp (logname, name)) {
|
||||
fclose (fp);
|
||||
*result = pwd;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct passwd *getpwnam(
|
||||
const char *name
|
||||
)
|
||||
{
|
||||
char buf[1024];
|
||||
struct passwd *p;
|
||||
|
||||
if ( getpwnam_r( name, &pw_passwd, buf, 1024, &p ) )
|
||||
return NULL;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
int getpwuid_r(
|
||||
uid_t uid,
|
||||
struct passwd *pwd,
|
||||
char *buffer,
|
||||
size_t bufsize,
|
||||
struct passwd **result
|
||||
)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets (buffer, bufsize, fp)) {
|
||||
sscanf (buffer, "%[^:]:%[^:]:%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;
|
||||
pwd->pw_name = logname;
|
||||
pwd->pw_passwd = password;
|
||||
pwd->pw_comment = comment;
|
||||
pwd->pw_gecos = gecos;
|
||||
pwd->pw_dir = dir;
|
||||
pwd->pw_shell = shell;
|
||||
|
||||
if (!strcmp (logname, name))
|
||||
{
|
||||
if (uid == pwd->pw_uid) {
|
||||
fclose (fp);
|
||||
return &pw_passwd;
|
||||
*result = pwd;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
return NULL;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct passwd *
|
||||
getpwuid (uid_t uid)
|
||||
struct passwd *getpwuid(
|
||||
uid_t uid
|
||||
)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[1024];
|
||||
struct passwd *p;
|
||||
|
||||
if ((fp = fopen ("/etc/passwd", "r")) == NULL)
|
||||
{
|
||||
if ( getpwuid_r( uid, &pw_passwd, buf, 1024, &p ) )
|
||||
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;
|
||||
return p;
|
||||
}
|
||||
|
||||
struct passwd *
|
||||
getpwent ()
|
||||
struct passwd *getpwent()
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
@@ -112,8 +143,7 @@ getpwent ()
|
||||
return &pw_passwd;
|
||||
}
|
||||
|
||||
void
|
||||
setpwent ()
|
||||
void setpwent( void )
|
||||
{
|
||||
if (passwd_fp != NULL)
|
||||
fclose (passwd_fp);
|
||||
@@ -121,8 +151,7 @@ setpwent ()
|
||||
passwd_fp = fopen ("/etc/passwd", "r");
|
||||
}
|
||||
|
||||
void
|
||||
endpwent ()
|
||||
void endpwent( void )
|
||||
{
|
||||
if (passwd_fp != NULL)
|
||||
fclose (passwd_fp);
|
||||
|
||||
@@ -47,7 +47,7 @@ MALLOC_PIECES=\
|
||||
malloc __brk __sbrk
|
||||
|
||||
PASSWORD_GROUP_PIECES=\
|
||||
getpwent getgwent
|
||||
getpwent getgrent
|
||||
|
||||
LIBC_GLUE_PIECES=\
|
||||
__gettod __times \
|
||||
|
||||
@@ -19,51 +19,70 @@ static char password[1024];
|
||||
static char groups[1024];
|
||||
static char *gr_mem[16] = { } ;
|
||||
|
||||
struct group *
|
||||
getgrnam (name)
|
||||
const char *name;
|
||||
int getgrnam_r(
|
||||
const char *name,
|
||||
struct group *grp,
|
||||
char *buffer,
|
||||
size_t bufsize,
|
||||
struct group **result
|
||||
)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[1024];
|
||||
|
||||
if ((fp = fopen ("/etc/group", "r")) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
if ((fp = fopen ("/etc/group", "r")) == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets (buf, sizeof (buf), fp))
|
||||
{
|
||||
sscanf (buf, "%[^:]:%[^:]:%d:%s\n",
|
||||
groupname, password, &gr_group.gr_gid,
|
||||
while (fgets (buffer, bufsize, fp)) {
|
||||
sscanf (buffer, "%[^:]:%[^:]:%d:%s\n",
|
||||
groupname, password, &grp->gr_gid,
|
||||
groups);
|
||||
gr_group.gr_name = groupname;
|
||||
gr_group.gr_passwd = password;
|
||||
gr_group.gr_mem = gr_mem ;
|
||||
grp->gr_name = groupname;
|
||||
grp->gr_passwd = password;
|
||||
grp->gr_mem = gr_mem ;
|
||||
|
||||
if (!strcmp (groupname, name))
|
||||
{
|
||||
if (!strcmp (groupname, name)) {
|
||||
fclose (fp);
|
||||
return &gr_group;
|
||||
*result = grp;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
return NULL;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct group *
|
||||
getgrgid (gid_t gid)
|
||||
struct group *getgrnam(
|
||||
const char *name
|
||||
)
|
||||
{
|
||||
char buf[1024];
|
||||
struct group *g;
|
||||
|
||||
if ( getgrnam_r( name, &gr_group, buf, 1024, &g ) )
|
||||
return NULL;
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
int getgrgid_r(
|
||||
gid_t gid,
|
||||
struct group *grp,
|
||||
char *buffer,
|
||||
size_t bufsize,
|
||||
struct group **result
|
||||
)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[1024];
|
||||
|
||||
if ((fp = fopen ("/etc/group", "r")) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
if ((fp = fopen ("/etc/group", "r")) == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets (buf, sizeof (buf), fp))
|
||||
{
|
||||
sscanf (buf, "%[^:]:%[^:]:%d:%s\n",
|
||||
while (fgets (buffer, bufsize, fp)) {
|
||||
sscanf (buffer, "%[^:]:%[^:]:%d:%s\n",
|
||||
groupname, password, &gr_group.gr_gid,
|
||||
groups);
|
||||
gr_group.gr_name = groupname;
|
||||
@@ -71,18 +90,31 @@ getgrgid (gid_t gid)
|
||||
gr_group.gr_mem = gr_mem ;
|
||||
|
||||
|
||||
if (gid == gr_group.gr_gid)
|
||||
{
|
||||
if (gid == gr_group.gr_gid) {
|
||||
fclose (fp);
|
||||
return &gr_group;
|
||||
*result = grp;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
return NULL;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct group *
|
||||
getgrent ()
|
||||
struct group *getgrgid (
|
||||
gid_t gid
|
||||
)
|
||||
{
|
||||
char buf[1024];
|
||||
struct group *g;
|
||||
|
||||
if ( getgrgid_r( gid, &gr_group, buf, 1024, &g ) )
|
||||
return NULL;
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
struct group *getgrent( void )
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
|
||||
@@ -17,78 +17,109 @@ static char gecos[1024];
|
||||
static char dir[1024];
|
||||
static char shell[1024];
|
||||
|
||||
struct passwd *
|
||||
getpwnam (name)
|
||||
const char *name;
|
||||
int getpwnam_r(
|
||||
const char *name,
|
||||
struct passwd *pwd,
|
||||
char *buffer,
|
||||
size_t bufsize,
|
||||
struct passwd **result
|
||||
)
|
||||
{
|
||||
FILE *fp;
|
||||
int uid, gid;
|
||||
char buf[1024];
|
||||
|
||||
if ((fp = fopen ("/etc/passwd", "r")) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets (buf, sizeof (buf), fp))
|
||||
{
|
||||
sscanf (buf, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",
|
||||
while (fgets (buffer, bufsize, fp)) {
|
||||
sscanf (buffer, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",
|
||||
logname, password, &pwd->pw_uid,
|
||||
&pwd->pw_gid, comment, gecos,
|
||||
dir, shell);
|
||||
pwd->pw_name = logname;
|
||||
pwd->pw_passwd = password;
|
||||
pwd->pw_comment = comment;
|
||||
pwd->pw_gecos = gecos;
|
||||
pwd->pw_dir = dir;
|
||||
pwd->pw_shell = shell;
|
||||
|
||||
if (!strcmp (logname, name)) {
|
||||
fclose (fp);
|
||||
*result = pwd;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct passwd *getpwnam(
|
||||
const char *name
|
||||
)
|
||||
{
|
||||
char buf[1024];
|
||||
struct passwd *p;
|
||||
|
||||
if ( getpwnam_r( name, &pw_passwd, buf, 1024, &p ) )
|
||||
return NULL;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
int getpwuid_r(
|
||||
uid_t uid,
|
||||
struct passwd *pwd,
|
||||
char *buffer,
|
||||
size_t bufsize,
|
||||
struct passwd **result
|
||||
)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets (buffer, bufsize, fp)) {
|
||||
sscanf (buffer, "%[^:]:%[^:]:%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;
|
||||
pwd->pw_name = logname;
|
||||
pwd->pw_passwd = password;
|
||||
pwd->pw_comment = comment;
|
||||
pwd->pw_gecos = gecos;
|
||||
pwd->pw_dir = dir;
|
||||
pwd->pw_shell = shell;
|
||||
|
||||
if (!strcmp (logname, name))
|
||||
{
|
||||
if (uid == pwd->pw_uid) {
|
||||
fclose (fp);
|
||||
return &pw_passwd;
|
||||
*result = pwd;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
return NULL;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct passwd *
|
||||
getpwuid (uid_t uid)
|
||||
struct passwd *getpwuid(
|
||||
uid_t uid
|
||||
)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[1024];
|
||||
struct passwd *p;
|
||||
|
||||
if ((fp = fopen ("/etc/passwd", "r")) == NULL)
|
||||
{
|
||||
if ( getpwuid_r( uid, &pw_passwd, buf, 1024, &p ) )
|
||||
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;
|
||||
return p;
|
||||
}
|
||||
|
||||
struct passwd *
|
||||
getpwent ()
|
||||
struct passwd *getpwent()
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
@@ -112,8 +143,7 @@ getpwent ()
|
||||
return &pw_passwd;
|
||||
}
|
||||
|
||||
void
|
||||
setpwent ()
|
||||
void setpwent( void )
|
||||
{
|
||||
if (passwd_fp != NULL)
|
||||
fclose (passwd_fp);
|
||||
@@ -121,8 +151,7 @@ setpwent ()
|
||||
passwd_fp = fopen ("/etc/passwd", "r");
|
||||
}
|
||||
|
||||
void
|
||||
endpwent ()
|
||||
void endpwent( void )
|
||||
{
|
||||
if (passwd_fp != NULL)
|
||||
fclose (passwd_fp);
|
||||
|
||||
@@ -19,51 +19,70 @@ static char password[1024];
|
||||
static char groups[1024];
|
||||
static char *gr_mem[16] = { } ;
|
||||
|
||||
struct group *
|
||||
getgrnam (name)
|
||||
const char *name;
|
||||
int getgrnam_r(
|
||||
const char *name,
|
||||
struct group *grp,
|
||||
char *buffer,
|
||||
size_t bufsize,
|
||||
struct group **result
|
||||
)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[1024];
|
||||
|
||||
if ((fp = fopen ("/etc/group", "r")) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
if ((fp = fopen ("/etc/group", "r")) == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets (buf, sizeof (buf), fp))
|
||||
{
|
||||
sscanf (buf, "%[^:]:%[^:]:%d:%s\n",
|
||||
groupname, password, &gr_group.gr_gid,
|
||||
while (fgets (buffer, bufsize, fp)) {
|
||||
sscanf (buffer, "%[^:]:%[^:]:%d:%s\n",
|
||||
groupname, password, &grp->gr_gid,
|
||||
groups);
|
||||
gr_group.gr_name = groupname;
|
||||
gr_group.gr_passwd = password;
|
||||
gr_group.gr_mem = gr_mem ;
|
||||
grp->gr_name = groupname;
|
||||
grp->gr_passwd = password;
|
||||
grp->gr_mem = gr_mem ;
|
||||
|
||||
if (!strcmp (groupname, name))
|
||||
{
|
||||
if (!strcmp (groupname, name)) {
|
||||
fclose (fp);
|
||||
return &gr_group;
|
||||
*result = grp;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
return NULL;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct group *
|
||||
getgrgid (gid_t gid)
|
||||
struct group *getgrnam(
|
||||
const char *name
|
||||
)
|
||||
{
|
||||
char buf[1024];
|
||||
struct group *g;
|
||||
|
||||
if ( getgrnam_r( name, &gr_group, buf, 1024, &g ) )
|
||||
return NULL;
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
int getgrgid_r(
|
||||
gid_t gid,
|
||||
struct group *grp,
|
||||
char *buffer,
|
||||
size_t bufsize,
|
||||
struct group **result
|
||||
)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[1024];
|
||||
|
||||
if ((fp = fopen ("/etc/group", "r")) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
if ((fp = fopen ("/etc/group", "r")) == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets (buf, sizeof (buf), fp))
|
||||
{
|
||||
sscanf (buf, "%[^:]:%[^:]:%d:%s\n",
|
||||
while (fgets (buffer, bufsize, fp)) {
|
||||
sscanf (buffer, "%[^:]:%[^:]:%d:%s\n",
|
||||
groupname, password, &gr_group.gr_gid,
|
||||
groups);
|
||||
gr_group.gr_name = groupname;
|
||||
@@ -71,18 +90,31 @@ getgrgid (gid_t gid)
|
||||
gr_group.gr_mem = gr_mem ;
|
||||
|
||||
|
||||
if (gid == gr_group.gr_gid)
|
||||
{
|
||||
if (gid == gr_group.gr_gid) {
|
||||
fclose (fp);
|
||||
return &gr_group;
|
||||
*result = grp;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
return NULL;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct group *
|
||||
getgrent ()
|
||||
struct group *getgrgid (
|
||||
gid_t gid
|
||||
)
|
||||
{
|
||||
char buf[1024];
|
||||
struct group *g;
|
||||
|
||||
if ( getgrgid_r( gid, &gr_group, buf, 1024, &g ) )
|
||||
return NULL;
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
struct group *getgrent( void )
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
|
||||
@@ -17,78 +17,109 @@ static char gecos[1024];
|
||||
static char dir[1024];
|
||||
static char shell[1024];
|
||||
|
||||
struct passwd *
|
||||
getpwnam (name)
|
||||
const char *name;
|
||||
int getpwnam_r(
|
||||
const char *name,
|
||||
struct passwd *pwd,
|
||||
char *buffer,
|
||||
size_t bufsize,
|
||||
struct passwd **result
|
||||
)
|
||||
{
|
||||
FILE *fp;
|
||||
int uid, gid;
|
||||
char buf[1024];
|
||||
|
||||
if ((fp = fopen ("/etc/passwd", "r")) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets (buf, sizeof (buf), fp))
|
||||
{
|
||||
sscanf (buf, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",
|
||||
while (fgets (buffer, bufsize, fp)) {
|
||||
sscanf (buffer, "%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",
|
||||
logname, password, &pwd->pw_uid,
|
||||
&pwd->pw_gid, comment, gecos,
|
||||
dir, shell);
|
||||
pwd->pw_name = logname;
|
||||
pwd->pw_passwd = password;
|
||||
pwd->pw_comment = comment;
|
||||
pwd->pw_gecos = gecos;
|
||||
pwd->pw_dir = dir;
|
||||
pwd->pw_shell = shell;
|
||||
|
||||
if (!strcmp (logname, name)) {
|
||||
fclose (fp);
|
||||
*result = pwd;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct passwd *getpwnam(
|
||||
const char *name
|
||||
)
|
||||
{
|
||||
char buf[1024];
|
||||
struct passwd *p;
|
||||
|
||||
if ( getpwnam_r( name, &pw_passwd, buf, 1024, &p ) )
|
||||
return NULL;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
int getpwuid_r(
|
||||
uid_t uid,
|
||||
struct passwd *pwd,
|
||||
char *buffer,
|
||||
size_t bufsize,
|
||||
struct passwd **result
|
||||
)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
if ((fp = fopen ("/etc/passwd", "r")) == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets (buffer, bufsize, fp)) {
|
||||
sscanf (buffer, "%[^:]:%[^:]:%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;
|
||||
pwd->pw_name = logname;
|
||||
pwd->pw_passwd = password;
|
||||
pwd->pw_comment = comment;
|
||||
pwd->pw_gecos = gecos;
|
||||
pwd->pw_dir = dir;
|
||||
pwd->pw_shell = shell;
|
||||
|
||||
if (!strcmp (logname, name))
|
||||
{
|
||||
if (uid == pwd->pw_uid) {
|
||||
fclose (fp);
|
||||
return &pw_passwd;
|
||||
*result = pwd;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
return NULL;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct passwd *
|
||||
getpwuid (uid_t uid)
|
||||
struct passwd *getpwuid(
|
||||
uid_t uid
|
||||
)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[1024];
|
||||
struct passwd *p;
|
||||
|
||||
if ((fp = fopen ("/etc/passwd", "r")) == NULL)
|
||||
{
|
||||
if ( getpwuid_r( uid, &pw_passwd, buf, 1024, &p ) )
|
||||
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;
|
||||
return p;
|
||||
}
|
||||
|
||||
struct passwd *
|
||||
getpwent ()
|
||||
struct passwd *getpwent()
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
@@ -112,8 +143,7 @@ getpwent ()
|
||||
return &pw_passwd;
|
||||
}
|
||||
|
||||
void
|
||||
setpwent ()
|
||||
void setpwent( void )
|
||||
{
|
||||
if (passwd_fp != NULL)
|
||||
fclose (passwd_fp);
|
||||
@@ -121,8 +151,7 @@ setpwent ()
|
||||
passwd_fp = fopen ("/etc/passwd", "r");
|
||||
}
|
||||
|
||||
void
|
||||
endpwent ()
|
||||
void endpwent( void )
|
||||
{
|
||||
if (passwd_fp != NULL)
|
||||
fclose (passwd_fp);
|
||||
|
||||
Reference in New Issue
Block a user