Commit add4696
committed
cvd_refresh_groups: Use getpwuid(getuid()) instead of getlogin_r
cvd_refresh_groups was using getlogin_r to determine the username for
initgroups. However, when running under sudo -u <user>, getlogin_r
still returns the original login user of the terminal, not the target
user of sudo.
The test scripts used by our Kokoro and GitHub actions workflows create
a test user and use `sudo -u` to run commands as that test user.
This caused initgroups to be called with the wrong user, refreshing the
process groups to those of the original user (which typically lack
cvdnetwork group), leading to assemble_cvd failing with "Operation not
permitted" when trying to set group ownership of directories.
Using getpwuid(getuid()) correctly resolves the username of the running
user based on the real UID, which is preserved under sudo.
Assisted-by: Jetski <jetski@google.com>
Bug: b/5109307371 parent a070843 commit add4696
1 file changed
Lines changed: 7 additions & 5 deletions
Lines changed: 7 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | | - | |
44 | | - | |
45 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | | - | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
0 commit comments