2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * $TOG: ttauth.c /main/1 1999/08/30 10:46:20 mgreess $
26 * xauth - manipulate authorization file
29 Copyright 1989, 1998 The Open Group
33 The above copyright notice and this permission notice shall be included in
34 all copies or substantial portions of the Software.
36 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
40 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
41 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43 Except as contained in this notice, the name of The Open Group shall not be
44 used in advertising or otherwise to promote the sale, use or other dealings
45 in this Software without prior written authorization from The Open Group.
47 * Original Author of "xauth" : Jim Fulton, MIT X Consortium
48 * Modified into "iceauth" : Ralph Mor, X Consortium
49 * Modified into "ttauth" : Mitch Greess, Solutions Atlantic
53 #include "api/c/tt_c.h"
59 char *ProgramName; /* argv[0], set at top of main() */
60 int verbose = -1; /* print certain messages */
61 Bool ignore_locks = False; /* for error recovery */
62 Bool break_locks = False; /* for error recovery */
68 static char *authfilename = NULL; /* filename of cookie file */
69 static char *defcmds[] = { "source", "-", NULL }; /* default command */
70 static int ndefcmds = 2;
71 static char *defsource = "(stdin)";
78 static char *prefixmsg[] = {
80 "where options include:",
81 " -f authfilename name of authority file to use",
82 " -v turn on extra messages",
83 " -q turn off extra messages",
84 " -i ignore locks on authority file",
85 " -b break locks on authority file",
87 "and commands have the following syntax:",
90 static char *suffixmsg[] = {
91 "A dash may be used with the \"merge\" and \"source\" to read from the",
92 "standard input. Commands beginning with \"n\" use numeric format.",
97 fprintf (stderr, "usage: %s [-options ...] [command arg ...]\n",
99 for (msg = prefixmsg; *msg; msg++) {
100 fprintf (stderr, "%s\n", *msg);
102 print_help (stderr, NULL, " "); /* match prefix indentation */
103 fprintf (stderr, "\n");
104 for (msg = suffixmsg; *msg; msg++) {
105 fprintf (stderr, "%s\n", *msg);
112 * The main routine - parses command line and calls action procedures
119 char *sourcename = defsource;
120 char **arglist = defcmds;
121 int nargs = ndefcmds;
124 ProgramName = argv[0];
126 for (i = 1; i < argc; i++) {
132 for (flag = (arg + 1); *flag; flag++) {
134 case 'f': /* -f authfilename */
135 if (++i >= argc) usage ();
136 authfilename = argv[i];
155 sourcename = "(argv)";
158 if (verbose == -1) verbose = 0;
163 if (verbose == -1) { /* set default, don't junk stdout */
164 verbose = (isatty(fileno(stdout)) != 0);
168 authfilename = tt_AuthFileName (); /* static name, do not free */
171 "%s: unable to generate an authority file name\n",
176 if (auth_initialize (authfilename) != 0) {
177 /* error message printed in auth_initialize */
181 status = process_command (sourcename, 1, nargs, arglist);
183 (void) auth_finalize ();
184 exit ((status != 0) ? 1 : 0);