home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / clients / xauth / xauth.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-11  |  4.3 KB  |  163 lines

  1. /*
  2.  * $XConsortium: xauth.c,v 1.17 89/12/07 10:39:55 rws Exp $
  3.  *
  4.  * xauth - manipulate authorization file
  5.  *
  6.  * Copyright 1989 Massachusetts Institute of Technology
  7.  *
  8.  * Permission to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted, provided
  10.  * that the above copyright notice appear in all copies and that both that
  11.  * copyright notice and this permission notice appear in supporting
  12.  * documentation, and that the name of M.I.T. not be used in advertising
  13.  * or publicity pertaining to distribution of the software without specific,
  14.  * written prior permission.  M.I.T. makes no representations about the
  15.  * suitability of this software for any purpose.  It is provided "as is"
  16.  * without express or implied warranty.
  17.  *
  18.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  19.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  20.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  21.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  22.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  23.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  *
  25.  * Author:  Jim Fulton, MIT X Consortium
  26.  */
  27.  
  28. #include "xauth.h"
  29.  
  30.  
  31. /*
  32.  * global data
  33.  */
  34. char *ProgramName;            /* argv[0], set at top of main() */
  35. int verbose = -1;            /* print certain messages */
  36. Bool ignore_locks = False;        /* for error recovery */
  37. Bool break_locks = False;        /* for error recovery */
  38.  
  39. /*
  40.  * local data
  41.  */
  42.  
  43. static char *authfilename = NULL;    /* filename of cookie file */
  44. static char *defcmds[] = { "source", "-", NULL };  /* default command */
  45. static int ndefcmds = 2;
  46. static char *defsource = "(stdin)";
  47.  
  48. /*
  49.  * utility routines
  50.  */
  51. static void usage ()
  52. {
  53.     static char *prefixmsg[] = {
  54. "",
  55. "where options include:",
  56. "    -f authfilename                name of authority file to use",
  57. "    -v                             turn on extra messages",
  58. "    -q                             turn off extra messages",
  59. "    -i                             ignore locks on authority file",
  60. "    -b                             break locks on authority file",
  61. "",
  62. "and commands have the following syntax:",
  63. "",
  64. NULL };
  65.     static char *suffixmsg[] = {
  66. "A dash may be used with the \"merge\" and \"source\" to read from the",
  67. "standard input.  Commands beginning with \"n\" use numeric format.",
  68. "",
  69. NULL };
  70.     char **msg;
  71.  
  72.     fprintf (stderr, "usage:  %s [-options ...] [command arg ...]\n",
  73.          ProgramName);
  74.     for (msg = prefixmsg; *msg; msg++) {
  75.     fprintf (stderr, "%s\n", *msg);
  76.     }
  77.     print_help (stderr, NULL, "    ");    /* match prefix indentation */
  78.     fprintf (stderr, "\n");
  79.     for (msg = suffixmsg; *msg; msg++) {
  80.     fprintf (stderr, "%s\n", *msg);
  81.     }
  82.     exit (1);
  83. }
  84.  
  85.  
  86. /*
  87.  * The main routine - parses command line and calls action procedures
  88.  */
  89. main (argc, argv)
  90.     int argc;
  91.     char *argv[];
  92. {
  93.     int i;
  94.     char *sourcename = defsource;
  95.     char **arglist = defcmds;
  96.     int nargs = ndefcmds;
  97.     int status;
  98.  
  99.     ProgramName = argv[0];
  100.  
  101.     for (i = 1; i < argc; i++) {
  102.     char *arg = argv[i];
  103.  
  104.     if (arg[0] == '-') {
  105.         char *flag;
  106.  
  107.         for (flag = (arg + 1); *flag; flag++) {
  108.         switch (*flag) {
  109.           case 'f':        /* -f authfilename */
  110.             if (++i >= argc) usage ();
  111.             authfilename = argv[i];
  112.             continue;
  113.           case 'v':        /* -v */
  114.             verbose = 1;
  115.             continue;
  116.           case 'q':        /* -q */
  117.             verbose = 0;
  118.             continue;
  119.           case 'b':        /* -b */
  120.             break_locks = True;
  121.             continue;
  122.           case 'i':        /* -i */
  123.             ignore_locks = True;
  124.             continue;
  125.           default:
  126.             usage ();
  127.         }
  128.         }
  129.     } else {
  130.         sourcename = "(argv)";
  131.         nargs = argc - i;
  132.         arglist = argv + i;
  133.         if (verbose == -1) verbose = 0;
  134.         break;
  135.     }
  136.     }
  137.  
  138.     if (verbose == -1) {        /* set default, don't junk stdout */
  139.     verbose = (isatty(fileno(stdout)) != 0);
  140.     }
  141.  
  142.     if (!authfilename) {
  143.     authfilename = XauFileName ();    /* static name, do not free */
  144.     if (!authfilename) {
  145.         fprintf (stderr,
  146.              "%s:  unable to generate an authority file name\n",
  147.              ProgramName);
  148.         exit (1);
  149.     }
  150.     }
  151.     if (auth_initialize (authfilename) != 0) {
  152.     /* error message printed in auth_initialize */
  153.     exit (1);
  154.     }
  155.  
  156.     status = process_command (sourcename, 1, nargs, arglist);
  157.  
  158.     (void) auth_finalize ();
  159.     exit ((status != 0) ? 1 : 0);
  160. }
  161.  
  162.  
  163.