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