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 /* Test of the ktc_*Token() routines */
17 #include <afs/param.h>
19 #include <afs/afsutil.h>
22 extern int ktc_SetToken(struct ktc_principal *aserver,
23 struct ktc_token *atoken,
24 struct ktc_principal *aclient,
27 extern int ktc_GetToken(struct ktc_principal *aserver,
28 struct ktc_token *atoken,
30 struct ktc_principal *aclient);
32 extern int ktc_ListTokens(int aprevIndex,
33 int* aindex, struct ktc_principal *aserver);
35 extern int ktc_ForgetAllTokens(void);
38 static int SamePrincipal(struct ktc_principal *p1, struct ktc_principal *p2);
39 static int SameToken(struct ktc_token *t1, struct ktc_token *t2);
46 struct ktc_principal oldServer[MAXCELLS], newServer[MAXCELLS];
47 struct ktc_principal oldClient[MAXCELLS], newClient[MAXCELLS];
48 struct ktc_token oldToken[MAXCELLS], newToken[MAXCELLS];
49 int cellCount, cellIndex;
53 /* Initialize winsock; required by NT pioctl() */
54 if (afs_winsockInit()) {
55 printf("\nUnable to initialize winsock (required by NT pioctl()).\n");
60 /* Get original tokens */
62 printf("\nFetching original tokens.\n");
66 for (i = 0; i < MAXCELLS; i++) {
67 /* fetch server principal */
68 code = ktc_ListTokens(cellIndex, &cellIndex, &oldServer[i]);
71 if (code == KTC_NOENT) {
75 /* some error occured */
76 perror("ktc_ListTokens failed fetching original tokens");
81 /* fetch token and client identity w.r.t. server */
82 code = ktc_GetToken(&oldServer[i],
83 &oldToken[i], sizeof(struct ktc_token),
87 /* some unexpected error occured */
88 perror("ktc_GetToken failed fetching original tokens");
96 printf("Obtain one or more tokens prior to executing test.\n");
98 } else if (cellCount == MAXCELLS) {
99 printf("Only first %d tokens utilized by test; rest will be lost.\n",
103 for (i = 0; i < cellCount; i++) {
104 printf("Token[%d]: server = %s@%s, client = %s@%s\n", i,
105 oldServer[i].name, oldServer[i].cell,
106 oldClient[i].name, oldClient[i].cell);
110 /* Forget original tokens */
112 printf("\nClearing original tokens and verifying disposal.\n");
114 code = ktc_ForgetAllTokens();
117 perror("ktc_ForgetAllTokens failed on original tokens");
121 for (i = 0; i < cellCount; i++) {
122 struct ktc_principal dummyPrincipal;
123 struct ktc_token dummyToken;
125 code = ktc_GetToken(&oldServer[i],
126 &dummyToken, sizeof(struct ktc_token),
129 if (code != KTC_NOENT) {
130 printf("ktc_ForgetAllTokens did not eliminate all tokens.\n");
136 code = ktc_ListTokens(cellIndex, &cellIndex, &dummyPrincipal);
138 if (code != KTC_NOENT) {
139 printf("ktc_ForgetAllTokens did not eliminate all tokens.\n");
145 /* Reinstall tokens */
147 printf("\nReinstalling original tokens.\n");
149 for (i = 0; i < cellCount; i++) {
150 code = ktc_SetToken(&oldServer[i], &oldToken[i], &oldClient[i], 0);
153 perror("ktc_SetToken failed reinstalling tokens");
159 /* Get reinstalled tokens */
161 printf("\nFetching reinstalled tokens.\n");
165 for (i = 0; i < MAXCELLS; i++) {
166 /* fetch server principal */
167 code = ktc_ListTokens(cellIndex, &cellIndex, &newServer[i]);
170 if (code == KTC_NOENT) {
174 /* some error occured */
175 perror("ktc_ListTokens failed fetching reinstalled tokens");
180 /* fetch token and client identity w.r.t. server */
181 code = ktc_GetToken(&newServer[i],
182 &newToken[i], sizeof(struct ktc_token),
186 /* some unexpected error occured */
187 perror("ktc_GetToken failed fetching reinstalled tokens");
193 /* Verify content of reinstalled tokens */
195 printf("\nVerifying reinstalled tokens against original tokens.\n");
197 if (i != cellCount) {
198 printf("Reinstalled token count does not match original count.\n");
202 for (i = 0; i < cellCount; i++) {
206 for (k = 0; k < cellCount; k++) {
207 if (SamePrincipal(&oldServer[i], &newServer[k]) &&
208 SamePrincipal(&oldClient[i], &newClient[k]) &&
209 SameToken(&oldToken[i], &newToken[k])) {
210 /* found a matching token */
217 printf("Reinstalled token does not match any original token.\n");
224 printf("\nTest completed without error.\n");
230 SamePrincipal(struct ktc_principal *p1, struct ktc_principal *p2)
232 if (strcmp(p1->name, p2->name) ||
233 strcmp(p1->instance, p2->instance) ||
234 strcmp(p1->cell, p2->cell)) {
235 /* principals do not match */
245 SameToken(struct ktc_token *t1, struct ktc_token *t2)
247 if ((t1->startTime != t2->startTime) ||
248 (t1->endTime != t2->endTime) ||
249 memcmp(&t1->sessionKey, &t2->sessionKey, sizeof(t1->sessionKey)) ||
250 (t1->kvno != t2->kvno) ||
251 (t1->ticketLen != t2->ticketLen) ||
252 memcmp(t1->ticket, t2->ticket, t1->ticketLen)) {
253 /* tokens do not match */