345ed7d49af8dedfce64ec3c0927850f0eaec088
[samba.git] / source3 / rpcclient / display.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    Samba utility functions
5    Copyright (C) Andrew Tridgell 1992-1998
6    Copyright (C) Luke Kenneth Casson Leighton 1996 - 1998
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24
25
26 /****************************************************************************
27 convert a share mode to a string
28 ****************************************************************************/
29 char *get_file_mode_str(uint32 share_mode)
30 {
31         static fstring mode;
32
33         switch (GET_DENY_MODE(share_mode))
34         {
35                 case DENY_NONE : fstrcpy(mode, "DENY_NONE  "); break;
36                 case DENY_ALL  : fstrcpy(mode, "DENY_ALL   "); break;
37                 case DENY_DOS  : fstrcpy(mode, "DENY_DOS   "); break;
38                 case DENY_READ : fstrcpy(mode, "DENY_READ  "); break;
39                 case DENY_WRITE: fstrcpy(mode, "DENY_WRITE "); break;
40                 case DENY_FCB:   fstrcpy(mode, "DENY_FCB "); break;
41                 default        : fstrcpy(mode, "DENY_????  "); break;
42         }
43
44         switch (share_mode & 0xF)
45         {
46                 case 0 : fstrcat(mode, "RDONLY"); break;
47                 case 1 : fstrcat(mode, "WRONLY"); break;
48                 case 2 : fstrcat(mode, "RDWR  "); break;
49                 default: fstrcat(mode, "R??W??"); break;
50         }
51
52         return mode;
53 }
54
55 /****************************************************************************
56 convert an oplock mode to a string
57 ****************************************************************************/
58 char *get_file_oplock_str(uint32 op_type)
59 {
60         static fstring oplock;
61         BOOL excl  = ((op_type & EXCLUSIVE_OPLOCK) != 0);
62         BOOL batch = ((op_type & BATCH_OPLOCK    ) != 0);
63
64         oplock[0] = 0;
65
66         if (excl           ) fstrcat(oplock, "EXCLUSIVE");
67         if (excl  &&  batch) fstrcat(oplock, "+");
68         if (          batch) fstrcat(oplock, "BATCH");
69         if (!excl && !batch) fstrcat(oplock, "NONE");
70
71         return oplock;
72 }
73
74 /****************************************************************************
75 convert a share type enum to a string
76 ****************************************************************************/
77 char *get_share_type_str(uint32 type)
78 {
79         static fstring typestr;
80
81         switch (type)
82         {
83                 case STYPE_DISKTREE: fstrcpy(typestr, "Disk"   ); break;
84                 case STYPE_PRINTQ  : fstrcpy(typestr, "Printer"); break;              
85                 case STYPE_DEVICE  : fstrcpy(typestr, "Device" ); break;
86                 case STYPE_IPC     : fstrcpy(typestr, "IPC"    ); break;      
87                 default            : fstrcpy(typestr, "????"   ); break;      
88         }
89         return typestr;
90 }
91
92 /****************************************************************************
93 convert a server type enum to a string
94 ****************************************************************************/
95 char *get_server_type_str(uint32 type)
96 {
97         static fstring typestr;
98
99         if (type == SV_TYPE_ALL)
100         {
101                 fstrcpy(typestr, "All");
102         }
103         else
104         {
105                 int i;
106                 typestr[0] = 0;
107                 for (i = 0; i < 32; i++)
108                 {
109                         if (type & (1 << i))
110                         {
111                                 switch (((unsigned)1) << i)
112                                 {
113                                         case SV_TYPE_WORKSTATION      : fstrcat(typestr, "Wk " ); break;
114                                         case SV_TYPE_SERVER           : fstrcat(typestr, "Sv " ); break;
115                                         case SV_TYPE_SQLSERVER        : fstrcat(typestr, "Sql "); break;
116                                         case SV_TYPE_DOMAIN_CTRL      : fstrcat(typestr, "PDC "); break;
117                                         case SV_TYPE_DOMAIN_BAKCTRL   : fstrcat(typestr, "BDC "); break;
118                                         case SV_TYPE_TIME_SOURCE      : fstrcat(typestr, "Tim "); break;
119                                         case SV_TYPE_AFP              : fstrcat(typestr, "AFP "); break;
120                                         case SV_TYPE_NOVELL           : fstrcat(typestr, "Nov "); break;
121                                         case SV_TYPE_DOMAIN_MEMBER    : fstrcat(typestr, "Dom "); break;
122                                         case SV_TYPE_PRINTQ_SERVER    : fstrcat(typestr, "PrQ "); break;
123                                         case SV_TYPE_DIALIN_SERVER    : fstrcat(typestr, "Din "); break;
124                                         case SV_TYPE_SERVER_UNIX      : fstrcat(typestr, "Unx "); break;
125                                         case SV_TYPE_NT               : fstrcat(typestr, "NT " ); break;
126                                         case SV_TYPE_WFW              : fstrcat(typestr, "Wfw "); break;
127                                         case SV_TYPE_SERVER_MFPN      : fstrcat(typestr, "Mfp "); break;
128                                         case SV_TYPE_SERVER_NT        : fstrcat(typestr, "SNT "); break;
129                                         case SV_TYPE_POTENTIAL_BROWSER: fstrcat(typestr, "PtB "); break;
130                                         case SV_TYPE_BACKUP_BROWSER   : fstrcat(typestr, "BMB "); break;
131                                         case SV_TYPE_MASTER_BROWSER   : fstrcat(typestr, "LMB "); break;
132                                         case SV_TYPE_DOMAIN_MASTER    : fstrcat(typestr, "DMB "); break;
133                                         case SV_TYPE_SERVER_OSF       : fstrcat(typestr, "OSF "); break;
134                                         case SV_TYPE_SERVER_VMS       : fstrcat(typestr, "VMS "); break;
135                                         case SV_TYPE_WIN95_PLUS       : fstrcat(typestr, "W95 "); break;
136                                         case SV_TYPE_ALTERNATE_XPORT  : fstrcat(typestr, "Xpt "); break;
137                                         case SV_TYPE_LOCAL_LIST_ONLY  : fstrcat(typestr, "Dom "); break;
138                                         case SV_TYPE_DOMAIN_ENUM      : fstrcat(typestr, "Loc "); break;
139                                 }
140                         }
141                 }
142                 i = strlen(typestr)-1;
143                 if (typestr[i] == ' ') typestr[i] = 0;
144
145         }
146         return typestr;
147 }
148
149 /****************************************************************************
150 server info level 101 display function
151 ****************************************************************************/
152 void display_srv_info_101(FILE *out_hnd, enum action_type action,
153                 SRV_INFO_101 *sv101)
154 {
155         if (sv101 == NULL)
156         {
157                 return;
158         }
159
160         switch (action)
161         {
162                 case ACTION_HEADER:
163                 {
164                         fprintf(out_hnd, "Server Info Level 101:\n");
165
166                         break;
167                 }
168                 case ACTION_ENUMERATE:
169                 {
170                         fstring name;
171                         fstring comment;
172
173                         rpcstr_pull(name, sv101->uni_name.buffer,  sizeof(name), sv101->uni_name.uni_str_len*2, 0);
174                         rpcstr_pull(comment, sv101->uni_comment.buffer,  sizeof(comment), sv101->uni_comment.uni_str_len*2, 0);
175
176                         display_server(out_hnd, action, name, sv101->srv_type, comment);
177
178                         fprintf(out_hnd, "\tplatform_id     : %d\n"    , sv101->platform_id);
179                         fprintf(out_hnd, "\tos version      : %d.%d\n" , sv101->ver_major, sv101->ver_minor);
180
181                         break;
182                 }
183                 case ACTION_FOOTER:
184                 {
185                         break;
186                 }
187         }
188
189 }
190
191 /****************************************************************************
192 server info level 102 display function
193 ****************************************************************************/
194 void display_srv_info_102(FILE *out_hnd, enum action_type action,SRV_INFO_102 *sv102)
195 {
196         if (sv102 == NULL)
197         {
198                 return;
199         }
200
201         switch (action)
202         {
203                 case ACTION_HEADER:
204                 {
205                         fprintf(out_hnd, "Server Info Level 102:\n");
206
207                         break;
208                 }
209                 case ACTION_ENUMERATE:
210                 {
211                         fstring name;
212                         fstring comment;
213                         fstring usr_path;
214
215                         rpcstr_pull(name, sv102->uni_name.buffer,  sizeof(name), sv102->uni_name.uni_str_len*2, 0);
216                         rpcstr_pull(comment, sv102->uni_comment.buffer,  sizeof(comment), sv102->uni_comment.uni_str_len*2, 0);
217                         rpcstr_pull(usr_path, sv102->uni_usr_path.buffer,  sizeof(usr_path), sv102->uni_usr_path.uni_str_len*2, 0);
218
219                         display_server(out_hnd, action, name, sv102->srv_type, comment);
220
221                         fprintf(out_hnd, "\tplatform_id     : %d\n"    , sv102->platform_id);
222                         fprintf(out_hnd, "\tos version      : %d.%d\n" , sv102->ver_major, sv102->ver_minor);
223
224                         fprintf(out_hnd, "\tusers           : %x\n"    , sv102->users      );
225                         fprintf(out_hnd, "\tdisc, hidden    : %x,%x\n" , sv102->disc     , sv102->hidden   );
226                         fprintf(out_hnd, "\tannounce, delta : %d, %d\n", sv102->announce , sv102->ann_delta);
227                         fprintf(out_hnd, "\tlicenses        : %d\n"    , sv102->licenses   );
228                         fprintf(out_hnd, "\tuser path       : %s\n"    , usr_path);
229
230                         break;
231                 }
232                 case ACTION_FOOTER:
233                 {
234                         break;
235                 }
236         }
237 }
238
239 /****************************************************************************
240 server info container display function
241 ****************************************************************************/
242 void display_srv_info_ctr(FILE *out_hnd, enum action_type action,SRV_INFO_CTR *ctr)
243 {
244         if (ctr == NULL || ctr->ptr_srv_ctr == 0)
245         {
246                 fprintf(out_hnd, "Server Information: unavailable due to an error\n");
247                 return;
248         }
249
250         switch (ctr->switch_value)
251         {
252                 case 101:
253                 {
254                         display_srv_info_101(out_hnd, action, &(ctr->srv.sv101));
255                         break;
256                 }
257                 case 102:
258                 {
259                         display_srv_info_102(out_hnd, action, &(ctr->srv.sv102));
260                         break;
261                 }
262                 default:
263                 {
264                         fprintf(out_hnd, "Server Information: Unknown Info Level\n");
265                         break;
266                 }
267         }
268 }
269
270 /****************************************************************************
271 connection info level 0 display function
272 ****************************************************************************/
273 void display_conn_info_0(FILE *out_hnd, enum action_type action,
274                 CONN_INFO_0 *info0)
275 {
276         if (info0 == NULL)
277         {
278                 return;
279         }
280
281         switch (action)
282         {
283                 case ACTION_HEADER:
284                 {
285                         fprintf(out_hnd, "Connection Info Level 0:\n");
286
287                         break;
288                 }
289                 case ACTION_ENUMERATE:
290                 {
291                         fprintf(out_hnd, "\tid: %d\n", info0->id);
292
293                         break;
294                 }
295                 case ACTION_FOOTER:
296                 {
297                         fprintf(out_hnd, "\n");
298                         break;
299                 }
300         }
301
302 }
303
304 /****************************************************************************
305 connection info level 1 display function
306 ****************************************************************************/
307 void display_conn_info_1(FILE *out_hnd, enum action_type action,
308                 CONN_INFO_1 *info1, CONN_INFO_1_STR *str1)
309 {
310         if (info1 == NULL || str1 == NULL)
311         {
312                 return;
313         }
314
315         switch (action)
316         {
317                 case ACTION_HEADER:
318                 {
319                         fprintf(out_hnd, "Connection Info Level 1:\n");
320
321                         break;
322                 }
323                 case ACTION_ENUMERATE:
324                 {
325                         fstring usr_name;
326                         fstring net_name;
327
328                         rpcstr_pull(usr_name, str1->uni_usr_name.buffer, sizeof(usr_name), str1->uni_usr_name.uni_str_len*2,0);
329                         rpcstr_pull(net_name, str1->uni_net_name.buffer, sizeof(net_name), str1->uni_net_name.uni_str_len*2,0);
330
331                         fprintf(out_hnd, "\tid       : %d\n", info1->id);
332                         fprintf(out_hnd, "\ttype     : %s\n", get_share_type_str(info1->type));
333                         fprintf(out_hnd, "\tnum_opens: %d\n", info1->num_opens);
334                         fprintf(out_hnd, "\tnum_users: %d\n", info1->num_users);
335                         fprintf(out_hnd, "\topen_time: %d\n", info1->open_time);
336
337                         fprintf(out_hnd, "\tuser name: %s\n", usr_name);
338                         fprintf(out_hnd, "\tnet  name: %s\n", net_name);
339
340                         break;
341                 }
342                 case ACTION_FOOTER:
343                 {
344                         fprintf(out_hnd, "\n");
345                         break;
346                 }
347         }
348
349 }
350
351 /****************************************************************************
352 connection info level 0 container display function
353 ****************************************************************************/
354 void display_srv_conn_info_0_ctr(FILE *out_hnd, enum action_type action,
355                                 SRV_CONN_INFO_0 *ctr)
356 {
357         if (ctr == NULL)
358         {
359                 fprintf(out_hnd, "display_srv_conn_info_0_ctr: unavailable due to an internal error\n");
360                 return;
361         }
362
363         switch (action)
364         {
365                 case ACTION_HEADER:
366                 {
367                         break;
368                 }
369                 case ACTION_ENUMERATE:
370                 {
371                         int i;
372
373                         for (i = 0; i < ctr->num_entries_read; i++)
374                         {
375                                 display_conn_info_0(out_hnd, ACTION_HEADER   , &(ctr->info_0[i]));
376                                 display_conn_info_0(out_hnd, ACTION_ENUMERATE, &(ctr->info_0[i]));
377                                 display_conn_info_0(out_hnd, ACTION_FOOTER   , &(ctr->info_0[i]));
378                         }
379                         break;
380                 }
381                 case ACTION_FOOTER:
382                 {
383                         break;
384                 }
385         }
386 }
387
388 /****************************************************************************
389 connection info level 1 container display function
390 ****************************************************************************/
391 void display_srv_conn_info_1_ctr(FILE *out_hnd, enum action_type action,
392                                 SRV_CONN_INFO_1 *ctr)
393 {
394         if (ctr == NULL)
395         {
396                 fprintf(out_hnd, "display_srv_conn_info_1_ctr: unavailable due to an internal error\n");
397                 return;
398         }
399
400         switch (action)
401         {
402                 case ACTION_HEADER:
403                 {
404                         break;
405                 }
406                 case ACTION_ENUMERATE:
407                 {
408                         int i;
409
410                         for (i = 0; i < ctr->num_entries_read; i++)
411                         {
412                                 display_conn_info_1(out_hnd, ACTION_HEADER   , &(ctr->info_1[i]), &(ctr->info_1_str[i]));
413                                 display_conn_info_1(out_hnd, ACTION_ENUMERATE, &(ctr->info_1[i]), &(ctr->info_1_str[i]));
414                                 display_conn_info_1(out_hnd, ACTION_FOOTER   , &(ctr->info_1[i]), &(ctr->info_1_str[i]));
415                         }
416                         break;
417                 }
418                 case ACTION_FOOTER:
419                 {
420                         break;
421                 }
422         }
423 }
424
425 /****************************************************************************
426 connection info container display function
427 ****************************************************************************/
428 void display_srv_conn_info_ctr(FILE *out_hnd, enum action_type action,
429                                 SRV_CONN_INFO_CTR *ctr)
430 {
431         if (ctr == NULL || ctr->ptr_conn_ctr == 0)
432         {
433                 fprintf(out_hnd, "display_srv_conn_info_ctr: unavailable due to an internal error\n");
434                 return;
435         }
436
437         switch (ctr->switch_value)
438         {
439                 case 0:
440                 {
441                         display_srv_conn_info_0_ctr(out_hnd, action,
442                                            &(ctr->conn.info0));
443                         break;
444                 }
445                 case 1:
446                 {
447                         display_srv_conn_info_1_ctr(out_hnd, action,
448                                            &(ctr->conn.info1));
449                         break;
450                 }
451                 default:
452                 {
453                         fprintf(out_hnd, "display_srv_conn_info_ctr: Unknown Info Level\n");
454                         break;
455                 }
456         }
457 }
458
459
460 /****************************************************************************
461 share info level 1 display function
462 ****************************************************************************/
463 void display_share_info_1(FILE *out_hnd, enum action_type action,
464                           SRV_SHARE_INFO_1 *info1)
465 {
466         if (info1 == NULL)
467         {
468                 return;
469         }
470
471         switch (action)
472         {
473                 case ACTION_HEADER:
474                 {
475                         fprintf(out_hnd, "Share Info Level 1:\n");
476
477                         break;
478                 }
479                 case ACTION_ENUMERATE:
480                 {
481                         fstring remark  ;
482                         fstring net_name;
483
484                         rpcstr_pull(net_name, info1->info_1_str.uni_netname.buffer, sizeof(net_name), info1->info_1_str.uni_netname.uni_str_len*2, 0);
485                         rpcstr_pull(remark, info1->info_1_str.uni_remark.buffer, sizeof(remark), info1->info_1_str.uni_remark.uni_str_len*2, 0);
486
487                         display_share(out_hnd, action, net_name, info1->info_1.type, remark);
488
489                         break;
490                 }
491                 case ACTION_FOOTER:
492                 {
493                         fprintf(out_hnd, "\n");
494                         break;
495                 }
496         }
497
498 }
499
500 /****************************************************************************
501 share info level 2 display function
502 ****************************************************************************/
503 void display_share_info_2(FILE *out_hnd, enum action_type action,
504                           SRV_SHARE_INFO_2 *info2)
505 {
506         if (info2 == NULL)
507         {
508                 return;
509         }
510
511         switch (action)
512         {
513                 case ACTION_HEADER:
514                 {
515                         fprintf(out_hnd, "Share Info Level 2:\n");
516
517                         break;
518                 }
519                 case ACTION_ENUMERATE:
520                 {
521                         fstring remark  ;
522                         fstring net_name;
523                         fstring path    ;
524                         fstring passwd  ;
525
526                         rpcstr_pull(net_name, info2->info_2_str.uni_netname.buffer, sizeof(net_name), info2->info_2_str.uni_netname.uni_str_len*2, 0);
527                         rpcstr_pull(remark, info2->info_2_str.uni_remark.buffer, sizeof(remark), info2->info_2_str.uni_remark.uni_str_len*2, 0);
528                         rpcstr_pull(path, info2->info_2_str.uni_path.buffer, sizeof(path), info2->info_2_str.uni_path.uni_str_len*2, 0);
529                         rpcstr_pull(passwd, info2->info_2_str.uni_passwd.buffer, sizeof(passwd), info2->info_2_str.uni_passwd.uni_str_len*2, 0);
530
531                         display_share2(out_hnd, action, net_name,
532                               info2->info_2.type, remark, info2->info_2.perms,
533                               info2->info_2.max_uses, info2->info_2.num_uses,
534                               path, passwd);
535
536                         break;
537                 }
538                 case ACTION_FOOTER:
539                 {
540                         fprintf(out_hnd, "\n");
541                         break;
542                 }
543         }
544
545 }
546
547 /****************************************************************************
548 share info container display function
549 ****************************************************************************/
550 void display_srv_share_info_ctr(FILE *out_hnd, enum action_type action,
551                                 SRV_SHARE_INFO_CTR *ctr)
552 {
553         if (ctr == NULL)
554         {
555                 fprintf(out_hnd, "display_srv_share_info_ctr: unavailable due to an internal error\n");
556         return;
557         }
558
559         switch (action)
560         {
561                 case ACTION_HEADER:
562                 {
563                         break;
564                 }
565                 case ACTION_ENUMERATE:
566                 {
567                         int i;
568
569                         for (i = 0; i < ctr->num_entries; i++)
570                         {
571                                 switch (ctr->info_level) {
572                                 case 1:
573                                         display_share_info_1(out_hnd, ACTION_HEADER   , &(ctr->share.info1[i]));
574                                         display_share_info_1(out_hnd, ACTION_ENUMERATE, &(ctr->share.info1[i]));
575                                         display_share_info_1(out_hnd, ACTION_FOOTER   , &(ctr->share.info1[i]));
576                                         break;
577                                 case 2:
578                                         display_share_info_2(out_hnd, ACTION_HEADER   , &(ctr->share.info2[i]));
579                                         display_share_info_2(out_hnd, ACTION_ENUMERATE, &(ctr->share.info2[i]));
580                                         display_share_info_2(out_hnd, ACTION_FOOTER   , &(ctr->share.info2[i]));
581                                         break;
582                                 default:
583                                         fprintf(out_hnd, "display_srv_share_info_ctr: Unknown Info Level\n");
584                                         break;
585                                 }
586                         }
587                         break;
588                 }
589                 case ACTION_FOOTER:
590                 {
591                         break;
592                 }
593         }
594 }
595
596 /****************************************************************************
597 file info level 3 display function
598 ****************************************************************************/
599 void display_file_info_3(FILE *out_hnd, enum action_type action,
600                 FILE_INFO_3 *info3, FILE_INFO_3_STR *str3)
601 {
602         if (info3 == NULL || str3 == NULL)
603         {
604                 return;
605         }
606
607         switch (action)
608         {
609                 case ACTION_HEADER:
610                 {
611                         fprintf(out_hnd, "File Info Level 3:\n");
612
613                         break;
614                 }
615                 case ACTION_ENUMERATE:
616                 {
617                         fstring path_name;
618                         fstring user_name;
619
620                         rpcstr_pull(path_name, str3->uni_path_name.buffer, sizeof(path_name), str3->uni_path_name.uni_str_len*2, 0);
621                         rpcstr_pull(user_name, str3->uni_user_name.buffer, sizeof(user_name), str3->uni_user_name.uni_str_len*2, 0);
622
623                         fprintf(out_hnd, "\tid       : %d\n", info3->id);
624                         fprintf(out_hnd, "\tperms    : %s\n", get_file_mode_str(info3->perms));
625                         fprintf(out_hnd, "\tnum_locks: %d\n", info3->num_locks);
626
627                         fprintf(out_hnd, "\tpath name: %s\n", path_name);
628                         fprintf(out_hnd, "\tuser name: %s\n", user_name);
629
630                         break;
631                 }
632                 case ACTION_FOOTER:
633                 {
634                         fprintf(out_hnd, "\n");
635                         break;
636                 }
637         }
638
639 }
640
641 /****************************************************************************
642 file info level 3 container display function
643 ****************************************************************************/
644 void display_srv_file_info_3_ctr(FILE *out_hnd, enum action_type action,
645                                 SRV_FILE_INFO_3 *ctr)
646 {
647         if (ctr == NULL)
648         {
649                 fprintf(out_hnd, "display_srv_file_info_3_ctr: unavailable due to an internal error\n");
650                 return;
651         }
652
653         switch (action)
654         {
655                 case ACTION_HEADER:
656                 {
657                         break;
658                 }
659                 case ACTION_ENUMERATE:
660                 {
661                         int i;
662
663                         for (i = 0; i < ctr->num_entries_read; i++)
664                         {
665                                 display_file_info_3(out_hnd, ACTION_HEADER   , &(ctr->info_3[i]), &(ctr->info_3_str[i]));
666                                 display_file_info_3(out_hnd, ACTION_ENUMERATE, &(ctr->info_3[i]), &(ctr->info_3_str[i]));
667                                 display_file_info_3(out_hnd, ACTION_FOOTER   , &(ctr->info_3[i]), &(ctr->info_3_str[i]));
668                         }
669                         break;
670                 }
671                 case ACTION_FOOTER:
672                 {
673                         break;
674                 }
675         }
676 }
677
678 /****************************************************************************
679 file info container display function
680 ****************************************************************************/
681 void display_srv_file_info_ctr(FILE *out_hnd, enum action_type action,
682                                 SRV_FILE_INFO_CTR *ctr)
683 {
684         if (ctr == NULL || ctr->ptr_file_ctr == 0)
685         {
686                 fprintf(out_hnd, "display_srv_file_info_ctr: unavailable due to an internal error\n");
687                 return;
688         }
689
690         switch (ctr->switch_value)
691         {
692                 case 3:
693                 {
694                         display_srv_file_info_3_ctr(out_hnd, action,
695                                            &(ctr->file.info3));
696                         break;
697                 }
698                 default:
699                 {
700                         fprintf(out_hnd, "display_srv_file_info_ctr: Unknown Info Level\n");
701                         break;
702                 }
703         }
704 }
705
706 /****************************************************************************
707  print browse connection on a host
708  ****************************************************************************/
709 void display_server(FILE *out_hnd, enum action_type action,
710                                 char *sname, uint32 type, char *comment)
711 {
712         switch (action)
713         {
714                 case ACTION_HEADER:
715                 {
716                         break;
717                 }
718                 case ACTION_ENUMERATE:
719                 {
720                         fprintf(out_hnd, "\t%-15.15s%-20s %s\n",
721                                          sname, get_server_type_str(type), comment);
722                         break;
723                 }
724                 case ACTION_FOOTER:
725                 {
726                         break;
727                 }
728         }
729 }
730
731 /****************************************************************************
732 print shares on a host
733 ****************************************************************************/
734 void display_share(FILE *out_hnd, enum action_type action,
735                                 char *sname, uint32 type, char *comment)
736 {
737         switch (action)
738         {
739                 case ACTION_HEADER:
740                 {
741                         break;
742                 }
743                 case ACTION_ENUMERATE:
744                 {
745                         fprintf(out_hnd, "\t%-15.15s%-10.10s%s\n",
746                                          sname, get_share_type_str(type), comment);
747                         break;
748                 }
749                 case ACTION_FOOTER:
750                 {
751                         break;
752                 }
753         }
754 }
755
756
757 /****************************************************************************
758 print shares on a host, level 2
759 ****************************************************************************/
760 void display_share2(FILE *out_hnd, enum action_type action,
761                                 char *sname, uint32 type, char *comment,
762                                 uint32 perms, uint32 max_uses, uint32 num_uses,
763                                 char *path, char *passwd)
764 {
765         switch (action)
766         {
767                 case ACTION_HEADER:
768                 {
769                         break;
770                 }
771                 case ACTION_ENUMERATE:
772                 {
773                         fprintf(out_hnd, "\t%-15.15s%-10.10s%s %x %x %x %s %s\n",
774                                          sname, get_share_type_str(type), comment,
775                                          perms, max_uses, num_uses, path, passwd);
776                         break;
777                 }
778                 case ACTION_FOOTER:
779                 {
780                         break;
781                 }
782         }
783 }
784
785
786 /****************************************************************************
787 print name info
788 ****************************************************************************/
789 void display_name(FILE *out_hnd, enum action_type action,
790                                 char *sname)
791 {
792         switch (action)
793         {
794                 case ACTION_HEADER:
795                 {
796                         break;
797                 }
798                 case ACTION_ENUMERATE:
799                 {
800                         fprintf(out_hnd, "\t%-21.21s\n", sname);
801                         break;
802                 }
803                 case ACTION_FOOTER:
804                 {
805                         break;
806                 }
807         }
808 }
809
810
811 /****************************************************************************
812  display group rid info
813  ****************************************************************************/
814 void display_group_rid_info(FILE *out_hnd, enum action_type action,
815                                 uint32 num_gids, DOM_GID *gid)
816 {
817         switch (action)
818         {
819                 case ACTION_HEADER:
820                 {
821                         if (num_gids == 0)
822                         {
823                                 fprintf(out_hnd, "\tNo Groups\n");
824                         }
825                         else
826                         {
827                                 fprintf(out_hnd, "\tGroup Info\n");
828                                 fprintf(out_hnd, "\t----------\n");
829                         }
830                         break;
831                 }
832                 case ACTION_ENUMERATE:
833                 {
834                         int i;
835
836                         for (i = 0; i < num_gids; i++)
837                         {
838                                 fprintf(out_hnd, "\tGroup RID: %8x attr: %x\n",
839                                                                   gid[i].g_rid, gid[i].attr);
840                         }
841
842                         break;
843                 }
844                 case ACTION_FOOTER:
845                 {
846                         fprintf(out_hnd, "\n");
847                         break;
848                 }
849         }
850 }
851
852
853 /****************************************************************************
854  display alias name info
855  ****************************************************************************/
856 void display_alias_name_info(FILE *out_hnd, enum action_type action,
857                                 uint32 num_aliases, fstring *alias_name, uint32 *num_als_usrs)
858 {
859         switch (action)
860         {
861                 case ACTION_HEADER:
862                 {
863                         if (num_aliases == 0)
864                         {
865                                 fprintf(out_hnd, "\tNo Aliases\n");
866                         }
867                         else
868                         {
869                                 fprintf(out_hnd, "\tAlias Names\n");
870                                 fprintf(out_hnd, "\t----------- \n");
871                         }
872                         break;
873                 }
874                 case ACTION_ENUMERATE:
875                 {
876                         int i;
877
878                         for (i = 0; i < num_aliases; i++)
879                         {
880                                 fprintf(out_hnd, "\tAlias Name: %s Attributes: %3d\n",
881                                                                   alias_name[i], num_als_usrs[i]);
882                         }
883
884                         break;
885                 }
886                 case ACTION_FOOTER:
887                 {
888                         fprintf(out_hnd, "\n");
889                         break;
890                 }
891         }
892 }
893
894
895 /****************************************************************************
896  display sam_user_info_21 structure
897  ****************************************************************************/
898 void display_sam_user_info_21(FILE *out_hnd, enum action_type action, SAM_USER_INFO_21 *usr)
899 {
900         switch (action)
901         {
902                 case ACTION_HEADER:
903                 {
904                         fprintf(out_hnd, "\tUser Info, Level 0x15\n");
905                         fprintf(out_hnd, "\t---------------------\n");
906
907                         break;
908                 }
909                 case ACTION_ENUMERATE:
910                 {
911                         pstring tmp;
912                         rpcstr_pull(tmp, usr->uni_user_name.buffer, sizeof(tmp),usr->uni_user_name.uni_str_len*2, 0);
913                         fprintf(out_hnd, "\t\tUser Name   : %s\n", tmp); /* username unicode string */
914                         rpcstr_pull(tmp, usr->uni_full_name.buffer, sizeof(tmp),usr->uni_full_name.uni_str_len*2, 0);
915                         fprintf(out_hnd, "\t\tFull Name   : %s\n", tmp); /* user's full name unicode string */
916                         rpcstr_pull(tmp, usr->uni_home_dir.buffer, sizeof(tmp),usr->uni_home_dir.uni_str_len*2, 0);
917                         fprintf(out_hnd, "\t\tHome Drive  : %s\n", tmp); /* home directory unicode string */
918                         rpcstr_pull(tmp, usr->uni_dir_drive.buffer, sizeof(tmp),usr->uni_dir_drive.uni_str_len*2, 0);
919                         fprintf(out_hnd, "\t\tDir Drive   : %s\n", tmp); /* home directory drive unicode string */
920                         rpcstr_pull(tmp, usr->uni_profile_path.buffer, sizeof(tmp),usr->uni_profile_path.uni_str_len*2, 0);
921                         fprintf(out_hnd, "\t\tProfile Path: %s\n", tmp); /* profile path unicode string */
922                         rpcstr_pull(tmp, usr->uni_logon_script.buffer, sizeof(tmp),usr->uni_logon_script.uni_str_len*2, 0);
923                         fprintf(out_hnd, "\t\tLogon Script: %s\n", tmp); /* logon script unicode string */
924                         rpcstr_pull(tmp, usr->uni_acct_desc.buffer, sizeof(tmp),usr->uni_acct_desc.uni_str_len*2, 0);
925                         fprintf(out_hnd, "\t\tDescription : %s\n", tmp); /* user description unicode string */
926                         rpcstr_pull(tmp, usr->uni_workstations.buffer, sizeof(tmp),usr->uni_workstations.uni_str_len*2, 0);
927                         fprintf(out_hnd, "\t\tWorkstations: %s\n", tmp); /* workstaions unicode string */
928                         rpcstr_pull(tmp, usr->uni_unknows_str.buffer, sizeof(tmp),usr->uni_unknown_str.uni_str_len*2, 0);
929                         fprintf(out_hnd, "\t\tUnknown Str : %s\n", tmp); /* unknown string unicode string */
930                         rpcstr_pull(tmp, usr->uni_munged_dial.buffer, sizeof(tmp),usr->uni_munged_dial.uni_str_len*2, 0);
931                         fprintf(out_hnd, "\t\tRemote Dial : %s\n", tmp); /* munged remote access unicode string */
932
933                         fprintf(out_hnd, "\t\tLogon Time               : %s\n", http_timestring(nt_time_to_unix(&(usr->logon_time           ))));
934                         fprintf(out_hnd, "\t\tLogoff Time              : %s\n", http_timestring(nt_time_to_unix(&(usr->logoff_time          ))));
935                         fprintf(out_hnd, "\t\tKickoff Time             : %s\n", http_timestring(nt_time_to_unix(&(usr->kickoff_time         ))));
936                         fprintf(out_hnd, "\t\tPassword last set Time   : %s\n", http_timestring(nt_time_to_unix(&(usr->pass_last_set_time   ))));
937                         fprintf(out_hnd, "\t\tPassword can change Time : %s\n", http_timestring(nt_time_to_unix(&(usr->pass_can_change_time ))));
938                         fprintf(out_hnd, "\t\tPassword must change Time: %s\n", http_timestring(nt_time_to_unix(&(usr->pass_must_change_time))));
939                         
940                         fprintf(out_hnd, "\t\tunknown_2[0..31]...\n"); /* user passwords? */
941
942                         fprintf(out_hnd, "\t\tuser_rid : %x\n"  , usr->user_rid ); /* User ID */
943                         fprintf(out_hnd, "\t\tgroup_rid: %x\n"  , usr->group_rid); /* Group ID */
944                         fprintf(out_hnd, "\t\tacb_info : %04x\n", usr->acb_info ); /* Account Control Info */
945
946                         fprintf(out_hnd, "\t\tunknown_3: %08x\n", usr->unknown_3); /* 0x00ff ffff */
947                         fprintf(out_hnd, "\t\tlogon_divs: %d\n", usr->logon_divs); /* 0x0000 00a8 which is 168 which is num hrs in a week */
948                         fprintf(out_hnd, "\t\tunknown_5: %08x\n", usr->unknown_5); /* 0x0002 0000 */
949
950                         fprintf(out_hnd, "\t\tpadding1[0..7]...\n");
951
952                         if (usr->ptr_logon_hrs)
953                         {
954                                 fprintf(out_hnd, "\t\tlogon_hrs[0..%d]...\n", usr->logon_hrs.len);
955                         }
956
957                         break;
958                 }
959                 case ACTION_FOOTER:
960                 {
961                         fprintf(out_hnd, "\n");
962                         break;
963                 }
964         }
965 }
966
967
968 /****************************************************************************
969 convert a security permissions into a string
970 ****************************************************************************/
971 char *get_sec_mask_str(uint32 type)
972 {
973         static fstring typestr;
974         int i;
975
976         switch (type)
977         {
978                 case SEC_RIGHTS_FULL_CONTROL:
979                 {
980                         fstrcpy(typestr, "Full Control");
981                         return typestr;
982                 }
983
984                 case SEC_RIGHTS_READ:
985                 {
986                         fstrcpy(typestr, "Read");
987                         return typestr;
988                 }
989                 default:
990                 {
991                         break;
992                 }
993         }
994
995         typestr[0] = 0;
996         for (i = 0; i < 32; i++)
997         {
998                 if (type & (1 << i))
999                 {
1000                         switch (((unsigned)1) << i)
1001                         {
1002                                 case SEC_RIGHTS_QUERY_VALUE    : fstrcat(typestr, "Query " ); break;
1003                                 case SEC_RIGHTS_SET_VALUE      : fstrcat(typestr, "Set " ); break;
1004                                 case SEC_RIGHTS_CREATE_SUBKEY  : fstrcat(typestr, "Create "); break;
1005                                 case SEC_RIGHTS_ENUM_SUBKEYS   : fstrcat(typestr, "Enum "); break;
1006                                 case SEC_RIGHTS_NOTIFY         : fstrcat(typestr, "Notify "); break;
1007                                 case SEC_RIGHTS_CREATE_LINK    : fstrcat(typestr, "CreateLink "); break;
1008                                 case SEC_RIGHTS_DELETE         : fstrcat(typestr, "Delete "); break;
1009                                 case SEC_RIGHTS_READ_CONTROL   : fstrcat(typestr, "ReadControl "); break;
1010                                 case SEC_RIGHTS_WRITE_DAC      : fstrcat(typestr, "WriteDAC "); break;
1011                                 case SEC_RIGHTS_WRITE_OWNER    : fstrcat(typestr, "WriteOwner "); break;
1012                         }
1013                         type &= ~(1 << i);
1014                 }
1015         }
1016
1017         /* remaining bits get added on as-is */
1018         if (type != 0)
1019         {
1020                 fstring tmp;
1021                 slprintf(tmp, sizeof(tmp)-1, "[%08x]", type);
1022                 fstrcat(typestr, tmp);
1023         }
1024
1025         /* remove last space */
1026         i = strlen(typestr)-1;
1027         if (typestr[i] == ' ') typestr[i] = 0;
1028
1029         return typestr;
1030 }
1031
1032 /****************************************************************************
1033  display sec_access structure
1034  ****************************************************************************/
1035 void display_sec_access(FILE *out_hnd, enum action_type action, SEC_ACCESS *info)
1036 {
1037         switch (action)
1038         {
1039                 case ACTION_HEADER:
1040                 {
1041                         break;
1042                 }
1043                 case ACTION_ENUMERATE:
1044                 {
1045                         fprintf(out_hnd, "\t\tPermissions: %s\n",
1046                                 get_sec_mask_str(info->mask));
1047                 }
1048                 case ACTION_FOOTER:
1049                 {
1050                         break;
1051                 }
1052         }
1053 }
1054
1055 /****************************************************************************
1056  display sec_ace structure
1057  ****************************************************************************/
1058 void display_sec_ace(FILE *out_hnd, enum action_type action, SEC_ACE *ace)
1059 {
1060         switch (action)
1061         {
1062                 case ACTION_HEADER:
1063                 {
1064                         fprintf(out_hnd, "\tACE\n");
1065                         break;
1066                 }
1067                 case ACTION_ENUMERATE:
1068                 {
1069                         fstring sid_str;
1070
1071                         display_sec_access(out_hnd, ACTION_HEADER   , &ace->info);
1072                         display_sec_access(out_hnd, ACTION_ENUMERATE, &ace->info);
1073                         display_sec_access(out_hnd, ACTION_FOOTER   , &ace->info);
1074
1075                         sid_to_string(sid_str, &ace->sid);
1076                         fprintf(out_hnd, "\t\tSID: %s\n", sid_str);
1077                 }
1078                 case ACTION_FOOTER:
1079                 {
1080                         break;
1081                 }
1082         }
1083 }
1084
1085 /****************************************************************************
1086  display sec_acl structure
1087  ****************************************************************************/
1088 void display_sec_acl(FILE *out_hnd, enum action_type action, SEC_ACL *sec_acl)
1089 {
1090         switch (action)
1091         {
1092                 case ACTION_HEADER:
1093                 {
1094                         fprintf(out_hnd, "\tACL\tNum ACEs:\t%d\trevision:\t%x\n",
1095                                          sec_acl->num_aces, sec_acl->revision); 
1096                         fprintf(out_hnd, "\t---\n");
1097
1098                         break;
1099                 }
1100                 case ACTION_ENUMERATE:
1101                 {
1102                         if (sec_acl->size != 0 && sec_acl->num_aces != 0)
1103                         {
1104                                 int i;
1105                                 for (i = 0; i < sec_acl->num_aces; i++)
1106                                 {
1107                                         display_sec_ace(out_hnd, ACTION_HEADER   , &sec_acl->ace[i]);
1108                                         display_sec_ace(out_hnd, ACTION_ENUMERATE, &sec_acl->ace[i]);
1109                                         display_sec_ace(out_hnd, ACTION_FOOTER   , &sec_acl->ace[i]);
1110                                 }
1111                         }
1112                                 
1113                         break;
1114                 }
1115                 case ACTION_FOOTER:
1116                 {
1117                         fprintf(out_hnd, "\n");
1118                         break;
1119                 }
1120         }
1121 }
1122
1123 /****************************************************************************
1124  display sec_desc structure
1125  ****************************************************************************/
1126 void display_sec_desc(FILE *out_hnd, enum action_type action, SEC_DESC *sec)
1127 {
1128         switch (action)
1129         {
1130                 case ACTION_HEADER:
1131                 {
1132                         fprintf(out_hnd, "\tSecurity Descriptor\trevision:\t%x\ttype:\t%x\n",
1133                                          sec->revision, sec->type); 
1134                         fprintf(out_hnd, "\t-------------------\n");
1135
1136                         break;
1137                 }
1138                 case ACTION_ENUMERATE:
1139                 {
1140                         fstring sid_str;
1141
1142                         if (sec->off_sacl != 0)
1143                         {
1144                                 display_sec_acl(out_hnd, ACTION_HEADER   , sec->sacl);
1145                                 display_sec_acl(out_hnd, ACTION_ENUMERATE, sec->sacl);
1146                                 display_sec_acl(out_hnd, ACTION_FOOTER   , sec->sacl);
1147                         }
1148                         if (sec->off_dacl != 0)
1149                         {
1150                                 display_sec_acl(out_hnd, ACTION_HEADER   , sec->dacl);
1151                                 display_sec_acl(out_hnd, ACTION_ENUMERATE, sec->dacl);
1152                                 display_sec_acl(out_hnd, ACTION_FOOTER   , sec->dacl);
1153                         }
1154                         if (sec->off_owner_sid != 0)
1155                         {
1156                                 sid_to_string(sid_str, sec->owner_sid);
1157                                 fprintf(out_hnd, "\tOwner SID:\t%s\n", sid_str);
1158                         }
1159                         if (sec->off_grp_sid != 0)
1160                         {
1161                                 sid_to_string(sid_str, sec->grp_sid);
1162                                 fprintf(out_hnd, "\tParent SID:\t%s\n", sid_str);
1163                         }
1164                                 
1165                         break;
1166                 }
1167                 case ACTION_FOOTER:
1168                 {
1169                         fprintf(out_hnd, "\n");
1170                         break;
1171                 }
1172         }
1173 }
1174
1175 /****************************************************************************
1176 convert a security permissions into a string
1177 ****************************************************************************/
1178 char *get_reg_val_type_str(uint32 type)
1179 {
1180         static fstring typestr;
1181
1182         switch (type)
1183         {
1184                 case 0x01:
1185                 {
1186                         fstrcpy(typestr, "string");
1187                         return typestr;
1188                 }
1189
1190                 case 0x03:
1191                 {
1192                         fstrcpy(typestr, "bytes");
1193                         return typestr;
1194                 }
1195
1196                 case 0x04:
1197                 {
1198                         fstrcpy(typestr, "uint32");
1199                         return typestr;
1200                 }
1201
1202                 case 0x07:
1203                 {
1204                         fstrcpy(typestr, "multi");
1205                         return typestr;
1206                 }
1207                 default:
1208                 {
1209                         break;
1210                 }
1211         }
1212         slprintf(typestr, sizeof(typestr)-1, "[%d]", type);
1213         return typestr;
1214 }
1215
1216
1217 static void print_reg_value(FILE *out_hnd, char *val_name, uint32 val_type, BUFFER2 *value)
1218 {
1219         fstring type;
1220         pstring intvalue;
1221         fstrcpy(type, get_reg_val_type_str(val_type));
1222
1223         switch (val_type)
1224         {
1225                 case 0x01: /* unistr */
1226                 {
1227                         rpcstr_pull(intvalue, value->buffer, sizeof(intvalue), value->buf_len, 0);      
1228                         /*fprintf(out_hnd,"\t%s:\t%s:\t%s\n", val_name, type, dos_buffer2_to_str(value));*/
1229                         fprintf(out_hnd,"\t%s:\t%s:\t%s\n", val_name, type, value);
1230                         break;
1231                 }
1232
1233                 default: /* unknown */
1234                 case 0x03: /* bytes */
1235                 {
1236                         if (value->buf_len <= 8)
1237                         {
1238                                 fprintf(out_hnd,"\t%s:\t%s:\t", val_name, type);
1239                                 out_data(out_hnd, (char*)value->buffer, value->buf_len, 8);
1240                         }
1241                         else
1242                         {
1243                                 fprintf(out_hnd,"\t%s:\t%s:\n", val_name, type);
1244                                 out_data(out_hnd, (char*)value->buffer, value->buf_len, 16);
1245                         }
1246                         break;
1247                 }
1248
1249                 case 0x04: /* uint32 */
1250                 {
1251                         fprintf(out_hnd,"\t%s:\t%s: 0x%08x\n", val_name, type, buffer2_to_uint32(value));
1252                         break;
1253                 }
1254
1255                 case 0x07: /* multiunistr */
1256                 {
1257                         fprintf(out_hnd,"\t%s:\t%s:\t%s\n", val_name, type, dos_buffer2_to_multistr(value));
1258                         break;
1259                 }
1260         }
1261 }
1262
1263 /****************************************************************************
1264  display structure
1265  ****************************************************************************/
1266 void display_reg_value_info(FILE *out_hnd, enum action_type action,
1267                                 char *val_name, uint32 val_type, BUFFER2 *value)
1268 {
1269         switch (action)
1270         {
1271                 case ACTION_HEADER:
1272                 {
1273                         break;
1274                 }
1275                 case ACTION_ENUMERATE:
1276                 {
1277                         print_reg_value(out_hnd, val_name, val_type, value);
1278                         break;
1279                 }
1280                 case ACTION_FOOTER:
1281                 {
1282                         break;
1283                 }
1284         }
1285 }
1286
1287 /****************************************************************************
1288  display structure
1289  ****************************************************************************/
1290 void display_reg_key_info(FILE *out_hnd, enum action_type action,
1291                                 char *key_name, time_t key_mod_time)
1292 {
1293         switch (action)
1294         {
1295                 case ACTION_HEADER:
1296                 {
1297                         break;
1298                 }
1299                 case ACTION_ENUMERATE:
1300                 {
1301                         fprintf(out_hnd, "\t%s\t(%s)\n",
1302                                 key_name, http_timestring(key_mod_time));
1303                         break;
1304                 }
1305                 case ACTION_FOOTER:
1306                 {
1307                         break;
1308                 }
1309         }
1310 }
1311
1312 #if COPY_THIS_TEMPLATE
1313 /****************************************************************************
1314  display structure
1315  ****************************************************************************/
1316  void display_(FILE *out_hnd, enum action_type action, *)
1317 {
1318         switch (action)
1319         {
1320                 case ACTION_HEADER:
1321                 {
1322                         fprintf(out_hnd, "\t\n"); 
1323                         fprintf(out_hnd, "\t-------------------\n");
1324
1325                         break;
1326                 }
1327                 case ACTION_ENUMERATE:
1328                 {
1329                         break;
1330                 }
1331                 case ACTION_FOOTER:
1332                 {
1333                         fprintf(out_hnd, "\n");
1334                         break;
1335                 }
1336         }
1337 }
1338
1339 #endif