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

Annotation of src/usr.bin/ssh/auth-options.c, Revision 1.64

1.64    ! millert     1: /* $OpenBSD: auth-options.c,v 1.63 2014/06/24 01:13:21 djm Exp $ */
1.3       deraadt     2: /*
                      3:  * Author: Tatu Ylonen <ylo@cs.hut.fi>
                      4:  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
                      5:  *                    All rights reserved
                      6:  * As far as I am concerned, the code I have written for this software
                      7:  * can be used freely for any purpose.  Any derived versions of this
                      8:  * software must be clearly marked as such, and if the derived work is
                      9:  * incompatible with the protocol description in the RFC file, it must be
                     10:  * called by a name other than "ssh" or "Secure Shell".
                     11:  */
                     12:
1.36      stevesk    13: #include <sys/types.h>
1.42      djm        14: #include <sys/queue.h>
1.36      stevesk    15:
1.37      stevesk    16: #include <netdb.h>
1.36      stevesk    17: #include <pwd.h>
1.39      stevesk    18: #include <string.h>
1.40      deraadt    19: #include <stdio.h>
                     20: #include <stdarg.h>
1.1       markus     21:
                     22: #include "xmalloc.h"
                     23: #include "match.h"
1.11      markus     24: #include "log.h"
                     25: #include "canohost.h"
1.40      deraadt    26: #include "buffer.h"
1.64    ! millert    27: #include "misc.h"
1.18      markus     28: #include "channels.h"
1.12      markus     29: #include "servconf.h"
1.40      deraadt    30: #include "key.h"
1.50      djm        31: #include "auth-options.h"
1.40      deraadt    32: #include "hostfile.h"
                     33: #include "auth.h"
1.1       markus     34:
                     35: /* Flags set authorized_keys flags */
                     36: int no_port_forwarding_flag = 0;
                     37: int no_agent_forwarding_flag = 0;
                     38: int no_x11_forwarding_flag = 0;
                     39: int no_pty_flag = 0;
1.41      djm        40: int no_user_rc = 0;
1.45      djm        41: int key_is_cert_authority = 0;
1.1       markus     42:
                     43: /* "command=" option. */
                     44: char *forced_command = NULL;
                     45:
                     46: /* "environment=" options. */
                     47: struct envstring *custom_environment = NULL;
                     48:
1.32      reyk       49: /* "tunnel=" option. */
                     50: int forced_tun_device = -1;
                     51:
1.51      djm        52: /* "principals=" option. */
                     53: char *authorized_principals = NULL;
                     54:
1.12      markus     55: extern ServerOptions options;
                     56:
1.22      provos     57: void
1.5       markus     58: auth_clear_options(void)
                     59: {
                     60:        no_agent_forwarding_flag = 0;
                     61:        no_port_forwarding_flag = 0;
                     62:        no_pty_flag = 0;
                     63:        no_x11_forwarding_flag = 0;
1.41      djm        64:        no_user_rc = 0;
1.45      djm        65:        key_is_cert_authority = 0;
1.5       markus     66:        while (custom_environment) {
                     67:                struct envstring *ce = custom_environment;
                     68:                custom_environment = ce->next;
1.58      djm        69:                free(ce->s);
                     70:                free(ce);
1.5       markus     71:        }
                     72:        if (forced_command) {
1.58      djm        73:                free(forced_command);
1.5       markus     74:                forced_command = NULL;
                     75:        }
1.51      djm        76:        if (authorized_principals) {
1.58      djm        77:                free(authorized_principals);
1.51      djm        78:                authorized_principals = NULL;
                     79:        }
1.32      reyk       80:        forced_tun_device = -1;
1.15      markus     81:        channel_clear_permitted_opens();
1.5       markus     82: }
                     83:
1.10      markus     84: /*
                     85:  * return 1 if access is granted, 0 if not.
                     86:  * side effect: sets key option flags
                     87:  */
1.1       markus     88: int
1.12      markus     89: auth_parse_options(struct passwd *pw, char *opts, char *file, u_long linenum)
1.1       markus     90: {
                     91:        const char *cp;
1.15      markus     92:        int i;
1.5       markus     93:
                     94:        /* reset options */
                     95:        auth_clear_options();
1.13      markus     96:
                     97:        if (!opts)
                     98:                return 1;
1.5       markus     99:
1.12      markus    100:        while (*opts && *opts != ' ' && *opts != '\t') {
1.45      djm       101:                cp = "cert-authority";
                    102:                if (strncasecmp(opts, cp, strlen(cp)) == 0) {
                    103:                        key_is_cert_authority = 1;
                    104:                        opts += strlen(cp);
                    105:                        goto next_option;
                    106:                }
1.1       markus    107:                cp = "no-port-forwarding";
1.12      markus    108:                if (strncasecmp(opts, cp, strlen(cp)) == 0) {
1.24      markus    109:                        auth_debug_add("Port forwarding disabled.");
1.1       markus    110:                        no_port_forwarding_flag = 1;
1.12      markus    111:                        opts += strlen(cp);
1.1       markus    112:                        goto next_option;
                    113:                }
                    114:                cp = "no-agent-forwarding";
1.12      markus    115:                if (strncasecmp(opts, cp, strlen(cp)) == 0) {
1.24      markus    116:                        auth_debug_add("Agent forwarding disabled.");
1.1       markus    117:                        no_agent_forwarding_flag = 1;
1.12      markus    118:                        opts += strlen(cp);
1.1       markus    119:                        goto next_option;
                    120:                }
                    121:                cp = "no-X11-forwarding";
1.12      markus    122:                if (strncasecmp(opts, cp, strlen(cp)) == 0) {
1.24      markus    123:                        auth_debug_add("X11 forwarding disabled.");
1.1       markus    124:                        no_x11_forwarding_flag = 1;
1.12      markus    125:                        opts += strlen(cp);
1.1       markus    126:                        goto next_option;
                    127:                }
                    128:                cp = "no-pty";
1.12      markus    129:                if (strncasecmp(opts, cp, strlen(cp)) == 0) {
1.24      markus    130:                        auth_debug_add("Pty allocation disabled.");
1.1       markus    131:                        no_pty_flag = 1;
1.41      djm       132:                        opts += strlen(cp);
                    133:                        goto next_option;
                    134:                }
                    135:                cp = "no-user-rc";
                    136:                if (strncasecmp(opts, cp, strlen(cp)) == 0) {
                    137:                        auth_debug_add("User rc file execution disabled.");
                    138:                        no_user_rc = 1;
1.12      markus    139:                        opts += strlen(cp);
1.1       markus    140:                        goto next_option;
                    141:                }
                    142:                cp = "command=\"";
1.12      markus    143:                if (strncasecmp(opts, cp, strlen(cp)) == 0) {
                    144:                        opts += strlen(cp);
1.51      djm       145:                        if (forced_command != NULL)
1.58      djm       146:                                free(forced_command);
1.12      markus    147:                        forced_command = xmalloc(strlen(opts) + 1);
1.1       markus    148:                        i = 0;
1.12      markus    149:                        while (*opts) {
                    150:                                if (*opts == '"')
1.1       markus    151:                                        break;
1.12      markus    152:                                if (*opts == '\\' && opts[1] == '"') {
                    153:                                        opts += 2;
1.1       markus    154:                                        forced_command[i++] = '"';
                    155:                                        continue;
                    156:                                }
1.12      markus    157:                                forced_command[i++] = *opts++;
1.1       markus    158:                        }
1.12      markus    159:                        if (!*opts) {
1.1       markus    160:                                debug("%.100s, line %lu: missing end quote",
1.10      markus    161:                                    file, linenum);
1.24      markus    162:                                auth_debug_add("%.100s, line %lu: missing end quote",
1.10      markus    163:                                    file, linenum);
1.58      djm       164:                                free(forced_command);
1.14      markus    165:                                forced_command = NULL;
                    166:                                goto bad_option;
1.1       markus    167:                        }
1.38      dtucker   168:                        forced_command[i] = '\0';
1.54      djm       169:                        auth_debug_add("Forced command.");
1.51      djm       170:                        opts++;
                    171:                        goto next_option;
                    172:                }
                    173:                cp = "principals=\"";
                    174:                if (strncasecmp(opts, cp, strlen(cp)) == 0) {
                    175:                        opts += strlen(cp);
                    176:                        if (authorized_principals != NULL)
1.58      djm       177:                                free(authorized_principals);
1.51      djm       178:                        authorized_principals = xmalloc(strlen(opts) + 1);
                    179:                        i = 0;
                    180:                        while (*opts) {
                    181:                                if (*opts == '"')
                    182:                                        break;
                    183:                                if (*opts == '\\' && opts[1] == '"') {
                    184:                                        opts += 2;
                    185:                                        authorized_principals[i++] = '"';
                    186:                                        continue;
                    187:                                }
                    188:                                authorized_principals[i++] = *opts++;
                    189:                        }
                    190:                        if (!*opts) {
                    191:                                debug("%.100s, line %lu: missing end quote",
                    192:                                    file, linenum);
                    193:                                auth_debug_add("%.100s, line %lu: missing end quote",
                    194:                                    file, linenum);
1.58      djm       195:                                free(authorized_principals);
1.51      djm       196:                                authorized_principals = NULL;
                    197:                                goto bad_option;
                    198:                        }
                    199:                        authorized_principals[i] = '\0';
                    200:                        auth_debug_add("principals: %.900s",
                    201:                            authorized_principals);
1.12      markus    202:                        opts++;
1.1       markus    203:                        goto next_option;
                    204:                }
                    205:                cp = "environment=\"";
1.26      markus    206:                if (options.permit_user_env &&
                    207:                    strncasecmp(opts, cp, strlen(cp)) == 0) {
1.1       markus    208:                        char *s;
                    209:                        struct envstring *new_envstring;
1.15      markus    210:
1.12      markus    211:                        opts += strlen(cp);
                    212:                        s = xmalloc(strlen(opts) + 1);
1.1       markus    213:                        i = 0;
1.12      markus    214:                        while (*opts) {
                    215:                                if (*opts == '"')
1.1       markus    216:                                        break;
1.12      markus    217:                                if (*opts == '\\' && opts[1] == '"') {
                    218:                                        opts += 2;
1.1       markus    219:                                        s[i++] = '"';
                    220:                                        continue;
                    221:                                }
1.12      markus    222:                                s[i++] = *opts++;
1.1       markus    223:                        }
1.12      markus    224:                        if (!*opts) {
1.1       markus    225:                                debug("%.100s, line %lu: missing end quote",
1.10      markus    226:                                    file, linenum);
1.24      markus    227:                                auth_debug_add("%.100s, line %lu: missing end quote",
1.10      markus    228:                                    file, linenum);
1.58      djm       229:                                free(s);
1.14      markus    230:                                goto bad_option;
1.1       markus    231:                        }
1.38      dtucker   232:                        s[i] = '\0';
1.24      markus    233:                        auth_debug_add("Adding to environment: %.900s", s);
1.1       markus    234:                        debug("Adding to environment: %.900s", s);
1.12      markus    235:                        opts++;
1.61      djm       236:                        new_envstring = xcalloc(1, sizeof(struct envstring));
1.1       markus    237:                        new_envstring->s = s;
                    238:                        new_envstring->next = custom_environment;
                    239:                        custom_environment = new_envstring;
                    240:                        goto next_option;
                    241:                }
                    242:                cp = "from=\"";
1.12      markus    243:                if (strncasecmp(opts, cp, strlen(cp)) == 0) {
                    244:                        const char *remote_ip = get_remote_ipaddr();
                    245:                        const char *remote_host = get_canonical_hostname(
1.28      markus    246:                            options.use_dns);
1.12      markus    247:                        char *patterns = xmalloc(strlen(opts) + 1);
1.15      markus    248:
1.12      markus    249:                        opts += strlen(cp);
1.1       markus    250:                        i = 0;
1.12      markus    251:                        while (*opts) {
                    252:                                if (*opts == '"')
1.1       markus    253:                                        break;
1.12      markus    254:                                if (*opts == '\\' && opts[1] == '"') {
                    255:                                        opts += 2;
1.1       markus    256:                                        patterns[i++] = '"';
                    257:                                        continue;
                    258:                                }
1.12      markus    259:                                patterns[i++] = *opts++;
1.1       markus    260:                        }
1.12      markus    261:                        if (!*opts) {
1.1       markus    262:                                debug("%.100s, line %lu: missing end quote",
1.10      markus    263:                                    file, linenum);
1.24      markus    264:                                auth_debug_add("%.100s, line %lu: missing end quote",
1.10      markus    265:                                    file, linenum);
1.58      djm       266:                                free(patterns);
1.14      markus    267:                                goto bad_option;
1.1       markus    268:                        }
1.38      dtucker   269:                        patterns[i] = '\0';
1.12      markus    270:                        opts++;
1.43      djm       271:                        switch (match_host_and_ip(remote_host, remote_ip,
                    272:                            patterns)) {
                    273:                        case 1:
1.58      djm       274:                                free(patterns);
1.43      djm       275:                                /* Host name matches. */
                    276:                                goto next_option;
                    277:                        case -1:
                    278:                                debug("%.100s, line %lu: invalid criteria",
                    279:                                    file, linenum);
                    280:                                auth_debug_add("%.100s, line %lu: "
                    281:                                    "invalid criteria", file, linenum);
                    282:                                /* FALLTHROUGH */
                    283:                        case 0:
1.58      djm       284:                                free(patterns);
1.27      itojun    285:                                logit("Authentication tried for %.100s with "
1.12      markus    286:                                    "correct key but not from a permitted "
                    287:                                    "host (host=%.200s, ip=%.200s).",
                    288:                                    pw->pw_name, remote_host, remote_ip);
1.24      markus    289:                                auth_debug_add("Your host '%.200s' is not "
1.12      markus    290:                                    "permitted to use this key for login.",
                    291:                                    remote_host);
1.43      djm       292:                                break;
1.1       markus    293:                        }
1.43      djm       294:                        /* deny access */
                    295:                        return 0;
1.15      markus    296:                }
                    297:                cp = "permitopen=\"";
                    298:                if (strncasecmp(opts, cp, strlen(cp)) == 0) {
1.29      djm       299:                        char *host, *p;
1.44      djm       300:                        int port;
1.15      markus    301:                        char *patterns = xmalloc(strlen(opts) + 1);
                    302:
                    303:                        opts += strlen(cp);
                    304:                        i = 0;
                    305:                        while (*opts) {
                    306:                                if (*opts == '"')
                    307:                                        break;
                    308:                                if (*opts == '\\' && opts[1] == '"') {
                    309:                                        opts += 2;
                    310:                                        patterns[i++] = '"';
                    311:                                        continue;
                    312:                                }
                    313:                                patterns[i++] = *opts++;
                    314:                        }
                    315:                        if (!*opts) {
                    316:                                debug("%.100s, line %lu: missing end quote",
                    317:                                    file, linenum);
1.29      djm       318:                                auth_debug_add("%.100s, line %lu: missing "
                    319:                                    "end quote", file, linenum);
1.58      djm       320:                                free(patterns);
1.15      markus    321:                                goto bad_option;
                    322:                        }
1.38      dtucker   323:                        patterns[i] = '\0';
1.15      markus    324:                        opts++;
1.29      djm       325:                        p = patterns;
1.64    ! millert   326:                        /* XXX - add streamlocal support */
1.29      djm       327:                        host = hpdelim(&p);
                    328:                        if (host == NULL || strlen(host) >= NI_MAXHOST) {
                    329:                                debug("%.100s, line %lu: Bad permitopen "
1.31      deraadt   330:                                    "specification <%.100s>", file, linenum,
1.29      djm       331:                                    patterns);
1.24      markus    332:                                auth_debug_add("%.100s, line %lu: "
1.29      djm       333:                                    "Bad permitopen specification", file,
                    334:                                    linenum);
1.58      djm       335:                                free(patterns);
1.15      markus    336:                                goto bad_option;
                    337:                        }
1.30      deraadt   338:                        host = cleanhostname(host);
1.55      dtucker   339:                        if (p == NULL || (port = permitopen_port(p)) < 0) {
1.29      djm       340:                                debug("%.100s, line %lu: Bad permitopen port "
                    341:                                    "<%.100s>", file, linenum, p ? p : "");
1.24      markus    342:                                auth_debug_add("%.100s, line %lu: "
1.20      stevesk   343:                                    "Bad permitopen port", file, linenum);
1.58      djm       344:                                free(patterns);
1.15      markus    345:                                goto bad_option;
                    346:                        }
1.57      djm       347:                        if ((options.allow_tcp_forwarding & FORWARD_LOCAL) != 0)
1.20      stevesk   348:                                channel_add_permitted_opens(host, port);
1.58      djm       349:                        free(patterns);
1.32      reyk      350:                        goto next_option;
                    351:                }
                    352:                cp = "tunnel=\"";
                    353:                if (strncasecmp(opts, cp, strlen(cp)) == 0) {
                    354:                        char *tun = NULL;
                    355:                        opts += strlen(cp);
                    356:                        tun = xmalloc(strlen(opts) + 1);
                    357:                        i = 0;
                    358:                        while (*opts) {
                    359:                                if (*opts == '"')
                    360:                                        break;
                    361:                                tun[i++] = *opts++;
                    362:                        }
                    363:                        if (!*opts) {
                    364:                                debug("%.100s, line %lu: missing end quote",
                    365:                                    file, linenum);
                    366:                                auth_debug_add("%.100s, line %lu: missing end quote",
                    367:                                    file, linenum);
1.58      djm       368:                                free(tun);
1.32      reyk      369:                                forced_tun_device = -1;
                    370:                                goto bad_option;
                    371:                        }
1.38      dtucker   372:                        tun[i] = '\0';
1.32      reyk      373:                        forced_tun_device = a2tun(tun, NULL);
1.58      djm       374:                        free(tun);
1.33      reyk      375:                        if (forced_tun_device == SSH_TUNID_ERR) {
1.32      reyk      376:                                debug("%.100s, line %lu: invalid tun device",
                    377:                                    file, linenum);
                    378:                                auth_debug_add("%.100s, line %lu: invalid tun device",
                    379:                                    file, linenum);
                    380:                                forced_tun_device = -1;
                    381:                                goto bad_option;
                    382:                        }
                    383:                        auth_debug_add("Forced tun device: %d", forced_tun_device);
                    384:                        opts++;
1.1       markus    385:                        goto next_option;
                    386:                }
                    387: next_option:
                    388:                /*
                    389:                 * Skip the comma, and move to the next option
                    390:                 * (or break out if there are no more).
                    391:                 */
1.12      markus    392:                if (!*opts)
1.1       markus    393:                        fatal("Bugs in auth-options.c option processing.");
1.12      markus    394:                if (*opts == ' ' || *opts == '\t')
1.1       markus    395:                        break;          /* End of options. */
1.12      markus    396:                if (*opts != ',')
1.1       markus    397:                        goto bad_option;
1.12      markus    398:                opts++;
1.1       markus    399:                /* Process the next option. */
                    400:        }
1.22      provos    401:
1.1       markus    402:        /* grant access */
                    403:        return 1;
                    404:
                    405: bad_option:
1.27      itojun    406:        logit("Bad options in %.100s file, line %lu: %.50s",
1.12      markus    407:            file, linenum, opts);
1.24      markus    408:        auth_debug_add("Bad options in %.100s file, line %lu: %.50s",
1.12      markus    409:            file, linenum, opts);
1.22      provos    410:
1.1       markus    411:        /* deny access */
                    412:        return 0;
                    413: }
1.45      djm       414:
1.52      djm       415: #define OPTIONS_CRITICAL       1
                    416: #define OPTIONS_EXTENSIONS     2
                    417: static int
                    418: parse_option_list(u_char *optblob, size_t optblob_len, struct passwd *pw,
                    419:     u_int which, int crit,
                    420:     int *cert_no_port_forwarding_flag,
                    421:     int *cert_no_agent_forwarding_flag,
                    422:     int *cert_no_x11_forwarding_flag,
                    423:     int *cert_no_pty_flag,
                    424:     int *cert_no_user_rc,
                    425:     char **cert_forced_command,
                    426:     int *cert_source_address_done)
1.45      djm       427: {
1.52      djm       428:        char *command, *allowed;
                    429:        const char *remote_ip;
1.59      djm       430:        char *name = NULL;
                    431:        u_char *data_blob = NULL;
1.46      djm       432:        u_int nlen, dlen, clen;
1.45      djm       433:        Buffer c, data;
1.62      djm       434:        int ret = -1, result, found;
1.45      djm       435:
                    436:        buffer_init(&data);
                    437:
                    438:        /* Make copy to avoid altering original */
                    439:        buffer_init(&c);
1.52      djm       440:        buffer_append(&c, optblob, optblob_len);
1.45      djm       441:
                    442:        while (buffer_len(&c) > 0) {
1.53      djm       443:                if ((name = buffer_get_cstring_ret(&c, &nlen)) == NULL ||
1.46      djm       444:                    (data_blob = buffer_get_string_ret(&c, &dlen)) == NULL) {
1.50      djm       445:                        error("Certificate options corrupt");
1.45      djm       446:                        goto out;
                    447:                }
1.46      djm       448:                buffer_append(&data, data_blob, dlen);
1.52      djm       449:                debug3("found certificate option \"%.100s\" len %u",
1.46      djm       450:                    name, dlen);
1.52      djm       451:                found = 0;
                    452:                if ((which & OPTIONS_EXTENSIONS) != 0) {
                    453:                        if (strcmp(name, "permit-X11-forwarding") == 0) {
                    454:                                *cert_no_x11_forwarding_flag = 0;
                    455:                                found = 1;
                    456:                        } else if (strcmp(name,
                    457:                            "permit-agent-forwarding") == 0) {
                    458:                                *cert_no_agent_forwarding_flag = 0;
                    459:                                found = 1;
                    460:                        } else if (strcmp(name,
                    461:                            "permit-port-forwarding") == 0) {
                    462:                                *cert_no_port_forwarding_flag = 0;
                    463:                                found = 1;
                    464:                        } else if (strcmp(name, "permit-pty") == 0) {
                    465:                                *cert_no_pty_flag = 0;
                    466:                                found = 1;
                    467:                        } else if (strcmp(name, "permit-user-rc") == 0) {
                    468:                                *cert_no_user_rc = 0;
                    469:                                found = 1;
                    470:                        }
                    471:                }
                    472:                if (!found && (which & OPTIONS_CRITICAL) != 0) {
                    473:                        if (strcmp(name, "force-command") == 0) {
1.53      djm       474:                                if ((command = buffer_get_cstring_ret(&data,
1.52      djm       475:                                    &clen)) == NULL) {
                    476:                                        error("Certificate constraint \"%s\" "
                    477:                                            "corrupt", name);
                    478:                                        goto out;
                    479:                                }
                    480:                                if (*cert_forced_command != NULL) {
                    481:                                        error("Certificate has multiple "
                    482:                                            "force-command options");
1.58      djm       483:                                        free(command);
1.52      djm       484:                                        goto out;
                    485:                                }
                    486:                                *cert_forced_command = command;
                    487:                                found = 1;
1.45      djm       488:                        }
1.52      djm       489:                        if (strcmp(name, "source-address") == 0) {
1.53      djm       490:                                if ((allowed = buffer_get_cstring_ret(&data,
1.52      djm       491:                                    &clen)) == NULL) {
                    492:                                        error("Certificate constraint "
                    493:                                            "\"%s\" corrupt", name);
                    494:                                        goto out;
                    495:                                }
                    496:                                if ((*cert_source_address_done)++) {
                    497:                                        error("Certificate has multiple "
                    498:                                            "source-address options");
1.58      djm       499:                                        free(allowed);
1.52      djm       500:                                        goto out;
                    501:                                }
                    502:                                remote_ip = get_remote_ipaddr();
1.62      djm       503:                                result = addr_match_cidr_list(remote_ip,
                    504:                                    allowed);
                    505:                                free(allowed);
                    506:                                switch (result) {
1.52      djm       507:                                case 1:
                    508:                                        /* accepted */
                    509:                                        break;
                    510:                                case 0:
                    511:                                        /* no match */
                    512:                                        logit("Authentication tried for %.100s "
                    513:                                            "with valid certificate but not "
                    514:                                            "from a permitted host "
                    515:                                            "(ip=%.200s).", pw->pw_name,
                    516:                                            remote_ip);
                    517:                                        auth_debug_add("Your address '%.200s' "
                    518:                                            "is not permitted to use this "
                    519:                                            "certificate for login.",
                    520:                                            remote_ip);
                    521:                                        goto out;
                    522:                                case -1:
1.62      djm       523:                                default:
1.52      djm       524:                                        error("Certificate source-address "
                    525:                                            "contents invalid");
                    526:                                        goto out;
                    527:                                }
                    528:                                found = 1;
1.46      djm       529:                        }
1.52      djm       530:                }
                    531:
                    532:                if (!found) {
                    533:                        if (crit) {
                    534:                                error("Certificate critical option \"%s\" "
                    535:                                    "is not supported", name);
1.45      djm       536:                                goto out;
1.52      djm       537:                        } else {
                    538:                                logit("Certificate extension \"%s\" "
                    539:                                    "is not supported", name);
1.45      djm       540:                        }
1.52      djm       541:                } else if (buffer_len(&data) != 0) {
                    542:                        error("Certificate option \"%s\" corrupt "
1.45      djm       543:                            "(extra data)", name);
                    544:                        goto out;
                    545:                }
                    546:                buffer_clear(&data);
1.58      djm       547:                free(name);
                    548:                free(data_blob);
1.59      djm       549:                name = NULL;
                    550:                data_blob = NULL;
1.45      djm       551:        }
1.50      djm       552:        /* successfully parsed all options */
1.45      djm       553:        ret = 0;
                    554:
1.52      djm       555:  out:
                    556:        if (ret != 0 &&
                    557:            cert_forced_command != NULL &&
                    558:            *cert_forced_command != NULL) {
1.58      djm       559:                free(*cert_forced_command);
1.52      djm       560:                *cert_forced_command = NULL;
                    561:        }
                    562:        if (name != NULL)
1.58      djm       563:                free(name);
1.52      djm       564:        if (data_blob != NULL)
1.58      djm       565:                free(data_blob);
1.52      djm       566:        buffer_free(&data);
                    567:        buffer_free(&c);
                    568:        return ret;
                    569: }
                    570:
                    571: /*
                    572:  * Set options from critical certificate options. These supersede user key
                    573:  * options so this must be called after auth_parse_options().
                    574:  */
                    575: int
                    576: auth_cert_options(Key *k, struct passwd *pw)
                    577: {
                    578:        int cert_no_port_forwarding_flag = 1;
                    579:        int cert_no_agent_forwarding_flag = 1;
                    580:        int cert_no_x11_forwarding_flag = 1;
                    581:        int cert_no_pty_flag = 1;
                    582:        int cert_no_user_rc = 1;
                    583:        char *cert_forced_command = NULL;
                    584:        int cert_source_address_done = 0;
                    585:
                    586:        if (key_cert_is_legacy(k)) {
                    587:                /* All options are in the one field for v00 certs */
1.63      djm       588:                if (parse_option_list(buffer_ptr(k->cert->critical),
                    589:                    buffer_len(k->cert->critical), pw,
1.52      djm       590:                    OPTIONS_CRITICAL|OPTIONS_EXTENSIONS, 1,
                    591:                    &cert_no_port_forwarding_flag,
                    592:                    &cert_no_agent_forwarding_flag,
                    593:                    &cert_no_x11_forwarding_flag,
                    594:                    &cert_no_pty_flag,
                    595:                    &cert_no_user_rc,
                    596:                    &cert_forced_command,
                    597:                    &cert_source_address_done) == -1)
                    598:                        return -1;
                    599:        } else {
                    600:                /* Separate options and extensions for v01 certs */
1.63      djm       601:                if (parse_option_list(buffer_ptr(k->cert->critical),
                    602:                    buffer_len(k->cert->critical), pw,
1.52      djm       603:                    OPTIONS_CRITICAL, 1, NULL, NULL, NULL, NULL, NULL,
                    604:                    &cert_forced_command,
                    605:                    &cert_source_address_done) == -1)
                    606:                        return -1;
1.63      djm       607:                if (parse_option_list(buffer_ptr(k->cert->extensions),
                    608:                    buffer_len(k->cert->extensions), pw,
1.52      djm       609:                    OPTIONS_EXTENSIONS, 1,
                    610:                    &cert_no_port_forwarding_flag,
                    611:                    &cert_no_agent_forwarding_flag,
                    612:                    &cert_no_x11_forwarding_flag,
                    613:                    &cert_no_pty_flag,
                    614:                    &cert_no_user_rc,
                    615:                    NULL, NULL) == -1)
                    616:                        return -1;
                    617:        }
                    618:
1.45      djm       619:        no_port_forwarding_flag |= cert_no_port_forwarding_flag;
                    620:        no_agent_forwarding_flag |= cert_no_agent_forwarding_flag;
                    621:        no_x11_forwarding_flag |= cert_no_x11_forwarding_flag;
                    622:        no_pty_flag |= cert_no_pty_flag;
                    623:        no_user_rc |= cert_no_user_rc;
                    624:        /* CA-specified forced command supersedes key option */
                    625:        if (cert_forced_command != NULL) {
                    626:                if (forced_command != NULL)
1.58      djm       627:                        free(forced_command);
1.45      djm       628:                forced_command = cert_forced_command;
                    629:        }
1.52      djm       630:        return 0;
1.45      djm       631: }
                    632: