2 * xauth - manipulate authorization file
5 Copyright 1989, 1998 The Open Group
7 Permission to use, copy, modify, distribute, and sell this software and its
8 documentation for any purpose is hereby granted without fee, provided that
9 the above copyright notice appear in all copies and that both that
10 copyright notice and this permission notice appear in supporting
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of The Open Group shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from The Open Group.
27 * Original Author of "xauth" : Jim Fulton, MIT X Consortium
28 * Modified into "iceauth" : Ralph Mor, X Consortium
37 const char *ProgramName; /* argv[0], set at top of main() */
38 int verbose = -1; /* print certain messages */
39 Bool ignore_locks = False; /* for error recovery */
40 Bool break_locks = False; /* for error recovery */
46 static char *authfilename = NULL; /* filename of cookie file */
47 static char *defcmds[] = { "source", "-", NULL }; /* default command */
48 static int ndefcmds = 2;
49 static const char *defsource = "(stdin)";
55 static void usage (void)
57 static const char prefixmsg[] =
59 "where options include:\n"
60 " -f authfilename name of authority file to use\n"
61 " -v turn on extra messages\n"
62 " -q turn off extra messages\n"
63 " -i ignore locks on authority file\n"
64 " -b break locks on authority file\n"
66 "and commands have the following syntax:\n";
67 static const char suffixmsg[] =
68 "A dash may be used with the \"merge\" and \"source\" to read from the\n"
69 "standard input. Commands beginning with \"n\" use numeric format.\n";
71 fprintf (stderr, "usage: %s [-options ...] [command arg ...]\n",
73 fprintf (stderr, "%s\n", prefixmsg);
74 print_help (stderr, " "); /* match prefix indentation */
75 fprintf (stderr, "\n%s\n", suffixmsg);
81 * The main routine - parses command line and calls action procedures
84 main (int argc, char *argv[])
87 const char *sourcename = defsource;
88 char **arglist = defcmds;
92 ProgramName = argv[0];
94 for (i = 1; i < argc; i++) {
100 for (flag = (arg + 1); *flag; flag++) {
102 case 'f': /* -f authfilename */
103 if (++i >= argc) usage ();
104 authfilename = argv[i];
123 sourcename = "(argv)";
126 if (verbose == -1) verbose = 0;
131 if (verbose == -1) { /* set default, don't junk stdout */
132 verbose = (isatty(fileno(stdout)) != 0);
136 authfilename = IceAuthFileName (); /* static name, do not free */
139 "%s: unable to generate an authority file name\n",
144 if (auth_initialize (authfilename) != 0) {
145 /* error message printed in auth_initialize */
149 status = process_command (sourcename, 1, nargs, arglist);
151 (void) auth_finalize ();
152 exit ((status != 0) ? 1 : 0);