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

📄 method_uname.c

📁 sock protocol ,it is useful!
💻 C
字号:
/* * Copyright (c) 1997, 1998, 1999 *      Inferno Nettverk A/S, Norway.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. The above copyright notice, this list of conditions and the following *    disclaimer must appear in all copies of the software, derivative works *    or modified versions, and any portions thereof, aswell as in all *    supporting documentation. * 2. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *      This product includes software developed by *      Inferno Nettverk A/S, Norway. * 3. The name of the author may not be used to endorse or promote products *    derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * Inferno Nettverk A/S requests users of this software to return to * *  Software Distribution Coordinator  or  sdc@inet.no *  Inferno Nettverk A/S *  Oslo Research Park *  Gaustadal閑n 21 *  N-0349 Oslo *  Norway * * any improvements or extensions that they make and grant Inferno Nettverk A/S * the rights to redistribute these changes. * */#include "common.h"static const char rcsid[] ="$Id: method_uname.c,v 1.30 1999/12/22 09:29:25 karls Exp $";__BEGIN_DECLSstatic intrecv_unamever __P((int s, struct request_t *request,						 struct negotiate_state_t *state));static intrecv_ulen __P((int s, struct request_t *request,					struct negotiate_state_t *state));static intrecv_uname __P((int s, struct request_t *request,					 struct negotiate_state_t *state));static intrecv_plen __P((int s, struct request_t *request,					struct negotiate_state_t *state));static intrecv_passwd __P((int s, struct request_t *request,					  struct negotiate_state_t *state));__END_DECLSintmethod_uname(s, request, state)	int s;	struct request_t *request;	struct negotiate_state_t *state;{	state->rcurrent = recv_unamever;	return state->rcurrent(s, request, state);}static intrecv_unamever(s, request, state)	int s;	struct request_t *request;	struct negotiate_state_t *state;{	INIT(sizeof(request->auth->mdata.uname.version));	CHECK(&request->auth->mdata.uname.version, NULL);	switch (request->auth->mdata.uname.version) {		case SOCKS_UNAMEVERSION:			break;		default:			slog(LOG_DEBUG, "unknown version on uname packet from client: %d",			request->auth->mdata.uname.version);			return -1;	}	state->rcurrent = recv_ulen;	return state->rcurrent(s, request, state);}static intrecv_ulen(s, request, state)	int s;	struct request_t *request;	struct negotiate_state_t *state;{	INIT(sizeof(*request->auth->mdata.uname.name));	CHECK(request->auth->mdata.uname.name, NULL);	OCTETIFY(*request->auth->mdata.uname.name);	state->rcurrent = recv_uname;	return state->rcurrent(s, request, state);}static intrecv_uname(s, request, state)	int s;	struct request_t *request;	struct negotiate_state_t *state;{	const size_t ulen = (size_t)*request->auth->mdata.uname.name;	INIT(ulen);	CHECK(request->auth->mdata.uname.name + 1, NULL);	/* convert to string. */	memcpy(request->auth->mdata.uname.name, request->auth->mdata.uname.name + 1,	ulen);	request->auth->mdata.uname.name[ulen] = NUL;	state->rcurrent = recv_plen;	return state->rcurrent(s, request, state);}static intrecv_plen(s, request, state)	int s;	struct request_t *request;	struct negotiate_state_t *state;{	INIT(sizeof(*request->auth->mdata.uname.password));	CHECK(request->auth->mdata.uname.password, NULL);	OCTETIFY(*request->auth->mdata.uname.password);	state->rcurrent = recv_passwd;	return state->rcurrent(s, request, state);}static intrecv_passwd(s, request, state)	int s;	struct request_t *request;	struct negotiate_state_t *state;{/*	const char *function = "recv_passwd()"; */	const size_t plen = (size_t)*request->auth->mdata.uname.password;	int status;	unsigned char response[1				/* version. */								+ 1				/* status.	*/	];	INIT(plen);	CHECK(request->auth->mdata.uname.password + 1, NULL);	/* convert to string. */	memcpy(request->auth->mdata.uname.password,	request->auth->mdata.uname.password + 1, plen);	request->auth->mdata.uname.password[plen] = NUL;	switch (status	= (unsigned char) passwordcheck(request->auth->mdata.uname.name,	request->auth->mdata.uname.password)) {		case 0:			request->auth->matched = 1;			break; /* ok. */		case 1: {				char *name = request->auth->mdata.uname.name;				snprintf(state->emsg, sizeof(state->emsg),				"denied access to non-existing user \"%s\"",				strcheck(name = str2vis(name, strlen(name))));				free(name);				break;		}		case 2: {				char *name = request->auth->mdata.uname.name;				snprintf(state->emsg, sizeof(state->emsg),				"password authentication failed for user \"%s\"",				strcheck(name = str2vis(name, strlen(name))));				free(name);				break;		}		default:			SERRX(status);	}	bzero(request->auth->mdata.uname.password,	sizeof(request->auth->mdata.uname.password));	response[UNAME_VERSION] = request->auth->mdata.uname.version;	response[UNAME_STATUS]	= (unsigned char)status;	if (writen(s, response, sizeof(response)) != sizeof(response))		return -1;	if (status == 0) {	/* 0 is success. */		state->rcurrent = recv_sockspacket;		return state->rcurrent(s, request, state);	}	errno = 0;	return -1;}

⌨️ 快捷键说明

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