New test to expose erroneous negative sign on logb(1) (bug 887).
[glibc.git] / nis / nis_print.c
blobc2cffc6d8e694455c3a9bbcdfd7f619bb02a20b2
1 /* Copyright (c) 1997, 1998, 1999, 2004 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 Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <time.h>
20 #include <string.h>
21 #include <libintl.h>
23 #include <rpcsvc/nis.h>
25 static const char *
26 nis_nstype2str (const nstype type)
29 /* Name service names mustn't be translated, only UNKNOWN needs it */
31 switch (type)
33 case NIS:
34 return "NIS";
35 case SUNYP:
36 return "SUNYP";
37 case IVY:
38 return "IVY";
39 case DNS:
40 return "DNS";
41 case X500:
42 return "X500";
43 case DNANS:
44 return "DNANS";
45 case XCHS:
46 return "XCHS";
47 case CDS:
48 return "CDS";
49 default:
50 return N_("UNKNOWN");
54 static void
55 print_ttl (const uint32_t ttl)
57 uint32_t time, s, m, h;
59 time = ttl;
61 h = time / (60 * 60);
62 time %= (60 * 60);
63 m = time / 60;
64 time %= 60;
65 s = time;
66 printf ("%u:%u:%u\n", h, m, s);
69 static void
70 print_flags (const unsigned int flags)
72 fputs ("(", stdout);
74 if (flags & TA_SEARCHABLE)
75 fputs ("SEARCHABLE, ", stdout);
77 if (flags & TA_BINARY)
79 fputs ("BINARY DATA", stdout);
80 if (flags & TA_XDR)
81 fputs (", XDR ENCODED", stdout);
82 if (flags & TA_ASN1)
83 fputs (", ASN.1 ENCODED", stdout);
84 if (flags & TA_CRYPT)
85 fputs (", ENCRYPTED", stdout);
87 else
89 fputs ("TEXTUAL DATA", stdout);
90 if (flags & TA_SEARCHABLE)
92 if (flags & TA_CASE)
93 fputs (", CASE INSENSITIVE", stdout);
94 else
95 fputs (", CASE SENSITIVE", stdout);
99 fputs (")\n", stdout);
102 static void
103 nis_print_objtype (enum zotypes type)
105 switch (type)
107 case NIS_BOGUS_OBJ:
108 fputs (_("BOGUS OBJECT\n"), stdout);
109 break;
110 case NIS_NO_OBJ:
111 fputs (_("NO OBJECT\n"), stdout);
112 break;
113 case NIS_DIRECTORY_OBJ:
114 fputs (_("DIRECTORY\n"), stdout);
115 break;
116 case NIS_GROUP_OBJ:
117 fputs (_("GROUP\n"), stdout);
118 break;
119 case NIS_TABLE_OBJ:
120 fputs (_("TABLE\n"), stdout);
121 break;
122 case NIS_ENTRY_OBJ:
123 fputs (_("ENTRY\n"), stdout);
124 break;
125 case NIS_LINK_OBJ:
126 fputs (_("LINK\n"), stdout);
127 break;
128 case NIS_PRIVATE_OBJ:
129 fputs (_("PRIVATE\n"), stdout);
130 break;
131 default:
132 fputs (_("(Unknown object)\n"), stdout);
133 break;
137 void
138 nis_print_rights (const unsigned int access)
140 char result[17];
141 unsigned int acc;
142 int i;
144 acc = access; /* Parameter is const ! */
145 result[i = 16] = '\0';
146 while (i > 0)
148 i -= 4;
149 result[i + 0] = (acc & NIS_READ_ACC) ? 'r' : '-';
150 result[i + 1] = (acc & NIS_MODIFY_ACC) ? 'm' : '-';
151 result[i + 2] = (acc & NIS_CREATE_ACC) ? 'c' : '-';
152 result[i + 3] = (acc & NIS_DESTROY_ACC) ? 'd' : '-';
154 acc >>= 8;
156 fputs (result, stdout);
158 libnsl_hidden_def (nis_print_rights)
160 void
161 nis_print_directory (const directory_obj *dir)
163 nis_server *sptr;
164 unsigned int i;
166 printf (_("Name : `%s'\n"), dir->do_name);
167 printf (_("Type : %s\n"), nis_nstype2str (dir->do_type));
168 sptr = dir->do_servers.do_servers_val;
169 for (i = 0; i < dir->do_servers.do_servers_len; i++)
171 if (i == 0)
172 fputs (_("Master Server :\n"), stdout);
173 else
174 fputs (_("Replicate :\n"), stdout);
175 printf (_("\tName : %s\n"), sptr->name);
176 fputs (_("\tPublic Key : "), stdout);
177 switch (sptr->key_type)
179 case NIS_PK_NONE:
180 fputs (_("None.\n"), stdout);
181 break;
182 case NIS_PK_DH:
183 printf (_("Diffie-Hellmann (%d bits)\n"),
184 (sptr->pkey.n_len - 1) * 4);
185 /* sptr->pkey.n_len counts the last 0, too */
186 break;
187 case NIS_PK_RSA:
188 printf (_("RSA (%d bits)\n"), (sptr->pkey.n_len - 1) * 4);
189 break;
190 case NIS_PK_KERB:
191 fputs (_("Kerberos.\n"), stdout);
192 break;
193 default:
194 printf (_("Unknown (type = %d, bits = %d)\n"), sptr->key_type,
195 (sptr->pkey.n_len - 1) * 4);
196 break;
199 if (sptr->ep.ep_len != 0)
201 unsigned int j;
203 endpoint *ptr;
204 ptr = sptr->ep.ep_val;
205 printf (_("\tUniversal addresses (%u)\n"), sptr->ep.ep_len);
206 for (j = 0; j < sptr->ep.ep_len; j++)
208 printf ("\t[%d] - ", j + 1);
209 if (ptr->proto != NULL && ptr->proto[0] != '\0')
210 printf ("%s, ", ptr->proto);
211 else
212 printf ("-, ");
213 if (ptr->family != NULL && ptr->family[0] != '\0')
214 printf ("%s, ", ptr->family);
215 else
216 printf ("-, ");
217 if (ptr->uaddr != NULL && ptr->uaddr[0] != '\0')
218 printf ("%s\n", ptr->uaddr);
219 else
220 fputs ("-\n", stdout);
221 ptr++;
224 sptr++;
227 fputs (_("Time to live : "), stdout);
228 print_ttl (dir->do_ttl);
229 fputs (_("Default Access rights :\n"), stdout);
230 if (dir->do_armask.do_armask_len != 0)
232 oar_mask *ptr;
234 ptr = dir->do_armask.do_armask_val;
235 for (i = 0; i < dir->do_armask.do_armask_len; i++)
237 nis_print_rights (ptr->oa_rights);
238 printf (_("\tType : %s\n"), nis_nstype2str (ptr->oa_otype));
239 fputs (_("\tAccess rights: "), stdout);
240 nis_print_rights (ptr->oa_rights);
241 fputs ("\n", stdout);
242 ptr++;
246 libnsl_hidden_def (nis_print_directory)
248 void
249 nis_print_group (const group_obj *obj)
251 unsigned int i;
253 fputs (_("Group Flags :"), stdout);
254 if (obj->gr_flags)
255 printf ("0x%08X", obj->gr_flags);
256 fputs (_("\nGroup Members :\n"), stdout);
258 for (i = 0; i < obj->gr_members.gr_members_len; i++)
259 printf ("\t%s\n", obj->gr_members.gr_members_val[i]);
261 libnsl_hidden_def (nis_print_group)
263 void
264 nis_print_table (const table_obj *obj)
266 unsigned int i;
268 printf (_("Table Type : %s\n"), obj->ta_type);
269 printf (_("Number of Columns : %d\n"), obj->ta_maxcol);
270 printf (_("Character Separator : %c\n"), obj->ta_sep);
271 printf (_("Search Path : %s\n"), obj->ta_path);
272 fputs (_("Columns :\n"), stdout);
273 for (i = 0; i < obj->ta_cols.ta_cols_len; i++)
275 printf (_("\t[%d]\tName : %s\n"), i,
276 obj->ta_cols.ta_cols_val[i].tc_name);
277 fputs (_("\t\tAttributes : "), stdout);
278 print_flags (obj->ta_cols.ta_cols_val[i].tc_flags);
279 fputs (_("\t\tAccess Rights : "), stdout);
280 nis_print_rights (obj->ta_cols.ta_cols_val[i].tc_rights);
281 fputc ('\n', stdout);
284 libnsl_hidden_def (nis_print_table)
286 void
287 nis_print_link (const link_obj *obj)
289 fputs (_("Linked Object Type : "), stdout);
290 nis_print_objtype (obj->li_rtype);
291 printf (_("Linked to : %s\n"), obj->li_name);
292 /* XXX Print the attributs here, if they exists */
294 libnsl_hidden_def (nis_print_link)
296 void
297 nis_print_entry (const entry_obj *obj)
299 unsigned int i;
301 printf (_("\tEntry data of type %s\n"), obj->en_type);
302 for (i = 0; i < obj->en_cols.en_cols_len; i++)
304 printf (_("\t[%u] - [%u bytes] "), i,
305 obj->en_cols.en_cols_val[i].ec_value.ec_value_len);
306 if ((obj->en_cols.en_cols_val[i].ec_flags & EN_CRYPT) == EN_CRYPT)
307 fputs (_("Encrypted data\n"), stdout);
308 else if ((obj->en_cols.en_cols_val[i].ec_flags & EN_BINARY) == EN_BINARY)
309 fputs (_("Binary data\n"), stdout);
310 else if (obj->en_cols.en_cols_val[i].ec_value.ec_value_len == 0)
311 fputs ("'(nil)'\n", stdout);
312 else
313 printf ("'%.*s'\n",
314 (int)obj->en_cols.en_cols_val[i].ec_value.ec_value_len,
315 obj->en_cols.en_cols_val[i].ec_value.ec_value_val);
318 libnsl_hidden_def (nis_print_entry)
320 void
321 nis_print_object (const nis_object * obj)
323 time_t buf;
325 printf (_("Object Name : %s\n"), obj->zo_name);
326 printf (_("Directory : %s\n"), obj->zo_domain);
327 printf (_("Owner : %s\n"), obj->zo_owner);
328 printf (_("Group : %s\n"), obj->zo_group);
329 fputs (_("Access Rights : "), stdout);
330 nis_print_rights (obj->zo_access);
331 printf (_("\nTime to Live : "));
332 print_ttl (obj->zo_ttl);
333 buf = obj->zo_oid.ctime;
334 printf (_("Creation Time : %s"), ctime (&buf));
335 buf = obj->zo_oid.mtime;
336 printf (_("Mod. Time : %s"), ctime (&buf));
337 fputs (_("Object Type : "), stdout);
338 nis_print_objtype (obj->zo_data.zo_type);
339 switch (obj->zo_data.zo_type)
341 case NIS_DIRECTORY_OBJ:
342 nis_print_directory (&obj->zo_data.objdata_u.di_data);
343 break;
344 case NIS_GROUP_OBJ:
345 nis_print_group (&obj->zo_data.objdata_u.gr_data);
346 break;
347 case NIS_TABLE_OBJ:
348 nis_print_table (&obj->zo_data.objdata_u.ta_data);
349 break;
350 case NIS_ENTRY_OBJ:
351 nis_print_entry (&obj->zo_data.objdata_u.en_data);
352 break;
353 case NIS_LINK_OBJ:
354 nis_print_link (&obj->zo_data.objdata_u.li_data);
355 break;
356 case NIS_PRIVATE_OBJ:
357 printf (_(" Data Length = %u\n"),
358 obj->zo_data.objdata_u.po_data.po_data_len);
359 break;
360 default:
361 break;
364 libnsl_hidden_def (nis_print_object)
366 void
367 nis_print_result (const nis_result *res)
369 unsigned int i;
371 printf (_("Status : %s\n"), nis_sperrno (NIS_RES_STATUS (res)));
372 printf (_("Number of objects : %u\n"), res->objects.objects_len);
374 for (i = 0; i < res->objects.objects_len; i++)
376 printf (_("Object #%d:\n"), i);
377 nis_print_object (&res->objects.objects_val[i]);