djm@openbsd.org | c28fc62 | 2015-07-03 03:43:18 +0000 | [diff] [blame] | 1 | /* $OpenBSD: auth-options.c,v 1.68 2015/07/03 03:43:18 djm Exp $ */ |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 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 |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 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 | |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 13 | #include "includes.h" |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 14 | |
Damien Miller | 9f2abc4 | 2006-07-10 20:53:08 +1000 | [diff] [blame] | 15 | #include <sys/types.h> |
| 16 | |
Damien Miller | b8fe89c | 2006-07-24 14:51:00 +1000 | [diff] [blame] | 17 | #include <netdb.h> |
Damien Miller | 9f2abc4 | 2006-07-10 20:53:08 +1000 | [diff] [blame] | 18 | #include <pwd.h> |
Damien Miller | e3476ed | 2006-07-24 14:13:33 +1000 | [diff] [blame] | 19 | #include <string.h> |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 20 | #include <stdio.h> |
| 21 | #include <stdarg.h> |
Damien Miller | 9f2abc4 | 2006-07-10 20:53:08 +1000 | [diff] [blame] | 22 | |
Damien Miller | b84886b | 2008-05-19 15:05:07 +1000 | [diff] [blame] | 23 | #include "openbsd-compat/sys-queue.h" |
markus@openbsd.org | ae8b463 | 2015-01-14 10:30:34 +0000 | [diff] [blame] | 24 | |
| 25 | #include "key.h" /* XXX for typedef */ |
| 26 | #include "buffer.h" /* XXX for typedef */ |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 27 | #include "xmalloc.h" |
| 28 | #include "match.h" |
markus@openbsd.org | ae8b463 | 2015-01-14 10:30:34 +0000 | [diff] [blame] | 29 | #include "ssherr.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 30 | #include "log.h" |
| 31 | #include "canohost.h" |
markus@openbsd.org | ae8b463 | 2015-01-14 10:30:34 +0000 | [diff] [blame] | 32 | #include "sshbuf.h" |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame] | 33 | #include "misc.h" |
Ben Lindstrom | c763767 | 2001-06-09 00:36:26 +0000 | [diff] [blame] | 34 | #include "channels.h" |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 35 | #include "servconf.h" |
markus@openbsd.org | ae8b463 | 2015-01-14 10:30:34 +0000 | [diff] [blame] | 36 | #include "sshkey.h" |
Damien Miller | 4e270b0 | 2010-04-16 15:56:21 +1000 | [diff] [blame] | 37 | #include "auth-options.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 38 | #include "hostfile.h" |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 39 | #include "auth.h" |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 40 | |
| 41 | /* Flags set authorized_keys flags */ |
| 42 | int no_port_forwarding_flag = 0; |
| 43 | int no_agent_forwarding_flag = 0; |
| 44 | int no_x11_forwarding_flag = 0; |
| 45 | int no_pty_flag = 0; |
Damien Miller | 95e8095 | 2008-03-27 11:03:05 +1100 | [diff] [blame] | 46 | int no_user_rc = 0; |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 47 | int key_is_cert_authority = 0; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 48 | |
| 49 | /* "command=" option. */ |
| 50 | char *forced_command = NULL; |
| 51 | |
| 52 | /* "environment=" options. */ |
| 53 | struct envstring *custom_environment = NULL; |
| 54 | |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 55 | /* "tunnel=" option. */ |
| 56 | int forced_tun_device = -1; |
| 57 | |
Damien Miller | 30da344 | 2010-05-10 11:58:03 +1000 | [diff] [blame] | 58 | /* "principals=" option. */ |
| 59 | char *authorized_principals = NULL; |
| 60 | |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 61 | extern ServerOptions options; |
| 62 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 63 | void |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 64 | auth_clear_options(void) |
| 65 | { |
| 66 | no_agent_forwarding_flag = 0; |
| 67 | no_port_forwarding_flag = 0; |
| 68 | no_pty_flag = 0; |
| 69 | no_x11_forwarding_flag = 0; |
Damien Miller | 95e8095 | 2008-03-27 11:03:05 +1100 | [diff] [blame] | 70 | no_user_rc = 0; |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 71 | key_is_cert_authority = 0; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 72 | while (custom_environment) { |
| 73 | struct envstring *ce = custom_environment; |
| 74 | custom_environment = ce->next; |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 75 | free(ce->s); |
| 76 | free(ce); |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 77 | } |
| 78 | if (forced_command) { |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 79 | free(forced_command); |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 80 | forced_command = NULL; |
| 81 | } |
Damien Miller | 30da344 | 2010-05-10 11:58:03 +1000 | [diff] [blame] | 82 | if (authorized_principals) { |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 83 | free(authorized_principals); |
Damien Miller | 30da344 | 2010-05-10 11:58:03 +1000 | [diff] [blame] | 84 | authorized_principals = NULL; |
| 85 | } |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 86 | forced_tun_device = -1; |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 87 | channel_clear_permitted_opens(); |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 88 | } |
| 89 | |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 90 | /* |
| 91 | * return 1 if access is granted, 0 if not. |
| 92 | * side effect: sets key option flags |
| 93 | */ |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 94 | int |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 95 | auth_parse_options(struct passwd *pw, char *opts, char *file, u_long linenum) |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 96 | { |
| 97 | const char *cp; |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 98 | int i; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 99 | |
| 100 | /* reset options */ |
| 101 | auth_clear_options(); |
| 102 | |
Ben Lindstrom | 36d7bd0 | 2001-02-10 22:27:19 +0000 | [diff] [blame] | 103 | if (!opts) |
| 104 | return 1; |
| 105 | |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 106 | while (*opts && *opts != ' ' && *opts != '\t') { |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 107 | cp = "cert-authority"; |
| 108 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
| 109 | key_is_cert_authority = 1; |
| 110 | opts += strlen(cp); |
| 111 | goto next_option; |
| 112 | } |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 113 | cp = "no-port-forwarding"; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 114 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 115 | auth_debug_add("Port forwarding disabled."); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 116 | no_port_forwarding_flag = 1; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 117 | opts += strlen(cp); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 118 | goto next_option; |
| 119 | } |
| 120 | cp = "no-agent-forwarding"; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 121 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 122 | auth_debug_add("Agent forwarding disabled."); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 123 | no_agent_forwarding_flag = 1; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 124 | opts += strlen(cp); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 125 | goto next_option; |
| 126 | } |
| 127 | cp = "no-X11-forwarding"; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 128 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 129 | auth_debug_add("X11 forwarding disabled."); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 130 | no_x11_forwarding_flag = 1; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 131 | opts += strlen(cp); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 132 | goto next_option; |
| 133 | } |
| 134 | cp = "no-pty"; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 135 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 136 | auth_debug_add("Pty allocation disabled."); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 137 | no_pty_flag = 1; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 138 | opts += strlen(cp); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 139 | goto next_option; |
| 140 | } |
Damien Miller | 95e8095 | 2008-03-27 11:03:05 +1100 | [diff] [blame] | 141 | cp = "no-user-rc"; |
| 142 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
| 143 | auth_debug_add("User rc file execution disabled."); |
| 144 | no_user_rc = 1; |
| 145 | opts += strlen(cp); |
| 146 | goto next_option; |
| 147 | } |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 148 | cp = "command=\""; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 149 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 150 | opts += strlen(cp); |
Damien Miller | 30da344 | 2010-05-10 11:58:03 +1000 | [diff] [blame] | 151 | if (forced_command != NULL) |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 152 | free(forced_command); |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 153 | forced_command = xmalloc(strlen(opts) + 1); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 154 | i = 0; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 155 | while (*opts) { |
| 156 | if (*opts == '"') |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 157 | break; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 158 | if (*opts == '\\' && opts[1] == '"') { |
| 159 | opts += 2; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 160 | forced_command[i++] = '"'; |
| 161 | continue; |
| 162 | } |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 163 | forced_command[i++] = *opts++; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 164 | } |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 165 | if (!*opts) { |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 166 | debug("%.100s, line %lu: missing end quote", |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 167 | file, linenum); |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 168 | auth_debug_add("%.100s, line %lu: missing end quote", |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 169 | file, linenum); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 170 | free(forced_command); |
Damien Miller | 056ddf7 | 2001-03-14 10:15:20 +1100 | [diff] [blame] | 171 | forced_command = NULL; |
| 172 | goto bad_option; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 173 | } |
Damien Miller | 9829926 | 2006-07-24 14:01:43 +1000 | [diff] [blame] | 174 | forced_command[i] = '\0'; |
Damien Miller | de53fd0 | 2011-01-06 22:44:18 +1100 | [diff] [blame] | 175 | auth_debug_add("Forced command."); |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 176 | opts++; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 177 | goto next_option; |
| 178 | } |
Damien Miller | 30da344 | 2010-05-10 11:58:03 +1000 | [diff] [blame] | 179 | cp = "principals=\""; |
| 180 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
| 181 | opts += strlen(cp); |
| 182 | if (authorized_principals != NULL) |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 183 | free(authorized_principals); |
Damien Miller | 30da344 | 2010-05-10 11:58:03 +1000 | [diff] [blame] | 184 | authorized_principals = xmalloc(strlen(opts) + 1); |
| 185 | i = 0; |
| 186 | while (*opts) { |
| 187 | if (*opts == '"') |
| 188 | break; |
| 189 | if (*opts == '\\' && opts[1] == '"') { |
| 190 | opts += 2; |
| 191 | authorized_principals[i++] = '"'; |
| 192 | continue; |
| 193 | } |
| 194 | authorized_principals[i++] = *opts++; |
| 195 | } |
| 196 | if (!*opts) { |
| 197 | debug("%.100s, line %lu: missing end quote", |
| 198 | file, linenum); |
| 199 | auth_debug_add("%.100s, line %lu: missing end quote", |
| 200 | file, linenum); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 201 | free(authorized_principals); |
Damien Miller | 30da344 | 2010-05-10 11:58:03 +1000 | [diff] [blame] | 202 | authorized_principals = NULL; |
| 203 | goto bad_option; |
| 204 | } |
| 205 | authorized_principals[i] = '\0'; |
| 206 | auth_debug_add("principals: %.900s", |
| 207 | authorized_principals); |
| 208 | opts++; |
| 209 | goto next_option; |
| 210 | } |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 211 | cp = "environment=\""; |
djm@openbsd.org | a42d67b | 2015-05-01 03:20:54 +0000 | [diff] [blame] | 212 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 213 | char *s; |
| 214 | struct envstring *new_envstring; |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 215 | |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 216 | opts += strlen(cp); |
| 217 | s = xmalloc(strlen(opts) + 1); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 218 | i = 0; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 219 | while (*opts) { |
| 220 | if (*opts == '"') |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 221 | break; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 222 | if (*opts == '\\' && opts[1] == '"') { |
| 223 | opts += 2; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 224 | s[i++] = '"'; |
| 225 | continue; |
| 226 | } |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 227 | s[i++] = *opts++; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 228 | } |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 229 | if (!*opts) { |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 230 | debug("%.100s, line %lu: missing end quote", |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 231 | file, linenum); |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 232 | auth_debug_add("%.100s, line %lu: missing end quote", |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 233 | file, linenum); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 234 | free(s); |
Damien Miller | 056ddf7 | 2001-03-14 10:15:20 +1100 | [diff] [blame] | 235 | goto bad_option; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 236 | } |
Damien Miller | 9829926 | 2006-07-24 14:01:43 +1000 | [diff] [blame] | 237 | s[i] = '\0'; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 238 | opts++; |
djm@openbsd.org | a42d67b | 2015-05-01 03:20:54 +0000 | [diff] [blame] | 239 | if (options.permit_user_env) { |
| 240 | auth_debug_add("Adding to environment: " |
| 241 | "%.900s", s); |
| 242 | debug("Adding to environment: %.900s", s); |
| 243 | new_envstring = xcalloc(1, |
| 244 | sizeof(*new_envstring)); |
| 245 | new_envstring->s = s; |
| 246 | new_envstring->next = custom_environment; |
| 247 | custom_environment = new_envstring; |
| 248 | s = NULL; |
| 249 | } |
| 250 | free(s); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 251 | goto next_option; |
| 252 | } |
| 253 | cp = "from=\""; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 254 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 255 | const char *remote_ip = get_remote_ipaddr(); |
| 256 | const char *remote_host = get_canonical_hostname( |
Damien Miller | 3a961dc | 2003-06-03 10:25:48 +1000 | [diff] [blame] | 257 | options.use_dns); |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 258 | char *patterns = xmalloc(strlen(opts) + 1); |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 259 | |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 260 | opts += strlen(cp); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 261 | i = 0; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 262 | while (*opts) { |
| 263 | if (*opts == '"') |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 264 | break; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 265 | if (*opts == '\\' && opts[1] == '"') { |
| 266 | opts += 2; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 267 | patterns[i++] = '"'; |
| 268 | continue; |
| 269 | } |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 270 | patterns[i++] = *opts++; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 271 | } |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 272 | if (!*opts) { |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 273 | debug("%.100s, line %lu: missing end quote", |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 274 | file, linenum); |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 275 | auth_debug_add("%.100s, line %lu: missing end quote", |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 276 | file, linenum); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 277 | free(patterns); |
Damien Miller | 056ddf7 | 2001-03-14 10:15:20 +1100 | [diff] [blame] | 278 | goto bad_option; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 279 | } |
Damien Miller | 9829926 | 2006-07-24 14:01:43 +1000 | [diff] [blame] | 280 | patterns[i] = '\0'; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 281 | opts++; |
Darren Tucker | 896ad5a | 2008-06-11 09:34:46 +1000 | [diff] [blame] | 282 | switch (match_host_and_ip(remote_host, remote_ip, |
| 283 | patterns)) { |
| 284 | case 1: |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 285 | free(patterns); |
Darren Tucker | 896ad5a | 2008-06-11 09:34:46 +1000 | [diff] [blame] | 286 | /* Host name matches. */ |
| 287 | goto next_option; |
| 288 | case -1: |
| 289 | debug("%.100s, line %lu: invalid criteria", |
| 290 | file, linenum); |
| 291 | auth_debug_add("%.100s, line %lu: " |
| 292 | "invalid criteria", file, linenum); |
| 293 | /* FALLTHROUGH */ |
| 294 | case 0: |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 295 | free(patterns); |
Damien Miller | 996acd2 | 2003-04-09 20:59:48 +1000 | [diff] [blame] | 296 | logit("Authentication tried for %.100s with " |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 297 | "correct key but not from a permitted " |
| 298 | "host (host=%.200s, ip=%.200s).", |
| 299 | pw->pw_name, remote_host, remote_ip); |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 300 | auth_debug_add("Your host '%.200s' is not " |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 301 | "permitted to use this key for login.", |
| 302 | remote_host); |
Darren Tucker | 896ad5a | 2008-06-11 09:34:46 +1000 | [diff] [blame] | 303 | break; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 304 | } |
Darren Tucker | 896ad5a | 2008-06-11 09:34:46 +1000 | [diff] [blame] | 305 | /* deny access */ |
| 306 | return 0; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 307 | } |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 308 | cp = "permitopen=\""; |
| 309 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 310 | char *host, *p; |
Damien Miller | e37dde0 | 2009-01-28 16:33:01 +1100 | [diff] [blame] | 311 | int port; |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 312 | char *patterns = xmalloc(strlen(opts) + 1); |
| 313 | |
| 314 | opts += strlen(cp); |
| 315 | i = 0; |
| 316 | while (*opts) { |
| 317 | if (*opts == '"') |
| 318 | break; |
| 319 | if (*opts == '\\' && opts[1] == '"') { |
| 320 | opts += 2; |
| 321 | patterns[i++] = '"'; |
| 322 | continue; |
| 323 | } |
| 324 | patterns[i++] = *opts++; |
| 325 | } |
| 326 | if (!*opts) { |
| 327 | debug("%.100s, line %lu: missing end quote", |
| 328 | file, linenum); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 329 | auth_debug_add("%.100s, line %lu: missing " |
| 330 | "end quote", file, linenum); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 331 | free(patterns); |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 332 | goto bad_option; |
| 333 | } |
Damien Miller | 9829926 | 2006-07-24 14:01:43 +1000 | [diff] [blame] | 334 | patterns[i] = '\0'; |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 335 | opts++; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 336 | p = patterns; |
Damien Miller | 7acefbb | 2014-07-18 14:11:24 +1000 | [diff] [blame] | 337 | /* XXX - add streamlocal support */ |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 338 | host = hpdelim(&p); |
| 339 | if (host == NULL || strlen(host) >= NI_MAXHOST) { |
| 340 | debug("%.100s, line %lu: Bad permitopen " |
Darren Tucker | 90b9e02 | 2005-03-14 23:08:50 +1100 | [diff] [blame] | 341 | "specification <%.100s>", file, linenum, |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 342 | patterns); |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 343 | auth_debug_add("%.100s, line %lu: " |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 344 | "Bad permitopen specification", file, |
| 345 | linenum); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 346 | free(patterns); |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 347 | goto bad_option; |
| 348 | } |
Darren Tucker | 47eede7 | 2005-03-14 23:08:12 +1100 | [diff] [blame] | 349 | host = cleanhostname(host); |
Darren Tucker | 1338b9e | 2011-10-02 18:57:35 +1100 | [diff] [blame] | 350 | if (p == NULL || (port = permitopen_port(p)) < 0) { |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 351 | debug("%.100s, line %lu: Bad permitopen port " |
| 352 | "<%.100s>", file, linenum, p ? p : ""); |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 353 | auth_debug_add("%.100s, line %lu: " |
Ben Lindstrom | d71ba57 | 2001-09-12 18:03:31 +0000 | [diff] [blame] | 354 | "Bad permitopen port", file, linenum); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 355 | free(patterns); |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 356 | goto bad_option; |
| 357 | } |
Damien Miller | aa5b3f8 | 2012-12-03 09:50:54 +1100 | [diff] [blame] | 358 | if ((options.allow_tcp_forwarding & FORWARD_LOCAL) != 0) |
Ben Lindstrom | d71ba57 | 2001-09-12 18:03:31 +0000 | [diff] [blame] | 359 | channel_add_permitted_opens(host, port); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 360 | free(patterns); |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 361 | goto next_option; |
| 362 | } |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 363 | cp = "tunnel=\""; |
| 364 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
| 365 | char *tun = NULL; |
| 366 | opts += strlen(cp); |
| 367 | tun = xmalloc(strlen(opts) + 1); |
| 368 | i = 0; |
| 369 | while (*opts) { |
| 370 | if (*opts == '"') |
| 371 | break; |
| 372 | tun[i++] = *opts++; |
| 373 | } |
| 374 | if (!*opts) { |
| 375 | debug("%.100s, line %lu: missing end quote", |
| 376 | file, linenum); |
| 377 | auth_debug_add("%.100s, line %lu: missing end quote", |
| 378 | file, linenum); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 379 | free(tun); |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 380 | forced_tun_device = -1; |
| 381 | goto bad_option; |
| 382 | } |
Damien Miller | 9829926 | 2006-07-24 14:01:43 +1000 | [diff] [blame] | 383 | tun[i] = '\0'; |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 384 | forced_tun_device = a2tun(tun, NULL); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 385 | free(tun); |
Damien Miller | 7b58e80 | 2005-12-13 19:33:19 +1100 | [diff] [blame] | 386 | if (forced_tun_device == SSH_TUNID_ERR) { |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 387 | debug("%.100s, line %lu: invalid tun device", |
| 388 | file, linenum); |
| 389 | auth_debug_add("%.100s, line %lu: invalid tun device", |
| 390 | file, linenum); |
| 391 | forced_tun_device = -1; |
| 392 | goto bad_option; |
| 393 | } |
| 394 | auth_debug_add("Forced tun device: %d", forced_tun_device); |
| 395 | opts++; |
| 396 | goto next_option; |
| 397 | } |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 398 | next_option: |
| 399 | /* |
| 400 | * Skip the comma, and move to the next option |
| 401 | * (or break out if there are no more). |
| 402 | */ |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 403 | if (!*opts) |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 404 | fatal("Bugs in auth-options.c option processing."); |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 405 | if (*opts == ' ' || *opts == '\t') |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 406 | break; /* End of options. */ |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 407 | if (*opts != ',') |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 408 | goto bad_option; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 409 | opts++; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 410 | /* Process the next option. */ |
| 411 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 412 | |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 413 | /* grant access */ |
| 414 | return 1; |
| 415 | |
| 416 | bad_option: |
Damien Miller | 996acd2 | 2003-04-09 20:59:48 +1000 | [diff] [blame] | 417 | logit("Bad options in %.100s file, line %lu: %.50s", |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 418 | file, linenum, opts); |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 419 | auth_debug_add("Bad options in %.100s file, line %lu: %.50s", |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 420 | file, linenum, opts); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 421 | |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 422 | /* deny access */ |
| 423 | return 0; |
| 424 | } |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 425 | |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 426 | #define OPTIONS_CRITICAL 1 |
| 427 | #define OPTIONS_EXTENSIONS 2 |
| 428 | static int |
markus@openbsd.org | ae8b463 | 2015-01-14 10:30:34 +0000 | [diff] [blame] | 429 | parse_option_list(struct sshbuf *oblob, struct passwd *pw, |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 430 | u_int which, int crit, |
| 431 | int *cert_no_port_forwarding_flag, |
| 432 | int *cert_no_agent_forwarding_flag, |
| 433 | int *cert_no_x11_forwarding_flag, |
| 434 | int *cert_no_pty_flag, |
| 435 | int *cert_no_user_rc, |
| 436 | char **cert_forced_command, |
| 437 | int *cert_source_address_done) |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 438 | { |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 439 | char *command, *allowed; |
| 440 | const char *remote_ip; |
Damien Miller | ce98654 | 2013-07-18 16:12:44 +1000 | [diff] [blame] | 441 | char *name = NULL; |
markus@openbsd.org | ae8b463 | 2015-01-14 10:30:34 +0000 | [diff] [blame] | 442 | struct sshbuf *c = NULL, *data = NULL; |
| 443 | int r, ret = -1, result, found; |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 444 | |
markus@openbsd.org | ae8b463 | 2015-01-14 10:30:34 +0000 | [diff] [blame] | 445 | if ((c = sshbuf_fromb(oblob)) == NULL) { |
| 446 | error("%s: sshbuf_fromb failed", __func__); |
| 447 | goto out; |
| 448 | } |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 449 | |
markus@openbsd.org | ae8b463 | 2015-01-14 10:30:34 +0000 | [diff] [blame] | 450 | while (sshbuf_len(c) > 0) { |
| 451 | sshbuf_free(data); |
| 452 | data = NULL; |
| 453 | if ((r = sshbuf_get_cstring(c, &name, NULL)) != 0 || |
| 454 | (r = sshbuf_froms(c, &data)) != 0) { |
| 455 | error("Unable to parse certificate options: %s", |
| 456 | ssh_err(r)); |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 457 | goto out; |
| 458 | } |
markus@openbsd.org | ae8b463 | 2015-01-14 10:30:34 +0000 | [diff] [blame] | 459 | debug3("found certificate option \"%.100s\" len %zu", |
| 460 | name, sshbuf_len(data)); |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 461 | found = 0; |
| 462 | if ((which & OPTIONS_EXTENSIONS) != 0) { |
| 463 | if (strcmp(name, "permit-X11-forwarding") == 0) { |
| 464 | *cert_no_x11_forwarding_flag = 0; |
| 465 | found = 1; |
| 466 | } else if (strcmp(name, |
| 467 | "permit-agent-forwarding") == 0) { |
| 468 | *cert_no_agent_forwarding_flag = 0; |
| 469 | found = 1; |
| 470 | } else if (strcmp(name, |
| 471 | "permit-port-forwarding") == 0) { |
| 472 | *cert_no_port_forwarding_flag = 0; |
| 473 | found = 1; |
| 474 | } else if (strcmp(name, "permit-pty") == 0) { |
| 475 | *cert_no_pty_flag = 0; |
| 476 | found = 1; |
| 477 | } else if (strcmp(name, "permit-user-rc") == 0) { |
| 478 | *cert_no_user_rc = 0; |
| 479 | found = 1; |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 480 | } |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 481 | } |
| 482 | if (!found && (which & OPTIONS_CRITICAL) != 0) { |
| 483 | if (strcmp(name, "force-command") == 0) { |
markus@openbsd.org | ae8b463 | 2015-01-14 10:30:34 +0000 | [diff] [blame] | 484 | if ((r = sshbuf_get_cstring(data, &command, |
| 485 | NULL)) != 0) { |
| 486 | error("Unable to parse \"%s\" " |
| 487 | "section: %s", name, ssh_err(r)); |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 488 | goto out; |
| 489 | } |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 490 | if (*cert_forced_command != NULL) { |
| 491 | error("Certificate has multiple " |
| 492 | "force-command options"); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 493 | free(command); |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 494 | goto out; |
| 495 | } |
| 496 | *cert_forced_command = command; |
| 497 | found = 1; |
Damien Miller | 4139657 | 2010-03-04 21:51:11 +1100 | [diff] [blame] | 498 | } |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 499 | if (strcmp(name, "source-address") == 0) { |
markus@openbsd.org | ae8b463 | 2015-01-14 10:30:34 +0000 | [diff] [blame] | 500 | if ((r = sshbuf_get_cstring(data, &allowed, |
| 501 | NULL)) != 0) { |
| 502 | error("Unable to parse \"%s\" " |
| 503 | "section: %s", name, ssh_err(r)); |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 504 | goto out; |
| 505 | } |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 506 | if ((*cert_source_address_done)++) { |
| 507 | error("Certificate has multiple " |
| 508 | "source-address options"); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 509 | free(allowed); |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 510 | goto out; |
| 511 | } |
| 512 | remote_ip = get_remote_ipaddr(); |
Damien Miller | bf25d11 | 2013-12-29 17:44:56 +1100 | [diff] [blame] | 513 | result = addr_match_cidr_list(remote_ip, |
| 514 | allowed); |
| 515 | free(allowed); |
| 516 | switch (result) { |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 517 | case 1: |
| 518 | /* accepted */ |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 519 | break; |
| 520 | case 0: |
| 521 | /* no match */ |
| 522 | logit("Authentication tried for %.100s " |
| 523 | "with valid certificate but not " |
| 524 | "from a permitted host " |
| 525 | "(ip=%.200s).", pw->pw_name, |
| 526 | remote_ip); |
| 527 | auth_debug_add("Your address '%.200s' " |
| 528 | "is not permitted to use this " |
| 529 | "certificate for login.", |
| 530 | remote_ip); |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 531 | goto out; |
| 532 | case -1: |
Damien Miller | bf25d11 | 2013-12-29 17:44:56 +1100 | [diff] [blame] | 533 | default: |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 534 | error("Certificate source-address " |
| 535 | "contents invalid"); |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 536 | goto out; |
| 537 | } |
| 538 | found = 1; |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 539 | } |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 540 | } |
| 541 | |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 542 | if (!found) { |
| 543 | if (crit) { |
| 544 | error("Certificate critical option \"%s\" " |
| 545 | "is not supported", name); |
| 546 | goto out; |
| 547 | } else { |
| 548 | logit("Certificate extension \"%s\" " |
| 549 | "is not supported", name); |
| 550 | } |
markus@openbsd.org | ae8b463 | 2015-01-14 10:30:34 +0000 | [diff] [blame] | 551 | } else if (sshbuf_len(data) != 0) { |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 552 | error("Certificate option \"%s\" corrupt " |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 553 | "(extra data)", name); |
| 554 | goto out; |
| 555 | } |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 556 | free(name); |
Damien Miller | ce98654 | 2013-07-18 16:12:44 +1000 | [diff] [blame] | 557 | name = NULL; |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 558 | } |
Damien Miller | 4e270b0 | 2010-04-16 15:56:21 +1000 | [diff] [blame] | 559 | /* successfully parsed all options */ |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 560 | ret = 0; |
| 561 | |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 562 | out: |
| 563 | if (ret != 0 && |
| 564 | cert_forced_command != NULL && |
| 565 | *cert_forced_command != NULL) { |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 566 | free(*cert_forced_command); |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 567 | *cert_forced_command = NULL; |
| 568 | } |
| 569 | if (name != NULL) |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 570 | free(name); |
markus@openbsd.org | ae8b463 | 2015-01-14 10:30:34 +0000 | [diff] [blame] | 571 | sshbuf_free(data); |
| 572 | sshbuf_free(c); |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 573 | return ret; |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | * Set options from critical certificate options. These supersede user key |
| 578 | * options so this must be called after auth_parse_options(). |
| 579 | */ |
| 580 | int |
markus@openbsd.org | ae8b463 | 2015-01-14 10:30:34 +0000 | [diff] [blame] | 581 | auth_cert_options(struct sshkey *k, struct passwd *pw) |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 582 | { |
| 583 | int cert_no_port_forwarding_flag = 1; |
| 584 | int cert_no_agent_forwarding_flag = 1; |
| 585 | int cert_no_x11_forwarding_flag = 1; |
| 586 | int cert_no_pty_flag = 1; |
| 587 | int cert_no_user_rc = 1; |
| 588 | char *cert_forced_command = NULL; |
| 589 | int cert_source_address_done = 0; |
| 590 | |
djm@openbsd.org | c28fc62 | 2015-07-03 03:43:18 +0000 | [diff] [blame] | 591 | /* Separate options and extensions for v01 certs */ |
| 592 | if (parse_option_list(k->cert->critical, pw, |
| 593 | OPTIONS_CRITICAL, 1, NULL, NULL, NULL, NULL, NULL, |
| 594 | &cert_forced_command, |
| 595 | &cert_source_address_done) == -1) |
| 596 | return -1; |
| 597 | if (parse_option_list(k->cert->extensions, pw, |
| 598 | OPTIONS_EXTENSIONS, 0, |
| 599 | &cert_no_port_forwarding_flag, |
| 600 | &cert_no_agent_forwarding_flag, |
| 601 | &cert_no_x11_forwarding_flag, |
| 602 | &cert_no_pty_flag, |
| 603 | &cert_no_user_rc, |
| 604 | NULL, NULL) == -1) |
| 605 | return -1; |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 606 | |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 607 | no_port_forwarding_flag |= cert_no_port_forwarding_flag; |
| 608 | no_agent_forwarding_flag |= cert_no_agent_forwarding_flag; |
| 609 | no_x11_forwarding_flag |= cert_no_x11_forwarding_flag; |
| 610 | no_pty_flag |= cert_no_pty_flag; |
| 611 | no_user_rc |= cert_no_user_rc; |
| 612 | /* CA-specified forced command supersedes key option */ |
| 613 | if (cert_forced_command != NULL) { |
| 614 | if (forced_command != NULL) |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 615 | free(forced_command); |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 616 | forced_command = cert_forced_command; |
| 617 | } |
Damien Miller | d0e4a8e | 2010-05-21 14:58:32 +1000 | [diff] [blame] | 618 | return 0; |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 619 | } |
| 620 | |