Use GMP 6.2.1 in build-many-glibcs.py.
[glibc.git] / nis / nis_print.c
blob1182d874c650d9dc7f2aeb3cbdee45ebc351f825
1 /* Copyright (c) 1997-2020 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 <https://www.gnu.org/licenses/>. */
19 #include <time.h>
20 #include <string.h>
21 #include <libintl.h>
22 #include <stdint.h>
24 #include <rpcsvc/nis.h>
25 #include <shlib-compat.h>
27 static const char *
28 nis_nstype2str (const nstype type)
31 /* Name service names mustn't be translated, only UNKNOWN needs it */
33 switch (type)
35 case NIS:
36 return "NIS";
37 case SUNYP:
38 return "SUNYP";
39 case IVY:
40 return "IVY";
41 case DNS:
42 return "DNS";
43 case X500:
44 return "X500";
45 case DNANS:
46 return "DNANS";
47 case XCHS:
48 return "XCHS";
49 case CDS:
50 return "CDS";
51 default:
52 return N_("UNKNOWN");
56 static void
57 print_ttl (const uint32_t ttl)
59 uint32_t time, s, m, h;
61 time = ttl;
63 h = time / (60 * 60);
64 time %= (60 * 60);
65 m = time / 60;
66 time %= 60;
67 s = time;
68 printf ("%u:%u:%u\n", h, m, s);
71 static void
72 print_flags (const unsigned int flags)
74 fputs ("(", stdout);
76 if (flags & TA_SEARCHABLE)
77 fputs ("SEARCHABLE, ", stdout);
79 if (flags & TA_BINARY)
81 fputs ("BINARY DATA", stdout);
82 if (flags & TA_XDR)
83 fputs (", XDR ENCODED", stdout);
84 if (flags & TA_ASN1)
85 fputs (", ASN.1 ENCODED", stdout);
86 if (flags & TA_CRYPT)
87 fputs (", ENCRYPTED", stdout);
89 else
91 fputs ("TEXTUAL DATA", stdout);
92 if (flags & TA_SEARCHABLE)
94 if (flags & TA_CASE)
95 fputs (", CASE INSENSITIVE", stdout);
96 else
97 fputs (", CASE SENSITIVE", stdout);
101 fputs (")\n", stdout);
104 static void
105 nis_print_objtype (enum zotypes type)
107 switch (type)
109 case NIS_BOGUS_OBJ:
110 fputs (_("BOGUS OBJECT\n"), stdout);
111 break;
112 case NIS_NO_OBJ:
113 fputs (_("NO OBJECT\n"), stdout);
114 break;
115 case NIS_DIRECTORY_OBJ:
116 fputs (_("DIRECTORY\n"), stdout);
117 break;
118 case NIS_GROUP_OBJ:
119 fputs (_("GROUP\n"), stdout);
120 break;
121 case NIS_TABLE_OBJ:
122 fputs (_("TABLE\n"), stdout);
123 break;
124 case NIS_ENTRY_OBJ:
125 fputs (_("ENTRY\n"), stdout);
126 break;
127 case NIS_LINK_OBJ:
128 fputs (_("LINK\n"), stdout);
129 break;
130 case NIS_PRIVATE_OBJ:
131 fputs (_("PRIVATE\n"), stdout);
132 break;
133 default:
134 fputs (_("(Unknown object)\n"), stdout);
135 break;
139 void
140 nis_print_rights (const unsigned int access)
142 char result[17];
143 unsigned int acc;
144 int i;
146 acc = access; /* Parameter is const ! */
147 result[i = 16] = '\0';
148 while (i > 0)
150 i -= 4;
151 result[i + 0] = (acc & NIS_READ_ACC) ? 'r' : '-';
152 result[i + 1] = (acc & NIS_MODIFY_ACC) ? 'm' : '-';
153 result[i + 2] = (acc & NIS_CREATE_ACC) ? 'c' : '-';
154 result[i + 3] = (acc & NIS_DESTROY_ACC) ? 'd' : '-';
156 acc >>= 8;
158 fputs (result, stdout);
160 libnsl_hidden_nolink_def (nis_print_rights, GLIBC_2_1)
162 void
163 nis_print_directory (const directory_obj *dir)
165 nis_server *sptr;
166 unsigned int i;
168 printf (_("Name : `%s'\n"), dir->do_name);
169 printf (_("Type : %s\n"), nis_nstype2str (dir->do_type));
170 sptr = dir->do_servers.do_servers_val;
171 for (i = 0; i < dir->do_servers.do_servers_len; i++)
173 if (i == 0)
174 fputs (_("Master Server :\n"), stdout);
175 else
176 fputs (_("Replicate :\n"), stdout);
177 printf (_("\tName : %s\n"), sptr->name);
178 fputs (_("\tPublic Key : "), stdout);
179 switch (sptr->key_type)
181 case NIS_PK_NONE:
182 fputs (_("None.\n"), stdout);
183 break;
184 case NIS_PK_DH:
185 printf (_("Diffie-Hellmann (%d bits)\n"),
186 (sptr->pkey.n_len - 1) * 4);
187 /* sptr->pkey.n_len counts the last 0, too */
188 break;
189 case NIS_PK_RSA:
190 printf (_("RSA (%d bits)\n"), (sptr->pkey.n_len - 1) * 4);
191 break;
192 case NIS_PK_KERB:
193 fputs (_("Kerberos.\n"), stdout);
194 break;
195 default:
196 printf (_("Unknown (type = %d, bits = %d)\n"), sptr->key_type,
197 (sptr->pkey.n_len - 1) * 4);
198 break;
201 if (sptr->ep.ep_len != 0)
203 unsigned int j;
205 endpoint *ptr;
206 ptr = sptr->ep.ep_val;
207 printf (_("\tUniversal addresses (%u)\n"), sptr->ep.ep_len);
208 for (j = 0; j < sptr->ep.ep_len; j++)
210 printf ("\t[%d] - ", j + 1);
211 if (ptr->proto != NULL && ptr->proto[0] != '\0')
212 printf ("%s, ", ptr->proto);
213 else
214 printf ("-, ");
215 if (ptr->family != NULL && ptr->family[0] != '\0')
216 printf ("%s, ", ptr->family);
217 else
218 printf ("-, ");
219 if (ptr->uaddr != NULL && ptr->uaddr[0] != '\0')
220 printf ("%s\n", ptr->uaddr);
221 else
222 fputs ("-\n", stdout);
223 ptr++;
226 sptr++;
229 fputs (_("Time to live : "), stdout);
230 print_ttl (dir->do_ttl);
231 fputs (_("Default Access rights :\n"), stdout);
232 if (dir->do_armask.do_armask_len != 0)
234 oar_mask *ptr;
236 ptr = dir->do_armask.do_armask_val;
237 for (i = 0; i < dir->do_armask.do_armask_len; i++)
239 nis_print_rights (ptr->oa_rights);
240 printf (_("\tType : %s\n"), nis_nstype2str (ptr->oa_otype));
241 fputs (_("\tAccess rights: "), stdout);
242 nis_print_rights (ptr->oa_rights);
243 fputs ("\n", stdout);
244 ptr++;
248 libnsl_hidden_nolink_def (nis_print_directory, GLIBC_2_1)
250 void
251 nis_print_group (const group_obj *obj)
253 unsigned int i;
255 fputs (_("Group Flags :"), stdout);
256 if (obj->gr_flags)
257 printf ("0x%08X", obj->gr_flags);
258 fputs (_("\nGroup Members :\n"), stdout);
260 for (i = 0; i < obj->gr_members.gr_members_len; i++)
261 printf ("\t%s\n", obj->gr_members.gr_members_val[i]);
263 libnsl_hidden_nolink_def (nis_print_group, GLIBC_2_1)
265 void
266 nis_print_table (const table_obj *obj)
268 unsigned int i;
270 printf (_("Table Type : %s\n"), obj->ta_type);
271 printf (_("Number of Columns : %d\n"), obj->ta_maxcol);
272 printf (_("Character Separator : %c\n"), obj->ta_sep);
273 printf (_("Search Path : %s\n"), obj->ta_path);
274 fputs (_("Columns :\n"), stdout);
275 for (i = 0; i < obj->ta_cols.ta_cols_len; i++)
277 printf (_("\t[%d]\tName : %s\n"), i,
278 obj->ta_cols.ta_cols_val[i].tc_name);
279 fputs (_("\t\tAttributes : "), stdout);
280 print_flags (obj->ta_cols.ta_cols_val[i].tc_flags);
281 fputs (_("\t\tAccess Rights : "), stdout);
282 nis_print_rights (obj->ta_cols.ta_cols_val[i].tc_rights);
283 fputc ('\n', stdout);
286 libnsl_hidden_nolink_def (nis_print_table, GLIBC_2_1)
288 void
289 nis_print_link (const link_obj *obj)
291 fputs (_("Linked Object Type : "), stdout);
292 nis_print_objtype (obj->li_rtype);
293 printf (_("Linked to : %s\n"), obj->li_name);
294 /* XXX Print the attributes here, if they exists */
296 libnsl_hidden_nolink_def (nis_print_link, GLIBC_2_1)
298 void
299 nis_print_entry (const entry_obj *obj)
301 unsigned int i;
303 printf (_("\tEntry data of type %s\n"), obj->en_type);
304 for (i = 0; i < obj->en_cols.en_cols_len; i++)
306 printf (_("\t[%u] - [%u bytes] "), i,
307 obj->en_cols.en_cols_val[i].ec_value.ec_value_len);
308 if ((obj->en_cols.en_cols_val[i].ec_flags & EN_CRYPT) == EN_CRYPT)
309 fputs (_("Encrypted data\n"), stdout);
310 else if ((obj->en_cols.en_cols_val[i].ec_flags & EN_BINARY) == EN_BINARY)
311 fputs (_("Binary data\n"), stdout);
312 else if (obj->en_cols.en_cols_val[i].ec_value.ec_value_len == 0)
313 fputs ("'(nil)'\n", stdout);
314 else
315 printf ("'%.*s'\n",
316 (int)obj->en_cols.en_cols_val[i].ec_value.ec_value_len,
317 obj->en_cols.en_cols_val[i].ec_value.ec_value_val);
320 libnsl_hidden_nolink_def (nis_print_entry, GLIBC_2_1)
322 void
323 nis_print_object (const nis_object * obj)
325 time_t buf;
327 printf (_("Object Name : %s\n"), obj->zo_name);
328 printf (_("Directory : %s\n"), obj->zo_domain);
329 printf (_("Owner : %s\n"), obj->zo_owner);
330 printf (_("Group : %s\n"), obj->zo_group);
331 fputs (_("Access Rights : "), stdout);
332 nis_print_rights (obj->zo_access);
333 printf (_("\nTime to Live : "));
334 print_ttl (obj->zo_ttl);
335 buf = obj->zo_oid.ctime;
336 printf (_("Creation Time : %s"), ctime (&buf));
337 buf = obj->zo_oid.mtime;
338 printf (_("Mod. Time : %s"), ctime (&buf));
339 fputs (_("Object Type : "), stdout);
340 nis_print_objtype (obj->zo_data.zo_type);
341 switch (obj->zo_data.zo_type)
343 case NIS_DIRECTORY_OBJ:
344 nis_print_directory (&obj->zo_data.objdata_u.di_data);
345 break;
346 case NIS_GROUP_OBJ:
347 nis_print_group (&obj->zo_data.objdata_u.gr_data);
348 break;
349 case NIS_TABLE_OBJ:
350 nis_print_table (&obj->zo_data.objdata_u.ta_data);
351 break;
352 case NIS_ENTRY_OBJ:
353 nis_print_entry (&obj->zo_data.objdata_u.en_data);
354 break;
355 case NIS_LINK_OBJ:
356 nis_print_link (&obj->zo_data.objdata_u.li_data);
357 break;
358 case NIS_PRIVATE_OBJ:
359 printf (_(" Data Length = %u\n"),
360 obj->zo_data.objdata_u.po_data.po_data_len);
361 break;
362 default:
363 break;
366 libnsl_hidden_nolink_def (nis_print_object, GLIBC_2_1)
368 void
369 nis_print_result (const nis_result *res)
371 unsigned int i;
373 printf (_("Status : %s\n"), nis_sperrno (NIS_RES_STATUS (res)));
374 printf (_("Number of objects : %u\n"), res->objects.objects_len);
376 for (i = 0; i < res->objects.objects_len; i++)
378 printf (_("Object #%d:\n"), i);
379 nis_print_object (&res->objects.objects_val[i]);
382 libnsl_hidden_nolink_def (nis_print_result, GLIBC_2_1)