1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * Copyright (c) 2001 Markus Friedl. All rights reserved. 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 5*0Sstevel@tonic-gate * modification, are permitted provided that the following conditions 6*0Sstevel@tonic-gate * are met: 7*0Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 8*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 9*0Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 10*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 11*0Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 12*0Sstevel@tonic-gate * 13*0Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14*0Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15*0Sstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16*0Sstevel@tonic-gate * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17*0Sstevel@tonic-gate * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18*0Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19*0Sstevel@tonic-gate * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20*0Sstevel@tonic-gate * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21*0Sstevel@tonic-gate * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22*0Sstevel@tonic-gate * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23*0Sstevel@tonic-gate */ 24*0Sstevel@tonic-gate #include "includes.h" 25*0Sstevel@tonic-gate RCSID("$OpenBSD: auth-bsdauth.c,v 1.5 2002/06/30 21:59:45 deraadt Exp $"); 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #ifdef BSD_AUTH 30*0Sstevel@tonic-gate #include "xmalloc.h" 31*0Sstevel@tonic-gate #include "auth.h" 32*0Sstevel@tonic-gate #include "log.h" 33*0Sstevel@tonic-gate #include "monitor_wrap.h" 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gate static void * 36*0Sstevel@tonic-gate bsdauth_init_ctx(Authctxt *authctxt) 37*0Sstevel@tonic-gate { 38*0Sstevel@tonic-gate return authctxt; 39*0Sstevel@tonic-gate } 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate int 42*0Sstevel@tonic-gate bsdauth_query(void *ctx, char **name, char **infotxt, 43*0Sstevel@tonic-gate u_int *numprompts, char ***prompts, u_int **echo_on) 44*0Sstevel@tonic-gate { 45*0Sstevel@tonic-gate Authctxt *authctxt = ctx; 46*0Sstevel@tonic-gate char *challenge = NULL; 47*0Sstevel@tonic-gate 48*0Sstevel@tonic-gate if (authctxt->as != NULL) { 49*0Sstevel@tonic-gate debug2("bsdauth_query: try reuse session"); 50*0Sstevel@tonic-gate challenge = auth_getitem(authctxt->as, AUTHV_CHALLENGE); 51*0Sstevel@tonic-gate if (challenge == NULL) { 52*0Sstevel@tonic-gate auth_close(authctxt->as); 53*0Sstevel@tonic-gate authctxt->as = NULL; 54*0Sstevel@tonic-gate } 55*0Sstevel@tonic-gate } 56*0Sstevel@tonic-gate 57*0Sstevel@tonic-gate if (challenge == NULL) { 58*0Sstevel@tonic-gate debug2("bsdauth_query: new bsd auth session"); 59*0Sstevel@tonic-gate debug3("bsdauth_query: style %s", 60*0Sstevel@tonic-gate authctxt->style ? authctxt->style : "<default>"); 61*0Sstevel@tonic-gate authctxt->as = auth_userchallenge(authctxt->user, 62*0Sstevel@tonic-gate authctxt->style, "auth-ssh", &challenge); 63*0Sstevel@tonic-gate if (authctxt->as == NULL) 64*0Sstevel@tonic-gate challenge = NULL; 65*0Sstevel@tonic-gate debug2("bsdauth_query: <%s>", challenge ? challenge : "empty"); 66*0Sstevel@tonic-gate } 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate if (challenge == NULL) 69*0Sstevel@tonic-gate return -1; 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate *name = xstrdup(""); 72*0Sstevel@tonic-gate *infotxt = xstrdup(""); 73*0Sstevel@tonic-gate *numprompts = 1; 74*0Sstevel@tonic-gate *prompts = xmalloc(*numprompts * sizeof(char *)); 75*0Sstevel@tonic-gate *echo_on = xmalloc(*numprompts * sizeof(u_int)); 76*0Sstevel@tonic-gate (*echo_on)[0] = 0; 77*0Sstevel@tonic-gate (*prompts)[0] = xstrdup(challenge); 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate return 0; 80*0Sstevel@tonic-gate } 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate int 83*0Sstevel@tonic-gate bsdauth_respond(void *ctx, u_int numresponses, char **responses) 84*0Sstevel@tonic-gate { 85*0Sstevel@tonic-gate Authctxt *authctxt = ctx; 86*0Sstevel@tonic-gate int authok; 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate if (authctxt->as == 0) 89*0Sstevel@tonic-gate error("bsdauth_respond: no bsd auth session"); 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate if (numresponses != 1) 92*0Sstevel@tonic-gate return -1; 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate authok = auth_userresponse(authctxt->as, responses[0], 0); 95*0Sstevel@tonic-gate authctxt->as = NULL; 96*0Sstevel@tonic-gate debug3("bsdauth_respond: <%s> = <%d>", responses[0], authok); 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate return (authok == 0) ? -1 : 0; 99*0Sstevel@tonic-gate } 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate static void 102*0Sstevel@tonic-gate bsdauth_free_ctx(void *ctx) 103*0Sstevel@tonic-gate { 104*0Sstevel@tonic-gate Authctxt *authctxt = ctx; 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate if (authctxt && authctxt->as) { 107*0Sstevel@tonic-gate auth_close(authctxt->as); 108*0Sstevel@tonic-gate authctxt->as = NULL; 109*0Sstevel@tonic-gate } 110*0Sstevel@tonic-gate } 111*0Sstevel@tonic-gate 112*0Sstevel@tonic-gate KbdintDevice bsdauth_device = { 113*0Sstevel@tonic-gate "bsdauth", 114*0Sstevel@tonic-gate bsdauth_init_ctx, 115*0Sstevel@tonic-gate bsdauth_query, 116*0Sstevel@tonic-gate bsdauth_respond, 117*0Sstevel@tonic-gate bsdauth_free_ctx 118*0Sstevel@tonic-gate }; 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate KbdintDevice mm_bsdauth_device = { 121*0Sstevel@tonic-gate "bsdauth", 122*0Sstevel@tonic-gate bsdauth_init_ctx, 123*0Sstevel@tonic-gate mm_bsdauth_query, 124*0Sstevel@tonic-gate mm_bsdauth_respond, 125*0Sstevel@tonic-gate bsdauth_free_ctx 126*0Sstevel@tonic-gate }; 127*0Sstevel@tonic-gate #endif 128