summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--Makefile.in4
-rw-r--r--misc.c47
-rw-r--r--misc.h7
-rw-r--r--tildexpand.c73
5 files changed, 55 insertions, 82 deletions
diff --git a/ChangeLog b/ChangeLog
index 7712c31c9..b60dedef8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,10 @@
12 [ssh.c] 12 [ssh.c]
13 Fix debug call for port forwards; patch from pete at seebeyond.com, 13 Fix debug call for port forwards; patch from pete at seebeyond.com,
14 ok djm@ (ID sync only - change already in portable) 14 ok djm@ (ID sync only - change already in portable)
15 - djm@cvs.openbsd.org 2005/04/09 04:32:54
16 [misc.c misc.h tildexpand.c Makefile.in]
17 replace tilde_expand_filename with a simpler implementation, ahead of
18 more whacking; ok deraadt@
15 19
1620050524 2020050524
17 - (djm) [contrib/caldera/openssh.spec contrib/redhat/openssh.spec] 21 - (djm) [contrib/caldera/openssh.spec contrib/redhat/openssh.spec]
@@ -2511,4 +2515,4 @@
2511 - (djm) Trim deprecated options from INSTALL. Mention UsePAM 2515 - (djm) Trim deprecated options from INSTALL. Mention UsePAM
2512 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu 2516 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
2513 2517
2514$Id: ChangeLog,v 1.3764 2005/05/26 02:01:22 djm Exp $ 2518$Id: ChangeLog,v 1.3765 2005/05/26 02:02:14 djm Exp $
diff --git a/Makefile.in b/Makefile.in
index 3351d64d5..b8a01d2f8 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.271 2005/05/26 01:35:38 djm Exp $ 1# $Id: Makefile.in,v 1.272 2005/05/26 02:02:15 djm Exp $
2 2
3# uncomment if you run a non bourne compatable shell. Ie. csh 3# uncomment if you run a non bourne compatable shell. Ie. csh
4#SHELL = @SH@ 4#SHELL = @SH@
@@ -67,7 +67,7 @@ LIBSSH_OBJS=acss.o authfd.o authfile.o bufaux.o buffer.o \
67 cipher-bf1.o cipher-ctr.o cipher-3des1.o cleanup.o \ 67 cipher-bf1.o cipher-ctr.o cipher-3des1.o cleanup.o \
68 compat.o compress.o crc32.o deattack.o fatal.o hostfile.o \ 68 compat.o compress.o crc32.o deattack.o fatal.o hostfile.o \
69 log.o match.o moduli.o nchan.o packet.o \ 69 log.o match.o moduli.o nchan.o packet.o \
70 readpass.o rsa.o tildexpand.o ttymodes.o xmalloc.o \ 70 readpass.o rsa.o ttymodes.o xmalloc.o \
71 atomicio.o key.o dispatch.o kex.o mac.o uidswap.o uuencode.o misc.o \ 71 atomicio.o key.o dispatch.o kex.o mac.o uidswap.o uuencode.o misc.o \
72 monitor_fdpass.o rijndael.o ssh-dss.o ssh-rsa.o dh.o kexdh.o \ 72 monitor_fdpass.o rijndael.o ssh-dss.o ssh-rsa.o dh.o kexdh.o \
73 kexgex.o kexdhc.o kexgexc.o scard.o msg.o progressmeter.o dns.o \ 73 kexgex.o kexdhc.o kexgexc.o scard.o msg.o progressmeter.o dns.o \
diff --git a/misc.c b/misc.c
index 7adbcea1c..4bc07a42a 100644
--- a/misc.c
+++ b/misc.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: misc.c,v 1.29 2005/03/10 22:01:05 deraadt Exp $"); 26RCSID("$OpenBSD: misc.c,v 1.30 2005/04/09 04:32:54 djm Exp $");
27 27
28#include "misc.h" 28#include "misc.h"
29#include "log.h" 29#include "log.h"
@@ -376,6 +376,51 @@ addargs(arglist *args, char *fmt, ...)
376} 376}
377 377
378/* 378/*
379 * Expands tildes in the file name. Returns data allocated by xmalloc.
380 * Warning: this calls getpw*.
381 */
382char *
383tilde_expand_filename(const char *filename, uid_t uid)
384{
385 const char *path;
386 char user[128], ret[MAXPATHLEN];
387 struct passwd *pw;
388 int len;
389
390 if (*filename != '~')
391 return (xstrdup(filename));
392 filename++;
393
394 path = strchr(filename, '/');
395 if (path != NULL && path > filename) { /* ~user/path */
396 if (path - filename > sizeof(user) - 1)
397 fatal("tilde_expand_filename: ~username too long");
398 memcpy(user, filename, path - filename);
399 user[path - filename] = '\0';
400 if ((pw = getpwnam(user)) == NULL)
401 fatal("tilde_expand_filename: No such user %s", user);
402 } else if ((pw = getpwuid(uid)) == NULL) /* ~/path */
403 fatal("tilde_expand_filename: No such uid %d", uid);
404
405 if (strlcpy(ret, pw->pw_dir, sizeof(ret)) >= sizeof(ret))
406 fatal("tilde_expand_filename: Path too long");
407
408 /* Make sure directory has a trailing '/' */
409 len = strlen(pw->pw_dir);
410 if ((len == 0 || pw->pw_dir[len - 1] != '/') &&
411 strlcat(ret, "/", sizeof(ret)) >= sizeof(ret))
412 fatal("tilde_expand_filename: Path too long");
413
414 /* Skip leading '/' from specified path */
415 if (path != NULL)
416 filename = path + 1;
417 if (strlcat(ret, filename, sizeof(ret)) >= sizeof(ret))
418 fatal("tilde_expand_filename: Path too long");
419
420 return (xstrdup(ret));
421}
422
423/*
379 * Read an entire line from a public key file into a static buffer, discarding 424 * Read an entire line from a public key file into a static buffer, discarding
380 * lines that exceed the buffer size. Returns 0 on success, -1 on failure. 425 * lines that exceed the buffer size. Returns 0 on success, -1 on failure.
381 */ 426 */
diff --git a/misc.h b/misc.h
index 8bbc87f0d..798d80fbf 100644
--- a/misc.h
+++ b/misc.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: misc.h,v 1.21 2005/03/01 10:09:52 djm Exp $ */ 1/* $OpenBSD: misc.h,v 1.22 2005/04/09 04:32:54 djm Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -24,6 +24,7 @@ char *hpdelim(char **);
24char *cleanhostname(char *); 24char *cleanhostname(char *);
25char *colon(char *); 25char *colon(char *);
26long convtime(const char *); 26long convtime(const char *);
27char *tilde_expand_filename(const char *, uid_t);
27 28
28struct passwd *pwcopy(struct passwd *); 29struct passwd *pwcopy(struct passwd *);
29 30
@@ -35,10 +36,6 @@ struct arglist {
35}; 36};
36void addargs(arglist *, char *, ...) __attribute__((format(printf, 2, 3))); 37void addargs(arglist *, char *, ...) __attribute__((format(printf, 2, 3)));
37 38
38/* tildexpand.c */
39
40char *tilde_expand_filename(const char *, uid_t);
41
42/* readpass.c */ 39/* readpass.c */
43 40
44#define RP_ECHO 0x0001 41#define RP_ECHO 0x0001
diff --git a/tildexpand.c b/tildexpand.c
deleted file mode 100644
index cedb653b2..000000000
--- a/tildexpand.c
+++ /dev/null
@@ -1,73 +0,0 @@
1/*
2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
5 *
6 * As far as I am concerned, the code I have written for this software
7 * can be used freely for any purpose. Any derived versions of this
8 * software must be clearly marked as such, and if the derived work is
9 * incompatible with the protocol description in the RFC file, it must be
10 * called by a name other than "ssh" or "Secure Shell".
11 */
12
13#include "includes.h"
14RCSID("$OpenBSD: tildexpand.c,v 1.15 2004/05/21 08:43:03 markus Exp $");
15
16#include "xmalloc.h"
17#include "log.h"
18#include "misc.h"
19
20/*
21 * Expands tildes in the file name. Returns data allocated by xmalloc.
22 * Warning: this calls getpw*.
23 */
24char *
25tilde_expand_filename(const char *filename, uid_t my_uid)
26{
27 const char *cp;
28 u_int userlen;
29 char *expanded;
30 struct passwd *pw;
31 char user[100];
32 int len;
33
34 /* Return immediately if no tilde. */
35 if (filename[0] != '~')
36 return xstrdup(filename);
37
38 /* Skip the tilde. */
39 filename++;
40
41 /* Find where the username ends. */
42 cp = strchr(filename, '/');
43 if (cp)
44 userlen = cp - filename; /* Something after username. */
45 else
46 userlen = strlen(filename); /* Nothing after username. */
47 if (userlen == 0)
48 pw = getpwuid(my_uid); /* Own home directory. */
49 else {
50 /* Tilde refers to someone elses home directory. */
51 if (userlen > sizeof(user) - 1)
52 fatal("User name after tilde too long.");
53 memcpy(user, filename, userlen);
54 user[userlen] = 0;
55 pw = getpwnam(user);
56 }
57 if (!pw)
58 fatal("Unknown user %100s.", user);
59
60 /* If referring to someones home directory, return it now. */
61 if (!cp) {
62 /* Only home directory specified */
63 return xstrdup(pw->pw_dir);
64 }
65 /* Build a path combining the specified directory and path. */
66 len = strlen(pw->pw_dir) + strlen(cp + 1) + 2;
67 if (len > MAXPATHLEN)
68 fatal("Home directory too long (%d > %d", len-1, MAXPATHLEN-1);
69 expanded = xmalloc(len);
70 snprintf(expanded, len, "%s%s%s", pw->pw_dir,
71 strcmp(pw->pw_dir, "/") ? "/" : "", cp + 1);
72 return expanded;
73}