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

📄 bsd-cray.c

📁 OpenSSH 是 SSH (Secure SHell) 协议的免费开源实现。它用安全、加密的网络连接工具代替了 telnet、ftp、 rlogin、rsh 和 rcp 工具。OpenSSH 支持
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  * $Id: bsd-cray.c,v 1.14 2005/02/02 06:10:11 dtucker Exp $ * * bsd-cray.c * * Copyright (c) 2002, Cray Inc.  (Wendy Palm <wendyp@cray.com>) * Significant portions provided by  *          Wayne Schroeder, SDSC <schroeder@sdsc.edu> *          William Jones, UTexas <jones@tacc.utexas.edu> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * * 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. * * Created: Apr 22 16.34:00 2002 wp * * This file contains functions required for proper execution * on UNICOS systems. * */#ifdef _UNICOS#include <udb.h>#include <tmpdir.h>#include <unistd.h>#include <sys/category.h>#include <utmp.h>#include <sys/jtab.h>#include <signal.h>#include <sys/priv.h>#include <sys/secparm.h>#include <sys/tfm.h>#include <sys/usrv.h>#include <sys/sysv.h>#include <sys/sectab.h>#include <sys/secstat.h>#include <sys/stat.h>#include <sys/session.h>#include <stdlib.h>#include <pwd.h>#include <fcntl.h>#include <errno.h>#include <ia.h>#include <urm.h>#include "ssh.h"#include "includes.h"#include "sys/types.h"#ifndef HAVE_STRUCT_SOCKADDR_STORAGE# define      _SS_MAXSIZE     128     /* Implementation specific max size */# define       _SS_PADSIZE     (_SS_MAXSIZE - sizeof (struct sockaddr))# define ss_family ss_sa.sa_family#endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */#ifndef IN6_IS_ADDR_LOOPBACK# define IN6_IS_ADDR_LOOPBACK(a) \	(((u_int32_t *) (a))[0] == 0 && ((u_int32_t *) (a))[1] == 0 && \	 ((u_int32_t *) (a))[2] == 0 && ((u_int32_t *) (a))[3] == htonl (1))#endif /* !IN6_IS_ADDR_LOOPBACK */#ifndef AF_INET6/* Define it to something that should never appear */#define AF_INET6 AF_MAX#endif#include "log.h"#include "servconf.h"#include "bsd-cray.h"#define MAXACID 80extern ServerOptions options;char cray_tmpdir[TPATHSIZ + 1];		    /* job TMPDIR path */struct sysv sysv;	/* system security structure */struct usrv usrv;	/* user security structure *//* * Functions. */void cray_retain_utmp(struct utmp *, int);void cray_delete_tmpdir(char *, int, uid_t);void cray_init_job(struct passwd *);void cray_set_tmpdir(struct utmp *);void cray_login_failure(char *, int);int cray_setup(uid_t, char *, const char *);int cray_access_denied(char *);voidcray_login_failure(char *username, int errcode){	struct udb *ueptr;		/* UDB pointer for username */	ia_failure_t fsent;		/* ia_failure structure */	ia_failure_ret_t fret;		/* ia_failure return stuff */	struct jtab jtab;		/* job table structure */	int jid = 0;			/* job id */	if ((jid = getjtab(&jtab)) < 0)		debug("cray_login_failure(): getjtab error");	getsysudb();	if ((ueptr = getudbnam(username)) == UDB_NULL)		debug("cray_login_failure(): getudbname() returned NULL");	endudb();	memset(&fsent, '\0', sizeof(fsent));	fsent.revision = 0;	fsent.uname = username;	fsent.host = (char *)get_canonical_hostname(options.use_dns);	fsent.ttyn = "sshd";	fsent.caller = IA_SSHD;	fsent.flags = IA_INTERACTIVE;	fsent.ueptr = ueptr;	fsent.jid = jid;	fsent.errcode = errcode;	fsent.pwdp = NULL;	fsent.exitcode = 0;	/* dont exit in ia_failure() */	fret.revision = 0;	fret.normal = 0;	/*	 * Call ia_failure because of an login failure.	 */	ia_failure(&fsent, &fret);}/* *  Cray access denied */intcray_access_denied(char *username){	struct udb *ueptr;		/* UDB pointer for username */	int errcode;			/* IA errorcode */	errcode = 0;	getsysudb();	if ((ueptr = getudbnam(username)) == UDB_NULL)		debug("cray_login_failure(): getudbname() returned NULL");	endudb();	if (ueptr != NULL && ueptr->ue_disabled)		errcode = IA_DISABLED;	if (errcode)		cray_login_failure(username, errcode);	return (errcode);}/* * record_failed_login: generic "login failed" interface function */voidrecord_failed_login(const char *user, const char *hostname, const char *ttyname){	cray_login_failure((char *)user, IA_UDBERR);}intcray_setup (uid_t uid, char *username, const char *command){	extern struct udb *getudb();	extern char *setlimits();	int err;			/* error return */	time_t system_time;		/* current system clock */	time_t expiration_time;		/* password expiration time */	int maxattempts;		/* maximum no. of failed login attempts */	int SecureSys;			/* unicos security flag */	int minslevel = 0;		/* system minimum security level */	int i, j;	int valid_acct = -1;		/* flag for reading valid acct */	char acct_name[MAXACID] = { "" }; /* used to read acct name */	struct jtab jtab;		/* Job table struct */	struct udb ue;			/* udb entry for logging-in user */	struct udb *up;			/* pointer to UDB entry */	struct secstat secinfo;		/* file  security attributes */	struct servprov init_info;	/* used for sesscntl() call */	int jid;			/* job ID */	int pid;			/* process ID */	char *sr;			/* status return from setlimits() */	char *ttyn = NULL;		/* ttyname or command name*/	char hostname[MAXHOSTNAMELEN];	/* passwd stuff for ia_user */	passwd_t pwdacm, pwddialup, pwdudb, pwdwal, pwddce;	ia_user_ret_t uret;		/* stuff returned from ia_user */	ia_user_t usent;		/* ia_user main structure */	int ia_rcode;			/* ia_user return code */	ia_failure_t fsent;		/* ia_failure structure */	ia_failure_ret_t fret;		/* ia_failure return stuff */	ia_success_t ssent;		/* ia_success structure */	ia_success_ret_t sret;		/* ia_success return stuff */	int ia_mlsrcode;		/* ia_mlsuser return code */	int secstatrc;			/* [f]secstat return code */	if (SecureSys = (int)sysconf(_SC_CRAY_SECURE_SYS)) {		getsysv(&sysv, sizeof(struct sysv));		minslevel = sysv.sy_minlvl;		if (getusrv(&usrv) < 0)			fatal("getusrv() failed, errno = %d", errno);	}	hostname[0] = '\0';	strlcpy(hostname,	   (char *)get_canonical_hostname(options.use_dns),	   MAXHOSTNAMELEN);	/*	 *  Fetch user's UDB entry.	 */	getsysudb();	if ((up = getudbnam(username)) == UDB_NULL)		fatal("cannot fetch user's UDB entry");	/*	 *  Prevent any possible fudging so perform a data	 *  safety check and compare the supplied uid against	 *  the udb's uid.	 */	if (up->ue_uid != uid)		fatal("IA uid missmatch");	endudb();	if ((jid = getjtab(&jtab)) < 0) {		debug("getjtab");		return(-1);	}	pid = getpid();	ttyn = ttyname(0);	if (SecureSys) {		if (ttyn != NULL)			secstatrc = secstat(ttyn, &secinfo);		else			secstatrc = fsecstat(1, &secinfo);		if (secstatrc == 0)			debug("[f]secstat() successful");		else			fatal("[f]secstat() error, rc = %d", secstatrc);	}	if ((ttyn == NULL) && ((char *)command != NULL))		ttyn = (char *)command;	/*	 *  Initialize all structures to call ia_user	 */	usent.revision = 0;	usent.uname = username;	usent.host = hostname;	usent.ttyn = ttyn;	usent.caller = IA_SSHD; 	usent.pswdlist = &pwdacm;	usent.ueptr = &ue;	usent.flags = IA_INTERACTIVE | IA_FFLAG;	pwdacm.atype = IA_SECURID;	pwdacm.pwdp = NULL;	pwdacm.next = &pwdudb;	pwdudb.atype = IA_UDB;	pwdudb.pwdp = NULL;	pwdudb.next = &pwddce;	pwddce.atype = IA_DCE;	pwddce.pwdp = NULL;	pwddce.next = &pwddialup;	pwddialup.atype = IA_DIALUP;	pwddialup.pwdp = NULL;	/* pwddialup.next = &pwdwal; */	pwddialup.next = NULL;	pwdwal.atype = IA_WAL;	pwdwal.pwdp = NULL;	pwdwal.next = NULL;	uret.revision = 0;	uret.pswd = NULL;	uret.normal = 0;	ia_rcode = ia_user(&usent, &uret);	switch (ia_rcode) {	/*	 *  These are acceptable return codes from ia_user()	 */	case IA_UDBWEEK:        /* Password Expires in 1 week */		expiration_time = ue.ue_pwage.time + ue.ue_pwage.maxage;		printf ("WARNING - your current password will expire %s\n",		ctime((const time_t *)&expiration_time));		break;	case IA_UDBEXPIRED:		if (ttyname(0) != NULL) {			/* Force a password change */			printf("Your password has expired; Choose a new one.\n");			execl("/bin/passwd", "passwd", username, 0);			exit(9);			}		break;	case IA_NORMAL:         /* Normal Return Code */		break;	case IA_BACKDOOR:		/* XXX: can we memset it to zero here so save some of this */		strlcpy(ue.ue_name, "root", sizeof(ue.ue_name));		strlcpy(ue.ue_dir, "/", sizeof(ue.ue_dir));		strlcpy(ue.ue_shell, "/bin/sh", sizeof(ue.ue_shell));		ue.ue_passwd[0] = '\0';		ue.ue_age[0] = '\0';		ue.ue_comment[0] = '\0';		ue.ue_loghost[0] = '\0';		ue.ue_logline[0] = '\0';		ue.ue_uid = -1;		ue.ue_nice[UDBRC_INTER] = 0;		for (i = 0; i < MAXVIDS; i++)			ue.ue_gids[i] = 0;		ue.ue_logfails = 0;		ue.ue_minlvl = ue.ue_maxlvl = ue.ue_deflvl = minslevel;		ue.ue_defcomps = 0;		ue.ue_comparts = 0;		ue.ue_permits = 0;		ue.ue_trap = 0;		ue.ue_disabled = 0;		ue.ue_logtime = 0;		break;	case IA_CONSOLE:        /* Superuser not from Console */	case IA_TRUSTED:	/* Trusted user */		if (options.permit_root_login > PERMIT_NO)			break;	/* Accept root login */	default:	/*	 *  These are failed return codes from ia_user()	 */		switch (ia_rcode) 		{		case IA_BADAUTH:			printf("Bad authorization, access denied.\n");			break;		case IA_DISABLED:			printf("Your login has been disabled. Contact the system ");			printf("administrator for assistance.\n");			break;		case IA_GETSYSV:			printf("getsysv() failed - errno = %d\n", errno);			break;		case IA_MAXLOGS:			printf("Maximum number of failed login attempts exceeded.\n");			printf("Access denied.\n");			break;		case IA_UDBPWDNULL:			if (SecureSys)				printf("NULL Password not allowed on MLS systems.\n");			break;		default:			break;		}		/*		 *  Authentication failed.		 */		printf("sshd: Login incorrect, (0%o)\n",		    ia_rcode-IA_ERRORCODE);		/*		 *  Initialize structure for ia_failure		 *  which will exit.		 */		fsent.revision = 0;		fsent.uname = username;		fsent.host = hostname;		fsent.ttyn = ttyn;		fsent.caller = IA_SSHD;		fsent.flags = IA_INTERACTIVE;		fsent.ueptr = &ue;		fsent.jid = jid;		fsent.errcode = ia_rcode;		fsent.pwdp = uret.pswd;		fsent.exitcode = 1;		fret.revision = 0;		fret.normal = 0;		/*		*  Call ia_failure because of an IA failure.		*  There is no return because ia_failure exits.		*/		ia_failure(&fsent, &fret);		exit(1); 	}

⌨️ 快捷键说明

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