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