mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-04-30 10:47:48 +02:00
Server: ServerService: correctly handle unsupported ShareEnum levels
This commit is contained in:
parent
64a27f1d86
commit
3b683cd4ae
6 changed files with 84 additions and 22 deletions
28
SMBLibrary/Services/Exceptions/InvalidLevelException.cs
Normal file
28
SMBLibrary/Services/Exceptions/InvalidLevelException.cs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/* Copyright (C) 2024 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||||
|
*
|
||||||
|
* You can redistribute this program and/or modify it under the terms of
|
||||||
|
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||||
|
* either version 3 of the License, or (at your option) any later version.
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace SMBLibrary.Services
|
||||||
|
{
|
||||||
|
public class InvalidLevelException : Exception
|
||||||
|
{
|
||||||
|
private uint m_level;
|
||||||
|
|
||||||
|
public InvalidLevelException(uint level)
|
||||||
|
{
|
||||||
|
m_level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint Level
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return m_level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
SMBLibrary/Services/Exceptions/UnsupportedLevelException.cs
Normal file
28
SMBLibrary/Services/Exceptions/UnsupportedLevelException.cs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/* Copyright (C) 2024 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||||
|
*
|
||||||
|
* You can redistribute this program and/or modify it under the terms of
|
||||||
|
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||||
|
* either version 3 of the License, or (at your option) any later version.
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace SMBLibrary.Services
|
||||||
|
{
|
||||||
|
public class UnsupportedLevelException : Exception
|
||||||
|
{
|
||||||
|
private uint m_level;
|
||||||
|
|
||||||
|
public UnsupportedLevelException(uint level)
|
||||||
|
{
|
||||||
|
m_level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint Level
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return m_level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2014-2018 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2014-2024 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||||
*
|
*
|
||||||
* You can redistribute this program and/or modify it under the terms of
|
* You can redistribute this program and/or modify it under the terms of
|
||||||
* the GNU Lesser Public License as published by the Free Software Foundation,
|
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||||
|
@ -6,8 +6,6 @@
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
|
||||||
using Utilities;
|
|
||||||
|
|
||||||
namespace SMBLibrary.Services
|
namespace SMBLibrary.Services
|
||||||
{
|
{
|
||||||
|
@ -47,8 +45,7 @@ namespace SMBLibrary.Services
|
||||||
{
|
{
|
||||||
case ServerServiceOpName.NetrShareEnum:
|
case ServerServiceOpName.NetrShareEnum:
|
||||||
{
|
{
|
||||||
NetrShareEnumRequest request = new NetrShareEnumRequest(requestBytes);
|
NetrShareEnumResponse response = GetNetrShareEnumResponse(requestBytes);
|
||||||
NetrShareEnumResponse response = GetNetrShareEnumResponse(request);
|
|
||||||
return response.GetBytes();
|
return response.GetBytes();
|
||||||
}
|
}
|
||||||
case ServerServiceOpName.NetrShareGetInfo:
|
case ServerServiceOpName.NetrShareGetInfo:
|
||||||
|
@ -68,9 +65,27 @@ namespace SMBLibrary.Services
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetrShareEnumResponse GetNetrShareEnumResponse(NetrShareEnumRequest request)
|
public NetrShareEnumResponse GetNetrShareEnumResponse(byte[] requestBytes)
|
||||||
{
|
{
|
||||||
|
NetrShareEnumRequest request;
|
||||||
NetrShareEnumResponse response = new NetrShareEnumResponse();
|
NetrShareEnumResponse response = new NetrShareEnumResponse();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
request = new NetrShareEnumRequest(requestBytes);
|
||||||
|
}
|
||||||
|
catch (UnsupportedLevelException ex)
|
||||||
|
{
|
||||||
|
response.InfoStruct = new ShareEnum(ex.Level);
|
||||||
|
response.Result = Win32Error.ERROR_NOT_SUPPORTED;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
catch (InvalidLevelException ex)
|
||||||
|
{
|
||||||
|
response.InfoStruct = new ShareEnum(ex.Level);
|
||||||
|
response.Result = Win32Error.ERROR_INVALID_LEVEL;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
switch (request.InfoStruct.Level)
|
switch (request.InfoStruct.Level)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
/* Copyright (C) 2014-2018 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2014-2024 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||||
*
|
*
|
||||||
* You can redistribute this program and/or modify it under the terms of
|
* You can redistribute this program and/or modify it under the terms of
|
||||||
* the GNU Lesser Public License as published by the Free Software Foundation,
|
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||||
* either version 3 of the License, or (at your option) any later version.
|
* either version 3 of the License, or (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using SMBLibrary.RPC;
|
using SMBLibrary.RPC;
|
||||||
using Utilities;
|
|
||||||
|
|
||||||
namespace SMBLibrary.Services
|
namespace SMBLibrary.Services
|
||||||
{
|
{
|
||||||
|
@ -56,9 +53,8 @@ namespace SMBLibrary.Services
|
||||||
Info = info101;
|
Info = info101;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException();
|
throw new InvalidLevelException(Level);
|
||||||
}
|
}
|
||||||
;
|
|
||||||
parser.EndStructure(); // SERVER_INFO Union
|
parser.EndStructure(); // SERVER_INFO Union
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
/* Copyright (C) 2014-2018 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2014-2024 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||||
*
|
*
|
||||||
* You can redistribute this program and/or modify it under the terms of
|
* You can redistribute this program and/or modify it under the terms of
|
||||||
* the GNU Lesser Public License as published by the Free Software Foundation,
|
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||||
* either version 3 of the License, or (at your option) any later version.
|
* either version 3 of the License, or (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using SMBLibrary.RPC;
|
using SMBLibrary.RPC;
|
||||||
using Utilities;
|
|
||||||
|
|
||||||
namespace SMBLibrary.Services
|
namespace SMBLibrary.Services
|
||||||
{
|
{
|
||||||
|
@ -64,9 +62,9 @@ namespace SMBLibrary.Services
|
||||||
case 501:
|
case 501:
|
||||||
case 502:
|
case 502:
|
||||||
case 503:
|
case 503:
|
||||||
throw new NotImplementedException();
|
throw new UnsupportedLevelException(level);
|
||||||
default:
|
default:
|
||||||
break;
|
throw new InvalidLevelException(level);
|
||||||
}
|
}
|
||||||
parser.EndStructure(); // SHARE_ENUM_UNION
|
parser.EndStructure(); // SHARE_ENUM_UNION
|
||||||
parser.EndStructure(); // SHARE_ENUM_STRUCT
|
parser.EndStructure(); // SHARE_ENUM_STRUCT
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
/* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2014-2024 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||||
*
|
*
|
||||||
* You can redistribute this program and/or modify it under the terms of
|
* You can redistribute this program and/or modify it under the terms of
|
||||||
* the GNU Lesser Public License as published by the Free Software Foundation,
|
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||||
* either version 3 of the License, or (at your option) any later version.
|
* either version 3 of the License, or (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using SMBLibrary.RPC;
|
using SMBLibrary.RPC;
|
||||||
using Utilities;
|
|
||||||
|
|
||||||
namespace SMBLibrary.Services
|
namespace SMBLibrary.Services
|
||||||
{
|
{
|
||||||
|
@ -56,7 +53,7 @@ namespace SMBLibrary.Services
|
||||||
Info = info1;
|
Info = info1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException();
|
throw new InvalidLevelException(Level);
|
||||||
}
|
}
|
||||||
parser.EndStructure(); // SHARE_INFO Union
|
parser.EndStructure(); // SHARE_INFO Union
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue