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