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>
19 #include <sys/types.h>
23 #include <WINNT/afsevent.h>
26 #include <netinet/in.h>
37 #include <rx/rx_globals.h>
40 #include <afs/cellconfig.h>
44 #include "error_macros.h"
45 #include "afs/audit.h"
46 #include <afs/afsutil.h>
49 /* make all of these into a structure if you want */
50 struct prheader cheader;
51 struct ubik_dbase *dbase;
52 struct afsconf_dir *prdir;
54 extern afs_int32 ubik_lastYesTime;
55 extern afs_int32 ubik_nBuffers;
57 extern int afsconf_ServerAuth();
58 extern int afsconf_CheckAuth();
63 #include "AFS_component_version_number.c"
65 /* check whether caller is authorized to manage RX statistics */
66 int pr_rxstat_userok(call)
69 return afsconf_SuperUser(prdir, call, (char *)0);
72 void main (argc, argv)
76 register afs_int32 code;
78 register struct hostent *th;
80 struct rx_service *tservice;
81 struct rx_securityClass *sc[3];
82 extern struct rx_securityClass *rxnull_NewServerSecurityObject();
83 extern struct rx_securityClass *rxkad_NewServerSecurityObject();
84 extern int RXSTATS_ExecuteRequest();
85 extern int PR_ExecuteRequest();
87 struct ktc_encryptionKey tkey;
89 struct afsconf_cell info;
90 int kerberosKeys; /* set if found some keys */
92 char clones[MAXHOSTSPERCELL];
94 const char *pr_dbaseName;
95 char *whoami = "ptserver";
102 * The following signal action for AIX is necessary so that in case of a
103 * crash (i.e. core is generated) we can include the user's data section
104 * in the core dump. Unfortunately, by default, only a partial core is
105 * generated which, in many cases, isn't too useful.
107 struct sigaction nsa;
109 sigemptyset(&nsa.sa_mask);
110 nsa.sa_handler = SIG_DFL;
111 nsa.sa_flags = SA_FULLDUMP;
112 sigaction(SIGABRT, &nsa, NULL);
113 sigaction(SIGSEGV, &nsa, NULL);
115 osi_audit (PTS_StartEvent, 0, AUD_END);
117 /* Initialize dirpaths */
118 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
120 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0],0);
122 fprintf(stderr,"%s: Unable to obtain AFS server directory.\n", argv[0]);
126 pr_dbaseName = AFSDIR_SERVER_PRDB_FILEPATH;
128 for (a=1; a<argc; a++) {
130 lcstring (arg, argv[a], sizeof(arg));
132 if ((strncmp (arg, "-database", alen) == 0) ||
133 (strncmp (arg, "-db", alen) == 0)) {
134 pr_dbaseName = argv[++a]; /* specify a database */
136 else if (strncmp(arg, "-p", alen) == 0) {
137 lwps = atoi(argv[++a]);
138 if (lwps > 16) { /* maximum of 16 */
139 printf("Warning: '-p %d' is too big; using %d instead\n",
142 } else if (lwps < 3) { /* minimum of 3 */
143 printf("Warning: '-p %d' is too small; using %d instead\n",
148 else if (strncmp (arg, "-rebuild", alen) == 0) /* rebuildDB++ */ ;
149 else if (strncmp (arg, "-enable_peer_stats", alen) == 0) {
150 rx_enablePeerRPCStats();
152 else if (strncmp (arg, "-enable_process_stats", alen) == 0) {
153 rx_enableProcessRPCStats();
156 else if (strncmp(arg, "-syslog", alen)==0) {
157 /* set syslog logging flag */
160 else if (strncmp(arg, "-syslog=", MIN(8,alen))==0) {
162 serverLogSyslogFacility = atoi(arg+8);
165 else if (*arg == '-') {
166 /* hack in help flag support */
169 printf ("Usage: ptserver [-database <db path>] "
170 "[-syslog[=FACILITY]] "
171 "[-p <number of processes>] [-rebuild] "
172 "[-enable_peer_stats] [-enable_process_stats] "
175 printf ("Usage: ptserver [-database <db path>] "
176 "[-p <number of processes>] [-rebuild] "
185 OpenLog(AFSDIR_SERVER_PTLOG_FILEPATH); /* set up logging */
188 prdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
190 fprintf (stderr, "ptserver: can't open configuration directory.\n");
193 if (afsconf_GetNoAuthFlag(prdir))
194 printf ("ptserver: running unauthenticated\n");
197 /* initialize winsock */
198 if (afs_winsockInit()<0) {
199 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0,
202 fprintf(stderr, "ptserver: couldn't initialize winsock. \n");
207 gethostname(hostname,sizeof(hostname));
208 th = gethostbyname(hostname);
210 fprintf (stderr, "ptserver: couldn't get address of this host.\n");
213 memcpy(&myHost, th->h_addr, sizeof(afs_int32));
215 /* get list of servers */
216 code = afsconf_GetExtendedCellInfo(prdir,(char *)0,"afsprot",
219 com_err (whoami, code, "Couldn't get server list");
222 pr_realmName = info.name;
223 pr_realmNameLen = strlen (pr_realmName);
227 code = afsconf_GetKey(prdir,999,&tkey);
229 com_err (whoami, code, "couldn't get bcrypt keys from key file, ignoring.");
232 { afs_int32 kvno; /* see if there is a KeyFile here */
233 struct ktc_encryptionKey key;
234 code = afsconf_GetLatestKey (prdir, &kvno, &key);
235 kerberosKeys = (code == 0);
237 printf ("ptserver: can't find any Kerberos keys, code = %d, ignoring\n", code);
240 /* initialize ubik */
241 ubik_CRXSecurityProc = afsconf_ClientAuth;
242 ubik_CRXSecurityRock = (char *)prdir;
243 ubik_SRXSecurityProc = afsconf_ServerAuth;
244 ubik_SRXSecurityRock = (char *)prdir;
245 ubik_CheckRXSecurityProc = afsconf_CheckAuth;
246 ubik_CheckRXSecurityRock = (char *)prdir;
248 /* The max needed is when deleting an entry. A full CoEntry deletion
249 * required removal from 39 entries. Each of which may refers to the entry
250 * being deleted in one of its CoEntries. If a CoEntry is freed its
251 * predecessor CoEntry will be modified as well. Any freed blocks also
252 * modifies the database header. Counting the entry being deleted and its
253 * CoEntry this adds up to as much as 1+1+39*3 = 119. If all these entries
254 * and the header are in separate Ubik buffers then 120 buffers may be
256 ubik_nBuffers = 120 + /*fudge*/40;
257 code = ubik_ServerInitByInfo(myHost, htons(AFSCONF_PROTPORT), &info,
258 &clones, pr_dbaseName, &dbase);
260 com_err (whoami, code, "Ubik init failed");
263 sc[0] = rxnull_NewServerSecurityObject();
266 sc[2] = rxkad_NewServerSecurityObject
267 (0, prdir, afsconf_GetKey, (char *)0);
271 /* Disable jumbograms */
274 tservice = rx_NewService(0,PRSRV,"Protection Server",sc,3,PR_ExecuteRequest);
275 if (tservice == (struct rx_service *)0) {
276 fprintf (stderr, "ptserver: Could not create new rx service.\n");
279 rx_SetMinProcs(tservice,2);
280 rx_SetMaxProcs(tservice,lwps);
282 tservice = rx_NewService(0,RX_STATS_SERVICE_ID,"rpcstats",sc,3,RXSTATS_ExecuteRequest);
283 if (tservice == (struct rx_service *)0) {
284 fprintf (stderr, "ptserver: Could not create new rx service.\n");
287 rx_SetMinProcs(tservice,2);
288 rx_SetMaxProcs(tservice,4);
290 /* allow super users to manage RX statistics */
291 rx_SetRxStatUserOk(pr_rxstat_userok);
294 osi_audit (PTS_FinishEvent, -1, AUD_END);