Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / log / tokens.c
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
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
8 */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 #include <roken.h>
14
15 #include <rx/xdr.h>
16 #include <afs/auth.h>
17 #include <afs/ktc.h>
18
19 #define VIRTUE
20 #define VICE
21
22 #ifdef CMUWP_ENV
23 #include <afs/afsutil.h> /*getv*(), getc*() routine family */
24 #endif /* CMUWP_ENV */
25
26 #undef VIRTUE
27 #undef VICE
28
29 #include "AFS_component_version_number.c"
30
31 int
32 main(int argc, char **argv)
33 { /*Main program */
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 */
40 char *cellName;
41 struct ktc_principal clientName; /* service name for ticket */
42 struct ktc_token token; /* the token we're printing */
43 struct ktc_setTokenData *tokenSet;
44
45 #ifdef AFS_AIX32_ENV
46 /*
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.
51 */
52 struct sigaction nsa;
53
54 sigemptyset(&nsa.sa_mask);
55 nsa.sa_handler = SIG_DFL;
56 nsa.sa_flags = SA_FULLDUMP;
57 sigaction(SIGSEGV, &nsa, NULL);
58 #endif
59
60 /* has no args ... support for help flag */
61
62 if (argc > 1) {
63 /* syntax from AFS Com Ref Man p9-39 */
64
65 printf("Usage: tokens [-help]\n");
66 fflush(stdout);
67 exit(0);
68 }
69
70 printf("\nTokens held by the Cache Manager:\n\n");
71 cellNum = 0;
72 current_time = time(0);
73 while (1) {
74 rc = ktc_ListTokensEx(cellNum, &cellNum, &cellName);
75 if (rc) {
76 /* only error is now end of list */
77 printf(" --End of list--\n");
78 break;
79 } else {
80 /* get the ticket info itself */
81 rc = ktc_GetTokenEx(cellName, &tokenSet);
82 if (rc) {
83 printf
84 ("tokens: failed to get token info for cell %s (code %d)\n",
85 cellName, rc);
86 continue;
87 }
88 rc = token_extractRxkad(tokenSet, &token, NULL, &clientName);
89 if (rc == 0) {
90 tokenExpireTime = token.endTime;
91 strcpy(UserName, clientName.name);
92 if (clientName.instance[0] != 0) {
93 strcat(UserName, ".");
94 strcat(UserName, clientName.instance);
95 }
96 if (UserName[0] == 0)
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");
102 } else
103 printf("User %s's rxkad tokens", UserName);
104 printf(" for %s ", cellName);
105 if (tokenExpireTime <= current_time)
106 printf("[>> Expired <<]\n");
107 else {
108 expireString = ctime(&tokenExpireTime);
109 expireString += 4; /*Move past the day of week */
110 expireString[12] = '\0';
111 printf("[Expires %s]\n", expireString);
112 }
113 }
114 token_FreeSet(&tokenSet);
115 }
116 }
117 exit(0);
118 } /*Main program */