~kris/9p

9hist

ref: 6130ddb5ccfa6e667f9a452999df55fb7cd47d9e 9hist/boot/userpasswd.c -rw-r--r-- 1.0 KiB
6130ddb5 — David du Colombier Plan 9 from Bell Labs 1999-08-28 27 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <u.h>
#include <libc.h>
#include <auth.h>
#include <../boot/boot.h>

char	password[NAMELEN];
#ifdef asdf
extern	char *sauth;
#endif asdf

char *homsg = "can't set user name or key; please reboot";

/*
 *  get/set user name and password.  verify password with auth server.
 */
void
userpasswd(int islocal, Method *mp)
{
	int fd;
	char *msg;
	char hostkey[DESKEYLEN];

	if(*username == 0 || strcmp(username, "none") == 0){
		strcpy(username, "none");
		outin("user", username, sizeof(username));
	}
	fd = -1;
	while(strcmp(username, "none") != 0){
		getpasswd(password, sizeof password);
		passtokey(hostkey, password);
		fd = -1;
		if(islocal)
			break;
		msg = checkkey(mp, username, hostkey);
		if(msg == 0)
			break;
		fprint(2, "?%s\n", msg);
		outin("user", username, sizeof(username));
	}
	if(fd > 0)
		close(fd);

	/* 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);
}