blob: 7d3b11731d0b2d8723c0d5eceeb9699902325c81 [file] [log] [blame]
<html lang="en">
<head>
<title>Reading Persona - The GNU C Library</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="The GNU C Library">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Users-and-Groups.html#Users-and-Groups" title="Users and Groups">
<link rel="prev" href="How-Change-Persona.html#How-Change-Persona" title="How Change Persona">
<link rel="next" href="Setting-User-ID.html#Setting-User-ID" title="Setting User ID">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This file documents the GNU C library.
This is Edition 0.12, last updated 2007-10-27,
of `The GNU C Library Reference Manual', for version
2.8 (Sourcery G++ Lite 2011.03-41).
Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002,
2003, 2007, 2008, 2010 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software Needs Free Documentation''
and ``GNU Lesser General Public License'', the Front-Cover texts being
``A GNU Manual'', and with the Back-Cover Texts as in (a) below. A
copy of the license is included in the section entitled "GNU Free
Documentation License".
(a) The FSF's Back-Cover Text is: ``You have the freedom to
copy and modify this GNU manual. Buying copies from the FSF
supports it in developing GNU and promoting software freedom.''-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
<link rel="stylesheet" type="text/css" href="../cs.css">
</head>
<body>
<div class="node">
<a name="Reading-Persona"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Setting-User-ID.html#Setting-User-ID">Setting User ID</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="How-Change-Persona.html#How-Change-Persona">How Change Persona</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Users-and-Groups.html#Users-and-Groups">Users and Groups</a>
<hr>
</div>
<h3 class="section">29.5 Reading the Persona of a Process</h3>
<p>Here are detailed descriptions of the functions for reading the user and
group IDs of a process, both real and effective. To use these
facilities, you must include the header files <samp><span class="file">sys/types.h</span></samp> and
<samp><span class="file">unistd.h</span></samp>.
<a name="index-unistd_002eh-3305"></a><a name="index-sys_002ftypes_002eh-3306"></a>
<!-- sys/types.h -->
<!-- POSIX.1 -->
<div class="defun">
&mdash; Data Type: <b>uid_t</b><var><a name="index-uid_005ft-3307"></a></var><br>
<blockquote><p>This is an integer data type used to represent user IDs. In the GNU
library, this is an alias for <code>unsigned int</code>.
</p></blockquote></div>
<!-- sys/types.h -->
<!-- POSIX.1 -->
<div class="defun">
&mdash; Data Type: <b>gid_t</b><var><a name="index-gid_005ft-3308"></a></var><br>
<blockquote><p>This is an integer data type used to represent group IDs. In the GNU
library, this is an alias for <code>unsigned int</code>.
</p></blockquote></div>
<!-- unistd.h -->
<!-- POSIX.1 -->
<div class="defun">
&mdash; Function: uid_t <b>getuid</b> (<var>void</var>)<var><a name="index-getuid-3309"></a></var><br>
<blockquote><p>The <code>getuid</code> function returns the real user ID of the process.
</p></blockquote></div>
<!-- unistd.h -->
<!-- POSIX.1 -->
<div class="defun">
&mdash; Function: gid_t <b>getgid</b> (<var>void</var>)<var><a name="index-getgid-3310"></a></var><br>
<blockquote><p>The <code>getgid</code> function returns the real group ID of the process.
</p></blockquote></div>
<!-- unistd.h -->
<!-- POSIX.1 -->
<div class="defun">
&mdash; Function: uid_t <b>geteuid</b> (<var>void</var>)<var><a name="index-geteuid-3311"></a></var><br>
<blockquote><p>The <code>geteuid</code> function returns the effective user ID of the process.
</p></blockquote></div>
<!-- unistd.h -->
<!-- POSIX.1 -->
<div class="defun">
&mdash; Function: gid_t <b>getegid</b> (<var>void</var>)<var><a name="index-getegid-3312"></a></var><br>
<blockquote><p>The <code>getegid</code> function returns the effective group ID of the process.
</p></blockquote></div>
<!-- unistd.h -->
<!-- POSIX.1 -->
<div class="defun">
&mdash; Function: int <b>getgroups</b> (<var>int count, gid_t *groups</var>)<var><a name="index-getgroups-3313"></a></var><br>
<blockquote><p>The <code>getgroups</code> function is used to inquire about the supplementary
group IDs of the process. Up to <var>count</var> of these group IDs are
stored in the array <var>groups</var>; the return value from the function is
the number of group IDs actually stored. If <var>count</var> is smaller than
the total number of supplementary group IDs, then <code>getgroups</code>
returns a value of <code>-1</code> and <code>errno</code> is set to <code>EINVAL</code>.
<p>If <var>count</var> is zero, then <code>getgroups</code> just returns the total
number of supplementary group IDs. On systems that do not support
supplementary groups, this will always be zero.
<p>Here's how to use <code>getgroups</code> to read all the supplementary group
IDs:
<pre class="smallexample"> gid_t *
read_all_groups (void)
{
int ngroups = getgroups (0, NULL);
gid_t *groups
= (gid_t *) xmalloc (ngroups * sizeof (gid_t));
int val = getgroups (ngroups, groups);
if (val &lt; 0)
{
free (groups);
return NULL;
}
return groups;
}
</pre>
</blockquote></div>
</body></html>