char * AFPUser_get_user(AFPUserRef user, char *buf, size_t buf_len) { CFStringRef name; ODRecordRef record; record = (ODRecordRef)CFDictionaryGetValue(user, kAFPUserODRecord); name = ODRecordGetRecordName(record); (void) _SC_cfstring_to_cstring(name, buf, buf_len, kCFStringEncodingASCII); return buf; }
AFPUserRef AFPUserList_lookup(AFPUserListRef users, CFStringRef afp_user) { int i; int n; n = CFArrayGetCount(users->list); for (i = 0; i < n; i++) { CFStringRef name; AFPUserRef user; ODRecordRef record; user = (AFPUserRef)CFArrayGetValueAtIndex(users->list, i); record = (ODRecordRef)CFDictionaryGetValue(user, kAFPUserODRecord); name = ODRecordGetRecordName(record); if (CFEqual(name, afp_user)) { return (user); } } return (NULL); }
/* ------------------------------------------------------------------ * get_attr_from_record () */ static CFStringRef get_attr_from_record ( ODRecordRef in_rec_ref, CFStringRef in_attr ) { CFErrorRef cf_err_ref = NULL; CFArrayRef cf_arry_values = ODRecordCopyValues( in_rec_ref, in_attr, &cf_err_ref ); if ( !cf_arry_values ) return( NULL ); if ( CFArrayGetCount( cf_arry_values ) > 1 ) { msg_error( "aod: multiple attribute values (%d) found in record user record: %s for attribute: %s", (int)CFArrayGetCount( cf_arry_values ), CFStringGetCStringPtr( ODRecordGetRecordName( in_rec_ref ), kCFStringEncodingUTF8 ), CFStringGetCStringPtr( in_attr, kCFStringEncodingUTF8 ) ); CFRelease( cf_arry_values ); return( NULL ); } CFStringRef cf_str_out = CFArrayGetValueAtIndex( cf_arry_values, 0 ); CFRetain( cf_str_out ); CFRelease( cf_arry_values ); return( cf_str_out ); } /* get_attr_from_record */
/* ------------------------------------------------------------------ * get_user_attributes () */ static int get_user_attributes ( ODNodeRef in_node_ref, const char *in_user_name, struct od_user_opts *in_out_opts ) { CFStringRef cf_str_ref = CFStringCreateWithCString( NULL, in_user_name, kCFStringEncodingUTF8 ); if ( !cf_str_ref ) { msg_error( "aod: unable to create user name CFStringRef"); return( -1 ); } /* look up user record */ ODRecordRef od_rec_ref = NULL; CFErrorRef cf_err_ref = NULL; CFTypeRef cf_type_ref[] = { CFSTR(kDSAttributesStandardAll) }; CFArrayRef cf_arry_ref = CFArrayCreate( NULL, cf_type_ref, 1, &kCFTypeArrayCallBacks ); ODQueryRef cf_query_ref = ODQueryCreateWithNode( NULL, in_node_ref, CFSTR(kDSStdRecordTypeUsers), CFSTR(kDSNAttrRecordName), kODMatchInsensitiveEqualTo, cf_str_ref, cf_arry_ref, 100, &cf_err_ref ); if ( cf_query_ref ) { CFArrayRef cf_arry_result = ODQueryCopyResults( cf_query_ref, false, &cf_err_ref ); if ( cf_arry_result ) { if ( CFArrayGetCount( cf_arry_result ) == 1 ) { od_rec_ref = (ODRecordRef)CFArrayGetValueAtIndex( cf_arry_result, 0 ); CFRetain(od_rec_ref); } else { if ( CFArrayGetCount( cf_arry_result ) == 0 ) msg_error( "aod: no user record found for: %s", in_user_name ); else msg_error( "aod: multiple user records (%ld) found for: %s", CFArrayGetCount( cf_arry_result ), in_user_name ); } CFRelease(cf_arry_result); } else print_cf_error( cf_err_ref, in_user_name, "aod: ODQueryCopyResults() failed" ); CFRelease( cf_query_ref ); } else print_cf_error( cf_err_ref, in_user_name, "aod: ODQueryCreateWithNode() failed" ); CFRelease( cf_str_ref ); CFRelease( cf_arry_ref ); if ( !od_rec_ref ) { /* print the error and bail */ print_cf_error( cf_err_ref, in_user_name, "aod: unable to lookup user record" ); return( -1 ); } /* get guid */ char user_guid[ 64 ]; size_t str_size = 0; memset(user_guid, 0, sizeof user_guid); CFStringRef cf_str_value = get_attr_from_record( od_rec_ref, CFSTR(kDS1AttrGeneratedUID) ); if ( cf_str_value ) { str_size = CFStringGetMaximumSizeForEncoding(CFStringGetLength( cf_str_value ), kCFStringEncodingUTF8) + 1; CFStringGetCString( cf_str_value, user_guid, str_size, kCFStringEncodingUTF8 ); CFRelease( cf_str_value ); } /* get record name */ cf_str_value = ODRecordGetRecordName( od_rec_ref ); if ( cf_str_value ) str_size = CFStringGetMaximumSizeForEncoding(CFStringGetLength( cf_str_value ), kCFStringEncodingUTF8) + 1; if (str_size ) CFStringGetCString( cf_str_value, in_out_opts->fRecName, sizeof(in_out_opts->fRecName), kCFStringEncodingUTF8 ); /* get mail attribute */ if ( !get_attributes_local(in_out_opts, user_guid) ) { cf_str_value = get_attr_from_record( od_rec_ref, CFSTR(kDS1AttrMailAttribute) ); if ( cf_str_value != NULL ) { str_size = CFStringGetMaximumSizeForEncoding(CFStringGetLength( cf_str_value ), kCFStringEncodingUTF8) + 1; char *c_str = malloc( str_size ); if ( c_str ) { if( CFStringGetCString( cf_str_value, c_str, str_size, kCFStringEncodingUTF8 ) ) { CFMutableDictionaryRef user_dict = get_mail_attribute_values( c_str, in_out_opts ); set_attributes_local(user_dict, user_guid); CFRelease(user_dict); } free( c_str ); } CFRelease( cf_str_value ); } } CFRelease(od_rec_ref); return( 0 ); } /* get_user_attributes */