2 * $Xorg: xauth.c,v 1.4 2001/02/09 02:05:38 xorgcvs Exp $
5 * xauth - manipulate authorization file
8 Copyright 1989,1998 The Open Group
10 Permission to use, copy, modify, distribute, and sell this software and its
11 documentation for any purpose is hereby granted without fee, provided that
12 the above copyright notice appear in all copies and that both that
13 copyright notice and this permission notice appear in supporting
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 Except as contained in this notice, the name of The Open Group shall not be
27 used in advertising or otherwise to promote the sale, use or other dealings
28 in this Software without prior written authorization from The Open Group.
30 * Author: Jim Fulton, MIT X Consortium
32 /* $XFree86: xc/programs/xauth/xauth.c,v 1.5tsi Exp $ */
44 char *ProgramName; /* argv[0], set at top of main() */
45 int verbose = -1; /* print certain messages */
46 Bool ignore_locks = False; /* for error recovery */
47 Bool break_locks = False; /* for error recovery */
48 Bool no_name_lookups = False; /* show addresses instead of names */
54 static char *authfilename = NULL; /* filename of cookie file */
55 static char *defcmds[] = { "source", "-", NULL }; /* default command */
56 static int ndefcmds = 2;
57 static char *defsource = "(stdin)";
65 static char *prefixmsg[] = {
67 "where options include:",
68 " -f authfilename name of authority file to use",
69 " -v turn on extra messages",
70 " -q turn off extra messages",
71 " -i ignore locks on authority file",
72 " -b break locks on authority file",
74 "and commands have the following syntax:",
77 static char *suffixmsg[] = {
78 "A dash may be used with the \"merge\" and \"source\" to read from the",
79 "standard input. Commands beginning with \"n\" use numeric format.",
84 fprintf (stderr, "usage: %s [-options ...] [command arg ...]\n",
86 for (msg = prefixmsg; *msg; msg++) {
87 fprintf (stderr, "%s\n", *msg);
89 print_help (stderr, NULL, " "); /* match prefix indentation */
90 fprintf (stderr, "\n");
91 for (msg = suffixmsg; *msg; msg++) {
92 fprintf (stderr, "%s\n", *msg);
99 * The main routine - parses command line and calls action procedures
102 main(int argc, char *argv[])
105 char *sourcename = defsource;
106 char **arglist = defcmds;
107 int nargs = ndefcmds;
110 ProgramName = argv[0];
112 for (i = 1; i < argc; i++) {
118 for (flag = (arg + 1); *flag; flag++) {
120 case 'f': /* -f authfilename */
121 if (++i >= argc) usage ();
122 authfilename = argv[i];
137 no_name_lookups = True;
144 sourcename = "(argv)";
147 if (verbose == -1) verbose = 0;
152 if (verbose == -1) { /* set default, don't junk stdout */
153 verbose = (isatty(fileno(stdout)) != 0);
157 authfilename = XauFileName (); /* static name, do not free */
160 "%s: unable to generate an authority file name\n",
165 if (auth_initialize (authfilename) != 0) {
166 /* error message printed in auth_initialize */
170 status = process_command (sourcename, 1, nargs, arglist);
172 (void) auth_finalize ();
173 exit ((status != 0) ? 1 : 0);