- (stevesk) sshpty.c, cray.[ch]: whitespace, formatting and cleanup
for some #ifdef _CRAY code; ok wendyp@cray.com
This commit is contained in:
parent
56cb92968b
commit
f744b512f3
|
@ -1,3 +1,7 @@
|
||||||
|
/*
|
||||||
|
* XXX: license?
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The modules contains code to support cray t3e and sv1 computers.
|
* The modules contains code to support cray t3e and sv1 computers.
|
||||||
* It is here to minimize the modifcations to the openssh base code.
|
* It is here to minimize the modifcations to the openssh base code.
|
||||||
|
@ -25,7 +29,7 @@
|
||||||
|
|
||||||
#include "bsd-cray.h"
|
#include "bsd-cray.h"
|
||||||
|
|
||||||
char cray_tmpdir[TPATHSIZ+1]; /* job TMPDIR path */
|
char cray_tmpdir[TPATHSIZ+1]; /* job TMPDIR path */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Functions.
|
* Functions.
|
||||||
|
@ -47,55 +51,59 @@ void cray_set_tmpdir(struct utmp *);
|
||||||
void
|
void
|
||||||
cray_setup(uid_t uid, char *username)
|
cray_setup(uid_t uid, char *username)
|
||||||
{
|
{
|
||||||
struct udb *p;
|
struct udb *p;
|
||||||
extern char *setlimits();
|
extern char *setlimits();
|
||||||
int i, j;
|
int i, j;
|
||||||
int accts[MAXVIDS];
|
int accts[MAXVIDS];
|
||||||
int naccts;
|
int naccts;
|
||||||
int err;
|
int err;
|
||||||
char *sr;
|
char *sr;
|
||||||
int pid;
|
int pid;
|
||||||
struct jtab jbuf;
|
struct jtab jbuf;
|
||||||
int jid;
|
int jid;
|
||||||
|
|
||||||
if ((jid = getjtab (&jbuf)) < 0) fatal("getjtab: no jid");
|
if ((jid = getjtab(&jbuf)) < 0)
|
||||||
|
fatal("getjtab: no jid");
|
||||||
|
|
||||||
err = setudb(); /* open and rewind the Cray User DataBase */
|
err = setudb(); /* open and rewind the Cray User DataBase */
|
||||||
if(err != 0) fatal("UDB open failure");
|
if (err != 0)
|
||||||
naccts = 0;
|
fatal("UDB open failure");
|
||||||
|
naccts = 0;
|
||||||
p = getudbnam(username);
|
p = getudbnam(username);
|
||||||
if (p == NULL) fatal("No UDB entry for %s", username);
|
if (p == NULL)
|
||||||
if(uid != p->ue_uid)
|
fatal("No UDB entry for %.100s", username);
|
||||||
fatal("UDB etnry %s uid(%d) does not match uid %d\n",
|
if (uid != p->ue_uid)
|
||||||
username, p->ue_uid, uid);
|
fatal("UDB etnry %.100s uid(%d) does not match uid %d",
|
||||||
for(j = 0; p->ue_acids[j] != -1 && j < MAXVIDS; j++) {
|
username, p->ue_uid, uid);
|
||||||
accts[naccts] = p->ue_acids[j];
|
for (j = 0; p->ue_acids[j] != -1 && j < MAXVIDS; j++) {
|
||||||
naccts++;
|
accts[naccts] = p->ue_acids[j];
|
||||||
}
|
naccts++;
|
||||||
endudb(); /* close the udb */
|
}
|
||||||
|
endudb(); /* close the udb */
|
||||||
|
|
||||||
if (naccts != 0) {
|
if (naccts != 0) {
|
||||||
/* Perhaps someday we'll prompt users who have multiple accounts
|
/* Perhaps someday we'll prompt users who have multiple accounts
|
||||||
to let them pick one (like CRI's login does), but for now just set
|
to let them pick one (like CRI's login does), but for now just set
|
||||||
the account to the first entry. */
|
the account to the first entry. */
|
||||||
if (acctid(0, accts[0]) < 0)
|
if (acctid(0, accts[0]) < 0)
|
||||||
fatal("System call acctid failed, accts[0]=%d",accts[0]);
|
fatal("System call acctid failed, accts[0]=%d", accts[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now set limits, including CPU time for the (interactive) job and process,
|
/* Now set limits, including CPU time for the (interactive) job and process,
|
||||||
and set up permissions (for chown etc), etc. This is via an internal CRI
|
and set up permissions (for chown etc), etc. This is via an internal CRI
|
||||||
routine, setlimits, used by CRI's login. */
|
routine, setlimits, used by CRI's login. */
|
||||||
|
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
sr = setlimits(username, C_PROC, pid, UDBRC_INTER);
|
sr = setlimits(username, C_PROC, pid, UDBRC_INTER);
|
||||||
if (sr != NULL) fatal("%.200s", sr);
|
if (sr != NULL)
|
||||||
|
fatal("%.200s", sr);
|
||||||
|
|
||||||
sr = setlimits(username, C_JOB, jid, UDBRC_INTER);
|
sr = setlimits(username, C_JOB, jid, UDBRC_INTER);
|
||||||
if (sr != NULL) fatal("%.200s", sr);
|
if (sr != NULL)
|
||||||
|
fatal("%.200s", sr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The rc.* and /etc/sdaemon methods of starting a program on unicos/unicosmk
|
* The rc.* and /etc/sdaemon methods of starting a program on unicos/unicosmk
|
||||||
* can have pal privileges that sshd can inherit which
|
* can have pal privileges that sshd can inherit which
|
||||||
|
@ -106,34 +114,39 @@ void
|
||||||
drop_cray_privs()
|
drop_cray_privs()
|
||||||
{
|
{
|
||||||
#if defined(_SC_CRAY_PRIV_SU)
|
#if defined(_SC_CRAY_PRIV_SU)
|
||||||
priv_proc_t* privstate;
|
priv_proc_t* privstate;
|
||||||
int result;
|
int result;
|
||||||
extern int priv_set_proc();
|
extern int priv_set_proc();
|
||||||
extern priv_proc_t* priv_init_proc();
|
extern priv_proc_t* priv_init_proc();
|
||||||
struct usrv usrv;
|
struct usrv usrv;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If ether of theses two flags are not set
|
* If ether of theses two flags are not set
|
||||||
* then don't allow this version of ssh to run.
|
* 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_PRIV_SU))
|
||||||
if (!sysconf(_SC_CRAY_POSIX_PRIV)) fatal("Not POSIX_PRIV.");
|
fatal("Not PRIV_SU system.");
|
||||||
|
if (!sysconf(_SC_CRAY_POSIX_PRIV))
|
||||||
|
fatal("Not POSIX_PRIV.");
|
||||||
|
|
||||||
debug ("Dropping privileges.");
|
debug("Dropping privileges.");
|
||||||
|
|
||||||
memset(&usrv, 0, sizeof(usrv));
|
memset(&usrv, 0, sizeof(usrv));
|
||||||
if (setusrv(&usrv) < 0)
|
if (setusrv(&usrv) < 0)
|
||||||
fatal ("%s(%d): setusrv(): %s\n", __FILE__, __LINE__, strerror(errno));
|
fatal("%s(%d): setusrv(): %s\n", __FILE__, __LINE__,
|
||||||
|
strerror(errno));
|
||||||
|
|
||||||
if ((privstate = priv_init_proc()) != NULL) {
|
if ((privstate = priv_init_proc()) != NULL) {
|
||||||
result = priv_set_proc(privstate);
|
result = priv_set_proc(privstate);
|
||||||
if ( result != 0 ) fatal ("%s(%d): priv_set_proc(): %s\n",
|
if (result != 0 )
|
||||||
__FILE__, __LINE__, strerror(errno));
|
fatal("%s(%d): priv_set_proc(): %s\n",
|
||||||
priv_free_proc(privstate);
|
__FILE__, __LINE__, strerror(errno));
|
||||||
}
|
priv_free_proc(privstate);
|
||||||
debug ("Privileges should be cleared...");
|
}
|
||||||
|
debug ("Privileges should be cleared...");
|
||||||
#else
|
#else
|
||||||
Cray systems must be run with _SC_CRAY_PRIV_SU on!
|
/* XXX: do this differently */
|
||||||
|
# error Cray systems must be run with _SC_CRAY_PRIV_SU on!
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,20 +158,21 @@ void
|
||||||
cray_retain_utmp(struct utmp *ut, int pid)
|
cray_retain_utmp(struct utmp *ut, int pid)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct utmp utmp;
|
struct utmp utmp;
|
||||||
|
|
||||||
if ((fd = open(UTMP_FILE, O_RDONLY)) >= 0) {
|
if ((fd = open(UTMP_FILE, O_RDONLY)) != -1) {
|
||||||
while (read(fd, (char *)&utmp, sizeof(utmp)) == sizeof(utmp)) {
|
while (read(fd, (char *)&utmp, sizeof(utmp)) == sizeof(utmp)) {
|
||||||
if (pid == utmp.ut_pid) {
|
if (pid == utmp.ut_pid) {
|
||||||
ut->ut_jid = utmp.ut_jid;
|
ut->ut_jid = utmp.ut_jid;
|
||||||
strncpy(ut->ut_tpath, utmp.ut_tpath, TPATHSIZ);
|
strncpy(ut->ut_tpath, utmp.ut_tpath, TPATHSIZ);
|
||||||
strncpy(ut->ut_host, utmp.ut_host, strlen(utmp.ut_host));
|
strncpy(ut->ut_host, utmp.ut_host, strlen(utmp.ut_host));
|
||||||
strncpy(ut->ut_name, utmp.ut_name, strlen(utmp.ut_name));
|
strncpy(ut->ut_name, utmp.ut_name, strlen(utmp.ut_name));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
/* XXX: error message? */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -172,31 +186,34 @@ void
|
||||||
cray_delete_tmpdir(char *login, int jid, uid_t uid)
|
cray_delete_tmpdir(char *login, int jid, uid_t uid)
|
||||||
{
|
{
|
||||||
int child;
|
int child;
|
||||||
static char jtmp[TPATHSIZ];
|
static char jtmp[TPATHSIZ];
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
int c;
|
int c;
|
||||||
int wstat;
|
int wstat;
|
||||||
|
|
||||||
for (c = 'a'; c <= 'z'; c++) {
|
for (c = 'a'; c <= 'z'; c++) {
|
||||||
snprintf(jtmp, TPATHSIZ, "%s/jtmp.%06d%c", JTMPDIR, jid, c);
|
snprintf(jtmp, TPATHSIZ, "%s/jtmp.%06d%c", JTMPDIR, jid, c);
|
||||||
if (stat(jtmp, &statbuf) == 0 && statbuf.st_uid == uid) break;
|
if (stat(jtmp, &statbuf) == 0 && statbuf.st_uid == uid)
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (c > 'z') return;
|
if (c > 'z')
|
||||||
|
return;
|
||||||
|
|
||||||
if ((child = fork()) == 0) {
|
if ((child = fork()) == 0) {
|
||||||
execl(CLEANTMPCMD, CLEANTMPCMD, login, jtmp, 0);
|
execl(CLEANTMPCMD, CLEANTMPCMD, login, jtmp, 0);
|
||||||
fatal("ssh_cray_rmtmpdir: execl of CLEANTMPCMD failed");
|
fatal("cray_delete_tmpdir: execl of CLEANTMPCMD failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
while (waitpid (child, &wstat, 0) == -1 && errno == EINTR);
|
while (waitpid(child, &wstat, 0) == -1 && errno == EINTR)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remove tmpdir on job termination.
|
* Remove tmpdir on job termination.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cray_job_termination_handler (int sig)
|
cray_job_termination_handler(int sig)
|
||||||
{
|
{
|
||||||
int jid;
|
int jid;
|
||||||
char *login = NULL;
|
char *login = NULL;
|
||||||
|
@ -205,50 +222,53 @@ cray_job_termination_handler (int sig)
|
||||||
debug("Received SIG JOB.");
|
debug("Received SIG JOB.");
|
||||||
|
|
||||||
if ((jid = waitjob(&jtab)) == -1 ||
|
if ((jid = waitjob(&jtab)) == -1 ||
|
||||||
(login = uid2nam(jtab.j_uid)) == NULL) return;
|
(login = uid2nam(jtab.j_uid)) == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
cray_delete_tmpdir(login, jid, jtab.j_uid);
|
cray_delete_tmpdir(login, jid, jtab.j_uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set job id and create tmpdir directory.
|
* Set job id and create tmpdir directory.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cray_init_job(struct passwd *pw)
|
cray_init_job(struct passwd *pw)
|
||||||
{
|
{
|
||||||
int jid;
|
int jid;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
jid = setjob(pw->pw_uid, WJSIGNAL);
|
jid = setjob(pw->pw_uid, WJSIGNAL);
|
||||||
if (jid < 0) fatal("System call setjob failure");
|
if (jid < 0)
|
||||||
|
fatal("System call setjob failure");
|
||||||
|
|
||||||
for (c = 'a'; c <= 'z'; c++) {
|
for (c = 'a'; c <= 'z'; c++) {
|
||||||
snprintf(cray_tmpdir, TPATHSIZ, "%s/jtmp.%06d%c", JTMPDIR, jid, c);
|
snprintf(cray_tmpdir, TPATHSIZ, "%s/jtmp.%06d%c", JTMPDIR, jid, c);
|
||||||
if (mkdir(cray_tmpdir, JTMPMODE) != 0) continue;
|
if (mkdir(cray_tmpdir, JTMPMODE) != 0)
|
||||||
if (chown(cray_tmpdir, pw->pw_uid, pw->pw_gid) != 0) {
|
continue;
|
||||||
rmdir(cray_tmpdir);
|
if (chown(cray_tmpdir, pw->pw_uid, pw->pw_gid) != 0) {
|
||||||
continue;
|
rmdir(cray_tmpdir);
|
||||||
}
|
continue;
|
||||||
break;
|
}
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (c > 'z') cray_tmpdir[0] = '\0';
|
if (c > 'z')
|
||||||
|
cray_tmpdir[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cray_set_tmpdir(struct utmp *ut)
|
cray_set_tmpdir(struct utmp *ut)
|
||||||
{
|
{
|
||||||
int jid;
|
int jid;
|
||||||
struct jtab jbuf;
|
struct jtab jbuf;
|
||||||
|
|
||||||
if ((jid = getjtab (&jbuf)) < 0) return;
|
if ((jid = getjtab(&jbuf)) < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set jid and tmpdir in utmp record.
|
* Set jid and tmpdir in utmp record.
|
||||||
*/
|
*/
|
||||||
ut->ut_jid = jid;
|
ut->ut_jid = jid;
|
||||||
strncpy(ut->ut_tpath, cray_tmpdir, TPATHSIZ);
|
strncpy(ut->ut_tpath, cray_tmpdir, TPATHSIZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
|
|
||||||
#ifndef _BSD_CRAY_H
|
#ifndef _BSD_CRAY_H
|
||||||
#define _BSD_CRAY_H
|
#define _BSD_CRAY_H
|
||||||
|
|
||||||
#ifdef _CRAY
|
#ifdef _CRAY
|
||||||
void cray_init_job(struct passwd *); /* init cray job */
|
void cray_init_job(struct passwd *); /* init cray job */
|
||||||
void cray_job_termination_handler(int); /* process end of job signal */
|
void cray_job_termination_handler(int); /* process end of job signal */
|
||||||
void cray_setup(uid_t, char *); /* set cray limits */
|
void cray_setup(uid_t, char *); /* set cray limits */
|
||||||
extern char cray_tmpdir[]; /* cray tmpdir */
|
extern char cray_tmpdir[]; /* cray tmpdir */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* _BSD_CRAY_H */
|
#endif /* _BSD_CRAY_H */
|
||||||
|
|
69
sshpty.c
69
sshpty.c
|
@ -168,27 +168,28 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
|
||||||
int highpty;
|
int highpty;
|
||||||
|
|
||||||
#ifdef _SC_CRAY_NPTY
|
#ifdef _SC_CRAY_NPTY
|
||||||
highpty = sysconf(_SC_CRAY_NPTY);
|
highpty = sysconf(_SC_CRAY_NPTY);
|
||||||
if (highpty == -1)
|
if (highpty == -1)
|
||||||
highpty = 128;
|
highpty = 128;
|
||||||
#else
|
#else
|
||||||
highpty = 128;
|
highpty = 128;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (i = 0; i < highpty; i++) {
|
for (i = 0; i < highpty; i++) {
|
||||||
snprintf(buf, sizeof(buf), "/dev/pty/%03d", i);
|
snprintf(buf, sizeof(buf), "/dev/pty/%03d", i);
|
||||||
*ptyfd = open(buf, O_RDWR|O_NOCTTY);
|
*ptyfd = open(buf, O_RDWR|O_NOCTTY);
|
||||||
if (*ptyfd < 0) continue;
|
if (*ptyfd < 0)
|
||||||
snprintf(namebuf, namebuflen, "/dev/ttyp%03d", i);
|
continue;
|
||||||
/* Open the slave side. */
|
snprintf(namebuf, namebuflen, "/dev/ttyp%03d", i);
|
||||||
*ttyfd = open(namebuf, O_RDWR|O_NOCTTY);
|
/* Open the slave side. */
|
||||||
if (*ttyfd < 0) {
|
*ttyfd = open(namebuf, O_RDWR|O_NOCTTY);
|
||||||
|
if (*ttyfd < 0) {
|
||||||
error("%.100s: %.100s", namebuf, strerror(errno));
|
error("%.100s: %.100s", namebuf, strerror(errno));
|
||||||
close(*ptyfd);
|
close(*ptyfd);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
/* BSD-style pty code. */
|
/* BSD-style pty code. */
|
||||||
char buf[64];
|
char buf[64];
|
||||||
|
@ -250,29 +251,25 @@ pty_make_controlling_tty(int *ttyfd, const char *ttyname)
|
||||||
#ifdef _CRAY
|
#ifdef _CRAY
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (setsid() < 0)
|
if (setsid() < 0)
|
||||||
error("setsid: %.100s", strerror(errno));
|
error("setsid: %.100s", strerror(errno));
|
||||||
|
|
||||||
fd = open(ttyname, O_RDWR|O_NOCTTY);
|
fd = open(ttyname, O_RDWR|O_NOCTTY);
|
||||||
if (fd >= 0) {
|
if (fd != -1) {
|
||||||
signal(SIGHUP, SIG_IGN);
|
signal(SIGHUP, SIG_IGN);
|
||||||
ioctl(fd, TCVHUP, (char *)0);
|
ioctl(fd, TCVHUP, (char *)NULL);
|
||||||
signal(SIGHUP, SIG_DFL);
|
signal(SIGHUP, SIG_DFL);
|
||||||
setpgid(0,0);
|
setpgid(0, 0);
|
||||||
close(fd);
|
close(fd);
|
||||||
} else {
|
} else {
|
||||||
error("Failed to disconnect from controlling tty.");
|
error("Failed to disconnect from controlling tty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug("Setting controlling tty using TCSETCTTY.");
|
||||||
debug("Setting controlling tty using TCSETCTTY.\n");
|
ioctl(*ttyfd, TCSETCTTY, NULL);
|
||||||
ioctl(*ttyfd, TCSETCTTY, NULL);
|
fd = open("/dev/tty", O_RDWR);
|
||||||
|
if (fd < 0)
|
||||||
fd = open("/dev/tty", O_RDWR);
|
error("%.100s: %.100s", ttyname, strerror(errno));
|
||||||
|
|
||||||
if (fd < 0)
|
|
||||||
error("%.100s: %.100s", ttyname, strerror(errno));
|
|
||||||
|
|
||||||
close(*ttyfd);
|
close(*ttyfd);
|
||||||
*ttyfd = fd;
|
*ttyfd = fd;
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in New Issue