[BACK]Return to auth.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Annotation of src/usr.bin/ssh/auth.c, Revision 1.102

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