2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\"
|
|
|
|
.\" References consulted:
|
|
|
|
.\" Linux libc source code
|
|
|
|
.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
|
|
|
|
.\" 386BSD man pages
|
|
|
|
.\"
|
|
|
|
.\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
|
|
|
|
.\" Modified 2003-11-15 by aeb
|
|
|
|
.\"
|
2010-10-21 09:52:05 +00:00
|
|
|
.TH GETGRNAM 3 2010-10-21 "" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
|
|
|
getgrnam, getgrnam_r, getgrgid, getgrgid_r \- get group file entry
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.B #include <sys/types.h>
|
|
|
|
.B #include <grp.h>
|
|
|
|
.sp
|
|
|
|
.BI "struct group *getgrnam(const char *" name );
|
|
|
|
.sp
|
|
|
|
.BI "struct group *getgrgid(gid_t " gid );
|
|
|
|
.sp
|
2008-11-07 21:32:52 +00:00
|
|
|
.BI "int getgrnam_r(const char *" name ", struct group *" grp ,
|
2004-11-03 13:51:07 +00:00
|
|
|
.br
|
2008-11-07 21:32:52 +00:00
|
|
|
.BI " char *" buf ", size_t " buflen ", struct group **" result );
|
2004-11-03 13:51:07 +00:00
|
|
|
.sp
|
2008-11-07 21:32:52 +00:00
|
|
|
.BI "int getgrgid_r(gid_t " gid ", struct group *" grp ,
|
2004-11-03 13:51:07 +00:00
|
|
|
.br
|
2008-11-07 21:32:52 +00:00
|
|
|
.BI " char *" buf ", size_t " buflen ", struct group **" result );
|
2004-11-03 13:51:07 +00:00
|
|
|
.fi
|
2008-08-29 15:50:13 +00:00
|
|
|
.sp
|
|
|
|
.in -4n
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
|
|
.BR feature_test_macros (7)):
|
|
|
|
.ad l
|
|
|
|
.in
|
|
|
|
.sp
|
|
|
|
.BR getgrnam_r (),
|
|
|
|
.BR getgrgid_r ():
|
2010-09-19 05:11:46 +00:00
|
|
|
.RS 4
|
2008-08-29 15:50:13 +00:00
|
|
|
_POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE ||
|
|
|
|
_SVID_SOURCE || _POSIX_SOURCE
|
2010-09-19 05:11:46 +00:00
|
|
|
.RE
|
2008-08-29 15:50:13 +00:00
|
|
|
.ad b
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH DESCRIPTION
|
|
|
|
The
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR getgrnam ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function returns a pointer to a structure containing
|
2005-07-04 08:58:13 +00:00
|
|
|
the broken-out fields of the record in the group database
|
2007-04-12 22:42:49 +00:00
|
|
|
(e.g., the local group file
|
2005-07-01 16:50:33 +00:00
|
|
|
.IR /etc/group ,
|
|
|
|
NIS, and LDAP)
|
2005-07-04 08:58:13 +00:00
|
|
|
that matches the group name
|
2004-11-03 13:51:07 +00:00
|
|
|
.IR name .
|
|
|
|
.PP
|
|
|
|
The
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR getgrgid ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function returns a pointer to a structure containing
|
2005-07-01 16:50:33 +00:00
|
|
|
the broken-out fields of the record in the group database
|
2005-07-04 08:58:13 +00:00
|
|
|
that matches the group ID
|
2004-11-03 13:51:07 +00:00
|
|
|
.IR gid .
|
|
|
|
.PP
|
2010-10-21 09:52:05 +00:00
|
|
|
The \fIgroup\fP structure is defined in \fI<grp.h>\fP as follows:
|
|
|
|
.sp
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
struct group {
|
|
|
|
char *gr_name; /* group name */
|
|
|
|
char *gr_passwd; /* group password */
|
|
|
|
gid_t gr_gid; /* group ID */
|
|
|
|
char **gr_mem; /* group members */
|
|
|
|
};
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
|
|
|
For more information about the fields of this structure, see
|
|
|
|
.BR group (5).
|
|
|
|
.PP
|
2004-11-03 13:51:07 +00:00
|
|
|
The
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR getgrnam_r ()
|
2004-11-03 13:51:07 +00:00
|
|
|
and
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR getgrgid_r ()
|
2010-10-21 09:52:05 +00:00
|
|
|
functions obtain the same information as
|
|
|
|
.BR getgrnam ()
|
|
|
|
and
|
|
|
|
.BR getgrgid (),
|
|
|
|
but store the retrieved
|
2005-07-01 16:50:33 +00:00
|
|
|
.I group
|
|
|
|
structure
|
2004-11-03 13:51:07 +00:00
|
|
|
in the space pointed to by
|
2008-11-07 21:32:52 +00:00
|
|
|
.IR grp .
|
2010-10-21 09:52:05 +00:00
|
|
|
The string fields pointed to by the members of the
|
2005-07-01 16:50:33 +00:00
|
|
|
.I group
|
2010-10-21 09:52:05 +00:00
|
|
|
structure are stored in the buffer
|
2004-11-03 13:51:07 +00:00
|
|
|
.I buf
|
|
|
|
of size
|
|
|
|
.IR buflen .
|
|
|
|
A pointer to the result (in case of success) or NULL (in case no entry
|
|
|
|
was found or an error occurred) is stored in
|
2008-11-07 21:32:52 +00:00
|
|
|
.IR *result .
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
|
|
|
The maximum needed size for
|
|
|
|
.I buf
|
|
|
|
can be found using
|
|
|
|
.BR sysconf (3)
|
2008-07-10 20:53:08 +00:00
|
|
|
with the argument
|
|
|
|
.BR _SC_GETGR_R_SIZE_MAX .
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "RETURN VALUE"
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR getgrnam ()
|
|
|
|
and
|
|
|
|
.BR getgrgid ()
|
|
|
|
functions return a pointer to a
|
2005-07-01 16:50:33 +00:00
|
|
|
.I group
|
|
|
|
structure, or NULL if the matching entry
|
|
|
|
is not found or an error occurs.
|
|
|
|
If an error occurs,
|
2004-11-03 13:51:07 +00:00
|
|
|
.I errno
|
2005-07-01 16:50:33 +00:00
|
|
|
is set appropriately.
|
|
|
|
If one wants to check
|
2004-11-03 13:51:07 +00:00
|
|
|
.I errno
|
|
|
|
after the call, it should be set to zero before the call.
|
|
|
|
.LP
|
2009-03-29 22:57:50 +00:00
|
|
|
The return value may point to a static area, and may be overwritten
|
2004-11-03 13:51:07 +00:00
|
|
|
by subsequent calls to
|
2007-05-12 01:02:19 +00:00
|
|
|
.BR getgrent (3),
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR getgrgid (),
|
2004-11-03 13:51:07 +00:00
|
|
|
or
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR getgrnam ().
|
2009-03-29 23:33:55 +00:00
|
|
|
(Do not pass the returned pointer to
|
|
|
|
.BR free (3).)
|
2004-11-03 13:51:07 +00:00
|
|
|
.LP
|
2008-11-07 21:09:11 +00:00
|
|
|
On success,
|
2007-05-12 09:06:04 +00:00
|
|
|
.BR getgrnam_r ()
|
|
|
|
and
|
|
|
|
.BR getgrgid_r ()
|
2008-11-07 21:01:18 +00:00
|
|
|
return zero, and set
|
2008-11-07 21:32:52 +00:00
|
|
|
.IR *result
|
2008-11-07 21:01:18 +00:00
|
|
|
to
|
2008-11-07 21:32:52 +00:00
|
|
|
.IR grp .
|
2008-11-07 21:01:18 +00:00
|
|
|
If no matching group record was found,
|
|
|
|
these functions return 0 and store NULL in
|
2008-11-07 21:32:52 +00:00
|
|
|
.IR *result .
|
2008-11-07 21:01:18 +00:00
|
|
|
In case of error, an error number is returned, and NULL is stored in
|
2008-11-07 21:32:52 +00:00
|
|
|
.IR *result .
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH ERRORS
|
|
|
|
.TP
|
|
|
|
.BR 0 " or " ENOENT " or " ESRCH " or " EBADF " or " EPERM " or ... "
|
|
|
|
The given
|
|
|
|
.I name
|
|
|
|
or
|
|
|
|
.I gid
|
|
|
|
was not found.
|
|
|
|
.TP
|
|
|
|
.B EINTR
|
|
|
|
A signal was caught.
|
|
|
|
.TP
|
|
|
|
.B EIO
|
|
|
|
I/O error.
|
|
|
|
.TP
|
|
|
|
.B EMFILE
|
2007-06-22 19:42:52 +00:00
|
|
|
The maximum number
|
|
|
|
.RB ( OPEN_MAX )
|
|
|
|
of files was open already in the calling process.
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B ENFILE
|
|
|
|
The maximum number of files was open already in the system.
|
|
|
|
.TP
|
|
|
|
.B ENOMEM
|
2005-07-01 16:50:33 +00:00
|
|
|
.\" not in POSIX
|
2008-07-10 12:54:32 +00:00
|
|
|
Insufficient memory to allocate
|
|
|
|
.I group
|
|
|
|
structure.
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" to allocate the group structure, or to allocate buffers
|
|
|
|
.TP
|
|
|
|
.B ERANGE
|
|
|
|
Insufficient buffer space supplied.
|
|
|
|
.SH FILES
|
|
|
|
.TP
|
|
|
|
.I /etc/group
|
2005-07-01 16:50:33 +00:00
|
|
|
local group database file
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "CONFORMING TO"
|
2008-07-15 13:39:17 +00:00
|
|
|
SVr4, 4.3BSD, POSIX.1-2001.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NOTES
|
2006-08-03 13:57:30 +00:00
|
|
|
The formulation given above under "RETURN VALUE" is from POSIX.1-2001.
|
2004-11-03 13:51:07 +00:00
|
|
|
It does not call "not found" an error, hence does not specify what value
|
|
|
|
.I errno
|
2007-04-12 22:42:49 +00:00
|
|
|
might have in this situation.
|
|
|
|
But that makes it impossible to recognize
|
|
|
|
errors.
|
|
|
|
One might argue that according to POSIX
|
2004-11-03 13:51:07 +00:00
|
|
|
.I errno
|
2007-04-12 22:42:49 +00:00
|
|
|
should be left unchanged if an entry is not found.
|
|
|
|
Experiments on various
|
intro.1, time.1, accept.2, bind.2, connect.2, execve.2, flock.2, getdents.2, getpriority.2, getuid.2, intro.2, ioctl.2, mincore.2, mknod.2, personality.2, ptrace.2, read.2, recv.2, select_tut.2, send.2, sendfile.2, shmctl.2, sigaction.2, signal.2, stat.2, times.2, truncate.2, umask.2, wait.2, MB_CUR_MAX.3, MB_LEN_MAX.3, argz_add.3, btowc.3, clearenv.3, clock.3, cmsg.3, end.3, endian.3, errno.3, exit.3, fgetwc.3, fgetws.3, fopen.3, fputwc.3, fputws.3, fseek.3, fwide.3, getfsent.3, getgrnam.3, gethostid.3, getipnodebyname.3, getmntent.3, getpwnam.3, getwchar.3, grantpt.3, iconv.3, iconv_close.3, iconv_open.3, insque.3, intro.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, malloc.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mkstemp.3, mktemp.3, nl_langinfo.3, openpty.3, posix_openpt.3, printf.3, ptsname.3, putwchar.3, qecvt.3, rcmd.3, readdir.3, rexec.3, rpc.3, setnetgrent.3, shm_open.3, sigpause.3, stdin.3, stpcpy.3, strftime.3, strptime.3, syslog.3, towctrans.3, towlower.3, towupper.3, ttyslot.3, ungetwc.3, unlocked_stdio.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wprintf.3, console_ioctl.4, pts.4, elf.5, filesystems.5, hosts.5, proc.5, ttytype.5, boot.7, capabilities.7, credentials.7, epoll.7, glob.7, koi8-r.7, path_resolution.7, pty.7, signal.7, suffixes.7, time.7, unicode.7, unix.7, uri.7, utf-8.7: global fix: s/Unix/UNIX/
The man pages were rather inconsistent in the use of "Unix"
versus "UNIX". Let's go with the trademark usage.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-12 04:45:38 +00:00
|
|
|
UNIX-like systems shows that lots of different values occur in this
|
2004-11-03 13:51:07 +00:00
|
|
|
situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM and probably others.
|
|
|
|
.\" more precisely:
|
|
|
|
.\" AIX 5.1 - gives ESRCH
|
|
|
|
.\" OSF1 4.0g - gives EWOULDBLOCK
|
2009-03-31 19:30:46 +00:00
|
|
|
.\" libc, glibc up to version 2.6, Irix 6.5 - give ENOENT
|
|
|
|
.\" glibc since version 2.7 - give 0
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 - give EPERM
|
|
|
|
.\" SunOS 5.8 - gives EBADF
|
|
|
|
.\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 - give 0
|
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR endgrent (3),
|
|
|
|
.BR fgetgrent (3),
|
|
|
|
.BR getgrent (3),
|
|
|
|
.BR getpwnam (3),
|
|
|
|
.BR setgrent (3),
|
|
|
|
.BR group (5)
|