[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.130

1.130   ! djm         1: /* $OpenBSD: auth.c,v 1.129 2018/06/01 03:33:53 djm 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.114     djm        28: #include <sys/socket.h>
1.125     markus     29: #include <sys/wait.h>
1.22      markus     30:
1.70      stevesk    31: #include <errno.h>
1.79      dtucker    32: #include <fcntl.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.109     deraadt    40: #include <limits.h>
1.114     djm        41: #include <netdb.h>
1.1       markus     42:
                     43: #include "xmalloc.h"
1.13      markus     44: #include "match.h"
1.14      markus     45: #include "groupaccess.h"
                     46: #include "log.h"
1.75      deraadt    47: #include "buffer.h"
1.106     millert    48: #include "misc.h"
1.1       markus     49: #include "servconf.h"
1.75      deraadt    50: #include "key.h"
                     51: #include "hostfile.h"
1.2       markus     52: #include "auth.h"
1.13      markus     53: #include "auth-options.h"
1.14      markus     54: #include "canohost.h"
1.24      markus     55: #include "uidswap.h"
1.42      markus     56: #include "packet.h"
1.75      deraadt    57: #ifdef GSSAPI
                     58: #include "ssh-gss.h"
                     59: #endif
1.85      djm        60: #include "authfile.h"
1.67      dtucker    61: #include "monitor_wrap.h"
1.107     djm        62: #include "authfile.h"
                     63: #include "ssherr.h"
1.103     djm        64: #include "compat.h"
1.126     djm        65: #include "channels.h"
1.2       markus     66:
1.1       markus     67: /* import */
                     68: extern ServerOptions options;
1.67      dtucker    69: extern int use_privsep;
1.126     djm        70: extern struct sshauthopt *auth_opts;
1.1       markus     71:
1.42      markus     72: /* Debugging messages */
                     73: Buffer auth_debug;
                     74: int auth_debug_init;
                     75:
1.1       markus     76: /*
1.12      markus     77:  * Check if the user is allowed to log in via ssh. If user is listed
                     78:  * in DenyUsers or one of user's groups is listed in DenyGroups, false
                     79:  * will be returned. If AllowUsers isn't empty and user isn't listed
                     80:  * there, or if AllowGroups isn't empty and one of user's groups isn't
                     81:  * listed there, false will be returned.
1.1       markus     82:  * If the user's shell is not executable, false will be returned.
1.4       markus     83:  * Otherwise true is returned.
1.1       markus     84:  */
1.5       markus     85: int
1.1       markus     86: allowed_user(struct passwd * pw)
                     87: {
1.114     djm        88:        struct ssh *ssh = active_state; /* XXX */
1.1       markus     89:        struct stat st;
1.35      markus     90:        const char *hostname = NULL, *ipaddr = NULL;
1.117     djm        91:        int r;
1.60      djm        92:        u_int i;
1.1       markus     93:
                     94:        /* Shouldn't be called if pw is NULL, but better safe than sorry... */
1.12      markus     95:        if (!pw || !pw->pw_name)
1.1       markus     96:                return 0;
                     97:
1.7       deraadt    98:        /*
1.84      djm        99:         * Deny if shell does not exist or is not executable unless we
                    100:         * are chrooting.
1.7       deraadt   101:         */
1.84      djm       102:        if (options.chroot_directory == NULL ||
                    103:            strcasecmp(options.chroot_directory, "none") == 0) {
                    104:                char *shell = xstrdup((pw->pw_shell[0] == '\0') ?
                    105:                    _PATH_BSHELL : pw->pw_shell); /* empty = /bin/sh */
                    106:
                    107:                if (stat(shell, &st) != 0) {
                    108:                        logit("User %.100s not allowed because shell %.100s "
                    109:                            "does not exist", pw->pw_name, shell);
1.102     djm       110:                        free(shell);
1.84      djm       111:                        return 0;
                    112:                }
                    113:                if (S_ISREG(st.st_mode) == 0 ||
                    114:                    (st.st_mode & (S_IXOTH|S_IXUSR|S_IXGRP)) == 0) {
                    115:                        logit("User %.100s not allowed because shell %.100s "
                    116:                            "is not executable", pw->pw_name, shell);
1.102     djm       117:                        free(shell);
1.84      djm       118:                        return 0;
                    119:                }
1.102     djm       120:                free(shell);
1.34      stevesk   121:        }
1.1       markus    122:
1.58      dtucker   123:        if (options.num_deny_users > 0 || options.num_allow_users > 0 ||
                    124:            options.num_deny_groups > 0 || options.num_allow_groups > 0) {
1.114     djm       125:                hostname = auth_get_canonical_hostname(ssh, options.use_dns);
                    126:                ipaddr = ssh_remote_ipaddr(ssh);
1.35      markus    127:        }
                    128:
1.1       markus    129:        /* Return false if user is listed in DenyUsers */
                    130:        if (options.num_deny_users > 0) {
1.119     dtucker   131:                for (i = 0; i < options.num_deny_users; i++) {
1.117     djm       132:                        r = match_user(pw->pw_name, hostname, ipaddr,
                    133:                            options.deny_users[i]);
                    134:                        if (r < 0) {
                    135:                                fatal("Invalid DenyUsers pattern \"%.100s\"",
                    136:                                    options.deny_users[i]);
1.118     djm       137:                        } else if (r != 0) {
1.57      dtucker   138:                                logit("User %.100s from %.100s not allowed "
                    139:                                    "because listed in DenyUsers",
                    140:                                    pw->pw_name, hostname);
1.1       markus    141:                                return 0;
1.34      stevesk   142:                        }
1.119     dtucker   143:                }
1.1       markus    144:        }
                    145:        /* Return false if AllowUsers isn't empty and user isn't listed there */
                    146:        if (options.num_allow_users > 0) {
1.117     djm       147:                for (i = 0; i < options.num_allow_users; i++) {
                    148:                        r = match_user(pw->pw_name, hostname, ipaddr,
                    149:                            options.allow_users[i]);
                    150:                        if (r < 0) {
                    151:                                fatal("Invalid AllowUsers pattern \"%.100s\"",
                    152:                                    options.allow_users[i]);
                    153:                        } else if (r == 1)
1.1       markus    154:                                break;
1.117     djm       155:                }
1.1       markus    156:                /* i < options.num_allow_users iff we break for loop */
1.34      stevesk   157:                if (i >= options.num_allow_users) {
1.57      dtucker   158:                        logit("User %.100s from %.100s not allowed because "
                    159:                            "not listed in AllowUsers", pw->pw_name, hostname);
1.1       markus    160:                        return 0;
1.34      stevesk   161:                }
1.1       markus    162:        }
                    163:        if (options.num_deny_groups > 0 || options.num_allow_groups > 0) {
1.12      markus    164:                /* Get the user's group access list (primary and supplementary) */
1.34      stevesk   165:                if (ga_init(pw->pw_name, pw->pw_gid) == 0) {
1.57      dtucker   166:                        logit("User %.100s from %.100s not allowed because "
                    167:                            "not in any group", pw->pw_name, hostname);
1.1       markus    168:                        return 0;
1.34      stevesk   169:                }
1.1       markus    170:
1.12      markus    171:                /* Return false if one of user's groups is listed in DenyGroups */
                    172:                if (options.num_deny_groups > 0)
                    173:                        if (ga_match(options.deny_groups,
                    174:                            options.num_deny_groups)) {
                    175:                                ga_free();
1.57      dtucker   176:                                logit("User %.100s from %.100s not allowed "
                    177:                                    "because a group is listed in DenyGroups",
                    178:                                    pw->pw_name, hostname);
1.1       markus    179:                                return 0;
1.12      markus    180:                        }
1.1       markus    181:                /*
1.12      markus    182:                 * Return false if AllowGroups isn't empty and one of user's groups
1.1       markus    183:                 * isn't listed there
                    184:                 */
1.12      markus    185:                if (options.num_allow_groups > 0)
                    186:                        if (!ga_match(options.allow_groups,
                    187:                            options.num_allow_groups)) {
                    188:                                ga_free();
1.57      dtucker   189:                                logit("User %.100s from %.100s not allowed "
                    190:                                    "because none of user's groups are listed "
                    191:                                    "in AllowGroups", pw->pw_name, hostname);
1.1       markus    192:                                return 0;
1.12      markus    193:                        }
                    194:                ga_free();
1.1       markus    195:        }
                    196:        /* We found no reason not to let this user try to log on... */
                    197:        return 1;
1.13      markus    198: }
                    199:
1.122     djm       200: /*
                    201:  * Formats any key left in authctxt->auth_method_key for inclusion in
                    202:  * auth_log()'s message. Also includes authxtct->auth_method_info if present.
                    203:  */
                    204: static char *
                    205: format_method_key(Authctxt *authctxt)
1.103     djm       206: {
1.122     djm       207:        const struct sshkey *key = authctxt->auth_method_key;
                    208:        const char *methinfo = authctxt->auth_method_info;
                    209:        char *fp, *ret = NULL;
                    210:
                    211:        if (key == NULL)
                    212:                return NULL;
                    213:
                    214:        if (key_is_cert(key)) {
                    215:                fp = sshkey_fingerprint(key->cert->signature_key,
                    216:                    options.fingerprint_hash, SSH_FP_DEFAULT);
                    217:                xasprintf(&ret, "%s ID %s (serial %llu) CA %s %s%s%s",
                    218:                    sshkey_type(key), key->cert->key_id,
                    219:                    (unsigned long long)key->cert->serial,
                    220:                    sshkey_type(key->cert->signature_key),
                    221:                    fp == NULL ? "(null)" : fp,
                    222:                    methinfo == NULL ? "" : ", ",
                    223:                    methinfo == NULL ? "" : methinfo);
                    224:                free(fp);
                    225:        } else {
                    226:                fp = sshkey_fingerprint(key, options.fingerprint_hash,
                    227:                    SSH_FP_DEFAULT);
                    228:                xasprintf(&ret, "%s %s%s%s", sshkey_type(key),
                    229:                    fp == NULL ? "(null)" : fp,
                    230:                    methinfo == NULL ? "" : ", ",
                    231:                    methinfo == NULL ? "" : methinfo);
                    232:                free(fp);
                    233:        }
                    234:        return ret;
1.103     djm       235: }
                    236:
                    237: void
1.98      djm       238: auth_log(Authctxt *authctxt, int authenticated, int partial,
1.103     djm       239:     const char *method, const char *submethod)
1.13      markus    240: {
1.114     djm       241:        struct ssh *ssh = active_state; /* XXX */
1.13      markus    242:        void (*authlog) (const char *fmt,...) = verbose;
1.122     djm       243:        const char *authmsg;
                    244:        char *extra = NULL;
1.67      dtucker   245:
                    246:        if (use_privsep && !mm_is_monitor() && !authctxt->postponed)
                    247:                return;
1.13      markus    248:
                    249:        /* Raise logging level */
                    250:        if (authenticated == 1 ||
                    251:            !authctxt->valid ||
1.54      dtucker   252:            authctxt->failures >= options.max_authtries / 2 ||
1.13      markus    253:            strcmp(method, "password") == 0)
1.47      itojun    254:                authlog = logit;
1.13      markus    255:
                    256:        if (authctxt->postponed)
                    257:                authmsg = "Postponed";
1.98      djm       258:        else if (partial)
                    259:                authmsg = "Partial";
1.13      markus    260:        else
                    261:                authmsg = authenticated ? "Accepted" : "Failed";
                    262:
1.122     djm       263:        if ((extra = format_method_key(authctxt)) == NULL) {
                    264:                if (authctxt->auth_method_info != NULL)
                    265:                        extra = xstrdup(authctxt->auth_method_info);
                    266:        }
                    267:
1.116     markus    268:        authlog("%s %s%s%s for %s%.100s from %.200s port %d ssh2%s%s",
1.13      markus    269:            authmsg,
                    270:            method,
1.98      djm       271:            submethod != NULL ? "/" : "", submethod == NULL ? "" : submethod,
1.56      markus    272:            authctxt->valid ? "" : "invalid user ",
1.29      markus    273:            authctxt->user,
1.114     djm       274:            ssh_remote_ipaddr(ssh),
                    275:            ssh_remote_port(ssh),
1.122     djm       276:            extra != NULL ? ": " : "",
                    277:            extra != NULL ? extra : "");
                    278:
                    279:        free(extra);
1.105     djm       280: }
                    281:
                    282: void
                    283: auth_maxtries_exceeded(Authctxt *authctxt)
                    284: {
1.114     djm       285:        struct ssh *ssh = active_state; /* XXX */
                    286:
1.110     djm       287:        error("maximum authentication attempts exceeded for "
1.116     markus    288:            "%s%.100s from %.200s port %d ssh2",
1.105     djm       289:            authctxt->valid ? "" : "invalid user ",
                    290:            authctxt->user,
1.114     djm       291:            ssh_remote_ipaddr(ssh),
1.116     markus    292:            ssh_remote_port(ssh));
1.110     djm       293:        packet_disconnect("Too many authentication failures");
1.105     djm       294:        /* NOTREACHED */
1.13      markus    295: }
                    296:
                    297: /*
1.17      markus    298:  * Check whether root logins are disallowed.
1.13      markus    299:  */
                    300: int
1.126     djm       301: auth_root_allowed(struct ssh *ssh, const char *method)
1.13      markus    302: {
1.17      markus    303:        switch (options.permit_root_login) {
                    304:        case PERMIT_YES:
1.13      markus    305:                return 1;
1.17      markus    306:        case PERMIT_NO_PASSWD:
1.112     deraadt   307:                if (strcmp(method, "publickey") == 0 ||
                    308:                    strcmp(method, "hostbased") == 0 ||
1.113     djm       309:                    strcmp(method, "gssapi-with-mic") == 0)
1.17      markus    310:                        return 1;
                    311:                break;
                    312:        case PERMIT_FORCED_ONLY:
1.126     djm       313:                if (auth_opts->force_command != NULL) {
1.47      itojun    314:                        logit("Root login accepted for forced command.");
1.17      markus    315:                        return 1;
                    316:                }
                    317:                break;
1.13      markus    318:        }
1.114     djm       319:        logit("ROOT LOGIN REFUSED FROM %.200s port %d",
                    320:            ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
1.22      markus    321:        return 0;
                    322: }
                    323:
                    324:
                    325: /*
                    326:  * Given a template and a passwd structure, build a filename
                    327:  * by substituting % tokenised options. Currently, %% becomes '%',
                    328:  * %h becomes the home directory and %u the username.
                    329:  *
                    330:  * This returns a buffer allocated by xmalloc.
                    331:  */
1.93      djm       332: char *
1.59      djm       333: expand_authorized_keys(const char *filename, struct passwd *pw)
1.22      markus    334: {
1.129     djm       335:        char *file, uidstr[32], ret[PATH_MAX];
1.65      djm       336:        int i;
1.22      markus    337:
1.129     djm       338:        snprintf(uidstr, sizeof(uidstr), "%llu",
                    339:            (unsigned long long)pw->pw_uid);
1.59      djm       340:        file = percent_expand(filename, "h", pw->pw_dir,
1.129     djm       341:            "u", pw->pw_name, "U", uidstr, (char *)NULL);
1.22      markus    342:
                    343:        /*
                    344:         * Ensure that filename starts anchored. If not, be backward
                    345:         * compatible and prepend the '%h/'
                    346:         */
1.59      djm       347:        if (*file == '/')
                    348:                return (file);
                    349:
1.65      djm       350:        i = snprintf(ret, sizeof(ret), "%s/%s", pw->pw_dir, file);
                    351:        if (i < 0 || (size_t)i >= sizeof(ret))
1.59      djm       352:                fatal("expand_authorized_keys: path too long");
1.102     djm       353:        free(file);
1.65      djm       354:        return (xstrdup(ret));
1.22      markus    355: }
1.24      markus    356:
1.87      djm       357: char *
                    358: authorized_principals_file(struct passwd *pw)
                    359: {
1.111     djm       360:        if (options.authorized_principals_file == NULL)
1.87      djm       361:                return NULL;
                    362:        return expand_authorized_keys(options.authorized_principals_file, pw);
                    363: }
                    364:
1.24      markus    365: /* return ok if key exists in sysfile or userfile */
                    366: HostStatus
1.121     markus    367: check_key_in_hostfiles(struct passwd *pw, struct sshkey *key, const char *host,
1.24      markus    368:     const char *sysfile, const char *userfile)
                    369: {
                    370:        char *user_hostfile;
                    371:        struct stat st;
1.30      stevesk   372:        HostStatus host_status;
1.91      djm       373:        struct hostkeys *hostkeys;
                    374:        const struct hostkey_entry *found;
1.24      markus    375:
1.91      djm       376:        hostkeys = init_hostkeys();
                    377:        load_hostkeys(hostkeys, host, sysfile);
                    378:        if (userfile != NULL) {
1.24      markus    379:                user_hostfile = tilde_expand_filename(userfile, pw->pw_uid);
                    380:                if (options.strict_modes &&
                    381:                    (stat(user_hostfile, &st) == 0) &&
                    382:                    ((st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
1.31      deraadt   383:                    (st.st_mode & 022) != 0)) {
1.47      itojun    384:                        logit("Authentication refused for %.100s: "
1.24      markus    385:                            "bad owner or modes for %.200s",
                    386:                            pw->pw_name, user_hostfile);
1.88      djm       387:                        auth_debug_add("Ignored %.200s: bad ownership or modes",
                    388:                            user_hostfile);
1.24      markus    389:                } else {
                    390:                        temporarily_use_uid(pw);
1.91      djm       391:                        load_hostkeys(hostkeys, host, user_hostfile);
1.24      markus    392:                        restore_uid();
                    393:                }
1.102     djm       394:                free(user_hostfile);
1.24      markus    395:        }
1.91      djm       396:        host_status = check_key_in_hostkeys(hostkeys, key, &found);
                    397:        if (host_status == HOST_REVOKED)
                    398:                error("WARNING: revoked key for %s attempted authentication",
                    399:                    found->host);
                    400:        else if (host_status == HOST_OK)
                    401:                debug("%s: key for %s found at %s:%ld", __func__,
                    402:                    found->host, found->file, found->line);
                    403:        else
                    404:                debug("%s: key for host %s not found", __func__, host);
                    405:
                    406:        free_hostkeys(hostkeys);
1.24      markus    407:
                    408:        return host_status;
                    409: }
                    410:
1.87      djm       411: static FILE *
                    412: auth_openfile(const char *file, struct passwd *pw, int strict_modes,
                    413:     int log_missing, char *file_type)
1.79      dtucker   414: {
                    415:        char line[1024];
                    416:        struct stat st;
                    417:        int fd;
                    418:        FILE *f;
                    419:
1.81      dtucker   420:        if ((fd = open(file, O_RDONLY|O_NONBLOCK)) == -1) {
1.87      djm       421:                if (log_missing || errno != ENOENT)
                    422:                        debug("Could not open %s '%s': %s", file_type, file,
1.81      dtucker   423:                           strerror(errno));
1.79      dtucker   424:                return NULL;
1.81      dtucker   425:        }
1.79      dtucker   426:
                    427:        if (fstat(fd, &st) < 0) {
                    428:                close(fd);
                    429:                return NULL;
                    430:        }
                    431:        if (!S_ISREG(st.st_mode)) {
1.87      djm       432:                logit("User %s %s %s is not a regular file",
                    433:                    pw->pw_name, file_type, file);
1.79      dtucker   434:                close(fd);
                    435:                return NULL;
                    436:        }
                    437:        unset_nonblock(fd);
                    438:        if ((f = fdopen(fd, "r")) == NULL) {
                    439:                close(fd);
                    440:                return NULL;
                    441:        }
1.90      djm       442:        if (strict_modes &&
1.123     djm       443:            safe_path_fd(fileno(f), file, pw, line, sizeof(line)) != 0) {
1.79      dtucker   444:                fclose(f);
                    445:                logit("Authentication refused: %s", line);
1.88      djm       446:                auth_debug_add("Ignored %s: %s", file_type, line);
1.79      dtucker   447:                return NULL;
                    448:        }
                    449:
                    450:        return f;
1.87      djm       451: }
                    452:
                    453:
                    454: FILE *
                    455: auth_openkeyfile(const char *file, struct passwd *pw, int strict_modes)
                    456: {
                    457:        return auth_openfile(file, pw, strict_modes, 1, "authorized keys");
                    458: }
                    459:
                    460: FILE *
                    461: auth_openprincipals(const char *file, struct passwd *pw, int strict_modes)
                    462: {
                    463:        return auth_openfile(file, pw, strict_modes, 0,
                    464:            "authorized principals");
1.37      provos    465: }
                    466:
                    467: struct passwd *
                    468: getpwnamallow(const char *user)
                    469: {
1.114     djm       470:        struct ssh *ssh = active_state; /* XXX */
1.38      provos    471:        extern login_cap_t *lc;
                    472:        auth_session_t *as;
1.37      provos    473:        struct passwd *pw;
1.96      dtucker   474:        struct connection_info *ci = get_connection_info(1, options.use_dns);
1.71      dtucker   475:
1.96      dtucker   476:        ci->user = user;
                    477:        parse_server_match_config(&options, ci);
1.120     djm       478:        log_change_level(options.log_level);
1.124     djm       479:        process_permitopen(ssh, &options);
1.37      provos    480:
                    481:        pw = getpwnam(user);
1.45      stevesk   482:        if (pw == NULL) {
1.114     djm       483:                logit("Invalid user %.100s from %.100s port %d",
                    484:                    user, ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
1.45      stevesk   485:                return (NULL);
                    486:        }
                    487:        if (!allowed_user(pw))
1.38      provos    488:                return (NULL);
                    489:        if ((lc = login_getclass(pw->pw_class)) == NULL) {
                    490:                debug("unable to get login class: %s", user);
                    491:                return (NULL);
                    492:        }
                    493:        if ((as = auth_open()) == NULL || auth_setpwd(as, pw) != 0 ||
1.43      millert   494:            auth_approval(as, lc, pw->pw_name, "ssh") <= 0) {
1.38      provos    495:                debug("Approval failure for %s", user);
1.37      provos    496:                pw = NULL;
1.38      provos    497:        }
                    498:        if (as != NULL)
                    499:                auth_close(as);
1.41      markus    500:        if (pw != NULL)
                    501:                return (pwcopy(pw));
                    502:        return (NULL);
1.85      djm       503: }
                    504:
                    505: /* Returns 1 if key is revoked by revoked_keys_file, 0 otherwise */
                    506: int
1.121     markus    507: auth_key_is_revoked(struct sshkey *key)
1.85      djm       508: {
1.107     djm       509:        char *fp = NULL;
                    510:        int r;
1.85      djm       511:
                    512:        if (options.revoked_keys_file == NULL)
                    513:                return 0;
1.108     djm       514:        if ((fp = sshkey_fingerprint(key, options.fingerprint_hash,
                    515:            SSH_FP_DEFAULT)) == NULL) {
1.107     djm       516:                r = SSH_ERR_ALLOC_FAIL;
                    517:                error("%s: fingerprint key: %s", __func__, ssh_err(r));
                    518:                goto out;
                    519:        }
                    520:
                    521:        r = sshkey_check_revoked(key, options.revoked_keys_file);
                    522:        switch (r) {
1.100     djm       523:        case 0:
1.107     djm       524:                break; /* not revoked */
                    525:        case SSH_ERR_KEY_REVOKED:
                    526:                error("Authentication key %s %s revoked by file %s",
                    527:                    sshkey_type(key), fp, options.revoked_keys_file);
                    528:                goto out;
1.100     djm       529:        default:
1.107     djm       530:                error("Error checking authentication key %s %s in "
                    531:                    "revoked keys file %s: %s", sshkey_type(key), fp,
                    532:                    options.revoked_keys_file, ssh_err(r));
                    533:                goto out;
1.100     djm       534:        }
1.107     djm       535:
                    536:        /* Success */
                    537:        r = 0;
                    538:
                    539:  out:
                    540:        free(fp);
                    541:        return r == 0 ? 0 : 1;
1.42      markus    542: }
                    543:
                    544: void
                    545: auth_debug_add(const char *fmt,...)
                    546: {
                    547:        char buf[1024];
                    548:        va_list args;
                    549:
                    550:        if (!auth_debug_init)
                    551:                return;
                    552:
                    553:        va_start(args, fmt);
                    554:        vsnprintf(buf, sizeof(buf), fmt, args);
                    555:        va_end(args);
                    556:        buffer_put_cstring(&auth_debug, buf);
                    557: }
                    558:
                    559: void
                    560: auth_debug_send(void)
                    561: {
                    562:        char *msg;
                    563:
                    564:        if (!auth_debug_init)
                    565:                return;
                    566:        while (buffer_len(&auth_debug)) {
                    567:                msg = buffer_get_string(&auth_debug, NULL);
                    568:                packet_send_debug("%s", msg);
1.102     djm       569:                free(msg);
1.42      markus    570:        }
                    571: }
                    572:
                    573: void
                    574: auth_debug_reset(void)
                    575: {
                    576:        if (auth_debug_init)
                    577:                buffer_clear(&auth_debug);
                    578:        else {
                    579:                buffer_init(&auth_debug);
                    580:                auth_debug_init = 1;
                    581:        }
1.49      markus    582: }
                    583:
                    584: struct passwd *
                    585: fakepw(void)
                    586: {
                    587:        static struct passwd fake;
                    588:
                    589:        memset(&fake, 0, sizeof(fake));
                    590:        fake.pw_name = "NOUSER";
                    591:        fake.pw_passwd =
1.51      djm       592:            "$2a$06$r3.juUaHZDlIbQaO2dS9FuYxL1W9M81R1Tc92PoSNmzvpEqLkLGrK";
1.49      markus    593:        fake.pw_gecos = "NOUSER";
1.53      deraadt   594:        fake.pw_uid = (uid_t)-1;
                    595:        fake.pw_gid = (gid_t)-1;
1.49      markus    596:        fake.pw_class = "";
                    597:        fake.pw_dir = "/nonexist";
                    598:        fake.pw_shell = "/nonexist";
                    599:
                    600:        return (&fake);
1.114     djm       601: }
                    602:
                    603: /*
                    604:  * Returns the remote DNS hostname as a string. The returned string must not
                    605:  * be freed. NB. this will usually trigger a DNS query the first time it is
                    606:  * called.
                    607:  * This function does additional checks on the hostname to mitigate some
                    608:  * attacks on legacy rhosts-style authentication.
                    609:  * XXX is RhostsRSAAuthentication vulnerable to these?
                    610:  * XXX Can we remove these checks? (or if not, remove RhostsRSAAuthentication?)
                    611:  */
                    612:
                    613: static char *
                    614: remote_hostname(struct ssh *ssh)
                    615: {
                    616:        struct sockaddr_storage from;
                    617:        socklen_t fromlen;
                    618:        struct addrinfo hints, *ai, *aitop;
                    619:        char name[NI_MAXHOST], ntop2[NI_MAXHOST];
                    620:        const char *ntop = ssh_remote_ipaddr(ssh);
                    621:
                    622:        /* Get IP address of client. */
                    623:        fromlen = sizeof(from);
                    624:        memset(&from, 0, sizeof(from));
                    625:        if (getpeername(ssh_packet_get_connection_in(ssh),
                    626:            (struct sockaddr *)&from, &fromlen) < 0) {
                    627:                debug("getpeername failed: %.100s", strerror(errno));
                    628:                return strdup(ntop);
                    629:        }
                    630:
                    631:        debug3("Trying to reverse map address %.100s.", ntop);
                    632:        /* Map the IP address to a host name. */
                    633:        if (getnameinfo((struct sockaddr *)&from, fromlen, name, sizeof(name),
                    634:            NULL, 0, NI_NAMEREQD) != 0) {
                    635:                /* Host name not found.  Use ip address. */
                    636:                return strdup(ntop);
                    637:        }
                    638:
                    639:        /*
                    640:         * if reverse lookup result looks like a numeric hostname,
                    641:         * someone is trying to trick us by PTR record like following:
                    642:         *      1.1.1.10.in-addr.arpa.  IN PTR  2.3.4.5
                    643:         */
                    644:        memset(&hints, 0, sizeof(hints));
                    645:        hints.ai_socktype = SOCK_DGRAM; /*dummy*/
                    646:        hints.ai_flags = AI_NUMERICHOST;
                    647:        if (getaddrinfo(name, NULL, &hints, &ai) == 0) {
                    648:                logit("Nasty PTR record \"%s\" is set up for %s, ignoring",
                    649:                    name, ntop);
                    650:                freeaddrinfo(ai);
                    651:                return strdup(ntop);
                    652:        }
                    653:
                    654:        /* Names are stored in lowercase. */
                    655:        lowercase(name);
                    656:
                    657:        /*
                    658:         * Map it back to an IP address and check that the given
                    659:         * address actually is an address of this host.  This is
                    660:         * necessary because anyone with access to a name server can
                    661:         * define arbitrary names for an IP address. Mapping from
                    662:         * name to IP address can be trusted better (but can still be
                    663:         * fooled if the intruder has access to the name server of
                    664:         * the domain).
                    665:         */
                    666:        memset(&hints, 0, sizeof(hints));
                    667:        hints.ai_family = from.ss_family;
                    668:        hints.ai_socktype = SOCK_STREAM;
                    669:        if (getaddrinfo(name, NULL, &hints, &aitop) != 0) {
                    670:                logit("reverse mapping checking getaddrinfo for %.700s "
1.115     dtucker   671:                    "[%s] failed.", name, ntop);
1.114     djm       672:                return strdup(ntop);
                    673:        }
                    674:        /* Look for the address from the list of addresses. */
                    675:        for (ai = aitop; ai; ai = ai->ai_next) {
                    676:                if (getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop2,
                    677:                    sizeof(ntop2), NULL, 0, NI_NUMERICHOST) == 0 &&
                    678:                    (strcmp(ntop, ntop2) == 0))
                    679:                                break;
                    680:        }
                    681:        freeaddrinfo(aitop);
                    682:        /* If we reached the end of the list, the address was not there. */
                    683:        if (ai == NULL) {
                    684:                /* Address not found for the host name. */
                    685:                logit("Address %.100s maps to %.600s, but this does not "
1.115     dtucker   686:                    "map back to the address.", ntop, name);
1.114     djm       687:                return strdup(ntop);
                    688:        }
                    689:        return strdup(name);
                    690: }
                    691:
                    692: /*
                    693:  * Return the canonical name of the host in the other side of the current
                    694:  * connection.  The host name is cached, so it is efficient to call this
                    695:  * several times.
                    696:  */
                    697:
                    698: const char *
                    699: auth_get_canonical_hostname(struct ssh *ssh, int use_dns)
                    700: {
                    701:        static char *dnsname;
                    702:
                    703:        if (!use_dns)
                    704:                return ssh_remote_ipaddr(ssh);
                    705:        else if (dnsname != NULL)
                    706:                return dnsname;
                    707:        else {
                    708:                dnsname = remote_hostname(ssh);
                    709:                return dnsname;
                    710:        }
1.125     markus    711: }
                    712:
                    713: /*
                    714:  * Runs command in a subprocess wuth a minimal environment.
                    715:  * Returns pid on success, 0 on failure.
                    716:  * The child stdout and stderr maybe captured, left attached or sent to
                    717:  * /dev/null depending on the contents of flags.
                    718:  * "tag" is prepended to log messages.
                    719:  * NB. "command" is only used for logging; the actual command executed is
                    720:  * av[0].
                    721:  */
                    722: pid_t
                    723: subprocess(const char *tag, struct passwd *pw, const char *command,
                    724:     int ac, char **av, FILE **child, u_int flags)
                    725: {
                    726:        FILE *f = NULL;
                    727:        struct stat st;
                    728:        int fd, devnull, p[2], i;
                    729:        pid_t pid;
                    730:        char *cp, errmsg[512];
                    731:        u_int envsize;
                    732:        char **child_env;
                    733:
                    734:        if (child != NULL)
                    735:                *child = NULL;
                    736:
                    737:        debug3("%s: %s command \"%s\" running as %s (flags 0x%x)", __func__,
                    738:            tag, command, pw->pw_name, flags);
                    739:
                    740:        /* Check consistency */
                    741:        if ((flags & SSH_SUBPROCESS_STDOUT_DISCARD) != 0 &&
                    742:            (flags & SSH_SUBPROCESS_STDOUT_CAPTURE) != 0) {
                    743:                error("%s: inconsistent flags", __func__);
                    744:                return 0;
                    745:        }
                    746:        if (((flags & SSH_SUBPROCESS_STDOUT_CAPTURE) == 0) != (child == NULL)) {
                    747:                error("%s: inconsistent flags/output", __func__);
                    748:                return 0;
                    749:        }
                    750:
                    751:        /*
                    752:         * If executing an explicit binary, then verify the it exists
                    753:         * and appears safe-ish to execute
                    754:         */
                    755:        if (*av[0] != '/') {
                    756:                error("%s path is not absolute", tag);
                    757:                return 0;
                    758:        }
                    759:        temporarily_use_uid(pw);
                    760:        if (stat(av[0], &st) < 0) {
                    761:                error("Could not stat %s \"%s\": %s", tag,
                    762:                    av[0], strerror(errno));
                    763:                restore_uid();
                    764:                return 0;
                    765:        }
                    766:        if (safe_path(av[0], &st, NULL, 0, errmsg, sizeof(errmsg)) != 0) {
                    767:                error("Unsafe %s \"%s\": %s", tag, av[0], errmsg);
                    768:                restore_uid();
                    769:                return 0;
                    770:        }
                    771:        /* Prepare to keep the child's stdout if requested */
                    772:        if (pipe(p) != 0) {
                    773:                error("%s: pipe: %s", tag, strerror(errno));
                    774:                restore_uid();
                    775:                return 0;
                    776:        }
                    777:        restore_uid();
                    778:
                    779:        switch ((pid = fork())) {
                    780:        case -1: /* error */
                    781:                error("%s: fork: %s", tag, strerror(errno));
                    782:                close(p[0]);
                    783:                close(p[1]);
                    784:                return 0;
                    785:        case 0: /* child */
                    786:                /* Prepare a minimal environment for the child. */
                    787:                envsize = 5;
                    788:                child_env = xcalloc(sizeof(*child_env), envsize);
                    789:                child_set_env(&child_env, &envsize, "PATH", _PATH_STDPATH);
                    790:                child_set_env(&child_env, &envsize, "USER", pw->pw_name);
                    791:                child_set_env(&child_env, &envsize, "LOGNAME", pw->pw_name);
                    792:                child_set_env(&child_env, &envsize, "HOME", pw->pw_dir);
                    793:                if ((cp = getenv("LANG")) != NULL)
                    794:                        child_set_env(&child_env, &envsize, "LANG", cp);
                    795:
                    796:                for (i = 0; i < NSIG; i++)
                    797:                        signal(i, SIG_DFL);
                    798:
                    799:                if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1) {
                    800:                        error("%s: open %s: %s", tag, _PATH_DEVNULL,
                    801:                            strerror(errno));
                    802:                        _exit(1);
                    803:                }
                    804:                if (dup2(devnull, STDIN_FILENO) == -1) {
                    805:                        error("%s: dup2: %s", tag, strerror(errno));
                    806:                        _exit(1);
                    807:                }
                    808:
                    809:                /* Set up stdout as requested; leave stderr in place for now. */
                    810:                fd = -1;
                    811:                if ((flags & SSH_SUBPROCESS_STDOUT_CAPTURE) != 0)
                    812:                        fd = p[1];
                    813:                else if ((flags & SSH_SUBPROCESS_STDOUT_DISCARD) != 0)
                    814:                        fd = devnull;
                    815:                if (fd != -1 && dup2(fd, STDOUT_FILENO) == -1) {
                    816:                        error("%s: dup2: %s", tag, strerror(errno));
                    817:                        _exit(1);
                    818:                }
                    819:                closefrom(STDERR_FILENO + 1);
                    820:
                    821:                /* Don't use permanently_set_uid() here to avoid fatal() */
                    822:                if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) != 0) {
                    823:                        error("%s: setresgid %u: %s", tag, (u_int)pw->pw_gid,
                    824:                            strerror(errno));
                    825:                        _exit(1);
                    826:                }
                    827:                if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) != 0) {
                    828:                        error("%s: setresuid %u: %s", tag, (u_int)pw->pw_uid,
                    829:                            strerror(errno));
                    830:                        _exit(1);
                    831:                }
                    832:                /* stdin is pointed to /dev/null at this point */
                    833:                if ((flags & SSH_SUBPROCESS_STDOUT_DISCARD) != 0 &&
                    834:                    dup2(STDIN_FILENO, STDERR_FILENO) == -1) {
                    835:                        error("%s: dup2: %s", tag, strerror(errno));
                    836:                        _exit(1);
                    837:                }
                    838:
                    839:                execve(av[0], av, child_env);
                    840:                error("%s exec \"%s\": %s", tag, command, strerror(errno));
                    841:                _exit(127);
                    842:        default: /* parent */
                    843:                break;
                    844:        }
                    845:
                    846:        close(p[1]);
                    847:        if ((flags & SSH_SUBPROCESS_STDOUT_CAPTURE) == 0)
                    848:                close(p[0]);
                    849:        else if ((f = fdopen(p[0], "r")) == NULL) {
                    850:                error("%s: fdopen: %s", tag, strerror(errno));
                    851:                close(p[0]);
                    852:                /* Don't leave zombie child */
                    853:                kill(pid, SIGTERM);
                    854:                while (waitpid(pid, NULL, 0) == -1 && errno == EINTR)
                    855:                        ;
                    856:                return 0;
                    857:        }
                    858:        /* Success */
                    859:        debug3("%s: %s pid %ld", __func__, tag, (long)pid);
                    860:        if (child != NULL)
                    861:                *child = f;
                    862:        return pid;
1.126     djm       863: }
                    864:
                    865: /* These functions link key/cert options to the auth framework */
                    866:
                    867: /* Log sshauthopt options locally and (optionally) for remote transmission */
                    868: void
                    869: auth_log_authopts(const char *loc, const struct sshauthopt *opts, int do_remote)
                    870: {
                    871:        int do_env = options.permit_user_env && opts->nenv > 0;
                    872:        int do_permitopen = opts->npermitopen > 0 &&
                    873:            (options.allow_tcp_forwarding & FORWARD_LOCAL) != 0;
1.130   ! djm       874:        int do_permitlisten = opts->npermitlisten > 0 &&
        !           875:            (options.allow_tcp_forwarding & FORWARD_REMOTE) != 0;
1.126     djm       876:        size_t i;
1.127     djm       877:        char msg[1024], buf[64];
1.126     djm       878:
1.127     djm       879:        snprintf(buf, sizeof(buf), "%d", opts->force_tun_device);
1.126     djm       880:        /* Try to keep this alphabetically sorted */
1.130   ! djm       881:        snprintf(msg, sizeof(msg), "key options:%s%s%s%s%s%s%s%s%s%s%s%s%s",
1.126     djm       882:            opts->permit_agent_forwarding_flag ? " agent-forwarding" : "",
                    883:            opts->force_command == NULL ? "" : " command",
                    884:            do_env ?  " environment" : "",
1.127     djm       885:            opts->valid_before == 0 ? "" : "expires",
1.126     djm       886:            do_permitopen ?  " permitopen" : "",
1.130   ! djm       887:            do_permitlisten ?  " permitlisten" : "",
1.126     djm       888:            opts->permit_port_forwarding_flag ? " port-forwarding" : "",
                    889:            opts->cert_principals == NULL ? "" : " principals",
                    890:            opts->permit_pty_flag ? " pty" : "",
                    891:            opts->force_tun_device == -1 ? "" : " tun=",
1.127     djm       892:            opts->force_tun_device == -1 ? "" : buf,
1.126     djm       893:            opts->permit_user_rc ? " user-rc" : "",
                    894:            opts->permit_x11_forwarding_flag ? " x11-forwarding" : "");
                    895:
                    896:        debug("%s: %s", loc, msg);
                    897:        if (do_remote)
                    898:                auth_debug_add("%s: %s", loc, msg);
                    899:
                    900:        if (options.permit_user_env) {
                    901:                for (i = 0; i < opts->nenv; i++) {
                    902:                        debug("%s: environment: %s", loc, opts->env[i]);
                    903:                        if (do_remote) {
                    904:                                auth_debug_add("%s: environment: %s",
                    905:                                    loc, opts->env[i]);
                    906:                        }
                    907:                }
                    908:        }
                    909:
                    910:        /* Go into a little more details for the local logs. */
1.127     djm       911:        if (opts->valid_before != 0) {
                    912:                format_absolute_time(opts->valid_before, buf, sizeof(buf));
                    913:                debug("%s: expires at %s", loc, buf);
                    914:        }
1.126     djm       915:        if (opts->cert_principals != NULL) {
                    916:                debug("%s: authorized principals: \"%s\"",
                    917:                    loc, opts->cert_principals);
                    918:        }
                    919:        if (opts->force_command != NULL)
                    920:                debug("%s: forced command: \"%s\"", loc, opts->force_command);
1.130   ! djm       921:        if (do_permitopen) {
1.126     djm       922:                for (i = 0; i < opts->npermitopen; i++) {
                    923:                        debug("%s: permitted open: %s",
                    924:                            loc, opts->permitopen[i]);
1.130   ! djm       925:                }
        !           926:        }
        !           927:        if (do_permitlisten) {
        !           928:                for (i = 0; i < opts->npermitlisten; i++) {
        !           929:                        debug("%s: permitted listen: %s",
        !           930:                            loc, opts->permitlisten[i]);
1.126     djm       931:                }
                    932:        }
                    933: }
                    934:
                    935: /* Activate a new set of key/cert options; merging with what is there. */
                    936: int
                    937: auth_activate_options(struct ssh *ssh, struct sshauthopt *opts)
                    938: {
                    939:        struct sshauthopt *old = auth_opts;
                    940:        const char *emsg = NULL;
                    941:
                    942:        debug("%s: setting new authentication options", __func__);
                    943:        if ((auth_opts = sshauthopt_merge(old, opts, &emsg)) == NULL) {
                    944:                error("Inconsistent authentication options: %s", emsg);
                    945:                return -1;
                    946:        }
                    947:        return 0;
                    948: }
                    949:
                    950: /* Disable forwarding, etc for the session */
                    951: void
                    952: auth_restrict_session(struct ssh *ssh)
                    953: {
                    954:        struct sshauthopt *restricted;
                    955:
                    956:        debug("%s: restricting session", __func__);
                    957:
                    958:        /* A blank sshauthopt defaults to permitting nothing */
                    959:        restricted = sshauthopt_new();
1.128     djm       960:        restricted->permit_pty_flag = 1;
1.126     djm       961:        restricted->restricted = 1;
                    962:
                    963:        if (auth_activate_options(ssh, restricted) != 0)
                    964:                fatal("%s: failed to restrict session", __func__);
                    965:        sshauthopt_free(restricted);
                    966: }
                    967:
                    968: int
                    969: auth_authorise_keyopts(struct ssh *ssh, struct passwd *pw,
                    970:     struct sshauthopt *opts, int allow_cert_authority, const char *loc)
                    971: {
                    972:        const char *remote_ip = ssh_remote_ipaddr(ssh);
                    973:        const char *remote_host = auth_get_canonical_hostname(ssh,
                    974:            options.use_dns);
1.127     djm       975:        time_t now = time(NULL);
                    976:        char buf[64];
1.126     djm       977:
1.127     djm       978:        /*
                    979:         * Check keys/principals file expiry time.
                    980:         * NB. validity interval in certificate is handled elsewhere.
                    981:         */
                    982:        if (opts->valid_before && now > 0 &&
                    983:            opts->valid_before < (uint64_t)now) {
                    984:                format_absolute_time(opts->valid_before, buf, sizeof(buf));
                    985:                debug("%s: entry expired at %s", loc, buf);
                    986:                auth_debug_add("%s: entry expired at %s", loc, buf);
                    987:                return -1;
                    988:        }
1.126     djm       989:        /* Consistency checks */
                    990:        if (opts->cert_principals != NULL && !opts->cert_authority) {
                    991:                debug("%s: principals on non-CA key", loc);
                    992:                auth_debug_add("%s: principals on non-CA key", loc);
                    993:                /* deny access */
                    994:                return -1;
                    995:        }
                    996:        /* cert-authority flag isn't valid in authorized_principals files */
                    997:        if (!allow_cert_authority && opts->cert_authority) {
                    998:                debug("%s: cert-authority flag invalid here", loc);
                    999:                auth_debug_add("%s: cert-authority flag invalid here", loc);
                   1000:                /* deny access */
                   1001:                return -1;
                   1002:        }
                   1003:
                   1004:        /* Perform from= checks */
                   1005:        if (opts->required_from_host_keys != NULL) {
                   1006:                switch (match_host_and_ip(remote_host, remote_ip,
                   1007:                    opts->required_from_host_keys )) {
                   1008:                case 1:
                   1009:                        /* Host name matches. */
                   1010:                        break;
                   1011:                case -1:
                   1012:                default:
                   1013:                        debug("%s: invalid from criteria", loc);
                   1014:                        auth_debug_add("%s: invalid from criteria", loc);
                   1015:                        /* FALLTHROUGH */
                   1016:                case 0:
                   1017:                        logit("%s: Authentication tried for %.100s with "
                   1018:                            "correct key but not from a permitted "
                   1019:                            "host (host=%.200s, ip=%.200s, required=%.200s).",
                   1020:                            loc, pw->pw_name, remote_host, remote_ip,
                   1021:                            opts->required_from_host_keys);
                   1022:                        auth_debug_add("%s: Your host '%.200s' is not "
                   1023:                            "permitted to use this key for login.",
                   1024:                            loc, remote_host);
                   1025:                        /* deny access */
                   1026:                        return -1;
                   1027:                }
                   1028:        }
                   1029:        /* Check source-address restriction from certificate */
                   1030:        if (opts->required_from_host_cert != NULL) {
                   1031:                switch (addr_match_cidr_list(remote_ip,
                   1032:                    opts->required_from_host_cert)) {
                   1033:                case 1:
                   1034:                        /* accepted */
                   1035:                        break;
                   1036:                case -1:
                   1037:                default:
                   1038:                        /* invalid */
                   1039:                        error("%s: Certificate source-address invalid",
                   1040:                            loc);
                   1041:                        /* FALLTHROUGH */
                   1042:                case 0:
                   1043:                        logit("%s: Authentication tried for %.100s with valid "
                   1044:                            "certificate but not from a permitted source "
                   1045:                            "address (%.200s).", loc, pw->pw_name, remote_ip);
                   1046:                        auth_debug_add("%s: Your address '%.200s' is not "
                   1047:                            "permitted to use this certificate for login.",
                   1048:                            loc, remote_ip);
                   1049:                        return -1;
                   1050:                }
                   1051:        }
                   1052:        /*
                   1053:         *
                   1054:         * XXX this is spammy. We should report remotely only for keys
                   1055:         *     that are successful in actual auth attempts, and not PK_OK
                   1056:         *     tests.
                   1057:         */
                   1058:        auth_log_authopts(loc, opts, 1);
                   1059:
                   1060:        return 0;
1.1       markus   1061: }