Damien Miller | 95e8095 | 2008-03-27 11:03:05 +1100 | [diff] [blame] | 1 | /* $OpenBSD: auth-options.c,v 1.41 2008/03/26 21:28:14 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 | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 23 | #include "xmalloc.h" |
| 24 | #include "match.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 25 | #include "log.h" |
| 26 | #include "canohost.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 27 | #include "buffer.h" |
Ben Lindstrom | c763767 | 2001-06-09 00:36:26 +0000 | [diff] [blame] | 28 | #include "channels.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 29 | #include "auth-options.h" |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 30 | #include "servconf.h" |
Ben Lindstrom | d71ba57 | 2001-09-12 18:03:31 +0000 | [diff] [blame] | 31 | #include "misc.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 32 | #include "key.h" |
| 33 | #include "hostfile.h" |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 34 | #include "auth.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 35 | #ifdef GSSAPI |
| 36 | #include "ssh-gss.h" |
| 37 | #endif |
| 38 | #include "monitor_wrap.h" |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 39 | |
| 40 | /* Flags set authorized_keys flags */ |
| 41 | int no_port_forwarding_flag = 0; |
| 42 | int no_agent_forwarding_flag = 0; |
| 43 | int no_x11_forwarding_flag = 0; |
| 44 | int no_pty_flag = 0; |
Damien Miller | 95e8095 | 2008-03-27 11:03:05 +1100 | [diff] [blame] | 45 | int no_user_rc = 0; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 46 | |
| 47 | /* "command=" option. */ |
| 48 | char *forced_command = NULL; |
| 49 | |
| 50 | /* "environment=" options. */ |
| 51 | struct envstring *custom_environment = NULL; |
| 52 | |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 53 | /* "tunnel=" option. */ |
| 54 | int forced_tun_device = -1; |
| 55 | |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 56 | extern ServerOptions options; |
| 57 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 58 | void |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 59 | auth_clear_options(void) |
| 60 | { |
| 61 | no_agent_forwarding_flag = 0; |
| 62 | no_port_forwarding_flag = 0; |
| 63 | no_pty_flag = 0; |
| 64 | no_x11_forwarding_flag = 0; |
Damien Miller | 95e8095 | 2008-03-27 11:03:05 +1100 | [diff] [blame] | 65 | no_user_rc = 0; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 66 | while (custom_environment) { |
| 67 | struct envstring *ce = custom_environment; |
| 68 | custom_environment = ce->next; |
| 69 | xfree(ce->s); |
| 70 | xfree(ce); |
| 71 | } |
| 72 | if (forced_command) { |
| 73 | xfree(forced_command); |
| 74 | forced_command = NULL; |
| 75 | } |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 76 | forced_tun_device = -1; |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 77 | channel_clear_permitted_opens(); |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 78 | auth_debug_reset(); |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 79 | } |
| 80 | |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 81 | /* |
| 82 | * return 1 if access is granted, 0 if not. |
| 83 | * side effect: sets key option flags |
| 84 | */ |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 85 | int |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 86 | 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] | 87 | { |
| 88 | const char *cp; |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 89 | int i; |
Damien Miller | 874d77b | 2000-10-14 16:23:11 +1100 | [diff] [blame] | 90 | |
| 91 | /* reset options */ |
| 92 | auth_clear_options(); |
| 93 | |
Ben Lindstrom | 36d7bd0 | 2001-02-10 22:27:19 +0000 | [diff] [blame] | 94 | if (!opts) |
| 95 | return 1; |
| 96 | |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 97 | while (*opts && *opts != ' ' && *opts != '\t') { |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 98 | cp = "no-port-forwarding"; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 99 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 100 | auth_debug_add("Port forwarding disabled."); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 101 | no_port_forwarding_flag = 1; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 102 | opts += strlen(cp); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 103 | goto next_option; |
| 104 | } |
| 105 | cp = "no-agent-forwarding"; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 106 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 107 | auth_debug_add("Agent forwarding disabled."); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 108 | no_agent_forwarding_flag = 1; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 109 | opts += strlen(cp); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 110 | goto next_option; |
| 111 | } |
| 112 | cp = "no-X11-forwarding"; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 113 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 114 | auth_debug_add("X11 forwarding disabled."); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 115 | no_x11_forwarding_flag = 1; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 116 | opts += strlen(cp); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 117 | goto next_option; |
| 118 | } |
| 119 | cp = "no-pty"; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 120 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 121 | auth_debug_add("Pty allocation disabled."); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 122 | no_pty_flag = 1; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 123 | opts += strlen(cp); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 124 | goto next_option; |
| 125 | } |
Damien Miller | 95e8095 | 2008-03-27 11:03:05 +1100 | [diff] [blame] | 126 | cp = "no-user-rc"; |
| 127 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
| 128 | auth_debug_add("User rc file execution disabled."); |
| 129 | no_user_rc = 1; |
| 130 | opts += strlen(cp); |
| 131 | goto next_option; |
| 132 | } |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 133 | cp = "command=\""; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 134 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 135 | opts += strlen(cp); |
| 136 | forced_command = xmalloc(strlen(opts) + 1); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 137 | i = 0; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 138 | while (*opts) { |
| 139 | if (*opts == '"') |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 140 | break; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 141 | if (*opts == '\\' && opts[1] == '"') { |
| 142 | opts += 2; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 143 | forced_command[i++] = '"'; |
| 144 | continue; |
| 145 | } |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 146 | forced_command[i++] = *opts++; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 147 | } |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 148 | if (!*opts) { |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 149 | debug("%.100s, line %lu: missing end quote", |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 150 | file, linenum); |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 151 | auth_debug_add("%.100s, line %lu: missing end quote", |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 152 | file, linenum); |
Damien Miller | 056ddf7 | 2001-03-14 10:15:20 +1100 | [diff] [blame] | 153 | xfree(forced_command); |
| 154 | forced_command = NULL; |
| 155 | goto bad_option; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 156 | } |
Damien Miller | 9829926 | 2006-07-24 14:01:43 +1000 | [diff] [blame] | 157 | forced_command[i] = '\0'; |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 158 | auth_debug_add("Forced command: %.900s", forced_command); |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 159 | opts++; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 160 | goto next_option; |
| 161 | } |
| 162 | cp = "environment=\""; |
Ben Lindstrom | 5d860f0 | 2002-08-01 01:28:38 +0000 | [diff] [blame] | 163 | if (options.permit_user_env && |
| 164 | strncasecmp(opts, cp, strlen(cp)) == 0) { |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 165 | char *s; |
| 166 | struct envstring *new_envstring; |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 167 | |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 168 | opts += strlen(cp); |
| 169 | s = xmalloc(strlen(opts) + 1); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 170 | i = 0; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 171 | while (*opts) { |
| 172 | if (*opts == '"') |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 173 | break; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 174 | if (*opts == '\\' && opts[1] == '"') { |
| 175 | opts += 2; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 176 | s[i++] = '"'; |
| 177 | continue; |
| 178 | } |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 179 | s[i++] = *opts++; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 180 | } |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 181 | if (!*opts) { |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 182 | debug("%.100s, line %lu: missing end quote", |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 183 | file, linenum); |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 184 | auth_debug_add("%.100s, line %lu: missing end quote", |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 185 | file, linenum); |
Damien Miller | 056ddf7 | 2001-03-14 10:15:20 +1100 | [diff] [blame] | 186 | xfree(s); |
| 187 | goto bad_option; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 188 | } |
Damien Miller | 9829926 | 2006-07-24 14:01:43 +1000 | [diff] [blame] | 189 | s[i] = '\0'; |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 190 | auth_debug_add("Adding to environment: %.900s", s); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 191 | debug("Adding to environment: %.900s", s); |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 192 | opts++; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 193 | new_envstring = xmalloc(sizeof(struct envstring)); |
| 194 | new_envstring->s = s; |
| 195 | new_envstring->next = custom_environment; |
| 196 | custom_environment = new_envstring; |
| 197 | goto next_option; |
| 198 | } |
| 199 | cp = "from=\""; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 200 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 201 | const char *remote_ip = get_remote_ipaddr(); |
| 202 | const char *remote_host = get_canonical_hostname( |
Damien Miller | 3a961dc | 2003-06-03 10:25:48 +1000 | [diff] [blame] | 203 | options.use_dns); |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 204 | char *patterns = xmalloc(strlen(opts) + 1); |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 205 | |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 206 | opts += strlen(cp); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 207 | i = 0; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 208 | while (*opts) { |
| 209 | if (*opts == '"') |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 210 | break; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 211 | if (*opts == '\\' && opts[1] == '"') { |
| 212 | opts += 2; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 213 | patterns[i++] = '"'; |
| 214 | continue; |
| 215 | } |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 216 | patterns[i++] = *opts++; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 217 | } |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 218 | if (!*opts) { |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 219 | debug("%.100s, line %lu: missing end quote", |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 220 | file, linenum); |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 221 | auth_debug_add("%.100s, line %lu: missing end quote", |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 222 | file, linenum); |
Damien Miller | 056ddf7 | 2001-03-14 10:15:20 +1100 | [diff] [blame] | 223 | xfree(patterns); |
| 224 | goto bad_option; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 225 | } |
Damien Miller | 9829926 | 2006-07-24 14:01:43 +1000 | [diff] [blame] | 226 | patterns[i] = '\0'; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 227 | opts++; |
Ben Lindstrom | f0c5029 | 2001-06-25 05:17:53 +0000 | [diff] [blame] | 228 | if (match_host_and_ip(remote_host, remote_ip, |
| 229 | patterns) != 1) { |
| 230 | xfree(patterns); |
Damien Miller | 996acd2 | 2003-04-09 20:59:48 +1000 | [diff] [blame] | 231 | logit("Authentication tried for %.100s with " |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 232 | "correct key but not from a permitted " |
| 233 | "host (host=%.200s, ip=%.200s).", |
| 234 | pw->pw_name, remote_host, remote_ip); |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 235 | auth_debug_add("Your host '%.200s' is not " |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 236 | "permitted to use this key for login.", |
| 237 | remote_host); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 238 | /* deny access */ |
| 239 | return 0; |
| 240 | } |
Ben Lindstrom | f0c5029 | 2001-06-25 05:17:53 +0000 | [diff] [blame] | 241 | xfree(patterns); |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 242 | /* Host name matches. */ |
| 243 | goto next_option; |
| 244 | } |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 245 | cp = "permitopen=\""; |
| 246 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 247 | char *host, *p; |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 248 | u_short port; |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 249 | char *patterns = xmalloc(strlen(opts) + 1); |
| 250 | |
| 251 | opts += strlen(cp); |
| 252 | i = 0; |
| 253 | while (*opts) { |
| 254 | if (*opts == '"') |
| 255 | break; |
| 256 | if (*opts == '\\' && opts[1] == '"') { |
| 257 | opts += 2; |
| 258 | patterns[i++] = '"'; |
| 259 | continue; |
| 260 | } |
| 261 | patterns[i++] = *opts++; |
| 262 | } |
| 263 | if (!*opts) { |
| 264 | debug("%.100s, line %lu: missing end quote", |
| 265 | file, linenum); |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 266 | auth_debug_add("%.100s, line %lu: missing " |
| 267 | "end quote", file, linenum); |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 268 | xfree(patterns); |
| 269 | goto bad_option; |
| 270 | } |
Damien Miller | 9829926 | 2006-07-24 14:01:43 +1000 | [diff] [blame] | 271 | patterns[i] = '\0'; |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 272 | opts++; |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 273 | p = patterns; |
| 274 | host = hpdelim(&p); |
| 275 | if (host == NULL || strlen(host) >= NI_MAXHOST) { |
| 276 | debug("%.100s, line %lu: Bad permitopen " |
Darren Tucker | 90b9e02 | 2005-03-14 23:08:50 +1100 | [diff] [blame] | 277 | "specification <%.100s>", file, linenum, |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 278 | patterns); |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 279 | auth_debug_add("%.100s, line %lu: " |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 280 | "Bad permitopen specification", file, |
| 281 | linenum); |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 282 | xfree(patterns); |
| 283 | goto bad_option; |
| 284 | } |
Darren Tucker | 47eede7 | 2005-03-14 23:08:12 +1100 | [diff] [blame] | 285 | host = cleanhostname(host); |
| 286 | if (p == NULL || (port = a2port(p)) == 0) { |
Damien Miller | f91ee4c | 2005-03-01 21:24:33 +1100 | [diff] [blame] | 287 | debug("%.100s, line %lu: Bad permitopen port " |
| 288 | "<%.100s>", file, linenum, p ? p : ""); |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 289 | auth_debug_add("%.100s, line %lu: " |
Ben Lindstrom | d71ba57 | 2001-09-12 18:03:31 +0000 | [diff] [blame] | 290 | "Bad permitopen port", file, linenum); |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 291 | xfree(patterns); |
| 292 | goto bad_option; |
| 293 | } |
Ben Lindstrom | 2d70f98 | 2001-03-19 00:13:46 +0000 | [diff] [blame] | 294 | if (options.allow_tcp_forwarding) |
Ben Lindstrom | d71ba57 | 2001-09-12 18:03:31 +0000 | [diff] [blame] | 295 | channel_add_permitted_opens(host, port); |
Ben Lindstrom | 7bb8b49 | 2001-03-17 00:47:54 +0000 | [diff] [blame] | 296 | xfree(patterns); |
| 297 | goto next_option; |
| 298 | } |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 299 | cp = "tunnel=\""; |
| 300 | if (strncasecmp(opts, cp, strlen(cp)) == 0) { |
| 301 | char *tun = NULL; |
| 302 | opts += strlen(cp); |
| 303 | tun = xmalloc(strlen(opts) + 1); |
| 304 | i = 0; |
| 305 | while (*opts) { |
| 306 | if (*opts == '"') |
| 307 | break; |
| 308 | tun[i++] = *opts++; |
| 309 | } |
| 310 | if (!*opts) { |
| 311 | debug("%.100s, line %lu: missing end quote", |
| 312 | file, linenum); |
| 313 | auth_debug_add("%.100s, line %lu: missing end quote", |
| 314 | file, linenum); |
| 315 | xfree(tun); |
| 316 | forced_tun_device = -1; |
| 317 | goto bad_option; |
| 318 | } |
Damien Miller | 9829926 | 2006-07-24 14:01:43 +1000 | [diff] [blame] | 319 | tun[i] = '\0'; |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 320 | forced_tun_device = a2tun(tun, NULL); |
| 321 | xfree(tun); |
Damien Miller | 7b58e80 | 2005-12-13 19:33:19 +1100 | [diff] [blame] | 322 | if (forced_tun_device == SSH_TUNID_ERR) { |
Damien Miller | d27b947 | 2005-12-13 19:29:02 +1100 | [diff] [blame] | 323 | debug("%.100s, line %lu: invalid tun device", |
| 324 | file, linenum); |
| 325 | auth_debug_add("%.100s, line %lu: invalid tun device", |
| 326 | file, linenum); |
| 327 | forced_tun_device = -1; |
| 328 | goto bad_option; |
| 329 | } |
| 330 | auth_debug_add("Forced tun device: %d", forced_tun_device); |
| 331 | opts++; |
| 332 | goto next_option; |
| 333 | } |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 334 | next_option: |
| 335 | /* |
| 336 | * Skip the comma, and move to the next option |
| 337 | * (or break out if there are no more). |
| 338 | */ |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 339 | if (!*opts) |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 340 | fatal("Bugs in auth-options.c option processing."); |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 341 | if (*opts == ' ' || *opts == '\t') |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 342 | break; /* End of options. */ |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 343 | if (*opts != ',') |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 344 | goto bad_option; |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 345 | opts++; |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 346 | /* Process the next option. */ |
| 347 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 348 | |
| 349 | if (!use_privsep) |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 350 | auth_debug_send(); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 351 | |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 352 | /* grant access */ |
| 353 | return 1; |
| 354 | |
| 355 | bad_option: |
Damien Miller | 996acd2 | 2003-04-09 20:59:48 +1000 | [diff] [blame] | 356 | logit("Bad options in %.100s file, line %lu: %.50s", |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 357 | file, linenum, opts); |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 358 | auth_debug_add("Bad options in %.100s file, line %lu: %.50s", |
Damien Miller | 3380426 | 2001-02-04 23:20:18 +1100 | [diff] [blame] | 359 | file, linenum, opts); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 360 | |
| 361 | if (!use_privsep) |
Ben Lindstrom | a574cda | 2002-05-15 16:16:14 +0000 | [diff] [blame] | 362 | auth_debug_send(); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 363 | |
Damien Miller | f6d9e22 | 2000-06-18 14:50:44 +1000 | [diff] [blame] | 364 | /* deny access */ |
| 365 | return 0; |
| 366 | } |