⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 auth.c

📁 inetutils的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	}	return(1);}/* * This routine is called by the server to start authentication * negotiation. */	voidauth_request(){	static unsigned char str_request[64] = { IAC, SB,						 TELOPT_AUTHENTICATION,						 TELQUAL_SEND, };	TN_Authenticator *ap = authenticators;	unsigned char *e = str_request + 4;	if (!authenticating) {		authenticating = 1;		while (ap->type) {			if (i_support & ~i_wont_support & typemask(ap->type)) {				if (auth_debug_mode) {					printf(">>>%s: Sending type %d %d\r\n",						Name, ap->type, ap->way);				}				*e++ = ap->type;				*e++ = ap->way;			}			++ap;		}		*e++ = IAC;		*e++ = SE;		net_write(str_request, e - str_request);		printsub('>', &str_request[2], e - str_request - 2);	}}/* * This is called when an AUTH SEND is received. * It should never arrive on the server side (as only the server can * send an AUTH SEND). * You should probably respond to it if you can... * * If you want to respond to the types out of order (i.e. even * if he sends  LOGIN KERBEROS and you support both, you respond * with KERBEROS instead of LOGIN (which is against what the * protocol says)) you will have to hack this code... */	voidauth_send(data, cnt)	unsigned char *data;	int cnt;{	TN_Authenticator *ap;	static unsigned char str_none[] = { IAC, SB, TELOPT_AUTHENTICATION,					    TELQUAL_IS, AUTHTYPE_NULL, 0,					    IAC, SE };	if (Server) {		if (auth_debug_mode) {			printf(">>>%s: auth_send called!\r\n", Name);		}		return;	}	if (auth_debug_mode) {		printf(">>>%s: auth_send got:", Name);		printd(data, cnt); printf("\r\n");	}	/*	 * Save the data, if it is new, so that we can continue looking	 * at it if the authorization we try doesn't work	 */	if (data < _auth_send_data ||	    data > _auth_send_data + sizeof(_auth_send_data)) {		auth_send_cnt = cnt > sizeof(_auth_send_data)					? sizeof(_auth_send_data)					: cnt;		memmove((void *)_auth_send_data, (void *)data, auth_send_cnt);		auth_send_data = _auth_send_data;	} else {		/*		 * This is probably a no-op, but we just make sure		 */		auth_send_data = data;		auth_send_cnt = cnt;	}	while ((auth_send_cnt -= 2) >= 0) {		if (auth_debug_mode)			printf(">>>%s: He supports %s (%d) %s (%d)\r\n",			       Name,  AUTHTYPE_NAME_OK(auth_send_data[0]) ?			       AUTHTYPE_NAME(auth_send_data[0]) : 			       "unknown",			       auth_send_data[0],			       auth_send_data[1] & 			       AUTH_HOW_MASK & 			       AUTH_HOW_MUTUAL ? 			       "MUTUAL" : 			       "ONEWAY",			       auth_send_data[1]);		if ((i_support & ~i_wont_support) & typemask(*auth_send_data)) {			ap = findauthenticator(auth_send_data[0],					       auth_send_data[1]);			if (ap && ap->send) {				if (auth_debug_mode)					printf(">>>%s: Trying %s (%d) %s (%d)\r\n",					       Name, 					       AUTHTYPE_NAME_OK(auth_send_data[0]) ?					       AUTHTYPE_NAME(auth_send_data[0]) : 					       "unknown",					       auth_send_data[0],					       auth_send_data[1] & 					       AUTH_HOW_MASK & 					       AUTH_HOW_MUTUAL ? 					       "MUTUAL" : 					       "ONEWAY",					       auth_send_data[1]);				if ((*ap->send)(ap)) {					/*					 * Okay, we found one we like					 * and did it.					 * we can go home now.					 */					if (auth_debug_mode)						printf(">>>%s: Using type %s (%d)\r\n",							Name, 						       AUTHTYPE_NAME_OK(*auth_send_data) ?						       AUTHTYPE_NAME(*auth_send_data) : 						       "unknown",						       *auth_send_data);					auth_send_data += 2;					return;				}			}			/* else			 *	just continue on and look for the			 *	next one if we didn't do anything.			 */		}		auth_send_data += 2;	}	net_write(str_none, sizeof(str_none));	printsub('>', &str_none[2], sizeof(str_none) - 2);	if (auth_debug_mode)		printf(">>>%s: Sent failure message\r\n", Name);	auth_finished(0, AUTH_REJECT);#ifdef KANNAN	/*	 *  We requested strong authentication, however no mechanisms worked.	 *  Therefore, exit on client end.	 */	printf("Unable to securely authenticate user ... exit\n");	exit(0);#endif /* KANNAN */}	voidauth_send_retry(){	/*	 * if auth_send_cnt <= 0 then auth_send will end up rejecting	 * the authentication and informing the other side of this.	 */	auth_send(auth_send_data, auth_send_cnt);}	voidauth_is(data, cnt)	unsigned char *data;	int cnt;{	TN_Authenticator *ap;	if (cnt < 2)		return;	if (data[0] == AUTHTYPE_NULL) {		auth_finished(0, AUTH_REJECT);		return;	}	if (ap = findauthenticator(data[0], data[1])) {		if (ap->is)			(*ap->is)(ap, data+2, cnt-2);	} else if (auth_debug_mode)		printf(">>>%s: Invalid authentication in IS: %d\r\n",			Name, *data);}	voidauth_reply(data, cnt)	unsigned char *data;	int cnt;{	TN_Authenticator *ap;	if (cnt < 2)		return;	if (ap = findauthenticator(data[0], data[1])) {		if (ap->reply)			(*ap->reply)(ap, data+2, cnt-2);	} else if (auth_debug_mode)		printf(">>>%s: Invalid authentication in SEND: %d\r\n",			Name, *data);}	voidauth_name(data, cnt)	unsigned char *data;	int cnt;{	TN_Authenticator *ap;	unsigned char savename[256];	if (cnt < 1) {		if (auth_debug_mode)			printf(">>>%s: Empty name in NAME\r\n", Name);		return;	}	if (cnt > sizeof(savename) - 1) {		if (auth_debug_mode)			printf(">>>%s: Name in NAME (%d) exceeds %d length\r\n",					Name, cnt, sizeof(savename)-1);		return;	}	memmove((void *)savename, (void *)data, cnt);	savename[cnt] = '\0';	/* Null terminate */	if (auth_debug_mode)		printf(">>>%s: Got NAME [%s]\r\n", Name, savename);	auth_encrypt_user(savename);}	intauth_sendname(cp, len)	unsigned char *cp;	int len;{	static unsigned char str_request[256+6]			= { IAC, SB, TELOPT_AUTHENTICATION, TELQUAL_NAME, };	register unsigned char *e = str_request + 4;	register unsigned char *ee = &str_request[sizeof(str_request)-2];	while (--len >= 0) {		if ((*e++ = *cp++) == IAC)			*e++ = IAC;		if (e >= ee)			return(0);	}	*e++ = IAC;	*e++ = SE;	net_write(str_request, e - str_request);	printsub('>', &str_request[2], e - &str_request[2]);	return(1);}	voidauth_finished(ap, result)	TN_Authenticator *ap;	int result;{	if (!(authenticated = ap))		authenticated = &NoAuth;	validuser = result;}	/* ARGSUSED */	static voidauth_intr(sig)	int sig;{	auth_finished(0, AUTH_REJECT);}	intauth_wait(name)	char *name;{	if (auth_debug_mode)		printf(">>>%s: in auth_wait.\r\n", Name);	if (Server && !authenticating)		return(0);	(void) signal(SIGALRM, auth_intr);	alarm(30);	while (!authenticated)		if (telnet_spin())			break;	alarm(0);	(void) signal(SIGALRM, SIG_DFL);	/*	 * Now check to see if the user is valid or not	 */	if (!authenticated || authenticated == &NoAuth)		return(AUTH_REJECT);	if (validuser == AUTH_VALID)		validuser = AUTH_USER;	if (authenticated->status)		validuser = (*authenticated->status)(authenticated,						     name, validuser);	return(validuser);}	voidauth_debug(mode)	int mode;{	auth_debug_mode = mode;}	voidauth_printsub(data, cnt, buf, buflen)	unsigned char *data, *buf;	int cnt, buflen;{	TN_Authenticator *ap;	if ((ap = findauthenticator(data[1], data[2])) && ap->printsub)		(*ap->printsub)(data, cnt, buf, buflen);	else		auth_gen_printsub(data, cnt, buf, buflen);}	voidauth_gen_printsub(data, cnt, buf, buflen)	unsigned char *data, *buf;	int cnt, buflen;{	register unsigned char *cp;	unsigned char tbuf[16];	cnt -= 3;	data += 3;	buf[buflen-1] = '\0';	buf[buflen-2] = '*';	buflen -= 2;	for (; cnt > 0; cnt--, data++) {		sprintf((char *)tbuf, " %d", *data);		for (cp = tbuf; *cp && buflen > 0; --buflen)			*buf++ = *cp++;		if (buflen <= 0)			return;	}	*buf = '\0';}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -