Annotation of src/usr.bin/ssh/auth.c, Revision 1.110
1.110 ! djm 1: /* $OpenBSD: auth.c,v 1.109 2015/01/20 23:14:00 deraadt Exp $ */
1.1 markus 2: /*
1.19 deraadt 3: * Copyright (c) 2000 Markus Friedl. All rights reserved.
1.9 deraadt 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.
1.1 markus 24: */
25:
1.62 stevesk 26: #include <sys/types.h>
27: #include <sys/stat.h>
1.22 markus 28:
1.70 stevesk 29: #include <errno.h>
1.79 dtucker 30: #include <fcntl.h>
1.22 markus 31: #include <libgen.h>
1.77 djm 32: #include <login_cap.h>
1.61 stevesk 33: #include <paths.h>
1.68 stevesk 34: #include <pwd.h>
1.69 stevesk 35: #include <stdarg.h>
1.74 stevesk 36: #include <stdio.h>
1.72 stevesk 37: #include <string.h>
1.80 djm 38: #include <unistd.h>
1.109 deraadt 39: #include <limits.h>
1.1 markus 40:
41: #include "xmalloc.h"
1.13 markus 42: #include "match.h"
1.14 markus 43: #include "groupaccess.h"
44: #include "log.h"
1.75 deraadt 45: #include "buffer.h"
1.106 millert 46: #include "misc.h"
1.1 markus 47: #include "servconf.h"
1.75 deraadt 48: #include "key.h"
49: #include "hostfile.h"
1.2 markus 50: #include "auth.h"
1.13 markus 51: #include "auth-options.h"
1.14 markus 52: #include "canohost.h"
1.24 markus 53: #include "uidswap.h"
1.42 markus 54: #include "packet.h"
1.75 deraadt 55: #ifdef GSSAPI
56: #include "ssh-gss.h"
57: #endif
1.85 djm 58: #include "authfile.h"
1.67 dtucker 59: #include "monitor_wrap.h"
1.107 djm 60: #include "authfile.h"
61: #include "ssherr.h"
1.103 djm 62: #include "compat.h"
1.2 markus 63:
1.1 markus 64: /* import */
65: extern ServerOptions options;
1.67 dtucker 66: extern int use_privsep;
1.1 markus 67:
1.42 markus 68: /* Debugging messages */
69: Buffer auth_debug;
70: int auth_debug_init;
71:
1.1 markus 72: /*
1.12 markus 73: * Check if the user is allowed to log in via ssh. If user is listed
74: * in DenyUsers or one of user's groups is listed in DenyGroups, false
75: * will be returned. If AllowUsers isn't empty and user isn't listed
76: * there, or if AllowGroups isn't empty and one of user's groups isn't
77: * listed there, false will be returned.
1.1 markus 78: * If the user's shell is not executable, false will be returned.
1.4 markus 79: * Otherwise true is returned.
1.1 markus 80: */
1.5 markus 81: int
1.1 markus 82: allowed_user(struct passwd * pw)
83: {
84: struct stat st;
1.35 markus 85: const char *hostname = NULL, *ipaddr = NULL;
1.60 djm 86: u_int i;
1.1 markus 87:
88: /* Shouldn't be called if pw is NULL, but better safe than sorry... */
1.12 markus 89: if (!pw || !pw->pw_name)
1.1 markus 90: return 0;
91:
1.7 deraadt 92: /*
1.84 djm 93: * Deny if shell does not exist or is not executable unless we
94: * are chrooting.
1.7 deraadt 95: */
1.84 djm 96: if (options.chroot_directory == NULL ||
97: strcasecmp(options.chroot_directory, "none") == 0) {
98: char *shell = xstrdup((pw->pw_shell[0] == '\0') ?
99: _PATH_BSHELL : pw->pw_shell); /* empty = /bin/sh */
100:
101: if (stat(shell, &st) != 0) {
102: logit("User %.100s not allowed because shell %.100s "
103: "does not exist", pw->pw_name, shell);
1.102 djm 104: free(shell);
1.84 djm 105: return 0;
106: }
107: if (S_ISREG(st.st_mode) == 0 ||
108: (st.st_mode & (S_IXOTH|S_IXUSR|S_IXGRP)) == 0) {
109: logit("User %.100s not allowed because shell %.100s "
110: "is not executable", pw->pw_name, shell);
1.102 djm 111: free(shell);
1.84 djm 112: return 0;
113: }
1.102 djm 114: free(shell);
1.34 stevesk 115: }
1.1 markus 116:
1.58 dtucker 117: if (options.num_deny_users > 0 || options.num_allow_users > 0 ||
118: options.num_deny_groups > 0 || options.num_allow_groups > 0) {
1.48 markus 119: hostname = get_canonical_hostname(options.use_dns);
1.35 markus 120: ipaddr = get_remote_ipaddr();
121: }
122:
1.1 markus 123: /* Return false if user is listed in DenyUsers */
124: if (options.num_deny_users > 0) {
125: for (i = 0; i < options.num_deny_users; i++)
1.39 markus 126: if (match_user(pw->pw_name, hostname, ipaddr,
1.34 stevesk 127: options.deny_users[i])) {
1.57 dtucker 128: logit("User %.100s from %.100s not allowed "
129: "because listed in DenyUsers",
130: pw->pw_name, hostname);
1.1 markus 131: return 0;
1.34 stevesk 132: }
1.1 markus 133: }
134: /* Return false if AllowUsers isn't empty and user isn't listed there */
135: if (options.num_allow_users > 0) {
136: for (i = 0; i < options.num_allow_users; i++)
1.39 markus 137: if (match_user(pw->pw_name, hostname, ipaddr,
1.26 markus 138: options.allow_users[i]))
1.1 markus 139: break;
140: /* i < options.num_allow_users iff we break for loop */
1.34 stevesk 141: if (i >= options.num_allow_users) {
1.57 dtucker 142: logit("User %.100s from %.100s not allowed because "
143: "not listed in AllowUsers", pw->pw_name, hostname);
1.1 markus 144: return 0;
1.34 stevesk 145: }
1.1 markus 146: }
147: if (options.num_deny_groups > 0 || options.num_allow_groups > 0) {
1.12 markus 148: /* Get the user's group access list (primary and supplementary) */
1.34 stevesk 149: if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
1.57 dtucker 150: logit("User %.100s from %.100s not allowed because "
151: "not in any group", pw->pw_name, hostname);
1.1 markus 152: return 0;
1.34 stevesk 153: }
1.1 markus 154:
1.12 markus 155: /* Return false if one of user's groups is listed in DenyGroups */
156: if (options.num_deny_groups > 0)
157: if (ga_match(options.deny_groups,
158: options.num_deny_groups)) {
159: ga_free();
1.57 dtucker 160: logit("User %.100s from %.100s not allowed "
161: "because a group is listed in DenyGroups",
162: pw->pw_name, hostname);
1.1 markus 163: return 0;
1.12 markus 164: }
1.1 markus 165: /*
1.12 markus 166: * Return false if AllowGroups isn't empty and one of user's groups
1.1 markus 167: * isn't listed there
168: */
1.12 markus 169: if (options.num_allow_groups > 0)
170: if (!ga_match(options.allow_groups,
171: options.num_allow_groups)) {
172: ga_free();
1.57 dtucker 173: logit("User %.100s from %.100s not allowed "
174: "because none of user's groups are listed "
175: "in AllowGroups", pw->pw_name, hostname);
1.1 markus 176: return 0;
1.12 markus 177: }
178: ga_free();
1.1 markus 179: }
180: /* We found no reason not to let this user try to log on... */
181: return 1;
1.13 markus 182: }
183:
184: void
1.103 djm 185: auth_info(Authctxt *authctxt, const char *fmt, ...)
186: {
187: va_list ap;
188: int i;
189:
190: free(authctxt->info);
191: authctxt->info = NULL;
192:
193: va_start(ap, fmt);
194: i = vasprintf(&authctxt->info, fmt, ap);
195: va_end(ap);
196:
197: if (i < 0 || authctxt->info == NULL)
198: fatal("vasprintf failed");
199: }
200:
201: void
1.98 djm 202: auth_log(Authctxt *authctxt, int authenticated, int partial,
1.103 djm 203: const char *method, const char *submethod)
1.13 markus 204: {
205: void (*authlog) (const char *fmt,...) = verbose;
206: char *authmsg;
1.67 dtucker 207:
208: if (use_privsep && !mm_is_monitor() && !authctxt->postponed)
209: return;
1.13 markus 210:
211: /* Raise logging level */
212: if (authenticated == 1 ||
213: !authctxt->valid ||
1.54 dtucker 214: authctxt->failures >= options.max_authtries / 2 ||
1.13 markus 215: strcmp(method, "password") == 0)
1.47 itojun 216: authlog = logit;
1.13 markus 217:
218: if (authctxt->postponed)
219: authmsg = "Postponed";
1.98 djm 220: else if (partial)
221: authmsg = "Partial";
1.13 markus 222: else
223: authmsg = authenticated ? "Accepted" : "Failed";
224:
1.103 djm 225: authlog("%s %s%s%s for %s%.100s from %.200s port %d %s%s%s",
1.13 markus 226: authmsg,
227: method,
1.98 djm 228: submethod != NULL ? "/" : "", submethod == NULL ? "" : submethod,
1.56 markus 229: authctxt->valid ? "" : "invalid user ",
1.29 markus 230: authctxt->user,
1.13 markus 231: get_remote_ipaddr(),
232: get_remote_port(),
1.103 djm 233: compat20 ? "ssh2" : "ssh1",
234: authctxt->info != NULL ? ": " : "",
235: authctxt->info != NULL ? authctxt->info : "");
236: free(authctxt->info);
237: authctxt->info = NULL;
1.105 djm 238: }
239:
240: void
241: auth_maxtries_exceeded(Authctxt *authctxt)
242: {
1.110 ! djm 243: error("maximum authentication attempts exceeded for "
1.105 djm 244: "%s%.100s from %.200s port %d %s",
245: authctxt->valid ? "" : "invalid user ",
246: authctxt->user,
247: get_remote_ipaddr(),
248: get_remote_port(),
249: compat20 ? "ssh2" : "ssh1");
1.110 ! djm 250: packet_disconnect("Too many authentication failures");
1.105 djm 251: /* NOTREACHED */
1.13 markus 252: }
253:
254: /*
1.17 markus 255: * Check whether root logins are disallowed.
1.13 markus 256: */
257: int
1.98 djm 258: auth_root_allowed(const char *method)
1.13 markus 259: {
1.17 markus 260: switch (options.permit_root_login) {
261: case PERMIT_YES:
1.13 markus 262: return 1;
1.17 markus 263: case PERMIT_NO_PASSWD:
264: if (strcmp(method, "password") != 0)
265: return 1;
266: break;
267: case PERMIT_FORCED_ONLY:
268: if (forced_command) {
1.47 itojun 269: logit("Root login accepted for forced command.");
1.17 markus 270: return 1;
271: }
272: break;
1.13 markus 273: }
1.47 itojun 274: logit("ROOT LOGIN REFUSED FROM %.200s", get_remote_ipaddr());
1.22 markus 275: return 0;
276: }
277:
278:
279: /*
280: * Given a template and a passwd structure, build a filename
281: * by substituting % tokenised options. Currently, %% becomes '%',
282: * %h becomes the home directory and %u the username.
283: *
284: * This returns a buffer allocated by xmalloc.
285: */
1.93 djm 286: char *
1.59 djm 287: expand_authorized_keys(const char *filename, struct passwd *pw)
1.22 markus 288: {
1.109 deraadt 289: char *file, ret[PATH_MAX];
1.65 djm 290: int i;
1.22 markus 291:
1.59 djm 292: file = percent_expand(filename, "h", pw->pw_dir,
293: "u", pw->pw_name, (char *)NULL);
1.22 markus 294:
295: /*
296: * Ensure that filename starts anchored. If not, be backward
297: * compatible and prepend the '%h/'
298: */
1.59 djm 299: if (*file == '/')
300: return (file);
301:
1.65 djm 302: i = snprintf(ret, sizeof(ret), "%s/%s", pw->pw_dir, file);
303: if (i < 0 || (size_t)i >= sizeof(ret))
1.59 djm 304: fatal("expand_authorized_keys: path too long");
1.102 djm 305: free(file);
1.65 djm 306: return (xstrdup(ret));
1.22 markus 307: }
1.24 markus 308:
1.87 djm 309: char *
310: authorized_principals_file(struct passwd *pw)
311: {
1.95 djm 312: if (options.authorized_principals_file == NULL ||
313: strcasecmp(options.authorized_principals_file, "none") == 0)
1.87 djm 314: return NULL;
315: return expand_authorized_keys(options.authorized_principals_file, pw);
316: }
317:
1.24 markus 318: /* return ok if key exists in sysfile or userfile */
319: HostStatus
320: check_key_in_hostfiles(struct passwd *pw, Key *key, const char *host,
321: const char *sysfile, const char *userfile)
322: {
323: char *user_hostfile;
324: struct stat st;
1.30 stevesk 325: HostStatus host_status;
1.91 djm 326: struct hostkeys *hostkeys;
327: const struct hostkey_entry *found;
1.24 markus 328:
1.91 djm 329: hostkeys = init_hostkeys();
330: load_hostkeys(hostkeys, host, sysfile);
331: if (userfile != NULL) {
1.24 markus 332: user_hostfile = tilde_expand_filename(userfile, pw->pw_uid);
333: if (options.strict_modes &&
334: (stat(user_hostfile, &st) == 0) &&
335: ((st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
1.31 deraadt 336: (st.st_mode & 022) != 0)) {
1.47 itojun 337: logit("Authentication refused for %.100s: "
1.24 markus 338: "bad owner or modes for %.200s",
339: pw->pw_name, user_hostfile);
1.88 djm 340: auth_debug_add("Ignored %.200s: bad ownership or modes",
341: user_hostfile);
1.24 markus 342: } else {
343: temporarily_use_uid(pw);
1.91 djm 344: load_hostkeys(hostkeys, host, user_hostfile);
1.24 markus 345: restore_uid();
346: }
1.102 djm 347: free(user_hostfile);
1.24 markus 348: }
1.91 djm 349: host_status = check_key_in_hostkeys(hostkeys, key, &found);
350: if (host_status == HOST_REVOKED)
351: error("WARNING: revoked key for %s attempted authentication",
352: found->host);
353: else if (host_status == HOST_OK)
354: debug("%s: key for %s found at %s:%ld", __func__,
355: found->host, found->file, found->line);
356: else
357: debug("%s: key for host %s not found", __func__, host);
358:
359: free_hostkeys(hostkeys);
1.24 markus 360:
361: return host_status;
362: }
363:
1.22 markus 364: /*
1.97 djm 365: * Check a given path for security. This is defined as all components
1.44 stevesk 366: * of the path to the file must be owned by either the owner of
1.23 markus 367: * of the file or root and no directories must be group or world writable.
1.22 markus 368: *
369: * XXX Should any specific check be done for sym links ?
370: *
1.101 dtucker 371: * Takes a file name, its stat information (preferably from fstat() to
1.97 djm 372: * avoid races), the uid of the expected owner, their home directory and an
1.22 markus 373: * error buffer plus max size as arguments.
374: *
375: * Returns 0 on success and -1 on failure
376: */
1.97 djm 377: int
378: auth_secure_path(const char *name, struct stat *stp, const char *pw_dir,
379: uid_t uid, char *err, size_t errlen)
1.22 markus 380: {
1.109 deraadt 381: char buf[PATH_MAX], homedir[PATH_MAX];
1.22 markus 382: char *cp;
1.46 markus 383: int comparehome = 0;
1.22 markus 384: struct stat st;
385:
1.97 djm 386: if (realpath(name, buf) == NULL) {
387: snprintf(err, errlen, "realpath %s failed: %s", name,
1.22 markus 388: strerror(errno));
389: return -1;
390: }
1.97 djm 391: if (pw_dir != NULL && realpath(pw_dir, homedir) != NULL)
1.46 markus 392: comparehome = 1;
1.22 markus 393:
1.97 djm 394: if (!S_ISREG(stp->st_mode)) {
395: snprintf(err, errlen, "%s is not a regular file", buf);
396: return -1;
397: }
398: if ((stp->st_uid != 0 && stp->st_uid != uid) ||
399: (stp->st_mode & 022) != 0) {
1.22 markus 400: snprintf(err, errlen, "bad ownership or modes for file %s",
401: buf);
402: return -1;
403: }
404:
405: /* for each component of the canonical path, walking upwards */
406: for (;;) {
407: if ((cp = dirname(buf)) == NULL) {
408: snprintf(err, errlen, "dirname() failed");
409: return -1;
410: }
411: strlcpy(buf, cp, sizeof(buf));
1.25 provos 412:
1.22 markus 413: if (stat(buf, &st) < 0 ||
414: (st.st_uid != 0 && st.st_uid != uid) ||
415: (st.st_mode & 022) != 0) {
1.31 deraadt 416: snprintf(err, errlen,
1.22 markus 417: "bad ownership or modes for directory %s", buf);
418: return -1;
419: }
420:
1.82 dtucker 421: /* If are past the homedir then we can stop */
1.94 djm 422: if (comparehome && strcmp(homedir, buf) == 0)
1.27 markus 423: break;
1.94 djm 424:
1.22 markus 425: /*
426: * dirname should always complete with a "/" path,
427: * but we can be paranoid and check for "." too
428: */
429: if ((strcmp("/", buf) == 0) || (strcmp(".", buf) == 0))
430: break;
431: }
1.17 markus 432: return 0;
1.97 djm 433: }
434:
435: /*
436: * Version of secure_path() that accepts an open file descriptor to
437: * avoid races.
438: *
439: * Returns 0 on success and -1 on failure
440: */
441: static int
442: secure_filename(FILE *f, const char *file, struct passwd *pw,
443: char *err, size_t errlen)
444: {
445: struct stat st;
446:
447: /* check the open file to avoid races */
448: if (fstat(fileno(f), &st) < 0) {
449: snprintf(err, errlen, "cannot stat file %s: %s",
1.99 dtucker 450: file, strerror(errno));
1.97 djm 451: return -1;
452: }
453: return auth_secure_path(file, &st, pw->pw_dir, pw->pw_uid, err, errlen);
1.79 dtucker 454: }
455:
1.87 djm 456: static FILE *
457: auth_openfile(const char *file, struct passwd *pw, int strict_modes,
458: int log_missing, char *file_type)
1.79 dtucker 459: {
460: char line[1024];
461: struct stat st;
462: int fd;
463: FILE *f;
464:
1.81 dtucker 465: if ((fd = open(file, O_RDONLY|O_NONBLOCK)) == -1) {
1.87 djm 466: if (log_missing || errno != ENOENT)
467: debug("Could not open %s '%s': %s", file_type, file,
1.81 dtucker 468: strerror(errno));
1.79 dtucker 469: return NULL;
1.81 dtucker 470: }
1.79 dtucker 471:
472: if (fstat(fd, &st) < 0) {
473: close(fd);
474: return NULL;
475: }
476: if (!S_ISREG(st.st_mode)) {
1.87 djm 477: logit("User %s %s %s is not a regular file",
478: pw->pw_name, file_type, file);
1.79 dtucker 479: close(fd);
480: return NULL;
481: }
482: unset_nonblock(fd);
483: if ((f = fdopen(fd, "r")) == NULL) {
484: close(fd);
485: return NULL;
486: }
1.90 djm 487: if (strict_modes &&
1.79 dtucker 488: secure_filename(f, file, pw, line, sizeof(line)) != 0) {
489: fclose(f);
490: logit("Authentication refused: %s", line);
1.88 djm 491: auth_debug_add("Ignored %s: %s", file_type, line);
1.79 dtucker 492: return NULL;
493: }
494:
495: return f;
1.87 djm 496: }
497:
498:
499: FILE *
500: auth_openkeyfile(const char *file, struct passwd *pw, int strict_modes)
501: {
502: return auth_openfile(file, pw, strict_modes, 1, "authorized keys");
503: }
504:
505: FILE *
506: auth_openprincipals(const char *file, struct passwd *pw, int strict_modes)
507: {
508: return auth_openfile(file, pw, strict_modes, 0,
509: "authorized principals");
1.37 provos 510: }
511:
512: struct passwd *
513: getpwnamallow(const char *user)
514: {
1.38 provos 515: extern login_cap_t *lc;
516: auth_session_t *as;
1.37 provos 517: struct passwd *pw;
1.96 dtucker 518: struct connection_info *ci = get_connection_info(1, options.use_dns);
1.71 dtucker 519:
1.96 dtucker 520: ci->user = user;
521: parse_server_match_config(&options, ci);
1.37 provos 522:
523: pw = getpwnam(user);
1.45 stevesk 524: if (pw == NULL) {
1.55 markus 525: logit("Invalid user %.100s from %.100s",
1.45 stevesk 526: user, get_remote_ipaddr());
527: return (NULL);
528: }
529: if (!allowed_user(pw))
1.38 provos 530: return (NULL);
531: if ((lc = login_getclass(pw->pw_class)) == NULL) {
532: debug("unable to get login class: %s", user);
533: return (NULL);
534: }
535: if ((as = auth_open()) == NULL || auth_setpwd(as, pw) != 0 ||
1.43 millert 536: auth_approval(as, lc, pw->pw_name, "ssh") <= 0) {
1.38 provos 537: debug("Approval failure for %s", user);
1.37 provos 538: pw = NULL;
1.38 provos 539: }
540: if (as != NULL)
541: auth_close(as);
1.41 markus 542: if (pw != NULL)
543: return (pwcopy(pw));
544: return (NULL);
1.85 djm 545: }
546:
547: /* Returns 1 if key is revoked by revoked_keys_file, 0 otherwise */
548: int
549: auth_key_is_revoked(Key *key)
550: {
1.107 djm 551: char *fp = NULL;
552: int r;
1.85 djm 553:
554: if (options.revoked_keys_file == NULL)
555: return 0;
1.108 djm 556: if ((fp = sshkey_fingerprint(key, options.fingerprint_hash,
557: SSH_FP_DEFAULT)) == NULL) {
1.107 djm 558: r = SSH_ERR_ALLOC_FAIL;
559: error("%s: fingerprint key: %s", __func__, ssh_err(r));
560: goto out;
561: }
562:
563: r = sshkey_check_revoked(key, options.revoked_keys_file);
564: switch (r) {
1.100 djm 565: case 0:
1.107 djm 566: break; /* not revoked */
567: case SSH_ERR_KEY_REVOKED:
568: error("Authentication key %s %s revoked by file %s",
569: sshkey_type(key), fp, options.revoked_keys_file);
570: goto out;
1.100 djm 571: default:
1.107 djm 572: error("Error checking authentication key %s %s in "
573: "revoked keys file %s: %s", sshkey_type(key), fp,
574: options.revoked_keys_file, ssh_err(r));
575: goto out;
1.100 djm 576: }
1.107 djm 577:
578: /* Success */
579: r = 0;
580:
581: out:
582: free(fp);
583: return r == 0 ? 0 : 1;
1.42 markus 584: }
585:
586: void
587: auth_debug_add(const char *fmt,...)
588: {
589: char buf[1024];
590: va_list args;
591:
592: if (!auth_debug_init)
593: return;
594:
595: va_start(args, fmt);
596: vsnprintf(buf, sizeof(buf), fmt, args);
597: va_end(args);
598: buffer_put_cstring(&auth_debug, buf);
599: }
600:
601: void
602: auth_debug_send(void)
603: {
604: char *msg;
605:
606: if (!auth_debug_init)
607: return;
608: while (buffer_len(&auth_debug)) {
609: msg = buffer_get_string(&auth_debug, NULL);
610: packet_send_debug("%s", msg);
1.102 djm 611: free(msg);
1.42 markus 612: }
613: }
614:
615: void
616: auth_debug_reset(void)
617: {
618: if (auth_debug_init)
619: buffer_clear(&auth_debug);
620: else {
621: buffer_init(&auth_debug);
622: auth_debug_init = 1;
623: }
1.49 markus 624: }
625:
626: struct passwd *
627: fakepw(void)
628: {
629: static struct passwd fake;
630:
631: memset(&fake, 0, sizeof(fake));
632: fake.pw_name = "NOUSER";
633: fake.pw_passwd =
1.51 djm 634: "$2a$06$r3.juUaHZDlIbQaO2dS9FuYxL1W9M81R1Tc92PoSNmzvpEqLkLGrK";
1.49 markus 635: fake.pw_gecos = "NOUSER";
1.53 deraadt 636: fake.pw_uid = (uid_t)-1;
637: fake.pw_gid = (gid_t)-1;
1.49 markus 638: fake.pw_class = "";
639: fake.pw_dir = "/nonexist";
640: fake.pw_shell = "/nonexist";
641:
642: return (&fake);
1.1 markus 643: }