Main Page | Namespace List | Class List | Directories | File List | Class Members | File Members

auth-skey.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001 Markus Friedl.  All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  * 1. Redistributions of source code must retain the above copyright
00008  *    notice, this list of conditions and the following disclaimer.
00009  * 2. Redistributions in binary form must reproduce the above copyright
00010  *    notice, this list of conditions and the following disclaimer in the
00011  *    documentation and/or other materials provided with the distribution.
00012  *
00013  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00014  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00015  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00016  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00017  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00018  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00019  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00020  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00021  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00022  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00023  */
00024 #include "includes.h"
00025 RCSID("$OpenBSD: auth-skey.c,v 1.20 2002/06/30 21:59:45 deraadt Exp $");
00026 
00027 #ifdef SKEY
00028 
00029 #include <skey.h>
00030 
00031 #include "xmalloc.h"
00032 #include "auth.h"
00033 #include "monitor_wrap.h"
00034 
00035 static void *
00036 skey_init_ctx(Authctxt *authctxt)
00037 {
00038         return authctxt;
00039 }
00040 
00041 int
00042 skey_query(void *ctx, char **name, char **infotxt,
00043     u_int* numprompts, char ***prompts, u_int **echo_on)
00044 {
00045         Authctxt *authctxt = ctx;
00046         char challenge[1024], *p;
00047         int len;
00048         struct skey skey;
00049 
00050         if (_compat_skeychallenge(&skey, authctxt->user, challenge,
00051             sizeof(challenge)) == -1)
00052                 return -1;
00053 
00054         *name  = xstrdup("");
00055         *infotxt  = xstrdup("");
00056         *numprompts = 1;
00057         *prompts = xmalloc(*numprompts * sizeof(char *));
00058         *echo_on = xmalloc(*numprompts * sizeof(u_int));
00059         (*echo_on)[0] = 0;
00060 
00061         len = strlen(challenge) + strlen(SKEY_PROMPT) + 1;
00062         p = xmalloc(len);
00063         strlcpy(p, challenge, len);
00064         strlcat(p, SKEY_PROMPT, len);
00065         (*prompts)[0] = p;
00066 
00067         return 0;
00068 }
00069 
00070 int
00071 skey_respond(void *ctx, u_int numresponses, char **responses)
00072 {
00073         Authctxt *authctxt = ctx;
00074 
00075         if (authctxt->valid &&
00076             numresponses == 1 &&
00077             skey_haskey(authctxt->pw->pw_name) == 0 &&
00078             skey_passcheck(authctxt->pw->pw_name, responses[0]) != -1)
00079             return 0;
00080         return -1;
00081 }
00082 
00083 static void
00084 skey_free_ctx(void *ctx)
00085 {
00086         /* we don't have a special context */
00087 }
00088 
00089 KbdintDevice skey_device = {
00090         "skey",
00091         skey_init_ctx,
00092         skey_query,
00093         skey_respond,
00094         skey_free_ctx
00095 };
00096 
00097 KbdintDevice mm_skey_device = {
00098         "skey",
00099         skey_init_ctx,
00100         mm_skey_query,
00101         mm_skey_respond,
00102         skey_free_ctx
00103 };
00104 #endif /* SKEY */

© sourcejam.com 2005-2008