summaryrefslogtreecommitdiff
path: root/sys/src/libauth/auth_getkey.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libauth/auth_getkey.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libauth/auth_getkey.c')
-rwxr-xr-xsys/src/libauth/auth_getkey.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/sys/src/libauth/auth_getkey.c b/sys/src/libauth/auth_getkey.c
new file mode 100755
index 000000000..0ae28b1e4
--- /dev/null
+++ b/sys/src/libauth/auth_getkey.c
@@ -0,0 +1,51 @@
+#include <u.h>
+#include <libc.h>
+#include <auth.h>
+
+int
+auth_getkey(char *params)
+{
+ char *name;
+ Dir *d;
+ int pid;
+ Waitmsg *w;
+
+ /* start /factotum to query for a key */
+ name = "/factotum";
+ d = dirstat(name);
+ if(d == nil){
+ name = "/boot/factotum";
+ d = dirstat(name);
+ }
+ if(d == nil){
+ werrstr("auth_getkey: no /factotum or /boot/factotum: didn't get key %s", params);
+ return -1;
+ }
+if(0) if(d->type != '/'){
+ werrstr("auth_getkey: /factotum may be bad: didn't get key %s", params);
+ return -1;
+ }
+ switch(pid = fork()){
+ case -1:
+ werrstr("can't fork for %s: %r", name);
+ return -1;
+ case 0:
+ execl(name, "getkey", "-g", params, nil);
+ exits(0);
+ default:
+ for(;;){
+ w = wait();
+ if(w == nil)
+ break;
+ if(w->pid == pid){
+ if(w->msg[0] != '\0'){
+ free(w);
+ return -1;
+ }
+ free(w);
+ return 0;
+ }
+ }
+ }
+ return 0;
+}