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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/sun/constype.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
 * $Xorg: constype.c,v 1.3 2000/08/17 19:48:29 cpqbld Exp $
 
3
 * 
 
4
 * consoletype - utility to print out string identifying Sun console type
 
5
 *
 
6
 * Copyright 1988 SRI 
 
7
 *
 
8
 * Permission to use, copy, modify, and distribute this software and its
 
9
 * documentation for any purpose and without fee is hereby granted, provided
 
10
 * that the above copyright notice appear in all copies and that both that
 
11
 * copyright notice and this permission notice appear in supporting
 
12
 * documentation, and that the name of SRI not be used in advertising or
 
13
 * publicity pertaining to distribution of the software without specific,
 
14
 * written prior permission.  SRI makes no representations about the
 
15
 * suitability of this software for any purpose.  It is provided "as is"
 
16
 * without express or implied warranty.
 
17
 *
 
18
 * Author:  Doug Moran, SRI
 
19
 */
 
20
/* $XFree86: xc/programs/Xserver/hw/sun/constype.c,v 3.7 2001/10/28 03:33:10 tsi Exp $ */
 
21
 
 
22
/*
 
23
SUN-SPOTS DIGEST         Thursday, 17 March 1988       Volume 6 : Issue 31
 
24
 
 
25
Date:    Wed, 2 Mar 88 14:50:26 PST
 
26
From:    Doug Moran <moran@ai.sri.com>
 
27
Subject: Program to determine console type
 
28
 
 
29
There have been several requests in this digest for programs to determine
 
30
the type of the console.  Below is a program that I wrote to produce an
 
31
identifying string (I start suntools in my .login file and use this pgm to
 
32
determine which arguments to use).
 
33
 
 
34
Caveat:  my cluster has only a few of these monitor types, so the pgm has
 
35
not been fully tested.
 
36
 
 
37
Note on coding style: the function wu_fbid is actually located in a local
 
38
library, accounting for what otherwise might appear to be a strange coding
 
39
style.
 
40
*/
 
41
#include <stdio.h>
 
42
#if defined(SVR4) || defined(__bsdi__)
 
43
#include <string.h>
 
44
#else
 
45
/* NetBSD seemingly still uses <strings.h> and naturally SunOS does */
 
46
#include <strings.h>
 
47
#endif
 
48
#include <unistd.h>
 
49
 
 
50
int wu_fbid(char *devname, char **fbname, int *fbtype);
 
51
 
 
52
int
 
53
main (argc, argv)
 
54
    int argc;
 
55
    char **argv;
 
56
{
 
57
    int fbtype = -1;
 
58
    char *fbname, *dev;
 
59
    int print_num = 0;
 
60
    int error;
 
61
 
 
62
    if (argc > 1 && argv[1][0] == '/') {
 
63
        dev = argv[1];
 
64
        argc--; argv++;
 
65
    } else
 
66
        dev = "/dev/fb";
 
67
    error = wu_fbid(dev, &fbname, &fbtype );
 
68
    if (argc > 1 && strncmp (argv[1], "-num", strlen(argv[1])) == 0)
 
69
        print_num = 1;
 
70
 
 
71
    printf ("%s", fbname ? fbname : "tty");
 
72
    if (print_num) {
 
73
        printf (" %d", fbtype);
 
74
    }
 
75
    putchar ('\n');
 
76
    return error;
 
77
}
 
78
#include <sys/ioctl.h>
 
79
#include <sys/file.h>
 
80
#if defined(SVR4) || defined(__bsdi__)
 
81
#include <fcntl.h>
 
82
#include <sys/fbio.h>
 
83
#else
 
84
#ifndef CSRG_BASED
 
85
#include <sun/fbio.h>
 
86
#else
 
87
#include <machine/fbio.h>
 
88
#endif
 
89
#endif
 
90
 
 
91
/* Sun doesn't see fit to update <sys/fbio.h> to reflect the addition
 
92
 * of the TCX 
 
93
 */
 
94
#define XFBTYPE_TCX             21
 
95
#define XFBTYPE_LASTPLUSONE     22
 
96
 
 
97
/* decoding as of Release 3.4 : fbio.h 1.3 87/01/09 SMI */
 
98
        /* the convention for entries in this table is to translate the
 
99
         * macros for frame buffer codes (in <sun/fbio.h>) to short names
 
100
         * thus:
 
101
         *      FBTYPE_SUNxBW           becomes bwx
 
102
         *      FBTYPE_SUNxCOLOR        becomes cgx
 
103
         *      FBTYPE_SUNxGP           becomes gpx
 
104
         *      FBTYPE_NOTSUN[1-9]      becomes ns[A-J]
 
105
         */
 
106
static char *decode_fb[] = {
 
107
        "bw1", "cg1",
 
108
        "bw2", "cg2",
 
109
        "gp2",
 
110
        "bw3", "cg3",
 
111
        "cg8", "cg4",
 
112
        "nsA", "nsB", "nsC", 
 
113
#ifdef FBTYPE_SUNFAST_COLOR
 
114
        "gx/cg6", 
 
115
#endif
 
116
#ifdef FBTYPE_SUNROP_COLOR
 
117
        "rop", 
 
118
#endif
 
119
#ifdef FBTYPE_SUNFB_VIDEO
 
120
        "vid", 
 
121
#endif
 
122
#ifdef FBTYPE_SUNGIFB
 
123
        "gifb", 
 
124
#endif
 
125
#ifdef FBTYPE_SUNGPLAS
 
126
        "plas", 
 
127
#endif
 
128
#ifdef FBTYPE_SUNGP3
 
129
        "gp3/cg12", 
 
130
#endif
 
131
#ifdef FBTYPE_SUNGT
 
132
        "gt", 
 
133
#endif
 
134
#ifdef FBTYPE_SUNLEO
 
135
        "leo/zx", 
 
136
#endif
 
137
#ifdef FBTYPE_MDICOLOR
 
138
        "mdi/cg14",
 
139
#endif
 
140
        };
 
141
 
 
142
int wu_fbid(devname, fbname, fbtype)
 
143
        char* devname;
 
144
        char** fbname;
 
145
        int* fbtype;
 
146
{
 
147
        struct fbgattr fbattr;
 
148
        int fd, ioctl_ret;
 
149
        if ( (fd = open(devname, O_RDWR, 0)) == -1 ) {
 
150
            *fbname = "unable to open fb";
 
151
            return 2;
 
152
        }
 
153
        /* FBIOGATTR fails for early frame buffer types */
 
154
        if ((ioctl_ret = ioctl(fd,FBIOGATTR,&fbattr)))  /*success=>0(false)*/
 
155
            ioctl_ret = ioctl(fd, FBIOGTYPE, &fbattr.fbtype);
 
156
        close(fd);
 
157
        if ( ioctl_ret == -1 ) {
 
158
            *fbname = "ioctl on fb failed";
 
159
            return 2;
 
160
        }
 
161
        *fbtype = fbattr.fbtype.fb_type;
 
162
        /* The binary is obsolete and needs to be re-compiled:
 
163
         * the ioctl returned a value beyond what was possible
 
164
         * when the program was compiled */
 
165
        if (fbattr.fbtype.fb_type>=FBTYPE_LASTPLUSONE) {
 
166
            if (fbattr.fbtype.fb_type == XFBTYPE_TCX) {
 
167
                *fbname = "tcx";
 
168
                return 0;
 
169
            } else {
 
170
                *fbname = "unk";
 
171
                return 1;
 
172
            }
 
173
        }
 
174
        /* The source is obsolete.  The table "decode_fb" does not
 
175
         * have entries for some of the values returned by the ioctl.
 
176
         * Compare <sun/fbio.h> to the entries in "decode_fb" */
 
177
        if ( decode_fb[fbattr.fbtype.fb_type] == NULL ) {
 
178
            *fbname = "unk";
 
179
            return 1;
 
180
        }
 
181
        *fbname = decode_fb[fbattr.fbtype.fb_type];
 
182
        return 0;
 
183
}