Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/root/sys/src/cmd/mkpass/mkpass.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


/* mkpass.c    Steve Simon     Apr 2005 */
#include <u.h>
#include <libc.h>
#include <libsec.h>
#include <auth.h>

static void
ding(void *u, char *msg)
{
	USED(u);

	if(strstr(msg, "alarm"))
		noted(NCONT);
	noted(NDFLT);
}

void
main()
{
	int fd, cfd, num, n;
	char buf[1024];
	DigestState *s;
	uchar digest[SHA1dlen];

	notify(ding);
	fmtinstall('[', encodefmt);

	if((fd = dial("/net/ether0!-1", 0, 0, &cfd)) == -1)
		sysfatal("cannot open ether device - %r\n");
	if (fprint(cfd, "promiscuous") < 0)
		sysfatal("cannot set ether to promiscuous mode\n");

	alarm(1000*10);
	s = sha1(nil, 0, nil, nil);
	for(n = num = 0; num < 4096 && n >= 0; num += n){
		n = read(fd, buf, sizeof(buf));
		s = sha1((uchar *)buf, n, nil, s);
		num += n;
	}
	sha1(nil, 0, digest, s);

	if (num < 4096)
		sysfatal("%d bytes, not enough ethernet traffic\n", num);
 	/*
	 *  -2 below as otherwise base64 gives
	 *  a fixed pattern at the end of each password.
	 */
	print("%.*[\n", SHA1dlen-2, digest);
	exits(0);
}



Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.