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(rock, kvno, key)
43 OUT struct ktc_encryptionKey *key;
45 struct serverParms *parms = (struct serverParms *)rock;
46 struct afsconf_keys tstr;
50 fprintf(stderr, "GetKey called for kvno %d\n", kvno);
51 if (!parms->keyfile) {
52 memcpy(key, &serviceKey, sizeof(*key));
56 /* the rest of this function borrows heavily from auth/cellconfig.c */
57 fd = open(parms->keyfile, O_RDONLY);
59 return AFSCONF_FAILURE;
61 code = read(fd, &tstr, sizeof(struct afsconf_keys));
63 if (code < sizeof(afs_int32)) {
64 return AFSCONF_FAILURE;
67 /* convert key structure to host order */
68 tstr.nkeys = ntohl(tstr.nkeys);
69 for (fd = 0; fd < tstr.nkeys; fd++) {
70 if (kvno == ntohl(tstr.key[fd].kvno)) {
71 memcpy(key, tstr.key[fd].key, sizeof(*key));
76 return AFSCONF_NOTFOUND;
82 rxkst_StartServer(parms)
83 INOUT struct serverParms *parms;
85 extern int rx_stackSize;
86 struct rx_service *tservice;
87 struct rx_securityClass *sc[3];
90 minAuth = parms->authentication;
92 minLevel = rxkad_clear;
96 sc[0] = rxnull_NewServerSecurityObject();
97 sc[1] = 0; /* no rxvab anymore */
98 sc[2] = rxkad_NewServerSecurityObject(minLevel, (void *)parms, GetKey, 0);
100 rx_NewService(htons(RXKST_SERVICEPORT), RXKST_SERVICEID,
101 "stress test", sc, 3, RXKST_ExecuteRequest);
102 if (tservice == (struct rx_service *)0) {
103 fprintf(stderr, "Could not create stress test rx service\n");
106 rx_SetMinProcs(tservice, parms->threads);
107 rx_SetMaxProcs(tservice, parms->threads);
108 rx_SetStackSize(tservice, 10000);
110 rx_StartServer( /*donate me */ 1); /* start handling req. of all types */
115 static char test_client_name[MAXKTCNAMELEN];
116 static char test_client_inst[MAXKTCNAMELEN];
117 static char test_client_cell[MAXKTCREALMLEN];
118 static int got_client_id = 0;
121 IN struct rx_call *call;
126 char name[MAXKTCNAMELEN];
127 char inst[MAXKTCNAMELEN];
128 char cell[MAXKTCREALMLEN];
130 u_long expiration; /* checked by Security Module */
132 si = rx_SecurityClassOf(rx_ConnectionOf(call));
134 printf("No support for VAB security module.\n");
136 } else if (si == 0) {
141 } else if (si != 2) {
142 fprintf(stderr, "Unknown security index %d\n", si);
147 rxkad_GetServerInfo(rx_ConnectionOf(call), &level, &expiration, name,
153 fprintf(stderr, "Test client is %s.%s@%s\n", name, inst, cell);
155 if (strcmp(name, test_client_name))
156 return RXKST_BADCLIENT;
157 if (strcmp(inst, test_client_inst))
158 return RXKST_BADCLIENT;
159 if (strcmp(cell, test_client_cell))
160 return RXKST_BADCLIENT;
162 strcpy(test_client_name, name);
163 strcpy(test_client_inst, inst);
164 strcpy(test_client_cell, cell);
170 /* Stop the server. There isn't a graceful way to do this so just exit. */
174 IN struct rx_call *call;
177 code = CheckAuth(call);
181 /* This is tricky, but since we're never going to return, we end the call
182 * here, then rx_Finalize should push out the response/ack. */
186 printf("Server halted by RPC request.\n");
192 SRXKST_Fast(call, n, inc_nP)
193 IN struct rx_call *call;
202 SRXKST_Slow(call, tag, nowP)
203 IN struct rx_call *call;
208 code = CheckAuth(call);
211 #ifdef AFS_PTHREAD_ENV
220 #define COPBUFSIZE 10000
221 static struct buflist {
222 struct buflist *next;
224 static int bufAllocs = 0;
231 ret = (u_char *) buflist;
232 buflist = buflist->next;
234 ret = (u_char *) osi_Alloc(COPBUFSIZE);
244 struct buflist *bl = (struct buflist *)b;
250 SRXKST_Copious(call, inlen, insum, outlen, outsum)
251 IN struct rx_call *call;
262 long bytesTransfered;
265 code = CheckAuth(call);
271 while (bytesTransfered < inlen) {
272 u_long tlen; /* how much more to do */
273 tlen = inlen - bytesTransfered;
274 if (tlen > COPBUFSIZE)
276 n = rx_Read(call, buf, tlen);
281 code = RXKST_READSHORT;
284 for (i = 0; i < tlen; i++)
286 bytesTransfered += tlen;
290 if (mysum != insum) {
291 code = RXKST_BADINPUTSUM;
294 #define BIG_PRIME 1257056893 /* 0x4AED2A7d */
296 #define NextByte() ((b>24 ? ((seed = seed*BIG_PRIME + BIG_PRIME),b=0) : 0), \
297 (b +=8), ((seed >> (b-8))&0xff))
299 #define NextByte() (b+=3)
305 while (bytesTransfered < outlen) {
306 u_long tlen; /* how much more to do */
307 tlen = outlen - bytesTransfered;
308 if (tlen > COPBUFSIZE)
310 for (i = 0; i < tlen; i++)
311 mysum += (buf[i] = NextByte());
312 n = rx_Write(call, buf, tlen);
317 code = RXKST_WRITESHORT;
320 bytesTransfered += tlen;