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