[uClibc-cvs] uClibc/libc/pwd_grp __getpwent_r.c,1.2,1.3 __getspent_r.c,1.4,1.5 __sgetspent_r.c,1.2,1.3 fgetpwent.c,1.7,1.8 fgetspent.c,1.3,1.4 getpwnam.c,1.8,1.9 getpwuid.c,1.7,1.8 getspnam.c,1.3,1.4 getspuid.c,1.3,1.4 initgroups.c,1.10,1.11 pwent.c,1.9,1.10 sgetspent.c,1.3,1.4 spent.c,1.3,1.4
Erik Andersen
andersen at uclibc.org
Fri Jun 27 10:19:33 UTC 2003
- Previous message: [uClibc-cvs] uClibc/extra/Configs Config.in,1.18,1.19
- Next message: [uClibc-cvs] uClibc/libc/pwd_grp fgetpwent.c,1.8,1.9 fgetspent.c,1.4,1.5 getpwnam.c,1.9,1.10 getpwuid.c,1.8,1.9 getspnam.c,1.4,1.5 getspuid.c,1.4,1.5 pwent.c,1.10,1.11 sgetspent.c,1.4,1.5 spent.c,1.4,1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /var/cvs/uClibc/libc/pwd_grp
In directory winder:/tmp/cvs-serv25951
Modified Files:
__getpwent_r.c __getspent_r.c __sgetspent_r.c fgetpwent.c
fgetspent.c getpwnam.c getpwuid.c getspnam.c getspuid.c
initgroups.c pwent.c sgetspent.c spent.c
Log Message:
Fixup errno handling
-Erik
Index: __getpwent_r.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/__getpwent_r.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- __getpwent_r.c 12 Jun 2002 23:26:59 -0000 1.2
+++ __getpwent_r.c 27 Jun 2003 10:19:28 -0000 1.3
@@ -24,6 +24,7 @@
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
+#include <errno.h>
#include "config.h"
@@ -42,12 +43,15 @@
int line_len;
int i;
+ if (buflen<PWD_BUFFER_SIZE)
+ return ERANGE;
+
/* We use the restart label to handle malformatted lines */
- restart:
- /* Read the passwd line into the static buffer using a minimal of
+restart:
+ /* Read the passwd line into the static buffer using a minimum of
syscalls. */
if ((line_len = read(pwd_fd, line_buff, buflen)) <= 0)
- return -1;
+ return EIO;
field_begin = strchr(line_buff, '\n');
if (field_begin != NULL)
lseek(pwd_fd, (long) (1 + field_begin - (line_buff + line_len)),
@@ -56,7 +60,7 @@
do {
if ((line_len = read(pwd_fd, line_buff, buflen)) <= 0)
- return -1;
+ return EIO;
} while (!(field_begin = strchr(line_buff, '\n')));
lseek(pwd_fd, (long) (field_begin - line_buff) - line_len + 1,
SEEK_CUR);
Index: __getspent_r.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/__getspent_r.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- __getspent_r.c 8 Aug 2002 07:28:32 -0000 1.4
+++ __getspent_r.c 27 Jun 2003 10:19:28 -0000 1.5
@@ -20,6 +20,7 @@
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
+#include <errno.h>
#include "config.h"
@@ -28,11 +29,14 @@
char *endptr;
int line_len;
+ if (buflen<PWD_BUFFER_SIZE)
+ return ERANGE;
+
/* We use the restart label to handle malformatted lines */
restart:
/* Read the shadow line into the buffer using a minimum of syscalls. */
if ((line_len = read(spwd_fd, line_buff, buflen)) <= 0)
- return -1;
+ return EIO;
endptr = strchr(line_buff, '\n');
if (endptr != NULL)
lseek(spwd_fd, (long) (1 + endptr - (line_buff + line_len)), SEEK_CUR);
@@ -40,13 +44,13 @@
/* The line is too long - skip it. :-\ */
do {
if ((line_len = read(spwd_fd, line_buff, buflen)) <= 0)
- return -1;
+ return EIO;
} while (!(endptr = strchr(line_buff, '\n')));
lseek(spwd_fd, (long) (endptr - line_buff) - line_len + 1, SEEK_CUR);
goto restart;
}
- if (__sgetspent_r(line_buff, spwd, line_buff, buflen) < 0)
+ if (__sgetspent_r(line_buff, spwd, line_buff, buflen) != 0)
goto restart;
return 0;
Index: __sgetspent_r.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/__sgetspent_r.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- __sgetspent_r.c 12 Jun 2002 23:26:59 -0000 1.2
+++ __sgetspent_r.c 27 Jun 2003 10:19:28 -0000 1.3
@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
+#include <errno.h>
#include "config.h"
@@ -35,15 +36,18 @@
char *flag_ptr=NULL;
int i;
+ if (buflen<PWD_BUFFER_SIZE)
+ return ERANGE;
+
if (string != line_buff) {
if (strlen(string) >= buflen)
- return -1;
+ return ERANGE;
strcpy(line_buff, string);
}
if (*line_buff == '#' || *line_buff == ' ' || *line_buff == '\n' ||
*line_buff == '\t')
- return -1;
+ return EINVAL;
field_begin = strchr(line_buff, '\n');
if (field_begin != NULL)
@@ -86,7 +90,7 @@
if (field_begin == NULL) {
if (i==4 || i==7)
break;
- return -1;
+ return EINVAL;
}
*field_begin++ = '\0';
}
@@ -97,7 +101,7 @@
} else {
spwd->sp_lstchg = (gid_t) strtoul(lstchg_ptr, &endptr, 10);
if (*endptr != '\0')
- return -1;
+ return EINVAL;
}
if (*min_ptr == '\0') {
@@ -105,7 +109,7 @@
} else {
spwd->sp_min = (gid_t) strtoul(min_ptr, &endptr, 10);
if (*endptr != '\0')
- return -1;
+ return EINVAL;
}
if (*max_ptr == '\0') {
@@ -113,7 +117,7 @@
} else {
spwd->sp_max = (gid_t) strtoul(max_ptr, &endptr, 10);
if (*endptr != '\0')
- return -1;
+ return EINVAL;
}
if (warn_ptr == NULL) {
@@ -129,7 +133,7 @@
} else {
spwd->sp_warn = (gid_t) strtoul(warn_ptr, &endptr, 10);
if (*endptr != '\0')
- return -1;
+ return EINVAL;
}
if (*inact_ptr == '\0') {
@@ -137,7 +141,7 @@
} else {
spwd->sp_inact = (gid_t) strtoul(inact_ptr, &endptr, 10);
if (*endptr != '\0')
- return -1;
+ return EINVAL;
}
if (*expire_ptr == '\0') {
@@ -145,7 +149,7 @@
} else {
spwd->sp_expire = (gid_t) strtoul(expire_ptr, &endptr, 10);
if (*endptr != '\0')
- return -1;
+ return EINVAL;
}
if (flag_ptr==NULL || *flag_ptr=='\0') {
@@ -153,7 +157,7 @@
} else {
spwd->sp_flag = (gid_t) strtoul(flag_ptr, &endptr, 10);
if (*endptr != '\0')
- return -1;
+ return EINVAL;
}
}
Index: fgetpwent.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/fgetpwent.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- fgetpwent.c 8 Aug 2002 07:28:32 -0000 1.7
+++ fgetpwent.c 27 Jun 2003 10:19:28 -0000 1.8
@@ -37,22 +37,23 @@
char *buff, size_t buflen, struct passwd **crap)
{
if (file == NULL) {
- __set_errno(EINTR);
- return -1;
+ return EINTR;
}
return(__getpwent_r(password, buff, buflen, fileno(file)));
}
struct passwd *fgetpwent(FILE * file)
{
+ int ret;
static char line_buff[PWD_BUFFER_SIZE];
static struct passwd pwd;
LOCK;
- if (fgetpwent_r(file, &pwd, line_buff, sizeof(line_buff), NULL) != -1) {
+ if ((ret=fgetpwent_r(file, &pwd, line_buff, sizeof(line_buff), NULL)) == 0) {
UNLOCK;
return &pwd;
}
UNLOCK;
+ __set_errno(ret);
return NULL;
}
Index: fgetspent.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/fgetspent.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- fgetspent.c 8 Aug 2002 07:28:32 -0000 1.3
+++ fgetspent.c 27 Jun 2003 10:19:28 -0000 1.4
@@ -36,22 +36,23 @@
char *buff, size_t buflen, struct spwd **crap)
{
if (file == NULL) {
- __set_errno(EINTR);
- return -1;
+ return EINTR;
}
return(__getspent_r(spwd, buff, buflen, fileno(file)));
}
struct spwd *fgetspent(FILE * file)
{
+ int ret;
static char line_buff[PWD_BUFFER_SIZE];
static struct spwd spwd;
LOCK;
- if (fgetspent_r(file, &spwd, line_buff, sizeof(line_buff), NULL) != -1) {
+ if ((ret=fgetspent_r(file, &spwd, line_buff, sizeof(line_buff), NULL)) == 0) {
UNLOCK;
return &spwd;
}
UNLOCK;
+ __set_errno(ret);
return NULL;
}
Index: getpwnam.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/getpwnam.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- getpwnam.c 8 Aug 2002 07:28:32 -0000 1.8
+++ getpwnam.c 27 Jun 2003 10:19:28 -0000 1.9
@@ -37,38 +37,43 @@
#endif
int getpwnam_r (const char *name, struct passwd *password,
- char *buff, size_t buflen, struct passwd **crap)
+ char *buff, size_t buflen, struct passwd **result)
{
+ int ret;
int passwd_fd;
if (name == NULL) {
- __set_errno(EINVAL);
- return -1;
+ return EINVAL;
}
- if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0)
- return -1;
+ if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0) {
+ return ENOENT;
+ }
- while (__getpwent_r(password, buff, buflen, passwd_fd) != -1)
+ while ((ret=__getpwent_r(password, buff, buflen, passwd_fd)) == 0) {
if (!strcmp(password->pw_name, name)) {
+ *result=password;
close(passwd_fd);
return 0;
}
+ }
close(passwd_fd);
- return -1;
+ return ret;
}
struct passwd *getpwnam(const char *name)
{
+ int ret;
static char line_buff[PWD_BUFFER_SIZE];
- static struct passwd pwd;
+ static struct passwd pwd, *result;
LOCK;
- if (getpwnam_r(name, &pwd, line_buff, sizeof(line_buff), NULL) != -1) {
+ if ((ret=getpwnam_r(name, &pwd, line_buff, sizeof(line_buff), &result)) == 0) {
UNLOCK;
return &pwd;
}
+ __set_errno(ret);
UNLOCK;
return NULL;
}
Index: getpwuid.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/getpwuid.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- getpwuid.c 8 Aug 2002 07:28:32 -0000 1.7
+++ getpwuid.c 27 Jun 2003 10:19:28 -0000 1.8
@@ -23,6 +23,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <paths.h>
+#include <errno.h>
#include "config.h"
#ifdef __UCLIBC_HAS_THREADS__
@@ -41,30 +42,32 @@
int passwd_fd;
if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0)
- return -1;
+ return errno;
- while (__getpwent_r(password, buff, buflen, passwd_fd) != -1)
+ while (__getpwent_r(password, buff, buflen, passwd_fd) == 0)
if (password->pw_uid == uid) {
close(passwd_fd);
return 0;
}
close(passwd_fd);
- return -1;
+ return EINVAL;
}
struct passwd *getpwuid(uid_t uid)
{
+ int ret;
/* file descriptor for the password file currently open */
static char line_buff[PWD_BUFFER_SIZE];
static struct passwd pwd;
LOCK;
- if (getpwuid_r(uid, &pwd, line_buff, sizeof(line_buff), NULL) != -1) {
+ if ((ret=getpwuid_r(uid, &pwd, line_buff, sizeof(line_buff), NULL)) == 0) {
UNLOCK;
return &pwd;
}
UNLOCK;
+ __set_errno(ret);
return NULL;
}
Index: getspnam.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/getspnam.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- getspnam.c 8 Aug 2002 07:28:32 -0000 1.3
+++ getspnam.c 27 Jun 2003 10:19:28 -0000 1.4
@@ -40,34 +40,35 @@
int spwd_fd;
if (name == NULL) {
- __set_errno(EINVAL);
- return -1;
+ return EINVAL;
}
if ((spwd_fd = open(_PATH_SHADOW, O_RDONLY)) < 0)
- return -1;
+ return errno;
- while (__getspent_r(spwd, buff, buflen, spwd_fd) != -1)
+ while (__getspent_r(spwd, buff, buflen, spwd_fd) == 0)
if (!strcmp(spwd->sp_namp, name)) {
close(spwd_fd);
return 0;
}
close(spwd_fd);
- return -1;
+ return EINVAL;
}
struct spwd *getspnam(const char *name)
{
+ int ret;
static char line_buff[PWD_BUFFER_SIZE];
static struct spwd spwd;
LOCK;
- if (getspnam_r(name, &spwd, line_buff, sizeof(line_buff), NULL) != -1) {
+ if ((ret=getspnam_r(name, &spwd, line_buff, sizeof(line_buff), NULL)) == 0) {
UNLOCK;
return &spwd;
}
UNLOCK;
+ __set_errno(ret);
return NULL;
}
Index: getspuid.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/getspuid.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- getspuid.c 8 Aug 2002 07:28:32 -0000 1.3
+++ getspuid.c 27 Jun 2003 10:19:28 -0000 1.4
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
+#include <errno.h>
#include "config.h"
#ifdef __UCLIBC_HAS_THREADS__
@@ -34,28 +35,32 @@
#endif
int getspuid_r (uid_t uid, struct spwd *spwd,
- char *buff, size_t buflen, struct spwd **crap)
+ char *buff, size_t buflen, struct spwd **result)
{
+ int ret;
char pwd_buff[PWD_BUFFER_SIZE];
struct passwd password;
- if (getpwuid_r(uid, &password, pwd_buff, sizeof(pwd_buff), NULL) < 0)
- return -1;
+ ret = getpwuid_r(uid, &password, pwd_buff, sizeof(pwd_buff), NULL);
+ if (ret != 0)
+ return ret;
- return getspnam_r(password.pw_name, spwd, buff, buflen, crap);
+ return getspnam_r(password.pw_name, spwd, buff, buflen, result);
}
struct spwd *getspuid(uid_t uid)
{
+ int ret;
static char line_buff[PWD_BUFFER_SIZE];
static struct spwd spwd;
LOCK;
- if (getspuid_r(uid, &spwd, line_buff, sizeof(line_buff), NULL) != -1) {
+ if ((ret=getspuid_r(uid, &spwd, line_buff, sizeof(line_buff), NULL)) == 0) {
UNLOCK;
return &spwd;
}
UNLOCK;
+ __set_errno(ret);
return NULL;
}
Index: initgroups.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/initgroups.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- initgroups.c 16 Sep 2002 06:31:02 -0000 1.10
+++ initgroups.c 27 Jun 2003 10:19:29 -0000 1.11
@@ -23,6 +23,7 @@
#include <fcntl.h>
#include <paths.h>
#include <stdlib.h>
+#include <errno.h>
#include "config.h"
#ifdef __UCLIBC_HAS_THREADS__
@@ -49,7 +50,7 @@
if ((grp_fd = open(_PATH_GROUP, O_RDONLY)) < 0)
- return -1;
+ return errno;
num_groups = 0;
group_list = (gid_t *) realloc(group_list, 1);
Index: pwent.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/pwent.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- pwent.c 18 Aug 2002 00:21:45 -0000 1.9
+++ pwent.c 27 Jun 2003 10:19:29 -0000 1.10
@@ -67,23 +67,27 @@
int getpwent_r (struct passwd *password, char *buff,
size_t buflen, struct passwd **crap)
{
+ int ret;
LOCK;
- if (pw_fd != -1 && __getpwent_r(password, buff, buflen, pw_fd) != -1) {
+ if (pw_fd != -1 && (ret=__getpwent_r(password, buff, buflen, pw_fd)) == 0) {
UNLOCK;
return 0;
}
UNLOCK;
- return -1;
+ __set_errno(ret);
+ return ret;
}
struct passwd *getpwent(void)
{
+ int ret;
static char line_buff[PWD_BUFFER_SIZE];
static struct passwd pwd;
- if (getpwent_r(&pwd, line_buff, sizeof(line_buff), NULL) != -1) {
+ if ((ret=getpwent_r(&pwd, line_buff, sizeof(line_buff), NULL)) == 0) {
return &pwd;
}
+ __set_errno(ret);
return NULL;
}
Index: sgetspent.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/sgetspent.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- sgetspent.c 8 Aug 2002 07:28:33 -0000 1.3
+++ sgetspent.c 27 Jun 2003 10:19:29 -0000 1.4
@@ -40,14 +40,16 @@
struct spwd *sgetspent(const char *string)
{
+ int ret;
static char line_buff[PWD_BUFFER_SIZE];
static struct spwd spwd;
LOCK;
- if (sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), NULL) != -1) {
+ if ((ret = sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), NULL)) == 0) {
UNLOCK;
return &spwd;
}
+ __set_errno(ret);
UNLOCK;
return NULL;
}
Index: spent.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/spent.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- spent.c 8 Aug 2002 07:28:33 -0000 1.3
+++ spent.c 27 Jun 2003 10:19:29 -0000 1.4
@@ -64,26 +64,29 @@
int getspent_r (struct spwd *spwd, char *buff,
size_t buflen, struct spwd **crap)
{
+ int ret;
LOCK;
- if (spwd_fd != -1 && __getspent_r(spwd, buff, buflen, spwd_fd) != -1) {
+ if (spwd_fd != -1 && (ret=__getspent_r(spwd, buff, buflen, spwd_fd)) == 0) {
UNLOCK;
return 0;
}
UNLOCK;
- return -1;
+ return ret;
}
struct spwd *getspent(void)
{
+ int ret;
static char line_buff[PWD_BUFFER_SIZE];
static struct spwd spwd;
LOCK;
- if (getspent_r(&spwd, line_buff, sizeof(line_buff), NULL) != -1) {
+ if ((ret=getspent_r(&spwd, line_buff, sizeof(line_buff), NULL)) == 0) {
UNLOCK;
return &spwd;
}
UNLOCK;
+ __set_errno(ret);
return NULL;
}
- Previous message: [uClibc-cvs] uClibc/extra/Configs Config.in,1.18,1.19
- Next message: [uClibc-cvs] uClibc/libc/pwd_grp fgetpwent.c,1.8,1.9 fgetspent.c,1.4,1.5 getpwnam.c,1.9,1.10 getpwuid.c,1.8,1.9 getspnam.c,1.4,1.5 getspuid.c,1.4,1.5 pwent.c,1.10,1.11 sgetspent.c,1.4,1.5 spent.c,1.4,1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the uClibc-cvs
mailing list