9 /* Flags set authorized_keys flags */
10 int no_port_forwarding_flag = 0;
11 int no_agent_forwarding_flag = 0;
12 int no_x11_forwarding_flag = 0;
15 /* "command=" option. */
16 char *forced_command = NULL;
18 /* "environment=" options. */
19 struct envstring *custom_environment = NULL;
21 /* return 1 if access is granted, 0 if not. side effect: sets key option flags */
23 auth_parse_options(struct passwd *pw, char *options, unsigned long linenum)
28 while (*options && *options != ' ' && *options != '\t') {
29 cp = "no-port-forwarding";
30 if (strncmp(options, cp, strlen(cp)) == 0) {
31 packet_send_debug("Port forwarding disabled.");
32 no_port_forwarding_flag = 1;
33 options += strlen(cp);
36 cp = "no-agent-forwarding";
37 if (strncmp(options, cp, strlen(cp)) == 0) {
38 packet_send_debug("Agent forwarding disabled.");
39 no_agent_forwarding_flag = 1;
40 options += strlen(cp);
43 cp = "no-X11-forwarding";
44 if (strncmp(options, cp, strlen(cp)) == 0) {
45 packet_send_debug("X11 forwarding disabled.");
46 no_x11_forwarding_flag = 1;
47 options += strlen(cp);
51 if (strncmp(options, cp, strlen(cp)) == 0) {
52 packet_send_debug("Pty allocation disabled.");
54 options += strlen(cp);
58 if (strncmp(options, cp, strlen(cp)) == 0) {
60 options += strlen(cp);
61 forced_command = xmalloc(strlen(options) + 1);
66 if (*options == '\\' && options[1] == '"') {
68 forced_command[i++] = '"';
71 forced_command[i++] = *options++;
74 debug("%.100s, line %lu: missing end quote",
75 SSH_USER_PERMITTED_KEYS, linenum);
76 packet_send_debug("%.100s, line %lu: missing end quote",
77 SSH_USER_PERMITTED_KEYS, linenum);
80 forced_command[i] = 0;
81 packet_send_debug("Forced command: %.900s", forced_command);
85 cp = "environment=\"";
86 if (strncmp(options, cp, strlen(cp)) == 0) {
89 struct envstring *new_envstring;
90 options += strlen(cp);
91 s = xmalloc(strlen(options) + 1);
96 if (*options == '\\' && options[1] == '"') {
104 debug("%.100s, line %lu: missing end quote",
105 SSH_USER_PERMITTED_KEYS, linenum);
106 packet_send_debug("%.100s, line %lu: missing end quote",
107 SSH_USER_PERMITTED_KEYS, linenum);
111 packet_send_debug("Adding to environment: %.900s", s);
112 debug("Adding to environment: %.900s", s);
114 new_envstring = xmalloc(sizeof(struct envstring));
115 new_envstring->s = s;
116 new_envstring->next = custom_environment;
117 custom_environment = new_envstring;
121 if (strncmp(options, cp, strlen(cp)) == 0) {
123 char *patterns = xmalloc(strlen(options) + 1);
125 options += strlen(cp);
130 if (*options == '\\' && options[1] == '"') {
135 patterns[i++] = *options++;
138 debug("%.100s, line %lu: missing end quote",
139 SSH_USER_PERMITTED_KEYS, linenum);
140 packet_send_debug("%.100s, line %lu: missing end quote",
141 SSH_USER_PERMITTED_KEYS, linenum);
147 * Deny access if we get a negative
148 * match for the hostname or the ip
149 * or if we get not match at all
151 mname = match_hostname(get_canonical_hostname(),
152 patterns, strlen(patterns));
153 mip = match_hostname(get_remote_ipaddr(),
154 patterns, strlen(patterns));
156 if (mname == -1 || mip == -1 ||
157 (mname != 1 && mip != 1)) {
158 log("Authentication tried for %.100s with correct key but not from a permitted host (host=%.200s, ip=%.200s).",
159 pw->pw_name, get_canonical_hostname(),
160 get_remote_ipaddr());
161 packet_send_debug("Your host '%.200s' is not permitted to use this key for login.",
162 get_canonical_hostname());
163 /* key invalid for this host, reset flags */
164 no_agent_forwarding_flag = 0;
165 no_port_forwarding_flag = 0;
167 no_x11_forwarding_flag = 0;
168 while (custom_environment) {
169 struct envstring *ce = custom_environment;
170 custom_environment = ce->next;
174 if (forced_command) {
175 xfree(forced_command);
176 forced_command = NULL;
181 /* Host name matches. */
186 * Skip the comma, and move to the next option
187 * (or break out if there are no more).
190 fatal("Bugs in auth-options.c option processing.");
191 if (*options == ' ' || *options == '\t')
192 break; /* End of options. */
196 /* Process the next option. */
202 log("Bad options in %.100s file, line %lu: %.50s",
203 SSH_USER_PERMITTED_KEYS, linenum, options);
204 packet_send_debug("Bad options in %.100s file, line %lu: %.50s",
205 SSH_USER_PERMITTED_KEYS, linenum, options);