Windows: remove extraneous "pingCount" format param
[openafs.git] / src / WINNT / afsd / ctokens.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 #include <roken.h>
14
15 #include <afs/stds.h>
16
17 #include <windows.h>
18 #include <winsock2.h>
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <time.h>
23 #include <afs/auth.h>
24
25 main(argc, argv)
26         int argc;
27         char **argv;
28 {
29         int cellNum;
30         int rc;
31         time_t current_time;
32         time_t tokenExpireTime;
33         char *expireString;
34         char userName[100];
35         struct ktc_principal serviceName, clientName;
36         struct ktc_token token;
37         WSADATA WSAjunk;
38
39         WSAStartup(0x0101, &WSAjunk);
40         if (argc > 1) {
41            printf("%s [-help]\n", argv[0]);
42            return 0;
43         }
44
45         printf("\nTokens held by the Cache Manager:\n\n");
46         cellNum = 0;
47         current_time = time((void *) 0);
48
49         while (1) {
50                 rc = ktc_ListTokens(cellNum, &cellNum, &serviceName);
51                 if (rc == KTC_NOENT) {
52                         /* end of list */
53                         printf("   --End of list --\n");
54                         break;
55                 }
56                 else if (rc == KTC_NOCM) {
57                         printf("AFS device may not have started\n");
58                         break;
59                 }
60                 else if (rc) {
61                         printf("Unexpected error, code %d\n", rc);
62                         exit(1);
63                 }
64                 else {
65                         rc = ktc_GetToken(&serviceName, &token, sizeof(token),
66                                           &clientName);
67                         if (rc) {
68                                 printf("Unexpected error, service %s.%s.%s, code %d\n",
69                                         serviceName.name, serviceName.instance,
70                                         serviceName.cell, rc);
71                                 continue;
72                         }
73                         tokenExpireTime = token.endTime;
74                         strcpy(userName, clientName.name);
75                         if (clientName.instance[0] != 0) {
76                                 strcat(userName, ".");
77                                 strcat(userName, clientName.instance);
78                         }
79                         if (userName[0] == '\0')
80                                 printf("Tokens");
81                         else if (strncmp(userName, "AFS ID", 6) == 0)
82                                 printf("User's (%s) tokens", userName);
83                         else if (strncmp(userName, "Unix UID", 8) == 0)
84                                 printf("Tokens");
85                         else
86                                 printf("User %s's tokens", userName);
87                         printf(" for %s%s%s@%s ",
88                                 serviceName.name,
89                                 serviceName.instance[0] ? "." : "",
90                                 serviceName.instance,
91                                 serviceName.cell);
92                         if (tokenExpireTime <= current_time)
93                                 printf("[>> Expired <<]\n");
94                         else {
95                                 time_t t = tokenExpireTime;
96                                 expireString = ctime(&t);
97                                 expireString += 4;       /* Skip day of week */
98                                 expireString[12] = '\0'; /* Omit secs & year */
99                                 printf("[Expires %s]\n", expireString);
100                         }
101                 }
102         }
103         return(0);
104 }