]> git.ipfire.org Git - thirdparty/glibc.git/blame - nis/nis_print.c
Update.
[thirdparty/glibc.git] / nis / nis_print.c
CommitLineData
c0fb8a56 1/* Copyright (c) 1997, 1998 Free Software Foundation, Inc.
e61abf83
UD
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20#include <time.h>
76b87c03
UD
21#include <string.h>
22
e61abf83 23#include <rpcsvc/nis.h>
e61abf83
UD
24
25static const char *
26nis_nstype2str (const nstype type)
27{
28 switch (type)
29 {
30 case NIS:
31 return N_("NIS");
32 case SUNYP:
33 return N_("SUNYP");
34 case IVY:
35 return N_("IVY");
36 case DNS:
37 return N_("DNS");
38 case X500:
39 return N_("X500");
40 case DNANS:
41 return N_("DNANS");
42 case XCHS:
43 return N_("XCHS");
44 case CDS:
45 return N_("CDS");
46 default:
47 return N_("UNKNOWN");
48 }
49}
50
dfd2257a
UD
51static void
52print_ttl (const u_long ttl)
e61abf83 53{
e61abf83
UD
54 unsigned long int time, s, m, h;
55
56 time = ttl;
57
58 h = time / (60 * 60);
59 time %= (60 * 60);
60 m = time / 60;
61 time %= 60;
62 s = time;
dfd2257a 63 printf ("%lu:%lu:%lu\n", h, m, s);
e61abf83
UD
64}
65
dfd2257a
UD
66static void
67print_flags (const u_long flags)
e61abf83 68{
dfd2257a 69 fputs ("(", stdout);
e61abf83 70
dfd2257a
UD
71 if (flags & TA_SEARCHABLE)
72 fputs ("SEARCHABLE, ", stdout);
e61abf83 73
dfd2257a
UD
74 if (flags & TA_BINARY)
75 {
76 fputs ("BINARY DATA", stdout);
77 if (flags & TA_XDR)
78 fputs (", XDR ENCODED", stdout);
79 if (flags & TA_ASN1)
80 fputs (", ASN.1 ENCODED", stdout);
81 if (flags & TA_CRYPT)
82 fputs (", ENCRYPTED", stdout);
83 }
84 else
85 {
86 fputs("TEXTUAL DATA", stdout);
87 if (flags & TA_SEARCHABLE)
88 {
89 if (flags & TA_CASE)
90 fputs (", CASE INSENSITIVE", stdout);
91 else
92 fputs (", CASE SENSITIVE", stdout);
93 }
94 }
95
96 fputs (")\n", stdout);
e61abf83
UD
97}
98
2d7da676
UD
99static void
100nis_print_objtype (enum zotypes type)
101{
102 switch (type)
103 {
dfd2257a 104 case NIS_BOGUS_OBJ:
2d7da676
UD
105 fputs (_("BOGUS OBJECT\n"), stdout);
106 break;
dfd2257a 107 case NIS_NO_OBJ:
2d7da676
UD
108 fputs (_("NO OBJECT\n"), stdout);
109 break;
dfd2257a 110 case NIS_DIRECTORY_OBJ:
2d7da676
UD
111 fputs (_("DIRECTORY\n"), stdout);
112 break;
dfd2257a 113 case NIS_GROUP_OBJ:
2d7da676
UD
114 fputs (_("GROUP\n"), stdout);
115 break;
dfd2257a 116 case NIS_TABLE_OBJ:
2d7da676
UD
117 fputs (_("TABLE\n"), stdout);
118 break;
dfd2257a 119 case NIS_ENTRY_OBJ:
2d7da676
UD
120 fputs (_("ENTRY\n"), stdout);
121 break;
dfd2257a 122 case NIS_LINK_OBJ:
2d7da676
UD
123 fputs (_("LINK\n"), stdout);
124 break;
dfd2257a 125 case NIS_PRIVATE_OBJ:
2d7da676
UD
126 fputs (_("PRIVATE\n"), stdout);
127 break;
128 default:
129 fputs (_("(Unknown object)\n"), stdout);
130 break;
131 }
132}
133
e61abf83
UD
134void
135nis_print_rights (const u_long access)
136{
137 char result[17];
138 u_long acc;
139 int i;
140
141 acc = access; /* Parameter is const ! */
142 result[i = 16] = '\0';
143 while (i > 0)
144 {
145 i -= 4;
146 result[i + 0] = (acc & NIS_READ_ACC) ? 'r' : '-';
147 result[i + 1] = (acc & NIS_MODIFY_ACC) ? 'm' : '-';
148 result[i + 2] = (acc & NIS_CREATE_ACC) ? 'c' : '-';
149 result[i + 3] = (acc & NIS_DESTROY_ACC) ? 'd' : '-';
150
151 acc >>= 8;
152 }
c0fb8a56 153 fputs (result, stdout);
e61abf83
UD
154}
155
156void
157nis_print_directory (const directory_obj *dir)
158{
159 nis_server *sptr;
160 unsigned int i;
161
162 printf (_("Name : '%s'\n"), dir->do_name);
dfd2257a 163 printf (_("Type : %s\n"), nis_nstype2str (dir->do_type));
e61abf83
UD
164 sptr = dir->do_servers.do_servers_val;
165 for (i = 0; i < dir->do_servers.do_servers_len; i++)
166 {
167 if (i == 0)
168 fputs (_("Master Server :\n"), stdout);
169 else
170 fputs (_("Replicate :\n"), stdout);
171 printf (_("\tName : %s\n"), sptr->name);
172 fputs (_("\tPublic Key : "), stdout);
173 switch (sptr->key_type)
174 {
175 case NIS_PK_NONE:
176 fputs (_("None.\n"), stdout);
177 break;
178 case NIS_PK_DH:
c0fb8a56
UD
179 printf (_("Diffie-Hellmann (%d bits)\n"),
180 (sptr->pkey.n_len - 1) * 4);
dfd2257a 181 /* sptr->pkey.n_len counts the last 0, too */
e61abf83
UD
182 break;
183 case NIS_PK_RSA:
c0fb8a56 184 printf (_("RSA (%d bits)\n"), (sptr->pkey.n_len - 1) * 4);
e61abf83
UD
185 break;
186 case NIS_PK_KERB:
dfd2257a 187 fputs (_("Kerberos.\n"), stdout);
e61abf83
UD
188 break;
189 default:
c0fb8a56
UD
190 printf (_("Unknown (type = %d, bits = %d)\n"), sptr->key_type,
191 (sptr->pkey.n_len - 1) * 4);
e61abf83
UD
192 break;
193 }
194
195 if (sptr->ep.ep_len != 0)
196 {
197 unsigned int j;
198
199 endpoint *ptr;
200 ptr = sptr->ep.ep_val;
201 printf (_("\tUniversal addresses (%u)\n"), sptr->ep.ep_len);
202 for (j = 0; j < sptr->ep.ep_len; j++)
203 {
204 printf ("\t[%d] - ", j + 1);
a53bad16 205 if (ptr->proto != NULL && ptr->proto[0] != '\0')
e61abf83
UD
206 printf ("%s, ", ptr->proto);
207 else
208 printf ("-, ");
a53bad16 209 if (ptr->family != NULL && ptr->family[0] != '\0')
e61abf83
UD
210 printf ("%s, ", ptr->family);
211 else
212 printf ("-, ");
a53bad16 213 if (ptr->uaddr != NULL && ptr->uaddr[0] != '\0')
e61abf83
UD
214 printf ("%s\n", ptr->uaddr);
215 else
c0fb8a56 216 fputs ("-\n", stdout);
e61abf83
UD
217 ptr++;
218 }
219 }
220 sptr++;
221 }
222
dfd2257a
UD
223 fputs (_("Time to live : "), stdout);
224 print_ttl (dir->do_ttl);
225 fputs (_("Default Access rights :\n"), stdout);
e61abf83
UD
226 if (dir->do_armask.do_armask_len != 0)
227 {
228 oar_mask *ptr;
229
230 ptr = dir->do_armask.do_armask_val;
231 for (i = 0; i < dir->do_armask.do_armask_len; i++)
232 {
e61abf83 233 nis_print_rights (ptr->oa_rights);
dfd2257a 234 printf (_("\tType : %s\n"), nis_nstype2str (ptr->oa_otype));
c0fb8a56 235 fputs (_("\tAccess rights: "), stdout);
dfd2257a
UD
236 nis_print_rights (ptr->oa_rights);
237 fputs ("\n", stdout);
e61abf83
UD
238 ptr++;
239 }
240 }
241}
242
243void
244nis_print_group (const group_obj *obj)
245{
246 unsigned int i;
247
248 fputs (_("Group Flags :"), stdout);
249 if (obj->gr_flags)
250 printf ("0x%08lX", obj->gr_flags);
251 fputs (_("\nGroup Members :\n"), stdout);
252
253 for (i = 0; i < obj->gr_members.gr_members_len; i++)
254 printf ("\t%s\n", obj->gr_members.gr_members_val[i]);
255}
256
257void
258nis_print_table (const table_obj *obj)
259{
260 unsigned int i;
261
262 printf (_("Table Type : %s\n"), obj->ta_type);
263 printf (_("Number of Columns : %d\n"), obj->ta_maxcol);
264 printf (_("Character Separator : %c\n"), obj->ta_sep);
265 printf (_("Search Path : %s\n"), obj->ta_path);
266 fputs (_("Columns :\n"), stdout);
267 for (i = 0; i < obj->ta_cols.ta_cols_len; i++)
268 {
269 printf (_("\t[%d]\tName : %s\n"), i,
270 obj->ta_cols.ta_cols_val[i].tc_name);
dfd2257a
UD
271 fputs (_("\t\tAttributes : "), stdout);
272 print_flags (obj->ta_cols.ta_cols_val[i].tc_flags);
e61abf83
UD
273 fputs (_("\t\tAccess Rights : "), stdout);
274 nis_print_rights (obj->ta_cols.ta_cols_val[i].tc_rights);
275 fputc ('\n', stdout);
276 }
277}
278
279void
280nis_print_link (const link_obj *obj)
281{
2d7da676
UD
282 fputs (_("Linked Object Type : "), stdout);
283 nis_print_objtype (obj->li_rtype);
284 printf (_("Linked to : %s\n"), obj->li_name);
285 /* XXX Print the attributs here, if they exists */
e61abf83
UD
286}
287
288void
289nis_print_entry (const entry_obj *obj)
290{
291 unsigned int i;
292
293 printf (_("\tEntry data of type %s\n"), obj->en_type);
294 for (i = 0; i < obj->en_cols.en_cols_len; i++)
295 {
296 printf (_("\t[%u] - [%u bytes] "), i,
297 obj->en_cols.en_cols_val[i].ec_value.ec_value_len);
298 if ((obj->en_cols.en_cols_val[i].ec_flags & EN_CRYPT) == EN_CRYPT)
299 fputs (_("Encrypted data\n"), stdout);
300 else if ((obj->en_cols.en_cols_val[i].ec_flags & EN_BINARY) == EN_BINARY)
301 fputs (_("Binary data\n"), stdout);
302 else
dfd2257a
UD
303 printf ("%.*s\n", (int)obj->en_cols.en_cols_val[i].ec_value.ec_value_len,
304 obj->en_cols.en_cols_val[i].ec_value.ec_value_val);
e61abf83
UD
305 }
306}
307
308void
309nis_print_object (const nis_object * obj)
310{
311 printf (_("Object Name : %s\n"), obj->zo_name);
312 printf (_("Directory : %s\n"), obj->zo_domain);
313 printf (_("Owner : %s\n"), obj->zo_owner);
314 printf (_("Group : %s\n"), obj->zo_group);
315 fputs (_("Access Rights : "), stdout);
316 nis_print_rights (obj->zo_access);
dfd2257a
UD
317 printf (_("\nTime to Live : "));
318 print_ttl (obj->zo_ttl);
e61abf83
UD
319 printf (_("Creation Time : %s"), ctime (&obj->zo_oid.ctime));
320 printf (_("Mod. Time : %s"), ctime (&obj->zo_oid.mtime));
321 fputs (_("Object Type : "), stdout);
2d7da676 322 nis_print_objtype (obj->zo_data.zo_type);
e61abf83
UD
323 switch (obj->zo_data.zo_type)
324 {
dfd2257a 325 case NIS_DIRECTORY_OBJ:
e61abf83
UD
326 nis_print_directory (&obj->zo_data.objdata_u.di_data);
327 break;
dfd2257a 328 case NIS_GROUP_OBJ:
e61abf83
UD
329 nis_print_group (&obj->zo_data.objdata_u.gr_data);
330 break;
dfd2257a 331 case NIS_TABLE_OBJ:
e61abf83
UD
332 nis_print_table (&obj->zo_data.objdata_u.ta_data);
333 break;
dfd2257a 334 case NIS_ENTRY_OBJ:
e61abf83
UD
335 nis_print_entry (&obj->zo_data.objdata_u.en_data);
336 break;
dfd2257a 337 case NIS_LINK_OBJ:
e61abf83
UD
338 nis_print_link (&obj->zo_data.objdata_u.li_data);
339 break;
dfd2257a 340 case NIS_PRIVATE_OBJ:
e61abf83
UD
341 printf (_(" Data Length = %u\n"),
342 obj->zo_data.objdata_u.po_data.po_data_len);
343 break;
344 default:
e61abf83
UD
345 break;
346 }
347}
348
349void
350nis_print_result (const nis_result *res)
351{
352 unsigned int i;
353
91eee4dd 354 printf (_("Status : %s\n"), nis_sperrno (NIS_RES_STATUS (res)));
e61abf83
UD
355 printf (_("Number of objects : %u\n"), res->objects.objects_len);
356
357 for (i = 0; i < res->objects.objects_len; i++)
358 {
359 printf (_("Object #%d:\n"), i);
360 nis_print_object (&res->objects.objects_val[i]);
361 }
362}