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 /* RX Authentication Stress test: server side code. */
12 #include <afsconfig.h>
13 #include <afs/param.h>
19 #include <sys/types.h>
23 #include <netinet/in.h>
25 #include <rx/rx_null.h>
30 #include <afs/cellconfig.h>
33 #include "stress_internal.h"
35 struct ktc_encryptionKey serviceKey =
36 { { 0x45, 0xe3, 0x3d, 0x16, 0x29, 0x64, 0x8a, 0x8f } };
37 long serviceKeyVersion = 7;
40 GetKey(void *rock, int kvno, struct ktc_encryptionKey *key)
42 struct serverParms *parms = (struct serverParms *)rock;
43 struct afsconf_keys tstr;
47 fprintf(stderr, "GetKey called for kvno %d\n", kvno);
48 if (!parms->keyfile) {
49 memcpy(key, &serviceKey, sizeof(*key));
53 /* the rest of this function borrows heavily from auth/cellconfig.c */
54 fd = open(parms->keyfile, O_RDONLY);
56 return AFSCONF_FAILURE;
58 code = read(fd, &tstr, sizeof(struct afsconf_keys));
60 if (code < sizeof(afs_int32)) {
61 return AFSCONF_FAILURE;
64 /* convert key structure to host order */
65 tstr.nkeys = ntohl(tstr.nkeys);
66 for (fd = 0; fd < tstr.nkeys; fd++) {
67 if (kvno == ntohl(tstr.key[fd].kvno)) {
68 memcpy(key, tstr.key[fd].key, sizeof(*key));
73 return AFSCONF_NOTFOUND;
79 rxkst_StartServer(void * rock)
81 struct serverParms *parms = rock;
82 extern int rx_stackSize;
83 struct rx_service *tservice;
84 struct rx_securityClass *sc[3];
87 minAuth = parms->authentication;
89 minLevel = rxkad_clear;
93 sc[0] = rxnull_NewServerSecurityObject();
94 sc[1] = 0; /* no rxvab anymore */
95 sc[2] = rxkad_NewServerSecurityObject(minLevel, (void *)parms, GetKey, 0);
97 rx_NewService(htons(RXKST_SERVICEPORT), RXKST_SERVICEID,
98 "stress test", sc, 3, RXKST_ExecuteRequest);
99 if (tservice == (struct rx_service *)0) {
100 fprintf(stderr, "Could not create stress test rx service\n");
103 rx_SetMinProcs(tservice, parms->threads);
104 rx_SetMaxProcs(tservice, parms->threads);
105 rx_SetStackSize(tservice, 10000);
107 rx_StartServer( /*donate me */ 1); /* start handling req. of all types */
112 static char test_client_name[MAXKTCNAMELEN];
113 static char test_client_inst[MAXKTCNAMELEN];
114 static char test_client_cell[MAXKTCREALMLEN];
115 static int got_client_id = 0;
117 CheckAuth(struct rx_call *call)
122 char name[MAXKTCNAMELEN];
123 char inst[MAXKTCNAMELEN];
124 char cell[MAXKTCREALMLEN];
126 unsigned int expiration; /* checked by Security Module */
128 si = rx_SecurityClassOf(rx_ConnectionOf(call));
129 if (si == RX_SECIDX_VAB) {
130 printf("No support for VAB security module.\n");
132 } else if (si == RX_SECIDX_NULL) {
137 } else if (si != RX_SECIDX_KAD) {
138 fprintf(stderr, "Unknown security index %d\n", si);
143 rxkad_GetServerInfo(rx_ConnectionOf(call), &level, &expiration, name,
149 fprintf(stderr, "Test client is %s.%s@%s\n", name, inst, cell);
151 if (strcmp(name, test_client_name))
152 return RXKST_BADCLIENT;
153 if (strcmp(inst, test_client_inst))
154 return RXKST_BADCLIENT;
155 if (strcmp(cell, test_client_cell))
156 return RXKST_BADCLIENT;
158 strcpy(test_client_name, name);
159 strcpy(test_client_inst, inst);
160 strcpy(test_client_cell, cell);
166 /* Stop the server. There isn't a graceful way to do this so just exit. */
169 SRXKST_Kill(struct rx_call *call)
172 code = CheckAuth(call);
176 /* This is tricky, but since we're never going to return, we end the call
177 * here, then rx_Finalize should push out the response/ack. */
181 printf("Server halted by RPC request.\n");
187 SRXKST_Fast(struct rx_call *call, u_long n, u_long *inc_nP)
194 SRXKST_Slow(struct rx_call *call, u_long tag, u_long *nowP)
198 code = CheckAuth(call);
201 #ifdef AFS_PTHREAD_ENV
211 #define COPBUFSIZE 10000
212 static struct buflist {
213 struct buflist *next;
215 static int bufAllocs = 0;
222 ret = (char *) buflist;
223 buflist = buflist->next;
225 ret = osi_Alloc(COPBUFSIZE);
234 struct buflist *bl = (struct buflist *)b;
240 SRXKST_Copious(struct rx_call *call, u_long inlen, u_long insum,
241 u_long outlen, u_long *outsum)
248 long bytesTransfered;
251 code = CheckAuth(call);
257 while (bytesTransfered < inlen) {
258 u_long tlen; /* how much more to do */
259 tlen = inlen - bytesTransfered;
260 if (tlen > COPBUFSIZE)
262 n = rx_Read(call, buf, tlen);
267 code = RXKST_READSHORT;
270 for (i = 0; i < tlen; i++)
272 bytesTransfered += tlen;
276 if (mysum != insum) {
277 code = RXKST_BADINPUTSUM;
280 #define BIG_PRIME 1257056893 /* 0x4AED2A7d */
282 #define NextByte() ((b>24 ? ((seed = seed*BIG_PRIME + BIG_PRIME),b=0) : 0), \
283 (b +=8), ((seed >> (b-8))&0xff))
285 #define NextByte() (b+=3)
291 while (bytesTransfered < outlen) {
292 u_long tlen; /* how much more to do */
293 tlen = outlen - bytesTransfered;
294 if (tlen > COPBUFSIZE)
296 for (i = 0; i < tlen; i++)
297 mysum += (buf[i] = NextByte());
298 n = rx_Write(call, buf, tlen);
303 code = RXKST_WRITESHORT;
306 bytesTransfered += tlen;