Annotation of src/usr.bin/ssh/auth-bsdauth.c, Revision 1.11
1.11 ! djm 1: /* $OpenBSD: auth-bsdauth.c,v 1.10 2006/08/03 03:34:41 deraadt Exp $ */
1.1 markus 2: /*
3: * Copyright (c) 2001 Markus Friedl. All rights reserved.
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.10 deraadt 25:
26: #include <sys/types.h>
1.1 markus 27:
28: #include "xmalloc.h"
1.10 deraadt 29: #include "key.h"
30: #include "hostfile.h"
1.1 markus 31: #include "auth.h"
32: #include "log.h"
1.10 deraadt 33: #include "buffer.h"
34: #ifdef GSSAPI
35: #include "ssh-gss.h"
36: #endif
1.3 provos 37: #include "monitor_wrap.h"
1.1 markus 38:
39: static void *
40: bsdauth_init_ctx(Authctxt *authctxt)
41: {
42: return authctxt;
43: }
44:
1.3 provos 45: int
1.2 deraadt 46: bsdauth_query(void *ctx, char **name, char **infotxt,
1.1 markus 47: u_int *numprompts, char ***prompts, u_int **echo_on)
48: {
1.2 deraadt 49: Authctxt *authctxt = ctx;
50: char *challenge = NULL;
1.1 markus 51:
1.2 deraadt 52: if (authctxt->as != NULL) {
53: debug2("bsdauth_query: try reuse session");
54: challenge = auth_getitem(authctxt->as, AUTHV_CHALLENGE);
55: if (challenge == NULL) {
56: auth_close(authctxt->as);
57: authctxt->as = NULL;
58: }
59: }
60:
61: if (challenge == NULL) {
62: debug2("bsdauth_query: new bsd auth session");
63: debug3("bsdauth_query: style %s",
1.1 markus 64: authctxt->style ? authctxt->style : "<default>");
1.2 deraadt 65: authctxt->as = auth_userchallenge(authctxt->user,
1.4 deraadt 66: authctxt->style, "auth-ssh", &challenge);
1.2 deraadt 67: if (authctxt->as == NULL)
68: challenge = NULL;
69: debug2("bsdauth_query: <%s>", challenge ? challenge : "empty");
70: }
71:
72: if (challenge == NULL)
73: return -1;
74:
1.4 deraadt 75: *name = xstrdup("");
76: *infotxt = xstrdup("");
1.2 deraadt 77: *numprompts = 1;
1.8 djm 78: *prompts = xcalloc(*numprompts, sizeof(char *));
79: *echo_on = xcalloc(*numprompts, sizeof(u_int));
1.2 deraadt 80: (*prompts)[0] = xstrdup(challenge);
1.1 markus 81:
1.2 deraadt 82: return 0;
1.1 markus 83: }
84:
1.3 provos 85: int
1.1 markus 86: bsdauth_respond(void *ctx, u_int numresponses, char **responses)
87: {
1.2 deraadt 88: Authctxt *authctxt = ctx;
89: int authok;
1.6 dtucker 90:
91: if (!authctxt->valid)
92: return -1;
1.1 markus 93:
1.2 deraadt 94: if (authctxt->as == 0)
95: error("bsdauth_respond: no bsd auth session");
96:
97: if (numresponses != 1)
98: return -1;
99:
100: authok = auth_userresponse(authctxt->as, responses[0], 0);
101: authctxt->as = NULL;
102: debug3("bsdauth_respond: <%s> = <%d>", responses[0], authok);
103:
104: return (authok == 0) ? -1 : 0;
1.1 markus 105: }
106:
107: static void
108: bsdauth_free_ctx(void *ctx)
109: {
1.2 deraadt 110: Authctxt *authctxt = ctx;
1.1 markus 111:
1.2 deraadt 112: if (authctxt && authctxt->as) {
113: auth_close(authctxt->as);
114: authctxt->as = NULL;
115: }
1.1 markus 116: }
117:
118: KbdintDevice bsdauth_device = {
119: "bsdauth",
120: bsdauth_init_ctx,
121: bsdauth_query,
122: bsdauth_respond,
1.3 provos 123: bsdauth_free_ctx
124: };
125:
126: KbdintDevice mm_bsdauth_device = {
127: "bsdauth",
128: bsdauth_init_ctx,
129: mm_bsdauth_query,
130: mm_bsdauth_respond,
1.1 markus 131: bsdauth_free_ctx
132: };