summaryrefslogtreecommitdiff
path: root/tildexpand.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2005-05-26 12:02:14 +1000
committerDamien Miller <djm@mindrot.org>2005-05-26 12:02:14 +1000
commit5fd38c0ed985d7d699e6be1ff5d211cac130b71e (patch)
treeaa80a3f2b1e522b6f83805ab582645df2049f6ab /tildexpand.c
parent1b0de9a04127eeec9a5352abd16113bb8faa494c (diff)
- djm@cvs.openbsd.org 2005/04/09 04:32:54
[misc.c misc.h tildexpand.c Makefile.in] replace tilde_expand_filename with a simpler implementation, ahead of more whacking; ok deraadt@
Diffstat (limited to 'tildexpand.c')
-rw-r--r--tildexpand.c73
1 files changed, 0 insertions, 73 deletions
diff --git a/tildexpand.c b/tildexpand.c
deleted file mode 100644
index cedb653b..00000000
--- a/tildexpand.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Author: Tatu Ylonen <ylo@cs.hut.fi>
- * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
- * All rights reserved
- *
- * As far as I am concerned, the code I have written for this software
- * can be used freely for any purpose. Any derived versions of this
- * software must be clearly marked as such, and if the derived work is
- * incompatible with the protocol description in the RFC file, it must be
- * called by a name other than "ssh" or "Secure Shell".
- */
-
-#include "includes.h"
-RCSID("$OpenBSD: tildexpand.c,v 1.15 2004/05/21 08:43:03 markus Exp $");
-
-#include "xmalloc.h"
-#include "log.h"
-#include "misc.h"
-
-/*
- * Expands tildes in the file name. Returns data allocated by xmalloc.
- * Warning: this calls getpw*.
- */
-char *
-tilde_expand_filename(const char *filename, uid_t my_uid)
-{
- const char *cp;
- u_int userlen;
- char *expanded;
- struct passwd *pw;
- char user[100];
- int len;
-
- /* Return immediately if no tilde. */
- if (filename[0] != '~')
- return xstrdup(filename);
-
- /* Skip the tilde. */
- filename++;
-
- /* Find where the username ends. */
- cp = strchr(filename, '/');
- if (cp)
- userlen = cp - filename; /* Something after username. */
- else
- userlen = strlen(filename); /* Nothing after username. */
- if (userlen == 0)
- pw = getpwuid(my_uid); /* Own home directory. */
- else {
- /* Tilde refers to someone elses home directory. */
- if (userlen > sizeof(user) - 1)
- fatal("User name after tilde too long.");
- memcpy(user, filename, userlen);
- user[userlen] = 0;
- pw = getpwnam(user);
- }
- if (!pw)
- fatal("Unknown user %100s.", user);
-
- /* If referring to someones home directory, return it now. */
- if (!cp) {
- /* Only home directory specified */
- return xstrdup(pw->pw_dir);
- }
- /* Build a path combining the specified directory and path. */
- len = strlen(pw->pw_dir) + strlen(cp + 1) + 2;
- if (len > MAXPATHLEN)
- fatal("Home directory too long (%d > %d", len-1, MAXPATHLEN-1);
- expanded = xmalloc(len);
- snprintf(expanded, len, "%s%s%s", pw->pw_dir,
- strcmp(pw->pw_dir, "/") ? "/" : "", cp + 1);
- return expanded;
-}