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

📄 ruserpass.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
字号:
#ifndef lintstatic	char	*sccsid = "@(#)ruserpass.c	4.4	(ULTRIX)	1/3/91";#endif lint/************************************************************************ *									* *			Copyright (c) 1983,1990 by			* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any  other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived  from  software  received  from  the	* *   University    of   California,   Berkeley,   and   from   Bell	* *   Laboratories.  Use, duplication, or disclosure is  subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or  reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************//*  * Derived from: * Copyright (c) 1982 Regents of the University of California * static char sccsid[] = "@(#)ruserpass.c 4.2 10/10/82"; *//* * Modification History: * * 02-Jan-91	jsd *	Use old version of ruserpass here (*without* macdef support) and *	place newer version in the ftp source directory.  The old *	version stay here for use with rexec() in libc.a. * * 10-Jul-90	jsd *	upgrade to 4.3BSD with macdef support, etc. * * 15-Sep-89	reeves *	environ->__environ for ANSI (even though it's not usually present) * * 27-Jan-88	logcher *	Added two casts - void to sprintf * * 21-Feb-84	Dave Borman *	#ifdef CRYPT added.  This is to remove decryption from *	the product so that we can ship it overseas. The ramafacations *	of this is that ruserpass will no longer look in your  *	environment for an encrypted password for remote logins. * */#include <stdio.h>#include <ctype.h>#include <sys/types.h>#include <sys/stat.h>#include <errno.h>#ifndef CRYPTchar	*malloc(), *index(), *getpass(), *getlogin();#endif	CRYPTstatic	FILE *cfile;#define MAXLEN_USER 66	/* host, 2 colons, username */ruserpass(host, aname, apass)	char *host, **aname, **apass;{	if (*aname == 0 || *apass == 0)		rnetrc(host, aname, apass);	if (*aname == 0) {		char *myname = getlogin();		*aname = malloc(MAXLEN_USER+1);		printf("Name (%s:%s): ", host, myname);		fflush(stdout);		if (read(2, *aname, MAXLEN_USER) <= 0)			exit(1);		if ((*aname)[0] == '\n')			*aname = myname;		else			if (index(*aname, '\n'))				*index(*aname, '\n') = 0;	}	if (*aname && *apass == 0) {		printf("Password (%s:%s): ", host, *aname);		fflush(stdout);		*apass = getpass("");	}}#define	DEFAULT	1#define	LOGIN	2#define	PASSWD	3#define	NOTIFY	4#define	WRITE	5#define	YES	6#define	NO	7#define	COMMAND	8#define	FORCE	9#define	ID	10#define	MACHINE	11static char tokval[100];static struct toktab {	char *tokstr;	int tval;} toktab[]= {	"default",	DEFAULT,	"login",	LOGIN,	"password",	PASSWD,	"notify",	NOTIFY,	"write",	WRITE,	"yes",		YES,	"y",		YES,	"no",		NO,	"n",		NO,	"command",	COMMAND,	"force",	FORCE,	"machine",	MACHINE,	0,		0};staticrnetrc(host, aname, apass)	char *host, **aname, **apass;{	char *hdir, buf[BUFSIZ];	int t;	struct stat stb;	extern int errno;	char *getenv();	hdir = getenv("HOME");	if (hdir == NULL)		hdir = ".";	(void)sprintf(buf, "%s/.netrc", hdir);	cfile = fopen(buf, "r");	if (cfile == NULL) {		if (errno != ENOENT)			perror(buf);		return;	}next:	while ((t = token())) switch(t) {	case DEFAULT:		(void) token();		continue;	case MACHINE:		if (token() != ID || strcmp(host, tokval))			continue;		while ((t = token()) && t != MACHINE) switch(t) {		case LOGIN:			if (token())				if (*aname == 0) { 					*aname = malloc(strlen(tokval) + 1);					strcpy(*aname, tokval);				} else {					if (strcmp(*aname, tokval))						goto next;				}			break;		case PASSWD:			if (fstat(fileno(cfile), &stb) >= 0			    && (stb.st_mode & 077) != 0) {	fprintf(stderr, "Error - .netrc file not correct mode.\n");	fprintf(stderr, "Remove password or correct mode.\n");				exit(1);			}			if (token() && *apass == 0) {				*apass = malloc(strlen(tokval) + 1);				strcpy(*apass, tokval);			}			break;		case COMMAND:		case NOTIFY:		case WRITE:		case FORCE:			(void) token();			break;		default:	fprintf(stderr, "Unknown .netrc option %s\n", tokval);			break;		}		goto done;	}done:	fclose(cfile);}statictoken(){	char *cp;	int c;	struct toktab *t;	if (feof(cfile))		return (0);	while ((c = getc(cfile)) != EOF &&	    (c == '\n' || c == '\t' || c == ' ' || c == ','))		continue;	if (c == EOF)		return (0);	cp = tokval;	if (c == '"') {		while ((c = getc(cfile)) != EOF && c != '"') {			if (c == '\\')				c = getc(cfile);			*cp++ = c;		}	} else {		*cp++ = c;		while ((c = getc(cfile)) != EOF		    && c != '\n' && c != '\t' && c != ' ' && c != ',') {			if (c == '\\')				c = getc(cfile);			*cp++ = c;		}	}	*cp = 0;	if (tokval[0] == 0)		return (0);	for (t = toktab; t->tokstr; t++)		if (!strcmp(t->tokstr, tokval))			return (t->tval);	return (ID);}

⌨️ 快捷键说明

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