mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-09 07:43:03 +01:00
update sharpcifs
This commit is contained in:
@@ -22,115 +22,114 @@ using SharpCifs.Util.Sharpen;
|
||||
|
||||
namespace SharpCifs.Dcerpc
|
||||
{
|
||||
public class DcerpcPipeHandle : DcerpcHandle
|
||||
{
|
||||
internal SmbNamedPipe Pipe;
|
||||
public class DcerpcPipeHandle : DcerpcHandle
|
||||
{
|
||||
internal SmbNamedPipe Pipe;
|
||||
|
||||
internal SmbFileInputStream In;
|
||||
internal SmbFileInputStream In;
|
||||
|
||||
internal SmbFileOutputStream Out;
|
||||
internal SmbFileOutputStream Out;
|
||||
|
||||
internal bool IsStart = true;
|
||||
internal bool IsStart = true;
|
||||
|
||||
/// <exception cref="UnknownHostException"></exception>
|
||||
/// <exception cref="System.UriFormatException"></exception>
|
||||
/// <exception cref="SharpCifs.Dcerpc.DcerpcException"></exception>
|
||||
public DcerpcPipeHandle(string url, NtlmPasswordAuthentication auth)
|
||||
{
|
||||
Binding = ParseBinding(url);
|
||||
url = "smb://" + Binding.Server + "/IPC$/" + Runtime.Substring(Binding.Endpoint, 6);
|
||||
string @params = string.Empty;
|
||||
string server;
|
||||
string address;
|
||||
server = (string)Binding.GetOption("server");
|
||||
if (server != null)
|
||||
{
|
||||
@params += "&server=" + server;
|
||||
}
|
||||
address = (string)Binding.GetOption("address");
|
||||
if (server != null)
|
||||
{
|
||||
@params += "&address=" + address;
|
||||
}
|
||||
if (@params.Length > 0)
|
||||
{
|
||||
url += "?" + Runtime.Substring(@params, 1);
|
||||
}
|
||||
Pipe = new SmbNamedPipe(url,
|
||||
(unchecked(0x2019F) << 16)
|
||||
| SmbNamedPipe.PipeTypeRdwr
|
||||
| SmbNamedPipe.PipeTypeDceTransact,
|
||||
auth);
|
||||
}
|
||||
/// <exception cref="UnknownHostException"></exception>
|
||||
/// <exception cref="System.UriFormatException"></exception>
|
||||
/// <exception cref="SharpCifs.Dcerpc.DcerpcException"></exception>
|
||||
public DcerpcPipeHandle(string url, NtlmPasswordAuthentication auth)
|
||||
{
|
||||
Binding = ParseBinding(url);
|
||||
url = "smb://" + Binding.Server + "/IPC$/" + Runtime.Substring(Binding.Endpoint
|
||||
, 6);
|
||||
string @params = string.Empty;
|
||||
string server;
|
||||
string address;
|
||||
server = (string)Binding.GetOption("server");
|
||||
if (server != null)
|
||||
{
|
||||
@params += "&server=" + server;
|
||||
}
|
||||
address = (string)Binding.GetOption("address");
|
||||
if (server != null)
|
||||
{
|
||||
@params += "&address=" + address;
|
||||
}
|
||||
if (@params.Length > 0)
|
||||
{
|
||||
url += "?" + Runtime.Substring(@params, 1);
|
||||
}
|
||||
Pipe = new SmbNamedPipe(url, (unchecked(0x2019F) << 16) | SmbNamedPipe.PipeTypeRdwr
|
||||
| SmbNamedPipe.PipeTypeDceTransact, auth);
|
||||
}
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
protected internal override void DoSendFragment(byte[] buf, int off, int length, bool isDirect)
|
||||
{
|
||||
if (Out != null && Out.IsOpen() == false)
|
||||
{
|
||||
throw new IOException("DCERPC pipe is no longer open");
|
||||
}
|
||||
if (In == null)
|
||||
{
|
||||
In = (SmbFileInputStream)Pipe.GetNamedPipeInputStream();
|
||||
}
|
||||
if (Out == null)
|
||||
{
|
||||
Out = (SmbFileOutputStream)Pipe.GetNamedPipeOutputStream();
|
||||
}
|
||||
if (isDirect)
|
||||
{
|
||||
Out.WriteDirect(buf, off, length, 1);
|
||||
return;
|
||||
}
|
||||
Out.Write(buf, off, length);
|
||||
}
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
protected internal override void DoSendFragment(byte[] buf, int off, int length,
|
||||
bool isDirect)
|
||||
{
|
||||
if (Out != null && Out.IsOpen() == false)
|
||||
{
|
||||
throw new IOException("DCERPC pipe is no longer open");
|
||||
}
|
||||
if (In == null)
|
||||
{
|
||||
In = (SmbFileInputStream)Pipe.GetNamedPipeInputStream();
|
||||
}
|
||||
if (Out == null)
|
||||
{
|
||||
Out = (SmbFileOutputStream)Pipe.GetNamedPipeOutputStream();
|
||||
}
|
||||
if (isDirect)
|
||||
{
|
||||
Out.WriteDirect(buf, off, length, 1);
|
||||
return;
|
||||
}
|
||||
Out.Write(buf, off, length);
|
||||
}
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
protected internal override void DoReceiveFragment(byte[] buf, bool isDirect)
|
||||
{
|
||||
int off;
|
||||
int flags;
|
||||
int length;
|
||||
if (buf.Length < MaxRecv)
|
||||
{
|
||||
throw new ArgumentException("buffer too small");
|
||||
}
|
||||
if (IsStart && !isDirect)
|
||||
{
|
||||
// start of new frag, do trans
|
||||
off = In.Read(buf, 0, 1024);
|
||||
}
|
||||
else
|
||||
{
|
||||
off = In.ReadDirect(buf, 0, buf.Length);
|
||||
}
|
||||
if (buf[0] != 5 && buf[1] != 0)
|
||||
{
|
||||
throw new IOException("Unexpected DCERPC PDU header");
|
||||
}
|
||||
flags = buf[3] & unchecked(0xFF);
|
||||
// next read is start of new frag
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
protected internal override void DoReceiveFragment(byte[] buf, bool isDirect)
|
||||
{
|
||||
int off;
|
||||
int flags;
|
||||
int length;
|
||||
if (buf.Length < MaxRecv)
|
||||
{
|
||||
throw new ArgumentException("buffer too small");
|
||||
}
|
||||
if (IsStart && !isDirect)
|
||||
{
|
||||
// start of new frag, do trans
|
||||
off = In.Read(buf, 0, 1024);
|
||||
}
|
||||
else
|
||||
{
|
||||
off = In.ReadDirect(buf, 0, buf.Length);
|
||||
}
|
||||
if (buf[0] != 5 && buf[1] != 0)
|
||||
{
|
||||
throw new IOException("Unexpected DCERPC PDU header");
|
||||
}
|
||||
flags = buf[3] & unchecked(0xFF);
|
||||
// next read is start of new frag
|
||||
IsStart = (flags & DcerpcConstants.DcerpcLastFrag) == DcerpcConstants.DcerpcLastFrag;
|
||||
length = Encdec.Dec_uint16le(buf, 8);
|
||||
if (length > MaxRecv)
|
||||
{
|
||||
throw new IOException("Unexpected fragment length: " + length);
|
||||
}
|
||||
while (off < length)
|
||||
{
|
||||
off += In.ReadDirect(buf, off, length - off);
|
||||
}
|
||||
}
|
||||
length = Encdec.Dec_uint16le(buf, 8);
|
||||
if (length > MaxRecv)
|
||||
{
|
||||
throw new IOException("Unexpected fragment length: " + length);
|
||||
}
|
||||
while (off < length)
|
||||
{
|
||||
off += In.ReadDirect(buf, off, length - off);
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
public override void Close()
|
||||
{
|
||||
State = 0;
|
||||
if (Out != null)
|
||||
{
|
||||
Out.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
public override void Close()
|
||||
{
|
||||
State = 0;
|
||||
if (Out != null)
|
||||
{
|
||||
Out.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user