Bugzilla – Attachment 18 Details for
Bug 95
Allow '%' expansion to work in ssh and ssh-add
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
patch to tildexpand.c and auth.c to allow '%' substitution everywhere
fileexpand.patch (text/plain), 5.27 KB, created by
Jason Prondak
on 2002-02-02 09:25:52 AEDT
(
hide
)
Description:
patch to tildexpand.c and auth.c to allow '%' substitution everywhere
Filename:
MIME Type:
Creator:
Jason Prondak
Created:
2002-02-02 09:25:52 AEDT
Size:
5.27 KB
patch
obsolete
>Index: 3_0_2p1.1/tildexpand.h >--- 3_0_2p1.1/tildexpand.h Wed, 21 Nov 2001 10:38:46 -0500 jd (OpenSSH/h/18_tildexpand 1.2 644) >+++ 3_0_2p1_w_file_expansion.2(w)/tildexpand.h Fri, 11 Jan 2002 13:26:54 -0500 prondaja (OpenSSH/h/18_tildexpand 1.3 644) >@@ -13,3 +13,4 @@ > */ > > char *tilde_expand_filename(const char *, uid_t); >+char *expand_filename(const char *, struct passwd *); >Index: 3_0_2p1.1/tildexpand.c >--- 3_0_2p1.1/tildexpand.c Wed, 21 Nov 2001 10:38:46 -0500 jd (OpenSSH/h/19_tildexpand 1.2 644) >+++ 3_0_2p1_w_file_expansion.2(w)/tildexpand.c Mon, 14 Jan 2002 12:20:24 -0500 prondaja (OpenSSH/h/19_tildexpand 1.4 644) >@@ -16,6 +16,7 @@ > #include "xmalloc.h" > #include "log.h" > #include "tildexpand.h" >+#include "buffer.h" > > /* > * Expands tildes in the file name. Returns data allocated by xmalloc. >@@ -31,6 +32,12 @@ > char user[100]; > int len; > >+ pw = getpwuid(my_uid); /* Own home directory. */ >+ if (!pw) >+ fatal("Unknown user %100s.", user); >+ >+ filename = expand_filename(filename, pw); >+ > /* Return immediately if no tilde. */ > if (filename[0] != '~') > return xstrdup(filename); >@@ -44,9 +51,7 @@ > userlen = cp - filename; /* Something after username. */ > else > userlen = strlen(filename); /* Nothing after username. */ >- if (userlen == 0) >- pw = getpwuid(my_uid); /* Own home directory. */ >- else { >+ if (userlen != 0) { > /* Tilde refers to someone elses home directory. */ > if (userlen > sizeof(user) - 1) > fatal("User name after tilde too long."); >@@ -54,8 +59,6 @@ > user[userlen] = 0; > pw = getpwnam(user); > } >- if (!pw) >- fatal("Unknown user %100s.", user); > > /* If referring to someones home directory, return it now. */ > if (!cp) { >@@ -68,5 +71,61 @@ > 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; >+ return expand_filename(expanded, pw); >+} >+ >+/* >+ * Given a template and a passwd structure, build a filename >+ * by substituting % tokenised options. Currently, %% becomes '%', >+ * %h becomes the home directory and %u the username. >+ * >+ * This returns a buffer allocated by xmalloc. >+ */ >+char * >+expand_filename(const char *filename, struct passwd *pw) >+{ >+ Buffer buffer; >+ char *file; >+ const char *cp; >+ >+ /* >+ * Build the filename string in the buffer by making the appropriate >+ * substitutions to the given file name. >+ */ >+ buffer_init(&buffer); >+ for (cp = filename; *cp; cp++) { >+ if (cp[0] == '%' && cp[1] == '%') { >+ buffer_append(&buffer, "%", 1); >+ cp++; >+ continue; >+ } >+ if (cp[0] == '%' && cp[1] == 'h') { >+ buffer_append(&buffer, pw->pw_dir, strlen(pw->pw_dir)); >+ cp++; >+ continue; >+ } >+ if (cp[0] == '%' && cp[1] == 'u') { >+ buffer_append(&buffer, pw->pw_name, >+ strlen(pw->pw_name)); >+ cp++; >+ continue; >+ } >+ buffer_append(&buffer, cp, 1); >+ } >+ buffer_append(&buffer, "\0", 1); >+ >+ /* >+ * Ensure that filename starts anchored. If not, be backward >+ * compatible and prepend the '%h/' >+ */ >+ file = xmalloc(MAXPATHLEN); >+ cp = buffer_ptr(&buffer); >+ if (*cp != '/' && *cp != '~') >+ snprintf(file, MAXPATHLEN, "%s/%s", pw->pw_dir, cp); >+ else >+ strlcpy(file, cp, MAXPATHLEN); >+ >+ buffer_free(&buffer); >+ return file; > } >+ >Index: 3_0_2p1.1/auth.h >--- 3_0_2p1.1/auth.h Wed, 21 Nov 2001 10:38:46 -0500 jd (OpenSSH/k/11_auth.h 1.1.1.1 644) >+++ 3_0_2p1_w_file_expansion.2(w)/auth.h Fri, 11 Jan 2002 13:26:54 -0500 prondaja (OpenSSH/k/11_auth.h 1.1.1.1.1.1 644) >@@ -138,7 +138,6 @@ > > struct passwd * auth_get_user(void); > >-char *expand_filename(const char *, struct passwd *); > char *authorized_keys_file(struct passwd *); > char *authorized_keys_file2(struct passwd *); > >Index: 3_0_2p1.1/auth.c >--- 3_0_2p1.1/auth.c Wed, 21 Nov 2001 10:38:46 -0500 jd (OpenSSH/k/12_auth.c 1.1.1.1 644) >+++ 3_0_2p1_w_file_expansion.2(w)/auth.c Fri, 11 Jan 2002 13:26:54 -0500 prondaja (OpenSSH/k/12_auth.c 1.1.1.2 644) >@@ -239,62 +239,6 @@ > return 0; > } > >- >-/* >- * Given a template and a passwd structure, build a filename >- * by substituting % tokenised options. Currently, %% becomes '%', >- * %h becomes the home directory and %u the username. >- * >- * This returns a buffer allocated by xmalloc. >- */ >-char * >-expand_filename(const char *filename, struct passwd *pw) >-{ >- Buffer buffer; >- char *file; >- const char *cp; >- >- /* >- * Build the filename string in the buffer by making the appropriate >- * substitutions to the given file name. >- */ >- buffer_init(&buffer); >- for (cp = filename; *cp; cp++) { >- if (cp[0] == '%' && cp[1] == '%') { >- buffer_append(&buffer, "%", 1); >- cp++; >- continue; >- } >- if (cp[0] == '%' && cp[1] == 'h') { >- buffer_append(&buffer, pw->pw_dir, strlen(pw->pw_dir)); >- cp++; >- continue; >- } >- if (cp[0] == '%' && cp[1] == 'u') { >- buffer_append(&buffer, pw->pw_name, >- strlen(pw->pw_name)); >- cp++; >- continue; >- } >- buffer_append(&buffer, cp, 1); >- } >- buffer_append(&buffer, "\0", 1); >- >- /* >- * Ensure that filename starts anchored. If not, be backward >- * compatible and prepend the '%h/' >- */ >- file = xmalloc(MAXPATHLEN); >- cp = buffer_ptr(&buffer); >- if (*cp != '/') >- snprintf(file, MAXPATHLEN, "%s/%s", pw->pw_dir, cp); >- else >- strlcpy(file, cp, MAXPATHLEN); >- >- buffer_free(&buffer); >- return file; >-} >- > char * > authorized_keys_file(struct passwd *pw) > {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 95
: 18