disklabel[32,64] utilities - Change the default disklabel program
[dragonfly.git] / contrib / smbfs / smbutil / dumptree.c
blob2ae383318ed3de8ac77fd6e37c6e837ab8fc9ee6
1 #include <sys/param.h>
2 #include <sys/time.h>
3 #include <grp.h>
4 #include <pwd.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <stdlib.h>
9 #ifdef APPLE
10 #include <err.h>
11 #include <sysexits.h>
12 #endif
14 #include <netsmb/smb_lib.h>
15 #include <netsmb/smb_conn.h>
17 #include "common.h"
19 #define DEFBIT(bit) {bit, #bit}
21 static struct smb_bitname conn_caps[] = {
22 DEFBIT(SMB_CAP_RAW_MODE),
23 DEFBIT(SMB_CAP_MPX_MODE),
24 DEFBIT(SMB_CAP_UNICODE),
25 DEFBIT(SMB_CAP_LARGE_FILES),
26 DEFBIT(SMB_CAP_NT_SMBS),
27 DEFBIT(SMB_CAP_NT_FIND),
28 DEFBIT(SMB_CAP_EXT_SECURITY),
29 {0, NULL}
32 static struct smb_bitname vc_flags[] = {
33 DEFBIT(SMBV_PERMANENT),
34 {SMBV_PRIVATE, "private"},
35 {SMBV_SINGLESHARE, "singleshare"},
36 {SMBV_ENCRYPT, "encpwd"},
37 {SMBV_WIN95, "win95"},
38 {SMBV_LONGNAMES,"longnames"},
39 {0, NULL}
42 static struct smb_bitname ss_flags[] = {
43 DEFBIT(SMBS_PERMANENT),
44 {0, NULL}
47 static char *conn_proto[] = {
48 "unknown",
49 "PC NETWORK PROGRAM 1.0, PCLAN1.0",
50 "MICROSOFT NETWORKS 1.03",
51 "MICROSOFT NETWORKS 3.0, LANMAN1.0",
52 "LM1.2X002, DOS LM1.2X002",
53 "DOS LANMAN2.1, LANMAN2.1",
54 "NT LM 0.12, Windows for Workgroups 3.1a, NT LANMAN 1.0"
57 static char *iod_state[] = {
58 "Not connected",
59 "Reconnecting",
60 "Transport activated",
61 "Session active",
62 "Session dead"
65 static void
66 print_vcinfo(struct smb_vc_info *vip)
68 char buf[200];
70 printf("VC: \\\\%s\\%s\n", vip->srvname, vip->vcname);
71 printf("(%s:%s) %o", user_from_uid(vip->uid, 0),
72 group_from_gid(vip->gid, 0), vip->mode);
73 printf("\n");
74 if (!verbose)
75 return;
76 iprintf(4, "state: %s\n", iod_state[vip->iodstate]);
77 iprintf(4, "flags: 0x%04x %s\n", vip->flags,
78 smb_printb(buf, vip->flags, vc_flags));
79 iprintf(4, "usecount: %d\n", vip->usecount);
80 iprintf(4, "dialect: %d (%s)\n", vip->sopt.sv_proto, conn_proto[vip->sopt.sv_proto]);
81 iprintf(4, "smode: %d\n", vip->sopt.sv_sm);
82 iprintf(4, "caps: 0x%04x %s\n", vip->sopt.sv_caps,
83 smb_printb(buf, vip->sopt.sv_caps, conn_caps));
84 iprintf(4, "maxmux: %d\n", vip->sopt.sv_maxmux);
85 iprintf(4, "maxvcs: %d\n", vip->sopt.sv_maxvcs);
88 static void
89 print_shareinfo(struct smb_share_info *sip)
91 char buf[200];
93 iprintf(4, "Share: %s", sip->sname);
94 printf("(%s:%s) %o", user_from_uid(sip->uid, 0),
95 group_from_gid(sip->gid, 0), sip->mode);
96 printf("\n");
97 if (!verbose)
98 return;
99 iprintf(8, "flags: 0x%04x %s\n", sip->flags,
100 smb_printb(buf, sip->flags, ss_flags));
101 iprintf(8, "usecount: %d\n", sip->usecount);
105 cmd_dumptree(int argc, char *argv[])
107 void *p, *op;
108 int *itype;
110 printf("SMB connections:\n");
111 #ifdef APPLE
112 if (loadsmbvfs())
113 errx(EX_OSERR, "SMB filesystem is not available");
114 #endif
115 p = smb_dumptree();
116 if (p == NULL) {
117 printf("None\n");
118 return 0;
120 op = p;
121 for (;;) {
122 itype = p;
123 if (*itype == SMB_INFO_NONE)
124 break;
125 switch (*itype) {
126 case SMB_INFO_VC:
127 print_vcinfo(p);
128 p = (struct smb_vc_info*)p + 1;
129 break;
130 case SMB_INFO_SHARE:
131 print_shareinfo(p);
132 p = (struct smb_share_info*)p + 1;
133 break;
134 default:
135 printf("Out of sync\n");
136 free(op);
137 return 1;
141 free(op);
142 printf("\n");
143 return 0;