ttauth.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * $TOG: ttauth.c /main/1 1999/08/30 10:46:20 mgreess $
  25. *
  26. * xauth - manipulate authorization file
  27. *
  28. *
  29. Copyright 1989, 1998 The Open Group
  30. All Rights Reserved.
  31. The above copyright notice and this permission notice shall be included in
  32. all copies or substantial portions of the Software.
  33. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  34. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  35. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  36. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  37. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  38. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  39. Except as contained in this notice, the name of The Open Group shall not be
  40. used in advertising or otherwise to promote the sale, use or other dealings
  41. in this Software without prior written authorization from The Open Group.
  42. * *
  43. * Original Author of "xauth" : Jim Fulton, MIT X Consortium
  44. * Modified into "iceauth" : Ralph Mor, X Consortium
  45. * Modified into "ttauth" : Mitch Greess, Solutions Atlantic
  46. */
  47. #include "ttauth.h"
  48. #include "Tt/tt_c.h"
  49. /*
  50. * global data
  51. */
  52. char *ProgramName; /* argv[0], set at top of main() */
  53. int verbose = -1; /* print certain messages */
  54. Bool ignore_locks = False; /* for error recovery */
  55. Bool break_locks = False; /* for error recovery */
  56. /*
  57. * local data
  58. */
  59. static char *authfilename = NULL; /* filename of cookie file */
  60. static char *defcmds[] = { "source", "-", NULL }; /* default command */
  61. static int ndefcmds = 2;
  62. static char *defsource = "(stdin)";
  63. /*
  64. * utility routines
  65. */
  66. static void
  67. usage(void)
  68. {
  69. static char *prefixmsg[] = {
  70. "",
  71. "where options include:",
  72. " -f authfilename name of authority file to use",
  73. " -v turn on extra messages",
  74. " -q turn off extra messages",
  75. " -i ignore locks on authority file",
  76. " -b break locks on authority file",
  77. "",
  78. "and commands have the following syntax:",
  79. "",
  80. NULL };
  81. static char *suffixmsg[] = {
  82. "A dash may be used with the \"merge\" and \"source\" to read from the",
  83. "standard input. Commands beginning with \"n\" use numeric format.",
  84. "",
  85. NULL };
  86. char **msg;
  87. fprintf (stderr, "usage: %s [-options ...] [command arg ...]\n",
  88. ProgramName);
  89. for (msg = prefixmsg; *msg; msg++) {
  90. fprintf (stderr, "%s\n", *msg);
  91. }
  92. print_help (stderr, NULL, " "); /* match prefix indentation */
  93. fprintf (stderr, "\n");
  94. for (msg = suffixmsg; *msg; msg++) {
  95. fprintf (stderr, "%s\n", *msg);
  96. }
  97. exit (1);
  98. }
  99. /*
  100. * The main routine - parses command line and calls action procedures
  101. */
  102. int
  103. main(int argc, char *argv[])
  104. {
  105. int i;
  106. char *sourcename = defsource;
  107. char **arglist = defcmds;
  108. int nargs = ndefcmds;
  109. int status;
  110. ProgramName = argv[0];
  111. for (i = 1; i < argc; i++) {
  112. char *arg = argv[i];
  113. if (arg[0] == '-') {
  114. char *flag;
  115. for (flag = (arg + 1); *flag; flag++) {
  116. switch (*flag) {
  117. case 'f': /* -f authfilename */
  118. if (++i >= argc) usage ();
  119. authfilename = argv[i];
  120. continue;
  121. case 'v': /* -v */
  122. verbose = 1;
  123. continue;
  124. case 'q': /* -q */
  125. verbose = 0;
  126. continue;
  127. case 'b': /* -b */
  128. break_locks = True;
  129. continue;
  130. case 'i': /* -i */
  131. ignore_locks = True;
  132. continue;
  133. default:
  134. usage ();
  135. }
  136. }
  137. } else {
  138. sourcename = "(argv)";
  139. nargs = argc - i;
  140. arglist = argv + i;
  141. if (verbose == -1) verbose = 0;
  142. break;
  143. }
  144. }
  145. if (verbose == -1) { /* set default, don't junk stdout */
  146. verbose = (isatty(fileno(stdout)) != 0);
  147. }
  148. if (!authfilename) {
  149. authfilename = tt_AuthFileName (); /* static name, do not free */
  150. if (!authfilename) {
  151. fprintf (stderr,
  152. "%s: unable to generate an authority file name\n",
  153. ProgramName);
  154. exit (1);
  155. }
  156. }
  157. if (auth_initialize (authfilename) != 0) {
  158. /* error message printed in auth_initialize */
  159. exit (1);
  160. }
  161. status = process_command (sourcename, 1, nargs, arglist);
  162. (void) auth_finalize ();
  163. exit ((status != 0) ? 1 : 0);
  164. }