00001 /* 00002 Display real and effective user and group IDs 00003 AUP2, Sec. 5.11 00004 00005 Copyright 2003 by Marc J. Rochkind. All rights reserved. 00006 May be copied only for purposes and under conditions described 00007 on the Web page www.basepath.com/aup/copyright.htm. 00008 00009 The Example Files are provided "as is," without any warranty; 00010 without even the implied warranty of merchantability or fitness 00011 for a particular purpose. The author and his publisher are not 00012 responsible for any damages, direct or incidental, resulting 00013 from the use or non-use of these Example Files. 00014 00015 The Example Files may contain defects, and some contain deliberate 00016 coding mistakes that were included for educational reasons. 00017 You are responsible for determining if and how the Example Files 00018 are to be used. 00019 00020 */ 00021 #include "defs.h" 00022 #include <pwd.h> 00023 #include <grp.h> 00024 00025 /*[uidgrp]*/ 00026 int main(void) 00027 { 00028 uid_t uid; 00029 gid_t gid; 00030 struct passwd *pwd; 00031 struct group *grp; 00032 00033 uid = getuid(); 00034 ec_null( pwd = getpwuid(uid) ) 00035 printf("Real user = %ld (%s)\n", (long)uid, pwd->pw_name); 00036 00037 uid = geteuid(); 00038 ec_null( pwd = getpwuid(uid) ) 00039 printf("Effective user = %ld (%s)\n", (long)uid, pwd->pw_name); 00040 00041 gid = getgid(); 00042 ec_null( grp = getgrgid(gid) ) 00043 printf("Real group = %ld (%s)\n", (long)gid, grp->gr_name); 00044 00045 gid = getegid(); 00046 ec_null( grp = getgrgid(gid) ) 00047 printf("Effective group = %ld (%s)\n", (long)gid, grp->gr_name); 00048 00049 exit(EXIT_SUCCESS); 00050 00051 EC_CLEANUP_BGN 00052 exit(EXIT_FAILURE); 00053 EC_CLEANUP_END 00054 } 00055 /*[]*/