Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/boot/userpasswd.c

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


## diffname boot/userpasswd.c 1992/0317
## diff -e /dev/null /n/bootesdump/1992/0317/sys/src/9/boot/userpasswd.c
0a
#include <u.h>
#include <libc.h>
#include <../boot/boot.h>

char	password[NAMELEN];

static int
passtokey(char *key, char *p, int n)
{
	uchar t[10];
	int c;

	memset(t, ' ', sizeof t);
	if(n < 5)
		return 0;
	if(n > 10)
		n = 10;
	strncpy((char*)t, p, n);
	if(n >= 9){
		c = p[8] & 0xf;
		if(n == 10)
			c += p[9] << 4;
		for(n = 0; n < 8; n++)
			if(c & (1 << n))
				t[n] -= ' ';
	}
	for(n = 0; n < 7; n++)
		key[n] = (t[n] >> n) + (t[n+1] << (8 - (n+1)));
	return 1;
}

/*
 *  get/set user name and password.  verify password with auth server.
 */
void
userpasswd(Method *mp)
{
	char key[7];
	char buf[8 + NAMELEN];
	int fd, crfd;

	if(*username == 0 || strcmp(username, "none") == 0){
		strcpy(username, "none");
		outin("user", username, sizeof(username));
	}
	crfd = fd = -1;
	while(strcmp(username, "none") != 0 && strcmp(mp->name, "local") != 0){
		getpasswd(password, sizeof password);
		if(!passtokey(key, password, strlen(password))){
			print("bad password; try again\n");
			continue;
		}
		fd = open("#c/key", OWRITE);
		if(fd < 0)
			fatal("can't open #c/key; please reboot");
		if(write(fd, key, 7) != 7)
			fatal("can't write #c/key; please reboot");
		close(fd);
		crfd = open("#c/crypt", ORDWR);
		if(crfd < 0)
			fatal("can't open crypt file");
		write(crfd, "E", 1);
		fd = (*mp->auth)();
		if(fd < 0){
			warning("password not checked!");
			break;
		}
		strncpy(buf+8, username, NAMELEN);
		if(read(fd, buf, 8) != 8
		|| write(crfd, buf, 8) != 8
		|| read(crfd, buf, 8) != 8
		|| write(fd, buf, 8 + NAMELEN) != 8 + NAMELEN){
			warning("password not checked!");
			break;
		}
		if(read(fd, buf, 2) == 2 && buf[0]=='O' && buf[1]=='K')
			break;
		close(fd);
		outin("user", username, sizeof(username));
	}
	close(fd);
	close(crfd);

	/* set user now that we're sure */
	fd = open("#c/user", OWRITE|OTRUNC);
	if(fd >= 0){
		if(write(fd, username, strlen(username)) < 0)
			warning("write user name");
		close(fd);
	}else
		warning("open #c/user");
}
.
## diffname boot/userpasswd.c 1992/0318
## diff -e /n/bootesdump/1992/0317/sys/src/9/boot/userpasswd.c /n/bootesdump/1992/0318/sys/src/9/boot/userpasswd.c
47c
	while(strcmp(username, "none") != 0 && !islocal){
.
36c
userpasswd(int islocal, Method *mp)
.
7,31d
## diffname boot/userpasswd.c 1992/0322
## diff -e /n/bootesdump/1992/0318/sys/src/9/boot/userpasswd.c /n/bootesdump/1992/0322/sys/src/9/boot/userpasswd.c
24,27c
		passtokey(key, password);
.
2a
#include <auth.h>
.
## diffname boot/userpasswd.c 1992/0323
## diff -e /n/bootesdump/1992/0322/sys/src/9/boot/userpasswd.c /n/bootesdump/1992/0323/sys/src/9/boot/userpasswd.c
20a
		/* Hack to do authentication testing */
		p = utfrrune(username, '!');
		if(p && p > username) {
			*p = '\0';
			sauth = "any";
		}
.
16a
	char *p;
.
6a
extern	char *sauth;
.
## diffname boot/userpasswd.c 1992/0325
## diff -e /n/bootesdump/1992/0323/sys/src/9/boot/userpasswd.c /n/bootesdump/1992/0325/sys/src/9/boot/userpasswd.c
44c
		fd = -1;
		if(mp->auth)
			fd = (*mp->auth)();
.
23,28d
7a
#endif asdf
.
6a
#ifdef asdf
.
## diffname boot/userpasswd.c 1992/0507
## diff -e /n/bootesdump/1992/0325/sys/src/9/boot/userpasswd.c /n/bootesdump/1992/0507/sys/src/9/boot/userpasswd.c
40a
		if(islocal)
			break;
.
27c
	while(strcmp(username, "none") != 0){
.
## diffname boot/userpasswd.c 1992/0728
## diff -e /n/bootesdump/1992/0507/sys/src/9/boot/userpasswd.c /n/bootesdump/1992/0728/sys/src/9/boot/userpasswd.c
20d
## diffname boot/userpasswd.c 1993/0330
## diff -e /n/bootesdump/1992/0728/sys/src/9/boot/userpasswd.c /n/bootesdump/1993/0330/sys/src/9/boot/userpasswd.c
70,71c

	/* set host's key */
	if(writefile("#c/key", hostkey, DESKEYLEN) < 0)
		fatal(homsg);

	/* set host's owner (and uid of current process) */
	if(writefile("#c/hostowner", username, strlen(username)) < 0)
		fatal(homsg);
	close(fd);
.
61,68c
	if(fd > 0)
.
47,58c
		fprint(2, "?%s\n", msg);
.
42,45c
		msg = checkkey(mp, username, hostkey);
		if(msg == 0)
.
28,38c
		passtokey(hostkey, password);
.
25c
	fd = -1;
.
17,19c
	int fd;
	char *msg;
	char hostkey[DESKEYLEN];
.
10a
char *homsg = "can't set user name or key; please reboot";

.
## diffname boot/userpasswd.c 1993/0331
## diff -e /n/bootesdump/1993/0330/sys/src/9/boot/userpasswd.c /n/bootesdump/1993/0331/sys/src/9/boot/userpasswd.c
36a
		/* try the old key algorithm till everyone has switched */
		opasstokey(hostkey, password);
		msg = checkkey(mp, username, hostkey);
		if(msg == 0){
			print("You have an old style key.  Once you are up, please run 'aux/passwd'\n");
			print("and retype your key to convert.\n");
			break;
		}
.
## diffname boot/userpasswd.c 1994/0715
## diff -e /n/bootesdump/1993/0331/sys/src/9/boot/userpasswd.c /n/fornaxdump/1994/0715/sys/src/brazil/boot/userpasswd.c
37,44d
## diffname boot/userpasswd.c 2000/0328
## diff -e /n/fornaxdump/1994/0715/sys/src/brazil/boot/userpasswd.c /n/emeliedump/2000/0328/sys/src/9/boot/userpasswd.c
50d
## diffname boot/userpasswd.c 2001/0527
## diff -e /n/emeliedump/2000/0328/sys/src/9/boot/userpasswd.c /n/emeliedump/2001/0527/sys/src/9/boot/userpasswd.c
27,45d
19,22d
17c
setusername(int, Method*)
.
14c
 *  get/set user name.
.
6c
char	username[64];
char	password[64];
.
## diffname boot/userpasswd.c 2001/1107 # deleted
## diff -e /n/emeliedump/2001/0527/sys/src/9/boot/userpasswd.c /n/emeliedump/2001/1107/sys/src/9/boot/userpasswd.c
1,28d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].