def deleteUsersEAPProfile(networkName): users = '/var/db/dslocal/nodes/Default/users' listing = os.listdir(users) for plist in listing: # Hardware test for Air excluded = re.compile("^((?!^_|root|daemon|nobody|com.apple.*).)*$") if excluded.match(plist): plistPath = '%s/%s' % (users,plist) print 'Processing: %s' % plistPath user = NSDictionary.dictionaryWithContentsOfFile_(plistPath) try: uid = int(user['uid'][0]) gid = int(user['gid'][0]) for home in user['home']: profile = home + '/Library/Preferences/com.apple.eap.profiles.plist' print 'Processing profile: %s' % profile # Profile if os.path.exists(profile): profileFile = NSMutableDictionary.dictionaryWithContentsOfFile_(profile) profileByHost = home + '/Library/Preferences/ByHost/com.apple.eap.bindings.%s.plist' % getPlatformUUID() if os.path.exists(profileByHost): print 'Updating File: %s' % profileByHost profileByHostFile = NSMutableDictionary.dictionaryWithContentsOfFile_(profileByHost) # Make a copy for enumeration copy = NSDictionary.dictionaryWithDictionary_(profileByHostFile) # Multiple MAC Addresses may exist for mac in copy: index = 0 for key in copy[mac]: if key['Wireless Network'] == networkName: UniqueIdentifier = key['UniqueIdentifier'] print 'Found Network with Identifier: %s' % UniqueIdentifier # Delete the entry and update the file del profileByHostFile[mac][index] writePlist(profileByHostFile,profileByHost) try: os.chown(profileByHost,uid,gid) except: print 'Path not found: %s' % profileByHost profileFileCopy = NSDictionary.dictionaryWithDictionary_(profileFile) profileIndex = 0 print '-' * 80 for key in profileFileCopy['Profiles']: if key['UniqueIdentifier'] == UniqueIdentifier: print 'Found network: %s' % key['UserDefinedName'] # Delete the entry and update the file del profileFile['Profiles'][index] writePlist(profileFile,profile) os.chown(profile,uid,gid) profileIndex += 1 index += 1 else: print 'File not found: %s' % profileByHost else: print 'Profile file: %s does not exist' % profile except KeyError: print 'User plist %s does not have a home key' % plistPath
def writePlist(self, the_token): """Function to write to the plist. Only sets the token for now. Could add in more parameters later.""" if debug: print 'Writing plist' mydict = {} mydict['Token']=the_token NSDictionary.dictionaryWithDictionary_(mydict).writeToFile_atomically_(the_plist, True)