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