Skip to content

Commit

Permalink
Add uid_from_user() and gid_from_group(), derived from pax's cache.c.
Browse files Browse the repository at this point in the history
It replaces the existing pwcache.c functions user_from_uid(3) and
group_from_gid(3) with the pax equivalents.  Adapted from NetBSD
(mycroft) changes from our own pax's cache.c.  OK guenther@
  • Loading branch information
millert committed Sep 13, 2018
1 parent 4b5fa55 commit 5a122e6
Show file tree
Hide file tree
Showing 9 changed files with 456 additions and 94 deletions.
5 changes: 3 additions & 2 deletions include/grp.h
@@ -1,4 +1,4 @@
/* $OpenBSD: grp.h,v 1.12 2014/08/31 04:04:38 guenther Exp $ */
/* $OpenBSD: grp.h,v 1.13 2018/09/13 12:31:15 millert Exp $ */
/* $NetBSD: grp.h,v 1.7 1995/04/29 05:30:40 cgd Exp $ */

/*-
Expand Down Expand Up @@ -70,7 +70,8 @@ int getgrnam_r(const char *, struct group *, char *,
#endif
#if __BSD_VISIBLE
int setgroupent(int);
char *group_from_gid(gid_t, int);
int gid_from_group(const char *, gid_t *);
const char *group_from_gid(gid_t, int);
#endif
__END_DECLS

Expand Down
5 changes: 3 additions & 2 deletions include/pwd.h
@@ -1,4 +1,4 @@
/* $OpenBSD: pwd.h,v 1.25 2017/03/09 10:13:03 fcambus Exp $ */
/* $OpenBSD: pwd.h,v 1.26 2018/09/13 12:31:15 millert Exp $ */
/* $NetBSD: pwd.h,v 1.9 1996/05/15 21:36:45 jtc Exp $ */

/*-
Expand Down Expand Up @@ -106,7 +106,8 @@ void endpwent(void);
#endif
#if __BSD_VISIBLE
int setpassent(int);
char *user_from_uid(uid_t, int);
int uid_from_user(const char *, uid_t *);
const char *user_from_uid(uid_t, int);
char *bcrypt_gensalt(u_int8_t);
char *bcrypt(const char *, const char *);
int bcrypt_newhash(const char *, int, char *, size_t);
Expand Down
2 changes: 2 additions & 0 deletions lib/libc/Symbols.list
Expand Up @@ -663,6 +663,7 @@ getpwuid_shadow
getttyent
getttynam
getusershell
gid_from_group
glob
globfree
group_from_gid
Expand Down Expand Up @@ -798,6 +799,7 @@ ttyname
ttyname_r
ttyslot
ualarm
uid_from_user
uname
unvis
user_from_uid
Expand Down
3 changes: 2 additions & 1 deletion lib/libc/gen/getgrent.c
@@ -1,4 +1,4 @@
/* $OpenBSD: getgrent.c,v 1.46 2015/12/01 15:08:25 deraadt Exp $ */
/* $OpenBSD: getgrent.c,v 1.47 2018/09/13 12:31:15 millert Exp $ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
Expand Down Expand Up @@ -144,6 +144,7 @@ getgrnam_r(const char *name, struct group *grp, char *buffer,
errno = errnosave;
return ret;
}
DEF_WEAK(getgrnam_r);

static struct group *
getgrgid_gs(gid_t gid, struct group *p_gr, struct group_storage *gs)
Expand Down
59 changes: 54 additions & 5 deletions lib/libc/gen/pwcache.3
@@ -1,4 +1,4 @@
.\" $OpenBSD: pwcache.3,v 1.13 2016/03/26 14:36:37 schwarze Exp $
.\" $OpenBSD: pwcache.3,v 1.14 2018/09/13 12:31:15 millert Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
Expand Down Expand Up @@ -27,19 +27,25 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd $Mdocdate: March 26 2016 $
.Dd $Mdocdate: September 13 2018 $
.Dt USER_FROM_UID 3
.Os
.Sh NAME
.Nm user_from_uid ,
.Nm uid_from_user ,
.Nm group_from_gid
.Nm gid_from_group
.Nd cache password and group entries
.Sh SYNOPSIS
.In grp.h
.In pwd.h
.Ft char *
.Ft int
.Fn uid_from_user "const char *name" "uid_t *uid"
.Ft const char *
.Fn user_from_uid "uid_t uid" "int nouser"
.Ft char *
.In grp.h
.Ft int
.Fn gid_from_group "const char *name" "gid_t *gid"
.Ft const char *
.Fn group_from_gid "gid_t gid" "int nogroup"
.Sh DESCRIPTION
The
Expand All @@ -60,6 +66,23 @@ unless the argument
is non-zero, in which case a null pointer is returned.
.Pp
The
.Fn uid_from_user
function returns the user ID associated with the argument
.Fa name .
The user ID is cached so that multiple calls with the same
.Fa name
do not require additional calls to
.Xr getpwnam 3 .
If there is no user ID associated with the
.Fa name ,
the
.Fn uid_from_user
function returns -1;
otherwise it stores the user ID at the location pointed to by
.Fa uid
and returns 0.
.Pp
The
.Fn group_from_gid
function returns the group name associated with the argument
.Fa gid .
Expand All @@ -75,6 +98,23 @@ to a string representation of the
unless the argument
.Fa nogroup
is non-zero, in which case a null pointer is returned.
.Pp
The
.Fn gid_from_group
function returns the group ID associated with the argument
.Fa name .
The group ID is cached so that multiple calls with the same
.Fa name
do not require additional calls to
.Xr getgrnam 3 .
If there is no group ID associated with the
.Fa name ,
the
.Fn gid_from_group
function returns -1;
otherwise it stores the group ID at the location pointed to by
.Fa gid
and returns 0.
.Sh SEE ALSO
.Xr getgrgid 3 ,
.Xr getpwuid 3
Expand All @@ -85,3 +125,12 @@ and
.Fn group_from_gid
functions first appeared in
.Bx 4.4 .
.Pp
The
.Fn uid_from_user
and
.Fn gid_from_group
functions were ported from
.Nx
and first appeared in
.Ox 6.4 .

0 comments on commit 5a122e6

Please sign in to comment.