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

« back to all changes in this revision

Viewing changes to unix/xc/lib/X11/SetHints.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: SetHints.c,v 1.5 2001/02/09 02:03:36 xorgcvs Exp $ */
 
2
 
 
3
/***********************************************************
 
4
 
 
5
Copyright 1987, 1998  The Open Group
 
6
 
 
7
Permission to use, copy, modify, distribute, and sell this software and its
 
8
documentation for any purpose is hereby granted without fee, provided that
 
9
the above copyright notice appear in all copies and that both that
 
10
copyright notice and this permission notice appear in supporting
 
11
documentation.
 
12
 
 
13
The above copyright notice and this permission notice shall be included in
 
14
all copies or substantial portions of the Software.
 
15
 
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
22
 
 
23
Except as contained in this notice, the name of The Open Group shall not be
 
24
used in advertising or otherwise to promote the sale, use or other dealings
 
25
in this Software without prior written authorization from The Open Group.
 
26
 
 
27
 
 
28
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
 
29
 
 
30
                        All Rights Reserved
 
31
 
 
32
Permission to use, copy, modify, and distribute this software and its 
 
33
documentation for any purpose and without fee is hereby granted, 
 
34
provided that the above copyright notice appear in all copies and that
 
35
both that copyright notice and this permission notice appear in 
 
36
supporting documentation, and that the name of Digital not be
 
37
used in advertising or publicity pertaining to distribution of the
 
38
software without specific, written prior permission.  
 
39
 
 
40
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 
41
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 
42
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 
43
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
44
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 
45
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 
46
SOFTWARE.
 
47
 
 
48
******************************************************************/
 
49
/* $XFree86: xc/lib/X11/SetHints.c,v 1.4 2001/12/14 19:54:06 dawes Exp $ */
 
50
 
 
51
#include <X11/Xlibint.h>
 
52
#include <X11/Xutil.h>
 
53
#include "Xatomtype.h"
 
54
#include <X11/Xatom.h>
 
55
#include <X11/Xos.h>
 
56
 
 
57
#define safestrlen(s) ((s) ? strlen(s) : 0)
 
58
 
 
59
int
 
60
XSetSizeHints(dpy, w, hints, property)          /* old routine */
 
61
        Display *dpy;
 
62
        Window w;
 
63
        XSizeHints *hints;
 
64
        Atom property;
 
65
{
 
66
        xPropSizeHints prop;
 
67
        prop.flags = (hints->flags & (USPosition|USSize|PAllHints));
 
68
        prop.x = hints->x;
 
69
        prop.y = hints->y;
 
70
        prop.width = hints->width;
 
71
        prop.height = hints->height;
 
72
        prop.minWidth = hints->min_width;
 
73
        prop.minHeight = hints->min_height;
 
74
        prop.maxWidth  = hints->max_width;
 
75
        prop.maxHeight = hints->max_height;
 
76
        prop.widthInc = hints->width_inc;
 
77
        prop.heightInc = hints->height_inc;
 
78
        prop.minAspectX = hints->min_aspect.x;
 
79
        prop.minAspectY = hints->min_aspect.y;
 
80
        prop.maxAspectX = hints->max_aspect.x;
 
81
        prop.maxAspectY = hints->max_aspect.y;
 
82
        return XChangeProperty (dpy, w, property, XA_WM_SIZE_HINTS, 32,
 
83
                                PropModeReplace, (unsigned char *) &prop, 
 
84
                                OldNumPropSizeElements);
 
85
}
 
86
 
 
87
/* 
 
88
 * XSetWMHints sets the property 
 
89
 *      WM_HINTS        type: WM_HINTS  format:32
 
90
 */
 
91
 
 
92
int
 
93
XSetWMHints (dpy, w, wmhints)
 
94
        Display *dpy;
 
95
        Window w;
 
96
        XWMHints *wmhints; 
 
97
{
 
98
        xPropWMHints prop;
 
99
        prop.flags = wmhints->flags;
 
100
        prop.input = (wmhints->input == True ? 1 : 0);
 
101
        prop.initialState = wmhints->initial_state;
 
102
        prop.iconPixmap = wmhints->icon_pixmap;
 
103
        prop.iconWindow = wmhints->icon_window;
 
104
        prop.iconX = wmhints->icon_x;
 
105
        prop.iconY = wmhints->icon_y;
 
106
        prop.iconMask = wmhints->icon_mask;
 
107
        prop.windowGroup = wmhints->window_group;
 
108
        return XChangeProperty (dpy, w, XA_WM_HINTS, XA_WM_HINTS, 32,
 
109
                                PropModeReplace, (unsigned char *) &prop, 
 
110
                                NumPropWMHintsElements);
 
111
}
 
112
 
 
113
 
 
114
 
 
115
/* 
 
116
 * XSetZoomHints sets the property 
 
117
 *      WM_ZOOM_HINTS   type: WM_SIZE_HINTS format: 32
 
118
 */
 
119
 
 
120
int
 
121
XSetZoomHints (dpy, w, zhints)
 
122
        Display *dpy;
 
123
        Window w;
 
124
        XSizeHints *zhints;
 
125
{
 
126
        return XSetSizeHints (dpy, w, zhints, XA_WM_ZOOM_HINTS);
 
127
}
 
128
 
 
129
 
 
130
/* 
 
131
 * XSetNormalHints sets the property 
 
132
 *      WM_NORMAL_HINTS         type: WM_SIZE_HINTS format: 32
 
133
 */
 
134
 
 
135
int
 
136
XSetNormalHints (dpy, w, hints)                 /* old routine */
 
137
        Display *dpy;
 
138
        Window w;
 
139
        XSizeHints *hints;
 
140
{
 
141
        return XSetSizeHints (dpy, w, hints, XA_WM_NORMAL_HINTS);
 
142
}
 
143
 
 
144
 
 
145
 
 
146
/*
 
147
 * Note, the following is one of the few cases were we really do want sizeof
 
148
 * when examining a protocol structure.  This is because the XChangeProperty
 
149
 * routine will take care of converting to host to network data structures.
 
150
 */
 
151
 
 
152
int
 
153
XSetIconSizes (dpy, w, list, count)
 
154
        Display *dpy;
 
155
        Window w;       /* typically, root */
 
156
        XIconSize *list;
 
157
        int count;      /* number of items on the list */
 
158
{
 
159
        register int i;
 
160
        xPropIconSize *pp, *prop;
 
161
#define size_of_the_real_thing sizeof   /* avoid grepping screwups */
 
162
        unsigned nbytes = count * size_of_the_real_thing(xPropIconSize);
 
163
#undef size_of_the_real_thing
 
164
        if ((prop = pp = (xPropIconSize *) Xmalloc (nbytes))) {
 
165
            for (i = 0; i < count; i++) {
 
166
                pp->minWidth  = list->min_width;
 
167
                pp->minHeight = list->min_height;
 
168
                pp->maxWidth  = list->max_width;
 
169
                pp->maxHeight = list->max_height;
 
170
                pp->widthInc  = list->width_inc;
 
171
                pp->heightInc = list->height_inc;
 
172
                pp += 1;
 
173
                list += 1;
 
174
            }
 
175
            XChangeProperty (dpy, w, XA_WM_ICON_SIZE, XA_WM_ICON_SIZE, 32, 
 
176
                             PropModeReplace, (unsigned char *) prop, 
 
177
                             count * NumPropIconSizeElements);
 
178
            Xfree ((char *)prop);
 
179
        }
 
180
        return 1;
 
181
}
 
182
 
 
183
int
 
184
XSetCommand (dpy, w, argv, argc)
 
185
        Display *dpy;
 
186
        Window w;
 
187
        char **argv;
 
188
        int argc;
 
189
{
 
190
        register int i;
 
191
        register int nbytes;
 
192
        register char *buf, *bp;
 
193
        for (i = 0, nbytes = 0; i < argc; i++) {
 
194
                nbytes += safestrlen(argv[i]) + 1;
 
195
        }
 
196
        if ((bp = buf = Xmalloc((unsigned) nbytes))) { 
 
197
            /* copy arguments into single buffer */
 
198
            for (i = 0; i < argc; i++) {
 
199
                if (argv[i]) { 
 
200
                    (void) strcpy(bp, argv[i]);
 
201
                    bp += strlen(argv[i]) + 1;
 
202
                }
 
203
                else
 
204
                    *bp++ = '\0';
 
205
            }
 
206
            XChangeProperty (dpy, w, XA_WM_COMMAND, XA_STRING, 8,
 
207
                             PropModeReplace, (unsigned char *)buf, nbytes);
 
208
            Xfree(buf);         
 
209
        }
 
210
        return 1;
 
211
}
 
212
/* 
 
213
 * XSetStandardProperties sets the following properties:
 
214
 *      WM_NAME           type: STRING          format: 8
 
215
 *      WM_ICON_NAME      type: STRING          format: 8
 
216
 *      WM_HINTS          type: WM_HINTS        format: 32
 
217
 *      WM_COMMAND        type: STRING
 
218
 *      WM_NORMAL_HINTS   type: WM_SIZE_HINTS   format: 32
 
219
 */
 
220
 
 
221
int
 
222
#if NeedFunctionPrototypes
 
223
XSetStandardProperties (
 
224
        Display *dpy,
 
225
        Window w,               /* window to decorate */
 
226
        _Xconst char *name,     /* name of application */
 
227
        _Xconst char *icon_string,/* name string for icon */
 
228
        Pixmap icon_pixmap,     /* pixmap to use as icon, or None */
 
229
        char **argv,            /* command to be used to restart application */
 
230
        int argc,               /* count of arguments */
 
231
        XSizeHints *hints)      /* size hints for window in its normal state */
 
232
#else
 
233
XSetStandardProperties (dpy, w, name, icon_string, icon_pixmap, argv, argc, hints)
 
234
        Display *dpy;
 
235
        Window w;               /* window to decorate */
 
236
        char *name;             /* name of application */
 
237
        char *icon_string;      /* name string for icon */
 
238
        Pixmap icon_pixmap;     /* pixmap to use as icon, or None */
 
239
        char **argv;            /* command to be used to restart application */
 
240
        int argc;               /* count of arguments */
 
241
        XSizeHints *hints;      /* size hints for window in its normal state */
 
242
#endif
 
243
{
 
244
        XWMHints phints;
 
245
        phints.flags = 0;
 
246
 
 
247
        if (name != NULL) XStoreName (dpy, w, name);
 
248
 
 
249
        if (icon_string != NULL) {
 
250
            XChangeProperty (dpy, w, XA_WM_ICON_NAME, XA_STRING, 8,
 
251
                PropModeReplace, (unsigned char *)icon_string, safestrlen(icon_string));
 
252
                }
 
253
 
 
254
        if (icon_pixmap != None) {
 
255
                phints.icon_pixmap = icon_pixmap;
 
256
                phints.flags |= IconPixmapHint;
 
257
                }
 
258
        if (argv != NULL) XSetCommand(dpy, w, argv, argc);
 
259
        
 
260
        if (hints != NULL) XSetNormalHints(dpy, w, hints);
 
261
 
 
262
        if (phints.flags != 0) XSetWMHints(dpy, w, &phints);
 
263
 
 
264
        return 1;
 
265
}
 
266
 
 
267
int
 
268
XSetTransientForHint(dpy, w, propWindow)
 
269
        Display *dpy;
 
270
        Window w;
 
271
        Window propWindow;
 
272
{
 
273
        return XChangeProperty(dpy, w, XA_WM_TRANSIENT_FOR, XA_WINDOW, 32,
 
274
                               PropModeReplace, (unsigned char *) &propWindow, 1);
 
275
}
 
276
 
 
277
int
 
278
XSetClassHint(dpy, w, classhint)
 
279
        Display *dpy;
 
280
        Window w;
 
281
        XClassHint *classhint;
 
282
{
 
283
        char *class_string;
 
284
        char *s;
 
285
        int len_nm, len_cl;
 
286
 
 
287
        len_nm = safestrlen(classhint->res_name);
 
288
        len_cl = safestrlen(classhint->res_class);
 
289
        if ((class_string = s = Xmalloc((unsigned) (len_nm + len_cl + 2)))) { 
 
290
            if (len_nm) {
 
291
                strcpy(s, classhint->res_name);
 
292
                s += len_nm + 1;
 
293
            }
 
294
            else
 
295
                *s++ = '\0';
 
296
            if (len_cl)
 
297
                strcpy(s, classhint->res_class);
 
298
            else
 
299
                *s = '\0';
 
300
            XChangeProperty(dpy, w, XA_WM_CLASS, XA_STRING, 8,
 
301
                            PropModeReplace, (unsigned char *) class_string, 
 
302
                            len_nm+len_cl+2);
 
303
            Xfree(class_string);
 
304
        }
 
305
        return 1;
 
306
}