~ubuntu-branches/ubuntu/vivid/xauth/vivid

« back to all changes in this revision

Viewing changes to xauth.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Stone
  • Date: 2005-07-26 21:45:42 UTC
  • Revision ID: james.westby@ubuntu.com-20050726214542-0c1gsmulfz6f3fff
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Xorg: xauth.c,v 1.4 2001/02/09 02:05:38 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
 * Author:  Jim Fulton, MIT X Consortium
 
30
 */
 
31
/* $XFree86: xc/programs/xauth/xauth.c,v 1.5tsi Exp $ */
 
32
 
 
33
#ifdef HAVE_CONFIG_H
 
34
#include <config.h>
 
35
#endif
 
36
 
 
37
#include "xauth.h"
 
38
 
 
39
 
 
40
/*
 
41
 * global data
 
42
 */
 
43
char *ProgramName;                      /* argv[0], set at top of main() */
 
44
int verbose = -1;                       /* print certain messages */
 
45
Bool ignore_locks = False;              /* for error recovery */
 
46
Bool break_locks = False;               /* for error recovery */
 
47
Bool no_name_lookups = False;           /* show addresses instead of names */
 
48
 
 
49
/*
 
50
 * local data
 
51
 */
 
52
 
 
53
static char *authfilename = NULL;       /* filename of cookie file */
 
54
static char *defcmds[] = { "source", "-", NULL };  /* default command */
 
55
static int ndefcmds = 2;
 
56
static char *defsource = "(stdin)";
 
57
 
 
58
/*
 
59
 * utility routines
 
60
 */
 
61
static void 
 
62
usage(void)
 
63
{
 
64
    static char *prefixmsg[] = {
 
65
"",
 
66
"where options include:",
 
67
"    -f authfilename                name of authority file to use",
 
68
"    -v                             turn on extra messages",
 
69
"    -q                             turn off extra messages",
 
70
"    -i                             ignore locks on authority file",
 
71
"    -b                             break locks on authority file",
 
72
"",
 
73
"and commands have the following syntax:",
 
74
"",
 
75
NULL };
 
76
    static char *suffixmsg[] = {
 
77
"A dash may be used with the \"merge\" and \"source\" to read from the",
 
78
"standard input.  Commands beginning with \"n\" use numeric format.",
 
79
"",
 
80
NULL };
 
81
    char **msg;
 
82
 
 
83
    fprintf (stderr, "usage:  %s [-options ...] [command arg ...]\n",
 
84
             ProgramName);
 
85
    for (msg = prefixmsg; *msg; msg++) {
 
86
        fprintf (stderr, "%s\n", *msg);
 
87
    }
 
88
    print_help (stderr, NULL, "    ");  /* match prefix indentation */
 
89
    fprintf (stderr, "\n");
 
90
    for (msg = suffixmsg; *msg; msg++) {
 
91
        fprintf (stderr, "%s\n", *msg);
 
92
    }
 
93
    exit (1);
 
94
}
 
95
 
 
96
 
 
97
/*
 
98
 * The main routine - parses command line and calls action procedures
 
99
 */
 
100
int
 
101
main(int argc, char *argv[])
 
102
{
 
103
    int i;
 
104
    char *sourcename = defsource;
 
105
    char **arglist = defcmds;
 
106
    int nargs = ndefcmds;
 
107
    int status;
 
108
 
 
109
    ProgramName = argv[0];
 
110
 
 
111
    for (i = 1; i < argc; i++) {
 
112
        char *arg = argv[i];
 
113
 
 
114
        if (arg[0] == '-') {
 
115
            char *flag;
 
116
 
 
117
            for (flag = (arg + 1); *flag; flag++) {
 
118
                switch (*flag) {
 
119
                  case 'f':             /* -f authfilename */
 
120
                    if (++i >= argc) usage ();
 
121
                    authfilename = argv[i];
 
122
                    continue;
 
123
                  case 'v':             /* -v */
 
124
                    verbose = 1;
 
125
                    continue;
 
126
                  case 'q':             /* -q */
 
127
                    verbose = 0;
 
128
                    continue;
 
129
                  case 'b':             /* -b */
 
130
                    break_locks = True;
 
131
                    continue;
 
132
                  case 'i':             /* -i */
 
133
                    ignore_locks = True;
 
134
                    continue;
 
135
                  case 'n':             /* -n */
 
136
                    no_name_lookups = True;
 
137
                    continue;
 
138
                  default:
 
139
                    usage ();
 
140
                }
 
141
            }
 
142
        } else {
 
143
            sourcename = "(argv)";
 
144
            nargs = argc - i;
 
145
            arglist = argv + i;
 
146
            if (verbose == -1) verbose = 0;
 
147
            break;
 
148
        }
 
149
    }
 
150
 
 
151
    if (verbose == -1) {                /* set default, don't junk stdout */
 
152
        verbose = (isatty(fileno(stdout)) != 0);
 
153
    }
 
154
 
 
155
    if (!authfilename) {
 
156
        authfilename = XauFileName ();  /* static name, do not free */
 
157
        if (!authfilename) {
 
158
            fprintf (stderr,
 
159
                     "%s:  unable to generate an authority file name\n",
 
160
                     ProgramName);
 
161
            exit (1);
 
162
        }
 
163
    }
 
164
    if (auth_initialize (authfilename) != 0) {
 
165
        /* error message printed in auth_initialize */
 
166
        exit (1);
 
167
    }
 
168
 
 
169
    status = process_command (sourcename, 1, nargs, arglist);
 
170
 
 
171
    (void) auth_finalize ();
 
172
    exit ((status != 0) ? 1 : 0);
 
173
}
 
174
 
 
175