plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

auth_getkey.c (704B)


      1 #include <u.h>
      2 #include <libc.h>
      3 #include <auth.h>
      4 
      5 int
      6 auth_getkey(char *params)
      7 {
      8 	char *name;
      9 	int pid;
     10 	Waitmsg *w;
     11 
     12 	/* start /factotum to query for a key */
     13 	name = unsharp("#9/bin/factotum");
     14 	if(name == nil || access(name, AEXEC) < 0){
     15 		werrstr("auth_getkey: no $PLAN9/bin/factotum: didn't get key %s", params);
     16 		return -1;
     17 	}
     18 	switch(pid = fork()){
     19 	case -1:
     20 		werrstr("can't fork for %s: %r", name);
     21 		return -1;
     22 	case 0:
     23 		execl(name, "getkey", "-g", params, nil);
     24 		exits(0);
     25 	default:
     26 		free(name);
     27 		for(;;){
     28 			w = wait();
     29 			if(w == nil)
     30 				break;
     31 			if(w->pid == pid){
     32 				if(w->msg[0] != '\0'){
     33 					free(w);
     34 					return -1;
     35 				}
     36 				free(w);
     37 				return 0;
     38 			}
     39 		}
     40 	}
     41 	return 0;
     42 }