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

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


## diffname boot/doauthenticate.c 1993/0330
## diff -e /dev/null /n/bootesdump/1993/0330/sys/src/9/boot/doauthenticate.c
0a
#include <u.h>
#include <libc.h>
#include <auth.h>
#include <../boot/boot.h>

static char *pbmsg = "AS protocol botch";
static char *ccmsg = "can't connect to AS";

int
readn(int fd, char *buf, int len)
{
	int m, n;

	for(n = 0; n < len; n += m){
		m = read(fd, buf+n, len-n);
		if(m <= 0)
			return -1;
	}
	return n;
}

static char*
fromauth(Method *mp, char *trbuf, char *tbuf)
{
	char t;
	char *msg;
	static char error[ERRLEN];

	if(afd < 0){
		if(mp->auth == 0)
			fatal("no method for accessing auth server");
		afd = (*mp->auth)();
		if(afd < 0)
			return ccmsg;
	}
	if(write(afd, trbuf, TICKREQLEN) < 0 || read(afd, &t, 1) != 1){
		close(afd);
		afd = -1;
		return pbmsg;
	}
	switch(t){
	case AuthOK:
		msg = 0;
		if(readn(afd, tbuf, 2*TICKETLEN) < 0)
			msg = pbmsg;
		break;
	case AuthErr:
		if(readn(afd, error, ERRLEN) < 0)
			msg = pbmsg;
		else {
			error[ERRLEN-1] = 0;
			msg = error;
		}
		break;
	default:
		msg = pbmsg;
		break;
	}
	return msg;
}

void
doauthenticate(int fd, Method *mp)
{
	char *msg;
	char trbuf[TICKREQLEN];
	char tbuf[2*TICKETLEN];

	print("session...");
	if(fsession(fd, trbuf) < 0)
		fatal("session command failed");

	/* no authentication required? */
	memset(tbuf, 0, 2*TICKETLEN);
	if(trbuf[0] == 0)
		return;

	/* try getting to an auth server */
	msg = fromauth(mp, trbuf, tbuf);
	if(msg == 0)
		if(fauth(fd, tbuf) >= 0)
			return;

	/* didn't work, go for the security hole */
	fprint(2, "no authentication server (%s), using your key as server key\n", msg);
}

char*
checkkey(Method *mp, char *name, char *key)
{
	char *msg;
	Ticketreq tr;
	Ticket t;
	char trbuf[TICKREQLEN];
	char tbuf[TICKETLEN];

	memset(&tr, 0, sizeof tr);
	tr.type = AuthTreq;
	strcpy(tr.authid, name);
	strcpy(tr.hostid, name);
	strcpy(tr.uid, name);
	convTR2M(&tr, trbuf);
	msg = fromauth(mp, trbuf, tbuf);
	if(msg)
		return msg;
	if(msg == ccmsg){
		fprint(2, "boot: can't contact auth server, passwd unchecked\n");
		return 0;
	}
	convM2T(tbuf, &t, key);
	if(t.num == AuthTc && strcmp(name, t.cuid)==0)
		return 0;
	return "no match";
}
.
## diffname boot/doauthenticate.c 1993/0402
## diff -e /n/bootesdump/1993/0330/sys/src/9/boot/doauthenticate.c /n/bootesdump/1993/0402/sys/src/9/boot/doauthenticate.c
109a
	if(msg)
		return msg;
.
104,105d
## diffname boot/doauthenticate.c 1993/0501
## diff -e /n/bootesdump/1993/0402/sys/src/9/boot/doauthenticate.c /n/fornaxdump/1993/0501/sys/src/brazil/boot/doauthenticate.c
48,49c
		if(readn(afd, error, ERRLEN) < 0) {
			sprint(error, "%s: %r", pbmsg);
			msg = error;
		}
.
44,45c
		if(readn(afd, tbuf, 2*TICKETLEN) < 0) {
			sprint(error, "%s: %r", pbmsg);
			msg = error;
		}
.
39c
		sprint(error, "%s: %r", pbmsg);
		return error;
.
33,34c
		if(afd < 0) {
			sprint(error, "%s: %r", ccmsg);
			return error;
		}
.
27c
	static char error[2*ERRLEN];
.
## diffname boot/doauthenticate.c 1996/0111
## diff -e /n/fornaxdump/1993/0501/sys/src/brazil/boot/doauthenticate.c /n/fornaxdump/1996/0111/sys/src/brazil/boot/doauthenticate.c
65a

	close(afd);
.
40d
37a

.
29,36c
	if(mp->auth == 0)
		fatal("no method for accessing auth server");
	afd = (*mp->auth)();
	if(afd < 0) {
		sprint(error, "%s: %r", ccmsg);
		return error;
.
24a
	int afd;
.
## diffname boot/doauthenticate.c 1996/1225
## diff -e /n/fornaxdump/1996/0111/sys/src/brazil/boot/doauthenticate.c /n/fornaxdump/1996/1225/sys/src/brazil/boot/doauthenticate.c
15c
		m = read(fd, p+n, len-n);
.
13a
	p = buf;
.
12a
	char *p;
.
9,10c
long
readn(int fd, void *buf, long len)
.
## diffname boot/doauthenticate.c 1997/0327
## diff -e /n/fornaxdump/1996/1225/sys/src/brazil/boot/doauthenticate.c /n/emeliedump/1997/0327/sys/src/brazil/boot/doauthenticate.c
4c
#include "../boot/boot.h"
.
## diffname boot/doauthenticate.c 2001/0527
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/boot/doauthenticate.c /n/emeliedump/2001/0527/sys/src/9/boot/doauthenticate.c
89a
	print("authenticating...");
.
88a
	print("getting ticket...");
.
80c
	if(fsession(fd, trbuf, sizeof trbuf) < 0)
.
59c
			error[ERRMAX-1] = 0;
.
54c
		if(readn(afd, error, ERRMAX) < 0) {
.
30c
	static char error[2*ERRMAX];
.
## diffname boot/doauthenticate.c 2001/0807
## diff -e /n/emeliedump/2001/0527/sys/src/9/boot/doauthenticate.c /n/emeliedump/2001/0807/sys/src/9/boot/doauthenticate.c
88,97c
	print("not authenticated!!!\n");
.
84,85c
	if(authlist[0] == 0)
.
82a
print("boot says session done\n");

.
81a
}
.
80c
	if(fsession(fd, authlist, sizeof authlist) < 0)
{print("boot failed in session: %r\n");
.
76,77c
	char authlist[1024];
.
## diffname boot/doauthenticate.c 2001/0808
## diff -e /n/emeliedump/2001/0807/sys/src/9/boot/doauthenticate.c /n/emeliedump/2001/0808/sys/src/9/boot/doauthenticate.c
90c
	/* try getting to an auth server */
	print("getting ticket...");
	msg = fromauth(mp, trbuf, tbuf);
	print("authenticating...");
	if(msg == 0)
		if(fauth(fd, tbuf) >= 0)
			return;

	/* didn't work, go for the security hole */
	fprint(2, "no authentication server (%s), using your key as server key\n", msg);
.
87c
	memset(tbuf, 0, 2*TICKETLEN);
	if(trbuf[0] == 0)
.
84,85d
82d
79,80c
	if(fsession(fd, trbuf, sizeof trbuf) < 0)
.
76c
	char trbuf[TICKREQLEN];
	char tbuf[2*TICKETLEN];
.

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].