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() */
34 #include <afs/afsutil.h> /*getv*(), getc*() routine family */
35 #endif /* CMUWP_ENV */
40 #include "AFS_component_version_number.c"
43 main(int argc, char **argv)
45 int cellNum; /*Cell entry number */
46 int rc; /*Return value from U_CellGetLocalTokens */
47 time_t current_time; /*Current time of day */
48 time_t tokenExpireTime; /*When token expires */
49 char *expireString; /*Char string of expiration time */
50 char UserName[MAXKTCNAMELEN * 2 + 2]; /*Printable user name */
51 struct ktc_principal serviceName, clientName; /* service name for ticket */
52 struct ktc_token token; /* the token we're printing */
56 * The following signal action for AIX is necessary so that in case of a
57 * crash (i.e. core is generated) we can include the user's data section
58 * in the core dump. Unfortunately, by default, only a partial core is
59 * generated which, in many cases, isn't too useful.
63 sigemptyset(&nsa.sa_mask);
64 nsa.sa_handler = SIG_DFL;
65 nsa.sa_flags = SA_FULLDUMP;
66 sigaction(SIGSEGV, &nsa, NULL);
69 /* 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");
89 /* get the ticket info itself */
90 rc = ktc_GetToken(&serviceName, &token, sizeof(token),
94 ("tokens: failed to get token info for service %s.%s.%s (code %d)\n",
95 serviceName.name, serviceName.instance, serviceName.cell,
99 tokenExpireTime = token.endTime;
100 strcpy(UserName, clientName.name);
101 if (clientName.instance[0] != 0) {
102 strcat(UserName, ".");
103 strcat(UserName, clientName.instance);
105 if (UserName[0] == 0)
107 else if (strncmp(UserName, "AFS ID", 6) == 0) {
108 printf("User's (%s) tokens", UserName);
109 } else if (strncmp(UserName, "Unix UID", 8) == 0) {
112 printf("User %s's tokens", UserName);
113 printf(" for %s%s%s@%s ", serviceName.name,
114 serviceName.instance[0] ? "." : "", serviceName.instance,
116 if (tokenExpireTime <= current_time)
117 printf("[>> Expired <<]\n");
119 expireString = ctime(&tokenExpireTime);
120 expireString += 4; /*Move past the day of week */
121 expireString[12] = '\0';
122 printf("[Expires %s]\n", expireString);