3ebd0840ab7b39b64e7b9f062d9b2ba0e65e2193
[openafs.git] / src / kauth / kas.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /* These two needed for rxgen output to work */
11 #include <afs/param.h>
12 #include <afsconfig.h>
13
14 RCSID("$Header$");
15
16 #include <afs/stds.h>
17 #ifdef  AFS_AIX32_ENV
18 #include <signal.h>
19 #endif
20
21 #include <sys/types.h>
22 #include <rx/xdr.h>
23
24 #include <lock.h>
25 #include <ubik.h>
26 #ifndef AFS_NT40_ENV
27 #include <pwd.h>
28 #else
29 #include <WINNT/afsevent.h>
30 #endif
31 #include <afs/cellconfig.h>
32 #include <afs/com_err.h>
33
34 #include "kauth.h"
35 #include "kautils.h"
36
37
38 int main (
39   int   argc,
40   char *argv[])
41 {
42     afs_int32 code;
43     char *ap[25];
44     int   i;
45     char *whoami = argv[0];
46
47 #ifdef  AFS_AIX32_ENV
48     /*
49      * The following signal action for AIX is necessary so that in case of a 
50      * crash (i.e. core is generated) we can include the user's data section 
51      * in the core dump. Unfortunately, by default, only a partial core is
52      * generated which, in many cases, isn't too useful.
53      */
54     struct sigaction nsa;
55     
56     sigemptyset(&nsa.sa_mask);
57     nsa.sa_handler = SIG_DFL;
58     nsa.sa_flags = SA_FULLDUMP;
59     sigaction(SIGABRT, &nsa, NULL);
60     sigaction(SIGSEGV, &nsa, NULL);
61 #endif
62     initialize_cmd_error_table();
63     initialize_ktc_error_table();
64     initialize_ka_error_table();
65     initialize_acfg_error_table();
66     initialize_u_error_table();
67
68 #ifdef AFS_NT40_ENV
69     /* initialize winsock */
70     if (afs_winsockInit()<0) {
71       fprintf(stderr, "%s: Couldn't initialize winsock.\n", whoami);
72       exit(1);
73     }
74 #endif
75
76     code = ka_Init(0);
77     if (code) {
78         com_err (whoami, code, "Can't get cell info");
79         exit (1);
80     }
81
82     /* if there are no arguments or if the first argument is "-cell" or if the
83        first argument is clearly a username (it contains a '.' or '@') assume
84        the interactive command and splice it into the arglist. */
85
86     ap[0] = argv[0];
87     ap[1] = "interactive";
88     if (argc == 1) code = ka_AdminInteractive (2, ap);
89     else if ((strncmp (argv[1], "-admin_username", strlen(argv[1])) == 0) ||
90              (strncmp (argv[1], "-password_for_admin", strlen(argv[1])) == 0) ||
91              (strncmp (argv[1], "-cell", strlen(argv[1])) == 0) ||
92              (strncmp (argv[1], "-servers", strlen(argv[1])) == 0) ||
93              (strncmp (argv[1], "-noauth", strlen(argv[1])) == 0) ||
94              (strpbrk (argv[1], "@.") != 0)) {
95         for (i=1; i<argc; i++) ap[i+1] = argv[i];
96         code = ka_AdminInteractive (argc+1, ap);
97     }
98     else code = ka_AdminInteractive (argc, argv);
99
100     rx_Finalize();
101     exit (code != 0);
102 }