title: Extract `username` out of `SecKeychainItemRef` given by `SecKeychainFindGenericPassword`?
body: <p>From this question, I know you can use <code>SecKeychainFindGenericPassword</code> <em>without</em> a username value. It will still return a keychain item for the given service. But how do I then get the username?
  <a href="https://stackoverflow.com/questions/8451239/get-the-usernames-stored-in-keychain-using-only-the-servicename-or-where-ar">Get the Username(s) stored in Keychain, using only the ServiceName? OR: Where are you supposed to store the Username?</a></p>
  
  <pre><code>//SecKeychainFindGenericPassword
  //Finds the first generic password based on the attributes passed.
  
  OSStatus SecKeychainFindGenericPassword (
     CFTypeRef keychainOrArray,
     UInt32 serviceNameLength,
     const char *serviceName,
     UInt32 accountNameLength,
     const char *accountName,
     UInt32 *passwordLength,
     void **passwordData,
     SecKeychainItemRef *itemRef
  );
  </code></pre>
  
  <p>My code looks like this:</p>
  
  <pre><code>UInt32 passwordLength = 0;
  char *password = nil;
  
  SecKeychainItemRef item = nil;
  
  OSStatus returnStatus = SecKeychainFindGenericPassword(NULL, 9, @"MyAppName", 0, NULL, &amp;passwordLength, (void **)&amp;password, &amp;item);
  
  //Get password
  NSString *passwordString = [[[NSString alloc] initWithData:[NSData dataWithBytes:password length:passwordLength] encoding:NSUTF8StringEncoding] autorelease];
  SecKeychainItemFreeContent(NULL, password);
  
  //Get username (not yet working)
  UInt32 attributeTags[1];
  *attributeTags = 'acct';// TODO: populate with the kSecAttrAccount constant (NOT a string cast to a UInt32)
  //kSecAccountItemAttr = 'acct',
  
  UInt32 formatConstants[1];
  *formatConstants = 0; // TODO: populate with a format constant found in "cssmtype.h". I'm picking "0" = "string" in list below...
  
  //SecKeychainAttributeInfo doc says: "A pointer to the first attribute format in the array. Attribute formats are of type CSSM_DB_ATTRIBUTE_FORMAT."
  
  /* //found in "cssmtype.h"
   typedef uint32 CSSM_DB_ATTRIBUTE_FORMAT, *CSSM_DB_ATTRIBUTE_FORMAT_PTR;
   enum {
   CSSM_DB_ATTRIBUTE_FORMAT_STRING =          0,
   CSSM_DB_ATTRIBUTE_FORMAT_SINT32 =          1,
   CSSM_DB_ATTRIBUTE_FORMAT_UINT32 =          2,
   CSSM_DB_ATTRIBUTE_FORMAT_BIG_NUM =         3,
   CSSM_DB_ATTRIBUTE_FORMAT_REAL =                4,
   CSSM_DB_ATTRIBUTE_FORMAT_TIME_DATE =       5,
   CSSM_DB_ATTRIBUTE_FORMAT_BLOB =                6,
   CSSM_DB_ATTRIBUTE_FORMAT_MULTI_UINT32 =        7,
   CSSM_DB_ATTRIBUTE_FORMAT_COMPLEX =         8
   };
  */
  
  struct SecKeychainAttributeInfo attributeInfo, 1, *attributeTags, *formatConstants; //ERROR: "Expected ';' at end of declaration list.
  //OR:
  /*
  struct SecKeychainAttributeInfo
  {
      UInt32 1; //ERROR: "Expected ';' at end of declaration list.
      UInt32 *attributeTags;
      UInt32 *formatConstants;
  }attributeInfo;
  */
  
  /*
  SecKeychainAttributeInfo *attributeInfo; //TODO: "change it to hold the structure directly"
  attributeInfo-&gt;count = 1;
  attributeInfo-&gt;tag = attributeTags;
  attributeInfo-&gt;format = formatConstants;
  */
  
  SecKeychainAttributeList *attributeList = nil;
  OSStatus attributeStatus = SecKeychainItemCopyAttributesAndData(item, &amp;attributeInfo, NULL, &amp;attributeList, 0, NULL);
  
  if (attributeStatus != noErr)
  {
      if (_logsErrors)
          NSLog(@"Error (%@) - %s", NSStringFromSelector(_cmd), GetMacOSStatusErrorString(attributeStatus));
      return nil;
  }
  
  
  for (int i = 0; i &lt; attributeList-&gt;count; i ++)
  {
      SecKeychainAttribute attr = attributeList-&gt;attr[i];
      NSLog(@"%08x %@", attr.tag, [NSData dataWithBytes:attr.data length:attr.length]);
  }
  </code></pre>
  
  <p>How do I get an NSString value of the username contained in that <code>SecKeychainItemRef</code>?</p>