xref: /titanic_44/usr/src/cmd/ssh/sshd/auth-skey.c (revision 9a8058b57457911fab0e3b4b6f0a97740e7a816d)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2001 Markus Friedl.  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 #include "includes.h"
25*7c478bd9Sstevel@tonic-gate RCSID("$OpenBSD: auth-skey.c,v 1.20 2002/06/30 21:59:45 deraadt Exp $");
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #ifdef SKEY
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #include <skey.h>
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #include "xmalloc.h"
34*7c478bd9Sstevel@tonic-gate #include "auth.h"
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate static void *
skey_init_ctx(Authctxt * authctxt)37*7c478bd9Sstevel@tonic-gate skey_init_ctx(Authctxt *authctxt)
38*7c478bd9Sstevel@tonic-gate {
39*7c478bd9Sstevel@tonic-gate 	return authctxt;
40*7c478bd9Sstevel@tonic-gate }
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate int
skey_query(void * ctx,char ** name,char ** infotxt,u_int * numprompts,char *** prompts,u_int ** echo_on)43*7c478bd9Sstevel@tonic-gate skey_query(void *ctx, char **name, char **infotxt,
44*7c478bd9Sstevel@tonic-gate     u_int* numprompts, char ***prompts, u_int **echo_on)
45*7c478bd9Sstevel@tonic-gate {
46*7c478bd9Sstevel@tonic-gate 	Authctxt *authctxt = ctx;
47*7c478bd9Sstevel@tonic-gate 	char challenge[1024], *p;
48*7c478bd9Sstevel@tonic-gate 	int len;
49*7c478bd9Sstevel@tonic-gate 	struct skey skey;
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate 	if (skeychallenge(&skey, authctxt->user, challenge) == -1)
52*7c478bd9Sstevel@tonic-gate 		return -1;
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate 	*name  = xstrdup("");
55*7c478bd9Sstevel@tonic-gate 	*infotxt  = xstrdup("");
56*7c478bd9Sstevel@tonic-gate 	*numprompts = 1;
57*7c478bd9Sstevel@tonic-gate 	*prompts = xmalloc(*numprompts * sizeof(char *));
58*7c478bd9Sstevel@tonic-gate 	*echo_on = xmalloc(*numprompts * sizeof(u_int));
59*7c478bd9Sstevel@tonic-gate 	(*echo_on)[0] = 0;
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate 	len = strlen(challenge) + strlen(SKEY_PROMPT) + 1;
62*7c478bd9Sstevel@tonic-gate 	p = xmalloc(len);
63*7c478bd9Sstevel@tonic-gate 	strlcpy(p, challenge, len);
64*7c478bd9Sstevel@tonic-gate 	strlcat(p, SKEY_PROMPT, len);
65*7c478bd9Sstevel@tonic-gate 	(*prompts)[0] = p;
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate 	return 0;
68*7c478bd9Sstevel@tonic-gate }
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate int
skey_respond(void * ctx,u_int numresponses,char ** responses)71*7c478bd9Sstevel@tonic-gate skey_respond(void *ctx, u_int numresponses, char **responses)
72*7c478bd9Sstevel@tonic-gate {
73*7c478bd9Sstevel@tonic-gate 	Authctxt *authctxt = ctx;
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate 	if (authctxt->valid &&
76*7c478bd9Sstevel@tonic-gate 	    numresponses == 1 &&
77*7c478bd9Sstevel@tonic-gate 	    skey_haskey(authctxt->pw->pw_name) == 0 &&
78*7c478bd9Sstevel@tonic-gate 	    skey_passcheck(authctxt->pw->pw_name, responses[0]) != -1)
79*7c478bd9Sstevel@tonic-gate 	    return 0;
80*7c478bd9Sstevel@tonic-gate 	return -1;
81*7c478bd9Sstevel@tonic-gate }
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate static void
skey_free_ctx(void * ctx)84*7c478bd9Sstevel@tonic-gate skey_free_ctx(void *ctx)
85*7c478bd9Sstevel@tonic-gate {
86*7c478bd9Sstevel@tonic-gate 	/* we don't have a special context */
87*7c478bd9Sstevel@tonic-gate }
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate KbdintDevice skey_device = {
90*7c478bd9Sstevel@tonic-gate 	"skey",
91*7c478bd9Sstevel@tonic-gate 	skey_init_ctx,
92*7c478bd9Sstevel@tonic-gate 	skey_query,
93*7c478bd9Sstevel@tonic-gate 	skey_respond,
94*7c478bd9Sstevel@tonic-gate 	skey_free_ctx
95*7c478bd9Sstevel@tonic-gate };
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate KbdintDevice mm_skey_device = {
98*7c478bd9Sstevel@tonic-gate 	"skey",
99*7c478bd9Sstevel@tonic-gate 	skey_init_ctx,
100*7c478bd9Sstevel@tonic-gate 	mm_skey_query,
101*7c478bd9Sstevel@tonic-gate 	mm_skey_respond,
102*7c478bd9Sstevel@tonic-gate 	skey_free_ctx
103*7c478bd9Sstevel@tonic-gate };
104*7c478bd9Sstevel@tonic-gate #endif /* SKEY */
105