Lines 138-192
do_filename(const char *filename, int qu
Link Here
|
138 |
f = stdin; |
138 |
f = stdin; |
139 |
while (read_keyfile_line(f, filename, line, sizeof(line), |
139 |
while (read_keyfile_line(f, filename, line, sizeof(line), |
140 |
&linenum) != -1) { |
140 |
&linenum) != -1) { |
141 |
cp = line; |
141 |
int i; |
142 |
switch (*cp) { |
142 |
char *space; |
143 |
case '#': |
143 |
int type; |
144 |
case '\n': |
144 |
|
145 |
case '\0': |
145 |
/* Chop trailing newline. */ |
146 |
continue; |
146 |
i = strlen(line) - 1; |
147 |
} |
147 |
if (line[i] == '\n') |
148 |
/* Skip leading whitespace. */ |
148 |
line[i] = '\0'; |
149 |
for (; *cp && (*cp == ' ' || *cp == '\t'); cp++) |
149 |
|
|
|
150 |
/* Skip leading whitespace, empty and comment lines. */ |
151 |
for (cp = line; *cp == ' ' || *cp == '\t'; cp++) |
150 |
; |
152 |
; |
151 |
/* Cope with ssh-keyscan output. */ |
153 |
if (!*cp || *cp == '\n' || *cp == '#') |
152 |
comment = NULL; |
154 |
continue; |
153 |
if (*cp) { |
|
|
154 |
char *space; |
155 |
int type; |
156 |
|
155 |
|
157 |
space = strchr(cp, ' '); |
156 |
/* Cope with ssh-keyscan output and options in |
158 |
if (!space) |
157 |
* authorized_keys files. |
159 |
continue; |
158 |
*/ |
160 |
*space = '\0'; |
159 |
space = strchr(cp, ' '); |
161 |
type = key_type_from_name(cp); |
160 |
if (!space) |
162 |
if (type == KEY_UNSPEC) { |
161 |
continue; |
163 |
comment = xstrdup(cp); |
162 |
*space = '\0'; |
164 |
cp = space + 1; |
163 |
type = key_type_from_name(cp); |
|
|
164 |
*space = ' '; |
165 |
/* Leading number (RSA1) or valid type (RSA/DSA) indicates |
166 |
* that we have no host name or options to skip. |
167 |
*/ |
168 |
if (atoi(cp) == 0 && type == KEY_UNSPEC) { |
169 |
int quoted = 0; |
170 |
|
171 |
for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) { |
172 |
if (*cp == '\\' && cp[1] == '"') |
173 |
cp++; /* Skip both */ |
174 |
else if (*cp == '"') |
175 |
quoted = !quoted; |
165 |
} |
176 |
} |
166 |
*space = ' '; |
177 |
/* Skip remaining whitespace. */ |
|
|
178 |
for (; *cp == ' ' || *cp == '\t'; cp++) |
179 |
; |
180 |
if (!*cp) |
181 |
continue; |
167 |
} |
182 |
} |
168 |
if (!comment) |
183 |
|
169 |
comment = xstrdup(filename); |
184 |
/* Read and process the key itself. */ |
170 |
if (*cp) { |
185 |
key = key_new(KEY_RSA1); |
171 |
key = key_new(KEY_RSA1); |
186 |
if (key_read(key, &cp) == 1) { |
|
|
187 |
while (*cp == ' ' || *cp == '\t') |
188 |
cp++; |
189 |
if (!do_key(key, *cp ? cp : filename)) |
190 |
ret = 0; |
191 |
found = 1; |
192 |
} else { |
193 |
key_free(key); |
194 |
key = key_new(KEY_UNSPEC); |
172 |
if (key_read(key, &cp) == 1) { |
195 |
if (key_read(key, &cp) == 1) { |
173 |
if (!do_key(key, comment)) |
196 |
while (*cp == ' ' || *cp == '\t') |
|
|
197 |
cp++; |
198 |
if (!do_key(key, *cp ? cp : filename)) |
174 |
ret = 0; |
199 |
ret = 0; |
175 |
key_free(key); |
|
|
176 |
found = 1; |
200 |
found = 1; |
177 |
} else { |
|
|
178 |
key_free(key); |
179 |
key = key_new(KEY_UNSPEC); |
180 |
if (key_read(key, &cp) == 1) { |
181 |
if (!do_key(key, comment)) |
182 |
ret = 0; |
183 |
key_free(key); |
184 |
found = 1; |
185 |
} |
186 |
} |
201 |
} |
187 |
} |
202 |
} |
188 |
xfree(comment); |
203 |
key_free(key); |
189 |
comment = NULL; |
|
|
190 |
} |
204 |
} |
191 |
if (f != stdin) |
205 |
if (f != stdin) |
192 |
fclose(f); |
206 |
fclose(f); |