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

« back to all changes in this revision

Viewing changes to unix/xc/programs/xtrap/xtrapout.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
/* $XFree86: xc/programs/xtrap/xtrapout.c,v 1.2 2001/12/12 00:43:50 dawes Exp $ */
 
2
/*
 
3
 * @DEC_COPYRIGHT@
 
4
 */
 
5
/*
 
6
 * HISTORY
 
7
 * Log: xtrapout.c,v $
 
8
 * Revision 1.1.4.2  1993/12/14  12:37:28  Kenneth_Miller
 
9
 *      ANSI-standardize code and turn client build on
 
10
 *      [1993/12/09  20:16:01  Kenneth_Miller]
 
11
 *
 
12
 * Revision 1.1.2.2  1992/04/27  13:51:57  Leela_Obilichetti
 
13
 *      initial load of xtrap clients - from silver BL6 pool
 
14
 *      [92/04/27  13:49:33  Leela_Obilichetti]
 
15
 * 
 
16
 * EndLog$
 
17
 */
 
18
/*****************************************************************************
 
19
Copyright 1987, 1988, 1989, 1990, 1991, 1993 by Digital Equipment Corp., 
 
20
Maynard, MA
 
21
 
 
22
Permission to use, copy, modify, and distribute this software and its 
 
23
documentation for any purpose and without fee is hereby granted, 
 
24
provided that the above copyright notice appear in all copies and that
 
25
both that copyright notice and this permission notice appear in 
 
26
supporting documentation, and that the name of Digital not be
 
27
used in advertising or publicity pertaining to distribution of the
 
28
software without specific, written prior permission.  
 
29
 
 
30
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 
31
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 
32
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 
33
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
34
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 
35
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 
36
SOFTWARE.
 
37
 
 
38
*****************************************************************************/
 
39
/*
 
40
 *
 
41
 *  CONTRIBUTORS:
 
42
 *
 
43
 *      Dick Annicchiarico
 
44
 *      Robert Chesler
 
45
 *      Dan Coutu
 
46
 *      Gene Durso
 
47
 *      Marc Evans
 
48
 *      Alan Jamison
 
49
 *      Mark Henry
 
50
 *      Ken Miller
 
51
 *
 
52
 */
 
53
#define ProgName "xtrapout"
 
54
/*
 
55
**++
 
56
**  FACILITY:  xtrapout - Sample client to test output from XTrap extension
 
57
**
 
58
**  MODULE DESCRIPTION:
 
59
**
 
60
**      This is the main module for a sample/test client
 
61
**      for the XTrap X11 Server Extension.  It accepts  
 
62
**      a script output file, a transport method,
 
63
**      and an "events mode" flag (-e) as input,
 
64
**      in addition to the standard X arguments (-d, etc.).
 
65
**      If no script file is provided, stdout is the default
 
66
**      and can be piped to the companion "xtrapin"
 
67
**      client (normally used with the -e argument which  
 
68
**      sends all core input events to stdout).
 
69
**
 
70
**
 
71
**  AUTHORS:
 
72
**
 
73
**      Kenneth B. Miller
 
74
**
 
75
**  CREATION DATE:  March 28, 1990
 
76
**
 
77
**  DESIGN ISSUES:
 
78
**
 
79
**      See the companion "xtrapin" client.
 
80
**
 
81
**      Also, getopt() is used to parse the command
 
82
**      line arguments prior to calling XtAppInitialize().
 
83
**      This is because DECwindows appears to remove the user-
 
84
**      defined arguments from the argv[] vector without actually
 
85
**      acting upon them.
 
86
**
 
87
**
 
88
**--
 
89
*/
 
90
 
 
91
#include <stdio.h>
 
92
#include <X11/extensions/xtraplib.h>
 
93
#include <X11/extensions/xtraplibp.h>
 
94
#include <signal.h>
 
95
#include <X11/keysym.h>
 
96
#include <unistd.h>
 
97
#include <stdlib.h>
 
98
 
 
99
#include "XEKeybCtrl.h"
 
100
 
 
101
#ifndef vaxc
 
102
#define globalref extern
 
103
#endif
 
104
 
 
105
 
 
106
/* Forward declarations */
 
107
static void SetGlobalDone (void );
 
108
static void print_req_callback (XETC *tc , XETrapDatum *data , 
 
109
    char *my_buf );
 
110
static void print_evt_callback (XETC *tc , XETrapDatum *data , 
 
111
    char *my_buf );
 
112
 
 
113
 
 
114
FILE *ofp;
 
115
Bool GlobalDone = False;
 
116
XrmOptionDescRec optionTable [] = 
 
117
{
 
118
    {"-f",     "*script",    XrmoptionSepArg,  (caddr_t) NULL},
 
119
    {"-e",     "*eventFlag", XrmoptionSkipArg, (caddr_t) NULL},
 
120
    {"-v",     "*verbose",   XrmoptionSkipArg, (caddr_t) NULL},
 
121
};
 
122
 
 
123
static void SetGlobalDone(void)
 
124
{
 
125
    GlobalDone = 1L;
 
126
    fprintf(stderr,"Process Completed!\n");
 
127
    return;
 
128
}
 
129
 
 
130
static void print_req_callback(XETC *tc, XETrapDatum *data, char *my_buf)
 
131
{
 
132
    char *req_type;
 
133
    req_type = (data->u.req.reqType == XETrapGetExtOpcode(tc) ? "XTrap" :
 
134
        XERequestIDToString(data->u.req.reqType,tc));
 
135
    fprintf(ofp,"Request: %-19s (%d): length '%ld' client '%d' window=%ld\n", 
 
136
        req_type, data->u.req.reqType, (long)data->hdr.count, data->hdr.client, 
 
137
        (long)data->u.req.id);
 
138
}
 
139
 
 
140
static void print_evt_callback(XETC *tc, XETrapDatum *data, char *my_buf)
 
141
{
 
142
    static Time last_time = 0;
 
143
    int delta;
 
144
 
 
145
    delta = abs((int)last_time ? data->u.event.u.keyButtonPointer.time -
 
146
        (int)last_time  : (int)last_time);
 
147
    last_time = data->u.event.u.keyButtonPointer.time;
 
148
 
 
149
    /* The "screen" and "root" fields aren't valid until "event"
 
150
     * vectoring becomes a reality.  Currently, XTrap intercepts
 
151
     * the core events prior to when fields other than rootX, rootY,
 
152
     * type, detail, time, and state are filled in.  This will be
 
153
     * addressed in the next release of XTrap (3.2?).
 
154
     */
 
155
    fprintf(ofp,
 
156
        "Event: %-15s (%d):det=%d scr=%d (%d,%d) root=%d Msk=%d TS=%d\n",
 
157
        XEEventIDToString(data->u.event.u.u.type,tc), data->u.event.u.u.type,
 
158
        data->u.event.u.u.detail, data->hdr.screen, /* Not really valid yet */
 
159
        data->u.event.u.keyButtonPointer.rootX, 
 
160
        data->u.event.u.keyButtonPointer.rootY,
 
161
        (int)data->u.event.u.keyButtonPointer.root, /* Not really valid yet */
 
162
        (int)data->u.event.u.keyButtonPointer.state,
 
163
        (int)delta);
 
164
    fflush(ofp);
 
165
}
 
166
static Boolean eventFlag = False;
 
167
static Boolean verboseFlag = False;
 
168
static Widget appW;
 
169
static Display *dpy;
 
170
 
 
171
int
 
172
main(int argc, char *argv[])
 
173
{
 
174
    XETrapGetAvailRep ret_avail;
 
175
    XETrapGetCurRep   ret_cur;
 
176
    XETC    *tc;
 
177
    ReqFlags     requests;
 
178
    EventFlags   events;
 
179
    XtAppContext app;
 
180
    char *tmp = NULL;
 
181
    INT16 ch;
 
182
    int *popterr;
 
183
    char **poptarg;
 
184
#ifndef vms
 
185
    popterr = &opterr;
 
186
    poptarg = &optarg;
 
187
#else
 
188
    popterr = XEgetopterr();
 
189
    poptarg = XEgetoptarg();
 
190
#endif
 
191
 
 
192
    eventFlag = False;
 
193
    ofp = NULL;
 
194
    *popterr = 0; /* don't complain about -d (display) */
 
195
    while ((ch = getopt(argc, argv, "d:evf:")) != EOF)
 
196
    {
 
197
        switch(ch)
 
198
        {
 
199
            case 'e':
 
200
                eventFlag = True;
 
201
                break;
 
202
            case 'v':
 
203
                verboseFlag = True;
 
204
                break;
 
205
            case 'f':
 
206
                if ((ofp = fopen(*poptarg,"wb")) == NULL)
 
207
                {   /* can't open it */
 
208
                    fprintf(stderr,"%s: could not open output file '%s'!\n",
 
209
                        ProgName, *poptarg);
 
210
                }
 
211
                break;
 
212
            case 'd':   /* -display, let's let the toolkit parse it */
 
213
                break;
 
214
            default:
 
215
                break;
 
216
        }
 
217
    }
 
218
    ofp = (ofp ? ofp : stdout);
 
219
 
 
220
    appW = XtAppInitialize(&app,"XTrap",optionTable,(Cardinal)2L,
 
221
        (int *)&argc, (String *)argv, (String *)NULL,(ArgList)&tmp,
 
222
        (Cardinal)NULL);
 
223
 
 
224
    dpy = XtDisplay(appW);
 
225
#ifdef DEBUG
 
226
    XSynchronize(dpy, True);
 
227
#endif
 
228
    fprintf(stderr,"Display:  %s \n", DisplayString(dpy));
 
229
    if ((tc = XECreateTC(dpy,0L, NULL)) == False)
 
230
    {
 
231
        fprintf(stderr,"%s: could not initialize XTrap extension\n",ProgName);
 
232
        exit (1L);
 
233
    }
 
234
    XETrapSetTimestamps(tc,True, False);
 
235
    (void)XEGetAvailableRequest(tc,&ret_avail);
 
236
    XEPrintAvail(stderr,&ret_avail);
 
237
    XEPrintTkFlags(stderr,tc);
 
238
 
 
239
    /* Need to prime events/requests initially turning all off  */
 
240
    (void)memset(requests,0L,sizeof(requests));
 
241
    (void)memset(events,0L,sizeof(events));
 
242
    /* Now turn on the ones you really want */
 
243
    (void)memset(events,0xFFL,XETrapMaxEvent);
 
244
    if (eventFlag == False)
 
245
    {   /* doesn't want just events */
 
246
        (void)memset(requests,0xFFL,XETrapMaxRequest);
 
247
        /* Turn off XTrap Requests for multi-client regression tests & XLib */
 
248
        BitFalse(requests, XETrapGetExtOpcode(tc));
 
249
        /* Turn off noisy events */
 
250
        BitFalse(events, MotionNotify);
 
251
    }
 
252
    if (verboseFlag == True)
 
253
    {   /* want's *all* requests/events */
 
254
        (void)memset(requests,0xFFL,XETrapMaxRequest);
 
255
        (void)memset(events,0xFFL,XETrapMaxEvent);
 
256
    }
 
257
    /* Tell the TC about it */
 
258
    XETrapSetRequests(tc, True, requests);
 
259
    XETrapSetEvents(tc, True, events);
 
260
    XETrapSetMaxPacket(tc, True, XETrapMinPktSize); /* just get the minimum */
 
261
    
 
262
    /* Set up callbacks for data */
 
263
    XEAddRequestCBs(tc, requests, print_req_callback, NULL);
 
264
    XEAddEventCBs(tc, events, print_evt_callback, NULL);
 
265
 
 
266
    (void)XEStartTrapRequest(tc);
 
267
    (void)XEGetCurrentRequest(tc,&ret_cur);
 
268
    XEPrintCurrent(stderr,&ret_cur);
 
269
 
 
270
    /* Add signal handlers so that we clean up properly */
 
271
    _InitExceptionHandling((void_function)SetGlobalDone);
 
272
    (void)XEEnableCtrlKeys((void_function)SetGlobalDone);
 
273
             
 
274
    XETrapAppWhileLoop(app,tc,&GlobalDone);
 
275
 
 
276
    /* Make sure <CTRL> key is released */
 
277
    XESimulateXEventRequest(tc, KeyRelease, 
 
278
        XKeysymToKeycode(dpy, XK_Control_L), 0L, 0L, 0L);
 
279
 
 
280
    /* close down everything nicely */
 
281
    XEFreeTC(tc);
 
282
    (void)XCloseDisplay(dpy);
 
283
    (void)XEClearCtrlKeys();
 
284
    _ClearExceptionHandling();
 
285
    exit(0L);
 
286
}
 
287