<s> """<STR_LIT>""" <EOL> import ctypes <EOL> import sys <EOL> SECURITY = ctypes . cdll . LoadLibrary ( '<STR_LIT>' ) <EOL> def find_airport_password ( ssid ) : <EOL> """<STR_LIT>""" <EOL> item = ctypes . c_void_p ( ) <EOL> password_length = ctypes . c_uint32 ( <NUM_LIT:0> ) <EOL> password_data = ctypes . c_char_p ( <NUM_LIT> ) <EOL> system_keychain = ctypes . c_void_p ( ) <EOL> keychain_ptr = ctypes . pointer ( system_keychain ) <EOL> rc = SECURITY . SecKeychainOpen ( "<STR_LIT>" , keychain_ptr ) <EOL> if rc != <NUM_LIT:0> : <EOL> raise RuntimeError ( "<STR_LIT>" % rc ) <EOL> rc = SECURITY . SecKeychainFindGenericPassword ( <EOL> system_keychain , <EOL> None , <EOL> None , <EOL> len ( ssid ) , <EOL> ssid , <EOL> ctypes . byref ( password_length ) , <EOL> ctypes . pointer ( password_data ) , <EOL> ctypes . pointer ( item ) <EOL> ) <EOL> if rc == - <NUM_LIT> : <EOL> raise RuntimeError ( '<STR_LIT>' % ( ssid , rc ) ) <EOL> elif rc != <NUM_LIT:0> : <EOL> raise RuntimeError ( '<STR_LIT>' % ( ssid , rc ) ) <EOL> password = password_data . value [ <NUM_LIT:0> : password_length . value ] <EOL> SECURITY . SecKeychainItemFreeContent ( None , password_data ) <EOL> return ( password , item ) <EOL> def change_airport_password ( ssid , new_password ) : <EOL> """<STR_LIT>""" <EOL> password , item = find_airport_password ( ssid ) <EOL> if password != new_password : <EOL> rc = SECURITY . SecKeychainItemModifyAttributesAndData ( <EOL> item , <EOL> None , <EOL> len ( new_password ) , <EOL> new_password <EOL> ) <EOL> if rc == - <NUM_LIT> : <EOL> raise RuntimeError ( "<STR_LIT>" % ( ssid , rc ) ) <EOL> elif rc != <NUM_LIT:0> : <EOL> raise RuntimeError ( "<STR_LIT>" % ( ssid , rc ) ) <EOL> def main ( ) : <EOL> if len ( sys . argv ) < <NUM_LIT:3> : <EOL> print >> sys . stderr , "<STR_LIT>" % ( sys . argv [ <NUM_LIT:0> ] ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> ssid , new_password = sys . argv [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> try : <EOL> change_airport_password ( ssid , new_password ) <EOL> except RuntimeError , exc : <EOL> print >> sys . stderr , "<STR_LIT>" % ( ssid , exc ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> print "<STR_LIT>" % ( ssid , new_password ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
