| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/groups.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* groups -- print the groups a user is in | - | ||||||||||||
| 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 James Youngman based on id.c and groups.sh, | - | ||||||||||||
| 18 | which were written by Arnold Robbins and David MacKenzie. */ | - | ||||||||||||
| 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 | - | |||||||||||||
| 27 | #include "system.h" | - | ||||||||||||
| 28 | #include "die.h" | - | ||||||||||||
| 29 | #include "group-list.h" | - | ||||||||||||
| 30 | #include "quote.h" | - | ||||||||||||
| 31 | - | |||||||||||||
| 32 | /* The official name of this program (e.g., no 'g' prefix). */ | - | ||||||||||||
| 33 | #define PROGRAM_NAME "groups" | - | ||||||||||||
| 34 | - | |||||||||||||
| 35 | #define AUTHORS \ | - | ||||||||||||
| 36 | proper_name ("David MacKenzie"), \ | - | ||||||||||||
| 37 | proper_name ("James Youngman") | - | ||||||||||||
| 38 | - | |||||||||||||
| 39 | - | |||||||||||||
| 40 | static struct option const longopts[] = | - | ||||||||||||
| 41 | { | - | ||||||||||||
| 42 | {GETOPT_HELP_OPTION_DECL}, | - | ||||||||||||
| 43 | {GETOPT_VERSION_OPTION_DECL}, | - | ||||||||||||
| 44 | {NULL, 0, NULL, 0} | - | ||||||||||||
| 45 | }; | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | void | - | ||||||||||||
| 48 | usage (int status) | - | ||||||||||||
| 49 | { | - | ||||||||||||
| 50 | if (status != EXIT_SUCCESS)
| 3 | ||||||||||||
| 51 | emit_try_help (); executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||
| 52 | else | - | ||||||||||||
| 53 | { | - | ||||||||||||
| 54 | printf (_("Usage: %s [OPTION]... [USERNAME]...\n"), program_name); | - | ||||||||||||
| 55 | fputs (_("\ | - | ||||||||||||
| 56 | Print group memberships for each USERNAME or, if no USERNAME is specified, for\ | - | ||||||||||||
| 57 | \n\ | - | ||||||||||||
| 58 | the current process (which may differ if the groups database has changed).\n"), | - | ||||||||||||
| 59 | stdout); | - | ||||||||||||
| 60 | fputs (HELP_OPTION_DESCRIPTION, stdout); | - | ||||||||||||
| 61 | fputs (VERSION_OPTION_DESCRIPTION, stdout); | - | ||||||||||||
| 62 | emit_ancillary_info (PROGRAM_NAME); | - | ||||||||||||
| 63 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||
| 64 | exit (status); executed 6 times by 1 test: exit (status);Executed by:
| 6 | ||||||||||||
| 65 | } | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | int | - | ||||||||||||
| 68 | main (int argc, char **argv) | - | ||||||||||||
| 69 | { | - | ||||||||||||
| 70 | int optc; | - | ||||||||||||
| 71 | bool ok = true; | - | ||||||||||||
| 72 | gid_t rgid, egid; | - | ||||||||||||
| 73 | uid_t ruid; | - | ||||||||||||
| 74 | - | |||||||||||||
| 75 | initialize_main (&argc, &argv); | - | ||||||||||||
| 76 | set_program_name (argv[0]); | - | ||||||||||||
| 77 | setlocale (LC_ALL, ""); | - | ||||||||||||
| 78 | bindtextdomain (PACKAGE, LOCALEDIR); | - | ||||||||||||
| 79 | textdomain (PACKAGE); | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | atexit (close_stdout); | - | ||||||||||||
| 82 | - | |||||||||||||
| 83 | /* Processing the arguments this way makes groups.c behave differently to | - | ||||||||||||
| 84 | * groups.sh if one of the arguments is "--". | - | ||||||||||||
| 85 | */ | - | ||||||||||||
| 86 | while ((optc = getopt_long (argc, argv, "", longopts, NULL)) != -1)
| 2-14 | ||||||||||||
| 87 | { | - | ||||||||||||
| 88 | switch (optc) | - | ||||||||||||
| 89 | { | - | ||||||||||||
| 90 | case_GETOPT_HELP_CHAR; never executed: break;executed 3 times by 1 test: case GETOPT_HELP_CHAR:Executed by:
| 0-3 | ||||||||||||
| 91 | case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); executed 8 times by 1 test: exit ( 0 );Executed by:
never executed: break;executed 8 times by 1 test: case GETOPT_VERSION_CHAR:Executed by:
| 0-8 | ||||||||||||
| 92 | default: executed 3 times by 1 test: default:Executed by:
| 3 | ||||||||||||
| 93 | usage (EXIT_FAILURE); | - | ||||||||||||
| 94 | } never executed: end of block | 0 | ||||||||||||
| 95 | } | - | ||||||||||||
| 96 | - | |||||||||||||
| 97 | if (optind == argc)
| 0-2 | ||||||||||||
| 98 | { | - | ||||||||||||
| 99 | /* No arguments. Divulge the details of the current process. */ | - | ||||||||||||
| 100 | uid_t NO_UID = -1; | - | ||||||||||||
| 101 | gid_t NO_GID = -1; | - | ||||||||||||
| 102 | - | |||||||||||||
| 103 | errno = 0; | - | ||||||||||||
| 104 | ruid = getuid (); | - | ||||||||||||
| 105 | if (ruid == NO_UID && errno)
| 0 | ||||||||||||
| 106 | 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 | ||||||||||||
| 107 | - | |||||||||||||
| 108 | errno = 0; | - | ||||||||||||
| 109 | egid = getegid (); | - | ||||||||||||
| 110 | if (egid == NO_GID && errno)
| 0 | ||||||||||||
| 111 | 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 | ||||||||||||
| 112 | - | |||||||||||||
| 113 | errno = 0; | - | ||||||||||||
| 114 | rgid = getgid (); | - | ||||||||||||
| 115 | if (rgid == NO_GID && errno)
| 0 | ||||||||||||
| 116 | 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 | ||||||||||||
| 117 | - | |||||||||||||
| 118 | if (!print_group_list (NULL, ruid, rgid, egid, true, ' '))
| 0 | ||||||||||||
| 119 | ok = false; never executed: ok = 0 ; | 0 | ||||||||||||
| 120 | putchar ('\n'); | - | ||||||||||||
| 121 | } never executed: end of block | 0 | ||||||||||||
| 122 | else | - | ||||||||||||
| 123 | { | - | ||||||||||||
| 124 | /* At least one argument. Divulge the details of the specified users. */ | - | ||||||||||||
| 125 | for ( ; optind < argc; optind++)
| 2-4 | ||||||||||||
| 126 | { | - | ||||||||||||
| 127 | struct passwd *pwd = getpwnam (argv[optind]); | - | ||||||||||||
| 128 | if (pwd == NULL)
| 0-4 | ||||||||||||
| 129 | { | - | ||||||||||||
| 130 | error (0, 0, _("%s: no such user"), quote (argv[optind])); | - | ||||||||||||
| 131 | ok = false; | - | ||||||||||||
| 132 | continue; executed 4 times by 1 test: continue;Executed by:
| 4 | ||||||||||||
| 133 | } | - | ||||||||||||
| 134 | ruid = pwd->pw_uid; | - | ||||||||||||
| 135 | rgid = egid = pwd->pw_gid; | - | ||||||||||||
| 136 | - | |||||||||||||
| 137 | printf ("%s : ", argv[optind]); | - | ||||||||||||
| 138 | if (!print_group_list (argv[optind], ruid, rgid, egid, true, ' '))
| 0 | ||||||||||||
| 139 | ok = false; never executed: ok = 0 ; | 0 | ||||||||||||
| 140 | putchar ('\n'); | - | ||||||||||||
| 141 | } never executed: end of block | 0 | ||||||||||||
| 142 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 143 | - | |||||||||||||
| 144 | return ok ? EXIT_SUCCESS : EXIT_FAILURE; executed 2 times by 1 test: return ok ? 0 : 1 ;Executed by:
| 2 | ||||||||||||
| 145 | } | - | ||||||||||||
| Source code | Switch to Preprocessed file |