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