blob: b66bef64cc4131dfaca16280454c3cc2e8542876 [file] [log] [blame]
Damien Miller8ed4de82011-12-19 10:52:50 +11001/* $OpenBSD: auth2.c,v 1.124 2011/12/07 05:44:38 djm Exp $ */
Damien Millereba71ba2000-04-29 23:57:08 +10002/*
3 * Copyright (c) 2000 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.
Damien Millereba71ba2000-04-29 23:57:08 +100013 *
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 */
Damien Millere4340be2000-09-16 13:29:08 +110025
Damien Millereba71ba2000-04-29 23:57:08 +100026#include "includes.h"
Damien Millereba71ba2000-04-29 23:57:08 +100027
Damien Miller9f2abc42006-07-10 20:53:08 +100028#include <sys/types.h>
Darren Tucker4230a5d2008-07-02 22:56:09 +100029#include <sys/stat.h>
30#include <sys/uio.h>
Damien Miller9f2abc42006-07-10 20:53:08 +100031
Darren Tucker4230a5d2008-07-02 22:56:09 +100032#include <fcntl.h>
Damien Miller9f2abc42006-07-10 20:53:08 +100033#include <pwd.h>
Damien Millerd7834352006-08-05 12:39:39 +100034#include <stdarg.h>
Damien Millere3476ed2006-07-24 14:13:33 +100035#include <string.h>
Darren Tucker4230a5d2008-07-02 22:56:09 +100036#include <unistd.h>
Damien Miller9f2abc42006-07-10 20:53:08 +100037
Damien Miller0b4d48b2008-07-05 09:44:53 +100038#include "atomicio.h"
Darren Tucker43e7a352009-06-21 19:50:08 +100039#include "xmalloc.h"
Damien Millerd7834352006-08-05 12:39:39 +100040#include "ssh2.h"
Damien Millereba71ba2000-04-29 23:57:08 +100041#include "packet.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000042#include "log.h"
Damien Millerd7834352006-08-05 12:39:39 +100043#include "buffer.h"
Damien Millereba71ba2000-04-29 23:57:08 +100044#include "servconf.h"
45#include "compat.h"
Damien Millerd7834352006-08-05 12:39:39 +100046#include "key.h"
47#include "hostfile.h"
Damien Millereba71ba2000-04-29 23:57:08 +100048#include "auth.h"
Damien Millereba71ba2000-04-29 23:57:08 +100049#include "dispatch.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000050#include "pathnames.h"
Darren Tucker77fc29e2004-09-11 23:07:03 +100051#include "buffer.h"
Damien Millereba71ba2000-04-29 23:57:08 +100052
Darren Tucker0efd1552003-08-26 11:49:55 +100053#ifdef GSSAPI
54#include "ssh-gss.h"
55#endif
Damien Millerd7834352006-08-05 12:39:39 +100056#include "monitor_wrap.h"
Darren Tucker0efd1552003-08-26 11:49:55 +100057
Damien Millereba71ba2000-04-29 23:57:08 +100058/* import */
59extern ServerOptions options;
Ben Lindstrom46c16222000-12-22 01:43:59 +000060extern u_char *session_id2;
Darren Tucker502d3842003-06-28 12:38:01 +100061extern u_int session_id2_len;
Darren Tucker77fc29e2004-09-11 23:07:03 +100062extern Buffer loginmsg;
Damien Millereba71ba2000-04-29 23:57:08 +100063
Ben Lindstrom511bb242002-06-06 20:52:37 +000064/* methods */
65
66extern Authmethod method_none;
67extern Authmethod method_pubkey;
68extern Authmethod method_passwd;
69extern Authmethod method_kbdint;
70extern Authmethod method_hostbased;
Darren Tucker0efd1552003-08-26 11:49:55 +100071#ifdef GSSAPI
72extern Authmethod method_gssapi;
73#endif
Damien Miller01ed2272008-11-05 16:20:46 +110074#ifdef JPAKE
75extern Authmethod method_jpake;
76#endif
Ben Lindstrom511bb242002-06-06 20:52:37 +000077
78Authmethod *authmethods[] = {
79 &method_none,
80 &method_pubkey,
Darren Tucker0efd1552003-08-26 11:49:55 +100081#ifdef GSSAPI
82 &method_gssapi,
83#endif
Damien Miller01ed2272008-11-05 16:20:46 +110084#ifdef JPAKE
85 &method_jpake,
86#endif
Ben Lindstrom511bb242002-06-06 20:52:37 +000087 &method_passwd,
88 &method_kbdint,
89 &method_hostbased,
90 NULL
Damien Miller874d77b2000-10-14 16:23:11 +110091};
92
Damien Millereba71ba2000-04-29 23:57:08 +100093/* protocol */
94
Damien Miller630d6f42002-01-22 23:17:30 +110095static void input_service_request(int, u_int32_t, void *);
96static void input_userauth_request(int, u_int32_t, void *);
Damien Millereba71ba2000-04-29 23:57:08 +100097
Damien Millereba71ba2000-04-29 23:57:08 +100098/* helper */
Ben Lindstrombba81212001-06-25 05:01:22 +000099static Authmethod *authmethod_lookup(const char *);
Ben Lindstrom79073822001-07-04 03:42:30 +0000100static char *authmethods_get(void);
Damien Millereba71ba2000-04-29 23:57:08 +1000101
Darren Tucker4230a5d2008-07-02 22:56:09 +1000102char *
103auth2_read_banner(void)
104{
105 struct stat st;
106 char *banner = NULL;
107 size_t len, n;
108 int fd;
109
110 if ((fd = open(options.banner, O_RDONLY)) == -1)
111 return (NULL);
112 if (fstat(fd, &st) == -1) {
113 close(fd);
114 return (NULL);
115 }
Damien Miller8ed4de82011-12-19 10:52:50 +1100116 if (st.st_size <= 0 || st.st_size > 1*1024*1024) {
Darren Tucker4230a5d2008-07-02 22:56:09 +1000117 close(fd);
118 return (NULL);
119 }
120
121 len = (size_t)st.st_size; /* truncate */
122 banner = xmalloc(len + 1);
123 n = atomicio(read, fd, banner, len);
124 close(fd);
125
126 if (n != len) {
127 xfree(banner);
128 return (NULL);
129 }
130 banner[n] = '\0';
131
132 return (banner);
133}
134
135void
136userauth_send_banner(const char *msg)
137{
138 if (datafellows & SSH_BUG_BANNER)
139 return;
140
141 packet_start(SSH2_MSG_USERAUTH_BANNER);
142 packet_put_cstring(msg);
143 packet_put_cstring(""); /* language, unused */
144 packet_send();
145 debug("%s: sent", __func__);
146}
147
148static void
149userauth_banner(void)
150{
151 char *banner = NULL;
152
153 if (options.banner == NULL ||
154 strcasecmp(options.banner, "none") == 0 ||
155 (datafellows & SSH_BUG_BANNER) != 0)
156 return;
157
158 if ((banner = PRIVSEP(auth2_read_banner())) == NULL)
159 goto done;
160 userauth_send_banner(banner);
161
162done:
163 if (banner)
164 xfree(banner);
165}
166
Damien Millereba71ba2000-04-29 23:57:08 +1000167/*
Damien Miller874d77b2000-10-14 16:23:11 +1100168 * loop until authctxt->success == TRUE
Damien Millereba71ba2000-04-29 23:57:08 +1000169 */
Darren Tucker3e33cec2003-10-02 16:12:36 +1000170void
171do_authentication2(Authctxt *authctxt)
Damien Millereba71ba2000-04-29 23:57:08 +1000172{
Damien Miller7d053392002-01-22 23:24:13 +1100173 dispatch_init(&dispatch_protocol_error);
Damien Millereba71ba2000-04-29 23:57:08 +1000174 dispatch_set(SSH2_MSG_SERVICE_REQUEST, &input_service_request);
Damien Miller874d77b2000-10-14 16:23:11 +1100175 dispatch_run(DISPATCH_BLOCK, &authctxt->success, authctxt);
Damien Millereba71ba2000-04-29 23:57:08 +1000176}
177
Damien Miller91d4b122006-03-26 14:05:20 +1100178/*ARGSUSED*/
Ben Lindstrombba81212001-06-25 05:01:22 +0000179static void
Damien Miller630d6f42002-01-22 23:17:30 +1100180input_service_request(int type, u_int32_t seq, void *ctxt)
Damien Millereba71ba2000-04-29 23:57:08 +1000181{
Damien Miller874d77b2000-10-14 16:23:11 +1100182 Authctxt *authctxt = ctxt;
Ben Lindstrom46c16222000-12-22 01:43:59 +0000183 u_int len;
Ben Lindstrom5a9d0ea2002-07-04 00:12:53 +0000184 int acceptit = 0;
Damien Millerda108ec2010-08-31 22:36:39 +1000185 char *service = packet_get_cstring(&len);
Damien Miller48b03fc2002-01-22 23:11:40 +1100186 packet_check_eom();
Damien Millereba71ba2000-04-29 23:57:08 +1000187
Damien Miller874d77b2000-10-14 16:23:11 +1100188 if (authctxt == NULL)
189 fatal("input_service_request: no authctxt");
190
Damien Millereba71ba2000-04-29 23:57:08 +1000191 if (strcmp(service, "ssh-userauth") == 0) {
Damien Miller874d77b2000-10-14 16:23:11 +1100192 if (!authctxt->success) {
Ben Lindstrom5a9d0ea2002-07-04 00:12:53 +0000193 acceptit = 1;
Damien Millereba71ba2000-04-29 23:57:08 +1000194 /* now we can handle user-auth requests */
195 dispatch_set(SSH2_MSG_USERAUTH_REQUEST, &input_userauth_request);
196 }
197 }
198 /* XXX all other service requests are denied */
199
Ben Lindstrom5a9d0ea2002-07-04 00:12:53 +0000200 if (acceptit) {
Damien Millereba71ba2000-04-29 23:57:08 +1000201 packet_start(SSH2_MSG_SERVICE_ACCEPT);
202 packet_put_cstring(service);
203 packet_send();
204 packet_write_wait();
205 } else {
206 debug("bad service request %s", service);
207 packet_disconnect("bad service request %s", service);
208 }
209 xfree(service);
210}
211
Damien Miller91d4b122006-03-26 14:05:20 +1100212/*ARGSUSED*/
Ben Lindstrombba81212001-06-25 05:01:22 +0000213static void
Damien Miller630d6f42002-01-22 23:17:30 +1100214input_userauth_request(int type, u_int32_t seq, void *ctxt)
Damien Millereba71ba2000-04-29 23:57:08 +1000215{
Damien Miller874d77b2000-10-14 16:23:11 +1100216 Authctxt *authctxt = ctxt;
217 Authmethod *m = NULL;
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000218 char *user, *service, *method, *style = NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000219 int authenticated = 0;
Damien Millereba71ba2000-04-29 23:57:08 +1000220
Damien Miller874d77b2000-10-14 16:23:11 +1100221 if (authctxt == NULL)
222 fatal("input_userauth_request: no authctxt");
Damien Millereba71ba2000-04-29 23:57:08 +1000223
Damien Millerda108ec2010-08-31 22:36:39 +1000224 user = packet_get_cstring(NULL);
225 service = packet_get_cstring(NULL);
226 method = packet_get_cstring(NULL);
Damien Miller874d77b2000-10-14 16:23:11 +1100227 debug("userauth-request for user %s service %s method %s", user, service, method);
Ben Lindstrom4dccfa52000-12-28 16:40:05 +0000228 debug("attempt %d failures %d", authctxt->attempt, authctxt->failures);
Damien Miller874d77b2000-10-14 16:23:11 +1100229
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000230 if ((style = strchr(user, ':')) != NULL)
231 *style++ = 0;
232
Kevin Stevesef4eea92001-02-05 12:42:17 +0000233 if (authctxt->attempt++ == 0) {
Damien Miller3a5b0232002-03-13 13:19:42 +1100234 /* setup auth context */
Kevin Steves205cc1e2002-03-22 20:43:05 +0000235 authctxt->pw = PRIVSEP(getpwnamallow(user));
Darren Tuckerdbf7a742004-03-08 23:04:06 +1100236 authctxt->user = xstrdup(user);
Kevin Steves205cc1e2002-03-22 20:43:05 +0000237 if (authctxt->pw && strcmp(service, "ssh-connection")==0) {
Damien Miller874d77b2000-10-14 16:23:11 +1100238 authctxt->valid = 1;
239 debug2("input_userauth_request: setting up authctxt for %s", user);
Damien Miller874d77b2000-10-14 16:23:11 +1100240 } else {
Darren Tucker5cb30ad2004-08-12 22:40:24 +1000241 logit("input_userauth_request: invalid user %s", user);
Damien Miller856f0be2003-09-03 07:32:45 +1000242 authctxt->pw = fakepw();
Darren Tucker2e0cf0d2005-02-08 21:52:47 +1100243#ifdef SSH_AUDIT_EVENTS
244 PRIVSEP(audit_event(SSH_INVALID_USER));
Darren Tucker269a1ea2005-02-03 00:20:53 +1100245#endif
Damien Miller874d77b2000-10-14 16:23:11 +1100246 }
Darren Tuckerd3eff2b2005-09-24 12:43:51 +1000247#ifdef USE_PAM
248 if (options.use_pam)
249 PRIVSEP(start_pam(authctxt));
250#endif
Damien Miller30d1f842004-07-21 20:48:53 +1000251 setproctitle("%s%s", authctxt->valid ? user : "unknown",
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000252 use_privsep ? " [net]" : "");
Damien Miller874d77b2000-10-14 16:23:11 +1100253 authctxt->service = xstrdup(service);
Ben Lindstrom9d0c0662001-06-09 01:40:00 +0000254 authctxt->style = style ? xstrdup(style) : NULL;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000255 if (use_privsep)
256 mm_inform_authserv(service, style);
Darren Tucker4230a5d2008-07-02 22:56:09 +1000257 userauth_banner();
Ben Lindstrom9d0c0662001-06-09 01:40:00 +0000258 } else if (strcmp(user, authctxt->user) != 0 ||
259 strcmp(service, authctxt->service) != 0) {
260 packet_disconnect("Change of username or service not allowed: "
261 "(%s,%s) -> (%s,%s)",
262 authctxt->user, authctxt->service, user, service);
Damien Millereba71ba2000-04-29 23:57:08 +1000263 }
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000264 /* reset state */
Damien Milleree116252001-12-21 12:42:34 +1100265 auth2_challenge_stop(authctxt);
Damien Miller01ed2272008-11-05 16:20:46 +1100266#ifdef JPAKE
267 auth2_jpake_stop(authctxt);
268#endif
Darren Tucker0efd1552003-08-26 11:49:55 +1000269
270#ifdef GSSAPI
Damien Miller01ed2272008-11-05 16:20:46 +1100271 /* XXX move to auth2_gssapi_stop() */
Darren Tucker0efd1552003-08-26 11:49:55 +1000272 dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL);
273 dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE, NULL);
274#endif
275
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000276 authctxt->postponed = 0;
Damien Miller3fcdfd52011-05-05 14:04:11 +1000277 authctxt->server_caused_failure = 0;
Damien Millerb70b61f2000-09-16 16:25:12 +1100278
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000279 /* try to authenticate user */
Damien Miller874d77b2000-10-14 16:23:11 +1100280 m = authmethod_lookup(method);
Darren Tucker4230a5d2008-07-02 22:56:09 +1000281 if (m != NULL && authctxt->failures < options.max_authtries) {
Damien Miller874d77b2000-10-14 16:23:11 +1100282 debug2("input_userauth_request: try method %s", method);
283 authenticated = m->userauth(authctxt);
Damien Miller874d77b2000-10-14 16:23:11 +1100284 }
Damien Miller5d57e502001-03-30 10:48:31 +1000285 userauth_finish(authctxt, authenticated, method);
286
287 xfree(service);
288 xfree(user);
289 xfree(method);
290}
291
292void
293userauth_finish(Authctxt *authctxt, int authenticated, char *method)
294{
Ben Lindstromcd4349f2001-06-09 00:23:17 +0000295 char *methods;
296
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000297 if (!authctxt->valid && authenticated)
298 fatal("INTERNAL ERROR: authenticated invalid user %s",
299 authctxt->user);
Damien Millerb70b61f2000-09-16 16:25:12 +1100300
Damien Miller874d77b2000-10-14 16:23:11 +1100301 /* Special handling for root */
Damien Miller556f9312003-02-24 11:59:26 +1100302 if (authenticated && authctxt->pw->pw_uid == 0 &&
Darren Tucker269a1ea2005-02-03 00:20:53 +1100303 !auth_root_allowed(method)) {
Damien Millereba71ba2000-04-29 23:57:08 +1000304 authenticated = 0;
Darren Tucker2e0cf0d2005-02-08 21:52:47 +1100305#ifdef SSH_AUDIT_EVENTS
306 PRIVSEP(audit_event(SSH_LOGIN_ROOT_DENIED));
Darren Tucker269a1ea2005-02-03 00:20:53 +1100307#endif
308 }
Damien Millereba71ba2000-04-29 23:57:08 +1000309
Damien Miller1f499fd2003-08-25 13:08:49 +1000310#ifdef USE_PAM
Darren Tucker77fc29e2004-09-11 23:07:03 +1000311 if (options.use_pam && authenticated) {
312 if (!PRIVSEP(do_pam_account())) {
Darren Tucker77fc29e2004-09-11 23:07:03 +1000313 /* if PAM returned a message, send it to the user */
314 if (buffer_len(&loginmsg) > 0) {
315 buffer_append(&loginmsg, "\0", 1);
316 userauth_send_banner(buffer_ptr(&loginmsg));
Darren Tuckerc1386672004-12-03 14:33:47 +1100317 packet_write_wait();
Darren Tucker77fc29e2004-09-11 23:07:03 +1000318 }
Darren Tuckerc1386672004-12-03 14:33:47 +1100319 fatal("Access denied for user %s by PAM account "
Damien Millerb6f72f52005-07-17 17:26:43 +1000320 "configuration", authctxt->user);
Darren Tucker77fc29e2004-09-11 23:07:03 +1000321 }
322 }
Damien Miller1f499fd2003-08-25 13:08:49 +1000323#endif
324
Tim Rice81ed5182002-09-25 17:38:46 -0700325#ifdef _UNICOS
326 if (authenticated && cray_access_denied(authctxt->user)) {
327 authenticated = 0;
328 fatal("Access denied for user %s.",authctxt->user);
329 }
330#endif /* _UNICOS */
331
Damien Miller874d77b2000-10-14 16:23:11 +1100332 /* Log before sending the reply */
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000333 auth_log(authctxt, authenticated, method, " ssh2");
334
Ben Lindstromcd4349f2001-06-09 00:23:17 +0000335 if (authctxt->postponed)
336 return;
337
338 /* XXX todo: check if multiple auth methods are needed */
339 if (authenticated == 1) {
340 /* turn off userauth */
Damien Miller7d053392002-01-22 23:24:13 +1100341 dispatch_set(SSH2_MSG_USERAUTH_REQUEST, &dispatch_protocol_ignore);
Ben Lindstromcd4349f2001-06-09 00:23:17 +0000342 packet_start(SSH2_MSG_USERAUTH_SUCCESS);
343 packet_send();
344 packet_write_wait();
345 /* now we can break out */
346 authctxt->success = 1;
347 } else {
Damien Miller0b4d48b2008-07-05 09:44:53 +1000348
349 /* Allow initial try of "none" auth without failure penalty */
Damien Miller3fcdfd52011-05-05 14:04:11 +1000350 if (!authctxt->server_caused_failure &&
351 (authctxt->attempt > 1 || strcmp(method, "none") != 0))
Damien Miller0b4d48b2008-07-05 09:44:53 +1000352 authctxt->failures++;
353 if (authctxt->failures >= options.max_authtries) {
Darren Tucker2e0cf0d2005-02-08 21:52:47 +1100354#ifdef SSH_AUDIT_EVENTS
355 PRIVSEP(audit_event(SSH_LOGIN_EXCEED_MAXTRIES));
Darren Tucker269a1ea2005-02-03 00:20:53 +1100356#endif
Ben Lindstromcd4349f2001-06-09 00:23:17 +0000357 packet_disconnect(AUTH_FAIL_MSG, authctxt->user);
Darren Tucker269a1ea2005-02-03 00:20:53 +1100358 }
Ben Lindstromcd4349f2001-06-09 00:23:17 +0000359 methods = authmethods_get();
360 packet_start(SSH2_MSG_USERAUTH_FAILURE);
361 packet_put_cstring(methods);
362 packet_put_char(0); /* XXX partial success, unused */
363 packet_send();
364 packet_write_wait();
365 xfree(methods);
366 }
Damien Miller874d77b2000-10-14 16:23:11 +1100367}
368
Ben Lindstrom79073822001-07-04 03:42:30 +0000369static char *
Damien Miller874d77b2000-10-14 16:23:11 +1100370authmethods_get(void)
371{
Damien Miller0e3b8722002-01-22 23:26:38 +1100372 Buffer b;
Damien Miller874d77b2000-10-14 16:23:11 +1100373 char *list;
Ben Lindstrom511bb242002-06-06 20:52:37 +0000374 int i;
Damien Miller874d77b2000-10-14 16:23:11 +1100375
Damien Miller0e3b8722002-01-22 23:26:38 +1100376 buffer_init(&b);
Ben Lindstrom511bb242002-06-06 20:52:37 +0000377 for (i = 0; authmethods[i] != NULL; i++) {
378 if (strcmp(authmethods[i]->name, "none") == 0)
Damien Miller874d77b2000-10-14 16:23:11 +1100379 continue;
Ben Lindstrom511bb242002-06-06 20:52:37 +0000380 if (authmethods[i]->enabled != NULL &&
381 *(authmethods[i]->enabled) != 0) {
Damien Miller0e3b8722002-01-22 23:26:38 +1100382 if (buffer_len(&b) > 0)
383 buffer_append(&b, ",", 1);
Ben Lindstrom511bb242002-06-06 20:52:37 +0000384 buffer_append(&b, authmethods[i]->name,
385 strlen(authmethods[i]->name));
Damien Millereba71ba2000-04-29 23:57:08 +1000386 }
387 }
Damien Miller0e3b8722002-01-22 23:26:38 +1100388 buffer_append(&b, "\0", 1);
389 list = xstrdup(buffer_ptr(&b));
390 buffer_free(&b);
Damien Miller874d77b2000-10-14 16:23:11 +1100391 return list;
392}
393
Ben Lindstrombba81212001-06-25 05:01:22 +0000394static Authmethod *
Damien Miller874d77b2000-10-14 16:23:11 +1100395authmethod_lookup(const char *name)
396{
Ben Lindstrom511bb242002-06-06 20:52:37 +0000397 int i;
398
Damien Miller874d77b2000-10-14 16:23:11 +1100399 if (name != NULL)
Ben Lindstrom511bb242002-06-06 20:52:37 +0000400 for (i = 0; authmethods[i] != NULL; i++)
401 if (authmethods[i]->enabled != NULL &&
402 *(authmethods[i]->enabled) != 0 &&
403 strcmp(name, authmethods[i]->name) == 0)
404 return authmethods[i];
405 debug2("Unrecognized authentication method name: %s",
406 name ? name : "NULL");
Damien Miller874d77b2000-10-14 16:23:11 +1100407 return NULL;
Damien Millereba71ba2000-04-29 23:57:08 +1000408}
Darren Tucker4230a5d2008-07-02 22:56:09 +1000409