# @(#) sysadmin-moveuser.tcl ############################################################################## # # turn on "Applications" menu # .title.apps configure -state normal .title.apps.menu add cascade \ -label "Move files to User" \ -menu [set menu .title.apps.menu.moveuser] menu $menu $menu add command \ -label "uid to user" \ -command "sysadmin_moveuser_uid .uid" $menu add command \ -label "user to user" \ -command "sysadmin_moveuser_user .user" ############################################################################## # Help Screens set sysadmin_help(uid) \ "Enter a numeric user id number (uid). All of the mounted file systems will be searched for entries with \ this user id and the ownership will be replaced by the user you select from within the password file." set sysadmin_help(password) \ "Select a user from the given list." # Global Storage areas set sysadmin_uid "" set sysadmin_passwd "" ############################################################################## # Name : sysadmin_moveuser_uid # Purpose : enter a uid to search for ownership # Input : # w : name of the top-level widget # Output : # History : # 1995-04-26 briank@kimbro.com created ############################################################################## proc sysadmin_moveuser_uid { w } { global sysadmin_uid global sysadmin_passwd sysadmin_proc_mkmsg "" set sysadmin_uid "" sysadmin_get_uid $w tkwait window $w if { $sysadmin_uid == ""} { puts "Uid=$sysadmin_uid" return } set sysadmin_passwd "" sysadmin_get_user "Select user to map" $w tkwait window $w if { $sysadmin_passwd == ""} { puts "User=$sysadmin_passwd" } puts "Move files owned by uid $sysadmin_uid" puts "To user $sysadmin_passwd" # Note # This is not according to specifications for the problem. # BUT # It does demonstrate that the problem can easily be solved # by changing the find statement to do 'chown' instead of 'ls'. set fn "/tmp/x1" set command {find / -user $sysadmin_uid -mount -exec ls -l \{\} \;} puts stdout "[llength $command] Command=$command" catch {eval exec $command ">$fn"} x puts stdout "Results=$x" # set fh [open {|find / -user $sysadmin_uid -mount -exec ls -l \{\} \; } r ] # set fh [open |$command r ] # puts stdout [pid $fh] # while {! [eof $fh]} { # gets $fh text # puts stdout ">> $text <" # } # close $fh } ############################################################################## # Name : sysadmin_moveuser_user # Purpose : select 2 password user # Input : # w : name of the top-level widget # Output : - uid # History : # 1995-04-26 briank@kimbro.com created ############################################################################## proc sysadmin_moveuser_user { w } { global sysadmin_uid set sysadmin_uid "" sysadmin_proc_mkmsg "" if { $sysadmin_uid == ""} { # puts "Uid=$sysadmin_uid" return } sysadmin_get_user "Select user to map" } ############################################################################## # Name : sysadmin_get_user # Purpose : get a user form the password file # Input : # title : # Output : # History : # 1995-04-26 briank@kimbro.com created ############################################################################## proc sysadmin_get_user { title w } { global sysadmin_passwd global passwd_count global passwd global passwd_x set passwd_count 0 set fh [open /etc/passwd r] while {! [eof $fh]} { gets $fh text if {$text == ""} {break} set text [split $text ":"] set text [lreplace $text 1 1] set text [lreplace $text 2 2] set text [lreplace $text 3 4] set passwd($passwd_count) \ [format "%-10s %6d %s" [lindex $text 0] \ [lindex $text 1] [lindex $text 2]] incr passwd_count } close $fh sysadmin_proc_mkmsg "" catch { destroy $w } toplevel $w wm title $w $title frame $w.t \ -relief flat \ -borderwidth 10 pack append $w.t \ [label $w.t.t \ -text "Current users in the password file" \ -borderwidth 2] \ {top} \ [listbox $w.t.lb \ -borderwidth 2 \ -relief sunken \ -geometry 60x20 \ -yscrollcommand "$w.t.sb set"] \ {left expand fill} \ [scrollbar $w.t.sb \ -relief sunken \ -width 15 \ -command "$w.t.lb yview"] \ {right fill} frame $w.b \ -borderwidth 1 pack append $w.b \ [button $w.b.select \ -command "sysadmin_callback_passwd; destroy $w" \ -text Select] \ {left expand padx 20 pady 5} \ [button $w.b.help \ -command "sysadmin_callback_help {Help Selecting a password entry} password" \ -text Help] \ {left expand padx 20 pady 5} \ [button $w.b.cancel \ -command "destroy $w" \ -text Cancel] \ {left expand padx 20 pady 5} pack append $w \ $w.t {top expand filly} \ $w.b {bottom fill} bind $w.t.lb "sysadmin_select_passwd $w.t.lb %y" for {set ix 0} {$ix < $passwd_count} {incr ix} { set pos [expr $ix*204] set passwd_x($ix,text) \ [$w.t.lb insert end $passwd($ix)] } $w.t.sb set $passwd_count 20 0 20 } ############################################################################## # Name : sysadmin_callback_passwd # Purpose : accept the entered uid # Input : # w : name of the top-level widget # Output : - uid # History : # 1995-05-01 briank@kimbro.com created ############################################################################## proc sysadmin_callback_passwd { } { global sysadmin_passwd set text [split $sysadmin_passwd " "] set sysadmin_passwd [lreplace $text 1 end] # puts stdout "Passwd=$sysadmin_passwd" } ############################################################################## # Name : sysadmin_select_passwd # Purpose : accept the entered uid # Input : # w : name of the top-level widget # Output : - uid # History : # 1995-05-01 briank@kimbro.com created ############################################################################## proc sysadmin_select_passwd {win pos} { global sysadmin_passwd set index [$win nearest $pos] set sysadmin_passwd [$win get $index] $win select clear $win select from $index } ############################################################################## # Name : sysadmin_moveuser_uid # Purpose : enter a uid to search for ownership # Input : # w : name of the top-level widget # Output : - uid # History : # 1995-04-26 briank@kimbro.com created ############################################################################## proc sysadmin_get_uid { w } { global sysadmin_uid sysadmin_proc_mkmsg "" catch { destroy $w } toplevel $w wm title $w "enter a uid" # wm iconname $w "select" # wm iconbitmap $w @$snmptcl_icon frame $w.t \ -borderwidth 10 label $w.t.l \ -text "Uid: " $w.t.l configure \ -anchor e \ -width 11 # Entry field pack append $w.t \ $w.t.l {left} \ [entry $w.t.e \ -borderwidth 2 \ -font -*-courier-medium-r-normal-*-140-* \ -relief sunken \ -textvariable sysadmin_uid \ -width 10] \ {left} # Bottom Buttons frame $w.b \ -borderwidth 5 pack append $w.b \ [button $w.b.select \ -command "sysadmin_callback_uid; destroy $w" \ -text Select] \ {left expand padx 20 pady 5} \ [button $w.b.help \ -command "sysadmin_callback_help {Help Selecting a Management Context} uid" \ -text Help] \ {left expand padx 20 pady 5} \ [button $w.b.cancel \ -command "destroy $w" \ -text Cancel] \ {left expand padx 20 pady 5} pack append $w \ $w.t {top expand filly} \ $w.b {right fill} bind $w.b.select "sysadmin_callback_uid; destroy $w" focus $w.t.e } ############################################################################## # Name : sysadmin_callback_uid # Purpose : accept the entered uid # Input : # w : name of the top-level widget # Output : - uid # History : # 1995-04-26 briank@kimbro.com created ############################################################################## proc sysadmin_callback_uid { } { global sysadmin_uid # puts stdout "Uid to move from = $sysadmin_uid" } ############################################################################## ### END