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>
23 #include <sys/types.h>
25 #include <time.h> /*time(), ctime() */
41 #include <afs/afsutil.h> /*getv*(), getc*() routine family */
42 #endif /* CMUWP_ENV */
47 #include "AFS_component_version_number.c"
50 main(int argc, char **argv)
52 int cellNum; /*Cell entry number */
53 int rc; /*Return value from U_CellGetLocalTokens */
54 time_t current_time; /*Current time of day */
55 time_t tokenExpireTime; /*When token expires */
56 char *expireString; /*Char string of expiration time */
57 char UserName[MAXKTCNAMELEN * 2 + 2]; /*Printable user name */
58 struct ktc_principal serviceName, clientName; /* service name for ticket */
59 struct ktc_token token; /* the token we're printing */
63 * The following signal action for AIX is necessary so that in case of a
64 * crash (i.e. core is generated) we can include the user's data section
65 * in the core dump. Unfortunately, by default, only a partial core is
66 * generated which, in many cases, isn't too useful.
70 sigemptyset(&nsa.sa_mask);
71 nsa.sa_handler = SIG_DFL;
72 nsa.sa_flags = SA_FULLDUMP;
73 sigaction(SIGSEGV, &nsa, NULL);
76 /* has no args ... support for help flag */
79 /* syntax from AFS Com Ref Man p9-39 */
81 printf("Usage: tokens [-help]\n");
86 printf("\nTokens held by the Cache Manager:\n\n");
88 current_time = time(0);
90 rc = ktc_ListTokens(cellNum, &cellNum, &serviceName);
92 /* only error is now end of list */
93 printf(" --End of list--\n");
96 /* get the ticket info itself */
97 rc = ktc_GetToken(&serviceName, &token, sizeof(token),
101 ("tokens: failed to get token info for service %s.%s.%s (code %d)\n",
102 serviceName.name, serviceName.instance, serviceName.cell,
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);
116 } else if (strncmp(UserName, "Unix UID", 8) == 0) {
119 printf("User %s's tokens", UserName);
120 printf(" for %s%s%s@%s ", serviceName.name,
121 serviceName.instance[0] ? "." : "", serviceName.instance,
123 if (tokenExpireTime <= current_time)
124 printf("[>> Expired <<]\n");
126 expireString = ctime(&tokenExpireTime);
127 expireString += 4; /*Move past the day of week */
128 expireString[12] = '\0';
129 printf("[Expires %s]\n", expireString);