]>
Commit | Line | Data |
---|---|---|
e61abf83 UD |
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. | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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. */ | |
19 | ||
20 | #include <time.h> | |
21 | #include <rpcsvc/nis.h> | |
22 | #include <rpcsvc/nislib.h> | |
23 | ||
24 | static const char * | |
25 | nis_nstype2str (const nstype type) | |
26 | { | |
27 | switch (type) | |
28 | { | |
29 | case NIS: | |
30 | return N_("NIS"); | |
31 | case SUNYP: | |
32 | return N_("SUNYP"); | |
33 | case IVY: | |
34 | return N_("IVY"); | |
35 | case DNS: | |
36 | return N_("DNS"); | |
37 | case X500: | |
38 | return N_("X500"); | |
39 | case DNANS: | |
40 | return N_("DNANS"); | |
41 | case XCHS: | |
42 | return N_("XCHS"); | |
43 | case CDS: | |
44 | return N_("CDS"); | |
45 | default: | |
46 | return N_("UNKNOWN"); | |
47 | } | |
48 | } | |
49 | ||
50 | static char * | |
51 | nis_ttl2str (const u_long ttl) | |
52 | { | |
53 | static char buf[64]; | |
54 | unsigned long int time, s, m, h; | |
55 | ||
56 | time = ttl; | |
57 | ||
58 | h = time / (60 * 60); | |
59 | time %= (60 * 60); | |
60 | m = time / 60; | |
61 | time %= 60; | |
62 | s = time; | |
63 | snprintf (buf, 63, "%lu:%02lu:%02lu", h, m, s); | |
64 | ||
65 | return buf; | |
66 | } | |
67 | ||
68 | static char * | |
69 | nis_flags2str (const u_long flags) | |
70 | { | |
71 | static char buf[1024]; | |
72 | ||
73 | snprintf (buf, 1023, "%lu", flags); | |
74 | ||
75 | return buf; | |
76 | } | |
77 | ||
78 | void | |
79 | nis_print_rights (const u_long access) | |
80 | { | |
81 | char result[17]; | |
82 | u_long acc; | |
83 | int i; | |
84 | ||
85 | acc = access; /* Parameter is const ! */ | |
86 | result[i = 16] = '\0'; | |
87 | while (i > 0) | |
88 | { | |
89 | i -= 4; | |
90 | result[i + 0] = (acc & NIS_READ_ACC) ? 'r' : '-'; | |
91 | result[i + 1] = (acc & NIS_MODIFY_ACC) ? 'm' : '-'; | |
92 | result[i + 2] = (acc & NIS_CREATE_ACC) ? 'c' : '-'; | |
93 | result[i + 3] = (acc & NIS_DESTROY_ACC) ? 'd' : '-'; | |
94 | ||
95 | acc >>= 8; | |
96 | } | |
97 | printf ("%s", result); | |
98 | } | |
99 | ||
100 | void | |
101 | nis_print_directory (const directory_obj *dir) | |
102 | { | |
103 | nis_server *sptr; | |
104 | unsigned int i; | |
105 | ||
106 | printf (_("Name : '%s'\n"), dir->do_name); | |
107 | printf (_("Type : %s\n"), gettext (nis_nstype2str (dir->do_type))); | |
108 | sptr = dir->do_servers.do_servers_val; | |
109 | for (i = 0; i < dir->do_servers.do_servers_len; i++) | |
110 | { | |
111 | if (i == 0) | |
112 | fputs (_("Master Server :\n"), stdout); | |
113 | else | |
114 | fputs (_("Replicate :\n"), stdout); | |
115 | printf (_("\tName : %s\n"), sptr->name); | |
116 | fputs (_("\tPublic Key : "), stdout); | |
117 | switch (sptr->key_type) | |
118 | { | |
119 | case NIS_PK_NONE: | |
120 | fputs (_("None.\n"), stdout); | |
121 | break; | |
122 | case NIS_PK_DH: | |
123 | fputs (_("DH.\n"), stdout); | |
124 | break; | |
125 | case NIS_PK_RSA: | |
126 | fputs (_("RSA.\n"), stdout); | |
127 | break; | |
128 | case NIS_PK_KERB: | |
129 | fputs (_("Kerberous.\n"), stdout); | |
130 | break; | |
131 | default: | |
132 | fputs (_("Unknown.\n"), stdout); | |
133 | break; | |
134 | } | |
135 | ||
136 | if (sptr->ep.ep_len != 0) | |
137 | { | |
138 | unsigned int j; | |
139 | ||
140 | endpoint *ptr; | |
141 | ptr = sptr->ep.ep_val; | |
142 | printf (_("\tUniversal addresses (%u)\n"), sptr->ep.ep_len); | |
143 | for (j = 0; j < sptr->ep.ep_len; j++) | |
144 | { | |
145 | printf ("\t[%d] - ", j + 1); | |
146 | if (ptr->proto != NULL && strlen (ptr->proto) > 0) | |
147 | printf ("%s, ", ptr->proto); | |
148 | else | |
149 | printf ("-, "); | |
150 | if (ptr->family != NULL && strlen (ptr->family) > 0) | |
151 | printf ("%s, ", ptr->family); | |
152 | else | |
153 | printf ("-, "); | |
154 | if (ptr->uaddr != NULL && strlen (ptr->uaddr) > 0) | |
155 | printf ("%s\n", ptr->uaddr); | |
156 | else | |
157 | printf ("-\n"); | |
158 | ptr++; | |
159 | } | |
160 | } | |
161 | sptr++; | |
162 | } | |
163 | ||
164 | printf (_("Time to live : %s\n"), nis_ttl2str (dir->do_ttl)); | |
165 | if (dir->do_armask.do_armask_len != 0) | |
166 | { | |
167 | oar_mask *ptr; | |
168 | ||
169 | ptr = dir->do_armask.do_armask_val; | |
170 | for (i = 0; i < dir->do_armask.do_armask_len; i++) | |
171 | { | |
172 | fputs (_("Default Access rights: "), stdout); | |
173 | nis_print_rights (ptr->oa_rights); | |
174 | printf (_("\nDirect Type : %d\n"), ptr->oa_otype); | |
175 | ptr++; | |
176 | } | |
177 | } | |
178 | } | |
179 | ||
180 | void | |
181 | nis_print_group (const group_obj *obj) | |
182 | { | |
183 | unsigned int i; | |
184 | ||
185 | fputs (_("Group Flags :"), stdout); | |
186 | if (obj->gr_flags) | |
187 | printf ("0x%08lX", obj->gr_flags); | |
188 | fputs (_("\nGroup Members :\n"), stdout); | |
189 | ||
190 | for (i = 0; i < obj->gr_members.gr_members_len; i++) | |
191 | printf ("\t%s\n", obj->gr_members.gr_members_val[i]); | |
192 | } | |
193 | ||
194 | void | |
195 | nis_print_table (const table_obj *obj) | |
196 | { | |
197 | unsigned int i; | |
198 | ||
199 | printf (_("Table Type : %s\n"), obj->ta_type); | |
200 | printf (_("Number of Columns : %d\n"), obj->ta_maxcol); | |
201 | printf (_("Character Separator : %c\n"), obj->ta_sep); | |
202 | printf (_("Search Path : %s\n"), obj->ta_path); | |
203 | fputs (_("Columns :\n"), stdout); | |
204 | for (i = 0; i < obj->ta_cols.ta_cols_len; i++) | |
205 | { | |
206 | printf (_("\t[%d]\tName : %s\n"), i, | |
207 | obj->ta_cols.ta_cols_val[i].tc_name); | |
208 | printf (_("\t\tAttributes : %s\n"), | |
209 | nis_flags2str (obj->ta_cols.ta_cols_val[i].tc_flags)); | |
210 | fputs (_("\t\tAccess Rights : "), stdout); | |
211 | nis_print_rights (obj->ta_cols.ta_cols_val[i].tc_rights); | |
212 | fputc ('\n', stdout); | |
213 | } | |
214 | } | |
215 | ||
216 | void | |
217 | nis_print_link (const link_obj *obj) | |
218 | { | |
219 | printf (_("Type : %d\n"), obj->li_rtype); | |
220 | printf (_("Name : %s\n"), obj->li_name); | |
221 | printf (_("Attributes : %d\n"), obj->li_attrs.li_attrs_len); | |
222 | } | |
223 | ||
224 | void | |
225 | nis_print_entry (const entry_obj *obj) | |
226 | { | |
227 | unsigned int i; | |
228 | ||
229 | printf (_("\tEntry data of type %s\n"), obj->en_type); | |
230 | for (i = 0; i < obj->en_cols.en_cols_len; i++) | |
231 | { | |
232 | printf (_("\t[%u] - [%u bytes] "), i, | |
233 | obj->en_cols.en_cols_val[i].ec_value.ec_value_len); | |
234 | if ((obj->en_cols.en_cols_val[i].ec_flags & EN_CRYPT) == EN_CRYPT) | |
235 | fputs (_("Encrypted data\n"), stdout); | |
236 | else if ((obj->en_cols.en_cols_val[i].ec_flags & EN_BINARY) == EN_BINARY) | |
237 | fputs (_("Binary data\n"), stdout); | |
238 | else | |
239 | printf ("%s\n", obj->en_cols.en_cols_val[i].ec_value.ec_value_val); | |
240 | } | |
241 | } | |
242 | ||
243 | void | |
244 | nis_print_object (const nis_object * obj) | |
245 | { | |
246 | printf (_("Object Name : %s\n"), obj->zo_name); | |
247 | printf (_("Directory : %s\n"), obj->zo_domain); | |
248 | printf (_("Owner : %s\n"), obj->zo_owner); | |
249 | printf (_("Group : %s\n"), obj->zo_group); | |
250 | fputs (_("Access Rights : "), stdout); | |
251 | nis_print_rights (obj->zo_access); | |
252 | printf (_("\nTime to Live : %lu (seconds)\n"), obj->zo_ttl); | |
253 | printf (_("Creation Time : %s"), ctime (&obj->zo_oid.ctime)); | |
254 | printf (_("Mod. Time : %s"), ctime (&obj->zo_oid.mtime)); | |
255 | fputs (_("Object Type : "), stdout); | |
256 | switch (obj->zo_data.zo_type) | |
257 | { | |
258 | case BOGUS_OBJ: | |
259 | fputs (_("BOGUS OBJECT\n"), stdout); | |
260 | break; | |
261 | case NO_OBJ: | |
262 | fputs (_("NO OBJECT\n"), stdout); | |
263 | break; | |
264 | case DIRECTORY_OBJ: | |
265 | fputs (_("DIRECTORY\n"), stdout); | |
266 | nis_print_directory (&obj->zo_data.objdata_u.di_data); | |
267 | break; | |
268 | case GROUP_OBJ: | |
269 | fputs (_("GROUP\n"), stdout); | |
270 | nis_print_group (&obj->zo_data.objdata_u.gr_data); | |
271 | break; | |
272 | case TABLE_OBJ: | |
273 | fputs (_("TABLE\n"), stdout); | |
274 | nis_print_table (&obj->zo_data.objdata_u.ta_data); | |
275 | break; | |
276 | case ENTRY_OBJ: | |
277 | fputs (_("ENTRY\n"), stdout); | |
278 | nis_print_entry (&obj->zo_data.objdata_u.en_data); | |
279 | break; | |
280 | case LINK_OBJ: | |
281 | fputs (_("LINK\n"), stdout); | |
282 | nis_print_link (&obj->zo_data.objdata_u.li_data); | |
283 | break; | |
284 | case PRIVATE_OBJ: | |
285 | fputs (_("PRIVATE\n"), stdout); | |
286 | printf (_(" Data Length = %u\n"), | |
287 | obj->zo_data.objdata_u.po_data.po_data_len); | |
288 | break; | |
289 | default: | |
290 | fputs (_("(Unknown object)\n"), stdout); | |
291 | break; | |
292 | } | |
293 | } | |
294 | ||
295 | void | |
296 | nis_print_result (const nis_result *res) | |
297 | { | |
298 | unsigned int i; | |
299 | ||
300 | printf (_("Status : %s\n"), nis_sperrno (res->status)); | |
301 | printf (_("Number of objects : %u\n"), res->objects.objects_len); | |
302 | ||
303 | for (i = 0; i < res->objects.objects_len; i++) | |
304 | { | |
305 | printf (_("Object #%d:\n"), i); | |
306 | nis_print_object (&res->objects.objects_val[i]); | |
307 | } | |
308 | } |