Update.
[glibc.git] / nis / nis_print.c
blobab5f6838bdd0e49063b1562239f5642a5d0f361e
1 /* Copyright (c) 1997, 1998, 1999 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
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.
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.
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. */
20 #include <time.h>
21 #include <string.h>
22 #include <libintl.h>
24 #include <rpcsvc/nis.h>
26 static const char *
27 nis_nstype2str (const nstype type)
29 switch (type)
31 case NIS:
32 return N_("NIS");
33 case SUNYP:
34 return N_("SUNYP");
35 case IVY:
36 return N_("IVY");
37 case DNS:
38 return N_("DNS");
39 case X500:
40 return N_("X500");
41 case DNANS:
42 return N_("DNANS");
43 case XCHS:
44 return N_("XCHS");
45 case CDS:
46 return N_("CDS");
47 default:
48 return N_("UNKNOWN");
52 static void
53 print_ttl (const uint32_t ttl)
55 uint32_t time, s, m, h;
57 time = ttl;
59 h = time / (60 * 60);
60 time %= (60 * 60);
61 m = time / 60;
62 time %= 60;
63 s = time;
64 printf ("%u:%u:%u\n", h, m, s);
67 static void
68 print_flags (const unsigned int flags)
70 fputs ("(", stdout);
72 if (flags & TA_SEARCHABLE)
73 fputs ("SEARCHABLE, ", stdout);
75 if (flags & TA_BINARY)
77 fputs ("BINARY DATA", stdout);
78 if (flags & TA_XDR)
79 fputs (", XDR ENCODED", stdout);
80 if (flags & TA_ASN1)
81 fputs (", ASN.1 ENCODED", stdout);
82 if (flags & TA_CRYPT)
83 fputs (", ENCRYPTED", stdout);
85 else
87 fputs("TEXTUAL DATA", stdout);
88 if (flags & TA_SEARCHABLE)
90 if (flags & TA_CASE)
91 fputs (", CASE INSENSITIVE", stdout);
92 else
93 fputs (", CASE SENSITIVE", stdout);
97 fputs (")\n", stdout);
100 static void
101 nis_print_objtype (enum zotypes type)
103 switch (type)
105 case NIS_BOGUS_OBJ:
106 fputs (_("BOGUS OBJECT\n"), stdout);
107 break;
108 case NIS_NO_OBJ:
109 fputs (_("NO OBJECT\n"), stdout);
110 break;
111 case NIS_DIRECTORY_OBJ:
112 fputs (_("DIRECTORY\n"), stdout);
113 break;
114 case NIS_GROUP_OBJ:
115 fputs (_("GROUP\n"), stdout);
116 break;
117 case NIS_TABLE_OBJ:
118 fputs (_("TABLE\n"), stdout);
119 break;
120 case NIS_ENTRY_OBJ:
121 fputs (_("ENTRY\n"), stdout);
122 break;
123 case NIS_LINK_OBJ:
124 fputs (_("LINK\n"), stdout);
125 break;
126 case NIS_PRIVATE_OBJ:
127 fputs (_("PRIVATE\n"), stdout);
128 break;
129 default:
130 fputs (_("(Unknown object)\n"), stdout);
131 break;
135 void
136 nis_print_rights (const unsigned int access)
138 char result[17];
139 unsigned int acc;
140 int i;
142 acc = access; /* Parameter is const ! */
143 result[i = 16] = '\0';
144 while (i > 0)
146 i -= 4;
147 result[i + 0] = (acc & NIS_READ_ACC) ? 'r' : '-';
148 result[i + 1] = (acc & NIS_MODIFY_ACC) ? 'm' : '-';
149 result[i + 2] = (acc & NIS_CREATE_ACC) ? 'c' : '-';
150 result[i + 3] = (acc & NIS_DESTROY_ACC) ? 'd' : '-';
152 acc >>= 8;
154 fputs (result, stdout);
157 void
158 nis_print_directory (const directory_obj *dir)
160 nis_server *sptr;
161 unsigned int i;
163 printf (_("Name : `%s'\n"), dir->do_name);
164 printf (_("Type : %s\n"), nis_nstype2str (dir->do_type));
165 sptr = dir->do_servers.do_servers_val;
166 for (i = 0; i < dir->do_servers.do_servers_len; i++)
168 if (i == 0)
169 fputs (_("Master Server :\n"), stdout);
170 else
171 fputs (_("Replicate :\n"), stdout);
172 printf (_("\tName : %s\n"), sptr->name);
173 fputs (_("\tPublic Key : "), stdout);
174 switch (sptr->key_type)
176 case NIS_PK_NONE:
177 fputs (_("None.\n"), stdout);
178 break;
179 case NIS_PK_DH:
180 printf (_("Diffie-Hellmann (%d bits)\n"),
181 (sptr->pkey.n_len - 1) * 4);
182 /* sptr->pkey.n_len counts the last 0, too */
183 break;
184 case NIS_PK_RSA:
185 printf (_("RSA (%d bits)\n"), (sptr->pkey.n_len - 1) * 4);
186 break;
187 case NIS_PK_KERB:
188 fputs (_("Kerberos.\n"), stdout);
189 break;
190 default:
191 printf (_("Unknown (type = %d, bits = %d)\n"), sptr->key_type,
192 (sptr->pkey.n_len - 1) * 4);
193 break;
196 if (sptr->ep.ep_len != 0)
198 unsigned int j;
200 endpoint *ptr;
201 ptr = sptr->ep.ep_val;
202 printf (_("\tUniversal addresses (%u)\n"), sptr->ep.ep_len);
203 for (j = 0; j < sptr->ep.ep_len; j++)
205 printf ("\t[%d] - ", j + 1);
206 if (ptr->proto != NULL && ptr->proto[0] != '\0')
207 printf ("%s, ", ptr->proto);
208 else
209 printf ("-, ");
210 if (ptr->family != NULL && ptr->family[0] != '\0')
211 printf ("%s, ", ptr->family);
212 else
213 printf ("-, ");
214 if (ptr->uaddr != NULL && ptr->uaddr[0] != '\0')
215 printf ("%s\n", ptr->uaddr);
216 else
217 fputs ("-\n", stdout);
218 ptr++;
221 sptr++;
224 fputs (_("Time to live : "), stdout);
225 print_ttl (dir->do_ttl);
226 fputs (_("Default Access rights :\n"), stdout);
227 if (dir->do_armask.do_armask_len != 0)
229 oar_mask *ptr;
231 ptr = dir->do_armask.do_armask_val;
232 for (i = 0; i < dir->do_armask.do_armask_len; i++)
234 nis_print_rights (ptr->oa_rights);
235 printf (_("\tType : %s\n"), nis_nstype2str (ptr->oa_otype));
236 fputs (_("\tAccess rights: "), stdout);
237 nis_print_rights (ptr->oa_rights);
238 fputs ("\n", stdout);
239 ptr++;
244 void
245 nis_print_group (const group_obj *obj)
247 unsigned int i;
249 fputs (_("Group Flags :"), stdout);
250 if (obj->gr_flags)
251 printf ("0x%08X", obj->gr_flags);
252 fputs (_("\nGroup Members :\n"), stdout);
254 for (i = 0; i < obj->gr_members.gr_members_len; i++)
255 printf ("\t%s\n", obj->gr_members.gr_members_val[i]);
258 void
259 nis_print_table (const table_obj *obj)
261 unsigned int i;
263 printf (_("Table Type : %s\n"), obj->ta_type);
264 printf (_("Number of Columns : %d\n"), obj->ta_maxcol);
265 printf (_("Character Separator : %c\n"), obj->ta_sep);
266 printf (_("Search Path : %s\n"), obj->ta_path);
267 fputs (_("Columns :\n"), stdout);
268 for (i = 0; i < obj->ta_cols.ta_cols_len; i++)
270 printf (_("\t[%d]\tName : %s\n"), i,
271 obj->ta_cols.ta_cols_val[i].tc_name);
272 fputs (_("\t\tAttributes : "), stdout);
273 print_flags (obj->ta_cols.ta_cols_val[i].tc_flags);
274 fputs (_("\t\tAccess Rights : "), stdout);
275 nis_print_rights (obj->ta_cols.ta_cols_val[i].tc_rights);
276 fputc ('\n', stdout);
280 void
281 nis_print_link (const link_obj *obj)
283 fputs (_("Linked Object Type : "), stdout);
284 nis_print_objtype (obj->li_rtype);
285 printf (_("Linked to : %s\n"), obj->li_name);
286 /* XXX Print the attributs here, if they exists */
289 void
290 nis_print_entry (const entry_obj *obj)
292 unsigned int i;
294 printf (_("\tEntry data of type %s\n"), obj->en_type);
295 for (i = 0; i < obj->en_cols.en_cols_len; i++)
297 printf (_("\t[%u] - [%u bytes] "), i,
298 obj->en_cols.en_cols_val[i].ec_value.ec_value_len);
299 if ((obj->en_cols.en_cols_val[i].ec_flags & EN_CRYPT) == EN_CRYPT)
300 fputs (_("Encrypted data\n"), stdout);
301 else if ((obj->en_cols.en_cols_val[i].ec_flags & EN_BINARY) == EN_BINARY)
302 fputs (_("Binary data\n"), stdout);
303 else if (obj->en_cols.en_cols_val[i].ec_value.ec_value_len == 0)
304 fputs ("'(nil)'\n", stdout);
305 else
306 printf ("'%.*s'\n",
307 (int)obj->en_cols.en_cols_val[i].ec_value.ec_value_len,
308 obj->en_cols.en_cols_val[i].ec_value.ec_value_val);
312 void
313 nis_print_object (const nis_object * obj)
315 time_t buf;
317 printf (_("Object Name : %s\n"), obj->zo_name);
318 printf (_("Directory : %s\n"), obj->zo_domain);
319 printf (_("Owner : %s\n"), obj->zo_owner);
320 printf (_("Group : %s\n"), obj->zo_group);
321 fputs (_("Access Rights : "), stdout);
322 nis_print_rights (obj->zo_access);
323 printf (_("\nTime to Live : "));
324 print_ttl (obj->zo_ttl);
325 buf = obj->zo_oid.ctime;
326 printf (_("Creation Time : %s"), ctime (&buf));
327 buf = obj->zo_oid.mtime;
328 printf (_("Mod. Time : %s"), ctime (&buf));
329 fputs (_("Object Type : "), stdout);
330 nis_print_objtype (obj->zo_data.zo_type);
331 switch (obj->zo_data.zo_type)
333 case NIS_DIRECTORY_OBJ:
334 nis_print_directory (&obj->zo_data.objdata_u.di_data);
335 break;
336 case NIS_GROUP_OBJ:
337 nis_print_group (&obj->zo_data.objdata_u.gr_data);
338 break;
339 case NIS_TABLE_OBJ:
340 nis_print_table (&obj->zo_data.objdata_u.ta_data);
341 break;
342 case NIS_ENTRY_OBJ:
343 nis_print_entry (&obj->zo_data.objdata_u.en_data);
344 break;
345 case NIS_LINK_OBJ:
346 nis_print_link (&obj->zo_data.objdata_u.li_data);
347 break;
348 case NIS_PRIVATE_OBJ:
349 printf (_(" Data Length = %u\n"),
350 obj->zo_data.objdata_u.po_data.po_data_len);
351 break;
352 default:
353 break;
357 void
358 nis_print_result (const nis_result *res)
360 unsigned int i;
362 printf (_("Status : %s\n"), nis_sperrno (NIS_RES_STATUS (res)));
363 printf (_("Number of objects : %u\n"), res->objects.objects_len);
365 for (i = 0; i < res->objects.objects_len; i++)
367 printf (_("Object #%d:\n"), i);
368 nis_print_object (&res->objects.objects_val[i]);