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 <afsconfig.h>
18 #include <afs/param.h>
24 #include <afs/afsutil.h>
27 extern int ktc_SetToken(struct ktc_principal *aserver,
28 struct ktc_token *atoken,
29 struct ktc_principal *aclient, int flags);
31 extern int ktc_GetToken(struct ktc_principal *aserver,
32 struct ktc_token *atoken, int atokenLen,
33 struct ktc_principal *aclient);
35 extern int ktc_ListTokens(int aprevIndex, int *aindex,
36 struct ktc_principal *aserver);
38 extern int ktc_ForgetAllTokens(void);
41 static int SamePrincipal(struct ktc_principal *p1, struct ktc_principal *p2);
42 static int SameToken(struct ktc_token *t1, struct ktc_token *t2);
50 struct ktc_principal oldServer[MAXCELLS], newServer[MAXCELLS];
51 struct ktc_principal oldClient[MAXCELLS], newClient[MAXCELLS];
52 struct ktc_token oldToken[MAXCELLS], newToken[MAXCELLS];
53 int cellCount, cellIndex;
57 /* Initialize winsock; required by NT pioctl() */
58 if (afs_winsockInit()) {
59 printf("\nUnable to initialize winsock (required by NT pioctl()).\n");
64 /* Get original tokens */
66 printf("\nFetching original tokens.\n");
70 for (i = 0; i < MAXCELLS; i++) {
71 /* fetch server principal */
72 code = ktc_ListTokens(cellIndex, &cellIndex, &oldServer[i]);
75 if (code == KTC_NOENT) {
79 /* some error occured */
80 perror("ktc_ListTokens failed fetching original tokens");
85 /* fetch token and client identity w.r.t. server */
87 ktc_GetToken(&oldServer[i], &oldToken[i],
88 sizeof(struct ktc_token), &oldClient[i]);
91 /* some unexpected error occured */
92 perror("ktc_GetToken failed fetching original tokens");
100 printf("Obtain one or more tokens prior to executing test.\n");
102 } else if (cellCount == MAXCELLS) {
103 printf("Only first %d tokens utilized by test; rest will be lost.\n",
107 for (i = 0; i < cellCount; i++) {
108 printf("Token[%d]: server = %s@%s, client = %s@%s\n", i,
109 oldServer[i].name, oldServer[i].cell, oldClient[i].name,
114 /* Forget original tokens */
116 printf("\nClearing original tokens and verifying disposal.\n");
118 code = ktc_ForgetAllTokens();
121 perror("ktc_ForgetAllTokens failed on original tokens");
125 for (i = 0; i < cellCount; i++) {
126 struct ktc_principal dummyPrincipal;
127 struct ktc_token dummyToken;
130 ktc_GetToken(&oldServer[i], &dummyToken, sizeof(struct ktc_token),
133 if (code != KTC_NOENT) {
134 printf("ktc_ForgetAllTokens did not eliminate all tokens.\n");
140 code = ktc_ListTokens(cellIndex, &cellIndex, &dummyPrincipal);
142 if (code != KTC_NOENT) {
143 printf("ktc_ForgetAllTokens did not eliminate all tokens.\n");
149 /* Reinstall tokens */
151 printf("\nReinstalling original tokens.\n");
153 for (i = 0; i < cellCount; i++) {
154 code = ktc_SetToken(&oldServer[i], &oldToken[i], &oldClient[i], 0);
157 perror("ktc_SetToken failed reinstalling tokens");
163 /* Get reinstalled tokens */
165 printf("\nFetching reinstalled tokens.\n");
169 for (i = 0; i < MAXCELLS; i++) {
170 /* fetch server principal */
171 code = ktc_ListTokens(cellIndex, &cellIndex, &newServer[i]);
174 if (code == KTC_NOENT) {
178 /* some error occured */
179 perror("ktc_ListTokens failed fetching reinstalled tokens");
184 /* fetch token and client identity w.r.t. server */
186 ktc_GetToken(&newServer[i], &newToken[i],
187 sizeof(struct ktc_token), &newClient[i]);
190 /* some unexpected error occured */
191 perror("ktc_GetToken failed fetching reinstalled tokens");
197 /* Verify content of reinstalled tokens */
199 printf("\nVerifying reinstalled tokens against original tokens.\n");
201 if (i != cellCount) {
202 printf("Reinstalled token count does not match original count.\n");
206 for (i = 0; i < cellCount; i++) {
210 for (k = 0; k < cellCount; k++) {
211 if (SamePrincipal(&oldServer[i], &newServer[k])
212 && SamePrincipal(&oldClient[i], &newClient[k])
213 && SameToken(&oldToken[i], &newToken[k])) {
214 /* found a matching token */
221 printf("Reinstalled token does not match any original token.\n");
228 printf("\nTest completed without error.\n");
234 SamePrincipal(struct ktc_principal *p1, struct ktc_principal *p2)
236 if (strcmp(p1->name, p2->name) || strcmp(p1->instance, p2->instance)
237 || strcmp(p1->cell, p2->cell)) {
238 /* principals do not match */
248 SameToken(struct ktc_token *t1, struct ktc_token *t2)
250 if ((t1->startTime != t2->startTime) || (t1->endTime != t2->endTime)
251 || memcmp(&t1->sessionKey, &t2->sessionKey, sizeof(t1->sessionKey))
252 || (t1->kvno != t2->kvno) || (t1->ticketLen != t2->ticketLen)
253 || memcmp(t1->ticket, t2->ticket, t1->ticketLen)) {
254 /* tokens do not match */