OpenCoverage

id.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/id.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* id -- print real and effective UIDs and GIDs-
2 Copyright (C) 1989-2018 Free Software Foundation, Inc.-
3-
4 This program is free software: you can redistribute it and/or modify-
5 it under the terms of the GNU General Public License as published by-
6 the Free Software Foundation, either version 3 of the License, or-
7 (at your option) any later version.-
8-
9 This program is distributed in the hope that it will be useful,-
10 but WITHOUT ANY WARRANTY; without even the implied warranty of-
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
12 GNU General Public License for more details.-
13-
14 You should have received a copy of the GNU General Public License-
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
16-
17/* Written by Arnold Robbins.-
18 Major rewrite by David MacKenzie, djm@gnu.ai.mit.edu. */-
19-
20#include <config.h>-
21#include <stdio.h>-
22#include <sys/types.h>-
23#include <pwd.h>-
24#include <grp.h>-
25#include <getopt.h>-
26#include <selinux/selinux.h>-
27-
28#include "system.h"-
29#include "die.h"-
30#include "error.h"-
31#include "mgetgroups.h"-
32#include "quote.h"-
33#include "group-list.h"-
34#include "smack.h"-
35#include "userspec.h"-
36-
37/* The official name of this program (e.g., no 'g' prefix). */-
38#define PROGRAM_NAME "id"-
39-
40#define AUTHORS \-
41 proper_name ("Arnold Robbins"), \-
42 proper_name ("David MacKenzie")-
43-
44/* If nonzero, output only the SELinux context. */-
45static bool just_context = 0;-
46-
47static void print_user (uid_t uid);-
48static void print_full_info (const char *username);-
49-
50/* If true, output user/group name instead of ID number. -n */-
51static bool use_name = false;-
52-
53/* The real and effective IDs of the user to print. */-
54static uid_t ruid, euid;-
55static gid_t rgid, egid;-
56-
57/* True unless errors have been encountered. */-
58static bool ok = true;-
59-
60/* The SELinux context. Start with a known invalid value so print_full_info-
61 knows when 'context' has not been set to a meaningful value. */-
62static char *context = NULL;-
63-
64static struct option const longopts[] =-
65{-
66 {"context", no_argument, NULL, 'Z'},-
67 {"group", no_argument, NULL, 'g'},-
68 {"groups", no_argument, NULL, 'G'},-
69 {"name", no_argument, NULL, 'n'},-
70 {"real", no_argument, NULL, 'r'},-
71 {"user", no_argument, NULL, 'u'},-
72 {"zero", no_argument, NULL, 'z'},-
73 {GETOPT_HELP_OPTION_DECL},-
74 {GETOPT_VERSION_OPTION_DECL},-
75 {NULL, 0, NULL, 0}-
76};-
77-
78void-
79usage (int status)-
80{-
81 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • id
FALSEevaluated 16 times by 1 test
Evaluated by:
  • id
3-16
82 emit_try_help ();
executed 3 times by 1 test: end of block
Executed by:
  • id
3
83 else-
84 {-
85 printf (_("Usage: %s [OPTION]... [USER]\n"), program_name);-
86 fputs (_("\-
87Print user and group information for the specified USER,\n\-
88or (when USER omitted) for the current user.\n\-
89\n"),-
90 stdout);-
91 fputs (_("\-
92 -a ignore, for compatibility with other versions\n\-
93 -Z, --context print only the security context of the process\n\-
94 -g, --group print only the effective group ID\n\-
95 -G, --groups print all group IDs\n\-
96 -n, --name print a name instead of a number, for -ugG\n\-
97 -r, --real print the real ID instead of the effective ID, with -ugG\n\-
98 -u, --user print only the effective user ID\n\-
99 -z, --zero delimit entries with NUL characters, not whitespace;\n\-
100 not permitted in default format\n\-
101"), stdout);-
102 fputs (HELP_OPTION_DESCRIPTION, stdout);-
103 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
104 fputs (_("\-
105\n\-
106Without any OPTION, print some useful set of identified information.\n\-
107"), stdout);-
108 emit_ancillary_info (PROGRAM_NAME);-
109 }
executed 16 times by 1 test: end of block
Executed by:
  • id
16
110 exit (status);
executed 19 times by 1 test: exit (status);
Executed by:
  • id
19
111}-
112-
113int-
114main (int argc, char **argv)-
115{-
116 int optc;-
117 int selinux_enabled = (is_selinux_enabled () > 0);-
118 bool smack_enabled = is_smack_enabled ();-
119 bool opt_zero = false;-
120 char *pw_name = NULL;-
121-
122 /* If true, output the list of all group IDs. -G */-
123 bool just_group_list = false;-
124 /* If true, output only the group ID(s). -g */-
125 bool just_group = false;-
126 /* If true, output real UID/GID instead of default effective UID/GID. -r */-
127 bool use_real = false;-
128 /* If true, output only the user ID(s). -u */-
129 bool just_user = false;-
130-
131 initialize_main (&argc, &argv);-
132 set_program_name (argv[0]);-
133 setlocale (LC_ALL, "");-
134 bindtextdomain (PACKAGE, LOCALEDIR);-
135 textdomain (PACKAGE);-
136-
137 atexit (close_stdout);-
138-
139 while ((optc = getopt_long (argc, argv, "agnruzGZ", longopts, NULL)) != -1)
(optc = getopt... *)0) )) != -1Description
TRUEevaluated 454 times by 1 test
Evaluated by:
  • id
FALSEevaluated 233 times by 1 test
Evaluated by:
  • id
233-454
140 {-
141 switch (optc)-
142 {-
143 case 'a':
executed 1 time by 1 test: case 'a':
Executed by:
  • id
1
144 /* Ignore -a, for compatibility with SVR4. */-
145 break;
executed 1 time by 1 test: break;
Executed by:
  • id
1
146-
147 case 'Z':
executed 3 times by 1 test: case 'Z':
Executed by:
  • id
3
148 /* politely decline if we're not on a SELinux/SMACK-enabled kernel. */-
149#ifdef HAVE_SMACK-
150 if (!selinux_enabled && !smack_enabled)-
151 die (EXIT_FAILURE, 0,-
152 _("--context (-Z) works only on "-
153 "an SELinux/SMACK-enabled kernel"));-
154#else-
155 if (!selinux_enabled)
!selinux_enabledDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • id
FALSEnever evaluated
0-3
156 die (EXIT_FAILURE, 0,
executed 3 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"--context (-Z) works only on an SELinux-enabled kernel\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0),...works only on an SELinux-enabled kernel" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "--context (-Z) works only on an SELinux-enabled kernel" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • id
3
157 _("--context (-Z) works only on an SELinux-enabled kernel"));
executed 3 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"--context (-Z) works only on an SELinux-enabled kernel\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0),...works only on an SELinux-enabled kernel" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "--context (-Z) works only on an SELinux-enabled kernel" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • id
3
158#endif-
159 just_context = true;-
160 break;
never executed: break;
0
161-
162 case 'g':
executed 50 times by 1 test: case 'g':
Executed by:
  • id
50
163 just_group = true;-
164 break;
executed 50 times by 1 test: break;
Executed by:
  • id
50
165 case 'n':
executed 66 times by 1 test: case 'n':
Executed by:
  • id
66
166 use_name = true;-
167 break;
executed 66 times by 1 test: break;
Executed by:
  • id
66
168 case 'r':
executed 64 times by 1 test: case 'r':
Executed by:
  • id
64
169 use_real = true;-
170 break;
executed 64 times by 1 test: break;
Executed by:
  • id
64
171 case 'u':
executed 125 times by 1 test: case 'u':
Executed by:
  • id
125
172 just_user = true;-
173 break;
executed 125 times by 1 test: break;
Executed by:
  • id
125
174 case 'z':
executed 63 times by 1 test: case 'z':
Executed by:
  • id
63
175 opt_zero = true;-
176 break;
executed 63 times by 1 test: break;
Executed by:
  • id
63
177 case 'G':
executed 52 times by 1 test: case 'G':
Executed by:
  • id
52
178 just_group_list = true;-
179 break;
executed 52 times by 1 test: break;
Executed by:
  • id
52
180 case_GETOPT_HELP_CHAR;
never executed: break;
executed 16 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • id
0-16
181 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 11 times by 1 test: exit ( 0 );
Executed by:
  • id
never executed: break;
executed 11 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • id
0-11
182 default:
executed 3 times by 1 test: default:
Executed by:
  • id
3
183 usage (EXIT_FAILURE);-
184 }
never executed: end of block
0
185 }-
186-
187 size_t n_ids = argc - optind;-
188 if (1 < n_ids)
1 < n_idsDescription
TRUEnever evaluated
FALSEevaluated 233 times by 1 test
Evaluated by:
  • id
0-233
189 {-
190 error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));-
191 usage (EXIT_FAILURE);-
192 }
never executed: end of block
0
193-
194 if (n_ids && just_context)
n_idsDescription
TRUEevaluated 114 times by 1 test
Evaluated by:
  • id
FALSEevaluated 119 times by 1 test
Evaluated by:
  • id
just_contextDescription
TRUEnever evaluated
FALSEevaluated 114 times by 1 test
Evaluated by:
  • id
0-119
195 die (EXIT_FAILURE, 0,
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot print security context when user specified\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "cannot print security context when user specified" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "cannot print security context when user specified" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
196 _("cannot print security context when user specified"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot print security context when user specified\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "cannot print security context when user specified" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "cannot print security context when user specified" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
197-
198 if (just_user + just_group + just_group_list + just_context > 1)
just_user + ju...st_context > 1Description
TRUEnever evaluated
FALSEevaluated 233 times by 1 test
Evaluated by:
  • id
0-233
199 die (EXIT_FAILURE, 0, _("cannot print \"only\" of more than one choice"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot print \\\"only\\\" of more than one choice\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "cannot print \"only\" of more than one choice" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "cannot print \"only\" of more than one choice" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
200-
201 bool default_format = ! (just_user
just_userDescription
TRUEevaluated 123 times by 1 test
Evaluated by:
  • id
FALSEevaluated 110 times by 1 test
Evaluated by:
  • id
110-123
202 || just_group
just_groupDescription
TRUEevaluated 48 times by 1 test
Evaluated by:
  • id
FALSEevaluated 62 times by 1 test
Evaluated by:
  • id
48-62
203 || just_group_list
just_group_listDescription
TRUEevaluated 50 times by 1 test
Evaluated by:
  • id
FALSEevaluated 12 times by 1 test
Evaluated by:
  • id
12-50
204 || just_context);
just_contextDescription
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • id
0-12
205-
206 if (default_format && (use_real || use_name))
default_formatDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • id
FALSEevaluated 221 times by 1 test
Evaluated by:
  • id
use_realDescription
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • id
use_nameDescription
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • id
0-221
207 die (EXIT_FAILURE, 0,
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot print only names or real IDs in default format\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), ...only names or real IDs in default format" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "cannot print only names or real IDs in default format" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
208 _("cannot print only names or real IDs in default format"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot print only names or real IDs in default format\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), ...only names or real IDs in default format" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "cannot print only names or real IDs in default format" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
209-
210 if (default_format && opt_zero)
default_formatDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • id
FALSEevaluated 221 times by 1 test
Evaluated by:
  • id
opt_zeroDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • id
FALSEevaluated 11 times by 1 test
Evaluated by:
  • id
1-221
211 die (EXIT_FAILURE, 0,
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"option --zero not permitted in default format\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "option --zero not permitted in default format" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "option --zero not permitted in default format" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • id
1
212 _("option --zero not permitted in default format"));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"option --zero not permitted in default format\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "option --zero not permitted in default format" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "option --zero not permitted in default format" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • id
1
213-
214 /* If we are on a SELinux/SMACK-enabled kernel, no user is specified, and-
215 either --context is specified or none of (-u,-g,-G) is specified,-
216 and we're not in POSIXLY_CORRECT mode, get our context. Otherwise,-
217 leave the context variable alone - it has been initialized to an-
218 invalid value that will be not displayed in print_full_info(). */-
219 if (n_ids == 0
n_ids == 0Description
TRUEevaluated 118 times by 1 test
Evaluated by:
  • id
FALSEevaluated 114 times by 1 test
Evaluated by:
  • id
114-118
220 && (just_context
just_contextDescription
TRUEnever evaluated
FALSEevaluated 118 times by 1 test
Evaluated by:
  • id
0-118
221 || (default_format && ! getenv ("POSIXLY_CORRECT"))))
default_formatDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • id
FALSEevaluated 117 times by 1 test
Evaluated by:
  • id
! getenv ("POSIXLY_CORRECT")Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • id
FALSEnever evaluated
0-117
222 {-
223 /* Report failure only if --context (-Z) was explicitly requested. */-
224 if ((selinux_enabled && getcon (&context) && just_context)
selinux_enabledDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • id
getcon (&context)Description
TRUEnever evaluated
FALSEnever evaluated
just_contextDescription
TRUEnever evaluated
FALSEnever evaluated
0-1
225 || (smack_enabled
smack_enabledDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • id
0-1
226 && smack_new_label_from_self (&context) < 0
smack_new_labe...(&context) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
227 && just_context))
just_contextDescription
TRUEnever evaluated
FALSEnever evaluated
0
228 die (EXIT_FAILURE, 0, _("can't get process context"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"can't get process context\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "can't get process context" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "can't get process context" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
229 }
executed 1 time by 1 test: end of block
Executed by:
  • id
1
230-
231 if (n_ids == 1)
n_ids == 1Description
TRUEevaluated 114 times by 1 test
Evaluated by:
  • id
FALSEevaluated 118 times by 1 test
Evaluated by:
  • id
114-118
232 {-
233 struct passwd *pwd = NULL;-
234 const char *spec = argv[optind];-
235 /* Disallow an empty spec here as parse_user_spec() doesn't-
236 give an error for that as it seems it's a valid way to-
237 specify a noop or "reset special bits" depending on the system. */-
238 if (*spec)
*specDescription
TRUEevaluated 113 times by 1 test
Evaluated by:
  • id
FALSEevaluated 1 time by 1 test
Evaluated by:
  • id
1-113
239 {-
240 if (parse_user_spec (spec, &euid, NULL, NULL, NULL) == NULL)
parse_user_spe...== ((void *)0)Description
TRUEevaluated 111 times by 1 test
Evaluated by:
  • id
FALSEevaluated 2 times by 1 test
Evaluated by:
  • id
2-111
241 {-
242 /* parse_user_spec will only extract a numeric spec,-
243 so we lookup that here to verify and also retrieve-
244 the PW_NAME used subsequently in group lookup. */-
245 pwd = getpwuid (euid);-
246 }
executed 111 times by 1 test: end of block
Executed by:
  • id
111
247 }
executed 113 times by 1 test: end of block
Executed by:
  • id
113
248 if (pwd == NULL)
pwd == ((void *)0)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • id
FALSEevaluated 111 times by 1 test
Evaluated by:
  • id
3-111
249 die (EXIT_FAILURE, 0, _("%s: no such user"), quote (spec));
executed 3 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"%s: no such user\", 5), quote (spec)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "%s: no such user" , 5) , quote (spec)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "%s: no such user" , 5) , quote (spec)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
Executed by:
  • id
3
250 pw_name = xstrdup (pwd->pw_name);-
251 ruid = euid = pwd->pw_uid;-
252 rgid = egid = pwd->pw_gid;-
253 }
executed 111 times by 1 test: end of block
Executed by:
  • id
111
254 else-
255 {-
256 /* POSIX says identification functions (getuid, getgid, and-
257 others) cannot fail, but they can fail under GNU/Hurd and a-
258 few other systems. Test for failure by checking errno. */-
259 uid_t NO_UID = -1;-
260 gid_t NO_GID = -1;-
261-
262 if (just_user ? !use_real
just_user ? !u... !just_contextDescription
TRUEevaluated 85 times by 1 test
Evaluated by:
  • id
FALSEevaluated 33 times by 1 test
Evaluated by:
  • id
just_userDescription
TRUEevaluated 89 times by 1 test
Evaluated by:
  • id
FALSEevaluated 29 times by 1 test
Evaluated by:
  • id
29-89
263 : !just_group && !just_group_list && !just_context)
just_user ? !u... !just_contextDescription
TRUEevaluated 85 times by 1 test
Evaluated by:
  • id
FALSEevaluated 33 times by 1 test
Evaluated by:
  • id
!just_groupDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • id
FALSEevaluated 13 times by 1 test
Evaluated by:
  • id
!just_group_listDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • id
FALSEevaluated 15 times by 1 test
Evaluated by:
  • id
!just_contextDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • id
FALSEnever evaluated
0-85
264 {-
265 errno = 0;-
266 euid = geteuid ();-
267 if (euid == NO_UID && errno)
euid == NO_UIDDescription
TRUEnever evaluated
FALSEevaluated 85 times by 1 test
Evaluated by:
  • id
(*__errno_location ())Description
TRUEnever evaluated
FALSEnever evaluated
0-85
268 die (EXIT_FAILURE, errno, _("cannot get effective UID"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"cannot get effective UID\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "cannot get effective UID" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "cannot get effective UID" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
269 }
executed 85 times by 1 test: end of block
Executed by:
  • id
85
270-
271 if (just_user ? use_real
just_user ? us...!just_context)Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • id
FALSEevaluated 97 times by 1 test
Evaluated by:
  • id
just_userDescription
TRUEevaluated 89 times by 1 test
Evaluated by:
  • id
FALSEevaluated 29 times by 1 test
Evaluated by:
  • id
21-97
272 : !just_group && (just_group_list || !just_context))
just_user ? us...!just_context)Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • id
FALSEevaluated 97 times by 1 test
Evaluated by:
  • id
!just_groupDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • id
FALSEevaluated 13 times by 1 test
Evaluated by:
  • id
just_group_listDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • id
FALSEevaluated 1 time by 1 test
Evaluated by:
  • id
!just_contextDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • id
FALSEnever evaluated
0-97
273 {-
274 errno = 0;-
275 ruid = getuid ();-
276 if (ruid == NO_UID && errno)
ruid == NO_UIDDescription
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • id
(*__errno_location ())Description
TRUEnever evaluated
FALSEnever evaluated
0-21
277 die (EXIT_FAILURE, errno, _("cannot get real UID"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"cannot get real UID\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "cannot get real UID" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "cannot get real UID" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
278 }
executed 21 times by 1 test: end of block
Executed by:
  • id
21
279-
280 if (!just_user && (just_group || just_group_list || !just_context))
!just_userDescription
TRUEevaluated 29 times by 1 test
Evaluated by:
  • id
FALSEevaluated 89 times by 1 test
Evaluated by:
  • id
just_groupDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • id
FALSEevaluated 16 times by 1 test
Evaluated by:
  • id
just_group_listDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • id
FALSEevaluated 1 time by 1 test
Evaluated by:
  • id
!just_contextDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • id
FALSEnever evaluated
0-89
281 {-
282 errno = 0;-
283 egid = getegid ();-
284 if (egid == NO_GID && errno)
egid == NO_GIDDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • id
(*__errno_location ())Description
TRUEnever evaluated
FALSEnever evaluated
0-29
285 die (EXIT_FAILURE, errno, _("cannot get effective GID"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"cannot get effective GID\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "cannot get effective GID" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "cannot get effective GID" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
286-
287 errno = 0;-
288 rgid = getgid ();-
289 if (rgid == NO_GID && errno)
rgid == NO_GIDDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • id
(*__errno_location ())Description
TRUEnever evaluated
FALSEnever evaluated
0-29
290 die (EXIT_FAILURE, errno, _("cannot get real GID"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"cannot get real GID\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "cannot get real GID" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "cannot get real GID" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
291 }
executed 29 times by 1 test: end of block
Executed by:
  • id
29
292 }
executed 118 times by 1 test: end of block
Executed by:
  • id
118
293-
294 if (just_user)
just_userDescription
TRUEevaluated 123 times by 1 test
Evaluated by:
  • id
FALSEevaluated 106 times by 1 test
Evaluated by:
  • id
106-123
295 {-
296 print_user (use_real ? ruid : euid);-
297 }
executed 123 times by 1 test: end of block
Executed by:
  • id
123
298 else if (just_group)
just_groupDescription
TRUEevaluated 48 times by 1 test
Evaluated by:
  • id
FALSEevaluated 58 times by 1 test
Evaluated by:
  • id
48-58
299 {-
300 if (!print_group (use_real ? rgid : egid, use_name))
!print_group (...gid, use_name)Description
TRUEnever evaluated
FALSEevaluated 48 times by 1 test
Evaluated by:
  • id
0-48
301 ok = false;
never executed: ok = 0 ;
0
302 }
executed 48 times by 1 test: end of block
Executed by:
  • id
48
303 else if (just_group_list)
just_group_listDescription
TRUEevaluated 50 times by 1 test
Evaluated by:
  • id
FALSEevaluated 8 times by 1 test
Evaluated by:
  • id
8-50
304 {-
305 if (!print_group_list (pw_name, ruid, rgid, egid, use_name,
!print_group_l... ? '\0' : ' ')Description
TRUEnever evaluated
FALSEevaluated 50 times by 1 test
Evaluated by:
  • id
0-50
306 opt_zero ? '\0' : ' '))
!print_group_l... ? '\0' : ' ')Description
TRUEnever evaluated
FALSEevaluated 50 times by 1 test
Evaluated by:
  • id
0-50
307 ok = false;
never executed: ok = 0 ;
0
308 }
executed 50 times by 1 test: end of block
Executed by:
  • id
50
309 else if (just_context)
just_contextDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • id
0-8
310 {-
311 fputs (context, stdout);-
312 }
never executed: end of block
0
313 else-
314 {-
315 print_full_info (pw_name);-
316 }
executed 8 times by 1 test: end of block
Executed by:
  • id
8
317 putchar (opt_zero ? '\0' : '\n');-
318-
319 IF_LINT (free (pw_name));-
320 return ok ? EXIT_SUCCESS : EXIT_FAILURE;
executed 229 times by 1 test: return ok ? 0 : 1 ;
Executed by:
  • id
229
321}-
322-
323/* Convert a gid_t to string. Do not use this function directly.-
324 Instead, use it via the gidtostr macro.-
325 Beware that it returns a pointer to static storage. */-
326static char *-
327gidtostr_ptr (gid_t const *gid)-
328{-
329 static char buf[INT_BUFSIZE_BOUND (uintmax_t)];-
330 return umaxtostr (*gid, buf);
executed 66 times by 1 test: return umaxtostr (*gid, buf);
Executed by:
  • id
66
331}-
332#define gidtostr(g) gidtostr_ptr (&(g))-
333-
334/* Convert a uid_t to string. Do not use this function directly.-
335 Instead, use it via the uidtostr macro.-
336 Beware that it returns a pointer to static storage. */-
337static char *-
338uidtostr_ptr (uid_t const *uid)-
339{-
340 static char buf[INT_BUFSIZE_BOUND (uintmax_t)];-
341 return umaxtostr (*uid, buf);
executed 108 times by 1 test: return umaxtostr (*uid, buf);
Executed by:
  • id
108
342}-
343#define uidtostr(u) uidtostr_ptr (&(u))-
344-
345/* Print the name or value of user ID UID. */-
346-
347static void-
348print_user (uid_t uid)-
349{-
350 struct passwd *pwd = NULL;-
351-
352 if (use_name)
use_nameDescription
TRUEevaluated 23 times by 1 test
Evaluated by:
  • id
FALSEevaluated 100 times by 1 test
Evaluated by:
  • id
23-100
353 {-
354 pwd = getpwuid (uid);-
355 if (pwd == NULL)
pwd == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 23 times by 1 test
Evaluated by:
  • id
0-23
356 {-
357 error (0, 0, _("cannot find name for user ID %s"),-
358 uidtostr (uid));-
359 ok = false;-
360 }
never executed: end of block
0
361 }
executed 23 times by 1 test: end of block
Executed by:
  • id
23
362-
363 char *s = pwd ? pwd->pw_name : uidtostr (uid);
pwdDescription
TRUEevaluated 23 times by 1 test
Evaluated by:
  • id
FALSEevaluated 100 times by 1 test
Evaluated by:
  • id
23-100
364 fputs (s, stdout);-
365}
executed 123 times by 1 test: end of block
Executed by:
  • id
123
366-
367/* Print all of the info about the user's user and group IDs. */-
368-
369static void-
370print_full_info (const char *username)-
371{-
372 struct passwd *pwd;-
373 struct group *grp;-
374-
375 printf (_("uid=%s"), uidtostr (ruid));-
376 pwd = getpwuid (ruid);-
377 if (pwd)
pwdDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • id
FALSEnever evaluated
0-8
378 printf ("(%s)", pwd->pw_name);
executed 8 times by 1 test: printf ("(%s)", pwd->pw_name);
Executed by:
  • id
8
379-
380 printf (_(" gid=%s"), gidtostr (rgid));-
381 grp = getgrgid (rgid);-
382 if (grp)
grpDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • id
FALSEnever evaluated
0-8
383 printf ("(%s)", grp->gr_name);
executed 8 times by 1 test: printf ("(%s)", grp->gr_name);
Executed by:
  • id
8
384-
385 if (euid != ruid)
euid != ruidDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • id
0-8
386 {-
387 printf (_(" euid=%s"), uidtostr (euid));-
388 pwd = getpwuid (euid);-
389 if (pwd)
pwdDescription
TRUEnever evaluated
FALSEnever evaluated
0
390 printf ("(%s)", pwd->pw_name);
never executed: printf ("(%s)", pwd->pw_name);
0
391 }
never executed: end of block
0
392-
393 if (egid != rgid)
egid != rgidDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • id
0-8
394 {-
395 printf (_(" egid=%s"), gidtostr (egid));-
396 grp = getgrgid (egid);-
397 if (grp)
grpDescription
TRUEnever evaluated
FALSEnever evaluated
0
398 printf ("(%s)", grp->gr_name);
never executed: printf ("(%s)", grp->gr_name);
0
399 }
never executed: end of block
0
400-
401 {-
402 gid_t *groups;-
403-
404 gid_t primary_group;-
405 if (username)
usernameDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • id
FALSEevaluated 1 time by 1 test
Evaluated by:
  • id
1-7
406 primary_group = pwd ? pwd->pw_gid : -1;
executed 7 times by 1 test: primary_group = pwd ? pwd->pw_gid : -1;
Executed by:
  • id
pwdDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • id
FALSEnever evaluated
0-7
407 else-
408 primary_group = egid;
executed 1 time by 1 test: primary_group = egid;
Executed by:
  • id
1
409-
410 int n_groups = xgetgroups (username, primary_group, &groups);-
411 if (n_groups < 0)
n_groups < 0Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • id
0-8
412 {-
413 if (username)
usernameDescription
TRUEnever evaluated
FALSEnever evaluated
0
414 error (0, errno, _("failed to get groups for user %s"),
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "failed to get groups for user %s" , 5) , quote (username));
0
415 quote (username));
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "failed to get groups for user %s" , 5) , quote (username));
0
416 else-
417 error (0, errno, _("failed to get groups for the current process"));
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "failed to get groups for the current process" , 5) );
0
418 ok = false;-
419 return;
never executed: return;
0
420 }-
421-
422 if (n_groups > 0)
n_groups > 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • id
FALSEnever evaluated
0-8
423 fputs (_(" groups="), stdout);
executed 8 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " groups=" , 5) , stdout );
Executed by:
  • id
8
424 for (int i = 0; i < n_groups; i++)
i < n_groupsDescription
TRUEevaluated 58 times by 1 test
Evaluated by:
  • id
FALSEevaluated 8 times by 1 test
Evaluated by:
  • id
8-58
425 {-
426 if (i > 0)
i > 0Description
TRUEevaluated 50 times by 1 test
Evaluated by:
  • id
FALSEevaluated 8 times by 1 test
Evaluated by:
  • id
8-50
427 putchar (',');
executed 50 times by 1 test: putchar_unlocked (',');
Executed by:
  • id
50
428 fputs (gidtostr (groups[i]), stdout);-
429 grp = getgrgid (groups[i]);-
430 if (grp)
grpDescription
TRUEevaluated 58 times by 1 test
Evaluated by:
  • id
FALSEnever evaluated
0-58
431 printf ("(%s)", grp->gr_name);
executed 58 times by 1 test: printf ("(%s)", grp->gr_name);
Executed by:
  • id
58
432 }
executed 58 times by 1 test: end of block
Executed by:
  • id
58
433 free (groups);-
434 }-
435-
436 /* POSIX mandates the precise output format, and that it not include-
437 any context=... part, so skip that if POSIXLY_CORRECT is set. */-
438 if (context)
contextDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • id
0-8
439 printf (_(" context=%s"), context);
never executed: printf ( dcgettext (((void *)0), " context=%s" , 5) , context);
0
440}
executed 8 times by 1 test: end of block
Executed by:
  • id
8
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2