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.12 2001/02/03 10:08:36 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)
70 while (*opts && *opts != ' ' && *opts != '\t') {
71 cp = "no-port-forwarding";
72 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
73 packet_send_debug("Port forwarding disabled.");
74 no_port_forwarding_flag = 1;
78 cp = "no-agent-forwarding";
79 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
80 packet_send_debug("Agent forwarding disabled.");
81 no_agent_forwarding_flag = 1;
85 cp = "no-X11-forwarding";
86 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
87 packet_send_debug("X11 forwarding disabled.");
88 no_x11_forwarding_flag = 1;
93 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
94 packet_send_debug("Pty allocation disabled.");
100 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
103 forced_command = xmalloc(strlen(opts) + 1);
108 if (*opts == '\\' && opts[1] == '"') {
110 forced_command[i++] = '"';
113 forced_command[i++] = *opts++;
116 debug("%.100s, line %lu: missing end quote",
118 packet_send_debug("%.100s, line %lu: missing end quote",
122 forced_command[i] = 0;
123 packet_send_debug("Forced command: %.900s", forced_command);
127 cp = "environment=\"";
128 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
131 struct envstring *new_envstring;
133 s = xmalloc(strlen(opts) + 1);
138 if (*opts == '\\' && opts[1] == '"') {
146 debug("%.100s, line %lu: missing end quote",
148 packet_send_debug("%.100s, line %lu: missing end quote",
153 packet_send_debug("Adding to environment: %.900s", s);
154 debug("Adding to environment: %.900s", s);
156 new_envstring = xmalloc(sizeof(struct envstring));
157 new_envstring->s = s;
158 new_envstring->next = custom_environment;
159 custom_environment = new_envstring;
163 if (strncasecmp(opts, cp, strlen(cp)) == 0) {
165 const char *remote_ip = get_remote_ipaddr();
166 const char *remote_host = get_canonical_hostname(
167 options.reverse_mapping_check);
168 char *patterns = xmalloc(strlen(opts) + 1);
175 if (*opts == '\\' && opts[1] == '"') {
180 patterns[i++] = *opts++;
183 debug("%.100s, line %lu: missing end quote",
185 packet_send_debug("%.100s, line %lu: missing end quote",
192 * Deny access if we get a negative
193 * match for the hostname or the ip
194 * or if we get not match at all
196 mname = match_hostname(remote_host, patterns,
198 mip = match_hostname(remote_ip, patterns,
201 if (mname == -1 || mip == -1 ||
202 (mname != 1 && mip != 1)) {
203 log("Authentication tried for %.100s with "
204 "correct key but not from a permitted "
205 "host (host=%.200s, ip=%.200s).",
206 pw->pw_name, remote_host, remote_ip);
207 packet_send_debug("Your host '%.200s' is not "
208 "permitted to use this key for login.",
213 /* Host name matches. */
218 * Skip the comma, and move to the next option
219 * (or break out if there are no more).
222 fatal("Bugs in auth-options.c option processing.");
223 if (*opts == ' ' || *opts == '\t')
224 break; /* End of options. */
228 /* Process the next option. */
234 log("Bad options in %.100s file, line %lu: %.50s",
235 file, linenum, opts);
236 packet_send_debug("Bad options in %.100s file, line %lu: %.50s",
237 file, linenum, opts);