[38144] branches/gsoc08-privileges/base/src/port1.0
pmagrath at macports.org
pmagrath at macports.org
Tue Jul 8 13:35:35 PDT 2008
Revision: 38144
http://trac.macosforge.org/projects/macports/changeset/38144
Author: pmagrath at macports.org
Date: 2008-07-08 13:35:34 -0700 (Tue, 08 Jul 2008)
Log Message:
-----------
Added a new procedure for recursive chowning of directories. Inserted calls to this procedure where necessary.
Modified Paths:
--------------
branches/gsoc08-privileges/base/src/port1.0/portextract.tcl
branches/gsoc08-privileges/base/src/port1.0/portutil.tcl
Modified: branches/gsoc08-privileges/base/src/port1.0/portextract.tcl
===================================================================
--- branches/gsoc08-privileges/base/src/port1.0/portextract.tcl 2008-07-08 19:52:43 UTC (rev 38143)
+++ branches/gsoc08-privileges/base/src/port1.0/portextract.tcl 2008-07-08 20:35:34 UTC (rev 38144)
@@ -93,7 +93,6 @@
proc extract_main {args} {
global UI_PREFIX euid egid worksrcpath macportsuser
- global filespath
if {![exists distfiles] && ![exists extract.only]} {
# nothing to do
@@ -102,11 +101,7 @@
foreach distfile [option extract.only] {
ui_info "$UI_PREFIX [format [msgcat::mc "Extracting %s"] $distfile]"
- if {[file exists $filespath/$distfile]} {
- option extract.args "$filespath/$distfile"
- } else {
- option extract.args "[option distpath]/$distfile"
- }
+ option extract.args "[option distpath]/$distfile"
if {[catch {command_exec extract} result]} {
return -code error "$result"
}
@@ -116,11 +111,14 @@
# if started with sudo but have dropped the privileges
seteuid $euid
ui_debug "euid changed to: [geteuid]"
- file attributes "${worksrcpath}" -owner [name_to_uid "$macportsuser"]
+ chown ${worksrcpath} ${macportsuser}
ui_debug "chowned $worksrcpath to $macportsuser"
seteuid [name_to_uid "$macportsuser"]
ui_debug "euid changed to: [geteuid]"
+ } else {
+ ui_debug "no need to chown $worksrcpath. uid=[getuid]. euid=[geteuid]."
}
+
# end gsoc08-privileges
}
Modified: branches/gsoc08-privileges/base/src/port1.0/portutil.tcl
===================================================================
--- branches/gsoc08-privileges/base/src/port1.0/portutil.tcl 2008-07-08 19:52:43 UTC (rev 38143)
+++ branches/gsoc08-privileges/base/src/port1.0/portutil.tcl 2008-07-08 20:35:34 UTC (rev 38144)
@@ -717,6 +717,8 @@
# reinplace
# Provides "sed in place" functionality
proc reinplace {args} {
+ global euid macportsuser
+
set extended 0
while 1 {
set arg [lindex $args 0]
@@ -776,6 +778,21 @@
close $tmpfd
+ # start gsoc08-privileges
+ if { [getuid] == 0 && [geteuid] == [name_to_uid "$macportsuser"] } {
+ # if started with sudo but have dropped the privileges
+ seteuid $euid
+ ui_debug "euid changed to: [geteuid]"
+ chown $file ${macportsuser}
+ ui_debug "chowned $file to $macportsuser"
+ seteuid [name_to_uid "$macportsuser"]
+ ui_debug "euid changed to: [geteuid]"
+ } else {
+ ui_debug "no need to chown $file. uid=[getuid]. euid=[geteuid]."
+ }
+
+ # end gsoc08-privileges
+
set attributes [file attributes $file]
# We need to overwrite this file
if {[catch {file attributes $file -permissions u+w} error]} {
@@ -2247,3 +2264,18 @@
return $str
}
+##
+# Recusively chown the given file or directory to the specified user.
+#
+# @param path the file/directory to be chowned
+# @param user the user to chown file to
+proc chown {path user} {
+ file attributes $path -owner [name_to_uid "$user"]
+
+ if {[file isdirectory $path]} {
+ foreach g [glob [file join $path *]] {
+ chown $g $user
+ }
+ }
+}
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080708/68b8e1e9/attachment.html
More information about the macports-changes
mailing list