Server: ServerService: correctly handle unsupported ShareEnum levels

This commit is contained in:
Tal Aloni 2024-01-06 21:26:22 +02:00
parent 64a27f1d86
commit 3b683cd4ae
6 changed files with 84 additions and 22 deletions

View 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;
}
}
}
}

View 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;
}
}
}
}

View file

@ -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
* the GNU Lesser Public License as published by the Free Software Foundation,
@ -6,8 +6,6 @@
*/
using System;
using System.Collections.Generic;
using System.Text;
using Utilities;
namespace SMBLibrary.Services
{
@ -47,8 +45,7 @@ namespace SMBLibrary.Services
{
case ServerServiceOpName.NetrShareEnum:
{
NetrShareEnumRequest request = new NetrShareEnumRequest(requestBytes);
NetrShareEnumResponse response = GetNetrShareEnumResponse(request);
NetrShareEnumResponse response = GetNetrShareEnumResponse(requestBytes);
return response.GetBytes();
}
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();
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)
{
case 0:

View file

@ -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
* 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;
using System.Collections.Generic;
using SMBLibrary.RPC;
using Utilities;
namespace SMBLibrary.Services
{
@ -56,9 +53,8 @@ namespace SMBLibrary.Services
Info = info101;
break;
default:
throw new NotImplementedException();
throw new InvalidLevelException(Level);
}
;
parser.EndStructure(); // SERVER_INFO Union
}

View file

@ -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
* 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;
using System.Collections.Generic;
using SMBLibrary.RPC;
using Utilities;
namespace SMBLibrary.Services
{
@ -64,9 +62,9 @@ namespace SMBLibrary.Services
case 501:
case 502:
case 503:
throw new NotImplementedException();
throw new UnsupportedLevelException(level);
default:
break;
throw new InvalidLevelException(level);
}
parser.EndStructure(); // SHARE_ENUM_UNION
parser.EndStructure(); // SHARE_ENUM_STRUCT

View file

@ -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
* 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;
using System.Collections.Generic;
using SMBLibrary.RPC;
using Utilities;
namespace SMBLibrary.Services
{
@ -56,7 +53,7 @@ namespace SMBLibrary.Services
Info = info1;
break;
default:
throw new NotImplementedException();
throw new InvalidLevelException(Level);
}
parser.EndStructure(); // SHARE_INFO Union
}