]> andersk Git - openssh.git/blobdiff - misc.c
- dtucker@cvs.openbsd.org 2005/10/31 06:15:04
[openssh.git] / misc.c
diff --git a/misc.c b/misc.c
index fc094f87414bc730e8ff893f692f98ff4d2f1912..27b947f0c79f54ba0cb6aedc68e231e77cb116dc 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -24,7 +24,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: misc.c,v 1.31 2005/06/06 11:20:36 djm Exp $");
+RCSID("$OpenBSD: misc.c,v 1.35 2005/09/13 23:40:07 djm Exp $");
 
 #include "misc.h"
 #include "log.h"
@@ -386,7 +386,7 @@ tilde_expand_filename(const char *filename, uid_t uid)
        const char *path;
        char user[128], ret[MAXPATHLEN];
        struct passwd *pw;
-       int len;
+       u_int len, slash;
 
        if (*filename != '~')
                return (xstrdup(filename));
@@ -394,10 +394,11 @@ tilde_expand_filename(const char *filename, uid_t uid)
 
        path = strchr(filename, '/');
        if (path != NULL && path > filename) {          /* ~user/path */
-               if (path - filename > sizeof(user) - 1)
+               slash = path - filename;
+               if (slash > sizeof(user) - 1)
                        fatal("tilde_expand_filename: ~username too long");
-               memcpy(user, filename, path - filename);
-               user[path - filename] = '\0';
+               memcpy(user, filename, slash);
+               user[slash] = '\0';
                if ((pw = getpwnam(user)) == NULL)
                        fatal("tilde_expand_filename: No such user %s", user);
        } else if ((pw = getpwuid(uid)) == NULL)        /* ~/path */
@@ -424,7 +425,7 @@ tilde_expand_filename(const char *filename, uid_t uid)
 /*
  * Expand a string with a set of %[char] escapes. A number of escapes may be
  * specified as (char *escape_chars, char *replacement) pairs. The list must
- * be terminated by an escape_char of -1. Returns replaced string in memory
+ * be terminated by a NULL escape_char. Returns replaced string in memory
  * allocated by xmalloc.
  */
 char *
@@ -435,7 +436,7 @@ percent_expand(const char *string, ...)
                const char *key;
                const char *repl;
        } keys[EXPAND_MAX_KEYS];
-       int num_keys, i, j;
+       u_int num_keys, i, j;
        char buf[4096];
        va_list ap;
 
@@ -505,3 +506,40 @@ read_keyfile_line(FILE *f, const char *filename, char *buf, size_t bufsz,
        }
        return -1;
 }
+
+void
+sanitise_stdfd(void)
+{
+       int nullfd;
+
+       if ((nullfd = open(_PATH_DEVNULL, O_RDWR)) == -1) {
+               fprintf(stderr, "Couldn't open /dev/null: %s", strerror(errno));
+               exit(1);
+       }
+       while (nullfd < 2) {
+               if (dup2(nullfd, nullfd + 1) == -1) {
+                       fprintf(stderr, "dup2: %s", strerror(errno));
+                       exit(1);
+               }
+               nullfd++;
+       }
+       if (nullfd > 2)
+               close(nullfd);
+}
+
+char *
+tohex(const u_char *d, u_int l)
+{
+       char b[3], *r;
+       u_int i, hl;
+
+       hl = l * 2 + 1;
+       r = xmalloc(hl);
+       *r = '\0';
+       for (i = 0; i < l; i++) {
+               snprintf(b, sizeof(b), "%02x", d[i]);
+               strlcat(r, b, hl);
+       }
+       return (r);
+}
+
This page took 0.1044 seconds and 4 git commands to generate.