1
0
mirror of https://github.com/docker/docker-credential-helpers.git synced 2026-06-14 08:21:28 +05:30

Add a Docker Credentials label support for macOS

Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
This commit is contained in:
Nassim 'Nass' Eddequiouaq
2017-03-08 17:08:22 +01:00
parent 595b7f2531
commit 406812bf8e
4 changed files with 33 additions and 9 deletions
+22 -3
View File
@@ -14,7 +14,9 @@ char *get_error(OSStatus status) {
return buf;
}
char *keychain_add(struct Server *server, char *username, char *secret) {
char *keychain_add(struct Server *server, char *label, char *username, char *secret) {
SecKeychainItemRef item;
OSStatus status = SecKeychainAddInternetPassword(
NULL,
strlen(server->host), server->host,
@@ -25,11 +27,27 @@ char *keychain_add(struct Server *server, char *username, char *secret) {
server->proto,
kSecAuthenticationTypeDefault,
strlen(secret), secret,
NULL
&item
);
if (status) {
return get_error(status);
}
SecKeychainAttribute attribute;
SecKeychainAttributeList attrs;
attribute.tag = kSecLabelItemAttr;
attribute.data = label;
attribute.length = strlen(label);
attrs.count = 1;
attrs.attr = &attribute;
status = SecKeychainItemModifyContent(item, &attrs, 0, NULL);
if (status) {
return get_error(status);
}
return NULL;
}
@@ -116,11 +134,12 @@ char * CFStringToCharArr(CFStringRef aString) {
return NULL;
}
char *keychain_list(char *** paths, char *** accts, unsigned int *list_l) {
char *keychain_list(char *credsLabel, char *** paths, char *** accts, unsigned int *list_l) {
CFMutableDictionaryRef query = CFDictionaryCreateMutable (NULL, 1, NULL, NULL);
CFDictionaryAddValue(query, kSecClass, kSecClassInternetPassword);
CFDictionaryAddValue(query, kSecReturnAttributes, kCFBooleanTrue);
CFDictionaryAddValue(query, kSecMatchLimit, kSecMatchLimitAll);
CFDictionaryAddValue(query, kSecAttrLabel, CFSTR(credsLabel));
//Use this query dictionary
CFTypeRef result= NULL;
OSStatus status = SecItemCopyMatching(