diff options
author | Damien Miller <djm@mindrot.org> | 2005-06-16 13:18:34 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2005-06-16 13:18:34 +1000 |
commit | 6476cad9bb6b8a9524a153639b4ebceb3427e743 (patch) | |
tree | 59e9068c25f8d9c6d7e51f66e3c8c983c52db0d9 /auth.c | |
parent | 05656967b111a7c2b1f831eab0c31002dfac6fa9 (diff) |
- djm@cvs.openbsd.org 2005/06/06 11:20:36
[auth.c auth.h misc.c misc.h ssh.c ssh_config.5 sshconnect.c]
introduce a generic %foo expansion function. replace existing % expansion
and add expansion to ControlPath; ok markus@
Diffstat (limited to 'auth.c')
-rw-r--r-- | auth.c | 59 |
1 files changed, 18 insertions, 41 deletions
@@ -23,7 +23,7 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | RCSID("$OpenBSD: auth.c,v 1.58 2005/03/14 11:44:42 dtucker Exp $"); | 26 | RCSID("$OpenBSD: auth.c,v 1.59 2005/06/06 11:20:36 djm Exp $"); |
27 | 27 | ||
28 | #ifdef HAVE_LOGIN_H | 28 | #ifdef HAVE_LOGIN_H |
29 | #include <login.h> | 29 | #include <login.h> |
@@ -326,64 +326,41 @@ auth_root_allowed(char *method) | |||
326 | * | 326 | * |
327 | * This returns a buffer allocated by xmalloc. | 327 | * This returns a buffer allocated by xmalloc. |
328 | */ | 328 | */ |
329 | char * | 329 | static char * |
330 | expand_filename(const char *filename, struct passwd *pw) | 330 | expand_authorized_keys(const char *filename, struct passwd *pw) |
331 | { | 331 | { |
332 | Buffer buffer; | 332 | char *file, *ret; |
333 | char *file; | ||
334 | const char *cp; | ||
335 | 333 | ||
336 | /* | 334 | file = percent_expand(filename, "h", pw->pw_dir, |
337 | * Build the filename string in the buffer by making the appropriate | 335 | "u", pw->pw_name, (char *)NULL); |
338 | * substitutions to the given file name. | ||
339 | */ | ||
340 | buffer_init(&buffer); | ||
341 | for (cp = filename; *cp; cp++) { | ||
342 | if (cp[0] == '%' && cp[1] == '%') { | ||
343 | buffer_append(&buffer, "%", 1); | ||
344 | cp++; | ||
345 | continue; | ||
346 | } | ||
347 | if (cp[0] == '%' && cp[1] == 'h') { | ||
348 | buffer_append(&buffer, pw->pw_dir, strlen(pw->pw_dir)); | ||
349 | cp++; | ||
350 | continue; | ||
351 | } | ||
352 | if (cp[0] == '%' && cp[1] == 'u') { | ||
353 | buffer_append(&buffer, pw->pw_name, | ||
354 | strlen(pw->pw_name)); | ||
355 | cp++; | ||
356 | continue; | ||
357 | } | ||
358 | buffer_append(&buffer, cp, 1); | ||
359 | } | ||
360 | buffer_append(&buffer, "\0", 1); | ||
361 | 336 | ||
362 | /* | 337 | /* |
363 | * Ensure that filename starts anchored. If not, be backward | 338 | * Ensure that filename starts anchored. If not, be backward |
364 | * compatible and prepend the '%h/' | 339 | * compatible and prepend the '%h/' |
365 | */ | 340 | */ |
366 | file = xmalloc(MAXPATHLEN); | 341 | if (*file == '/') |
367 | cp = buffer_ptr(&buffer); | 342 | return (file); |
368 | if (*cp != '/') | 343 | |
369 | snprintf(file, MAXPATHLEN, "%s/%s", pw->pw_dir, cp); | 344 | ret = xmalloc(MAXPATHLEN); |
370 | else | 345 | if (strlcpy(ret, pw->pw_dir, MAXPATHLEN) >= MAXPATHLEN || |
371 | strlcpy(file, cp, MAXPATHLEN); | 346 | strlcat(ret, "/", MAXPATHLEN) >= MAXPATHLEN || |
347 | strlcat(ret, file, MAXPATHLEN) >= MAXPATHLEN) | ||
348 | fatal("expand_authorized_keys: path too long"); | ||
372 | 349 | ||
373 | buffer_free(&buffer); | 350 | xfree(file); |
374 | return file; | 351 | return (ret); |
375 | } | 352 | } |
376 | 353 | ||
377 | char * | 354 | char * |
378 | authorized_keys_file(struct passwd *pw) | 355 | authorized_keys_file(struct passwd *pw) |
379 | { | 356 | { |
380 | return expand_filename(options.authorized_keys_file, pw); | 357 | return expand_authorized_keys(options.authorized_keys_file, pw); |
381 | } | 358 | } |
382 | 359 | ||
383 | char * | 360 | char * |
384 | authorized_keys_file2(struct passwd *pw) | 361 | authorized_keys_file2(struct passwd *pw) |
385 | { | 362 | { |
386 | return expand_filename(options.authorized_keys_file2, pw); | 363 | return expand_authorized_keys(options.authorized_keys_file2, pw); |
387 | } | 364 | } |
388 | 365 | ||
389 | /* return ok if key exists in sysfile or userfile */ | 366 | /* return ok if key exists in sysfile or userfile */ |