예제 #1
0
def doesRestorePartitionExist(message_level="normal") :
    """
    Checks for the existence of the restore partition
    
    Author: Roy Nielsen
    """
    log_message("Start checking for restore partition...", "debug", message_level)
    doesItExist = False
    
    #####
    # Get valid users on the system, put them in a list
    cmd = ["/usr/sbin/diskutil", "list", "/dev/disk0"]
    
    (retval, reterr) = system_call_retval(cmd, message_level)
    
    partitions = retval.split("\n")
    
    for partition in partitions :
        print partition
        if re.match("^\s+\S+\s+\S+\s+Recovery HD\s+\S+\s+\S+\s+\S+", partition) :
            doesItExist = True
            break
        else :
            continue
    log_message("Finishing check for restore parition with: " + str(doesItExist), "debug", message_level)
    return doesItExist
예제 #2
0
def checkIfUserIsLocalAdmin(user="", message_level="normal") :
    """
    Check the local directory and see if a user is a local admin on the system.

    command:
    dscl . read /Groups/admin GroupMembership
    
    above command returns:
    GroupMembership: root rsn
    
    Author: Roy Nielsen
    """

    userFound = False

    if not re.match("^\s*$", username) :

        dsclCommand = ["/usr/bin/dscl", ".", "read", "/Groups/admin", "GroupMembership"]

        log_message("About to run command: " + " ".join(dsclCommand), "debug", message_level)

        (retval, reterr) = system_call_retval(dsclCommand, message_level)
        
        #print "Retval: \"" + retval + "\""
        
        if retval :
            users = retval.split()[1:]
            #print str(users)
            for user in users :
                if re.match("^%s$"%user, username) :
                    userFound = True
                    break

    return userFound
예제 #3
0
    def processCurrentUser(self) :
        """
        Run Stonix with the currently logged in user
        
        @author: Roy Nielsen
        """
        fullStonixPath = os.path.join(getResourcesDir(), "stonix.app/Contents/MacOS/stonix")
        
        if self.args:
            command = [fullStonixPath] + self.args
        else:
            command = [fullStonixPath, "-G", "-dv"]
        

        retval = ""
        reterr = ""
        
        child_pid = os.fork()
        if child_pid == 0 :
            print "Child Process: PID# %s" % os.getpid()
            retval, reterr = system_call_retval(command, self.message_level)

        else:
            print "Exiting parent process: PID# %s" % os.getpid()
            self.reject()
            
        self.reject()
예제 #4
0
    def processCurrentUser(self):
        """
        Run Stonix with the currently logged in user
        
        @author: Roy Nielsen
        """
        fullStonixPath = os.path.join(getResourcesDir(),
                                      "stonix.app/Contents/MacOS/stonix")

        if self.args:
            command = [fullStonixPath] + self.args
        else:
            command = [fullStonixPath, "-G", "-dv"]

        retval = ""
        reterr = ""

        child_pid = os.fork()
        if child_pid == 0:
            print "Child Process: PID# %s" % os.getpid()
            retval, reterr = system_call_retval(command, self.message_level)

        else:
            print "Exiting parent process: PID# %s" % os.getpid()
            self.reject()

        self.reject()
예제 #5
0
def getOsVers(message_level="normal") :
    """
    Get the version of OS X
    
    Author: Roy Nielsen
    """
    cmd_string = ["/usr/bin/sw_vers", "-productVersion"]
    
    (os_vers, os_vers_err) = system_call_retval(cmd_string, message_level)
    
    if os_vers :
        return os_vers
    else :
        return -1
예제 #6
0
def isUserOnSystem(user="", message_level="normal") :
    """
    Check if the passed in user is a local user on the system
    
    Author: Roy Nielsen
    """
    is_user_on_local_system = False

    #####
    # If the passed in user is empty or only spaces, return false.
    if re.match("^\s*$", user) :
        return is_user_on_local_system
    
    #####
    # Get valid users on the system, put them in a list
    cmd = ["/usr/bin/dscl", "/Search", "list", "/Users"]
    
    (retval, reterr) = system_call_retval(cmd, message_level)
    
    systemUserList = retval.split("\n")

    validSystemUserList = []
    
    for systemUser in systemUserList :
        if not re.match("^_.*", systemUser) and \
           not re.match("^root$", systemUser) and \
           not re.match("^nobody$", systemUser) and \
           not re.match("^daemon$", systemUser) and \
           not re.match("^\s*$", systemUser) :
            log_message("Valid System User: "******"debug", message_level)
            validSystemUserList.append(systemUser)

    #####
    # Check if the passed in user is a valid local user on the system
    for systemUser in validSystemUserList :
        if re.match("^%s$"%(systemUser), user) :
            is_user_on_local_system = True
            log_message("User: \"" + str(user) + "\" found on the system", "debug", message_level)
            break

    log_message("ivar = " + str(is_user_on_local_system), "debug", message_level)
    return is_user_on_local_system
예제 #7
0
def isFilevaultActive(message_level="normal") :
    """
    Determine if Filevault is active or not
    
    Author: Roy Nielsen
    """
    is_filevault_active = False
    
    cmd = ["/usr/bin/fdesetup", "status"]
    
    (retval, reterr) = system_call_retval(cmd, message_level)

    if re.search("On", str(retval)) :
        is_filevault_active = True
    elif re.search("Off", str(retval)) :
        is_filevault_active = False
    else :
        is_filevault_active = False
        
    return is_filevault_active