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>
21 #include <sys/types.h>
23 #include <time.h> /*time(), ctime() */
33 #include <afs/afsutil.h> /*getv*(), getc*() routine family */
34 #endif /* CMUWP_ENV */
39 #include "AFS_component_version_number.c"
42 main(int argc, char **argv)
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[MAXKTCNAMELEN * 2 + 2]; /*Printable user name */
51 struct ktc_principal clientName; /* service name for ticket */
52 struct ktc_token token; /* the token we're printing */
53 struct ktc_setTokenData *tokenSet;
57 * The following signal action for AIX is necessary so that in case of a
58 * crash (i.e. core is generated) we can include the user's data section
59 * in the core dump. Unfortunately, by default, only a partial core is
60 * generated which, in many cases, isn't too useful.
64 sigemptyset(&nsa.sa_mask);
65 nsa.sa_handler = SIG_DFL;
66 nsa.sa_flags = SA_FULLDUMP;
67 sigaction(SIGSEGV, &nsa, NULL);
70 /* has no args ... support for help flag */
73 /* syntax from AFS Com Ref Man p9-39 */
75 printf("Usage: tokens [-help]\n");
80 printf("\nTokens held by the Cache Manager:\n\n");
82 current_time = time(0);
84 rc = ktc_ListTokensEx(cellNum, &cellNum, &cellName);
86 /* only error is now end of list */
87 printf(" --End of list--\n");
90 /* get the ticket info itself */
91 rc = ktc_GetTokenEx(cellName, &tokenSet);
94 ("tokens: failed to get token info for cell %s (code %d)\n",
98 rc = token_extractRxkad(tokenSet, &token, NULL, &clientName);
100 tokenExpireTime = token.endTime;
101 strcpy(UserName, clientName.name);
102 if (clientName.instance[0] != 0) {
103 strcat(UserName, ".");
104 strcat(UserName, clientName.instance);
106 if (UserName[0] == 0)
107 printf("rxkad Tokens");
108 else if (strncmp(UserName, "AFS ID", 6) == 0) {
109 printf("User's (%s) rxkad tokens", UserName);
110 } else if (strncmp(UserName, "Unix UID", 8) == 0) {
111 printf("RxkadTokens");
113 printf("User %s's rxkad tokens", UserName);
114 printf(" for %s ", cellName);
115 if (tokenExpireTime <= current_time)
116 printf("[>> Expired <<]\n");
118 expireString = ctime(&tokenExpireTime);
119 expireString += 4; /*Move past the day of week */
120 expireString[12] = '\0';
121 printf("[Expires %s]\n", expireString);
124 token_FreeSet(&tokenSet);