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 <afs/afsutil.h> /*getv*(), getc*() routine family */
24 #endif /* CMUWP_ENV */
29 #include "AFS_component_version_number.c"
32 main(int argc, char **argv)
34 int cellNum; /*Cell entry number */
35 int rc; /*Return value from U_CellGetLocalTokens */
36 time_t current_time; /*Current time of day */
37 time_t tokenExpireTime; /*When token expires */
38 char *expireString; /*Char string of expiration time */
39 char UserName[MAXKTCNAMELEN * 2 + 2]; /*Printable user name */
41 struct ktc_principal clientName; /* service name for ticket */
42 struct ktc_token token; /* the token we're printing */
43 struct ktc_setTokenData *tokenSet;
47 * The following signal action for AIX is necessary so that in case of a
48 * crash (i.e. core is generated) we can include the user's data section
49 * in the core dump. Unfortunately, by default, only a partial core is
50 * generated which, in many cases, isn't too useful.
54 sigemptyset(&nsa.sa_mask);
55 nsa.sa_handler = SIG_DFL;
56 nsa.sa_flags = SA_FULLDUMP;
57 sigaction(SIGSEGV, &nsa, NULL);
60 /* has no args ... support for help flag */
63 /* syntax from AFS Com Ref Man p9-39 */
65 printf("Usage: tokens [-help]\n");
70 printf("\nTokens held by the Cache Manager:\n\n");
72 current_time = time(0);
74 rc = ktc_ListTokensEx(cellNum, &cellNum, &cellName);
76 /* only error is now end of list */
77 printf(" --End of list--\n");
80 /* get the ticket info itself */
81 rc = ktc_GetTokenEx(cellName, &tokenSet);
84 ("tokens: failed to get token info for cell %s (code %d)\n",
88 rc = token_extractRxkad(tokenSet, &token, NULL, &clientName);
90 tokenExpireTime = token.endTime;
91 strcpy(UserName, clientName.name);
92 if (clientName.instance[0] != 0) {
93 strcat(UserName, ".");
94 strcat(UserName, clientName.instance);
97 printf("rxkad Tokens");
98 else if (strncmp(UserName, "AFS ID", 6) == 0) {
99 printf("User's (%s) rxkad tokens", UserName);
100 } else if (strncmp(UserName, "Unix UID", 8) == 0) {
101 printf("RxkadTokens");
103 printf("User %s's rxkad tokens", UserName);
104 printf(" for %s ", cellName);
105 if (tokenExpireTime <= current_time)
106 printf("[>> Expired <<]\n");
108 expireString = ctime(&tokenExpireTime);
109 expireString += 4; /*Move past the day of week */
110 expireString[12] = '\0';
111 printf("[Expires %s]\n", expireString);
114 token_FreeSet(&tokenSet);