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 #include <afs/param.h>
11 #include <afsconfig.h>
22 #include <sys/types.h>
24 #include <time.h> /*time(), ctime()*/
31 #include <afs/afsutil.h> /*getv*(), getc*() routine family*/
32 #endif /* CMUWP_ENV */
37 #include "AFS_component_version_number.c"
44 int cellNum; /*Cell entry number*/
45 int rc; /*Return value from U_CellGetLocalTokens*/
46 time_t current_time; /*Current time of day*/
47 time_t tokenExpireTime; /*When token expires*/
48 char *expireString; /*Char string of expiration time*/
49 char UserName[16]; /*Printable user name*/
50 struct ktc_principal serviceName, clientName; /* service name for ticket */
51 struct ktc_token token; /* the token we're printing */
55 * The following signal action for AIX is necessary so that in case of a
56 * crash (i.e. core is generated) we can include the user's data section
57 * in the core dump. Unfortunately, by default, only a partial core is
58 * generated which, in many cases, isn't too useful.
62 sigemptyset(&nsa.sa_mask);
63 nsa.sa_handler = SIG_DFL;
64 nsa.sa_flags = SA_FULLDUMP;
65 sigaction(SIGSEGV, &nsa, NULL);
68 /* has no args ... support for help flag */
72 /* syntax from AFS Com Ref Man p9-39 */
74 printf("Usage: tokens [-help]\n");
79 printf("\nTokens held by the Cache Manager:\n\n");
81 current_time = time(0);
83 rc = ktc_ListTokens(cellNum, &cellNum, &serviceName);
85 /* only error is now end of list */
86 printf(" --End of list--\n");
90 /* get the ticket info itself */
91 rc = ktc_GetToken(&serviceName, &token, sizeof(token), &clientName);
93 printf("tokens: failed to get token info for service %s.%s.%s (code %d)\n",
94 serviceName.name, serviceName.instance, serviceName.cell, rc);
97 tokenExpireTime = token.endTime;
98 strcpy(UserName, clientName.name);
99 if (clientName.instance[0] != 0) {
100 strcat(UserName, ".");
101 strcat(UserName, clientName.instance);
103 if (UserName[0] == 0)
105 else if (strncmp(UserName, "AFS ID", 6) == 0) {
106 printf("User's (%s) tokens", UserName);
108 else if (strncmp(UserName, "Unix UID", 8) == 0) {
112 printf("User %s's tokens", UserName);
113 printf(" for %s%s%s@%s ",
115 serviceName.instance[0] ? "." : "",
116 serviceName.instance,
118 if (tokenExpireTime <= current_time)
119 printf("[>> Expired <<]\n");
121 expireString = ctime(&tokenExpireTime);
122 expireString += 4; /*Move past the day of week*/
123 expireString[12] = '\0';
124 printf("[Expires %s]\n",