]>
Commit | Line | Data |
---|---|---|
581c785b | 1 | /* Copyright (C) 2012-2022 Free Software Foundation, Inc. |
84b3fd84 FW |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library 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 GNU | |
12 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
15 | License along with the GNU C Library; if not, see | |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
84b3fd84 FW |
17 | |
18 | /* Test that secure_getenv works by invoking the test as a SGID | |
19 | program with a group ID from the supplementary group list. This | |
20 | test can fail spuriously if the user is not a member of a suitable | |
edb3cb88 | 21 | supplementary group. */ |
84b3fd84 FW |
22 | |
23 | #include <errno.h> | |
24 | #include <fcntl.h> | |
25 | #include <stdlib.h> | |
26 | #include <stdint.h> | |
27 | #include <stdio.h> | |
28 | #include <string.h> | |
29 | #include <sys/stat.h> | |
30 | #include <sys/wait.h> | |
31 | #include <unistd.h> | |
32 | ||
716a3bdc | 33 | #include <support/check.h> |
c23de0aa | 34 | #include <support/support.h> |
716a3bdc | 35 | #include <support/capture_subprocess.h> |
c23de0aa FW |
36 | #include <support/test-driver.h> |
37 | ||
84b3fd84 | 38 | static char MAGIC_ARGUMENT[] = "run-actual-test"; |
84b3fd84 FW |
39 | |
40 | static int | |
41 | do_test (void) | |
42 | { | |
43 | if (getenv ("PATH") == NULL) | |
44 | { | |
2bc13872 | 45 | printf ("PATH not set\n"); |
84b3fd84 FW |
46 | exit (1); |
47 | } | |
48 | if (secure_getenv ("PATH") == NULL) | |
49 | { | |
2bc13872 | 50 | printf ("PATH not set according to secure_getenv\n"); |
84b3fd84 FW |
51 | exit (1); |
52 | } | |
53 | if (strcmp (getenv ("PATH"), secure_getenv ("PATH")) != 0) | |
54 | { | |
2bc13872 FW |
55 | printf ("PATH mismatch (%s, %s)\n", |
56 | getenv ("PATH"), secure_getenv ("PATH")); | |
84b3fd84 FW |
57 | exit (1); |
58 | } | |
59 | ||
716a3bdc SP |
60 | int status = support_capture_subprogram_self_sgid (MAGIC_ARGUMENT); |
61 | ||
62 | if (WEXITSTATUS (status) == EXIT_UNSUPPORTED) | |
63 | return EXIT_UNSUPPORTED; | |
64 | ||
65 | if (!WIFEXITED (status)) | |
66 | FAIL_EXIT1 ("Unexpected exit status %d from child process\n", status); | |
67 | ||
68 | return 0; | |
84b3fd84 FW |
69 | } |
70 | ||
71 | static void | |
72 | alternative_main (int argc, char **argv) | |
73 | { | |
74 | if (argc == 2 && strcmp (argv[1], MAGIC_ARGUMENT) == 0) | |
75 | { | |
76 | if (getgid () == getegid ()) | |
716a3bdc SP |
77 | /* This can happen if the file system is mounted nosuid. */ |
78 | FAIL_UNSUPPORTED ("SGID failed: GID and EGID match (%jd)\n", | |
79 | (intmax_t) getgid ()); | |
84b3fd84 | 80 | if (getenv ("PATH") == NULL) |
716a3bdc | 81 | FAIL_EXIT (3, "PATH variable not present\n"); |
84b3fd84 | 82 | if (secure_getenv ("PATH") != NULL) |
716a3bdc SP |
83 | FAIL_EXIT (4, "PATH variable not filtered out\n"); |
84 | ||
85 | exit (EXIT_SUCCESS); | |
84b3fd84 FW |
86 | } |
87 | } | |
88 | ||
c23de0aa FW |
89 | #define PREPARE alternative_main |
90 | #include <support/test-driver.c> |