DragonFly kernel List (threaded) for 2003-12
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]
Re: LibC status and others...
> What I would do is rename, e.g., getpwnam() to getpwnam_r(), add the
> required passwd pointer, and use the pointer instead of the static
> _pw_passwd. Then write a new getpwnam() which simply aclls
> getpwnam_r() using &_pw_passwd for the passwd pointer.
>
> Would you like to have a go at making this change? If you know any C
> at all it should be a breeze. If not, maybe one of the other
> developers
> would like to have a go at it. If not that, then I can do it (it
> would take me less then 30 minutes to do).
well, it took me less than 30 minutes...
but it was really simple and is most likely not correct.
but maybe it is, and this way, we could concentrate on something different.
btw: if this looks right, i may tackle the other _r's tomorrow.
~ibotty
(note to myself, do not write (and actually post) code after midnight, w/o
thinking)
Index: lib/libc/gen/getpwent.c
===================================================================
RCS file: /home/src/dcvs/src/lib/libc/gen/getpwent.c,v
retrieving revision 1.3
diff -u -3 -p -r1.3 getpwent.c
--- lib/libc/gen/getpwent.c 12 Nov 2003 20:21:23 -0000 1.3
+++ lib/libc/gen/getpwent.c 11 Dec 2003 00:28:36 -0000
@@ -141,23 +141,22 @@ tryagain:
return(&_pw_passwd);
}
-struct passwd *
-getpwnam(name)
- const char *name;
+int
+getpwnam_r(const char *name, struct passwd *pwent, char *buffer, size_t bufsize, struct passwd **result)
{
DBT key;
int len, rval;
- char bf[UT_NAMESIZE + 2];
if (!_pw_db && !__initdb())
- return((struct passwd *)NULL);
+ /* FIXME: what error to return */
+ return(0);
- bf[0] = _PW_KEYBYNAME;
+ buffer[0] = _PW_KEYBYNAME;
len = strlen(name);
- if (len > UT_NAMESIZE)
- return(NULL);
- bcopy(name, bf + 1, len);
- key.data = (u_char *)bf;
+ if (len > bufsize-1)
+ return(EOVERFLOW);
+ bcopy(name, buffer + 1, len);
+ key.data = (u_char *)buffer;
key.size = len + 1;
rval = __hashpw(&key);
@@ -166,19 +165,33 @@ getpwnam(name)
if (_yp_enabled == -1)
_ypinitdb();
if (_yp_enabled)
- rval = _getyppass(&_pw_passwd, name, "passwd.byname");
+ rval = _getyppass(pwent, name, "passwd.byname");
}
#endif
/*
* Prevent login attempts when YP is not enabled but YP entries
* are in /etc/master.passwd.
*/
- if (rval && (_pw_passwd.pw_name[0] == '+'||
- _pw_passwd.pw_name[0] == '-')) rval = 0;
+ if (rval && ((*pwent).pw_name[0] == '+'||
+ (*pwent).pw_name[0] == '-')) rval = 0;
if (!_pw_stayopen)
endpwent();
- return(rval ? &_pw_passwd : (struct passwd *)NULL);
+
+ /* store a pointer of pwent in result */
+ result = &pwent;
+ return(rval);
+}
+
+struct passwd *
+getpwnam(const char *name)
+{
+ char bf[UT_NAMESIZE + 2];
+ struct passwd *result;
+ if (getpwnam_r(name, &_pw_passwd, bf, sizeof bf, &result))
+ return result;
+ else
+ return NULL;
}
struct passwd *
Index: include/pwd.h
===================================================================
RCS file: /home/src/dcvs/src/include/pwd.h,v
retrieving revision 1.2
diff -u -3 -p -r1.2 pwd.h
--- include/pwd.h 14 Nov 2003 01:01:43 -0000 1.2
+++ include/pwd.h 11 Dec 2003 00:23:29 -0000
@@ -100,7 +100,8 @@ struct passwd {
__BEGIN_DECLS
struct passwd *getpwuid (uid_t);
-struct passwd *getpwnam (const char *);
+int getpwnam_r (const char *, struct pwent *, char *, size_t, struct passwd **);
+struct passwd *getpwnam (const char *);
#ifndef _POSIX_SOURCE
struct passwd *getpwent (void);
int setpassent (int);
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]