Annotation of src/usr.bin/ssh/auth-skey.c, Revision 1.26
1.26 ! dtucker 1: /* $OpenBSD: auth-skey.c,v 1.25 2006/08/05 08:00:33 dtucker 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;
1.26 ! dtucker 52: char challenge[1024];
1.12 markus 53: struct skey skey;
54:
1.10 markus 55: if (skeychallenge(&skey, authctxt->user, challenge) == -1)
1.12 markus 56: return -1;
57:
1.19 deraadt 58: *name = xstrdup("");
59: *infotxt = xstrdup("");
1.12 markus 60: *numprompts = 1;
1.22 djm 61: *prompts = xcalloc(*numprompts, sizeof(char *));
62: *echo_on = xcalloc(*numprompts, sizeof(u_int));
1.12 markus 63:
1.22 djm 64: xasprintf(*prompts, "%s%s", challenge, SKEY_PROMPT);
1.12 markus 65:
66: return 0;
1.10 markus 67: }
1.12 markus 68:
1.18 itojun 69: int
1.12 markus 70: skey_respond(void *ctx, u_int numresponses, char **responses)
1.4 markus 71: {
1.12 markus 72: Authctxt *authctxt = ctx;
1.13 deraadt 73:
1.12 markus 74: if (authctxt->valid &&
1.13 deraadt 75: numresponses == 1 &&
1.10 markus 76: skey_haskey(authctxt->pw->pw_name) == 0 &&
1.12 markus 77: skey_passcheck(authctxt->pw->pw_name, responses[0]) != -1)
78: return 0;
79: return -1;
1.4 markus 80: }
1.12 markus 81:
82: static void
83: skey_free_ctx(void *ctx)
1.1 markus 84: {
1.12 markus 85: /* we don't have a special context */
1.1 markus 86: }
1.12 markus 87:
88: KbdintDevice skey_device = {
89: "skey",
90: skey_init_ctx,
91: skey_query,
92: skey_respond,
1.17 provos 93: skey_free_ctx
94: };
95:
96: KbdintDevice mm_skey_device = {
97: "skey",
98: skey_init_ctx,
99: mm_skey_query,
100: mm_skey_respond,
1.12 markus 101: skey_free_ctx
102: };
103: #endif /* SKEY */