2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include <afs/param.h>
18 #include <WINNT/afsevent.h>
25 #include <rx/rxstat.h>
27 #include <rx/rx_globals.h>
28 #include <afs/cellconfig.h>
30 #include <afs/afsutil.h>
31 #include <afs/com_err.h>
32 #include <afs/audit.h>
35 #include "kalog.h" /* for OpenLog() */
37 #include "kauth_internal.h"
40 #include "kadatabase.h"
43 struct kadstats dynamic_statistics;
44 struct ubik_dbase *KA_dbase;
45 afs_uint32 myHost = 0;
46 afs_int32 verbose_track = 1;
47 afs_int32 krb4_cross = 0;
50 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
51 afs_uint32 SHostAddrs[ADDRSPERSITE];
53 struct afsconf_dir *KA_conf; /* for getting cell info */
56 int npwSums = KA_NPWSUMS; /* needs to be variable sometime */
58 #if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
60 #define vfprintf(stream,fmt,args) _doprnt(fmt,args,stream)
63 static int debugOutput;
65 /* check whether caller is authorized to manage RX statistics */
67 KA_rxstat_userok(struct rx_call *call)
69 return afsconf_SuperUser(KA_conf, call, NULL);
73 es_Report(char *fmt, ...)
80 vfprintf(stderr, fmt, pvar);
86 initialize_dstats(void)
88 memset(&dynamic_statistics, 0, sizeof(dynamic_statistics));
89 dynamic_statistics.start_time = time(0);
90 dynamic_statistics.host = myHost;
94 convert_cell_to_ubik(struct afsconf_cell *cellinfo, afs_uint32 *myHost,
95 afs_uint32 *serverList)
102 gethostname(hostname, sizeof(hostname));
103 th = gethostbyname(hostname);
105 ViceLog(0, ("kaserver: couldn't get address of this host.\n"));
108 memcpy(myHost, th->h_addr, sizeof(afs_uint32));
110 for (i = 0; i < cellinfo->numServers; i++)
111 if (cellinfo->hostAddr[i].sin_addr.s_addr != *myHost) {
112 /* omit my host from serverList */
113 *serverList++ = cellinfo->hostAddr[i].sin_addr.s_addr;
115 *serverList = 0; /* terminate list */
120 kvno_admin_key(void *rock, afs_int32 kvno, struct ktc_encryptionKey *key)
122 return ka_LookupKvno(0, KA_ADMIN_NAME, KA_ADMIN_INST, kvno, key);
124 /* we would like to start a Ubik transaction to fill the cache if that
125 * fails, but may deadlock as Rx is now organized. */
128 /* initFlags: 0x01 Do not require authenticated connections.
129 0x02 Do not check the bos NoAuth flag
130 0x04 Use fast key expiration to test oldkey code.
131 0x08 Temporary flag allowing database inconsistency fixup
134 #include "AFS_component_version_number.c"
137 main(int argc, char *argv[])
140 char *whoami = argv[0];
141 afs_uint32 serverList[MAXSERVERS];
142 struct afsconf_cell cellinfo;
144 const char *cellservdb, *dbpath, *lclpath;
147 char default_lclpath[AFSDIR_PATH_MAX];
150 int level; /* security level for Ubik */
152 char clones[MAXHOSTSPERCELL];
153 afs_uint32 host = ntohl(INADDR_ANY);
154 char *auditFileName = NULL;
156 struct rx_service *tservice;
157 struct rx_securityClass *sca[1];
158 struct rx_securityClass *scm[3];
160 extern int rx_stackSize;
164 * The following signal action for AIX is necessary so that in case of a
165 * crash (i.e. core is generated) we can include the user's data section
166 * in the core dump. Unfortunately, by default, only a partial core is
167 * generated which, in many cases, isn't too useful.
169 struct sigaction nsa;
171 sigemptyset(&nsa.sa_mask);
172 nsa.sa_handler = SIG_DFL;
173 nsa.sa_flags = SA_FULLDUMP;
174 sigaction(SIGABRT, &nsa, NULL);
175 sigaction(SIGSEGV, &nsa, NULL);
181 printf("Usage: kaserver [-noAuth] [-database <dbpath>] "
182 "[-auditlog <log path>] [-audit-interface <file|sysvmq>] "
183 "[-rxbind] [-localfiles <lclpath>] [-minhours <n>] "
184 "[-servers <serverlist>] [-crossrealm] "
185 /*" [-enable_peer_stats] [-enable_process_stats] " */
190 /* initialize winsock */
191 if (afs_winsockInit() < 0) {
192 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
193 fprintf(stderr, "%s: Couldn't initialize winsock.\n", whoami);
197 /* Initialize dirpaths */
198 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
200 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
202 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
207 cellservdb = AFSDIR_SERVER_ETC_DIRPATH;
208 dbpath = AFSDIR_SERVER_KADB_FILEPATH;
209 strcompose(default_lclpath, AFSDIR_PATH_MAX, AFSDIR_SERVER_LOCAL_DIRPATH,
210 "/", AFSDIR_KADB_FILE, NULL);
211 lclpath = default_lclpath;
217 for (a = 1; a < argc; a++) {
218 int arglen = strlen(argv[a]);
219 lcstring(arg, argv[a], sizeof(arg));
220 #define IsArg(a) (strncmp (arg,a, arglen) == 0)
222 if (strcmp(arg, "-database") == 0) {
224 if (strcmp(lclpath, default_lclpath) == 0)
227 else if (strncmp(arg, "-auditlog", arglen) == 0) {
228 auditFileName = argv[++a];
230 } else if (strncmp(arg, "-audit-interface", arglen) == 0) {
231 char *interface = argv[++a];
233 if (osi_audit_interface(interface)) {
234 printf("Invalid audit interface '%s'\n", interface);
238 } else if (strcmp(arg, "-localfiles") == 0)
240 else if (strcmp(arg, "-servers") == 0)
241 debugOutput++, servers = 1;
242 else if (strcmp(arg, "-noauth") == 0)
243 debugOutput++, initFlags |= 1;
244 else if (strcmp(arg, "-fastkeys") == 0)
245 debugOutput++, initFlags |= 4;
246 else if (strcmp(arg, "-dbfixup") == 0)
247 debugOutput++, initFlags |= 8;
248 else if (strcmp(arg, "-cellservdb") == 0) {
249 cellservdb = argv[++a];
254 else if (IsArg("-crypt"))
256 else if (IsArg("-safe"))
258 else if (IsArg("-clear"))
260 else if (IsArg("-sorry"))
262 else if (IsArg("-debug"))
264 else if (IsArg("-crossrealm"))
266 else if (IsArg("-rxbind"))
268 else if (IsArg("-minhours")) {
269 MinHours = atoi(argv[++a]);
270 } else if (IsArg("-enable_peer_stats")) {
271 rx_enablePeerRPCStats();
272 } else if (IsArg("-enable_process_stats")) {
273 rx_enableProcessRPCStats();
274 } else if (*arg == '-') {
275 /* hack to support help flag */
281 osi_audit_file(auditFileName);
284 if ((code = ka_CellConfig(cellservdb)))
286 cell = ka_LocalCell();
287 KA_conf = afsconf_Open(cellservdb);
291 afs_com_err(whoami, code, "Failed getting cell info");
297 /* NT & HPUX do not have dbm package support. So we can only do some
298 * text logging. So open the AuthLog file for logging and redirect
299 * stdin and stdout to it
301 OpenLog(AFSDIR_SERVER_KALOG_FILEPATH);
305 fprintf(stderr, "%s: WARNING: kaserver is deprecated due to its weak security "
306 "properties. Migrating to a Kerberos 5 KDC is advised. "
307 "http://www.openafs.org/no-more-des.html\n", whoami);
308 ViceLog(0, ("WARNING: kaserver is deprecated due to its weak security properties. "
309 "Migrating to a Kerberos 5 KDC is advised. "
310 "http://www.openafs.org/no-more-des.html\n"));
313 afsconf_GetExtendedCellInfo(KA_conf, cell, AFSCONF_KAUTHSERVICE,
316 if ((code = ubik_ParseServerList(argc, argv, &myHost, serverList))) {
317 afs_com_err(whoami, code, "Couldn't parse server list");
320 cellinfo.hostAddr[0].sin_addr.s_addr = myHost;
321 for (i = 1; i < MAXSERVERS; i++) {
324 cellinfo.hostAddr[i].sin_addr.s_addr = serverList[i];
326 cellinfo.numServers = i;
328 code = convert_cell_to_ubik(&cellinfo, &myHost, serverList);
331 ViceLog(0, ("Using server list from %s cell database.\n", cell));
334 /* initialize ubik */
335 if (level == rxkad_clear)
336 ubik_SetClientSecurityProcs(afsconf_ClientAuth, afsconf_UpToDate,
338 else if (level == rxkad_crypt)
339 ubik_SetClientSecurityProcs(afsconf_ClientAuthSecure,
340 afsconf_UpToDate, KA_conf);
342 ViceLog(0, ("Unsupported security level %d\n", level));
346 ("Using level %s for Ubik connections.\n",
347 (level == rxkad_crypt ? "crypt" : "clear")));
349 ubik_SetServerSecurityProcs(afsconf_BuildServerSecurityObjects,
357 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
358 AFSDIR_SERVER_NETINFO_FILEPATH) {
360 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
361 ADDRSPERSITE, reason,
362 AFSDIR_SERVER_NETINFO_FILEPATH,
363 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
366 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
369 host = SHostAddrs[0];
370 rx_InitHost(host, htons(AFSCONF_KAUTHPORT));
376 ubik_ServerInit(myHost, htons(AFSCONF_KAUTHPORT), serverList,
380 ubik_ServerInitByInfo(myHost, htons(AFSCONF_KAUTHPORT), &cellinfo,
381 clones, dbpath, &KA_dbase);
384 afs_com_err(whoami, code, "Ubik init failed");
388 sca[RX_SCINDEX_NULL] = rxnull_NewServerSecurityObject();
390 /* Disable jumbograms */
394 rx_NewServiceHost(host, 0, KA_AUTHENTICATION_SERVICE,
395 "AuthenticationService", sca, 1, KAA_ExecuteRequest);
396 if (tservice == (struct rx_service *)0) {
397 ViceLog(0, ("Could not create Authentication rx service\n"));
400 rx_SetMinProcs(tservice, 1);
401 rx_SetMaxProcs(tservice, 1);
405 rx_NewServiceHost(host, 0, KA_TICKET_GRANTING_SERVICE, "TicketGrantingService",
406 sca, 1, KAT_ExecuteRequest);
407 if (tservice == (struct rx_service *)0) {
408 ViceLog(0, ("Could not create Ticket Granting rx service\n"));
411 rx_SetMinProcs(tservice, 1);
412 rx_SetMaxProcs(tservice, 1);
414 scm[RX_SCINDEX_NULL] = sca[RX_SCINDEX_NULL];
415 scm[RX_SCINDEX_VAB] = 0;
416 scm[RX_SCINDEX_KAD] =
417 rxkad_NewServerSecurityObject(rxkad_crypt, 0, kvno_admin_key, 0);
419 rx_NewServiceHost(host, 0, KA_MAINTENANCE_SERVICE, "Maintenance", scm, 3,
421 if (tservice == (struct rx_service *)0) {
422 ViceLog(0, ("Could not create Maintenance rx service\n"));
425 rx_SetMinProcs(tservice, 1);
426 rx_SetMaxProcs(tservice, 1);
427 rx_SetStackSize(tservice, 10000);
430 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats", scm, 3,
431 RXSTATS_ExecuteRequest);
432 if (tservice == (struct rx_service *)0) {
433 ViceLog(0, ("Could not create rpc stats rx service\n"));
436 rx_SetMinProcs(tservice, 2);
437 rx_SetMaxProcs(tservice, 4);
441 /* allow super users to manage RX statistics */
442 rx_SetRxStatUserOk(KA_rxstat_userok);
444 rx_StartServer(0); /* start handling req. of all types */
446 if (init_kaprocs(lclpath, initFlags))
449 if ((code = init_krb_udp())) {
451 ("Failed to initialize UDP interface; code = %d.\n", code));
452 ViceLog(0, ("Running without UDP access.\n"));
455 ViceLog(0, ("Starting to process AuthServer requests\n"));
456 rx_ServerProc(NULL); /* donate this LWP */