From 6de9e06b9b5733980e5477a2a1f6727b49e0854a Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Fri, 8 May 2009 22:27:14 -0400 Subject: [PATCH] Keychain regression fixes Fixed a crash caused by calling SecKeychainFreeAttributeInfo on an attribute list. Sigh... --HG-- extra : convert_revision : 1c6f52a19b040d04a8e6e16e9be8f87a5a88cc92 --- lib/PyMacAdmin/SCUtilities/__init__.py | 7 +++---- lib/PyMacAdmin/Security/Keychain.py | 6 ++++-- lib/PyMacAdmin/Security/tests/test_Keychain.py | 6 ++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/PyMacAdmin/SCUtilities/__init__.py b/lib/PyMacAdmin/SCUtilities/__init__.py index bdbd360..d2efc31 100755 --- a/lib/PyMacAdmin/SCUtilities/__init__.py +++ b/lib/PyMacAdmin/SCUtilities/__init__.py @@ -4,11 +4,10 @@ SCUtilities: tools for dealing with Apple's SystemConfiguration framework Created by Chris Adams on 2008-05-28. - -TODO: -* Import code related to SystemConfiguration events """ +# TODO: Import code related to SystemConfiguration events + import sys import os import unittest @@ -18,4 +17,4 @@ def setUp(self): raise RuntimeError("Thwack Chris about not writing these yet") if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() diff --git a/lib/PyMacAdmin/Security/Keychain.py b/lib/PyMacAdmin/Security/Keychain.py index e5f9ca1..f24fe66 100755 --- a/lib/PyMacAdmin/Security/Keychain.py +++ b/lib/PyMacAdmin/Security/Keychain.py @@ -67,6 +67,8 @@ def find_generic_password(self, service_name="", account_name=""): password = password_data.value[0:password_length.value] + Security.lib.SecKeychainItemFreeContent(None, password_data) + # itemRef: A reference to the keychain item from which you wish to # retrieve data or attributes. # @@ -93,7 +95,7 @@ def find_generic_password(self, service_name="", account_name=""): # Thank you Wil Shipley: # http://www.wilshipley.com/blog/2006/10/pimp-my-code-part-12-frozen-in.html info.count = 1 - info.tag.contents = Security.kSecLabelItemAttr + info.tag.contents = Security.kSecLabelItemAttr Security.lib.SecKeychainItemCopyAttributesAndData(item_p, ctypes.pointer(info), None, ctypes.byref(attrs_p), None, None) attrs = attrs_p.contents @@ -101,7 +103,7 @@ def find_generic_password(self, service_name="", account_name=""): label = attrs.attr[0].data[:attrs.attr[0].length] - Security.lib.SecKeychainFreeAttributeInfo(attrs_p) + Security.lib.SecKeychainItemFreeAttributesAndData(attrs_p) return GenericPassword(service_name=service_name, account_name=account_name, password=password, keychain_item=item_p, label=label) diff --git a/lib/PyMacAdmin/Security/tests/test_Keychain.py b/lib/PyMacAdmin/Security/tests/test_Keychain.py index 35acaac..b2fe5c2 100644 --- a/lib/PyMacAdmin/Security/tests/test_Keychain.py +++ b/lib/PyMacAdmin/Security/tests/test_Keychain.py @@ -25,8 +25,7 @@ def test_load_system_keychain(self): def test_find_airport_password(self): system_keychain = Keychain("/Library/Keychains/System.keychain") - # BUG: Most people probably have this - but not everyone? - system_keychain.find_generic_password(account_name="linksys") + system_keychain.find_generic_password(account_name="default") def test_find_nonexistent_generic_password(self): import uuid @@ -49,8 +48,7 @@ def test_add_and_remove_generic_password(self): def test_find_internet_password(self): keychain = Keychain() - i = keychain.find_internet_password(server_name="connect.apple.com") # BUG: Most people probably have this - but not everyone? - + i = keychain.find_internet_password(server_name="connect.apple.com") self.failIfEqual(i, None) def test_add_and_remove_internet_password(self):