[51920] trunk/base/src/port1.0

jmr at macports.org jmr at macports.org
Sat Jun 6 05:43:53 PDT 2009


Revision: 51920
          http://trac.macports.org/changeset/51920
Author:   jmr at macports.org
Date:     2009-06-06 05:43:49 -0700 (Sat, 06 Jun 2009)
Log Message:
-----------
more fixes and cleanups for gsoc08-privileges code

Modified Paths:
--------------
    trunk/base/src/port1.0/portdestroot.tcl
    trunk/base/src/port1.0/portmain.tcl
    trunk/base/src/port1.0/portutil.tcl

Modified: trunk/base/src/port1.0/portdestroot.tcl
===================================================================
--- trunk/base/src/port1.0/portdestroot.tcl	2009-06-06 11:50:53 UTC (rev 51919)
+++ trunk/base/src/port1.0/portdestroot.tcl	2009-06-06 12:43:49 UTC (rev 51920)
@@ -106,9 +106,7 @@
     }
 
     if { [tbool destroot.asroot] && [getuid] != 0 } {
-        global errorisprivileges
-        set errorisprivileges yes
-        return -code error "You can not run this port without elevated privileges. You need to re-run with 'sudo port'.";
+        return -code error "You can not run this port without root privileges. You need to re-run with 'sudo port'.";
     }
 
     if {[info exists usealtworkpath] && $usealtworkpath == "yes"} {

Modified: trunk/base/src/port1.0/portmain.tcl
===================================================================
--- trunk/base/src/port1.0/portmain.tcl	2009-06-06 11:50:53 UTC (rev 51919)
+++ trunk/base/src/port1.0/portmain.tcl	2009-06-06 12:43:49 UTC (rev 51920)
@@ -129,6 +129,10 @@
     }
 }
 
+# Record initial euid/egid
+set euid [geteuid]
+set egid [getegid]
+
 proc portmain::main {args} {
     return 0
 }

Modified: trunk/base/src/port1.0/portutil.tcl
===================================================================
--- trunk/base/src/port1.0/portutil.tcl	2009-06-06 11:50:53 UTC (rev 51919)
+++ trunk/base/src/port1.0/portutil.tcl	2009-06-06 12:43:49 UTC (rev 51920)
@@ -829,7 +829,6 @@
 # reinplace
 # Provides "sed in place" functionality
 proc reinplace {args}  {
-    global euid macportsuser
 
     set extended 0
     while 1 {
@@ -1208,7 +1207,7 @@
 set ports_dry_last_skipped ""
 
 proc target_run {ditem} {
-    global target_state_fd workpath ports_trace PortInfo ports_dryrun ports_dry_last_skipped errorisprivileges
+    global target_state_fd workpath ports_trace PortInfo ports_dryrun ports_dry_last_skipped
     set portname [option name]
     set result 0
     set skipped 0
@@ -1376,13 +1375,9 @@
             write_statefile target $targetname $target_state_fd
             }
         } else {
-            if {$errorisprivileges != "yes"} {
-                global errorInfo
-                ui_error "Target $targetname returned: $errstr"
-                ui_debug "Backtrace: $errorInfo"
-            } else {
-                ui_msg "Target $targetname returned: $errstr"
-            }
+            global errorInfo
+            ui_error "Target $targetname returned: $errstr"
+            ui_debug "Backtrace: $errorInfo"
             set result 1
         }
 
@@ -1432,9 +1427,8 @@
 
 
 proc eval_targets {target} {
-    global targets target_state_fd name version revision portvariants ports_dryrun user_options errorisprivileges
+    global targets target_state_fd name version revision portvariants ports_dryrun user_options
     set dlist $targets
-    set errorisprivileges "no"
 
     # the statefile will likely be autocleaned away after install,
     # so special-case ignore already-completed install and activate
@@ -1486,12 +1480,6 @@
         set result 0
     }
 
-    # start gsoc08-privileges
-    if { $result == 1 && $errorisprivileges == "yes" } {
-        set result 2
-    }
-    # end gsoc08-privileges
-
     return $result
 }
 
@@ -1502,16 +1490,16 @@
     global altprefix usealtworkpath env applications_dir portbuildpath distpath
 
     # start gsoc08-privileges
-
-    # de-escalate privileges - only run if MacPorts was started with sudo
-    dropPrivileges
-
     if { ![file exists $workpath] } {
         if {[catch {set result [file mkdir $workpath]} result]} {
             global errorInfo
             ui_debug "mkdir $workpath: $errorInfo"
         }
     }
+    chownAsRoot $workpath
+    
+    # de-escalate privileges - only run if MacPorts was started with sudo
+    dropPrivileges
 
     # if unable to write to workpath, implies running without either root privileges
     # or a shared directory owned by the group so use ~/.macports
@@ -1522,7 +1510,7 @@
 
         if { $userid !=0 } {
             ui_msg "MacPorts running without privileges.\
-                    You may be prompted for your sudo password in order to complete certain actions (eg install)."
+                    You may be unable to complete certain actions (eg install)."
         }
 
         # set global variable indicating to other functions to use ~/.macports as well
@@ -2405,7 +2393,7 @@
 #
 # @param action the action for which privileges are being elevated
 proc elevateToRoot {action} {
-    global euid egid macportsuser errorisprivileges
+    global euid egid macportsuser
 
     if { [getuid] == 0 && [geteuid] == [name_to_uid "$macportsuser"] } {
     # if started with sudo but have dropped the privileges
@@ -2416,8 +2404,7 @@
     }
 
     if { [getuid] != 0 } {
-        set errorisprivileges yes
-        return -code error "port requires root privileges for this action and needs you to type your password for sudo.";
+        return -code error "MacPorts requires root privileges for this action";
     }
 }
 
@@ -2428,8 +2415,6 @@
     global euid egid macportsuser workpath
     if { [geteuid] == 0 } {
         if { [catch {
-                set euid [geteuid]
-                set egid [getegid]
                 ui_debug "changing euid/egid - current euid: $euid - current egid: $egid"
 
                 #seteuid [name_to_uid [file attributes $workpath -owner]]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20090606/755bcb45/attachment.html>


More information about the macports-changes mailing list