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.14 2001/03/13 17:34:42 markus Exp $");
20 #include "auth-options.h"
23 /* Flags set authorized_keys flags */
24 int no_port_forwarding_flag = 0;
25 int no_agent_forwarding_flag = 0;
26 int no_x11_forwarding_flag = 0;
29 /* "command=" option. */
30 char *forced_command = NULL;
32 /* "environment=" options. */
33 struct envstring *custom_environment = NULL;
35 extern ServerOptions options;
38 auth_clear_options(void)
40 no_agent_forwarding_flag = 0;
41 no_port_forwarding_flag = 0;
43 no_x11_forwarding_flag = 0;
44 while (custom_environment) {
45 struct envstring *ce = custom_environment;
46 custom_environment = ce->next;
51 xfree(forced_command);
52 forced_command = NULL;
57 * return 1 if access is granted, 0 if not.
58 * side effect: sets key option flags
61 auth_parse_options(struct passwd *pw, char *opts, char *file, u_long linenum)
71 while (*opts && *opts != ' ' && *opts != '\t') {
72 cp = "no-port-forwarding";
73 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
74 packet_send_debug("Port forwarding disabled.");
75 no_port_forwarding_flag = 1;
79 cp = "no-agent-forwarding";
80 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
81 packet_send_debug("Agent forwarding disabled.");
82 no_agent_forwarding_flag = 1;
86 cp = "no-X11-forwarding";
87 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
88 packet_send_debug("X11 forwarding disabled.");
89 no_x11_forwarding_flag = 1;
94 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
95 packet_send_debug("Pty allocation disabled.");
101 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
104 forced_command = xmalloc(strlen(opts) + 1);
109 if (*opts == '\\' && opts[1] == '"') {
111 forced_command[i++] = '"';
114 forced_command[i++] = *opts++;
117 debug("%.100s, line %lu: missing end quote",
119 packet_send_debug("%.100s, line %lu: missing end quote",
121 xfree(forced_command);
122 forced_command = NULL;
125 forced_command[i] = 0;
126 packet_send_debug("Forced command: %.900s", forced_command);
130 cp = "environment=\"";
131 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
134 struct envstring *new_envstring;
136 s = xmalloc(strlen(opts) + 1);
141 if (*opts == '\\' && opts[1] == '"') {
149 debug("%.100s, line %lu: missing end quote",
151 packet_send_debug("%.100s, line %lu: missing end quote",
157 packet_send_debug("Adding to environment: %.900s", s);
158 debug("Adding to environment: %.900s", s);
160 new_envstring = xmalloc(sizeof(struct envstring));
161 new_envstring->s = s;
162 new_envstring->next = custom_environment;
163 custom_environment = new_envstring;
167 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
169 const char *remote_ip = get_remote_ipaddr();
170 const char *remote_host = get_canonical_hostname(
171 options.reverse_mapping_check);
172 char *patterns = xmalloc(strlen(opts) + 1);
179 if (*opts == '\\' && opts[1] == '"') {
184 patterns[i++] = *opts++;
187 debug("%.100s, line %lu: missing end quote",
189 packet_send_debug("%.100s, line %lu: missing end quote",
197 * Deny access if we get a negative
198 * match for the hostname or the ip
199 * or if we get not match at all
201 mname = match_hostname(remote_host, patterns,
203 mip = match_hostname(remote_ip, patterns,
206 if (mname == -1 || mip == -1 ||
207 (mname != 1 && mip != 1)) {
208 log("Authentication tried for %.100s with "
209 "correct key but not from a permitted "
210 "host (host=%.200s, ip=%.200s).",
211 pw->pw_name, remote_host, remote_ip);
212 packet_send_debug("Your host '%.200s' is not "
213 "permitted to use this key for login.",
218 /* Host name matches. */
223 * Skip the comma, and move to the next option
224 * (or break out if there are no more).
227 fatal("Bugs in auth-options.c option processing.");
228 if (*opts == ' ' || *opts == '\t')
229 break; /* End of options. */
233 /* Process the next option. */
239 log("Bad options in %.100s file, line %lu: %.50s",
240 file, linenum, opts);
241 packet_send_debug("Bad options in %.100s file, line %lu: %.50s",
242 file, linenum, opts);