New Ticket     Tickets     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Changeset 81369


Ignore:
Timestamp:
07/29/11 17:35:11 (4 years ago)
Author:
fotanus@…
Message:

Implemented multiple granularity for whitelist

now it works as files and folders.
also, the code was cleaned up

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/gsoc11-post-destroot/base/src/port1.0/portcheckdestroot.tcl

    r80963 r81369  
    6969            #is from the correct type 
    7070            if { $bin } { 
    71                 if { [binary? $item] } { 
    72                     lappend ret $item 
    73                 } 
     71                lappend ret $item 
    7472            } else { 
    7573                lappend ret $item 
     
    219217    } 
    220218 
    221     # Check for dynamic links that aren't in the dependency list 
    222     proc portcheckdestroot::checkdestroot_libs {} { 
    223         global destroot prefix UI_PREFIX subport 
    224         ui_notice "$UI_PREFIX Checking for wrong dynamic links" 
    225  
    226         #Folders that don't need to be alerted if not on dependencies. 
    227         #TODO: Compile whitelist folders 
    228         set dep_whitelist {/usr/lib/ /System/Library/ /lib/} 
    229  
    230         #Get dependencies files list. 
    231         set dep_files {} 
    232         foreach dep [get_dependencies] { 
    233             lappend dep_files [file tail [registry_port_registered $dep]] 
    234         } 
    235         set self_files [bin_list $destroot$prefix] 
    236         set dep_files [concat $dep_files $self_files] 
    237  
    238  
    239         #Get package files 
    240         foreach file [files_list $destroot] { 
    241             foreach file_lib [list_dlibs $file] { 
    242             if { ! [regexp $file_lib $file] } { 
     219# Check for dynamic links that aren't in the dependency list 
     220proc portcheckdestroot::checkdestroot_libs {} { 
     221    global destroot prefix UI_PREFIX subport 
     222    ui_notice "$UI_PREFIX Checking for wrong dynamic links" 
     223 
     224    #Folders that don't need to be alerted if not on dependencies. 
     225    set files_whitelist {libSystem.B.dylib} 
     226    set folders_whitelist {/System/Library} 
     227 
     228    #Get dependencies files list. 
     229    set dep_files {} 
     230    foreach dep [get_dependencies] { 
     231        lappend dep_files [file tail [registry_port_registered $dep]] 
     232    } 
     233    set self_files [bin_list $destroot$prefix] 
     234    set dep_files [concat $dep_files $self_files] 
     235 
     236 
     237    #Get package files 
     238    foreach file [files_list $destroot] { 
     239        foreach file_lib [list_dlibs $file] { 
     240            set valid_lib 0 
     241            if { [regexp $file_lib $file] } { 
     242                set valid_lib 1 
     243            } 
     244            if { ! $valid_lib } { 
    243245                if { [lsearch $dep_files $file_lib] != -1 } { 
     246                    set valid_lib 1 
    244247                    ui_debug "$file_lib binary dependency is met" 
    245                 } else { 
    246                     #match file folder agains whitelist 
    247                     set found 0 
    248                     foreach dep $dep_whitelist { 
    249                         if { [regexp "^$dep" [regsub $prefix $file_lib ""]] } { 
    250                             set found 1 
    251                             break 
    252                         } 
    253                     } 
    254                     if { $found } { 
     248                } 
     249            } 
     250            if { ! $valid_lib } { 
     251                foreach dep_file $files_whitelist { 
     252                    if { [regexp $dep_file [regsub ".*/" $file_lib ""]] } { 
    255253                        ui_debug "$file_lib binary dependency folder is on whitelist" 
    256                     } else { 
    257                         return -code error "$file_lib binary dependencies are NOT met" 
    258                     } 
    259                 } 
    260             } 
    261         } 
    262     } 
    263 } 
    264  
    265 #For the given archs, check if the files from destroot are compatible 
    266 proc portcheckdestroot::checkdestroot_arches { archs } { 
    267     global destroot 
    268     foreach file [files_list $destroot] { 
    269         set file_archs [list_archs $file] 
    270         foreach arch $file_archs { 
    271             if { [lsearch $arch $archs] == -1 } { 
    272                 return -code error "$file supports the arch $arch, and should not" 
    273             } 
    274         } 
    275     } 
    276 } 
    277  
    278 # Recover the arches from a file, from it's lipo output. For internal use only. 
    279 proc portcheckdestroot::get_lipo_arches { file } { 
    280     if { [ catch { set lipo_output [exec lipo -info $file 2>/dev/null] } ] } { 
    281         return "ignore" 
    282     } 
    283     return [regsub "Architectures in the.*are:" $lipo_output ""] 
    284 } 
    285  
    286 # Recover the arches from a file, from it's lipo output. For internal use only. 
    287 proc portcheckdestroot::get_otool_libs { file } { 
    288     if { [ catch { set output [exec -keepnewline otool -L $file 2>/dev/null] } ] } { 
    289         return "ignore" 
    290     } 
    291     return [split $output "\n"] 
     254                        set valid_lib 1 
     255                        break 
     256                    } 
     257                } 
     258            } 
     259            if { ! $valid_lib } { 
     260                foreach dep_folder $folders_whitelist { 
     261                    if { [regexp "^$dep" [regsub $prefix $file_lib ""]] } { 
     262                        ui_debug "$file_lib binary dependency folder is on whitelist" 
     263                        set valid_lib 1 
     264                        break 
     265                    } 
     266                } 
     267            } 
     268            if { ! $valid_lib } { 
     269                   return -code error "$file_lib binary dependencies are NOT met" 
     270            } 
     271        } 
     272    } 
    292273} 
    293274 
    294275# Check for arch constraints 
    295276proc portcheckdestroot::checkdestroot_arch {} { 
    296     global UI_PREFIX 
     277    global UI_PREFIX destroot 
    297278    ui_notice "$UI_PREFIX Checking for archs" 
    298279    set archs [get_canonical_archs] 
    299280    if { "archs" != "noarch" } { 
    300         checkdestroot_arches $archs 
     281        foreach file [files_list $destroot] { 
     282            set file_archs [list_archs $file] 
     283            foreach arch $file_archs { 
     284                if { [lsearch $arch $archs] == -1 } { 
     285                    return -code error "$file supports the arch $arch, and should not" 
     286                } 
     287            } 
     288        } 
    301289    } 
    302290} 
Note: See TracChangeset for help on using the changeset viewer.