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

« back to all changes in this revision

Viewing changes to unix/xc/programs/iceauth/iceauth.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: iceauth.c,v 1.4 2001/02/09 02:05:31 xorgcvs Exp $
 
3
 *
 
4
 * xauth - manipulate authorization file
 
5
 *
 
6
 * 
 
7
Copyright 1989, 1998  The Open Group
 
8
 
 
9
Permission to use, copy, modify, distribute, and sell this software and its
 
10
documentation for any purpose is hereby granted without fee, provided that
 
11
the above copyright notice appear in all copies and that both that
 
12
copyright notice and this permission notice appear in supporting
 
13
documentation.
 
14
 
 
15
The above copyright notice and this permission notice shall be included in
 
16
all copies or substantial portions of the Software.
 
17
 
 
18
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
19
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
20
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
21
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
22
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
23
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
24
 
 
25
Except as contained in this notice, the name of The Open Group shall not be
 
26
used in advertising or otherwise to promote the sale, use or other dealings
 
27
in this Software without prior written authorization from The Open Group.
 
28
 * *
 
29
 * Original Author of "xauth" : Jim Fulton, MIT X Consortium
 
30
 * Modified into "iceauth"    : Ralph Mor, X Consortium
 
31
 */
 
32
/* $XFree86: xc/programs/iceauth/iceauth.c,v 1.5 2001/12/14 20:00:48 dawes Exp $ */
 
33
 
 
34
#include "iceauth.h"
 
35
 
 
36
 
 
37
/*
 
38
 * global data
 
39
 */
 
40
char *ProgramName;                      /* argv[0], set at top of main() */
 
41
int verbose = -1;                       /* print certain messages */
 
42
Bool ignore_locks = False;              /* for error recovery */
 
43
Bool break_locks = False;               /* for error recovery */
 
44
 
 
45
/*
 
46
 * local data
 
47
 */
 
48
 
 
49
static char *authfilename = NULL;       /* filename of cookie file */
 
50
static char *defcmds[] = { "source", "-", NULL };  /* default command */
 
51
static int ndefcmds = 2;
 
52
static char *defsource = "(stdin)";
 
53
 
 
54
 
 
55
/*
 
56
 * utility routines
 
57
 */
 
58
static void usage (void)
 
59
{
 
60
    static char *prefixmsg[] = {
 
61
"",
 
62
"where options include:",
 
63
"    -f authfilename                name of authority file to use",
 
64
"    -v                             turn on extra messages",
 
65
"    -q                             turn off extra messages",
 
66
"    -i                             ignore locks on authority file",
 
67
"    -b                             break locks on authority file",
 
68
"",
 
69
"and commands have the following syntax:",
 
70
"",
 
71
NULL };
 
72
    static char *suffixmsg[] = {
 
73
"A dash may be used with the \"merge\" and \"source\" to read from the",
 
74
"standard input.  Commands beginning with \"n\" use numeric format.",
 
75
"",
 
76
NULL };
 
77
    char **msg;
 
78
 
 
79
    fprintf (stderr, "usage:  %s [-options ...] [command arg ...]\n",
 
80
             ProgramName);
 
81
    for (msg = prefixmsg; *msg; msg++) {
 
82
        fprintf (stderr, "%s\n", *msg);
 
83
    }
 
84
    print_help (stderr, "    ");        /* match prefix indentation */
 
85
    fprintf (stderr, "\n");
 
86
    for (msg = suffixmsg; *msg; msg++) {
 
87
        fprintf (stderr, "%s\n", *msg);
 
88
    }
 
89
    exit (1);
 
90
}
 
91
 
 
92
 
 
93
/*
 
94
 * The main routine - parses command line and calls action procedures
 
95
 */
 
96
int
 
97
main (int argc, char *argv[])
 
98
{
 
99
    int i;
 
100
    char *sourcename = defsource;
 
101
    char **arglist = defcmds;
 
102
    int nargs = ndefcmds;
 
103
    int status;
 
104
 
 
105
    ProgramName = argv[0];
 
106
 
 
107
    for (i = 1; i < argc; i++) {
 
108
        char *arg = argv[i];
 
109
 
 
110
        if (arg[0] == '-') {
 
111
            char *flag;
 
112
 
 
113
            for (flag = (arg + 1); *flag; flag++) {
 
114
                switch (*flag) {
 
115
                  case 'f':             /* -f authfilename */
 
116
                    if (++i >= argc) usage ();
 
117
                    authfilename = argv[i];
 
118
                    continue;
 
119
                  case 'v':             /* -v */
 
120
                    verbose = 1;
 
121
                    continue;
 
122
                  case 'q':             /* -q */
 
123
                    verbose = 0;
 
124
                    continue;
 
125
                  case 'b':             /* -b */
 
126
                    break_locks = True;
 
127
                    continue;
 
128
                  case 'i':             /* -i */
 
129
                    ignore_locks = True;
 
130
                    continue;
 
131
                  default:
 
132
                    usage ();
 
133
                }
 
134
            }
 
135
        } else {
 
136
            sourcename = "(argv)";
 
137
            nargs = argc - i;
 
138
            arglist = argv + i;
 
139
            if (verbose == -1) verbose = 0;
 
140
            break;
 
141
        }
 
142
    }
 
143
 
 
144
    if (verbose == -1) {                /* set default, don't junk stdout */
 
145
        verbose = (isatty(fileno(stdout)) != 0);
 
146
    }
 
147
 
 
148
    if (!authfilename) {
 
149
        authfilename = IceAuthFileName ();      /* static name, do not free */
 
150
        if (!authfilename) {
 
151
            fprintf (stderr,
 
152
                     "%s:  unable to generate an authority file name\n",
 
153
                     ProgramName);
 
154
            exit (1);
 
155
        }
 
156
    }
 
157
    if (auth_initialize (authfilename) != 0) {
 
158
        /* error message printed in auth_initialize */
 
159
        exit (1);
 
160
    }
 
161
 
 
162
    status = process_command (sourcename, 1, nargs, arglist);
 
163
 
 
164
    (void) auth_finalize ();
 
165
    exit ((status != 0) ? 1 : 0);
 
166
}