~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/xfs/os/waitfor.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: waitfor.c,v 1.4 2001/02/09 02:05:45 xorgcvs Exp $ */
 
2
/*
 
3
 * waits for input
 
4
 */
 
5
/*
 
6
Copyright 1987, 1998  The Open Group
 
7
 
 
8
Permission to use, copy, modify, distribute, and sell this software and its
 
9
documentation for any purpose is hereby granted without fee, provided that
 
10
the above copyright notice appear in all copies and that both that
 
11
copyright notice and this permission notice appear in supporting
 
12
documentation.
 
13
 
 
14
The above copyright notice and this permission notice shall be included in
 
15
all copies or substantial portions of the Software.
 
16
 
 
17
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
18
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
19
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
20
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
21
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
22
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
23
 
 
24
Except as contained in this notice, the name of The Open Group shall not be
 
25
used in advertising or otherwise to promote the sale, use or other dealings
 
26
in this Software without prior written authorization from The Open Group.
 
27
 * Copyright 1990, 1991 Network Computing Devices;
 
28
 * Portions Copyright 1987 by Digital Equipment Corporation 
 
29
 *
 
30
 * Permission to use, copy, modify, distribute, and sell this software and its
 
31
 * documentation for any purpose is hereby granted without fee, provided that
 
32
 * the above copyright notice appear in all copies and that both that
 
33
 * copyright notice and this permission notice appear in supporting
 
34
 * documentation, and that the names of Network Computing Devices,
 
35
 * or Digital not be used in advertising or
 
36
 * publicity pertaining to distribution of the software without specific,
 
37
 * written prior permission.  Network Computing Devices, or Digital
 
38
 * make no representations about the
 
39
 * suitability of this software for any purpose.  It is provided "as is"
 
40
 * without express or implied warranty.
 
41
 *
 
42
 * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH
 
43
 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 
44
 * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, OR DIGITAL BE
 
45
 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 
46
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 
47
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 
48
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
49
 *
 
50
 * $NCDXorg: @(#)waitfor.c,v 4.5 1991/06/24 11:59:20 lemke Exp $
 
51
 *
 
52
 */
 
53
/* $XFree86: xc/programs/xfs/os/waitfor.c,v 3.16 2002/05/31 18:46:12 dawes Exp $ */
 
54
 
 
55
#include        <X11/Xos.h>     /* strings, time, etc */
 
56
 
 
57
#include        <stdio.h>
 
58
#include        <errno.h>
 
59
#if !defined(Lynx)
 
60
#include        <sys/param.h>
 
61
#endif
 
62
 
 
63
#include        "clientstr.h"
 
64
#include        "globals.h"
 
65
#include        "X11/Xpoll.h"
 
66
#include        "osdep.h"
 
67
#include        "os.h"
 
68
 
 
69
#ifdef __UNIXOS2__
 
70
#define select(n,r,w,x,t) os2PseudoSelect(n,r,w,x,t)
 
71
#endif
 
72
 
 
73
extern WorkQueuePtr workQueue;
 
74
 
 
75
 
 
76
extern fd_set WellKnownConnections;
 
77
extern fd_set LastSelectMask;
 
78
extern fd_set WriteMask;
 
79
extern fd_set ClientsWithInput;
 
80
extern fd_set ClientsWriteBlocked;
 
81
extern fd_set AllSockets;
 
82
extern fd_set AllClients;
 
83
extern fd_set OutputPending;
 
84
 
 
85
extern Bool AnyClientsWriteBlocked;
 
86
extern Bool NewOutputPending;
 
87
 
 
88
extern int  ConnectionTranslation[];
 
89
 
 
90
long        LastReapTime;
 
91
 
 
92
/*
 
93
 * wait_for_something
 
94
 *
 
95
 * server suspends until
 
96
 * - data from clients
 
97
 * - new client connects
 
98
 * - room to write data to clients
 
99
 */
 
100
 
 
101
int
 
102
WaitForSomething(int *pClientsReady)
 
103
{
 
104
    struct timeval *wt,
 
105
                waittime;
 
106
    fd_set      clientsReadable;
 
107
    fd_set      clientsWriteable;
 
108
    long        curclient;
 
109
    int         selecterr;
 
110
    long        current_time = 0;
 
111
    long        timeout;
 
112
    int         nready,
 
113
                i;
 
114
 
 
115
    while (1) {
 
116
        /* handle the work Q */
 
117
        if (workQueue)
 
118
            ProcessWorkQueue();
 
119
 
 
120
        if (XFD_ANYSET(&ClientsWithInput)) {
 
121
            XFD_COPYSET(&ClientsWithInput, &clientsReadable);
 
122
            break;
 
123
        }
 
124
        /*
 
125
         * deal with KeepAlive timeouts.  if this seems to costly, SIGALRM
 
126
         * could be used, but its more dangerous since some it could catch us
 
127
         * at an inopportune moment (like inside un-reentrant malloc()).
 
128
         */
 
129
        current_time = GetTimeInMillis();
 
130
        timeout = current_time - LastReapTime;
 
131
        if (timeout > ReapClientTime) {
 
132
            ReapAnyOldClients();
 
133
            LastReapTime = current_time;
 
134
            timeout = ReapClientTime;
 
135
        }
 
136
        timeout = ReapClientTime - timeout;
 
137
        waittime.tv_sec = timeout / MILLI_PER_SECOND;
 
138
        waittime.tv_usec = (timeout % MILLI_PER_SECOND) *
 
139
            (1000000 / MILLI_PER_SECOND);
 
140
        wt = &waittime;
 
141
 
 
142
        XFD_COPYSET(&AllSockets, &LastSelectMask);
 
143
 
 
144
        BlockHandler(&wt, (pointer) &LastSelectMask);
 
145
        if (NewOutputPending)
 
146
            FlushAllOutput();
 
147
 
 
148
        if (AnyClientsWriteBlocked) {
 
149
            XFD_COPYSET(&ClientsWriteBlocked, &clientsWriteable);
 
150
            i = Select(MAXSOCKS, &LastSelectMask, &clientsWriteable, NULL, wt);
 
151
        } else {
 
152
            i = Select(MAXSOCKS, &LastSelectMask, NULL, NULL, wt);
 
153
        }
 
154
        selecterr = errno;
 
155
 
 
156
        WakeupHandler(i, (unsigned long *) &LastSelectMask);
 
157
        if (i <= 0) {           /* error or timeout */
 
158
            FD_ZERO(&clientsWriteable);
 
159
            if (i < 0) {
 
160
                if (selecterr == EBADF) {       /* somebody disconnected */
 
161
                    CheckConnections();
 
162
                } else if (selecterr != EINTR) {
 
163
                    ErrorF("WaitForSomething: select(): errno %d\n", selecterr);
 
164
                } else {
 
165
                    /*
 
166
                     * must have been broken by a signal.  go deal with any
 
167
                     * exception flags
 
168
                     */
 
169
                    return 0;
 
170
                }
 
171
            } else {            /* must have timed out */
 
172
                ReapAnyOldClients();
 
173
                LastReapTime = GetTimeInMillis();
 
174
            }
 
175
        } else {
 
176
            if (AnyClientsWriteBlocked && XFD_ANYSET(&clientsWriteable)) {
 
177
                NewOutputPending = TRUE;
 
178
                XFD_ORSET(&OutputPending, &clientsWriteable, &OutputPending);
 
179
                XFD_UNSET(&ClientsWriteBlocked, &clientsWriteable);
 
180
                if (!XFD_ANYSET(&ClientsWriteBlocked))
 
181
                    AnyClientsWriteBlocked = FALSE;
 
182
            }
 
183
            XFD_ANDSET(&clientsReadable, &LastSelectMask, &AllClients);
 
184
            if (LastSelectMask.fds_bits[0] & WellKnownConnections.fds_bits[0])
 
185
                MakeNewConnections();
 
186
            if (XFD_ANYSET(&clientsReadable))
 
187
                break;
 
188
 
 
189
        }
 
190
    }
 
191
    nready = 0;
 
192
 
 
193
    if (XFD_ANYSET(&clientsReadable)) {
 
194
        ClientPtr   client;
 
195
        int         conn;
 
196
 
 
197
        if (current_time)       /* may not have been set */
 
198
            current_time = GetTimeInMillis();
 
199
        for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++) {
 
200
            while (clientsReadable.fds_bits[i]) {
 
201
                curclient = ffs(clientsReadable.fds_bits[i]) - 1;
 
202
                conn = ConnectionTranslation[curclient + (i << 5)];
 
203
                clientsReadable.fds_bits[i] &= ~(((fd_mask)1L) << curclient);
 
204
                client = clients[conn];
 
205
                if (!client)
 
206
                    continue;
 
207
                pClientsReady[nready++] = conn;
 
208
                client->last_request_time = current_time;
 
209
                client->clientGone = CLIENT_ALIVE;
 
210
            }
 
211
        }
 
212
    }
 
213
    return nready;
 
214
}
 
215
 
 
216
#if 0
 
217
/*
 
218
 * This is not always a macro
 
219
  */
 
220
int
 
221
ANYSET(long *src)
 
222
{
 
223
    int         i;
 
224
 
 
225
    for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++)
 
226
        if (src[i])
 
227
            return (1);
 
228
    return (0);
 
229
}
 
230
 
 
231
#endif