Skip to content

Commit

Permalink
Fix validation for empty SMB share name
Browse files Browse the repository at this point in the history
We weren't raising a validation error on empty string for SMB
share name.
  • Loading branch information
anodos325 committed Mar 6, 2024
1 parent c473f3e commit f5e0ef4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/middlewared/middlewared/plugins/smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,12 @@ async def validate_share_name(self, name, schema_name, verrors, exist_ok=True):
f'{name} is a reserved section name, please select another one'
)

if len(name) == 0:
verrors.add(
f'{schema_name}.name',
'Share name may not be an empty string.'
)

invalid_characters = INVALID_SHARE_NAME_CHARACTERS & set(name)
if invalid_characters:
verrors.add(
Expand Down Expand Up @@ -1518,7 +1524,7 @@ async def validate(self, data, schema_name, verrors, old=None):
'of SMB share.'
)

if data.get('name'):
if data.get('name') is not None:
await self.validate_share_name(data['name'], schema_name, verrors)

if data.get('path_suffix') and len(data['path_suffix'].split('/')) > 2:
Expand Down Expand Up @@ -1583,7 +1589,7 @@ async def share_precheck(self, data):
'at least one local SMB user before creating an SMB share.'
)

if data.get('name'):
if data.get('name') is not None:
await self.validate_share_name(data['name'], 'sharing.smb.share_precheck', verrors, False)

verrors.check()
Expand Down

0 comments on commit f5e0ef4

Please sign in to comment.