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

« back to all changes in this revision

Viewing changes to unix/xc/programs/listres/listres.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
 * $XConsortium: listres.c,v 1.32 94/04/17 20:43:22 dave Exp $
 
3
 *
 
4
 * 
 
5
Copyright (c) 1989  X Consortium
 
6
 
 
7
Permission is hereby granted, free of charge, to any person obtaining a copy
 
8
of this software and associated documentation files (the "Software"), to deal
 
9
in the Software without restriction, including without limitation the rights
 
10
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
11
copies of the Software, and to permit persons to whom the Software is
 
12
furnished to do so, subject to the following conditions:
 
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
X CONSORTIUM 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 X Consortium 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 X Consortium.
 
27
 * *
 
28
 * Author:  Jim Fulton, MIT X Consortium
 
29
 */
 
30
/* $XFree86: xc/programs/listres/listres.c,v 1.4 2001/04/01 14:00:18 tsi Exp $ */
 
31
 
 
32
#include <stdio.h>
 
33
#include <stdlib.h>
 
34
#include <X11/Xos.h>
 
35
#include <X11/StringDefs.h>
 
36
#include <X11/IntrinsicP.h>
 
37
#include <X11/Xaw/Cardinals.h>
 
38
#include <X11/Core.h>
 
39
#include <X11/Xmu/CharSet.h>
 
40
#include <X11/Xmu/WidgetNode.h>
 
41
#include <X11/Xaw/AllWidgets.h>
 
42
 
 
43
#define widget_list XawWidgetArray  /* or motif or ol or ... */
 
44
#define nwidgets XawWidgetCount
 
45
 
 
46
 
 
47
static XrmOptionDescRec Options[] = {
 
48
  { "-top", "*topObject", XrmoptionSepArg, (caddr_t) NULL },
 
49
  { "-format", "*resourceFormat", XrmoptionSepArg, (caddr_t) NULL },
 
50
  { "-tree", "*showTree", XrmoptionNoArg, (caddr_t) "on" },
 
51
  { "-nosuper", "*showSuper", XrmoptionNoArg, (caddr_t) "off" },
 
52
  { "-variable", "*showVariable", XrmoptionNoArg, (caddr_t) "on" },
 
53
};
 
54
 
 
55
typedef struct {
 
56
    Boolean show_tree;
 
57
    Boolean show_all;
 
58
    Boolean show_variable;
 
59
    Boolean show_superclass;
 
60
    char *top_object;
 
61
    char *format;
 
62
  } OptionsRec;
 
63
 
 
64
OptionsRec options;
 
65
 
 
66
#define Offset(field) XtOffsetOf(OptionsRec, field)
 
67
 
 
68
static XtResource Resources[] = {
 
69
  { "showTree", "ShowTree", XtRBoolean, sizeof(Boolean),
 
70
      Offset(show_tree), XtRImmediate, (XtPointer) FALSE },
 
71
  { "showSuper", "ShowSuper", XtRBoolean, sizeof(Boolean),
 
72
      Offset(show_superclass), XtRImmediate, (caddr_t) TRUE },
 
73
  { "showVariable", "ShowVariable", XtRBoolean, sizeof(Boolean),
 
74
      Offset(show_variable), XtRImmediate, (caddr_t) FALSE },
 
75
  { "topObject", "TopObject", XtRString, sizeof(char *),
 
76
      Offset(top_object), XtRString, (caddr_t) "core" },
 
77
  { "resourceFormat", "ResourceFormat", XtRString, sizeof(char *),
 
78
      Offset(format), XtRString, (caddr_t) " %-16s %20s  %-20s  %s" },
 
79
};
 
80
 
 
81
#undef Offset
 
82
 
 
83
const char *ProgramName;
 
84
 
 
85
void
 
86
usage ()
 
87
{
 
88
    fprintf(stderr, "usage:  %s [-options...]\n", ProgramName);
 
89
    fprintf(stderr, "\nwhere options include:\n");
 
90
    fprintf(stderr,
 
91
            "    -all             list all known widget and object classes\n");
 
92
    fprintf(stderr,
 
93
            "    -tree            list all widgets and objects in a tree\n");
 
94
    fprintf(stderr,
 
95
            "    -nosuper         do not print superclass resources\n");
 
96
    fprintf(stderr,
 
97
            "    -variable        show variable name instead of class name\n");
 
98
    fprintf(stderr,
 
99
            "    -top name        object to be top of tree\n");
 
100
    fprintf(stderr,
 
101
            "    -format string   printf format for instance, class, type\n");
 
102
    fprintf(stderr, "\n");
 
103
    exit (1);
 
104
}
 
105
 
 
106
static void print_tree_level (wn, level)
 
107
    register XmuWidgetNode *wn;
 
108
    register int level;
 
109
{
 
110
    register int i;
 
111
 
 
112
    if (!wn) return;
 
113
 
 
114
    for (i = 0; i < level; i++) {
 
115
        putchar (' '); putchar (' '); 
 
116
    }
 
117
    printf ("%d:  %s/%s\n", level, wn->label, XmuWnClassname(wn));
 
118
    print_tree_level (wn->children, level + 1);
 
119
    print_tree_level (wn->siblings, level);
 
120
}
 
121
 
 
122
static void tree_known_widgets ()
 
123
{
 
124
    register int i;
 
125
    register XmuWidgetNode *wn;
 
126
 
 
127
    for (i = 0, wn = widget_list; i < nwidgets; i++, wn++) {
 
128
        if (!wn->superclass) {          /* list all rooted objects */
 
129
            print_tree_level (wn, 0);
 
130
        }
 
131
    }
 
132
}
 
133
 
 
134
 
 
135
/*
 
136
 * print_classname - print out the superclass-to-subclass hierchy of names
 
137
 * in the form super\sub\sub....
 
138
 */
 
139
static int print_classname (node, topnode, level, showvar)
 
140
    XmuWidgetNode *node, *topnode;
 
141
    int level;
 
142
    Bool showvar;
 
143
{
 
144
    int retval;
 
145
 
 
146
    if (node && node != topnode) {
 
147
        retval = print_classname (node->superclass, topnode, level + 1,
 
148
                                  showvar);
 
149
    } else {
 
150
        retval = level - 1;
 
151
    }
 
152
    if (node)
 
153
      printf ("%s%s", showvar ? node->label : XmuWnClassname(node),
 
154
              level ? "\\" : "");
 
155
 
 
156
    return retval;
 
157
}
 
158
 
 
159
static void list_known_widgets ()
 
160
{
 
161
    int i;
 
162
    XmuWidgetNode *wn;
 
163
    int width = 0;
 
164
    char format[20];
 
165
 
 
166
    for (i = 0, wn = widget_list; i < nwidgets; i++, wn++) {
 
167
        int l = strlen (wn->label);
 
168
        if (l > width) width = l;
 
169
    }
 
170
    sprintf (format, "%%-%ds  ", width);
 
171
    for (i = 0, wn = widget_list; i < nwidgets; i++, wn++) {
 
172
        printf (format, wn->label);
 
173
        print_classname (wn, (XmuWidgetNode *) NULL, 0, False);
 
174
        putchar ('\n');
 
175
    }
 
176
}
 
177
 
 
178
/* ARGSUSED */
 
179
static void print_resources (node, format, topnode, showsuper, showvar)
 
180
    XmuWidgetNode *node;
 
181
    const char *format;
 
182
    XmuWidgetNode *topnode;
 
183
    Bool showsuper;
 
184
    Bool showvar;
 
185
{
 
186
    int i;
 
187
    XtResourceList res = node->resources;
 
188
    XmuWidgetNode **wn = node->resourcewn;
 
189
 
 
190
    for (i = 0; i < node->nresources; i++, res++, wn++) {
 
191
        if (!showsuper && *wn != node) continue;
 
192
        printf (format, showvar ? (*wn)->label : XmuWnClassname(*wn),
 
193
                res->resource_name, res->resource_class, res->resource_type);
 
194
        putchar ('\n');
 
195
    }
 
196
    if (node->nconstraints > 0) {
 
197
        printf (format, "----", "----", "----", "----");
 
198
        putchar ('\n');
 
199
    }
 
200
    res = node->constraints;
 
201
    wn = node->constraintwn;
 
202
    for (i = 0; i < node->nconstraints; i++, res++, wn++) {
 
203
        if (!showsuper && *wn != node) continue;
 
204
        printf (format, showvar ? (*wn)->label : XmuWnClassname(*wn),
 
205
                res->resource_name, res->resource_class, res->resource_type);
 
206
        putchar ('\n');
 
207
    }
 
208
    return;
 
209
}
 
210
 
 
211
 
 
212
/*
 
213
 * list_resources - display resources of a widget, identifying class from
 
214
 * which they come
 
215
 */
 
216
static void
 
217
list_resources (node, format, topnode, toplevel, showsuper, showvar)
 
218
    XmuWidgetNode *node;
 
219
    const char *format;
 
220
    XmuWidgetNode *topnode;
 
221
    Widget toplevel;
 
222
    Bool showsuper;
 
223
    Bool showvar;
 
224
{
 
225
    static Bool first = True;
 
226
 
 
227
    XmuWnFetchResources (node, toplevel, topnode);
 
228
    if (first) {
 
229
        printf (format, showvar ? "Variable" : "WidgetClass",
 
230
                "Instance", "Class", "Type");
 
231
        putchar ('\n');
 
232
        printf (format, showvar ? "--------" : "-----------",
 
233
                "--------", "-----", "----");
 
234
        putchar ('\n');
 
235
        first = False;
 
236
    }
 
237
    printf ("%s:  ", node->label);
 
238
    print_classname (node, topnode, 0, showvar);
 
239
    putchar ('\n');
 
240
    print_resources (node, format, topnode, showsuper, showvar);
 
241
    putchar ('\n');
 
242
}
 
243
 
 
244
 
 
245
int
 
246
main (argc, argv)
 
247
    int argc;
 
248
    char **argv;
 
249
{
 
250
    int i;
 
251
    XtAppContext appcon;
 
252
    XmuWidgetNode *topnode;
 
253
    Widget toplevel, container;
 
254
 
 
255
    ProgramName = argv[0];
 
256
 
 
257
    XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL);
 
258
 
 
259
    toplevel = XtAppInitialize (&appcon, "Listres", Options, XtNumber(Options),
 
260
                                &argc, argv, NULL, NULL, 0);
 
261
    container = XtCreateWidget ("dummy", widgetClass, toplevel, NULL, ZERO);
 
262
 
 
263
    XtGetApplicationResources (toplevel, (caddr_t) &options,
 
264
                               Resources, XtNumber(Resources), NULL, ZERO);
 
265
    XmuWnInitializeNodes (widget_list, nwidgets);
 
266
    if (argc == 1) {
 
267
        if (options.show_tree) {
 
268
            tree_known_widgets();
 
269
        } else {
 
270
            list_known_widgets();
 
271
        }
 
272
        exit (0);
 
273
    }
 
274
 
 
275
    topnode = XmuWnNameToNode (widget_list, nwidgets, options.top_object);
 
276
    argc--, argv++;                     /* skip command */
 
277
 
 
278
    if (argc > 0 && argv[0][0] == '-') {
 
279
        int len = strlen (argv[0]);
 
280
        if (len >= 2 && strncmp(argv[0], "-all", len) == 0) {
 
281
            XmuWidgetNode *wn;
 
282
            for (i = 0, wn = widget_list; i < nwidgets; i++, wn++) {
 
283
                list_resources (wn, options.format, topnode, container,
 
284
                                (Bool) options.show_superclass,
 
285
                                (Bool) options.show_variable);
 
286
            }
 
287
        } else
 
288
          usage();
 
289
    } else {
 
290
        for (; argc > 0; argc--, argv++) {
 
291
            XmuWidgetNode *node;
 
292
 
 
293
            if (argv[0][0] == '-') usage ();
 
294
            node = XmuWnNameToNode (widget_list, nwidgets, *argv);
 
295
            if (!node) {
 
296
                fprintf (stderr, "%s:  unable to find widget \"%s\"\n",
 
297
                         ProgramName, *argv);
 
298
                continue;
 
299
            }
 
300
            list_resources (node, options.format, topnode, container,
 
301
                            (Bool) options.show_superclass,
 
302
                            (Bool) options.show_variable);
 
303
        }
 
304
    }
 
305
    exit (0);
 
306
}