<pre style='margin:0'>
Clemens Lang (neverpanic) pushed a commit to branch release-2.6
in repository macports-base.
</pre>
<p><a href="https://github.com/macports/macports-base/commit/fcb9cd207563a64bdc841ac8f97b044fcbeb0e46">https://github.com/macports/macports-base/commit/fcb9cd207563a64bdc841ac8f97b044fcbeb0e46</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit fcb9cd207563a64bdc841ac8f97b044fcbeb0e46
</span>Author: Clemens Lang <cal@macports.org>
AuthorDate: Fri Jun 19 13:16:42 2020 +0200
<span style='display:block; white-space:pre;color:#404040;'> port1.0: Ensure adduser drops privs in all cases
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> adduser and addgroup (invoked by the add_users statement in
</span><span style='display:block; white-space:pre;color:#404040;'> handle_add_users) elevates its privileges, but does not always drop them
</span><span style='display:block; white-space:pre;color:#404040;'> again. Specifically, this could happen if a user or group already
</span><span style='display:block; white-space:pre;color:#404040;'> existed, in which case adduser did elevate to root, but not drop back to
</span><span style='display:block; white-space:pre;color:#404040;'> the macportsuser again.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> This can cause files to be created with incorrect permissions, which can
</span><span style='display:block; white-space:pre;color:#404040;'> then cause permissions problems in subsequent phases.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> Closes: https://trac.macports.org/ticket/50918
</span><span style='display:block; white-space:pre;color:#404040;'> (cherry picked from commit 9dbfd65955a277d0c798355f0aac735a9d46a301)
</span>---
src/port1.0/portutil.tcl | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/port1.0/portutil.tcl b/src/port1.0/portutil.tcl
</span><span style='display:block; white-space:pre;color:#808080;'>index 65dd3fc8..e01956f9 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/port1.0/portutil.tcl
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/port1.0/portutil.tcl
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2302,9 +2302,6 @@ proc adduser {name args} {
</span> ui_warn "adduser only works when running as root."
ui_warn "The requested user '$name' was not created."
return
<span style='display:block; white-space:pre;background:#ffe0e0;'>- } elseif {[geteuid] != 0} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- seteuid 0; setegid 0
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set escalated 1
</span> }
set passwd {*}
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2325,6 +2322,11 @@ proc adduser {name args} {
</span> return
}
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[geteuid] != 0} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ seteuid 0; setegid 0
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set escalated 1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> if {${os.platform} eq "darwin"} {
set dscl [findBinary dscl $portutil::autoconf::dscl_path]
set failed? 0
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2391,6 +2393,11 @@ proc adduser {name args} {
</span> }
}
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ # drop privileges if they were escalated before
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[info exists escalated]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ dropPrivileges
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> # and raise an error to abort
error "dscl failed to create required user $name."
}
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2413,9 +2420,6 @@ proc addgroup {name args} {
</span> ui_warn "addgroup only works when running as root."
ui_warn "The requested group '$name' was not created."
return
<span style='display:block; white-space:pre;background:#ffe0e0;'>- } elseif {[geteuid] != 0} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- seteuid 0; setegid 0
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- set escalated 1
</span> }
set gid [nextgid]
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2434,6 +2438,11 @@ proc addgroup {name args} {
</span> return
}
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[geteuid] != 0} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ seteuid 0; setegid 0
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set escalated 1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> if {${os.platform} eq "darwin"} {
set dscl [findBinary dscl $portutil::autoconf::dscl_path]
set failed? 0
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2490,6 +2499,10 @@ proc addgroup {name args} {
</span> }
}
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ if {[info exists escalated]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ dropPrivileges
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> # and raise an error to abort
error "dscl failed to create required group $name."
}
</pre><pre style='margin:0'>
</pre>