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.11 2001/01/21 19:05:41 markus Exp $");
20 #include "auth-options.h"
22 /* Flags set authorized_keys flags */
23 int no_port_forwarding_flag = 0;
24 int no_agent_forwarding_flag = 0;
25 int no_x11_forwarding_flag = 0;
28 /* "command=" option. */
29 char *forced_command = NULL;
31 /* "environment=" options. */
32 struct envstring *custom_environment = NULL;
35 auth_clear_options(void)
37 no_agent_forwarding_flag = 0;
38 no_port_forwarding_flag = 0;
40 no_x11_forwarding_flag = 0;
41 while (custom_environment) {
42 struct envstring *ce = custom_environment;
43 custom_environment = ce->next;
48 xfree(forced_command);
49 forced_command = NULL;
54 * return 1 if access is granted, 0 if not.
55 * side effect: sets key option flags
58 auth_parse_options(struct passwd *pw, char *options, char *file, u_long linenum)
67 while (*options && *options != ' ' && *options != '\t') {
68 cp = "no-port-forwarding";
69 if (strncasecmp(options, cp, strlen(cp)) == 0) {
70 packet_send_debug("Port forwarding disabled.");
71 no_port_forwarding_flag = 1;
72 options += strlen(cp);
75 cp = "no-agent-forwarding";
76 if (strncasecmp(options, cp, strlen(cp)) == 0) {
77 packet_send_debug("Agent forwarding disabled.");
78 no_agent_forwarding_flag = 1;
79 options += strlen(cp);
82 cp = "no-X11-forwarding";
83 if (strncasecmp(options, cp, strlen(cp)) == 0) {
84 packet_send_debug("X11 forwarding disabled.");
85 no_x11_forwarding_flag = 1;
86 options += strlen(cp);
90 if (strncasecmp(options, cp, strlen(cp)) == 0) {
91 packet_send_debug("Pty allocation disabled.");
93 options += strlen(cp);
97 if (strncasecmp(options, cp, strlen(cp)) == 0) {
99 options += strlen(cp);
100 forced_command = xmalloc(strlen(options) + 1);
105 if (*options == '\\' && options[1] == '"') {
107 forced_command[i++] = '"';
110 forced_command[i++] = *options++;
113 debug("%.100s, line %lu: missing end quote",
115 packet_send_debug("%.100s, line %lu: missing end quote",
119 forced_command[i] = 0;
120 packet_send_debug("Forced command: %.900s", forced_command);
124 cp = "environment=\"";
125 if (strncasecmp(options, cp, strlen(cp)) == 0) {
128 struct envstring *new_envstring;
129 options += strlen(cp);
130 s = xmalloc(strlen(options) + 1);
135 if (*options == '\\' && options[1] == '"') {
143 debug("%.100s, line %lu: missing end quote",
145 packet_send_debug("%.100s, line %lu: missing end quote",
150 packet_send_debug("Adding to environment: %.900s", s);
151 debug("Adding to environment: %.900s", s);
153 new_envstring = xmalloc(sizeof(struct envstring));
154 new_envstring->s = s;
155 new_envstring->next = custom_environment;
156 custom_environment = new_envstring;
160 if (strncasecmp(options, cp, strlen(cp)) == 0) {
162 char *patterns = xmalloc(strlen(options) + 1);
164 options += strlen(cp);
169 if (*options == '\\' && options[1] == '"') {
174 patterns[i++] = *options++;
177 debug("%.100s, line %lu: missing end quote",
179 packet_send_debug("%.100s, line %lu: missing end quote",
186 * Deny access if we get a negative
187 * match for the hostname or the ip
188 * or if we get not match at all
190 mname = match_hostname(get_canonical_hostname(),
191 patterns, strlen(patterns));
192 mip = match_hostname(get_remote_ipaddr(),
193 patterns, strlen(patterns));
195 if (mname == -1 || mip == -1 ||
196 (mname != 1 && mip != 1)) {
197 log("Authentication tried for %.100s with correct key but not from a permitted host (host=%.200s, ip=%.200s).",
198 pw->pw_name, get_canonical_hostname(),
199 get_remote_ipaddr());
200 packet_send_debug("Your host '%.200s' is not permitted to use this key for login.",
201 get_canonical_hostname());
205 /* Host name matches. */
210 * Skip the comma, and move to the next option
211 * (or break out if there are no more).
214 fatal("Bugs in auth-options.c option processing.");
215 if (*options == ' ' || *options == '\t')
216 break; /* End of options. */
220 /* Process the next option. */
226 log("Bad options in %.100s file, line %lu: %.50s",
227 file, linenum, options);
228 packet_send_debug("Bad options in %.100s file, line %lu: %.50s",
229 file, linenum, options);