plan9port

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

netkey.c (771B)


      1 #include <u.h>
      2 #include <libc.h>
      3 #include <libsec.h>
      4 #include <authsrv.h>
      5 
      6 void
      7 usage(void)
      8 {
      9 	fprint(2, "usage: netkey\n");
     10 	exits("usage");
     11 }
     12 
     13 void
     14 main(int argc, char *argv[])
     15 {
     16 	char *chal, *pass, buf[32], key[DESKEYLEN];
     17 	char *s;
     18 	int n;
     19 
     20 	ARGBEGIN{
     21 	default:
     22 		usage();
     23 	}ARGEND
     24 	if(argc)
     25 		usage();
     26 
     27 	s = getenv("service");
     28 	if(s && strcmp(s, "cpu") == 0){
     29 		fprint(2, "netkey must not be run on the cpu server\n");
     30 		exits("boofhead");
     31 	}
     32 
     33 	pass = readcons("password", nil, 1);
     34 	if(pass == nil)
     35 		sysfatal("reading password: %r");
     36 	passtokey(key, pass);
     37 
     38 	for(;;){
     39 		chal = readcons("challenge", nil, 0);
     40 		if(chal == nil || *chal == 0)
     41 			exits(nil);
     42 		n = strtol(chal, 0, 10);
     43 		sprint(buf, "%d", n);
     44 		netcrypt(key, buf);
     45 		print("response: %s\n", buf);
     46 	}
     47 }