summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Steves <stevesk@pobox.com>2001-08-14 20:31:49 +0000
committerKevin Steves <stevesk@pobox.com>2001-08-14 20:31:49 +0000
commitf744b512f310db2c7e317ad55be011e21cd13ac3 (patch)
tree04f93497fd572bd10636df391ff8de6b2f0b61d4
parent56cb92968bc94322561e44959680a4dcf98bcc55 (diff)
- (stevesk) sshpty.c, cray.[ch]: whitespace, formatting and cleanup
for some #ifdef _CRAY code; ok wendyp@cray.com
-rw-r--r--openbsd-compat/bsd-cray.c258
-rw-r--r--openbsd-compat/bsd-cray.h10
-rw-r--r--sshpty.c69
3 files changed, 176 insertions, 161 deletions
diff --git a/openbsd-compat/bsd-cray.c b/openbsd-compat/bsd-cray.c
index a11a5b6aa..3cef7d15d 100644
--- a/openbsd-compat/bsd-cray.c
+++ b/openbsd-compat/bsd-cray.c
@@ -1,4 +1,8 @@
1/* 1/*
2 * XXX: license?
3 */
4
5/*
2 * The modules contains code to support cray t3e and sv1 computers. 6 * The modules contains code to support cray t3e and sv1 computers.
3 * It is here to minimize the modifcations to the openssh base code. 7 * It is here to minimize the modifcations to the openssh base code.
4 */ 8 */
@@ -25,7 +29,7 @@
25 29
26#include "bsd-cray.h" 30#include "bsd-cray.h"
27 31
28char cray_tmpdir[TPATHSIZ+1]; /* job TMPDIR path */ 32char cray_tmpdir[TPATHSIZ+1]; /* job TMPDIR path */
29 33
30/* 34/*
31 * Functions. 35 * Functions.
@@ -38,7 +42,7 @@ void cray_init_job(struct passwd *);
38void cray_set_tmpdir(struct utmp *); 42void cray_set_tmpdir(struct utmp *);
39 43
40 44
41/* 45/*
42 * Orignal written by: 46 * Orignal written by:
43 * Wayne Schroeder 47 * Wayne Schroeder
44 * San Diego Supercomputer Center 48 * San Diego Supercomputer Center
@@ -47,56 +51,60 @@ void cray_set_tmpdir(struct utmp *);
47void 51void
48cray_setup(uid_t uid, char *username) 52cray_setup(uid_t uid, char *username)
49{ 53{
50 struct udb *p; 54 struct udb *p;
51 extern char *setlimits(); 55 extern char *setlimits();
52 int i, j; 56 int i, j;
53 int accts[MAXVIDS]; 57 int accts[MAXVIDS];
54 int naccts; 58 int naccts;
55 int err; 59 int err;
56 char *sr; 60 char *sr;
57 int pid; 61 int pid;
58 struct jtab jbuf; 62 struct jtab jbuf;
59 int jid; 63 int jid;
60 64
61 if ((jid = getjtab (&jbuf)) < 0) fatal("getjtab: no jid"); 65 if ((jid = getjtab(&jbuf)) < 0)
62 66 fatal("getjtab: no jid");
63 err = setudb(); /* open and rewind the Cray User DataBase */ 67
64 if(err != 0) fatal("UDB open failure"); 68 err = setudb(); /* open and rewind the Cray User DataBase */
65 naccts = 0; 69 if (err != 0)
70 fatal("UDB open failure");
71 naccts = 0;
66 p = getudbnam(username); 72 p = getudbnam(username);
67 if (p == NULL) fatal("No UDB entry for %s", username); 73 if (p == NULL)
68 if(uid != p->ue_uid) 74 fatal("No UDB entry for %.100s", username);
69 fatal("UDB etnry %s uid(%d) does not match uid %d\n", 75 if (uid != p->ue_uid)
70 username, p->ue_uid, uid); 76 fatal("UDB etnry %.100s uid(%d) does not match uid %d",
71 for(j = 0; p->ue_acids[j] != -1 && j < MAXVIDS; j++) { 77 username, p->ue_uid, uid);
72 accts[naccts] = p->ue_acids[j]; 78 for (j = 0; p->ue_acids[j] != -1 && j < MAXVIDS; j++) {
73 naccts++; 79 accts[naccts] = p->ue_acids[j];
74 } 80 naccts++;
75 endudb(); /* close the udb */ 81 }
76 82 endudb(); /* close the udb */
77 if (naccts != 0) { 83
78 /* Perhaps someday we'll prompt users who have multiple accounts 84 if (naccts != 0) {
79 to let them pick one (like CRI's login does), but for now just set 85 /* Perhaps someday we'll prompt users who have multiple accounts
80 the account to the first entry. */ 86 to let them pick one (like CRI's login does), but for now just set
81 if (acctid(0, accts[0]) < 0) 87 the account to the first entry. */
82 fatal("System call acctid failed, accts[0]=%d",accts[0]); 88 if (acctid(0, accts[0]) < 0)
89 fatal("System call acctid failed, accts[0]=%d", accts[0]);
83 } 90 }
84
85 /* Now set limits, including CPU time for the (interactive) job and process,
86 and set up permissions (for chown etc), etc. This is via an internal CRI
87 routine, setlimits, used by CRI's login. */
88 91
89 pid = getpid(); 92 /* Now set limits, including CPU time for the (interactive) job and process,
90 sr = setlimits(username, C_PROC, pid, UDBRC_INTER); 93 and set up permissions (for chown etc), etc. This is via an internal CRI
91 if (sr != NULL) fatal("%.200s", sr); 94 routine, setlimits, used by CRI's login. */
92 95
93 sr = setlimits(username, C_JOB, jid, UDBRC_INTER); 96 pid = getpid();
94 if (sr != NULL) fatal("%.200s", sr); 97 sr = setlimits(username, C_PROC, pid, UDBRC_INTER);
98 if (sr != NULL)
99 fatal("%.200s", sr);
95 100
96} 101 sr = setlimits(username, C_JOB, jid, UDBRC_INTER);
102 if (sr != NULL)
103 fatal("%.200s", sr);
97 104
105}
98 106
99/* 107/*
100 * The rc.* and /etc/sdaemon methods of starting a program on unicos/unicosmk 108 * The rc.* and /etc/sdaemon methods of starting a program on unicos/unicosmk
101 * can have pal privileges that sshd can inherit which 109 * can have pal privileges that sshd can inherit which
102 * could allow a user to su to root with out a password. 110 * could allow a user to su to root with out a password.
@@ -106,34 +114,39 @@ void
106drop_cray_privs() 114drop_cray_privs()
107{ 115{
108#if defined(_SC_CRAY_PRIV_SU) 116#if defined(_SC_CRAY_PRIV_SU)
109 priv_proc_t* privstate; 117 priv_proc_t* privstate;
110 int result; 118 int result;
111 extern int priv_set_proc(); 119 extern int priv_set_proc();
112 extern priv_proc_t* priv_init_proc(); 120 extern priv_proc_t* priv_init_proc();
113 struct usrv usrv; 121 struct usrv usrv;
114 122
115 /* 123 /*
116 * If ether of theses two flags are not set 124 * If ether of theses two flags are not set
117 * then don't allow this version of ssh to run. 125 * then don't allow this version of ssh to run.
118 */ 126 */
119 if (!sysconf(_SC_CRAY_PRIV_SU)) fatal("Not PRIV_SU system."); 127 if (!sysconf(_SC_CRAY_PRIV_SU))
120 if (!sysconf(_SC_CRAY_POSIX_PRIV)) fatal("Not POSIX_PRIV."); 128 fatal("Not PRIV_SU system.");
129 if (!sysconf(_SC_CRAY_POSIX_PRIV))
130 fatal("Not POSIX_PRIV.");
121 131
122 debug ("Dropping privileges."); 132 debug("Dropping privileges.");
123 133
124 memset(&usrv, 0, sizeof(usrv)); 134 memset(&usrv, 0, sizeof(usrv));
125 if (setusrv(&usrv) < 0) 135 if (setusrv(&usrv) < 0)
126 fatal ("%s(%d): setusrv(): %s\n", __FILE__, __LINE__, strerror(errno)); 136 fatal("%s(%d): setusrv(): %s\n", __FILE__, __LINE__,
137 strerror(errno));
127 138
128 if ((privstate = priv_init_proc()) != NULL) { 139 if ((privstate = priv_init_proc()) != NULL) {
129 result = priv_set_proc(privstate); 140 result = priv_set_proc(privstate);
130 if ( result != 0 ) fatal ("%s(%d): priv_set_proc(): %s\n", 141 if (result != 0 )
131 __FILE__, __LINE__, strerror(errno)); 142 fatal("%s(%d): priv_set_proc(): %s\n",
132 priv_free_proc(privstate); 143 __FILE__, __LINE__, strerror(errno));
133 } 144 priv_free_proc(privstate);
134 debug ("Privileges should be cleared..."); 145 }
146 debug ("Privileges should be cleared...");
135#else 147#else
136Cray systems must be run with _SC_CRAY_PRIV_SU on! 148 /* XXX: do this differently */
149# error Cray systems must be run with _SC_CRAY_PRIV_SU on!
137#endif 150#endif
138} 151}
139 152
@@ -145,20 +158,21 @@ void
145cray_retain_utmp(struct utmp *ut, int pid) 158cray_retain_utmp(struct utmp *ut, int pid)
146{ 159{
147 int fd; 160 int fd;
148 struct utmp utmp; 161 struct utmp utmp;
149 162
150 if ((fd = open(UTMP_FILE, O_RDONLY)) >= 0) { 163 if ((fd = open(UTMP_FILE, O_RDONLY)) != -1) {
151 while (read(fd, (char *)&utmp, sizeof(utmp)) == sizeof(utmp)) { 164 while (read(fd, (char *)&utmp, sizeof(utmp)) == sizeof(utmp)) {
152 if (pid == utmp.ut_pid) { 165 if (pid == utmp.ut_pid) {
153 ut->ut_jid = utmp.ut_jid; 166 ut->ut_jid = utmp.ut_jid;
154 strncpy(ut->ut_tpath, utmp.ut_tpath, TPATHSIZ); 167 strncpy(ut->ut_tpath, utmp.ut_tpath, TPATHSIZ);
155 strncpy(ut->ut_host, utmp.ut_host, strlen(utmp.ut_host)); 168 strncpy(ut->ut_host, utmp.ut_host, strlen(utmp.ut_host));
156 strncpy(ut->ut_name, utmp.ut_name, strlen(utmp.ut_name)); 169 strncpy(ut->ut_name, utmp.ut_name, strlen(utmp.ut_name));
157 break; 170 break;
158 } 171 }
159 } 172 }
160 close(fd); 173 close(fd);
161 } 174 }
175 /* XXX: error message? */
162} 176}
163 177
164/* 178/*
@@ -172,31 +186,34 @@ void
172cray_delete_tmpdir(char *login, int jid, uid_t uid) 186cray_delete_tmpdir(char *login, int jid, uid_t uid)
173{ 187{
174 int child; 188 int child;
175 static char jtmp[TPATHSIZ]; 189 static char jtmp[TPATHSIZ];
176 struct stat statbuf; 190 struct stat statbuf;
177 int c; 191 int c;
178 int wstat; 192 int wstat;
179 193
180 for (c = 'a'; c <= 'z'; c++) { 194 for (c = 'a'; c <= 'z'; c++) {
181 snprintf(jtmp, TPATHSIZ, "%s/jtmp.%06d%c", JTMPDIR, jid, c); 195 snprintf(jtmp, TPATHSIZ, "%s/jtmp.%06d%c", JTMPDIR, jid, c);
182 if (stat(jtmp, &statbuf) == 0 && statbuf.st_uid == uid) break; 196 if (stat(jtmp, &statbuf) == 0 && statbuf.st_uid == uid)
183 } 197 break;
198 }
184 199
185 if (c > 'z') return; 200 if (c > 'z')
201 return;
186 202
187 if ((child = fork()) == 0) { 203 if ((child = fork()) == 0) {
188 execl(CLEANTMPCMD, CLEANTMPCMD, login, jtmp, 0); 204 execl(CLEANTMPCMD, CLEANTMPCMD, login, jtmp, 0);
189 fatal("ssh_cray_rmtmpdir: execl of CLEANTMPCMD failed"); 205 fatal("cray_delete_tmpdir: execl of CLEANTMPCMD failed");
190 } 206 }
191 207
192 while (waitpid (child, &wstat, 0) == -1 && errno == EINTR); 208 while (waitpid(child, &wstat, 0) == -1 && errno == EINTR)
209 ;
193} 210}
194 211
195/* 212/*
196 * Remove tmpdir on job termination. 213 * Remove tmpdir on job termination.
197 */ 214 */
198void 215void
199cray_job_termination_handler (int sig) 216cray_job_termination_handler(int sig)
200{ 217{
201 int jid; 218 int jid;
202 char *login = NULL; 219 char *login = NULL;
@@ -205,50 +222,53 @@ cray_job_termination_handler (int sig)
205 debug("Received SIG JOB."); 222 debug("Received SIG JOB.");
206 223
207 if ((jid = waitjob(&jtab)) == -1 || 224 if ((jid = waitjob(&jtab)) == -1 ||
208 (login = uid2nam(jtab.j_uid)) == NULL) return; 225 (login = uid2nam(jtab.j_uid)) == NULL)
226 return;
209 227
210 cray_delete_tmpdir(login, jid, jtab.j_uid); 228 cray_delete_tmpdir(login, jid, jtab.j_uid);
211} 229}
212 230
213
214/* 231/*
215 * Set job id and create tmpdir directory. 232 * Set job id and create tmpdir directory.
216 */ 233 */
217void 234void
218cray_init_job(struct passwd *pw) 235cray_init_job(struct passwd *pw)
219{ 236{
220 int jid; 237 int jid;
221 int c; 238 int c;
222 239
223 jid = setjob(pw->pw_uid, WJSIGNAL); 240 jid = setjob(pw->pw_uid, WJSIGNAL);
224 if (jid < 0) fatal("System call setjob failure"); 241 if (jid < 0)
225 242 fatal("System call setjob failure");
226 for (c = 'a'; c <= 'z'; c++) { 243
227 snprintf(cray_tmpdir, TPATHSIZ, "%s/jtmp.%06d%c", JTMPDIR, jid, c); 244 for (c = 'a'; c <= 'z'; c++) {
228 if (mkdir(cray_tmpdir, JTMPMODE) != 0) continue; 245 snprintf(cray_tmpdir, TPATHSIZ, "%s/jtmp.%06d%c", JTMPDIR, jid, c);
229 if (chown(cray_tmpdir, pw->pw_uid, pw->pw_gid) != 0) { 246 if (mkdir(cray_tmpdir, JTMPMODE) != 0)
230 rmdir(cray_tmpdir); 247 continue;
231 continue; 248 if (chown(cray_tmpdir, pw->pw_uid, pw->pw_gid) != 0) {
232 } 249 rmdir(cray_tmpdir);
233 break; 250 continue;
234 } 251 }
235 252 break;
236 if (c > 'z') cray_tmpdir[0] = '\0'; 253 }
237} 254
255 if (c > 'z')
256 cray_tmpdir[0] = '\0';
257}
238 258
239void 259void
240cray_set_tmpdir(struct utmp *ut) 260cray_set_tmpdir(struct utmp *ut)
241{ 261{
242 int jid; 262 int jid;
243 struct jtab jbuf; 263 struct jtab jbuf;
244 264
245 if ((jid = getjtab (&jbuf)) < 0) return; 265 if ((jid = getjtab(&jbuf)) < 0)
266 return;
246 267
247 /* 268 /*
248 * Set jid and tmpdir in utmp record. 269 * Set jid and tmpdir in utmp record.
249 */ 270 */
250 ut->ut_jid = jid; 271 ut->ut_jid = jid;
251 strncpy(ut->ut_tpath, cray_tmpdir, TPATHSIZ); 272 strncpy(ut->ut_tpath, cray_tmpdir, TPATHSIZ);
252} 273}
253
254#endif 274#endif
diff --git a/openbsd-compat/bsd-cray.h b/openbsd-compat/bsd-cray.h
index 4ca2dbe51..ef36652e4 100644
--- a/openbsd-compat/bsd-cray.h
+++ b/openbsd-compat/bsd-cray.h
@@ -1,13 +1,11 @@
1
2#ifndef _BSD_CRAY_H 1#ifndef _BSD_CRAY_H
3#define _BSD_CRAY_H 2#define _BSD_CRAY_H
4 3
5#ifdef _CRAY 4#ifdef _CRAY
6void cray_init_job(struct passwd *); /* init cray job */ 5void cray_init_job(struct passwd *); /* init cray job */
7void cray_job_termination_handler(int); /* process end of job signal */ 6void cray_job_termination_handler(int); /* process end of job signal */
8void cray_setup(uid_t, char *); /* set cray limits */ 7void cray_setup(uid_t, char *); /* set cray limits */
9extern char cray_tmpdir[]; /* cray tmpdir */ 8extern char cray_tmpdir[]; /* cray tmpdir */
10#endif 9#endif
11 10
12
13#endif /* _BSD_CRAY_H */ 11#endif /* _BSD_CRAY_H */
diff --git a/sshpty.c b/sshpty.c
index 84572c901..31abd696c 100644
--- a/sshpty.c
+++ b/sshpty.c
@@ -168,27 +168,28 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
168 int highpty; 168 int highpty;
169 169
170#ifdef _SC_CRAY_NPTY 170#ifdef _SC_CRAY_NPTY
171 highpty = sysconf(_SC_CRAY_NPTY); 171 highpty = sysconf(_SC_CRAY_NPTY);
172 if (highpty == -1) 172 if (highpty == -1)
173 highpty = 128; 173 highpty = 128;
174#else 174#else
175 highpty = 128; 175 highpty = 128;
176#endif 176#endif
177 177
178 for (i = 0; i < highpty; i++) { 178 for (i = 0; i < highpty; i++) {
179 snprintf(buf, sizeof(buf), "/dev/pty/%03d", i); 179 snprintf(buf, sizeof(buf), "/dev/pty/%03d", i);
180 *ptyfd = open(buf, O_RDWR|O_NOCTTY); 180 *ptyfd = open(buf, O_RDWR|O_NOCTTY);
181 if (*ptyfd < 0) continue; 181 if (*ptyfd < 0)
182 snprintf(namebuf, namebuflen, "/dev/ttyp%03d", i); 182 continue;
183 /* Open the slave side. */ 183 snprintf(namebuf, namebuflen, "/dev/ttyp%03d", i);
184 *ttyfd = open(namebuf, O_RDWR|O_NOCTTY); 184 /* Open the slave side. */
185 if (*ttyfd < 0) { 185 *ttyfd = open(namebuf, O_RDWR|O_NOCTTY);
186 if (*ttyfd < 0) {
186 error("%.100s: %.100s", namebuf, strerror(errno)); 187 error("%.100s: %.100s", namebuf, strerror(errno));
187 close(*ptyfd); 188 close(*ptyfd);
188 } 189 }
189 return 1; 190 return 1;
190 } 191 }
191 return 0; 192 return 0;
192#else 193#else
193 /* BSD-style pty code. */ 194 /* BSD-style pty code. */
194 char buf[64]; 195 char buf[64];
@@ -250,29 +251,25 @@ pty_make_controlling_tty(int *ttyfd, const char *ttyname)
250#ifdef _CRAY 251#ifdef _CRAY
251 int fd; 252 int fd;
252 253
253 if (setsid() < 0) 254 if (setsid() < 0)
254 error("setsid: %.100s", strerror(errno)); 255 error("setsid: %.100s", strerror(errno));
255 256
256 fd = open(ttyname, O_RDWR|O_NOCTTY); 257 fd = open(ttyname, O_RDWR|O_NOCTTY);
257 if (fd >= 0) { 258 if (fd != -1) {
258 signal(SIGHUP, SIG_IGN); 259 signal(SIGHUP, SIG_IGN);
259 ioctl(fd, TCVHUP, (char *)0); 260 ioctl(fd, TCVHUP, (char *)NULL);
260 signal(SIGHUP, SIG_DFL); 261 signal(SIGHUP, SIG_DFL);
261 setpgid(0,0); 262 setpgid(0, 0);
262 close(fd); 263 close(fd);
263 } else { 264 } else {
264 error("Failed to disconnect from controlling tty."); 265 error("Failed to disconnect from controlling tty.");
265 } 266 }
266
267
268 debug("Setting controlling tty using TCSETCTTY.\n");
269 ioctl(*ttyfd, TCSETCTTY, NULL);
270
271 fd = open("/dev/tty", O_RDWR);
272
273 if (fd < 0)
274 error("%.100s: %.100s", ttyname, strerror(errno));
275 267
268 debug("Setting controlling tty using TCSETCTTY.");
269 ioctl(*ttyfd, TCSETCTTY, NULL);
270 fd = open("/dev/tty", O_RDWR);
271 if (fd < 0)
272 error("%.100s: %.100s", ttyname, strerror(errno));
276 close(*ttyfd); 273 close(*ttyfd);
277 *ttyfd = fd; 274 *ttyfd = fd;
278#else 275#else