blob: 3e6a06db7d2fc50cd2c43b2f67ec599e997f1b07 [file] [log] [blame]
Ben Lindstromd1aed9c2001-06-10 00:41:18 +00001/*
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"
Ben Lindstromd1aed9c2001-06-10 00:41:18 +000025
26#ifdef SKEY
27
28#include <skey.h>
29
30#include "xmalloc.h"
31#include "auth.h"
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000032#include "monitor_wrap.h"
Ben Lindstromd1aed9c2001-06-10 00:41:18 +000033
34static void *
35skey_init_ctx(Authctxt *authctxt)
36{
37 return authctxt;
38}
39
Ben Lindstrom58d4daf2002-05-15 16:14:36 +000040int
Damien Miller9f0f5c62001-12-21 14:45:46 +110041skey_query(void *ctx, char **name, char **infotxt,
Ben Lindstromd1aed9c2001-06-10 00:41:18 +000042 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
Damien Miller94cf4c82005-07-17 17:04:47 +100049 if (_compat_skeychallenge(&skey, authctxt->user, challenge,
Darren Tucker06a8cfe2004-04-14 17:24:30 +100050 sizeof(challenge)) == -1)
Ben Lindstromd1aed9c2001-06-10 00:41:18 +000051 return -1;
52
Ben Lindstromcb72e4f2002-06-21 00:41:51 +000053 *name = xstrdup("");
54 *infotxt = xstrdup("");
Ben Lindstromd1aed9c2001-06-10 00:41:18 +000055 *numprompts = 1;
Damien Miller07d86be2006-03-26 14:19:21 +110056 *prompts = xcalloc(*numprompts, sizeof(char *));
57 *echo_on = xcalloc(*numprompts, sizeof(u_int));
Ben Lindstromd1aed9c2001-06-10 00:41:18 +000058
Damien Miller07d86be2006-03-26 14:19:21 +110059 xasprintf(*prompts, "%s%s", challenge, SKEY_PROMPT);
Ben Lindstromd1aed9c2001-06-10 00:41:18 +000060
61 return 0;
62}
63
Ben Lindstrom58d4daf2002-05-15 16:14:36 +000064int
Ben Lindstromd1aed9c2001-06-10 00:41:18 +000065skey_respond(void *ctx, u_int numresponses, char **responses)
66{
67 Authctxt *authctxt = ctx;
Damien Miller9f0f5c62001-12-21 14:45:46 +110068
Ben Lindstromd1aed9c2001-06-10 00:41:18 +000069 if (authctxt->valid &&
Damien Miller9f0f5c62001-12-21 14:45:46 +110070 numresponses == 1 &&
Ben Lindstromd1aed9c2001-06-10 00:41:18 +000071 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
77static void
78skey_free_ctx(void *ctx)
79{
80 /* we don't have a special context */
81}
82
83KbdintDevice skey_device = {
84 "skey",
85 skey_init_ctx,
86 skey_query,
87 skey_respond,
88 skey_free_ctx
89};
Ben Lindstrom7a2073c2002-03-22 02:30:41 +000090
91KbdintDevice mm_skey_device = {
92 "skey",
93 skey_init_ctx,
94 mm_skey_query,
95 mm_skey_respond,
96 skey_free_ctx
97};
Ben Lindstromd1aed9c2001-06-10 00:41:18 +000098#endif /* SKEY */