diff options
author | Colin Watson <cjwatson@debian.org> | 2007-06-12 16:16:35 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2007-06-12 16:16:35 +0000 |
commit | b7e40fa9da0b5491534a429dadb321eab5a77558 (patch) | |
tree | bed1da11e9f829925797aa093e379fc0b5868ecd /openbsd-compat | |
parent | 4f84beedf1005e44ff33c854abd6b711ffc0adb7 (diff) | |
parent | 086ea76990b1e6287c24b6db74adffd4605eb3b0 (diff) |
* New upstream release (closes: #395507, #397961, #420035). Important
changes not previously backported to 4.3p2:
- 4.4/4.4p1 (http://www.openssh.org/txt/release-4.4):
+ On portable OpenSSH, fix a GSSAPI authentication abort that could be
used to determine the validity of usernames on some platforms.
+ Implemented conditional configuration in sshd_config(5) using the
"Match" directive. This allows some configuration options to be
selectively overridden if specific criteria (based on user, group,
hostname and/or address) are met. So far a useful subset of
post-authentication options are supported and more are expected to
be added in future releases.
+ Add support for Diffie-Hellman group exchange key agreement with a
final hash of SHA256.
+ Added a "ForceCommand" directive to sshd_config(5). Similar to the
command="..." option accepted in ~/.ssh/authorized_keys, this forces
the execution of the specified command regardless of what the user
requested. This is very useful in conjunction with the new "Match"
option.
+ Add a "PermitOpen" directive to sshd_config(5). This mirrors the
permitopen="..." authorized_keys option, allowing fine-grained
control over the port-forwardings that a user is allowed to
establish.
+ Add optional logging of transactions to sftp-server(8).
+ ssh(1) will now record port numbers for hosts stored in
~/.ssh/known_hosts when a non-standard port has been requested
(closes: #50612).
+ Add an "ExitOnForwardFailure" option to cause ssh(1) to exit (with a
non-zero exit code) when requested port forwardings could not be
established.
+ Extend sshd_config(5) "SubSystem" declarations to allow the
specification of command-line arguments.
+ Replacement of all integer overflow susceptible invocations of
malloc(3) and realloc(3) with overflow-checking equivalents.
+ Many manpage fixes and improvements.
+ Add optional support for OpenSSL hardware accelerators (engines),
enabled using the --with-ssl-engine configure option.
+ Tokens in configuration files may be double-quoted in order to
contain spaces (closes: #319639).
+ Move a debug() call out of a SIGCHLD handler, fixing a hang when the
session exits very quickly (closes: #307890).
+ Fix some incorrect buffer allocation calculations (closes: #410599).
+ ssh-add doesn't ask for a passphrase if key file permissions are too
liberal (closes: #103677).
+ Likewise, ssh doesn't ask either (closes: #99675).
- 4.6/4.6p1 (http://www.openssh.org/txt/release-4.6):
+ sshd now allows the enabling and disabling of authentication methods
on a per user, group, host and network basis via the Match directive
in sshd_config.
+ Fixed an inconsistent check for a terminal when displaying scp
progress meter (closes: #257524).
+ Fix "hang on exit" when background processes are running at the time
of exit on a ttyful/login session (closes: #88337).
* Update to current GSSAPI patch from
http://www.sxw.org.uk/computing/patches/openssh-4.6p1-gsskex-20070312.patch;
install ChangeLog.gssapi.
Diffstat (limited to 'openbsd-compat')
47 files changed, 2172 insertions, 159 deletions
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in index 3a8703bc1..9f06605d7 100644 --- a/openbsd-compat/Makefile.in +++ b/openbsd-compat/Makefile.in | |||
@@ -1,4 +1,4 @@ | |||
1 | # $Id: Makefile.in,v 1.37 2005/12/31 05:33:37 djm Exp $ | 1 | # $Id: Makefile.in,v 1.40 2006/08/30 17:24:41 djm Exp $ |
2 | 2 | ||
3 | sysconfdir=@sysconfdir@ | 3 | sysconfdir=@sysconfdir@ |
4 | piddir=@piddir@ | 4 | piddir=@piddir@ |
@@ -16,11 +16,11 @@ RANLIB=@RANLIB@ | |||
16 | INSTALL=@INSTALL@ | 16 | INSTALL=@INSTALL@ |
17 | LDFLAGS=-L. @LDFLAGS@ | 17 | LDFLAGS=-L. @LDFLAGS@ |
18 | 18 | ||
19 | OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o strtonum.o strtoll.o strtoul.o vis.o | 19 | OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o strtonum.o strtoll.o strtoul.o vis.o |
20 | 20 | ||
21 | COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-snprintf.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o | 21 | COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-snprintf.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o |
22 | 22 | ||
23 | PORTS=port-irix.o port-aix.o port-uw.o port-tun.o | 23 | PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-tun.o port-uw.o |
24 | 24 | ||
25 | .c.o: | 25 | .c.o: |
26 | $(CC) $(CFLAGS) $(CPPFLAGS) -c $< | 26 | $(CC) $(CFLAGS) $(CPPFLAGS) -c $< |
diff --git a/openbsd-compat/basename.c b/openbsd-compat/basename.c index ad040e139..ffa5c8984 100644 --- a/openbsd-compat/basename.c +++ b/openbsd-compat/basename.c | |||
@@ -20,6 +20,8 @@ | |||
20 | 20 | ||
21 | #include "includes.h" | 21 | #include "includes.h" |
22 | #ifndef HAVE_BASENAME | 22 | #ifndef HAVE_BASENAME |
23 | #include <errno.h> | ||
24 | #include <string.h> | ||
23 | 25 | ||
24 | char * | 26 | char * |
25 | basename(const char *path) | 27 | basename(const char *path) |
diff --git a/openbsd-compat/bindresvport.c b/openbsd-compat/bindresvport.c index 7f48fd03a..65afed1e3 100644 --- a/openbsd-compat/bindresvport.c +++ b/openbsd-compat/bindresvport.c | |||
@@ -33,8 +33,14 @@ | |||
33 | #include "includes.h" | 33 | #include "includes.h" |
34 | 34 | ||
35 | #ifndef HAVE_BINDRESVPORT_SA | 35 | #ifndef HAVE_BINDRESVPORT_SA |
36 | #include <sys/types.h> | ||
37 | #include <sys/socket.h> | ||
36 | 38 | ||
37 | #include "includes.h" | 39 | #include <netinet/in.h> |
40 | #include <arpa/inet.h> | ||
41 | |||
42 | #include <errno.h> | ||
43 | #include <string.h> | ||
38 | 44 | ||
39 | #define STARTPORT 600 | 45 | #define STARTPORT 600 |
40 | #define ENDPORT (IPPORT_RESERVED - 1) | 46 | #define ENDPORT (IPPORT_RESERVED - 1) |
diff --git a/openbsd-compat/bsd-arc4random.c b/openbsd-compat/bsd-arc4random.c index 1eeb6953b..d45fb182a 100644 --- a/openbsd-compat/bsd-arc4random.c +++ b/openbsd-compat/bsd-arc4random.c | |||
@@ -15,9 +15,13 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "includes.h" | 17 | #include "includes.h" |
18 | #include "log.h" | ||
19 | 18 | ||
20 | RCSID("$Id: bsd-arc4random.c,v 1.10 2005/02/16 02:01:28 djm Exp $"); | 19 | #include <sys/types.h> |
20 | |||
21 | #include <string.h> | ||
22 | #include <stdarg.h> | ||
23 | |||
24 | #include "log.h" | ||
21 | 25 | ||
22 | #ifndef HAVE_ARC4RANDOM | 26 | #ifndef HAVE_ARC4RANDOM |
23 | 27 | ||
diff --git a/openbsd-compat/bsd-asprintf.c b/openbsd-compat/bsd-asprintf.c index 5ca01f80f..00fa0dfd8 100644 --- a/openbsd-compat/bsd-asprintf.c +++ b/openbsd-compat/bsd-asprintf.c | |||
@@ -21,6 +21,10 @@ | |||
21 | 21 | ||
22 | #ifndef HAVE_VASPRINTF | 22 | #ifndef HAVE_VASPRINTF |
23 | 23 | ||
24 | #include <errno.h> | ||
25 | #include <stdarg.h> | ||
26 | #include <stdlib.h> | ||
27 | |||
24 | #ifndef VA_COPY | 28 | #ifndef VA_COPY |
25 | # ifdef HAVE_VA_COPY | 29 | # ifdef HAVE_VA_COPY |
26 | # define VA_COPY(dest, src) va_copy(dest, src) | 30 | # define VA_COPY(dest, src) va_copy(dest, src) |
@@ -35,7 +39,8 @@ | |||
35 | 39 | ||
36 | #define INIT_SZ 128 | 40 | #define INIT_SZ 128 |
37 | 41 | ||
38 | int vasprintf(char **str, const char *fmt, va_list ap) | 42 | int |
43 | vasprintf(char **str, const char *fmt, va_list ap) | ||
39 | { | 44 | { |
40 | int ret = -1; | 45 | int ret = -1; |
41 | va_list ap2; | 46 | va_list ap2; |
@@ -49,7 +54,7 @@ int vasprintf(char **str, const char *fmt, va_list ap) | |||
49 | ret = vsnprintf(string, INIT_SZ, fmt, ap2); | 54 | ret = vsnprintf(string, INIT_SZ, fmt, ap2); |
50 | if (ret >= 0 && ret < INIT_SZ) { /* succeeded with initial alloc */ | 55 | if (ret >= 0 && ret < INIT_SZ) { /* succeeded with initial alloc */ |
51 | *str = string; | 56 | *str = string; |
52 | } else if (ret == INT_MAX) { /* shouldn't happen */ | 57 | } else if (ret == INT_MAX || ret < 0) { /* Bad length */ |
53 | goto fail; | 58 | goto fail; |
54 | } else { /* bigger than initial, realloc allowing for nul */ | 59 | } else { /* bigger than initial, realloc allowing for nul */ |
55 | len = (size_t)ret + 1; | 60 | len = (size_t)ret + 1; |
diff --git a/openbsd-compat/bsd-closefrom.c b/openbsd-compat/bsd-closefrom.c index 5b7b94ae4..9380b33a7 100644 --- a/openbsd-compat/bsd-closefrom.c +++ b/openbsd-compat/bsd-closefrom.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2004 Todd C. Miller <Todd.Miller@courtesan.com> | 2 | * Copyright (c) 2004-2005 Todd C. Miller <Todd.Miller@courtesan.com> |
3 | * | 3 | * |
4 | * Permission to use, copy, modify, and distribute this software for any | 4 | * Permission to use, copy, modify, and distribute this software for any |
5 | * purpose with or without fee is hereby granted, provided that the above | 5 | * purpose with or without fee is hereby granted, provided that the above |
@@ -22,9 +22,14 @@ | |||
22 | #include <sys/param.h> | 22 | #include <sys/param.h> |
23 | #include <unistd.h> | 23 | #include <unistd.h> |
24 | #include <stdio.h> | 24 | #include <stdio.h> |
25 | #ifdef HAVE_FCNTL_H | ||
26 | # include <fcntl.h> | ||
27 | #endif | ||
25 | #include <limits.h> | 28 | #include <limits.h> |
26 | #include <stdlib.h> | 29 | #include <stdlib.h> |
27 | #include <stddef.h> | 30 | #include <stddef.h> |
31 | #include <string.h> | ||
32 | #include <unistd.h> | ||
28 | #ifdef HAVE_DIRENT_H | 33 | #ifdef HAVE_DIRENT_H |
29 | # include <dirent.h> | 34 | # include <dirent.h> |
30 | # define NAMLEN(dirent) strlen((dirent)->d_name) | 35 | # define NAMLEN(dirent) strlen((dirent)->d_name) |
@@ -46,15 +51,20 @@ | |||
46 | # define OPEN_MAX 256 | 51 | # define OPEN_MAX 256 |
47 | #endif | 52 | #endif |
48 | 53 | ||
49 | RCSID("$Id: bsd-closefrom.c,v 1.2 2005/11/10 08:29:13 dtucker Exp $"); | 54 | #if 0 |
50 | 55 | __unused static const char rcsid[] = "$Sudo: closefrom.c,v 1.11 2006/08/17 15:26:54 millert Exp $"; | |
51 | #ifndef lint | ||
52 | static const char sudorcsid[] = "$Sudo: closefrom.c,v 1.6 2004/06/01 20:51:56 millert Exp $"; | ||
53 | #endif /* lint */ | 56 | #endif /* lint */ |
54 | 57 | ||
55 | /* | 58 | /* |
56 | * Close all file descriptors greater than or equal to lowfd. | 59 | * Close all file descriptors greater than or equal to lowfd. |
57 | */ | 60 | */ |
61 | #ifdef HAVE_FCNTL_CLOSEM | ||
62 | void | ||
63 | closefrom(int lowfd) | ||
64 | { | ||
65 | (void) fcntl(lowfd, F_CLOSEM, 0); | ||
66 | } | ||
67 | #else | ||
58 | void | 68 | void |
59 | closefrom(int lowfd) | 69 | closefrom(int lowfd) |
60 | { | 70 | { |
@@ -67,7 +77,7 @@ closefrom(int lowfd) | |||
67 | 77 | ||
68 | /* Check for a /proc/$$/fd directory. */ | 78 | /* Check for a /proc/$$/fd directory. */ |
69 | len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid()); | 79 | len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid()); |
70 | if (len >= 0 && (u_int)len <= sizeof(fdpath) && (dirp = opendir(fdpath))) { | 80 | if (len > 0 && (size_t)len <= sizeof(fdpath) && (dirp = opendir(fdpath))) { |
71 | while ((dent = readdir(dirp)) != NULL) { | 81 | while ((dent = readdir(dirp)) != NULL) { |
72 | fd = strtol(dent->d_name, &endp, 10); | 82 | fd = strtol(dent->d_name, &endp, 10); |
73 | if (dent->d_name != endp && *endp == '\0' && | 83 | if (dent->d_name != endp && *endp == '\0' && |
@@ -95,6 +105,5 @@ closefrom(int lowfd) | |||
95 | (void) close((int) fd); | 105 | (void) close((int) fd); |
96 | } | 106 | } |
97 | } | 107 | } |
98 | 108 | #endif /* !HAVE_FCNTL_CLOSEM */ | |
99 | #endif /* HAVE_CLOSEFROM */ | 109 | #endif /* HAVE_CLOSEFROM */ |
100 | |||
diff --git a/openbsd-compat/bsd-cray.c b/openbsd-compat/bsd-cray.c index d1f1c059c..1532c991c 100644 --- a/openbsd-compat/bsd-cray.c +++ b/openbsd-compat/bsd-cray.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * $Id: bsd-cray.c,v 1.14 2005/02/02 06:10:11 dtucker Exp $ | 2 | * $Id: bsd-cray.c,v 1.16 2006/09/01 05:38:41 djm Exp $ |
3 | * | 3 | * |
4 | * bsd-cray.c | 4 | * bsd-cray.c |
5 | * | 5 | * |
@@ -52,7 +52,10 @@ | |||
52 | #include <sys/secstat.h> | 52 | #include <sys/secstat.h> |
53 | #include <sys/stat.h> | 53 | #include <sys/stat.h> |
54 | #include <sys/session.h> | 54 | #include <sys/session.h> |
55 | #include <stdarg.h> | ||
55 | #include <stdlib.h> | 56 | #include <stdlib.h> |
57 | #include <string.h> | ||
58 | #include <unistd.h> | ||
56 | #include <pwd.h> | 59 | #include <pwd.h> |
57 | #include <fcntl.h> | 60 | #include <fcntl.h> |
58 | #include <errno.h> | 61 | #include <errno.h> |
diff --git a/openbsd-compat/bsd-cygwin_util.c b/openbsd-compat/bsd-cygwin_util.c index b5e3cc52b..dbf8176b6 100644 --- a/openbsd-compat/bsd-cygwin_util.c +++ b/openbsd-compat/bsd-cygwin_util.c | |||
@@ -29,15 +29,25 @@ | |||
29 | 29 | ||
30 | #include "includes.h" | 30 | #include "includes.h" |
31 | 31 | ||
32 | RCSID("$Id: bsd-cygwin_util.c,v 1.14 2005/05/25 09:42:11 dtucker Exp $"); | ||
33 | |||
34 | #ifdef HAVE_CYGWIN | 32 | #ifdef HAVE_CYGWIN |
35 | 33 | ||
36 | #include <fcntl.h> | 34 | #if defined(open) && open == binary_open |
37 | #include <stdlib.h> | 35 | # undef open |
36 | #endif | ||
37 | #if defined(pipe) && open == binary_pipe | ||
38 | # undef pipe | ||
39 | #endif | ||
40 | |||
41 | #include <sys/types.h> | ||
42 | #include <sys/stat.h> | ||
38 | #include <sys/utsname.h> | 43 | #include <sys/utsname.h> |
39 | #include <sys/vfs.h> | 44 | #include <sys/vfs.h> |
45 | |||
46 | #include <fcntl.h> | ||
47 | #include <stdlib.h> | ||
48 | #include <unistd.h> | ||
40 | #include <windows.h> | 49 | #include <windows.h> |
50 | |||
41 | #include "xmalloc.h" | 51 | #include "xmalloc.h" |
42 | #define is_winnt (GetVersion() < 0x80000000) | 52 | #define is_winnt (GetVersion() < 0x80000000) |
43 | 53 | ||
@@ -45,13 +55,6 @@ RCSID("$Id: bsd-cygwin_util.c,v 1.14 2005/05/25 09:42:11 dtucker Exp $"); | |||
45 | #define ntsec_off(c) ((c) && strstr((c),"nontsec")) | 55 | #define ntsec_off(c) ((c) && strstr((c),"nontsec")) |
46 | #define ntea_on(c) ((c) && strstr((c),"ntea") && !strstr((c),"nontea")) | 56 | #define ntea_on(c) ((c) && strstr((c),"ntea") && !strstr((c),"nontea")) |
47 | 57 | ||
48 | #if defined(open) && open == binary_open | ||
49 | # undef open | ||
50 | #endif | ||
51 | #if defined(pipe) && open == binary_pipe | ||
52 | # undef pipe | ||
53 | #endif | ||
54 | |||
55 | int | 58 | int |
56 | binary_open(const char *filename, int flags, ...) | 59 | binary_open(const char *filename, int flags, ...) |
57 | { | 60 | { |
@@ -268,9 +271,9 @@ char ** | |||
268 | fetch_windows_environment(void) | 271 | fetch_windows_environment(void) |
269 | { | 272 | { |
270 | char **e, **p; | 273 | char **e, **p; |
271 | int i, idx = 0; | 274 | unsigned int i, idx = 0; |
272 | 275 | ||
273 | p = xmalloc((WENV_SIZ + 1) * sizeof(char *)); | 276 | p = xcalloc(WENV_SIZ + 1, sizeof(char *)); |
274 | for (e = environ; *e != NULL; ++e) { | 277 | for (e = environ; *e != NULL; ++e) { |
275 | for (i = 0; i < WENV_SIZ; ++i) { | 278 | for (i = 0; i < WENV_SIZ; ++i) { |
276 | if (!strncmp(*e, wenv_arr[i].name, wenv_arr[i].namelen)) | 279 | if (!strncmp(*e, wenv_arr[i].name, wenv_arr[i].namelen)) |
diff --git a/openbsd-compat/bsd-getpeereid.c b/openbsd-compat/bsd-getpeereid.c index fe2edad71..bdae8b637 100644 --- a/openbsd-compat/bsd-getpeereid.c +++ b/openbsd-compat/bsd-getpeereid.c | |||
@@ -16,10 +16,13 @@ | |||
16 | 16 | ||
17 | #include "includes.h" | 17 | #include "includes.h" |
18 | 18 | ||
19 | RCSID("$Id: bsd-getpeereid.c,v 1.3 2004/02/17 05:49:55 djm Exp $"); | ||
20 | |||
21 | #if !defined(HAVE_GETPEEREID) | 19 | #if !defined(HAVE_GETPEEREID) |
22 | 20 | ||
21 | #include <sys/types.h> | ||
22 | #include <sys/socket.h> | ||
23 | |||
24 | #include <unistd.h> | ||
25 | |||
23 | #if defined(SO_PEERCRED) | 26 | #if defined(SO_PEERCRED) |
24 | int | 27 | int |
25 | getpeereid(int s, uid_t *euid, gid_t *gid) | 28 | getpeereid(int s, uid_t *euid, gid_t *gid) |
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index d32b054d7..17d731bd2 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c | |||
@@ -16,9 +16,19 @@ | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "includes.h" | 18 | #include "includes.h" |
19 | #include "xmalloc.h" | ||
20 | 19 | ||
21 | RCSID("$Id: bsd-misc.c,v 1.28 2005/11/01 22:07:31 dtucker Exp $"); | 20 | #ifdef HAVE_SYS_SELECT_H |
21 | # include <sys/select.h> | ||
22 | #endif | ||
23 | #ifdef HAVE_SYS_TIME_H | ||
24 | # include <sys/time.h> | ||
25 | #endif | ||
26 | |||
27 | #include <string.h> | ||
28 | #include <signal.h> | ||
29 | #include <stdlib.h> | ||
30 | |||
31 | #include "xmalloc.h" | ||
22 | 32 | ||
23 | #ifndef HAVE___PROGNAME | 33 | #ifndef HAVE___PROGNAME |
24 | char *__progname; | 34 | char *__progname; |
diff --git a/openbsd-compat/bsd-nextstep.c b/openbsd-compat/bsd-nextstep.c index bd35a3afc..8195af88a 100644 --- a/openbsd-compat/bsd-nextstep.c +++ b/openbsd-compat/bsd-nextstep.c | |||
@@ -24,8 +24,6 @@ | |||
24 | 24 | ||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | 26 | ||
27 | RCSID("$Id: bsd-nextstep.c,v 1.6 2003/06/01 03:23:57 mouring Exp $"); | ||
28 | |||
29 | #ifdef HAVE_NEXT | 27 | #ifdef HAVE_NEXT |
30 | #include <errno.h> | 28 | #include <errno.h> |
31 | #include <sys/wait.h> | 29 | #include <sys/wait.h> |
diff --git a/openbsd-compat/bsd-openpty.c b/openbsd-compat/bsd-openpty.c index 8eb62b7a8..9777eb556 100644 --- a/openbsd-compat/bsd-openpty.c +++ b/openbsd-compat/bsd-openpty.c | |||
@@ -35,6 +35,21 @@ | |||
35 | #include "includes.h" | 35 | #include "includes.h" |
36 | #if !defined(HAVE_OPENPTY) | 36 | #if !defined(HAVE_OPENPTY) |
37 | 37 | ||
38 | #include <sys/types.h> | ||
39 | |||
40 | #include <stdlib.h> | ||
41 | |||
42 | #ifdef HAVE_SYS_STAT_H | ||
43 | # include <sys/stat.h> | ||
44 | #endif | ||
45 | #ifdef HAVE_SYS_IOCTL_H | ||
46 | # include <sys/ioctl.h> | ||
47 | #endif | ||
48 | |||
49 | #ifdef HAVE_FCNTL_H | ||
50 | # include <fcntl.h> | ||
51 | #endif | ||
52 | |||
38 | #ifdef HAVE_UTIL_H | 53 | #ifdef HAVE_UTIL_H |
39 | # include <util.h> | 54 | # include <util.h> |
40 | #endif /* HAVE_UTIL_H */ | 55 | #endif /* HAVE_UTIL_H */ |
@@ -46,6 +61,10 @@ | |||
46 | # include <sys/stropts.h> | 61 | # include <sys/stropts.h> |
47 | #endif | 62 | #endif |
48 | 63 | ||
64 | #include <signal.h> | ||
65 | #include <string.h> | ||
66 | #include <unistd.h> | ||
67 | |||
49 | #ifndef O_NOCTTY | 68 | #ifndef O_NOCTTY |
50 | #define O_NOCTTY 0 | 69 | #define O_NOCTTY 0 |
51 | #endif | 70 | #endif |
diff --git a/openbsd-compat/bsd-snprintf.c b/openbsd-compat/bsd-snprintf.c index e4ba154fd..41d2be238 100644 --- a/openbsd-compat/bsd-snprintf.c +++ b/openbsd-compat/bsd-snprintf.c | |||
@@ -85,12 +85,15 @@ | |||
85 | * | 85 | * |
86 | * Move #endif to make sure VA_COPY, LDOUBLE, etc are defined even | 86 | * Move #endif to make sure VA_COPY, LDOUBLE, etc are defined even |
87 | * if the C library has some snprintf functions already. | 87 | * if the C library has some snprintf functions already. |
88 | * | ||
89 | * Damien Miller (djm@mindrot.org) Jan 2007 | ||
90 | * Fix integer overflows in return value. | ||
91 | * Make formatting quite a bit faster by inlining dopr_outch() | ||
92 | * | ||
88 | **************************************************************/ | 93 | **************************************************************/ |
89 | 94 | ||
90 | #include "includes.h" | 95 | #include "includes.h" |
91 | 96 | ||
92 | RCSID("$Id: bsd-snprintf.c,v 1.11 2005/12/17 11:32:04 dtucker Exp $"); | ||
93 | |||
94 | #if defined(BROKEN_SNPRINTF) /* For those with broken snprintf() */ | 97 | #if defined(BROKEN_SNPRINTF) /* For those with broken snprintf() */ |
95 | # undef HAVE_SNPRINTF | 98 | # undef HAVE_SNPRINTF |
96 | # undef HAVE_VSNPRINTF | 99 | # undef HAVE_VSNPRINTF |
@@ -110,6 +113,13 @@ RCSID("$Id: bsd-snprintf.c,v 1.11 2005/12/17 11:32:04 dtucker Exp $"); | |||
110 | 113 | ||
111 | #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) | 114 | #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) |
112 | 115 | ||
116 | #include <ctype.h> | ||
117 | #include <stdarg.h> | ||
118 | #include <stdlib.h> | ||
119 | #include <string.h> | ||
120 | #include <limits.h> | ||
121 | #include <errno.h> | ||
122 | |||
113 | #ifdef HAVE_LONG_DOUBLE | 123 | #ifdef HAVE_LONG_DOUBLE |
114 | # define LDOUBLE long double | 124 | # define LDOUBLE long double |
115 | #else | 125 | #else |
@@ -156,17 +166,28 @@ RCSID("$Id: bsd-snprintf.c,v 1.11 2005/12/17 11:32:04 dtucker Exp $"); | |||
156 | # define MAX(p,q) (((p) >= (q)) ? (p) : (q)) | 166 | # define MAX(p,q) (((p) >= (q)) ? (p) : (q)) |
157 | #endif | 167 | #endif |
158 | 168 | ||
159 | static size_t dopr(char *buffer, size_t maxlen, const char *format, | 169 | #define DOPR_OUTCH(buf, pos, buflen, thechar) \ |
160 | va_list args_in); | 170 | do { \ |
161 | static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, | 171 | if (pos + 1 >= INT_MAX) { \ |
162 | char *value, int flags, int min, int max); | 172 | errno = ERANGE; \ |
163 | static void fmtint(char *buffer, size_t *currlen, size_t maxlen, | 173 | return -1; \ |
164 | long value, int base, int min, int max, int flags); | 174 | } \ |
165 | static void fmtfp(char *buffer, size_t *currlen, size_t maxlen, | 175 | if (pos < buflen) \ |
166 | LDOUBLE fvalue, int min, int max, int flags); | 176 | buf[pos] = thechar; \ |
167 | static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c); | 177 | (pos)++; \ |
168 | 178 | } while (0) | |
169 | static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) | 179 | |
180 | static int dopr(char *buffer, size_t maxlen, const char *format, | ||
181 | va_list args_in); | ||
182 | static int fmtstr(char *buffer, size_t *currlen, size_t maxlen, | ||
183 | char *value, int flags, int min, int max); | ||
184 | static int fmtint(char *buffer, size_t *currlen, size_t maxlen, | ||
185 | LLONG value, int base, int min, int max, int flags); | ||
186 | static int fmtfp(char *buffer, size_t *currlen, size_t maxlen, | ||
187 | LDOUBLE fvalue, int min, int max, int flags); | ||
188 | |||
189 | static int | ||
190 | dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) | ||
170 | { | 191 | { |
171 | char ch; | 192 | char ch; |
172 | LLONG value; | 193 | LLONG value; |
@@ -195,8 +216,8 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args | |||
195 | case DP_S_DEFAULT: | 216 | case DP_S_DEFAULT: |
196 | if (ch == '%') | 217 | if (ch == '%') |
197 | state = DP_S_FLAGS; | 218 | state = DP_S_FLAGS; |
198 | else | 219 | else |
199 | dopr_outch (buffer, &currlen, maxlen, ch); | 220 | DOPR_OUTCH(buffer, currlen, maxlen, ch); |
200 | ch = *format++; | 221 | ch = *format++; |
201 | break; | 222 | break; |
202 | case DP_S_FLAGS: | 223 | case DP_S_FLAGS: |
@@ -295,7 +316,9 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args | |||
295 | value = va_arg (args, LLONG); | 316 | value = va_arg (args, LLONG); |
296 | else | 317 | else |
297 | value = va_arg (args, int); | 318 | value = va_arg (args, int); |
298 | fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags); | 319 | if (fmtint(buffer, &currlen, maxlen, |
320 | value, 10, min, max, flags) == -1) | ||
321 | return -1; | ||
299 | break; | 322 | break; |
300 | case 'o': | 323 | case 'o': |
301 | flags |= DP_F_UNSIGNED; | 324 | flags |= DP_F_UNSIGNED; |
@@ -307,7 +330,9 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args | |||
307 | value = (long)va_arg (args, unsigned LLONG); | 330 | value = (long)va_arg (args, unsigned LLONG); |
308 | else | 331 | else |
309 | value = (long)va_arg (args, unsigned int); | 332 | value = (long)va_arg (args, unsigned int); |
310 | fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags); | 333 | if (fmtint(buffer, &currlen, maxlen, value, |
334 | 8, min, max, flags) == -1) | ||
335 | return -1; | ||
311 | break; | 336 | break; |
312 | case 'u': | 337 | case 'u': |
313 | flags |= DP_F_UNSIGNED; | 338 | flags |= DP_F_UNSIGNED; |
@@ -319,7 +344,9 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args | |||
319 | value = (LLONG)va_arg (args, unsigned LLONG); | 344 | value = (LLONG)va_arg (args, unsigned LLONG); |
320 | else | 345 | else |
321 | value = (long)va_arg (args, unsigned int); | 346 | value = (long)va_arg (args, unsigned int); |
322 | fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags); | 347 | if (fmtint(buffer, &currlen, maxlen, value, |
348 | 10, min, max, flags) == -1) | ||
349 | return -1; | ||
323 | break; | 350 | break; |
324 | case 'X': | 351 | case 'X': |
325 | flags |= DP_F_UP; | 352 | flags |= DP_F_UP; |
@@ -333,15 +360,18 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args | |||
333 | value = (LLONG)va_arg (args, unsigned LLONG); | 360 | value = (LLONG)va_arg (args, unsigned LLONG); |
334 | else | 361 | else |
335 | value = (long)va_arg (args, unsigned int); | 362 | value = (long)va_arg (args, unsigned int); |
336 | fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags); | 363 | if (fmtint(buffer, &currlen, maxlen, value, |
364 | 16, min, max, flags) == -1) | ||
365 | return -1; | ||
337 | break; | 366 | break; |
338 | case 'f': | 367 | case 'f': |
339 | if (cflags == DP_C_LDOUBLE) | 368 | if (cflags == DP_C_LDOUBLE) |
340 | fvalue = va_arg (args, LDOUBLE); | 369 | fvalue = va_arg (args, LDOUBLE); |
341 | else | 370 | else |
342 | fvalue = va_arg (args, double); | 371 | fvalue = va_arg (args, double); |
343 | /* um, floating point? */ | 372 | if (fmtfp(buffer, &currlen, maxlen, fvalue, |
344 | fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags); | 373 | min, max, flags) == -1) |
374 | return -1; | ||
345 | break; | 375 | break; |
346 | case 'E': | 376 | case 'E': |
347 | flags |= DP_F_UP; | 377 | flags |= DP_F_UP; |
@@ -350,7 +380,9 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args | |||
350 | fvalue = va_arg (args, LDOUBLE); | 380 | fvalue = va_arg (args, LDOUBLE); |
351 | else | 381 | else |
352 | fvalue = va_arg (args, double); | 382 | fvalue = va_arg (args, double); |
353 | fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags); | 383 | if (fmtfp(buffer, &currlen, maxlen, fvalue, |
384 | min, max, flags) == -1) | ||
385 | return -1; | ||
354 | break; | 386 | break; |
355 | case 'G': | 387 | case 'G': |
356 | flags |= DP_F_UP; | 388 | flags |= DP_F_UP; |
@@ -359,10 +391,13 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args | |||
359 | fvalue = va_arg (args, LDOUBLE); | 391 | fvalue = va_arg (args, LDOUBLE); |
360 | else | 392 | else |
361 | fvalue = va_arg (args, double); | 393 | fvalue = va_arg (args, double); |
362 | fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags); | 394 | if (fmtfp(buffer, &currlen, maxlen, fvalue, |
395 | min, max, flags) == -1) | ||
396 | return -1; | ||
363 | break; | 397 | break; |
364 | case 'c': | 398 | case 'c': |
365 | dopr_outch (buffer, &currlen, maxlen, va_arg (args, int)); | 399 | DOPR_OUTCH(buffer, currlen, maxlen, |
400 | va_arg (args, int)); | ||
366 | break; | 401 | break; |
367 | case 's': | 402 | case 's': |
368 | strvalue = va_arg (args, char *); | 403 | strvalue = va_arg (args, char *); |
@@ -371,11 +406,15 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args | |||
371 | max = strlen(strvalue); | 406 | max = strlen(strvalue); |
372 | } | 407 | } |
373 | if (min > 0 && max >= 0 && min > max) max = min; | 408 | if (min > 0 && max >= 0 && min > max) max = min; |
374 | fmtstr (buffer, &currlen, maxlen, strvalue, flags, min, max); | 409 | if (fmtstr(buffer, &currlen, maxlen, |
410 | strvalue, flags, min, max) == -1) | ||
411 | return -1; | ||
375 | break; | 412 | break; |
376 | case 'p': | 413 | case 'p': |
377 | strvalue = va_arg (args, void *); | 414 | strvalue = va_arg (args, void *); |
378 | fmtint (buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags); | 415 | if (fmtint(buffer, &currlen, maxlen, |
416 | (long) strvalue, 16, min, max, flags) == -1) | ||
417 | return -1; | ||
379 | break; | 418 | break; |
380 | case 'n': | 419 | case 'n': |
381 | if (cflags == DP_C_SHORT) { | 420 | if (cflags == DP_C_SHORT) { |
@@ -397,7 +436,7 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args | |||
397 | } | 436 | } |
398 | break; | 437 | break; |
399 | case '%': | 438 | case '%': |
400 | dopr_outch (buffer, &currlen, maxlen, ch); | 439 | DOPR_OUTCH(buffer, currlen, maxlen, ch); |
401 | break; | 440 | break; |
402 | case 'w': | 441 | case 'w': |
403 | /* not supported yet, treat as next char */ | 442 | /* not supported yet, treat as next char */ |
@@ -426,11 +465,12 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args | |||
426 | buffer[maxlen - 1] = '\0'; | 465 | buffer[maxlen - 1] = '\0'; |
427 | } | 466 | } |
428 | 467 | ||
429 | return currlen; | 468 | return currlen < INT_MAX ? (int)currlen : -1; |
430 | } | 469 | } |
431 | 470 | ||
432 | static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, | 471 | static int |
433 | char *value, int flags, int min, int max) | 472 | fmtstr(char *buffer, size_t *currlen, size_t maxlen, |
473 | char *value, int flags, int min, int max) | ||
434 | { | 474 | { |
435 | int padlen, strln; /* amount to pad */ | 475 | int padlen, strln; /* amount to pad */ |
436 | int cnt = 0; | 476 | int cnt = 0; |
@@ -450,28 +490,31 @@ static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, | |||
450 | padlen = -padlen; /* Left Justify */ | 490 | padlen = -padlen; /* Left Justify */ |
451 | 491 | ||
452 | while ((padlen > 0) && (cnt < max)) { | 492 | while ((padlen > 0) && (cnt < max)) { |
453 | dopr_outch (buffer, currlen, maxlen, ' '); | 493 | DOPR_OUTCH(buffer, *currlen, maxlen, ' '); |
454 | --padlen; | 494 | --padlen; |
455 | ++cnt; | 495 | ++cnt; |
456 | } | 496 | } |
457 | while (*value && (cnt < max)) { | 497 | while (*value && (cnt < max)) { |
458 | dopr_outch (buffer, currlen, maxlen, *value++); | 498 | DOPR_OUTCH(buffer, *currlen, maxlen, *value); |
499 | *value++; | ||
459 | ++cnt; | 500 | ++cnt; |
460 | } | 501 | } |
461 | while ((padlen < 0) && (cnt < max)) { | 502 | while ((padlen < 0) && (cnt < max)) { |
462 | dopr_outch (buffer, currlen, maxlen, ' '); | 503 | DOPR_OUTCH(buffer, *currlen, maxlen, ' '); |
463 | ++padlen; | 504 | ++padlen; |
464 | ++cnt; | 505 | ++cnt; |
465 | } | 506 | } |
507 | return 0; | ||
466 | } | 508 | } |
467 | 509 | ||
468 | /* Have to handle DP_F_NUM (ie 0x and 0 alternates) */ | 510 | /* Have to handle DP_F_NUM (ie 0x and 0 alternates) */ |
469 | 511 | ||
470 | static void fmtint(char *buffer, size_t *currlen, size_t maxlen, | 512 | static int |
471 | long value, int base, int min, int max, int flags) | 513 | fmtint(char *buffer, size_t *currlen, size_t maxlen, |
514 | LLONG value, int base, int min, int max, int flags) | ||
472 | { | 515 | { |
473 | int signvalue = 0; | 516 | int signvalue = 0; |
474 | unsigned long uvalue; | 517 | unsigned LLONG uvalue; |
475 | char convert[20]; | 518 | char convert[20]; |
476 | int place = 0; | 519 | int place = 0; |
477 | int spadlen = 0; /* amount to space pad */ | 520 | int spadlen = 0; /* amount to space pad */ |
@@ -524,31 +567,34 @@ static void fmtint(char *buffer, size_t *currlen, size_t maxlen, | |||
524 | 567 | ||
525 | /* Spaces */ | 568 | /* Spaces */ |
526 | while (spadlen > 0) { | 569 | while (spadlen > 0) { |
527 | dopr_outch (buffer, currlen, maxlen, ' '); | 570 | DOPR_OUTCH(buffer, *currlen, maxlen, ' '); |
528 | --spadlen; | 571 | --spadlen; |
529 | } | 572 | } |
530 | 573 | ||
531 | /* Sign */ | 574 | /* Sign */ |
532 | if (signvalue) | 575 | if (signvalue) |
533 | dopr_outch (buffer, currlen, maxlen, signvalue); | 576 | DOPR_OUTCH(buffer, *currlen, maxlen, signvalue); |
534 | 577 | ||
535 | /* Zeros */ | 578 | /* Zeros */ |
536 | if (zpadlen > 0) { | 579 | if (zpadlen > 0) { |
537 | while (zpadlen > 0) { | 580 | while (zpadlen > 0) { |
538 | dopr_outch (buffer, currlen, maxlen, '0'); | 581 | DOPR_OUTCH(buffer, *currlen, maxlen, '0'); |
539 | --zpadlen; | 582 | --zpadlen; |
540 | } | 583 | } |
541 | } | 584 | } |
542 | 585 | ||
543 | /* Digits */ | 586 | /* Digits */ |
544 | while (place > 0) | 587 | while (place > 0) { |
545 | dopr_outch (buffer, currlen, maxlen, convert[--place]); | 588 | --place; |
589 | DOPR_OUTCH(buffer, *currlen, maxlen, convert[place]); | ||
590 | } | ||
546 | 591 | ||
547 | /* Left Justified spaces */ | 592 | /* Left Justified spaces */ |
548 | while (spadlen < 0) { | 593 | while (spadlen < 0) { |
549 | dopr_outch (buffer, currlen, maxlen, ' '); | 594 | DOPR_OUTCH(buffer, *currlen, maxlen, ' '); |
550 | ++spadlen; | 595 | ++spadlen; |
551 | } | 596 | } |
597 | return 0; | ||
552 | } | 598 | } |
553 | 599 | ||
554 | static LDOUBLE abs_val(LDOUBLE value) | 600 | static LDOUBLE abs_val(LDOUBLE value) |
@@ -561,13 +607,13 @@ static LDOUBLE abs_val(LDOUBLE value) | |||
561 | return result; | 607 | return result; |
562 | } | 608 | } |
563 | 609 | ||
564 | static LDOUBLE POW10(int exp) | 610 | static LDOUBLE POW10(int val) |
565 | { | 611 | { |
566 | LDOUBLE result = 1; | 612 | LDOUBLE result = 1; |
567 | 613 | ||
568 | while (exp) { | 614 | while (val) { |
569 | result *= 10; | 615 | result *= 10; |
570 | exp--; | 616 | val--; |
571 | } | 617 | } |
572 | 618 | ||
573 | return result; | 619 | return result; |
@@ -601,7 +647,10 @@ static double my_modf(double x0, double *iptr) | |||
601 | } | 647 | } |
602 | 648 | ||
603 | if (i == 100) { | 649 | if (i == 100) { |
604 | /* yikes! the number is beyond what we can handle. What do we do? */ | 650 | /* |
651 | * yikes! the number is beyond what we can handle. | ||
652 | * What do we do? | ||
653 | */ | ||
605 | (*iptr) = 0; | 654 | (*iptr) = 0; |
606 | return 0; | 655 | return 0; |
607 | } | 656 | } |
@@ -620,8 +669,9 @@ static double my_modf(double x0, double *iptr) | |||
620 | } | 669 | } |
621 | 670 | ||
622 | 671 | ||
623 | static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, | 672 | static int |
624 | LDOUBLE fvalue, int min, int max, int flags) | 673 | fmtfp (char *buffer, size_t *currlen, size_t maxlen, |
674 | LDOUBLE fvalue, int min, int max, int flags) | ||
625 | { | 675 | { |
626 | int signvalue = 0; | 676 | int signvalue = 0; |
627 | double ufvalue; | 677 | double ufvalue; |
@@ -726,24 +776,26 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, | |||
726 | 776 | ||
727 | if ((flags & DP_F_ZERO) && (padlen > 0)) { | 777 | if ((flags & DP_F_ZERO) && (padlen > 0)) { |
728 | if (signvalue) { | 778 | if (signvalue) { |
729 | dopr_outch (buffer, currlen, maxlen, signvalue); | 779 | DOPR_OUTCH(buffer, *currlen, maxlen, signvalue); |
730 | --padlen; | 780 | --padlen; |
731 | signvalue = 0; | 781 | signvalue = 0; |
732 | } | 782 | } |
733 | while (padlen > 0) { | 783 | while (padlen > 0) { |
734 | dopr_outch (buffer, currlen, maxlen, '0'); | 784 | DOPR_OUTCH(buffer, *currlen, maxlen, '0'); |
735 | --padlen; | 785 | --padlen; |
736 | } | 786 | } |
737 | } | 787 | } |
738 | while (padlen > 0) { | 788 | while (padlen > 0) { |
739 | dopr_outch (buffer, currlen, maxlen, ' '); | 789 | DOPR_OUTCH(buffer, *currlen, maxlen, ' '); |
740 | --padlen; | 790 | --padlen; |
741 | } | 791 | } |
742 | if (signvalue) | 792 | if (signvalue) |
743 | dopr_outch (buffer, currlen, maxlen, signvalue); | 793 | DOPR_OUTCH(buffer, *currlen, maxlen, signvalue); |
744 | 794 | ||
745 | while (iplace > 0) | 795 | while (iplace > 0) { |
746 | dopr_outch (buffer, currlen, maxlen, iconvert[--iplace]); | 796 | --iplace; |
797 | DOPR_OUTCH(buffer, *currlen, maxlen, iconvert[iplace]); | ||
798 | } | ||
747 | 799 | ||
748 | #ifdef DEBUG_SNPRINTF | 800 | #ifdef DEBUG_SNPRINTF |
749 | printf("fmtfp: fplace=%d zpadlen=%d\n", fplace, zpadlen); | 801 | printf("fmtfp: fplace=%d zpadlen=%d\n", fplace, zpadlen); |
@@ -754,41 +806,38 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, | |||
754 | * char to print out. | 806 | * char to print out. |
755 | */ | 807 | */ |
756 | if (max > 0) { | 808 | if (max > 0) { |
757 | dopr_outch (buffer, currlen, maxlen, '.'); | 809 | DOPR_OUTCH(buffer, *currlen, maxlen, '.'); |
758 | 810 | ||
759 | while (zpadlen > 0) { | 811 | while (zpadlen > 0) { |
760 | dopr_outch (buffer, currlen, maxlen, '0'); | 812 | DOPR_OUTCH(buffer, *currlen, maxlen, '0'); |
761 | --zpadlen; | 813 | --zpadlen; |
762 | } | 814 | } |
763 | 815 | ||
764 | while (fplace > 0) | 816 | while (fplace > 0) { |
765 | dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]); | 817 | --fplace; |
818 | DOPR_OUTCH(buffer, *currlen, maxlen, fconvert[fplace]); | ||
819 | } | ||
766 | } | 820 | } |
767 | 821 | ||
768 | while (padlen < 0) { | 822 | while (padlen < 0) { |
769 | dopr_outch (buffer, currlen, maxlen, ' '); | 823 | DOPR_OUTCH(buffer, *currlen, maxlen, ' '); |
770 | ++padlen; | 824 | ++padlen; |
771 | } | 825 | } |
772 | } | 826 | return 0; |
773 | |||
774 | static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) | ||
775 | { | ||
776 | if (*currlen < maxlen) { | ||
777 | buffer[(*currlen)] = c; | ||
778 | } | ||
779 | (*currlen)++; | ||
780 | } | 827 | } |
781 | #endif /* !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) */ | 828 | #endif /* !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) */ |
782 | 829 | ||
783 | #if !defined(HAVE_VSNPRINTF) | 830 | #if !defined(HAVE_VSNPRINTF) |
784 | int vsnprintf (char *str, size_t count, const char *fmt, va_list args) | 831 | int |
832 | vsnprintf (char *str, size_t count, const char *fmt, va_list args) | ||
785 | { | 833 | { |
786 | return dopr(str, count, fmt, args); | 834 | return dopr(str, count, fmt, args); |
787 | } | 835 | } |
788 | #endif | 836 | #endif |
789 | 837 | ||
790 | #if !defined(HAVE_SNPRINTF) | 838 | #if !defined(HAVE_SNPRINTF) |
791 | int snprintf(char *str, size_t count, SNPRINTF_CONST char *fmt, ...) | 839 | int |
840 | snprintf(char *str, size_t count, SNPRINTF_CONST char *fmt, ...) | ||
792 | { | 841 | { |
793 | size_t ret; | 842 | size_t ret; |
794 | va_list ap; | 843 | va_list ap; |
@@ -799,4 +848,3 @@ int snprintf(char *str, size_t count, SNPRINTF_CONST char *fmt, ...) | |||
799 | return ret; | 848 | return ret; |
800 | } | 849 | } |
801 | #endif | 850 | #endif |
802 | |||
diff --git a/openbsd-compat/bsd-waitpid.c b/openbsd-compat/bsd-waitpid.c index 93c9ec35e..40e6ffaa8 100644 --- a/openbsd-compat/bsd-waitpid.c +++ b/openbsd-compat/bsd-waitpid.c | |||
@@ -24,8 +24,6 @@ | |||
24 | 24 | ||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | 26 | ||
27 | RCSID("$Id: bsd-waitpid.c,v 1.5 2003/06/01 03:23:57 mouring Exp $"); | ||
28 | |||
29 | #ifndef HAVE_WAITPID | 27 | #ifndef HAVE_WAITPID |
30 | #include <errno.h> | 28 | #include <errno.h> |
31 | #include <sys/wait.h> | 29 | #include <sys/wait.h> |
diff --git a/openbsd-compat/daemon.c b/openbsd-compat/daemon.c index f8a0680bf..e3a6886bd 100644 --- a/openbsd-compat/daemon.c +++ b/openbsd-compat/daemon.c | |||
@@ -34,6 +34,20 @@ | |||
34 | 34 | ||
35 | #ifndef HAVE_DAEMON | 35 | #ifndef HAVE_DAEMON |
36 | 36 | ||
37 | #include <sys/types.h> | ||
38 | |||
39 | #ifdef HAVE_SYS_STAT_H | ||
40 | # include <sys/stat.h> | ||
41 | #endif | ||
42 | |||
43 | #ifdef HAVE_FCNTL_H | ||
44 | # include <fcntl.h> | ||
45 | #endif | ||
46 | |||
47 | #ifdef HAVE_UNISTD_H | ||
48 | # include <unistd.h> | ||
49 | #endif | ||
50 | |||
37 | int | 51 | int |
38 | daemon(int nochdir, int noclose) | 52 | daemon(int nochdir, int noclose) |
39 | { | 53 | { |
diff --git a/openbsd-compat/fake-rfc2553.c b/openbsd-compat/fake-rfc2553.c index 0186b5300..b6ea3d21e 100644 --- a/openbsd-compat/fake-rfc2553.c +++ b/openbsd-compat/fake-rfc2553.c | |||
@@ -37,7 +37,11 @@ | |||
37 | 37 | ||
38 | #include "includes.h" | 38 | #include "includes.h" |
39 | 39 | ||
40 | RCSID("$Id: fake-rfc2553.c,v 1.5 2003/09/22 02:08:23 dtucker Exp $"); | 40 | #include <stdlib.h> |
41 | #include <string.h> | ||
42 | |||
43 | #include <netinet/in.h> | ||
44 | #include <arpa/inet.h> | ||
41 | 45 | ||
42 | #ifndef HAVE_GETNAMEINFO | 46 | #ifndef HAVE_GETNAMEINFO |
43 | int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, | 47 | int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, |
diff --git a/openbsd-compat/fake-rfc2553.h b/openbsd-compat/fake-rfc2553.h index cbcf7f727..5c2ce5b1b 100644 --- a/openbsd-compat/fake-rfc2553.h +++ b/openbsd-compat/fake-rfc2553.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: fake-rfc2553.h,v 1.12 2005/08/03 05:36:21 dtucker Exp $ */ | 1 | /* $Id: fake-rfc2553.h,v 1.13 2006/07/24 03:51:52 djm Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (C) 2000-2003 Damien Miller. All rights reserved. | 4 | * Copyright (C) 2000-2003 Damien Miller. All rights reserved. |
@@ -41,7 +41,10 @@ | |||
41 | #define _FAKE_RFC2553_H | 41 | #define _FAKE_RFC2553_H |
42 | 42 | ||
43 | #include "includes.h" | 43 | #include "includes.h" |
44 | #include "sys/types.h" | 44 | #include <sys/types.h> |
45 | #if defined(HAVE_NETDB_H) | ||
46 | # include <netdb.h> | ||
47 | #endif | ||
45 | 48 | ||
46 | /* | 49 | /* |
47 | * First, socket and INET6 related definitions | 50 | * First, socket and INET6 related definitions |
diff --git a/openbsd-compat/getrrsetbyname.c b/openbsd-compat/getrrsetbyname.c index bea6aea3b..07231d005 100644 --- a/openbsd-compat/getrrsetbyname.c +++ b/openbsd-compat/getrrsetbyname.c | |||
@@ -49,6 +49,12 @@ | |||
49 | 49 | ||
50 | #ifndef HAVE_GETRRSETBYNAME | 50 | #ifndef HAVE_GETRRSETBYNAME |
51 | 51 | ||
52 | #include <stdlib.h> | ||
53 | #include <string.h> | ||
54 | |||
55 | #include <netinet/in.h> | ||
56 | #include <arpa/inet.h> | ||
57 | |||
52 | #include "getrrsetbyname.h" | 58 | #include "getrrsetbyname.h" |
53 | 59 | ||
54 | #if defined(HAVE_DECL_H_ERRNO) && !HAVE_DECL_H_ERRNO | 60 | #if defined(HAVE_DECL_H_ERRNO) && !HAVE_DECL_H_ERRNO |
@@ -60,6 +66,13 @@ extern int h_errno; | |||
60 | # undef _THREAD_PRIVATE | 66 | # undef _THREAD_PRIVATE |
61 | #endif | 67 | #endif |
62 | #define _THREAD_PRIVATE(a,b,c) (c) | 68 | #define _THREAD_PRIVATE(a,b,c) (c) |
69 | |||
70 | /* to avoid conflicts where a platform already has _res */ | ||
71 | #ifdef _res | ||
72 | # undef _res | ||
73 | #endif | ||
74 | #define _res _compat_res | ||
75 | |||
63 | struct __res_state _res; | 76 | struct __res_state _res; |
64 | 77 | ||
65 | /* Necessary functions and macros */ | 78 | /* Necessary functions and macros */ |
@@ -290,10 +303,12 @@ getrrsetbyname(const char *hostname, unsigned int rdclass, | |||
290 | } | 303 | } |
291 | 304 | ||
292 | /* allocate memory for signatures */ | 305 | /* allocate memory for signatures */ |
293 | rrset->rri_sigs = calloc(rrset->rri_nsigs, sizeof(struct rdatainfo)); | 306 | if (rrset->rri_nsigs > 0) { |
294 | if (rrset->rri_sigs == NULL) { | 307 | rrset->rri_sigs = calloc(rrset->rri_nsigs, sizeof(struct rdatainfo)); |
295 | result = ERRSET_NOMEMORY; | 308 | if (rrset->rri_sigs == NULL) { |
296 | goto fail; | 309 | result = ERRSET_NOMEMORY; |
310 | goto fail; | ||
311 | } | ||
297 | } | 312 | } |
298 | 313 | ||
299 | /* copy answers & signatures */ | 314 | /* copy answers & signatures */ |
diff --git a/openbsd-compat/glob.c b/openbsd-compat/glob.c index f6a04ea3f..b3dd2b171 100644 --- a/openbsd-compat/glob.c +++ b/openbsd-compat/glob.c | |||
@@ -34,7 +34,21 @@ | |||
34 | /* OPENBSD ORIGINAL: lib/libc/gen/glob.c */ | 34 | /* OPENBSD ORIGINAL: lib/libc/gen/glob.c */ |
35 | 35 | ||
36 | #include "includes.h" | 36 | #include "includes.h" |
37 | |||
38 | #include <sys/types.h> | ||
39 | #include <sys/stat.h> | ||
40 | |||
41 | #include <dirent.h> | ||
37 | #include <ctype.h> | 42 | #include <ctype.h> |
43 | #include <errno.h> | ||
44 | #include <pwd.h> | ||
45 | #include <stdlib.h> | ||
46 | #include <string.h> | ||
47 | #include <unistd.h> | ||
48 | |||
49 | #if !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || \ | ||
50 | !defined(GLOB_HAS_GL_MATCHC) || \ | ||
51 | !defined(HAVE_DECL_GLOB_NOMATCH) || HAVE_DECL_GLOB_NOMATCH == 0 | ||
38 | 52 | ||
39 | static long | 53 | static long |
40 | get_arg_max(void) | 54 | get_arg_max(void) |
@@ -48,9 +62,6 @@ get_arg_max(void) | |||
48 | #endif | 62 | #endif |
49 | } | 63 | } |
50 | 64 | ||
51 | #if !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || \ | ||
52 | !defined(GLOB_HAS_GL_MATCHC) | ||
53 | |||
54 | /* | 65 | /* |
55 | * glob(3) -- a superset of the one defined in POSIX 1003.2. | 66 | * glob(3) -- a superset of the one defined in POSIX 1003.2. |
56 | * | 67 | * |
diff --git a/openbsd-compat/glob.h b/openbsd-compat/glob.h index 4fdbfc1ea..9ba07f76e 100644 --- a/openbsd-compat/glob.h +++ b/openbsd-compat/glob.h | |||
@@ -38,7 +38,8 @@ | |||
38 | /* OPENBSD ORIGINAL: include/glob.h */ | 38 | /* OPENBSD ORIGINAL: include/glob.h */ |
39 | 39 | ||
40 | #if !defined(HAVE_GLOB_H) || !defined(GLOB_HAS_ALTDIRFUNC) || \ | 40 | #if !defined(HAVE_GLOB_H) || !defined(GLOB_HAS_ALTDIRFUNC) || \ |
41 | !defined(GLOB_HAS_GL_MATCHC) | 41 | !defined(GLOB_HAS_GL_MATCHC) || \ |
42 | !defined(HAVE_DECL_GLOB_NOMATCH) || HAVE_DECL_GLOB_NOMATCH == 0 | ||
42 | 43 | ||
43 | #ifndef _GLOB_H_ | 44 | #ifndef _GLOB_H_ |
44 | #define _GLOB_H_ | 45 | #define _GLOB_H_ |
diff --git a/openbsd-compat/mktemp.c b/openbsd-compat/mktemp.c index 88e04c520..2285c84df 100644 --- a/openbsd-compat/mktemp.c +++ b/openbsd-compat/mktemp.c | |||
@@ -35,6 +35,14 @@ | |||
35 | 35 | ||
36 | #include "includes.h" | 36 | #include "includes.h" |
37 | 37 | ||
38 | #include <sys/types.h> | ||
39 | #include <sys/stat.h> | ||
40 | |||
41 | #include <fcntl.h> | ||
42 | #include <ctype.h> | ||
43 | #include <errno.h> | ||
44 | #include <unistd.h> | ||
45 | |||
38 | #if !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP) | 46 | #if !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP) |
39 | 47 | ||
40 | static int _gettemp(char *, int *, int, int); | 48 | static int _gettemp(char *, int *, int, int); |
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h index 1a3027353..aac2e6cbc 100644 --- a/openbsd-compat/openbsd-compat.h +++ b/openbsd-compat/openbsd-compat.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: openbsd-compat.h,v 1.33 2005/12/31 05:33:37 djm Exp $ */ | 1 | /* $Id: openbsd-compat.h,v 1.42 2006/09/03 12:44:50 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1999-2003 Damien Miller. All rights reserved. | 4 | * Copyright (c) 1999-2003 Damien Miller. All rights reserved. |
@@ -31,6 +31,11 @@ | |||
31 | 31 | ||
32 | #include "includes.h" | 32 | #include "includes.h" |
33 | 33 | ||
34 | #include <sys/types.h> | ||
35 | #include <pwd.h> | ||
36 | |||
37 | #include <sys/socket.h> | ||
38 | |||
34 | /* OpenBSD function replacements */ | 39 | /* OpenBSD function replacements */ |
35 | #include "base64.h" | 40 | #include "base64.h" |
36 | #include "sigact.h" | 41 | #include "sigact.h" |
@@ -38,7 +43,7 @@ | |||
38 | #include "readpassphrase.h" | 43 | #include "readpassphrase.h" |
39 | #include "vis.h" | 44 | #include "vis.h" |
40 | #include "getrrsetbyname.h" | 45 | #include "getrrsetbyname.h" |
41 | 46 | #include "sha2.h" | |
42 | 47 | ||
43 | #ifndef HAVE_BASENAME | 48 | #ifndef HAVE_BASENAME |
44 | char *basename(const char *path); | 49 | char *basename(const char *path); |
@@ -126,13 +131,16 @@ int getgrouplist(const char *, gid_t, gid_t *, int *); | |||
126 | int BSDgetopt(int argc, char * const *argv, const char *opts); | 131 | int BSDgetopt(int argc, char * const *argv, const char *opts); |
127 | #endif | 132 | #endif |
128 | 133 | ||
134 | #if defined(HAVE_DECL_WRITEV) && HAVE_DECL_WRITEV == 0 | ||
135 | # include <sys/types.h> | ||
136 | # include <sys/uio.h> | ||
137 | int writev(int, struct iovec *, int); | ||
138 | #endif | ||
129 | 139 | ||
130 | /* Home grown routines */ | 140 | /* Home grown routines */ |
131 | #include "bsd-misc.h" | 141 | #include "bsd-misc.h" |
132 | #include "bsd-waitpid.h" | 142 | #include "bsd-waitpid.h" |
133 | 143 | ||
134 | /*#include <sys/types.h> XXX Still needed? * For uid_t, gid_t * */ | ||
135 | |||
136 | #ifndef HAVE_GETPEEREID | 144 | #ifndef HAVE_GETPEEREID |
137 | int getpeereid(int , uid_t *, gid_t *); | 145 | int getpeereid(int , uid_t *, gid_t *); |
138 | #endif | 146 | #endif |
@@ -147,13 +155,14 @@ int asprintf(char **, const char *, ...); | |||
147 | #endif | 155 | #endif |
148 | 156 | ||
149 | #ifndef HAVE_OPENPTY | 157 | #ifndef HAVE_OPENPTY |
158 | # include <sys/ioctl.h> /* for struct winsize */ | ||
150 | int openpty(int *, int *, char *, struct termios *, struct winsize *); | 159 | int openpty(int *, int *, char *, struct termios *, struct winsize *); |
151 | #endif /* HAVE_OPENPTY */ | 160 | #endif /* HAVE_OPENPTY */ |
152 | 161 | ||
153 | /* #include <sys/types.h> XXX needed? For size_t */ | 162 | /* #include <sys/types.h> XXX needed? For size_t */ |
154 | 163 | ||
155 | #ifndef HAVE_SNPRINTF | 164 | #ifndef HAVE_SNPRINTF |
156 | int snprintf(char *, size_t, const char *, ...); | 165 | int snprintf(char *, size_t, SNPRINTF_CONST char *, ...); |
157 | #endif | 166 | #endif |
158 | 167 | ||
159 | #ifndef HAVE_STRTOLL | 168 | #ifndef HAVE_STRTOLL |
@@ -164,6 +173,10 @@ long long strtoll(const char *, char **, int); | |||
164 | long long strtonum(const char *, long long, long long, const char **); | 173 | long long strtonum(const char *, long long, long long, const char **); |
165 | #endif | 174 | #endif |
166 | 175 | ||
176 | #if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF) | ||
177 | # include <stdarg.h> | ||
178 | #endif | ||
179 | |||
167 | #ifndef HAVE_VASPRINTF | 180 | #ifndef HAVE_VASPRINTF |
168 | int vasprintf(char **, const char *, va_list); | 181 | int vasprintf(char **, const char *, va_list); |
169 | #endif | 182 | #endif |
@@ -176,16 +189,18 @@ void *xmmap(size_t size); | |||
176 | char *xcrypt(const char *password, const char *salt); | 189 | char *xcrypt(const char *password, const char *salt); |
177 | char *shadow_pw(struct passwd *pw); | 190 | char *shadow_pw(struct passwd *pw); |
178 | 191 | ||
179 | |||
180 | /* rfc2553 socket API replacements */ | 192 | /* rfc2553 socket API replacements */ |
181 | #include "fake-rfc2553.h" | 193 | #include "fake-rfc2553.h" |
182 | 194 | ||
183 | /* Routines for a single OS platform */ | 195 | /* Routines for a single OS platform */ |
184 | #include "bsd-cray.h" | 196 | #include "bsd-cray.h" |
185 | #include "bsd-cygwin_util.h" | 197 | #include "bsd-cygwin_util.h" |
186 | #include "port-irix.h" | 198 | |
187 | #include "port-aix.h" | 199 | #include "port-aix.h" |
188 | #include "port-uw.h" | 200 | #include "port-irix.h" |
201 | #include "port-linux.h" | ||
202 | #include "port-solaris.h" | ||
189 | #include "port-tun.h" | 203 | #include "port-tun.h" |
204 | #include "port-uw.h" | ||
190 | 205 | ||
191 | #endif /* _OPENBSD_COMPAT_H */ | 206 | #endif /* _OPENBSD_COMPAT_H */ |
diff --git a/openbsd-compat/openssl-compat.c b/openbsd-compat/openssl-compat.c index b690e8fe6..45ebd3f66 100644 --- a/openbsd-compat/openssl-compat.c +++ b/openbsd-compat/openssl-compat.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: openssl-compat.c,v 1.2 2005/06/17 11:15:21 dtucker Exp $ */ | 1 | /* $Id: openssl-compat.c,v 1.4 2006/02/22 11:24:47 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> | 4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> |
@@ -18,7 +18,11 @@ | |||
18 | 18 | ||
19 | #include "includes.h" | 19 | #include "includes.h" |
20 | 20 | ||
21 | #define SSH_DONT_REDEF_EVP | 21 | #ifdef USE_OPENSSL_ENGINE |
22 | # include <openssl/engine.h> | ||
23 | #endif | ||
24 | |||
25 | #define SSH_DONT_OVERLOAD_OPENSSL_FUNCS | ||
22 | #include "openssl-compat.h" | 26 | #include "openssl-compat.h" |
23 | 27 | ||
24 | #ifdef SSH_OLD_EVP | 28 | #ifdef SSH_OLD_EVP |
@@ -44,3 +48,15 @@ ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *evp) | |||
44 | return 1; | 48 | return 1; |
45 | } | 49 | } |
46 | #endif | 50 | #endif |
51 | |||
52 | #ifdef USE_OPENSSL_ENGINE | ||
53 | void | ||
54 | ssh_SSLeay_add_all_algorithms(void) | ||
55 | { | ||
56 | SSLeay_add_all_algorithms(); | ||
57 | |||
58 | /* Enable use of crypto hardware */ | ||
59 | ENGINE_load_builtin_engines(); | ||
60 | ENGINE_register_all_complete(); | ||
61 | } | ||
62 | #endif | ||
diff --git a/openbsd-compat/openssl-compat.h b/openbsd-compat/openssl-compat.h index 8a015ec43..9b5ccff5f 100644 --- a/openbsd-compat/openssl-compat.h +++ b/openbsd-compat/openssl-compat.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: openssl-compat.h,v 1.3 2005/12/19 06:40:40 dtucker Exp $ */ | 1 | /* $Id: openssl-compat.h,v 1.7 2007/03/05 07:25:20 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> | 4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> |
@@ -46,6 +46,11 @@ extern const EVP_CIPHER *evp_acss(void); | |||
46 | # endif | 46 | # endif |
47 | #endif | 47 | #endif |
48 | 48 | ||
49 | /* OpenSSL 0.9.8e returns cipher key len not context key len */ | ||
50 | #if (OPENSSL_VERSION_NUMBER == 0x0090805fL) | ||
51 | # define EVP_CIPHER_CTX_key_length(c) ((c)->key_len) | ||
52 | #endif | ||
53 | |||
49 | /* | 54 | /* |
50 | * We overload some of the OpenSSL crypto functions with ssh_* equivalents | 55 | * We overload some of the OpenSSL crypto functions with ssh_* equivalents |
51 | * which cater for older and/or less featureful OpenSSL version. | 56 | * which cater for older and/or less featureful OpenSSL version. |
@@ -54,21 +59,27 @@ extern const EVP_CIPHER *evp_acss(void); | |||
54 | * define SSH_DONT_OVERLOAD_OPENSSL_FUNCS before including this file and | 59 | * define SSH_DONT_OVERLOAD_OPENSSL_FUNCS before including this file and |
55 | * implement the ssh_* equivalents. | 60 | * implement the ssh_* equivalents. |
56 | */ | 61 | */ |
57 | #ifdef SSH_OLD_EVP | 62 | #ifndef SSH_DONT_OVERLOAD_OPENSSL_FUNCS |
58 | |||
59 | # ifndef SSH_DONT_REDEF_EVP | ||
60 | 63 | ||
64 | # ifdef SSH_OLD_EVP | ||
61 | # ifdef EVP_Cipher | 65 | # ifdef EVP_Cipher |
62 | # undef EVP_Cipher | 66 | # undef EVP_Cipher |
63 | # endif | 67 | # endif |
64 | |||
65 | # define EVP_CipherInit(a,b,c,d,e) ssh_EVP_CipherInit((a),(b),(c),(d),(e)) | 68 | # define EVP_CipherInit(a,b,c,d,e) ssh_EVP_CipherInit((a),(b),(c),(d),(e)) |
66 | # define EVP_Cipher(a,b,c,d) ssh_EVP_Cipher((a),(b),(c),(d)) | 69 | # define EVP_Cipher(a,b,c,d) ssh_EVP_Cipher((a),(b),(c),(d)) |
67 | # define EVP_CIPHER_CTX_cleanup(a) ssh_EVP_CIPHER_CTX_cleanup((a)) | 70 | # define EVP_CIPHER_CTX_cleanup(a) ssh_EVP_CIPHER_CTX_cleanup((a)) |
68 | # endif | 71 | # endif /* SSH_OLD_EVP */ |
72 | |||
73 | # ifdef USE_OPENSSL_ENGINE | ||
74 | # ifdef SSLeay_add_all_algorithms | ||
75 | # undef SSLeay_add_all_algorithms | ||
76 | # endif | ||
77 | # define SSLeay_add_all_algorithms() ssh_SSLeay_add_all_algorithms() | ||
78 | #endif | ||
69 | 79 | ||
70 | int ssh_EVP_CipherInit(EVP_CIPHER_CTX *, const EVP_CIPHER *, unsigned char *, | 80 | int ssh_EVP_CipherInit(EVP_CIPHER_CTX *, const EVP_CIPHER *, unsigned char *, |
71 | unsigned char *, int); | 81 | unsigned char *, int); |
72 | int ssh_EVP_Cipher(EVP_CIPHER_CTX *, char *, char *, int); | 82 | int ssh_EVP_Cipher(EVP_CIPHER_CTX *, char *, char *, int); |
73 | int ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *); | 83 | int ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *); |
74 | #endif | 84 | void ssh_SSLeay_add_all_algorithms(void); |
85 | #endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */ | ||
diff --git a/openbsd-compat/port-aix.c b/openbsd-compat/port-aix.c index 81d8124e0..b9fabf61f 100644 --- a/openbsd-compat/port-aix.c +++ b/openbsd-compat/port-aix.c | |||
@@ -25,16 +25,36 @@ | |||
25 | * | 25 | * |
26 | */ | 26 | */ |
27 | #include "includes.h" | 27 | #include "includes.h" |
28 | |||
29 | #include "xmalloc.h" | ||
30 | #include "buffer.h" | ||
31 | #include "key.h" | ||
32 | #include "hostfile.h" | ||
28 | #include "auth.h" | 33 | #include "auth.h" |
29 | #include "ssh.h" | 34 | #include "ssh.h" |
30 | #include "log.h" | 35 | #include "log.h" |
31 | #include "xmalloc.h" | ||
32 | #include "buffer.h" | ||
33 | 36 | ||
34 | #ifdef _AIX | 37 | #ifdef _AIX |
35 | 38 | ||
39 | #include <errno.h> | ||
40 | #if defined(HAVE_NETDB_H) | ||
41 | # include <netdb.h> | ||
42 | #endif | ||
36 | #include <uinfo.h> | 43 | #include <uinfo.h> |
44 | #include <stdarg.h> | ||
45 | #include <string.h> | ||
46 | #include <unistd.h> | ||
37 | #include <sys/socket.h> | 47 | #include <sys/socket.h> |
48 | |||
49 | #ifdef WITH_AIXAUTHENTICATE | ||
50 | # include <login.h> | ||
51 | # include <userpw.h> | ||
52 | # if defined(HAVE_SYS_AUDIT_H) && defined(AIX_LOGINFAILED_4ARG) | ||
53 | # include <sys/audit.h> | ||
54 | # endif | ||
55 | # include <usersec.h> | ||
56 | #endif | ||
57 | |||
38 | #include "port-aix.h" | 58 | #include "port-aix.h" |
39 | 59 | ||
40 | # ifdef HAVE_SETAUTHDB | 60 | # ifdef HAVE_SETAUTHDB |
@@ -256,15 +276,17 @@ sys_auth_record_login(const char *user, const char *host, const char *ttynm, | |||
256 | Buffer *loginmsg) | 276 | Buffer *loginmsg) |
257 | { | 277 | { |
258 | char *msg = NULL; | 278 | char *msg = NULL; |
279 | static int msg_done = 0; | ||
259 | int success = 0; | 280 | int success = 0; |
260 | 281 | ||
261 | aix_setauthdb(user); | 282 | aix_setauthdb(user); |
262 | if (loginsuccess((char *)user, (char *)host, (char *)ttynm, &msg) == 0) { | 283 | if (loginsuccess((char *)user, (char *)host, (char *)ttynm, &msg) == 0) { |
263 | success = 1; | 284 | success = 1; |
264 | if (msg != NULL) { | 285 | if (msg != NULL && loginmsg != NULL && !msg_done) { |
265 | debug("AIX/loginsuccess: msg %s", msg); | 286 | debug("AIX/loginsuccess: msg %s", msg); |
266 | buffer_append(loginmsg, msg, strlen(msg)); | 287 | buffer_append(loginmsg, msg, strlen(msg)); |
267 | xfree(msg); | 288 | xfree(msg); |
289 | msg_done = 1; | ||
268 | } | 290 | } |
269 | } | 291 | } |
270 | aix_restoreauthdb(); | 292 | aix_restoreauthdb(); |
diff --git a/openbsd-compat/port-aix.h b/openbsd-compat/port-aix.h index 37b2c12b0..5a04bedad 100644 --- a/openbsd-compat/port-aix.h +++ b/openbsd-compat/port-aix.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: port-aix.h,v 1.26 2005/05/28 10:28:40 dtucker Exp $ */ | 1 | /* $Id: port-aix.h,v 1.27 2006/09/18 13:54:33 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * | 4 | * |
@@ -31,18 +31,6 @@ | |||
31 | #ifdef HAVE_SYS_SOCKET_H | 31 | #ifdef HAVE_SYS_SOCKET_H |
32 | # include <sys/socket.h> | 32 | # include <sys/socket.h> |
33 | #endif | 33 | #endif |
34 | #ifdef HAVE_UNISTD_H | ||
35 | # include <unistd.h> /* for seteuid() */ | ||
36 | #endif | ||
37 | |||
38 | #ifdef WITH_AIXAUTHENTICATE | ||
39 | # include <login.h> | ||
40 | # include <userpw.h> | ||
41 | # if defined(HAVE_SYS_AUDIT_H) && defined(AIX_LOGINFAILED_4ARG) | ||
42 | # include <sys/audit.h> | ||
43 | # endif | ||
44 | # include <usersec.h> | ||
45 | #endif | ||
46 | 34 | ||
47 | #include "buffer.h" | 35 | #include "buffer.h" |
48 | 36 | ||
diff --git a/openbsd-compat/port-irix.c b/openbsd-compat/port-irix.c index aa6db1cf8..ba751a538 100644 --- a/openbsd-compat/port-irix.c +++ b/openbsd-compat/port-irix.c | |||
@@ -29,6 +29,10 @@ | |||
29 | defined(WITH_IRIX_JOBS) || \ | 29 | defined(WITH_IRIX_JOBS) || \ |
30 | defined(WITH_IRIX_ARRAY) | 30 | defined(WITH_IRIX_ARRAY) |
31 | 31 | ||
32 | #include <errno.h> | ||
33 | #include <string.h> | ||
34 | #include <unistd.h> | ||
35 | |||
32 | #ifdef WITH_IRIX_PROJECT | 36 | #ifdef WITH_IRIX_PROJECT |
33 | # include <proj.h> | 37 | # include <proj.h> |
34 | #endif /* WITH_IRIX_PROJECT */ | 38 | #endif /* WITH_IRIX_PROJECT */ |
diff --git a/openbsd-compat/port-linux.c b/openbsd-compat/port-linux.c new file mode 100644 index 000000000..d153f8fb5 --- /dev/null +++ b/openbsd-compat/port-linux.c | |||
@@ -0,0 +1,178 @@ | |||
1 | /* $Id: port-linux.c,v 1.3 2006/09/01 05:38:41 djm Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2005 Daniel Walsh <dwalsh@redhat.com> | ||
5 | * Copyright (c) 2006 Damien Miller <djm@openbsd.org> | ||
6 | * | ||
7 | * Permission to use, copy, modify, and distribute this software for any | ||
8 | * purpose with or without fee is hereby granted, provided that the above | ||
9 | * copyright notice and this permission notice appear in all copies. | ||
10 | * | ||
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
18 | */ | ||
19 | |||
20 | /* | ||
21 | * Linux-specific portability code - just SELinux support at present | ||
22 | */ | ||
23 | |||
24 | #include "includes.h" | ||
25 | |||
26 | #include <errno.h> | ||
27 | #include <stdarg.h> | ||
28 | #include <string.h> | ||
29 | |||
30 | #ifdef WITH_SELINUX | ||
31 | #include "log.h" | ||
32 | #include "port-linux.h" | ||
33 | |||
34 | #include <selinux/selinux.h> | ||
35 | #include <selinux/flask.h> | ||
36 | #include <selinux/get_context_list.h> | ||
37 | |||
38 | /* Wrapper around is_selinux_enabled() to log its return value once only */ | ||
39 | static int | ||
40 | ssh_selinux_enabled(void) | ||
41 | { | ||
42 | static int enabled = -1; | ||
43 | |||
44 | if (enabled == -1) { | ||
45 | enabled = is_selinux_enabled(); | ||
46 | debug("SELinux support %s", enabled ? "enabled" : "disabled"); | ||
47 | } | ||
48 | |||
49 | return (enabled); | ||
50 | } | ||
51 | |||
52 | /* Return the default security context for the given username */ | ||
53 | static security_context_t | ||
54 | ssh_selinux_getctxbyname(char *pwname) | ||
55 | { | ||
56 | security_context_t sc; | ||
57 | char *sename = NULL, *role = NULL, *lvl = NULL; | ||
58 | int r; | ||
59 | |||
60 | #ifdef HAVE_GETSEUSERBYNAME | ||
61 | if (getseuserbyname(pwname, &sename, &lvl) != 0) | ||
62 | return NULL; | ||
63 | #else | ||
64 | sename = pwname; | ||
65 | lvl = NULL; | ||
66 | #endif | ||
67 | if (the_authctxt) | ||
68 | role = the_authctxt->role; | ||
69 | |||
70 | #ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL | ||
71 | if (role != NULL && role[0]) | ||
72 | r = get_default_context_with_rolelevel(sename, role, lvl, NULL, | ||
73 | &sc); | ||
74 | else | ||
75 | r = get_default_context_with_level(sename, lvl, NULL, &sc); | ||
76 | #else | ||
77 | if (role != NULL && role[0]) | ||
78 | r = get_default_context_with_role(sename, role, NULL, &sc); | ||
79 | else | ||
80 | r = get_default_context(sename, NULL, &sc); | ||
81 | #endif | ||
82 | |||
83 | if (r != 0) { | ||
84 | switch (security_getenforce()) { | ||
85 | case -1: | ||
86 | fatal("%s: ssh_selinux_getctxbyname: " | ||
87 | "security_getenforce() failed", __func__); | ||
88 | case 0: | ||
89 | error("%s: Failed to get default SELinux security " | ||
90 | "context for %s", __func__, pwname); | ||
91 | default: | ||
92 | fatal("%s: Failed to get default SELinux security " | ||
93 | "context for %s (in enforcing mode)", | ||
94 | __func__, pwname); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | #ifdef HAVE_GETSEUSERBYNAME | ||
99 | if (sename != NULL) | ||
100 | xfree(sename); | ||
101 | if (lvl != NULL) | ||
102 | xfree(lvl); | ||
103 | #endif | ||
104 | |||
105 | return (sc); | ||
106 | } | ||
107 | |||
108 | /* Set the execution context to the default for the specified user */ | ||
109 | void | ||
110 | ssh_selinux_setup_exec_context(char *pwname) | ||
111 | { | ||
112 | security_context_t user_ctx = NULL; | ||
113 | |||
114 | if (!ssh_selinux_enabled()) | ||
115 | return; | ||
116 | |||
117 | debug3("%s: setting execution context", __func__); | ||
118 | |||
119 | user_ctx = ssh_selinux_getctxbyname(pwname); | ||
120 | if (setexeccon(user_ctx) != 0) { | ||
121 | switch (security_getenforce()) { | ||
122 | case -1: | ||
123 | fatal("%s: security_getenforce() failed", __func__); | ||
124 | case 0: | ||
125 | error("%s: Failed to set SELinux execution " | ||
126 | "context for %s", __func__, pwname); | ||
127 | default: | ||
128 | fatal("%s: Failed to set SELinux execution context " | ||
129 | "for %s (in enforcing mode)", __func__, pwname); | ||
130 | } | ||
131 | } | ||
132 | if (user_ctx != NULL) | ||
133 | freecon(user_ctx); | ||
134 | |||
135 | debug3("%s: done", __func__); | ||
136 | } | ||
137 | |||
138 | /* Set the TTY context for the specified user */ | ||
139 | void | ||
140 | ssh_selinux_setup_pty(char *pwname, const char *tty) | ||
141 | { | ||
142 | security_context_t new_tty_ctx = NULL; | ||
143 | security_context_t user_ctx = NULL; | ||
144 | security_context_t old_tty_ctx = NULL; | ||
145 | |||
146 | if (!ssh_selinux_enabled()) | ||
147 | return; | ||
148 | |||
149 | debug3("%s: setting TTY context on %s", __func__, tty); | ||
150 | |||
151 | user_ctx = ssh_selinux_getctxbyname(pwname); | ||
152 | |||
153 | /* XXX: should these calls fatal() upon failure in enforcing mode? */ | ||
154 | |||
155 | if (getfilecon(tty, &old_tty_ctx) == -1) { | ||
156 | error("%s: getfilecon: %s", __func__, strerror(errno)); | ||
157 | goto out; | ||
158 | } | ||
159 | |||
160 | if (security_compute_relabel(user_ctx, old_tty_ctx, | ||
161 | SECCLASS_CHR_FILE, &new_tty_ctx) != 0) { | ||
162 | error("%s: security_compute_relabel: %s", | ||
163 | __func__, strerror(errno)); | ||
164 | goto out; | ||
165 | } | ||
166 | |||
167 | if (setfilecon(tty, new_tty_ctx) != 0) | ||
168 | error("%s: setfilecon: %s", __func__, strerror(errno)); | ||
169 | out: | ||
170 | if (new_tty_ctx != NULL) | ||
171 | freecon(new_tty_ctx); | ||
172 | if (old_tty_ctx != NULL) | ||
173 | freecon(old_tty_ctx); | ||
174 | if (user_ctx != NULL) | ||
175 | freecon(user_ctx); | ||
176 | debug3("%s: done", __func__); | ||
177 | } | ||
178 | #endif /* WITH_SELINUX */ | ||
diff --git a/openbsd-compat/port-linux.h b/openbsd-compat/port-linux.h new file mode 100644 index 000000000..05e520e1c --- /dev/null +++ b/openbsd-compat/port-linux.h | |||
@@ -0,0 +1,27 @@ | |||
1 | /* $Id: port-linux.h,v 1.1 2006/04/22 11:26:08 djm Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2006 Damien Miller <djm@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #ifndef _PORT_LINUX_H | ||
20 | #define _PORT_LINUX_H | ||
21 | |||
22 | #ifdef WITH_SELINUX | ||
23 | void ssh_selinux_setup_pty(char *, const char *); | ||
24 | void ssh_selinux_setup_exec_context(char *); | ||
25 | #endif | ||
26 | |||
27 | #endif /* ! _PORT_LINUX_H */ | ||
diff --git a/openbsd-compat/port-solaris.c b/openbsd-compat/port-solaris.c new file mode 100644 index 000000000..2ab64d487 --- /dev/null +++ b/openbsd-compat/port-solaris.c | |||
@@ -0,0 +1,199 @@ | |||
1 | /* $Id: port-solaris.c,v 1.3 2006/10/31 23:28:49 dtucker Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2006 Chad Mynhier. | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include "config.h" | ||
20 | #include "includes.h" | ||
21 | |||
22 | #ifdef USE_SOLARIS_PROCESS_CONTRACTS | ||
23 | |||
24 | #include <sys/types.h> | ||
25 | #include <sys/stat.h> | ||
26 | #include <sys/param.h> | ||
27 | |||
28 | #include <errno.h> | ||
29 | #ifdef HAVE_FCNTL_H | ||
30 | # include <fcntl.h> | ||
31 | #endif | ||
32 | #include <stdarg.h> | ||
33 | #include <string.h> | ||
34 | #include <unistd.h> | ||
35 | |||
36 | #include <libcontract.h> | ||
37 | #include <sys/contract/process.h> | ||
38 | #include <sys/ctfs.h> | ||
39 | |||
40 | #include "log.h" | ||
41 | |||
42 | #define CT_TEMPLATE CTFS_ROOT "/process/template" | ||
43 | #define CT_LATEST CTFS_ROOT "/process/latest" | ||
44 | |||
45 | static int tmpl_fd = -1; | ||
46 | |||
47 | /* Lookup the latest process contract */ | ||
48 | static ctid_t | ||
49 | get_active_process_contract_id(void) | ||
50 | { | ||
51 | int stat_fd; | ||
52 | ctid_t ctid = -1; | ||
53 | ct_stathdl_t stathdl; | ||
54 | |||
55 | if ((stat_fd = open64(CT_LATEST, O_RDONLY)) == -1) { | ||
56 | error("%s: Error opening 'latest' process " | ||
57 | "contract: %s", __func__, strerror(errno)); | ||
58 | return -1; | ||
59 | } | ||
60 | if (ct_status_read(stat_fd, CTD_COMMON, &stathdl) != 0) { | ||
61 | error("%s: Error reading process contract " | ||
62 | "status: %s", __func__, strerror(errno)); | ||
63 | goto out; | ||
64 | } | ||
65 | if ((ctid = ct_status_get_id(stathdl)) < 0) { | ||
66 | error("%s: Error getting process contract id: %s", | ||
67 | __func__, strerror(errno)); | ||
68 | goto out; | ||
69 | } | ||
70 | |||
71 | ct_status_free(stathdl); | ||
72 | out: | ||
73 | close(stat_fd); | ||
74 | return ctid; | ||
75 | } | ||
76 | |||
77 | void | ||
78 | solaris_contract_pre_fork(void) | ||
79 | { | ||
80 | if ((tmpl_fd = open64(CT_TEMPLATE, O_RDWR)) == -1) { | ||
81 | error("%s: open %s: %s", __func__, | ||
82 | CT_TEMPLATE, strerror(errno)); | ||
83 | return; | ||
84 | } | ||
85 | |||
86 | debug2("%s: setting up process contract template on fd %d", | ||
87 | __func__, tmpl_fd); | ||
88 | |||
89 | /* First we set the template parameters and event sets. */ | ||
90 | if (ct_pr_tmpl_set_param(tmpl_fd, CT_PR_PGRPONLY) != 0) { | ||
91 | error("%s: Error setting process contract parameter set " | ||
92 | "(pgrponly): %s", __func__, strerror(errno)); | ||
93 | goto fail; | ||
94 | } | ||
95 | if (ct_pr_tmpl_set_fatal(tmpl_fd, CT_PR_EV_HWERR) != 0) { | ||
96 | error("%s: Error setting process contract template " | ||
97 | "fatal events: %s", __func__, strerror(errno)); | ||
98 | goto fail; | ||
99 | } | ||
100 | if (ct_tmpl_set_critical(tmpl_fd, 0) != 0) { | ||
101 | error("%s: Error setting process contract template " | ||
102 | "critical events: %s", __func__, strerror(errno)); | ||
103 | goto fail; | ||
104 | } | ||
105 | if (ct_tmpl_set_informative(tmpl_fd, CT_PR_EV_HWERR) != 0) { | ||
106 | error("%s: Error setting process contract template " | ||
107 | "informative events: %s", __func__, strerror(errno)); | ||
108 | goto fail; | ||
109 | } | ||
110 | |||
111 | /* Now make this the active template for this process. */ | ||
112 | if (ct_tmpl_activate(tmpl_fd) != 0) { | ||
113 | error("%s: Error activating process contract " | ||
114 | "template: %s", __func__, strerror(errno)); | ||
115 | goto fail; | ||
116 | } | ||
117 | return; | ||
118 | |||
119 | fail: | ||
120 | if (tmpl_fd != -1) { | ||
121 | close(tmpl_fd); | ||
122 | tmpl_fd = -1; | ||
123 | } | ||
124 | } | ||
125 | |||
126 | void | ||
127 | solaris_contract_post_fork_child() | ||
128 | { | ||
129 | debug2("%s: clearing process contract template on fd %d", | ||
130 | __func__, tmpl_fd); | ||
131 | |||
132 | /* Clear the active template. */ | ||
133 | if (ct_tmpl_clear(tmpl_fd) != 0) | ||
134 | error("%s: Error clearing active process contract " | ||
135 | "template: %s", __func__, strerror(errno)); | ||
136 | |||
137 | close(tmpl_fd); | ||
138 | tmpl_fd = -1; | ||
139 | } | ||
140 | |||
141 | void | ||
142 | solaris_contract_post_fork_parent(pid_t pid) | ||
143 | { | ||
144 | ctid_t ctid; | ||
145 | char ctl_path[256]; | ||
146 | int r, ctl_fd = -1, stat_fd = -1; | ||
147 | |||
148 | debug2("%s: clearing template (fd %d)", __func__, tmpl_fd); | ||
149 | |||
150 | if (tmpl_fd == -1) | ||
151 | return; | ||
152 | |||
153 | /* First clear the active template. */ | ||
154 | if ((r = ct_tmpl_clear(tmpl_fd)) != 0) | ||
155 | error("%s: Error clearing active process contract " | ||
156 | "template: %s", __func__, strerror(errno)); | ||
157 | |||
158 | close(tmpl_fd); | ||
159 | tmpl_fd = -1; | ||
160 | |||
161 | /* | ||
162 | * If either the fork didn't succeed (pid < 0), or clearing | ||
163 | * th active contract failed (r != 0), then we have nothing | ||
164 | * more do. | ||
165 | */ | ||
166 | if (r != 0 || pid <= 0) | ||
167 | return; | ||
168 | |||
169 | /* Now lookup and abandon the contract we've created. */ | ||
170 | ctid = get_active_process_contract_id(); | ||
171 | |||
172 | debug2("%s: abandoning contract id %ld", __func__, ctid); | ||
173 | |||
174 | snprintf(ctl_path, sizeof(ctl_path), | ||
175 | CTFS_ROOT "/process/%ld/ctl", ctid); | ||
176 | if ((ctl_fd = open64(ctl_path, O_WRONLY)) < 0) { | ||
177 | error("%s: Error opening process contract " | ||
178 | "ctl file: %s", __func__, strerror(errno)); | ||
179 | goto fail; | ||
180 | } | ||
181 | if (ct_ctl_abandon(ctl_fd) < 0) { | ||
182 | error("%s: Error abandoning process contract: %s", | ||
183 | __func__, strerror(errno)); | ||
184 | goto fail; | ||
185 | } | ||
186 | close(ctl_fd); | ||
187 | return; | ||
188 | |||
189 | fail: | ||
190 | if (tmpl_fd != -1) { | ||
191 | close(tmpl_fd); | ||
192 | tmpl_fd = -1; | ||
193 | } | ||
194 | if (stat_fd != -1) | ||
195 | close(stat_fd); | ||
196 | if (ctl_fd != -1) | ||
197 | close(ctl_fd); | ||
198 | } | ||
199 | #endif | ||
diff --git a/openbsd-compat/port-solaris.h b/openbsd-compat/port-solaris.h new file mode 100644 index 000000000..4c324871e --- /dev/null +++ b/openbsd-compat/port-solaris.h | |||
@@ -0,0 +1,27 @@ | |||
1 | /* $Id: port-solaris.h,v 1.1 2006/08/30 17:24:42 djm Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2006 Chad Mynhier. | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #ifndef _PORT_SOLARIS_H | ||
20 | |||
21 | #include <sys/types.h> | ||
22 | |||
23 | void solaris_contract_pre_fork(void); | ||
24 | void solaris_contract_post_fork_child(void); | ||
25 | void solaris_contract_post_fork_parent(pid_t pid); | ||
26 | |||
27 | #endif | ||
diff --git a/openbsd-compat/port-tun.c b/openbsd-compat/port-tun.c index 31921615f..276474db8 100644 --- a/openbsd-compat/port-tun.c +++ b/openbsd-compat/port-tun.c | |||
@@ -16,9 +16,23 @@ | |||
16 | 16 | ||
17 | #include "includes.h" | 17 | #include "includes.h" |
18 | 18 | ||
19 | #include <sys/types.h> | ||
20 | #include <sys/ioctl.h> | ||
21 | |||
22 | #include <netinet/in.h> | ||
23 | #include <arpa/inet.h> | ||
24 | #include <netinet/ip.h> | ||
25 | |||
26 | #include <errno.h> | ||
27 | #include <fcntl.h> | ||
28 | #include <stdarg.h> | ||
29 | #include <string.h> | ||
30 | #include <unistd.h> | ||
31 | |||
19 | #include "log.h" | 32 | #include "log.h" |
20 | #include "misc.h" | 33 | #include "misc.h" |
21 | #include "bufaux.h" | 34 | #include "buffer.h" |
35 | #include "channels.h" | ||
22 | 36 | ||
23 | /* | 37 | /* |
24 | * This is the portable version of the SSH tunnel forwarding, it | 38 | * This is the portable version of the SSH tunnel forwarding, it |
@@ -26,6 +40,7 @@ | |||
26 | * settings. | 40 | * settings. |
27 | * | 41 | * |
28 | * SSH_TUN_LINUX Use the (newer) Linux tun/tap device | 42 | * SSH_TUN_LINUX Use the (newer) Linux tun/tap device |
43 | * SSH_TUN_FREEBSD Use the FreeBSD tun/tap device | ||
29 | * SSH_TUN_COMPAT_AF Translate the OpenBSD address family | 44 | * SSH_TUN_COMPAT_AF Translate the OpenBSD address family |
30 | * SSH_TUN_PREPEND_AF Prepend/remove the address family | 45 | * SSH_TUN_PREPEND_AF Prepend/remove the address family |
31 | */ | 46 | */ |
@@ -93,7 +108,10 @@ sys_tun_open(int tun, int mode) | |||
93 | #ifdef SSH_TUN_FREEBSD | 108 | #ifdef SSH_TUN_FREEBSD |
94 | #include <sys/socket.h> | 109 | #include <sys/socket.h> |
95 | #include <net/if.h> | 110 | #include <net/if.h> |
111 | |||
112 | #ifdef HAVE_NET_IF_TUN_H | ||
96 | #include <net/if_tun.h> | 113 | #include <net/if_tun.h> |
114 | #endif | ||
97 | 115 | ||
98 | int | 116 | int |
99 | sys_tun_open(int tun, int mode) | 117 | sys_tun_open(int tun, int mode) |
diff --git a/openbsd-compat/port-tun.h b/openbsd-compat/port-tun.h index 86d9272b4..c53df01fc 100644 --- a/openbsd-compat/port-tun.h +++ b/openbsd-compat/port-tun.h | |||
@@ -17,7 +17,7 @@ | |||
17 | #ifndef _PORT_TUN_H | 17 | #ifndef _PORT_TUN_H |
18 | #define _PORT_TUN_H | 18 | #define _PORT_TUN_H |
19 | 19 | ||
20 | #include "channels.h" | 20 | struct Channel; |
21 | 21 | ||
22 | #if defined(SSH_TUN_LINUX) || defined(SSH_TUN_FREEBSD) | 22 | #if defined(SSH_TUN_LINUX) || defined(SSH_TUN_FREEBSD) |
23 | # define CUSTOM_SYS_TUN_OPEN | 23 | # define CUSTOM_SYS_TUN_OPEN |
diff --git a/openbsd-compat/port-uw.c b/openbsd-compat/port-uw.c index c64427121..6f3523902 100644 --- a/openbsd-compat/port-uw.c +++ b/openbsd-compat/port-uw.c | |||
@@ -26,15 +26,26 @@ | |||
26 | #include "includes.h" | 26 | #include "includes.h" |
27 | 27 | ||
28 | #ifdef HAVE_LIBIAF | 28 | #ifdef HAVE_LIBIAF |
29 | #include <sys/types.h> | ||
29 | #ifdef HAVE_CRYPT_H | 30 | #ifdef HAVE_CRYPT_H |
30 | #include <crypt.h> | 31 | # include <crypt.h> |
31 | #endif | 32 | #endif |
33 | #include <pwd.h> | ||
34 | #include <stdarg.h> | ||
35 | #include <stdlib.h> | ||
36 | #include <stdio.h> | ||
37 | #include <string.h> | ||
38 | |||
39 | #include "xmalloc.h" | ||
32 | #include "packet.h" | 40 | #include "packet.h" |
33 | #include "buffer.h" | 41 | #include "buffer.h" |
42 | #include "auth-options.h" | ||
34 | #include "log.h" | 43 | #include "log.h" |
35 | #include "servconf.h" | 44 | #include "servconf.h" |
45 | #include "key.h" | ||
46 | #include "hostfile.h" | ||
36 | #include "auth.h" | 47 | #include "auth.h" |
37 | #include "auth-options.h" | 48 | #include "ssh.h" |
38 | 49 | ||
39 | int nischeck(char *); | 50 | int nischeck(char *); |
40 | 51 | ||
diff --git a/openbsd-compat/readpassphrase.c b/openbsd-compat/readpassphrase.c index 919c0174a..11bd8f646 100644 --- a/openbsd-compat/readpassphrase.c +++ b/openbsd-compat/readpassphrase.c | |||
@@ -27,7 +27,13 @@ | |||
27 | #ifndef HAVE_READPASSPHRASE | 27 | #ifndef HAVE_READPASSPHRASE |
28 | 28 | ||
29 | #include <termios.h> | 29 | #include <termios.h> |
30 | #include <signal.h> | ||
31 | #include <ctype.h> | ||
32 | #include <fcntl.h> | ||
30 | #include <readpassphrase.h> | 33 | #include <readpassphrase.h> |
34 | #include <errno.h> | ||
35 | #include <string.h> | ||
36 | #include <unistd.h> | ||
31 | 37 | ||
32 | #ifdef TCSASOFT | 38 | #ifdef TCSASOFT |
33 | # define _T_FLUSH (TCSAFLUSH|TCSASOFT) | 39 | # define _T_FLUSH (TCSAFLUSH|TCSASOFT) |
diff --git a/openbsd-compat/regress/Makefile.in b/openbsd-compat/regress/Makefile.in new file mode 100644 index 000000000..bcf214bd0 --- /dev/null +++ b/openbsd-compat/regress/Makefile.in | |||
@@ -0,0 +1,38 @@ | |||
1 | # $Id: Makefile.in,v 1.4 2006/08/19 09:12:14 dtucker Exp $ | ||
2 | |||
3 | sysconfdir=@sysconfdir@ | ||
4 | piddir=@piddir@ | ||
5 | srcdir=@srcdir@ | ||
6 | top_srcdir=@top_srcdir@ | ||
7 | |||
8 | VPATH=@srcdir@ | ||
9 | CC=@CC@ | ||
10 | LD=@LD@ | ||
11 | CFLAGS=@CFLAGS@ | ||
12 | CPPFLAGS=-I. -I.. -I$(srcdir) -I$(srcdir)/.. @CPPFLAGS@ @DEFS@ | ||
13 | EXEEXT=@EXEEXT@ | ||
14 | LIBCOMPAT=../libopenbsd-compat.a | ||
15 | LIBS=@LIBS@ | ||
16 | LDFLAGS=@LDFLAGS@ $(LIBCOMPAT) | ||
17 | |||
18 | TESTPROGS=closefromtest$(EXEEXT) snprintftest$(EXEEXT) strduptest$(EXEEXT) \ | ||
19 | strtonumtest$(EXEEXT) | ||
20 | |||
21 | all: t-exec ${OTHERTESTS} | ||
22 | |||
23 | %$(EXEEXT): %.c | ||
24 | $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $< $(LIBCOMPAT) $(LIBS) | ||
25 | |||
26 | t-exec: $(TESTPROGS) | ||
27 | @echo running compat regress tests | ||
28 | @for TEST in ""$?; do \ | ||
29 | echo "run test $${TEST}" ... 1>&2; \ | ||
30 | ./$${TEST}$(EXEEXT) || exit $$? ; \ | ||
31 | done | ||
32 | @echo finished compat regress tests | ||
33 | |||
34 | clean: | ||
35 | rm -f *.o *.a core $(TESTPROGS) valid.out | ||
36 | |||
37 | distclean: clean | ||
38 | rm -f Makefile *~ | ||
diff --git a/openbsd-compat/regress/closefromtest.c b/openbsd-compat/regress/closefromtest.c new file mode 100644 index 000000000..feb1b567d --- /dev/null +++ b/openbsd-compat/regress/closefromtest.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2006 Darren Tucker | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include <sys/types.h> | ||
18 | #include <sys/stat.h> | ||
19 | |||
20 | #include <fcntl.h> | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <unistd.h> | ||
24 | |||
25 | #define NUM_OPENS 10 | ||
26 | |||
27 | void | ||
28 | fail(char *msg) | ||
29 | { | ||
30 | fprintf(stderr, "closefrom: %s\n", msg); | ||
31 | exit(1); | ||
32 | } | ||
33 | |||
34 | int | ||
35 | main(void) | ||
36 | { | ||
37 | int i, max, fds[NUM_OPENS]; | ||
38 | char buf[512]; | ||
39 | |||
40 | for (i = 0; i < NUM_OPENS; i++) | ||
41 | if ((fds[i] = open("/dev/null", "r")) == -1) | ||
42 | exit(0); /* can't test */ | ||
43 | max = i - 1; | ||
44 | |||
45 | /* should close last fd only */ | ||
46 | closefrom(fds[max]); | ||
47 | if (close(fds[max]) != -1) | ||
48 | fail("failed to close highest fd"); | ||
49 | |||
50 | /* make sure we can still use remaining descriptors */ | ||
51 | for (i = 0; i < max; i++) | ||
52 | if (read(fds[i], buf, sizeof(buf)) == -1) | ||
53 | fail("closed descriptors it should not have"); | ||
54 | |||
55 | /* should close all fds */ | ||
56 | closefrom(fds[0]); | ||
57 | for (i = 0; i < NUM_OPENS; i++) | ||
58 | if (close(fds[i]) != -1) | ||
59 | fail("failed to close from lowest fd"); | ||
60 | } | ||
diff --git a/openbsd-compat/regress/snprintftest.c b/openbsd-compat/regress/snprintftest.c new file mode 100644 index 000000000..4ca63e180 --- /dev/null +++ b/openbsd-compat/regress/snprintftest.c | |||
@@ -0,0 +1,73 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2005 Darren Tucker | ||
3 | * Copyright (c) 2005 Damien Miller | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #define BUFSZ 2048 | ||
19 | |||
20 | #include <sys/types.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <stdio.h> | ||
23 | #include <stdarg.h> | ||
24 | #include <string.h> | ||
25 | |||
26 | static int failed = 0; | ||
27 | |||
28 | static void | ||
29 | fail(const char *m) | ||
30 | { | ||
31 | fprintf(stderr, "snprintftest: %s\n", m); | ||
32 | failed = 1; | ||
33 | } | ||
34 | |||
35 | int x_snprintf(char *str, size_t count, const char *fmt, ...) | ||
36 | { | ||
37 | size_t ret; | ||
38 | va_list ap; | ||
39 | |||
40 | va_start(ap, fmt); | ||
41 | ret = vsnprintf(str, count, fmt, ap); | ||
42 | va_end(ap); | ||
43 | return ret; | ||
44 | } | ||
45 | |||
46 | int | ||
47 | main(void) | ||
48 | { | ||
49 | char b[5]; | ||
50 | char *src; | ||
51 | |||
52 | snprintf(b,5,"123456789"); | ||
53 | if (b[4] != '\0') | ||
54 | fail("snprintf does not correctly terminate long strings"); | ||
55 | |||
56 | /* check for read overrun on unterminated string */ | ||
57 | if ((src = malloc(BUFSZ)) == NULL) { | ||
58 | fail("malloc failed"); | ||
59 | } else { | ||
60 | memset(src, 'a', BUFSZ); | ||
61 | snprintf(b, sizeof(b), "%.*s", 1, src); | ||
62 | if (strcmp(b, "a") != 0) | ||
63 | fail("failed with length limit '%%.s'"); | ||
64 | } | ||
65 | |||
66 | /* check that snprintf and vsnprintf return sane values */ | ||
67 | if (snprintf(b, 1, "%s %d", "hello", 12345) != 11) | ||
68 | fail("snprintf does not return required length"); | ||
69 | if (x_snprintf(b, 1, "%s %d", "hello", 12345) != 11) | ||
70 | fail("vsnprintf does not return required length"); | ||
71 | |||
72 | return failed; | ||
73 | } | ||
diff --git a/openbsd-compat/regress/strduptest.c b/openbsd-compat/regress/strduptest.c new file mode 100644 index 000000000..7f6d779be --- /dev/null +++ b/openbsd-compat/regress/strduptest.c | |||
@@ -0,0 +1,45 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2005 Darren Tucker | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include <stdlib.h> | ||
18 | #include <string.h> | ||
19 | |||
20 | static int fail = 0; | ||
21 | |||
22 | void | ||
23 | test(const char *a) | ||
24 | { | ||
25 | char *b; | ||
26 | |||
27 | b = strdup(a); | ||
28 | if (b == 0) { | ||
29 | fail = 1; | ||
30 | return; | ||
31 | } | ||
32 | if (strcmp(a, b) != 0) | ||
33 | fail = 1; | ||
34 | free(b); | ||
35 | } | ||
36 | |||
37 | int | ||
38 | main(void) | ||
39 | { | ||
40 | test(""); | ||
41 | test("a"); | ||
42 | test("\0"); | ||
43 | test("abcdefghijklmnopqrstuvwxyz"); | ||
44 | return fail; | ||
45 | } | ||
diff --git a/openbsd-compat/regress/strtonumtest.c b/openbsd-compat/regress/strtonumtest.c new file mode 100644 index 000000000..cb8585129 --- /dev/null +++ b/openbsd-compat/regress/strtonumtest.c | |||
@@ -0,0 +1,66 @@ | |||
1 | /* $OpenBSD: strtonumtest.c,v 1.1 2004/08/03 20:38:36 otto Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2004 Otto Moerbeek <otto@drijf.net> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | /* OPENBSD ORIGINAL: regress/lib/libc/strtonum/strtonumtest.c */ | ||
19 | |||
20 | #include <limits.h> | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | int fail; | ||
25 | |||
26 | void | ||
27 | test(const char *p, long long lb, long long ub, int ok) | ||
28 | { | ||
29 | long long val; | ||
30 | const char *q; | ||
31 | |||
32 | val = strtonum(p, lb, ub, &q); | ||
33 | if (ok && q != NULL) { | ||
34 | fprintf(stderr, "%s [%lld-%lld] ", p, lb, ub); | ||
35 | fprintf(stderr, "NUMBER NOT ACCEPTED %s\n", q); | ||
36 | fail = 1; | ||
37 | } else if (!ok && q == NULL) { | ||
38 | fprintf(stderr, "%s [%lld-%lld] %lld ", p, lb, ub, val); | ||
39 | fprintf(stderr, "NUMBER ACCEPTED\n"); | ||
40 | fail = 1; | ||
41 | } | ||
42 | } | ||
43 | |||
44 | int main(int argc, char *argv[]) | ||
45 | { | ||
46 | test("1", 0, 10, 1); | ||
47 | test("0", -2, 5, 1); | ||
48 | test("0", 2, 5, 0); | ||
49 | test("0", 2, LLONG_MAX, 0); | ||
50 | test("-2", 0, LLONG_MAX, 0); | ||
51 | test("0", -5, LLONG_MAX, 1); | ||
52 | test("-3", -3, LLONG_MAX, 1); | ||
53 | test("-9223372036854775808", LLONG_MIN, LLONG_MAX, 1); | ||
54 | test("9223372036854775807", LLONG_MIN, LLONG_MAX, 1); | ||
55 | test("-9223372036854775809", LLONG_MIN, LLONG_MAX, 0); | ||
56 | test("9223372036854775808", LLONG_MIN, LLONG_MAX, 0); | ||
57 | test("1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0); | ||
58 | test("-1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0); | ||
59 | test("-2", 10, -1, 0); | ||
60 | test("-2", -10, -1, 1); | ||
61 | test("-20", -10, -1, 0); | ||
62 | test("20", -10, -1, 0); | ||
63 | |||
64 | return (fail); | ||
65 | } | ||
66 | |||
diff --git a/openbsd-compat/rresvport.c b/openbsd-compat/rresvport.c index 71cf6e6eb..5b0275ce0 100644 --- a/openbsd-compat/rresvport.c +++ b/openbsd-compat/rresvport.c | |||
@@ -35,6 +35,16 @@ | |||
35 | 35 | ||
36 | #ifndef HAVE_RRESVPORT_AF | 36 | #ifndef HAVE_RRESVPORT_AF |
37 | 37 | ||
38 | #include <sys/types.h> | ||
39 | #include <sys/socket.h> | ||
40 | |||
41 | #include <netinet/in.h> | ||
42 | #include <arpa/inet.h> | ||
43 | |||
44 | #include <errno.h> | ||
45 | #include <stdlib.h> | ||
46 | #include <string.h> | ||
47 | |||
38 | #if 0 | 48 | #if 0 |
39 | int | 49 | int |
40 | rresvport(int *alport) | 50 | rresvport(int *alport) |
diff --git a/openbsd-compat/setproctitle.c b/openbsd-compat/setproctitle.c index 6e2b19bb4..b511f6649 100644 --- a/openbsd-compat/setproctitle.c +++ b/openbsd-compat/setproctitle.c | |||
@@ -35,10 +35,13 @@ | |||
35 | 35 | ||
36 | #ifndef HAVE_SETPROCTITLE | 36 | #ifndef HAVE_SETPROCTITLE |
37 | 37 | ||
38 | #include <stdarg.h> | ||
39 | #include <stdlib.h> | ||
38 | #include <unistd.h> | 40 | #include <unistd.h> |
39 | #ifdef HAVE_SYS_PSTAT_H | 41 | #ifdef HAVE_SYS_PSTAT_H |
40 | #include <sys/pstat.h> | 42 | #include <sys/pstat.h> |
41 | #endif | 43 | #endif |
44 | #include <string.h> | ||
42 | 45 | ||
43 | #define SPT_NONE 0 /* don't use it at all */ | 46 | #define SPT_NONE 0 /* don't use it at all */ |
44 | #define SPT_PSTAT 1 /* use pstat(PSTAT_SETCMD, ...) */ | 47 | #define SPT_PSTAT 1 /* use pstat(PSTAT_SETCMD, ...) */ |
@@ -80,7 +83,7 @@ compat_init_setproctitle(int argc, char *argv[]) | |||
80 | /* Fail if we can't allocate room for the new environment */ | 83 | /* Fail if we can't allocate room for the new environment */ |
81 | for (i = 0; envp[i] != NULL; i++) | 84 | for (i = 0; envp[i] != NULL; i++) |
82 | ; | 85 | ; |
83 | if ((environ = malloc(sizeof(*environ) * (i + 1))) == NULL) { | 86 | if ((environ = calloc(i + 1, sizeof(*environ))) == NULL) { |
84 | environ = envp; /* put it back */ | 87 | environ = envp; /* put it back */ |
85 | return; | 88 | return; |
86 | } | 89 | } |
diff --git a/openbsd-compat/sha2.c b/openbsd-compat/sha2.c new file mode 100755 index 000000000..cf8e0ad66 --- /dev/null +++ b/openbsd-compat/sha2.c | |||
@@ -0,0 +1,882 @@ | |||
1 | /* $OpenBSD: sha2.c,v 1.11 2005/08/08 08:05:35 espie Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * FILE: sha2.c | ||
5 | * AUTHOR: Aaron D. Gifford <me@aarongifford.com> | ||
6 | * | ||
7 | * Copyright (c) 2000-2001, Aaron D. Gifford | ||
8 | * All rights reserved. | ||
9 | * | ||
10 | * Redistribution and use in source and binary forms, with or without | ||
11 | * modification, are permitted provided that the following conditions | ||
12 | * are met: | ||
13 | * 1. Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in the | ||
17 | * documentation and/or other materials provided with the distribution. | ||
18 | * 3. Neither the name of the copyright holder nor the names of contributors | ||
19 | * may be used to endorse or promote products derived from this software | ||
20 | * without specific prior written permission. | ||
21 | * | ||
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND | ||
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE | ||
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | * SUCH DAMAGE. | ||
33 | * | ||
34 | * $From: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $ | ||
35 | */ | ||
36 | |||
37 | /* OPENBSD ORIGINAL: lib/libc/hash/sha2.c */ | ||
38 | |||
39 | #include "includes.h" | ||
40 | |||
41 | #include <openssl/opensslv.h> | ||
42 | |||
43 | #if !defined(HAVE_EVP_SHA256) && !defined(HAVE_SHA256_UPDATE) && \ | ||
44 | (OPENSSL_VERSION_NUMBER >= 0x00907000L) | ||
45 | #include <sys/types.h> | ||
46 | #include <string.h> | ||
47 | #include "sha2.h" | ||
48 | |||
49 | /* | ||
50 | * UNROLLED TRANSFORM LOOP NOTE: | ||
51 | * You can define SHA2_UNROLL_TRANSFORM to use the unrolled transform | ||
52 | * loop version for the hash transform rounds (defined using macros | ||
53 | * later in this file). Either define on the command line, for example: | ||
54 | * | ||
55 | * cc -DSHA2_UNROLL_TRANSFORM -o sha2 sha2.c sha2prog.c | ||
56 | * | ||
57 | * or define below: | ||
58 | * | ||
59 | * #define SHA2_UNROLL_TRANSFORM | ||
60 | * | ||
61 | */ | ||
62 | |||
63 | /*** SHA-256/384/512 Machine Architecture Definitions *****************/ | ||
64 | /* | ||
65 | * BYTE_ORDER NOTE: | ||
66 | * | ||
67 | * Please make sure that your system defines BYTE_ORDER. If your | ||
68 | * architecture is little-endian, make sure it also defines | ||
69 | * LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are | ||
70 | * equivilent. | ||
71 | * | ||
72 | * If your system does not define the above, then you can do so by | ||
73 | * hand like this: | ||
74 | * | ||
75 | * #define LITTLE_ENDIAN 1234 | ||
76 | * #define BIG_ENDIAN 4321 | ||
77 | * | ||
78 | * And for little-endian machines, add: | ||
79 | * | ||
80 | * #define BYTE_ORDER LITTLE_ENDIAN | ||
81 | * | ||
82 | * Or for big-endian machines: | ||
83 | * | ||
84 | * #define BYTE_ORDER BIG_ENDIAN | ||
85 | * | ||
86 | * The FreeBSD machine this was written on defines BYTE_ORDER | ||
87 | * appropriately by including <sys/types.h> (which in turn includes | ||
88 | * <machine/endian.h> where the appropriate definitions are actually | ||
89 | * made). | ||
90 | */ | ||
91 | #if !defined(BYTE_ORDER) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN) | ||
92 | #error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN | ||
93 | #endif | ||
94 | |||
95 | |||
96 | /*** SHA-256/384/512 Various Length Definitions ***********************/ | ||
97 | /* NOTE: Most of these are in sha2.h */ | ||
98 | #define SHA256_SHORT_BLOCK_LENGTH (SHA256_BLOCK_LENGTH - 8) | ||
99 | #define SHA384_SHORT_BLOCK_LENGTH (SHA384_BLOCK_LENGTH - 16) | ||
100 | #define SHA512_SHORT_BLOCK_LENGTH (SHA512_BLOCK_LENGTH - 16) | ||
101 | |||
102 | /*** ENDIAN SPECIFIC COPY MACROS **************************************/ | ||
103 | #define BE_8_TO_32(dst, cp) do { \ | ||
104 | (dst) = (u_int32_t)(cp)[3] | ((u_int32_t)(cp)[2] << 8) | \ | ||
105 | ((u_int32_t)(cp)[1] << 16) | ((u_int32_t)(cp)[0] << 24); \ | ||
106 | } while(0) | ||
107 | |||
108 | #define BE_8_TO_64(dst, cp) do { \ | ||
109 | (dst) = (u_int64_t)(cp)[7] | ((u_int64_t)(cp)[6] << 8) | \ | ||
110 | ((u_int64_t)(cp)[5] << 16) | ((u_int64_t)(cp)[4] << 24) | \ | ||
111 | ((u_int64_t)(cp)[3] << 32) | ((u_int64_t)(cp)[2] << 40) | \ | ||
112 | ((u_int64_t)(cp)[1] << 48) | ((u_int64_t)(cp)[0] << 56); \ | ||
113 | } while (0) | ||
114 | |||
115 | #define BE_64_TO_8(cp, src) do { \ | ||
116 | (cp)[0] = (src) >> 56; \ | ||
117 | (cp)[1] = (src) >> 48; \ | ||
118 | (cp)[2] = (src) >> 40; \ | ||
119 | (cp)[3] = (src) >> 32; \ | ||
120 | (cp)[4] = (src) >> 24; \ | ||
121 | (cp)[5] = (src) >> 16; \ | ||
122 | (cp)[6] = (src) >> 8; \ | ||
123 | (cp)[7] = (src); \ | ||
124 | } while (0) | ||
125 | |||
126 | #define BE_32_TO_8(cp, src) do { \ | ||
127 | (cp)[0] = (src) >> 24; \ | ||
128 | (cp)[1] = (src) >> 16; \ | ||
129 | (cp)[2] = (src) >> 8; \ | ||
130 | (cp)[3] = (src); \ | ||
131 | } while (0) | ||
132 | |||
133 | /* | ||
134 | * Macro for incrementally adding the unsigned 64-bit integer n to the | ||
135 | * unsigned 128-bit integer (represented using a two-element array of | ||
136 | * 64-bit words): | ||
137 | */ | ||
138 | #define ADDINC128(w,n) do { \ | ||
139 | (w)[0] += (u_int64_t)(n); \ | ||
140 | if ((w)[0] < (n)) { \ | ||
141 | (w)[1]++; \ | ||
142 | } \ | ||
143 | } while (0) | ||
144 | |||
145 | /*** THE SIX LOGICAL FUNCTIONS ****************************************/ | ||
146 | /* | ||
147 | * Bit shifting and rotation (used by the six SHA-XYZ logical functions: | ||
148 | * | ||
149 | * NOTE: The naming of R and S appears backwards here (R is a SHIFT and | ||
150 | * S is a ROTATION) because the SHA-256/384/512 description document | ||
151 | * (see http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf) uses this | ||
152 | * same "backwards" definition. | ||
153 | */ | ||
154 | /* Shift-right (used in SHA-256, SHA-384, and SHA-512): */ | ||
155 | #define R(b,x) ((x) >> (b)) | ||
156 | /* 32-bit Rotate-right (used in SHA-256): */ | ||
157 | #define S32(b,x) (((x) >> (b)) | ((x) << (32 - (b)))) | ||
158 | /* 64-bit Rotate-right (used in SHA-384 and SHA-512): */ | ||
159 | #define S64(b,x) (((x) >> (b)) | ((x) << (64 - (b)))) | ||
160 | |||
161 | /* Two of six logical functions used in SHA-256, SHA-384, and SHA-512: */ | ||
162 | #define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z))) | ||
163 | #define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) | ||
164 | |||
165 | /* Four of six logical functions used in SHA-256: */ | ||
166 | #define Sigma0_256(x) (S32(2, (x)) ^ S32(13, (x)) ^ S32(22, (x))) | ||
167 | #define Sigma1_256(x) (S32(6, (x)) ^ S32(11, (x)) ^ S32(25, (x))) | ||
168 | #define sigma0_256(x) (S32(7, (x)) ^ S32(18, (x)) ^ R(3 , (x))) | ||
169 | #define sigma1_256(x) (S32(17, (x)) ^ S32(19, (x)) ^ R(10, (x))) | ||
170 | |||
171 | /* Four of six logical functions used in SHA-384 and SHA-512: */ | ||
172 | #define Sigma0_512(x) (S64(28, (x)) ^ S64(34, (x)) ^ S64(39, (x))) | ||
173 | #define Sigma1_512(x) (S64(14, (x)) ^ S64(18, (x)) ^ S64(41, (x))) | ||
174 | #define sigma0_512(x) (S64( 1, (x)) ^ S64( 8, (x)) ^ R( 7, (x))) | ||
175 | #define sigma1_512(x) (S64(19, (x)) ^ S64(61, (x)) ^ R( 6, (x))) | ||
176 | |||
177 | |||
178 | /*** SHA-XYZ INITIAL HASH VALUES AND CONSTANTS ************************/ | ||
179 | /* Hash constant words K for SHA-256: */ | ||
180 | const static u_int32_t K256[64] = { | ||
181 | 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, | ||
182 | 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, | ||
183 | 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL, | ||
184 | 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL, | ||
185 | 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL, | ||
186 | 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, | ||
187 | 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, | ||
188 | 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL, | ||
189 | 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL, | ||
190 | 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL, | ||
191 | 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, | ||
192 | 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, | ||
193 | 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL, | ||
194 | 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL, | ||
195 | 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL, | ||
196 | 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL | ||
197 | }; | ||
198 | |||
199 | /* Initial hash value H for SHA-256: */ | ||
200 | const static u_int32_t sha256_initial_hash_value[8] = { | ||
201 | 0x6a09e667UL, | ||
202 | 0xbb67ae85UL, | ||
203 | 0x3c6ef372UL, | ||
204 | 0xa54ff53aUL, | ||
205 | 0x510e527fUL, | ||
206 | 0x9b05688cUL, | ||
207 | 0x1f83d9abUL, | ||
208 | 0x5be0cd19UL | ||
209 | }; | ||
210 | |||
211 | /* Hash constant words K for SHA-384 and SHA-512: */ | ||
212 | const static u_int64_t K512[80] = { | ||
213 | 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, | ||
214 | 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL, | ||
215 | 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, | ||
216 | 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, | ||
217 | 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL, | ||
218 | 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL, | ||
219 | 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, | ||
220 | 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL, | ||
221 | 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, | ||
222 | 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, | ||
223 | 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL, | ||
224 | 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL, | ||
225 | 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, | ||
226 | 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL, | ||
227 | 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, | ||
228 | 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, | ||
229 | 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL, | ||
230 | 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL, | ||
231 | 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, | ||
232 | 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL, | ||
233 | 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, | ||
234 | 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, | ||
235 | 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL, | ||
236 | 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL, | ||
237 | 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, | ||
238 | 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL, | ||
239 | 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, | ||
240 | 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, | ||
241 | 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL, | ||
242 | 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL, | ||
243 | 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, | ||
244 | 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL, | ||
245 | 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, | ||
246 | 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, | ||
247 | 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL, | ||
248 | 0x113f9804bef90daeULL, 0x1b710b35131c471bULL, | ||
249 | 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, | ||
250 | 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL, | ||
251 | 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, | ||
252 | 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL | ||
253 | }; | ||
254 | |||
255 | /* Initial hash value H for SHA-384 */ | ||
256 | const static u_int64_t sha384_initial_hash_value[8] = { | ||
257 | 0xcbbb9d5dc1059ed8ULL, | ||
258 | 0x629a292a367cd507ULL, | ||
259 | 0x9159015a3070dd17ULL, | ||
260 | 0x152fecd8f70e5939ULL, | ||
261 | 0x67332667ffc00b31ULL, | ||
262 | 0x8eb44a8768581511ULL, | ||
263 | 0xdb0c2e0d64f98fa7ULL, | ||
264 | 0x47b5481dbefa4fa4ULL | ||
265 | }; | ||
266 | |||
267 | /* Initial hash value H for SHA-512 */ | ||
268 | const static u_int64_t sha512_initial_hash_value[8] = { | ||
269 | 0x6a09e667f3bcc908ULL, | ||
270 | 0xbb67ae8584caa73bULL, | ||
271 | 0x3c6ef372fe94f82bULL, | ||
272 | 0xa54ff53a5f1d36f1ULL, | ||
273 | 0x510e527fade682d1ULL, | ||
274 | 0x9b05688c2b3e6c1fULL, | ||
275 | 0x1f83d9abfb41bd6bULL, | ||
276 | 0x5be0cd19137e2179ULL | ||
277 | }; | ||
278 | |||
279 | |||
280 | /*** SHA-256: *********************************************************/ | ||
281 | void | ||
282 | SHA256_Init(SHA256_CTX *context) | ||
283 | { | ||
284 | if (context == NULL) | ||
285 | return; | ||
286 | memcpy(context->state, sha256_initial_hash_value, | ||
287 | sizeof(sha256_initial_hash_value)); | ||
288 | memset(context->buffer, 0, sizeof(context->buffer)); | ||
289 | context->bitcount = 0; | ||
290 | } | ||
291 | |||
292 | #ifdef SHA2_UNROLL_TRANSFORM | ||
293 | |||
294 | /* Unrolled SHA-256 round macros: */ | ||
295 | |||
296 | #define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) do { \ | ||
297 | BE_8_TO_32(W256[j], data); \ | ||
298 | data += 4; \ | ||
299 | T1 = (h) + Sigma1_256((e)) + Ch((e), (f), (g)) + K256[j] + W256[j]; \ | ||
300 | (d) += T1; \ | ||
301 | (h) = T1 + Sigma0_256((a)) + Maj((a), (b), (c)); \ | ||
302 | j++; \ | ||
303 | } while(0) | ||
304 | |||
305 | #define ROUND256(a,b,c,d,e,f,g,h) do { \ | ||
306 | s0 = W256[(j+1)&0x0f]; \ | ||
307 | s0 = sigma0_256(s0); \ | ||
308 | s1 = W256[(j+14)&0x0f]; \ | ||
309 | s1 = sigma1_256(s1); \ | ||
310 | T1 = (h) + Sigma1_256((e)) + Ch((e), (f), (g)) + K256[j] + \ | ||
311 | (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0); \ | ||
312 | (d) += T1; \ | ||
313 | (h) = T1 + Sigma0_256((a)) + Maj((a), (b), (c)); \ | ||
314 | j++; \ | ||
315 | } while(0) | ||
316 | |||
317 | void | ||
318 | SHA256_Transform(u_int32_t state[8], const u_int8_t data[SHA256_BLOCK_LENGTH]) | ||
319 | { | ||
320 | u_int32_t a, b, c, d, e, f, g, h, s0, s1; | ||
321 | u_int32_t T1, W256[16]; | ||
322 | int j; | ||
323 | |||
324 | /* Initialize registers with the prev. intermediate value */ | ||
325 | a = state[0]; | ||
326 | b = state[1]; | ||
327 | c = state[2]; | ||
328 | d = state[3]; | ||
329 | e = state[4]; | ||
330 | f = state[5]; | ||
331 | g = state[6]; | ||
332 | h = state[7]; | ||
333 | |||
334 | j = 0; | ||
335 | do { | ||
336 | /* Rounds 0 to 15 (unrolled): */ | ||
337 | ROUND256_0_TO_15(a,b,c,d,e,f,g,h); | ||
338 | ROUND256_0_TO_15(h,a,b,c,d,e,f,g); | ||
339 | ROUND256_0_TO_15(g,h,a,b,c,d,e,f); | ||
340 | ROUND256_0_TO_15(f,g,h,a,b,c,d,e); | ||
341 | ROUND256_0_TO_15(e,f,g,h,a,b,c,d); | ||
342 | ROUND256_0_TO_15(d,e,f,g,h,a,b,c); | ||
343 | ROUND256_0_TO_15(c,d,e,f,g,h,a,b); | ||
344 | ROUND256_0_TO_15(b,c,d,e,f,g,h,a); | ||
345 | } while (j < 16); | ||
346 | |||
347 | /* Now for the remaining rounds up to 63: */ | ||
348 | do { | ||
349 | ROUND256(a,b,c,d,e,f,g,h); | ||
350 | ROUND256(h,a,b,c,d,e,f,g); | ||
351 | ROUND256(g,h,a,b,c,d,e,f); | ||
352 | ROUND256(f,g,h,a,b,c,d,e); | ||
353 | ROUND256(e,f,g,h,a,b,c,d); | ||
354 | ROUND256(d,e,f,g,h,a,b,c); | ||
355 | ROUND256(c,d,e,f,g,h,a,b); | ||
356 | ROUND256(b,c,d,e,f,g,h,a); | ||
357 | } while (j < 64); | ||
358 | |||
359 | /* Compute the current intermediate hash value */ | ||
360 | state[0] += a; | ||
361 | state[1] += b; | ||
362 | state[2] += c; | ||
363 | state[3] += d; | ||
364 | state[4] += e; | ||
365 | state[5] += f; | ||
366 | state[6] += g; | ||
367 | state[7] += h; | ||
368 | |||
369 | /* Clean up */ | ||
370 | a = b = c = d = e = f = g = h = T1 = 0; | ||
371 | } | ||
372 | |||
373 | #else /* SHA2_UNROLL_TRANSFORM */ | ||
374 | |||
375 | void | ||
376 | SHA256_Transform(u_int32_t state[8], const u_int8_t data[SHA256_BLOCK_LENGTH]) | ||
377 | { | ||
378 | u_int32_t a, b, c, d, e, f, g, h, s0, s1; | ||
379 | u_int32_t T1, T2, W256[16]; | ||
380 | int j; | ||
381 | |||
382 | /* Initialize registers with the prev. intermediate value */ | ||
383 | a = state[0]; | ||
384 | b = state[1]; | ||
385 | c = state[2]; | ||
386 | d = state[3]; | ||
387 | e = state[4]; | ||
388 | f = state[5]; | ||
389 | g = state[6]; | ||
390 | h = state[7]; | ||
391 | |||
392 | j = 0; | ||
393 | do { | ||
394 | BE_8_TO_32(W256[j], data); | ||
395 | data += 4; | ||
396 | /* Apply the SHA-256 compression function to update a..h */ | ||
397 | T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + W256[j]; | ||
398 | T2 = Sigma0_256(a) + Maj(a, b, c); | ||
399 | h = g; | ||
400 | g = f; | ||
401 | f = e; | ||
402 | e = d + T1; | ||
403 | d = c; | ||
404 | c = b; | ||
405 | b = a; | ||
406 | a = T1 + T2; | ||
407 | |||
408 | j++; | ||
409 | } while (j < 16); | ||
410 | |||
411 | do { | ||
412 | /* Part of the message block expansion: */ | ||
413 | s0 = W256[(j+1)&0x0f]; | ||
414 | s0 = sigma0_256(s0); | ||
415 | s1 = W256[(j+14)&0x0f]; | ||
416 | s1 = sigma1_256(s1); | ||
417 | |||
418 | /* Apply the SHA-256 compression function to update a..h */ | ||
419 | T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + | ||
420 | (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0); | ||
421 | T2 = Sigma0_256(a) + Maj(a, b, c); | ||
422 | h = g; | ||
423 | g = f; | ||
424 | f = e; | ||
425 | e = d + T1; | ||
426 | d = c; | ||
427 | c = b; | ||
428 | b = a; | ||
429 | a = T1 + T2; | ||
430 | |||
431 | j++; | ||
432 | } while (j < 64); | ||
433 | |||
434 | /* Compute the current intermediate hash value */ | ||
435 | state[0] += a; | ||
436 | state[1] += b; | ||
437 | state[2] += c; | ||
438 | state[3] += d; | ||
439 | state[4] += e; | ||
440 | state[5] += f; | ||
441 | state[6] += g; | ||
442 | state[7] += h; | ||
443 | |||
444 | /* Clean up */ | ||
445 | a = b = c = d = e = f = g = h = T1 = T2 = 0; | ||
446 | } | ||
447 | |||
448 | #endif /* SHA2_UNROLL_TRANSFORM */ | ||
449 | |||
450 | void | ||
451 | SHA256_Update(SHA256_CTX *context, const u_int8_t *data, size_t len) | ||
452 | { | ||
453 | size_t freespace, usedspace; | ||
454 | |||
455 | /* Calling with no data is valid (we do nothing) */ | ||
456 | if (len == 0) | ||
457 | return; | ||
458 | |||
459 | usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH; | ||
460 | if (usedspace > 0) { | ||
461 | /* Calculate how much free space is available in the buffer */ | ||
462 | freespace = SHA256_BLOCK_LENGTH - usedspace; | ||
463 | |||
464 | if (len >= freespace) { | ||
465 | /* Fill the buffer completely and process it */ | ||
466 | memcpy(&context->buffer[usedspace], data, freespace); | ||
467 | context->bitcount += freespace << 3; | ||
468 | len -= freespace; | ||
469 | data += freespace; | ||
470 | SHA256_Transform(context->state, context->buffer); | ||
471 | } else { | ||
472 | /* The buffer is not yet full */ | ||
473 | memcpy(&context->buffer[usedspace], data, len); | ||
474 | context->bitcount += len << 3; | ||
475 | /* Clean up: */ | ||
476 | usedspace = freespace = 0; | ||
477 | return; | ||
478 | } | ||
479 | } | ||
480 | while (len >= SHA256_BLOCK_LENGTH) { | ||
481 | /* Process as many complete blocks as we can */ | ||
482 | SHA256_Transform(context->state, data); | ||
483 | context->bitcount += SHA256_BLOCK_LENGTH << 3; | ||
484 | len -= SHA256_BLOCK_LENGTH; | ||
485 | data += SHA256_BLOCK_LENGTH; | ||
486 | } | ||
487 | if (len > 0) { | ||
488 | /* There's left-overs, so save 'em */ | ||
489 | memcpy(context->buffer, data, len); | ||
490 | context->bitcount += len << 3; | ||
491 | } | ||
492 | /* Clean up: */ | ||
493 | usedspace = freespace = 0; | ||
494 | } | ||
495 | |||
496 | void | ||
497 | SHA256_Pad(SHA256_CTX *context) | ||
498 | { | ||
499 | unsigned int usedspace; | ||
500 | |||
501 | usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH; | ||
502 | if (usedspace > 0) { | ||
503 | /* Begin padding with a 1 bit: */ | ||
504 | context->buffer[usedspace++] = 0x80; | ||
505 | |||
506 | if (usedspace <= SHA256_SHORT_BLOCK_LENGTH) { | ||
507 | /* Set-up for the last transform: */ | ||
508 | memset(&context->buffer[usedspace], 0, | ||
509 | SHA256_SHORT_BLOCK_LENGTH - usedspace); | ||
510 | } else { | ||
511 | if (usedspace < SHA256_BLOCK_LENGTH) { | ||
512 | memset(&context->buffer[usedspace], 0, | ||
513 | SHA256_BLOCK_LENGTH - usedspace); | ||
514 | } | ||
515 | /* Do second-to-last transform: */ | ||
516 | SHA256_Transform(context->state, context->buffer); | ||
517 | |||
518 | /* Prepare for last transform: */ | ||
519 | memset(context->buffer, 0, SHA256_SHORT_BLOCK_LENGTH); | ||
520 | } | ||
521 | } else { | ||
522 | /* Set-up for the last transform: */ | ||
523 | memset(context->buffer, 0, SHA256_SHORT_BLOCK_LENGTH); | ||
524 | |||
525 | /* Begin padding with a 1 bit: */ | ||
526 | *context->buffer = 0x80; | ||
527 | } | ||
528 | /* Store the length of input data (in bits) in big endian format: */ | ||
529 | BE_64_TO_8(&context->buffer[SHA256_SHORT_BLOCK_LENGTH], | ||
530 | context->bitcount); | ||
531 | |||
532 | /* Final transform: */ | ||
533 | SHA256_Transform(context->state, context->buffer); | ||
534 | |||
535 | /* Clean up: */ | ||
536 | usedspace = 0; | ||
537 | } | ||
538 | |||
539 | void | ||
540 | SHA256_Final(u_int8_t digest[SHA256_DIGEST_LENGTH], SHA256_CTX *context) | ||
541 | { | ||
542 | SHA256_Pad(context); | ||
543 | |||
544 | /* If no digest buffer is passed, we don't bother doing this: */ | ||
545 | if (digest != NULL) { | ||
546 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
547 | int i; | ||
548 | |||
549 | /* Convert TO host byte order */ | ||
550 | for (i = 0; i < 8; i++) | ||
551 | BE_32_TO_8(digest + i * 4, context->state[i]); | ||
552 | #else | ||
553 | memcpy(digest, context->state, SHA256_DIGEST_LENGTH); | ||
554 | #endif | ||
555 | memset(context, 0, sizeof(*context)); | ||
556 | } | ||
557 | } | ||
558 | |||
559 | |||
560 | /*** SHA-512: *********************************************************/ | ||
561 | void | ||
562 | SHA512_Init(SHA512_CTX *context) | ||
563 | { | ||
564 | if (context == NULL) | ||
565 | return; | ||
566 | memcpy(context->state, sha512_initial_hash_value, | ||
567 | sizeof(sha512_initial_hash_value)); | ||
568 | memset(context->buffer, 0, sizeof(context->buffer)); | ||
569 | context->bitcount[0] = context->bitcount[1] = 0; | ||
570 | } | ||
571 | |||
572 | #ifdef SHA2_UNROLL_TRANSFORM | ||
573 | |||
574 | /* Unrolled SHA-512 round macros: */ | ||
575 | |||
576 | #define ROUND512_0_TO_15(a,b,c,d,e,f,g,h) do { \ | ||
577 | BE_8_TO_64(W512[j], data); \ | ||
578 | data += 8; \ | ||
579 | T1 = (h) + Sigma1_512((e)) + Ch((e), (f), (g)) + K512[j] + W512[j]; \ | ||
580 | (d) += T1; \ | ||
581 | (h) = T1 + Sigma0_512((a)) + Maj((a), (b), (c)); \ | ||
582 | j++; \ | ||
583 | } while(0) | ||
584 | |||
585 | |||
586 | #define ROUND512(a,b,c,d,e,f,g,h) do { \ | ||
587 | s0 = W512[(j+1)&0x0f]; \ | ||
588 | s0 = sigma0_512(s0); \ | ||
589 | s1 = W512[(j+14)&0x0f]; \ | ||
590 | s1 = sigma1_512(s1); \ | ||
591 | T1 = (h) + Sigma1_512((e)) + Ch((e), (f), (g)) + K512[j] + \ | ||
592 | (W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0); \ | ||
593 | (d) += T1; \ | ||
594 | (h) = T1 + Sigma0_512((a)) + Maj((a), (b), (c)); \ | ||
595 | j++; \ | ||
596 | } while(0) | ||
597 | |||
598 | void | ||
599 | SHA512_Transform(u_int64_t state[8], const u_int8_t data[SHA512_BLOCK_LENGTH]) | ||
600 | { | ||
601 | u_int64_t a, b, c, d, e, f, g, h, s0, s1; | ||
602 | u_int64_t T1, W512[16]; | ||
603 | int j; | ||
604 | |||
605 | /* Initialize registers with the prev. intermediate value */ | ||
606 | a = state[0]; | ||
607 | b = state[1]; | ||
608 | c = state[2]; | ||
609 | d = state[3]; | ||
610 | e = state[4]; | ||
611 | f = state[5]; | ||
612 | g = state[6]; | ||
613 | h = state[7]; | ||
614 | |||
615 | j = 0; | ||
616 | do { | ||
617 | /* Rounds 0 to 15 (unrolled): */ | ||
618 | ROUND512_0_TO_15(a,b,c,d,e,f,g,h); | ||
619 | ROUND512_0_TO_15(h,a,b,c,d,e,f,g); | ||
620 | ROUND512_0_TO_15(g,h,a,b,c,d,e,f); | ||
621 | ROUND512_0_TO_15(f,g,h,a,b,c,d,e); | ||
622 | ROUND512_0_TO_15(e,f,g,h,a,b,c,d); | ||
623 | ROUND512_0_TO_15(d,e,f,g,h,a,b,c); | ||
624 | ROUND512_0_TO_15(c,d,e,f,g,h,a,b); | ||
625 | ROUND512_0_TO_15(b,c,d,e,f,g,h,a); | ||
626 | } while (j < 16); | ||
627 | |||
628 | /* Now for the remaining rounds up to 79: */ | ||
629 | do { | ||
630 | ROUND512(a,b,c,d,e,f,g,h); | ||
631 | ROUND512(h,a,b,c,d,e,f,g); | ||
632 | ROUND512(g,h,a,b,c,d,e,f); | ||
633 | ROUND512(f,g,h,a,b,c,d,e); | ||
634 | ROUND512(e,f,g,h,a,b,c,d); | ||
635 | ROUND512(d,e,f,g,h,a,b,c); | ||
636 | ROUND512(c,d,e,f,g,h,a,b); | ||
637 | ROUND512(b,c,d,e,f,g,h,a); | ||
638 | } while (j < 80); | ||
639 | |||
640 | /* Compute the current intermediate hash value */ | ||
641 | state[0] += a; | ||
642 | state[1] += b; | ||
643 | state[2] += c; | ||
644 | state[3] += d; | ||
645 | state[4] += e; | ||
646 | state[5] += f; | ||
647 | state[6] += g; | ||
648 | state[7] += h; | ||
649 | |||
650 | /* Clean up */ | ||
651 | a = b = c = d = e = f = g = h = T1 = 0; | ||
652 | } | ||
653 | |||
654 | #else /* SHA2_UNROLL_TRANSFORM */ | ||
655 | |||
656 | void | ||
657 | SHA512_Transform(u_int64_t state[8], const u_int8_t data[SHA512_BLOCK_LENGTH]) | ||
658 | { | ||
659 | u_int64_t a, b, c, d, e, f, g, h, s0, s1; | ||
660 | u_int64_t T1, T2, W512[16]; | ||
661 | int j; | ||
662 | |||
663 | /* Initialize registers with the prev. intermediate value */ | ||
664 | a = state[0]; | ||
665 | b = state[1]; | ||
666 | c = state[2]; | ||
667 | d = state[3]; | ||
668 | e = state[4]; | ||
669 | f = state[5]; | ||
670 | g = state[6]; | ||
671 | h = state[7]; | ||
672 | |||
673 | j = 0; | ||
674 | do { | ||
675 | BE_8_TO_64(W512[j], data); | ||
676 | data += 8; | ||
677 | /* Apply the SHA-512 compression function to update a..h */ | ||
678 | T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + W512[j]; | ||
679 | T2 = Sigma0_512(a) + Maj(a, b, c); | ||
680 | h = g; | ||
681 | g = f; | ||
682 | f = e; | ||
683 | e = d + T1; | ||
684 | d = c; | ||
685 | c = b; | ||
686 | b = a; | ||
687 | a = T1 + T2; | ||
688 | |||
689 | j++; | ||
690 | } while (j < 16); | ||
691 | |||
692 | do { | ||
693 | /* Part of the message block expansion: */ | ||
694 | s0 = W512[(j+1)&0x0f]; | ||
695 | s0 = sigma0_512(s0); | ||
696 | s1 = W512[(j+14)&0x0f]; | ||
697 | s1 = sigma1_512(s1); | ||
698 | |||
699 | /* Apply the SHA-512 compression function to update a..h */ | ||
700 | T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + | ||
701 | (W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0); | ||
702 | T2 = Sigma0_512(a) + Maj(a, b, c); | ||
703 | h = g; | ||
704 | g = f; | ||
705 | f = e; | ||
706 | e = d + T1; | ||
707 | d = c; | ||
708 | c = b; | ||
709 | b = a; | ||
710 | a = T1 + T2; | ||
711 | |||
712 | j++; | ||
713 | } while (j < 80); | ||
714 | |||
715 | /* Compute the current intermediate hash value */ | ||
716 | state[0] += a; | ||
717 | state[1] += b; | ||
718 | state[2] += c; | ||
719 | state[3] += d; | ||
720 | state[4] += e; | ||
721 | state[5] += f; | ||
722 | state[6] += g; | ||
723 | state[7] += h; | ||
724 | |||
725 | /* Clean up */ | ||
726 | a = b = c = d = e = f = g = h = T1 = T2 = 0; | ||
727 | } | ||
728 | |||
729 | #endif /* SHA2_UNROLL_TRANSFORM */ | ||
730 | |||
731 | void | ||
732 | SHA512_Update(SHA512_CTX *context, const u_int8_t *data, size_t len) | ||
733 | { | ||
734 | size_t freespace, usedspace; | ||
735 | |||
736 | /* Calling with no data is valid (we do nothing) */ | ||
737 | if (len == 0) | ||
738 | return; | ||
739 | |||
740 | usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH; | ||
741 | if (usedspace > 0) { | ||
742 | /* Calculate how much free space is available in the buffer */ | ||
743 | freespace = SHA512_BLOCK_LENGTH - usedspace; | ||
744 | |||
745 | if (len >= freespace) { | ||
746 | /* Fill the buffer completely and process it */ | ||
747 | memcpy(&context->buffer[usedspace], data, freespace); | ||
748 | ADDINC128(context->bitcount, freespace << 3); | ||
749 | len -= freespace; | ||
750 | data += freespace; | ||
751 | SHA512_Transform(context->state, context->buffer); | ||
752 | } else { | ||
753 | /* The buffer is not yet full */ | ||
754 | memcpy(&context->buffer[usedspace], data, len); | ||
755 | ADDINC128(context->bitcount, len << 3); | ||
756 | /* Clean up: */ | ||
757 | usedspace = freespace = 0; | ||
758 | return; | ||
759 | } | ||
760 | } | ||
761 | while (len >= SHA512_BLOCK_LENGTH) { | ||
762 | /* Process as many complete blocks as we can */ | ||
763 | SHA512_Transform(context->state, data); | ||
764 | ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3); | ||
765 | len -= SHA512_BLOCK_LENGTH; | ||
766 | data += SHA512_BLOCK_LENGTH; | ||
767 | } | ||
768 | if (len > 0) { | ||
769 | /* There's left-overs, so save 'em */ | ||
770 | memcpy(context->buffer, data, len); | ||
771 | ADDINC128(context->bitcount, len << 3); | ||
772 | } | ||
773 | /* Clean up: */ | ||
774 | usedspace = freespace = 0; | ||
775 | } | ||
776 | |||
777 | void | ||
778 | SHA512_Pad(SHA512_CTX *context) | ||
779 | { | ||
780 | unsigned int usedspace; | ||
781 | |||
782 | usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH; | ||
783 | if (usedspace > 0) { | ||
784 | /* Begin padding with a 1 bit: */ | ||
785 | context->buffer[usedspace++] = 0x80; | ||
786 | |||
787 | if (usedspace <= SHA512_SHORT_BLOCK_LENGTH) { | ||
788 | /* Set-up for the last transform: */ | ||
789 | memset(&context->buffer[usedspace], 0, SHA512_SHORT_BLOCK_LENGTH - usedspace); | ||
790 | } else { | ||
791 | if (usedspace < SHA512_BLOCK_LENGTH) { | ||
792 | memset(&context->buffer[usedspace], 0, SHA512_BLOCK_LENGTH - usedspace); | ||
793 | } | ||
794 | /* Do second-to-last transform: */ | ||
795 | SHA512_Transform(context->state, context->buffer); | ||
796 | |||
797 | /* And set-up for the last transform: */ | ||
798 | memset(context->buffer, 0, SHA512_BLOCK_LENGTH - 2); | ||
799 | } | ||
800 | } else { | ||
801 | /* Prepare for final transform: */ | ||
802 | memset(context->buffer, 0, SHA512_SHORT_BLOCK_LENGTH); | ||
803 | |||
804 | /* Begin padding with a 1 bit: */ | ||
805 | *context->buffer = 0x80; | ||
806 | } | ||
807 | /* Store the length of input data (in bits) in big endian format: */ | ||
808 | BE_64_TO_8(&context->buffer[SHA512_SHORT_BLOCK_LENGTH], | ||
809 | context->bitcount[1]); | ||
810 | BE_64_TO_8(&context->buffer[SHA512_SHORT_BLOCK_LENGTH + 8], | ||
811 | context->bitcount[0]); | ||
812 | |||
813 | /* Final transform: */ | ||
814 | SHA512_Transform(context->state, context->buffer); | ||
815 | |||
816 | /* Clean up: */ | ||
817 | usedspace = 0; | ||
818 | } | ||
819 | |||
820 | void | ||
821 | SHA512_Final(u_int8_t digest[SHA512_DIGEST_LENGTH], SHA512_CTX *context) | ||
822 | { | ||
823 | SHA512_Pad(context); | ||
824 | |||
825 | /* If no digest buffer is passed, we don't bother doing this: */ | ||
826 | if (digest != NULL) { | ||
827 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
828 | int i; | ||
829 | |||
830 | /* Convert TO host byte order */ | ||
831 | for (i = 0; i < 8; i++) | ||
832 | BE_64_TO_8(digest + i * 8, context->state[i]); | ||
833 | #else | ||
834 | memcpy(digest, context->state, SHA512_DIGEST_LENGTH); | ||
835 | #endif | ||
836 | memset(context, 0, sizeof(*context)); | ||
837 | } | ||
838 | } | ||
839 | |||
840 | |||
841 | #if 0 | ||
842 | /*** SHA-384: *********************************************************/ | ||
843 | void | ||
844 | SHA384_Init(SHA384_CTX *context) | ||
845 | { | ||
846 | if (context == NULL) | ||
847 | return; | ||
848 | memcpy(context->state, sha384_initial_hash_value, | ||
849 | sizeof(sha384_initial_hash_value)); | ||
850 | memset(context->buffer, 0, sizeof(context->buffer)); | ||
851 | context->bitcount[0] = context->bitcount[1] = 0; | ||
852 | } | ||
853 | |||
854 | __weak_alias(SHA384_Transform, SHA512_Transform); | ||
855 | __weak_alias(SHA384_Update, SHA512_Update); | ||
856 | __weak_alias(SHA384_Pad, SHA512_Pad); | ||
857 | |||
858 | void | ||
859 | SHA384_Final(u_int8_t digest[SHA384_DIGEST_LENGTH], SHA384_CTX *context) | ||
860 | { | ||
861 | SHA384_Pad(context); | ||
862 | |||
863 | /* If no digest buffer is passed, we don't bother doing this: */ | ||
864 | if (digest != NULL) { | ||
865 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
866 | int i; | ||
867 | |||
868 | /* Convert TO host byte order */ | ||
869 | for (i = 0; i < 6; i++) | ||
870 | BE_64_TO_8(digest + i * 8, context->state[i]); | ||
871 | #else | ||
872 | memcpy(digest, context->state, SHA384_DIGEST_LENGTH); | ||
873 | #endif | ||
874 | } | ||
875 | |||
876 | /* Zero out state data */ | ||
877 | memset(context, 0, sizeof(*context)); | ||
878 | } | ||
879 | #endif | ||
880 | |||
881 | #endif /* !defined(HAVE_EVP_SHA256) && !defined(HAVE_SHA256_UPDATE) && \ | ||
882 | (OPENSSL_VERSION_NUMBER >= 0x00907000L) */ | ||
diff --git a/openbsd-compat/sha2.h b/openbsd-compat/sha2.h new file mode 100755 index 000000000..821f2dd6c --- /dev/null +++ b/openbsd-compat/sha2.h | |||
@@ -0,0 +1,133 @@ | |||
1 | /* $OpenBSD: sha2.h,v 1.6 2004/06/22 01:57:30 jfb Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * FILE: sha2.h | ||
5 | * AUTHOR: Aaron D. Gifford <me@aarongifford.com> | ||
6 | * | ||
7 | * Copyright (c) 2000-2001, Aaron D. Gifford | ||
8 | * All rights reserved. | ||
9 | * | ||
10 | * Redistribution and use in source and binary forms, with or without | ||
11 | * modification, are permitted provided that the following conditions | ||
12 | * are met: | ||
13 | * 1. Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in the | ||
17 | * documentation and/or other materials provided with the distribution. | ||
18 | * 3. Neither the name of the copyright holder nor the names of contributors | ||
19 | * may be used to endorse or promote products derived from this software | ||
20 | * without specific prior written permission. | ||
21 | * | ||
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND | ||
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE | ||
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | * SUCH DAMAGE. | ||
33 | * | ||
34 | * $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $ | ||
35 | */ | ||
36 | |||
37 | /* OPENBSD ORIGINAL: include/sha2.h */ | ||
38 | |||
39 | #ifndef _SSHSHA2_H | ||
40 | #define _SSHSHA2_H | ||
41 | |||
42 | #include "includes.h" | ||
43 | |||
44 | #include <openssl/opensslv.h> | ||
45 | |||
46 | #if !defined(HAVE_EVP_SHA256) && !defined(HAVE_SHA256_UPDATE) && \ | ||
47 | (OPENSSL_VERSION_NUMBER >= 0x00907000L) | ||
48 | |||
49 | /*** SHA-256/384/512 Various Length Definitions ***********************/ | ||
50 | #define SHA256_BLOCK_LENGTH 64 | ||
51 | #define SHA256_DIGEST_LENGTH 32 | ||
52 | #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) | ||
53 | #define SHA384_BLOCK_LENGTH 128 | ||
54 | #define SHA384_DIGEST_LENGTH 48 | ||
55 | #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1) | ||
56 | #define SHA512_BLOCK_LENGTH 128 | ||
57 | #define SHA512_DIGEST_LENGTH 64 | ||
58 | #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) | ||
59 | |||
60 | |||
61 | /*** SHA-256/384/512 Context Structures *******************************/ | ||
62 | typedef struct _SHA256_CTX { | ||
63 | u_int32_t state[8]; | ||
64 | u_int64_t bitcount; | ||
65 | u_int8_t buffer[SHA256_BLOCK_LENGTH]; | ||
66 | } SHA256_CTX; | ||
67 | typedef struct _SHA512_CTX { | ||
68 | u_int64_t state[8]; | ||
69 | u_int64_t bitcount[2]; | ||
70 | u_int8_t buffer[SHA512_BLOCK_LENGTH]; | ||
71 | } SHA512_CTX; | ||
72 | |||
73 | #if 0 | ||
74 | typedef SHA512_CTX SHA384_CTX; | ||
75 | #endif | ||
76 | |||
77 | void SHA256_Init(SHA256_CTX *); | ||
78 | void SHA256_Transform(u_int32_t state[8], const u_int8_t [SHA256_BLOCK_LENGTH]); | ||
79 | void SHA256_Update(SHA256_CTX *, const u_int8_t *, size_t) | ||
80 | __attribute__((__bounded__(__string__,2,3))); | ||
81 | void SHA256_Pad(SHA256_CTX *); | ||
82 | void SHA256_Final(u_int8_t [SHA256_DIGEST_LENGTH], SHA256_CTX *) | ||
83 | __attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH))); | ||
84 | char *SHA256_End(SHA256_CTX *, char *) | ||
85 | __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); | ||
86 | char *SHA256_File(const char *, char *) | ||
87 | __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); | ||
88 | char *SHA256_FileChunk(const char *, char *, off_t, off_t) | ||
89 | __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); | ||
90 | char *SHA256_Data(const u_int8_t *, size_t, char *) | ||
91 | __attribute__((__bounded__(__string__,1,2))) | ||
92 | __attribute__((__bounded__(__minbytes__,3,SHA256_DIGEST_STRING_LENGTH))); | ||
93 | |||
94 | #if 0 | ||
95 | void SHA384_Init(SHA384_CTX *); | ||
96 | void SHA384_Transform(u_int64_t state[8], const u_int8_t [SHA384_BLOCK_LENGTH]); | ||
97 | void SHA384_Update(SHA384_CTX *, const u_int8_t *, size_t) | ||
98 | __attribute__((__bounded__(__string__,2,3))); | ||
99 | void SHA384_Pad(SHA384_CTX *); | ||
100 | void SHA384_Final(u_int8_t [SHA384_DIGEST_LENGTH], SHA384_CTX *) | ||
101 | __attribute__((__bounded__(__minbytes__,1,SHA384_DIGEST_LENGTH))); | ||
102 | char *SHA384_End(SHA384_CTX *, char *) | ||
103 | __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); | ||
104 | char *SHA384_File(const char *, char *) | ||
105 | __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); | ||
106 | char *SHA384_FileChunk(const char *, char *, off_t, off_t) | ||
107 | __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); | ||
108 | char *SHA384_Data(const u_int8_t *, size_t, char *) | ||
109 | __attribute__((__bounded__(__string__,1,2))) | ||
110 | __attribute__((__bounded__(__minbytes__,3,SHA384_DIGEST_STRING_LENGTH))); | ||
111 | #endif /* 0 */ | ||
112 | |||
113 | void SHA512_Init(SHA512_CTX *); | ||
114 | void SHA512_Transform(u_int64_t state[8], const u_int8_t [SHA512_BLOCK_LENGTH]); | ||
115 | void SHA512_Update(SHA512_CTX *, const u_int8_t *, size_t) | ||
116 | __attribute__((__bounded__(__string__,2,3))); | ||
117 | void SHA512_Pad(SHA512_CTX *); | ||
118 | void SHA512_Final(u_int8_t [SHA512_DIGEST_LENGTH], SHA512_CTX *) | ||
119 | __attribute__((__bounded__(__minbytes__,1,SHA512_DIGEST_LENGTH))); | ||
120 | char *SHA512_End(SHA512_CTX *, char *) | ||
121 | __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); | ||
122 | char *SHA512_File(const char *, char *) | ||
123 | __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); | ||
124 | char *SHA512_FileChunk(const char *, char *, off_t, off_t) | ||
125 | __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); | ||
126 | char *SHA512_Data(const u_int8_t *, size_t, char *) | ||
127 | __attribute__((__bounded__(__string__,1,2))) | ||
128 | __attribute__((__bounded__(__minbytes__,3,SHA512_DIGEST_STRING_LENGTH))); | ||
129 | |||
130 | #endif /* !defined(HAVE_EVP_SHA256) && !defined(HAVE_SHA256_UPDATE) && \ | ||
131 | (OPENSSL_VERSION_NUMBER >= 0x00907000L) */ | ||
132 | |||
133 | #endif /* _SSHSHA2_H */ | ||
diff --git a/openbsd-compat/strtonum.c b/openbsd-compat/strtonum.c index 8ad0d0058..87f2f24b2 100644 --- a/openbsd-compat/strtonum.c +++ b/openbsd-compat/strtonum.c | |||
@@ -20,8 +20,11 @@ | |||
20 | /* OPENBSD ORIGINAL: lib/libc/stdlib/strtonum.c */ | 20 | /* OPENBSD ORIGINAL: lib/libc/stdlib/strtonum.c */ |
21 | 21 | ||
22 | #include "includes.h" | 22 | #include "includes.h" |
23 | |||
23 | #ifndef HAVE_STRTONUM | 24 | #ifndef HAVE_STRTONUM |
25 | #include <stdlib.h> | ||
24 | #include <limits.h> | 26 | #include <limits.h> |
27 | #include <errno.h> | ||
25 | 28 | ||
26 | #define INVALID 1 | 29 | #define INVALID 1 |
27 | #define TOOSMALL 2 | 30 | #define TOOSMALL 2 |
diff --git a/openbsd-compat/xcrypt.c b/openbsd-compat/xcrypt.c index 9afa0b9f2..14899321f 100644 --- a/openbsd-compat/xcrypt.c +++ b/openbsd-compat/xcrypt.c | |||
@@ -24,6 +24,10 @@ | |||
24 | 24 | ||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | 26 | ||
27 | #include <sys/types.h> | ||
28 | #include <unistd.h> | ||
29 | #include <pwd.h> | ||
30 | |||
27 | # ifdef HAVE_CRYPT_H | 31 | # ifdef HAVE_CRYPT_H |
28 | # include <crypt.h> | 32 | # include <crypt.h> |
29 | # endif | 33 | # endif |
diff --git a/openbsd-compat/xmmap.c b/openbsd-compat/xmmap.c index 74e8a8b13..0fb23269b 100644 --- a/openbsd-compat/xmmap.c +++ b/openbsd-compat/xmmap.c | |||
@@ -23,21 +23,31 @@ | |||
23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ | 24 | */ |
25 | 25 | ||
26 | /* $Id: xmmap.c,v 1.6 2004/10/06 13:15:44 dtucker Exp $ */ | 26 | /* $Id: xmmap.c,v 1.12 2006/08/24 09:58:36 dtucker Exp $ */ |
27 | 27 | ||
28 | #include "includes.h" | 28 | #include "includes.h" |
29 | 29 | ||
30 | #include <sys/types.h> | ||
30 | #ifdef HAVE_SYS_MMAN_H | 31 | #ifdef HAVE_SYS_MMAN_H |
31 | #include <sys/mman.h> | 32 | #include <sys/mman.h> |
32 | #endif | 33 | #endif |
34 | #include <sys/stat.h> | ||
35 | |||
36 | #ifdef HAVE_FCNTL_H | ||
37 | # include <fcntl.h> | ||
38 | #endif | ||
39 | #include <errno.h> | ||
40 | #include <stdarg.h> | ||
41 | #include <string.h> | ||
42 | #include <unistd.h> | ||
33 | 43 | ||
34 | #include "log.h" | 44 | #include "log.h" |
35 | 45 | ||
36 | void *xmmap(size_t size) | 46 | void *xmmap(size_t size) |
37 | { | 47 | { |
48 | #ifdef HAVE_MMAP | ||
38 | void *address; | 49 | void *address; |
39 | 50 | ||
40 | #ifdef HAVE_MMAP | ||
41 | # ifdef MAP_ANON | 51 | # ifdef MAP_ANON |
42 | address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_ANON|MAP_SHARED, | 52 | address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_ANON|MAP_SHARED, |
43 | -1, (off_t)0); | 53 | -1, (off_t)0); |