File tree Expand file tree Collapse file tree 3 files changed +11
-18
lines changed Expand file tree Collapse file tree 3 files changed +11
-18
lines changed Original file line number Diff line number Diff line change @@ -30,12 +30,13 @@ that you deem safe.
3030As explained, Git only allows you to access repositories owned by
3131yourself, i.e. the user who is running Git, by default. When Git
3232is running as 'root' in a non Windows platform that provides sudo,
33- however, git checks the SUDO_UID environment variable that sudo creates
34- and will allow access to the uid recorded as its value instead.
33+ however, git checks the SUDO_UID environment variable that sudo creates
34+ and will allow access to the uid recorded as its value in addition to
35+ the id from 'root'.
3536This is to make it easy to perform a common sequence during installation
3637"make && sudo make install". A git process running under 'sudo' runs as
3738'root' but the 'sudo' command exports the environment variable to record
3839which id the original user has.
3940If that is not what you would prefer and want git to only trust
40- repositories that are owned by root instead, then you must remove
41+ repositories that are owned by root instead, then you can remove
4142the `SUDO_UID` variable from root's environment before invoking git.
Original file line number Diff line number Diff line change @@ -497,7 +497,12 @@ static inline int is_path_owned_by_current_uid(const char *path)
497497
498498 euid = geteuid ();
499499 if (euid == ROOT_UID )
500- extract_id_from_env ("SUDO_UID" , & euid );
500+ {
501+ if (st .st_uid == ROOT_UID )
502+ return 1 ;
503+ else
504+ extract_id_from_env ("SUDO_UID" , & euid );
505+ }
501506
502507 return st .st_uid == euid ;
503508}
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ test_expect_success 'can access if addressed explicitly' '
6868 )
6969'
7070
71- test_expect_failure SUDO ' can access with sudo if root' '
71+ test_expect_success SUDO ' can access with sudo if root' '
7272 (
7373 cd root/p &&
7474 sudo git status
@@ -85,19 +85,6 @@ test_expect_success SUDO 'can access with sudo if root by removing SUDO_UID' '
8585 )
8686'
8787
88- test_lazy_prereq SUDO_SUDO '
89- sudo sudo id -u >u &&
90- id -u root >r &&
91- test_cmp u r
92- '
93-
94- test_expect_success SUDO_SUDO ' can access with sudo abusing SUDO_UID' '
95- (
96- cd root/p &&
97- sudo sudo git status
98- )
99- '
100-
10188# this MUST be always the last test
10289test_expect_success SUDO ' cleanup' '
10390 sudo rm -rf root
You can’t perform that action at this time.
0 commit comments