1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * $Id: bsd-cray.c,v 1.8 2002/09/26 00:38:51 tim Exp $
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * bsd-cray.c
5*7c478bd9Sstevel@tonic-gate *
6*7c478bd9Sstevel@tonic-gate * Copyright (c) 2002, Cray Inc. (Wendy Palm <wendyp@cray.com>)
7*7c478bd9Sstevel@tonic-gate * Significant portions provided by
8*7c478bd9Sstevel@tonic-gate * Wayne Schroeder, SDSC <schroeder@sdsc.edu>
9*7c478bd9Sstevel@tonic-gate * William Jones, UTexas <jones@tacc.utexas.edu>
10*7c478bd9Sstevel@tonic-gate *
11*7c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
12*7c478bd9Sstevel@tonic-gate * modification, are permitted provided that the following conditions
13*7c478bd9Sstevel@tonic-gate * are met:
14*7c478bd9Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
15*7c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer.
16*7c478bd9Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
17*7c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the
18*7c478bd9Sstevel@tonic-gate * documentation and/or other materials provided with the distribution.
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21*7c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22*7c478bd9Sstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23*7c478bd9Sstevel@tonic-gate * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24*7c478bd9Sstevel@tonic-gate * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25*7c478bd9Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26*7c478bd9Sstevel@tonic-gate * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27*7c478bd9Sstevel@tonic-gate * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28*7c478bd9Sstevel@tonic-gate * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29*7c478bd9Sstevel@tonic-gate * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*7c478bd9Sstevel@tonic-gate *
31*7c478bd9Sstevel@tonic-gate * Created: Apr 22 16.34:00 2002 wp
32*7c478bd9Sstevel@tonic-gate *
33*7c478bd9Sstevel@tonic-gate * This file contains functions required for proper execution
34*7c478bd9Sstevel@tonic-gate * on UNICOS systems.
35*7c478bd9Sstevel@tonic-gate *
36*7c478bd9Sstevel@tonic-gate */
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
39*7c478bd9Sstevel@tonic-gate
40*7c478bd9Sstevel@tonic-gate #include "includes.h"
41*7c478bd9Sstevel@tonic-gate
42*7c478bd9Sstevel@tonic-gate #ifdef _UNICOS
43*7c478bd9Sstevel@tonic-gate
44*7c478bd9Sstevel@tonic-gate #include <udb.h>
45*7c478bd9Sstevel@tonic-gate #include <tmpdir.h>
46*7c478bd9Sstevel@tonic-gate #include <unistd.h>
47*7c478bd9Sstevel@tonic-gate #include <sys/category.h>
48*7c478bd9Sstevel@tonic-gate #include <utmp.h>
49*7c478bd9Sstevel@tonic-gate #include <sys/jtab.h>
50*7c478bd9Sstevel@tonic-gate #include <signal.h>
51*7c478bd9Sstevel@tonic-gate #include <sys/priv.h>
52*7c478bd9Sstevel@tonic-gate #include <sys/secparm.h>
53*7c478bd9Sstevel@tonic-gate #include <sys/tfm.h>
54*7c478bd9Sstevel@tonic-gate #include <sys/usrv.h>
55*7c478bd9Sstevel@tonic-gate #include <sys/sysv.h>
56*7c478bd9Sstevel@tonic-gate #include <sys/sectab.h>
57*7c478bd9Sstevel@tonic-gate #include <sys/secstat.h>
58*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
59*7c478bd9Sstevel@tonic-gate #include <sys/session.h>
60*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
61*7c478bd9Sstevel@tonic-gate #include <pwd.h>
62*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
63*7c478bd9Sstevel@tonic-gate #include <errno.h>
64*7c478bd9Sstevel@tonic-gate #include <ia.h>
65*7c478bd9Sstevel@tonic-gate #include <urm.h>
66*7c478bd9Sstevel@tonic-gate #include "ssh.h"
67*7c478bd9Sstevel@tonic-gate #include "log.h"
68*7c478bd9Sstevel@tonic-gate #include "servconf.h"
69*7c478bd9Sstevel@tonic-gate #include "bsd-cray.h"
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gate #define MAXACID 80
72*7c478bd9Sstevel@tonic-gate
73*7c478bd9Sstevel@tonic-gate extern ServerOptions options;
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate char cray_tmpdir[TPATHSIZ+1]; /* job TMPDIR path */
76*7c478bd9Sstevel@tonic-gate
77*7c478bd9Sstevel@tonic-gate struct sysv sysv; /* system security structure */
78*7c478bd9Sstevel@tonic-gate struct usrv usrv; /* user security structure */
79*7c478bd9Sstevel@tonic-gate
80*7c478bd9Sstevel@tonic-gate /*
81*7c478bd9Sstevel@tonic-gate * Functions.
82*7c478bd9Sstevel@tonic-gate */
83*7c478bd9Sstevel@tonic-gate void cray_retain_utmp(struct utmp *, int);
84*7c478bd9Sstevel@tonic-gate void cray_delete_tmpdir(char *, int, uid_t);
85*7c478bd9Sstevel@tonic-gate void cray_init_job(struct passwd *);
86*7c478bd9Sstevel@tonic-gate void cray_set_tmpdir(struct utmp *);
87*7c478bd9Sstevel@tonic-gate void cray_login_failure(char *, int);
88*7c478bd9Sstevel@tonic-gate int cray_setup(uid_t, char *, const char *);
89*7c478bd9Sstevel@tonic-gate int cray_access_denied(char *);
90*7c478bd9Sstevel@tonic-gate
91*7c478bd9Sstevel@tonic-gate void
cray_login_failure(char * username,int errcode)92*7c478bd9Sstevel@tonic-gate cray_login_failure(char *username, int errcode)
93*7c478bd9Sstevel@tonic-gate {
94*7c478bd9Sstevel@tonic-gate struct udb *ueptr; /* UDB pointer for username */
95*7c478bd9Sstevel@tonic-gate ia_failure_t fsent; /* ia_failure structure */
96*7c478bd9Sstevel@tonic-gate ia_failure_ret_t fret; /* ia_failure return stuff */
97*7c478bd9Sstevel@tonic-gate struct jtab jtab; /* job table structure */
98*7c478bd9Sstevel@tonic-gate int jid = 0; /* job id */
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gate if ((jid = getjtab(&jtab)) < 0) {
101*7c478bd9Sstevel@tonic-gate debug("cray_login_failure(): getjtab error");
102*7c478bd9Sstevel@tonic-gate }
103*7c478bd9Sstevel@tonic-gate getsysudb();
104*7c478bd9Sstevel@tonic-gate if ((ueptr = getudbnam(username)) == UDB_NULL) {
105*7c478bd9Sstevel@tonic-gate debug("cray_login_failure(): getudbname() returned NULL");
106*7c478bd9Sstevel@tonic-gate }
107*7c478bd9Sstevel@tonic-gate endudb();
108*7c478bd9Sstevel@tonic-gate fsent.revision = 0;
109*7c478bd9Sstevel@tonic-gate fsent.uname = username;
110*7c478bd9Sstevel@tonic-gate fsent.host = (char *)get_canonical_hostname(options.verify_reverse_mapping);
111*7c478bd9Sstevel@tonic-gate fsent.ttyn = "sshd";
112*7c478bd9Sstevel@tonic-gate fsent.caller = IA_SSHD;
113*7c478bd9Sstevel@tonic-gate fsent.flags = IA_INTERACTIVE;
114*7c478bd9Sstevel@tonic-gate fsent.ueptr = ueptr;
115*7c478bd9Sstevel@tonic-gate fsent.jid = jid;
116*7c478bd9Sstevel@tonic-gate fsent.errcode = errcode;
117*7c478bd9Sstevel@tonic-gate fsent.pwdp = NULL;
118*7c478bd9Sstevel@tonic-gate fsent.exitcode = 0; /* dont exit in ia_failure() */
119*7c478bd9Sstevel@tonic-gate
120*7c478bd9Sstevel@tonic-gate fret.revision = 0;
121*7c478bd9Sstevel@tonic-gate fret.normal = 0;
122*7c478bd9Sstevel@tonic-gate
123*7c478bd9Sstevel@tonic-gate /*
124*7c478bd9Sstevel@tonic-gate * Call ia_failure because of an login failure.
125*7c478bd9Sstevel@tonic-gate */
126*7c478bd9Sstevel@tonic-gate ia_failure(&fsent,&fret);
127*7c478bd9Sstevel@tonic-gate }
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate /*
130*7c478bd9Sstevel@tonic-gate * Cray access denied
131*7c478bd9Sstevel@tonic-gate */
132*7c478bd9Sstevel@tonic-gate int
cray_access_denied(char * username)133*7c478bd9Sstevel@tonic-gate cray_access_denied(char *username)
134*7c478bd9Sstevel@tonic-gate {
135*7c478bd9Sstevel@tonic-gate struct udb *ueptr; /* UDB pointer for username */
136*7c478bd9Sstevel@tonic-gate int errcode; /* IA errorcode */
137*7c478bd9Sstevel@tonic-gate
138*7c478bd9Sstevel@tonic-gate errcode = 0;
139*7c478bd9Sstevel@tonic-gate getsysudb();
140*7c478bd9Sstevel@tonic-gate if ((ueptr = getudbnam(username)) == UDB_NULL) {
141*7c478bd9Sstevel@tonic-gate debug("cray_login_failure(): getudbname() returned NULL");
142*7c478bd9Sstevel@tonic-gate }
143*7c478bd9Sstevel@tonic-gate endudb();
144*7c478bd9Sstevel@tonic-gate if (ueptr && ueptr->ue_disabled)
145*7c478bd9Sstevel@tonic-gate errcode = IA_DISABLED;
146*7c478bd9Sstevel@tonic-gate if (errcode)
147*7c478bd9Sstevel@tonic-gate cray_login_failure(username, errcode);
148*7c478bd9Sstevel@tonic-gate return (errcode);
149*7c478bd9Sstevel@tonic-gate }
150*7c478bd9Sstevel@tonic-gate
151*7c478bd9Sstevel@tonic-gate int
cray_setup(uid_t uid,char * username,const char * command)152*7c478bd9Sstevel@tonic-gate cray_setup (uid_t uid, char *username, const char *command)
153*7c478bd9Sstevel@tonic-gate {
154*7c478bd9Sstevel@tonic-gate extern struct udb *getudb();
155*7c478bd9Sstevel@tonic-gate extern char *setlimits();
156*7c478bd9Sstevel@tonic-gate
157*7c478bd9Sstevel@tonic-gate int err; /* error return */
158*7c478bd9Sstevel@tonic-gate time_t system_time; /* current system clock */
159*7c478bd9Sstevel@tonic-gate time_t expiration_time; /* password expiration time */
160*7c478bd9Sstevel@tonic-gate int maxattempts; /* maximum no. of failed login attempts */
161*7c478bd9Sstevel@tonic-gate int SecureSys; /* unicos security flag */
162*7c478bd9Sstevel@tonic-gate int minslevel = 0; /* system minimum security level */
163*7c478bd9Sstevel@tonic-gate int i, j;
164*7c478bd9Sstevel@tonic-gate int valid_acct = -1; /* flag for reading valid acct */
165*7c478bd9Sstevel@tonic-gate char acct_name[MAXACID] = { "" }; /* used to read acct name */
166*7c478bd9Sstevel@tonic-gate struct jtab jtab; /* Job table struct */
167*7c478bd9Sstevel@tonic-gate struct udb ue; /* udb entry for logging-in user */
168*7c478bd9Sstevel@tonic-gate struct udb *up; /* pointer to UDB entry */
169*7c478bd9Sstevel@tonic-gate struct secstat secinfo; /* file security attributes */
170*7c478bd9Sstevel@tonic-gate struct servprov init_info; /* used for sesscntl() call */
171*7c478bd9Sstevel@tonic-gate int jid; /* job ID */
172*7c478bd9Sstevel@tonic-gate int pid; /* process ID */
173*7c478bd9Sstevel@tonic-gate char *sr; /* status return from setlimits() */
174*7c478bd9Sstevel@tonic-gate char *ttyn = NULL; /* ttyname or command name*/
175*7c478bd9Sstevel@tonic-gate char hostname[MAXHOSTNAMELEN];
176*7c478bd9Sstevel@tonic-gate passwd_t pwdacm,
177*7c478bd9Sstevel@tonic-gate pwddialup,
178*7c478bd9Sstevel@tonic-gate pwdudb,
179*7c478bd9Sstevel@tonic-gate pwdwal,
180*7c478bd9Sstevel@tonic-gate pwddce; /* passwd stuff for ia_user */
181*7c478bd9Sstevel@tonic-gate ia_user_ret_t uret; /* stuff returned from ia_user */
182*7c478bd9Sstevel@tonic-gate ia_user_t usent; /* ia_user main structure */
183*7c478bd9Sstevel@tonic-gate int ia_rcode; /* ia_user return code */
184*7c478bd9Sstevel@tonic-gate ia_failure_t fsent; /* ia_failure structure */
185*7c478bd9Sstevel@tonic-gate ia_failure_ret_t fret; /* ia_failure return stuff */
186*7c478bd9Sstevel@tonic-gate ia_success_t ssent; /* ia_success structure */
187*7c478bd9Sstevel@tonic-gate ia_success_ret_t sret; /* ia_success return stuff */
188*7c478bd9Sstevel@tonic-gate int ia_mlsrcode; /* ia_mlsuser return code */
189*7c478bd9Sstevel@tonic-gate int secstatrc; /* [f]secstat return code */
190*7c478bd9Sstevel@tonic-gate
191*7c478bd9Sstevel@tonic-gate if (SecureSys = (int)sysconf(_SC_CRAY_SECURE_SYS)) {
192*7c478bd9Sstevel@tonic-gate getsysv(&sysv, sizeof(struct sysv));
193*7c478bd9Sstevel@tonic-gate minslevel = sysv.sy_minlvl;
194*7c478bd9Sstevel@tonic-gate if (getusrv(&usrv) < 0) {
195*7c478bd9Sstevel@tonic-gate debug("getusrv() failed, errno = %d",errno);
196*7c478bd9Sstevel@tonic-gate exit(1);
197*7c478bd9Sstevel@tonic-gate }
198*7c478bd9Sstevel@tonic-gate }
199*7c478bd9Sstevel@tonic-gate hostname[0] = '\0';
200*7c478bd9Sstevel@tonic-gate strncpy(hostname,
201*7c478bd9Sstevel@tonic-gate (char *)get_canonical_hostname(options.verify_reverse_mapping),
202*7c478bd9Sstevel@tonic-gate MAXHOSTNAMELEN);
203*7c478bd9Sstevel@tonic-gate /*
204*7c478bd9Sstevel@tonic-gate * Fetch user's UDB entry.
205*7c478bd9Sstevel@tonic-gate */
206*7c478bd9Sstevel@tonic-gate getsysudb();
207*7c478bd9Sstevel@tonic-gate if ((up = getudbnam(username)) == UDB_NULL) {
208*7c478bd9Sstevel@tonic-gate debug("cannot fetch user's UDB entry");
209*7c478bd9Sstevel@tonic-gate exit(1);
210*7c478bd9Sstevel@tonic-gate }
211*7c478bd9Sstevel@tonic-gate
212*7c478bd9Sstevel@tonic-gate /*
213*7c478bd9Sstevel@tonic-gate * Prevent any possible fudging so perform a data
214*7c478bd9Sstevel@tonic-gate * safety check and compare the supplied uid against
215*7c478bd9Sstevel@tonic-gate * the udb's uid.
216*7c478bd9Sstevel@tonic-gate */
217*7c478bd9Sstevel@tonic-gate if (up->ue_uid != uid) {
218*7c478bd9Sstevel@tonic-gate debug("IA uid missmatch");
219*7c478bd9Sstevel@tonic-gate exit(1);
220*7c478bd9Sstevel@tonic-gate }
221*7c478bd9Sstevel@tonic-gate endudb();
222*7c478bd9Sstevel@tonic-gate
223*7c478bd9Sstevel@tonic-gate if ((jid = getjtab (&jtab)) < 0) {
224*7c478bd9Sstevel@tonic-gate debug("getjtab");
225*7c478bd9Sstevel@tonic-gate return -1;
226*7c478bd9Sstevel@tonic-gate }
227*7c478bd9Sstevel@tonic-gate pid = getpid();
228*7c478bd9Sstevel@tonic-gate ttyn = ttyname(0);
229*7c478bd9Sstevel@tonic-gate if (SecureSys) {
230*7c478bd9Sstevel@tonic-gate if (ttyn) {
231*7c478bd9Sstevel@tonic-gate secstatrc = secstat(ttyn, &secinfo);
232*7c478bd9Sstevel@tonic-gate } else {
233*7c478bd9Sstevel@tonic-gate secstatrc = fsecstat(1, &secinfo);
234*7c478bd9Sstevel@tonic-gate }
235*7c478bd9Sstevel@tonic-gate if (secstatrc == 0) {
236*7c478bd9Sstevel@tonic-gate debug("[f]secstat() successful");
237*7c478bd9Sstevel@tonic-gate } else {
238*7c478bd9Sstevel@tonic-gate debug("[f]secstat() error, rc = %d", secstatrc);
239*7c478bd9Sstevel@tonic-gate exit(1);
240*7c478bd9Sstevel@tonic-gate }
241*7c478bd9Sstevel@tonic-gate }
242*7c478bd9Sstevel@tonic-gate if ((ttyn == NULL) && ((char *)command != NULL))
243*7c478bd9Sstevel@tonic-gate ttyn = (char *)command;
244*7c478bd9Sstevel@tonic-gate /*
245*7c478bd9Sstevel@tonic-gate * Initialize all structures to call ia_user
246*7c478bd9Sstevel@tonic-gate */
247*7c478bd9Sstevel@tonic-gate usent.revision = 0;
248*7c478bd9Sstevel@tonic-gate usent.uname = username;
249*7c478bd9Sstevel@tonic-gate usent.host = hostname;
250*7c478bd9Sstevel@tonic-gate usent.ttyn = ttyn;
251*7c478bd9Sstevel@tonic-gate usent.caller = IA_SSHD;
252*7c478bd9Sstevel@tonic-gate usent.pswdlist = &pwdacm;
253*7c478bd9Sstevel@tonic-gate usent.ueptr = &ue;
254*7c478bd9Sstevel@tonic-gate usent.flags = IA_INTERACTIVE | IA_FFLAG;
255*7c478bd9Sstevel@tonic-gate pwdacm.atype = IA_SECURID;
256*7c478bd9Sstevel@tonic-gate pwdacm.pwdp = NULL;
257*7c478bd9Sstevel@tonic-gate pwdacm.next = &pwdudb;
258*7c478bd9Sstevel@tonic-gate
259*7c478bd9Sstevel@tonic-gate pwdudb.atype = IA_UDB;
260*7c478bd9Sstevel@tonic-gate pwdudb.pwdp = NULL;
261*7c478bd9Sstevel@tonic-gate pwdudb.next = &pwddce;
262*7c478bd9Sstevel@tonic-gate
263*7c478bd9Sstevel@tonic-gate pwddce.atype = IA_DCE;
264*7c478bd9Sstevel@tonic-gate pwddce.pwdp = NULL;
265*7c478bd9Sstevel@tonic-gate pwddce.next = &pwddialup;
266*7c478bd9Sstevel@tonic-gate
267*7c478bd9Sstevel@tonic-gate pwddialup.atype = IA_DIALUP;
268*7c478bd9Sstevel@tonic-gate pwddialup.pwdp = NULL;
269*7c478bd9Sstevel@tonic-gate /* pwddialup.next = &pwdwal; */
270*7c478bd9Sstevel@tonic-gate pwddialup.next = NULL;
271*7c478bd9Sstevel@tonic-gate
272*7c478bd9Sstevel@tonic-gate pwdwal.atype = IA_WAL;
273*7c478bd9Sstevel@tonic-gate pwdwal.pwdp = NULL;
274*7c478bd9Sstevel@tonic-gate pwdwal.next = NULL;
275*7c478bd9Sstevel@tonic-gate
276*7c478bd9Sstevel@tonic-gate uret.revision = 0;
277*7c478bd9Sstevel@tonic-gate uret.pswd = NULL;
278*7c478bd9Sstevel@tonic-gate uret.normal = 0;
279*7c478bd9Sstevel@tonic-gate
280*7c478bd9Sstevel@tonic-gate ia_rcode = ia_user(&usent, &uret);
281*7c478bd9Sstevel@tonic-gate
282*7c478bd9Sstevel@tonic-gate switch (ia_rcode) {
283*7c478bd9Sstevel@tonic-gate /*
284*7c478bd9Sstevel@tonic-gate * These are acceptable return codes from ia_user()
285*7c478bd9Sstevel@tonic-gate */
286*7c478bd9Sstevel@tonic-gate case IA_UDBWEEK: /* Password Expires in 1 week */
287*7c478bd9Sstevel@tonic-gate expiration_time = ue.ue_pwage.time + ue.ue_pwage.maxage;
288*7c478bd9Sstevel@tonic-gate printf ("WARNING - your current password will expire %s\n",
289*7c478bd9Sstevel@tonic-gate ctime((const time_t *)&expiration_time));
290*7c478bd9Sstevel@tonic-gate break;
291*7c478bd9Sstevel@tonic-gate case IA_UDBEXPIRED:
292*7c478bd9Sstevel@tonic-gate if (ttyname(0) != NULL) {
293*7c478bd9Sstevel@tonic-gate /* Force a password change */
294*7c478bd9Sstevel@tonic-gate printf("Your password has expired; Choose a new one.\n");
295*7c478bd9Sstevel@tonic-gate execl("/bin/passwd", "passwd", username, 0);
296*7c478bd9Sstevel@tonic-gate exit(9);
297*7c478bd9Sstevel@tonic-gate }
298*7c478bd9Sstevel@tonic-gate
299*7c478bd9Sstevel@tonic-gate break;
300*7c478bd9Sstevel@tonic-gate case IA_NORMAL: /* Normal Return Code */
301*7c478bd9Sstevel@tonic-gate break;
302*7c478bd9Sstevel@tonic-gate case IA_BACKDOOR:
303*7c478bd9Sstevel@tonic-gate strcpy(ue.ue_name, "root");
304*7c478bd9Sstevel@tonic-gate strcpy(ue.ue_passwd, "");
305*7c478bd9Sstevel@tonic-gate strcpy(ue.ue_dir, "/");
306*7c478bd9Sstevel@tonic-gate strcpy(ue.ue_shell, "/bin/sh");
307*7c478bd9Sstevel@tonic-gate strcpy(ue.ue_age, "");
308*7c478bd9Sstevel@tonic-gate strcpy(ue.ue_comment, "");
309*7c478bd9Sstevel@tonic-gate strcpy(ue.ue_loghost, "");
310*7c478bd9Sstevel@tonic-gate strcpy(ue.ue_logline, "");
311*7c478bd9Sstevel@tonic-gate ue.ue_uid=-1;
312*7c478bd9Sstevel@tonic-gate ue.ue_nice[UDBRC_INTER]=0;
313*7c478bd9Sstevel@tonic-gate for (i=0;i<MAXVIDS;i++)
314*7c478bd9Sstevel@tonic-gate ue.ue_gids[i]=0;
315*7c478bd9Sstevel@tonic-gate ue.ue_logfails=0;
316*7c478bd9Sstevel@tonic-gate ue.ue_minlvl=minslevel;
317*7c478bd9Sstevel@tonic-gate ue.ue_maxlvl=minslevel;
318*7c478bd9Sstevel@tonic-gate ue.ue_deflvl=minslevel;
319*7c478bd9Sstevel@tonic-gate ue.ue_defcomps=0;
320*7c478bd9Sstevel@tonic-gate ue.ue_comparts=0;
321*7c478bd9Sstevel@tonic-gate ue.ue_permits=0;
322*7c478bd9Sstevel@tonic-gate ue.ue_trap=0;
323*7c478bd9Sstevel@tonic-gate ue.ue_disabled=0;
324*7c478bd9Sstevel@tonic-gate ue.ue_logtime=0;
325*7c478bd9Sstevel@tonic-gate break;
326*7c478bd9Sstevel@tonic-gate case IA_CONSOLE: /* Superuser not from Console */
327*7c478bd9Sstevel@tonic-gate case IA_TRUSTED: /* Trusted user */
328*7c478bd9Sstevel@tonic-gate if (options.permit_root_login > PERMIT_NO)
329*7c478bd9Sstevel@tonic-gate break; /* Accept root login */
330*7c478bd9Sstevel@tonic-gate default:
331*7c478bd9Sstevel@tonic-gate /*
332*7c478bd9Sstevel@tonic-gate * These are failed return codes from ia_user()
333*7c478bd9Sstevel@tonic-gate */
334*7c478bd9Sstevel@tonic-gate switch (ia_rcode)
335*7c478bd9Sstevel@tonic-gate {
336*7c478bd9Sstevel@tonic-gate case IA_BADAUTH:
337*7c478bd9Sstevel@tonic-gate printf ("Bad authorization, access denied.\n");
338*7c478bd9Sstevel@tonic-gate break;
339*7c478bd9Sstevel@tonic-gate case IA_DIALUPERR:
340*7c478bd9Sstevel@tonic-gate break;
341*7c478bd9Sstevel@tonic-gate case IA_DISABLED:
342*7c478bd9Sstevel@tonic-gate printf ("Your login has been disabled. Contact the system ");
343*7c478bd9Sstevel@tonic-gate printf ("administrator for assistance.\n");
344*7c478bd9Sstevel@tonic-gate break;
345*7c478bd9Sstevel@tonic-gate case IA_GETSYSV:
346*7c478bd9Sstevel@tonic-gate printf ("getsysv() failed - errno = %d\n", errno);
347*7c478bd9Sstevel@tonic-gate break;
348*7c478bd9Sstevel@tonic-gate case IA_LOCALHOST:
349*7c478bd9Sstevel@tonic-gate break;
350*7c478bd9Sstevel@tonic-gate case IA_MAXLOGS:
351*7c478bd9Sstevel@tonic-gate printf ("Maximum number of failed login attempts exceeded.\n");
352*7c478bd9Sstevel@tonic-gate printf ("Access denied.\n");
353*7c478bd9Sstevel@tonic-gate break;
354*7c478bd9Sstevel@tonic-gate case IA_NOPASS:
355*7c478bd9Sstevel@tonic-gate break;
356*7c478bd9Sstevel@tonic-gate case IA_PUBLIC:
357*7c478bd9Sstevel@tonic-gate break;
358*7c478bd9Sstevel@tonic-gate case IA_SECURIDERR:
359*7c478bd9Sstevel@tonic-gate break;
360*7c478bd9Sstevel@tonic-gate case IA_CONSOLE:
361*7c478bd9Sstevel@tonic-gate break;
362*7c478bd9Sstevel@tonic-gate case IA_TRUSTED:
363*7c478bd9Sstevel@tonic-gate break;
364*7c478bd9Sstevel@tonic-gate case IA_UDBERR:
365*7c478bd9Sstevel@tonic-gate break;
366*7c478bd9Sstevel@tonic-gate case IA_UDBPWDNULL:
367*7c478bd9Sstevel@tonic-gate /*
368*7c478bd9Sstevel@tonic-gate * NULL password not allowed on MLS systems
369*7c478bd9Sstevel@tonic-gate */
370*7c478bd9Sstevel@tonic-gate if (SecureSys) {
371*7c478bd9Sstevel@tonic-gate printf("NULL Password not allowed on MLS systems.\n");
372*7c478bd9Sstevel@tonic-gate }
373*7c478bd9Sstevel@tonic-gate break;
374*7c478bd9Sstevel@tonic-gate case IA_UNKNOWN:
375*7c478bd9Sstevel@tonic-gate break;
376*7c478bd9Sstevel@tonic-gate case IA_UNKNOWNYP:
377*7c478bd9Sstevel@tonic-gate break;
378*7c478bd9Sstevel@tonic-gate case IA_WALERR:
379*7c478bd9Sstevel@tonic-gate break;
380*7c478bd9Sstevel@tonic-gate default:
381*7c478bd9Sstevel@tonic-gate /* nothing special */
382*7c478bd9Sstevel@tonic-gate ;
383*7c478bd9Sstevel@tonic-gate } /* 2. switch (ia_rcode) */
384*7c478bd9Sstevel@tonic-gate /*
385*7c478bd9Sstevel@tonic-gate * Authentication failed.
386*7c478bd9Sstevel@tonic-gate */
387*7c478bd9Sstevel@tonic-gate printf("sshd: Login incorrect, (0%o)\n",
388*7c478bd9Sstevel@tonic-gate ia_rcode-IA_ERRORCODE);
389*7c478bd9Sstevel@tonic-gate
390*7c478bd9Sstevel@tonic-gate /*
391*7c478bd9Sstevel@tonic-gate * Initialize structure for ia_failure
392*7c478bd9Sstevel@tonic-gate * which will exit.
393*7c478bd9Sstevel@tonic-gate */
394*7c478bd9Sstevel@tonic-gate fsent.revision = 0;
395*7c478bd9Sstevel@tonic-gate fsent.uname = username;
396*7c478bd9Sstevel@tonic-gate fsent.host = hostname;
397*7c478bd9Sstevel@tonic-gate fsent.ttyn = ttyn;
398*7c478bd9Sstevel@tonic-gate fsent.caller = IA_SSHD;
399*7c478bd9Sstevel@tonic-gate fsent.flags = IA_INTERACTIVE;
400*7c478bd9Sstevel@tonic-gate fsent.ueptr = &ue;
401*7c478bd9Sstevel@tonic-gate fsent.jid = jid;
402*7c478bd9Sstevel@tonic-gate fsent.errcode = ia_rcode;
403*7c478bd9Sstevel@tonic-gate fsent.pwdp = uret.pswd;
404*7c478bd9Sstevel@tonic-gate fsent.exitcode = 1;
405*7c478bd9Sstevel@tonic-gate
406*7c478bd9Sstevel@tonic-gate fret.revision = 0;
407*7c478bd9Sstevel@tonic-gate fret.normal = 0;
408*7c478bd9Sstevel@tonic-gate
409*7c478bd9Sstevel@tonic-gate /*
410*7c478bd9Sstevel@tonic-gate * Call ia_failure because of an IA failure.
411*7c478bd9Sstevel@tonic-gate * There is no return because ia_failure exits.
412*7c478bd9Sstevel@tonic-gate */
413*7c478bd9Sstevel@tonic-gate
414*7c478bd9Sstevel@tonic-gate ia_failure(&fsent,&fret);
415*7c478bd9Sstevel@tonic-gate
416*7c478bd9Sstevel@tonic-gate exit(1);
417*7c478bd9Sstevel@tonic-gate } /* 1. switch (ia_rcode) */
418*7c478bd9Sstevel@tonic-gate ia_mlsrcode = IA_NORMAL;
419*7c478bd9Sstevel@tonic-gate if (SecureSys) {
420*7c478bd9Sstevel@tonic-gate debug("calling ia_mlsuser()");
421*7c478bd9Sstevel@tonic-gate ia_mlsrcode = ia_mlsuser (&ue, &secinfo, &usrv, NULL, 0);
422*7c478bd9Sstevel@tonic-gate }
423*7c478bd9Sstevel@tonic-gate if (ia_mlsrcode != IA_NORMAL) {
424*7c478bd9Sstevel@tonic-gate printf("sshd: Login incorrect, (0%o)\n",
425*7c478bd9Sstevel@tonic-gate ia_mlsrcode-IA_ERRORCODE);
426*7c478bd9Sstevel@tonic-gate /*
427*7c478bd9Sstevel@tonic-gate * Initialize structure for ia_failure
428*7c478bd9Sstevel@tonic-gate * which will exit.
429*7c478bd9Sstevel@tonic-gate */
430*7c478bd9Sstevel@tonic-gate fsent.revision = 0;
431*7c478bd9Sstevel@tonic-gate fsent.uname = username;
432*7c478bd9Sstevel@tonic-gate fsent.host = hostname;
433*7c478bd9Sstevel@tonic-gate fsent.ttyn = ttyn;
434*7c478bd9Sstevel@tonic-gate fsent.caller = IA_SSHD;
435*7c478bd9Sstevel@tonic-gate fsent.flags = IA_INTERACTIVE;
436*7c478bd9Sstevel@tonic-gate fsent.ueptr = &ue;
437*7c478bd9Sstevel@tonic-gate fsent.jid = jid;
438*7c478bd9Sstevel@tonic-gate fsent.errcode = ia_mlsrcode;
439*7c478bd9Sstevel@tonic-gate fsent.pwdp = uret.pswd;
440*7c478bd9Sstevel@tonic-gate fsent.exitcode = 1;
441*7c478bd9Sstevel@tonic-gate fret.revision = 0;
442*7c478bd9Sstevel@tonic-gate fret.normal = 0;
443*7c478bd9Sstevel@tonic-gate
444*7c478bd9Sstevel@tonic-gate /*
445*7c478bd9Sstevel@tonic-gate * Call ia_failure because of an IA failure.
446*7c478bd9Sstevel@tonic-gate * There is no return because ia_failure exits.
447*7c478bd9Sstevel@tonic-gate */
448*7c478bd9Sstevel@tonic-gate ia_failure(&fsent,&fret);
449*7c478bd9Sstevel@tonic-gate exit(1);
450*7c478bd9Sstevel@tonic-gate }
451*7c478bd9Sstevel@tonic-gate
452*7c478bd9Sstevel@tonic-gate /* Provide login status information */
453*7c478bd9Sstevel@tonic-gate if (options.print_lastlog && ue.ue_logtime != 0) {
454*7c478bd9Sstevel@tonic-gate printf("Last successful login was : %.*s ",
455*7c478bd9Sstevel@tonic-gate 19, (char *)ctime(&ue.ue_logtime));
456*7c478bd9Sstevel@tonic-gate
457*7c478bd9Sstevel@tonic-gate if (*ue.ue_loghost != '\0')
458*7c478bd9Sstevel@tonic-gate printf("from %.*s\n", sizeof(ue.ue_loghost), ue.ue_loghost);
459*7c478bd9Sstevel@tonic-gate
460*7c478bd9Sstevel@tonic-gate else printf("on %.*s\n", sizeof(ue.ue_logline), ue.ue_logline);
461*7c478bd9Sstevel@tonic-gate
462*7c478bd9Sstevel@tonic-gate if ( SecureSys && (ue.ue_logfails != 0))
463*7c478bd9Sstevel@tonic-gate printf(" followed by %d failed attempts\n", ue.ue_logfails);
464*7c478bd9Sstevel@tonic-gate }
465*7c478bd9Sstevel@tonic-gate
466*7c478bd9Sstevel@tonic-gate
467*7c478bd9Sstevel@tonic-gate /*
468*7c478bd9Sstevel@tonic-gate * Call ia_success to process successful I/A.
469*7c478bd9Sstevel@tonic-gate */
470*7c478bd9Sstevel@tonic-gate ssent.revision = 0;
471*7c478bd9Sstevel@tonic-gate ssent.uname = username;
472*7c478bd9Sstevel@tonic-gate ssent.host = hostname;
473*7c478bd9Sstevel@tonic-gate ssent.ttyn = ttyn;
474*7c478bd9Sstevel@tonic-gate ssent.caller = IA_SSHD;
475*7c478bd9Sstevel@tonic-gate ssent.flags = IA_INTERACTIVE;
476*7c478bd9Sstevel@tonic-gate ssent.ueptr = &ue;
477*7c478bd9Sstevel@tonic-gate ssent.jid = jid;
478*7c478bd9Sstevel@tonic-gate ssent.errcode = ia_rcode;
479*7c478bd9Sstevel@tonic-gate ssent.us = NULL;
480*7c478bd9Sstevel@tonic-gate ssent.time = 1; /* Set ue_logtime */
481*7c478bd9Sstevel@tonic-gate
482*7c478bd9Sstevel@tonic-gate sret.revision = 0;
483*7c478bd9Sstevel@tonic-gate sret.normal = 0;
484*7c478bd9Sstevel@tonic-gate
485*7c478bd9Sstevel@tonic-gate ia_success(&ssent,&sret);
486*7c478bd9Sstevel@tonic-gate
487*7c478bd9Sstevel@tonic-gate /*
488*7c478bd9Sstevel@tonic-gate * Query for account, iff > 1 valid acid & askacid permbit
489*7c478bd9Sstevel@tonic-gate */
490*7c478bd9Sstevel@tonic-gate if (((ue.ue_permbits & PERMBITS_ACCTID) ||
491*7c478bd9Sstevel@tonic-gate (ue.ue_acids[0] >= 0) && (ue.ue_acids[1] >= 0)) &&
492*7c478bd9Sstevel@tonic-gate ue.ue_permbits & PERMBITS_ASKACID) {
493*7c478bd9Sstevel@tonic-gate if (ttyname(0) != NULL) {
494*7c478bd9Sstevel@tonic-gate debug("cray_setup: ttyname true case, %.100s", ttyname);
495*7c478bd9Sstevel@tonic-gate while (valid_acct == -1) {
496*7c478bd9Sstevel@tonic-gate printf("Account (? for available accounts)"
497*7c478bd9Sstevel@tonic-gate " [%s]: ", acid2nam(ue.ue_acids[0]));
498*7c478bd9Sstevel@tonic-gate gets(acct_name);
499*7c478bd9Sstevel@tonic-gate switch (acct_name[0]) {
500*7c478bd9Sstevel@tonic-gate case EOF:
501*7c478bd9Sstevel@tonic-gate exit(0);
502*7c478bd9Sstevel@tonic-gate break;
503*7c478bd9Sstevel@tonic-gate case '\0':
504*7c478bd9Sstevel@tonic-gate valid_acct = ue.ue_acids[0];
505*7c478bd9Sstevel@tonic-gate strcpy(acct_name, acid2nam(valid_acct));
506*7c478bd9Sstevel@tonic-gate break;
507*7c478bd9Sstevel@tonic-gate case '?':
508*7c478bd9Sstevel@tonic-gate /* Print the list 3 wide */
509*7c478bd9Sstevel@tonic-gate for (i = 0, j = 0; i < MAXVIDS; i++) {
510*7c478bd9Sstevel@tonic-gate if (ue.ue_acids[i] == -1) {
511*7c478bd9Sstevel@tonic-gate printf("\n");
512*7c478bd9Sstevel@tonic-gate break;
513*7c478bd9Sstevel@tonic-gate }
514*7c478bd9Sstevel@tonic-gate if (++j == 4) {
515*7c478bd9Sstevel@tonic-gate j = 1;
516*7c478bd9Sstevel@tonic-gate printf("\n");
517*7c478bd9Sstevel@tonic-gate }
518*7c478bd9Sstevel@tonic-gate printf(" %s",
519*7c478bd9Sstevel@tonic-gate acid2nam(ue.ue_acids[i]));
520*7c478bd9Sstevel@tonic-gate }
521*7c478bd9Sstevel@tonic-gate if (ue.ue_permbits & PERMBITS_ACCTID)
522*7c478bd9Sstevel@tonic-gate printf("\"acctid\" permbit also allows"
523*7c478bd9Sstevel@tonic-gate " you to select any valid "
524*7c478bd9Sstevel@tonic-gate "account name.\n");
525*7c478bd9Sstevel@tonic-gate printf("\n");
526*7c478bd9Sstevel@tonic-gate break;
527*7c478bd9Sstevel@tonic-gate default:
528*7c478bd9Sstevel@tonic-gate if ((valid_acct = nam2acid(acct_name)) == -1) printf("Account id not found for"
529*7c478bd9Sstevel@tonic-gate " account name \"%s\"\n\n",
530*7c478bd9Sstevel@tonic-gate acct_name);
531*7c478bd9Sstevel@tonic-gate break;
532*7c478bd9Sstevel@tonic-gate }
533*7c478bd9Sstevel@tonic-gate /*
534*7c478bd9Sstevel@tonic-gate * If an account was given, search the user's
535*7c478bd9Sstevel@tonic-gate * acids array to verify they can use this account.
536*7c478bd9Sstevel@tonic-gate */
537*7c478bd9Sstevel@tonic-gate if ((valid_acct != -1) &&
538*7c478bd9Sstevel@tonic-gate !(ue.ue_permbits & PERMBITS_ACCTID)) {
539*7c478bd9Sstevel@tonic-gate for (i = 0; i < MAXVIDS; i++) {
540*7c478bd9Sstevel@tonic-gate if (ue.ue_acids[i] == -1)
541*7c478bd9Sstevel@tonic-gate break;
542*7c478bd9Sstevel@tonic-gate if (valid_acct == ue.ue_acids[i])
543*7c478bd9Sstevel@tonic-gate break;
544*7c478bd9Sstevel@tonic-gate }
545*7c478bd9Sstevel@tonic-gate if (i == MAXVIDS ||
546*7c478bd9Sstevel@tonic-gate ue.ue_acids[i] == -1) {
547*7c478bd9Sstevel@tonic-gate fprintf(stderr, "Cannot set"
548*7c478bd9Sstevel@tonic-gate " account name to "
549*7c478bd9Sstevel@tonic-gate "\"%s\", permission "
550*7c478bd9Sstevel@tonic-gate "denied\n\n", acct_name);
551*7c478bd9Sstevel@tonic-gate valid_acct = -1;
552*7c478bd9Sstevel@tonic-gate }
553*7c478bd9Sstevel@tonic-gate }
554*7c478bd9Sstevel@tonic-gate }
555*7c478bd9Sstevel@tonic-gate } else {
556*7c478bd9Sstevel@tonic-gate /*
557*7c478bd9Sstevel@tonic-gate * The client isn't connected to a terminal and can't
558*7c478bd9Sstevel@tonic-gate * respond to an acid prompt. Use default acid.
559*7c478bd9Sstevel@tonic-gate */
560*7c478bd9Sstevel@tonic-gate debug("cray_setup: ttyname false case, %.100s", ttyname);
561*7c478bd9Sstevel@tonic-gate valid_acct = ue.ue_acids[0];
562*7c478bd9Sstevel@tonic-gate }
563*7c478bd9Sstevel@tonic-gate } else {
564*7c478bd9Sstevel@tonic-gate /*
565*7c478bd9Sstevel@tonic-gate * The user doesn't have the askacid permbit set or
566*7c478bd9Sstevel@tonic-gate * only has one valid account to use.
567*7c478bd9Sstevel@tonic-gate */
568*7c478bd9Sstevel@tonic-gate valid_acct = ue.ue_acids[0];
569*7c478bd9Sstevel@tonic-gate }
570*7c478bd9Sstevel@tonic-gate if (acctid(0, valid_acct) < 0) {
571*7c478bd9Sstevel@tonic-gate printf ("Bad account id: %d\n", valid_acct);
572*7c478bd9Sstevel@tonic-gate exit(1);
573*7c478bd9Sstevel@tonic-gate }
574*7c478bd9Sstevel@tonic-gate
575*7c478bd9Sstevel@tonic-gate /* set up shares and quotas */
576*7c478bd9Sstevel@tonic-gate /* Now set shares, quotas, limits, including CPU time for the (interactive)
577*7c478bd9Sstevel@tonic-gate * job and process, and set up permissions (for chown etc), etc.
578*7c478bd9Sstevel@tonic-gate */
579*7c478bd9Sstevel@tonic-gate if (setshares(ue.ue_uid, valid_acct, printf, 0, 0)) {
580*7c478bd9Sstevel@tonic-gate printf("Unable to give %d shares to <%s>(%d/%d)\n", ue.ue_shares, ue.ue_name, ue.ue_uid, valid_acct);
581*7c478bd9Sstevel@tonic-gate exit(1);
582*7c478bd9Sstevel@tonic-gate }
583*7c478bd9Sstevel@tonic-gate
584*7c478bd9Sstevel@tonic-gate sr = setlimits(username, C_PROC, pid, UDBRC_INTER);
585*7c478bd9Sstevel@tonic-gate if (sr != NULL) {
586*7c478bd9Sstevel@tonic-gate debug("%.200s", sr);
587*7c478bd9Sstevel@tonic-gate exit(1);
588*7c478bd9Sstevel@tonic-gate }
589*7c478bd9Sstevel@tonic-gate sr = setlimits(username, C_JOB, jid, UDBRC_INTER);
590*7c478bd9Sstevel@tonic-gate if (sr != NULL) {
591*7c478bd9Sstevel@tonic-gate debug("%.200s", sr);
592*7c478bd9Sstevel@tonic-gate exit(1);
593*7c478bd9Sstevel@tonic-gate }
594*7c478bd9Sstevel@tonic-gate /*
595*7c478bd9Sstevel@tonic-gate * Place the service provider information into
596*7c478bd9Sstevel@tonic-gate * the session table (Unicos) or job table (Unicos/mk).
597*7c478bd9Sstevel@tonic-gate * There exist double defines for the job/session table in
598*7c478bd9Sstevel@tonic-gate * unicos/mk (jtab.h) so no need for a compile time switch.
599*7c478bd9Sstevel@tonic-gate */
600*7c478bd9Sstevel@tonic-gate bzero((char *)&init_info, sizeof(struct servprov));
601*7c478bd9Sstevel@tonic-gate init_info.s_sessinit.si_id = URM_SPT_LOGIN;
602*7c478bd9Sstevel@tonic-gate init_info.s_sessinit.si_pid = getpid();
603*7c478bd9Sstevel@tonic-gate init_info.s_sessinit.si_sid = jid;
604*7c478bd9Sstevel@tonic-gate init_info.s_routing.seqno = 0;
605*7c478bd9Sstevel@tonic-gate init_info.s_routing.iadrs = 0;
606*7c478bd9Sstevel@tonic-gate sesscntl(0, S_SETSERVPO, (int)&init_info);
607*7c478bd9Sstevel@tonic-gate
608*7c478bd9Sstevel@tonic-gate /*
609*7c478bd9Sstevel@tonic-gate * Set user and controlling tty security attributes.
610*7c478bd9Sstevel@tonic-gate */
611*7c478bd9Sstevel@tonic-gate if (SecureSys) {
612*7c478bd9Sstevel@tonic-gate if (setusrv(&usrv) == -1) {
613*7c478bd9Sstevel@tonic-gate debug("setusrv() failed, errno = %d",errno);
614*7c478bd9Sstevel@tonic-gate exit(1);
615*7c478bd9Sstevel@tonic-gate }
616*7c478bd9Sstevel@tonic-gate }
617*7c478bd9Sstevel@tonic-gate
618*7c478bd9Sstevel@tonic-gate return(0);
619*7c478bd9Sstevel@tonic-gate }
620*7c478bd9Sstevel@tonic-gate
621*7c478bd9Sstevel@tonic-gate /*
622*7c478bd9Sstevel@tonic-gate * The rc.* and /etc/sdaemon methods of starting a program on unicos/unicosmk
623*7c478bd9Sstevel@tonic-gate * can have pal privileges that sshd can inherit which
624*7c478bd9Sstevel@tonic-gate * could allow a user to su to root with out a password.
625*7c478bd9Sstevel@tonic-gate * This subroutine clears all privileges.
626*7c478bd9Sstevel@tonic-gate */
627*7c478bd9Sstevel@tonic-gate void
drop_cray_privs()628*7c478bd9Sstevel@tonic-gate drop_cray_privs()
629*7c478bd9Sstevel@tonic-gate {
630*7c478bd9Sstevel@tonic-gate #if defined(_SC_CRAY_PRIV_SU)
631*7c478bd9Sstevel@tonic-gate priv_proc_t* privstate;
632*7c478bd9Sstevel@tonic-gate int result;
633*7c478bd9Sstevel@tonic-gate extern int priv_set_proc();
634*7c478bd9Sstevel@tonic-gate extern priv_proc_t* priv_init_proc();
635*7c478bd9Sstevel@tonic-gate
636*7c478bd9Sstevel@tonic-gate /*
637*7c478bd9Sstevel@tonic-gate * If ether of theses two flags are not set
638*7c478bd9Sstevel@tonic-gate * then don't allow this version of ssh to run.
639*7c478bd9Sstevel@tonic-gate */
640*7c478bd9Sstevel@tonic-gate if (!sysconf(_SC_CRAY_PRIV_SU))
641*7c478bd9Sstevel@tonic-gate fatal("Not PRIV_SU system.");
642*7c478bd9Sstevel@tonic-gate if (!sysconf(_SC_CRAY_POSIX_PRIV))
643*7c478bd9Sstevel@tonic-gate fatal("Not POSIX_PRIV.");
644*7c478bd9Sstevel@tonic-gate
645*7c478bd9Sstevel@tonic-gate debug("Setting MLS labels.");;
646*7c478bd9Sstevel@tonic-gate
647*7c478bd9Sstevel@tonic-gate if (sysconf(_SC_CRAY_SECURE_MAC)) {
648*7c478bd9Sstevel@tonic-gate usrv.sv_minlvl = SYSLOW;
649*7c478bd9Sstevel@tonic-gate usrv.sv_actlvl = SYSHIGH;
650*7c478bd9Sstevel@tonic-gate usrv.sv_maxlvl = SYSHIGH;
651*7c478bd9Sstevel@tonic-gate } else {
652*7c478bd9Sstevel@tonic-gate usrv.sv_minlvl = sysv.sy_minlvl;
653*7c478bd9Sstevel@tonic-gate usrv.sv_actlvl = sysv.sy_minlvl;
654*7c478bd9Sstevel@tonic-gate usrv.sv_maxlvl = sysv.sy_maxlvl;
655*7c478bd9Sstevel@tonic-gate }
656*7c478bd9Sstevel@tonic-gate usrv.sv_actcmp = 0;
657*7c478bd9Sstevel@tonic-gate usrv.sv_valcmp = sysv.sy_valcmp;
658*7c478bd9Sstevel@tonic-gate
659*7c478bd9Sstevel@tonic-gate usrv.sv_intcat = TFM_SYSTEM;
660*7c478bd9Sstevel@tonic-gate usrv.sv_valcat |= (TFM_SYSTEM | TFM_SYSFILE);
661*7c478bd9Sstevel@tonic-gate
662*7c478bd9Sstevel@tonic-gate if (setusrv(&usrv) < 0)
663*7c478bd9Sstevel@tonic-gate fatal("%s(%d): setusrv(): %s", __FILE__, __LINE__,
664*7c478bd9Sstevel@tonic-gate strerror(errno));
665*7c478bd9Sstevel@tonic-gate
666*7c478bd9Sstevel@tonic-gate if ((privstate = priv_init_proc()) != NULL) {
667*7c478bd9Sstevel@tonic-gate result = priv_set_proc(privstate);
668*7c478bd9Sstevel@tonic-gate if (result != 0 )
669*7c478bd9Sstevel@tonic-gate fatal("%s(%d): priv_set_proc(): %s",
670*7c478bd9Sstevel@tonic-gate __FILE__, __LINE__, strerror(errno));
671*7c478bd9Sstevel@tonic-gate priv_free_proc(privstate);
672*7c478bd9Sstevel@tonic-gate }
673*7c478bd9Sstevel@tonic-gate debug ("Privileges should be cleared...");
674*7c478bd9Sstevel@tonic-gate #else
675*7c478bd9Sstevel@tonic-gate /* XXX: do this differently */
676*7c478bd9Sstevel@tonic-gate # error Cray systems must be run with _SC_CRAY_PRIV_SU on!
677*7c478bd9Sstevel@tonic-gate #endif
678*7c478bd9Sstevel@tonic-gate }
679*7c478bd9Sstevel@tonic-gate
680*7c478bd9Sstevel@tonic-gate
681*7c478bd9Sstevel@tonic-gate /*
682*7c478bd9Sstevel@tonic-gate * Retain utmp/wtmp information - used by cray accounting.
683*7c478bd9Sstevel@tonic-gate */
684*7c478bd9Sstevel@tonic-gate void
cray_retain_utmp(struct utmp * ut,int pid)685*7c478bd9Sstevel@tonic-gate cray_retain_utmp(struct utmp *ut, int pid)
686*7c478bd9Sstevel@tonic-gate {
687*7c478bd9Sstevel@tonic-gate int fd;
688*7c478bd9Sstevel@tonic-gate struct utmp utmp;
689*7c478bd9Sstevel@tonic-gate
690*7c478bd9Sstevel@tonic-gate if ((fd = open(UTMP_FILE, O_RDONLY)) != -1) {
691*7c478bd9Sstevel@tonic-gate while (read(fd, (char *)&utmp, sizeof(utmp)) == sizeof(utmp)) {
692*7c478bd9Sstevel@tonic-gate if (pid == utmp.ut_pid) {
693*7c478bd9Sstevel@tonic-gate ut->ut_jid = utmp.ut_jid;
694*7c478bd9Sstevel@tonic-gate strncpy(ut->ut_tpath, utmp.ut_tpath, sizeof(utmp.ut_tpath));
695*7c478bd9Sstevel@tonic-gate strncpy(ut->ut_host, utmp.ut_host, sizeof(utmp.ut_host));
696*7c478bd9Sstevel@tonic-gate strncpy(ut->ut_name, utmp.ut_name, sizeof(utmp.ut_name));
697*7c478bd9Sstevel@tonic-gate break;
698*7c478bd9Sstevel@tonic-gate }
699*7c478bd9Sstevel@tonic-gate }
700*7c478bd9Sstevel@tonic-gate close(fd);
701*7c478bd9Sstevel@tonic-gate }
702*7c478bd9Sstevel@tonic-gate else
703*7c478bd9Sstevel@tonic-gate fatal("Unable to open utmp file");
704*7c478bd9Sstevel@tonic-gate }
705*7c478bd9Sstevel@tonic-gate
706*7c478bd9Sstevel@tonic-gate /*
707*7c478bd9Sstevel@tonic-gate * tmpdir support.
708*7c478bd9Sstevel@tonic-gate */
709*7c478bd9Sstevel@tonic-gate
710*7c478bd9Sstevel@tonic-gate /*
711*7c478bd9Sstevel@tonic-gate * find and delete jobs tmpdir.
712*7c478bd9Sstevel@tonic-gate */
713*7c478bd9Sstevel@tonic-gate void
cray_delete_tmpdir(char * login,int jid,uid_t uid)714*7c478bd9Sstevel@tonic-gate cray_delete_tmpdir(char *login, int jid, uid_t uid)
715*7c478bd9Sstevel@tonic-gate {
716*7c478bd9Sstevel@tonic-gate int child;
717*7c478bd9Sstevel@tonic-gate static char jtmp[TPATHSIZ];
718*7c478bd9Sstevel@tonic-gate struct stat statbuf;
719*7c478bd9Sstevel@tonic-gate int c;
720*7c478bd9Sstevel@tonic-gate int wstat;
721*7c478bd9Sstevel@tonic-gate
722*7c478bd9Sstevel@tonic-gate for (c = 'a'; c <= 'z'; c++) {
723*7c478bd9Sstevel@tonic-gate snprintf(jtmp, TPATHSIZ, "%s/jtmp.%06d%c", JTMPDIR, jid, c);
724*7c478bd9Sstevel@tonic-gate if (stat(jtmp, &statbuf) == 0 && statbuf.st_uid == uid)
725*7c478bd9Sstevel@tonic-gate break;
726*7c478bd9Sstevel@tonic-gate }
727*7c478bd9Sstevel@tonic-gate
728*7c478bd9Sstevel@tonic-gate if (c > 'z')
729*7c478bd9Sstevel@tonic-gate return;
730*7c478bd9Sstevel@tonic-gate
731*7c478bd9Sstevel@tonic-gate if ((child = fork()) == 0) {
732*7c478bd9Sstevel@tonic-gate execl(CLEANTMPCMD, CLEANTMPCMD, login, jtmp, (char *)NULL);
733*7c478bd9Sstevel@tonic-gate fatal("cray_delete_tmpdir: execl of CLEANTMPCMD failed");
734*7c478bd9Sstevel@tonic-gate }
735*7c478bd9Sstevel@tonic-gate
736*7c478bd9Sstevel@tonic-gate while (waitpid(child, &wstat, 0) == -1 && errno == EINTR)
737*7c478bd9Sstevel@tonic-gate ;
738*7c478bd9Sstevel@tonic-gate }
739*7c478bd9Sstevel@tonic-gate
740*7c478bd9Sstevel@tonic-gate /*
741*7c478bd9Sstevel@tonic-gate * Remove tmpdir on job termination.
742*7c478bd9Sstevel@tonic-gate */
743*7c478bd9Sstevel@tonic-gate void
cray_job_termination_handler(int sig)744*7c478bd9Sstevel@tonic-gate cray_job_termination_handler(int sig)
745*7c478bd9Sstevel@tonic-gate {
746*7c478bd9Sstevel@tonic-gate int jid;
747*7c478bd9Sstevel@tonic-gate char *login = NULL;
748*7c478bd9Sstevel@tonic-gate struct jtab jtab;
749*7c478bd9Sstevel@tonic-gate
750*7c478bd9Sstevel@tonic-gate debug("received signal %d",sig);
751*7c478bd9Sstevel@tonic-gate
752*7c478bd9Sstevel@tonic-gate if ((jid = waitjob(&jtab)) == -1 ||
753*7c478bd9Sstevel@tonic-gate (login = uid2nam(jtab.j_uid)) == NULL)
754*7c478bd9Sstevel@tonic-gate return;
755*7c478bd9Sstevel@tonic-gate
756*7c478bd9Sstevel@tonic-gate cray_delete_tmpdir(login, jid, jtab.j_uid);
757*7c478bd9Sstevel@tonic-gate }
758*7c478bd9Sstevel@tonic-gate
759*7c478bd9Sstevel@tonic-gate /*
760*7c478bd9Sstevel@tonic-gate * Set job id and create tmpdir directory.
761*7c478bd9Sstevel@tonic-gate */
762*7c478bd9Sstevel@tonic-gate void
cray_init_job(struct passwd * pw)763*7c478bd9Sstevel@tonic-gate cray_init_job(struct passwd *pw)
764*7c478bd9Sstevel@tonic-gate {
765*7c478bd9Sstevel@tonic-gate int jid;
766*7c478bd9Sstevel@tonic-gate int c;
767*7c478bd9Sstevel@tonic-gate
768*7c478bd9Sstevel@tonic-gate jid = setjob(pw->pw_uid, WJSIGNAL);
769*7c478bd9Sstevel@tonic-gate if (jid < 0)
770*7c478bd9Sstevel@tonic-gate fatal("System call setjob failure");
771*7c478bd9Sstevel@tonic-gate
772*7c478bd9Sstevel@tonic-gate for (c = 'a'; c <= 'z'; c++) {
773*7c478bd9Sstevel@tonic-gate snprintf(cray_tmpdir, TPATHSIZ, "%s/jtmp.%06d%c", JTMPDIR, jid, c);
774*7c478bd9Sstevel@tonic-gate if (mkdir(cray_tmpdir, JTMPMODE) != 0)
775*7c478bd9Sstevel@tonic-gate continue;
776*7c478bd9Sstevel@tonic-gate if (chown(cray_tmpdir, pw->pw_uid, pw->pw_gid) != 0) {
777*7c478bd9Sstevel@tonic-gate rmdir(cray_tmpdir);
778*7c478bd9Sstevel@tonic-gate continue;
779*7c478bd9Sstevel@tonic-gate }
780*7c478bd9Sstevel@tonic-gate break;
781*7c478bd9Sstevel@tonic-gate }
782*7c478bd9Sstevel@tonic-gate
783*7c478bd9Sstevel@tonic-gate if (c > 'z')
784*7c478bd9Sstevel@tonic-gate cray_tmpdir[0] = '\0';
785*7c478bd9Sstevel@tonic-gate }
786*7c478bd9Sstevel@tonic-gate
787*7c478bd9Sstevel@tonic-gate void
cray_set_tmpdir(struct utmp * ut)788*7c478bd9Sstevel@tonic-gate cray_set_tmpdir(struct utmp *ut)
789*7c478bd9Sstevel@tonic-gate {
790*7c478bd9Sstevel@tonic-gate int jid;
791*7c478bd9Sstevel@tonic-gate struct jtab jbuf;
792*7c478bd9Sstevel@tonic-gate
793*7c478bd9Sstevel@tonic-gate if ((jid = getjtab(&jbuf)) < 0)
794*7c478bd9Sstevel@tonic-gate return;
795*7c478bd9Sstevel@tonic-gate
796*7c478bd9Sstevel@tonic-gate /*
797*7c478bd9Sstevel@tonic-gate * Set jid and tmpdir in utmp record.
798*7c478bd9Sstevel@tonic-gate */
799*7c478bd9Sstevel@tonic-gate ut->ut_jid = jid;
800*7c478bd9Sstevel@tonic-gate strncpy(ut->ut_tpath, cray_tmpdir, TPATHSIZ);
801*7c478bd9Sstevel@tonic-gate }
802*7c478bd9Sstevel@tonic-gate #endif
803