1 /* Copyright (C) 1990, 1998 Transarc Corporation - All rights reserved */
3 * (C) COPYRIGHT IBM CORPORATION 1988
4 * LICENSED MATERIALS - PROPERTY OF IBM
12 #include <sys/types.h>
16 #include <WINNT/afsevent.h>
19 #include <netinet/in.h>
23 #include <rx/rx_globals.h>
26 #include <afs/cellconfig.h>
30 #include "error_macros.h"
31 #include "afs/audit.h"
32 #include <afs/afsutil.h>
35 /* make all of these into a structure if you want */
36 struct prheader cheader;
37 struct ubik_dbase *dbase;
38 struct afsconf_dir *prdir;
40 extern afs_int32 ubik_lastYesTime;
41 extern afs_int32 ubik_nBuffers;
43 extern int afsconf_ClientAuth();
44 extern int afsconf_ServerAuth();
45 extern int afsconf_CheckAuth();
50 #include "AFS_component_version_number.c"
52 /* check whether caller is authorized to manage RX statistics */
53 int pr_rxstat_userok(call)
56 return afsconf_SuperUser(prdir, call, (char *)0);
59 void main (argc, argv)
63 register afs_int32 code;
64 afs_int32 serverList[MAXSERVERS];
66 register struct hostent *th;
68 struct rx_service *tservice;
69 struct rx_securityClass *sc[3];
70 extern struct rx_securityClass *rxnull_NewServerSecurityObject();
71 extern struct rx_securityClass *rxkad_NewServerSecurityObject();
72 extern int RXSTATS_ExecuteRequest();
73 extern int PR_ExecuteRequest();
75 struct ktc_encryptionKey tkey;
77 struct afsconf_cell info;
78 int kerberosKeys; /* set if found some keys */
82 const char *pr_dbaseName;
83 char *whoami = "ptserver";
90 * The following signal action for AIX is necessary so that in case of a
91 * crash (i.e. core is generated) we can include the user's data section
92 * in the core dump. Unfortunately, by default, only a partial core is
93 * generated which, in many cases, isn't too useful.
97 sigemptyset(&nsa.sa_mask);
98 nsa.sa_handler = SIG_DFL;
99 nsa.sa_flags = SA_FULLDUMP;
100 sigaction(SIGABRT, &nsa, NULL);
101 sigaction(SIGSEGV, &nsa, NULL);
103 osi_audit (PTS_StartEvent, 0, AUD_END);
105 /* Initialize dirpaths */
106 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
108 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0],0);
110 fprintf(stderr,"%s: Unable to obtain AFS server directory.\n", argv[0]);
114 pr_dbaseName = AFSDIR_SERVER_PRDB_FILEPATH;
116 for (a=1; a<argc; a++) {
118 lcstring (arg, argv[a], sizeof(arg));
120 if ((strncmp (arg, "-database", alen) == 0) ||
121 (strncmp (arg, "-db", alen) == 0)) {
122 pr_dbaseName = argv[++a]; /* specify a database */
124 else if (strncmp(arg, "-p", alen) == 0) {
125 lwps = atoi(argv[++a]);
126 if (lwps > 16) { /* maximum of 16 */
127 printf("Warning: '-p %d' is too big; using %d instead\n",
130 } else if (lwps < 3) { /* minimum of 3 */
131 printf("Warning: '-p %d' is too small; using %d instead\n",
136 else if (strncmp (arg, "-rebuild", alen) == 0) /* rebuildDB++ */ ;
137 else if (strncmp (arg, "-enable_peer_stats", alen) == 0) {
138 rx_enablePeerRPCStats();
140 else if (strncmp (arg, "-enable_process_stats", alen) == 0) {
141 rx_enableProcessRPCStats();
143 else if (*arg == '-') {
146 /* hack in help flag support */
148 printf ("Usage: ptserver [-database <db path>] "
149 "[-p <number of processes>] [-rebuildDB] "
150 /* "[-enable_peer_stats] [-enable_process_stats] " */
158 OpenLog(AFSDIR_SERVER_PTLOG_FILEPATH); /* set up logging */
161 prdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
163 fprintf (stderr, "ptserver: can't open configuration directory.\n");
166 if (afsconf_GetNoAuthFlag(prdir))
167 printf ("ptserver: running unauthenticated\n");
170 /* initialize winsock */
171 if (afs_winsockInit()<0) {
172 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0,
175 fprintf(stderr, "ptserver: couldn't initialize winsock. \n");
180 gethostname(hostname,sizeof(hostname));
181 th = gethostbyname(hostname);
183 fprintf (stderr, "ptserver: couldn't get address of this host.\n");
186 bcopy(th->h_addr,&myHost,sizeof(afs_int32));
188 /* get list of servers */
189 code = afsconf_GetCellInfo(prdir,(char *)0,"afsprot",&info);
191 com_err (whoami, code, "Couldn't get server list");
194 pr_realmName = info.name;
195 pr_realmNameLen = strlen (pr_realmName);
197 for (i=0,j=0;i<info.numServers;i++)
198 if (info.hostAddr[i].sin_addr.s_addr != myHost) /* ubik already tacks myHost onto list */
199 serverList[j++] = info.hostAddr[i].sin_addr.s_addr;
204 code = afsconf_GetKey(prdir,999,&tkey);
206 com_err (whoami, code, "couldn't get bcrypt keys from key file, ignoring.");
209 { afs_int32 kvno; /* see if there is a KeyFile here */
210 struct ktc_encryptionKey key;
211 code = afsconf_GetLatestKey (prdir, &kvno, &key);
212 kerberosKeys = (code == 0);
214 printf ("ptserver: can't find any Kerberos keys, code = %d, ignoring\n", code);
217 /* initialize ubik */
218 ubik_CRXSecurityProc = afsconf_ClientAuth;
219 ubik_CRXSecurityRock = (char *)prdir;
220 ubik_SRXSecurityProc = afsconf_ServerAuth;
221 ubik_SRXSecurityRock = (char *)prdir;
222 ubik_CheckRXSecurityProc = afsconf_CheckAuth;
223 ubik_CheckRXSecurityRock = (char *)prdir;
225 /* The max needed is when deleting an entry. A full CoEntry deletion
226 * required removal from 39 entries. Each of which may refers to the entry
227 * being deleted in one of its CoEntries. If a CoEntry is freed its
228 * predecessor CoEntry will be modified as well. Any freed blocks also
229 * modifies the database header. Counting the entry being deleted and its
230 * CoEntry this adds up to as much as 1+1+39*3 = 119. If all these entries
231 * and the header are in separate Ubik buffers then 120 buffers may be
233 ubik_nBuffers = 120 + /*fudge*/40;
234 code = ubik_ServerInit(myHost, htons(AFSCONF_PROTPORT), serverList,
235 pr_dbaseName, &dbase);
237 com_err (whoami, code, "Ubik init failed");
240 sc[0] = rxnull_NewServerSecurityObject();
243 extern int afsconf_GetKey();
244 sc[2] = rxkad_NewServerSecurityObject
245 (0, prdir, afsconf_GetKey, (char *)0);
249 /* These two lines disallow jumbograms */
250 rx_maxReceiveSize = OLD_MAX_PACKET_SIZE;
251 rxi_nSendFrags = rxi_nRecvFrags = 1;
253 tservice = rx_NewService(0,PRSRV,"Protection Server",sc,3,PR_ExecuteRequest);
254 if (tservice == (struct rx_service *)0) {
255 fprintf (stderr, "ptserver: Could not create new rx service.\n");
258 rx_SetMinProcs(tservice,2);
259 rx_SetMaxProcs(tservice,lwps);
261 tservice = rx_NewService(0,RX_STATS_SERVICE_ID,"rpcstats",sc,3,RXSTATS_ExecuteRequest);
262 if (tservice == (struct rx_service *)0) {
263 fprintf (stderr, "ptserver: Could not create new rx service.\n");
266 rx_SetMinProcs(tservice,2);
267 rx_SetMaxProcs(tservice,4);
269 /* allow super users to manage RX statistics */
270 rx_SetRxStatUserOk(pr_rxstat_userok);
273 osi_audit (PTS_FinishEvent, -1, AUD_END);