xref: /titanic_41/usr/src/cmd/ssh/sshd/auth-sia.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2002 Chris Adams.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
5*7c478bd9Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
6*7c478bd9Sstevel@tonic-gate  * are met:
7*7c478bd9Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
8*7c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
9*7c478bd9Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
10*7c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
11*7c478bd9Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
12*7c478bd9Sstevel@tonic-gate  *
13*7c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14*7c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15*7c478bd9Sstevel@tonic-gate  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16*7c478bd9Sstevel@tonic-gate  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17*7c478bd9Sstevel@tonic-gate  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18*7c478bd9Sstevel@tonic-gate  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19*7c478bd9Sstevel@tonic-gate  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20*7c478bd9Sstevel@tonic-gate  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21*7c478bd9Sstevel@tonic-gate  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22*7c478bd9Sstevel@tonic-gate  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*7c478bd9Sstevel@tonic-gate  */
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate #include "includes.h"
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifdef HAVE_OSF_SIA
28*7c478bd9Sstevel@tonic-gate #include "ssh.h"
29*7c478bd9Sstevel@tonic-gate #include "auth.h"
30*7c478bd9Sstevel@tonic-gate #include "auth-sia.h"
31*7c478bd9Sstevel@tonic-gate #include "log.h"
32*7c478bd9Sstevel@tonic-gate #include "servconf.h"
33*7c478bd9Sstevel@tonic-gate #include "canohost.h"
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate #include <sia.h>
36*7c478bd9Sstevel@tonic-gate #include <siad.h>
37*7c478bd9Sstevel@tonic-gate #include <pwd.h>
38*7c478bd9Sstevel@tonic-gate #include <signal.h>
39*7c478bd9Sstevel@tonic-gate #include <setjmp.h>
40*7c478bd9Sstevel@tonic-gate #include <sys/resource.h>
41*7c478bd9Sstevel@tonic-gate #include <unistd.h>
42*7c478bd9Sstevel@tonic-gate #include <string.h>
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate extern ServerOptions options;
45*7c478bd9Sstevel@tonic-gate extern int saved_argc;
46*7c478bd9Sstevel@tonic-gate extern char **saved_argv;
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate extern int errno;
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate int
auth_sia_password(Authctxt * authctxt,char * pass)51*7c478bd9Sstevel@tonic-gate auth_sia_password(Authctxt *authctxt, char *pass)
52*7c478bd9Sstevel@tonic-gate {
53*7c478bd9Sstevel@tonic-gate 	int ret;
54*7c478bd9Sstevel@tonic-gate 	SIAENTITY *ent = NULL;
55*7c478bd9Sstevel@tonic-gate 	const char *host;
56*7c478bd9Sstevel@tonic-gate 	char *user = authctxt->user;
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate 	host = get_canonical_hostname(options.verify_reverse_mapping);
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate 	if (!user || !pass || pass[0] == '\0')
61*7c478bd9Sstevel@tonic-gate 		return(0);
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate 	if (sia_ses_init(&ent, saved_argc, saved_argv, host, user, NULL, 0,
64*7c478bd9Sstevel@tonic-gate 	    NULL) != SIASUCCESS)
65*7c478bd9Sstevel@tonic-gate 		return(0);
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate 	if ((ret = sia_ses_authent(NULL, pass, ent)) != SIASUCCESS) {
68*7c478bd9Sstevel@tonic-gate 		error("Couldn't authenticate %s from %s", user, host);
69*7c478bd9Sstevel@tonic-gate 		if (ret & SIASTOP)
70*7c478bd9Sstevel@tonic-gate 			sia_ses_release(&ent);
71*7c478bd9Sstevel@tonic-gate 		return(0);
72*7c478bd9Sstevel@tonic-gate 	}
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate 	sia_ses_release(&ent);
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate 	return(1);
77*7c478bd9Sstevel@tonic-gate }
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate void
session_setup_sia(char * user,char * tty)80*7c478bd9Sstevel@tonic-gate session_setup_sia(char *user, char *tty)
81*7c478bd9Sstevel@tonic-gate {
82*7c478bd9Sstevel@tonic-gate 	struct passwd *pw;
83*7c478bd9Sstevel@tonic-gate 	SIAENTITY *ent = NULL;
84*7c478bd9Sstevel@tonic-gate 	const char *host;
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 	host = get_canonical_hostname (options.verify_reverse_mapping);
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate 	if (sia_ses_init(&ent, saved_argc, saved_argv, host, user, tty, 0,
89*7c478bd9Sstevel@tonic-gate 	    NULL) != SIASUCCESS) {
90*7c478bd9Sstevel@tonic-gate 		fatal("sia_ses_init failed");
91*7c478bd9Sstevel@tonic-gate 	}
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate 	if ((pw = getpwnam(user)) == NULL) {
94*7c478bd9Sstevel@tonic-gate 		sia_ses_release(&ent);
95*7c478bd9Sstevel@tonic-gate 		fatal("getpwnam: no user: %s", user);
96*7c478bd9Sstevel@tonic-gate 	}
97*7c478bd9Sstevel@tonic-gate 	if (sia_make_entity_pwd(pw, ent) != SIASUCCESS) {
98*7c478bd9Sstevel@tonic-gate 		sia_ses_release(&ent);
99*7c478bd9Sstevel@tonic-gate 		fatal("sia_make_entity_pwd failed");
100*7c478bd9Sstevel@tonic-gate 	}
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	ent->authtype = SIA_A_NONE;
103*7c478bd9Sstevel@tonic-gate 	if (sia_ses_estab(sia_collect_trm, ent) != SIASUCCESS) {
104*7c478bd9Sstevel@tonic-gate 		fatal("Couldn't establish session for %s from %s", user,
105*7c478bd9Sstevel@tonic-gate 		    host);
106*7c478bd9Sstevel@tonic-gate 	}
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 	if (setpriority(PRIO_PROCESS, 0, 0) == -1) {
109*7c478bd9Sstevel@tonic-gate 		sia_ses_release(&ent);
110*7c478bd9Sstevel@tonic-gate 		fatal("setpriority: %s", strerror (errno));
111*7c478bd9Sstevel@tonic-gate 	}
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate 	if (sia_ses_launch(sia_collect_trm, ent) != SIASUCCESS) {
114*7c478bd9Sstevel@tonic-gate 		fatal("Couldn't launch session for %s from %s", user, host);
115*7c478bd9Sstevel@tonic-gate 	}
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate 	sia_ses_release(&ent);
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate 	if (setreuid(geteuid(), geteuid()) < 0) {
120*7c478bd9Sstevel@tonic-gate 		fatal("setreuid: %s", strerror(errno));
121*7c478bd9Sstevel@tonic-gate 	}
122*7c478bd9Sstevel@tonic-gate }
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate #endif /* HAVE_OSF_SIA */
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
127