summaryrefslogtreecommitdiff
path: root/openbsd-compat/bsd-poll.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2007-12-24 10:29:57 +0000
committerColin Watson <cjwatson@debian.org>2007-12-24 10:29:57 +0000
commitc3e531b12b2335b7fa5a6bcc9a309d3c523ff64b (patch)
treeb72c0867348e7e7914d64af6fc5e25c728922e03 /openbsd-compat/bsd-poll.c
parent6b222fdf3cb54c11a446df38e027fe7acf2220cb (diff)
parent70847d299887abb96f8703ca99db6d817b78960e (diff)
* New upstream release (closes: #453367).
- CVE-2007-4752: Prevent ssh(1) from using a trusted X11 cookie if creation of an untrusted cookie fails; found and fixed by Jan Pechanec (closes: #444738). - sshd(8) in new installations defaults to SSH Protocol 2 only. Existing installations are unchanged. - The SSH channel window size has been increased, and both ssh(1) sshd(8) now send window updates more aggressively. These improves performance on high-BDP (Bandwidth Delay Product) networks. - ssh(1) and sshd(8) now preserve MAC contexts between packets, which saves 2 hash calls per packet and results in 12-16% speedup for arcfour256/hmac-md5. - A new MAC algorithm has been added, UMAC-64 (RFC4418) as "umac-64@openssh.com". UMAC-64 has been measured to be approximately 20% faster than HMAC-MD5. - Failure to establish a ssh(1) TunnelForward is now treated as a fatal error when the ExitOnForwardFailure option is set. - ssh(1) returns a sensible exit status if the control master goes away without passing the full exit status. - When using a ProxyCommand in ssh(1), set the outgoing hostname with gethostname(2), allowing hostbased authentication to work. - Make scp(1) skip FIFOs rather than hanging (closes: #246774). - Encode non-printing characters in scp(1) filenames. These could cause copies to be aborted with a "protocol error". - Handle SIGINT in sshd(8) privilege separation child process to ensure that wtmp and lastlog records are correctly updated. - Report GSSAPI mechanism in errors, for libraries that support multiple mechanisms. - Improve documentation for ssh-add(1)'s -d option. - Rearrange and tidy GSSAPI code, removing server-only code being linked into the client. - Delay execution of ssh(1)'s LocalCommand until after all forwardings have been established. - In scp(1), do not truncate non-regular files. - Improve exit message from ControlMaster clients. - Prevent sftp-server(8) from reading until it runs out of buffer space, whereupon it would exit with a fatal error (closes: #365541). - pam_end() was not being called if authentication failed (closes: #405041). - Manual page datestamps updated (closes: #433181).
Diffstat (limited to 'openbsd-compat/bsd-poll.c')
-rw-r--r--openbsd-compat/bsd-poll.c117
1 files changed, 117 insertions, 0 deletions
diff --git a/openbsd-compat/bsd-poll.c b/openbsd-compat/bsd-poll.c
new file mode 100644
index 000000000..836882eea
--- /dev/null
+++ b/openbsd-compat/bsd-poll.c
@@ -0,0 +1,117 @@
1/* $Id: bsd-poll.c,v 1.1 2007/06/25 12:15:13 dtucker Exp $ */
2
3/*
4 * Copyright (c) 2004, 2005, 2007 Darren Tucker (dtucker at zip com au).
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 "includes.h"
20#if !defined(HAVE_POLL) && defined(HAVE_SELECT)
21
22#ifdef HAVE_SYS_SELECT_H
23# include <sys/select.h>
24#endif
25
26#include <errno.h>
27#include "bsd-poll.h"
28
29/*
30 * A minimal implementation of poll(2), built on top of select(2).
31 *
32 * Only supports POLLIN and POLLOUT flags in pfd.events, and POLLIN, POLLOUT
33 * and POLLERR flags in revents.
34 *
35 * Supports pfd.fd = -1 meaning "unused" although it's not standard.
36 */
37
38int
39poll(struct pollfd *fds, nfds_t nfds, int timeout)
40{
41 nfds_t i;
42 int saved_errno, ret, fd, maxfd = 0;
43 fd_set *readfds = NULL, *writefds = NULL, *exceptfds = NULL;
44 size_t nmemb;
45 struct timeval tv, *tvp = NULL;
46
47 for (i = 0; i < nfds; i++) {
48 if (fd >= FD_SETSIZE) {
49 errno = EINVAL;
50 return -1;
51 }
52 maxfd = MAX(maxfd, fds[i].fd);
53 }
54
55 nmemb = howmany(maxfd + 1 , NFDBITS);
56 if ((readfds = calloc(nmemb, sizeof(fd_mask))) == NULL ||
57 (writefds = calloc(nmemb, sizeof(fd_mask))) == NULL ||
58 (exceptfds = calloc(nmemb, sizeof(fd_mask))) == NULL) {
59 saved_errno = ENOMEM;
60 ret = -1;
61 goto out;
62 }
63
64 /* populate event bit vectors for the events we're interested in */
65 for (i = 0; i < nfds; i++) {
66 fd = fds[i].fd;
67 if (fd == -1)
68 continue;
69 if (fds[i].events & POLLIN) {
70 FD_SET(fd, readfds);
71 FD_SET(fd, exceptfds);
72 }
73 if (fds[i].events & POLLOUT) {
74 FD_SET(fd, writefds);
75 FD_SET(fd, exceptfds);
76 }
77 }
78
79 /* poll timeout is msec, select is timeval (sec + usec) */
80 if (timeout >= 0) {
81 tv.tv_sec = timeout / 1000;
82 tv.tv_usec = (timeout % 1000) * 1000;
83 tvp = &tv;
84 }
85
86 ret = select(maxfd + 1, readfds, writefds, exceptfds, tvp);
87 saved_errno = errno;
88
89 /* scan through select results and set poll() flags */
90 for (i = 0; i < nfds; i++) {
91 fd = fds[i].fd;
92 fds[i].revents = 0;
93 if (fd == -1)
94 continue;
95 if (FD_ISSET(fd, readfds)) {
96 fds[i].revents |= POLLIN;
97 }
98 if (FD_ISSET(fd, writefds)) {
99 fds[i].revents |= POLLOUT;
100 }
101 if (FD_ISSET(fd, exceptfds)) {
102 fds[i].revents |= POLLERR;
103 }
104 }
105
106out:
107 if (readfds != NULL)
108 free(readfds);
109 if (writefds != NULL)
110 free(writefds);
111 if (exceptfds != NULL)
112 free(exceptfds);
113 if (ret == -1)
114 errno = saved_errno;
115 return ret;
116}
117#endif