def _update_login(): try: if not ad.bound(): d = PyDialog.PasswordDialog() selection = d.display() if selection: principal = ad._format_principal(d.username()) domain = ad._split_principal(d.username())[1] write_pref('principal', principal) write_pref('domain', domain) if is_ldap_reachable(read_pref('domain')): result = kerberos.test_kerberos_password( read_pref('principal'), d.password()) if result != True: _update_login() else: if is_ldap_reachable(read_pref('domain')): success = kerberos.test_kerberos_password( read_pref('principal'), _update_password()) if not success: _update_login() except ad.PrincipalFormatError: message = 'Username must be formatted as [email protected]' username_dialog = PyDialog.AlertDialog('Invalid username!', message) username_dialog.display() self.validate_kerberos()
def update_managedshares(self): NSLog('Updating managed shares...') membership = ad.membership(read_pref('principal')) managed_shares = get_managed_shares() mapped_shares = self.get_mappedshares(membership) mapped_share_titles = [share['title'] for share in mapped_shares] for mapped_share in mapped_shares: existing_share, index = self.get_managedshare_bykey( 'title', mapped_share['title']) if existing_share: NSLog('Updating existing share') if existing_share['share_url'] != mapped_share['share_url']: managed_shares[index]['share_url'] = mapped_share[ 'share_url'] if existing_share['groups'] != mapped_share['groups']: managed_shares[index]['groups'] = mapped_share['groups'] else: NSLog('Processing new network share: {0}'.format( mapped_share.get('title'))) processed_share = self._process_networkshare(mapped_share) managed_shares.append(processed_share) write_pref('managed_shares', managed_shares) if read_pref('include_smb_home'): NSLog('Getting SMB Home info...') existing, index = self.get_managedshare_bykey( 'share_type', 'smb_home') if ad.bound(): smbhome = ad.smbhome() username = ad._get_consoleuser() if existing: NSLog('SMB Home already exists in config. Updating...') if existing.get('title') != username: managed_shares[index]['share_title'] = username if existing.get('share_url') != smbhome: managed_shares[index]['share_url'] = smbhome else: network_share = {'title': username, 'share_url': smbhome} processed = self._process_networkshare( network_share, share_type='smb_home') managed_shares.append(processed) NSLog('Done checking for SMB Info...') else: NSLog('Computer is not bound. Skipping SMB Home...') write_pref('managed_shares', managed_shares) current_shares = list(managed_shares) for network_share in current_shares: if (network_share.get('title') not in mapped_share_titles and network_share.get('share_type') != 'smb_home'): remove_share(network_share) NSLog('Managed shares have been updated!')
def check_keychain(principal=None): if principal: username, realm = ad._split_principal(principal) else: if not ad.bound(): raise ad.NotBound realm = ad.realms()[0] username = ad._get_consoleuser() security_args = [ '-a', username, '-l', realm.upper() + ' (' + username + ')', '-s', realm.upper(), '-c', 'aapl' ] return True if _keychain('find', 'generic', security_args) else False
def check_keychain(principal=None): if principal: username, realm = ad._split_principal(principal) else: if not ad.bound(): raise ad.NotBound realm = ad.realms()[0] username=ad._get_consoleuser() security_args = [ '-a', username, '-l', realm.upper() + ' (' + username + ')', '-s', realm.upper(), '-c', 'aapl' ] return True if _keychain('find', 'generic', security_args) else False
def load_prefs(self): NSLog('Loading user preferences...') defaults = { 'managed_shares': list(), 'user_added_shares': list(), 'display_notifications': True, 'group_membership': list(), 'domain': '', 'principal': '' } for key, value in defaults.iteritems(): if not read_pref(key): write_pref(key, value) if ad.bound(): write_pref('domain', ad.domain_dns()) write_pref('principal', ad.principal())
def test_bound_true(self): nose.tools.ok_(ad.bound())
def test_bound_false(self): self.assertFalse(ad.bound())