summaryrefslogtreecommitdiff
path: root/auth.c
diff options
context:
space:
mode:
Diffstat (limited to 'auth.c')
-rw-r--r--auth.c59
1 files changed, 18 insertions, 41 deletions
diff --git a/auth.c b/auth.c
index 46b013137..68c2824fb 100644
--- a/auth.c
+++ b/auth.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: auth.c,v 1.58 2005/03/14 11:44:42 dtucker Exp $"); 26RCSID("$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 */
329char * 329static char *
330expand_filename(const char *filename, struct passwd *pw) 330expand_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
377char * 354char *
378authorized_keys_file(struct passwd *pw) 355authorized_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
383char * 360char *
384authorized_keys_file2(struct passwd *pw) 361authorized_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 */