Add interface to select client security objects
[openafs.git] / src / ptserver / display.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
14 #include <afs/stds.h>
15 #include <sys/types.h>
16 #ifdef AFS_NT40_ENV
17 #include <winsock2.h>
18 #else
19 #include <netinet/in.h>
20 #endif
21 #include <string.h>
22 #include <stdio.h>
23 #include "ptserver.h"
24
25 #include "display.h"
26
27 #ifdef PR_REMEMBER_TIMES
28
29 # include <time.h>
30
31
32 static char *
33 pr_TimeToString(time_t clock)
34 {
35     struct tm *tm;
36     static char buffer[32];
37     static int this_year = 0;
38
39     if (clock == 0)
40         return "time-not-set  ";
41     if (!this_year) {
42         time_t now = time(0);
43         tm = localtime(&now);
44         this_year = tm->tm_year;
45     }
46     tm = localtime(&clock);
47     if (tm->tm_year != this_year)
48         strftime(buffer, 32, "%m/%d/%Y %H:%M:%S", tm);
49     else
50         strftime(buffer, 32, "%m/%d %H:%M:%S", tm);
51     return buffer;
52 }
53 #endif
54
55 #define host(a) (hostOrder ? (a) : ntohl(a))
56
57 static void
58 PrintEntries(FILE *f, int hostOrder, int indent, struct prentry *e, int n)
59 {
60     int i;
61     int newline;
62
63     newline = 0;
64     for (i = 0; i < n; i++) {
65         if (e->entries[i] == 0)
66             break;
67
68         if (i == 0)
69             fprintf(f, "%*sids ", indent, "");
70         else if (newline == 0)
71             fprintf(f, "%*s", indent + 4, "");
72
73         if (host(e->entries[i]) == PRBADID)
74             fprintf(f, " EMPTY");
75         else
76             fprintf(f, "%6d", host(e->entries[i]));
77         newline = 1;
78         if (i % 10 == 9) {
79             fprintf(f, "\n");
80             newline = 0;
81         } else
82             fprintf(f, " ");
83     }
84     if (newline)
85         fprintf(f, "\n");
86 }
87
88 int
89 pr_PrintEntry(FILE *f, int hostOrder, afs_int32 ea, struct prentry *e, int indent)
90 {
91     int i;
92
93     if (e->cellid)
94         fprintf(f, "cellid == %d\n", host(e->cellid));
95     for (i = 0; i < sizeof(e->reserved) / sizeof(e->reserved[0]); i++)
96         if (e->reserved[i])
97             fprintf(f, "reserved field [%d] not zero: %d\n", i,
98                     host(e->reserved[i]));
99
100     fprintf(f, "%*s", indent, "");
101     fprintf(f, "Entry at %d: flags 0x%x, id %di, next %d.\n", ea,
102             host(e->flags), host(e->id), host(e->next));
103 #ifdef PR_REMEMBER_TIMES
104     fprintf(f, "%*s", indent, "");
105     fprintf(f, "c:%s ", pr_TimeToString(host(e->createTime)));
106     fprintf(f, "a:%s ", pr_TimeToString(host(e->addTime)));
107     fprintf(f, "r:%s ", pr_TimeToString(host(e->removeTime)));
108     fprintf(f, "n:%s\n", pr_TimeToString(host(e->changeTime)));
109 #endif
110     if (host(e->flags) & PRCONT)
111         PrintEntries(f, hostOrder, indent, e, COSIZE);
112     else {                      /* regular entry */
113         PrintEntries(f, hostOrder, indent, e, PRSIZE);
114         fprintf(f, "%*s", indent, "");
115         fprintf(f, "hash (id %d name %d).  Owner %di, creator %di\n",
116                 host(e->nextID), host(e->nextName), host(e->owner),
117                 host(e->creator));
118         fprintf(f, "%*s", indent, "");
119 #if defined(SUPERGROUPS)
120         fprintf(f, "quota groups %d, foreign users %d.  Mem: %d, cntsg: %d\n",
121                 host(e->ngroups), host(e->nusers), host(e->count),
122                 host(e->instance));
123 #else
124         fprintf(f, "quota groups %d, foreign users %d.  Mem: %d, inst: %d\n",
125                 host(e->ngroups), host(e->nusers), host(e->count),
126                 host(e->instance));
127 #endif
128         fprintf(f, "%*s", indent, "");
129 #if defined(SUPERGROUPS)
130         fprintf(f, "Owned chain %d, next owned %d, nextsg %d, sg (%d %d).\n",
131                 host(e->owned), host(e->nextOwned), host(e->parent),
132                 host(e->sibling), host(e->child));
133 #else
134         fprintf(f, "Owned chain %d, next owned %d, inst ptrs(%d %d %d).\n",
135                 host(e->owned), host(e->nextOwned), host(e->parent),
136                 host(e->sibling), host(e->child));
137 #endif
138         fprintf(f, "%*s", indent, "");
139         if (strlen(e->name) >= PR_MAXNAMELEN)
140             fprintf(f, "NAME TOO LONG: ");
141         fprintf(f, "Name is '%.*s'\n", PR_MAXNAMELEN, e->name);
142     }
143     return 0;
144 }