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 <afs/param.h>
15 #include <sys/types.h>
19 #include <WINNT/afsevent.h>
22 #include <netinet/in.h>
26 #include <rx/rx_globals.h>
29 #include <afs/cellconfig.h>
33 #include "error_macros.h"
34 #include "afs/audit.h"
35 #include <afs/afsutil.h>
38 /* make all of these into a structure if you want */
39 struct prheader cheader;
40 struct ubik_dbase *dbase;
41 struct afsconf_dir *prdir;
43 extern afs_int32 ubik_lastYesTime;
44 extern afs_int32 ubik_nBuffers;
46 extern int afsconf_ClientAuth();
47 extern int afsconf_ServerAuth();
48 extern int afsconf_CheckAuth();
53 #include "AFS_component_version_number.c"
55 /* check whether caller is authorized to manage RX statistics */
56 int pr_rxstat_userok(call)
59 return afsconf_SuperUser(prdir, call, (char *)0);
62 void main (argc, argv)
66 register afs_int32 code;
67 afs_int32 serverList[MAXSERVERS];
69 register struct hostent *th;
71 struct rx_service *tservice;
72 struct rx_securityClass *sc[3];
73 extern struct rx_securityClass *rxnull_NewServerSecurityObject();
74 extern struct rx_securityClass *rxkad_NewServerSecurityObject();
75 extern int RXSTATS_ExecuteRequest();
76 extern int PR_ExecuteRequest();
78 struct ktc_encryptionKey tkey;
80 struct afsconf_cell info;
81 int kerberosKeys; /* set if found some keys */
85 const char *pr_dbaseName;
86 char *whoami = "ptserver";
93 * The following signal action for AIX is necessary so that in case of a
94 * crash (i.e. core is generated) we can include the user's data section
95 * in the core dump. Unfortunately, by default, only a partial core is
96 * generated which, in many cases, isn't too useful.
100 sigemptyset(&nsa.sa_mask);
101 nsa.sa_handler = SIG_DFL;
102 nsa.sa_flags = SA_FULLDUMP;
103 sigaction(SIGABRT, &nsa, NULL);
104 sigaction(SIGSEGV, &nsa, NULL);
106 osi_audit (PTS_StartEvent, 0, AUD_END);
108 /* Initialize dirpaths */
109 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
111 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0],0);
113 fprintf(stderr,"%s: Unable to obtain AFS server directory.\n", argv[0]);
117 pr_dbaseName = AFSDIR_SERVER_PRDB_FILEPATH;
119 for (a=1; a<argc; a++) {
121 lcstring (arg, argv[a], sizeof(arg));
123 if ((strncmp (arg, "-database", alen) == 0) ||
124 (strncmp (arg, "-db", alen) == 0)) {
125 pr_dbaseName = argv[++a]; /* specify a database */
127 else if (strncmp(arg, "-p", alen) == 0) {
128 lwps = atoi(argv[++a]);
129 if (lwps > 16) { /* maximum of 16 */
130 printf("Warning: '-p %d' is too big; using %d instead\n",
133 } else if (lwps < 3) { /* minimum of 3 */
134 printf("Warning: '-p %d' is too small; using %d instead\n",
139 else if (strncmp (arg, "-rebuild", alen) == 0) /* rebuildDB++ */ ;
140 else if (strncmp (arg, "-enable_peer_stats", alen) == 0) {
141 rx_enablePeerRPCStats();
143 else if (strncmp (arg, "-enable_process_stats", alen) == 0) {
144 rx_enableProcessRPCStats();
146 else if (*arg == '-') {
149 /* hack in help flag support */
151 printf ("Usage: ptserver [-database <db path>] "
152 "[-p <number of processes>] [-rebuildDB] "
153 /* "[-enable_peer_stats] [-enable_process_stats] " */
161 OpenLog(AFSDIR_SERVER_PTLOG_FILEPATH); /* set up logging */
164 prdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
166 fprintf (stderr, "ptserver: can't open configuration directory.\n");
169 if (afsconf_GetNoAuthFlag(prdir))
170 printf ("ptserver: running unauthenticated\n");
173 /* initialize winsock */
174 if (afs_winsockInit()<0) {
175 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0,
178 fprintf(stderr, "ptserver: couldn't initialize winsock. \n");
183 gethostname(hostname,sizeof(hostname));
184 th = gethostbyname(hostname);
186 fprintf (stderr, "ptserver: couldn't get address of this host.\n");
189 bcopy(th->h_addr,&myHost,sizeof(afs_int32));
191 /* get list of servers */
192 code = afsconf_GetCellInfo(prdir,(char *)0,"afsprot",&info);
194 com_err (whoami, code, "Couldn't get server list");
197 pr_realmName = info.name;
198 pr_realmNameLen = strlen (pr_realmName);
200 for (i=0,j=0;i<info.numServers;i++)
201 if (info.hostAddr[i].sin_addr.s_addr != myHost) /* ubik already tacks myHost onto list */
202 serverList[j++] = info.hostAddr[i].sin_addr.s_addr;
207 code = afsconf_GetKey(prdir,999,&tkey);
209 com_err (whoami, code, "couldn't get bcrypt keys from key file, ignoring.");
212 { afs_int32 kvno; /* see if there is a KeyFile here */
213 struct ktc_encryptionKey key;
214 code = afsconf_GetLatestKey (prdir, &kvno, &key);
215 kerberosKeys = (code == 0);
217 printf ("ptserver: can't find any Kerberos keys, code = %d, ignoring\n", code);
220 /* initialize ubik */
221 ubik_CRXSecurityProc = afsconf_ClientAuth;
222 ubik_CRXSecurityRock = (char *)prdir;
223 ubik_SRXSecurityProc = afsconf_ServerAuth;
224 ubik_SRXSecurityRock = (char *)prdir;
225 ubik_CheckRXSecurityProc = afsconf_CheckAuth;
226 ubik_CheckRXSecurityRock = (char *)prdir;
228 /* The max needed is when deleting an entry. A full CoEntry deletion
229 * required removal from 39 entries. Each of which may refers to the entry
230 * being deleted in one of its CoEntries. If a CoEntry is freed its
231 * predecessor CoEntry will be modified as well. Any freed blocks also
232 * modifies the database header. Counting the entry being deleted and its
233 * CoEntry this adds up to as much as 1+1+39*3 = 119. If all these entries
234 * and the header are in separate Ubik buffers then 120 buffers may be
236 ubik_nBuffers = 120 + /*fudge*/40;
237 code = ubik_ServerInit(myHost, htons(AFSCONF_PROTPORT), serverList,
238 pr_dbaseName, &dbase);
240 com_err (whoami, code, "Ubik init failed");
243 sc[0] = rxnull_NewServerSecurityObject();
246 extern int afsconf_GetKey();
247 sc[2] = rxkad_NewServerSecurityObject
248 (0, prdir, afsconf_GetKey, (char *)0);
252 /* These two lines disallow jumbograms */
253 rx_maxReceiveSize = OLD_MAX_PACKET_SIZE;
254 rxi_nSendFrags = rxi_nRecvFrags = 1;
256 tservice = rx_NewService(0,PRSRV,"Protection Server",sc,3,PR_ExecuteRequest);
257 if (tservice == (struct rx_service *)0) {
258 fprintf (stderr, "ptserver: Could not create new rx service.\n");
261 rx_SetMinProcs(tservice,2);
262 rx_SetMaxProcs(tservice,lwps);
264 tservice = rx_NewService(0,RX_STATS_SERVICE_ID,"rpcstats",sc,3,RXSTATS_ExecuteRequest);
265 if (tservice == (struct rx_service *)0) {
266 fprintf (stderr, "ptserver: Could not create new rx service.\n");
269 rx_SetMinProcs(tservice,2);
270 rx_SetMaxProcs(tservice,4);
272 /* allow super users to manage RX statistics */
273 rx_SetRxStatUserOk(pr_rxstat_userok);
276 osi_audit (PTS_FinishEvent, -1, AUD_END);