00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "includes.h"
00025 RCSID("$OpenBSD: auth-bsdauth.c,v 1.6 2005/01/19 13:11:47 dtucker Exp $");
00026
00027 #ifdef BSD_AUTH
00028 #include "xmalloc.h"
00029 #include "auth.h"
00030 #include "log.h"
00031 #include "monitor_wrap.h"
00032
00033 static void *
00034 bsdauth_init_ctx(Authctxt *authctxt)
00035 {
00036 return authctxt;
00037 }
00038
00039 int
00040 bsdauth_query(void *ctx, char **name, char **infotxt,
00041 u_int *numprompts, char ***prompts, u_int **echo_on)
00042 {
00043 Authctxt *authctxt = ctx;
00044 char *challenge = NULL;
00045
00046 if (authctxt->as != NULL) {
00047 debug2("bsdauth_query: try reuse session");
00048 challenge = auth_getitem(authctxt->as, AUTHV_CHALLENGE);
00049 if (challenge == NULL) {
00050 auth_close(authctxt->as);
00051 authctxt->as = NULL;
00052 }
00053 }
00054
00055 if (challenge == NULL) {
00056 debug2("bsdauth_query: new bsd auth session");
00057 debug3("bsdauth_query: style %s",
00058 authctxt->style ? authctxt->style : "<default>");
00059 authctxt->as = auth_userchallenge(authctxt->user,
00060 authctxt->style, "auth-ssh", &challenge);
00061 if (authctxt->as == NULL)
00062 challenge = NULL;
00063 debug2("bsdauth_query: <%s>", challenge ? challenge : "empty");
00064 }
00065
00066 if (challenge == NULL)
00067 return -1;
00068
00069 *name = xstrdup("");
00070 *infotxt = xstrdup("");
00071 *numprompts = 1;
00072 *prompts = xmalloc(*numprompts * sizeof(char *));
00073 *echo_on = xmalloc(*numprompts * sizeof(u_int));
00074 (*echo_on)[0] = 0;
00075 (*prompts)[0] = xstrdup(challenge);
00076
00077 return 0;
00078 }
00079
00080 int
00081 bsdauth_respond(void *ctx, u_int numresponses, char **responses)
00082 {
00083 Authctxt *authctxt = ctx;
00084 int authok;
00085
00086 if (!authctxt->valid)
00087 return -1;
00088
00089 if (authctxt->as == 0)
00090 error("bsdauth_respond: no bsd auth session");
00091
00092 if (numresponses != 1)
00093 return -1;
00094
00095 authok = auth_userresponse(authctxt->as, responses[0], 0);
00096 authctxt->as = NULL;
00097 debug3("bsdauth_respond: <%s> = <%d>", responses[0], authok);
00098
00099 return (authok == 0) ? -1 : 0;
00100 }
00101
00102 static void
00103 bsdauth_free_ctx(void *ctx)
00104 {
00105 Authctxt *authctxt = ctx;
00106
00107 if (authctxt && authctxt->as) {
00108 auth_close(authctxt->as);
00109 authctxt->as = NULL;
00110 }
00111 }
00112
00113 KbdintDevice bsdauth_device = {
00114 "bsdauth",
00115 bsdauth_init_ctx,
00116 bsdauth_query,
00117 bsdauth_respond,
00118 bsdauth_free_ctx
00119 };
00120
00121 KbdintDevice mm_bsdauth_device = {
00122 "bsdauth",
00123 bsdauth_init_ctx,
00124 mm_bsdauth_query,
00125 mm_bsdauth_respond,
00126 bsdauth_free_ctx
00127 };
00128 #endif