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