plan9port

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

secacct.c (755B)


      1 #include <u.h>
      2 #include <libc.h>
      3 #include <ip.h>
      4 
      5 int verbose = 1;
      6 static char testmess[] = "__secstore\tPAK\nC=%s\nm=0\n";
      7 
      8 void
      9 main(int argc, char **argv)
     10 {
     11 	int n, m, fd;
     12 	uchar buf[500];
     13 
     14 	if(argc != 2)
     15 		exits("usage: secacct userid");
     16 
     17 	n = snprint((char*)buf, sizeof buf, testmess, argv[1]);
     18 	hnputs(buf, 0x8000+n-2);
     19 
     20 	fd = dial("tcp!ruble.cs.bell-labs.com!5356", 0, 0, 0);
     21 	if(fd < 0)
     22 		exits("cannot dial ruble");
     23 	if(write(fd, buf, n) != n || readn(fd, buf, 2) != 2)
     24 		exits("cannot exchange first round");
     25 	n = ((buf[0]&0x7f)<<8) + buf[1];
     26 	if(n+1 > sizeof buf)
     27 		exits("implausibly large count");
     28 	m = readn(fd, buf, n);
     29 	close(fd);
     30 	if(m != n)
     31 		fprint(2,"short read from secstore\n");
     32 	buf[m] = 0;
     33 	print("%s\n", (char*)buf);
     34 	exits(0);
     35 }