2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * As far as I am concerned, the code I have written for this software
6 * can be used freely for any purpose. Any derived versions of this
7 * software must be clearly marked as such, and if the derived work is
8 * incompatible with the protocol description in the RFC file, it must be
9 * called by a name other than "ssh" or "Secure Shell".
13 RCSID("$OpenBSD: auth-options.c,v 1.19 2001/06/24 05:25:09 markus Exp $");
21 #include "auth-options.h"
24 /* Flags set authorized_keys flags */
25 int no_port_forwarding_flag = 0;
26 int no_agent_forwarding_flag = 0;
27 int no_x11_forwarding_flag = 0;
30 /* "command=" option. */
31 char *forced_command = NULL;
33 /* "environment=" options. */
34 struct envstring *custom_environment = NULL;
36 extern ServerOptions options;
39 auth_clear_options(void)
41 no_agent_forwarding_flag = 0;
42 no_port_forwarding_flag = 0;
44 no_x11_forwarding_flag = 0;
45 while (custom_environment) {
46 struct envstring *ce = custom_environment;
47 custom_environment = ce->next;
52 xfree(forced_command);
53 forced_command = NULL;
55 channel_clear_permitted_opens();
59 * return 1 if access is granted, 0 if not.
60 * side effect: sets key option flags
63 auth_parse_options(struct passwd *pw, char *opts, char *file, u_long linenum)
74 while (*opts && *opts != ' ' && *opts != '\t') {
75 cp = "no-port-forwarding";
76 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
77 packet_send_debug("Port forwarding disabled.");
78 no_port_forwarding_flag = 1;
82 cp = "no-agent-forwarding";
83 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
84 packet_send_debug("Agent forwarding disabled.");
85 no_agent_forwarding_flag = 1;
89 cp = "no-X11-forwarding";
90 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
91 packet_send_debug("X11 forwarding disabled.");
92 no_x11_forwarding_flag = 1;
97 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
98 packet_send_debug("Pty allocation disabled.");
104 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
106 forced_command = xmalloc(strlen(opts) + 1);
111 if (*opts == '\\' && opts[1] == '"') {
113 forced_command[i++] = '"';
116 forced_command[i++] = *opts++;
119 debug("%.100s, line %lu: missing end quote",
121 packet_send_debug("%.100s, line %lu: missing end quote",
123 xfree(forced_command);
124 forced_command = NULL;
127 forced_command[i] = 0;
128 packet_send_debug("Forced command: %.900s", forced_command);
132 cp = "environment=\"";
133 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
135 struct envstring *new_envstring;
138 s = xmalloc(strlen(opts) + 1);
143 if (*opts == '\\' && opts[1] == '"') {
151 debug("%.100s, line %lu: missing end quote",
153 packet_send_debug("%.100s, line %lu: missing end quote",
159 packet_send_debug("Adding to environment: %.900s", s);
160 debug("Adding to environment: %.900s", s);
162 new_envstring = xmalloc(sizeof(struct envstring));
163 new_envstring->s = s;
164 new_envstring->next = custom_environment;
165 custom_environment = new_envstring;
169 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
170 const char *remote_ip = get_remote_ipaddr();
171 const char *remote_host = get_canonical_hostname(
172 options.reverse_mapping_check);
173 char *patterns = xmalloc(strlen(opts) + 1);
180 if (*opts == '\\' && opts[1] == '"') {
185 patterns[i++] = *opts++;
188 debug("%.100s, line %lu: missing end quote",
190 packet_send_debug("%.100s, line %lu: missing end quote",
197 if (match_host_and_ip(remote_host, remote_ip,
200 log("Authentication tried for %.100s with "
201 "correct key but not from a permitted "
202 "host (host=%.200s, ip=%.200s).",
203 pw->pw_name, remote_host, remote_ip);
204 packet_send_debug("Your host '%.200s' is not "
205 "permitted to use this key for login.",
211 /* Host name matches. */
214 cp = "permitopen=\"";
215 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
218 char *patterns = xmalloc(strlen(opts) + 1);
225 if (*opts == '\\' && opts[1] == '"') {
230 patterns[i++] = *opts++;
233 debug("%.100s, line %lu: missing end quote",
235 packet_send_debug("%.100s, line %lu: missing end quote",
242 c = strchr(patterns, ':');
244 debug("%.100s, line %lu: permitopen: missing colon <%.100s>",
245 file, linenum, patterns);
246 packet_send_debug("%.100s, line %lu: missing colon",
253 port = strtol(c, &ep, 0);
255 debug("%.100s, line %lu: permitopen: missing port <%.100s>",
256 file, linenum, patterns);
257 packet_send_debug("%.100s, line %lu: missing port",
262 if (options.allow_tcp_forwarding)
263 channel_add_permitted_opens(patterns, port);
269 * Skip the comma, and move to the next option
270 * (or break out if there are no more).
273 fatal("Bugs in auth-options.c option processing.");
274 if (*opts == ' ' || *opts == '\t')
275 break; /* End of options. */
279 /* Process the next option. */
285 log("Bad options in %.100s file, line %lu: %.50s",
286 file, linenum, opts);
287 packet_send_debug("Bad options in %.100s file, line %lu: %.50s",
288 file, linenum, opts);