Annotation of src/usr.bin/ssh/auth-skey.c, Revision 1.25
1.25 ! dtucker 1: /* $OpenBSD: auth-skey.c,v 1.24 2006/08/03 03:34:41 deraadt Exp $ */
1.8 deraadt 2: /*
1.12 markus 3: * Copyright (c) 2001 Markus Friedl. All rights reserved.
1.8 deraadt 4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: * 1. Redistributions of source code must retain the above copyright
9: * notice, this list of conditions and the following disclaimer.
10: * 2. Redistributions in binary form must reproduce the above copyright
11: * notice, this list of conditions and the following disclaimer in the
12: * documentation and/or other materials provided with the distribution.
13: *
14: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24: */
1.12 markus 25:
26: #ifdef SKEY
1.24 deraadt 27:
28: #include <sys/types.h>
1.8 deraadt 29:
1.25 ! dtucker 30: #include <pwd.h>
! 31: #include <stdio.h>
! 32:
1.12 markus 33: #include <skey.h>
1.1 markus 34:
1.12 markus 35: #include "xmalloc.h"
1.25 ! dtucker 36: #include "key.h"
! 37: #include "hostfile.h"
1.10 markus 38: #include "auth.h"
1.17 provos 39: #include "monitor_wrap.h"
1.4 markus 40:
1.12 markus 41: static void *
42: skey_init_ctx(Authctxt *authctxt)
43: {
44: return authctxt;
45: }
46:
1.18 itojun 47: int
1.13 deraadt 48: skey_query(void *ctx, char **name, char **infotxt,
1.12 markus 49: u_int* numprompts, char ***prompts, u_int **echo_on)
1.10 markus 50: {
1.12 markus 51: Authctxt *authctxt = ctx;
52: char challenge[1024], *p;
53: int len;
54: struct skey skey;
55:
1.10 markus 56: if (skeychallenge(&skey, authctxt->user, challenge) == -1)
1.12 markus 57: return -1;
58:
1.19 deraadt 59: *name = xstrdup("");
60: *infotxt = xstrdup("");
1.12 markus 61: *numprompts = 1;
1.22 djm 62: *prompts = xcalloc(*numprompts, sizeof(char *));
63: *echo_on = xcalloc(*numprompts, sizeof(u_int));
1.12 markus 64:
1.22 djm 65: xasprintf(*prompts, "%s%s", challenge, SKEY_PROMPT);
1.12 markus 66:
67: return 0;
1.10 markus 68: }
1.12 markus 69:
1.18 itojun 70: int
1.12 markus 71: skey_respond(void *ctx, u_int numresponses, char **responses)
1.4 markus 72: {
1.12 markus 73: Authctxt *authctxt = ctx;
1.13 deraadt 74:
1.12 markus 75: if (authctxt->valid &&
1.13 deraadt 76: numresponses == 1 &&
1.10 markus 77: skey_haskey(authctxt->pw->pw_name) == 0 &&
1.12 markus 78: skey_passcheck(authctxt->pw->pw_name, responses[0]) != -1)
79: return 0;
80: return -1;
1.4 markus 81: }
1.12 markus 82:
83: static void
84: skey_free_ctx(void *ctx)
1.1 markus 85: {
1.12 markus 86: /* we don't have a special context */
1.1 markus 87: }
1.12 markus 88:
89: KbdintDevice skey_device = {
90: "skey",
91: skey_init_ctx,
92: skey_query,
93: skey_respond,
1.17 provos 94: skey_free_ctx
95: };
96:
97: KbdintDevice mm_skey_device = {
98: "skey",
99: skey_init_ctx,
100: mm_skey_query,
101: mm_skey_respond,
1.12 markus 102: skey_free_ctx
103: };
104: #endif /* SKEY */