openafs-string-header-cleanup-20071030
[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 <afsconfig.h>
12 #include <afs/param.h>
13
14 RCSID
15     ("$Header$");
16
17 #include <afs/stds.h>
18 #ifdef  AFS_AIX32_ENV
19 #include <signal.h>
20 #endif
21
22 #include <sys/types.h>
23 #include <rx/xdr.h>
24
25 #include <lock.h>
26 #include <ubik.h>
27 #ifndef AFS_NT40_ENV
28 #include <pwd.h>
29 #else
30 #include <WINNT/afsevent.h>
31 #endif
32 #include <string.h>
33 #include <afs/cellconfig.h>
34 #include <afs/com_err.h>
35
36 #include "kauth.h"
37 #include "kautils.h"
38
39
40 int
41 main(int argc, char *argv[])
42 {
43     afs_int32 code;
44     char *ap[25];
45     int i;
46     char *whoami = argv[0];
47
48 #ifdef  AFS_AIX32_ENV
49     /*
50      * The following signal action for AIX is necessary so that in case of a 
51      * crash (i.e. core is generated) we can include the user's data section 
52      * in the core dump. Unfortunately, by default, only a partial core is
53      * generated which, in many cases, isn't too useful.
54      */
55     struct sigaction nsa;
56
57     sigemptyset(&nsa.sa_mask);
58     nsa.sa_handler = SIG_DFL;
59     nsa.sa_flags = SA_FULLDUMP;
60     sigaction(SIGABRT, &nsa, NULL);
61     sigaction(SIGSEGV, &nsa, NULL);
62 #endif
63     initialize_CMD_error_table();
64     initialize_KTC_error_table();
65     initialize_KA_error_table();
66     initialize_ACFG_error_table();
67     initialize_U_error_table();
68
69 #ifdef AFS_NT40_ENV
70     /* initialize winsock */
71     if (afs_winsockInit() < 0) {
72         fprintf(stderr, "%s: Couldn't initialize winsock.\n", whoami);
73         exit(1);
74     }
75 #endif
76
77     code = ka_Init(0);
78     if (code) {
79         afs_com_err(whoami, code, "Can't get cell info");
80         exit(1);
81     }
82
83     /* if there are no arguments or if the first argument is "-cell" or if the
84      * first argument is clearly a username (it contains a '.' or '@') assume
85      * the interactive command and splice it into the arglist. */
86
87     ap[0] = argv[0];
88     ap[1] = "interactive";
89     if (argc == 1)
90         code = ka_AdminInteractive(2, ap);
91     else if ((strncmp(argv[1], "-admin_username", strlen(argv[1])) == 0)
92              || (strncmp(argv[1], "-password_for_admin", strlen(argv[1])) ==
93                  0)
94              || (strncmp(argv[1], "-cell", strlen(argv[1])) == 0)
95              || (strncmp(argv[1], "-servers", strlen(argv[1])) == 0)
96              || (strncmp(argv[1], "-noauth", strlen(argv[1])) == 0)
97              || (strpbrk(argv[1], "@.") != 0)) {
98         for (i = 1; i < argc; i++)
99             ap[i + 1] = argv[i];
100         code = ka_AdminInteractive(argc + 1, ap);
101     } else
102         code = ka_AdminInteractive(argc, argv);
103
104     rx_Finalize();
105     exit(code != 0);
106 }