Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

29.5 Reading the Persona of a Process

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 sys/types.h and unistd.h.

— Data Type: uid_t

This is an integer data type used to represent user IDs. In the GNU library, this is an alias for unsigned int.

— Data Type: gid_t

This is an integer data type used to represent group IDs. In the GNU library, this is an alias for unsigned int.

— Function: uid_t getuid (void)

The getuid function returns the real user ID of the process.

— Function: gid_t getgid (void)

The getgid function returns the real group ID of the process.

— Function: uid_t geteuid (void)

The geteuid function returns the effective user ID of the process.

— Function: gid_t getegid (void)

The getegid function returns the effective group ID of the process.

— Function: int getgroups (int count, gid_t *groups)

The getgroups function is used to inquire about the supplementary group IDs of the process. Up to count of these group IDs are stored in the array groups; the return value from the function is the number of group IDs actually stored. If count is smaller than the total number of supplementary group IDs, then getgroups returns a value of -1 and errno is set to EINVAL.

If count is zero, then getgroups just returns the total number of supplementary group IDs. On systems that do not support supplementary groups, this will always be zero.

Here's how to use getgroups to read all the supplementary group IDs:

          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 < 0)
              {
                free (groups);
                return NULL;
              }
            return groups;
          }
     

 
 
  Published under the terms of the GNU General Public License Design by Interspire