update.
[glibc/history.git] / nis / nis_print.c
blob1914840e86340a6124a3c571a7dfb4aa6f239654
1 /* Copyright (c) 1997 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>
23 #include <rpcsvc/nis.h>
24 #include <rpcsvc/nislib.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 char *
53 nis_ttl2str (const u_long ttl)
55 static char buf[64];
56 unsigned long int time, s, m, h;
58 time = ttl;
60 h = time / (60 * 60);
61 time %= (60 * 60);
62 m = time / 60;
63 time %= 60;
64 s = time;
65 snprintf (buf, 63, "%lu:%02lu:%02lu", h, m, s);
67 return buf;
70 static char *
71 nis_flags2str (const u_long flags)
73 static char buf[1024];
75 snprintf (buf, 1023, "%lu", flags);
77 return buf;
80 static void
81 nis_print_objtype (enum zotypes type)
83 switch (type)
85 case BOGUS_OBJ:
86 fputs (_("BOGUS OBJECT\n"), stdout);
87 break;
88 case NO_OBJ:
89 fputs (_("NO OBJECT\n"), stdout);
90 break;
91 case DIRECTORY_OBJ:
92 fputs (_("DIRECTORY\n"), stdout);
93 break;
94 case GROUP_OBJ:
95 fputs (_("GROUP\n"), stdout);
96 break;
97 case TABLE_OBJ:
98 fputs (_("TABLE\n"), stdout);
99 break;
100 case ENTRY_OBJ:
101 fputs (_("ENTRY\n"), stdout);
102 break;
103 case LINK_OBJ:
104 fputs (_("LINK\n"), stdout);
105 break;
106 case PRIVATE_OBJ:
107 fputs (_("PRIVATE\n"), stdout);
108 break;
109 default:
110 fputs (_("(Unknown object)\n"), stdout);
111 break;
115 void
116 nis_print_rights (const u_long access)
118 char result[17];
119 u_long acc;
120 int i;
122 acc = access; /* Parameter is const ! */
123 result[i = 16] = '\0';
124 while (i > 0)
126 i -= 4;
127 result[i + 0] = (acc & NIS_READ_ACC) ? 'r' : '-';
128 result[i + 1] = (acc & NIS_MODIFY_ACC) ? 'm' : '-';
129 result[i + 2] = (acc & NIS_CREATE_ACC) ? 'c' : '-';
130 result[i + 3] = (acc & NIS_DESTROY_ACC) ? 'd' : '-';
132 acc >>= 8;
134 printf ("%s", result);
137 void
138 nis_print_directory (const directory_obj *dir)
140 nis_server *sptr;
141 unsigned int i;
143 printf (_("Name : '%s'\n"), dir->do_name);
144 printf (_("Type : %s\n"), gettext (nis_nstype2str (dir->do_type)));
145 sptr = dir->do_servers.do_servers_val;
146 for (i = 0; i < dir->do_servers.do_servers_len; i++)
148 if (i == 0)
149 fputs (_("Master Server :\n"), stdout);
150 else
151 fputs (_("Replicate :\n"), stdout);
152 printf (_("\tName : %s\n"), sptr->name);
153 fputs (_("\tPublic Key : "), stdout);
154 switch (sptr->key_type)
156 case NIS_PK_NONE:
157 fputs (_("None.\n"), stdout);
158 break;
159 case NIS_PK_DH:
160 fputs (_("DH.\n"), stdout);
161 break;
162 case NIS_PK_RSA:
163 fputs (_("RSA.\n"), stdout);
164 break;
165 case NIS_PK_KERB:
166 fputs (_("Kerberous.\n"), stdout);
167 break;
168 default:
169 fputs (_("Unknown.\n"), stdout);
170 break;
173 if (sptr->ep.ep_len != 0)
175 unsigned int j;
177 endpoint *ptr;
178 ptr = sptr->ep.ep_val;
179 printf (_("\tUniversal addresses (%u)\n"), sptr->ep.ep_len);
180 for (j = 0; j < sptr->ep.ep_len; j++)
182 printf ("\t[%d] - ", j + 1);
183 if (ptr->proto != NULL && strlen (ptr->proto) > 0)
184 printf ("%s, ", ptr->proto);
185 else
186 printf ("-, ");
187 if (ptr->family != NULL && strlen (ptr->family) > 0)
188 printf ("%s, ", ptr->family);
189 else
190 printf ("-, ");
191 if (ptr->uaddr != NULL && strlen (ptr->uaddr) > 0)
192 printf ("%s\n", ptr->uaddr);
193 else
194 printf ("-\n");
195 ptr++;
198 sptr++;
201 printf (_("Time to live : %s\n"), nis_ttl2str (dir->do_ttl));
202 if (dir->do_armask.do_armask_len != 0)
204 oar_mask *ptr;
206 ptr = dir->do_armask.do_armask_val;
207 for (i = 0; i < dir->do_armask.do_armask_len; i++)
209 fputs (_("Default Access rights: "), stdout);
210 nis_print_rights (ptr->oa_rights);
211 printf (_("\nDirect Type : %d\n"), ptr->oa_otype);
212 ptr++;
217 void
218 nis_print_group (const group_obj *obj)
220 unsigned int i;
222 fputs (_("Group Flags :"), stdout);
223 if (obj->gr_flags)
224 printf ("0x%08lX", obj->gr_flags);
225 fputs (_("\nGroup Members :\n"), stdout);
227 for (i = 0; i < obj->gr_members.gr_members_len; i++)
228 printf ("\t%s\n", obj->gr_members.gr_members_val[i]);
231 void
232 nis_print_table (const table_obj *obj)
234 unsigned int i;
236 printf (_("Table Type : %s\n"), obj->ta_type);
237 printf (_("Number of Columns : %d\n"), obj->ta_maxcol);
238 printf (_("Character Separator : %c\n"), obj->ta_sep);
239 printf (_("Search Path : %s\n"), obj->ta_path);
240 fputs (_("Columns :\n"), stdout);
241 for (i = 0; i < obj->ta_cols.ta_cols_len; i++)
243 printf (_("\t[%d]\tName : %s\n"), i,
244 obj->ta_cols.ta_cols_val[i].tc_name);
245 printf (_("\t\tAttributes : %s\n"),
246 nis_flags2str (obj->ta_cols.ta_cols_val[i].tc_flags));
247 fputs (_("\t\tAccess Rights : "), stdout);
248 nis_print_rights (obj->ta_cols.ta_cols_val[i].tc_rights);
249 fputc ('\n', stdout);
253 void
254 nis_print_link (const link_obj *obj)
256 fputs (_("Linked Object Type : "), stdout);
257 nis_print_objtype (obj->li_rtype);
258 printf (_("Linked to : %s\n"), obj->li_name);
259 /* XXX Print the attributs here, if they exists */
262 void
263 nis_print_entry (const entry_obj *obj)
265 unsigned int i;
267 printf (_("\tEntry data of type %s\n"), obj->en_type);
268 for (i = 0; i < obj->en_cols.en_cols_len; i++)
270 printf (_("\t[%u] - [%u bytes] "), i,
271 obj->en_cols.en_cols_val[i].ec_value.ec_value_len);
272 if ((obj->en_cols.en_cols_val[i].ec_flags & EN_CRYPT) == EN_CRYPT)
273 fputs (_("Encrypted data\n"), stdout);
274 else if ((obj->en_cols.en_cols_val[i].ec_flags & EN_BINARY) == EN_BINARY)
275 fputs (_("Binary data\n"), stdout);
276 else
277 printf ("%s\n", obj->en_cols.en_cols_val[i].ec_value.ec_value_val);
281 void
282 nis_print_object (const nis_object * obj)
284 printf (_("Object Name : %s\n"), obj->zo_name);
285 printf (_("Directory : %s\n"), obj->zo_domain);
286 printf (_("Owner : %s\n"), obj->zo_owner);
287 printf (_("Group : %s\n"), obj->zo_group);
288 fputs (_("Access Rights : "), stdout);
289 nis_print_rights (obj->zo_access);
290 printf (_("\nTime to Live : %lu (seconds)\n"), obj->zo_ttl);
291 printf (_("Creation Time : %s"), ctime (&obj->zo_oid.ctime));
292 printf (_("Mod. Time : %s"), ctime (&obj->zo_oid.mtime));
293 fputs (_("Object Type : "), stdout);
294 nis_print_objtype (obj->zo_data.zo_type);
295 switch (obj->zo_data.zo_type)
297 case DIRECTORY_OBJ:
298 nis_print_directory (&obj->zo_data.objdata_u.di_data);
299 break;
300 case GROUP_OBJ:
301 nis_print_group (&obj->zo_data.objdata_u.gr_data);
302 break;
303 case TABLE_OBJ:
304 nis_print_table (&obj->zo_data.objdata_u.ta_data);
305 break;
306 case ENTRY_OBJ:
307 nis_print_entry (&obj->zo_data.objdata_u.en_data);
308 break;
309 case LINK_OBJ:
310 nis_print_link (&obj->zo_data.objdata_u.li_data);
311 break;
312 case PRIVATE_OBJ:
313 printf (_(" Data Length = %u\n"),
314 obj->zo_data.objdata_u.po_data.po_data_len);
315 break;
316 default:
317 break;
321 void
322 nis_print_result (const nis_result *res)
324 unsigned int i;
326 printf (_("Status : %s\n"), nis_sperrno (res->status));
327 printf (_("Number of objects : %u\n"), res->objects.objects_len);
329 for (i = 0; i < res->objects.objects_len; i++)
331 printf (_("Object #%d:\n"), i);
332 nis_print_object (&res->objects.objects_val[i]);