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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/kdrive/linux/ms.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
/*
 
2
Copyright (c) 2001 by Juliusz Chroboczek
 
3
Copyright (c) 1999 by Keith Packard
 
4
 
 
5
Permission is hereby granted, free of charge, to any person obtaining a copy
 
6
of this software and associated documentation files (the "Software"), to deal
 
7
in the Software without restriction, including without limitation the rights
 
8
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
9
copies of the Software, and to permit persons to whom the Software is
 
10
furnished to do so, subject to the following conditions:
 
11
 
 
12
The above copyright notice and this permission notice shall be included in
 
13
all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
18
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
19
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
20
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
21
THE SOFTWARE.
 
22
*/
 
23
/* $XFree86: xc/programs/Xserver/hw/kdrive/linux/ms.c,v 1.2 2001/10/12 06:33:10 keithp Exp $ */
 
24
 
 
25
#define NEED_EVENTS
 
26
#include "X.h"
 
27
#include "Xproto.h"
 
28
#include "inputstr.h"
 
29
#include "scrnintstr.h"
 
30
#include "kdrive.h"
 
31
#include "Xpoll.h"
 
32
#include <errno.h>
 
33
#include <termios.h>
 
34
 
 
35
int
 
36
MsReadBytes (int fd, char *buf, int len, int min)
 
37
{
 
38
    int             n, tot;
 
39
    fd_set          set;
 
40
    struct timeval  tv;
 
41
 
 
42
    tot = 0;
 
43
    while (len)
 
44
    {
 
45
        n = read (fd, buf, len);
 
46
        if (n > 0)
 
47
        {
 
48
            tot += n;
 
49
            buf += n;
 
50
            len -= n;
 
51
        }
 
52
        if (tot % min == 0)
 
53
            break;
 
54
        FD_ZERO (&set);
 
55
        FD_SET (fd, &set);
 
56
        tv.tv_sec = 0;
 
57
        tv.tv_usec = 100 * 1000;
 
58
        n = select (fd + 1, &set, 0, 0, &tv);
 
59
        if (n <= 0)
 
60
            break;
 
61
    }
 
62
    return tot;
 
63
}
 
64
 
 
65
void
 
66
MsRead (int port, void *closure)
 
67
{
 
68
    unsigned char   buf[3 * 200];
 
69
    unsigned char   *b;
 
70
    int             n;
 
71
    int             dx, dy;
 
72
    unsigned long   flags;
 
73
 
 
74
    while ((n = MsReadBytes (port, buf, sizeof (buf), 3)) > 0)
 
75
    {
 
76
        b = buf;
 
77
        while (n >= 3)
 
78
        {
 
79
            flags = KD_MOUSE_DELTA;
 
80
 
 
81
            if (b[0] & 0x20)
 
82
                flags |= KD_BUTTON_1;
 
83
            if (b[0] & 0x10)
 
84
                flags |= KD_BUTTON_3;
 
85
            
 
86
            dx = (char)(((b[0] & 0x03) << 6) | (b[1] & 0x3F));
 
87
            dy = (char)(((b[0] & 0x0C) << 4) | (b[2] & 0x3F));
 
88
            n -= 3;
 
89
            b += 3;
 
90
            KdEnqueueMouseEvent (kdMouseInfo, flags, dx, dy);
 
91
        }
 
92
    }
 
93
}
 
94
 
 
95
int MsInputType;
 
96
 
 
97
int
 
98
MsInit (void)
 
99
{
 
100
    int port;
 
101
    char *device = "/dev/mouse";
 
102
    struct termios t;
 
103
    int ret;
 
104
 
 
105
    if (!MsInputType)
 
106
        MsInputType = KdAllocInputType ();
 
107
    port = open (device, O_RDWR | O_NONBLOCK);
 
108
    if(port < 0) {
 
109
        ErrorF("Couldn't open %s (%d)\n", device, (int)errno);
 
110
        return 0;
 
111
    } else if (port == 0) {
 
112
        ErrorF("Opening %s returned 0!  Please complain to Keith.\n",
 
113
               device);
 
114
        goto bail;
 
115
    }
 
116
 
 
117
    if(!isatty(port)) {
 
118
        ErrorF("%s is not a tty\n", device);
 
119
        goto bail;
 
120
    }
 
121
 
 
122
    ret = tcgetattr(port, &t);
 
123
    if(ret < 0) {
 
124
        ErrorF("Couldn't tcgetattr(%s): %d\n", device, errno);
 
125
        goto bail;
 
126
    }
 
127
    t.c_iflag &= ~ (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR |
 
128
                   IGNCR | ICRNL | IXON | IXOFF);
 
129
    t.c_oflag &= ~ OPOST;
 
130
    t.c_lflag &= ~ (ECHO | ECHONL | ICANON | ISIG | IEXTEN);
 
131
    t.c_cflag &= ~ (CSIZE | PARENB);
 
132
    t.c_cflag |= CS8 | CLOCAL | CSTOPB;
 
133
 
 
134
    cfsetispeed (&t, B1200);
 
135
    cfsetospeed (&t, B1200);
 
136
    t.c_cc[VMIN] = 1;
 
137
    t.c_cc[VTIME] = 0;
 
138
    ret = tcsetattr(port, TCSANOW, &t);
 
139
    if(ret < 0) {
 
140
        ErrorF("Couldn't tcsetattr(%s): %d\n", device, errno);
 
141
        goto bail;
 
142
    }
 
143
    if (KdRegisterFd (MsInputType, port, MsRead, (void *) 0))
 
144
        return 1;
 
145
 
 
146
 bail:
 
147
    close(port);
 
148
    return 0;
 
149
}
 
150
 
 
151
void
 
152
MsFini (void)
 
153
{
 
154
    KdUnregisterFds (MsInputType, TRUE);
 
155
}
 
156
 
 
157
KdMouseFuncs MsMouseFuncs = {
 
158
    MsInit,
 
159
    MsFini
 
160
};