1 /* Copyright (c) 1997-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
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.
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
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
23 #include <rpcsvc/nis.h>
24 #include <shlib-compat.h>
27 nis_nstype2str (const nstype type
)
30 /* Name service names mustn't be translated, only UNKNOWN needs it */
56 nis_objtype (const zotypes type
)
61 return _("BOGUS OBJECT");
63 return _("NO OBJECT");
64 case NIS_DIRECTORY_OBJ
:
65 return _("DIRECTORY");
75 return _("PRIVATE\n");
77 return _("(Unknown object");
82 print_ttl (const uint32_t ttl
)
84 uint32_t time
, s
, m
, h
;
93 printf ("%u:%u:%u\n", h
, m
, s
);
97 print_flags (const unsigned int flags
)
101 if (flags
& TA_SEARCHABLE
)
102 fputs ("SEARCHABLE, ", stdout
);
104 if (flags
& TA_BINARY
)
106 fputs ("BINARY DATA", stdout
);
108 fputs (", XDR ENCODED", stdout
);
110 fputs (", ASN.1 ENCODED", stdout
);
111 if (flags
& TA_CRYPT
)
112 fputs (", ENCRYPTED", stdout
);
116 fputs ("TEXTUAL DATA", stdout
);
117 if (flags
& TA_SEARCHABLE
)
120 fputs (", CASE INSENSITIVE", stdout
);
122 fputs (", CASE SENSITIVE", stdout
);
126 fputs (")\n", stdout
);
130 nis_print_objtype (enum zotypes type
)
132 printf ("%s\n", nis_objtype (type
));
136 nis_print_rights (const unsigned int access
)
142 acc
= access
; /* Parameter is const ! */
143 result
[i
= 16] = '\0';
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' : '-';
154 fputs (result
, stdout
);
156 libnsl_hidden_nolink_def (nis_print_rights
, GLIBC_2_1
)
159 nis_print_directory (const directory_obj
*dir
)
164 printf (_("Name : `%s'\n"), dir
->do_name
);
165 printf (_("Type : %s\n"), nis_nstype2str (dir
->do_type
));
166 sptr
= dir
->do_servers
.do_servers_val
;
167 for (i
= 0; i
< dir
->do_servers
.do_servers_len
; i
++)
170 fputs (_("Master Server :\n"), stdout
);
172 fputs (_("Replicate :\n"), stdout
);
173 printf (_("\tName : %s\n"), sptr
->name
);
174 fputs (_("\tPublic Key : "), stdout
);
175 switch (sptr
->key_type
)
178 fputs (_("None.\n"), stdout
);
181 printf (_("Diffie-Hellmann (%d bits)\n"),
182 (sptr
->pkey
.n_len
- 1) * 4);
183 /* sptr->pkey.n_len counts the last 0, too */
186 printf (_("RSA (%d bits)\n"), (sptr
->pkey
.n_len
- 1) * 4);
189 fputs (_("Kerberos.\n"), stdout
);
192 printf (_("Unknown (type = %d, bits = %d)\n"), sptr
->key_type
,
193 (sptr
->pkey
.n_len
- 1) * 4);
197 if (sptr
->ep
.ep_len
!= 0)
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
++)
206 printf ("\t[%d] - ", j
+ 1);
207 if (ptr
->proto
!= NULL
&& ptr
->proto
[0] != '\0')
208 printf ("%s, ", ptr
->proto
);
211 if (ptr
->family
!= NULL
&& ptr
->family
[0] != '\0')
212 printf ("%s, ", ptr
->family
);
215 if (ptr
->uaddr
!= NULL
&& ptr
->uaddr
[0] != '\0')
216 printf ("%s\n", ptr
->uaddr
);
218 fputs ("-\n", stdout
);
225 fputs (_("Time to live : "), stdout
);
226 print_ttl (dir
->do_ttl
);
227 fputs (_("Default Access rights :\n"), stdout
);
228 if (dir
->do_armask
.do_armask_len
!= 0)
232 ptr
= dir
->do_armask
.do_armask_val
;
233 for (i
= 0; i
< dir
->do_armask
.do_armask_len
; i
++)
235 nis_print_rights (ptr
->oa_rights
);
236 printf (_("\tType : %s\n"), nis_objtype (ptr
->oa_otype
));
237 fputs (_("\tAccess rights: "), stdout
);
238 nis_print_rights (ptr
->oa_rights
);
239 fputs ("\n", stdout
);
244 libnsl_hidden_nolink_def (nis_print_directory
, GLIBC_2_1
)
247 nis_print_group (const group_obj
*obj
)
251 fputs (_("Group Flags :"), stdout
);
253 printf ("0x%08X", obj
->gr_flags
);
254 fputs (_("\nGroup Members :\n"), stdout
);
256 for (i
= 0; i
< obj
->gr_members
.gr_members_len
; i
++)
257 printf ("\t%s\n", obj
->gr_members
.gr_members_val
[i
]);
259 libnsl_hidden_nolink_def (nis_print_group
, GLIBC_2_1
)
262 nis_print_table (const table_obj
*obj
)
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
++)
273 printf (_("\t[%d]\tName : %s\n"), i
,
274 obj
->ta_cols
.ta_cols_val
[i
].tc_name
);
275 fputs (_("\t\tAttributes : "), stdout
);
276 print_flags (obj
->ta_cols
.ta_cols_val
[i
].tc_flags
);
277 fputs (_("\t\tAccess Rights : "), stdout
);
278 nis_print_rights (obj
->ta_cols
.ta_cols_val
[i
].tc_rights
);
279 fputc ('\n', stdout
);
282 libnsl_hidden_nolink_def (nis_print_table
, GLIBC_2_1
)
285 nis_print_link (const link_obj
*obj
)
287 fputs (_("Linked Object Type : "), stdout
);
288 nis_print_objtype (obj
->li_rtype
);
289 printf (_("Linked to : %s\n"), obj
->li_name
);
290 /* XXX Print the attributes here, if they exists */
292 libnsl_hidden_nolink_def (nis_print_link
, GLIBC_2_1
)
295 nis_print_entry (const entry_obj
*obj
)
299 printf (_("\tEntry data of type %s\n"), obj
->en_type
);
300 for (i
= 0; i
< obj
->en_cols
.en_cols_len
; i
++)
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
);
308 else if (obj
->en_cols
.en_cols_val
[i
].ec_value
.ec_value_len
== 0)
309 fputs ("'(nil)'\n", stdout
);
312 (int)obj
->en_cols
.en_cols_val
[i
].ec_value
.ec_value_len
,
313 obj
->en_cols
.en_cols_val
[i
].ec_value
.ec_value_val
);
316 libnsl_hidden_nolink_def (nis_print_entry
, GLIBC_2_1
)
319 nis_print_object (const nis_object
* obj
)
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
);
329 printf (_("\nTime to Live : "));
330 print_ttl (obj
->zo_ttl
);
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
));
335 fputs (_("Object Type : "), stdout
);
336 nis_print_objtype (obj
->zo_data
.zo_type
);
337 switch (obj
->zo_data
.zo_type
)
339 case NIS_DIRECTORY_OBJ
:
340 nis_print_directory (&obj
->zo_data
.objdata_u
.di_data
);
343 nis_print_group (&obj
->zo_data
.objdata_u
.gr_data
);
346 nis_print_table (&obj
->zo_data
.objdata_u
.ta_data
);
349 nis_print_entry (&obj
->zo_data
.objdata_u
.en_data
);
352 nis_print_link (&obj
->zo_data
.objdata_u
.li_data
);
354 case NIS_PRIVATE_OBJ
:
355 printf (_(" Data Length = %u\n"),
356 obj
->zo_data
.objdata_u
.po_data
.po_data_len
);
362 libnsl_hidden_nolink_def (nis_print_object
, GLIBC_2_1
)
365 nis_print_result (const nis_result
*res
)
369 printf (_("Status : %s\n"), nis_sperrno (NIS_RES_STATUS (res
)));
370 printf (_("Number of objects : %u\n"), res
->objects
.objects_len
);
372 for (i
= 0; i
< res
->objects
.objects_len
; i
++)
374 printf (_("Object #%d:\n"), i
);
375 nis_print_object (&res
->objects
.objects_val
[i
]);
378 libnsl_hidden_nolink_def (nis_print_result
, GLIBC_2_1
)