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>
30 #include <rx/rx_globals.h>
33 #include <afs/cellconfig.h>
37 #include "error_macros.h"
38 #include "afs/audit.h"
39 #include <afs/afsutil.h>
42 /* make all of these into a structure if you want */
43 struct prheader cheader;
44 struct ubik_dbase *dbase;
45 struct afsconf_dir *prdir;
47 extern afs_int32 ubik_lastYesTime;
48 extern afs_int32 ubik_nBuffers;
50 extern int afsconf_ServerAuth();
51 extern int afsconf_CheckAuth();
56 #include "AFS_component_version_number.c"
58 /* check whether caller is authorized to manage RX statistics */
59 int pr_rxstat_userok(call)
62 return afsconf_SuperUser(prdir, call, (char *)0);
65 void main (argc, argv)
69 register afs_int32 code;
71 register struct hostent *th;
73 struct rx_service *tservice;
74 struct rx_securityClass *sc[3];
75 extern struct rx_securityClass *rxnull_NewServerSecurityObject();
76 extern struct rx_securityClass *rxkad_NewServerSecurityObject();
77 extern int RXSTATS_ExecuteRequest();
78 extern int PR_ExecuteRequest();
80 struct ktc_encryptionKey tkey;
82 struct afsconf_cell info;
83 int kerberosKeys; /* set if found some keys */
85 char clones[MAXHOSTSPERCELL];
87 const char *pr_dbaseName;
88 char *whoami = "ptserver";
95 * The following signal action for AIX is necessary so that in case of a
96 * crash (i.e. core is generated) we can include the user's data section
97 * in the core dump. Unfortunately, by default, only a partial core is
98 * generated which, in many cases, isn't too useful.
100 struct sigaction nsa;
102 sigemptyset(&nsa.sa_mask);
103 nsa.sa_handler = SIG_DFL;
104 nsa.sa_flags = SA_FULLDUMP;
105 sigaction(SIGABRT, &nsa, NULL);
106 sigaction(SIGSEGV, &nsa, NULL);
108 osi_audit (PTS_StartEvent, 0, AUD_END);
110 /* Initialize dirpaths */
111 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
113 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0],0);
115 fprintf(stderr,"%s: Unable to obtain AFS server directory.\n", argv[0]);
119 pr_dbaseName = AFSDIR_SERVER_PRDB_FILEPATH;
121 for (a=1; a<argc; a++) {
123 lcstring (arg, argv[a], sizeof(arg));
125 if ((strncmp (arg, "-database", alen) == 0) ||
126 (strncmp (arg, "-db", alen) == 0)) {
127 pr_dbaseName = argv[++a]; /* specify a database */
129 else if (strncmp(arg, "-p", alen) == 0) {
130 lwps = atoi(argv[++a]);
131 if (lwps > 16) { /* maximum of 16 */
132 printf("Warning: '-p %d' is too big; using %d instead\n",
135 } else if (lwps < 3) { /* minimum of 3 */
136 printf("Warning: '-p %d' is too small; using %d instead\n",
141 else if (strncmp (arg, "-rebuild", alen) == 0) /* rebuildDB++ */ ;
142 else if (strncmp (arg, "-enable_peer_stats", alen) == 0) {
143 rx_enablePeerRPCStats();
145 else if (strncmp (arg, "-enable_process_stats", alen) == 0) {
146 rx_enableProcessRPCStats();
149 else if (strncmp(arg, "-syslog", alen)==0) {
150 /* set syslog logging flag */
153 else if (strncmp(arg, "-syslog=", MIN(8,alen))==0) {
155 serverLogSyslogFacility = atoi(arg+8);
158 else if (*arg == '-') {
159 /* hack in help flag support */
162 printf ("Usage: ptserver [-database <db path>] "
163 "[-syslog[=FACILITY]] "
164 "[-p <number of processes>] [-rebuild] "
165 "[-enable_peer_stats] [-enable_process_stats] "
168 printf ("Usage: ptserver [-database <db path>] "
169 "[-p <number of processes>] [-rebuild] "
178 OpenLog(AFSDIR_SERVER_PTLOG_FILEPATH); /* set up logging */
181 prdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
183 fprintf (stderr, "ptserver: can't open configuration directory.\n");
186 if (afsconf_GetNoAuthFlag(prdir))
187 printf ("ptserver: running unauthenticated\n");
190 /* initialize winsock */
191 if (afs_winsockInit()<0) {
192 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0,
195 fprintf(stderr, "ptserver: couldn't initialize winsock. \n");
200 gethostname(hostname,sizeof(hostname));
201 th = gethostbyname(hostname);
203 fprintf (stderr, "ptserver: couldn't get address of this host.\n");
206 memcpy(&myHost, th->h_addr, sizeof(afs_int32));
208 /* get list of servers */
209 code = afsconf_GetExtendedCellInfo(prdir,(char *)0,"afsprot",
212 com_err (whoami, code, "Couldn't get server list");
215 pr_realmName = info.name;
216 pr_realmNameLen = strlen (pr_realmName);
220 code = afsconf_GetKey(prdir,999,&tkey);
222 com_err (whoami, code, "couldn't get bcrypt keys from key file, ignoring.");
225 { afs_int32 kvno; /* see if there is a KeyFile here */
226 struct ktc_encryptionKey key;
227 code = afsconf_GetLatestKey (prdir, &kvno, &key);
228 kerberosKeys = (code == 0);
230 printf ("ptserver: can't find any Kerberos keys, code = %d, ignoring\n", code);
233 /* initialize ubik */
234 ubik_CRXSecurityProc = afsconf_ClientAuth;
235 ubik_CRXSecurityRock = (char *)prdir;
236 ubik_SRXSecurityProc = afsconf_ServerAuth;
237 ubik_SRXSecurityRock = (char *)prdir;
238 ubik_CheckRXSecurityProc = afsconf_CheckAuth;
239 ubik_CheckRXSecurityRock = (char *)prdir;
241 /* The max needed is when deleting an entry. A full CoEntry deletion
242 * required removal from 39 entries. Each of which may refers to the entry
243 * being deleted in one of its CoEntries. If a CoEntry is freed its
244 * predecessor CoEntry will be modified as well. Any freed blocks also
245 * modifies the database header. Counting the entry being deleted and its
246 * CoEntry this adds up to as much as 1+1+39*3 = 119. If all these entries
247 * and the header are in separate Ubik buffers then 120 buffers may be
249 ubik_nBuffers = 120 + /*fudge*/40;
250 code = ubik_ServerInitByInfo(myHost, htons(AFSCONF_PROTPORT), &info,
251 &clones, pr_dbaseName, &dbase);
253 com_err (whoami, code, "Ubik init failed");
256 sc[0] = rxnull_NewServerSecurityObject();
259 sc[2] = rxkad_NewServerSecurityObject
260 (0, prdir, afsconf_GetKey, (char *)0);
264 /* These two lines disallow jumbograms */
265 rx_maxReceiveSize = OLD_MAX_PACKET_SIZE;
266 rxi_nSendFrags = rxi_nRecvFrags = 1;
268 tservice = rx_NewService(0,PRSRV,"Protection Server",sc,3,PR_ExecuteRequest);
269 if (tservice == (struct rx_service *)0) {
270 fprintf (stderr, "ptserver: Could not create new rx service.\n");
273 rx_SetMinProcs(tservice,2);
274 rx_SetMaxProcs(tservice,lwps);
276 tservice = rx_NewService(0,RX_STATS_SERVICE_ID,"rpcstats",sc,3,RXSTATS_ExecuteRequest);
277 if (tservice == (struct rx_service *)0) {
278 fprintf (stderr, "ptserver: Could not create new rx service.\n");
281 rx_SetMinProcs(tservice,2);
282 rx_SetMaxProcs(tservice,4);
284 /* allow super users to manage RX statistics */
285 rx_SetRxStatUserOk(pr_rxstat_userok);
288 osi_audit (PTS_FinishEvent, -1, AUD_END);