1.\" $OpenBSD: user_from_uid.3,v 1.1 2019/09/02 21:18:41 deraadt Exp $ 2.\" 3.\" Copyright (c) 1989, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.Dd $Mdocdate: September 2 2019 $ 31.Dt USER_FROM_UID 3 32.Os 33.Sh NAME 34.Nm user_from_uid , 35.Nm uid_from_user , 36.Nm group_from_gid , 37.Nm gid_from_group 38.Nd cache password and group entries 39.Sh SYNOPSIS 40.In pwd.h 41.Ft int 42.Fn uid_from_user "const char *name" "uid_t *uid" 43.Ft const char * 44.Fn user_from_uid "uid_t uid" "int nouser" 45.In grp.h 46.Ft int 47.Fn gid_from_group "const char *name" "gid_t *gid" 48.Ft const char * 49.Fn group_from_gid "gid_t gid" "int nogroup" 50.Sh DESCRIPTION 51The 52.Fn user_from_uid 53function returns the user name associated with the argument 54.Fa uid . 55The user name is cached so that multiple calls with the same 56.Fa uid 57do not require additional calls to 58.Xr getpwuid 3 . 59If there is no user associated with the 60.Fa uid , 61a pointer is returned 62to a string representation of the 63.Fa uid , 64unless the argument 65.Fa nouser 66is non-zero, in which case a null pointer is returned. 67.Pp 68The 69.Fn uid_from_user 70function returns the user ID associated with the argument 71.Fa name . 72The user ID is cached so that multiple calls with the same 73.Fa name 74do not require additional calls to 75.Xr getpwnam 3 . 76If there is no user ID associated with the 77.Fa name , 78the 79.Fn uid_from_user 80function returns -1; 81otherwise it stores the user ID at the location pointed to by 82.Fa uid 83and returns 0. 84.Pp 85The 86.Fn group_from_gid 87function returns the group name associated with the argument 88.Fa gid . 89The group name is cached so that multiple calls with the same 90.Fa gid 91do not require additional calls to 92.Xr getgrgid 3 . 93If there is no group associated with the 94.Fa gid , 95a pointer is returned 96to a string representation of the 97.Fa gid , 98unless the argument 99.Fa nogroup 100is non-zero, in which case a null pointer is returned. 101.Pp 102The 103.Fn gid_from_group 104function returns the group ID associated with the argument 105.Fa name . 106The group ID is cached so that multiple calls with the same 107.Fa name 108do not require additional calls to 109.Xr getgrnam 3 . 110If there is no group ID associated with the 111.Fa name , 112the 113.Fn gid_from_group 114function returns -1; 115otherwise it stores the group ID at the location pointed to by 116.Fa gid 117and returns 0. 118.Sh SEE ALSO 119.Xr getgrgid 3 , 120.Xr getpwuid 3 121.Sh HISTORY 122The 123.Fn user_from_uid 124and 125.Fn group_from_gid 126functions first appeared in 127.Bx 4.4 . 128.Pp 129The 130.Fn uid_from_user 131and 132.Fn gid_from_group 133functions were ported from 134.Nx 135and first appeared in 136.Ox 6.4 . 137