@@ -31,10 +31,12 @@ type SmbStatusSigning struct {
31
31
Degree string `json:"degree"`
32
32
}
33
33
34
- // SmbStatusShare represents a single entry from the output of 'smbstatus -S'
35
- type SmbStatusShare struct {
34
+ // SmbStatusTreeCon represents a 'tcon' output field
35
+ type SmbStatusTreeCon struct {
36
36
Service string `json:"service"`
37
37
ServerID SmbStatusServerID `json:"server_id"`
38
+ TConID string `json:"tcon_id"`
39
+ SessionID string `json:"session_id"`
38
40
Machine string `json:"machine"`
39
41
ConnectedAt string `json:"connected_at"`
40
42
Encryption SmbStatusEncryption `json:"encryption"`
@@ -81,7 +83,7 @@ type SmbStatusJSON struct {
81
83
Version string `json:"version"`
82
84
SmbConf string `json:"smb_conf"`
83
85
Sessions map [string ]SmbStatusSession `json:"sessions"`
84
- TCons map [string ]SmbStatusShare `json:"tcons"`
86
+ TCons map [string ]SmbStatusTreeCon `json:"tcons"`
85
87
LockedFiles map [string ]SmbStatusLockedFile `json:"locked_files"`
86
88
}
87
89
@@ -148,7 +150,7 @@ func RunSmbStatusVersion() (string, error) {
148
150
}
149
151
150
152
// RunSmbStatusShares executes 'smbstatus -S' on host container
151
- func RunSmbStatusShares () ([]SmbStatusShare , error ) {
153
+ func RunSmbStatusShares () ([]SmbStatusTreeCon , error ) {
152
154
// Case 1: using new json output
153
155
dat , err := executeSmbStatusCommand ("-S --json" )
154
156
if err == nil {
@@ -159,19 +161,19 @@ func RunSmbStatusShares() ([]SmbStatusShare, error) {
159
161
if err == nil {
160
162
return parseSmbStatusShares (dat )
161
163
}
162
- return []SmbStatusShare {}, err
164
+ return []SmbStatusTreeCon {}, err
163
165
}
164
166
165
- func parseSmbStatusSharesAsJSON (dat string ) ([]SmbStatusShare , error ) {
166
- shares := []SmbStatusShare {}
167
+ func parseSmbStatusSharesAsJSON (dat string ) ([]SmbStatusTreeCon , error ) {
168
+ tcons := []SmbStatusTreeCon {}
167
169
res , err := parseSmbStatusJSON (dat )
168
170
if err != nil {
169
- return shares , err
171
+ return tcons , err
170
172
}
171
173
for _ , share := range res .TCons {
172
- shares = append (shares , share )
174
+ tcons = append (tcons , share )
173
175
}
174
- return shares , nil
176
+ return tcons , nil
175
177
}
176
178
177
179
// RunSmbStatusLocks executes 'smbstatus -L' on host container
@@ -215,16 +217,16 @@ func RunSmbStatusProcs() ([]SmbStatusProc, error) {
215
217
216
218
// SmbStatusSharesByMachine converts the output of RunSmbStatusShares into map
217
219
// indexed by machine's host
218
- func SmbStatusSharesByMachine () (map [string ][]SmbStatusShare , error ) {
220
+ func SmbStatusSharesByMachine () (map [string ][]SmbStatusTreeCon , error ) {
219
221
shares , err := RunSmbStatusShares ()
220
222
if err != nil {
221
- return map [string ][]SmbStatusShare {}, err
223
+ return map [string ][]SmbStatusTreeCon {}, err
222
224
}
223
225
return makeSmbSharesMap (shares ), nil
224
226
}
225
227
226
- func makeSmbSharesMap (shares []SmbStatusShare ) map [string ][]SmbStatusShare {
227
- ret := map [string ][]SmbStatusShare {}
228
+ func makeSmbSharesMap (shares []SmbStatusTreeCon ) map [string ][]SmbStatusTreeCon {
229
+ ret := map [string ][]SmbStatusTreeCon {}
228
230
for _ , share := range shares {
229
231
ret [share .Machine ] = append (ret [share .Machine ], share )
230
232
}
@@ -251,8 +253,8 @@ func executeCommand(command string, arg ...string) (string, error) {
251
253
252
254
// parseSmbStatusShares parses to output of 'smbstatus -S' into internal
253
255
// representation.
254
- func parseSmbStatusShares (data string ) ([]SmbStatusShare , error ) {
255
- shares := []SmbStatusShare {}
256
+ func parseSmbStatusShares (data string ) ([]SmbStatusTreeCon , error ) {
257
+ shares := []SmbStatusTreeCon {}
256
258
serviceIndex := 0
257
259
pidIndex := 0
258
260
machineIndex := 0
@@ -287,7 +289,7 @@ func parseSmbStatusShares(data string) ([]SmbStatusShare, error) {
287
289
continue
288
290
}
289
291
// Parse data into internal repr
290
- share := SmbStatusShare {}
292
+ share := SmbStatusTreeCon {}
291
293
share .Service = parseSubstr (ln , serviceIndex )
292
294
share .ServerID .PID = parseSubstr (ln , pidIndex )
293
295
share .Machine = parseSubstr (ln , machineIndex )
0 commit comments