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