Skip to content

smbserver: report the configured share type over SMB2 - #2355

Closed
qianeric-backup wants to merge 1 commit into
fortra:masterfrom
qianeric-backup:fix/smb2-share-types
Closed

qianeric-backup wants to merge 1 commit into
fortra:masterfrom
qianeric-backup:fix/smb2-share-types

Conversation

@qianeric-backup

Copy link
Copy Markdown
Contributor

What this fixes

Shares served over SMB2 all came back as Disk, whatever type they were configured with.
addShare stores the type as a string coming from the config section, and the SMB1 handlers convert
it:

entry['Type'] = int(shares[i]['share type'])
...
shareInfo['Type'] = int(share['share type'])

but the two SMB2 handlers assigned it straight into the NDR field:

answer['InfoStruct']['ShareInfo1']['shi1_type'] = share['share type']
...
shareInfo['shi1_type'] = self._shares[i]['share type']

so a printer or an IPC share was announced as a disk tree. Thanks to @rwakulszowa for pointing at
the two lines.

Fixes #2271.

Verification

smbclient against a server exposing a disk share, a shareType="1" printer and an
shareType="3" IPC share:

before                          after
Sharename   Type                Sharename   Type
IPC$        Disk                IPC$        IPC
DISK        Disk                DISK        Disk
PRINTER     Disk                PRINTER     Printer

Test

test_smbserver_list_shares_types lists shares from a server with all three types and asserts the
reported types. It runs under every dialect the suite covers, and the before/after is unambiguous:

before the fix:  5 failed, 5 passed
after the fix:  10 passed

The five that failed are exactly the SMB2 subclasses (SimpleSMBServer2FuncTests,
SimpleSMBServer2FuncTestsClientFallBack, SimpleSMBServer21FuncTests,
SimpleSMBServer311FuncTests); the SMB1 subclass passed before the change too, which matches the
fact that its handlers already had the conversion. Full file: 89 passed, 8 skipped.

Scope

Two lines changed, both in the SMB2 share enumeration/query handlers. No behaviour change for SMB1,
and no change to how the type is stored or parsed.

Shares served over SMB2 all came back as `Disk`. `addShare` stores the type
as a string from the config section, and the SMB1 handlers convert it:

    entry['Type'] = int(shares[i]['share type'])

while the two SMB2 handlers assigned it straight into the NDR field:

    answer['InfoStruct']['ShareInfo1']['shi1_type'] = share['share type']
    shareInfo['shi1_type'] = self._shares[i]['share type']

so a printer or an IPC share was announced as a disk tree:

    Sharename       Type
    IPC$            Disk
    DISK            Disk
    PRINTER         Disk

Convert in both SMB2 handlers, matching what the SMB1 ones already do.

Verified with smbclient against a server exposing disk, printer and IPC
shares:

    before                      after
    IPC$     type=0 -> Disk     IPC$     type=3 -> IPC
    DISK     type=0 -> Disk     DISK     type=0 -> Disk
    PRINTER  type=0 -> Disk     PRINTER  type=1 -> Printer

test_smbserver_list_shares_types covers this for every SMB dialect the
suite runs. It fails on the four SMB2 subclasses before the change and
passes after; the SMB1 subclass passed either way, which matches where the
conversion was already present.

Fixes fortra#2271
@anadrianmanrique

Copy link
Copy Markdown
Collaborator

this one looks like duplicate of #2280

@qianeric-backup

Copy link
Copy Markdown
Contributor Author

You're right, this is a duplicate of #2280 -- same two lines, same Fixes #2271. I checked the issue's timeline but not for an already-open PR implementing it, which is on me. Closing this one.

@gabrielg5's change is the correct minimal fix and I'd rather not split the review across two PRs.

For what it's worth, I did verify the behaviour end-to-end against a server exposing three share types, which may save whoever reviews #2280 some time:

config shares (shareType="0" / "1" / "3")

before                          after
Sharename   Type                Sharename   Type
IPC$        Disk                IPC$        IPC
DISK        Disk                DISK        Disk
PRINTER     Disk                PRINTER     Printer

Also worth noting while you're in there: the SMB1 handlers already coerce with int(...) in both places (MSRPC_UUID_SRVS_NETR_SHARE_ENUM and _GET_INFO), so #2280 brings the SMB2 path in line with SMB1 rather than introducing a new convention. And ConfigParser will happily return a non-numeric string if someone writes shareType = printer, in which case int() raises ValueError inside the RPC handler -- that is a separate, pre-existing issue (SMB1 has the same exposure) and not something #2280 needs to solve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

All SMB shares report type of Disk

2 participants