2 Unix SMB/Netbios implementation.
4 Samba utility functions
5 Copyright (C) Andrew Tridgell 1992-1998
6 Copyright (C) Luke Kenneth Casson Leighton 1996 - 1998
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.
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.
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.
26 struct field_info sid_name_info[] =
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" },
39 /****************************************************************************
40 convert a SID_NAME_USE to a string
41 ****************************************************************************/
42 char *get_sid_name_use_str(uint8 sid_name_use)
44 return enum_field_to_str((uint32)sid_name_use, sid_name_info, True);
47 /****************************************************************************
48 convert a share mode to a string
49 ****************************************************************************/
50 char *get_file_mode_str(uint32 share_mode)
54 switch ((share_mode>>4)&0xF)
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;
64 switch (share_mode & 0xF)
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;
75 /****************************************************************************
76 convert an oplock mode to a string
77 ****************************************************************************/
78 char *get_file_oplock_str(uint32 op_type)
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 );
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");
94 /****************************************************************************
95 convert a share type enum to a string
96 ****************************************************************************/
97 char *get_share_type_str(uint32 type)
99 static fstring typestr;
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;
112 /****************************************************************************
113 convert a server type enum to a string
114 ****************************************************************************/
115 char *get_server_type_str(uint32 type)
117 static fstring typestr;
119 if (type == SV_TYPE_ALL)
121 fstrcpy(typestr, "All");
127 for (i = 0; i < 32; i++)
129 if (IS_BITS_SET_ALL(type, 1 << i))
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;
162 i = strlen(typestr)-1;
163 if (typestr[i] == ' ') typestr[i] = 0;
169 /****************************************************************************
170 server info level 101 display function
171 ****************************************************************************/
172 void display_srv_info_101(FILE *out_hnd, enum action_type action,
184 fprintf(out_hnd, "Server Info Level 101:\n");
188 case ACTION_ENUMERATE:
193 unistr2_to_ascii(name, &sv101->uni_name, sizeof(name)-1);
194 unistr2_to_ascii(comment, &sv101->uni_comment, sizeof(comment)-1);
196 display_server(out_hnd, action, name, sv101->srv_type, comment);
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);
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)
225 fprintf(out_hnd, "Server Info Level 102:\n");
229 case ACTION_ENUMERATE:
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,
240 display_server(out_hnd, action, name, sv102->srv_type, comment);
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);
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);
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)
265 if (ctr == NULL || ctr->ptr_srv_ctr == 0)
267 fprintf(out_hnd, "Server Information: unavailable due to an error\n");
271 switch (ctr->switch_value)
275 display_srv_info_101(out_hnd, action, &(ctr->srv.sv101));
280 display_srv_info_102(out_hnd, action, &(ctr->srv.sv102));
285 fprintf(out_hnd, "Server Information: Unknown Info Level\n");
291 /****************************************************************************
292 connection info level 0 display function
293 ****************************************************************************/
294 void display_conn_info_0(FILE *out_hnd, enum action_type action,
306 fprintf(out_hnd, "Connection Info Level 0:\n");
310 case ACTION_ENUMERATE:
312 fprintf(out_hnd, "\tid:\t%d\n", info0->id);
318 fprintf(out_hnd, "\n");
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)
331 if (info1 == NULL || str1 == NULL)
340 fprintf(out_hnd, "Connection Info Level 1:\n");
344 case ACTION_ENUMERATE:
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);
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);
358 fprintf(out_hnd, "\tuser name:\t%s\n", usr_name);
359 fprintf(out_hnd, "\tnet name:\t%s\n", net_name);
365 fprintf(out_hnd, "\n");
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)
380 fprintf(out_hnd, "display_srv_conn_info_0_ctr: unavailable due to an internal error\n");
390 case ACTION_ENUMERATE:
394 for (i = 0; i < ctr->num_entries_read; i++)
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]));
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)
417 fprintf(out_hnd, "display_srv_conn_info_1_ctr: unavailable due to an internal error\n");
427 case ACTION_ENUMERATE:
431 for (i = 0; i < ctr->num_entries_read; i++)
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]));
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)
452 if (ctr == NULL || ctr->ptr_conn_ctr == 0)
454 fprintf(out_hnd, "display_srv_conn_info_ctr: unavailable due to an internal error\n");
458 switch (ctr->switch_value)
462 display_srv_conn_info_0_ctr(out_hnd, action,
468 display_srv_conn_info_1_ctr(out_hnd, action,
474 fprintf(out_hnd, "display_srv_conn_info_ctr: Unknown Info Level\n");
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)
487 if (info1 == NULL || str1 == NULL)
496 fprintf(out_hnd, "Share Info Level 1:\n");
500 case ACTION_ENUMERATE:
505 unistr2_to_ascii(net_name, &str1->uni_netname, sizeof(net_name)-1);
506 unistr2_to_ascii(remark, &str1->uni_remark, sizeof(remark)-1);
508 display_share(out_hnd, action, net_name, info1->type, remark);
514 fprintf(out_hnd, "\n");
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)
527 if (info2 == NULL || str2 == NULL)
536 fprintf(out_hnd, "Share Info Level 2:\n");
540 case ACTION_ENUMERATE:
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);
552 display_share2(out_hnd, action, net_name, info2->type, remark,
553 info2->perms, info2->max_uses, info2->num_uses,
560 fprintf(out_hnd, "\n");
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)
575 fprintf(out_hnd, "display_srv_share_info_1_ctr: unavailable due to an internal error\n");
585 case ACTION_ENUMERATE:
589 for (i = 0; i < ctr->num_entries_read; i++)
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]));
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)
612 fprintf(out_hnd, "display_srv_share_info_2_ctr: unavailable due to an internal error\n");
622 case ACTION_ENUMERATE:
626 for (i = 0; i < ctr->num_entries_read; i++)
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]));
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)
647 if (ctr == NULL || ctr->ptr_share_ctr == 0)
649 fprintf(out_hnd, "display_srv_share_info_ctr: unavailable due to an internal error\n");
653 switch (ctr->switch_value)
657 display_srv_share_info_1_ctr(out_hnd, action,
658 &(ctr->share.info1));
663 display_srv_share_info_2_ctr(out_hnd, action,
664 &(ctr->share.info2));
669 fprintf(out_hnd, "display_srv_share_info_ctr: Unknown Info Level\n");
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)
682 if (info3 == NULL || str3 == NULL)
691 fprintf(out_hnd, "File Info Level 3:\n");
695 case ACTION_ENUMERATE:
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);
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);
709 fprintf(out_hnd, "\tpath name:\t%s\n", path_name);
710 fprintf(out_hnd, "\tuser name:\t%s\n", user_name);
716 fprintf(out_hnd, "\n");
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)
731 fprintf(out_hnd, "display_srv_file_info_3_ctr: unavailable due to an internal error\n");
741 case ACTION_ENUMERATE:
745 for (i = 0; i < ctr->num_entries_read; i++)
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]));
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)
766 if (ctr == NULL || ctr->ptr_file_ctr == 0)
768 fprintf(out_hnd, "display_srv_file_info_ctr: unavailable due to an internal error\n");
772 switch (ctr->switch_value)
776 display_srv_file_info_3_ctr(out_hnd, action,
782 fprintf(out_hnd, "display_srv_file_info_ctr: Unknown Info Level\n");
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)
800 case ACTION_ENUMERATE:
802 fprintf(out_hnd, "\t%-15.15s%-20s %s\n",
803 sname, get_server_type_str(type), comment);
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)
825 case ACTION_ENUMERATE:
827 fprintf(out_hnd, "\t%-15.15s%-10.10s%s\n",
828 sname, get_share_type_str(type), comment);
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)
853 case ACTION_ENUMERATE:
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);
868 /****************************************************************************
870 ****************************************************************************/
871 void display_name(FILE *out_hnd, enum action_type action,
880 case ACTION_ENUMERATE:
882 fprintf(out_hnd, "\t%-21.21s\n", sname);
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)
905 fprintf(out_hnd, "\tNo Alias Members\n");
909 fprintf(out_hnd, "\tAlias Members:\n");
910 fprintf(out_hnd, "\t-------------\n");
914 case ACTION_ENUMERATE:
918 for (i = 0; i < num_mem; i++)
920 if (sid_mem[i] != NULL)
922 fprintf(out_hnd, "\tMember Name:\t%s\n", sid_mem[i]);
930 fprintf(out_hnd, "\n");
937 /****************************************************************************
938 display alias rid info
939 ****************************************************************************/
940 void display_alias_rid_info(FILE *out_hnd, enum action_type action,
942 uint32 num_rids, uint32 *rid)
949 sid_to_string(sid_str, sid);
952 fprintf(out_hnd, "\tNo Aliases:\tSid %s\n", sid_str);
956 fprintf(out_hnd, "\tAlias Info:\tSid %s\n", sid_str);
957 fprintf(out_hnd, "\t----------\n");
961 case ACTION_ENUMERATE:
965 for (i = 0; i < num_rids; i++)
967 fprintf(out_hnd, "\tAlias RID:\t%8x\n", rid[i]);
974 fprintf(out_hnd, "\n");
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)
992 fprintf(out_hnd, "\tNo Members\n");
996 fprintf(out_hnd, "\tMembers:\n");
997 fprintf(out_hnd, "\t-------\n");
1001 case ACTION_ENUMERATE:
1005 for (i = 0; i < num_mem; i++)
1007 fprintf(out_hnd, "\tMember Name:\t%s\tType:\t%s\n",
1008 name[i], get_sid_name_use_str(type[i]));
1015 fprintf(out_hnd, "\n");
1024 /****************************************************************************
1026 ****************************************************************************/
1027 void display_group_info1(FILE *out_hnd, enum action_type action, GROUP_INFO1 *info1)
1036 case ACTION_ENUMERATE:
1040 fprintf(out_hnd, "\tGroup Name:\t%s\tDescription:\t%s\tunk1:\t%sunk2:%s\n",
1045 fprintf(out_hnd, "\n");
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)
1064 fprintf(out_hnd, "\tNo Groups\n");
1068 fprintf(out_hnd, "\tGroup Info\n");
1069 fprintf(out_hnd, "\t----------\n");
1073 case ACTION_ENUMERATE:
1077 for (i = 0; i < num_gids; i++)
1079 fprintf(out_hnd, "\tGroup RID:\t%8x attr:\t%x\n",
1080 gid[i].g_rid, gid[i].attr);
1087 fprintf(out_hnd, "\n");
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)
1104 if (num_aliases == 0)
1106 fprintf(out_hnd, "\tNo Aliases\n");
1110 fprintf(out_hnd, "\tAlias Names\n");
1111 fprintf(out_hnd, "\t----------- \n");
1115 case ACTION_ENUMERATE:
1119 for (i = 0; i < num_aliases; i++)
1121 fprintf(out_hnd, "\tAlias Name:\t%s Attributes:\t%3d\n",
1122 alias_name[i], num_als_usrs[i]);
1129 fprintf(out_hnd, "\n");
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)
1145 fprintf(out_hnd, "\tUser Info, Level 0x15\n");
1146 fprintf(out_hnd, "\t---------------------\n");
1150 case ACTION_ENUMERATE:
1154 unistr2_to_ascii(temp, &usr->uni_user_name, sizeof(temp)-1);
1155 fprintf(out_hnd, "\t\tUser Name :\t%s\n", temp);
1157 unistr2_to_ascii(temp, &usr->uni_full_name, sizeof(temp)-1);
1158 fprintf(out_hnd, "\t\tFull Name :\t%s\n", temp);
1160 unistr2_to_ascii(temp, &usr->uni_home_dir, sizeof(temp)-1);
1161 fprintf(out_hnd, "\t\tHome Drive :\t%s\n", temp);
1163 unistr2_to_ascii(temp, &usr->uni_dir_drive, sizeof(temp)-1);
1164 fprintf(out_hnd, "\t\tDir Drive :\t%s\n", temp);
1166 unistr2_to_ascii(temp, &usr->uni_profile_path, sizeof(temp)-1);
1167 fprintf(out_hnd, "\t\tProfile Path:\t%s\n", temp);
1169 unistr2_to_ascii(temp, &usr->uni_logon_script, sizeof(temp)-1);
1170 fprintf(out_hnd, "\t\tLogon Script:\t%s\n", temp);
1172 unistr2_to_ascii(temp, &usr->uni_acct_desc, sizeof(temp)-1);
1173 fprintf(out_hnd, "\t\tDescription :\t%s\n", temp);
1175 unistr2_to_ascii(temp, &usr->uni_workstations, sizeof(temp)-1);
1176 fprintf(out_hnd, "\t\tWorkstations:\t%s\n", temp);
1178 unistr2_to_ascii(temp, &usr->uni_unknown_str, sizeof(temp)-1);
1179 fprintf(out_hnd, "\t\tUnknown Str :\t%s\n", temp);
1181 unistr2_to_ascii(temp, &usr->uni_munged_dial, sizeof(temp)-1);
1182 fprintf(out_hnd, "\t\tRemote Dial :\t%s\n", temp);
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))));
1191 fprintf(out_hnd, "\t\tunknown_2[0..31]...\n"); /* user passwords? */
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 */
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 */
1201 fprintf(out_hnd, "\t\tpadding1[0..7]...\n");
1203 if (usr->ptr_logon_hrs)
1205 fprintf(out_hnd, "\t\tlogon_hrs[0..%d]...\n", usr->logon_hrs.len);
1212 fprintf(out_hnd, "\n");
1219 /****************************************************************************
1220 convert a security permissions into a string
1221 ****************************************************************************/
1222 char *get_sec_mask_str(uint32 type)
1224 static fstring typestr;
1229 case SEC_RIGHTS_FULL_CONTROL:
1231 fstrcpy(typestr, "Full Control");
1235 case SEC_RIGHTS_READ:
1237 fstrcpy(typestr, "Read");
1247 for (i = 0; i < 32; i++)
1249 if (IS_BITS_SET_ALL(type, 1 << i))
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;
1268 /* remaining bits get added on as-is */
1272 slprintf(tmp, sizeof(tmp)-1, "[%08x]", type);
1273 fstrcat(typestr, tmp);
1276 /* remove last space */
1277 i = strlen(typestr)-1;
1278 if (typestr[i] == ' ') typestr[i] = 0;
1283 /****************************************************************************
1284 display sec_access structure
1285 ****************************************************************************/
1286 void display_sec_access(FILE *out_hnd, enum action_type action, SEC_ACCESS *info)
1294 case ACTION_ENUMERATE:
1296 fprintf(out_hnd, "\t\tPermissions:\t%s\n",
1297 get_sec_mask_str(info->mask));
1306 /****************************************************************************
1307 display sec_ace structure
1308 ****************************************************************************/
1309 void display_sec_ace(FILE *out_hnd, enum action_type action, SEC_ACE *ace)
1315 fprintf(out_hnd, "\tACE\n");
1318 case ACTION_ENUMERATE:
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);
1326 sid_to_string(sid_str, &ace->sid);
1327 fprintf(out_hnd, "\t\tSID:\t%s\n", sid_str);
1336 /****************************************************************************
1337 display sec_acl structure
1338 ****************************************************************************/
1339 void display_sec_acl(FILE *out_hnd, enum action_type action, SEC_ACL *sec_acl)
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");
1351 case ACTION_ENUMERATE:
1353 if (sec_acl->size != 0 && sec_acl->num_aces != 0)
1356 for (i = 0; i < sec_acl->num_aces; i++)
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]);
1368 fprintf(out_hnd, "\n");
1374 /****************************************************************************
1375 display sec_desc structure
1376 ****************************************************************************/
1377 void display_sec_desc(FILE *out_hnd, enum action_type action, SEC_DESC *sec)
1383 fprintf(out_hnd, "\tSecurity Descriptor\trevision:\t%x\ttype:\t%x\n",
1384 sec->revision, sec->type);
1385 fprintf(out_hnd, "\t-------------------\n");
1389 case ACTION_ENUMERATE:
1393 if (sec->off_sacl != 0)
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);
1399 if (sec->off_dacl != 0)
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);
1405 if (sec->off_owner_sid != 0)
1407 sid_to_string(sid_str, sec->owner_sid);
1408 fprintf(out_hnd, "\tOwner SID:\t%s\n", sid_str);
1410 if (sec->off_grp_sid != 0)
1412 sid_to_string(sid_str, sec->grp_sid);
1413 fprintf(out_hnd, "\tParent SID:\t%s\n", sid_str);
1420 fprintf(out_hnd, "\n");
1426 /****************************************************************************
1427 convert a security permissions into a string
1428 ****************************************************************************/
1429 char *get_reg_val_type_str(uint32 type)
1431 static fstring typestr;
1437 fstrcpy(typestr, "string");
1443 fstrcpy(typestr, "bytes");
1449 fstrcpy(typestr, "uint32");
1455 fstrcpy(typestr, "multi");
1463 slprintf(typestr, sizeof(typestr)-1, "[%d]", type);
1468 static void print_reg_value(FILE *out_hnd, char *val_name, uint32 val_type, BUFFER2 *value)
1473 fstrcpy(type, get_reg_val_type_str(val_type));
1477 case 0x01: /* unistr */
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);
1485 default: /* unknown */
1486 case 0x03: /* bytes */
1488 if (value->buf_len <= 8)
1490 fprintf(out_hnd,"\t%s:\t%s:\t", val_name, type);
1491 out_data(out_hnd, (char*)value->buffer, value->buf_len, 8);
1495 fprintf(out_hnd,"\t%s:\t%s:\n", val_name, type);
1496 out_data(out_hnd, (char*)value->buffer, value->buf_len, 16);
1501 case 0x04: /* uint32 */
1503 fprintf(out_hnd,"\t%s:\t%s:\t0x%08x\n", val_name, type, buffer2_to_uint32(value));
1507 case 0x07: /* multiunistr */
1509 buffer2_to_multistr(valstr, value, sizeof(valstr)-1);
1510 fprintf(out_hnd,"\t%s:\t%s:\t%s\n", val_name, type, valstr);
1516 /****************************************************************************
1518 ****************************************************************************/
1519 void display_reg_value_info(FILE *out_hnd, enum action_type action,
1520 char *val_name, uint32 val_type, BUFFER2 *value)
1528 case ACTION_ENUMERATE:
1530 print_reg_value(out_hnd, val_name, val_type, value);
1540 /****************************************************************************
1542 ****************************************************************************/
1543 void display_reg_key_info(FILE *out_hnd, enum action_type action,
1544 char *key_name, time_t key_mod_time)
1552 case ACTION_ENUMERATE:
1554 fprintf(out_hnd, "\t%s\t(%s)\n",
1555 key_name, http_timestring(key_mod_time));
1565 /****************************************************************************
1566 convert a security permissions into a string
1567 ****************************************************************************/
1568 char *get_svc_start_type_str(uint32 type)
1570 static fstring typestr;
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;
1581 slprintf(typestr, sizeof(typestr)-1, "[%d]", type);
1586 /****************************************************************************
1588 ****************************************************************************/
1589 void display_query_svc_cfg(FILE *out_hnd, enum action_type action,
1590 QUERY_SERVICE_CONFIG *cfg)
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");
1603 case ACTION_ENUMERATE:
1607 unistr2_to_ascii(temp, &cfg->uni_bin_path_name, sizeof(temp)-1);
1608 fprintf(out_hnd, "\tPath:\t%s\n", temp);
1610 unistr2_to_ascii(temp, &cfg->uni_load_order_grp, sizeof(temp)-1);
1611 fprintf(out_hnd, "\tLoad Order:\t%s\n", temp);
1613 unistr2_to_ascii(temp, &cfg->uni_dependencies, sizeof(temp)-1);
1614 fprintf(out_hnd, "\tDependencies:\t%s\n", temp);
1616 unistr2_to_ascii(temp, &cfg->uni_service_start_name, sizeof(temp)-1);
1617 fprintf(out_hnd, "\tService Start:\t%s\n", temp);
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);
1628 fprintf(out_hnd, "\n");
1634 /****************************************************************************
1636 ****************************************************************************/
1637 void display_svc_info(FILE *out_hnd, enum action_type action, ENUM_SRVC_STATUS *svc)
1645 case ACTION_ENUMERATE:
1649 unistr_to_ascii(name, svc->uni_srvc_name.buffer,
1650 sizeof(name)-1); /* service name */
1651 fprintf(out_hnd, "\t%s:", name);
1653 unistr_to_ascii(name, svc->uni_disp_name.buffer,
1654 sizeof(name)-1); /* display name */
1655 fprintf(out_hnd, "\t%s\n", name);
1665 #if COPY_THIS_TEMPLATE
1666 /****************************************************************************
1668 ****************************************************************************/
1669 void display_(FILE *out_hnd, enum action_type action, *)
1675 fprintf(out_hnd, "\t\n");
1676 fprintf(out_hnd, "\t-------------------\n");
1680 case ACTION_ENUMERATE:
1686 fprintf(out_hnd, "\n");