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

« back to all changes in this revision

Viewing changes to unix/xc/programs/dpsexec/dpsexec.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
/* dpsexec.c
 
2
 *
 
3
 * (c) Copyright 1990-1994 Adobe Systems Incorporated.
 
4
 * All rights reserved.
 
5
 * 
 
6
 * Permission to use, copy, modify, distribute, and sublicense this software
 
7
 * and its documentation for any purpose and without fee is hereby granted,
 
8
 * provided that the above copyright notices appear in all copies and that
 
9
 * both those copyright notices and this permission notice appear in
 
10
 * supporting documentation and that the name of Adobe Systems Incorporated
 
11
 * not be used in advertising or publicity pertaining to distribution of the
 
12
 * software without specific, written prior permission.  No trademark license
 
13
 * to use the Adobe trademarks is hereby granted.  If the Adobe trademark
 
14
 * "Display PostScript"(tm) is used to describe this software, its
 
15
 * functionality or for any other purpose, such use shall be limited to a
 
16
 * statement that this software works in conjunction with the Display
 
17
 * PostScript system.  Proper trademark attribution to reflect Adobe's
 
18
 * ownership of the trademark shall be given whenever any such reference to
 
19
 * the Display PostScript system is made.
 
20
 * 
 
21
 * ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR
 
22
 * ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
 
23
 * ADOBE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
 
24
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
25
 * NON- INFRINGEMENT OF THIRD PARTY RIGHTS.  IN NO EVENT SHALL ADOBE BE LIABLE
 
26
 * TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
 
27
 * DAMAGES OR ANY DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,
 
28
 * NEGLIGENCE, STRICT LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN
 
29
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.  ADOBE WILL NOT
 
30
 * PROVIDE ANY TRAINING OR OTHER SUPPORT FOR THE SOFTWARE.
 
31
 * 
 
32
 * Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
 
33
 * Incorporated which may be registered in certain jurisdictions
 
34
 * 
 
35
 * Author:  Adobe Systems Incorporated
 
36
 */
 
37
/* $XFree86: xc/programs/dpsexec/dpsexec.c,v 1.7 2002/03/05 21:50:15 herrb Exp $ */
 
38
 
 
39
#include <errno.h>
 
40
#include <stdlib.h>
 
41
#include <stdio.h>
 
42
#include <string.h>
 
43
#include <signal.h>
 
44
#include <unistd.h>
 
45
#include <sys/time.h>
 
46
#include <X11/X.h>
 
47
#include <DPS/XDPS.h>
 
48
#include <X11/Xlib.h>
 
49
#include <DPS/XDPSlib.h>
 
50
#include <DPS/dpsXclient.h>
 
51
 
 
52
#ifdef __QNX__
 
53
#include <sys/select.h>
 
54
#endif
 
55
 
 
56
#define W_HEIGHT        512
 
57
#define W_WIDTH         512
 
58
 
 
59
#ifdef _NO_PROTO
 
60
#define ARGCAST int
 
61
#else
 
62
#define ARGCAST void *
 
63
#endif
 
64
 
 
65
static void MyStatusProc (ctxt, code)
 
66
    DPSContext ctxt;
 
67
    int code;
 
68
{
 
69
    if (code == PSZOMBIE) {
 
70
        /* Zombie event means context died */
 
71
        exit(0);
 
72
    }
 
73
}
 
74
 
 
75
int main(argc, argv)
 
76
    int argc;
 
77
    char **argv;
 
78
{
 
79
    char *displayname = "";
 
80
    Display *dpy;
 
81
    int i;
 
82
    char buf[1000];
 
83
    XEvent ev;
 
84
    GC gc;
 
85
    long mask;
 
86
    int sync = 0;
 
87
    int backingStore = 0;
 
88
    int exe = 1;
 
89
    Window win;
 
90
    XSetWindowAttributes xswa;
 
91
    DPSContext ctxt;
 
92
    XWMHints *hints;
 
93
    int root = 0;
 
94
    int width = W_WIDTH;
 
95
    int height = W_HEIGHT;
 
96
    Drawable drawable = None;
 
97
 
 
98
    for (i = 1;  i < argc;  i++) {
 
99
        if (strncmp(argv[i], "-display", strlen(argv[i])) == 0) {
 
100
            i++;
 
101
            displayname = argv[i];
 
102
        } else if (strncmp(argv[i], "-sync", strlen(argv[i])) == 0)
 
103
            sync = 1;
 
104
        else if (strncmp(argv[i], "-backup", strlen(argv[i])) == 0)
 
105
            backingStore = 1;
 
106
        else if (strncmp(argv[i], "-noexec", strlen(argv[i])) == 0)
 
107
            exe = 0;
 
108
        else if (strncmp(argv[i], "-root", strlen(argv[i])) == 0)
 
109
            root = 1;
 
110
        else if (strncmp(argv[i], "-width", strlen(argv[i])) == 0)
 
111
            width = atoi(argv[++i]);
 
112
        else if (strncmp(argv[i], "-height", strlen(argv[i])) == 0)
 
113
            height = atoi(argv[++i]);
 
114
        else if (strncmp(argv[i], "-drawable", strlen(argv[i])) == 0)
 
115
            drawable = (Drawable) atoi(argv[++i]);
 
116
        else {
 
117
            fprintf(stderr,
 
118
               "usage: %s [-display displayname][-sync][-backup][-noexec]\n",
 
119
                    argv[0]);
 
120
            fprintf(stderr,
 
121
                    "       [-root][-width w][-height h][-drawable xid]\n");
 
122
            exit(1);
 
123
        }
 
124
    }
 
125
 
 
126
    dpy = XOpenDisplay(displayname);
 
127
    if (dpy == NULL) {
 
128
        fprintf(stderr, "%s: Can't open display %s!\n", argv[0], displayname);
 
129
        exit(1);
 
130
    }
 
131
    
 
132
    if (sync) (void) XSynchronize(dpy, True);
 
133
 
 
134
    gc = XCreateGC(dpy, drawable != None ? drawable :
 
135
                   RootWindow (dpy, DefaultScreen (dpy)), 0, NULL);
 
136
    XSetForeground(dpy, gc, BlackPixel (dpy, DefaultScreen (dpy)));
 
137
    XSetBackground(dpy, gc, WhitePixel (dpy, DefaultScreen (dpy)));
 
138
 
 
139
    if (root) {
 
140
        win = DefaultRootWindow(dpy);
 
141
        height = DisplayHeight(dpy, DefaultScreen(dpy));
 
142
    } else if (drawable != None) {                              
 
143
        Window root;
 
144
        int x, y;
 
145
        unsigned int wwidth, wheight, border, depth;
 
146
        win = drawable;
 
147
        (void) XGetGeometry(dpy, win, &root, &x, &y, &wwidth,
 
148
                            &wheight, &border, &depth);
 
149
        height = wheight;
 
150
    } else {
 
151
        win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy),
 
152
                                  3, 385, width, height, 1,
 
153
                                  BlackPixel(dpy, DefaultScreen(dpy)),
 
154
                                  WhitePixel(dpy, DefaultScreen(dpy)));
 
155
 
 
156
        hints = XAllocWMHints();
 
157
        if (hints != NULL) {
 
158
            hints->flags = InputHint;
 
159
            hints->input = False;
 
160
            XSetWMHints(dpy, win, hints);
 
161
            XFree((char *) hints);
 
162
        }
 
163
 
 
164
        XStoreName(dpy, win, "Display PostScript Executive");
 
165
        XSetIconName(dpy, win, "DPS Exec");
 
166
 
 
167
        xswa.bit_gravity = SouthWestGravity;
 
168
        if (backingStore) xswa.backing_store = WhenMapped;
 
169
        else xswa.backing_store = NotUseful;
 
170
        xswa.event_mask = 0x0;
 
171
        mask = CWBitGravity | CWBackingStore | CWEventMask;
 
172
        XChangeWindowAttributes(dpy, win, mask, &xswa);
 
173
 
 
174
        XMapWindow(dpy, win);
 
175
    }
 
176
 
 
177
    /* Make it possible for this client to start a DPS NX agent,
 
178
       if "dpsnx.agent" is on the executable search path. */
 
179
 
 
180
    (void) XDPSNXSetClientArg(XDPSNX_AUTO_LAUNCH, (ARGCAST) True);
 
181
 
 
182
    ctxt = XDPSCreateSimpleContext(dpy, win, gc, 0, height,
 
183
                                   DPSDefaultTextBackstop,
 
184
                                   DPSDefaultErrorProc, NULL);
 
185
 
 
186
    if (ctxt == NULL) {
 
187
        fprintf (stderr, "\ndpsexec: DPS is not available\n");
 
188
        fprintf (stderr,
 
189
          "You need an X server with the DPS extension, or a DPS NX agent.\n");
 
190
        exit (1);
 
191
    }
 
192
 
 
193
    DPSSetContext(ctxt);
 
194
 
 
195
    /* Allow zombie events to be delivered so application can exit
 
196
       if context dies. Detach context so it doesn't wait for a join 
 
197
       if it dies */
 
198
 
 
199
    XDPSRegisterStatusProc(ctxt, MyStatusProc);
 
200
    XDPSSetStatusMask(ctxt, PSZOMBIEMASK, 0, 0);
 
201
    DPSPrintf(ctxt, "currentcontext detach ");
 
202
    
 
203
    if (exe) DPSPrintf(ctxt, "executive");
 
204
    DPSPrintf(ctxt, "\n");
 
205
    DPSFlushContext(ctxt);
 
206
    DPSSuppressBinaryConversion(ctxt, True);
 
207
    
 
208
    while (1) {
 
209
        fd_set fdmask;
 
210
        FD_ZERO(&fdmask);
 
211
        FD_SET(0, &fdmask);
 
212
        FD_SET(ConnectionNumber(dpy), &fdmask);
 
213
        DPSFlushContext(ctxt);
 
214
        if (select(ConnectionNumber(dpy)+1, &fdmask, NULL, NULL, NULL) < 0)
 
215
            fprintf(stderr, "select() error %d\n", errno);
 
216
        else if (FD_ISSET(0, &fdmask)) {
 
217
            /* Read from command line, send to context */
 
218
            if (fgets(buf, 1000, stdin) == NULL) break;
 
219
            DPSWriteData(ctxt, buf, strlen(buf));
 
220
        }
 
221
            
 
222
        while (XPending(dpy) > 0) {
 
223
            /* No special event handling - just throw them away.
 
224
               Must call XNextEvent to allow DPS status events to
 
225
               be dispatched. */
 
226
            XNextEvent(dpy, &ev);
 
227
        }
 
228
    }
 
229
 
 
230
    DPSDestroySpace(DPSSpaceFromContext(ctxt));
 
231
    XFlush(dpy);
 
232
    return 0;
 
233
}