diff options
author | Kevin Steves <stevesk@pobox.com> | 2001-08-14 20:31:49 +0000 |
---|---|---|
committer | Kevin Steves <stevesk@pobox.com> | 2001-08-14 20:31:49 +0000 |
commit | f744b512f310db2c7e317ad55be011e21cd13ac3 (patch) | |
tree | 04f93497fd572bd10636df391ff8de6b2f0b61d4 /openbsd-compat/bsd-cray.c | |
parent | 56cb92968bc94322561e44959680a4dcf98bcc55 (diff) |
- (stevesk) sshpty.c, cray.[ch]: whitespace, formatting and cleanup
for some #ifdef _CRAY code; ok wendyp@cray.com
Diffstat (limited to 'openbsd-compat/bsd-cray.c')
-rw-r--r-- | openbsd-compat/bsd-cray.c | 258 |
1 files changed, 139 insertions, 119 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 | ||
28 | char cray_tmpdir[TPATHSIZ+1]; /* job TMPDIR path */ | 32 | char 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 *); | |||
38 | void cray_set_tmpdir(struct utmp *); | 42 | void 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 *); | |||
47 | void | 51 | void |
48 | cray_setup(uid_t uid, char *username) | 52 | cray_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 | |||
106 | drop_cray_privs() | 114 | drop_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 |
136 | Cray 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 | |||
145 | cray_retain_utmp(struct utmp *ut, int pid) | 158 | cray_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 | |||
172 | cray_delete_tmpdir(char *login, int jid, uid_t uid) | 186 | cray_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 | */ |
198 | void | 215 | void |
199 | cray_job_termination_handler (int sig) | 216 | cray_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 | */ |
217 | void | 234 | void |
218 | cray_init_job(struct passwd *pw) | 235 | cray_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 | ||
239 | void | 259 | void |
240 | cray_set_tmpdir(struct utmp *ut) | 260 | cray_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 |