2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * RSA-based authentication. This code determines whether to admit a login
6 * based on RSA authentication. This file also contains functions to check
7 * validity of the host key.
9 * As far as I am concerned, the code I have written for this software
10 * can be used freely for any purpose. Any derived versions of this
11 * software must be clearly marked as such, and if the derived work is
12 * incompatible with the protocol description in the RFC file, it must be
13 * called by a name other than "ssh" or "Secure Shell".
17 RCSID("$OpenBSD: auth-options.c,v 1.4 2000/09/07 21:13:36 markus Exp $");
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 /* return 1 if access is granted, 0 if not. side effect: sets key option flags */
38 auth_parse_options(struct passwd *pw, char *options, unsigned long linenum)
43 while (*options && *options != ' ' && *options != '\t') {
44 cp = "no-port-forwarding";
45 if (strncmp(options, cp, strlen(cp)) == 0) {
46 packet_send_debug("Port forwarding disabled.");
47 no_port_forwarding_flag = 1;
48 options += strlen(cp);
51 cp = "no-agent-forwarding";
52 if (strncmp(options, cp, strlen(cp)) == 0) {
53 packet_send_debug("Agent forwarding disabled.");
54 no_agent_forwarding_flag = 1;
55 options += strlen(cp);
58 cp = "no-X11-forwarding";
59 if (strncmp(options, cp, strlen(cp)) == 0) {
60 packet_send_debug("X11 forwarding disabled.");
61 no_x11_forwarding_flag = 1;
62 options += strlen(cp);
66 if (strncmp(options, cp, strlen(cp)) == 0) {
67 packet_send_debug("Pty allocation disabled.");
69 options += strlen(cp);
73 if (strncmp(options, cp, strlen(cp)) == 0) {
75 options += strlen(cp);
76 forced_command = xmalloc(strlen(options) + 1);
81 if (*options == '\\' && options[1] == '"') {
83 forced_command[i++] = '"';
86 forced_command[i++] = *options++;
89 debug("%.100s, line %lu: missing end quote",
90 SSH_USER_PERMITTED_KEYS, linenum);
91 packet_send_debug("%.100s, line %lu: missing end quote",
92 SSH_USER_PERMITTED_KEYS, linenum);
95 forced_command[i] = 0;
96 packet_send_debug("Forced command: %.900s", forced_command);
100 cp = "environment=\"";
101 if (strncmp(options, cp, strlen(cp)) == 0) {
104 struct envstring *new_envstring;
105 options += strlen(cp);
106 s = xmalloc(strlen(options) + 1);
111 if (*options == '\\' && options[1] == '"') {
119 debug("%.100s, line %lu: missing end quote",
120 SSH_USER_PERMITTED_KEYS, linenum);
121 packet_send_debug("%.100s, line %lu: missing end quote",
122 SSH_USER_PERMITTED_KEYS, linenum);
126 packet_send_debug("Adding to environment: %.900s", s);
127 debug("Adding to environment: %.900s", s);
129 new_envstring = xmalloc(sizeof(struct envstring));
130 new_envstring->s = s;
131 new_envstring->next = custom_environment;
132 custom_environment = new_envstring;
136 if (strncmp(options, cp, strlen(cp)) == 0) {
138 char *patterns = xmalloc(strlen(options) + 1);
140 options += strlen(cp);
145 if (*options == '\\' && options[1] == '"') {
150 patterns[i++] = *options++;
153 debug("%.100s, line %lu: missing end quote",
154 SSH_USER_PERMITTED_KEYS, linenum);
155 packet_send_debug("%.100s, line %lu: missing end quote",
156 SSH_USER_PERMITTED_KEYS, linenum);
162 * Deny access if we get a negative
163 * match for the hostname or the ip
164 * or if we get not match at all
166 mname = match_hostname(get_canonical_hostname(),
167 patterns, strlen(patterns));
168 mip = match_hostname(get_remote_ipaddr(),
169 patterns, strlen(patterns));
171 if (mname == -1 || mip == -1 ||
172 (mname != 1 && mip != 1)) {
173 log("Authentication tried for %.100s with correct key but not from a permitted host (host=%.200s, ip=%.200s).",
174 pw->pw_name, get_canonical_hostname(),
175 get_remote_ipaddr());
176 packet_send_debug("Your host '%.200s' is not permitted to use this key for login.",
177 get_canonical_hostname());
178 /* key invalid for this host, reset flags */
179 no_agent_forwarding_flag = 0;
180 no_port_forwarding_flag = 0;
182 no_x11_forwarding_flag = 0;
183 while (custom_environment) {
184 struct envstring *ce = custom_environment;
185 custom_environment = ce->next;
189 if (forced_command) {
190 xfree(forced_command);
191 forced_command = NULL;
196 /* Host name matches. */
201 * Skip the comma, and move to the next option
202 * (or break out if there are no more).
205 fatal("Bugs in auth-options.c option processing.");
206 if (*options == ' ' || *options == '\t')
207 break; /* End of options. */
211 /* Process the next option. */
217 log("Bad options in %.100s file, line %lu: %.50s",
218 SSH_USER_PERMITTED_KEYS, linenum, options);
219 packet_send_debug("Bad options in %.100s file, line %lu: %.50s",
220 SSH_USER_PERMITTED_KEYS, linenum, options);