Add a miniscule password retriever

This primarily exists so the user gets a helpful prompt when Security
Services asks them to grant keychain access.
This commit is contained in:
John Barnette
2013-02-13 16:10:48 -08:00
parent 1c248813ff
commit 731e6ebc30
4 changed files with 34 additions and 0 deletions

1
.gitignore vendored
View File

@@ -8,3 +8,4 @@
/boxen-*.gem
/log
/puppet
/script/Boxen.dSYM

BIN
script/Boxen Executable file

Binary file not shown.

6
script/build-keychain-helper Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/sh
set -e
cd $(dirname "$0")/..
cc -g -O2 -Wall -framework Security -o script/Boxen src/keychain-helper.c

27
src/keychain-helper.c Normal file
View File

@@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <Security/Security.h>
int main(int argc, char **argv) {
const char *service = argv[1];
const char *login = argv[2];
if (!(argv[1] && argv[2])) {
printf("Usage: %s <service> <account>\n", argv[0]);
exit(1);
}
void *buf;
UInt32 len;
SecKeychainItemRef item;
int ret = SecKeychainFindGenericPassword(
NULL, strlen(service), service, strlen(login), login, &len, &buf, &item);
if (ret) {
exit(1);
}
fwrite(buf, 1, len, stdout);
exit(0);
}