mirror of
https://github.com/zhigang1992/boxen.git
synced 2026-01-12 17:12:46 +08:00
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:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,3 +8,4 @@
|
||||
/boxen-*.gem
|
||||
/log
|
||||
/puppet
|
||||
/script/Boxen.dSYM
|
||||
|
||||
BIN
script/Boxen
Executable file
BIN
script/Boxen
Executable file
Binary file not shown.
6
script/build-keychain-helper
Executable file
6
script/build-keychain-helper
Executable 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
27
src/keychain-helper.c
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user