]> andersk Git - gssapi-openssh.git/blobdiff - openssh/misc.c
The man2html from jbasney on pkilab2 works whereas the standard one doesn't.
[gssapi-openssh.git] / openssh / misc.c
index 1cb71f8767c46c7dbb58c1530c368c197c5fefe7..c447d234cc3f83a7e360fb5ca280a7b1dde91799 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.65 2006/11/23 01:35:11 ray Exp $ */
+/* $OpenBSD: misc.c,v 1.71 2009/02/21 19:32:04 tobias Exp $ */
 /*
  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
  * Copyright (c) 2005,2006 Damien Miller.  All rights reserved.
@@ -42,6 +42,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <netdb.h>
 #ifdef HAVE_PATHS_H
 # include <paths.h>
 #include <pwd.h>
@@ -120,6 +121,14 @@ unset_nonblock(int fd)
        return (0);
 }
 
+const char *
+ssh_gai_strerror(int gaierr)
+{
+       if (gaierr == EAI_SYSTEM)
+               return strerror(errno);
+       return gai_strerror(gaierr);
+}
+
 /* disable nagle on socket */
 void
 set_nodelay(int fd)
@@ -228,25 +237,35 @@ pwcopy(struct passwd *pw)
        return copy;
 }
 
+void
+pwfree(struct passwd *pw)
+{
+       xfree(pw->pw_name);
+       xfree(pw->pw_passwd);
+       xfree(pw->pw_gecos);
+#ifdef HAVE_PW_CLASS_IN_PASSWD
+       xfree(pw->pw_class);
+#endif
+       xfree(pw->pw_dir);
+       xfree(pw->pw_shell);
+       xfree(pw);
+}
+
 /*
  * Convert ASCII string to TCP/IP port number.
- * Port must be >0 and <=65535.
- * Return 0 if invalid.
+ * Port must be >=0 and <=65535.
+ * Return -1 if invalid.
  */
 int
 a2port(const char *s)
 {
-       long port;
-       char *endp;
+       long long port;
+       const char *errstr;
 
-       errno = 0;
-       port = strtol(s, &endp, 0);
-       if (s == endp || *endp != '\0' ||
-           (errno == ERANGE && (port == LONG_MIN || port == LONG_MAX)) ||
-           port <= 0 || port > 65535)
-               return 0;
-
-       return port;
+       port = strtonum(s, 0, 65535, &errstr);
+       if (errstr != NULL)
+               return -1;
+       return (int)port;
 }
 
 int
@@ -543,7 +562,7 @@ tilde_expand_filename(const char *filename, uid_t uid)
                if ((pw = getpwnam(user)) == NULL)
                        fatal("tilde_expand_filename: No such user %s", user);
        } else if ((pw = getpwuid(uid)) == NULL)        /* ~/path */
-               fatal("tilde_expand_filename: No such uid %d", uid);
+               fatal("tilde_expand_filename: No such uid %ld", (long)uid);
 
        if (strlcpy(ret, pw->pw_dir, sizeof(ret)) >= sizeof(ret))
                fatal("tilde_expand_filename: Path too long");
@@ -727,7 +746,8 @@ sanitise_stdfd(void)
        int nullfd, dupfd;
 
        if ((nullfd = dupfd = open(_PATH_DEVNULL, O_RDWR)) == -1) {
-               fprintf(stderr, "Couldn't open /dev/null: %s", strerror(errno));
+               fprintf(stderr, "Couldn't open /dev/null: %s\n",
+                   strerror(errno));
                exit(1);
        }
        while (++dupfd <= 2) {
@@ -735,7 +755,7 @@ sanitise_stdfd(void)
                if (fcntl(dupfd, F_GETFL, 0) >= 0)
                        continue;
                if (dup2(nullfd, dupfd) == -1) {
-                       fprintf(stderr, "dup2: %s", strerror(errno));
+                       fprintf(stderr, "dup2: %s\n", strerror(errno));
                        exit(1);
                }
        }
@@ -841,3 +861,23 @@ put_u16(void *vp, u_int16_t v)
        p[0] = (u_char)(v >> 8) & 0xff;
        p[1] = (u_char)v & 0xff;
 }
+
+void
+ms_subtract_diff(struct timeval *start, int *ms)
+{
+       struct timeval diff, finish;
+
+       gettimeofday(&finish, NULL);
+       timersub(&finish, start, &diff);        
+       *ms -= (diff.tv_sec * 1000) + (diff.tv_usec / 1000);
+}
+
+void
+ms_to_timeval(struct timeval *tv, int ms)
+{
+       if (ms < 0)
+               ms = 0;
+       tv->tv_sec = ms / 1000;
+       tv->tv_usec = (ms % 1000) * 1000;
+}
+
This page took 0.299176 seconds and 4 git commands to generate.