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 */
12 #include <afsconfig.h>
13 #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
, int flags
);
26 extern int ktc_GetToken(struct ktc_principal
*aserver
,
27 struct ktc_token
*atoken
, int atokenLen
,
28 struct ktc_principal
*aclient
);
30 extern int ktc_ListTokens(int aprevIndex
, int *aindex
,
31 struct ktc_principal
*aserver
);
33 extern int ktc_ForgetAllTokens(void);
36 static int SamePrincipal(struct ktc_principal
*p1
, struct ktc_principal
*p2
);
37 static int SameToken(struct ktc_token
*t1
, struct ktc_token
*t2
);
45 struct ktc_principal oldServer
[MAXCELLS
], newServer
[MAXCELLS
];
46 struct ktc_principal oldClient
[MAXCELLS
], newClient
[MAXCELLS
];
47 struct ktc_token oldToken
[MAXCELLS
], newToken
[MAXCELLS
];
48 int cellCount
, cellIndex
;
52 /* Initialize winsock; required by NT pioctl() */
53 if (afs_winsockInit()) {
54 printf("\nUnable to initialize winsock (required by NT pioctl()).\n");
59 /* Get original tokens */
61 printf("\nFetching original tokens.\n");
65 for (i
= 0; i
< MAXCELLS
; i
++) {
66 /* fetch server principal */
67 code
= ktc_ListTokens(cellIndex
, &cellIndex
, &oldServer
[i
]);
70 if (code
== KTC_NOENT
) {
74 /* some error occured */
75 perror("ktc_ListTokens failed fetching original tokens");
80 /* fetch token and client identity w.r.t. server */
82 ktc_GetToken(&oldServer
[i
], &oldToken
[i
],
83 sizeof(struct ktc_token
), &oldClient
[i
]);
86 /* some unexpected error occured */
87 perror("ktc_GetToken failed fetching original tokens");
95 printf("Obtain one or more tokens prior to executing test.\n");
97 } else if (cellCount
== MAXCELLS
) {
98 printf("Only first %d tokens utilized by test; rest will be lost.\n",
102 for (i
= 0; i
< cellCount
; i
++) {
103 printf("Token[%d]: server = %s@%s, client = %s@%s\n", i
,
104 oldServer
[i
].name
, oldServer
[i
].cell
, oldClient
[i
].name
,
109 /* Forget original tokens */
111 printf("\nClearing original tokens and verifying disposal.\n");
113 code
= ktc_ForgetAllTokens();
116 perror("ktc_ForgetAllTokens failed on original tokens");
120 for (i
= 0; i
< cellCount
; i
++) {
121 struct ktc_principal dummyPrincipal
;
122 struct ktc_token dummyToken
;
125 ktc_GetToken(&oldServer
[i
], &dummyToken
, sizeof(struct ktc_token
),
128 if (code
!= KTC_NOENT
) {
129 printf("ktc_ForgetAllTokens did not eliminate all tokens.\n");
135 code
= ktc_ListTokens(cellIndex
, &cellIndex
, &dummyPrincipal
);
137 if (code
!= KTC_NOENT
) {
138 printf("ktc_ForgetAllTokens did not eliminate all tokens.\n");
144 /* Reinstall tokens */
146 printf("\nReinstalling original tokens.\n");
148 for (i
= 0; i
< cellCount
; i
++) {
149 code
= ktc_SetToken(&oldServer
[i
], &oldToken
[i
], &oldClient
[i
], 0);
152 perror("ktc_SetToken failed reinstalling tokens");
158 /* Get reinstalled tokens */
160 printf("\nFetching reinstalled tokens.\n");
164 for (i
= 0; i
< MAXCELLS
; i
++) {
165 /* fetch server principal */
166 code
= ktc_ListTokens(cellIndex
, &cellIndex
, &newServer
[i
]);
169 if (code
== KTC_NOENT
) {
173 /* some error occured */
174 perror("ktc_ListTokens failed fetching reinstalled tokens");
179 /* fetch token and client identity w.r.t. server */
181 ktc_GetToken(&newServer
[i
], &newToken
[i
],
182 sizeof(struct ktc_token
), &newClient
[i
]);
185 /* some unexpected error occured */
186 perror("ktc_GetToken failed fetching reinstalled tokens");
192 /* Verify content of reinstalled tokens */
194 printf("\nVerifying reinstalled tokens against original tokens.\n");
196 if (i
!= cellCount
) {
197 printf("Reinstalled token count does not match original count.\n");
201 for (i
= 0; i
< cellCount
; i
++) {
205 for (k
= 0; k
< cellCount
; k
++) {
206 if (SamePrincipal(&oldServer
[i
], &newServer
[k
])
207 && SamePrincipal(&oldClient
[i
], &newClient
[k
])
208 && SameToken(&oldToken
[i
], &newToken
[k
])) {
209 /* found a matching token */
216 printf("Reinstalled token does not match any original token.\n");
223 printf("\nTest completed without error.\n");
229 SamePrincipal(struct ktc_principal
*p1
, struct ktc_principal
*p2
)
231 if (strcmp(p1
->name
, p2
->name
) || strcmp(p1
->instance
, p2
->instance
)
232 || strcmp(p1
->cell
, p2
->cell
)) {
233 /* principals do not match */
243 SameToken(struct ktc_token
*t1
, struct ktc_token
*t2
)
245 if ((t1
->startTime
!= t2
->startTime
) || (t1
->endTime
!= t2
->endTime
)
246 || memcmp(&t1
->sessionKey
, &t2
->sessionKey
, sizeof(t1
->sessionKey
))
247 || (t1
->kvno
!= t2
->kvno
) || (t1
->ticketLen
!= t2
->ticketLen
)
248 || memcmp(t1
->ticket
, t2
->ticket
, t1
->ticketLen
)) {
249 /* tokens do not match */