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