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

📄 bsd-cray.c

📁 OpenSSH 是 SSH (Secure SHell) 协议的免费开源实现。它用安全、加密的网络连接工具代替了 telnet、ftp、 rlogin、rsh 和 rcp 工具。OpenSSH 支持
💻 C
📖 第 1 页 / 共 2 页
字号:
	ia_mlsrcode = IA_NORMAL;	if (SecureSys) {		debug("calling ia_mlsuser()");		ia_mlsrcode = ia_mlsuser(&ue, &secinfo, &usrv, NULL, 0);	}	if (ia_mlsrcode != IA_NORMAL) {		printf("sshd: Login incorrect, (0%o)\n",		    ia_mlsrcode-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_mlsrcode;		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); 	}	/* Provide login status information */	if (options.print_lastlog && ue.ue_logtime != 0) {		printf("Last successful login was : %.*s ", 19,		    (char *)ctime(&ue.ue_logtime));		if (*ue.ue_loghost != '\0') {			printf("from %.*s\n", sizeof(ue.ue_loghost),			    ue.ue_loghost);		} else {			printf("on %.*s\n", sizeof(ue.ue_logline),			    ue.ue_logline);		}		if (SecureSys && (ue.ue_logfails != 0)) {			printf("  followed by %d failed attempts\n",			    ue.ue_logfails);		}	}	/*	 * Call ia_success to process successful I/A.	 */	ssent.revision = 0;	ssent.uname = username;	ssent.host = hostname;	ssent.ttyn = ttyn;	ssent.caller = IA_SSHD;	ssent.flags = IA_INTERACTIVE;	ssent.ueptr = &ue;	ssent.jid = jid;	ssent.errcode = ia_rcode;	ssent.us = NULL;	ssent.time = 1;	/* Set ue_logtime */	sret.revision = 0;	sret.normal = 0;	ia_success(&ssent, &sret);	/*	 * Query for account, iff > 1 valid acid & askacid permbit	 */	if (((ue.ue_permbits & PERMBITS_ACCTID) ||	    (ue.ue_acids[0] >= 0) && (ue.ue_acids[1] >= 0)) &&	    ue.ue_permbits & PERMBITS_ASKACID) {		if (ttyname(0) != NULL) {			debug("cray_setup: ttyname true case, %.100s", ttyname);			while (valid_acct == -1) {				printf("Account (? for available accounts)"				    " [%s]: ", acid2nam(ue.ue_acids[0]));				fgets(acct_name, MAXACID, stdin);				switch (acct_name[0]) {				case EOF:					exit(0);					break;				case '\0':					valid_acct = ue.ue_acids[0];					strlcpy(acct_name, acid2nam(valid_acct), MAXACID);					break;				case '?':					/* Print the list 3 wide */					for (i = 0, j = 0; i < MAXVIDS; i++) {						if (ue.ue_acids[i] == -1) {							printf("\n");							break;						}						if (++j == 4) {							j = 1;							printf("\n");						}						printf(" %s",						    acid2nam(ue.ue_acids[i]));					}					if (ue.ue_permbits & PERMBITS_ACCTID) {						printf("\"acctid\" permbit also allows"						    " you to select any valid "						    "account name.\n");					}					printf("\n");					break;				default:					valid_acct = nam2acid(acct_name);					if (valid_acct == -1) 						printf(						    "Account id not found for"						    " account name \"%s\"\n\n",						    acct_name);					break;				}				/*				 * If an account was given, search the user's				 * acids array to verify they can use this account.				 */				if ((valid_acct != -1) &&				    !(ue.ue_permbits & PERMBITS_ACCTID)) {					for (i = 0; i < MAXVIDS; i++) {						if (ue.ue_acids[i] == -1)							break;						if (valid_acct == ue.ue_acids[i])							break;					}					if (i == MAXVIDS ||					    ue.ue_acids[i] == -1) {						fprintf(stderr, "Cannot set"						    " account name to "						    "\"%s\", permission "						    "denied\n\n", acct_name);						valid_acct = -1;					}				}			}		} else {			/*			 * The client isn't connected to a terminal and can't			 * respond to an acid prompt.  Use default acid.			 */			debug("cray_setup: ttyname false case, %.100s",			    ttyname);			valid_acct = ue.ue_acids[0];		}	} else {		/*		 * The user doesn't have the askacid permbit set or		 * only has one valid account to use.		 */		valid_acct = ue.ue_acids[0];	}	if (acctid(0, valid_acct) < 0) {		printf ("Bad account id: %d\n", valid_acct);		exit(1);	}	/* 	 * Now set shares, quotas, limits, including CPU time for the 	 * (interactive) job and process, and set up permissions 	 * (for chown etc), etc.	 */	if (setshares(ue.ue_uid, valid_acct, printf, 0, 0)) {		printf("Unable to give %d shares to <%s>(%d/%d)\n",		    ue.ue_shares, ue.ue_name, ue.ue_uid, valid_acct);		exit(1);	}	sr = setlimits(username, C_PROC, pid, UDBRC_INTER);	if (sr != NULL) {		debug("%.200s", sr);		exit(1);	}	sr = setlimits(username, C_JOB, jid, UDBRC_INTER);	if (sr != NULL) {		debug("%.200s", sr);		exit(1);	}	/*	 * Place the service provider information into	 * the session table (Unicos) or job table (Unicos/mk).	 * There exist double defines for the job/session table in	 * unicos/mk (jtab.h) so no need for a compile time switch.	 */	memset(&init_info, '\0', sizeof(init_info));	init_info.s_sessinit.si_id = URM_SPT_LOGIN;	init_info.s_sessinit.si_pid = getpid();	init_info.s_sessinit.si_sid = jid;	sesscntl(0, S_SETSERVPO, (int)&init_info);	/*	 * Set user and controlling tty security attributes.	 */	if (SecureSys) {		if (setusrv(&usrv) == -1) {			debug("setusrv() failed, errno = %d",errno);			exit(1);		}	}	return (0);}/* * The rc.* and /etc/sdaemon methods of starting a program on unicos/unicosmk * can have pal privileges that sshd can inherit which * could allow a user to su to root with out a password. * This subroutine clears all privileges. */voiddrop_cray_privs(){#if defined(_SC_CRAY_PRIV_SU)	priv_proc_t *privstate;	int result;	extern int priv_set_proc();	extern priv_proc_t *priv_init_proc();	/*	 * If ether of theses two flags are not set	 * then don't allow this version of ssh to run.	 */	if (!sysconf(_SC_CRAY_PRIV_SU))		fatal("Not PRIV_SU system.");	if (!sysconf(_SC_CRAY_POSIX_PRIV))		fatal("Not POSIX_PRIV.");	debug("Setting MLS labels.");;	if (sysconf(_SC_CRAY_SECURE_MAC)) {		usrv.sv_minlvl = SYSLOW;		usrv.sv_actlvl = SYSHIGH;		usrv.sv_maxlvl = SYSHIGH;	} else {		usrv.sv_minlvl = sysv.sy_minlvl;		usrv.sv_actlvl = sysv.sy_minlvl;		usrv.sv_maxlvl = sysv.sy_maxlvl;	}       	usrv.sv_actcmp = 0;	usrv.sv_valcmp = sysv.sy_valcmp;	usrv.sv_intcat = TFM_SYSTEM;	usrv.sv_valcat |= (TFM_SYSTEM | TFM_SYSFILE);	if (setusrv(&usrv) < 0) {		fatal("%s(%d): setusrv(): %s", __FILE__, __LINE__,		    strerror(errno));	}	if ((privstate = priv_init_proc()) != NULL) {		result = priv_set_proc(privstate);		if (result != 0 ) {			fatal("%s(%d): priv_set_proc(): %s",			    __FILE__, __LINE__, strerror(errno));		}		priv_free_proc(privstate);	}	debug ("Privileges should be cleared...");#else	/* XXX: do this differently */#	error Cray systems must be run with _SC_CRAY_PRIV_SU on!#endif}/* *  Retain utmp/wtmp information - used by cray accounting. */voidcray_retain_utmp(struct utmp *ut, int pid){	int fd;	struct utmp utmp;	if ((fd = open(UTMP_FILE, O_RDONLY)) != -1) {		/* XXX use atomicio */		while (read(fd, (char *)&utmp, sizeof(utmp)) == sizeof(utmp)) {			if (pid == utmp.ut_pid) {				ut->ut_jid = utmp.ut_jid;				strncpy(ut->ut_tpath, utmp.ut_tpath, sizeof(utmp.ut_tpath));				strncpy(ut->ut_host, utmp.ut_host, sizeof(utmp.ut_host));				strncpy(ut->ut_name, utmp.ut_name, sizeof(utmp.ut_name));				break;			}		}		close(fd);	} else		fatal("Unable to open utmp file");}/* * tmpdir support. *//* * find and delete jobs tmpdir. */voidcray_delete_tmpdir(char *login, int jid, uid_t uid){	static char jtmp[TPATHSIZ];	struct stat statbuf;	int child, c, wstat;	for (c = 'a'; c <= 'z'; c++) {		snprintf(jtmp, TPATHSIZ, "%s/jtmp.%06d%c", JTMPDIR, jid, c);		if (stat(jtmp, &statbuf) == 0 && statbuf.st_uid == uid)			break;	}	if (c > 'z')		return;	if ((child = fork()) == 0) {		execl(CLEANTMPCMD, CLEANTMPCMD, login, jtmp, (char *)NULL);		fatal("cray_delete_tmpdir: execl of CLEANTMPCMD failed");	}	while (waitpid(child, &wstat, 0) == -1 && errno == EINTR)		;}/* * Remove tmpdir on job termination. */voidcray_job_termination_handler(int sig){	int jid;	char *login = NULL;	struct jtab jtab;	debug("received signal %d",sig);	if ((jid = waitjob(&jtab)) == -1 ||	    (login = uid2nam(jtab.j_uid)) == NULL)		return;	cray_delete_tmpdir(login, jid, jtab.j_uid);}/* * Set job id and create tmpdir directory. */voidcray_init_job(struct passwd *pw){	int jid;	int c;	jid = setjob(pw->pw_uid, WJSIGNAL);	if (jid < 0)		fatal("System call setjob failure");	for (c = 'a'; c <= 'z'; c++) {		snprintf(cray_tmpdir, TPATHSIZ, "%s/jtmp.%06d%c", JTMPDIR, jid, c);		if (mkdir(cray_tmpdir, JTMPMODE) != 0)			continue;		if (chown(cray_tmpdir,	pw->pw_uid, pw->pw_gid) != 0) {			rmdir(cray_tmpdir);			continue;		}		break;	}	if (c > 'z')		cray_tmpdir[0] = '\0';}voidcray_set_tmpdir(struct utmp *ut){	int jid;	struct jtab jbuf;	if ((jid = getjtab(&jbuf)) < 0)		return;	/*	 * Set jid and tmpdir in utmp record.	 */	ut->ut_jid = jid;	strncpy(ut->ut_tpath, cray_tmpdir, TPATHSIZ);}#endif /* UNICOS */#ifdef _UNICOSMP#include <pwd.h>/* * Set job id and create tmpdir directory. */voidcray_init_job(struct passwd *pw){	initrm_silent(pw->pw_uid);	return;}#endif /* _UNICOSMP */

⌨️ 快捷键说明

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