Changeset 479

Show
Ignore:
Timestamp:
05/22/08 11:35:54 (8 months ago)
Author:
mgoldman
Message:

Replace sebools and sestatus function stubs with real functions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/trunk-pmd-intproto/agent/agent.py

    r462 r479  
    1212LOGPATH = "/var/log/audit/audit.log" 
    1313 
    14 def se_bool_to_val(string): 
    15         """ This function should take an SELinux boolean and return it's current value """ 
    16         # FIXME: unimplemented. 
    17         return 0; 
     14def sebools(): 
     15    ''' Returns a hash of all the selinux booleans on a system ''' 
     16    res = {} 
     17    for i in listdir("/selinux/booleans"): 
     18        f = file("/selinux/booleans/" + i, "r") 
     19        val = f.read(512) 
     20        res[i] = (val[0] == '1') 
     21    return res 
     22 
     23def sestatus(): 
     24    ''' Return selinux status ''' 
     25    f = file("/selinux/enforce", "r") 
     26    val = f.read(512) 
     27    return (val[0] == '1') 
     28 
     29def dictsub(a, b): 
     30    ''' Remove from a all elements where a[k] == b[k] ''' 
     31    for key in a.keys(): 
     32        if a.get(key) == b.get(key): 
     33            del a[key] 
     34    return a 
    1835 
    1936def insert_hash(hash, key, val): 
     
    2643        f(accum, seq[0]) 
    2744        fold(f,seq[1:], accum) 
    28  
    29 def selinux_status(): 
    30         # FIXME: unimplemented. 
    31         return "enforcing" 
    3245 
    3346class ClientD: 
     
    98111                        # Build response message 
    99112                        msg.type = "response" 
    100                         msg.body = selinux_status() 
     113                        msg.body = sestatus() 
    101114                        return msg 
    102115 
     
    105118                        msg.type = "response" 
    106119                        if(msg.body == "ALL"): 
    107                                 msg.body = se_all_bools() 
    108                         bools = {} 
    109                         # se_bool_to_val reads the bools, either from the filesystem or the bindings and returns 
    110                         # the status of true or false. 
    111                         fold(lambda x, y: insert_hash(x,y,se_bool_to_val(y)), msg.body, bools) 
    112                         msg.body = bools 
     120                                msg.body = sebools() 
     121                                return msg 
     122                        bools = sebools() 
     123                        res = dict([(k,v) for (k,v) in bools.getitems() if k in msg.body]) 
     124                        msg.body = res 
    113125                        return msg 
    114126