aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/IO/SharpCifs/Smb
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/IO/SharpCifs/Smb')
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/ACE.cs287
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/AllocInfo.cs25
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/AndXServerMessageBlock.cs221
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/BufferCache.cs80
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/Dfs.cs389
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/DfsReferral.cs67
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/DosError.cs64
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/DosFileFilter.cs37
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/FileEntry.cs33
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/IInfo.cs29
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/NetServerEnum2.cs122
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/NetServerEnum2Response.cs157
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/NetShareEnum.cs95
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/NetShareEnumResponse.cs94
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/NtStatus.cs202
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/NtTransQuerySecurityDesc.cs88
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/NtTransQuerySecurityDescResponse.cs78
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmAuthenticator.cs93
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmChallenge.cs40
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmContext.cs206
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmPasswordAuthentication.cs807
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/Principal.cs28
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SID.cs900
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SecurityDescriptor.cs101
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/ServerMessageBlock.cs692
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SigningDigest.cs257
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbAuthException.cs36
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComBlankResponse.cs47
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComClose.cs62
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComCreateDirectory.cs57
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComDelete.cs63
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComDeleteDirectory.cs57
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComFindClose2.cs56
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComLogoffAndX.cs52
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNTCreateAndX.cs193
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNTCreateAndXResponse.cs116
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNegotiate.cs70
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNegotiateResponse.cs164
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNtTransaction.cs93
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNtTransactionResponse.cs63
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComOpenAndX.cs190
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComOpenAndXResponse.cs87
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComQueryInformation.cs57
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComQueryInformationResponse.cs95
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComReadAndX.cs107
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComReadAndXResponse.cs87
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComRename.cs75
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComSessionSetupAndX.cs234
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComSessionSetupAndXResponse.cs92
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTransaction.cs346
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTransactionResponse.cs206
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTreeConnectAndX.cs226
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTreeConnectAndXResponse.cs84
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTreeDisconnect.cs52
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWrite.cs106
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWriteAndX.cs150
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWriteAndXResponse.cs50
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWriteResponse.cs50
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbConstants.cs302
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbException.cs212
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFile.cs3755
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileExtensions.cs133
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileFilter.cs24
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileInputStream.cs339
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileOutputStream.cs335
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFilenameFilter.cs24
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbNamedPipe.cs210
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbRandomAccessFile.cs506
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbSession.cs570
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbShareInfo.cs104
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbTransport.cs977
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/SmbTree.cs250
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2FindFirst2.cs146
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2FindFirst2Response.cs262
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2FindNext2.cs109
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2GetDfsReferral.cs78
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2GetDfsReferralResponse.cs179
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryFSInformation.cs80
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryFSInformationResponse.cs192
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryPathInformation.cs85
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryPathInformationResponse.cs227
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2SetFileInformation.cs105
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2SetFileInformationResponse.cs63
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/TransCallNamedPipe.cs97
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/TransCallNamedPipeResponse.cs77
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/TransPeekNamedPipe.cs78
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/TransPeekNamedPipeResponse.cs84
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/TransTransactNamedPipe.cs97
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/TransTransactNamedPipeResponse.cs77
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/TransWaitNamedPipe.cs76
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/TransWaitNamedPipeResponse.cs59
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/TransactNamedPipeInputStream.cs180
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/TransactNamedPipeOutputStream.cs86
-rw-r--r--Emby.Server.Implementations/IO/SharpCifs/Smb/WinError.cs49
94 files changed, 0 insertions, 18842 deletions
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/ACE.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/ACE.cs
deleted file mode 100644
index 73b742cfb..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/ACE.cs
+++ /dev/null
@@ -1,287 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System.Text;
-using SharpCifs.Util;
-
-namespace SharpCifs.Smb
-{
- /// <summary>
- /// An Access Control Entry (ACE) is an element in a security descriptor
- /// such as those associated with files and directories.
- /// </summary>
- /// <remarks>
- /// An Access Control Entry (ACE) is an element in a security descriptor
- /// such as those associated with files and directories. The Windows OS
- /// determines which users have the necessary permissions to access objects
- /// based on these entries.
- /// <p>
- /// To fully understand the information exposed by this class a description
- /// of the access check algorithm used by Windows is required. The following
- /// is a basic description of the algorithm. For a more complete description
- /// we recommend reading the section on Access Control in Keith Brown's
- /// "The .NET Developer's Guide to Windows Security" (which is also
- /// available online).
- /// <p>
- /// Direct ACEs are evaluated first in order. The SID of the user performing
- /// the operation and the desired access bits are compared to the SID
- /// and access mask of each ACE. If the SID matches, the allow/deny flags
- /// and access mask are considered. If the ACE is a "deny"
- /// ACE and <i>any</i> of the desired access bits match bits in the access
- /// mask of the ACE, the whole access check fails. If the ACE is an "allow"
- /// ACE and <i>all</i> of the bits in the desired access bits match bits in
- /// the access mask of the ACE, the access check is successful. Otherwise,
- /// more ACEs are evaluated until all desired access bits (combined)
- /// are "allowed". If all of the desired access bits are not "allowed"
- /// the then same process is repeated for inherited ACEs.
- /// <p>
- /// For example, if user <tt>WNET\alice</tt> tries to open a file
- /// with desired access bits <tt>0x00000003</tt> (<tt>FILE_READ_DATA |
- /// FILE_WRITE_DATA</tt>) and the target file has the following security
- /// descriptor ACEs:
- /// <pre>
- /// Allow WNET\alice 0x001200A9 Direct
- /// Allow Administrators 0x001F01FF Inherited
- /// Allow SYSTEM 0x001F01FF Inherited
- /// </pre>
- /// the access check would fail because the direct ACE has an access mask
- /// of <tt>0x001200A9</tt> which doesn't have the
- /// <tt>FILE_WRITE_DATA</tt> bit on (bit <tt>0x00000002</tt>). Actually, this isn't quite correct. If
- /// <tt>WNET\alice</tt> is in the local <tt>Administrators</tt> group the access check
- /// will succeed because the inherited ACE allows local <tt>Administrators</tt>
- /// both <tt>FILE_READ_DATA</tt> and <tt>FILE_WRITE_DATA</tt> access.
- /// </remarks>
- public class Ace
- {
- public const int FileReadData = unchecked(0x00000001);
-
- public const int FileWriteData = unchecked(0x00000002);
-
- public const int FileAppendData = unchecked(0x00000004);
-
- public const int FileReadEa = unchecked(0x00000008);
-
- public const int FileWriteEa = unchecked(0x00000010);
-
- public const int FileExecute = unchecked(0x00000020);
-
- public const int FileDelete = unchecked(0x00000040);
-
- public const int FileReadAttributes = unchecked(0x00000080);
-
- public const int FileWriteAttributes = unchecked(0x00000100);
-
- public const int Delete = unchecked(0x00010000);
-
- public const int ReadControl = unchecked(0x00020000);
-
- public const int WriteDac = unchecked(0x00040000);
-
- public const int WriteOwner = unchecked(0x00080000);
-
- public const int Synchronize = unchecked(0x00100000);
-
- public const int GenericAll = unchecked(0x10000000);
-
- public const int GenericExecute = unchecked(0x20000000);
-
- public const int GenericWrite = unchecked(0x40000000);
-
- public const int GenericRead = unchecked((int)(0x80000000));
-
- public const int FlagsObjectInherit = unchecked(0x01);
-
- public const int FlagsContainerInherit = unchecked(0x02);
-
- public const int FlagsNoPropagate = unchecked(0x04);
-
- public const int FlagsInheritOnly = unchecked(0x08);
-
- public const int FlagsInherited = unchecked(0x10);
-
- internal bool Allow;
-
- internal int Flags;
-
- internal int Access;
-
- internal Sid Sid;
-
- // 1
- // 2
- // 3
- // 4
- // 5
- // 6
- // 7
- // 8
- // 9
- // 16
- // 17
- // 18
- // 19
- // 20
- // 28
- // 29
- // 30
- // 31
- /// <summary>Returns true if this ACE is an allow ACE and false if it is a deny ACE.</summary>
- /// <remarks>Returns true if this ACE is an allow ACE and false if it is a deny ACE.</remarks>
- public virtual bool IsAllow()
- {
- return Allow;
- }
-
- /// <summary>Returns true if this ACE is an inherited ACE and false if it is a direct ACE.
- /// </summary>
- /// <remarks>
- /// Returns true if this ACE is an inherited ACE and false if it is a direct ACE.
- /// <p>
- /// Note: For reasons not fully understood, <tt>FLAGS_INHERITED</tt> may
- /// not be set within all security descriptors even though the ACE was in
- /// face inherited. If an inherited ACE is added to a parent the Windows
- /// ACL editor will rebuild all children ACEs and set this flag accordingly.
- /// </remarks>
- public virtual bool IsInherited()
- {
- return (Flags & FlagsInherited) != 0;
- }
-
- /// <summary>Returns the flags for this ACE.</summary>
- /// <remarks>
- /// Returns the flags for this ACE. The </tt>isInherited()</tt>
- /// method checks the <tt>FLAGS_INHERITED</tt> bit in these flags.
- /// </remarks>
- public virtual int GetFlags()
- {
- return Flags;
- }
-
- /// <summary>
- /// Returns the 'Apply To' text for inheritance of ACEs on
- /// directories such as 'This folder, subfolder and files'.
- /// </summary>
- /// <remarks>
- /// Returns the 'Apply To' text for inheritance of ACEs on
- /// directories such as 'This folder, subfolder and files'. For
- /// files the text is always 'This object only'.
- /// </remarks>
- public virtual string GetApplyToText()
- {
- switch (Flags & (FlagsObjectInherit | FlagsContainerInherit | FlagsInheritOnly
- ))
- {
- case unchecked(0x00):
- {
- return "This folder only";
- }
-
- case unchecked(0x03):
- {
- return "This folder, subfolders and files";
- }
-
- case unchecked(0x0B):
- {
- return "Subfolders and files only";
- }
-
- case unchecked(0x02):
- {
- return "This folder and subfolders";
- }
-
- case unchecked(0x0A):
- {
- return "Subfolders only";
- }
-
- case unchecked(0x01):
- {
- return "This folder and files";
- }
-
- case unchecked(0x09):
- {
- return "Files only";
- }
- }
- return "Invalid";
- }
-
- /// <summary>Returns the access mask accociated with this ACE.</summary>
- /// <remarks>
- /// Returns the access mask accociated with this ACE. Use the
- /// constants for <tt>FILE_READ_DATA</tt>, <tt>FILE_WRITE_DATA</tt>,
- /// <tt>READ_CONTROL</tt>, <tt>GENERIC_ALL</tt>, etc with bitwise
- /// operators to determine which bits of the mask are on or off.
- /// </remarks>
- public virtual int GetAccessMask()
- {
- return Access;
- }
-
- /// <summary>Return the SID associated with this ACE.</summary>
- /// <remarks>Return the SID associated with this ACE.</remarks>
- public virtual Sid GetSid()
- {
- return Sid;
- }
-
- internal virtual int Decode(byte[] buf, int bi)
- {
- Allow = buf[bi++] == unchecked(unchecked(0x00));
- Flags = buf[bi++] & unchecked(0xFF);
- int size = ServerMessageBlock.ReadInt2(buf, bi);
- bi += 2;
- Access = ServerMessageBlock.ReadInt4(buf, bi);
- bi += 4;
- Sid = new Sid(buf, bi);
- return size;
- }
-
- internal virtual void AppendCol(StringBuilder sb, string str, int width)
- {
- sb.Append(str);
- int count = width - str.Length;
- for (int i = 0; i < count; i++)
- {
- sb.Append(' ');
- }
- }
-
- /// <summary>Return a string represeting this ACE.</summary>
- /// <remarks>
- /// Return a string represeting this ACE.
- /// <p>
- /// Note: This function should probably be changed to return SDDL
- /// fragments but currently it does not.
- /// </remarks>
- public override string ToString()
- {
- int count;
- int i;
- string str;
- StringBuilder sb = new StringBuilder();
- sb.Append(IsAllow() ? "Allow " : "Deny ");
- AppendCol(sb, Sid.ToDisplayString(), 25);
- sb.Append(" 0x").Append(Hexdump.ToHexString(Access, 8)).Append(' ');
- sb.Append(IsInherited() ? "Inherited " : "Direct ");
- AppendCol(sb, GetApplyToText(), 34);
- return sb.ToString();
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/AllocInfo.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/AllocInfo.cs
deleted file mode 100644
index 6ebe88293..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/AllocInfo.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal interface IAllocInfo
- {
- long GetCapacity();
-
- long GetFree();
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/AndXServerMessageBlock.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/AndXServerMessageBlock.cs
deleted file mode 100644
index e78bff9d0..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/AndXServerMessageBlock.cs
+++ /dev/null
@@ -1,221 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal abstract class AndXServerMessageBlock : ServerMessageBlock
- {
- private const int AndxCommandOffset = 1;
-
- private const int AndxReservedOffset = 2;
-
- private const int AndxOffsetOffset = 3;
-
- private byte _andxCommand = unchecked(unchecked(0xFF));
-
- private int _andxOffset;
-
- internal ServerMessageBlock Andx;
-
- public AndXServerMessageBlock()
- {
- }
-
- internal AndXServerMessageBlock(ServerMessageBlock andx)
- {
- if (andx != null)
- {
- this.Andx = andx;
- _andxCommand = andx.Command;
- }
- }
-
- internal virtual int GetBatchLimit(byte command)
- {
- return 0;
- }
-
- internal override int Encode(byte[] dst, int dstIndex)
- {
- int start = HeaderStart = dstIndex;
- dstIndex += WriteHeaderWireFormat(dst, dstIndex);
- dstIndex += WriteAndXWireFormat(dst, dstIndex);
- Length = dstIndex - start;
- if (Digest != null)
- {
- Digest.Sign(dst, HeaderStart, Length, this, Response);
- }
- return Length;
- }
-
- internal override int Decode(byte[] buffer, int bufferIndex)
- {
- int start = HeaderStart = bufferIndex;
- bufferIndex += ReadHeaderWireFormat(buffer, bufferIndex);
- bufferIndex += ReadAndXWireFormat(buffer, bufferIndex);
- Length = bufferIndex - start;
- return Length;
- }
-
- internal virtual int WriteAndXWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- WordCount = WriteParameterWordsWireFormat(dst, start + AndxOffsetOffset + 2);
- WordCount += 4;
- // for command, reserved, and offset
- dstIndex += WordCount + 1;
- WordCount /= 2;
- dst[start] = unchecked((byte)(WordCount & unchecked(0xFF)));
- ByteCount = WriteBytesWireFormat(dst, dstIndex + 2);
- dst[dstIndex++] = unchecked((byte)(ByteCount & unchecked(0xFF)));
- dst[dstIndex++] = unchecked((byte)((ByteCount >> 8) & unchecked(0xFF)));
- dstIndex += ByteCount;
- if (Andx == null || SmbConstants.UseBatching == false || BatchLevel >= GetBatchLimit(Andx.Command
- ))
- {
- _andxCommand = unchecked(unchecked(0xFF));
- Andx = null;
- dst[start + AndxCommandOffset] = unchecked(unchecked(0xFF));
- dst[start + AndxReservedOffset] = unchecked(unchecked(0x00));
- // dst[start + ANDX_OFFSET_OFFSET] = (byte)0x00;
- // dst[start + ANDX_OFFSET_OFFSET + 1] = (byte)0x00;
- dst[start + AndxOffsetOffset] = unchecked(unchecked(0xde));
- dst[start + AndxOffsetOffset + 1] = unchecked(unchecked(0xde));
- // andx not used; return
- return dstIndex - start;
- }
- Andx.BatchLevel = BatchLevel + 1;
- dst[start + AndxCommandOffset] = _andxCommand;
- dst[start + AndxReservedOffset] = unchecked(unchecked(0x00));
- _andxOffset = dstIndex - HeaderStart;
- WriteInt2(_andxOffset, dst, start + AndxOffsetOffset);
- Andx.UseUnicode = UseUnicode;
- if (Andx is AndXServerMessageBlock)
- {
- Andx.Uid = Uid;
- dstIndex += ((AndXServerMessageBlock)Andx).WriteAndXWireFormat(dst, dstIndex
- );
- }
- else
- {
- // the andx smb is not of type andx so lets just write it here and
- // were done.
- int andxStart = dstIndex;
- Andx.WordCount = Andx.WriteParameterWordsWireFormat(dst, dstIndex);
- dstIndex += Andx.WordCount + 1;
- Andx.WordCount /= 2;
- dst[andxStart] = unchecked((byte)(Andx.WordCount & unchecked(0xFF)));
- Andx.ByteCount = Andx.WriteBytesWireFormat(dst, dstIndex + 2);
- dst[dstIndex++] = unchecked((byte)(Andx.ByteCount & unchecked(0xFF)));
- dst[dstIndex++] = unchecked((byte)((Andx.ByteCount >> 8) & unchecked(0xFF)
- ));
- dstIndex += Andx.ByteCount;
- }
- return dstIndex - start;
- }
-
- internal virtual int ReadAndXWireFormat(byte[] buffer, int bufferIndex)
- {
- int start = bufferIndex;
- WordCount = buffer[bufferIndex++];
- if (WordCount != 0)
- {
- _andxCommand = buffer[bufferIndex];
- _andxOffset = ReadInt2(buffer, bufferIndex + 2);
- if (_andxOffset == 0)
- {
- _andxCommand = unchecked(unchecked(0xFF));
- }
- if (WordCount > 2)
- {
- ReadParameterWordsWireFormat(buffer, bufferIndex + 4);
- if (Command == SmbComNtCreateAndx && ((SmbComNtCreateAndXResponse)this).IsExtended)
- {
- WordCount += 8;
- }
- }
- bufferIndex = start + 1 + (WordCount * 2);
- }
- ByteCount = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- if (ByteCount != 0)
- {
- int n;
- n = ReadBytesWireFormat(buffer, bufferIndex);
- bufferIndex += ByteCount;
- }
- if (ErrorCode != 0 || _andxCommand == unchecked(unchecked(0xFF)))
- {
- _andxCommand = unchecked(unchecked(0xFF));
- Andx = null;
- }
- else
- {
- if (Andx == null)
- {
- _andxCommand = unchecked(unchecked(0xFF));
- throw new RuntimeException("no andx command supplied with response");
- }
- bufferIndex = HeaderStart + _andxOffset;
- Andx.HeaderStart = HeaderStart;
- Andx.Command = _andxCommand;
- Andx.ErrorCode = ErrorCode;
- Andx.Flags = Flags;
- Andx.Flags2 = Flags2;
- Andx.Tid = Tid;
- Andx.Pid = Pid;
- Andx.Uid = Uid;
- Andx.Mid = Mid;
- Andx.UseUnicode = UseUnicode;
- if (Andx is AndXServerMessageBlock)
- {
- bufferIndex += ((AndXServerMessageBlock)Andx).ReadAndXWireFormat(buffer
- , bufferIndex);
- }
- else
- {
- buffer[bufferIndex++] = unchecked((byte)(Andx.WordCount & unchecked(0xFF))
- );
- if (Andx.WordCount != 0)
- {
- if (Andx.WordCount > 2)
- {
- bufferIndex += Andx.ReadParameterWordsWireFormat(buffer, bufferIndex);
- }
- }
- Andx.ByteCount = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- if (Andx.ByteCount != 0)
- {
- Andx.ReadBytesWireFormat(buffer, bufferIndex);
- bufferIndex += Andx.ByteCount;
- }
- }
- Andx.Received = true;
- }
- return bufferIndex - start;
- }
-
- public override string ToString()
- {
- return base.ToString() + ",andxCommand=0x" + Hexdump.ToHexString(_andxCommand
- , 2) + ",andxOffset=" + _andxOffset;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/BufferCache.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/BufferCache.cs
deleted file mode 100644
index b36816e26..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/BufferCache.cs
+++ /dev/null
@@ -1,80 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- public class BufferCache
- {
- private static readonly int MaxBuffers = Config.GetInt("jcifs.smb.maxBuffers", 16
- );
-
- internal static object[] Cache = new object[MaxBuffers];
-
- private static int _freeBuffers;
-
- public static byte[] GetBuffer()
- {
- lock (Cache)
- {
- byte[] buf;
- if (_freeBuffers > 0)
- {
- for (int i = 0; i < MaxBuffers; i++)
- {
- if (Cache[i] != null)
- {
- buf = (byte[])Cache[i];
- Cache[i] = null;
- _freeBuffers--;
- return buf;
- }
- }
- }
- buf = new byte[SmbComTransaction.TransactionBufSize];
- return buf;
- }
- }
-
- internal static void GetBuffers(SmbComTransaction req, SmbComTransactionResponse
- rsp)
- {
- lock (Cache)
- {
- req.TxnBuf = GetBuffer();
- rsp.TxnBuf = GetBuffer();
- }
- }
-
- public static void ReleaseBuffer(byte[] buf)
- {
- lock (Cache)
- {
- if (_freeBuffers < MaxBuffers)
- {
- for (int i = 0; i < MaxBuffers; i++)
- {
- if (Cache[i] == null)
- {
- Cache[i] = buf;
- _freeBuffers++;
- return;
- }
- }
- }
- }
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/Dfs.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/Dfs.cs
deleted file mode 100644
index 2f62e5b8d..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/Dfs.cs
+++ /dev/null
@@ -1,389 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System.IO;
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- public class Dfs
- {
- internal class CacheEntry
- {
- internal long Expiration;
-
- internal Hashtable Map;
-
- internal CacheEntry(long ttl)
- {
- if (ttl == 0)
- {
- ttl = Ttl;
- }
- Expiration = Runtime.CurrentTimeMillis() + ttl * 1000L;
- Map = new Hashtable();
- }
- }
-
- internal static LogStream Log = LogStream.GetInstance();
-
- internal static readonly bool StrictView = Config.GetBoolean("jcifs.smb.client.dfs.strictView"
- , false);
-
- internal static readonly long Ttl = Config.GetLong("jcifs.smb.client.dfs.ttl", 300
- );
-
- internal static readonly bool Disabled = Config.GetBoolean("jcifs.smb.client.dfs.disabled"
- , false);
-
- internal static CacheEntry FalseEntry = new CacheEntry(0L);
-
- internal CacheEntry Domains;
-
- internal CacheEntry Referrals;
-
- /// <exception cref="SharpCifs.Smb.SmbAuthException"></exception>
- public virtual Hashtable GetTrustedDomains(NtlmPasswordAuthentication auth)
- {
- if (Disabled || auth.Domain == "?")
- {
- return null;
- }
- if (Domains != null && Runtime.CurrentTimeMillis() > Domains.Expiration)
- {
- Domains = null;
- }
- if (Domains != null)
- {
- return Domains.Map;
- }
- try
- {
- UniAddress addr = UniAddress.GetByName(auth.Domain, true);
- SmbTransport trans = SmbTransport.GetSmbTransport(addr, 0);
- CacheEntry entry = new CacheEntry(Ttl * 10L);
- DfsReferral dr = trans.GetDfsReferrals(auth, string.Empty, 0);
- if (dr != null)
- {
- DfsReferral start = dr;
- do
- {
- string domain = dr.Server.ToLower();
- entry.Map.Put(domain, new Hashtable());
- dr = dr.Next;
- }
- while (dr != start);
- Domains = entry;
- return Domains.Map;
- }
- }
- catch (IOException ioe)
- {
- if (Log.Level >= 3)
- {
- Runtime.PrintStackTrace(ioe, Log);
- }
- if (StrictView && ioe is SmbAuthException)
- {
- throw (SmbAuthException)ioe;
- }
- }
- return null;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbAuthException"></exception>
- public virtual bool IsTrustedDomain(string domain, NtlmPasswordAuthentication auth
- )
- {
- Hashtable domains = GetTrustedDomains(auth);
- if (domains == null)
- {
- return false;
- }
- domain = domain.ToLower();
- return domains.Get(domain) != null;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbAuthException"></exception>
- public virtual SmbTransport GetDc(string domain, NtlmPasswordAuthentication auth)
- {
- if (Disabled)
- {
- return null;
- }
- try
- {
- UniAddress addr = UniAddress.GetByName(domain, true);
- SmbTransport trans = SmbTransport.GetSmbTransport(addr, 0);
- DfsReferral dr = trans.GetDfsReferrals(auth, "\\" + domain, 1);
- if (dr != null)
- {
- DfsReferral start = dr;
- IOException e = null;
- do
- {
- try
- {
- addr = UniAddress.GetByName(dr.Server);
- return SmbTransport.GetSmbTransport(addr, 0);
- }
- catch (IOException ioe)
- {
- e = ioe;
- }
- dr = dr.Next;
- }
- while (dr != start);
- throw e;
- }
- }
- catch (IOException ioe)
- {
- if (Log.Level >= 3)
- {
- Runtime.PrintStackTrace(ioe, Log);
- }
- if (StrictView && ioe is SmbAuthException)
- {
- throw (SmbAuthException)ioe;
- }
- }
- return null;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbAuthException"></exception>
- public virtual DfsReferral GetReferral(SmbTransport trans, string domain, string
- root, string path, NtlmPasswordAuthentication auth)
- {
- if (Disabled)
- {
- return null;
- }
- try
- {
- string p = "\\" + domain + "\\" + root;
- if (path != null)
- {
- p += path;
- }
- DfsReferral dr = trans.GetDfsReferrals(auth, p, 0);
- if (dr != null)
- {
- return dr;
- }
- }
- catch (IOException ioe)
- {
- if (Log.Level >= 4)
- {
- Runtime.PrintStackTrace(ioe, Log);
- }
- if (StrictView && ioe is SmbAuthException)
- {
- throw (SmbAuthException)ioe;
- }
- }
- return null;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbAuthException"></exception>
- public virtual DfsReferral Resolve(string domain, string root, string path, NtlmPasswordAuthentication
- auth)
- {
- lock (this)
- {
- DfsReferral dr = null;
- long now = Runtime.CurrentTimeMillis();
- if (Disabled || root.Equals("IPC$"))
- {
- return null;
- }
- Hashtable domains = GetTrustedDomains(auth);
- if (domains != null)
- {
- domain = domain.ToLower();
- Hashtable roots = (Hashtable)domains.Get(domain);
- if (roots != null)
- {
- SmbTransport trans = null;
- root = root.ToLower();
- CacheEntry links = (CacheEntry)roots.Get(root);
- if (links != null && now > links.Expiration)
- {
- //Sharpen.Collections.Remove(roots, root);
- roots.Remove(root);
- links = null;
- }
- if (links == null)
- {
- if ((trans = GetDc(domain, auth)) == null)
- {
- return null;
- }
- dr = GetReferral(trans, domain, root, path, auth);
- if (dr != null)
- {
- int len = 1 + domain.Length + 1 + root.Length;
- links = new CacheEntry(0L);
- DfsReferral tmp = dr;
- do
- {
- if (path == null)
- {
- // TODO: fix this
- //tmp.map = links.map;
- tmp.Key = "\\";
- }
- tmp.PathConsumed -= len;
- tmp = tmp.Next;
- }
- while (tmp != dr);
- if (dr.Key != null)
- {
- links.Map.Put(dr.Key, dr);
- }
- roots.Put(root, links);
- }
- else
- {
- if (path == null)
- {
- roots.Put(root, FalseEntry);
- }
- }
- }
- else
- {
- if (links == FalseEntry)
- {
- links = null;
- }
- }
- if (links != null)
- {
- string link = "\\";
- dr = (DfsReferral)links.Map.Get(link);
- if (dr != null && now > dr.Expiration)
- {
- //Sharpen.Collections.Remove(links.map, link);
- links.Map.Remove(link);
- dr = null;
- }
- if (dr == null)
- {
- if (trans == null)
- {
- if ((trans = GetDc(domain, auth)) == null)
- {
- return null;
- }
- }
- dr = GetReferral(trans, domain, root, path, auth);
- if (dr != null)
- {
- dr.PathConsumed -= 1 + domain.Length + 1 + root.Length;
- dr.Link = link;
- links.Map.Put(link, dr);
- }
- }
- }
- }
- }
- if (dr == null && path != null)
- {
- if (Referrals != null && now > Referrals.Expiration)
- {
- Referrals = null;
- }
- if (Referrals == null)
- {
- Referrals = new CacheEntry(0);
- }
- string key = "\\" + domain + "\\" + root;
- if (path.Equals("\\") == false)
- {
- key += path;
- }
- key = key.ToLower();
- //ListIterator<object> iter = new ListIterator<object>(referrals.map.Keys.GetEnumerator(), 0);
- foreach (var current in Referrals.Map.Keys)
- {
- string _key = (string)current;
- int klen = _key.Length;
- bool match = false;
- if (klen == key.Length)
- {
- match = _key.Equals(key);
- }
- else
- {
- if (klen < key.Length)
- {
- match = _key.RegionMatches(false, 0, key, 0, klen) && key[klen] == '\\';
- }
- }
- if (match)
- {
- dr = (DfsReferral)Referrals.Map.Get(_key);
- }
- }
- }
- return dr;
- }
- }
-
- internal virtual void Insert(string path, DfsReferral dr)
- {
- lock (this)
- {
- int s1;
- int s2;
- string server;
- string share;
- string key;
- if (Disabled)
- {
- return;
- }
- s1 = path.IndexOf('\\', 1);
- s2 = path.IndexOf('\\', s1 + 1);
- server = Runtime.Substring(path, 1, s1);
- share = Runtime.Substring(path, s1 + 1, s2);
- key = Runtime.Substring(path, 0, dr.PathConsumed).ToLower();
- int ki = key.Length;
- while (ki > 1 && key[ki - 1] == '\\')
- {
- ki--;
- }
- if (ki < key.Length)
- {
- key = Runtime.Substring(key, 0, ki);
- }
- dr.PathConsumed -= 1 + server.Length + 1 + share.Length;
- if (Referrals != null && (Runtime.CurrentTimeMillis() + 10000) > Referrals.Expiration)
- {
- Referrals = null;
- }
- if (Referrals == null)
- {
- Referrals = new CacheEntry(0);
- }
- Referrals.Map.Put(key, dr);
- }
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/DfsReferral.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/DfsReferral.cs
deleted file mode 100644
index 3b6091f73..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/DfsReferral.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System.Collections.Generic;
-
-namespace SharpCifs.Smb
-{
-
- public class DfsReferral : SmbException
- {
- public int PathConsumed;
-
- public long Ttl;
-
- public string Server;
-
- public string Share;
-
- public string Link;
-
- public string Path;
-
- public bool ResolveHashes;
-
- public long Expiration;
-
- internal DfsReferral Next;
-
- internal IDictionary<string, DfsReferral> Map;
-
- internal string Key = null;
-
- public DfsReferral()
- {
- // Server
- // Share
- // Path relative to tree from which this referral was thrown
- Next = this;
- }
-
- internal virtual void Append(DfsReferral dr)
- {
- dr.Next = Next;
- Next = dr;
- }
-
- public override string ToString()
- {
- return "DfsReferral[pathConsumed=" + PathConsumed + ",server=" + Server + ",share="
- + Share + ",link=" + Link + ",path=" + Path + ",ttl=" + Ttl + ",expiration=" +
- Expiration + ",resolveHashes=" + ResolveHashes + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/DosError.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/DosError.cs
deleted file mode 100644
index d89e5bafa..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/DosError.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- public static class DosError
- {
- public static int[][] DosErrorCodes = { new[] { unchecked(0x00000000), unchecked(0x00000000) }, new[] { unchecked(0x00010001), unchecked((int)(0xc0000002)) }, new[] { unchecked(0x00010002), unchecked(
- (int)(0xc0000002)) }, new[] { unchecked(0x00020001), unchecked((int)(
- 0xc000000f)) }, new[] { unchecked(0x00020002), unchecked((int)(0xc000006a
- )) }, new[] { unchecked(0x00030001), unchecked((int)(0xc000003a)) },
- new[] { unchecked(0x00030002), unchecked((int)(0xc00000cb)) }, new[] { unchecked(0x00040002), unchecked((int)(0xc00000ca)) }, new[] { unchecked(
- 0x00050001), unchecked((int)(0xc0000022)) }, new[] { unchecked(0x00050002), unchecked((int)(0xc000000d)) }, new[] { unchecked(0x00060001), unchecked((int)(0xc0000008)) }, new[] { unchecked(0x00060002), unchecked(
- (int)(0xc00000cc)) }, new[] { unchecked(0x00080001), unchecked((int)(
- 0xc000009a)) }, new[] { unchecked(0x00130003), unchecked((int)(0xc00000a2
- )) }, new[] { unchecked(0x00150003), unchecked((int)(0xc0000013)) },
- new[] { unchecked(0x001f0001), unchecked((int)(0xc0000001)) }, new[] { unchecked(0x001f0003), unchecked((int)(0xc0000001)) }, new[] { unchecked(
- 0x00200001), unchecked((int)(0xc0000043)) }, new[] { unchecked(0x00200003), unchecked((int)(0xc0000043)) }, new[] { unchecked(0x00210003), unchecked((int)(0xc0000054)) }, new[] { unchecked(0x00270003), unchecked(
- (int)(0xc000007f)) }, new[] { unchecked(0x00340001), unchecked((int)(
- 0xC00000bd)) }, new[] { unchecked(0x00430001), unchecked((int)(0xc00000cc
- )) }, new[] { unchecked(0x00470001), unchecked((int)(0xC00000d0)) },
- new[] { unchecked(0x00500001), unchecked((int)(0xc0000035)) }, new[] { unchecked(0x00570001), unchecked((int)(0xc0000003)) }, new[] { unchecked(
- 0x005a0002), unchecked((int)(0xc00000ce)) }, new[] { unchecked(0x005b0002), unchecked((int)(0xc000000d)) }, new[] { unchecked(0x006d0001), unchecked((int)(0xC000014b)) }, new[] { unchecked(0x007b0001), unchecked(
- (int)(0xc0000033)) }, new[] { unchecked(0x00910001), unchecked((int)(
- 0xC0000101)) }, new[] { unchecked(0x00b70001), unchecked((int)(0xc0000035
- )) }, new[] { unchecked(0x00e70001), unchecked((int)(0xc00000ab)) },
- new[] { unchecked(0x00e80001), unchecked((int)(0xc00000b1)) }, new[] { unchecked(0x00e90001), unchecked((int)(0xc00000b0)) }, new[] { unchecked(
- 0x00ea0001), unchecked((int)(0xc0000016)) }, new[] { unchecked(0x08bf0002), unchecked((int)(0xC0000193)) }, new[] { unchecked(0x08c00002), unchecked((int)(0xC0000070)) }, new[] { unchecked(0x08c10002), unchecked(
- (int)(0xC000006f)) }, new[] { unchecked(0x08c20002), unchecked((int)(
- 0xC0000071)) } };
-
- public static string[] DosErrorMessages = { "The operation completed successfully."
- , "Incorrect function.", "Incorrect function.", "The system cannot find the file specified."
- , "Bad password.", "The system cannot find the path specified.", "reserved", "The client does not have the necessary access rights to perform the requested function."
- , "Access is denied.", "The TID specified was invalid.", "The handle is invalid."
- , "The network name cannot be found.", "Not enough storage is available to process this command."
- , "The media is write protected.", "The device is not ready.", "A device attached to the system is not functioning."
- , "A device attached to the system is not functioning.", "The process cannot access the file because it is being used by another process."
- , "The process cannot access the file because it is being used by another process."
- , "The process cannot access the file because another process has locked a portion of the file."
- , "The disk is full.", "A duplicate name exists on the network.", "The network name cannot be found."
- , "ERRnomoreconn.", "The file exists.", "The parameter is incorrect.", "Too many Uids active on this session."
- , "The Uid is not known as a valid user identifier on this session.", "The pipe has been ended."
- , "The filename, directory name, or volume label syntax is incorrect.", "The directory is not empty."
- , "Cannot create a file when that file already exists.", "All pipe instances are busy."
- , "The pipe is being closed.", "No process is on the other end of the pipe.", "More data is available."
- , "This user account has expired.", "The user is not allowed to log on from this workstation."
- , "The user is not allowed to log on at this time.", "The password of this user has expired."
- };
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/DosFileFilter.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/DosFileFilter.cs
deleted file mode 100644
index bbf7882c8..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/DosFileFilter.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- public class DosFileFilter : ISmbFileFilter
- {
- protected internal string Wildcard;
-
- protected internal int Attributes;
-
- public DosFileFilter(string wildcard, int attributes)
- {
- this.Wildcard = wildcard;
- this.Attributes = attributes;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual bool Accept(SmbFile file)
- {
- return (file.GetAttributes() & Attributes) != 0;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/FileEntry.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/FileEntry.cs
deleted file mode 100644
index bbf3e7cc4..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/FileEntry.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- public interface IFileEntry
- {
- string GetName();
-
- int GetType();
-
- int GetAttributes();
-
- long CreateTime();
-
- long LastModified();
-
- long Length();
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/IInfo.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/IInfo.cs
deleted file mode 100644
index b0e40c5cd..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/IInfo.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal interface IInfo
- {
- int GetAttributes();
-
- long GetCreateTime();
-
- long GetLastWriteTime();
-
- long GetSize();
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/NetServerEnum2.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/NetServerEnum2.cs
deleted file mode 100644
index b4a02d8c3..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/NetServerEnum2.cs
+++ /dev/null
@@ -1,122 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class NetServerEnum2 : SmbComTransaction
- {
- internal const int SvTypeAll = unchecked((int)(0xFFFFFFFF));
-
- internal const int SvTypeDomainEnum = unchecked((int)(0x80000000));
-
- internal static readonly string[] Descr = { "WrLehDO\u0000B16BBDz\u0000"
- , "WrLehDz\u0000B16BBDz\u0000" };
-
- internal string Domain;
-
- internal string LastName;
-
- internal int ServerTypes;
-
- internal NetServerEnum2(string domain, int serverTypes)
- {
- this.Domain = domain;
- this.ServerTypes = serverTypes;
- Command = SmbComTransaction;
- SubCommand = NetServerEnum2;
- // not really true be used by upper logic
- Name = "\\PIPE\\LANMAN";
- MaxParameterCount = 8;
- MaxDataCount = 16384;
- MaxSetupCount = unchecked(unchecked(0x00));
- SetupCount = 0;
- Timeout = 5000;
- }
-
- internal override void Reset(int key, string lastName)
- {
- base.Reset();
- this.LastName = lastName;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- byte[] descr;
- int which = SubCommand == NetServerEnum2 ? 0 : 1;
- try
- {
- descr = Runtime.GetBytesForString(Descr[which], "UTF-8"); //"ASCII");
- }
- catch (UnsupportedEncodingException)
- {
- return 0;
- }
- WriteInt2(SubCommand & unchecked(0xFF), dst, dstIndex);
- dstIndex += 2;
- Array.Copy(descr, 0, dst, dstIndex, descr.Length);
- dstIndex += descr.Length;
- WriteInt2(unchecked(0x0001), dst, dstIndex);
- dstIndex += 2;
- WriteInt2(MaxDataCount, dst, dstIndex);
- dstIndex += 2;
- WriteInt4(ServerTypes, dst, dstIndex);
- dstIndex += 4;
- dstIndex += WriteString(Domain.ToUpper(), dst, dstIndex, false);
- if (which == 1)
- {
- dstIndex += WriteString(LastName.ToUpper(), dst, dstIndex, false);
- }
- return dstIndex - start;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "NetServerEnum2[" + base.ToString() + ",name=" + Name + ",serverTypes="
- + (ServerTypes == SvTypeAll ? "SV_TYPE_ALL" : "SV_TYPE_DOMAIN_ENUM") + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/NetServerEnum2Response.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/NetServerEnum2Response.cs
deleted file mode 100644
index 9a0e5e3d5..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/NetServerEnum2Response.cs
+++ /dev/null
@@ -1,157 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-
-namespace SharpCifs.Smb
-{
- internal class NetServerEnum2Response : SmbComTransactionResponse
- {
- internal class ServerInfo1 : IFileEntry
- {
- internal string Name;
-
- internal int VersionMajor;
-
- internal int VersionMinor;
-
- internal int Type;
-
- internal string CommentOrMasterBrowser;
-
- public virtual string GetName()
- {
- return Name;
- }
-
- public new virtual int GetType()
- {
- return (Type & unchecked((int)(0x80000000))) != 0 ? SmbFile.TypeWorkgroup :
- SmbFile.TypeServer;
- }
-
- public virtual int GetAttributes()
- {
- return SmbFile.AttrReadonly | SmbFile.AttrDirectory;
- }
-
- public virtual long CreateTime()
- {
- return 0L;
- }
-
- public virtual long LastModified()
- {
- return 0L;
- }
-
- public virtual long Length()
- {
- return 0L;
- }
-
- public override string ToString()
- {
- return "ServerInfo1[" + "name=" + Name + ",versionMajor=" + VersionMajor + ",versionMinor=" + VersionMinor + ",type=0x" + Hexdump.ToHexString
- (Type, 8) + ",commentOrMasterBrowser=" + CommentOrMasterBrowser + "]";
- }
-
- internal ServerInfo1(NetServerEnum2Response enclosing)
- {
- this._enclosing = enclosing;
- }
-
- private readonly NetServerEnum2Response _enclosing;
- }
-
- private int _converter;
-
- private int _totalAvailableEntries;
-
- internal string LastName;
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- int start = bufferIndex;
- Status = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- _converter = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- NumEntries = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- _totalAvailableEntries = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- return bufferIndex - start;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- int start = bufferIndex;
- ServerInfo1 e = null;
- Results = new ServerInfo1[NumEntries];
- for (int i = 0; i < NumEntries; i++)
- {
- Results[i] = e = new ServerInfo1(this);
- e.Name = ReadString(buffer, bufferIndex, 16, false);
- bufferIndex += 16;
- e.VersionMajor = buffer[bufferIndex++] & unchecked(0xFF);
- e.VersionMinor = buffer[bufferIndex++] & unchecked(0xFF);
- e.Type = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- int off = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- off = (off & unchecked(0xFFFF)) - _converter;
- off = start + off;
- e.CommentOrMasterBrowser = ReadString(buffer, off, 48, false);
- if (Log.Level >= 4)
- {
- Log.WriteLine(e);
- }
- }
- LastName = NumEntries == 0 ? null : e.Name;
- return bufferIndex - start;
- }
-
- public override string ToString()
- {
- return "NetServerEnum2Response[" + base.ToString() + ",status=" + Status
- + ",converter=" + _converter + ",entriesReturned=" + NumEntries + ",totalAvailableEntries="
- + _totalAvailableEntries + ",lastName=" + LastName + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/NetShareEnum.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/NetShareEnum.cs
deleted file mode 100644
index 1b0c6f931..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/NetShareEnum.cs
+++ /dev/null
@@ -1,95 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class NetShareEnum : SmbComTransaction
- {
- private static readonly string Descr = "WrLeh\u0000B13BWz\u0000";
-
- public NetShareEnum()
- {
- Command = SmbComTransaction;
- SubCommand = NetShareEnum;
- // not really true be used by upper logic
- Name ="\\PIPE\\LANMAN";
- MaxParameterCount = 8;
- // maxDataCount = 4096; why was this set?
- MaxSetupCount = 0x00;
- SetupCount = 0;
- Timeout = 5000;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- byte[] descr;
- try
- {
- //descr = Runtime.GetBytesForString(Descr, "ASCII");
- descr = Runtime.GetBytesForString(Descr, "UTF-8");
- }
- catch (UnsupportedEncodingException)
- {
- return 0;
- }
- WriteInt2(NetShareEnum, dst, dstIndex);
- dstIndex += 2;
- Array.Copy(descr, 0, dst, dstIndex, descr.Length);
- dstIndex += descr.Length;
- WriteInt2(unchecked(0x0001), dst, dstIndex);
- dstIndex += 2;
- WriteInt2(MaxDataCount, dst, dstIndex);
- dstIndex += 2;
- return dstIndex - start;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "NetShareEnum[" + base.ToString() + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/NetShareEnumResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/NetShareEnumResponse.cs
deleted file mode 100644
index 408f8e4d1..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/NetShareEnumResponse.cs
+++ /dev/null
@@ -1,94 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class NetShareEnumResponse : SmbComTransactionResponse
- {
- private int _converter;
-
- private int _totalAvailableEntries;
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- int start = bufferIndex;
- Status = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- _converter = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- NumEntries = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- _totalAvailableEntries = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- return bufferIndex - start;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- int start = bufferIndex;
- SmbShareInfo e;
- UseUnicode = false;
- Results = new SmbShareInfo[NumEntries];
- for (int i = 0; i < NumEntries; i++)
- {
- Results[i] = e = new SmbShareInfo();
- e.NetName = ReadString(buffer, bufferIndex, 13, false);
- bufferIndex += 14;
- e.Type = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- int off = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- off = (off & unchecked(0xFFFF)) - _converter;
- off = start + off;
- e.Remark = ReadString(buffer, off, 128, false);
- if (Log.Level >= 4)
- {
- Log.WriteLine(e);
- }
- }
- return bufferIndex - start;
- }
-
- public override string ToString()
- {
- return "NetShareEnumResponse[" + base.ToString() + ",status=" + Status
- + ",converter=" + _converter + ",entriesReturned=" + NumEntries + ",totalAvailableEntries="
- + _totalAvailableEntries + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtStatus.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/NtStatus.cs
deleted file mode 100644
index 511e7ae84..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtStatus.cs
+++ /dev/null
@@ -1,202 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- public static class NtStatus
- {
- public const int NtStatusOk = unchecked(0x00000000);
-
- public const int NtStatusUnsuccessful = unchecked((int)(0xC0000001));
-
- public const int NtStatusNotImplemented = unchecked((int)(0xC0000002));
-
- public const int NtStatusInvalidInfoClass = unchecked((int)(0xC0000003));
-
- public const int NtStatusAccessViolation = unchecked((int)(0xC0000005));
-
- public const int NtStatusInvalidHandle = unchecked((int)(0xC0000008));
-
- public const int NtStatusInvalidParameter = unchecked((int)(0xC000000d));
-
- public const int NtStatusNoSuchDevice = unchecked((int)(0xC000000e));
-
- public const int NtStatusNoSuchFile = unchecked((int)(0xC000000f));
-
- public const int NtStatusMoreProcessingRequired = unchecked((int)(0xC0000016)
- );
-
- public const int NtStatusAccessDenied = unchecked((int)(0xC0000022));
-
- public const int NtStatusBufferTooSmall = unchecked((int)(0xC0000023));
-
- public const int NtStatusObjectNameInvalid = unchecked((int)(0xC0000033));
-
- public const int NtStatusObjectNameNotFound = unchecked((int)(0xC0000034));
-
- public const int NtStatusObjectNameCollision = unchecked((int)(0xC0000035));
-
- public const int NtStatusPortDisconnected = unchecked((int)(0xC0000037));
-
- public const int NtStatusObjectPathInvalid = unchecked((int)(0xC0000039));
-
- public const int NtStatusObjectPathNotFound = unchecked((int)(0xC000003a));
-
- public const int NtStatusObjectPathSyntaxBad = unchecked((int)(0xC000003b));
-
- public const int NtStatusSharingViolation = unchecked((int)(0xC0000043));
-
- public const int NtStatusDeletePending = unchecked((int)(0xC0000056));
-
- public const int NtStatusNoLogonServers = unchecked((int)(0xC000005e));
-
- public const int NtStatusUserExists = unchecked((int)(0xC0000063));
-
- public const int NtStatusNoSuchUser = unchecked((int)(0xC0000064));
-
- public const int NtStatusWrongPassword = unchecked((int)(0xC000006a));
-
- public const int NtStatusLogonFailure = unchecked((int)(0xC000006d));
-
- public const int NtStatusAccountRestriction = unchecked((int)(0xC000006e));
-
- public const int NtStatusInvalidLogonHours = unchecked((int)(0xC000006f));
-
- public const int NtStatusInvalidWorkstation = unchecked((int)(0xC0000070));
-
- public const int NtStatusPasswordExpired = unchecked((int)(0xC0000071));
-
- public const int NtStatusAccountDisabled = unchecked((int)(0xC0000072));
-
- public const int NtStatusNoneMapped = unchecked((int)(0xC0000073));
-
- public const int NtStatusInvalidSid = unchecked((int)(0xC0000078));
-
- public const int NtStatusInstanceNotAvailable = unchecked((int)(0xC00000ab));
-
- public const int NtStatusPipeNotAvailable = unchecked((int)(0xC00000ac));
-
- public const int NtStatusInvalidPipeState = unchecked((int)(0xC00000ad));
-
- public const int NtStatusPipeBusy = unchecked((int)(0xC00000ae));
-
- public const int NtStatusPipeDisconnected = unchecked((int)(0xC00000b0));
-
- public const int NtStatusPipeClosing = unchecked((int)(0xC00000b1));
-
- public const int NtStatusPipeListening = unchecked((int)(0xC00000b3));
-
- public const int NtStatusFileIsADirectory = unchecked((int)(0xC00000ba));
-
- public const int NtStatusDuplicateName = unchecked((int)(0xC00000bd));
-
- public const int NtStatusNetworkNameDeleted = unchecked((int)(0xC00000c9));
-
- public const int NtStatusNetworkAccessDenied = unchecked((int)(0xC00000ca));
-
- public const int NtStatusBadNetworkName = unchecked((int)(0xC00000cc));
-
- public const int NtStatusRequestNotAccepted = unchecked((int)(0xC00000d0));
-
- public const int NtStatusCantAccessDomainInfo = unchecked((int)(0xC00000da));
-
- public const int NtStatusNoSuchDomain = unchecked((int)(0xC00000df));
-
- public const int NtStatusNotADirectory = unchecked((int)(0xC0000103));
-
- public const int NtStatusCannotDelete = unchecked((int)(0xC0000121));
-
- public const int NtStatusInvalidComputerName = unchecked((int)(0xC0000122));
-
- public const int NtStatusPipeBroken = unchecked((int)(0xC000014b));
-
- public const int NtStatusNoSuchAlias = unchecked((int)(0xC0000151));
-
- public const int NtStatusLogonTypeNotGranted = unchecked((int)(0xC000015b));
-
- public const int NtStatusNoTrustSamAccount = unchecked((int)(0xC000018b));
-
- public const int NtStatusTrustedDomainFailure = unchecked((int)(0xC000018c));
-
- public const int NtStatusNologonWorkstationTrustAccount = unchecked((int)(0xC0000199
- ));
-
- public const int NtStatusPasswordMustChange = unchecked((int)(0xC0000224));
-
- public const int NtStatusNotFound = unchecked((int)(0xC0000225));
-
- public const int NtStatusAccountLockedOut = unchecked((int)(0xC0000234));
-
- public const int NtStatusPathNotCovered = unchecked((int)(0xC0000257));
-
- public const int NtStatusIoReparseTagNotHandled = unchecked((int)(0xC0000279
- ));
-
- public static int[] NtStatusCodes = { NtStatusOk, NtStatusUnsuccessful
- , NtStatusNotImplemented, NtStatusInvalidInfoClass, NtStatusAccessViolation
- , NtStatusInvalidHandle, NtStatusInvalidParameter, NtStatusNoSuchDevice
- , NtStatusNoSuchFile, NtStatusMoreProcessingRequired, NtStatusAccessDenied
- , NtStatusBufferTooSmall, NtStatusObjectNameInvalid, NtStatusObjectNameNotFound
- , NtStatusObjectNameCollision, NtStatusPortDisconnected, NtStatusObjectPathInvalid
- , NtStatusObjectPathNotFound, NtStatusObjectPathSyntaxBad, NtStatusSharingViolation
- , NtStatusDeletePending, NtStatusNoLogonServers, NtStatusUserExists, NtStatusNoSuchUser
- , NtStatusWrongPassword, NtStatusLogonFailure, NtStatusAccountRestriction
- , NtStatusInvalidLogonHours, NtStatusInvalidWorkstation, NtStatusPasswordExpired
- , NtStatusAccountDisabled, NtStatusNoneMapped, NtStatusInvalidSid, NtStatusInstanceNotAvailable
- , NtStatusPipeNotAvailable, NtStatusInvalidPipeState, NtStatusPipeBusy
- , NtStatusPipeDisconnected, NtStatusPipeClosing, NtStatusPipeListening,
- NtStatusFileIsADirectory, NtStatusDuplicateName, NtStatusNetworkNameDeleted
- , NtStatusNetworkAccessDenied, NtStatusBadNetworkName, NtStatusRequestNotAccepted
- , NtStatusCantAccessDomainInfo, NtStatusNoSuchDomain, NtStatusNotADirectory
- , NtStatusCannotDelete, NtStatusInvalidComputerName, NtStatusPipeBroken
- , NtStatusNoSuchAlias, NtStatusLogonTypeNotGranted, NtStatusNoTrustSamAccount
- , NtStatusTrustedDomainFailure, NtStatusNologonWorkstationTrustAccount,
- NtStatusPasswordMustChange, NtStatusNotFound, NtStatusAccountLockedOut
- , NtStatusPathNotCovered, NtStatusIoReparseTagNotHandled };
-
- public static string[] NtStatusMessages = { "The operation completed successfully."
- , "A device attached to the system is not functioning.", "Incorrect function.",
- "The parameter is incorrect.", "Invalid access to memory location.", "The handle is invalid."
- , "The parameter is incorrect.", "The system cannot find the file specified.", "The system cannot find the file specified."
- , "More data is available.", "Access is denied.", "The data area passed to a system call is too small."
- , "The filename, directory name, or volume label syntax is incorrect.", "The system cannot find the file specified."
- , "Cannot create a file when that file already exists.", "The handle is invalid."
- , "The specified path is invalid.", "The system cannot find the path specified."
- , "The specified path is invalid.", "The process cannot access the file because it is being used by another process."
- , "Access is denied.", "There are currently no logon servers available to service the logon request."
- , "The specified user already exists.", "The specified user does not exist.", "The specified network password is not correct."
- , "Logon failure: unknown user name or bad password.", "Logon failure: user account restriction."
- , "Logon failure: account logon time restriction violation.", "Logon failure: user not allowed to log on to this computer."
- , "Logon failure: the specified account password has expired.", "Logon failure: account currently disabled."
- , "No mapping between account names and security IDs was done.", "The security ID structure is invalid."
- , "All pipe instances are busy.", "All pipe instances are busy.", "The pipe state is invalid."
- , "All pipe instances are busy.", "No process is on the other end of the pipe.",
- "The pipe is being closed.", "Waiting for a process to open the other end of the pipe."
- , "Access is denied.", "A duplicate name exists on the network.", "The specified network name is no longer available."
- , "Network access is denied.", "The network name cannot be found.", "No more connections can be made to this remote computer at this time because there are already as many connections as the computer can accept."
- , "Indicates a Windows NT Server could not be contacted or that objects within the domain are protected such that necessary information could not be retrieved."
- , "The specified domain did not exist.", "The directory name is invalid.", "Access is denied."
- , "The format of the specified computer name is invalid.", "The pipe has been ended."
- , "The specified local group does not exist.", "Logon failure: the user has not been granted the requested logon type at this computer."
- , "The SAM database on the Windows NT Server does not have a computer account for this workstation trust relationship."
- , "The trust relationship between the primary domain and the trusted domain failed."
- , "The account used is a Computer Account. Use your global user account or local user account to access this server."
- , "The user must change his password before he logs on the first time.", "NT_STATUS_NOT_FOUND"
- , "The referenced account is currently locked out and may not be logged on to.",
- "The remote system is not reachable by the transport.", "NT_STATUS_IO_REPARSE_TAG_NOT_HANDLED"
- };
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtTransQuerySecurityDesc.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/NtTransQuerySecurityDesc.cs
deleted file mode 100644
index 6a83543b1..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtTransQuerySecurityDesc.cs
+++ /dev/null
@@ -1,88 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-
-namespace SharpCifs.Smb
-{
- internal class NtTransQuerySecurityDesc : SmbComNtTransaction
- {
- internal int Fid;
-
- internal int SecurityInformation;
-
- internal NtTransQuerySecurityDesc(int fid, int securityInformation)
- {
- this.Fid = fid;
- this.SecurityInformation = securityInformation;
- Command = SmbComNtTransact;
- Function = NtTransactQuerySecurityDesc;
- SetupCount = 0;
- TotalDataCount = 0;
- MaxParameterCount = 4;
- MaxDataCount = 32768;
- MaxSetupCount = unchecked(unchecked(0x00));
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- WriteInt2(Fid, dst, dstIndex);
- dstIndex += 2;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- // Reserved
- dst[dstIndex++] = unchecked(unchecked(0x00));
- // Reserved
- WriteInt4(SecurityInformation, dst, dstIndex);
- dstIndex += 4;
- return dstIndex - start;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "NtTransQuerySecurityDesc[" + base.ToString() + ",fid=0x" + Hexdump
- .ToHexString(Fid, 4) + ",securityInformation=0x" + Hexdump.ToHexString(SecurityInformation
- , 8) + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtTransQuerySecurityDescResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/NtTransQuerySecurityDescResponse.cs
deleted file mode 100644
index 9365d5154..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtTransQuerySecurityDescResponse.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System.IO;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class NtTransQuerySecurityDescResponse : SmbComNtTransactionResponse
- {
- internal SecurityDescriptor SecurityDescriptor;
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- Length = ReadInt4(buffer, bufferIndex);
- return 4;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- int start = bufferIndex;
- if (ErrorCode != 0)
- {
- return 4;
- }
- try
- {
- SecurityDescriptor = new SecurityDescriptor();
- bufferIndex += SecurityDescriptor.Decode(buffer, bufferIndex, len);
- }
- catch (IOException ioe)
- {
- throw new RuntimeException(ioe.Message);
- }
- return bufferIndex - start;
- }
-
- public override string ToString()
- {
- return "NtTransQuerySecurityResponse[" + base.ToString() + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmAuthenticator.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmAuthenticator.cs
deleted file mode 100644
index 853364f8e..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmAuthenticator.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- /// <summary>This class can be extended by applications that wish to trap authentication related exceptions and automatically retry the exceptional operation with different credentials.
- /// </summary>
- /// <remarks>This class can be extended by applications that wish to trap authentication related exceptions and automatically retry the exceptional operation with different credentials. Read <a href="../../../authhandler.html">jCIFS Exceptions and NtlmAuthenticator</a> for complete details.
- /// </remarks>
- public abstract class NtlmAuthenticator
- {
- private static NtlmAuthenticator _auth;
-
- private string _url;
-
- private SmbAuthException _sae;
-
- private void Reset()
- {
- _url = null;
- _sae = null;
- }
-
- /// <summary>Set the default <tt>NtlmAuthenticator</tt>.</summary>
- /// <remarks>Set the default <tt>NtlmAuthenticator</tt>. Once the default authenticator is set it cannot be changed. Calling this metho again will have no effect.
- /// </remarks>
- public static void SetDefault(NtlmAuthenticator a)
- {
- lock (typeof(NtlmAuthenticator))
- {
- if (_auth != null)
- {
- return;
- }
- _auth = a;
- }
- }
-
- protected internal string GetRequestingUrl()
- {
- return _url;
- }
-
- protected internal SmbAuthException GetRequestingException()
- {
- return _sae;
- }
-
- /// <summary>Used internally by jCIFS when an <tt>SmbAuthException</tt> is trapped to retrieve new user credentials.
- /// </summary>
- /// <remarks>Used internally by jCIFS when an <tt>SmbAuthException</tt> is trapped to retrieve new user credentials.
- /// </remarks>
- public static NtlmPasswordAuthentication RequestNtlmPasswordAuthentication(string
- url, SmbAuthException sae)
- {
- if (_auth == null)
- {
- return null;
- }
- lock (_auth)
- {
- _auth._url = url;
- _auth._sae = sae;
- return _auth.GetNtlmPasswordAuthentication();
- }
- }
-
- /// <summary>An application extending this class must provide an implementation for this method that returns new user credentials try try when accessing SMB resources described by the <tt>getRequestingURL</tt> and <tt>getRequestingException</tt> methods.
- /// </summary>
- /// <remarks>
- /// An application extending this class must provide an implementation for this method that returns new user credentials try try when accessing SMB resources described by the <tt>getRequestingURL</tt> and <tt>getRequestingException</tt> methods.
- /// If this method returns <tt>null</tt> the <tt>SmbAuthException</tt> that triggered the authenticator check will simply be rethrown. The default implementation returns <tt>null</tt>.
- /// </remarks>
- protected internal virtual NtlmPasswordAuthentication GetNtlmPasswordAuthentication
- ()
- {
- return null;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmChallenge.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmChallenge.cs
deleted file mode 100644
index 745b1f663..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmChallenge.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-
-namespace SharpCifs.Smb
-{
-
- public sealed class NtlmChallenge
- {
- public byte[] Challenge;
-
- public UniAddress Dc;
-
- internal NtlmChallenge(byte[] challenge, UniAddress dc)
- {
- this.Challenge = challenge;
- this.Dc = dc;
- }
-
- public override string ToString()
- {
- return "NtlmChallenge[challenge=0x" + Hexdump.ToHexString(Challenge, 0, Challenge
- .Length * 2) + ",dc=" + Dc + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmContext.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmContext.cs
deleted file mode 100644
index 44266f974..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmContext.cs
+++ /dev/null
@@ -1,206 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using SharpCifs.Ntlmssp;
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- /// <summary>For initiating NTLM authentication (including NTLMv2).</summary>
- /// <remarks>For initiating NTLM authentication (including NTLMv2). If you want to add NTLMv2 authentication support to something this is what you want to use. See the code for details. Note that JCIFS does not implement the acceptor side of NTLM authentication.
- /// </remarks>
- public class NtlmContext
- {
- internal NtlmPasswordAuthentication Auth;
-
- internal int NtlmsspFlags;
-
- internal string Workstation;
-
- internal bool isEstablished;
-
- internal byte[] ServerChallenge;
-
- internal byte[] SigningKey;
-
- internal string NetbiosName = null;
-
- internal int State = 1;
-
- internal LogStream Log;
-
- public NtlmContext(NtlmPasswordAuthentication auth, bool doSigning)
- {
- this.Auth = auth;
- NtlmsspFlags = NtlmsspFlags | NtlmFlags.NtlmsspRequestTarget | NtlmFlags.NtlmsspNegotiateNtlm2
- | NtlmFlags.NtlmsspNegotiate128;
- if (doSigning)
- {
- NtlmsspFlags |= NtlmFlags.NtlmsspNegotiateSign | NtlmFlags.NtlmsspNegotiateAlwaysSign
- | NtlmFlags.NtlmsspNegotiateKeyExch;
- }
- Workstation = Type1Message.GetDefaultWorkstation();
- Log = LogStream.GetInstance();
- }
-
- public override string ToString()
- {
- string ret = "NtlmContext[auth=" + Auth + ",ntlmsspFlags=0x" + Hexdump.ToHexString
- (NtlmsspFlags, 8) + ",workstation=" + Workstation + ",isEstablished=" + isEstablished
- + ",state=" + State + ",serverChallenge=";
- if (ServerChallenge == null)
- {
- ret += "null";
- }
- else
- {
- ret += Hexdump.ToHexString(ServerChallenge, 0, ServerChallenge.Length * 2);
- }
- ret += ",signingKey=";
- if (SigningKey == null)
- {
- ret += "null";
- }
- else
- {
- ret += Hexdump.ToHexString(SigningKey, 0, SigningKey.Length * 2);
- }
- ret += "]";
- return ret;
- }
-
- public virtual bool IsEstablished()
- {
- return isEstablished;
- }
-
- public virtual byte[] GetServerChallenge()
- {
- return ServerChallenge;
- }
-
- public virtual byte[] GetSigningKey()
- {
- return SigningKey;
- }
-
- public virtual string GetNetbiosName()
- {
- return NetbiosName;
- }
-
- private string GetNtlmsspListItem(byte[] type2Token, int id0)
- {
- int ri = 58;
- for (; ; )
- {
- int id = Encdec.Dec_uint16le(type2Token, ri);
- int len = Encdec.Dec_uint16le(type2Token, ri + 2);
- ri += 4;
- if (id == 0 || (ri + len) > type2Token.Length)
- {
- break;
- }
- if (id == id0)
- {
- try
- {
- return Runtime.GetStringForBytes(type2Token, ri, len, SmbConstants.UniEncoding
- );
- }
- catch (UnsupportedEncodingException)
- {
- break;
- }
- }
- ri += len;
- }
- return null;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual byte[] InitSecContext(byte[] token, int offset, int len)
- {
- switch (State)
- {
- case 1:
- {
- Type1Message msg1 = new Type1Message(NtlmsspFlags, Auth.GetDomain(), Workstation);
- token = msg1.ToByteArray();
- if (Log.Level >= 4)
- {
- Log.WriteLine(msg1);
- if (Log.Level >= 6)
- {
- Hexdump.ToHexdump(Log, token, 0, token.Length);
- }
- }
- State++;
- break;
- }
-
- case 2:
- {
- try
- {
- Type2Message msg2 = new Type2Message(token);
- if (Log.Level >= 4)
- {
- Log.WriteLine(msg2);
- if (Log.Level >= 6)
- {
- Hexdump.ToHexdump(Log, token, 0, token.Length);
- }
- }
- ServerChallenge = msg2.GetChallenge();
- NtlmsspFlags &= msg2.GetFlags();
- // netbiosName = getNtlmsspListItem(token, 0x0001);
- Type3Message msg3 = new Type3Message(msg2, Auth.GetPassword(), Auth.GetDomain(),
- Auth.GetUsername(), Workstation, NtlmsspFlags);
- token = msg3.ToByteArray();
- if (Log.Level >= 4)
- {
- Log.WriteLine(msg3);
- if (Log.Level >= 6)
- {
- Hexdump.ToHexdump(Log, token, 0, token.Length);
- }
- }
- if ((NtlmsspFlags & NtlmFlags.NtlmsspNegotiateSign) != 0)
- {
- SigningKey = msg3.GetMasterKey();
- }
- isEstablished = true;
- State++;
- break;
- }
- catch (Exception e)
- {
- throw new SmbException(e.Message, e);
- }
- }
-
- default:
- {
- throw new SmbException("Invalid state");
- }
- }
- return token;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmPasswordAuthentication.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmPasswordAuthentication.cs
deleted file mode 100644
index ec3899fe9..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmPasswordAuthentication.cs
+++ /dev/null
@@ -1,807 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- /// <summary>This class stores and encrypts NTLM user credentials.</summary>
- /// <remarks>
- /// This class stores and encrypts NTLM user credentials. The default
- /// credentials are retrieved from the <tt>jcifs.smb.client.domain</tt>,
- /// <tt>jcifs.smb.client.username</tt>, and <tt>jcifs.smb.client.password</tt>
- /// properties.
- /// <p>
- /// Read <a href="../../../authhandler.html">jCIFS Exceptions and
- /// NtlmAuthenticator</a> for related information.
- /// </remarks>
-
- public sealed class NtlmPasswordAuthentication : Principal
- {
- private static readonly int LmCompatibility = Config.GetInt("jcifs.smb.lmCompatibility"
- , 3);
-
- private static readonly Random Random = new Random();
-
- private static LogStream _log = LogStream.GetInstance();
-
- private static readonly byte[] S8 = { unchecked(unchecked(0x4b)), unchecked(unchecked(0x47)), unchecked(unchecked(0x53)), unchecked(unchecked(0x21)), unchecked(unchecked(0x40)), unchecked(unchecked(0x23)), unchecked(unchecked(0x24)), unchecked(unchecked(0x25)) };
-
- // KGS!@#$%
- private static void E(byte[] key, byte[] data, byte[] e)
- {
- byte[] key7 = new byte[7];
- byte[] e8 = new byte[8];
- for (int i = 0; i < key.Length / 7; i++)
- {
- Array.Copy(key, i * 7, key7, 0, 7);
- DES des = new DES(key7);
- des.Encrypt(data, e8);
- Array.Copy(e8, 0, e, i * 8, 8);
- }
- }
-
- internal static string DefaultDomain;
-
- internal static string DefaultUsername;
-
- internal static string DefaultPassword;
-
- internal static readonly string Blank = string.Empty;
-
- public static readonly NtlmPasswordAuthentication Anonymous = new NtlmPasswordAuthentication
- (string.Empty, string.Empty, string.Empty);
-
- internal static void InitDefaults()
- {
- if (DefaultDomain != null)
- {
- return;
- }
- DefaultDomain = Config.GetProperty("jcifs.smb.client.domain", "?");
- DefaultUsername = Config.GetProperty("jcifs.smb.client.username", "GUEST");
- DefaultPassword = Config.GetProperty("jcifs.smb.client.password", Blank);
- }
-
- /// <summary>Generate the ANSI DES hash for the password associated with these credentials.
- /// </summary>
- /// <remarks>Generate the ANSI DES hash for the password associated with these credentials.
- /// </remarks>
- public static byte[] GetPreNtlmResponse(string password, byte[] challenge)
- {
- byte[] p14 = new byte[14];
- byte[] p21 = new byte[21];
- byte[] p24 = new byte[24];
- byte[] passwordBytes;
- try
- {
- passwordBytes = Runtime.GetBytesForString(password.ToUpper(), SmbConstants.OemEncoding);
- }
- catch (UnsupportedEncodingException uee)
- {
- throw new RuntimeException("Try setting jcifs.encoding=US-ASCII", uee);
- }
- int passwordLength = passwordBytes.Length;
- // Only encrypt the first 14 bytes of the password for Pre 0.12 NT LM
- if (passwordLength > 14)
- {
- passwordLength = 14;
- }
- Array.Copy(passwordBytes, 0, p14, 0, passwordLength);
- E(p14, S8, p21);
- E(p21, challenge, p24);
- return p24;
- }
-
- /// <summary>Generate the Unicode MD4 hash for the password associated with these credentials.
- /// </summary>
- /// <remarks>Generate the Unicode MD4 hash for the password associated with these credentials.
- /// </remarks>
- public static byte[] GetNtlmResponse(string password, byte[] challenge)
- {
- byte[] uni = null;
- byte[] p21 = new byte[21];
- byte[] p24 = new byte[24];
- try
- {
- uni = Runtime.GetBytesForString(password, SmbConstants.UniEncoding);
- }
- catch (UnsupportedEncodingException uee)
- {
- if (_log.Level > 0)
- {
- Runtime.PrintStackTrace(uee, _log);
- }
- }
- Md4 md4 = new Md4();
- md4.Update(uni);
- try
- {
- md4.Digest(p21, 0, 16);
- }
- catch (Exception ex)
- {
- if (_log.Level > 0)
- {
- Runtime.PrintStackTrace(ex, _log);
- }
- }
- E(p21, challenge, p24);
- return p24;
- }
-
- /// <summary>Creates the LMv2 response for the supplied information.</summary>
- /// <remarks>Creates the LMv2 response for the supplied information.</remarks>
- /// <param name="domain">The domain in which the username exists.</param>
- /// <param name="user">The username.</param>
- /// <param name="password">The user's password.</param>
- /// <param name="challenge">The server challenge.</param>
- /// <param name="clientChallenge">The client challenge (nonce).</param>
- public static byte[] GetLMv2Response(string domain, string user, string password,
- byte[] challenge, byte[] clientChallenge)
- {
- try
- {
- byte[] hash = new byte[16];
- byte[] response = new byte[24];
- // The next 2-1/2 lines of this should be placed with nTOWFv1 in place of password
- Md4 md4 = new Md4();
- md4.Update(Runtime.GetBytesForString(password, SmbConstants.UniEncoding)
- );
- Hmact64 hmac = new Hmact64(md4.Digest());
- hmac.Update(Runtime.GetBytesForString(user.ToUpper(), SmbConstants.UniEncoding
- ));
- hmac.Update(Runtime.GetBytesForString(domain.ToUpper(), SmbConstants.UniEncoding
- ));
- hmac = new Hmact64(hmac.Digest());
- hmac.Update(challenge);
- hmac.Update(clientChallenge);
- hmac.Digest(response, 0, 16);
- Array.Copy(clientChallenge, 0, response, 16, 8);
- return response;
- }
- catch (Exception ex)
- {
- if (_log.Level > 0)
- {
- Runtime.PrintStackTrace(ex, _log);
- }
- return null;
- }
- }
-
- public static byte[] GetNtlm2Response(byte[] nTowFv1, byte[] serverChallenge, byte
- [] clientChallenge)
- {
- byte[] sessionHash = new byte[8];
- try
- {
- MessageDigest md5;
- md5 = MessageDigest.GetInstance("MD5");
- md5.Update(serverChallenge);
- md5.Update(clientChallenge, 0, 8);
- Array.Copy(md5.Digest(), 0, sessionHash, 0, 8);
- }
- catch (Exception gse)
- {
- if (_log.Level > 0)
- {
- Runtime.PrintStackTrace(gse, _log);
- }
- throw new RuntimeException("MD5", gse);
- }
- byte[] key = new byte[21];
- Array.Copy(nTowFv1, 0, key, 0, 16);
- byte[] ntResponse = new byte[24];
- E(key, sessionHash, ntResponse);
- return ntResponse;
- }
-
- public static byte[] NtowFv1(string password)
- {
- if (password == null)
- {
- throw new RuntimeException("Password parameter is required");
- }
- try
- {
- Md4 md4 = new Md4();
- md4.Update(Runtime.GetBytesForString(password, SmbConstants.UniEncoding)
- );
- return md4.Digest();
- }
- catch (UnsupportedEncodingException uee)
- {
- throw new RuntimeException(uee.Message);
- }
- }
-
- public static byte[] NtowFv2(string domain, string username, string password)
- {
- try
- {
- Md4 md4 = new Md4();
- md4.Update(Runtime.GetBytesForString(password, SmbConstants.UniEncoding)
- );
- Hmact64 hmac = new Hmact64(md4.Digest());
- hmac.Update(Runtime.GetBytesForString(username.ToUpper(), SmbConstants.UniEncoding
- ));
- hmac.Update(Runtime.GetBytesForString(domain, SmbConstants.UniEncoding));
- return hmac.Digest();
- }
- catch (UnsupportedEncodingException uee)
- {
- throw new RuntimeException(uee.Message);
- }
- }
-
- internal static byte[] ComputeResponse(byte[] responseKey, byte[] serverChallenge
- , byte[] clientData, int offset, int length)
- {
- Hmact64 hmac = new Hmact64(responseKey);
- hmac.Update(serverChallenge);
- hmac.Update(clientData, offset, length);
- byte[] mac = hmac.Digest();
- byte[] ret = new byte[mac.Length + clientData.Length];
- Array.Copy(mac, 0, ret, 0, mac.Length);
- Array.Copy(clientData, 0, ret, mac.Length, clientData.Length);
- return ret;
- }
-
- public static byte[] GetLMv2Response(byte[] responseKeyLm, byte[] serverChallenge
- , byte[] clientChallenge)
- {
- return ComputeResponse(responseKeyLm, serverChallenge
- , clientChallenge, 0, clientChallenge.Length);
- }
-
- public static byte[] GetNtlMv2Response(byte[] responseKeyNt, byte[] serverChallenge
- , byte[] clientChallenge, long nanos1601, byte[] targetInfo)
- {
- int targetInfoLength = targetInfo != null ? targetInfo.Length : 0;
- byte[] temp = new byte[28 + targetInfoLength + 4];
- Encdec.Enc_uint32le(unchecked(0x00000101), temp, 0);
- // Header
- Encdec.Enc_uint32le(unchecked(0x00000000), temp, 4);
- // Reserved
- Encdec.Enc_uint64le(nanos1601, temp, 8);
- Array.Copy(clientChallenge, 0, temp, 16, 8);
- Encdec.Enc_uint32le(unchecked(0x00000000), temp, 24);
- // Unknown
- if (targetInfo != null)
- {
- Array.Copy(targetInfo, 0, temp, 28, targetInfoLength);
- }
- Encdec.Enc_uint32le(unchecked(0x00000000), temp, 28 + targetInfoLength);
- // mystery bytes!
- return ComputeResponse(responseKeyNt, serverChallenge
- , temp, 0, temp.Length);
- }
-
- internal static readonly NtlmPasswordAuthentication Null = new NtlmPasswordAuthentication
- (string.Empty, string.Empty, string.Empty);
-
- internal static readonly NtlmPasswordAuthentication Guest = new NtlmPasswordAuthentication
- ("?", "GUEST", string.Empty);
-
- internal static readonly NtlmPasswordAuthentication Default = new NtlmPasswordAuthentication
- (null);
-
- internal string Domain;
-
- internal string Username;
-
- internal string Password;
-
- internal byte[] AnsiHash;
-
- internal byte[] UnicodeHash;
-
- internal bool HashesExternal;
-
- internal byte[] ClientChallenge;
-
- internal byte[] Challenge;
-
- /// <summary>
- /// Create an <tt>NtlmPasswordAuthentication</tt> object from the userinfo
- /// component of an SMB URL like "<tt>domain;user:pass</tt>".
- /// </summary>
- /// <remarks>
- /// Create an <tt>NtlmPasswordAuthentication</tt> object from the userinfo
- /// component of an SMB URL like "<tt>domain;user:pass</tt>". This constructor
- /// is used internally be jCIFS when parsing SMB URLs.
- /// </remarks>
- public NtlmPasswordAuthentication(string userInfo)
- {
- Domain = Username = Password = null;
- if (userInfo != null)
- {
- try
- {
- userInfo = Unescape(userInfo);
- }
- catch (UnsupportedEncodingException)
- {
- }
- int i;
- int u;
- int end;
- char c;
- end = userInfo.Length;
- for (i = 0, u = 0; i < end; i++)
- {
- c = userInfo[i];
- if (c == ';')
- {
- Domain = Runtime.Substring(userInfo, 0, i);
- u = i + 1;
- }
- else
- {
- if (c == ':')
- {
- Password = Runtime.Substring(userInfo, i + 1);
- break;
- }
- }
- }
- Username = Runtime.Substring(userInfo, u, i);
- }
- InitDefaults();
- if (Domain == null)
- {
- Domain = DefaultDomain;
- }
- if (Username == null)
- {
- Username = DefaultUsername;
- }
- if (Password == null)
- {
- Password = DefaultPassword;
- }
- }
-
- /// <summary>
- /// Create an <tt>NtlmPasswordAuthentication</tt> object from a
- /// domain, username, and password.
- /// </summary>
- /// <remarks>
- /// Create an <tt>NtlmPasswordAuthentication</tt> object from a
- /// domain, username, and password. Parameters that are <tt>null</tt>
- /// will be substituted with <tt>jcifs.smb.client.domain</tt>,
- /// <tt>jcifs.smb.client.username</tt>, <tt>jcifs.smb.client.password</tt>
- /// property values.
- /// </remarks>
- public NtlmPasswordAuthentication(string domain, string username, string password
- )
- {
- int ci;
- if (username != null)
- {
- ci = username.IndexOf('@');
- if (ci > 0)
- {
- domain = Runtime.Substring(username, ci + 1);
- username = Runtime.Substring(username, 0, ci);
- }
- else
- {
- ci = username.IndexOf('\\');
- if (ci > 0)
- {
- domain = Runtime.Substring(username, 0, ci);
- username = Runtime.Substring(username, ci + 1);
- }
- }
- }
- this.Domain = domain;
- this.Username = username;
- this.Password = password;
- InitDefaults();
- if (domain == null)
- {
- this.Domain = DefaultDomain;
- }
- if (username == null)
- {
- this.Username = DefaultUsername;
- }
- if (password == null)
- {
- this.Password = DefaultPassword;
- }
- }
-
- /// <summary>
- /// Create an <tt>NtlmPasswordAuthentication</tt> object with raw password
- /// hashes.
- /// </summary>
- /// <remarks>
- /// Create an <tt>NtlmPasswordAuthentication</tt> object with raw password
- /// hashes. This is used exclusively by the <tt>jcifs.http.NtlmSsp</tt>
- /// class which is in turn used by NTLM HTTP authentication functionality.
- /// </remarks>
- public NtlmPasswordAuthentication(string domain, string username, byte[] challenge
- , byte[] ansiHash, byte[] unicodeHash)
- {
- if (domain == null || username == null || ansiHash == null || unicodeHash == null)
- {
- throw new ArgumentException("External credentials cannot be null");
- }
- this.Domain = domain;
- this.Username = username;
- Password = null;
- this.Challenge = challenge;
- this.AnsiHash = ansiHash;
- this.UnicodeHash = unicodeHash;
- HashesExternal = true;
- }
-
- /// <summary>Returns the domain.</summary>
- /// <remarks>Returns the domain.</remarks>
- public string GetDomain()
- {
- return Domain;
- }
-
- /// <summary>Returns the username.</summary>
- /// <remarks>Returns the username.</remarks>
- public string GetUsername()
- {
- return Username;
- }
-
- /// <summary>
- /// Returns the password in plain text or <tt>null</tt> if the raw password
- /// hashes were used to construct this <tt>NtlmPasswordAuthentication</tt>
- /// object which will be the case when NTLM HTTP Authentication is
- /// used.
- /// </summary>
- /// <remarks>
- /// Returns the password in plain text or <tt>null</tt> if the raw password
- /// hashes were used to construct this <tt>NtlmPasswordAuthentication</tt>
- /// object which will be the case when NTLM HTTP Authentication is
- /// used. There is no way to retrieve a users password in plain text unless
- /// it is supplied by the user at runtime.
- /// </remarks>
- public string GetPassword()
- {
- return Password;
- }
-
- /// <summary>
- /// Return the domain and username in the format:
- /// <tt>domain\\username</tt>.
- /// </summary>
- /// <remarks>
- /// Return the domain and username in the format:
- /// <tt>domain\\username</tt>. This is equivalent to <tt>toString()</tt>.
- /// </remarks>
- public new string GetName()
- {
- bool d = Domain.Length > 0 && Domain.Equals("?") == false;
- return d ? Domain + "\\" + Username : Username;
- }
-
- /// <summary>Computes the 24 byte ANSI password hash given the 8 byte server challenge.
- /// </summary>
- /// <remarks>Computes the 24 byte ANSI password hash given the 8 byte server challenge.
- /// </remarks>
- public byte[] GetAnsiHash(byte[] challenge)
- {
- if (HashesExternal)
- {
- return AnsiHash;
- }
- switch (LmCompatibility)
- {
- case 0:
- case 1:
- {
- return GetPreNtlmResponse(Password, challenge);
- }
-
- case 2:
- {
- return GetNtlmResponse(Password, challenge);
- }
-
- case 3:
- case 4:
- case 5:
- {
- if (ClientChallenge == null)
- {
- ClientChallenge = new byte[8];
- Random.NextBytes(ClientChallenge);
- }
- return GetLMv2Response(Domain, Username, Password, challenge, ClientChallenge);
- }
-
- default:
- {
- return GetPreNtlmResponse(Password, challenge);
- }
- }
- }
-
- /// <summary>Computes the 24 byte Unicode password hash given the 8 byte server challenge.
- /// </summary>
- /// <remarks>Computes the 24 byte Unicode password hash given the 8 byte server challenge.
- /// </remarks>
- public byte[] GetUnicodeHash(byte[] challenge)
- {
- if (HashesExternal)
- {
- return UnicodeHash;
- }
- switch (LmCompatibility)
- {
- case 0:
- case 1:
- case 2:
- {
- return GetNtlmResponse(Password, challenge);
- }
-
- case 3:
- case 4:
- case 5:
- {
- return new byte[0];
- }
-
- default:
- {
- return GetNtlmResponse(Password, challenge);
- }
- }
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public byte[] GetSigningKey(byte[] challenge)
- {
- switch (LmCompatibility)
- {
- case 0:
- case 1:
- case 2:
- {
- byte[] signingKey = new byte[40];
- GetUserSessionKey(challenge, signingKey, 0);
- Array.Copy(GetUnicodeHash(challenge), 0, signingKey, 16, 24);
- return signingKey;
- }
-
- case 3:
- case 4:
- case 5:
- {
- throw new SmbException("NTLMv2 requires extended security (jcifs.smb.client.useExtendedSecurity must be true if jcifs.smb.lmCompatibility >= 3)"
- );
- }
- }
- return null;
- }
-
- /// <summary>Returns the effective user session key.</summary>
- /// <remarks>Returns the effective user session key.</remarks>
- /// <param name="challenge">The server challenge.</param>
- /// <returns>
- /// A <code>byte[]</code> containing the effective user session key,
- /// used in SMB MAC signing and NTLMSSP signing and sealing.
- /// </returns>
- public byte[] GetUserSessionKey(byte[] challenge)
- {
- if (HashesExternal)
- {
- return null;
- }
- byte[] key = new byte[16];
- try
- {
- GetUserSessionKey(challenge, key, 0);
- }
- catch (Exception ex)
- {
- if (_log.Level > 0)
- {
- Runtime.PrintStackTrace(ex, _log);
- }
- }
- return key;
- }
-
- /// <summary>Calculates the effective user session key.</summary>
- /// <remarks>Calculates the effective user session key.</remarks>
- /// <param name="challenge">The server challenge.</param>
- /// <param name="dest">
- /// The destination array in which the user session key will be
- /// placed.
- /// </param>
- /// <param name="offset">
- /// The offset in the destination array at which the
- /// session key will start.
- /// </param>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal void GetUserSessionKey(byte[] challenge, byte[] dest, int offset)
- {
- if (HashesExternal)
- {
- return;
- }
- try
- {
- Md4 md4 = new Md4();
- md4.Update(Runtime.GetBytesForString(Password, SmbConstants.UniEncoding)
- );
- switch (LmCompatibility)
- {
- case 0:
- case 1:
- case 2:
- {
- md4.Update(md4.Digest());
- md4.Digest(dest, offset, 16);
- break;
- }
-
- case 3:
- case 4:
- case 5:
- {
- if (ClientChallenge == null)
- {
- ClientChallenge = new byte[8];
- Random.NextBytes(ClientChallenge);
- }
- Hmact64 hmac = new Hmact64(md4.Digest());
- hmac.Update(Runtime.GetBytesForString(Username.ToUpper(), SmbConstants.UniEncoding
- ));
- hmac.Update(Runtime.GetBytesForString(Domain.ToUpper(), SmbConstants.UniEncoding
- ));
- byte[] ntlmv2Hash = hmac.Digest();
- hmac = new Hmact64(ntlmv2Hash);
- hmac.Update(challenge);
- hmac.Update(ClientChallenge);
- Hmact64 userKey = new Hmact64(ntlmv2Hash);
- userKey.Update(hmac.Digest());
- userKey.Digest(dest, offset, 16);
- break;
- }
-
- default:
- {
- md4.Update(md4.Digest());
- md4.Digest(dest, offset, 16);
- break;
- }
- }
- }
- catch (Exception e)
- {
- throw new SmbException(string.Empty, e);
- }
- }
-
- /// <summary>
- /// Compares two <tt>NtlmPasswordAuthentication</tt> objects for
- /// equality.
- /// </summary>
- /// <remarks>
- /// Compares two <tt>NtlmPasswordAuthentication</tt> objects for
- /// equality. Two <tt>NtlmPasswordAuthentication</tt> objects are equal if
- /// their caseless domain and username fields are equal and either both hashes are external and they are equal or both internally supplied passwords are equal. If one <tt>NtlmPasswordAuthentication</tt> object has external hashes (meaning negotiated via NTLM HTTP Authentication) and the other does not they will not be equal. This is technically not correct however the server 8 byte challage would be required to compute and compare the password hashes but that it not available with this method.
- /// </remarks>
- public override bool Equals(object obj)
- {
- if (obj is NtlmPasswordAuthentication)
- {
- NtlmPasswordAuthentication ntlm = (NtlmPasswordAuthentication
- )obj;
- if (ntlm.Domain.ToUpper().Equals(Domain.ToUpper()) && ntlm.Username.ToUpper().Equals
- (Username.ToUpper()))
- {
- if (HashesExternal && ntlm.HashesExternal)
- {
-
- return Arrays.Equals(AnsiHash, ntlm.AnsiHash) && Arrays.Equals(UnicodeHash, ntlm.
- UnicodeHash);
- }
- if (!HashesExternal && Password.Equals(ntlm.Password))
- {
- return true;
- }
- }
- }
- return false;
- }
-
- /// <summary>Return the upcased username hash code.</summary>
- /// <remarks>Return the upcased username hash code.</remarks>
- public override int GetHashCode()
- {
- return GetName().ToUpper().GetHashCode();
- }
-
- /// <summary>
- /// Return the domain and username in the format:
- /// <tt>domain\\username</tt>.
- /// </summary>
- /// <remarks>
- /// Return the domain and username in the format:
- /// <tt>domain\\username</tt>. This is equivalent to <tt>getName()</tt>.
- /// </remarks>
- public override string ToString()
- {
- return GetName();
- }
-
- /// <exception cref="System.FormatException"></exception>
- /// <exception cref="UnsupportedEncodingException"></exception>
- internal static string Unescape(string str)
- {
- char ch;
- int i;
- int j;
- int state;
- int len;
- char[] @out;
- byte[] b = new byte[1];
- if (str == null)
- {
- return null;
- }
- len = str.Length;
- @out = new char[len];
- state = 0;
- for (i = j = 0; i < len; i++)
- {
- switch (state)
- {
- case 0:
- {
- ch = str[i];
- if (ch == '%')
- {
- state = 1;
- }
- else
- {
- @out[j++] = ch;
- }
- break;
- }
-
- case 1:
- {
- b[0] = unchecked((byte)(Convert.ToInt32(Runtime.Substring(str, i,
- i + 2), 16) & unchecked(0xFF)));
- @out[j++] = (Runtime.GetStringForBytes(b, 0, 1, "ASCII"))[0];
- i++;
- state = 0;
- break;
- }
- }
- }
- return new string(@out, 0, j);
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/Principal.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/Principal.cs
deleted file mode 100644
index 14a5479e3..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/Principal.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- public class Principal
- {
- private string _name = "";
-
- public string GetName()
- {
- return _name;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SID.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SID.cs
deleted file mode 100644
index a6ad59fb1..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SID.cs
+++ /dev/null
@@ -1,900 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.IO;
-using SharpCifs.Dcerpc;
-using SharpCifs.Dcerpc.Msrpc;
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-using Hashtable = SharpCifs.Util.Sharpen.Hashtable; //not System.Collections.Hashtable
-
-namespace SharpCifs.Smb
-{
- /// <summary>
- /// A Windows SID is a numeric identifier used to represent Windows
- /// accounts.
- /// </summary>
- /// <remarks>
- /// A Windows SID is a numeric identifier used to represent Windows
- /// accounts. SIDs are commonly represented using a textual format such as
- /// <tt>S-1-5-21-1496946806-2192648263-3843101252-1029</tt> but they may
- /// also be resolved to yield the name of the associated Windows account
- /// such as <tt>Administrators</tt> or <tt>MYDOM\alice</tt>.
- /// <p>
- /// Consider the following output of <tt>examples/SidLookup.java</tt>:
- /// <pre>
- /// toString: S-1-5-21-4133388617-793952518-2001621813-512
- /// toDisplayString: WNET\Domain Admins
- /// getType: 2
- /// getTypeText: Domain group
- /// getDomainName: WNET
- /// getAccountName: Domain Admins
- /// </pre>
- /// </remarks>
- public class Sid : Rpc.SidT
- {
- public const int SidTypeUseNone = Lsarpc.SidNameUseNone;
-
- public const int SidTypeUser = Lsarpc.SidNameUser;
-
- public const int SidTypeDomGrp = Lsarpc.SidNameDomGrp;
-
- public const int SidTypeDomain = Lsarpc.SidNameDomain;
-
- public const int SidTypeAlias = Lsarpc.SidNameAlias;
-
- public const int SidTypeWknGrp = Lsarpc.SidNameWknGrp;
-
- public const int SidTypeDeleted = Lsarpc.SidNameDeleted;
-
- public const int SidTypeInvalid = Lsarpc.SidNameInvalid;
-
- public const int SidTypeUnknown = Lsarpc.SidNameUnknown;
-
- internal static readonly string[] SidTypeNames = { "0", "User", "Domain group"
- , "Domain", "Local group", "Builtin group", "Deleted", "Invalid", "Unknown" };
-
- public const int SidFlagResolveSids = unchecked(0x0001);
-
- public static Sid Everyone;
-
- public static Sid CreatorOwner;
-
- public static Sid SYSTEM;
-
- static Sid()
- {
- try
- {
- Everyone = new Sid("S-1-1-0");
- CreatorOwner = new Sid("S-1-3-0");
- SYSTEM = new Sid("S-1-5-18");
- }
- catch (SmbException)
- {
- }
- }
-
- internal static Hashtable SidCache = new Hashtable();
-
- /// <exception cref="System.IO.IOException"></exception>
- internal static void ResolveSids(DcerpcHandle handle, LsaPolicyHandle policyHandle
- , Sid[] sids)
- {
- MsrpcLookupSids rpc = new MsrpcLookupSids(policyHandle, sids);
- handle.Sendrecv(rpc);
- switch (rpc.Retval)
- {
- case 0:
- case NtStatus.NtStatusNoneMapped:
- case unchecked(0x00000107):
- {
- // NT_STATUS_SOME_NOT_MAPPED
- break;
- }
-
- default:
- {
- throw new SmbException(rpc.Retval, false);
- }
- }
- for (int si = 0; si < sids.Length; si++)
- {
- sids[si].Type = rpc.Names.Names[si].SidType;
- sids[si].DomainName = null;
- switch (sids[si].Type)
- {
- case SidTypeUser:
- case SidTypeDomGrp:
- case SidTypeDomain:
- case SidTypeAlias:
- case SidTypeWknGrp:
- {
- int sidIndex = rpc.Names.Names[si].SidIndex;
- Rpc.Unicode_string ustr = rpc.Domains.Domains[sidIndex].Name;
- sids[si].DomainName = (new UnicodeString(ustr, false)).ToString();
- break;
- }
- }
- sids[si].AcctName = (new UnicodeString(rpc.Names.Names[si].Name, false)).ToString
- ();
- sids[si].OriginServer = null;
- sids[si].OriginAuth = null;
- }
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- internal static void ResolveSids0(string authorityServerName, NtlmPasswordAuthentication
- auth, Sid[] sids)
- {
- DcerpcHandle handle = null;
- LsaPolicyHandle policyHandle = null;
- lock (SidCache)
- {
- try
- {
- handle = DcerpcHandle.GetHandle("ncacn_np:" + authorityServerName + "[\\PIPE\\lsarpc]"
- , auth);
- string server = authorityServerName;
- int dot = server.IndexOf('.');
- if (dot > 0 && char.IsDigit(server[0]) == false)
- {
- server = Runtime.Substring(server, 0, dot);
- }
- policyHandle = new LsaPolicyHandle(handle, "\\\\" + server, unchecked(0x00000800));
- ResolveSids(handle, policyHandle, sids);
- }
- finally
- {
- if (handle != null)
- {
- if (policyHandle != null)
- {
- policyHandle.Close();
- }
- handle.Close();
- }
- }
- }
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- public static void ResolveSids(string authorityServerName, NtlmPasswordAuthentication
- auth, Sid[] sids, int offset, int length)
- {
- List<object> list = new List<object>();//new List<object>(sids.Length);
- int si;
- lock (SidCache)
- {
- for (si = 0; si < length; si++)
- {
- Sid sid = (Sid)SidCache.Get(sids[offset + si]);
- if (sid != null)
- {
- sids[offset + si].Type = sid.Type;
- sids[offset + si].DomainName = sid.DomainName;
- sids[offset + si].AcctName = sid.AcctName;
- }
- else
- {
- list.Add(sids[offset + si]);
- }
- }
- if (list.Count > 0)
- {
- //sids = (Jcifs.Smb.SID[])Sharpen.Collections.ToArray(list, new Jcifs.Smb.SID[0]);
- sids = (Sid[])list.ToArray();
- ResolveSids0(authorityServerName, auth, sids);
- for (si = 0; si < sids.Length; si++)
- {
- SidCache.Put(sids[si], sids[si]);
- }
- }
- }
- }
-
- /// <summary>Resolve an array of SIDs using a cache and at most one MSRPC request.</summary>
- /// <remarks>
- /// Resolve an array of SIDs using a cache and at most one MSRPC request.
- /// <p>
- /// This method will attempt
- /// to resolve SIDs using a cache and cache the results of any SIDs that
- /// required resolving with the authority. SID cache entries are currently not
- /// expired because under normal circumstances SID information never changes.
- /// </remarks>
- /// <param name="authorityServerName">The hostname of the server that should be queried. For maximum efficiency this should be the hostname of a domain controller however a member server will work as well and a domain controller may not return names for SIDs corresponding to local accounts for which the domain controller is not an authority.
- /// </param>
- /// <param name="auth">The credentials that should be used to communicate with the named server. As usual, <tt>null</tt> indicates that default credentials should be used.
- /// </param>
- /// <param name="sids">The SIDs that should be resolved. After this function is called, the names associated with the SIDs may be queried with the <tt>toDisplayString</tt>, <tt>getDomainName</tt>, and <tt>getAccountName</tt> methods.
- /// </param>
- /// <exception cref="System.IO.IOException"></exception>
- public static void ResolveSids(string authorityServerName, NtlmPasswordAuthentication
- auth, Sid[] sids)
- {
- List<object> list = new List<object>();//new List<object>(sids.Length);
- int si;
- lock (SidCache)
- {
- for (si = 0; si < sids.Length; si++)
- {
- Sid sid = (Sid)SidCache.Get(sids[si]);
- if (sid != null)
- {
- sids[si].Type = sid.Type;
- sids[si].DomainName = sid.DomainName;
- sids[si].AcctName = sid.AcctName;
- }
- else
- {
- list.Add(sids[si]);
- }
- }
- if (list.Count > 0)
- {
- //sids = (Jcifs.Smb.SID[])Sharpen.Collections.ToArray(list, new Jcifs.Smb.SID[0]);
- sids = (Sid[]) list.ToArray();
- ResolveSids0(authorityServerName, auth, sids);
- for (si = 0; si < sids.Length; si++)
- {
- SidCache.Put(sids[si], sids[si]);
- }
- }
- }
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- public static Sid GetServerSid(string server, NtlmPasswordAuthentication
- auth)
- {
- DcerpcHandle handle = null;
- LsaPolicyHandle policyHandle = null;
- Lsarpc.LsarDomainInfo info = new Lsarpc.LsarDomainInfo();
- MsrpcQueryInformationPolicy rpc;
- lock (SidCache)
- {
- try
- {
- handle = DcerpcHandle.GetHandle("ncacn_np:" + server + "[\\PIPE\\lsarpc]", auth);
- // NetApp doesn't like the 'generic' access mask values
- policyHandle = new LsaPolicyHandle(handle, null, unchecked(0x00000001));
- rpc = new MsrpcQueryInformationPolicy(policyHandle, Lsarpc.PolicyInfoAccountDomain
- , info);
- handle.Sendrecv(rpc);
- if (rpc.Retval != 0)
- {
- throw new SmbException(rpc.Retval, false);
- }
- return new Sid(info.Sid, SidTypeDomain, (new UnicodeString
- (info.Name, false)).ToString(), null, false);
- }
- finally
- {
- if (handle != null)
- {
- if (policyHandle != null)
- {
- policyHandle.Close();
- }
- handle.Close();
- }
- }
- }
- }
-
- public static byte[] ToByteArray(Rpc.SidT sid)
- {
- byte[] dst = new byte[1 + 1 + 6 + sid.SubAuthorityCount * 4];
- int di = 0;
- dst[di++] = sid.Revision;
- dst[di++] = sid.SubAuthorityCount;
- Array.Copy(sid.IdentifierAuthority, 0, dst, di, 6);
- di += 6;
- for (int ii = 0; ii < sid.SubAuthorityCount; ii++)
- {
- Encdec.Enc_uint32le(sid.SubAuthority[ii], dst, di);
- di += 4;
- }
- return dst;
- }
-
- internal int Type;
-
- internal string DomainName;
-
- internal string AcctName;
-
- internal string OriginServer;
-
- internal NtlmPasswordAuthentication OriginAuth;
-
- public Sid(byte[] src, int si)
- {
- Revision = src[si++];
- SubAuthorityCount = src[si++];
- IdentifierAuthority = new byte[6];
- Array.Copy(src, si, IdentifierAuthority, 0, 6);
- si += 6;
- if (SubAuthorityCount > 100)
- {
- throw new RuntimeException("Invalid SID sub_authority_count");
- }
- SubAuthority = new int[SubAuthorityCount];
- for (int i = 0; i < SubAuthorityCount; i++)
- {
- SubAuthority[i] = ServerMessageBlock.ReadInt4(src, si);
- si += 4;
- }
- }
-
- /// <summary>
- /// Construct a SID from it's textual representation such as
- /// <tt>S-1-5-21-1496946806-2192648263-3843101252-1029</tt>.
- /// </summary>
- /// <remarks>
- /// Construct a SID from it's textual representation such as
- /// <tt>S-1-5-21-1496946806-2192648263-3843101252-1029</tt>.
- /// </remarks>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public Sid(string textual)
- {
- StringTokenizer st = new StringTokenizer(textual, "-");
- if (st.CountTokens() < 3 || !st.NextToken().Equals("S"))
- {
- // need S-N-M
- throw new SmbException("Bad textual SID format: " + textual);
- }
- Revision = byte.Parse(st.NextToken());
- string tmp = st.NextToken();
- long id = 0;
- if (tmp.StartsWith("0x"))
- {
- //id = long.Parse(Sharpen.Runtime.Substring(tmp, 2), 16);
- id = long.Parse(Runtime.Substring(tmp, 2));
- }
- else
- {
- id = long.Parse(tmp);
- }
- IdentifierAuthority = new byte[6];
- for (int i = 5; id > 0; i--)
- {
- IdentifierAuthority[i] = unchecked((byte)(id % 256));
- id >>= 8;
- }
- SubAuthorityCount = unchecked((byte)st.CountTokens());
- if (SubAuthorityCount > 0)
- {
- SubAuthority = new int[SubAuthorityCount];
- for (int i1 = 0; i1 < SubAuthorityCount; i1++)
- {
- SubAuthority[i1] = (int)(long.Parse(st.NextToken()) & unchecked(0xFFFFFFFFL));
- }
- }
- }
-
- /// <summary>
- /// Construct a SID from a domain SID and an RID
- /// (relative identifier).
- /// </summary>
- /// <remarks>
- /// Construct a SID from a domain SID and an RID
- /// (relative identifier). For example, a domain SID
- /// <tt>S-1-5-21-1496946806-2192648263-3843101252</tt> and RID <tt>1029</tt> would
- /// yield the SID <tt>S-1-5-21-1496946806-2192648263-3843101252-1029</tt>.
- /// </remarks>
- public Sid(Sid domsid, int rid)
- {
- Revision = domsid.Revision;
- IdentifierAuthority = domsid.IdentifierAuthority;
- SubAuthorityCount = unchecked((byte)(domsid.SubAuthorityCount + 1));
- SubAuthority = new int[SubAuthorityCount];
- int i;
- for (i = 0; i < domsid.SubAuthorityCount; i++)
- {
- SubAuthority[i] = domsid.SubAuthority[i];
- }
- SubAuthority[i] = rid;
- }
-
- public Sid(Rpc.SidT sid, int type, string domainName, string acctName, bool decrementAuthority
- )
- {
- Revision = sid.Revision;
- SubAuthorityCount = sid.SubAuthorityCount;
- IdentifierAuthority = sid.IdentifierAuthority;
- SubAuthority = sid.SubAuthority;
- this.Type = type;
- this.DomainName = domainName;
- this.AcctName = acctName;
- if (decrementAuthority)
- {
- SubAuthorityCount--;
- SubAuthority = new int[SubAuthorityCount];
- for (int i = 0; i < SubAuthorityCount; i++)
- {
- SubAuthority[i] = sid.SubAuthority[i];
- }
- }
- }
-
- public virtual Sid GetDomainSid()
- {
- return new Sid(this, SidTypeDomain, DomainName, null, GetType()
- != SidTypeDomain);
- }
-
- public virtual int GetRid()
- {
- if (GetType() == SidTypeDomain)
- {
- throw new ArgumentException("This SID is a domain sid");
- }
- return SubAuthority[SubAuthorityCount - 1];
- }
-
- /// <summary>Returns the type of this SID indicating the state or type of account.</summary>
- /// <remarks>
- /// Returns the type of this SID indicating the state or type of account.
- /// <p>
- /// SID types are described in the following table.
- /// <tt>
- /// <table>
- /// <tr><th>Type</th><th>Name</th></tr>
- /// <tr><td>SID_TYPE_USE_NONE</td><td>0</td></tr>
- /// <tr><td>SID_TYPE_USER</td><td>User</td></tr>
- /// <tr><td>SID_TYPE_DOM_GRP</td><td>Domain group</td></tr>
- /// <tr><td>SID_TYPE_DOMAIN</td><td>Domain</td></tr>
- /// <tr><td>SID_TYPE_ALIAS</td><td>Local group</td></tr>
- /// <tr><td>SID_TYPE_WKN_GRP</td><td>Builtin group</td></tr>
- /// <tr><td>SID_TYPE_DELETED</td><td>Deleted</td></tr>
- /// <tr><td>SID_TYPE_INVALID</td><td>Invalid</td></tr>
- /// <tr><td>SID_TYPE_UNKNOWN</td><td>Unknown</td></tr>
- /// </table>
- /// </tt>
- /// </remarks>
- public virtual int GetType()
- {
- if (OriginServer != null)
- {
- ResolveWeak();
- }
- return Type;
- }
-
- /// <summary>
- /// Return text represeting the SID type suitable for display to
- /// users.
- /// </summary>
- /// <remarks>
- /// Return text represeting the SID type suitable for display to
- /// users. Text includes 'User', 'Domain group', 'Local group', etc.
- /// </remarks>
- public virtual string GetTypeText()
- {
- if (OriginServer != null)
- {
- ResolveWeak();
- }
- return SidTypeNames[Type];
- }
-
- /// <summary>
- /// Return the domain name of this SID unless it could not be
- /// resolved in which case the numeric representation is returned.
- /// </summary>
- /// <remarks>
- /// Return the domain name of this SID unless it could not be
- /// resolved in which case the numeric representation is returned.
- /// </remarks>
- public virtual string GetDomainName()
- {
- if (OriginServer != null)
- {
- ResolveWeak();
- }
- if (Type == SidTypeUnknown)
- {
- string full = ToString();
- return Runtime.Substring(full, 0, full.Length - GetAccountName().Length -
- 1);
- }
- return DomainName;
- }
-
- /// <summary>
- /// Return the sAMAccountName of this SID unless it could not
- /// be resolved in which case the numeric RID is returned.
- /// </summary>
- /// <remarks>
- /// Return the sAMAccountName of this SID unless it could not
- /// be resolved in which case the numeric RID is returned. If this
- /// SID is a domain SID, this method will return an empty String.
- /// </remarks>
- public virtual string GetAccountName()
- {
- if (OriginServer != null)
- {
- ResolveWeak();
- }
- if (Type == SidTypeUnknown)
- {
- return string.Empty + SubAuthority[SubAuthorityCount - 1];
- }
- if (Type == SidTypeDomain)
- {
- return string.Empty;
- }
- return AcctName;
- }
-
- public override int GetHashCode()
- {
- int hcode = IdentifierAuthority[5];
- for (int i = 0; i < SubAuthorityCount; i++)
- {
- hcode += 65599 * SubAuthority[i];
- }
- return hcode;
- }
-
- public override bool Equals(object obj)
- {
- if (obj is Sid)
- {
- Sid sid = (Sid)obj;
- if (sid == this)
- {
- return true;
- }
- if (sid.SubAuthorityCount == SubAuthorityCount)
- {
- int i = SubAuthorityCount;
- while (i-- > 0)
- {
- if (sid.SubAuthority[i] != SubAuthority[i])
- {
- return false;
- }
- }
- for (i = 0; i < 6; i++)
- {
- if (sid.IdentifierAuthority[i] != IdentifierAuthority[i])
- {
- return false;
- }
- }
- return sid.Revision == Revision;
- }
- }
- return false;
- }
-
- /// <summary>
- /// Return the numeric representation of this sid such as
- /// <tt>S-1-5-21-1496946806-2192648263-3843101252-1029</tt>.
- /// </summary>
- /// <remarks>
- /// Return the numeric representation of this sid such as
- /// <tt>S-1-5-21-1496946806-2192648263-3843101252-1029</tt>.
- /// </remarks>
- public override string ToString()
- {
- string ret = "S-" + (Revision & unchecked(0xFF)) + "-";
- if (IdentifierAuthority[0] != unchecked(0) || IdentifierAuthority[1] != unchecked(
- 0))
- {
- ret += "0x";
- ret += Hexdump.ToHexString(IdentifierAuthority, 0, 6);
- }
- else
- {
- int shift = 0;
- long id = 0;
- for (int i = 5; i > 1; i--)
- {
- id += (IdentifierAuthority[i] & unchecked(0xFFL)) << shift;
- shift += 8;
- }
- ret += id;
- }
- for (int i1 = 0; i1 < SubAuthorityCount; i1++)
- {
- ret += "-" + (SubAuthority[i1] & unchecked(0xFFFFFFFFL));
- }
- return ret;
- }
-
- /// <summary>
- /// Return a String representing this SID ideal for display to
- /// users.
- /// </summary>
- /// <remarks>
- /// Return a String representing this SID ideal for display to
- /// users. This method should return the same text that the ACL
- /// editor in Windows would display.
- /// <p>
- /// Specifically, if the SID has
- /// been resolved and it is not a domain SID or builtin account,
- /// the full DOMAIN\name form of the account will be
- /// returned (e.g. MYDOM\alice or MYDOM\Domain Users).
- /// If the SID has been resolved but it is is a domain SID,
- /// only the domain name will be returned (e.g. MYDOM).
- /// If the SID has been resolved but it is a builtin account,
- /// only the name component will be returned (e.g. SYSTEM).
- /// If the sid cannot be resolved the numeric representation from
- /// toString() is returned.
- /// </remarks>
- public virtual string ToDisplayString()
- {
- if (OriginServer != null)
- {
- ResolveWeak();
- }
- if (DomainName != null)
- {
- string str;
- if (Type == SidTypeDomain)
- {
- str = DomainName;
- }
- else
- {
- if (Type == SidTypeWknGrp || DomainName.Equals("BUILTIN"))
- {
- if (Type == SidTypeUnknown)
- {
- str = ToString();
- }
- else
- {
- str = AcctName;
- }
- }
- else
- {
- str = DomainName + "\\" + AcctName;
- }
- }
- return str;
- }
- return ToString();
- }
-
- /// <summary>Manually resolve this SID.</summary>
- /// <remarks>
- /// Manually resolve this SID. Normally SIDs are automatically
- /// resolved. However, if a SID is constructed explicitly using a SID
- /// constructor, JCIFS will have no knowledge of the server that created the
- /// SID and therefore cannot possibly resolve it automatically. In this case,
- /// this method will be necessary.
- /// </remarks>
- /// <param name="authorityServerName">The FQDN of the server that is an authority for the SID.
- /// </param>
- /// <param name="auth">Credentials suitable for accessing the SID's information.</param>
- /// <exception cref="System.IO.IOException"></exception>
- public virtual void Resolve(string authorityServerName, NtlmPasswordAuthentication
- auth)
- {
- Sid[] sids = new Sid[1];
- sids[0] = this;
- ResolveSids(authorityServerName, auth, sids);
- }
-
- internal virtual void ResolveWeak()
- {
- if (OriginServer != null)
- {
- try
- {
- Resolve(OriginServer, OriginAuth);
- }
- catch (IOException)
- {
- }
- finally
- {
- OriginServer = null;
- OriginAuth = null;
- }
- }
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- internal static Sid[] GetGroupMemberSids0(DcerpcHandle handle, SamrDomainHandle
- domainHandle, Sid domsid, int rid, int flags)
- {
- SamrAliasHandle aliasHandle = null;
- Lsarpc.LsarSidArray sidarray = new Lsarpc.LsarSidArray();
- MsrpcGetMembersInAlias rpc = null;
- try
- {
- aliasHandle = new SamrAliasHandle(handle, domainHandle, unchecked(0x0002000c), rid);
- rpc = new MsrpcGetMembersInAlias(aliasHandle, sidarray);
- handle.Sendrecv(rpc);
- if (rpc.Retval != 0)
- {
- throw new SmbException(rpc.Retval, false);
- }
- Sid[] sids = new Sid[rpc.Sids.NumSids];
- string originServer = handle.GetServer();
- NtlmPasswordAuthentication originAuth = (NtlmPasswordAuthentication)handle.GetPrincipal
- ();
- for (int i = 0; i < sids.Length; i++)
- {
- sids[i] = new Sid(rpc.Sids.Sids[i].Sid, 0, null, null, false);
- sids[i].OriginServer = originServer;
- sids[i].OriginAuth = originAuth;
- }
- if (sids.Length > 0 && (flags & SidFlagResolveSids) != 0)
- {
- ResolveSids(originServer, originAuth, sids);
- }
- return sids;
- }
- finally
- {
- if (aliasHandle != null)
- {
- aliasHandle.Close();
- }
- }
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- public virtual Sid[] GetGroupMemberSids(string authorityServerName, NtlmPasswordAuthentication
- auth, int flags)
- {
- if (Type != SidTypeDomGrp && Type != SidTypeAlias)
- {
- return new Sid[0];
- }
- DcerpcHandle handle = null;
- SamrPolicyHandle policyHandle = null;
- SamrDomainHandle domainHandle = null;
- Sid domsid = GetDomainSid();
- lock (SidCache)
- {
- try
- {
- handle = DcerpcHandle.GetHandle("ncacn_np:" + authorityServerName + "[\\PIPE\\samr]"
- , auth);
- policyHandle = new SamrPolicyHandle(handle, authorityServerName, unchecked(0x00000030));
- domainHandle = new SamrDomainHandle(handle, policyHandle, unchecked(0x00000200), domsid);
- return GetGroupMemberSids0(handle, domainHandle, domsid, GetRid(),
- flags);
- }
- finally
- {
- if (handle != null)
- {
- if (policyHandle != null)
- {
- if (domainHandle != null)
- {
- domainHandle.Close();
- }
- policyHandle.Close();
- }
- handle.Close();
- }
- }
- }
- }
-
- /// <summary>
- /// This specialized method returns a Map of users and local groups for the
- /// target server where keys are SIDs representing an account and each value
- /// is an List<object> of SIDs represents the local groups that the account is
- /// a member of.
- /// </summary>
- /// <remarks>
- /// This specialized method returns a Map of users and local groups for the
- /// target server where keys are SIDs representing an account and each value
- /// is an List<object> of SIDs represents the local groups that the account is
- /// a member of.
- /// <p/>
- /// This method is designed to assist with computing access control for a
- /// given user when the target object's ACL has local groups. Local groups
- /// are not listed in a user's group membership (e.g. as represented by the
- /// tokenGroups constructed attribute retrived via LDAP).
- /// <p/>
- /// Domain groups nested inside a local group are currently not expanded. In
- /// this case the key (SID) type will be SID_TYPE_DOM_GRP rather than
- /// SID_TYPE_USER.
- /// </remarks>
- /// <param name="authorityServerName">The server from which the local groups will be queried.
- /// </param>
- /// <param name="auth">The credentials required to query groups and group members.</param>
- /// <param name="flags">
- /// Flags that control the behavior of the operation. When all
- /// name associated with SIDs will be required, the SID_FLAG_RESOLVE_SIDS
- /// flag should be used which causes all group member SIDs to be resolved
- /// together in a single more efficient operation.
- /// </param>
- /// <exception cref="System.IO.IOException"></exception>
- internal static Hashtable GetLocalGroupsMap(string authorityServerName, NtlmPasswordAuthentication
- auth, int flags)
- {
- Sid domsid = GetServerSid(authorityServerName, auth);
- DcerpcHandle handle = null;
- SamrPolicyHandle policyHandle = null;
- SamrDomainHandle domainHandle = null;
- Samr.SamrSamArray sam = new Samr.SamrSamArray();
- MsrpcEnumerateAliasesInDomain rpc;
- lock (SidCache)
- {
- try
- {
- handle = DcerpcHandle.GetHandle("ncacn_np:" + authorityServerName + "[\\PIPE\\samr]"
- , auth);
- policyHandle = new SamrPolicyHandle(handle, authorityServerName, unchecked(0x02000000));
- domainHandle = new SamrDomainHandle(handle, policyHandle, unchecked(0x02000000), domsid);
- rpc = new MsrpcEnumerateAliasesInDomain(domainHandle, unchecked(0xFFFF), sam
- );
- handle.Sendrecv(rpc);
- if (rpc.Retval != 0)
- {
- throw new SmbException(rpc.Retval, false);
- }
- Hashtable map = new Hashtable();
- for (int ei = 0; ei < rpc.Sam.Count; ei++)
- {
- Samr.SamrSamEntry entry = rpc.Sam.Entries[ei];
- Sid[] mems = GetGroupMemberSids0(handle, domainHandle, domsid
- , entry.Idx, flags);
- Sid groupSid = new Sid(domsid, entry.Idx);
- groupSid.Type = SidTypeAlias;
- groupSid.DomainName = domsid.GetDomainName();
- groupSid.AcctName = (new UnicodeString(entry.Name, false)).ToString();
- for (int mi = 0; mi < mems.Length; mi++)
- {
- List<object> groups = (List<object>)map.Get(mems[mi]);
- if (groups == null)
- {
- groups = new List<object>();
- map.Put(mems[mi], groups);
- }
- if (!groups.Contains(groupSid))
- {
- groups.Add(groupSid);
- }
- }
- }
- return map;
- }
- finally
- {
- if (handle != null)
- {
- if (policyHandle != null)
- {
- if (domainHandle != null)
- {
- domainHandle.Close();
- }
- policyHandle.Close();
- }
- handle.Close();
- }
- }
- }
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SecurityDescriptor.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SecurityDescriptor.cs
deleted file mode 100644
index 8a424a019..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SecurityDescriptor.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System.IO;
-
-namespace SharpCifs.Smb
-{
- public class SecurityDescriptor
- {
- public int Type;
-
- public Ace[] Aces;
-
- public SecurityDescriptor()
- {
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- public SecurityDescriptor(byte[] buffer, int bufferIndex, int len)
- {
- Decode(buffer, bufferIndex, len);
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- public virtual int Decode(byte[] buffer, int bufferIndex, int len)
- {
- int start = bufferIndex;
- bufferIndex++;
- // revision
- bufferIndex++;
- Type = ServerMessageBlock.ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- ServerMessageBlock.ReadInt4(buffer, bufferIndex);
- // offset to owner sid
- bufferIndex += 4;
- ServerMessageBlock.ReadInt4(buffer, bufferIndex);
- // offset to group sid
- bufferIndex += 4;
- ServerMessageBlock.ReadInt4(buffer, bufferIndex);
- // offset to sacl
- bufferIndex += 4;
- int daclOffset = ServerMessageBlock.ReadInt4(buffer, bufferIndex);
- bufferIndex = start + daclOffset;
- bufferIndex++;
- // revision
- bufferIndex++;
- int size = ServerMessageBlock.ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- int numAces = ServerMessageBlock.ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- if (numAces > 4096)
- {
- throw new IOException("Invalid SecurityDescriptor");
- }
- if (daclOffset != 0)
- {
- Aces = new Ace[numAces];
- for (int i = 0; i < numAces; i++)
- {
- Aces[i] = new Ace();
- bufferIndex += Aces[i].Decode(buffer, bufferIndex);
- }
- }
- else
- {
- Aces = null;
- }
- return bufferIndex - start;
- }
-
- public override string ToString()
- {
- string ret = "SecurityDescriptor:\n";
- if (Aces != null)
- {
- for (int ai = 0; ai < Aces.Length; ai++)
- {
- ret += Aces[ai] + "\n";
- }
- }
- else
- {
- ret += "NULL";
- }
- return ret;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/ServerMessageBlock.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/ServerMessageBlock.cs
deleted file mode 100644
index cb38c89fa..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/ServerMessageBlock.cs
+++ /dev/null
@@ -1,692 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-using SharpCifs.Util.Transport;
-
-namespace SharpCifs.Smb
-{
- public abstract class ServerMessageBlock: Response
- {
- internal static LogStream Log = LogStream.GetInstance();
-
- internal static long Ticks1601 = new DateTime(1601, 1, 1).Ticks;
-
- internal static readonly byte[] Header = { 0xFF, (byte)('S'), (byte)('M'),
- (byte)('B'), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
- internal static void WriteInt2(long val, byte[] dst, int dstIndex)
- {
- dst[dstIndex] = unchecked((byte)(val));
- dst[++dstIndex] = unchecked((byte)(val >> 8));
- }
-
- internal static void WriteInt4(long val, byte[] dst, int dstIndex)
- {
- dst[dstIndex] = unchecked((byte)(val));
- dst[++dstIndex] = unchecked((byte)(val >>= 8));
- dst[++dstIndex] = unchecked((byte)(val >>= 8));
- dst[++dstIndex] = unchecked((byte)(val >> 8));
- }
-
- internal static int ReadInt2(byte[] src, int srcIndex)
- {
- return unchecked(src[srcIndex] & 0xFF) + ((src[srcIndex + 1] & 0xFF) << 8);
- }
-
- internal static int ReadInt4(byte[] src, int srcIndex)
- {
- return unchecked(src[srcIndex] & 0xFF) + ((src[srcIndex + 1] & 0xFF) << 8) + ((src[srcIndex + 2]
- & 0xFF) << 16) + ((src[srcIndex + 3] & 0xFF) << 24);
- }
-
- internal static long ReadInt8(byte[] src, int srcIndex)
- {
- return unchecked(ReadInt4(src, srcIndex) & unchecked(0xFFFFFFFFL)) + unchecked((long)(ReadInt4
- (src, srcIndex + 4)) << 32);
- }
-
- internal static void WriteInt8(long val, byte[] dst, int dstIndex)
- {
- dst[dstIndex] = unchecked((byte)(val));
- dst[++dstIndex] = unchecked((byte)(val >>= 8));
- dst[++dstIndex] = unchecked((byte)(val >>= 8));
- dst[++dstIndex] = unchecked((byte)(val >>= 8));
- dst[++dstIndex] = unchecked((byte)(val >>= 8));
- dst[++dstIndex] = unchecked((byte)(val >>= 8));
- dst[++dstIndex] = unchecked((byte)(val >>= 8));
- dst[++dstIndex] = unchecked((byte)(val >> 8));
- }
-
- internal static long ReadTime(byte[] src, int srcIndex)
- {
- int low = ReadInt4(src, srcIndex);
- int hi = ReadInt4(src, srcIndex + 4);
- long t = ((long)hi << (int)32L) | (low & unchecked((long)(0xFFFFFFFFL)));
- t = (t / 10000L - SmbConstants.MillisecondsBetween1970And1601);
- return t;
- }
-
- internal static void WriteTime(long t, byte[] dst, int dstIndex)
- {
- if (t != 0L)
- {
- t = (t + SmbConstants.MillisecondsBetween1970And1601) * 10000L;
- }
- WriteInt8(t, dst, dstIndex);
- }
-
- internal static long ReadUTime(byte[] buffer, int bufferIndex)
- {
- return ReadInt4(buffer, bufferIndex) * 1000L;
- }
-
- internal static void WriteUTime(long t, byte[] dst, int dstIndex)
- {
- if (t == 0L || t == unchecked((long)(0xFFFFFFFFFFFFFFFFL)))
- {
- WriteInt4(unchecked((int)(0xFFFFFFFF)), dst, dstIndex);
- return;
- }
- // t isn't in DST either
- WriteInt4((int)(t / 1000L), dst, dstIndex);
- }
-
- internal const byte SmbComCreateDirectory = 0x00;
-
- internal const byte SmbComDeleteDirectory = 0x01;
-
- internal const byte SmbComClose = 0x04;
-
- internal const byte SmbComDelete = 0x06;
-
- internal const byte SmbComRename = 0x07;
-
- internal const byte SmbComQueryInformation = 0x08;
-
- internal const byte SmbComWrite = 0x0B;
-
- internal const byte SmbComCheckDirectory = 0x10;
-
- internal const byte SmbComTransaction = 0x25;
-
- internal const byte SmbComTransactionSecondary = 0x26;
-
- internal const byte SmbComMove = 0x2A;
-
- internal const byte SmbComEcho = 0x2B;
-
- internal const byte SmbComOpenAndx = 0x2D;
-
- internal const byte SmbComReadAndx = 0x2E;
-
- internal const byte SmbComWriteAndx = 0x2F;
-
- internal const byte SmbComTransaction2 = 0x32;
-
- internal const byte SmbComFindClose2 = 0x34;
-
- internal const byte SmbComTreeDisconnect = 0x71;
-
- internal const byte SmbComNegotiate = 0x72;
-
- internal const byte SmbComSessionSetupAndx = 0x73;
-
- internal const byte SmbComLogoffAndx = 0x74;
-
- internal const byte SmbComTreeConnectAndx = 0x75;
-
- internal const byte SmbComNtTransact = 0xA0;
-
- internal const byte SmbComNtTransactSecondary = 0xA1;
-
- internal const byte SmbComNtCreateAndx = 0xA2;
-
- internal byte Command;
-
- internal byte Flags;
-
- internal int HeaderStart;
-
- internal int Length;
-
- internal int BatchLevel;
-
- internal int ErrorCode;
-
- internal int Flags2;
-
- internal int Tid;
-
- internal int Pid;
-
- internal int Uid;
-
- internal int Mid;
-
- internal int WordCount;
-
- internal int ByteCount;
-
- internal bool UseUnicode;
-
- internal bool Received;
-
- internal bool ExtendedSecurity;
-
- internal long ResponseTimeout = 1;
-
- internal int SignSeq;
-
- internal bool VerifyFailed;
-
- internal NtlmPasswordAuthentication Auth = null;
-
- internal string Path;
-
- internal SigningDigest Digest;
-
- internal ServerMessageBlock Response;
-
- public ServerMessageBlock()
- {
- Flags = unchecked((byte)(SmbConstants.FlagsPathNamesCaseless | SmbConstants.FlagsPathNamesCanonicalized
- ));
- Pid = SmbConstants.Pid;
- BatchLevel = 0;
- }
-
- internal virtual void Reset()
- {
- Flags = unchecked((byte)(SmbConstants.FlagsPathNamesCaseless | SmbConstants.FlagsPathNamesCanonicalized
- ));
- Flags2 = 0;
- ErrorCode = 0;
- Received = false;
- Digest = null;
- }
-
- internal virtual int WriteString(string str, byte[] dst, int dstIndex)
- {
- return WriteString(str, dst, dstIndex, UseUnicode);
- }
-
- internal virtual int WriteString(string str, byte[] dst, int dstIndex, bool useUnicode
- )
- {
- int start = dstIndex;
- try
- {
- if (useUnicode)
- {
- // Unicode requires word alignment
- if (((dstIndex - HeaderStart) % 2) != 0)
- {
- dst[dstIndex++] = (byte)('\0');
- }
- Array.Copy(Runtime.GetBytesForString(str, SmbConstants.UniEncoding), 0, dst, dstIndex
- , str.Length * 2);
- dstIndex += str.Length * 2;
- dst[dstIndex++] = (byte)('\0');
- dst[dstIndex++] = (byte)('\0');
- }
- else
- {
- byte[] b = Runtime.GetBytesForString(str, SmbConstants.OemEncoding);
- Array.Copy(b, 0, dst, dstIndex, b.Length);
- dstIndex += b.Length;
- dst[dstIndex++] = (byte)('\0');
- }
- }
- catch (UnsupportedEncodingException uee)
- {
- if (Log.Level > 1)
- {
- Runtime.PrintStackTrace(uee, Log);
- }
- }
- return dstIndex - start;
- }
-
- internal virtual string ReadString(byte[] src, int srcIndex)
- {
- return ReadString(src, srcIndex, 256, UseUnicode);
- }
-
- internal virtual string ReadString(byte[] src, int srcIndex, int maxLen, bool useUnicode
- )
- {
- int len = 0;
- string str = null;
- try
- {
- if (useUnicode)
- {
- // Unicode requires word alignment
- if (((srcIndex - HeaderStart) % 2) != 0)
- {
- srcIndex++;
- }
- while (src[srcIndex + len] != 0x00 || src[srcIndex
- + len + 1] != 0x00)
- {
- len += 2;
- if (len > maxLen)
- {
- if (Log.Level > 0)
- {
- Hexdump.ToHexdump(Console.Error, src, srcIndex, maxLen < 128 ? maxLen + 8 :
- 128);
- }
- throw new RuntimeException("zero termination not found");
- }
- }
- str = Runtime.GetStringForBytes(src, srcIndex, len, SmbConstants.UniEncoding);
- }
- else
- {
- while (src[srcIndex + len] != 0x00)
- {
- len++;
- if (len > maxLen)
- {
- if (Log.Level > 0)
- {
- Hexdump.ToHexdump(Console.Error, src, srcIndex, maxLen < 128 ? maxLen + 8 :
- 128);
- }
- throw new RuntimeException("zero termination not found");
- }
- }
- str = Runtime.GetStringForBytes(src, srcIndex, len, SmbConstants.OemEncoding);
- }
- }
- catch (UnsupportedEncodingException uee)
- {
- if (Log.Level > 1)
- {
- Runtime.PrintStackTrace(uee, Log);
- }
- }
- return str;
- }
-
- internal virtual string ReadString(byte[] src, int srcIndex, int srcEnd, int maxLen
- , bool useUnicode)
- {
- int len = 0;
- string str = null;
- try
- {
- if (useUnicode)
- {
- // Unicode requires word alignment
- if (((srcIndex - HeaderStart) % 2) != 0)
- {
- srcIndex++;
- }
- for (len = 0; (srcIndex + len + 1) < srcEnd; len += 2)
- {
- if (src[srcIndex + len] == 0x00 && src[srcIndex
- + len + 1] == 0x00)
- {
- break;
- }
- if (len > maxLen)
- {
- if (Log.Level > 0)
- {
- Hexdump.ToHexdump(Console.Error, src, srcIndex, maxLen < 128 ? maxLen + 8 :
- 128);
- }
- throw new RuntimeException("zero termination not found");
- }
- }
- str = Runtime.GetStringForBytes(src, srcIndex, len, SmbConstants.UniEncoding);
- }
- else
- {
- for (len = 0; srcIndex < srcEnd; len++)
- {
- if (src[srcIndex + len] == 0x00)
- {
- break;
- }
- if (len > maxLen)
- {
- if (Log.Level > 0)
- {
- Hexdump.ToHexdump(Console.Error, src, srcIndex, maxLen < 128 ? maxLen + 8 :
- 128);
- }
- throw new RuntimeException("zero termination not found");
- }
- }
- str = Runtime.GetStringForBytes(src, srcIndex, len, SmbConstants.OemEncoding);
- }
- }
- catch (UnsupportedEncodingException uee)
- {
- if (Log.Level > 1)
- {
- Runtime.PrintStackTrace(uee, Log);
- }
- }
- return str;
- }
-
- internal virtual int StringWireLength(string str, int offset)
- {
- int len = str.Length + 1;
- if (UseUnicode)
- {
- len = str.Length * 2 + 2;
- len = (offset % 2) != 0 ? len + 1 : len;
- }
- return len;
- }
-
- internal virtual int ReadStringLength(byte[] src, int srcIndex, int max)
- {
- int len = 0;
- while (src[srcIndex + len] != 0x00)
- {
- if (len++ > max)
- {
- throw new RuntimeException("zero termination not found: " + this);
- }
- }
- return len;
- }
-
- internal virtual int Encode(byte[] dst, int dstIndex)
- {
- int start = HeaderStart = dstIndex;
- dstIndex += WriteHeaderWireFormat(dst, dstIndex);
- WordCount = WriteParameterWordsWireFormat(dst, dstIndex + 1);
- dst[dstIndex++] = unchecked((byte)((WordCount / 2) & 0xFF));
- dstIndex += WordCount;
- WordCount /= 2;
- ByteCount = WriteBytesWireFormat(dst, dstIndex + 2);
- dst[dstIndex++] = unchecked((byte)(ByteCount & 0xFF));
- dst[dstIndex++] = unchecked((byte)((ByteCount >> 8) & 0xFF));
- dstIndex += ByteCount;
- Length = dstIndex - start;
- if (Digest != null)
- {
- Digest.Sign(dst, HeaderStart, Length, this, Response);
- }
- return Length;
- }
-
- internal virtual int Decode(byte[] buffer, int bufferIndex)
- {
- int start = HeaderStart = bufferIndex;
- bufferIndex += ReadHeaderWireFormat(buffer, bufferIndex);
- WordCount = buffer[bufferIndex++];
- if (WordCount != 0)
- {
- int n;
- if ((n = ReadParameterWordsWireFormat(buffer, bufferIndex)) != WordCount * 2)
- {
- if (Log.Level >= 5)
- {
- Log.WriteLine("wordCount * 2=" + (WordCount * 2) + " but readParameterWordsWireFormat returned "
- + n);
- }
- }
- bufferIndex += WordCount * 2;
- }
- ByteCount = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- if (ByteCount != 0)
- {
- int n;
- if ((n = ReadBytesWireFormat(buffer, bufferIndex)) != ByteCount)
- {
- if (Log.Level >= 5)
- {
- Log.WriteLine("byteCount=" + ByteCount + " but readBytesWireFormat returned " + n
- );
- }
- }
- // Don't think we can rely on n being correct here. Must use byteCount.
- // Last paragraph of section 3.13.3 eludes to this.
- bufferIndex += ByteCount;
- }
- Length = bufferIndex - start;
- return Length;
- }
-
- internal virtual int WriteHeaderWireFormat(byte[] dst, int dstIndex)
- {
- Array.Copy(Header, 0, dst, dstIndex, Header.Length);
- dst[dstIndex + SmbConstants.CmdOffset] = Command;
- dst[dstIndex + SmbConstants.FlagsOffset] = Flags;
- WriteInt2(Flags2, dst, dstIndex + SmbConstants.FlagsOffset + 1);
- dstIndex += SmbConstants.TidOffset;
- WriteInt2(Tid, dst, dstIndex);
- WriteInt2(Pid, dst, dstIndex + 2);
- WriteInt2(Uid, dst, dstIndex + 4);
- WriteInt2(Mid, dst, dstIndex + 6);
- return SmbConstants.HeaderLength;
- }
-
- internal virtual int ReadHeaderWireFormat(byte[] buffer, int bufferIndex)
- {
- Command = buffer[bufferIndex + SmbConstants.CmdOffset];
- ErrorCode = ReadInt4(buffer, bufferIndex + SmbConstants.ErrorCodeOffset);
- Flags = buffer[bufferIndex + SmbConstants.FlagsOffset];
- Flags2 = ReadInt2(buffer, bufferIndex + SmbConstants.FlagsOffset + 1);
- Tid = ReadInt2(buffer, bufferIndex + SmbConstants.TidOffset);
- Pid = ReadInt2(buffer, bufferIndex + SmbConstants.TidOffset + 2);
- Uid = ReadInt2(buffer, bufferIndex + SmbConstants.TidOffset + 4);
- Mid = ReadInt2(buffer, bufferIndex + SmbConstants.TidOffset + 6);
- return SmbConstants.HeaderLength;
- }
-
- internal virtual bool IsResponse()
- {
- return (Flags & SmbConstants.FlagsResponse) == SmbConstants.FlagsResponse;
- }
-
- internal abstract int WriteParameterWordsWireFormat(byte[] dst, int dstIndex);
-
- internal abstract int WriteBytesWireFormat(byte[] dst, int dstIndex);
-
- internal abstract int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- );
-
- internal abstract int ReadBytesWireFormat(byte[] buffer, int bufferIndex);
-
- public override int GetHashCode()
- {
- return Mid;
- }
-
- public override bool Equals(object obj)
- {
- return obj is ServerMessageBlock && ((ServerMessageBlock)obj)
- .Mid == Mid;
- }
-
- public override string ToString()
- {
- string c;
- switch (Command)
- {
- case SmbComNegotiate:
- {
- c = "SMB_COM_NEGOTIATE";
- break;
- }
-
- case SmbComSessionSetupAndx:
- {
- c = "SMB_COM_SESSION_SETUP_ANDX";
- break;
- }
-
- case SmbComTreeConnectAndx:
- {
- c = "SMB_COM_TREE_CONNECT_ANDX";
- break;
- }
-
- case SmbComQueryInformation:
- {
- c = "SMB_COM_QUERY_INFORMATION";
- break;
- }
-
- case SmbComCheckDirectory:
- {
- c = "SMB_COM_CHECK_DIRECTORY";
- break;
- }
-
- case SmbComTransaction:
- {
- c = "SMB_COM_TRANSACTION";
- break;
- }
-
- case SmbComTransaction2:
- {
- c = "SMB_COM_TRANSACTION2";
- break;
- }
-
- case SmbComTransactionSecondary:
- {
- c = "SMB_COM_TRANSACTION_SECONDARY";
- break;
- }
-
- case SmbComFindClose2:
- {
- c = "SMB_COM_FIND_CLOSE2";
- break;
- }
-
- case SmbComTreeDisconnect:
- {
- c = "SMB_COM_TREE_DISCONNECT";
- break;
- }
-
- case SmbComLogoffAndx:
- {
- c = "SMB_COM_LOGOFF_ANDX";
- break;
- }
-
- case SmbComEcho:
- {
- c = "SMB_COM_ECHO";
- break;
- }
-
- case SmbComMove:
- {
- c = "SMB_COM_MOVE";
- break;
- }
-
- case SmbComRename:
- {
- c = "SMB_COM_RENAME";
- break;
- }
-
- case SmbComDelete:
- {
- c = "SMB_COM_DELETE";
- break;
- }
-
- case SmbComDeleteDirectory:
- {
- c = "SMB_COM_DELETE_DIRECTORY";
- break;
- }
-
- case SmbComNtCreateAndx:
- {
- c = "SMB_COM_NT_CREATE_ANDX";
- break;
- }
-
- case SmbComOpenAndx:
- {
- c = "SMB_COM_OPEN_ANDX";
- break;
- }
-
- case SmbComReadAndx:
- {
- c = "SMB_COM_READ_ANDX";
- break;
- }
-
- case SmbComClose:
- {
- c = "SMB_COM_CLOSE";
- break;
- }
-
- case SmbComWriteAndx:
- {
- c = "SMB_COM_WRITE_ANDX";
- break;
- }
-
- case SmbComCreateDirectory:
- {
- c = "SMB_COM_CREATE_DIRECTORY";
- break;
- }
-
- case SmbComNtTransact:
- {
- c = "SMB_COM_NT_TRANSACT";
- break;
- }
-
- case SmbComNtTransactSecondary:
- {
- c = "SMB_COM_NT_TRANSACT_SECONDARY";
- break;
- }
-
- default:
- {
- c = "UNKNOWN";
- break;
- }
- }
- string str = ErrorCode == 0 ? "0" : SmbException.GetMessageByCode(ErrorCode);
- return "command=" + c + ",received=" + Received + ",errorCode=" + str
- + ",flags=0x" + Hexdump.ToHexString(Flags & 0xFF, 4) + ",flags2=0x"
- + Hexdump.ToHexString(Flags2, 4) + ",signSeq=" + SignSeq + ",tid=" + Tid + ",pid="
- + Pid + ",uid=" + Uid + ",mid=" + Mid + ",wordCount=" + WordCount + ",byteCount="
- + ByteCount;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SigningDigest.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SigningDigest.cs
deleted file mode 100644
index 9f57e887b..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SigningDigest.cs
+++ /dev/null
@@ -1,257 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- /// <summary>To filter 0 len updates and for debugging</summary>
- public class SigningDigest
- {
- internal static LogStream Log = LogStream.GetInstance();
-
- private MessageDigest _digest;
-
- private byte[] _macSigningKey;
-
- private bool _bypass;
-
- private int _updates;
-
- private int _signSequence;
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public SigningDigest(byte[] macSigningKey, bool bypass)
- {
- try
- {
- _digest = MessageDigest.GetInstance("MD5");
- }
- catch (NoSuchAlgorithmException ex)
- {
- if (Log.Level > 0)
- {
- Runtime.PrintStackTrace(ex, Log);
- }
- throw new SmbException("MD5", ex);
- }
- this._macSigningKey = macSigningKey;
- this._bypass = bypass;
- _updates = 0;
- _signSequence = 0;
- if (Log.Level >= 5)
- {
- Log.WriteLine("macSigningKey:");
- Hexdump.ToHexdump(Log, macSigningKey, 0, macSigningKey.Length);
- }
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public SigningDigest(SmbTransport transport, NtlmPasswordAuthentication auth)
- {
- try
- {
- _digest = MessageDigest.GetInstance("MD5");
- }
- catch (NoSuchAlgorithmException ex)
- {
- if (Log.Level > 0)
- {
- Runtime.PrintStackTrace(ex, Log);
- }
- throw new SmbException("MD5", ex);
- }
- try
- {
- switch (SmbConstants.LmCompatibility)
- {
- case 0:
- case 1:
- case 2:
- {
- _macSigningKey = new byte[40];
- auth.GetUserSessionKey(transport.Server.EncryptionKey, _macSigningKey, 0);
- Array.Copy(auth.GetUnicodeHash(transport.Server.EncryptionKey), 0, _macSigningKey
- , 16, 24);
- break;
- }
-
- case 3:
- case 4:
- case 5:
- {
- _macSigningKey = new byte[16];
- auth.GetUserSessionKey(transport.Server.EncryptionKey, _macSigningKey, 0);
- break;
- }
-
- default:
- {
- _macSigningKey = new byte[40];
- auth.GetUserSessionKey(transport.Server.EncryptionKey, _macSigningKey, 0);
- Array.Copy(auth.GetUnicodeHash(transport.Server.EncryptionKey), 0, _macSigningKey
- , 16, 24);
- break;
- }
- }
- }
- catch (Exception ex)
- {
- throw new SmbException(string.Empty, ex);
- }
- if (Log.Level >= 5)
- {
- Log.WriteLine("LM_COMPATIBILITY=" + SmbConstants.LmCompatibility);
- Hexdump.ToHexdump(Log, _macSigningKey, 0, _macSigningKey.Length);
- }
- }
-
- public virtual void Update(byte[] input, int offset, int len)
- {
- if (Log.Level >= 5)
- {
- Log.WriteLine("update: " + _updates + " " + offset + ":" + len);
- Hexdump.ToHexdump(Log, input, offset, Math.Min(len, 256));
- Log.Flush();
- }
- if (len == 0)
- {
- return;
- }
- _digest.Update(input, offset, len);
- _updates++;
- }
-
- public virtual byte[] Digest()
- {
- byte[] b;
- b = _digest.Digest();
- if (Log.Level >= 5)
- {
- Log.WriteLine("digest: ");
- Hexdump.ToHexdump(Log, b, 0, b.Length);
- Log.Flush();
- }
- _updates = 0;
- return b;
- }
-
- /// <summary>Performs MAC signing of the SMB.</summary>
- /// <remarks>
- /// Performs MAC signing of the SMB. This is done as follows.
- /// The signature field of the SMB is overwritted with the sequence number;
- /// The MD5 digest of the MAC signing key + the entire SMB is taken;
- /// The first 8 bytes of this are placed in the signature field.
- /// </remarks>
- /// <param name="data">The data.</param>
- /// <param name="offset">The starting offset at which the SMB header begins.</param>
- /// <param name="length">The length of the SMB data starting at offset.</param>
- internal virtual void Sign(byte[] data, int offset, int length, ServerMessageBlock
- request, ServerMessageBlock response)
- {
- request.SignSeq = _signSequence;
- if (response != null)
- {
- response.SignSeq = _signSequence + 1;
- response.VerifyFailed = false;
- }
- try
- {
- Update(_macSigningKey, 0, _macSigningKey.Length);
- int index = offset + SmbConstants.SignatureOffset;
- for (int i = 0; i < 8; i++)
- {
- data[index + i] = 0;
- }
- ServerMessageBlock.WriteInt4(_signSequence, data, index);
- Update(data, offset, length);
- Array.Copy(Digest(), 0, data, index, 8);
- if (_bypass)
- {
- _bypass = false;
- Array.Copy(Runtime.GetBytesForString("BSRSPYL "), 0, data, index,
- 8);
- }
- }
- catch (Exception ex)
- {
- if (Log.Level > 0)
- {
- Runtime.PrintStackTrace(ex, Log);
- }
- }
- finally
- {
- _signSequence += 2;
- }
- }
-
- /// <summary>Performs MAC signature verification.</summary>
- /// <remarks>
- /// Performs MAC signature verification. This calculates the signature
- /// of the SMB and compares it to the signature field on the SMB itself.
- /// </remarks>
- /// <param name="data">The data.</param>
- /// <param name="offset">The starting offset at which the SMB header begins.</param>
- /// <param name="length">The length of the SMB data starting at offset.</param>
- internal virtual bool Verify(byte[] data, int offset, ServerMessageBlock response
- )
- {
- Update(_macSigningKey, 0, _macSigningKey.Length);
- int index = offset;
- Update(data, index, SmbConstants.SignatureOffset);
- index += SmbConstants.SignatureOffset;
- byte[] sequence = new byte[8];
- ServerMessageBlock.WriteInt4(response.SignSeq, sequence, 0);
- Update(sequence, 0, sequence.Length);
- index += 8;
- if (response.Command == ServerMessageBlock.SmbComReadAndx)
- {
- SmbComReadAndXResponse raxr = (SmbComReadAndXResponse)response;
- int length = response.Length - raxr.DataLength;
- Update(data, index, length - SmbConstants.SignatureOffset - 8);
- Update(raxr.B, raxr.Off, raxr.DataLength);
- }
- else
- {
- Update(data, index, response.Length - SmbConstants.SignatureOffset - 8);
- }
- byte[] signature = Digest();
- for (int i = 0; i < 8; i++)
- {
- if (signature[i] != data[offset + SmbConstants.SignatureOffset + i])
- {
- if (Log.Level >= 2)
- {
- Log.WriteLine("signature verification failure");
- Hexdump.ToHexdump(Log, signature, 0, 8);
- Hexdump.ToHexdump(Log, data, offset + SmbConstants.SignatureOffset, 8);
- }
- return response.VerifyFailed = true;
- }
- }
- return response.VerifyFailed = false;
- }
-
- public override string ToString()
- {
- return "LM_COMPATIBILITY=" + SmbConstants.LmCompatibility + " MacSigningKey=" + Hexdump.ToHexString
- (_macSigningKey, 0, _macSigningKey.Length);
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbAuthException.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbAuthException.cs
deleted file mode 100644
index defaea71b..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbAuthException.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- /// <summary>
- /// The <code>SmbAuthException</code> encapsulates the variety of
- /// authentication related error codes returned by an SMB server.
- /// </summary>
- /// <remarks>
- /// The <code>SmbAuthException</code> encapsulates the variety of
- /// authentication related error codes returned by an SMB server.
- /// <p>
- /// See <a href="../../../authhandler.html">jCIFS Exceptions and NtlmAuthenticator</a> for more information about <code>SmbAuthException</code>.
- /// </remarks>
-
- public class SmbAuthException : SmbException
- {
- internal SmbAuthException(int errcode) : base(errcode, null)
- {
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComBlankResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComBlankResponse.cs
deleted file mode 100644
index 2295de5b9..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComBlankResponse.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class SmbComBlankResponse : ServerMessageBlock
- {
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComBlankResponse[" + base.ToString() + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComClose.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComClose.cs
deleted file mode 100644
index 4a160f518..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComClose.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class SmbComClose : ServerMessageBlock
- {
- private int _fid;
-
- private long _lastWriteTime;
-
- internal SmbComClose(int fid, long lastWriteTime)
- {
- this._fid = fid;
- this._lastWriteTime = lastWriteTime;
- Command = SmbComClose;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- WriteInt2(_fid, dst, dstIndex);
- dstIndex += 2;
- WriteUTime(_lastWriteTime, dst, dstIndex);
- return 6;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComClose[" + base.ToString() + ",fid=" + _fid + ",lastWriteTime="
- + _lastWriteTime + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComCreateDirectory.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComCreateDirectory.cs
deleted file mode 100644
index 7549db01a..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComCreateDirectory.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class SmbComCreateDirectory : ServerMessageBlock
- {
- internal SmbComCreateDirectory(string directoryName)
- {
- Path = directoryName;
- Command = SmbComCreateDirectory;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- dst[dstIndex++] = unchecked(unchecked(0x04));
- dstIndex += WriteString(Path, dst, dstIndex);
- return dstIndex - start;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComCreateDirectory[" + base.ToString() + ",directoryName="
- + Path + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComDelete.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComDelete.cs
deleted file mode 100644
index d055d2446..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComDelete.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-
-namespace SharpCifs.Smb
-{
- internal class SmbComDelete : ServerMessageBlock
- {
- private int _searchAttributes;
-
- internal SmbComDelete(string fileName)
- {
- Path = fileName;
- Command = SmbComDelete;
- _searchAttributes = SmbConstants.AttrHidden | SmbConstants.AttrHidden | SmbConstants.AttrSystem;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- WriteInt2(_searchAttributes, dst, dstIndex);
- return 2;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- dst[dstIndex++] = unchecked(unchecked(0x04));
- dstIndex += WriteString(Path, dst, dstIndex);
- return dstIndex - start;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComDelete[" + base.ToString() + ",searchAttributes=0x" + Hexdump
- .ToHexString(_searchAttributes, 4) + ",fileName=" + Path + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComDeleteDirectory.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComDeleteDirectory.cs
deleted file mode 100644
index 240139a17..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComDeleteDirectory.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class SmbComDeleteDirectory : ServerMessageBlock
- {
- internal SmbComDeleteDirectory(string directoryName)
- {
- Path = directoryName;
- Command = SmbComDeleteDirectory;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- dst[dstIndex++] = unchecked(unchecked(0x04));
- dstIndex += WriteString(Path, dst, dstIndex);
- return dstIndex - start;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComDeleteDirectory[" + base.ToString() + ",directoryName="
- + Path + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComFindClose2.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComFindClose2.cs
deleted file mode 100644
index 9b7c0c765..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComFindClose2.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class SmbComFindClose2 : ServerMessageBlock
- {
- private int _sid;
-
- internal SmbComFindClose2(int sid)
- {
- this._sid = sid;
- Command = SmbComFindClose2;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- WriteInt2(_sid, dst, dstIndex);
- return 2;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComFindClose2[" + base.ToString() + ",sid=" + _sid + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComLogoffAndX.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComLogoffAndX.cs
deleted file mode 100644
index 8f88ccd57..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComLogoffAndX.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class SmbComLogoffAndX : AndXServerMessageBlock
- {
- internal SmbComLogoffAndX(ServerMessageBlock andx) : base(andx)
- {
- Command = SmbComLogoffAndx;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComLogoffAndX[" + base.ToString() + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNTCreateAndX.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNTCreateAndX.cs
deleted file mode 100644
index 26b5ba63a..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNTCreateAndX.cs
+++ /dev/null
@@ -1,193 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-
-namespace SharpCifs.Smb
-{
- internal class SmbComNtCreateAndX : AndXServerMessageBlock
- {
- internal const int FileSupersede = unchecked(0x0);
-
- internal const int FileOpen = unchecked(0x1);
-
- internal const int FileCreate = unchecked(0x2);
-
- internal const int FileOpenIf = unchecked(0x3);
-
- internal const int FileOverwrite = unchecked(0x4);
-
- internal const int FileOverwriteIf = unchecked(0x5);
-
- internal const int FileWriteThrough = unchecked(0x00000002);
-
- internal const int FileSequentialOnly = unchecked(0x00000004);
-
- internal const int FileSynchronousIoAlert = unchecked(0x00000010);
-
- internal const int FileSynchronousIoNonalert = unchecked(0x00000020);
-
- internal const int SecurityContextTracking = unchecked(0x01);
-
- internal const int SecurityEffectiveOnly = unchecked(0x02);
-
- private int _rootDirectoryFid;
-
- private int _extFileAttributes;
-
- private int _shareAccess;
-
- private int _createDisposition;
-
- private int _createOptions;
-
- private int _impersonationLevel;
-
- private long _allocationSize;
-
- private byte _securityFlags;
-
- private int _namelenIndex;
-
- internal int Flags0;
-
- internal int DesiredAccess;
-
- internal SmbComNtCreateAndX(string name, int flags, int access, int shareAccess,
- int extFileAttributes, int createOptions, ServerMessageBlock andx) : base(andx)
- {
- // share access specified in SmbFile
- // create disposition
- // create options
- // security flags
- Path = name;
- Command = SmbComNtCreateAndx;
- DesiredAccess = access;
- DesiredAccess |= SmbConstants.FileReadData | SmbConstants.FileReadEa | SmbConstants.FileReadAttributes;
- // extFileAttributes
- this._extFileAttributes = extFileAttributes;
- // shareAccess
- this._shareAccess = shareAccess;
- // createDisposition
- if ((flags & SmbFile.OTrunc) == SmbFile.OTrunc)
- {
- // truncate the file
- if ((flags & SmbFile.OCreat) == SmbFile.OCreat)
- {
- // create it if necessary
- _createDisposition = FileOverwriteIf;
- }
- else
- {
- _createDisposition = FileOverwrite;
- }
- }
- else
- {
- // don't truncate the file
- if ((flags & SmbFile.OCreat) == SmbFile.OCreat)
- {
- // create it if necessary
- if ((flags & SmbFile.OExcl) == SmbFile.OExcl)
- {
- // fail if already exists
- _createDisposition = FileCreate;
- }
- else
- {
- _createDisposition = FileOpenIf;
- }
- }
- else
- {
- _createDisposition = FileOpen;
- }
- }
- if ((createOptions & unchecked(0x0001)) == 0)
- {
- this._createOptions = createOptions | unchecked(0x0040);
- }
- else
- {
- this._createOptions = createOptions;
- }
- _impersonationLevel = unchecked(0x02);
- // As seen on NT :~)
- _securityFlags = unchecked(unchecked(0x03));
- }
-
- // SECURITY_CONTEXT_TRACKING | SECURITY_EFFECTIVE_ONLY
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- // name length without counting null termination
- _namelenIndex = dstIndex;
- dstIndex += 2;
- WriteInt4(Flags0, dst, dstIndex);
- dstIndex += 4;
- WriteInt4(_rootDirectoryFid, dst, dstIndex);
- dstIndex += 4;
- WriteInt4(DesiredAccess, dst, dstIndex);
- dstIndex += 4;
- WriteInt8(_allocationSize, dst, dstIndex);
- dstIndex += 8;
- WriteInt4(_extFileAttributes, dst, dstIndex);
- dstIndex += 4;
- WriteInt4(_shareAccess, dst, dstIndex);
- dstIndex += 4;
- WriteInt4(_createDisposition, dst, dstIndex);
- dstIndex += 4;
- WriteInt4(_createOptions, dst, dstIndex);
- dstIndex += 4;
- WriteInt4(_impersonationLevel, dst, dstIndex);
- dstIndex += 4;
- dst[dstIndex++] = _securityFlags;
- return dstIndex - start;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- int n;
- n = WriteString(Path, dst, dstIndex);
- WriteInt2((UseUnicode ? Path.Length * 2 : n), dst, _namelenIndex);
- return n;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComNTCreateAndX[" + base.ToString() + ",flags=0x" + Hexdump
- .ToHexString(Flags0, 2) + ",rootDirectoryFid=" + _rootDirectoryFid + ",desiredAccess=0x"
- + Hexdump.ToHexString(DesiredAccess, 4) + ",allocationSize=" + _allocationSize +
- ",extFileAttributes=0x" + Hexdump.ToHexString(_extFileAttributes, 4) + ",shareAccess=0x"
- + Hexdump.ToHexString(_shareAccess, 4) + ",createDisposition=0x" + Hexdump.ToHexString
- (_createDisposition, 4) + ",createOptions=0x" + Hexdump.ToHexString(_createOptions
- , 8) + ",impersonationLevel=0x" + Hexdump.ToHexString(_impersonationLevel, 4) + ",securityFlags=0x"
- + Hexdump.ToHexString(_securityFlags, 2) + ",name=" + Path + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNTCreateAndXResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNTCreateAndXResponse.cs
deleted file mode 100644
index 4a007bdc5..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNTCreateAndXResponse.cs
+++ /dev/null
@@ -1,116 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class SmbComNtCreateAndXResponse : AndXServerMessageBlock
- {
- internal const int ExclusiveOplockGranted = 1;
-
- internal const int BatchOplockGranted = 2;
-
- internal const int LevelIiOplockGranted = 3;
-
- internal byte OplockLevel;
-
- internal int Fid;
-
- internal int CreateAction;
-
- internal int ExtFileAttributes;
-
- internal int FileType;
-
- internal int DeviceState;
-
- internal long CreationTime;
-
- internal long LastAccessTime;
-
- internal long LastWriteTime;
-
- internal long ChangeTime;
-
- internal long AllocationSize;
-
- internal long EndOfFile;
-
- internal bool Directory;
-
- internal bool IsExtended;
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- int start = bufferIndex;
- OplockLevel = buffer[bufferIndex++];
- Fid = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- CreateAction = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- CreationTime = ReadTime(buffer, bufferIndex);
- bufferIndex += 8;
- LastAccessTime = ReadTime(buffer, bufferIndex);
- bufferIndex += 8;
- LastWriteTime = ReadTime(buffer, bufferIndex);
- bufferIndex += 8;
- ChangeTime = ReadTime(buffer, bufferIndex);
- bufferIndex += 8;
- ExtFileAttributes = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- AllocationSize = ReadInt8(buffer, bufferIndex);
- bufferIndex += 8;
- EndOfFile = ReadInt8(buffer, bufferIndex);
- bufferIndex += 8;
- FileType = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- DeviceState = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- Directory = (buffer[bufferIndex++] & unchecked(0xFF)) > 0;
- return bufferIndex - start;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComNTCreateAndXResponse[" + base.ToString() + ",oplockLevel="
- + OplockLevel + ",fid=" + Fid + ",createAction=0x" + Hexdump.ToHexString(CreateAction
- , 4) + ",creationTime=" + Extensions.CreateDate(CreationTime) + ",lastAccessTime="
- + Extensions.CreateDate(LastAccessTime) + ",lastWriteTime=" + Extensions.CreateDate
- (LastWriteTime) + ",changeTime=" + Extensions.CreateDate(ChangeTime) + ",extFileAttributes=0x"
- + Hexdump.ToHexString(ExtFileAttributes, 4) + ",allocationSize=" + AllocationSize
- + ",endOfFile=" + EndOfFile + ",fileType=" + FileType + ",deviceState=" + DeviceState
- + ",directory=" + Directory + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNegotiate.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNegotiate.cs
deleted file mode 100644
index 499bffbd9..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNegotiate.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class SmbComNegotiate : ServerMessageBlock
- {
- private const string Dialects = "\u0002NT LM 0.12\u0000";
-
- public SmbComNegotiate()
- {
- Command = SmbComNegotiate;
- Flags2 = SmbConstants.DefaultFlags2;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- byte[] dialects;
- try
- {
- //dialects = Runtime.GetBytesForString(Dialects, "ASCII");
- dialects = Runtime.GetBytesForString(Dialects, "UTF-8");
- }
- catch (UnsupportedEncodingException)
- {
- return 0;
- }
- Array.Copy(dialects, 0, dst, dstIndex, dialects.Length);
- return dialects.Length;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComNegotiate[" + base.ToString() + ",wordCount=" + WordCount
- + ",dialects=NT LM 0.12]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNegotiateResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNegotiateResponse.cs
deleted file mode 100644
index c4cd1c129..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNegotiateResponse.cs
+++ /dev/null
@@ -1,164 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class SmbComNegotiateResponse : ServerMessageBlock
- {
- internal int DialectIndex;
-
- internal SmbTransport.ServerData Server;
-
- internal SmbComNegotiateResponse(SmbTransport.ServerData server)
- {
- this.Server = server;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- int start = bufferIndex;
- DialectIndex = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- if (DialectIndex > 10)
- {
- return bufferIndex - start;
- }
- Server.SecurityMode = buffer[bufferIndex++] & unchecked(0xFF);
- Server.Security = Server.SecurityMode & unchecked(0x01);
- Server.EncryptedPasswords = (Server.SecurityMode & unchecked(0x02)) == unchecked(
- 0x02);
- Server.SignaturesEnabled = (Server.SecurityMode & unchecked(0x04)) == unchecked(
- 0x04);
- Server.SignaturesRequired = (Server.SecurityMode & unchecked(0x08)) == unchecked(
- 0x08);
- Server.MaxMpxCount = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- Server.MaxNumberVcs = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- Server.MaxBufferSize = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- Server.MaxRawSize = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- Server.SessionKey = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- Server.Capabilities = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- Server.ServerTime = ReadTime(buffer, bufferIndex);
- bufferIndex += 8;
- Server.ServerTimeZone = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- Server.EncryptionKeyLength = buffer[bufferIndex++] & unchecked(0xFF);
- return bufferIndex - start;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- int start = bufferIndex;
- if ((Server.Capabilities & SmbConstants.CapExtendedSecurity) == 0)
- {
- Server.EncryptionKey = new byte[Server.EncryptionKeyLength];
- Array.Copy(buffer, bufferIndex, Server.EncryptionKey, 0, Server.EncryptionKeyLength
- );
- bufferIndex += Server.EncryptionKeyLength;
- if (ByteCount > Server.EncryptionKeyLength)
- {
- int len = 0;
- // TODO: we can use new string routine here
- try
- {
- if ((Flags2 & SmbConstants.Flags2Unicode) == SmbConstants.Flags2Unicode)
- {
- while (buffer[bufferIndex + len] != unchecked(unchecked(0x00)) || buffer
- [bufferIndex + len + 1] != unchecked(unchecked(0x00)))
- {
- len += 2;
- if (len > 256)
- {
- throw new RuntimeException("zero termination not found");
- }
- }
- Server.OemDomainName = Runtime.GetStringForBytes(buffer, bufferIndex, len
- , SmbConstants.UniEncoding);
- }
- else
- {
- while (buffer[bufferIndex + len] != unchecked(unchecked(0x00)))
- {
- len++;
- if (len > 256)
- {
- throw new RuntimeException("zero termination not found");
- }
- }
- Server.OemDomainName = Runtime.GetStringForBytes(buffer, bufferIndex, len
- , SmbConstants.OemEncoding);
- }
- }
- catch (UnsupportedEncodingException uee)
- {
- if (Log.Level > 1)
- {
- Runtime.PrintStackTrace(uee, Log);
- }
- }
- bufferIndex += len;
- }
- else
- {
- Server.OemDomainName = "";
- }
- }
- else
- {
- Server.Guid = new byte[16];
- Array.Copy(buffer, bufferIndex, Server.Guid, 0, 16);
- Server.OemDomainName = "";
- }
- // ignore SPNEGO token for now ...
- return bufferIndex - start;
- }
-
- public override string ToString()
- {
- return "SmbComNegotiateResponse[" + base.ToString() + ",wordCount=" +
- WordCount + ",dialectIndex=" + DialectIndex + ",securityMode=0x" + Hexdump.ToHexString
- (Server.SecurityMode, 1) + ",security=" + (Server.Security == SmbConstants.SecurityShare ? "share"
- : "user") + ",encryptedPasswords=" + Server.EncryptedPasswords + ",maxMpxCount="
- + Server.MaxMpxCount + ",maxNumberVcs=" + Server.MaxNumberVcs + ",maxBufferSize="
- + Server.MaxBufferSize + ",maxRawSize=" + Server.MaxRawSize + ",sessionKey=0x"
- + Hexdump.ToHexString(Server.SessionKey, 8) + ",capabilities=0x" + Hexdump.ToHexString
- (Server.Capabilities, 8) + ",serverTime=" + Extensions.CreateDate(Server
- .ServerTime) + ",serverTimeZone=" + Server.ServerTimeZone + ",encryptionKeyLength="
- + Server.EncryptionKeyLength + ",byteCount=" + ByteCount + ",oemDomainName=" +
- Server.OemDomainName + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNtTransaction.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNtTransaction.cs
deleted file mode 100644
index b5d2cf947..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNtTransaction.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal abstract class SmbComNtTransaction : SmbComTransaction
- {
- private const int NttPrimarySetupOffset = 69;
-
- private const int NttSecondaryParameterOffset = 51;
-
- internal const int NtTransactQuerySecurityDesc = 6;
-
- internal int Function;
-
- public SmbComNtTransaction()
- {
- // relative to headerStart
- primarySetupOffset = NttPrimarySetupOffset;
- secondaryParameterOffset = NttSecondaryParameterOffset;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- if (Command != SmbComNtTransactSecondary)
- {
- dst[dstIndex++] = MaxSetupCount;
- }
- else
- {
- dst[dstIndex++] = unchecked(unchecked(0x00));
- }
- // Reserved
- dst[dstIndex++] = unchecked(unchecked(0x00));
- // Reserved
- dst[dstIndex++] = unchecked(unchecked(0x00));
- // Reserved
- WriteInt4(TotalParameterCount, dst, dstIndex);
- dstIndex += 4;
- WriteInt4(TotalDataCount, dst, dstIndex);
- dstIndex += 4;
- if (Command != SmbComNtTransactSecondary)
- {
- WriteInt4(MaxParameterCount, dst, dstIndex);
- dstIndex += 4;
- WriteInt4(MaxDataCount, dst, dstIndex);
- dstIndex += 4;
- }
- WriteInt4(ParameterCount, dst, dstIndex);
- dstIndex += 4;
- WriteInt4((ParameterCount == 0 ? 0 : ParameterOffset), dst, dstIndex);
- dstIndex += 4;
- if (Command == SmbComNtTransactSecondary)
- {
- WriteInt4(ParameterDisplacement, dst, dstIndex);
- dstIndex += 4;
- }
- WriteInt4(DataCount, dst, dstIndex);
- dstIndex += 4;
- WriteInt4((DataCount == 0 ? 0 : DataOffset), dst, dstIndex);
- dstIndex += 4;
- if (Command == SmbComNtTransactSecondary)
- {
- WriteInt4(DataDisplacement, dst, dstIndex);
- dstIndex += 4;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- }
- else
- {
- // Reserved1
- dst[dstIndex++] = unchecked((byte)SetupCount);
- WriteInt2(Function, dst, dstIndex);
- dstIndex += 2;
- dstIndex += WriteSetupWireFormat(dst, dstIndex);
- }
- return dstIndex - start;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNtTransactionResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNtTransactionResponse.cs
deleted file mode 100644
index 88d73528a..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComNtTransactionResponse.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal abstract class SmbComNtTransactionResponse : SmbComTransactionResponse
- {
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- int start = bufferIndex;
- buffer[bufferIndex++] = unchecked(unchecked(0x00));
- // Reserved
- buffer[bufferIndex++] = unchecked(unchecked(0x00));
- // Reserved
- buffer[bufferIndex++] = unchecked(unchecked(0x00));
- // Reserved
- TotalParameterCount = ReadInt4(buffer, bufferIndex);
- if (BufDataStart == 0)
- {
- BufDataStart = TotalParameterCount;
- }
- bufferIndex += 4;
- TotalDataCount = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- ParameterCount = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- ParameterOffset = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- ParameterDisplacement = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- DataCount = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- DataOffset = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- DataDisplacement = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- SetupCount = buffer[bufferIndex] & unchecked(0xFF);
- bufferIndex += 2;
- if (SetupCount != 0)
- {
- if (Log.Level >= 3)
- {
- Log.WriteLine("setupCount is not zero: " + SetupCount);
- }
- }
- return bufferIndex - start;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComOpenAndX.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComOpenAndX.cs
deleted file mode 100644
index de11e2a6a..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComOpenAndX.cs
+++ /dev/null
@@ -1,190 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class SmbComOpenAndX : AndXServerMessageBlock
- {
- private const int FlagsReturnAdditionalInfo = 0x01;
-
- private const int FlagsRequestOplock = 0x02;
-
- private const int FlagsRequestBatchOplock = 0x04;
-
- private const int SharingCompatibility = 0x00;
-
- private const int SharingDenyReadWriteExecute = 0x10;
-
- private const int SharingDenyWrite = 0x20;
-
- private const int SharingDenyReadExecute = 0x30;
-
- private const int SharingDenyNone = 0x40;
-
- private const int DoNotCache = 0x1000;
-
- private const int WriteThrough = 0x4000;
-
- private const int OpenFnCreate = 0x10;
-
- private const int OpenFnFailIfExists = 0x00;
-
- private const int OpenFnOpen = 0x01;
-
- private const int OpenFnTrunc = 0x02;
-
- private static readonly int BatchLimit = Config.GetInt("jcifs.smb.client.OpenAndX.ReadAndX"
- , 1);
-
- internal int flags;
-
- internal int DesiredAccess;
-
- internal int SearchAttributes;
-
- internal int FileAttributes;
-
- internal int CreationTime;
-
- internal int OpenFunction;
-
- internal int AllocationSize;
-
- internal SmbComOpenAndX(string fileName, int access, int flags, ServerMessageBlock
- andx) : base(andx)
- {
- // flags (not the same as flags constructor argument)
- // Access Mode Encoding for desiredAccess
- // bit 12
- // bit 14
- // flags is NOT the same as flags member
- Path = fileName;
- Command = SmbComOpenAndx;
- DesiredAccess = access & 0x3;
- if (DesiredAccess == 0x3)
- {
- DesiredAccess = 0x2;
- }
- DesiredAccess |= SharingDenyNone;
- DesiredAccess &= ~0x1;
- // Win98 doesn't like GENERIC_READ ?! -- get Access Denied.
- // searchAttributes
- SearchAttributes = SmbConstants.AttrDirectory | SmbConstants.AttrHidden | SmbConstants.AttrSystem;
- // fileAttributes
- FileAttributes = 0;
- // openFunction
- if ((flags & SmbFile.OTrunc) == SmbFile.OTrunc)
- {
- // truncate the file
- if ((flags & SmbFile.OCreat) == SmbFile.OCreat)
- {
- // create it if necessary
- OpenFunction = OpenFnTrunc | OpenFnCreate;
- }
- else
- {
- OpenFunction = OpenFnTrunc;
- }
- }
- else
- {
- // don't truncate the file
- if ((flags & SmbFile.OCreat) == SmbFile.OCreat)
- {
- // create it if necessary
- if ((flags & SmbFile.OExcl) == SmbFile.OExcl)
- {
- // fail if already exists
- OpenFunction = OpenFnCreate | OpenFnFailIfExists;
- }
- else
- {
- OpenFunction = OpenFnCreate | OpenFnOpen;
- }
- }
- else
- {
- OpenFunction = OpenFnOpen;
- }
- }
- }
-
- internal override int GetBatchLimit(byte command)
- {
- return command == SmbComReadAndx ? BatchLimit : 0;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- WriteInt2(flags, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(DesiredAccess, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(SearchAttributes, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(FileAttributes, dst, dstIndex);
- dstIndex += 2;
- CreationTime = 0;
- WriteInt4(CreationTime, dst, dstIndex);
- dstIndex += 4;
- WriteInt2(OpenFunction, dst, dstIndex);
- dstIndex += 2;
- WriteInt4(AllocationSize, dst, dstIndex);
- dstIndex += 4;
- for (int i = 0; i < 8; i++)
- {
- dst[dstIndex++] = 0x00;
- }
- return dstIndex - start;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- if (UseUnicode)
- {
- dst[dstIndex++] = (byte)('\0');
- }
- dstIndex += WriteString(Path, dst, dstIndex);
- return dstIndex - start;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComOpenAndX[" + base.ToString() + ",flags=0x" + Hexdump.ToHexString
- (flags, 2) + ",desiredAccess=0x" + Hexdump.ToHexString(DesiredAccess, 4) + ",searchAttributes=0x"
- + Hexdump.ToHexString(SearchAttributes, 4) + ",fileAttributes=0x" + Hexdump.ToHexString
- (FileAttributes, 4) + ",creationTime=" + Extensions.CreateDate(CreationTime
- ) + ",openFunction=0x" + Hexdump.ToHexString(OpenFunction, 2) + ",allocationSize="
- + AllocationSize + ",fileName=" + Path + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComOpenAndXResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComOpenAndXResponse.cs
deleted file mode 100644
index 9c49d19a8..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComOpenAndXResponse.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class SmbComOpenAndXResponse : AndXServerMessageBlock
- {
- internal int Fid;
-
- internal int FileAttributes;
-
- internal int DataSize;
-
- internal int GrantedAccess;
-
- internal int FileType;
-
- internal int DeviceState;
-
- internal int Action;
-
- internal int ServerFid;
-
- internal long LastWriteTime;
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- int start = bufferIndex;
- Fid = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- FileAttributes = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- LastWriteTime = ReadUTime(buffer, bufferIndex);
- bufferIndex += 4;
- DataSize = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- GrantedAccess = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- FileType = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- DeviceState = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- Action = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- ServerFid = ReadInt4(buffer, bufferIndex);
- bufferIndex += 6;
- return bufferIndex - start;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComOpenAndXResponse[" + base.ToString() + ",fid=" + Fid + ",fileAttributes="
- + FileAttributes + ",lastWriteTime=" + LastWriteTime + ",dataSize=" + DataSize
- + ",grantedAccess=" + GrantedAccess + ",fileType=" + FileType + ",deviceState="
- + DeviceState + ",action=" + Action + ",serverFid=" + ServerFid + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComQueryInformation.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComQueryInformation.cs
deleted file mode 100644
index a528dbb11..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComQueryInformation.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class SmbComQueryInformation : ServerMessageBlock
- {
- internal SmbComQueryInformation(string filename)
- {
- Path = filename;
- Command = SmbComQueryInformation;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- dst[dstIndex++] = 0x04;
- dstIndex += WriteString(Path, dst, dstIndex);
- return dstIndex - start;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComQueryInformation[" + base.ToString() + ",filename=" + Path
- + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComQueryInformationResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComQueryInformationResponse.cs
deleted file mode 100644
index 040f081f0..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComQueryInformationResponse.cs
+++ /dev/null
@@ -1,95 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class SmbComQueryInformationResponse : ServerMessageBlock, IInfo
- {
- private int _fileAttributes = 0x0000;
-
- private long _lastWriteTime;
-
- private long _serverTimeZoneOffset;
-
- private int _fileSize;
-
- internal SmbComQueryInformationResponse(long serverTimeZoneOffset)
- {
- this._serverTimeZoneOffset = serverTimeZoneOffset;
- Command = SmbComQueryInformation;
- }
-
- public virtual int GetAttributes()
- {
- return _fileAttributes;
- }
-
- public virtual long GetCreateTime()
- {
- return _lastWriteTime + _serverTimeZoneOffset;
- }
-
- public virtual long GetLastWriteTime()
- {
- return _lastWriteTime + _serverTimeZoneOffset;
- }
-
- public virtual long GetSize()
- {
- return _fileSize;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- if (WordCount == 0)
- {
- return 0;
- }
- _fileAttributes = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- _lastWriteTime = ReadUTime(buffer, bufferIndex);
- bufferIndex += 4;
- _fileSize = ReadInt4(buffer, bufferIndex);
- return 20;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComQueryInformationResponse[" + base.ToString() + ",fileAttributes=0x"
- + Hexdump.ToHexString(_fileAttributes, 4) + ",lastWriteTime=" + Extensions.CreateDate
- (_lastWriteTime) + ",fileSize=" + _fileSize + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComReadAndX.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComReadAndX.cs
deleted file mode 100644
index e75179700..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComReadAndX.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class SmbComReadAndX : AndXServerMessageBlock
- {
- private static readonly int BatchLimit = Config.GetInt("jcifs.smb.client.ReadAndX.Close"
- , 1);
-
- private long _offset;
-
- private int _fid;
-
- private int _openTimeout;
-
- internal int MaxCount;
-
- internal int MinCount;
-
- internal int Remaining;
-
- public SmbComReadAndX() : base(null)
- {
- Command = SmbComReadAndx;
- _openTimeout = unchecked((int)(0xFFFFFFFF));
- }
-
- internal SmbComReadAndX(int fid, long offset, int maxCount, ServerMessageBlock andx
- ) : base(andx)
- {
- this._fid = fid;
- this._offset = offset;
- this.MaxCount = MinCount = maxCount;
- Command = SmbComReadAndx;
- _openTimeout = unchecked((int)(0xFFFFFFFF));
- }
-
- internal virtual void SetParam(int fid, long offset, int maxCount)
- {
- this._fid = fid;
- this._offset = offset;
- this.MaxCount = MinCount = maxCount;
- }
-
- internal override int GetBatchLimit(byte command)
- {
- return command == SmbComClose ? BatchLimit : 0;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- WriteInt2(_fid, dst, dstIndex);
- dstIndex += 2;
- WriteInt4(_offset, dst, dstIndex);
- dstIndex += 4;
- WriteInt2(MaxCount, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(MinCount, dst, dstIndex);
- dstIndex += 2;
- WriteInt4(_openTimeout, dst, dstIndex);
- dstIndex += 4;
- WriteInt2(Remaining, dst, dstIndex);
- dstIndex += 2;
- WriteInt4(_offset >> 32, dst, dstIndex);
- dstIndex += 4;
- return dstIndex - start;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComReadAndX[" + base.ToString() + ",fid=" + _fid + ",offset="
- + _offset + ",maxCount=" + MaxCount + ",minCount=" + MinCount + ",openTimeout="
- + _openTimeout + ",remaining=" + Remaining + ",offset=" + _offset + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComReadAndXResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComReadAndXResponse.cs
deleted file mode 100644
index 4d857aa2c..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComReadAndXResponse.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class SmbComReadAndXResponse : AndXServerMessageBlock
- {
- internal byte[] B;
-
- internal int Off;
-
- internal int DataCompactionMode;
-
- internal int DataLength;
-
- internal int DataOffset;
-
- public SmbComReadAndXResponse()
- {
- }
-
- internal SmbComReadAndXResponse(byte[] b, int off)
- {
- this.B = b;
- this.Off = off;
- }
-
- internal virtual void SetParam(byte[] b, int off)
- {
- this.B = b;
- this.Off = off;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- int start = bufferIndex;
- bufferIndex += 2;
- // reserved
- DataCompactionMode = ReadInt2(buffer, bufferIndex);
- bufferIndex += 4;
- // 2 reserved
- DataLength = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- DataOffset = ReadInt2(buffer, bufferIndex);
- bufferIndex += 12;
- // 10 reserved
- return bufferIndex - start;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- // handled special in SmbTransport.doRecv()
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComReadAndXResponse[" + base.ToString() + ",dataCompactionMode="
- + DataCompactionMode + ",dataLength=" + DataLength + ",dataOffset=" + DataOffset
- + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComRename.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComRename.cs
deleted file mode 100644
index 0ac57dd3e..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComRename.cs
+++ /dev/null
@@ -1,75 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-
-namespace SharpCifs.Smb
-{
- internal class SmbComRename : ServerMessageBlock
- {
- private int _searchAttributes;
-
- private string _oldFileName;
-
- private string _newFileName;
-
- internal SmbComRename(string oldFileName, string newFileName)
- {
- Command = SmbComRename;
- this._oldFileName = oldFileName;
- this._newFileName = newFileName;
- _searchAttributes = SmbConstants.AttrHidden | SmbConstants.AttrSystem | SmbConstants.AttrDirectory;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- WriteInt2(_searchAttributes, dst, dstIndex);
- return 2;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- dst[dstIndex++] = unchecked(unchecked(0x04));
- dstIndex += WriteString(_oldFileName, dst, dstIndex);
- dst[dstIndex++] = unchecked(unchecked(0x04));
- if (UseUnicode)
- {
- dst[dstIndex++] = unchecked((byte)('\0'));
- }
- dstIndex += WriteString(_newFileName, dst, dstIndex);
- return dstIndex - start;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComRename[" + base.ToString() + ",searchAttributes=0x" + Hexdump
- .ToHexString(_searchAttributes, 4) + ",oldFileName=" + _oldFileName + ",newFileName="
- + _newFileName + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComSessionSetupAndX.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComSessionSetupAndX.cs
deleted file mode 100644
index a1642391c..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComSessionSetupAndX.cs
+++ /dev/null
@@ -1,234 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// Ported to C# by J. Arturo <webmaster at komodosoft.net>
-using System;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class SmbComSessionSetupAndX : AndXServerMessageBlock
- {
- private static readonly int BatchLimit = Config.GetInt("jcifs.smb.client.SessionSetupAndX.TreeConnectAndX"
- , 1);
-
- private static readonly bool DisablePlainTextPasswords = Config.GetBoolean("jcifs.smb.client.disablePlainTextPasswords"
- , true);
-
- private byte[] _lmHash;
-
- private byte[] _ntHash;
-
- private byte[] _blob;
-
- private int _sessionKey;
-
- private int _capabilities;
-
- private string _accountName;
-
- private string _primaryDomain;
-
- internal SmbSession Session;
-
- internal object Cred;
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal SmbComSessionSetupAndX(SmbSession session, ServerMessageBlock andx, object
- cred) : base(andx)
- {
- Command = SmbComSessionSetupAndx;
- this.Session = session;
- this.Cred = cred;
- _sessionKey = session.transport.SessionKey;
- _capabilities = session.transport.Capabilities;
- if (session.transport.Server.Security == SmbConstants.SecurityUser)
- {
- if (cred is NtlmPasswordAuthentication)
- {
- NtlmPasswordAuthentication auth = (NtlmPasswordAuthentication)cred;
- if (auth == NtlmPasswordAuthentication.Anonymous)
- {
- _lmHash = new byte[0];
- _ntHash = new byte[0];
- _capabilities &= ~SmbConstants.CapExtendedSecurity;
- }
- else
- {
- if (session.transport.Server.EncryptedPasswords)
- {
- _lmHash = auth.GetAnsiHash(session.transport.Server.EncryptionKey);
- _ntHash = auth.GetUnicodeHash(session.transport.Server.EncryptionKey);
- // prohibit HTTP auth attempts for the null session
- if (_lmHash.Length == 0 && _ntHash.Length == 0)
- {
- throw new RuntimeException("Null setup prohibited.");
- }
- }
- else
- {
- if (DisablePlainTextPasswords)
- {
- throw new RuntimeException("Plain text passwords are disabled");
- }
- if (UseUnicode)
- {
- // plain text
- string password = auth.GetPassword();
- _lmHash = new byte[0];
- _ntHash = new byte[(password.Length + 1) * 2];
- WriteString(password, _ntHash, 0);
- }
- else
- {
- // plain text
- string password = auth.GetPassword();
- _lmHash = new byte[(password.Length + 1) * 2];
- _ntHash = new byte[0];
- WriteString(password, _lmHash, 0);
- }
- }
- }
- _accountName = auth.Username;
- if (UseUnicode)
- {
- _accountName = _accountName.ToUpper();
- }
- _primaryDomain = auth.Domain.ToUpper();
- }
- else
- {
- if (cred is byte[])
- {
- _blob = (byte[])cred;
- }
- else
- {
- throw new SmbException("Unsupported credential type");
- }
- }
- }
- else
- {
- if (session.transport.Server.Security == SmbConstants.SecurityShare)
- {
- if (cred is NtlmPasswordAuthentication)
- {
- NtlmPasswordAuthentication auth = (NtlmPasswordAuthentication)cred;
- _lmHash = new byte[0];
- _ntHash = new byte[0];
- _accountName = auth.Username;
- if (UseUnicode)
- {
- _accountName = _accountName.ToUpper();
- }
- _primaryDomain = auth.Domain.ToUpper();
- }
- else
- {
- throw new SmbException("Unsupported credential type");
- }
- }
- else
- {
- throw new SmbException("Unsupported");
- }
- }
- }
-
- internal override int GetBatchLimit(byte command)
- {
- return command == SmbComTreeConnectAndx ? BatchLimit : 0;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- WriteInt2(Session.transport.SndBufSize, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(Session.transport.MaxMpxCount, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(SmbConstants.VcNumber, dst, dstIndex);
- dstIndex += 2;
- WriteInt4(_sessionKey, dst, dstIndex);
- dstIndex += 4;
- if (_blob != null)
- {
- WriteInt2(_blob.Length, dst, dstIndex);
- dstIndex += 2;
- }
- else
- {
- WriteInt2(_lmHash.Length, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(_ntHash.Length, dst, dstIndex);
- dstIndex += 2;
- }
- dst[dstIndex++] = unchecked(unchecked(0x00));
- dst[dstIndex++] = unchecked(unchecked(0x00));
- dst[dstIndex++] = unchecked(unchecked(0x00));
- dst[dstIndex++] = unchecked(unchecked(0x00));
- WriteInt4(_capabilities, dst, dstIndex);
- dstIndex += 4;
- return dstIndex - start;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- if (_blob != null)
- {
- Array.Copy(_blob, 0, dst, dstIndex, _blob.Length);
- dstIndex += _blob.Length;
- }
- else
- {
- Array.Copy(_lmHash, 0, dst, dstIndex, _lmHash.Length);
- dstIndex += _lmHash.Length;
- Array.Copy(_ntHash, 0, dst, dstIndex, _ntHash.Length);
- dstIndex += _ntHash.Length;
- dstIndex += WriteString(_accountName, dst, dstIndex);
- dstIndex += WriteString(_primaryDomain, dst, dstIndex);
- }
- dstIndex += WriteString(SmbConstants.NativeOs, dst, dstIndex);
- dstIndex += WriteString(SmbConstants.NativeLanman, dst, dstIndex);
- return dstIndex - start;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- string result = "SmbComSessionSetupAndX[" + base.ToString() + ",snd_buf_size="
- + Session.transport.SndBufSize + ",maxMpxCount=" + Session.transport.MaxMpxCount
- + ",VC_NUMBER=" + SmbConstants.VcNumber + ",sessionKey=" + _sessionKey + ",lmHash.length="
- + (_lmHash == null ? 0 : _lmHash.Length) + ",ntHash.length=" + (_ntHash == null ?
- 0 : _ntHash.Length) + ",capabilities=" + _capabilities + ",accountName=" + _accountName
- + ",primaryDomain=" + _primaryDomain + ",NATIVE_OS=" + SmbConstants.NativeOs
- + ",NATIVE_LANMAN=" + SmbConstants.NativeLanman + "]";
- return result;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComSessionSetupAndXResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComSessionSetupAndXResponse.cs
deleted file mode 100644
index a3b80a669..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComSessionSetupAndXResponse.cs
+++ /dev/null
@@ -1,92 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-
-namespace SharpCifs.Smb
-{
- internal class SmbComSessionSetupAndXResponse : AndXServerMessageBlock
- {
- private string _nativeOs = string.Empty;
-
- private string _nativeLanMan = string.Empty;
-
- private string _primaryDomain = string.Empty;
-
- internal bool IsLoggedInAsGuest;
-
- internal byte[] Blob;
-
- internal SmbComSessionSetupAndXResponse(ServerMessageBlock andx) : base(andx)
- {
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- int start = bufferIndex;
- IsLoggedInAsGuest = (buffer[bufferIndex] & 0x01) == 0x01 ? true : false;
- bufferIndex += 2;
- if (ExtendedSecurity)
- {
- int blobLength = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- Blob = new byte[blobLength];
- }
- return bufferIndex - start;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- int start = bufferIndex;
- if (ExtendedSecurity)
- {
- Array.Copy(buffer, bufferIndex, Blob, 0, Blob.Length);
- bufferIndex += Blob.Length;
- }
- _nativeOs = ReadString(buffer, bufferIndex);
- bufferIndex += StringWireLength(_nativeOs, bufferIndex);
- _nativeLanMan = ReadString(buffer, bufferIndex, start + ByteCount, 255, UseUnicode
- );
- bufferIndex += StringWireLength(_nativeLanMan, bufferIndex);
- if (!ExtendedSecurity)
- {
- _primaryDomain = ReadString(buffer, bufferIndex, start + ByteCount, 255, UseUnicode
- );
- bufferIndex += StringWireLength(_primaryDomain, bufferIndex);
- }
- return bufferIndex - start;
- }
-
- public override string ToString()
- {
- string result = "SmbComSessionSetupAndXResponse[" + base.ToString() +
- ",isLoggedInAsGuest=" + IsLoggedInAsGuest + ",nativeOs=" + _nativeOs + ",nativeLanMan="
- + _nativeLanMan + ",primaryDomain=" + _primaryDomain + "]";
- return result;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTransaction.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTransaction.cs
deleted file mode 100644
index b3aeaaf7d..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTransaction.cs
+++ /dev/null
@@ -1,346 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using SharpCifs.Util;
-
-namespace SharpCifs.Smb
-{
- internal abstract class SmbComTransaction : ServerMessageBlock
- {
- private static readonly int DefaultMaxDataCount = Config.GetInt("jcifs.smb.client.transaction_buf_size"
- , TransactionBufSize) - 512;
-
- private const int PrimarySetupOffset = 61;
-
- private const int SecondaryParameterOffset = 51;
-
- private const int DisconnectTid = unchecked(0x01);
-
- private const int OneWayTransaction = unchecked(0x02);
-
- private const int PaddingSize = 2;
-
- private int _flags = unchecked(0x00);
-
- private int _fid;
-
- private int _pad;
-
- private int _pad1;
-
- private bool _hasMore = true;
-
- private bool _isPrimary = true;
-
- private int _bufParameterOffset;
-
- private int _bufDataOffset;
-
- internal const int TransactionBufSize = unchecked(0xFFFF);
-
- internal const byte Trans2FindFirst2 = unchecked(unchecked(0x01));
-
- internal const byte Trans2FindNext2 = unchecked(unchecked(0x02));
-
- internal const byte Trans2QueryFsInformation = unchecked(unchecked(0x03));
-
- internal const byte Trans2QueryPathInformation = unchecked(unchecked(0x05));
-
- internal const byte Trans2GetDfsReferral = unchecked(unchecked(0x10));
-
- internal const byte Trans2SetFileInformation = unchecked(unchecked(0x08));
-
- internal const int NetShareEnum = unchecked(0x0000);
-
- internal const int NetServerEnum2 = unchecked(0x0068);
-
- internal const int NetServerEnum3 = unchecked(0x00D7);
-
- internal const byte TransPeekNamedPipe = unchecked(unchecked(0x23
- ));
-
- internal const byte TransWaitNamedPipe = unchecked(unchecked(0x53
- ));
-
- internal const byte TransCallNamedPipe = unchecked(unchecked(0x54
- ));
-
- internal const byte TransTransactNamedPipe = unchecked(unchecked(0x26));
-
- protected internal int primarySetupOffset;
-
- protected internal int secondaryParameterOffset;
-
- protected internal int ParameterCount;
-
- protected internal int ParameterOffset;
-
- protected internal int ParameterDisplacement;
-
- protected internal int DataCount;
-
- protected internal int DataOffset;
-
- protected internal int DataDisplacement;
-
- internal int TotalParameterCount;
-
- internal int TotalDataCount;
-
- internal int MaxParameterCount;
-
- internal int MaxDataCount = DefaultMaxDataCount;
-
- internal byte MaxSetupCount;
-
- internal int Timeout = 0;
-
- internal int SetupCount = 1;
-
- internal byte SubCommand;
-
- internal string Name = string.Empty;
-
- internal int MaxBufferSize;
-
- internal byte[] TxnBuf;
-
- public SmbComTransaction()
- {
- // relative to headerStart
- // set in SmbTransport.sendTransaction() before nextElement called
- MaxParameterCount = 1024;
- primarySetupOffset = PrimarySetupOffset;
- secondaryParameterOffset = SecondaryParameterOffset;
- }
-
- internal override void Reset()
- {
- base.Reset();
- _isPrimary = _hasMore = true;
- }
-
- internal virtual void Reset(int key, string lastName)
- {
- Reset();
- }
-
- public virtual bool MoveNext()
- {
- return _hasMore;
- }
-
- public virtual object Current()
- {
- if (_isPrimary)
- {
- _isPrimary = false;
- ParameterOffset = primarySetupOffset + (SetupCount * 2) + 2;
- if (Command != SmbComNtTransact)
- {
- if (Command == SmbComTransaction && IsResponse() == false)
- {
- ParameterOffset += StringWireLength(Name, ParameterOffset);
- }
- }
- else
- {
- if (Command == SmbComNtTransact)
- {
- ParameterOffset += 2;
- }
- }
- _pad = ParameterOffset % PaddingSize;
- _pad = _pad == 0 ? 0 : PaddingSize - _pad;
- ParameterOffset += _pad;
- TotalParameterCount = WriteParametersWireFormat(TxnBuf, _bufParameterOffset);
- _bufDataOffset = TotalParameterCount;
- // data comes right after data
- int available = MaxBufferSize - ParameterOffset;
- ParameterCount = Math.Min(TotalParameterCount, available);
- available -= ParameterCount;
- DataOffset = ParameterOffset + ParameterCount;
- _pad1 = DataOffset % PaddingSize;
- _pad1 = _pad1 == 0 ? 0 : PaddingSize - _pad1;
- DataOffset += _pad1;
- TotalDataCount = WriteDataWireFormat(TxnBuf, _bufDataOffset);
- DataCount = Math.Min(TotalDataCount, available);
- }
- else
- {
- if (Command != SmbComNtTransact)
- {
- Command = SmbComTransactionSecondary;
- }
- else
- {
- Command = SmbComNtTransactSecondary;
- }
- // totalParameterCount and totalDataCount are set ok from primary
- ParameterOffset = SecondaryParameterOffset;
- if ((TotalParameterCount - ParameterDisplacement) > 0)
- {
- _pad = ParameterOffset % PaddingSize;
- _pad = _pad == 0 ? 0 : PaddingSize - _pad;
- ParameterOffset += _pad;
- }
- // caclulate parameterDisplacement before calculating new parameterCount
- ParameterDisplacement += ParameterCount;
- int available = MaxBufferSize - ParameterOffset - _pad;
- ParameterCount = Math.Min(TotalParameterCount - ParameterDisplacement, available);
- available -= ParameterCount;
- DataOffset = ParameterOffset + ParameterCount;
- _pad1 = DataOffset % PaddingSize;
- _pad1 = _pad1 == 0 ? 0 : PaddingSize - _pad1;
- DataOffset += _pad1;
- DataDisplacement += DataCount;
- available -= _pad1;
- DataCount = Math.Min(TotalDataCount - DataDisplacement, available);
- }
- if ((ParameterDisplacement + ParameterCount) >= TotalParameterCount && (DataDisplacement
- + DataCount) >= TotalDataCount)
- {
- _hasMore = false;
- }
- return this;
-
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- WriteInt2(TotalParameterCount, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(TotalDataCount, dst, dstIndex);
- dstIndex += 2;
- if (Command != SmbComTransactionSecondary)
- {
- WriteInt2(MaxParameterCount, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(MaxDataCount, dst, dstIndex);
- dstIndex += 2;
- dst[dstIndex++] = MaxSetupCount;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- // Reserved1
- WriteInt2(_flags, dst, dstIndex);
- dstIndex += 2;
- WriteInt4(Timeout, dst, dstIndex);
- dstIndex += 4;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- // Reserved2
- dst[dstIndex++] = unchecked(unchecked(0x00));
- }
- WriteInt2(ParameterCount, dst, dstIndex);
- dstIndex += 2;
- // writeInt2(( parameterCount == 0 ? 0 : parameterOffset ), dst, dstIndex );
- WriteInt2(ParameterOffset, dst, dstIndex);
- dstIndex += 2;
- if (Command == SmbComTransactionSecondary)
- {
- WriteInt2(ParameterDisplacement, dst, dstIndex);
- dstIndex += 2;
- }
- WriteInt2(DataCount, dst, dstIndex);
- dstIndex += 2;
- WriteInt2((DataCount == 0 ? 0 : DataOffset), dst, dstIndex);
- dstIndex += 2;
- if (Command == SmbComTransactionSecondary)
- {
- WriteInt2(DataDisplacement, dst, dstIndex);
- dstIndex += 2;
- }
- else
- {
- dst[dstIndex++] = unchecked((byte)SetupCount);
- dst[dstIndex++] = unchecked(unchecked(0x00));
- // Reserved3
- dstIndex += WriteSetupWireFormat(dst, dstIndex);
- }
- return dstIndex - start;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- int p = _pad;
- if (Command == SmbComTransaction && IsResponse() == false)
- {
- dstIndex += WriteString(Name, dst, dstIndex);
- }
- if (ParameterCount > 0)
- {
- while (p-- > 0)
- {
- dst[dstIndex++] = unchecked(unchecked(0x00));
- }
- // Pad
- Array.Copy(TxnBuf, _bufParameterOffset, dst, dstIndex, ParameterCount);
- dstIndex += ParameterCount;
- }
- if (DataCount > 0)
- {
- p = _pad1;
- while (p-- > 0)
- {
- dst[dstIndex++] = unchecked(unchecked(0x00));
- }
- // Pad1
- Array.Copy(TxnBuf, _bufDataOffset, dst, dstIndex, DataCount);
- _bufDataOffset += DataCount;
- dstIndex += DataCount;
- }
- return dstIndex - start;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- internal abstract int WriteSetupWireFormat(byte[] dst, int dstIndex);
-
- internal abstract int WriteParametersWireFormat(byte[] dst, int dstIndex);
-
- internal abstract int WriteDataWireFormat(byte[] dst, int dstIndex);
-
- internal abstract int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- );
-
- internal abstract int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len);
-
- internal abstract int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len);
-
- public override string ToString()
- {
- return base.ToString() + ",totalParameterCount=" + TotalParameterCount
- + ",totalDataCount=" + TotalDataCount + ",maxParameterCount=" + MaxParameterCount
- + ",maxDataCount=" + MaxDataCount + ",maxSetupCount=" + (int)MaxSetupCount + ",flags=0x"
- + Hexdump.ToHexString(_flags, 2) + ",timeout=" + Timeout + ",parameterCount=" +
- ParameterCount + ",parameterOffset=" + ParameterOffset + ",parameterDisplacement="
- + ParameterDisplacement + ",dataCount=" + DataCount + ",dataOffset=" + DataOffset
- + ",dataDisplacement=" + DataDisplacement + ",setupCount=" + SetupCount + ",pad="
- + _pad + ",pad1=" + _pad1;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTransactionResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTransactionResponse.cs
deleted file mode 100644
index 35f87594d..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTransactionResponse.cs
+++ /dev/null
@@ -1,206 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-
-namespace SharpCifs.Smb
-{
- internal abstract class SmbComTransactionResponse : ServerMessageBlock
- {
- private const int SetupOffset = 61;
-
- private const int DisconnectTid = unchecked(0x01);
-
- private const int OneWayTransaction = unchecked(0x02);
-
- private int _pad;
-
- private int _pad1;
-
- private bool _parametersDone;
-
- private bool _dataDone;
-
- protected internal int TotalParameterCount;
-
- protected internal int TotalDataCount;
-
- protected internal int ParameterCount;
-
- protected internal int ParameterOffset;
-
- protected internal int ParameterDisplacement;
-
- protected internal int DataOffset;
-
- protected internal int DataDisplacement;
-
- protected internal int SetupCount;
-
- protected internal int BufParameterStart;
-
- protected internal int BufDataStart;
-
- internal int DataCount;
-
- internal byte SubCommand;
-
- internal bool HasMore = true;
-
- internal bool IsPrimary = true;
-
- internal byte[] TxnBuf;
-
- internal int Status;
-
- internal int NumEntries;
-
- internal IFileEntry[] Results;
-
- public SmbComTransactionResponse()
- {
- // relative to headerStart
- TxnBuf = null;
- }
-
- internal override void Reset()
- {
- base.Reset();
- BufDataStart = 0;
- IsPrimary = HasMore = true;
- _parametersDone = _dataDone = false;
- }
-
- public virtual bool MoveNext()
- {
- return ErrorCode == 0 && HasMore;
- }
-
- public virtual object Current()
- {
- if (IsPrimary)
- {
- IsPrimary = false;
- }
- return this;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- int start = bufferIndex;
- TotalParameterCount = ReadInt2(buffer, bufferIndex);
- if (BufDataStart == 0)
- {
- BufDataStart = TotalParameterCount;
- }
- bufferIndex += 2;
- TotalDataCount = ReadInt2(buffer, bufferIndex);
- bufferIndex += 4;
- // Reserved
- ParameterCount = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- ParameterOffset = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- ParameterDisplacement = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- DataCount = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- DataOffset = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- DataDisplacement = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- SetupCount = buffer[bufferIndex] & unchecked(0xFF);
- bufferIndex += 2;
- if (SetupCount != 0)
- {
- if (Log.Level > 2)
- {
- Log.WriteLine("setupCount is not zero: " + SetupCount);
- }
- }
- return bufferIndex - start;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- _pad = _pad1 = 0;
- int n;
- if (ParameterCount > 0)
- {
- bufferIndex += _pad = ParameterOffset - (bufferIndex - HeaderStart);
- Array.Copy(buffer, bufferIndex, TxnBuf, BufParameterStart + ParameterDisplacement
- , ParameterCount);
- bufferIndex += ParameterCount;
- }
- if (DataCount > 0)
- {
- bufferIndex += _pad1 = DataOffset - (bufferIndex - HeaderStart);
- Array.Copy(buffer, bufferIndex, TxnBuf, BufDataStart + DataDisplacement,
- DataCount);
- bufferIndex += DataCount;
- }
- if (!_parametersDone && (ParameterDisplacement + ParameterCount) == TotalParameterCount)
- {
- _parametersDone = true;
- }
- if (!_dataDone && (DataDisplacement + DataCount) == TotalDataCount)
- {
- _dataDone = true;
- }
- if (_parametersDone && _dataDone)
- {
- HasMore = false;
- ReadParametersWireFormat(TxnBuf, BufParameterStart, TotalParameterCount);
- ReadDataWireFormat(TxnBuf, BufDataStart, TotalDataCount);
- }
- return _pad + ParameterCount + _pad1 + DataCount;
- }
-
- internal abstract int WriteSetupWireFormat(byte[] dst, int dstIndex);
-
- internal abstract int WriteParametersWireFormat(byte[] dst, int dstIndex);
-
- internal abstract int WriteDataWireFormat(byte[] dst, int dstIndex);
-
- internal abstract int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- );
-
- internal abstract int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len);
-
- internal abstract int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len);
-
- public override string ToString()
- {
- return base.ToString() + ",totalParameterCount=" + TotalParameterCount
- + ",totalDataCount=" + TotalDataCount + ",parameterCount=" + ParameterCount + ",parameterOffset="
- + ParameterOffset + ",parameterDisplacement=" + ParameterDisplacement + ",dataCount="
- + DataCount + ",dataOffset=" + DataOffset + ",dataDisplacement=" + DataDisplacement
- + ",setupCount=" + SetupCount + ",pad=" + _pad + ",pad1=" + _pad1;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTreeConnectAndX.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTreeConnectAndX.cs
deleted file mode 100644
index 67ad04f5f..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTreeConnectAndX.cs
+++ /dev/null
@@ -1,226 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class SmbComTreeConnectAndX : AndXServerMessageBlock
- {
- private static readonly bool DisablePlainTextPasswords = Config.GetBoolean("jcifs.smb.client.disablePlainTextPasswords"
- , true);
-
- private SmbSession _session;
-
- private bool _disconnectTid = false;
-
- private string _service;
-
- private byte[] _password;
-
- private int _passwordLength;
-
- internal string path;
-
- private static byte[] _batchLimits = { 1, 1, 1, 1, 1, 1, 1, 1, 0 };
-
- static SmbComTreeConnectAndX()
- {
- string s;
- if ((s = Config.GetProperty("jcifs.smb.client.TreeConnectAndX.CheckDirectory")) !=
- null)
- {
- _batchLimits[0] = byte.Parse(s);
- }
- if ((s = Config.GetProperty("jcifs.smb.client.TreeConnectAndX.CreateDirectory"))
- != null)
- {
- _batchLimits[2] = byte.Parse(s);
- }
- if ((s = Config.GetProperty("jcifs.smb.client.TreeConnectAndX.Delete")) != null)
- {
- _batchLimits[3] = byte.Parse(s);
- }
- if ((s = Config.GetProperty("jcifs.smb.client.TreeConnectAndX.DeleteDirectory"))
- != null)
- {
- _batchLimits[4] = byte.Parse(s);
- }
- if ((s = Config.GetProperty("jcifs.smb.client.TreeConnectAndX.OpenAndX")) != null)
- {
- _batchLimits[5] = byte.Parse(s);
- }
- if ((s = Config.GetProperty("jcifs.smb.client.TreeConnectAndX.Rename")) != null)
- {
- _batchLimits[6] = byte.Parse(s);
- }
- if ((s = Config.GetProperty("jcifs.smb.client.TreeConnectAndX.Transaction")) != null)
- {
- _batchLimits[7] = byte.Parse(s);
- }
- if ((s = Config.GetProperty("jcifs.smb.client.TreeConnectAndX.QueryInformation"))
- != null)
- {
- _batchLimits[8] = byte.Parse(s);
- }
- }
-
- internal SmbComTreeConnectAndX(SmbSession session, string path, string service, ServerMessageBlock
- andx) : base(andx)
- {
- this._session = session;
- this.path = path;
- this._service = service;
- Command = SmbComTreeConnectAndx;
- }
-
- internal override int GetBatchLimit(byte command)
- {
- int c = command & unchecked(0xFF);
- switch (c)
- {
- case SmbComCheckDirectory:
- {
- // why isn't this just return batchLimits[c]?
- return _batchLimits[0];
- }
-
- case SmbComCreateDirectory:
- {
- return _batchLimits[2];
- }
-
- case SmbComDelete:
- {
- return _batchLimits[3];
- }
-
- case SmbComDeleteDirectory:
- {
- return _batchLimits[4];
- }
-
- case SmbComOpenAndx:
- {
- return _batchLimits[5];
- }
-
- case SmbComRename:
- {
- return _batchLimits[6];
- }
-
- case SmbComTransaction:
- {
- return _batchLimits[7];
- }
-
- case SmbComQueryInformation:
- {
- return _batchLimits[8];
- }
- }
- return 0;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- if (_session.transport.Server.Security == SmbConstants.SecurityShare && (_session.Auth.HashesExternal
- || _session.Auth.Password.Length > 0))
- {
- if (_session.transport.Server.EncryptedPasswords)
- {
- // encrypted
- _password = _session.Auth.GetAnsiHash(_session.transport.Server.EncryptionKey);
- _passwordLength = _password.Length;
- }
- else
- {
- if (DisablePlainTextPasswords)
- {
- throw new RuntimeException("Plain text passwords are disabled");
- }
- // plain text
- _password = new byte[(_session.Auth.Password.Length + 1) * 2];
- _passwordLength = WriteString(_session.Auth.Password, _password, 0);
- }
- }
- else
- {
- // no password in tree connect
- _passwordLength = 1;
- }
- dst[dstIndex++] = _disconnectTid ? unchecked((byte)unchecked(0x01)) : unchecked(
- (byte)unchecked(0x00));
- dst[dstIndex++] = unchecked(unchecked(0x00));
- WriteInt2(_passwordLength, dst, dstIndex);
- return 4;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- if (_session.transport.Server.Security == SmbConstants.SecurityShare && (_session.Auth.HashesExternal
- || _session.Auth.Password.Length > 0))
- {
- Array.Copy(_password, 0, dst, dstIndex, _passwordLength);
- dstIndex += _passwordLength;
- }
- else
- {
- // no password in tree connect
- dst[dstIndex++] = unchecked(unchecked(0x00));
- }
- dstIndex += WriteString(path, dst, dstIndex);
- try
- {
-// Array.Copy(Runtime.GetBytesForString(_service, "ASCII"), 0, dst, dstIndex
- //, _service.Length);
- Array.Copy(Runtime.GetBytesForString(_service, "UTF-8"), 0, dst, dstIndex
- , _service.Length);
- }
- catch (UnsupportedEncodingException)
- {
- return 0;
- }
- dstIndex += _service.Length;
- dst[dstIndex++] = unchecked((byte)('\0'));
- return dstIndex - start;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- string result = "SmbComTreeConnectAndX[" + base.ToString() + ",disconnectTid="
- + _disconnectTid + ",passwordLength=" + _passwordLength + ",password=" + Hexdump.
- ToHexString(_password, _passwordLength, 0) + ",path=" + path + ",service=" + _service
- + "]";
- return result;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTreeConnectAndXResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTreeConnectAndXResponse.cs
deleted file mode 100644
index add660b26..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTreeConnectAndXResponse.cs
+++ /dev/null
@@ -1,84 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class SmbComTreeConnectAndXResponse : AndXServerMessageBlock
- {
- private const int SmbSupportSearchBits = unchecked(0x0001);
-
- private const int SmbShareIsInDfs = unchecked(0x0002);
-
- internal bool SupportSearchBits;
-
- internal bool ShareIsInDfs;
-
- internal string Service;
-
- internal string NativeFileSystem = string.Empty;
-
- internal SmbComTreeConnectAndXResponse(ServerMessageBlock andx) : base(andx)
- {
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- SupportSearchBits = (buffer[bufferIndex] & SmbSupportSearchBits) == SmbSupportSearchBits;
- ShareIsInDfs = (buffer[bufferIndex] & SmbShareIsInDfs) == SmbShareIsInDfs;
- return 2;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- int start = bufferIndex;
- int len = ReadStringLength(buffer, bufferIndex, 32);
- try
- {
- //Service = Runtime.GetStringForBytes(buffer, bufferIndex, len, "ASCII");
- Service = Runtime.GetStringForBytes(buffer, bufferIndex, len, "UTF-8");
- }
- catch (UnsupportedEncodingException)
- {
- return 0;
- }
- bufferIndex += len + 1;
- // win98 observed not returning nativeFileSystem
- return bufferIndex - start;
- }
-
- public override string ToString()
- {
- string result = "SmbComTreeConnectAndXResponse[" + base.ToString() + ",supportSearchBits="
- + SupportSearchBits + ",shareIsInDfs=" + ShareIsInDfs + ",service=" + Service +
- ",nativeFileSystem=" + NativeFileSystem + "]";
- return result;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTreeDisconnect.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTreeDisconnect.cs
deleted file mode 100644
index d9eb5b2eb..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComTreeDisconnect.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class SmbComTreeDisconnect : ServerMessageBlock
- {
- public SmbComTreeDisconnect()
- {
- Command = SmbComTreeDisconnect;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComTreeDisconnect[" + base.ToString() + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWrite.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWrite.cs
deleted file mode 100644
index 418a69d1d..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWrite.cs
+++ /dev/null
@@ -1,106 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-
-namespace SharpCifs.Smb
-{
- internal class SmbComWrite : ServerMessageBlock
- {
- private int _fid;
-
- private int _count;
-
- private int _offset;
-
- private int _remaining;
-
- private int _off;
-
- private byte[] _b;
-
- public SmbComWrite()
- {
- Command = SmbComWrite;
- }
-
- internal SmbComWrite(int fid, int offset, int remaining, byte[] b, int off, int len
- )
- {
- this._fid = fid;
- _count = len;
- this._offset = offset;
- this._remaining = remaining;
- this._b = b;
- this._off = off;
- Command = SmbComWrite;
- }
-
- internal virtual void SetParam(int fid, long offset, int remaining, byte[] b, int
- off, int len)
- {
- this._fid = fid;
- this._offset = (int)(offset & unchecked(0xFFFFFFFFL));
- this._remaining = remaining;
- this._b = b;
- this._off = off;
- _count = len;
- Digest = null;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- WriteInt2(_fid, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(_count, dst, dstIndex);
- dstIndex += 2;
- WriteInt4(_offset, dst, dstIndex);
- dstIndex += 4;
- WriteInt2(_remaining, dst, dstIndex);
- dstIndex += 2;
- return dstIndex - start;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- dst[dstIndex++] = 0x01;
- WriteInt2(_count, dst, dstIndex);
- dstIndex += 2;
- Array.Copy(_b, _off, dst, dstIndex, _count);
- dstIndex += _count;
- return dstIndex - start;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComWrite[" + base.ToString() + ",fid=" + _fid + ",count=" +
- _count + ",offset=" + _offset + ",remaining=" + _remaining + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWriteAndX.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWriteAndX.cs
deleted file mode 100644
index b182fd7ff..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWriteAndX.cs
+++ /dev/null
@@ -1,150 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-
-namespace SharpCifs.Smb
-{
- internal class SmbComWriteAndX : AndXServerMessageBlock
- {
- private static readonly int ReadAndxBatchLimit = Config.GetInt("jcifs.smb.client.WriteAndX.ReadAndX"
- , 1);
-
- private static readonly int CloseBatchLimit = Config.GetInt("jcifs.smb.client.WriteAndX.Close"
- , 1);
-
- private int _fid;
-
- private int _remaining;
-
- private int _dataLength;
-
- private int _dataOffset;
-
- private int _off;
-
- private byte[] _b;
-
- private long _offset;
-
- private int _pad;
-
- internal int WriteMode;
-
- public SmbComWriteAndX() : base(null)
- {
- Command = SmbComWriteAndx;
- }
-
- internal SmbComWriteAndX(int fid, long offset, int remaining, byte[] b, int off,
- int len, ServerMessageBlock andx) : base(andx)
- {
- this._fid = fid;
- this._offset = offset;
- this._remaining = remaining;
- this._b = b;
- this._off = off;
- _dataLength = len;
- Command = SmbComWriteAndx;
- }
-
- internal virtual void SetParam(int fid, long offset, int remaining, byte[] b, int
- off, int len)
- {
- this._fid = fid;
- this._offset = offset;
- this._remaining = remaining;
- this._b = b;
- this._off = off;
- _dataLength = len;
- Digest = null;
- }
-
- internal override int GetBatchLimit(byte command)
- {
- if (command == SmbComReadAndx)
- {
- return ReadAndxBatchLimit;
- }
- if (command == SmbComClose)
- {
- return CloseBatchLimit;
- }
- return 0;
- }
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- _dataOffset = (dstIndex - HeaderStart) + 26;
- // 26 = off from here to pad
- _pad = (_dataOffset - HeaderStart) % 4;
- _pad = _pad == 0 ? 0 : 4 - _pad;
- _dataOffset += _pad;
- WriteInt2(_fid, dst, dstIndex);
- dstIndex += 2;
- WriteInt4(_offset, dst, dstIndex);
- dstIndex += 4;
- for (int i = 0; i < 4; i++)
- {
- dst[dstIndex++] = 0xFF;
- }
- WriteInt2(WriteMode, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(_remaining, dst, dstIndex);
- dstIndex += 2;
- dst[dstIndex++] = 0x00;
- dst[dstIndex++] =0x00;
- WriteInt2(_dataLength, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(_dataOffset, dst, dstIndex);
- dstIndex += 2;
- WriteInt4(_offset >> 32, dst, dstIndex);
- dstIndex += 4;
- return dstIndex - start;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- while (_pad-- > 0)
- {
- dst[dstIndex++] = 0xEE;
- }
- Array.Copy(_b, _off, dst, dstIndex, _dataLength);
- dstIndex += _dataLength;
- return dstIndex - start;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- return 0;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComWriteAndX[" + base.ToString() + ",fid=" + _fid + ",offset="
- + _offset + ",writeMode=" + WriteMode + ",remaining=" + _remaining + ",dataLength="
- + _dataLength + ",dataOffset=" + _dataOffset + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWriteAndXResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWriteAndXResponse.cs
deleted file mode 100644
index c6749b6cb..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWriteAndXResponse.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class SmbComWriteAndXResponse : AndXServerMessageBlock
- {
- internal long Count;
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- Count = ReadInt2(buffer, bufferIndex) & unchecked(0xFFFFL);
- return 8;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComWriteAndXResponse[" + base.ToString() + ",count=" + Count + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWriteResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWriteResponse.cs
deleted file mode 100644
index 785d406c1..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbComWriteResponse.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class SmbComWriteResponse : ServerMessageBlock
- {
- internal long Count;
-
- internal override int WriteParameterWordsWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteBytesWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParameterWordsWireFormat(byte[] buffer, int bufferIndex
- )
- {
- Count = ReadInt2(buffer, bufferIndex) & unchecked(0xFFFFL);
- return 8;
- }
-
- internal override int ReadBytesWireFormat(byte[] buffer, int bufferIndex)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "SmbComWriteResponse[" + base.ToString() + ",count=" + Count + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbConstants.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbConstants.cs
deleted file mode 100644
index 0793c7541..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbConstants.cs
+++ /dev/null
@@ -1,302 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using System.Collections.Generic;
-using System.Net;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal static class SmbConstants
- {
- public static readonly int DefaultPort = 445;
-
- public static readonly int DefaultMaxMpxCount = 10;
-
- public static readonly int DefaultResponseTimeout = 30000;
-
- public static readonly int DefaultSoTimeout = 35000;
-
- public static readonly int DefaultRcvBufSize = 60416;
-
- public static readonly int DefaultSndBufSize = 16644;
-
- public static readonly int DefaultSsnLimit = 250;
-
- public static readonly int DefaultConnTimeout = 35000;
-
- public static readonly IPAddress Laddr = Config.GetLocalHost();
-
- public static readonly int Lport = Config.GetInt("jcifs.smb.client.lport", 0);
-
- public static readonly int MaxMpxCount = Config.GetInt("jcifs.smb.client.maxMpxCount", DefaultMaxMpxCount
- );
-
- public static readonly int SndBufSize = Config.GetInt("jcifs.smb.client.snd_buf_size", DefaultSndBufSize
- );
-
- public static readonly int RcvBufSize = Config.GetInt("jcifs.smb.client.rcv_buf_size", DefaultRcvBufSize
- );
-
- public static readonly bool UseUnicode = Config.GetBoolean("jcifs.smb.client.useUnicode",
- true);
-
- public static readonly bool ForceUnicode = Config.GetBoolean("jcifs.smb.client.useUnicode"
- , false);
-
- public static readonly bool UseNtstatus = Config.GetBoolean("jcifs.smb.client.useNtStatus"
- , true);
-
- public static readonly bool Signpref = Config.GetBoolean("jcifs.smb.client.signingPreferred"
- , false);
-
- public static readonly bool UseNtsmbs = Config.GetBoolean("jcifs.smb.client.useNTSmbs", true
- );
-
- public static readonly bool UseExtsec = Config.GetBoolean("jcifs.smb.client.useExtendedSecurity"
- , true);
-
- public static readonly string NetbiosHostname = Config.GetProperty("jcifs.netbios.hostname"
- , null);
-
- public static readonly int LmCompatibility = Config.GetInt("jcifs.smb.lmCompatibility", 3);
-
- public static readonly int FlagsNone = unchecked(0x00);
-
- public static readonly int FlagsLockAndReadWriteAndUnlock = unchecked(0x01);
-
- public static readonly int FlagsReceiveBufferPosted = unchecked(0x02);
-
- public static readonly int FlagsPathNamesCaseless = unchecked(0x08);
-
- public static readonly int FlagsPathNamesCanonicalized = unchecked(0x10);
-
- public static readonly int FlagsOplockRequestedOrGranted = unchecked(0x20);
-
- public static readonly int FlagsNotifyOfModifyAction = unchecked(0x40);
-
- public static readonly int FlagsResponse = unchecked(0x80);
-
- public static readonly int Flags2None = unchecked(0x0000);
-
- public static readonly int Flags2LongFilenames = unchecked(0x0001);
-
- public static readonly int Flags2ExtendedAttributes = unchecked(0x0002);
-
- public static readonly int Flags2SecuritySignatures = unchecked(0x0004);
-
- public static readonly int Flags2ExtendedSecurityNegotiation = unchecked(0x0800);
-
- public static readonly int Flags2ResolvePathsInDfs = unchecked(0x1000);
-
- public static readonly int Flags2PermitReadIfExecutePerm = unchecked(0x2000);
-
- public static readonly int Flags2Status32 = unchecked(0x4000);
-
- public static readonly int Flags2Unicode = unchecked(0x8000);
-
- public static readonly int CapNone = unchecked(0x0000);
-
- public static readonly int CapRawMode = unchecked(0x0001);
-
- public static readonly int CapMpxMode = unchecked(0x0002);
-
- public static readonly int CapUnicode = unchecked(0x0004);
-
- public static readonly int CapLargeFiles = unchecked(0x0008);
-
- public static readonly int CapNtSmbs = unchecked(0x0010);
-
- public static readonly int CapRpcRemoteApis = unchecked(0x0020);
-
- public static readonly int CapStatus32 = unchecked(0x0040);
-
- public static readonly int CapLevelIiOplocks = unchecked(0x0080);
-
- public static readonly int CapLockAndRead = unchecked(0x0100);
-
- public static readonly int CapNtFind = unchecked(0x0200);
-
- public static readonly int CapDfs = unchecked(0x1000);
-
- public static readonly int CapExtendedSecurity = unchecked((int)(0x80000000));
-
- public static readonly int AttrReadonly = unchecked(0x01);
-
- public static readonly int AttrHidden = unchecked(0x02);
-
- public static readonly int AttrSystem = unchecked(0x04);
-
- public static readonly int AttrVolume = unchecked(0x08);
-
- public static readonly int AttrDirectory = unchecked(0x10);
-
- public static readonly int AttrArchive = unchecked(0x20);
-
- public static readonly int AttrCompressed = unchecked(0x800);
-
- public static readonly int AttrNormal = unchecked(0x080);
-
- public static readonly int AttrTemporary = unchecked(0x100);
-
- public static readonly int FileReadData = unchecked(0x00000001);
-
- public static readonly int FileWriteData = unchecked(0x00000002);
-
- public static readonly int FileAppendData = unchecked(0x00000004);
-
- public static readonly int FileReadEa = unchecked(0x00000008);
-
- public static readonly int FileWriteEa = unchecked(0x00000010);
-
- public static readonly int FileExecute = unchecked(0x00000020);
-
- public static readonly int FileDelete = unchecked(0x00000040);
-
- public static readonly int FileReadAttributes = unchecked(0x00000080);
-
- public static readonly int FileWriteAttributes = unchecked(0x00000100);
-
- public static readonly int Delete = unchecked(0x00010000);
-
- public static readonly int ReadControl = unchecked(0x00020000);
-
- public static readonly int WriteDac = unchecked(0x00040000);
-
- public static readonly int WriteOwner = unchecked(0x00080000);
-
- public static readonly int Synchronize = unchecked(0x00100000);
-
- public static readonly int GenericAll = unchecked(0x10000000);
-
- public static readonly int GenericExecute = unchecked(0x20000000);
-
- public static readonly int GenericWrite = unchecked(0x40000000);
-
- public static readonly int GenericRead = unchecked((int)(0x80000000));
-
- public static readonly int FlagsTargetMustBeFile = unchecked(0x0001);
-
- public static readonly int FlagsTargetMustBeDirectory = unchecked(0x0002);
-
- public static readonly int FlagsCopyTargetModeAscii = unchecked(0x0004);
-
- public static readonly int FlagsCopySourceModeAscii = unchecked(0x0008);
-
- public static readonly int FlagsVerifyAllWrites = unchecked(0x0010);
-
- public static readonly int FlagsTreeCopy = unchecked(0x0020);
-
- public static readonly int OpenFunctionFailIfExists = unchecked(0x0000);
-
- public static readonly int OpenFunctionOverwriteIfExists = unchecked(0x0020);
-
- public static readonly int Pid = (int)(new Random().NextDouble() * 65536d);
-
- public static readonly int SecurityShare = unchecked(0x00);
-
- public static readonly int SecurityUser = unchecked(0x01);
-
- public static readonly int CmdOffset = 4;
-
- public static readonly int ErrorCodeOffset = 5;
-
- public static readonly int FlagsOffset = 9;
-
- public static readonly int SignatureOffset = 14;
-
- public static readonly int TidOffset = 24;
-
- public static readonly int HeaderLength = 32;
-
- public static readonly long MillisecondsBetween1970And1601 = 11644473600000L;
-
- public static readonly TimeZoneInfo Tz = TimeZoneInfo.Local;
-
- public static readonly bool UseBatching = Config.GetBoolean("jcifs.smb.client.useBatching"
- , true);
-
- public static readonly string OemEncoding = Config.GetProperty("jcifs.encoding", Config.DefaultOemEncoding
- );
-
- public static readonly string UniEncoding = "UTF-16LE";
-
- public static readonly int DefaultFlags2 = Flags2LongFilenames | Flags2ExtendedAttributes
- | (UseExtsec ? Flags2ExtendedSecurityNegotiation : 0) | (Signpref ? Flags2SecuritySignatures
- : 0) | (UseNtstatus ? Flags2Status32 : 0) | (UseUnicode ? Flags2Unicode : 0
- );
-
- public static readonly int DefaultCapabilities = (UseNtsmbs ? CapNtSmbs : 0) | (UseNtstatus
- ? CapStatus32 : 0) | (UseUnicode ? CapUnicode : 0) | CapDfs;
-
- public static readonly int Flags2 = Config.GetInt("jcifs.smb.client.flags2", DefaultFlags2
- );
-
- public static readonly int Capabilities = Config.GetInt("jcifs.smb.client.capabilities", DefaultCapabilities
- );
-
- public static readonly bool TcpNodelay = Config.GetBoolean("jcifs.smb.client.tcpNoDelay",
- false);
-
- public static readonly int ResponseTimeout = Config.GetInt("jcifs.smb.client.responseTimeout"
- , DefaultResponseTimeout);
-
- public static readonly List<SmbTransport> Connections = new List<SmbTransport>();
-
- public static readonly int SsnLimit = Config.GetInt("jcifs.smb.client.ssnLimit", DefaultSsnLimit
- );
-
- public static readonly int SoTimeout = Config.GetInt("jcifs.smb.client.soTimeout", DefaultSoTimeout
- );
-
- public static readonly int ConnTimeout = Config.GetInt("jcifs.smb.client.connTimeout", DefaultConnTimeout
- );
-
- public static readonly string NativeOs = Config.GetProperty("jcifs.smb.client.nativeOs", Runtime
- .GetProperty("os.name"));
-
- public static readonly string NativeLanman = Config.GetProperty("jcifs.smb.client.nativeLanMan"
- , "jCIFS");
-
- public static readonly int VcNumber = 1;
-
- public static SmbTransport NullTransport = new SmbTransport(null, 0, null, 0);
- // file attribute encoding
- // extended file attribute encoding(others same as above)
- // access mask encoding
- // 1
- // 2
- // 3
- // 4
- // 5
- // 6
- // 7
- // 8
- // 9
- // 16
- // 17
- // 18
- // 19
- // 20
- // 28
- // 29
- // 30
- // 31
- // flags for move and copy
- // open function
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbException.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbException.cs
deleted file mode 100644
index ea8a0b846..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbException.cs
+++ /dev/null
@@ -1,212 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using System.IO;
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- /// <summary>
- /// There are hundreds of error codes that may be returned by a CIFS
- /// server.
- /// </summary>
- /// <remarks>
- /// There are hundreds of error codes that may be returned by a CIFS
- /// server. Rather than represent each with it's own <code>Exception</code>
- /// class, this class represents all of them. For many of the popular
- /// error codes, constants and text messages like "The device is not ready"
- /// are provided.
- /// <p>
- /// The jCIFS client maps DOS error codes to NTSTATUS codes. This means that
- /// the user may recieve a different error from a legacy server than that of
- /// a newer varient such as Windows NT and above. If you should encounter
- /// such a case, please report it to jcifs at samba dot org and we will
- /// change the mapping.
- /// </remarks>
-
- public class SmbException : IOException
- {
-
- internal static string GetMessageByCode(int errcode)
- {
- if (errcode == 0)
- {
- return "NT_STATUS_SUCCESS";
- }
- if ((errcode & unchecked((int)(0xC0000000))) == unchecked((int)(0xC0000000)))
- {
- int min = 1;
- int max = NtStatus.NtStatusCodes.Length - 1;
- while (max >= min)
- {
- int mid = (min + max) / 2;
- if (errcode > NtStatus.NtStatusCodes[mid])
- {
- min = mid + 1;
- }
- else
- {
- if (errcode < NtStatus.NtStatusCodes[mid])
- {
- max = mid - 1;
- }
- else
- {
- return NtStatus.NtStatusMessages[mid];
- }
- }
- }
- }
- else
- {
- int min = 0;
- int max = DosError.DosErrorCodes.Length - 1;
- while (max >= min)
- {
- int mid = (min + max) / 2;
- if (errcode > DosError.DosErrorCodes[mid][0])
- {
- min = mid + 1;
- }
- else
- {
- if (errcode < DosError.DosErrorCodes[mid][0])
- {
- max = mid - 1;
- }
- else
- {
- return DosError.DosErrorMessages[mid];
- }
- }
- }
- }
- return "0x" + Hexdump.ToHexString(errcode, 8);
- }
-
- internal static int GetStatusByCode(int errcode)
- {
- if ((errcode & unchecked((int)(0xC0000000))) != 0)
- {
- return errcode;
- }
- int min = 0;
- int max = DosError.DosErrorCodes.Length - 1;
- while (max >= min)
- {
- int mid = (min + max) / 2;
- if (errcode > DosError.DosErrorCodes[mid][0])
- {
- min = mid + 1;
- }
- else
- {
- if (errcode < DosError.DosErrorCodes[mid][0])
- {
- max = mid - 1;
- }
- else
- {
- return DosError.DosErrorCodes[mid][1];
- }
- }
- }
- return NtStatus.NtStatusUnsuccessful;
- }
-
- internal static string GetMessageByWinerrCode(int errcode)
- {
- int min = 0;
- int max = WinError.WinerrCodes.Length - 1;
- while (max >= min)
- {
- int mid = (min + max) / 2;
- if (errcode > WinError.WinerrCodes[mid])
- {
- min = mid + 1;
- }
- else
- {
- if (errcode < WinError.WinerrCodes[mid])
- {
- max = mid - 1;
- }
- else
- {
- return WinError.WinerrMessages[mid];
- }
- }
- }
- return errcode + string.Empty;
- }
-
- private int _status;
-
- private Exception _rootCause;
-
- public SmbException()
- {
- }
-
- internal SmbException(int errcode, Exception rootCause) : base(GetMessageByCode(errcode
- ))
- {
- _status = GetStatusByCode(errcode);
- this._rootCause = rootCause;
- }
-
- public SmbException(string msg) : base(msg)
- {
- _status = NtStatus.NtStatusUnsuccessful;
- }
-
- public SmbException(string msg, Exception rootCause) : base(msg)
- {
- this._rootCause = rootCause;
- _status = NtStatus.NtStatusUnsuccessful;
- }
-
- public SmbException(int errcode, bool winerr) : base(winerr ? GetMessageByWinerrCode
- (errcode) : GetMessageByCode(errcode))
- {
- _status = winerr ? errcode : GetStatusByCode(errcode);
- }
-
- public virtual int GetNtStatus()
- {
- return _status;
- }
-
- public virtual Exception GetRootCause()
- {
- return _rootCause;
- }
-
- public override string ToString()
- {
- if (_rootCause != null)
- {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- Runtime.PrintStackTrace(_rootCause, pw);
- return base.ToString() + "\n" + sw;
- }
- return base.ToString();
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFile.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFile.cs
deleted file mode 100644
index 151ec35c4..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFile.cs
+++ /dev/null
@@ -1,3755 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Net;
-using System.Text;
-using SharpCifs.Dcerpc;
-using SharpCifs.Dcerpc.Msrpc;
-using SharpCifs.Netbios;
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- /// <summary>This class represents a resource on an SMB network.</summary>
- /// <remarks>
- /// This class represents a resource on an SMB network. Mainly these
- /// resources are files and directories however an <code>SmbFile</code>
- /// may also refer to servers and workgroups. If the resource is a file or
- /// directory the methods of <code>SmbFile</code> follow the behavior of
- /// the well known
- /// <see cref="FilePath">Sharpen.FilePath</see>
- /// class. One fundamental difference
- /// is the usage of a URL scheme [1] to specify the target file or
- /// directory. SmbFile URLs have the following syntax:
- /// <blockquote><pre>
- /// smb://[[[domain;]username[:password]@]server[:port]/[[share/[dir/]file]]][?[param=value[param2=value2[...]]]
- /// </pre></blockquote>
- /// This example:
- /// <blockquote><pre>
- /// smb://storage15/public/foo.txt
- /// </pre></blockquote>
- /// would reference the file <code>foo.txt</code> in the share
- /// <code>public</code> on the server <code>storage15</code>. In addition
- /// to referencing files and directories, jCIFS can also address servers,
- /// and workgroups.
- /// <p>
- /// <font color="#800000"><i>Important: all SMB URLs that represent
- /// workgroups, servers, shares, or directories require a trailing slash '/'.
- /// </i></font>
- /// <p>
- /// When using the <tt>java.net.URL</tt> class with
- /// 'smb://' URLs it is necessary to first call the static
- /// <tt>jcifs.Config.registerSmbURLHandler();</tt> method. This is required
- /// to register the SMB protocol handler.
- /// <p>
- /// The userinfo component of the SMB URL (<tt>domain;user:pass</tt>) must
- /// be URL encoded if it contains reserved characters. According to RFC 2396
- /// these characters are non US-ASCII characters and most meta characters
- /// however jCIFS will work correctly with anything but '@' which is used
- /// to delimit the userinfo component from the server and '%' which is the
- /// URL escape character itself.
- /// <p>
- /// The server
- /// component may a traditional NetBIOS name, a DNS name, or IP
- /// address. These name resolution mechanisms and their resolution order
- /// can be changed (See <a href="../../../resolver.html">Setting Name
- /// Resolution Properties</a>). The servername and path components are
- /// not case sensitive but the domain, username, and password components
- /// are. It is also likely that properties must be specified for jcifs
- /// to function (See <a href="../../overview-summary.html#scp">Setting
- /// JCIFS Properties</a>). Here are some examples of SMB URLs with brief
- /// descriptions of what they do:
- /// <p>[1] This URL scheme is based largely on the <i>SMB
- /// Filesharing URL Scheme</i> IETF draft.
- /// <p><table border="1" cellpadding="3" cellspacing="0" width="100%">
- /// <tr bgcolor="#ccccff">
- /// <td colspan="2"><b>SMB URL Examples</b></td>
- /// <tr><td width="20%"><b>URL</b></td><td><b>Description</b></td></tr>
- /// <tr><td width="20%"><code>smb://users-nyc;miallen:mypass@angus/tmp/</code></td><td>
- /// This URL references a share called <code>tmp</code> on the server
- /// <code>angus</code> as user <code>miallen</code> who's password is
- /// <code>mypass</code>.
- /// </td></tr>
- /// <tr><td width="20%">
- /// <code>smb://Administrator:P%40ss@msmith1/c/WINDOWS/Desktop/foo.txt</code></td><td>
- /// A relativly sophisticated example that references a file
- /// <code>msmith1</code>'s desktop as user <code>Administrator</code>. Notice the '@' is URL encoded with the '%40' hexcode escape.
- /// </td></tr>
- /// <tr><td width="20%"><code>smb://angus/</code></td><td>
- /// This references only a server. The behavior of some methods is different
- /// in this context(e.g. you cannot <code>delete</code> a server) however
- /// as you might expect the <code>list</code> method will list the available
- /// shares on this server.
- /// </td></tr>
- /// <tr><td width="20%"><code>smb://myworkgroup/</code></td><td>
- /// This syntactically is identical to the above example. However if
- /// <code>myworkgroup</code> happends to be a workgroup(which is indeed
- /// suggested by the name) the <code>list</code> method will return
- /// a list of servers that have registered themselves as members of
- /// <code>myworkgroup</code>.
- /// </td></tr>
- /// <tr><td width="20%"><code>smb://</code></td><td>
- /// Just as <code>smb://server/</code> lists shares and
- /// <code>smb://workgroup/</code> lists servers, the <code>smb://</code>
- /// URL lists all available workgroups on a netbios LAN. Again,
- /// in this context many methods are not valid and return default
- /// values(e.g. <code>isHidden</code> will always return false).
- /// </td></tr>
- /// <tr><td width="20%"><code>smb://angus.foo.net/d/jcifs/pipes.doc</code></td><td>
- /// The server name may also be a DNS name as it is in this example. See
- /// <a href="../../../resolver.html">Setting Name Resolution Properties</a>
- /// for details.
- /// </td></tr>
- /// <tr><td width="20%"><code>smb://192.168.1.15/ADMIN$/</code></td><td>
- /// The server name may also be an IP address. See &lt;a
- /// href="../../../resolver.html"&gt;Setting Name Resolution Properties</a>
- /// for details.
- /// </td></tr>
- /// <tr><td width="20%">
- /// <code>smb://domain;username:password@server/share/path/to/file.txt</code></td><td>
- /// A prototypical example that uses all the fields.
- /// </td></tr>
- /// <tr><td width="20%"><code>smb://myworkgroup/angus/ &lt;-- ILLEGAL </code></td><td>
- /// Despite the hierarchial relationship between workgroups, servers, and
- /// filesystems this example is not valid.
- /// </td></tr>
- /// <tr><td width="20%">
- /// <code>smb://server/share/path/to/dir &lt;-- ILLEGAL </code></td><td>
- /// URLs that represent workgroups, servers, shares, or directories require a trailing slash '/'.
- /// </td></tr>
- /// <tr><td width="20%">
- /// <code>smb://MYGROUP/?SERVER=192.168.10.15</code></td><td>
- /// SMB URLs support some query string parameters. In this example
- /// the <code>SERVER</code> parameter is used to override the
- /// server name service lookup to contact the server 192.168.10.15
- /// (presumably known to be a master
- /// browser) for the server list in workgroup <code>MYGROUP</code>.
- /// </td></tr>
- /// </table>
- /// <p>A second constructor argument may be specified to augment the URL
- /// for better programmatic control when processing many files under
- /// a common base. This is slightly different from the corresponding
- /// <code>java.io.File</code> usage; a '/' at the beginning of the second
- /// parameter will still use the server component of the first parameter. The
- /// examples below illustrate the resulting URLs when this second contructor
- /// argument is used.
- /// <p><table border="1" cellpadding="3" cellspacing="0" width="100%">
- /// <tr bgcolor="#ccccff">
- /// <td colspan="3">
- /// <b>Examples Of SMB URLs When Augmented With A Second Constructor Parameter</b></td>
- /// <tr><td width="20%">
- /// <b>First Parameter</b></td><td><b>Second Parameter</b></td><td><b>Result</b></td></tr>
- /// <tr><td width="20%"><code>
- /// smb://host/share/a/b/
- /// </code></td><td width="20%"><code>
- /// c/d/
- /// </code></td><td><code>
- /// smb://host/share/a/b/c/d/
- /// </code></td></tr>
- /// <tr><td width="20%"><code>
- /// smb://host/share/foo/bar/
- /// </code></td><td width="20%"><code>
- /// /share2/zig/zag
- /// </code></td><td><code>
- /// smb://host/share2/zig/zag
- /// </code></td></tr>
- /// <tr><td width="20%"><code>
- /// smb://host/share/foo/bar/
- /// </code></td><td width="20%"><code>
- /// ../zip/
- /// </code></td><td><code>
- /// smb://host/share/foo/zip/
- /// </code></td></tr>
- /// <tr><td width="20%"><code>
- /// smb://host/share/zig/zag
- /// </code></td><td width="20%"><code>
- /// smb://foo/bar/
- /// </code></td><td><code>
- /// smb://foo/bar/
- /// </code></td></tr>
- /// <tr><td width="20%"><code>
- /// smb://host/share/foo/
- /// </code></td><td width="20%"><code>
- /// ../.././.././../foo/
- /// </code></td><td><code>
- /// smb://host/foo/
- /// </code></td></tr>
- /// <tr><td width="20%"><code>
- /// smb://host/share/zig/zag
- /// </code></td><td width="20%"><code>
- /// /
- /// </code></td><td><code>
- /// smb://host/
- /// </code></td></tr>
- /// <tr><td width="20%"><code>
- /// smb://server/
- /// </code></td><td width="20%"><code>
- /// ../
- /// </code></td><td><code>
- /// smb://server/
- /// </code></td></tr>
- /// <tr><td width="20%"><code>
- /// smb://
- /// </code></td><td width="20%"><code>
- /// myworkgroup/
- /// </code></td><td><code>
- /// smb://myworkgroup/
- /// </code></td></tr>
- /// <tr><td width="20%"><code>
- /// smb://myworkgroup/
- /// </code></td><td width="20%"><code>
- /// angus/
- /// </code></td><td><code>
- /// smb://myworkgroup/angus/ &lt;-- ILLEGAL<br />(But if you first create an <tt>SmbFile</tt> with 'smb://workgroup/' and use and use it as the first parameter to a constructor that accepts it with a second <tt>String</tt> parameter jCIFS will factor out the 'workgroup'.)
- /// </code></td></tr>
- /// </table>
- /// <p>Instances of the <code>SmbFile</code> class are immutable; that is,
- /// once created, the abstract pathname represented by an SmbFile object
- /// will never change.
- /// </remarks>
- /// <seealso cref="FilePath">Sharpen.FilePath</seealso>
- public class SmbFile : UrlConnection
- {
- internal const int ORdonly = 0x01;
-
- internal const int OWronly = 0x02;
-
- internal const int ORdwr = 0x03;
-
- internal const int OAppend = 0x04;
-
- internal const int OCreat = 0x0010;
-
- internal const int OExcl = 0x0020;
-
- internal const int OTrunc = 0x0040;
-
- /// <summary>
- /// When specified as the <tt>shareAccess</tt> constructor parameter,
- /// other SMB clients (including other threads making calls into jCIFS)
- /// will not be permitted to access the target file and will receive "The
- /// file is being accessed by another process" message.
- /// </summary>
- /// <remarks>
- /// When specified as the <tt>shareAccess</tt> constructor parameter,
- /// other SMB clients (including other threads making calls into jCIFS)
- /// will not be permitted to access the target file and will receive "The
- /// file is being accessed by another process" message.
- /// </remarks>
- public const int FileNoShare = 0x00;
-
- /// <summary>
- /// When specified as the <tt>shareAccess</tt> constructor parameter,
- /// other SMB clients will be permitted to read from the target file while
- /// this file is open.
- /// </summary>
- /// <remarks>
- /// When specified as the <tt>shareAccess</tt> constructor parameter,
- /// other SMB clients will be permitted to read from the target file while
- /// this file is open. This constant may be logically OR'd with other share
- /// access flags.
- /// </remarks>
- public const int FileShareRead = 0x01;
-
- /// <summary>
- /// When specified as the <tt>shareAccess</tt> constructor parameter,
- /// other SMB clients will be permitted to write to the target file while
- /// this file is open.
- /// </summary>
- /// <remarks>
- /// When specified as the <tt>shareAccess</tt> constructor parameter,
- /// other SMB clients will be permitted to write to the target file while
- /// this file is open. This constant may be logically OR'd with other share
- /// access flags.
- /// </remarks>
- public const int FileShareWrite = 0x02;
-
- /// <summary>
- /// When specified as the <tt>shareAccess</tt> constructor parameter,
- /// other SMB clients will be permitted to delete the target file while
- /// this file is open.
- /// </summary>
- /// <remarks>
- /// When specified as the <tt>shareAccess</tt> constructor parameter,
- /// other SMB clients will be permitted to delete the target file while
- /// this file is open. This constant may be logically OR'd with other share
- /// access flags.
- /// </remarks>
- public const int FileShareDelete = 0x04;
-
- /// <summary>
- /// A file with this bit on as returned by <tt>getAttributes()</tt> or set
- /// with <tt>setAttributes()</tt> will be read-only
- /// </summary>
- public const int AttrReadonly = 0x01;
-
- /// <summary>
- /// A file with this bit on as returned by <tt>getAttributes()</tt> or set
- /// with <tt>setAttributes()</tt> will be hidden
- /// </summary>
- public const int AttrHidden = 0x02;
-
- /// <summary>
- /// A file with this bit on as returned by <tt>getAttributes()</tt> or set
- /// with <tt>setAttributes()</tt> will be a system file
- /// </summary>
- public const int AttrSystem = 0x04;
-
- /// <summary>
- /// A file with this bit on as returned by <tt>getAttributes()</tt> is
- /// a volume
- /// </summary>
- public const int AttrVolume = 0x08;
-
- /// <summary>
- /// A file with this bit on as returned by <tt>getAttributes()</tt> is
- /// a directory
- /// </summary>
- public const int AttrDirectory = 0x10;
-
- /// <summary>
- /// A file with this bit on as returned by <tt>getAttributes()</tt> or set
- /// with <tt>setAttributes()</tt> is an archived file
- /// </summary>
- public const int AttrArchive = 0x20;
-
- internal const int AttrCompressed = 0x800;
-
- internal const int AttrNormal = 0x080;
-
- internal const int AttrTemporary = 0x100;
-
- internal const int AttrGetMask = 0x7FFF;
-
- internal const int AttrSetMask = 0x30A7;
-
- internal const int DefaultAttrExpirationPeriod = 5000;
-
- internal static readonly int HashDot = ".".GetHashCode();
-
- internal static readonly int HashDotDot = "..".GetHashCode();
-
- //internal static LogStream log = LogStream.GetInstance();
- public LogStream Log
- {
- get { return LogStream.GetInstance(); }
- }
-
- internal static long AttrExpirationPeriod;
-
- internal static bool IgnoreCopyToException;
-
- static SmbFile()
- {
- // Open Function Encoding
- // create if the file does not exist
- // fail if the file exists
- // truncate if the file exists
- // share access
- // file attribute encoding
- // extended file attribute encoding(others same as above)
- /*try
- {
- Sharpen.Runtime.GetType("jcifs.Config");
- }
- catch (TypeLoadException cnfe)
- {
- Sharpen.Runtime.PrintStackTrace(cnfe);
- }*/
-
- AttrExpirationPeriod = Config.GetLong("jcifs.smb.client.attrExpirationPeriod", DefaultAttrExpirationPeriod
- );
- IgnoreCopyToException = Config.GetBoolean("jcifs.smb.client.ignoreCopyToException"
- , true);
- Dfs = new Dfs();
- }
-
- /// <summary>
- /// Returned by
- /// <see cref="GetType()">GetType()</see>
- /// if the resource this <tt>SmbFile</tt>
- /// represents is a regular file or directory.
- /// </summary>
- public const int TypeFilesystem = 0x01;
-
- /// <summary>
- /// Returned by
- /// <see cref="GetType()">GetType()</see>
- /// if the resource this <tt>SmbFile</tt>
- /// represents is a workgroup.
- /// </summary>
- public const int TypeWorkgroup = 0x02;
-
- /// <summary>
- /// Returned by
- /// <see cref="GetType()">GetType()</see>
- /// if the resource this <tt>SmbFile</tt>
- /// represents is a server.
- /// </summary>
- public const int TypeServer = 0x04;
-
- /// <summary>
- /// Returned by
- /// <see cref="GetType()">GetType()</see>
- /// if the resource this <tt>SmbFile</tt>
- /// represents is a share.
- /// </summary>
- public const int TypeShare = 0x08;
-
- /// <summary>
- /// Returned by
- /// <see cref="GetType()">GetType()</see>
- /// if the resource this <tt>SmbFile</tt>
- /// represents is a named pipe.
- /// </summary>
- public const int TypeNamedPipe = 0x10;
-
- /// <summary>
- /// Returned by
- /// <see cref="GetType()">GetType()</see>
- /// if the resource this <tt>SmbFile</tt>
- /// represents is a printer.
- /// </summary>
- public const int TypePrinter = 0x20;
-
- /// <summary>
- /// Returned by
- /// <see cref="GetType()">GetType()</see>
- /// if the resource this <tt>SmbFile</tt>
- /// represents is a communications device.
- /// </summary>
- public const int TypeComm = 0x40;
-
- private string _canon;
-
- private string _share;
-
- private long _createTime;
-
- private long _lastModified;
-
- private int _attributes;
-
- private long _attrExpiration;
-
- private long _size;
-
- private long _sizeExpiration;
-
- private bool _isExists;
-
- private int _shareAccess = FileShareRead | FileShareWrite | FileShareDelete;
-
- private bool _enableDfs = Config.GetBoolean("jcifs.smb.client.enabledfs", false);
-
- private SmbComBlankResponse _blankResp;
-
- private DfsReferral _dfsReferral;
-
- protected internal static Dfs Dfs;
-
- internal NtlmPasswordAuthentication Auth;
-
- internal SmbTree Tree;
-
- internal string Unc;
-
- internal int Fid;
-
- internal int Type;
-
- internal bool Opened;
-
- internal int TreeNum;
-
- public bool EnableDfs
- {
- get { return _enableDfs; }
- set { _enableDfs = value; }
- }
-
- /// <summary>
- /// Constructs an SmbFile representing a resource on an SMB network such as
- /// a file or directory.
- /// </summary>
- /// <remarks>
- /// Constructs an SmbFile representing a resource on an SMB network such as
- /// a file or directory. See the description and examples of smb URLs above.
- /// </remarks>
- /// <param name="url">A URL string</param>
- /// <exception cref="System.UriFormatException">
- /// If the <code>parent</code> and <code>child</code> parameters
- /// do not follow the prescribed syntax
- /// </exception>
- public SmbFile(string url)
- : this(new Uri(url))
- {
- }
-
- /// <summary>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory.
- /// </summary>
- /// <remarks>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory. The second parameter is a relative path from
- /// the <code>parent SmbFile</code>. See the description above for examples
- /// of using the second <code>name</code> parameter.
- /// </remarks>
- /// <param name="context">A base <code>SmbFile</code></param>
- /// <param name="name">A path string relative to the <code>parent</code> paremeter</param>
- /// <exception cref="System.UriFormatException">
- /// If the <code>parent</code> and <code>child</code> parameters
- /// do not follow the prescribed syntax
- /// </exception>
- /// <exception cref="UnknownHostException">If the server or workgroup of the <tt>context</tt> file cannot be determined
- /// </exception>
- public SmbFile(SmbFile context, string name)
- : this(context.IsWorkgroup0
- () ? new Uri("smb://" + name) : new Uri(context.Url.AbsoluteUri + name),
- context.Auth)
- {
-
- this._enableDfs = context.EnableDfs;
-
- if (!context.IsWorkgroup0())
- {
- Addresses = context.Addresses;
-
- if (context._share != null)
- {
- Tree = context.Tree;
- _dfsReferral = context._dfsReferral;
- }
- }
- }
-
- /// <summary>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory.
- /// </summary>
- /// <remarks>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory. The second parameter is a relative path from
- /// the <code>parent</code>. See the description above for examples of
- /// using the second <code>chile</code> parameter.
- /// </remarks>
- /// <param name="context">A URL string</param>
- /// <param name="name">A path string relative to the <code>context</code> paremeter</param>
- /// <exception cref="System.UriFormatException">
- /// If the <code>context</code> and <code>name</code> parameters
- /// do not follow the prescribed syntax
- /// </exception>
- /*public SmbFile(string context, string name)
- : this(new Uri(new Uri(null, context), name))
- {
- }*/
-
- public SmbFile(string context, string name)
- : this(new Uri(context + name))
- {
-
- }
-
-
- /// <summary>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory.
- /// </summary>
- /// <remarks>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory.
- /// </remarks>
- /// <param name="url">A URL string</param>
- /// <param name="auth">The credentials the client should use for authentication</param>
- /// <exception cref="System.UriFormatException">If the <code>url</code> parameter does not follow the prescribed syntax
- /// </exception>
- public SmbFile(string url, NtlmPasswordAuthentication auth)
- : this(new Uri(url, UriKind.RelativeOrAbsolute),
- auth)
- {
-
- }
-
- /// <summary>Constructs an SmbFile representing a file on an SMB network.</summary>
- /// <remarks>
- /// Constructs an SmbFile representing a file on an SMB network. The
- /// <tt>shareAccess</tt> parameter controls what permissions other
- /// clients have when trying to access the same file while this instance
- /// is still open. This value is either <tt>FILE_NO_SHARE</tt> or any
- /// combination of <tt>FILE_SHARE_READ</tt>, <tt>FILE_SHARE_WRITE</tt>,
- /// and <tt>FILE_SHARE_DELETE</tt> logically OR'd together.
- /// </remarks>
- /// <param name="url">A URL string</param>
- /// <param name="auth">The credentials the client should use for authentication</param>
- /// <param name="shareAccess">Specifies what access other clients have while this file is open.
- /// </param>
- /// <exception cref="System.UriFormatException">If the <code>url</code> parameter does not follow the prescribed syntax
- /// </exception>
- public SmbFile(string url, NtlmPasswordAuthentication auth, int shareAccess)
- : this
- (new Uri(url), auth)
- {
- // Initially null; set by getUncPath; dir must end with '/'
- // Can be null
- // For getDfsPath() and getServerWithDfs()
- // Cannot be null
- // Initially null
- // Initially null; set by getUncPath; never ends with '/'
- // Initially 0; set by open()
- if ((shareAccess & ~(FileShareRead | FileShareWrite | FileShareDelete)) !=
- 0)
- {
- throw new RuntimeException("Illegal shareAccess parameter");
- }
- this._shareAccess = shareAccess;
- }
-
- /// <summary>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory.
- /// </summary>
- /// <remarks>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory. The second parameter is a relative path from
- /// the <code>context</code>. See the description above for examples of
- /// using the second <code>name</code> parameter.
- /// </remarks>
- /// <param name="context">A URL string</param>
- /// <param name="name">A path string relative to the <code>context</code> paremeter</param>
- /// <param name="auth">The credentials the client should use for authentication</param>
- /// <exception cref="System.UriFormatException">
- /// If the <code>context</code> and <code>name</code> parameters
- /// do not follow the prescribed syntax
- /// </exception>
- public SmbFile(string context, string name, NtlmPasswordAuthentication auth)
- : this
- (new Uri(context + name)
- , auth)
- {
-
- }
-
-
- /// <summary>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory.
- /// </summary>
- /// <remarks>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory. The second parameter is a relative path from
- /// the <code>context</code>. See the description above for examples of
- /// using the second <code>name</code> parameter. The <tt>shareAccess</tt>
- /// parameter controls what permissions other clients have when trying
- /// to access the same file while this instance is still open. This
- /// value is either <tt>FILE_NO_SHARE</tt> or any combination
- /// of <tt>FILE_SHARE_READ</tt>, <tt>FILE_SHARE_WRITE</tt>, and
- /// <tt>FILE_SHARE_DELETE</tt> logically OR'd together.
- /// </remarks>
- /// <param name="context">A URL string</param>
- /// <param name="name">A path string relative to the <code>context</code> paremeter</param>
- /// <param name="auth">The credentials the client should use for authentication</param>
- /// <param name="shareAccess">Specifies what access other clients have while this file is open.
- /// </param>
- /// <exception cref="System.UriFormatException">
- /// If the <code>context</code> and <code>name</code> parameters
- /// do not follow the prescribed syntax
- /// </exception>
- public SmbFile(string context, string name, NtlmPasswordAuthentication auth, int
- shareAccess)
- : this(new Uri(context + name), auth)
- {
- if ((shareAccess & ~(FileShareRead | FileShareWrite | FileShareDelete)) !=
- 0)
- {
- throw new RuntimeException("Illegal shareAccess parameter");
- }
- this._shareAccess = shareAccess;
- }
-
- /// <summary>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory.
- /// </summary>
- /// <remarks>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory. The second parameter is a relative path from
- /// the <code>context</code>. See the description above for examples of
- /// using the second <code>name</code> parameter. The <tt>shareAccess</tt>
- /// parameter controls what permissions other clients have when trying
- /// to access the same file while this instance is still open. This
- /// value is either <tt>FILE_NO_SHARE</tt> or any combination
- /// of <tt>FILE_SHARE_READ</tt>, <tt>FILE_SHARE_WRITE</tt>, and
- /// <tt>FILE_SHARE_DELETE</tt> logically OR'd together.
- /// </remarks>
- /// <param name="context">A base <code>SmbFile</code></param>
- /// <param name="name">A path string relative to the <code>context</code> file path</param>
- /// <param name="shareAccess">Specifies what access other clients have while this file is open.
- /// </param>
- /// <exception cref="System.UriFormatException">
- /// If the <code>context</code> and <code>name</code> parameters
- /// do not follow the prescribed syntax
- /// </exception>
- /// <exception cref="UnknownHostException"></exception>
- public SmbFile(SmbFile context, string name, int shareAccess)
- : this(context.IsWorkgroup0() ? new Uri("smb://" + name) : new Uri(
- context.Url.AbsoluteUri + name), context.Auth)
- {
- if ((shareAccess & ~(FileShareRead | FileShareWrite | FileShareDelete)) !=
- 0)
- {
- throw new RuntimeException("Illegal shareAccess parameter");
- }
-
- if (!context.IsWorkgroup0())
- {
- this.Addresses = context.Addresses;
-
- if (context._share != null || context.Tree != null)
- {
- Tree = context.Tree;
- _dfsReferral = context._dfsReferral;
- }
- }
-
- this._shareAccess = shareAccess;
- this._enableDfs = context.EnableDfs;
- }
-
- /// <summary>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory from a <tt>URL</tt> object.
- /// </summary>
- /// <remarks>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory from a <tt>URL</tt> object.
- /// </remarks>
- /// <param name="url">The URL of the target resource</param>
- protected SmbFile(Uri url)
- : this(url, new NtlmPasswordAuthentication(url.GetUserInfo
- ()))
- {
- }
-
- /// <summary>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory from a <tt>URL</tt> object and an
- /// <tt>NtlmPasswordAuthentication</tt> object.
- /// </summary>
- /// <remarks>
- /// Constructs an SmbFile representing a resource on an SMB network such
- /// as a file or directory from a <tt>URL</tt> object and an
- /// <tt>NtlmPasswordAuthentication</tt> object.
- /// </remarks>
- /// <param name="url">The URL of the target resource</param>
- /// <param name="auth">The credentials the client should use for authentication</param>
- public SmbFile(Uri url, NtlmPasswordAuthentication auth)
- {
- this.Auth = auth ?? new NtlmPasswordAuthentication(url.GetUserInfo());
- Url = url;
- GetUncPath0();
- }
-
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- /*internal SmbFile(Jcifs.Smb.SmbFile context, string name, int type, int attributes
- , long createTime, long lastModified, long size)
- : this(context.IsWorkgroup0() ?
- new Uri(null, "smb://" + name + "/") : new Uri(context.url,
- name + ((attributes & ATTR_DIRECTORY) > 0 ? "/" : string.Empty)))*/
- internal SmbFile(SmbFile context, string name, int type, int attributes
- , long createTime, long lastModified, long size)
- : this(context.IsWorkgroup0() ?
- new Uri("smb://" + name + "/") : new Uri(context.Url.AbsoluteUri +
- name + ((attributes & AttrDirectory) > 0 ? "/" : string.Empty)))
- {
- Auth = context.Auth;
- if (context._share != null)
- {
- Tree = context.Tree;
- _dfsReferral = context._dfsReferral;
- }
- int last = name.Length - 1;
- if (name[last] == '/')
- {
- name = Runtime.Substring(name, 0, last);
- }
- if (context._share == null)
- {
- Unc = "\\";
- }
- else
- {
- if (context.Unc.Equals("\\"))
- {
- Unc = '\\' + name;
- }
- else
- {
- Unc = context.Unc + '\\' + name;
- }
- }
-
- if (!context.IsWorkgroup0())
- {
- Addresses = context.Addresses;
- }
-
- this._enableDfs = context.EnableDfs;
-
- this.Type = type;
- this._attributes = attributes;
- this._createTime = createTime;
- this._lastModified = lastModified;
- this._size = size;
- _isExists = true;
- _attrExpiration = _sizeExpiration = Runtime.CurrentTimeMillis() + AttrExpirationPeriod;
- }
-
- private SmbComBlankResponse Blank_resp()
- {
- if (_blankResp == null)
- {
- _blankResp = new SmbComBlankResponse();
- }
- return _blankResp;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual void ResolveDfs(ServerMessageBlock request)
- {
- if (!_enableDfs)
- {
- Connect0();
- return;
- }
-
- if (request is SmbComClose)
- {
- return;
- }
- Connect0();
- DfsReferral dr = Dfs.Resolve(Tree.Session.transport.TconHostName, Tree.Share, Unc
- , Auth);
- if (dr != null)
- {
- string service = null;
- if (request != null)
- {
- switch (request.Command)
- {
- case ServerMessageBlock.SmbComTransaction:
- case ServerMessageBlock.SmbComTransaction2:
- {
- switch (((SmbComTransaction)request).SubCommand & 0xFF)
- {
- case SmbComTransaction.Trans2GetDfsReferral:
- {
- break;
- }
-
- default:
- {
- service = "A:";
- break;
- }
- }
- break;
- }
-
- default:
- {
- service = "A:";
- break;
- }
- }
- }
- DfsReferral start = dr;
- SmbException se = null;
- do
- {
- try
- {
- if (Log.Level >= 2)
- {
- Log.WriteLine("DFS redirect: " + dr);
- }
- UniAddress addr = UniAddress.GetByName(dr.Server);
- SmbTransport trans = SmbTransport.GetSmbTransport(addr, Url.Port);
- trans.Connect();
- Tree = trans.GetSmbSession(Auth).GetSmbTree(dr.Share, service);
- if (dr != start && dr.Key != null)
- {
- dr.Map.Put(dr.Key, dr);
- }
- se = null;
- break;
- }
- catch (IOException ioe)
- {
- if (ioe is SmbException)
- {
- se = (SmbException)ioe;
- }
- else
- {
- se = new SmbException(dr.Server, ioe);
- }
- }
- dr = dr.Next;
- }
- while (dr != start);
- if (se != null)
- {
- throw se;
- }
- if (Log.Level >= 3)
- {
- Log.WriteLine(dr);
- }
- _dfsReferral = dr;
- if (dr.PathConsumed < 0)
- {
- dr.PathConsumed = 0;
- }
- else
- {
- if (dr.PathConsumed > Unc.Length)
- {
- dr.PathConsumed = Unc.Length;
- }
- }
- string dunc = Runtime.Substring(Unc, dr.PathConsumed);
- if (dunc.Equals(string.Empty))
- {
- dunc = "\\";
- }
- if (!dr.Path.Equals(string.Empty))
- {
- dunc = "\\" + dr.Path + dunc;
- }
- Unc = dunc;
- if (request != null && request.Path != null && request.Path.EndsWith("\\") && dunc
- .EndsWith("\\") == false)
- {
- dunc += "\\";
- }
- if (request != null)
- {
- request.Path = dunc;
- request.Flags2 |= SmbConstants.Flags2ResolvePathsInDfs;
- }
- }
- else
- {
- if (Tree.InDomainDfs && !(request is NtTransQuerySecurityDesc) && !(request is SmbComClose
- ) && !(request is SmbComFindClose2))
- {
- throw new SmbException(NtStatus.NtStatusNotFound, false);
- }
- if (request != null)
- {
- request.Flags2 &= ~SmbConstants.Flags2ResolvePathsInDfs;
- }
- }
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual void Send(ServerMessageBlock request, ServerMessageBlock response
- )
- {
- for (; ; )
- {
- ResolveDfs(request);
- try
- {
- Tree.Send(request, response);
- break;
- }
- catch (DfsReferral dre)
- {
- if (dre.ResolveHashes)
- {
- throw;
- }
- request.Reset();
- }
- }
- }
-
- internal static string QueryLookup(string query, string param)
- {
- char[] instr = query.ToCharArray();
- int i;
- int ch;
- int st;
- int eq;
- st = eq = 0;
- for (i = 0; i < instr.Length; i++)
- {
- ch = instr[i];
- if (ch == '&')
- {
- if (eq > st)
- {
- string p = new string(instr, st, eq - st);
- if (Runtime.EqualsIgnoreCase(p, param))
- {
- eq++;
- return new string(instr, eq, i - eq);
- }
- }
- st = i + 1;
- }
- else
- {
- if (ch == '=')
- {
- eq = i;
- }
- }
- }
- if (eq > st)
- {
- string p = new string(instr, st, eq - st);
- if (Runtime.EqualsIgnoreCase(p, param))
- {
- eq++;
- return new string(instr, eq, instr.Length - eq);
- }
- }
- return null;
- }
-
- internal UniAddress[] Addresses;
-
- internal int AddressIndex;
-
- /// <exception cref="UnknownHostException"></exception>
- internal virtual UniAddress GetAddress()
- {
- if (AddressIndex == 0)
- {
- return GetFirstAddress();
- }
- return Addresses[AddressIndex - 1];
- }
-
- /// <exception cref="UnknownHostException"></exception>
- internal virtual UniAddress GetFirstAddress()
- {
- AddressIndex = 0;
- string host = Url.GetHost();
- string path = Url.AbsolutePath;
- string query = Url.GetQuery();
-
- if (Addresses != null && Addresses.Length > 0)
- {
- return GetNextAddress();
- }
-
- if (query != null)
- {
- string server = QueryLookup(query, "server");
- if (!string.IsNullOrEmpty(server))
- {
- Addresses = new UniAddress[1];
- Addresses[0] = UniAddress.GetByName(server);
- return GetNextAddress();
- }
- string address = QueryLookup(query, "address");
- if (!string.IsNullOrEmpty(address))
- {
- byte[] ip = Extensions.GetAddressByName(address).GetAddressBytes();
- Addresses = new UniAddress[1];
- //addresses[0] = new UniAddress(IPAddress.Parse(host, ip));
- Addresses[0] = new UniAddress(IPAddress.Parse(host));
- return GetNextAddress();
- }
- }
- if (host.Length == 0)
- {
- try
- {
- NbtAddress addr = NbtAddress.GetByName(NbtAddress.MasterBrowserName, 0x01, null);
- Addresses = new UniAddress[1];
- Addresses[0] = UniAddress.GetByName(addr.GetHostAddress());
- }
- catch (UnknownHostException uhe)
- {
- NtlmPasswordAuthentication.InitDefaults();
- if (NtlmPasswordAuthentication.DefaultDomain.Equals("?"))
- {
- throw;
- }
- Addresses = UniAddress.GetAllByName(NtlmPasswordAuthentication.DefaultDomain, true
- );
- }
- }
- else
- {
- if (path.Length == 0 || path.Equals("/"))
- {
- Addresses = UniAddress.GetAllByName(host, true);
- }
- else
- {
- Addresses = UniAddress.GetAllByName(host, false);
- }
- }
- return GetNextAddress();
- }
-
- internal virtual UniAddress GetNextAddress()
- {
- UniAddress addr = null;
- if (AddressIndex < Addresses.Length)
- {
- addr = Addresses[AddressIndex++];
- }
- return addr;
- }
-
- internal virtual bool HasNextAddress()
- {
- return AddressIndex < Addresses.Length;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual void Connect0()
- {
- try
- {
- Connect();
- }
- catch (UnknownHostException uhe)
- {
- throw new SmbException("Failed to connect to server", uhe);
- }
- catch (SmbException se)
- {
- throw;
- }
- catch (IOException ioe)
- {
- throw new SmbException("Failed to connect to server", ioe);
- }
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- internal virtual void DoConnect()
- {
- SmbTransport trans;
- UniAddress addr;
- addr = GetAddress();
-
- if (Tree != null && Tree.Session.transport.Address.Equals(addr))
- {
- trans = Tree.Session.transport;
- }
- else
- {
- trans = SmbTransport.GetSmbTransport(addr, Url.Port);
- Tree = trans.GetSmbSession(Auth).GetSmbTree(_share, null);
- }
-
-
- string hostName = GetServerWithDfs();
- if (_enableDfs)
- {
- Tree.InDomainDfs = Dfs.Resolve(hostName, Tree.Share, null, Auth) != null;
- }
- if (Tree.InDomainDfs)
- {
- Tree.ConnectionState = 2;
- }
- try
- {
- if (Log.Level >= 3)
- {
- Log.WriteLine("doConnect: " + addr);
- }
- Tree.TreeConnect(null, null);
- }
- catch (SmbAuthException sae)
- {
- NtlmPasswordAuthentication a;
- SmbSession ssn;
- if (_share == null)
- {
- // IPC$ - try "anonymous" credentials
- ssn = trans.GetSmbSession(NtlmPasswordAuthentication.Null);
- Tree = ssn.GetSmbTree(null, null);
- Tree.TreeConnect(null, null);
- }
- else
- {
- if ((a = NtlmAuthenticator.RequestNtlmPasswordAuthentication(Url.ToString(), sae)
- ) != null)
- {
- Auth = a;
- ssn = trans.GetSmbSession(Auth);
- Tree = ssn.GetSmbTree(_share, null);
- Tree.InDomainDfs = Dfs.Resolve(hostName, Tree.Share, null, Auth) != null;
- if (Tree.InDomainDfs)
- {
- Tree.ConnectionState = 2;
- }
- Tree.TreeConnect(null, null);
- }
- else
- {
- if (Log.Level >= 1 && HasNextAddress())
- {
- Runtime.PrintStackTrace(sae, Log);
- }
- throw;
- }
- }
- }
- }
-
- /// <summary>It is not necessary to call this method directly.</summary>
- /// <remarks>
- /// It is not necessary to call this method directly. This is the
- /// <tt>URLConnection</tt> implementation of <tt>connect()</tt>.
- /// </remarks>
- /// <exception cref="System.IO.IOException"></exception>
- public void Connect()
- {
- SmbTransport trans;
- SmbSession ssn;
- UniAddress addr;
- if (IsConnected())
- {
- return;
- }
- GetUncPath0();
- GetFirstAddress();
- for (; ; )
- {
- try
- {
- DoConnect();
- return;
- }
- catch (SmbAuthException sae)
- {
- throw;
- }
- catch (SmbException se)
- {
- // Prevents account lockout on servers with multiple IPs
- if (GetNextAddress() == null)
- {
- throw;
- }
- else
- {
- RemoveCurrentAddress();
- }
-
- if (Log.Level >= 3)
- {
- Runtime.PrintStackTrace(se, Log);
- }
- }
- }
- }
-
- internal virtual bool IsConnected()
- {
- return Tree != null && Tree.ConnectionState == 2;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual int Open0(int flags, int access, int attrs, int options)
- {
- int f;
- Connect0();
- if (Log.Level >= 3)
- {
- Log.WriteLine("open0: " + Unc);
- }
- if (Tree.Session.transport.HasCapability(SmbConstants.CapNtSmbs))
- {
- SmbComNtCreateAndXResponse response = new SmbComNtCreateAndXResponse();
- SmbComNtCreateAndX request = new SmbComNtCreateAndX(Unc, flags, access, _shareAccess
- , attrs, options, null);
- if (this is SmbNamedPipe)
- {
- request.Flags0 |= 0x16;
- request.DesiredAccess |= 0x20000;
- response.IsExtended = true;
- }
- Send(request, response);
- f = response.Fid;
- _attributes = response.ExtFileAttributes & AttrGetMask;
- _attrExpiration = Runtime.CurrentTimeMillis() + AttrExpirationPeriod;
- _isExists = true;
- }
- else
- {
- SmbComOpenAndXResponse response = new SmbComOpenAndXResponse();
- Send(new SmbComOpenAndX(Unc, access, flags, null), response);
- f = response.Fid;
- }
- return f;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual void Open(int flags, int access, int attrs, int options)
- {
- if (IsOpen())
- {
- return;
- }
- Fid = Open0(flags, access, attrs, options);
- Opened = true;
- TreeNum = Tree.TreeNum;
- }
-
- internal virtual bool IsOpen()
- {
- bool ans = Opened && IsConnected() && TreeNum == Tree.TreeNum;
- return ans;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual void Close(int f, long lastWriteTime)
- {
- if (Log.Level >= 3)
- {
- Log.WriteLine("close: " + f);
- }
- Send(new SmbComClose(f, lastWriteTime), Blank_resp());
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual void Close(long lastWriteTime)
- {
- if (IsOpen() == false)
- {
- return;
- }
- Close(Fid, lastWriteTime);
- Opened = false;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual void Close()
- {
- Close(0L);
- }
-
- /// <summary>
- /// Returns the <tt>NtlmPasswordAuthentication</tt> object used as
- /// credentials with this file or pipe.
- /// </summary>
- /// <remarks>
- /// Returns the <tt>NtlmPasswordAuthentication</tt> object used as
- /// credentials with this file or pipe. This can be used to retrieve the
- /// username for example:
- /// <tt>
- /// String username = f.getPrincipal().getName();
- /// </tt>
- /// The <tt>Principal</tt> object returned will never be <tt>null</tt>
- /// however the username can be <tt>null</tt> indication anonymous
- /// credentials were used (e.g. some IPC$ services).
- /// </remarks>
- public virtual Principal GetPrincipal()
- {
- return Auth;
- }
-
- /// <summary>Returns the last component of the target URL.</summary>
- /// <remarks>
- /// Returns the last component of the target URL. This will
- /// effectively be the name of the file or directory represented by this
- /// <code>SmbFile</code> or in the case of URLs that only specify a server
- /// or workgroup, the server or workgroup will be returned. The name of
- /// the root URL <code>smb://</code> is also <code>smb://</code>. If this
- /// <tt>SmbFile</tt> refers to a workgroup, server, share, or directory,
- /// the name will include a trailing slash '/' so that composing new
- /// <tt>SmbFile</tt>s will maintain the trailing slash requirement.
- /// </remarks>
- /// <returns>
- /// The last component of the URL associated with this SMB
- /// resource or <code>smb://</code> if the resource is <code>smb://</code>
- /// itself.
- /// </returns>
- public virtual string GetName()
- {
- GetUncPath0();
- if (_canon.Length > 1)
- {
- int i = _canon.Length - 2;
- while (_canon[i] != '/')
- {
- i--;
- }
- return Runtime.Substring(_canon, i + 1);
- }
- if (_share != null)
- {
- return _share + '/';
- }
- if (Url.GetHost().Length > 0)
- {
- return Url.GetHost() + '/';
- }
- return "smb://";
- }
-
- /// <summary>
- /// Everything but the last component of the URL representing this SMB
- /// resource is effectivly it's parent.
- /// </summary>
- /// <remarks>
- /// Everything but the last component of the URL representing this SMB
- /// resource is effectivly it's parent. The root URL <code>smb://</code>
- /// does not have a parent. In this case <code>smb://</code> is returned.
- /// </remarks>
- /// <returns>
- /// The parent directory of this SMB resource or
- /// <code>smb://</code> if the resource refers to the root of the URL
- /// hierarchy which incedentally is also <code>smb://</code>.
- /// </returns>
- public virtual string GetParent()
- {
- string str = Url.Authority;
- if (str.Length > 0)
- {
- StringBuilder sb = new StringBuilder("smb://");
- sb.Append(str);
- GetUncPath0();
- if (_canon.Length > 1)
- {
- sb.Append(_canon);
- }
- else
- {
- sb.Append('/');
- }
- str = sb.ToString();
- int i = str.Length - 2;
- while (str[i] != '/')
- {
- i--;
- }
- return Runtime.Substring(str, 0, i + 1);
- }
- return "smb://";
- }
-
- /// <summary>Returns the full uncanonicalized URL of this SMB resource.</summary>
- /// <remarks>
- /// Returns the full uncanonicalized URL of this SMB resource. An
- /// <code>SmbFile</code> constructed with the result of this method will
- /// result in an <code>SmbFile</code> that is equal to the original.
- /// </remarks>
- /// <returns>The uncanonicalized full URL of this SMB resource.</returns>
- public virtual string GetPath()
- {
- return Url.ToString();
- }
-
- internal virtual string GetUncPath0()
- {
- if (Unc == null)
- {
- char[] instr = Url.LocalPath.ToCharArray();
- char[] outstr = new char[instr.Length];
- int length = instr.Length;
- int i;
- int o;
- int state;
-
- state = 0;
- o = 0;
- for (i = 0; i < length; i++)
- {
- switch (state)
- {
- case 0:
- {
- if (instr[i] != '/')
- {
- return null;
- }
- outstr[o++] = instr[i];
- state = 1;
- break;
- }
-
- case 1:
- {
- if (instr[i] == '/')
- {
- break;
- }
- if (instr[i] == '.' && ((i + 1) >= length || instr[i + 1] == '/'))
- {
- i++;
- break;
- }
- if ((i + 1) < length && instr[i] == '.' && instr[i + 1] == '.' && ((i + 2) >= length
- || instr[i + 2] == '/'))
- {
- i += 2;
- if (o == 1)
- {
- break;
- }
- do
- {
- o--;
- }
- while (o > 1 && outstr[o - 1] != '/');
- break;
- }
- state = 2;
- goto case 2;
- }
-
- case 2:
- {
- if (instr[i] == '/')
- {
- state = 1;
- }
- outstr[o++] = instr[i];
- break;
- }
- }
- }
- _canon = new string(outstr, 0, o);
- if (o > 1)
- {
- o--;
- i = _canon.IndexOf('/', 1);
- if (i < 0)
- {
- _share = Runtime.Substring(_canon, 1);
- Unc = "\\";
- }
- else
- {
- if (i == o)
- {
- _share = Runtime.Substring(_canon, 1, i);
- Unc = "\\";
- }
- else
- {
- _share = Runtime.Substring(_canon, 1, i);
- Unc = Runtime.Substring(_canon, i, outstr[o] == '/' ? o : o + 1);
- Unc = Unc.Replace('/', '\\');
- }
- }
- }
- else
- {
- _share = null;
- Unc = "\\";
- }
- }
- return Unc;
- }
-
- /// <summary>Retuns the Windows UNC style path with backslashs intead of forward slashes.
- /// </summary>
- /// <remarks>Retuns the Windows UNC style path with backslashs intead of forward slashes.
- /// </remarks>
- /// <returns>The UNC path.</returns>
- public virtual string GetUncPath()
- {
- GetUncPath0();
- if (_share == null)
- {
- return "\\\\" + Url.GetHost();
- }
- return "\\\\" + Url.GetHost() + _canon.Replace('/', '\\');
- }
-
- /// <summary>
- /// Returns the full URL of this SMB resource with '.' and '..' components
- /// factored out.
- /// </summary>
- /// <remarks>
- /// Returns the full URL of this SMB resource with '.' and '..' components
- /// factored out. An <code>SmbFile</code> constructed with the result of
- /// this method will result in an <code>SmbFile</code> that is equal to
- /// the original.
- /// </remarks>
- /// <returns>The canonicalized URL of this SMB resource.</returns>
- public virtual string GetCanonicalPath()
- {
- string str = Url.Authority;
- GetUncPath0();
- if (str.Length > 0)
- {
- return "smb://" + Url.Authority + _canon;
- }
- return "smb://";
- }
-
- /// <summary>Retrieves the share associated with this SMB resource.</summary>
- /// <remarks>
- /// Retrieves the share associated with this SMB resource. In
- /// the case of <code>smb://</code>, <code>smb://workgroup/</code>,
- /// and <code>smb://server/</code> URLs which do not specify a share,
- /// <code>null</code> will be returned.
- /// </remarks>
- /// <returns>The share component or <code>null</code> if there is no share</returns>
- public virtual string GetShare()
- {
- return _share;
- }
-
- internal virtual string GetServerWithDfs()
- {
- if (_dfsReferral != null)
- {
- return _dfsReferral.Server;
- }
- return GetServer();
- }
-
- /// <summary>Retrieve the hostname of the server for this SMB resource.</summary>
- /// <remarks>
- /// Retrieve the hostname of the server for this SMB resource. If this
- /// <code>SmbFile</code> references a workgroup, the name of the workgroup
- /// is returned. If this <code>SmbFile</code> refers to the root of this
- /// SMB network hierarchy, <code>null</code> is returned.
- /// </remarks>
- /// <returns>
- /// The server or workgroup name or <code>null</code> if this
- /// <code>SmbFile</code> refers to the root <code>smb://</code> resource.
- /// </returns>
- public virtual string GetServer()
- {
- string str = Url.GetHost();
- if (str.Length == 0)
- {
- return null;
- }
- return str;
- }
-
- /// <summary>Returns type of of object this <tt>SmbFile</tt> represents.</summary>
- /// <remarks>Returns type of of object this <tt>SmbFile</tt> represents.</remarks>
- /// <returns>
- /// <tt>TYPE_FILESYSTEM, TYPE_WORKGROUP, TYPE_SERVER, TYPE_SHARE,
- /// TYPE_PRINTER, TYPE_NAMED_PIPE</tt>, or <tt>TYPE_COMM</tt>.
- /// </returns>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public new virtual int GetType()
- {
- if (Type == 0)
- {
- if (GetUncPath0().Length > 1)
- {
- Type = TypeFilesystem;
- }
- else
- {
- if (_share != null)
- {
- // treeConnect good enough to test service type
- Connect0();
- if (_share.Equals("IPC$"))
- {
- Type = TypeNamedPipe;
- }
- else
- {
- if (Tree.Service.Equals("LPT1:"))
- {
- Type = TypePrinter;
- }
- else
- {
- if (Tree.Service.Equals("COMM"))
- {
- Type = TypeComm;
- }
- else
- {
- Type = TypeShare;
- }
- }
- }
- }
- else
- {
- if (string.IsNullOrEmpty(Url.Authority))
- {
- Type = TypeWorkgroup;
- }
- else
- {
- UniAddress addr;
- try
- {
- addr = GetAddress();
- }
- catch (UnknownHostException uhe)
- {
- throw new SmbException(Url.ToString(), uhe);
- }
- if (addr.GetAddress() is NbtAddress)
- {
- int code = ((NbtAddress)addr.GetAddress()).GetNameType();
- if (code == 0x1d || code == 0x1b)
- {
- Type = TypeWorkgroup;
- return Type;
- }
- }
- Type = TypeServer;
- }
- }
- }
- }
- return Type;
- }
-
- /// <exception cref="UnknownHostException"></exception>
- internal virtual bool IsWorkgroup0()
- {
- if (Type == TypeWorkgroup || Url.GetHost().Length == 0)
- {
- Type = TypeWorkgroup;
- return true;
- }
- GetUncPath0();
- if (_share == null)
- {
- UniAddress addr = GetAddress();
- if (addr.GetAddress() is NbtAddress)
- {
- int code = ((NbtAddress)addr.GetAddress()).GetNameType();
- if (code == 0x1d || code == 0x1b)
- {
- Type = TypeWorkgroup;
- return true;
- }
- }
- Type = TypeServer;
- }
- return false;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual IInfo QueryPath(string path, int infoLevel)
- {
- Connect0();
- if (Log.Level >= 3)
- {
- Log.WriteLine("queryPath: " + path);
- }
- if (Tree.Session.transport.HasCapability(SmbConstants.CapNtSmbs))
- {
- Trans2QueryPathInformationResponse response = new Trans2QueryPathInformationResponse
- (infoLevel);
- Send(new Trans2QueryPathInformation(path, infoLevel), response);
- return response.Info;
- }
- else
- {
- SmbComQueryInformationResponse response = new SmbComQueryInformationResponse(Tree
- .Session.transport.Server.ServerTimeZone * 1000 * 60L);
- Send(new SmbComQueryInformation(path), response);
- return response;
- }
- }
-
- /// <summary>Tests to see if the SMB resource exists.</summary>
- /// <remarks>
- /// Tests to see if the SMB resource exists. If the resource refers
- /// only to a server, this method determines if the server exists on the
- /// network and is advertising SMB services. If this resource refers to
- /// a workgroup, this method determines if the workgroup name is valid on
- /// the local SMB network. If this <code>SmbFile</code> refers to the root
- /// <code>smb://</code> resource <code>true</code> is always returned. If
- /// this <code>SmbFile</code> is a traditional file or directory, it will
- /// be queried for on the specified server as expected.
- /// </remarks>
- /// <returns>
- /// <code>true</code> if the resource exists or is alive or
- /// <code>false</code> otherwise
- /// </returns>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual bool Exists()
- {
- if (_attrExpiration > Runtime.CurrentTimeMillis())
- {
- return _isExists;
- }
- _attributes = AttrReadonly | AttrDirectory;
- _createTime = 0L;
- _lastModified = 0L;
- _isExists = false;
- try
- {
- if (Url.GetHost().Length == 0)
- {
- }
- else
- {
- if (_share == null)
- {
- if (GetType() == TypeWorkgroup)
- {
- UniAddress.GetByName(Url.GetHost(), true);
- }
- else
- {
- UniAddress.GetByName(Url.GetHost()).GetHostName();
- }
- }
- else
- {
- if (GetUncPath0().Length == 1 || Runtime.EqualsIgnoreCase(_share, "IPC$"))
- {
- Connect0();
- }
- else
- {
- // treeConnect is good enough
- IInfo info = QueryPath(GetUncPath0(), Trans2QueryPathInformationResponse.SMB_QUERY_FILE_BASIC_INFO
- );
- _attributes = info.GetAttributes();
- _createTime = info.GetCreateTime();
- _lastModified = info.GetLastWriteTime();
- }
- }
- }
- _isExists = true;
- }
- catch (UnknownHostException)
- {
- }
- catch (SmbException se)
- {
- switch (se.GetNtStatus())
- {
- case NtStatus.NtStatusNoSuchFile:
- case NtStatus.NtStatusObjectNameInvalid:
- case NtStatus.NtStatusObjectNameNotFound:
- case NtStatus.NtStatusObjectPathNotFound:
- {
- break;
- }
-
- default:
- {
- throw;
- }
- }
- }
- _attrExpiration = Runtime.CurrentTimeMillis() + AttrExpirationPeriod;
- return _isExists;
- }
-
- /// <summary>
- /// Tests to see if the file this <code>SmbFile</code> represents can be
- /// read.
- /// </summary>
- /// <remarks>
- /// Tests to see if the file this <code>SmbFile</code> represents can be
- /// read. Because any file, directory, or other resource can be read if it
- /// exists, this method simply calls the <code>exists</code> method.
- /// </remarks>
- /// <returns><code>true</code> if the file is read-only</returns>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual bool CanRead()
- {
- if (GetType() == TypeNamedPipe)
- {
- // try opening the pipe for reading?
- return true;
- }
- return Exists();
- }
-
- // try opening and catch sharing violation?
- /// <summary>
- /// Tests to see if the file this <code>SmbFile</code> represents
- /// exists and is not marked read-only.
- /// </summary>
- /// <remarks>
- /// Tests to see if the file this <code>SmbFile</code> represents
- /// exists and is not marked read-only. By default, resources are
- /// considered to be read-only and therefore for <code>smb://</code>,
- /// <code>smb://workgroup/</code>, and <code>smb://server/</code> resources
- /// will be read-only.
- /// </remarks>
- /// <returns>
- /// <code>true</code> if the resource exists is not marked
- /// read-only
- /// </returns>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual bool CanWrite()
- {
- if (GetType() == TypeNamedPipe)
- {
- // try opening the pipe for writing?
- return true;
- }
- return Exists() && (_attributes & AttrReadonly) == 0;
- }
-
- /// <summary>Tests to see if the file this <code>SmbFile</code> represents is a directory.
- /// </summary>
- /// <remarks>Tests to see if the file this <code>SmbFile</code> represents is a directory.
- /// </remarks>
- /// <returns><code>true</code> if this <code>SmbFile</code> is a directory</returns>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual bool IsDirectory()
- {
- if (GetUncPath0().Length == 1)
- {
- return true;
- }
- if (!Exists())
- {
- return false;
- }
- return (_attributes & AttrDirectory) == AttrDirectory;
- }
-
- /// <summary>Tests to see if the file this <code>SmbFile</code> represents is not a directory.
- /// </summary>
- /// <remarks>Tests to see if the file this <code>SmbFile</code> represents is not a directory.
- /// </remarks>
- /// <returns><code>true</code> if this <code>SmbFile</code> is not a directory</returns>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual bool IsFile()
- {
- if (GetUncPath0().Length == 1)
- {
- return false;
- }
- Exists();
- return (_attributes & AttrDirectory) == 0;
- }
-
- /// <summary>
- /// Tests to see if the file this SmbFile represents is marked as
- /// hidden.
- /// </summary>
- /// <remarks>
- /// Tests to see if the file this SmbFile represents is marked as
- /// hidden. This method will also return true for shares with names that
- /// end with '$' such as <code>IPC$</code> or <code>C$</code>.
- /// </remarks>
- /// <returns><code>true</code> if the <code>SmbFile</code> is marked as being hidden</returns>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual bool IsHidden()
- {
- if (_share == null)
- {
- return false;
- }
- if (GetUncPath0().Length == 1)
- {
- if (_share.EndsWith("$"))
- {
- return true;
- }
- return false;
- }
- Exists();
- return (_attributes & AttrHidden) == AttrHidden;
- }
-
- /// <summary>
- /// If the path of this <code>SmbFile</code> falls within a DFS volume,
- /// this method will return the referral path to which it maps.
- /// </summary>
- /// <remarks>
- /// If the path of this <code>SmbFile</code> falls within a DFS volume,
- /// this method will return the referral path to which it maps. Otherwise
- /// <code>null</code> is returned.
- /// </remarks>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual string GetDfsPath()
- {
- ResolveDfs(null);
- if (_dfsReferral == null)
- {
- return null;
- }
- string path = "smb:/" + _dfsReferral.Server + "/" + _dfsReferral.Share + Unc;
- path = path.Replace('\\', '/');
- if (IsDirectory())
- {
- path += '/';
- }
- return path;
- }
-
- /// <summary>Retrieve the time this <code>SmbFile</code> was created.</summary>
- /// <remarks>
- /// Retrieve the time this <code>SmbFile</code> was created. The value
- /// returned is suitable for constructing a
- /// <see cref="System.DateTime">System.DateTime</see>
- /// object
- /// (i.e. seconds since Epoch 1970). Times should be the same as those
- /// reported using the properties dialog of the Windows Explorer program.
- /// For Win95/98/Me this is actually the last write time. It is currently
- /// not possible to retrieve the create time from files on these systems.
- /// </remarks>
- /// <returns>
- /// The number of milliseconds since the 00:00:00 GMT, January 1,
- /// 1970 as a <code>long</code> value
- /// </returns>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual long CreateTime()
- {
- if (GetUncPath0().Length > 1)
- {
- Exists();
- return _createTime;
- }
- return 0L;
- }
-
- /// <summary>
- /// Retrieve the last time the file represented by this
- /// <code>SmbFile</code> was modified.
- /// </summary>
- /// <remarks>
- /// Retrieve the last time the file represented by this
- /// <code>SmbFile</code> was modified. The value returned is suitable for
- /// constructing a
- /// <see cref="System.DateTime">System.DateTime</see>
- /// object (i.e. seconds since Epoch
- /// 1970). Times should be the same as those reported using the properties
- /// dialog of the Windows Explorer program.
- /// </remarks>
- /// <returns>
- /// The number of milliseconds since the 00:00:00 GMT, January 1,
- /// 1970 as a <code>long</code> value
- /// </returns>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual long LastModified()
- {
- if (GetUncPath0().Length > 1)
- {
- Exists();
- return _lastModified;
- }
- return 0L;
- }
-
- /// <summary>List the contents of this SMB resource.</summary>
- /// <remarks>
- /// List the contents of this SMB resource. The list returned by this
- /// method will be;
- /// <ul>
- /// <li> files and directories contained within this resource if the
- /// resource is a normal disk file directory,
- /// <li> all available NetBIOS workgroups or domains if this resource is
- /// the top level URL <code>smb://</code>,
- /// <li> all servers registered as members of a NetBIOS workgroup if this
- /// resource refers to a workgroup in a <code>smb://workgroup/</code> URL,
- /// <li> all browseable shares of a server including printers, IPC
- /// services, or disk volumes if this resource is a server URL in the form
- /// <code>smb://server/</code>,
- /// <li> or <code>null</code> if the resource cannot be resolved.
- /// </ul>
- /// </remarks>
- /// <returns>
- /// A <code>String[]</code> array of files and directories,
- /// workgroups, servers, or shares depending on the context of the
- /// resource URL
- /// </returns>
- /// <exception cref="SmbException"></exception>
- public virtual string[] List()
- {
- return List("*", AttrDirectory | AttrHidden | AttrSystem, null, null);
- }
-
- /// <summary>List the contents of this SMB resource.</summary>
- /// <remarks>
- /// List the contents of this SMB resource. The list returned will be
- /// identical to the list returned by the parameterless <code>list()</code>
- /// method minus filenames filtered by the specified filter.
- /// </remarks>
- /// <param name="filter">a filename filter to exclude filenames from the results</param>
- /// <exception cref="SmbException"># @return An array of filenames</exception>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual string[] List(ISmbFilenameFilter filter)
- {
- return List("*", AttrDirectory | AttrHidden | AttrSystem, filter, null);
- }
-
- /// <summary>
- /// List the contents of this SMB resource as an array of
- /// <code>SmbFile</code> objects.
- /// </summary>
- /// <remarks>
- /// List the contents of this SMB resource as an array of
- /// <code>SmbFile</code> objects. This method is much more efficient than
- /// the regular <code>list</code> method when querying attributes of each
- /// file in the result set.
- /// <p>
- /// The list of <code>SmbFile</code>s returned by this method will be;
- /// <ul>
- /// <li> files and directories contained within this resource if the
- /// resource is a normal disk file directory,
- /// <li> all available NetBIOS workgroups or domains if this resource is
- /// the top level URL <code>smb://</code>,
- /// <li> all servers registered as members of a NetBIOS workgroup if this
- /// resource refers to a workgroup in a <code>smb://workgroup/</code> URL,
- /// <li> all browseable shares of a server including printers, IPC
- /// services, or disk volumes if this resource is a server URL in the form
- /// <code>smb://server/</code>,
- /// <li> or <code>null</code> if the resource cannot be resolved.
- /// </ul>
- /// </remarks>
- /// <returns>
- /// An array of <code>SmbFile</code> objects representing file
- /// and directories, workgroups, servers, or shares depending on the context
- /// of the resource URL
- /// </returns>
- /// <exception cref="SmbException"></exception>
- public virtual SmbFile[] ListFiles()
- {
- return ListFiles("*", AttrDirectory | AttrHidden | AttrSystem, null, null);
- }
-
- /// <summary>
- /// The CIFS protocol provides for DOS "wildcards" to be used as
- /// a performance enhancement.
- /// </summary>
- /// <remarks>
- /// The CIFS protocol provides for DOS "wildcards" to be used as
- /// a performance enhancement. The client does not have to filter
- /// the names and the server does not have to return all directory
- /// entries.
- /// <p>
- /// The wildcard expression may consist of two special meta
- /// characters in addition to the normal filename characters. The '*'
- /// character matches any number of characters in part of a name. If
- /// the expression begins with one or more '?'s then exactly that
- /// many characters will be matched whereas if it ends with '?'s
- /// it will match that many characters <i>or less</i>.
- /// <p>
- /// Wildcard expressions will not filter workgroup names or server names.
- /// <blockquote><pre>
- /// winnt&gt; ls c?o
- /// clock.avi -rw-- 82944 Mon Oct 14 1996 1:38 AM
- /// Cookies drw-- 0 Fri Nov 13 1998 9:42 PM
- /// 2 items in 5ms
- /// </pre></blockquote>
- /// </remarks>
- /// <param name="wildcard">a wildcard expression</param>
- /// <exception cref="SmbException">SmbException</exception>
- /// <returns>
- /// An array of <code>SmbFile</code> objects representing file
- /// and directories, workgroups, servers, or shares depending on the context
- /// of the resource URL
- /// </returns>
- /// <exception cref="SmbException"></exception>
- public virtual SmbFile[] ListFiles(string wildcard)
- {
- return ListFiles(wildcard, AttrDirectory | AttrHidden | AttrSystem, null, null
- );
- }
-
- /// <summary>List the contents of this SMB resource.</summary>
- /// <remarks>
- /// List the contents of this SMB resource. The list returned will be
- /// identical to the list returned by the parameterless <code>listFiles()</code>
- /// method minus files filtered by the specified filename filter.
- /// </remarks>
- /// <param name="filter">a filter to exclude files from the results</param>
- /// <returns>An array of <tt>SmbFile</tt> objects</returns>
- /// <exception cref="SmbException">SmbException</exception>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual SmbFile[] ListFiles(ISmbFilenameFilter filter)
- {
- return ListFiles("*", AttrDirectory | AttrHidden | AttrSystem, filter, null);
- }
-
- /// <summary>List the contents of this SMB resource.</summary>
- /// <remarks>
- /// List the contents of this SMB resource. The list returned will be
- /// identical to the list returned by the parameterless <code>listFiles()</code>
- /// method minus filenames filtered by the specified filter.
- /// </remarks>
- /// <param name="filter">a file filter to exclude files from the results</param>
- /// <returns>An array of <tt>SmbFile</tt> objects</returns>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual SmbFile[] ListFiles(ISmbFileFilter filter)
- {
- return ListFiles("*", AttrDirectory | AttrHidden | AttrSystem, null, filter);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual string[] List(string wildcard, int searchAttributes, ISmbFilenameFilter
- fnf, ISmbFileFilter ff)
- {
- List<object> list = new List<object>();
- DoEnum(list, false, wildcard, searchAttributes, fnf, ff);
-
- return Collections.ToArray<string>(list); //Collections.ToArray<string>(list);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual SmbFile[] ListFiles(string wildcard, int searchAttributes
- , ISmbFilenameFilter fnf, ISmbFileFilter ff)
- {
- List<object> list = new List<object>();
- DoEnum(list, true, wildcard, searchAttributes, fnf, ff);
-
- return Collections.ToArray<SmbFile>(list); //Collections.ToArray<SmbFile>(list);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual void DoEnum(List<object> list, bool files, string wildcard, int searchAttributes
- , ISmbFilenameFilter fnf, ISmbFileFilter ff)
- {
- if (ff != null && ff is DosFileFilter)
- {
- DosFileFilter dff = (DosFileFilter)ff;
- if (dff.Wildcard != null)
- {
- wildcard = dff.Wildcard;
- }
- searchAttributes = dff.Attributes;
- }
- try
- {
- int hostlen = Url.GetHost() != null ? Url.GetHost().Length : 0;
- if (hostlen == 0 || GetType() == TypeWorkgroup)
- {
- DoNetServerEnum(list, files, wildcard, searchAttributes, fnf, ff);
- }
- else
- {
- if (_share == null)
- {
- DoShareEnum(list, files, wildcard, searchAttributes, fnf, ff);
- }
- else
- {
- DoFindFirstNext(list, files, wildcard, searchAttributes, fnf, ff);
- }
- }
- }
- catch (UnknownHostException uhe)
- {
- throw new SmbException(Url.ToString(), uhe);
- }
- catch (UriFormatException mue)
- {
- throw new SmbException(Url.ToString(), mue);
- }
- }
-
- private void RemoveCurrentAddress()
- {
- if (AddressIndex >= 1)
- {
- UniAddress[] aux = new UniAddress[Addresses.Length - 1];
-
- Array.Copy(Addresses, 1, aux, 0, Addresses.Length - 1);
-
- Addresses = aux;
- AddressIndex--;
- }
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- /// <exception cref="System.UriFormatException"></exception>
- internal virtual void DoShareEnum(List<object> list, bool files, string wildcard, int
- searchAttributes, ISmbFilenameFilter fnf, ISmbFileFilter ff)
- {
- string p = Url.AbsolutePath;
- IOException last = null;
- IFileEntry[] entries;
- UniAddress addr;
- IFileEntry e;
- Hashtable map;
- if (p.LastIndexOf('/') != (p.Length - 1))
- {
- throw new SmbException(Url + " directory must end with '/'");
- }
- if (GetType() != TypeServer)
- {
- throw new SmbException("The requested list operations is invalid: " + Url);
- }
- map = new Hashtable();
- if (_enableDfs && Dfs.IsTrustedDomain(GetServer(), Auth))
- {
- try
- {
- entries = DoDfsRootEnum();
- for (int ei = 0; ei < entries.Length; ei++)
- {
- e = entries[ei];
- if (map.ContainsKey(e) == false)
- {
- map.Put(e, e);
- }
- }
- }
- catch (IOException ioe)
- {
- if (Log.Level >= 4)
- {
- Runtime.PrintStackTrace(ioe, Log);
- }
- }
- }
- addr = GetFirstAddress();
- while (addr != null)
- {
- try
- {
- last = null;
-
- DoConnect();
- try
- {
- entries = DoMsrpcShareEnum();
- }
- catch (IOException ioe)
- {
- if (Log.Level >= 3)
- {
- Runtime.PrintStackTrace(ioe, Log);
- }
- entries = DoNetShareEnum();
- }
- for (int ei = 0; ei < entries.Length; ei++)
- {
- e = entries[ei];
- if (map.ContainsKey(e) == false)
- {
- map.Put(e, e);
- }
- }
- break;
- }
- catch (IOException ioe)
- {
- if (Log.Level >= 3)
- {
- Runtime.PrintStackTrace(ioe, Log);
- }
- last = ioe;
-
- if (!(ioe is SmbAuthException))
- {
- RemoveCurrentAddress();
-
- addr = GetNextAddress();
- }
- else
- {
- break;
- }
- }
-
- }
- if (last != null && map.Count == 0)
- {
- if (last is SmbException == false)
- {
- throw new SmbException(Url.ToString(), last);
- }
- throw (SmbException)last;
- }
- //Iterator iter = map.Keys.Iterator();
- //while (iter.HasNext())
- foreach (var item in map.Keys)
- {
- e = (IFileEntry)item;
- string name = e.GetName();
- if (fnf != null && fnf.Accept(this, name) == false)
- {
- continue;
- }
- if (name.Length > 0)
- {
- // if !files we don't need to create SmbFiles here
- SmbFile f = new SmbFile(this, name, e.GetType(), AttrReadonly
- | AttrDirectory, 0L, 0L, 0L);
- if (ff != null && ff.Accept(f) == false)
- {
- continue;
- }
- if (files)
- {
- list.Add(f);
- }
- else
- {
- list.Add(name);
- }
- }
- }
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- internal virtual IFileEntry[] DoDfsRootEnum()
- {
- MsrpcDfsRootEnum rpc;
- DcerpcHandle handle = null;
- IFileEntry[] entries;
- handle = DcerpcHandle.GetHandle("ncacn_np:" + GetAddress().GetHostAddress() + "[\\PIPE\\netdfs]"
- , Auth);
- try
- {
- rpc = new MsrpcDfsRootEnum(GetServer());
- handle.Sendrecv(rpc);
- if (rpc.Retval != 0)
- {
- throw new SmbException(rpc.Retval, true);
- }
- return rpc.GetEntries();
- }
- finally
- {
- try
- {
- handle.Close();
- }
- catch (IOException ioe)
- {
- if (Log.Level >= 4)
- {
- Runtime.PrintStackTrace(ioe, Log);
- }
- }
- }
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- internal virtual IFileEntry[] DoMsrpcShareEnum()
- {
- MsrpcShareEnum rpc;
- DcerpcHandle handle;
- rpc = new MsrpcShareEnum(Url.GetHost());
- handle = DcerpcHandle.GetHandle("ncacn_np:" + GetAddress().GetHostAddress() + "[\\PIPE\\srvsvc]"
- , Auth);
- try
- {
- handle.Sendrecv(rpc);
- if (rpc.Retval != 0)
- {
- throw new SmbException(rpc.Retval, true);
- }
- return rpc.GetEntries();
- }
- finally
- {
- try
- {
- handle.Close();
- }
- catch (IOException ioe)
- {
- if (Log.Level >= 4)
- {
- Runtime.PrintStackTrace(ioe, Log);
- }
- }
- }
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual IFileEntry[] DoNetShareEnum()
- {
- SmbComTransaction req = new NetShareEnum();
- SmbComTransactionResponse resp = new NetShareEnumResponse();
- Send(req, resp);
- if (resp.Status != WinError.ErrorSuccess)
- {
- throw new SmbException(resp.Status, true);
- }
- return resp.Results;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- /// <exception cref="System.UriFormatException"></exception>
- internal virtual void DoNetServerEnum(List<object> list, bool files, string wildcard
- , int searchAttributes, ISmbFilenameFilter fnf, ISmbFileFilter ff)
- {
- int listType = Url.GetHost().Length == 0 ? 0 : GetType();
- SmbComTransaction req;
- SmbComTransactionResponse resp;
- if (listType == 0)
- {
- Connect0();
- req = new NetServerEnum2(Tree.Session.transport.Server.OemDomainName, NetServerEnum2
- .SvTypeDomainEnum);
- resp = new NetServerEnum2Response();
- }
- else
- {
- if (listType == TypeWorkgroup)
- {
- req = new NetServerEnum2(Url.GetHost(), NetServerEnum2.SvTypeAll);
- resp = new NetServerEnum2Response();
- }
- else
- {
- throw new SmbException("The requested list operations is invalid: " + Url);
- }
- }
- bool more;
- do
- {
- int n;
- Send(req, resp);
- if (resp.Status != WinError.ErrorSuccess && resp.Status != WinError.ErrorMoreData)
- {
- throw new SmbException(resp.Status, true);
- }
- more = resp.Status == WinError.ErrorMoreData;
- n = more ? resp.NumEntries - 1 : resp.NumEntries;
- for (int i = 0; i < n; i++)
- {
- IFileEntry e = resp.Results[i];
- string name = e.GetName();
- if (fnf != null && fnf.Accept(this, name) == false)
- {
- continue;
- }
- if (name.Length > 0)
- {
- // if !files we don't need to create SmbFiles here
- SmbFile f = new SmbFile(this, name, e.GetType(), AttrReadonly
- | AttrDirectory, 0L, 0L, 0L);
- if (ff != null && ff.Accept(f) == false)
- {
- continue;
- }
- if (files)
- {
- list.Add(f);
- }
- else
- {
- list.Add(name);
- }
- }
- }
- if (GetType() != TypeWorkgroup)
- {
- break;
- }
- req.SubCommand = unchecked(SmbComTransaction.NetServerEnum3);
- req.Reset(0, ((NetServerEnum2Response)resp).LastName);
- resp.Reset();
- }
- while (more);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- /// <exception cref="System.UriFormatException"></exception>
- internal virtual void DoFindFirstNext(List<object> list, bool files, string wildcard
- , int searchAttributes, ISmbFilenameFilter fnf, ISmbFileFilter ff)
- {
- SmbComTransaction req;
- Trans2FindFirst2Response resp;
- int sid;
- string path = GetUncPath0();
- string p = Url.AbsolutePath;
- if (p.LastIndexOf('/') != (p.Length - 1))
- {
- throw new SmbException(Url + " directory must end with '/'");
- }
- req = new Trans2FindFirst2(path, wildcard, searchAttributes);
- resp = new Trans2FindFirst2Response();
- if (Log.Level >= 3)
- {
- Log.WriteLine("doFindFirstNext: " + req.Path);
- }
- Send(req, resp);
- sid = resp.Sid;
- req = new Trans2FindNext2(sid, resp.ResumeKey, resp.LastName);
- resp.SubCommand = SmbComTransaction.Trans2FindNext2;
- for (; ; )
- {
- for (int i = 0; i < resp.NumEntries; i++)
- {
- IFileEntry e = resp.Results[i];
- string name = e.GetName();
- if (name.Length < 3)
- {
- int h = name.GetHashCode();
- if (h == HashDot || h == HashDotDot)
- {
- if (name.Equals(".") || name.Equals(".."))
- {
- continue;
- }
- }
- }
- if (fnf != null && fnf.Accept(this, name) == false)
- {
- continue;
- }
- if (name.Length > 0)
- {
- SmbFile f = new SmbFile(this, name, TypeFilesystem, e.GetAttributes
- (), e.CreateTime(), e.LastModified(), e.Length());
- if (ff != null && ff.Accept(f) == false)
- {
- continue;
- }
- if (files)
- {
- list.Add(f);
- }
- else
- {
- list.Add(name);
- }
- }
- }
- if (resp.IsEndOfSearch || resp.NumEntries == 0)
- {
- break;
- }
- req.Reset(resp.ResumeKey, resp.LastName);
- resp.Reset();
- Send(req, resp);
- }
- try
- {
- Send(new SmbComFindClose2(sid), Blank_resp());
- }
- catch (SmbException se)
- {
- if (Log.Level >= 4)
- {
- Runtime.PrintStackTrace(se, Log);
- }
- }
- }
-
- /// <summary>
- /// Changes the name of the file this <code>SmbFile</code> represents to the name
- /// designated by the <code>SmbFile</code> argument.
- /// </summary>
- /// <remarks>
- /// Changes the name of the file this <code>SmbFile</code> represents to the name
- /// designated by the <code>SmbFile</code> argument.
- /// <p/>
- /// <i>Remember: <code>SmbFile</code>s are immutible and therefore
- /// the path associated with this <code>SmbFile</code> object will not
- /// change). To access the renamed file it is necessary to construct a
- /// new <tt>SmbFile</tt></i>.
- /// </remarks>
- /// <param name="dest">An <code>SmbFile</code> that represents the new pathname</param>
- /// <exception cref="System.ArgumentNullException">If the <code>dest</code> argument is <code>null</code>
- /// </exception>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void RenameTo(SmbFile dest)
- {
- if (GetUncPath0().Length == 1 || dest.GetUncPath0().Length == 1)
- {
- throw new SmbException("Invalid operation for workgroups, servers, or shares");
- }
- ResolveDfs(null);
- dest.ResolveDfs(null);
- if (!Tree.Equals(dest.Tree))
- {
- throw new SmbException("Invalid operation for workgroups, servers, or shares");
- }
- if (Log.Level >= 3)
- {
- Log.WriteLine("renameTo: " + Unc + " -> " + dest.Unc);
- }
- _attrExpiration = _sizeExpiration = 0;
- dest._attrExpiration = 0;
- Send(new SmbComRename(Unc, dest.Unc), Blank_resp());
- }
-
- internal class WriterThread : Thread
- {
- internal byte[] B;
-
- internal int N;
-
- internal long Off;
-
- internal bool Ready;
-
- internal SmbFile Dest;
-
- internal SmbException E;
-
- internal bool UseNtSmbs;
-
- internal SmbComWriteAndX Reqx;
-
- internal SmbComWrite Req;
-
- internal ServerMessageBlock Resp;
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public WriterThread(SmbFile enclosing)
- : base("JCIFS-WriterThread")
- {
- this._enclosing = enclosing;
- UseNtSmbs = this._enclosing.Tree.Session.transport.HasCapability(SmbConstants.CapNtSmbs);
- if (UseNtSmbs)
- {
- Reqx = new SmbComWriteAndX();
- Resp = new SmbComWriteAndXResponse();
- }
- else
- {
- Req = new SmbComWrite();
- Resp = new SmbComWriteResponse();
- }
- Ready = false;
- }
-
- internal virtual void Write(byte[] b, int n, SmbFile dest, long off)
- {
- lock (this)
- {
- this.B = b;
- this.N = n;
- this.Dest = dest;
- this.Off = off;
- Ready = false;
- Runtime.Notify(this);
- }
- }
-
- public override void Run()
- {
- lock (this)
- {
- try
- {
- for (; ; )
- {
- Runtime.Notify(this);
- Ready = true;
- while (Ready)
- {
- Runtime.Wait(this);
- }
- if (N == -1)
- {
- return;
- }
- if (UseNtSmbs)
- {
- Reqx.SetParam(Dest.Fid, Off, N, B, 0, N);
- Dest.Send(Reqx, Resp);
- }
- else
- {
- Req.SetParam(Dest.Fid, Off, N, B, 0, N);
- Dest.Send(Req, Resp);
- }
- }
- }
- catch (SmbException e)
- {
- this.E = e;
- }
- catch (Exception x)
- {
- E = new SmbException("WriterThread", x);
- }
- Runtime.Notify(this);
- }
- }
-
- private readonly SmbFile _enclosing;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual void CopyTo0(SmbFile dest, byte[][] b, int bsize, WriterThread
- w, SmbComReadAndX req, SmbComReadAndXResponse resp)
- {
- int i;
- if (_attrExpiration < Runtime.CurrentTimeMillis())
- {
- _attributes = AttrReadonly | AttrDirectory;
- _createTime = 0L;
- _lastModified = 0L;
- _isExists = false;
- IInfo info = QueryPath(GetUncPath0(), Trans2QueryPathInformationResponse.SMB_QUERY_FILE_BASIC_INFO
- );
- _attributes = info.GetAttributes();
- _createTime = info.GetCreateTime();
- _lastModified = info.GetLastWriteTime();
- _isExists = true;
- _attrExpiration = Runtime.CurrentTimeMillis() + AttrExpirationPeriod;
- }
- if (IsDirectory())
- {
- SmbFile[] files;
- SmbFile ndest;
- string path = dest.GetUncPath0();
- if (path.Length > 1)
- {
- try
- {
- dest.Mkdir();
- dest.SetPathInformation(_attributes, _createTime, _lastModified);
- }
- catch (SmbException se)
- {
- if (se.GetNtStatus() != NtStatus.NtStatusAccessDenied && se.GetNtStatus() != NtStatus
- .NtStatusObjectNameCollision)
- {
- throw;
- }
- }
- }
- files = ListFiles("*", AttrDirectory | AttrHidden | AttrSystem, null, null);
- try
- {
- for (i = 0; i < files.Length; i++)
- {
- ndest = new SmbFile(dest, files[i].GetName(), files[i].Type, files[i]._attributes,
- files[i]._createTime, files[i]._lastModified, files[i]._size);
- files[i].CopyTo0(ndest, b, bsize, w, req, resp);
- }
- }
- catch (UnknownHostException uhe)
- {
- throw new SmbException(Url.ToString(), uhe);
- }
- catch (UriFormatException mue)
- {
- throw new SmbException(Url.ToString(), mue);
- }
- }
- else
- {
- long off;
- try
- {
- Open(ORdonly, 0, AttrNormal, 0);
- try
- {
- dest.Open(OCreat | OWronly | OTrunc, SmbConstants.FileWriteData |
- SmbConstants.FileWriteAttributes, _attributes, 0);
- }
- catch (SmbAuthException sae)
- {
- if ((dest._attributes & AttrReadonly) != 0)
- {
- dest.SetPathInformation(dest._attributes & ~AttrReadonly, 0L, 0L);
- dest.Open(OCreat | OWronly | OTrunc, SmbConstants.FileWriteData |
- SmbConstants.FileWriteAttributes, _attributes, 0);
- }
- else
- {
- throw;
- }
- }
- i = 0;
- off = 0L;
- for (; ; )
- {
- req.SetParam(Fid, off, bsize);
- resp.SetParam(b[i], 0);
- Send(req, resp);
- lock (w)
- {
- if (w.E != null)
- {
- throw w.E;
- }
- while (!w.Ready)
- {
- try
- {
- Runtime.Wait(w);
- }
- catch (Exception ie)
- {
- throw new SmbException(dest.Url.ToString(), ie);
- }
- }
- if (w.E != null)
- {
- throw w.E;
- }
- if (resp.DataLength <= 0)
- {
- break;
- }
- w.Write(b[i], resp.DataLength, dest, off);
- }
- i = i == 1 ? 0 : 1;
- off += resp.DataLength;
- }
- dest.Send(new Trans2SetFileInformation(dest.Fid, _attributes, _createTime, _lastModified
- ), new Trans2SetFileInformationResponse());
- dest.Close(0L);
- }
- catch (SmbException se)
- {
- if (IgnoreCopyToException == false)
- {
- throw new SmbException("Failed to copy file from [" + ToString() + "] to ["
- + dest + "]", se);
- }
- if (Log.Level > 1)
- {
- Runtime.PrintStackTrace(se, Log);
- }
- }
- finally
- {
- Close();
- }
- }
- }
-
- /// <summary>
- /// This method will copy the file or directory represented by this
- /// <tt>SmbFile</tt> and it's sub-contents to the location specified by the
- /// <tt>dest</tt> parameter.
- /// </summary>
- /// <remarks>
- /// This method will copy the file or directory represented by this
- /// <tt>SmbFile</tt> and it's sub-contents to the location specified by the
- /// <tt>dest</tt> parameter. This file and the destination file do not
- /// need to be on the same host. This operation does not copy extended
- /// file attibutes such as ACLs but it does copy regular attributes as
- /// well as create and last write times. This method is almost twice as
- /// efficient as manually copying as it employs an additional write
- /// thread to read and write data concurrently.
- /// <p/>
- /// It is not possible (nor meaningful) to copy entire workgroups or
- /// servers.
- /// </remarks>
- /// <param name="dest">the destination file or directory</param>
- /// <exception cref="SmbException">SmbException</exception>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void CopyTo(SmbFile dest)
- {
- SmbComReadAndX req;
- SmbComReadAndXResponse resp;
- WriterThread w;
- int bsize;
- byte[][] b;
- if (_share == null || dest._share == null)
- {
- throw new SmbException("Invalid operation for workgroups or servers");
- }
- req = new SmbComReadAndX();
- resp = new SmbComReadAndXResponse();
- Connect0();
- dest.Connect0();
- ResolveDfs(null);
- try
- {
- if (GetAddress().Equals(dest.GetAddress()) && _canon.RegionMatches(true, 0, dest._canon
- , 0, Math.Min(_canon.Length, dest._canon.Length)))
- {
- throw new SmbException("Source and destination paths overlap.");
- }
- }
- catch (UnknownHostException)
- {
- }
- w = new WriterThread(this);
- w.SetDaemon(true);
- w.Start();
- SmbTransport t1 = Tree.Session.transport;
- SmbTransport t2 = dest.Tree.Session.transport;
- if (t1.SndBufSize < t2.SndBufSize)
- {
- t2.SndBufSize = t1.SndBufSize;
- }
- else
- {
- t1.SndBufSize = t2.SndBufSize;
- }
- bsize = Math.Min(t1.RcvBufSize - 70, t1.SndBufSize - 70);
- b = new[] { new byte[bsize], new byte[bsize] };
- try
- {
- CopyTo0(dest, b, bsize, w, req, resp);
- }
- finally
- {
- w.Write(null, -1, null, 0);
- }
- }
-
- /// <summary>
- /// This method will delete the file or directory specified by this
- /// <code>SmbFile</code>.
- /// </summary>
- /// <remarks>
- /// This method will delete the file or directory specified by this
- /// <code>SmbFile</code>. If the target is a directory, the contents of
- /// the directory will be deleted as well. If a file within the directory or
- /// it's sub-directories is marked read-only, the read-only status will
- /// be removed and the file will be deleted.
- /// </remarks>
- /// <exception cref="SmbException">SmbException</exception>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void Delete()
- {
- Exists();
- GetUncPath0();
- Delete(Unc);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual void Delete(string fileName)
- {
- if (GetUncPath0().Length == 1)
- {
- throw new SmbException("Invalid operation for workgroups, servers, or shares");
- }
- if (Runtime.CurrentTimeMillis() > _attrExpiration)
- {
- _attributes = AttrReadonly | AttrDirectory;
- _createTime = 0L;
- _lastModified = 0L;
- _isExists = false;
- IInfo info = QueryPath(GetUncPath0(), Trans2QueryPathInformationResponse.SMB_QUERY_FILE_BASIC_INFO
- );
- _attributes = info.GetAttributes();
- _createTime = info.GetCreateTime();
- _lastModified = info.GetLastWriteTime();
- _attrExpiration = Runtime.CurrentTimeMillis() + AttrExpirationPeriod;
- _isExists = true;
- }
- if ((_attributes & AttrReadonly) != 0)
- {
- SetReadWrite();
- }
- if (Log.Level >= 3)
- {
- Log.WriteLine("delete: " + fileName);
- }
- if ((_attributes & AttrDirectory) != 0)
- {
- try
- {
- SmbFile[] l = ListFiles("*", AttrDirectory | AttrHidden | AttrSystem, null, null
- );
- for (int i = 0; i < l.Length; i++)
- {
- l[i].Delete();
- }
- }
- catch (SmbException se)
- {
- if (se.GetNtStatus() != NtStatus.NtStatusNoSuchFile)
- {
- throw;
- }
- }
- Send(new SmbComDeleteDirectory(fileName), Blank_resp());
- }
- else
- {
- Send(new SmbComDelete(fileName), Blank_resp());
- }
- _attrExpiration = _sizeExpiration = 0;
- }
-
- /// <summary>Returns the length of this <tt>SmbFile</tt> in bytes.</summary>
- /// <remarks>
- /// Returns the length of this <tt>SmbFile</tt> in bytes. If this object
- /// is a <tt>TYPE_SHARE</tt> the total capacity of the disk shared in
- /// bytes is returned. If this object is a directory or a type other than
- /// <tt>TYPE_SHARE</tt>, 0L is returned.
- /// </remarks>
- /// <returns>
- /// The length of the file in bytes or 0 if this
- /// <code>SmbFile</code> is not a file.
- /// </returns>
- /// <exception cref="SmbException">SmbException</exception>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual long Length()
- {
- if (_sizeExpiration > Runtime.CurrentTimeMillis())
- {
- return _size;
- }
- if (GetType() == TypeShare)
- {
- Trans2QueryFsInformationResponse response;
- int level = Trans2QueryFsInformationResponse.SMB_INFO_ALLOCATION;
- response = new Trans2QueryFsInformationResponse(level);
- Send(new Trans2QueryFsInformation(level), response);
- _size = response.Info.GetCapacity();
- }
- else
- {
- if (GetUncPath0().Length > 1 && Type != TypeNamedPipe)
- {
- IInfo info = QueryPath(GetUncPath0(), Trans2QueryPathInformationResponse.SMB_QUERY_FILE_STANDARD_INFO
- );
- _size = info.GetSize();
- }
- else
- {
- _size = 0L;
- }
- }
- _sizeExpiration = Runtime.CurrentTimeMillis() + AttrExpirationPeriod;
- return _size;
- }
-
- /// <summary>
- /// This method returns the free disk space in bytes of the drive this share
- /// represents or the drive on which the directory or file resides.
- /// </summary>
- /// <remarks>
- /// This method returns the free disk space in bytes of the drive this share
- /// represents or the drive on which the directory or file resides. Objects
- /// other than <tt>TYPE_SHARE</tt> or <tt>TYPE_FILESYSTEM</tt> will result
- /// in 0L being returned.
- /// </remarks>
- /// <returns>
- /// the free disk space in bytes of the drive on which this file or
- /// directory resides
- /// </returns>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual long GetDiskFreeSpace()
- {
- if (GetType() == TypeShare || Type == TypeFilesystem)
- {
- int level = Trans2QueryFsInformationResponse.SmbFsFullSizeInformation;
- try
- {
- return QueryFsInformation(level);
- }
- catch (SmbException ex)
- {
- switch (ex.GetNtStatus())
- {
- case NtStatus.NtStatusInvalidInfoClass:
- case NtStatus.NtStatusUnsuccessful:
- {
- // NetApp Filer
- // SMB_FS_FULL_SIZE_INFORMATION not supported by the server.
- level = Trans2QueryFsInformationResponse.SMB_INFO_ALLOCATION;
- return QueryFsInformation(level);
- }
- }
- throw;
- }
- }
- return 0L;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- private long QueryFsInformation(int level)
- {
- Trans2QueryFsInformationResponse response;
- response = new Trans2QueryFsInformationResponse(level);
- Send(new Trans2QueryFsInformation(level), response);
- if (Type == TypeShare)
- {
- _size = response.Info.GetCapacity();
- _sizeExpiration = Runtime.CurrentTimeMillis() + AttrExpirationPeriod;
- }
- return response.Info.GetFree();
- }
-
- /// <summary>
- /// Creates a directory with the path specified by this
- /// <code>SmbFile</code>.
- /// </summary>
- /// <remarks>
- /// Creates a directory with the path specified by this
- /// <code>SmbFile</code>. For this method to be successful, the target
- /// must not already exist. This method will fail when
- /// used with <code>smb://</code>, <code>smb://workgroup/</code>,
- /// <code>smb://server/</code>, or <code>smb://server/share/</code> URLs
- /// because workgroups, servers, and shares cannot be dynamically created
- /// (although in the future it may be possible to create shares).
- /// </remarks>
- /// <exception cref="SmbException">SmbException</exception>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void Mkdir()
- {
- string path = GetUncPath0();
- if (path.Length == 1)
- {
- throw new SmbException("Invalid operation for workgroups, servers, or shares");
- }
- if (Log.Level >= 3)
- {
- Log.WriteLine("mkdir: " + path);
- }
- Send(new SmbComCreateDirectory(path), Blank_resp());
- _attrExpiration = _sizeExpiration = 0;
- }
-
- /// <summary>
- /// Creates a directory with the path specified by this <tt>SmbFile</tt>
- /// and any parent directories that do not exist.
- /// </summary>
- /// <remarks>
- /// Creates a directory with the path specified by this <tt>SmbFile</tt>
- /// and any parent directories that do not exist. This method will fail
- /// when used with <code>smb://</code>, <code>smb://workgroup/</code>,
- /// <code>smb://server/</code>, or <code>smb://server/share/</code> URLs
- /// because workgroups, servers, and shares cannot be dynamically created
- /// (although in the future it may be possible to create shares).
- /// </remarks>
- /// <exception cref="SmbException">SmbException</exception>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void Mkdirs()
- {
- SmbFile parent;
- try
- {
- parent = new SmbFile(GetParent(), Auth);
- }
- catch (IOException)
- {
- return;
- }
- if (parent.Exists() == false)
- {
- parent.Mkdirs();
- }
- Mkdir();
- }
-
- /// <summary>Create a new file but fail if it already exists.</summary>
- /// <remarks>
- /// Create a new file but fail if it already exists. The check for
- /// existance of the file and it's creation are an atomic operation with
- /// respect to other filesystem activities.
- /// </remarks>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void CreateNewFile()
- {
- if (GetUncPath0().Length == 1)
- {
- throw new SmbException("Invalid operation for workgroups, servers, or shares");
- }
- Close(Open0(ORdwr | OCreat | OExcl, 0, AttrNormal, 0), 0L);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual void SetPathInformation(int attrs, long ctime, long mtime)
- {
- int f;
- int dir;
- Exists();
- dir = _attributes & AttrDirectory;
- f = Open0(ORdonly, SmbConstants.FileWriteAttributes, dir, dir != 0 ? 0x0001
- : 0x0040);
- Send(new Trans2SetFileInformation(f, attrs | dir, ctime, mtime), new Trans2SetFileInformationResponse
- ());
- Close(f, 0L);
- _attrExpiration = 0;
- }
-
- /// <summary>Set the create time of the file.</summary>
- /// <remarks>
- /// Set the create time of the file. The time is specified as milliseconds
- /// from Jan 1, 1970 which is the same as that which is returned by the
- /// <tt>createTime()</tt> method.
- /// <p/>
- /// This method does not apply to workgroups, servers, or shares.
- /// </remarks>
- /// <param name="time">the create time as milliseconds since Jan 1, 1970</param>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void SetCreateTime(long time)
- {
- if (GetUncPath0().Length == 1)
- {
- throw new SmbException("Invalid operation for workgroups, servers, or shares");
- }
- SetPathInformation(0, time, 0L);
- }
-
- /// <summary>Set the last modified time of the file.</summary>
- /// <remarks>
- /// Set the last modified time of the file. The time is specified as milliseconds
- /// from Jan 1, 1970 which is the same as that which is returned by the
- /// <tt>lastModified()</tt>, <tt>getLastModified()</tt>, and <tt>getDate()</tt> methods.
- /// <p/>
- /// This method does not apply to workgroups, servers, or shares.
- /// </remarks>
- /// <param name="time">the last modified time as milliseconds since Jan 1, 1970</param>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void SetLastModified(long time)
- {
- if (GetUncPath0().Length == 1)
- {
- throw new SmbException("Invalid operation for workgroups, servers, or shares");
- }
- SetPathInformation(0, 0L, time);
- }
-
- /// <summary>Return the attributes of this file.</summary>
- /// <remarks>
- /// Return the attributes of this file. Attributes are represented as a
- /// bitset that must be masked with <tt>ATTR_*</tt> constants to determine
- /// if they are set or unset. The value returned is suitable for use with
- /// the <tt>setAttributes()</tt> method.
- /// </remarks>
- /// <returns>the <tt>ATTR_*</tt> attributes associated with this file</returns>
- /// <exception cref="SmbException">SmbException</exception>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual int GetAttributes()
- {
- if (GetUncPath0().Length == 1)
- {
- return 0;
- }
- Exists();
- return _attributes & AttrGetMask;
- }
-
- /// <summary>Set the attributes of this file.</summary>
- /// <remarks>
- /// Set the attributes of this file. Attributes are composed into a
- /// bitset by bitwise ORing the <tt>ATTR_*</tt> constants. Setting the
- /// value returned by <tt>getAttributes</tt> will result in both files
- /// having the same attributes.
- /// </remarks>
- /// <exception cref="SmbException">SmbException</exception>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void SetAttributes(int attrs)
- {
- if (GetUncPath0().Length == 1)
- {
- throw new SmbException("Invalid operation for workgroups, servers, or shares");
- }
- SetPathInformation(attrs & AttrSetMask, 0L, 0L);
- }
-
- /// <summary>Make this file read-only.</summary>
- /// <remarks>
- /// Make this file read-only. This is shorthand for <tt>setAttributes(
- /// getAttributes() | ATTR_READ_ONLY )</tt>.
- /// </remarks>
- /// <exception cref="SmbException">SmbException</exception>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void SetReadOnly()
- {
- SetAttributes(GetAttributes() | AttrReadonly);
- }
-
- /// <summary>Turn off the read-only attribute of this file.</summary>
- /// <remarks>
- /// Turn off the read-only attribute of this file. This is shorthand for
- /// <tt>setAttributes( getAttributes() & ~ATTR_READONLY )</tt>.
- /// </remarks>
- /// <exception cref="SmbException">SmbException</exception>
- /// <exception cref="SmbException"></exception>
- public virtual void SetReadWrite()
- {
- SetAttributes(GetAttributes() & ~AttrReadonly);
- }
-
- /// <summary>
- /// Returns a
- /// <see cref="System.Uri">System.Uri</see>
- /// for this <code>SmbFile</code>. The
- /// <code>URL</code> may be used as any other <code>URL</code> might to
- /// access an SMB resource. Currently only retrieving data and information
- /// is supported (i.e. no <tt>doOutput</tt>).
- /// </summary>
- /// <returns>
- /// A new <code>
- /// <see cref="System.Uri">System.Uri</see>
- /// </code> for this <code>SmbFile</code>
- /// </returns>
- /// <exception cref="System.UriFormatException">System.UriFormatException</exception>
- [Obsolete(@"Use getURL() instead")]
- public virtual Uri ToUrl()
- {
- return Url;
- }
-
- /// <summary>
- /// Computes a hashCode for this file based on the URL string and IP
- /// address if the server.
- /// </summary>
- /// <remarks>
- /// Computes a hashCode for this file based on the URL string and IP
- /// address if the server. The hashing function uses the hashcode of the
- /// server address, the canonical representation of the URL, and does not
- /// compare authentication information. In essance, two
- /// <code>SmbFile</code> objects that refer to
- /// the same file should generate the same hashcode provided it is possible
- /// to make such a determination.
- /// </remarks>
- /// <returns>A hashcode for this abstract file</returns>
- /// <exception cref="SmbException">SmbException</exception>
- public override int GetHashCode()
- {
- int hash;
- try
- {
- hash = GetAddress().GetHashCode();
- }
- catch (UnknownHostException)
- {
- hash = GetServer().ToUpper().GetHashCode();
- }
- GetUncPath0();
- return hash + _canon.ToUpper().GetHashCode();
- }
-
- protected internal virtual bool PathNamesPossiblyEqual(string path1, string path2
- )
- {
- int p1;
- int p2;
- int l1;
- int l2;
- // if unsure return this method returns true
- p1 = path1.LastIndexOf('/');
- p2 = path2.LastIndexOf('/');
- l1 = path1.Length - p1;
- l2 = path2.Length - p2;
- // anything with dots voids comparison
- if (l1 > 1 && path1[p1 + 1] == '.')
- {
- return true;
- }
- if (l2 > 1 && path2[p2 + 1] == '.')
- {
- return true;
- }
- return l1 == l2 && path1.RegionMatches(true, p1, path2, p2, l1);
- }
-
- /// <summary>Tests to see if two <code>SmbFile</code> objects are equal.</summary>
- /// <remarks>
- /// Tests to see if two <code>SmbFile</code> objects are equal. Two
- /// SmbFile objects are equal when they reference the same SMB
- /// resource. More specifically, two <code>SmbFile</code> objects are
- /// equals if their server IP addresses are equal and the canonicalized
- /// representation of their URLs, minus authentication parameters, are
- /// case insensitivly and lexographically equal.
- /// <p/>
- /// For example, assuming the server <code>angus</code> resolves to the
- /// <code>192.168.1.15</code> IP address, the below URLs would result in
- /// <code>SmbFile</code>s that are equal.
- /// <p><blockquote><pre>
- /// smb://192.168.1.15/share/DIR/foo.txt
- /// smb://angus/share/data/../dir/foo.txt
- /// </pre></blockquote>
- /// </remarks>
- /// <param name="obj">Another <code>SmbFile</code> object to compare for equality</param>
- /// <returns>
- /// <code>true</code> if the two objects refer to the same SMB resource
- /// and <code>false</code> otherwise
- /// </returns>
- /// <exception cref="SmbException">SmbException</exception>
- public override bool Equals(object obj)
- {
- if (obj is SmbFile)
- {
- SmbFile f = (SmbFile)obj;
- bool ret;
- if (this == f)
- {
- return true;
- }
- if (PathNamesPossiblyEqual(Url.AbsolutePath, f.Url.AbsolutePath))
- {
- GetUncPath0();
- f.GetUncPath0();
- if (Runtime.EqualsIgnoreCase(_canon, f._canon))
- {
- try
- {
- ret = GetAddress().Equals(f.GetAddress());
- }
- catch (UnknownHostException)
- {
- ret = Runtime.EqualsIgnoreCase(GetServer(), f.GetServer());
- }
- return ret;
- }
- }
- }
- return false;
- }
-
- /// <summary>Returns the string representation of this SmbFile object.</summary>
- /// <remarks>
- /// Returns the string representation of this SmbFile object. This will
- /// be the same as the URL used to construct this <code>SmbFile</code>.
- /// This method will return the same value
- /// as <code>getPath</code>.
- /// </remarks>
- /// <returns>The original URL representation of this SMB resource</returns>
- /// <exception cref="SmbException">SmbException</exception>
- public override string ToString()
- {
- return Url.ToString();
- }
-
- /// <summary>This URLConnection method just returns the result of <tt>length()</tt>.</summary>
- /// <remarks>This URLConnection method just returns the result of <tt>length()</tt>.</remarks>
- /// <returns>the length of this file or 0 if it refers to a directory</returns>
- public int GetContentLength()
- {
- try
- {
- return (int)(Length() & unchecked(0xFFFFFFFFL));
- }
- catch (SmbException)
- {
- }
- return 0;
- }
-
- /// <summary>This URLConnection method just returns the result of <tt>lastModified</tt>.
- /// </summary>
- /// <remarks>This URLConnection method just returns the result of <tt>lastModified</tt>.
- /// </remarks>
- /// <returns>the last modified data as milliseconds since Jan 1, 1970</returns>
- public long GetDate()
- {
- try
- {
- return LastModified();
- }
- catch (SmbException)
- {
- }
- return 0L;
- }
-
- /// <summary>This URLConnection method just returns the result of <tt>lastModified</tt>.
- /// </summary>
- /// <remarks>This URLConnection method just returns the result of <tt>lastModified</tt>.
- /// </remarks>
- /// <returns>the last modified data as milliseconds since Jan 1, 1970</returns>
- public long GetLastModified()
- {
- try
- {
- return LastModified();
- }
- catch (SmbException)
- {
- }
- return 0L;
- }
-
- /// <summary>This URLConnection method just returns a new <tt>SmbFileInputStream</tt> created with this file.
- /// </summary>
- /// <remarks>This URLConnection method just returns a new <tt>SmbFileInputStream</tt> created with this file.
- /// </remarks>
- /// <exception cref="System.IO.IOException">thrown by <tt>SmbFileInputStream</tt> constructor
- /// </exception>
- public InputStream GetInputStream()
- {
- return new SmbFileInputStream(this);
- }
-
- /// <summary>This URLConnection method just returns a new <tt>SmbFileOutputStream</tt> created with this file.
- /// </summary>
- /// <remarks>This URLConnection method just returns a new <tt>SmbFileOutputStream</tt> created with this file.
- /// </remarks>
- /// <exception cref="System.IO.IOException">thrown by <tt>SmbFileOutputStream</tt> constructor
- /// </exception>
- public OutputStream GetOutputStream()
- {
- return new SmbFileOutputStream(this);
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- private void ProcessAces(Ace[] aces, bool resolveSids)
- {
- string server = GetServerWithDfs();
- int ai;
- if (resolveSids)
- {
- Sid[] sids = new Sid[aces.Length];
- string[] names = null;
- for (ai = 0; ai < aces.Length; ai++)
- {
- sids[ai] = aces[ai].Sid;
- }
- for (int off = 0; off < sids.Length; off += 64)
- {
- int len = sids.Length - off;
- if (len > 64)
- {
- len = 64;
- }
- Sid.ResolveSids(server, Auth, sids, off, len);
- }
- }
- else
- {
- for (ai = 0; ai < aces.Length; ai++)
- {
- aces[ai].Sid.OriginServer = server;
- aces[ai].Sid.OriginAuth = Auth;
- }
- }
- }
-
- /// <summary>
- /// Return an array of Access Control Entry (ACE) objects representing
- /// the security descriptor associated with this file or directory.
- /// </summary>
- /// <remarks>
- /// Return an array of Access Control Entry (ACE) objects representing
- /// the security descriptor associated with this file or directory.
- /// If no DACL is present, null is returned. If the DACL is empty, an array with 0 elements is returned.
- /// </remarks>
- /// <param name="resolveSids">
- /// Attempt to resolve the SIDs within each ACE form
- /// their numeric representation to their corresponding account names.
- /// </param>
- /// <exception cref="System.IO.IOException"></exception>
- public virtual Ace[] GetSecurity(bool resolveSids)
- {
- int f;
- Ace[] aces;
- f = Open0(ORdonly, SmbConstants.ReadControl, 0, IsDirectory() ? 1 : 0);
- NtTransQuerySecurityDesc request = new NtTransQuerySecurityDesc(f, 0x04);
- NtTransQuerySecurityDescResponse response = new NtTransQuerySecurityDescResponse(
- );
- try
- {
- Send(request, response);
- }
- finally
- {
- Close(f, 0L);
- }
- aces = response.SecurityDescriptor.Aces;
- if (aces != null)
- {
- ProcessAces(aces, resolveSids);
- }
- return aces;
- }
-
- /// <summary>
- /// Return an array of Access Control Entry (ACE) objects representing
- /// the share permissions on the share exporting this file or directory.
- /// </summary>
- /// <remarks>
- /// Return an array of Access Control Entry (ACE) objects representing
- /// the share permissions on the share exporting this file or directory.
- /// If no DACL is present, null is returned. If the DACL is empty, an array with 0 elements is returned.
- /// <p>
- /// Note that this is different from calling <tt>getSecurity</tt> on a
- /// share. There are actually two different ACLs for shares - the ACL on
- /// the share and the ACL on the folder being shared.
- /// Go to <i>Computer Management</i>
- /// &gt; <i>System Tools</i> &gt; <i>Shared Folders</i> &gt <i>Shares</i> and
- /// look at the <i>Properties</i> for a share. You will see two tabs - one
- /// for "Share Permissions" and another for "Security". These correspond to
- /// the ACLs returned by <tt>getShareSecurity</tt> and <tt>getSecurity</tt>
- /// respectively.
- /// </remarks>
- /// <param name="resolveSids">
- /// Attempt to resolve the SIDs within each ACE form
- /// their numeric representation to their corresponding account names.
- /// </param>
- /// <exception cref="System.IO.IOException"></exception>
- public virtual Ace[] GetShareSecurity(bool resolveSids)
- {
- string p = Url.AbsolutePath;
- MsrpcShareGetInfo rpc;
- DcerpcHandle handle;
- Ace[] aces;
- ResolveDfs(null);
- string server = GetServerWithDfs();
- rpc = new MsrpcShareGetInfo(server, Tree.Share);
- handle = DcerpcHandle.GetHandle("ncacn_np:" + server + "[\\PIPE\\srvsvc]", Auth);
- try
- {
- handle.Sendrecv(rpc);
- if (rpc.Retval != 0)
- {
- throw new SmbException(rpc.Retval, true);
- }
- aces = rpc.GetSecurity();
- if (aces != null)
- {
- ProcessAces(aces, resolveSids);
- }
- }
- finally
- {
- try
- {
- handle.Close();
- }
- catch (IOException ioe)
- {
- if (Log.Level >= 1)
- {
- Runtime.PrintStackTrace(ioe, Log);
- }
- }
- }
- return aces;
- }
-
- /// <summary>
- /// Return an array of Access Control Entry (ACE) objects representing
- /// the security descriptor associated with this file or directory.
- /// </summary>
- /// <remarks>
- /// Return an array of Access Control Entry (ACE) objects representing
- /// the security descriptor associated with this file or directory.
- /// <p>
- /// Initially, the SIDs within each ACE will not be resolved however when
- /// <tt>getType()</tt>, <tt>getDomainName()</tt>, <tt>getAccountName()</tt>,
- /// or <tt>toString()</tt> is called, the names will attempt to be
- /// resolved. If the names cannot be resolved (e.g. due to temporary
- /// network failure), the said methods will return default values (usually
- /// <tt>S-X-Y-Z</tt> strings of fragments of).
- /// <p>
- /// Alternatively <tt>getSecurity(true)</tt> may be used to resolve all
- /// SIDs together and detect network failures.
- /// </remarks>
- /// <exception cref="System.IO.IOException"></exception>
- public virtual Ace[] GetSecurity()
- {
- return GetSecurity(false);
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileExtensions.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileExtensions.cs
deleted file mode 100644
index 2ebcfa20f..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileExtensions.cs
+++ /dev/null
@@ -1,133 +0,0 @@
-// SmbFileExtensions.cs implementation by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-using System;
-using System.Threading.Tasks;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- public static class SmbFileExtensions
- {
- /// <summary>
- /// Get file's creation date converted to local timezone
- /// </summary>
- /// <param name="smbFile"></param>
- /// <returns></returns>
- public static DateTime GetLocalCreateTime(this SmbFile smbFile)
- {
- return TimeZoneInfo.ConvertTime(Extensions.CreateDateFromUTC(smbFile.CreateTime()),
- TimeZoneInfo.Local);
- }
-
- /// <summary>
- /// Get file's last modified date converted to local timezone
- /// </summary>
- /// <param name="smbFile"></param>
- /// <returns></returns>
- public static DateTime GetLocalLastModified(this SmbFile smbFile)
- {
- return TimeZoneInfo.ConvertTime(Extensions.CreateDateFromUTC(smbFile.LastModified()),
- TimeZoneInfo.Local);
- }
-
-
- /// <summary>
- /// List files async
- /// </summary>
- /// <param name="smbFile"></param>
- /// <returns></returns>
- public static Task<SmbFile[]> ListFilesAsync(this SmbFile smbFile)
- {
- return Task.Run(() => smbFile.ListFiles());
- }
-
- /// <summary>
- /// List files async
- /// </summary>
- /// <param name="smbFile"></param>
- /// <param name="wildcard"></param>
- /// <returns></returns>
- public static Task<SmbFile[]> ListFilesAsync(this SmbFile smbFile, string wildcard)
- {
- return Task.Run(() => smbFile.ListFiles(wildcard));
- }
-
- /// <summary>
- /// List files async
- /// </summary>
- /// <param name="smbFile"></param>
- /// <returns></returns>
- public static Task<string[]> ListAsync(this SmbFile smbFile)
- {
- return Task.Run(() => smbFile.List());
- }
-
- /// <summary>
- /// MkDir async method
- /// </summary>
- /// <param name="smbFile"></param>
- /// <returns></returns>
- public static Task MkDirAsync(this SmbFile smbFile)
- {
- return Task.Run(() => smbFile.Mkdir());
- }
-
-
- /// <summary>
- /// Delete file async
- /// </summary>
- /// <param name="smbFile"></param>
- /// <returns></returns>
- public static Task DeleteAsync(this SmbFile smbFile)
- {
- return Task.Run(() => smbFile.Delete());
- }
-
- /// <summary>
- /// Rename file async
- /// </summary>
- /// <param name="smbFile"></param>
- /// <param name="destination"></param>
- /// <returns></returns>
- public static Task RenameToAsync(this SmbFile smbFile, SmbFile destination)
- {
- return Task.Run(() => smbFile.RenameTo(destination));
- }
-
- /// <summary>
- /// Get input stream async
- /// </summary>
- /// <param name="smbFile"></param>
- /// <returns></returns>
- public static Task<InputStream> GetInputStreamAsync(this SmbFile smbFile)
- {
- return Task.Run(() => smbFile.GetInputStream());
- }
-
-
- /// <summary>
- /// Get output stream async
- /// </summary>
- /// <param name="smbFile"></param>
- /// <param name="append"></param>
- /// <returns></returns>
- public static Task<OutputStream> GetOutputStreamAsync(this SmbFile smbFile, bool append = false)
- {
- return Task.Run(() => new SmbFileOutputStream(smbFile, append) as OutputStream);
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileFilter.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileFilter.cs
deleted file mode 100644
index 196bfc1b6..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileFilter.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- public interface ISmbFileFilter
- {
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- bool Accept(SmbFile file);
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileInputStream.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileInputStream.cs
deleted file mode 100644
index a9a0ea112..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileInputStream.cs
+++ /dev/null
@@ -1,339 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using System.IO;
-using SharpCifs.Util.Sharpen;
-using SharpCifs.Util.Transport;
-
-namespace SharpCifs.Smb
-{
- /// <summary>This InputStream can read bytes from a file on an SMB file server.</summary>
- /// <remarks>This InputStream can read bytes from a file on an SMB file server. Offsets are 64 bits.
- /// </remarks>
- public class SmbFileInputStream : InputStream
- {
- private long _fp;
-
- private int _readSize;
-
- private int _openFlags;
-
- private int _access;
-
- private byte[] _tmp = new byte[1];
-
- internal SmbFile File;
-
- /// <summary>
- /// Creates an
- /// <see cref="System.IO.InputStream">System.IO.InputStream</see>
- /// for reading bytes from a file on
- /// an SMB server addressed by the <code>url</code> parameter. See
- /// <see cref="SmbFile">SmbFile</see>
- /// for a detailed description and examples of the smb
- /// URL syntax.
- /// </summary>
- /// <param name="url">An smb URL string representing the file to read from</param>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- public SmbFileInputStream(string url) : this(new SmbFile(url))
- {
- }
-
- /// <summary>
- /// Creates an
- /// <see cref="System.IO.InputStream">System.IO.InputStream</see>
- /// for reading bytes from a file on
- /// an SMB server represented by the
- /// <see cref="SmbFile">SmbFile</see>
- /// parameter. See
- /// <see cref="SmbFile">SmbFile</see>
- /// for a detailed description and examples of
- /// the smb URL syntax.
- /// </summary>
- /// <param name="file">An <code>SmbFile</code> specifying the file to read from</param>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- public SmbFileInputStream(SmbFile file) : this(file, SmbFile.ORdonly)
- {
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- internal SmbFileInputStream(SmbFile file, int openFlags)
- {
- this.File = file;
- this._openFlags = openFlags & 0xFFFF;
- _access = ((int)(((uint)openFlags) >> 16)) & 0xFFFF;
- if (file.Type != SmbFile.TypeNamedPipe)
- {
- file.Open(openFlags, _access, SmbFile.AttrNormal, 0);
- this._openFlags &= ~(SmbFile.OCreat | SmbFile.OTrunc);
- }
- else
- {
- file.Connect0();
- }
- _readSize = Math.Min(file.Tree.Session.transport.RcvBufSize - 70, file.Tree.Session
- .transport.Server.MaxBufferSize - 70);
- }
-
- protected internal virtual IOException SeToIoe(SmbException se)
- {
- IOException ioe = se;
- Exception root = se.GetRootCause();
- if (root is TransportException)
- {
- ioe = (TransportException)root;
- root = ((TransportException)ioe).GetRootCause();
- }
- if (root is Exception)
- {
- ioe = new IOException(root.Message);
- ioe.InitCause(root);
- }
- return ioe;
- }
-
- /// <summary>Closes this input stream and releases any system resources associated with the stream.
- /// </summary>
- /// <remarks>Closes this input stream and releases any system resources associated with the stream.
- /// </remarks>
- /// <exception cref="System.IO.IOException">if a network error occurs</exception>
- public override void Close()
- {
- try
- {
- File.Close();
- _tmp = null;
- }
- catch (SmbException se)
- {
- throw SeToIoe(se);
- }
- }
-
- /// <summary>Reads a byte of data from this input stream.</summary>
- /// <remarks>Reads a byte of data from this input stream.</remarks>
- /// <exception cref="System.IO.IOException">if a network error occurs</exception>
- public override int Read()
- {
- // need oplocks to cache otherwise use BufferedInputStream
- if (Read(_tmp, 0, 1) == -1)
- {
- return -1;
- }
- return _tmp[0] & unchecked(0xFF);
- }
-
- /// <summary>Reads up to b.length bytes of data from this input stream into an array of bytes.
- /// </summary>
- /// <remarks>Reads up to b.length bytes of data from this input stream into an array of bytes.
- /// </remarks>
- /// <exception cref="System.IO.IOException">if a network error occurs</exception>
- public override int Read(byte[] b)
- {
- return Read(b, 0, b.Length);
- }
-
- /// <summary>Reads up to len bytes of data from this input stream into an array of bytes.
- /// </summary>
- /// <remarks>Reads up to len bytes of data from this input stream into an array of bytes.
- /// </remarks>
- /// <exception cref="System.IO.IOException">if a network error occurs</exception>
- public override int Read(byte[] b, int off, int len)
- {
- return ReadDirect(b, off, len);
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- public virtual int ReadDirect(byte[] b, int off, int len)
- {
- if (len <= 0)
- {
- return 0;
- }
-
- long start = _fp;
- if (_tmp == null)
- {
- throw new IOException("Bad file descriptor");
- }
-
- // ensure file is open
- File.Open(_openFlags, _access, SmbFile.AttrNormal, 0);
- if (File.Log.Level >= 4)
- {
- File.Log.WriteLine("read: fid=" + File.Fid + ",off=" + off + ",len=" + len);
- }
-
- SmbComReadAndXResponse response = new SmbComReadAndXResponse(b, off);
- if (File.Type == SmbFile.TypeNamedPipe)
- {
- response.ResponseTimeout = 0;
- }
-
- int r;
- int n;
- do
- {
- r = len > _readSize ? _readSize : len;
- if (File.Log.Level >= 4)
- {
- File.Log.WriteLine("read: len=" + len + ",r=" + r + ",fp=" + _fp);
- }
-
- try
- {
- SmbComReadAndX request = new SmbComReadAndX(File.Fid, _fp, r, null);
- if (File.Type == SmbFile.TypeNamedPipe)
- {
- request.MinCount = request.MaxCount = request.Remaining = 1024;
- }
- //‚±‚±‚œǂݞ‚ñ‚Å‚¢‚é‚炵‚¢B
- File.Send(request, response);
- }
- catch (SmbException se)
- {
- if (File.Type == SmbFile.TypeNamedPipe && se.GetNtStatus() == NtStatus.NtStatusPipeBroken)
- {
- return -1;
- }
- throw SeToIoe(se);
- }
-
- if ((n = response.DataLength) <= 0)
- {
- return (int)((_fp - start) > 0L ? _fp - start : -1);
- }
-
- _fp += n;
- len -= n;
- response.Off += n;
- }
- while (len > 0 && n == r);
-
-
- return (int)(_fp - start);
- }
-
- /// <summary>This stream class is unbuffered.</summary>
- /// <remarks>
- /// This stream class is unbuffered. Therefore this method will always
- /// return 0 for streams connected to regular files. However, a
- /// stream created from a Named Pipe this method will query the server using a
- /// "peek named pipe" operation and return the number of available bytes
- /// on the server.
- /// </remarks>
- /// <exception cref="System.IO.IOException"></exception>
- public override int Available()
- {
- SmbNamedPipe pipe;
- TransPeekNamedPipe req;
- TransPeekNamedPipeResponse resp;
- if (File.Type != SmbFile.TypeNamedPipe)
- {
- return 0;
- }
- try
- {
- pipe = (SmbNamedPipe)File;
- File.Open(SmbFile.OExcl, pipe.PipeType & 0xFF0000, SmbFile.AttrNormal
- , 0);
- req = new TransPeekNamedPipe(File.Unc, File.Fid);
- resp = new TransPeekNamedPipeResponse(pipe);
- pipe.Send(req, resp);
- if (resp.status == TransPeekNamedPipeResponse.StatusDisconnected || resp.status
- == TransPeekNamedPipeResponse.StatusServerEndClosed)
- {
- File.Opened = false;
- return 0;
- }
- return resp.Available;
- }
- catch (SmbException se)
- {
- throw SeToIoe(se);
- }
- }
-
- /// <summary>Skip n bytes of data on this stream.</summary>
- /// <remarks>
- /// Skip n bytes of data on this stream. This operation will not result
- /// in any IO with the server. Unlink <tt>InputStream</tt> value less than
- /// the one provided will not be returned if it exceeds the end of the file
- /// (if this is a problem let us know).
- /// </remarks>
- /// <exception cref="System.IO.IOException"></exception>
- public override long Skip(long n)
- {
- if (n > 0)
- {
- _fp += n;
- return n;
- }
- return 0;
- }
-
-
- /// <summary>
- /// Position in Stream
- /// </summary>
- /// <remarks>
- /// Add by dobes
- /// mod interface to WrappedSystemStream readable, for random access.
- /// </remarks>
- internal override long Position {
- get { return this._fp; }
- set
- {
- var tmpPos = value;
- var length = File.Length();
- if (tmpPos < 0)
- tmpPos = 0;
- else if (length < tmpPos)
- tmpPos = length;
- this._fp = tmpPos;
- }
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- /// <remarks>
- /// Add by dobes
- /// mod interface to WrappedSystemStream readable, for random access.
- /// </remarks>
- internal override bool CanSeek()
- {
- return (File.Length() >= 0);
- }
-
- /// <summary>
- /// Get file length
- /// </summary>
- public override long Length
- {
- get { return File.Length(); }
- }
-
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileOutputStream.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileOutputStream.cs
deleted file mode 100644
index 58c704dd7..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileOutputStream.cs
+++ /dev/null
@@ -1,335 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System.IO;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- /// <summary>This <code>OutputStream</code> can write bytes to a file on an SMB file server.
- /// </summary>
- /// <remarks>This <code>OutputStream</code> can write bytes to a file on an SMB file server.
- /// </remarks>
- public class SmbFileOutputStream : OutputStream
- {
- private SmbFile _file;
-
- private bool _append;
-
- private bool _useNtSmbs;
-
- private int _openFlags;
-
- private int _access;
-
- private int _writeSize;
-
- private long _fp;
-
- private byte[] _tmp = new byte[1];
-
- private SmbComWriteAndX _reqx;
-
- private SmbComWriteAndXResponse _rspx;
-
- private SmbComWrite _req;
-
- private SmbComWriteResponse _rsp;
-
- /// <summary>
- /// Creates an
- /// <see cref="System.IO.OutputStream">System.IO.OutputStream</see>
- /// for writing to a file
- /// on an SMB server addressed by the URL parameter. See
- /// <see cref="SmbFile">SmbFile</see>
- /// for a detailed description and examples of
- /// the smb URL syntax.
- /// </summary>
- /// <param name="url">An smb URL string representing the file to write to</param>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- public SmbFileOutputStream(string url) : this(url, false)
- {
- }
-
- /// <summary>
- /// Creates an
- /// <see cref="System.IO.OutputStream">System.IO.OutputStream</see>
- /// for writing bytes to a file on
- /// an SMB server represented by the
- /// <see cref="SmbFile">SmbFile</see>
- /// parameter. See
- /// <see cref="SmbFile">SmbFile</see>
- /// for a detailed description and examples of
- /// the smb URL syntax.
- /// </summary>
- /// <param name="file">An <code>SmbFile</code> specifying the file to write to</param>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- public SmbFileOutputStream(SmbFile file) : this(file, false)
- {
- }
-
- /// <summary>
- /// Creates an
- /// <see cref="System.IO.OutputStream">System.IO.OutputStream</see>
- /// for writing bytes to a file on an
- /// SMB server addressed by the URL parameter. See
- /// <see cref="SmbFile">SmbFile</see>
- /// for a detailed description and examples of the smb URL syntax. If the
- /// second argument is <code>true</code>, then bytes will be written to the
- /// end of the file rather than the beginning.
- /// </summary>
- /// <param name="url">An smb URL string representing the file to write to</param>
- /// <param name="append">Append to the end of file</param>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- public SmbFileOutputStream(string url, bool append) : this(new SmbFile(url), append
- )
- {
- }
-
- /// <summary>
- /// Creates an
- /// <see cref="System.IO.OutputStream">System.IO.OutputStream</see>
- /// for writing bytes to a file
- /// on an SMB server addressed by the <code>SmbFile</code> parameter. See
- /// <see cref="SmbFile">SmbFile</see>
- /// for a detailed description and examples of
- /// the smb URL syntax. If the second argument is <code>true</code>, then
- /// bytes will be written to the end of the file rather than the beginning.
- /// </summary>
- /// <param name="file">An <code>SmbFile</code> representing the file to write to</param>
- /// <param name="append">Append to the end of file</param>
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- public SmbFileOutputStream(SmbFile file, bool append) : this(file, append, append
- ? SmbFile.OCreat | SmbFile.OWronly | SmbFile.OAppend : SmbFile.OCreat | SmbFile
- .OWronly | SmbFile.OTrunc)
- {
- }
-
- /// <summary>
- /// Creates an
- /// <see cref="System.IO.OutputStream">System.IO.OutputStream</see>
- /// for writing bytes to a file
- /// on an SMB server addressed by the <code>SmbFile</code> parameter. See
- /// <see cref="SmbFile">SmbFile</see>
- /// for a detailed description and examples of
- /// the smb URL syntax.
- /// <p>
- /// The second parameter specifies how the file should be shared. If
- /// <code>SmbFile.FILE_NO_SHARE</code> is specified the client will
- /// have exclusive access to the file. An additional open command
- /// from jCIFS or another application will fail with the "file is being
- /// accessed by another process" error. The <code>FILE_SHARE_READ</code>,
- /// <code>FILE_SHARE_WRITE</code>, and <code>FILE_SHARE_DELETE</code> may be
- /// combined with the bitwise OR '|' to specify that other peocesses may read,
- /// write, and/or delete the file while the jCIFS user has the file open.
- /// </summary>
- /// <param name="url">An smb URL representing the file to write to</param>
- /// <param name="shareAccess">File sharing flag: <code>SmbFile.FILE_NOSHARE</code> or any combination of <code>SmbFile.FILE_READ</code>, <code>SmbFile.FILE_WRITE</code>, and <code>SmbFile.FILE_DELETE</code>
- /// </param>
- /// <exception cref="Jcifs.Smb.SmbException"></exception>
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- public SmbFileOutputStream(string url, int shareAccess) : this(new SmbFile(url, string.Empty
- , null, shareAccess), false)
- {
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- internal SmbFileOutputStream(SmbFile file, bool append, int openFlags)
- {
- this._file = file;
- this._append = append;
- this._openFlags = openFlags;
- _access = ((int)(((uint)openFlags) >> 16)) & 0xFFFF;
- if (append)
- {
- try
- {
- _fp = file.Length();
- }
- catch (SmbAuthException sae)
- {
- throw;
- }
- catch (SmbException)
- {
- _fp = 0L;
- }
- }
- if (file is SmbNamedPipe && file.Unc.StartsWith("\\pipe\\"))
- {
- file.Unc = Runtime.Substring(file.Unc, 5);
- file.Send(new TransWaitNamedPipe("\\pipe" + file.Unc), new TransWaitNamedPipeResponse
- ());
- }
- file.Open(openFlags, _access | SmbConstants.FileWriteData, SmbFile.AttrNormal,
- 0);
- this._openFlags &= ~(SmbFile.OCreat | SmbFile.OTrunc);
- _writeSize = file.Tree.Session.transport.SndBufSize - 70;
- _useNtSmbs = file.Tree.Session.transport.HasCapability(SmbConstants.CapNtSmbs
- );
- if (_useNtSmbs)
- {
- _reqx = new SmbComWriteAndX();
- _rspx = new SmbComWriteAndXResponse();
- }
- else
- {
- _req = new SmbComWrite();
- _rsp = new SmbComWriteResponse();
- }
- }
-
- /// <summary>
- /// Closes this output stream and releases any system resources associated
- /// with it.
- /// </summary>
- /// <remarks>
- /// Closes this output stream and releases any system resources associated
- /// with it.
- /// </remarks>
- /// <exception cref="System.IO.IOException">if a network error occurs</exception>
- public override void Close()
- {
- _file.Close();
- _tmp = null;
- }
-
- /// <summary>Writes the specified byte to this file output stream.</summary>
- /// <remarks>Writes the specified byte to this file output stream.</remarks>
- /// <exception cref="System.IO.IOException">if a network error occurs</exception>
- public override void Write(int b)
- {
- _tmp[0] = unchecked((byte)b);
- Write(_tmp, 0, 1);
- }
-
- /// <summary>
- /// Writes b.length bytes from the specified byte array to this
- /// file output stream.
- /// </summary>
- /// <remarks>
- /// Writes b.length bytes from the specified byte array to this
- /// file output stream.
- /// </remarks>
- /// <exception cref="System.IO.IOException">if a network error occurs</exception>
- public override void Write(byte[] b)
- {
- Write(b, 0, b.Length);
- }
-
- public virtual bool IsOpen()
- {
- return _file.IsOpen();
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- internal virtual void EnsureOpen()
- {
- // ensure file is open
- if (_file.IsOpen() == false)
- {
- _file.Open(_openFlags, _access | SmbConstants.FileWriteData, SmbFile.AttrNormal,
- 0);
- if (_append)
- {
- _fp = _file.Length();
- }
- }
- }
-
- /// <summary>
- /// Writes len bytes from the specified byte array starting at
- /// offset off to this file output stream.
- /// </summary>
- /// <remarks>
- /// Writes len bytes from the specified byte array starting at
- /// offset off to this file output stream.
- /// </remarks>
- /// <param name="b">The array</param>
- /// <exception cref="System.IO.IOException">if a network error occurs</exception>
- public override void Write(byte[] b, int off, int len)
- {
- if (_file.IsOpen() == false && _file is SmbNamedPipe)
- {
- _file.Send(new TransWaitNamedPipe("\\pipe" + _file.Unc), new TransWaitNamedPipeResponse
- ());
- }
- WriteDirect(b, off, len, 0);
- }
-
- /// <summary>Just bypasses TransWaitNamedPipe - used by DCERPC bind.</summary>
- /// <remarks>Just bypasses TransWaitNamedPipe - used by DCERPC bind.</remarks>
- /// <exception cref="System.IO.IOException"></exception>
- public virtual void WriteDirect(byte[] b, int off, int len, int flags)
- {
- if (len <= 0)
- {
- return;
- }
- if (_tmp == null)
- {
- throw new IOException("Bad file descriptor");
- }
- EnsureOpen();
- /*if (file.log.level >= 4)
- {
- file.log.WriteLine("write: fid=" + file.fid + ",off=" + off + ",len=" + len);
- }*/
- int w;
- do
- {
- w = len > _writeSize ? _writeSize : len;
- if (_useNtSmbs)
- {
- _reqx.SetParam(_file.Fid, _fp, len - w, b, off, w);
- if ((flags & 1) != 0)
- {
- _reqx.SetParam(_file.Fid, _fp, len, b, off, w);
- _reqx.WriteMode = 0x8;
- }
- else
- {
- _reqx.WriteMode = 0;
- }
- _file.Send(_reqx, _rspx);
- _fp += _rspx.Count;
- len -= (int)_rspx.Count;
- off += (int)_rspx.Count;
- }
- else
- {
- _req.SetParam(_file.Fid, _fp, len - w, b, off, w);
- _fp += _rsp.Count;
- len -= (int)_rsp.Count;
- off += (int)_rsp.Count;
- _file.Send(_req, _rsp);
- }
- }
- while (len > 0);
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFilenameFilter.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFilenameFilter.cs
deleted file mode 100644
index b66dc133a..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFilenameFilter.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- public interface ISmbFilenameFilter
- {
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- bool Accept(SmbFile dir, string name);
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbNamedPipe.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbNamedPipe.cs
deleted file mode 100644
index f09e16cca..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbNamedPipe.cs
+++ /dev/null
@@ -1,210 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- /// <summary>
- /// This class will allow a Java program to read and write data to Named
- /// Pipes and Transact NamedPipes.
- /// </summary>
- /// <remarks>
- /// This class will allow a Java program to read and write data to Named
- /// Pipes and Transact NamedPipes.
- /// <p>There are three Win32 function calls provided by the Windows SDK
- /// that are important in the context of using jCIFS. They are:
- /// <ul>
- /// <li> <code>CallNamedPipe</code> A message-type pipe call that opens,
- /// writes to, reads from, and closes the pipe in a single operation.
- /// <li> <code>TransactNamedPipe</code> A message-type pipe call that
- /// writes to and reads from an existing pipe descriptor in one operation.
- /// <li> <code>CreateFile</code>, <code>ReadFile</code>,
- /// <code>WriteFile</code>, and <code>CloseFile</code> A byte-type pipe can
- /// be opened, written to, read from and closed using the standard Win32
- /// file operations.
- /// </ul>
- /// <p>The jCIFS API maps all of these operations into the standard Java
- /// <code>XxxputStream</code> interface. A special <code>PIPE_TYPE</code>
- /// flags is necessary to distinguish which type of Named Pipe behavior
- /// is desired.
- /// <p><table border="1" cellpadding="3" cellspacing="0" width="100%">
- /// <tr bgcolor="#ccccff">
- /// <td colspan="2"><b><code>SmbNamedPipe</code> Constructor Examples</b></td>
- /// <tr><td width="20%"><b>Code Sample</b></td><td><b>Description</b></td></tr>
- /// <tr><td width="20%"><pre>
- /// new SmbNamedPipe( "smb://server/IPC$/PIPE/foo",
- /// SmbNamedPipe.PIPE_TYPE_RDWR |
- /// SmbNamedPipe.PIPE_TYPE_CALL );
- /// </pre></td><td>
- /// Open the Named Pipe foo for reading and writing. The pipe will behave like the <code>CallNamedPipe</code> interface.
- /// </td></tr>
- /// <tr><td width="20%"><pre>
- /// new SmbNamedPipe( "smb://server/IPC$/foo",
- /// SmbNamedPipe.PIPE_TYPE_RDWR |
- /// SmbNamedPipe.PIPE_TYPE_TRANSACT );
- /// </pre></td><td>
- /// Open the Named Pipe foo for reading and writing. The pipe will behave like the <code>TransactNamedPipe</code> interface.
- /// </td></tr>
- /// <tr><td width="20%"><pre>
- /// new SmbNamedPipe( "smb://server/IPC$/foo",
- /// SmbNamedPipe.PIPE_TYPE_RDWR );
- /// </pre></td><td>
- /// Open the Named Pipe foo for reading and writing. The pipe will
- /// behave as though the <code>CreateFile</code>, <code>ReadFile</code>,
- /// <code>WriteFile</code>, and <code>CloseFile</code> interface was
- /// being used.
- /// </td></tr>
- /// </table>
- /// <p>See <a href="../../../pipes.html">Using jCIFS to Connect to Win32
- /// Named Pipes</a> for a detailed description of how to use jCIFS with
- /// Win32 Named Pipe server processes.
- /// </remarks>
- public class SmbNamedPipe : SmbFile
- {
- /// <summary>The pipe should be opened read-only.</summary>
- /// <remarks>The pipe should be opened read-only.</remarks>
- public const int PipeTypeRdonly = ORdonly;
-
- /// <summary>The pipe should be opened only for writing.</summary>
- /// <remarks>The pipe should be opened only for writing.</remarks>
- public const int PipeTypeWronly = OWronly;
-
- /// <summary>The pipe should be opened for both reading and writing.</summary>
- /// <remarks>The pipe should be opened for both reading and writing.</remarks>
- public const int PipeTypeRdwr = ORdwr;
-
- /// <summary>Pipe operations should behave like the <code>CallNamedPipe</code> Win32 Named Pipe function.
- /// </summary>
- /// <remarks>Pipe operations should behave like the <code>CallNamedPipe</code> Win32 Named Pipe function.
- /// </remarks>
- public const int PipeTypeCall = unchecked(0x0100);
-
- /// <summary>Pipe operations should behave like the <code>TransactNamedPipe</code> Win32 Named Pipe function.
- /// </summary>
- /// <remarks>Pipe operations should behave like the <code>TransactNamedPipe</code> Win32 Named Pipe function.
- /// </remarks>
- public const int PipeTypeTransact = unchecked(0x0200);
-
- public const int PipeTypeDceTransact = unchecked(0x0200) | unchecked(0x0400);
-
- internal InputStream PipeIn;
-
- internal OutputStream PipeOut;
-
- internal int PipeType;
-
- /// <summary>
- /// Open the Named Pipe resource specified by the url
- /// parameter.
- /// </summary>
- /// <remarks>
- /// Open the Named Pipe resource specified by the url
- /// parameter. The pipeType parameter should be at least one of
- /// the <code>PIPE_TYPE</code> flags combined with the bitwise OR
- /// operator <code>|</code>. See the examples listed above.
- /// </remarks>
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- public SmbNamedPipe(string url, int pipeType) : base(url)
- {
- this.PipeType = pipeType;
- Type = TypeNamedPipe;
- }
-
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- public SmbNamedPipe(string url, int pipeType, NtlmPasswordAuthentication auth) :
- base(url, auth)
- {
- this.PipeType = pipeType;
- Type = TypeNamedPipe;
- }
-
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- public SmbNamedPipe(Uri url, int pipeType, NtlmPasswordAuthentication auth) : base
- (url, auth)
- {
- this.PipeType = pipeType;
- Type = TypeNamedPipe;
- }
-
- /// <summary>
- /// Return the <code>InputStream</code> used to read information
- /// from this pipe instance.
- /// </summary>
- /// <remarks>
- /// Return the <code>InputStream</code> used to read information
- /// from this pipe instance. Presumably data would first be written
- /// to the <code>OutputStream</code> associated with this Named
- /// Pipe instance although this is not a requirement (e.g. a
- /// read-only named pipe would write data to this stream on
- /// connection). Reading from this stream may block. Therefore it
- /// may be necessary that an addition thread be used to read and
- /// write to a Named Pipe.
- /// </remarks>
- /// <exception cref="System.IO.IOException"></exception>
- public virtual InputStream GetNamedPipeInputStream()
- {
- if (PipeIn == null)
- {
- if ((PipeType & PipeTypeCall) == PipeTypeCall || (PipeType & PipeTypeTransact
- ) == PipeTypeTransact)
- {
- PipeIn = new TransactNamedPipeInputStream(this);
- }
- else
- {
- PipeIn = new SmbFileInputStream(this, (PipeType & unchecked((int)(0xFFFF00FF))) |
- OExcl);
- }
- }
- return PipeIn;
- }
-
- /// <summary>
- /// Return the <code>OutputStream</code> used to write
- /// information to this pipe instance.
- /// </summary>
- /// <remarks>
- /// Return the <code>OutputStream</code> used to write
- /// information to this pipe instance. The act of writing data
- /// to this stream will result in response data recieved in the
- /// <code>InputStream</code> associated with this Named Pipe
- /// instance (unless of course it does not elicite a response or the pipe is write-only).
- /// </remarks>
- /// <exception cref="System.IO.IOException"></exception>
- public virtual OutputStream GetNamedPipeOutputStream()
- {
- if (PipeOut == null)
- {
- if ((PipeType & PipeTypeCall) == PipeTypeCall || (PipeType & PipeTypeTransact
- ) == PipeTypeTransact)
- {
- PipeOut = new TransactNamedPipeOutputStream(this);
- }
- else
- {
- PipeOut = new SmbFileOutputStream(this, false, (PipeType & unchecked((int)(0xFFFF00FF
- ))) | OExcl);
- }
- }
- return PipeOut;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbRandomAccessFile.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbRandomAccessFile.cs
deleted file mode 100644
index 445a0656c..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbRandomAccessFile.cs
+++ /dev/null
@@ -1,506 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using System.IO;
-using System.Text;
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- public class SmbRandomAccessFile //: DataOutput, DataInput
- {
- private const int WriteOptions = unchecked(0x0842);
-
- private SmbFile _file;
-
- private long _fp;
-
- private int _openFlags;
-
- private int _access;
-
- private int _readSize;
-
- private int _writeSize;
-
- private int _ch;
-
- private int _options;
-
- private byte[] _tmp = new byte[8];
-
- private SmbComWriteAndXResponse _writeAndxResp;
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- public SmbRandomAccessFile(string url, string mode, int shareAccess) : this(new SmbFile
- (url, string.Empty, null, shareAccess), mode)
- {
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- public SmbRandomAccessFile(SmbFile file, string mode)
- {
- this._file = file;
- if (mode.Equals("r"))
- {
- _openFlags = SmbFile.OCreat | SmbFile.ORdonly;
- }
- else
- {
- if (mode.Equals("rw"))
- {
- _openFlags = SmbFile.OCreat | SmbFile.ORdwr | SmbFile.OAppend;
- _writeAndxResp = new SmbComWriteAndXResponse();
- _options = WriteOptions;
- _access = SmbConstants.FileReadData | SmbConstants.FileWriteData;
- }
- else
- {
- throw new ArgumentException("Invalid mode");
- }
- }
- file.Open(_openFlags, _access, SmbFile.AttrNormal, _options);
- _readSize = file.Tree.Session.transport.RcvBufSize - 70;
- _writeSize = file.Tree.Session.transport.SndBufSize - 70;
- _fp = 0L;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual int Read()
- {
- if (Read(_tmp, 0, 1) == -1)
- {
- return -1;
- }
- return _tmp[0] & unchecked(0xFF);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual int Read(byte[] b)
- {
- return Read(b, 0, b.Length);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual int Read(byte[] b, int off, int len)
- {
- if (len <= 0)
- {
- return 0;
- }
- long start = _fp;
- // ensure file is open
- if (_file.IsOpen() == false)
- {
- _file.Open(_openFlags, 0, SmbFile.AttrNormal, _options);
- }
- int r;
- int n;
- SmbComReadAndXResponse response = new SmbComReadAndXResponse(b, off);
- do
- {
- r = len > _readSize ? _readSize : len;
- _file.Send(new SmbComReadAndX(_file.Fid, _fp, r, null), response);
- if ((n = response.DataLength) <= 0)
- {
- return (int)((_fp - start) > 0L ? _fp - start : -1);
- }
- _fp += n;
- len -= n;
- response.Off += n;
- }
- while (len > 0 && n == r);
- return (int)(_fp - start);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public void ReadFully(byte[] b)
- {
- ReadFully(b, 0, b.Length);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public void ReadFully(byte[] b, int off, int len)
- {
- int n = 0;
- int count;
- do
- {
- count = Read(b, off + n, len - n);
- if (count < 0)
- {
- throw new SmbException("EOF");
- }
- n += count;
- _fp += count;
- }
- while (n < len);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual int SkipBytes(int n)
- {
- if (n > 0)
- {
- _fp += n;
- return n;
- }
- return 0;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void Write(int b)
- {
- _tmp[0] = unchecked((byte)b);
- Write(_tmp, 0, 1);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void Write(byte[] b)
- {
- Write(b, 0, b.Length);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void Write(byte[] b, int off, int len)
- {
- if (len <= 0)
- {
- return;
- }
- // ensure file is open
- if (_file.IsOpen() == false)
- {
- _file.Open(_openFlags, 0, SmbFile.AttrNormal, _options);
- }
- int w;
- do
- {
- w = len > _writeSize ? _writeSize : len;
- _file.Send(new SmbComWriteAndX(_file.Fid, _fp, len - w, b, off, w, null), _writeAndxResp
- );
- _fp += _writeAndxResp.Count;
- len -= (int)_writeAndxResp.Count;
- off += (int)_writeAndxResp.Count;
- }
- while (len > 0);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual long GetFilePointer()
- {
- return _fp;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void Seek(long pos)
- {
- _fp = pos;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual long Length()
- {
- return _file.Length();
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void SetLength(long newLength)
- {
- // ensure file is open
- if (_file.IsOpen() == false)
- {
- _file.Open(_openFlags, 0, SmbFile.AttrNormal, _options);
- }
- SmbComWriteResponse rsp = new SmbComWriteResponse();
- _file.Send(new SmbComWrite(_file.Fid, (int)(newLength & unchecked(0xFFFFFFFFL)), 0, _tmp, 0, 0), rsp);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void Close()
- {
- _file.Close();
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public bool ReadBoolean()
- {
- if ((Read(_tmp, 0, 1)) < 0)
- {
- throw new SmbException("EOF");
- }
- return _tmp[0] != unchecked(unchecked(0x00));
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public byte ReadByte()
- {
- if ((Read(_tmp, 0, 1)) < 0)
- {
- throw new SmbException("EOF");
- }
- return _tmp[0];
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public int ReadUnsignedByte()
- {
- if ((Read(_tmp, 0, 1)) < 0)
- {
- throw new SmbException("EOF");
- }
- return _tmp[0] & unchecked(0xFF);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public short ReadShort()
- {
- if ((Read(_tmp, 0, 2)) < 0)
- {
- throw new SmbException("EOF");
- }
- return Encdec.Dec_uint16be(_tmp, 0);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public int ReadUnsignedShort()
- {
- if ((Read(_tmp, 0, 2)) < 0)
- {
- throw new SmbException("EOF");
- }
- return Encdec.Dec_uint16be(_tmp, 0) & unchecked(0xFFFF);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public char ReadChar()
- {
- if ((Read(_tmp, 0, 2)) < 0)
- {
- throw new SmbException("EOF");
- }
- return (char)Encdec.Dec_uint16be(_tmp, 0);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public int ReadInt()
- {
- if ((Read(_tmp, 0, 4)) < 0)
- {
- throw new SmbException("EOF");
- }
- return Encdec.Dec_uint32be(_tmp, 0);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public long ReadLong()
- {
- if ((Read(_tmp, 0, 8)) < 0)
- {
- throw new SmbException("EOF");
- }
- return Encdec.Dec_uint64be(_tmp, 0);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public float ReadFloat()
- {
- if ((Read(_tmp, 0, 4)) < 0)
- {
- throw new SmbException("EOF");
- }
- return Encdec.Dec_floatbe(_tmp, 0);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public double ReadDouble()
- {
- if ((Read(_tmp, 0, 8)) < 0)
- {
- throw new SmbException("EOF");
- }
- return Encdec.Dec_doublebe(_tmp, 0);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public string ReadLine()
- {
- StringBuilder input = new StringBuilder();
- int c = -1;
- bool eol = false;
- while (!eol)
- {
- switch (c = Read())
- {
- case -1:
- case '\n':
- {
- eol = true;
- break;
- }
-
- case '\r':
- {
- eol = true;
- long cur = _fp;
- if (Read() != '\n')
- {
- _fp = cur;
- }
- break;
- }
-
- default:
- {
- input.Append((char)c);
- break;
- }
- }
- }
- if ((c == -1) && (input.Length == 0))
- {
- return null;
- }
- return input.ToString();
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public string ReadUtf()
- {
- int size = ReadUnsignedShort();
- byte[] b = new byte[size];
- Read(b, 0, size);
- try
- {
- return Encdec.Dec_utf8(b, 0, size);
- }
- catch (IOException ioe)
- {
- throw new SmbException(string.Empty, ioe);
- }
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public void WriteBoolean(bool v)
- {
- _tmp[0] = unchecked((byte)(v ? 1 : 0));
- Write(_tmp, 0, 1);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public void WriteByte(int v)
- {
- _tmp[0] = unchecked((byte)v);
- Write(_tmp, 0, 1);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public void WriteShort(int v)
- {
- Encdec.Enc_uint16be((short)v, _tmp, 0);
- Write(_tmp, 0, 2);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public void WriteChar(int v)
- {
- Encdec.Enc_uint16be((short)v, _tmp, 0);
- Write(_tmp, 0, 2);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public void WriteInt(int v)
- {
- Encdec.Enc_uint32be(v, _tmp, 0);
- Write(_tmp, 0, 4);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public void WriteLong(long v)
- {
- Encdec.Enc_uint64be(v, _tmp, 0);
- Write(_tmp, 0, 8);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public void WriteFloat(float v)
- {
- Encdec.Enc_floatbe(v, _tmp, 0);
- Write(_tmp, 0, 4);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public void WriteDouble(double v)
- {
- Encdec.Enc_doublebe(v, _tmp, 0);
- Write(_tmp, 0, 8);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public void WriteBytes(string s)
- {
- byte[] b = Runtime.GetBytesForString(s);
- Write(b, 0, b.Length);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /* public void WriteChars(string s)
- {
- int clen = s.Length;
- int blen = 2 * clen;
- byte[] b = new byte[blen];
- char[] c = new char[clen];
- Sharpen.Runtime.GetCharsForString(s, 0, clen, c, 0);
- for (int i = 0, j = 0; i < clen; i++)
- {
- b[j++] = unchecked((byte)((char)(((uchar)c[i]) >> 8)));
- b[j++] = unchecked((byte)((char)(((uchar)c[i]) >> 0)));
- }
- Write(b, 0, blen);
- }*/
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public void WriteUtf(string str)
- {
- int len = str.Length;
- int ch;
- int size = 0;
- byte[] dst;
- for (int i = 0; i < len; i++)
- {
- ch = str[i];
- size += ch > unchecked(0x07F) ? (ch > unchecked(0x7FF) ? 3 : 2) : 1;
- }
- dst = new byte[size];
- WriteShort(size);
- try
- {
- Encdec.Enc_utf8(str, dst, 0, size);
- }
- catch (IOException ioe)
- {
- throw new SmbException(string.Empty, ioe);
- }
- Write(dst, 0, size);
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbSession.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbSession.cs
deleted file mode 100644
index 6dc5087d0..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbSession.cs
+++ /dev/null
@@ -1,570 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Net;
-using SharpCifs.Netbios;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- public sealed class SmbSession
- {
- private static readonly string LogonShare = Config.GetProperty("jcifs.smb.client.logonShare"
- , null);
-
- private static readonly int LookupRespLimit = Config.GetInt("jcifs.netbios.lookupRespLimit"
- , 3);
-
- private static readonly string Domain = Config.GetProperty("jcifs.smb.client.domain"
- , null);
-
- private static readonly string Username = Config.GetProperty("jcifs.smb.client.username"
- , null);
-
- private static readonly int CachePolicy = Config.GetInt("jcifs.netbios.cachePolicy"
- , 60 * 10) * 60;
-
- internal static NbtAddress[] DcList;
-
- internal static long DcListExpiration;
-
- internal static int DcListCounter;
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- private static NtlmChallenge Interrogate(NbtAddress addr)
- {
- UniAddress dc = new UniAddress(addr);
- SmbTransport trans = SmbTransport.GetSmbTransport(dc, 0);
- if (Username == null)
- {
- trans.Connect();
- if (SmbTransport.LogStatic.Level >= 3)
- {
- SmbTransport.LogStatic.WriteLine("Default credentials (jcifs.smb.client.username/password)"
- + " not specified. SMB signing may not work propertly." + " Skipping DC interrogation."
- );
- }
- }
- else
- {
- SmbSession ssn = trans.GetSmbSession(NtlmPasswordAuthentication.Default
- );
- ssn.GetSmbTree(LogonShare, null).TreeConnect(null, null);
- }
- return new NtlmChallenge(trans.Server.EncryptionKey, dc);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- public static NtlmChallenge GetChallengeForDomain()
- {
- if (Domain == null)
- {
- throw new SmbException("A domain was not specified");
- }
- lock (Domain)
- {
- long now = Runtime.CurrentTimeMillis();
- int retry = 1;
- do
- {
- if (DcListExpiration < now)
- {
- NbtAddress[] list = NbtAddress.GetAllByName(Domain, 0x1C, null,
- null);
- DcListExpiration = now + CachePolicy * 1000L;
- if (list != null && list.Length > 0)
- {
- DcList = list;
- }
- else
- {
- DcListExpiration = now + 1000 * 60 * 15;
- if (SmbTransport.LogStatic.Level >= 2)
- {
- SmbTransport.LogStatic.WriteLine("Failed to retrieve DC list from WINS");
- }
- }
- }
- int max = Math.Min(DcList.Length, LookupRespLimit);
- for (int j = 0; j < max; j++)
- {
- int i = DcListCounter++ % max;
- if (DcList[i] != null)
- {
- try
- {
- return Interrogate(DcList[i]);
- }
- catch (SmbException se)
- {
- if (SmbTransport.LogStatic.Level >= 2)
- {
- SmbTransport.LogStatic.WriteLine("Failed validate DC: " + DcList[i]);
- if (SmbTransport.LogStatic.Level > 2)
- {
- Runtime.PrintStackTrace(se, SmbTransport.LogStatic);
- }
- }
- }
- DcList[i] = null;
- }
- }
- DcListExpiration = 0;
- }
- while (retry-- > 0);
- DcListExpiration = now + 1000 * 60 * 15;
- }
- throw new UnknownHostException("Failed to negotiate with a suitable domain controller for "
- + Domain);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- public static byte[] GetChallenge(UniAddress dc)
- {
- return GetChallenge(dc, 0);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- public static byte[] GetChallenge(UniAddress dc, int port)
- {
- SmbTransport trans = SmbTransport.GetSmbTransport(dc, port);
- trans.Connect();
- return trans.Server.EncryptionKey;
- }
-
- /// <summary>
- /// Authenticate arbitrary credentials represented by the
- /// <tt>NtlmPasswordAuthentication</tt> object against the domain controller
- /// specified by the <tt>UniAddress</tt> parameter.
- /// </summary>
- /// <remarks>
- /// Authenticate arbitrary credentials represented by the
- /// <tt>NtlmPasswordAuthentication</tt> object against the domain controller
- /// specified by the <tt>UniAddress</tt> parameter. If the credentials are
- /// not accepted, an <tt>SmbAuthException</tt> will be thrown. If an error
- /// occurs an <tt>SmbException</tt> will be thrown. If the credentials are
- /// valid, the method will return without throwing an exception. See the
- /// last <a href="../../../faq.html">FAQ</a> question.
- /// <p>
- /// See also the <tt>jcifs.smb.client.logonShare</tt> property.
- /// </remarks>
- /// <exception cref="SmbException"></exception>
- public static void Logon(UniAddress dc, NtlmPasswordAuthentication auth)
- {
- Logon(dc, -1, auth);
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public static void Logon(UniAddress dc, int port, NtlmPasswordAuthentication auth
- )
- {
- SmbTree tree = SmbTransport.GetSmbTransport(dc, port).GetSmbSession(auth).GetSmbTree
- (LogonShare, null);
- if (LogonShare == null)
- {
- tree.TreeConnect(null, null);
- }
- else
- {
- Trans2FindFirst2 req = new Trans2FindFirst2("\\", "*", SmbFile.AttrDirectory);
- Trans2FindFirst2Response resp = new Trans2FindFirst2Response();
- tree.Send(req, resp);
- }
- }
-
- internal int ConnectionState;
-
- internal int Uid;
-
- internal List<object> Trees;
-
- private UniAddress _address;
-
- private int _port;
-
- private int _localPort;
-
- private IPAddress _localAddr;
-
- internal SmbTransport transport;
-
- internal NtlmPasswordAuthentication Auth;
-
- internal long Expiration;
-
- internal string NetbiosName;
-
- internal SmbSession(UniAddress address, int port, IPAddress localAddr, int localPort
- , NtlmPasswordAuthentication auth)
- {
- // Transport parameters allows trans to be removed from CONNECTIONS
- this._address = address;
- this._port = port;
- this._localAddr = localAddr;
- this._localPort = localPort;
- this.Auth = auth;
- Trees = new List<object>();
- ConnectionState = 0;
- }
-
- internal SmbTree GetSmbTree(string share, string service)
- {
- lock (this)
- {
- SmbTree t;
- if (share == null)
- {
- share = "IPC$";
- }
- /*for (IEnumeration e = trees.GetEnumerator(); e.MoveNext(); )
- {
- t = (SmbTree)e.Current;
- if (t.Matches(share, service))
- {
- return t;
- }
- }*/
- foreach (var e in Trees)
- {
- t = (SmbTree)e;
- if (t.Matches(share, service))
- {
- return t;
- }
- }
-
- t = new SmbTree(this, share, service);
- Trees.Add(t);
- return t;
- }
- }
-
- internal bool Matches(NtlmPasswordAuthentication auth)
- {
- return this.Auth == auth || this.Auth.Equals(auth);
- }
-
- internal SmbTransport Transport()
- {
- lock (this)
- {
- if (transport == null)
- {
- transport = SmbTransport.GetSmbTransport(_address, _port, _localAddr, _localPort, null
- );
- }
- return transport;
- }
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal void Send(ServerMessageBlock request, ServerMessageBlock response)
- {
- lock (Transport())
- {
- if (response != null)
- {
- response.Received = false;
- }
- Expiration = Runtime.CurrentTimeMillis() + SmbConstants.SoTimeout;
- SessionSetup(request, response);
- if (response != null && response.Received)
- {
- return;
- }
- if (request is SmbComTreeConnectAndX)
- {
- SmbComTreeConnectAndX tcax = (SmbComTreeConnectAndX)request;
- if (NetbiosName != null && tcax.path.EndsWith("\\IPC$"))
- {
- tcax.path = "\\\\" + NetbiosName + "\\IPC$";
- }
- }
- request.Uid = Uid;
- request.Auth = Auth;
- try
- {
- transport.Send(request, response);
- }
- catch (SmbException se)
- {
- if (request is SmbComTreeConnectAndX)
- {
- Logoff(true);
- }
- request.Digest = null;
- throw;
- }
- }
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal void SessionSetup(ServerMessageBlock andx, ServerMessageBlock andxResponse
- )
- {
- lock (Transport())
- {
- NtlmContext nctx = null;
- SmbException ex = null;
- SmbComSessionSetupAndX request;
- SmbComSessionSetupAndXResponse response;
- byte[] token = new byte[0];
- int state = 10;
- while (ConnectionState != 0)
- {
- if (ConnectionState == 2 || ConnectionState == 3)
- {
- // connected or disconnecting
- return;
- }
- try
- {
- Runtime.Wait(transport);
- }
- catch (Exception ie)
- {
- throw new SmbException(ie.Message, ie);
- }
- }
- ConnectionState = 1;
- // trying ...
- try
- {
- transport.Connect();
- if (transport.Log.Level >= 4)
- {
- transport.Log.WriteLine("sessionSetup: accountName=" + Auth.Username + ",primaryDomain="
- + Auth.Domain);
- }
- Uid = 0;
- do
- {
- switch (state)
- {
- case 10:
- {
- if (Auth != NtlmPasswordAuthentication.Anonymous && transport.HasCapability(SmbConstants
- .CapExtendedSecurity))
- {
- state = 20;
- break;
- }
- request = new SmbComSessionSetupAndX(this, andx, Auth);
- response = new SmbComSessionSetupAndXResponse(andxResponse);
- if (transport.IsSignatureSetupRequired(Auth))
- {
- if (Auth.HashesExternal && NtlmPasswordAuthentication.DefaultPassword != NtlmPasswordAuthentication
- .Blank)
- {
- transport.GetSmbSession(NtlmPasswordAuthentication.Default).GetSmbTree(LogonShare
- , null).TreeConnect(null, null);
- }
- else
- {
- byte[] signingKey = Auth.GetSigningKey(transport.Server.EncryptionKey);
- request.Digest = new SigningDigest(signingKey, false);
- }
- }
- request.Auth = Auth;
- try
- {
- transport.Send(request, response);
- }
- catch (SmbAuthException sae)
- {
- throw;
- }
- catch (SmbException se)
- {
- ex = se;
- }
- if (response.IsLoggedInAsGuest && Runtime.EqualsIgnoreCase("GUEST", Auth.
- Username) == false && transport.Server.Security != SmbConstants.SecurityShare &&
- Auth != NtlmPasswordAuthentication.Anonymous)
- {
- throw new SmbAuthException(NtStatus.NtStatusLogonFailure);
- }
- if (ex != null)
- {
- throw ex;
- }
- Uid = response.Uid;
- if (request.Digest != null)
- {
- transport.Digest = request.Digest;
- }
- ConnectionState = 2;
- state = 0;
- break;
- }
-
- case 20:
- {
- if (nctx == null)
- {
- bool doSigning = (transport.Flags2 & SmbConstants.Flags2SecuritySignatures
- ) != 0;
- nctx = new NtlmContext(Auth, doSigning);
- }
- if (SmbTransport.LogStatic.Level >= 4)
- {
- SmbTransport.LogStatic.WriteLine(nctx);
- }
- if (nctx.IsEstablished())
- {
- NetbiosName = nctx.GetNetbiosName();
- ConnectionState = 2;
- state = 0;
- break;
- }
- try
- {
- token = nctx.InitSecContext(token, 0, token.Length);
- }
- catch (SmbException se)
- {
- try
- {
- transport.Disconnect(true);
- }
- catch (IOException)
- {
- }
- Uid = 0;
- throw;
- }
- if (token != null)
- {
- request = new SmbComSessionSetupAndX(this, null, token);
- response = new SmbComSessionSetupAndXResponse(null);
- if (transport.IsSignatureSetupRequired(Auth))
- {
- byte[] signingKey = nctx.GetSigningKey();
- if (signingKey != null)
- {
- request.Digest = new SigningDigest(signingKey, true);
- }
- }
- request.Uid = Uid;
- Uid = 0;
- try
- {
- transport.Send(request, response);
- }
- catch (SmbAuthException sae)
- {
- throw;
- }
- catch (SmbException se)
- {
- ex = se;
- try
- {
- transport.Disconnect(true);
- }
- catch (Exception)
- {
- }
- }
- if (response.IsLoggedInAsGuest && Runtime.EqualsIgnoreCase("GUEST", Auth.
- Username) == false)
- {
- throw new SmbAuthException(NtStatus.NtStatusLogonFailure);
- }
- if (ex != null)
- {
- throw ex;
- }
- Uid = response.Uid;
- if (request.Digest != null)
- {
- transport.Digest = request.Digest;
- }
- token = response.Blob;
- }
- break;
- }
-
- default:
- {
- throw new SmbException("Unexpected session setup state: " + state);
- }
- }
- }
- while (state != 0);
- }
- catch (SmbException se)
- {
- Logoff(true);
- ConnectionState = 0;
- throw;
- }
- finally
- {
- Runtime.NotifyAll(transport);
- }
- }
- }
-
- internal void Logoff(bool inError)
- {
- lock (Transport())
- {
- if (ConnectionState != 2)
- {
- // not-connected
- return;
- }
- ConnectionState = 3;
- // disconnecting
- NetbiosName = null;
-
- foreach (SmbTree t in Trees)
- {
- t.TreeDisconnect(inError);
- }
-
- if (!inError && transport.Server.Security != SmbConstants.SecurityShare)
- {
- SmbComLogoffAndX request = new SmbComLogoffAndX(null);
- request.Uid = Uid;
- try
- {
- transport.Send(request, null);
- }
- catch (SmbException)
- {
- }
- Uid = 0;
- }
- ConnectionState = 0;
- Runtime.NotifyAll(transport);
- }
- }
-
- public override string ToString()
- {
- return "SmbSession[accountName=" + Auth.Username + ",primaryDomain=" + Auth.Domain
- + ",uid=" + Uid + ",connectionState=" + ConnectionState + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbShareInfo.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbShareInfo.cs
deleted file mode 100644
index 811c76794..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbShareInfo.cs
+++ /dev/null
@@ -1,104 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-
-namespace SharpCifs.Smb
-{
- public class SmbShareInfo : IFileEntry
- {
- protected internal string NetName;
-
- protected internal int Type;
-
- protected internal string Remark;
-
- public SmbShareInfo()
- {
- }
-
- public SmbShareInfo(string netName, int type, string remark)
- {
- this.NetName = netName;
- this.Type = type;
- this.Remark = remark;
- }
-
- public virtual string GetName()
- {
- return NetName;
- }
-
- public new virtual int GetType()
- {
- switch (Type & unchecked(0xFFFF))
- {
- case 1:
- {
- return SmbFile.TypePrinter;
- }
-
- case 3:
- {
- return SmbFile.TypeNamedPipe;
- }
- }
- return SmbFile.TypeShare;
- }
-
- public virtual int GetAttributes()
- {
- return SmbFile.AttrReadonly | SmbFile.AttrDirectory;
- }
-
- public virtual long CreateTime()
- {
- return 0L;
- }
-
- public virtual long LastModified()
- {
- return 0L;
- }
-
- public virtual long Length()
- {
- return 0L;
- }
-
- public override bool Equals(object obj)
- {
- if (obj is SmbShareInfo)
- {
- SmbShareInfo si = (SmbShareInfo)obj;
- return NetName.Equals(si.NetName);
- }
- return false;
- }
-
- public override int GetHashCode()
- {
- int hashCode = NetName.GetHashCode();
- return hashCode;
- }
-
- public override string ToString()
- {
- return "SmbShareInfo[" + "netName=" + NetName + ",type=0x" + Hexdump.ToHexString
- (Type, 8) + ",remark=" + Remark + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbTransport.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbTransport.cs
deleted file mode 100644
index 800d6d9bc..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbTransport.cs
+++ /dev/null
@@ -1,977 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Net;
-using System.Net.Sockets;
-using SharpCifs.Netbios;
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-using SharpCifs.Util.Transport;
-
-namespace SharpCifs.Smb
-{
- public class SmbTransport : Transport
- {
- internal static readonly byte[] Buf = new byte[0xFFFF];
-
- internal static readonly SmbComNegotiate NegotiateRequest = new SmbComNegotiate(
- );
-
- internal static LogStream LogStatic = LogStream.GetInstance();
-
- internal static Hashtable DfsRoots = null;
-
-
- internal static SmbTransport GetSmbTransport(UniAddress address, int port
- )
- {
- lock (typeof(SmbTransport))
- {
- return GetSmbTransport(address, port, SmbConstants.Laddr, SmbConstants.Lport, null);
- }
- }
-
- internal static SmbTransport GetSmbTransport(UniAddress address, int port
- , IPAddress localAddr, int localPort, string hostName)
- {
- lock (typeof(SmbTransport))
- {
- SmbTransport conn;
-
- lock (SmbConstants.Connections)
- {
- if (SmbConstants.SsnLimit != 1)
- {
- conn =
- SmbConstants.Connections.FirstOrDefault(
- c =>
- c.Matches(address, port, localAddr, localPort, hostName) &&
- (SmbConstants.SsnLimit ==
- 0 || c.Sessions.Count < SmbConstants.SsnLimit));
-
- if (conn != null)
- {
- return conn;
- }
-
- }
-
- conn = new SmbTransport(address, port, localAddr, localPort);
- SmbConstants.Connections.Insert(0, conn);
- }
- return conn;
- }
- }
-
- internal class ServerData
- {
- internal byte Flags;
-
- internal int Flags2;
-
- internal int MaxMpxCount;
-
- internal int MaxBufferSize;
-
- internal int SessionKey;
-
- internal int Capabilities;
-
- internal string OemDomainName;
-
- internal int SecurityMode;
-
- internal int Security;
-
- internal bool EncryptedPasswords;
-
- internal bool SignaturesEnabled;
-
- internal bool SignaturesRequired;
-
- internal int MaxNumberVcs;
-
- internal int MaxRawSize;
-
- internal long ServerTime;
-
- internal int ServerTimeZone;
-
- internal int EncryptionKeyLength;
-
- internal byte[] EncryptionKey;
-
- internal byte[] Guid;
-
- internal ServerData(SmbTransport enclosing)
- {
- this._enclosing = enclosing;
- }
-
- private readonly SmbTransport _enclosing;
- }
-
- internal IPAddress LocalAddr;
-
- internal int LocalPort;
-
- internal UniAddress Address;
-
- internal SocketEx Socket;
-
- internal int Port;
-
- internal int Mid;
-
- internal OutputStream Out;
-
- internal InputStream In;
-
- internal byte[] Sbuf = new byte[512];
-
- internal SmbComBlankResponse Key = new SmbComBlankResponse();
-
- internal long SessionExpiration = Runtime.CurrentTimeMillis() + SmbConstants.SoTimeout;
-
- internal List<object> Referrals = new List<object>();
-
- internal SigningDigest Digest;
-
- internal List<SmbSession> Sessions = new List<SmbSession>();
-
- internal ServerData Server;
-
- internal int Flags2 = SmbConstants.Flags2;
-
- internal int MaxMpxCount = SmbConstants.MaxMpxCount;
-
- internal int SndBufSize = SmbConstants.SndBufSize;
-
- internal int RcvBufSize = SmbConstants.RcvBufSize;
-
- internal int Capabilities = SmbConstants.Capabilities;
-
- internal int SessionKey = 0x00000000;
-
- internal bool UseUnicode = SmbConstants.UseUnicode;
-
- internal string TconHostName;
-
- internal SmbTransport(UniAddress address, int port, IPAddress localAddr, int localPort
- )
- {
- Server = new ServerData(this);
- this.Address = address;
- this.Port = port;
- this.LocalAddr = localAddr;
- this.LocalPort = localPort;
- }
-
- internal virtual SmbSession GetSmbSession()
- {
- lock (this)
- {
- return GetSmbSession(new NtlmPasswordAuthentication(null, null, null));
- }
- }
-
- internal virtual SmbSession GetSmbSession(NtlmPasswordAuthentication auth)
- {
- lock (this)
- {
- SmbSession ssn;
- long now;
-
- ssn = Sessions.FirstOrDefault(s => s.Matches(auth));
- if (ssn != null)
- {
- ssn.Auth = auth;
- return ssn;
- }
-
- if (SmbConstants.SoTimeout > 0 && SessionExpiration < (now = Runtime.CurrentTimeMillis()))
- {
- SessionExpiration = now + SmbConstants.SoTimeout;
-
- foreach (var session in Sessions.Where(s => s.Expiration < now))
- {
- session.Logoff(false);
- }
- }
- ssn = new SmbSession(Address, Port, LocalAddr, LocalPort, auth);
- ssn.transport = this;
- Sessions.Add(ssn);
- return ssn;
- }
- }
-
- internal virtual bool Matches(UniAddress address, int port, IPAddress localAddr,
- int localPort, string hostName)
- {
- if (hostName == null)
- {
- hostName = address.GetHostName();
- }
- return (TconHostName == null || Runtime.EqualsIgnoreCase(hostName, TconHostName)) && address.Equals(this.Address) && (port == -1 || port == this.Port
- || (port == 445 && this.Port == 139)) && (localAddr == this.LocalAddr || (localAddr
- != null && localAddr.Equals(this.LocalAddr))) && localPort == this.LocalPort;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual bool HasCapability(int cap)
- {
- try
- {
- Connect(SmbConstants.ResponseTimeout);
- }
- catch (IOException ioe)
- {
- throw new SmbException(ioe.Message, ioe);
- }
- return (Capabilities & cap) == cap;
- }
-
- internal virtual bool IsSignatureSetupRequired(NtlmPasswordAuthentication auth)
- {
- return (Flags2 & SmbConstants.Flags2SecuritySignatures) != 0 && Digest ==
- null && auth != NtlmPasswordAuthentication.Null && NtlmPasswordAuthentication.Null
- .Equals(auth) == false;
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- internal virtual void Ssn139()
- {
- Name calledName = new Name(Address.FirstCalledName(), 0x20, null
- );
- do
- {
- Socket = new SocketEx(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- if (LocalAddr != null)
- {
- Socket.Bind2(new IPEndPoint(LocalAddr, LocalPort));
- }
-
- Socket.Connect(new IPEndPoint(IPAddress.Parse(Address.GetHostAddress()), 139), SmbConstants.ConnTimeout);
- Socket.SoTimeOut = SmbConstants.SoTimeout;
-
- Out = Socket.GetOutputStream();
- In = Socket.GetInputStream();
- SessionServicePacket ssp = new SessionRequestPacket(calledName, NbtAddress.GetLocalName
- ());
- Out.Write(Sbuf, 0, ssp.WriteWireFormat(Sbuf, 0));
- if (Readn(In, Sbuf, 0, 4) < 4)
- {
- try
- {
- //Socket.`Close` method deleted
- //Socket.Close();
- Socket.Dispose();
- }
- catch (IOException)
- {
- }
- throw new SmbException("EOF during NetBIOS session request");
- }
- switch (Sbuf[0] & 0xFF)
- {
- case SessionServicePacket.PositiveSessionResponse:
- {
- if (Log.Level >= 4)
- {
- Log.WriteLine("session established ok with " + Address);
- }
- return;
- }
-
- case SessionServicePacket.NegativeSessionResponse:
- {
- int errorCode = In.Read() & 0xFF;
- switch (errorCode)
- {
- case NbtException.CalledNotPresent:
- case NbtException.NotListeningCalled:
- {
- //Socket.`Close` method deleted
- //Socket.Close();
- Socket.Dispose();
- break;
- }
-
- default:
- {
- Disconnect(true);
- throw new NbtException(NbtException.ErrSsnSrvc, errorCode);
- }
- }
- break;
- }
-
- case -1:
- {
- Disconnect(true);
- throw new NbtException(NbtException.ErrSsnSrvc, NbtException.ConnectionRefused
- );
- }
-
- default:
- {
- Disconnect(true);
- throw new NbtException(NbtException.ErrSsnSrvc, 0);
- }
- }
- }
- while ((calledName.name = Address.NextCalledName()) != null);
- throw new IOException("Failed to establish session with " + Address);
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- private void Negotiate(int port, ServerMessageBlock resp)
- {
- lock (Sbuf)
- {
- if (port == 139)
- {
- Ssn139();
- }
- else
- {
- if (port == -1)
- {
- port = SmbConstants.DefaultPort;
- }
- // 445
- Socket = new SocketEx(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- if (LocalAddr != null)
- {
- Socket.Bind2(new IPEndPoint(LocalAddr, LocalPort));
- }
-
- Socket.Connect(new IPEndPoint(IPAddress.Parse(Address.GetHostAddress()), port), SmbConstants.ConnTimeout);
- Socket.SoTimeOut = SmbConstants.SoTimeout;
- Out = Socket.GetOutputStream();
- In = Socket.GetInputStream();
- }
- if (++Mid == 32000)
- {
- Mid = 1;
- }
- NegotiateRequest.Mid = Mid;
- int n = NegotiateRequest.Encode(Sbuf, 4);
- Encdec.Enc_uint32be(n & 0xFFFF, Sbuf, 0);
- if (Log.Level >= 4)
- {
- Log.WriteLine(NegotiateRequest);
- if (Log.Level >= 6)
- {
- Hexdump.ToHexdump(Log, Sbuf, 4, n);
- }
- }
- Out.Write(Sbuf, 0, 4 + n);
- Out.Flush();
- if (PeekKey() == null)
- {
- throw new IOException("transport closed in negotiate");
- }
- int size = Encdec.Dec_uint16be(Sbuf, 2) & 0xFFFF;
- if (size < 33 || (4 + size) > Sbuf.Length)
- {
- throw new IOException("Invalid payload size: " + size);
- }
- Readn(In, Sbuf, 4 + 32, size - 32);
- resp.Decode(Sbuf, 4);
- if (Log.Level >= 4)
- {
- Log.WriteLine(resp);
- if (Log.Level >= 6)
- {
- Hexdump.ToHexdump(Log, Sbuf, 4, n);
- }
- }
- }
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- public virtual void Connect()
- {
- try
- {
- base.Connect(SmbConstants.ResponseTimeout);
- }
- catch (TransportException te)
- {
- throw new SmbException("Failed to connect: " + Address, te);
- }
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- protected internal override void DoConnect()
- {
- SmbComNegotiateResponse resp = new SmbComNegotiateResponse(Server);
- try
- {
- Negotiate(Port, resp);
- }
- catch (ConnectException)
- {
- Port = (Port == -1 || Port == SmbConstants.DefaultPort) ? 139 : SmbConstants.DefaultPort;
- Negotiate(Port, resp);
- }
- if (resp.DialectIndex > 10)
- {
- throw new SmbException("This client does not support the negotiated dialect.");
- }
- if ((Server.Capabilities & SmbConstants.CapExtendedSecurity) != SmbConstants.CapExtendedSecurity && Server
- .EncryptionKeyLength != 8 && SmbConstants.LmCompatibility == 0)
- {
- throw new SmbException("Unexpected encryption key length: " + Server.EncryptionKeyLength
- );
- }
- TconHostName = Address.GetHostName();
- if (Server.SignaturesRequired || (Server.SignaturesEnabled && SmbConstants.Signpref))
- {
- Flags2 |= SmbConstants.Flags2SecuritySignatures;
- }
- else
- {
- Flags2 &= 0xFFFF ^ SmbConstants.Flags2SecuritySignatures;
- }
- MaxMpxCount = Math.Min(MaxMpxCount, Server.MaxMpxCount);
- if (MaxMpxCount < 1)
- {
- MaxMpxCount = 1;
- }
- SndBufSize = Math.Min(SndBufSize, Server.MaxBufferSize);
- Capabilities &= Server.Capabilities;
- if ((Server.Capabilities & SmbConstants.CapExtendedSecurity) == SmbConstants.CapExtendedSecurity)
- {
- Capabilities |= SmbConstants.CapExtendedSecurity;
- }
- // & doesn't copy high bit
- if ((Capabilities & SmbConstants.CapUnicode) == 0)
- {
- // server doesn't want unicode
- if (SmbConstants.ForceUnicode)
- {
- Capabilities |= SmbConstants.CapUnicode;
- }
- else
- {
- UseUnicode = false;
- Flags2 &= 0xFFFF ^ SmbConstants.Flags2Unicode;
- }
- }
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- protected internal override void DoDisconnect(bool hard)
- {
- try
- {
- foreach (var ssn in Sessions)
- {
- ssn.Logoff(hard);
- }
-
- Out.Close();
- In.Close();
-
- //Socket.`Close` method deleted
- //Socket.Close();
- Socket.Dispose();
- }
- finally
- {
- Digest = null;
- Socket = null;
- TconHostName = null;
- }
-
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- protected internal override void MakeKey(ServerMessageBlock request)
- {
- if (++Mid == 32000)
- {
- Mid = 1;
- }
- request.Mid = Mid;
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- protected internal override ServerMessageBlock PeekKey()
- {
- int n;
- do
- {
- if ((n = Readn(In, Sbuf, 0, 4)) < 4)
- {
- return null;
- }
- }
- while (Sbuf[0] == 0x85);
- if ((n = Readn(In, Sbuf, 4, 32)) < 32)
- {
- return null;
- }
- if (Log.Level >= 4)
- {
- Log.WriteLine("New data read: " + this);
- Hexdump.ToHexdump(Log, Sbuf, 4, 32);
- }
- for (; ; )
- {
- if (Sbuf[0] == 0x00 && Sbuf[1] == 0x00 &&
- Sbuf[4] == 0xFF &&
- Sbuf[5] == 'S' &&
- Sbuf[6] == 'M' &&
- Sbuf[7] == 'B')
- {
- break;
- }
- for (int i = 0; i < 35; i++)
- {
- Sbuf[i] = Sbuf[i + 1];
- }
- int b;
- if ((b = In.Read()) == -1)
- {
- return null;
- }
- Sbuf[35] = unchecked((byte)b);
- }
- Key.Mid = Encdec.Dec_uint16le(Sbuf, 34) & 0xFFFF;
- return Key;
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- protected internal override void DoSend(ServerMessageBlock request)
- {
- lock (Buf)
- {
- ServerMessageBlock smb = request;
- int n = smb.Encode(Buf, 4);
- Encdec.Enc_uint32be(n & 0xFFFF, Buf, 0);
- if (Log.Level >= 4)
- {
- do
- {
- Log.WriteLine(smb);
- }
- while (smb is AndXServerMessageBlock && (smb = ((AndXServerMessageBlock)smb).Andx
- ) != null);
- if (Log.Level >= 6)
- {
- Hexdump.ToHexdump(Log, Buf, 4, n);
- }
- }
- Out.Write(Buf, 0, 4 + n);
- }
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- protected internal virtual void DoSend0(ServerMessageBlock request)
- {
- try
- {
- DoSend(request);
- }
- catch (IOException ioe)
- {
- if (Log.Level > 2)
- {
- Runtime.PrintStackTrace(ioe, Log);
- }
- try
- {
- Disconnect(true);
- }
- catch (IOException ioe2)
- {
- Runtime.PrintStackTrace(ioe2, Log);
- }
- throw;
- }
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- protected internal override void DoRecv(Response response)
- {
- ServerMessageBlock resp = (ServerMessageBlock)response;
- resp.UseUnicode = UseUnicode;
- resp.ExtendedSecurity = (Capabilities & SmbConstants.CapExtendedSecurity) == SmbConstants.CapExtendedSecurity;
- lock (Buf)
- {
- Array.Copy(Sbuf, 0, Buf, 0, 4 + SmbConstants.HeaderLength);
- int size = Encdec.Dec_uint16be(Buf, 2) & 0xFFFF;
- if (size < (SmbConstants.HeaderLength + 1) || (4 + size) > RcvBufSize)
- {
- throw new IOException("Invalid payload size: " + size);
- }
- int errorCode = Encdec.Dec_uint32le(Buf, 9) & unchecked((int)(0xFFFFFFFF));
- if (resp.Command == ServerMessageBlock.SmbComReadAndx && (errorCode == 0 || errorCode
- == unchecked((int)(0x80000005))))
- {
- // overflow indicator normal for pipe
- SmbComReadAndXResponse r = (SmbComReadAndXResponse)resp;
- int off = SmbConstants.HeaderLength;
- Readn(In, Buf, 4 + off, 27);
- off += 27;
- resp.Decode(Buf, 4);
- int pad = r.DataOffset - off;
- if (r.ByteCount > 0 && pad > 0 && pad < 4)
- {
- Readn(In, Buf, 4 + off, pad);
- }
- if (r.DataLength > 0)
- {
- Readn(In, r.B, r.Off, r.DataLength);
- }
- }
- else
- {
- Readn(In, Buf, 4 + 32, size - 32);
- resp.Decode(Buf, 4);
- if (resp is SmbComTransactionResponse)
- {
- ((SmbComTransactionResponse)resp).Current();
- }
- }
- if (Digest != null && resp.ErrorCode == 0)
- {
- Digest.Verify(Buf, 4, resp);
- }
- if (Log.Level >= 4)
- {
- Log.WriteLine(response);
- if (Log.Level >= 6)
- {
- Hexdump.ToHexdump(Log, Buf, 4, size);
- }
- }
- }
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- protected internal override void DoSkip()
- {
- int size = Encdec.Dec_uint16be(Sbuf, 2) & 0xFFFF;
- if (size < 33 || (4 + size) > RcvBufSize)
- {
- In.Skip(In.Available());
- }
- else
- {
- In.Skip(size - 32);
- }
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual void CheckStatus(ServerMessageBlock req, ServerMessageBlock resp
- )
- {
- resp.ErrorCode = SmbException.GetStatusByCode(resp.ErrorCode);
- switch (resp.ErrorCode)
- {
- case NtStatus.NtStatusOk:
- {
- break;
- }
-
- case NtStatus.NtStatusAccessDenied:
- case NtStatus.NtStatusWrongPassword:
- case NtStatus.NtStatusLogonFailure:
- case NtStatus.NtStatusAccountRestriction:
- case NtStatus.NtStatusInvalidLogonHours:
- case NtStatus.NtStatusInvalidWorkstation:
- case NtStatus.NtStatusPasswordExpired:
- case NtStatus.NtStatusAccountDisabled:
- case NtStatus.NtStatusAccountLockedOut:
- case NtStatus.NtStatusTrustedDomainFailure:
- {
- throw new SmbAuthException(resp.ErrorCode);
- }
-
- case NtStatus.NtStatusPathNotCovered:
- {
- if (req.Auth == null)
- {
- throw new SmbException(resp.ErrorCode, null);
- }
- DfsReferral dr = GetDfsReferrals(req.Auth, req.Path, 1);
- if (dr == null)
- {
- throw new SmbException(resp.ErrorCode, null);
- }
- SmbFile.Dfs.Insert(req.Path, dr);
- throw dr;
- }
-
- case unchecked((int)(0x80000005)):
- {
- break;
- }
-
- case NtStatus.NtStatusMoreProcessingRequired:
- {
- break;
- }
-
- default:
- {
- throw new SmbException(resp.ErrorCode, null);
- }
- }
- if (resp.VerifyFailed)
- {
- throw new SmbException("Signature verification failed.");
- }
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual void Send(ServerMessageBlock request, ServerMessageBlock response
- )
- {
- Connect();
- request.Flags2 |= Flags2;
- request.UseUnicode = UseUnicode;
- request.Response = response;
- if (request.Digest == null)
- {
- request.Digest = Digest;
- }
- try
- {
- if (response == null)
- {
- DoSend0(request);
- return;
- }
- if (request is SmbComTransaction)
- {
- response.Command = request.Command;
- SmbComTransaction req = (SmbComTransaction)request;
- SmbComTransactionResponse resp = (SmbComTransactionResponse)response;
- req.MaxBufferSize = SndBufSize;
- resp.Reset();
- try
- {
- BufferCache.GetBuffers(req, resp);
- req.Current();
- if (req.MoveNext())
- {
- SmbComBlankResponse interim = new SmbComBlankResponse();
- Sendrecv(req, interim, SmbConstants.ResponseTimeout);
- if (interim.ErrorCode != 0)
- {
- CheckStatus(req, interim);
- }
- req.Current();
- }
- else
- {
- MakeKey(req);
- }
- lock (this)
- {
- response.Received = false;
- resp.IsReceived = false;
- try
- {
- ResponseMap.Put(req, resp);
- do
- {
- DoSend0(req);
- }
- while (req.MoveNext() && req.Current() != null);
- long timeout = SmbConstants.ResponseTimeout;
- resp.Expiration = Runtime.CurrentTimeMillis() + timeout;
- while (resp.MoveNext())
- {
- Runtime.Wait(this, timeout);
- timeout = resp.Expiration - Runtime.CurrentTimeMillis();
- if (timeout <= 0)
- {
- throw new TransportException(this + " timedout waiting for response to " + req);
- }
- }
- if (response.ErrorCode != 0)
- {
- CheckStatus(req, resp);
- }
- }
- catch (Exception ie)
- {
- if (ie is SmbException)
- {
- throw;
- }
- else
- {
- throw new TransportException(ie);
- }
- }
- finally
- {
- //Sharpen.Collections.Remove<Hashtable, SmbComTransaction>(response_map, req);
- ResponseMap.Remove(req);
- }
- }
- }
- finally
- {
- BufferCache.ReleaseBuffer(req.TxnBuf);
- BufferCache.ReleaseBuffer(resp.TxnBuf);
- }
- }
- else
- {
- response.Command = request.Command;
- Sendrecv(request, response, SmbConstants.ResponseTimeout);
- }
- }
- catch (SmbException se)
- {
- throw;
- }
- catch (IOException ioe)
- {
- throw new SmbException(ioe.Message, ioe);
- }
- CheckStatus(request, response);
- }
-
- public override string ToString()
- {
- return base.ToString() + "[" + Address + ":" + Port + "]";
- }
-
- internal virtual void DfsPathSplit(string path, string[] result)
- {
- int ri = 0;
- int rlast = result.Length - 1;
- int i = 0;
- int b = 0;
- int len = path.Length;
- do
- {
- if (ri == rlast)
- {
- result[rlast] = Runtime.Substring(path, b);
- return;
- }
- if (i == len || path[i] == '\\')
- {
- result[ri++] = Runtime.Substring(path, b, i);
- b = i + 1;
- }
- }
- while (i++ < len);
- while (ri < result.Length)
- {
- result[ri++] = string.Empty;
- }
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual DfsReferral GetDfsReferrals(NtlmPasswordAuthentication auth, string
- path, int rn)
- {
- SmbTree ipc = GetSmbSession(auth).GetSmbTree("IPC$", null);
- Trans2GetDfsReferralResponse resp = new Trans2GetDfsReferralResponse();
- ipc.Send(new Trans2GetDfsReferral(path), resp);
- if (resp.NumReferrals == 0)
- {
- return null;
- }
- if (rn == 0 || resp.NumReferrals < rn)
- {
- rn = resp.NumReferrals;
- }
- DfsReferral dr = new DfsReferral();
- string[] arr = new string[4];
- long expiration = Runtime.CurrentTimeMillis() + Dfs.Ttl * 1000;
- int di = 0;
- for (; ; )
- {
- dr.ResolveHashes = auth.HashesExternal;
- dr.Ttl = resp.Referrals[di].Ttl;
- dr.Expiration = expiration;
- if (path.Equals(string.Empty))
- {
- dr.Server = Runtime.Substring(resp.Referrals[di].Path, 1).ToLower();
- }
- else
- {
- DfsPathSplit(resp.Referrals[di].Node, arr);
- dr.Server = arr[1];
- dr.Share = arr[2];
- dr.Path = arr[3];
- }
- dr.PathConsumed = resp.PathConsumed;
- di++;
- if (di == rn)
- {
- break;
- }
- dr.Append(new DfsReferral());
- dr = dr.Next;
- }
- return dr.Next;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual DfsReferral[] __getDfsReferrals(NtlmPasswordAuthentication auth,
- string path, int rn)
- {
- SmbTree ipc = GetSmbSession(auth).GetSmbTree("IPC$", null);
- Trans2GetDfsReferralResponse resp = new Trans2GetDfsReferralResponse();
- ipc.Send(new Trans2GetDfsReferral(path), resp);
- if (rn == 0 || resp.NumReferrals < rn)
- {
- rn = resp.NumReferrals;
- }
- DfsReferral[] drs = new DfsReferral[rn];
- string[] arr = new string[4];
- long expiration = Runtime.CurrentTimeMillis() + Dfs.Ttl * 1000;
- for (int di = 0; di < drs.Length; di++)
- {
- DfsReferral dr = new DfsReferral();
- dr.ResolveHashes = auth.HashesExternal;
- dr.Ttl = resp.Referrals[di].Ttl;
- dr.Expiration = expiration;
- if (path.Equals(string.Empty))
- {
- dr.Server = Runtime.Substring(resp.Referrals[di].Path, 1).ToLower();
- }
- else
- {
- DfsPathSplit(resp.Referrals[di].Node, arr);
- dr.Server = arr[1];
- dr.Share = arr[2];
- dr.Path = arr[3];
- }
- dr.PathConsumed = resp.PathConsumed;
- drs[di] = dr;
- }
- return drs;
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbTree.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbTree.cs
deleted file mode 100644
index 8dc068c4c..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbTree.cs
+++ /dev/null
@@ -1,250 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- class SmbTree
- {
- private static int _treeConnCounter;
-
- internal int ConnectionState;
-
- internal int Tid;
-
- internal string Share;
-
- internal string Service = "?????";
-
- internal string Service0;
-
- internal SmbSession Session;
-
- internal bool InDfs;
-
- internal bool InDomainDfs;
-
- internal int TreeNum;
-
- internal SmbTree(SmbSession session, string share, string service)
- {
- // used by SmbFile.isOpen
- this.Session = session;
- this.Share = share.ToUpper();
- if (service != null && service.StartsWith("??") == false)
- {
- this.Service = service;
- }
- Service0 = this.Service;
- ConnectionState = 0;
- }
-
- internal virtual bool Matches(string share, string service)
- {
- return Runtime.EqualsIgnoreCase(this.Share, share) && (service == null ||
- service.StartsWith("??") || Runtime.EqualsIgnoreCase(this.Service, service
- ));
- }
-
- public override bool Equals(object obj)
- {
- if (obj is SmbTree)
- {
- SmbTree tree = (SmbTree)obj;
- return Matches(tree.Share, tree.Service);
- }
- return false;
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual void Send(ServerMessageBlock request, ServerMessageBlock response
- )
- {
- lock (Session.Transport())
- {
- if (response != null)
- {
- response.Received = false;
- }
- TreeConnect(request, response);
- if (request == null || (response != null && response.Received))
- {
- return;
- }
- if (Service.Equals("A:") == false)
- {
- switch (request.Command)
- {
- case ServerMessageBlock.SmbComOpenAndx:
- case ServerMessageBlock.SmbComNtCreateAndx:
- case ServerMessageBlock.SmbComReadAndx:
- case ServerMessageBlock.SmbComWriteAndx:
- case ServerMessageBlock.SmbComClose:
- case ServerMessageBlock.SmbComTreeDisconnect:
- {
- break;
- }
-
- case ServerMessageBlock.SmbComTransaction:
- case ServerMessageBlock.SmbComTransaction2:
- {
- switch (((SmbComTransaction)request).SubCommand & unchecked(0xFF))
- {
- case SmbComTransaction.NetShareEnum:
- case SmbComTransaction.NetServerEnum2:
- case SmbComTransaction.NetServerEnum3:
- case SmbComTransaction.TransPeekNamedPipe:
- case SmbComTransaction.TransWaitNamedPipe:
- case SmbComTransaction.TransCallNamedPipe:
- case SmbComTransaction.TransTransactNamedPipe:
- case SmbComTransaction.Trans2GetDfsReferral:
- {
- break;
- }
-
- default:
- {
- throw new SmbException("Invalid operation for " + Service + " service");
- }
- }
- break;
- }
-
- default:
- {
- throw new SmbException("Invalid operation for " + Service + " service" + request);
- }
- }
- }
- request.Tid = Tid;
- if (InDfs && !Service.Equals("IPC") && !string.IsNullOrEmpty(request.Path))
- {
- request.Flags2 = SmbConstants.Flags2ResolvePathsInDfs;
- request.Path = '\\' + Session.Transport().TconHostName + '\\' + Share + request.Path;
- }
- try
- {
- Session.Send(request, response);
- }
- catch (SmbException se)
- {
- if (se.GetNtStatus() == NtStatus.NtStatusNetworkNameDeleted)
- {
- TreeDisconnect(true);
- }
- throw;
- }
- }
- }
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- internal virtual void TreeConnect(ServerMessageBlock andx, ServerMessageBlock andxResponse
- )
- {
- lock (Session.Transport())
- {
- string unc;
- while (ConnectionState != 0)
- {
- if (ConnectionState == 2 || ConnectionState == 3)
- {
- // connected or disconnecting
- return;
- }
- try
- {
- Runtime.Wait(Session.transport);
- }
- catch (Exception ie)
- {
- throw new SmbException(ie.Message, ie);
- }
- }
- ConnectionState = 1;
- // trying ...
- try
- {
- Session.transport.Connect();
- unc = "\\\\" + Session.transport.TconHostName + '\\' + Share;
- Service = Service0;
- if (Session.transport.Log.Level >= 4)
- {
- Session.transport.Log.WriteLine("treeConnect: unc=" + unc + ",service=" + Service
- );
- }
- SmbComTreeConnectAndXResponse response = new SmbComTreeConnectAndXResponse(andxResponse
- );
- SmbComTreeConnectAndX request = new SmbComTreeConnectAndX(Session, unc, Service,
- andx);
- Session.Send(request, response);
- Tid = response.Tid;
- Service = response.Service;
- InDfs = response.ShareIsInDfs;
- TreeNum = _treeConnCounter++;
- ConnectionState = 2;
- }
- catch (SmbException se)
- {
- // connected
- TreeDisconnect(true);
- ConnectionState = 0;
- throw;
- }
- }
- }
-
- internal virtual void TreeDisconnect(bool inError)
- {
- lock (Session.Transport())
- {
- if (ConnectionState != 2)
- {
- // not-connected
- return;
- }
- ConnectionState = 3;
- // disconnecting
- if (!inError && Tid != 0)
- {
- try
- {
- Send(new SmbComTreeDisconnect(), null);
- }
- catch (SmbException se)
- {
- if (Session.transport.Log.Level > 1)
- {
- Runtime.PrintStackTrace(se, Session.transport.Log);
- }
- }
- }
- InDfs = false;
- InDomainDfs = false;
- ConnectionState = 0;
- Runtime.NotifyAll(Session.transport);
- }
- }
-
- public override string ToString()
- {
- return "SmbTree[share=" + Share + ",service=" + Service + ",tid=" + Tid + ",inDfs="
- + InDfs + ",inDomainDfs=" + InDomainDfs + ",connectionState=" + ConnectionState
- + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2FindFirst2.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2FindFirst2.cs
deleted file mode 100644
index 2ef874882..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2FindFirst2.cs
+++ /dev/null
@@ -1,146 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-
-namespace SharpCifs.Smb
-{
- internal class Trans2FindFirst2 : SmbComTransaction
- {
- private const int FlagsCloseAfterThisRequest = unchecked(0x01);
-
- private const int FlagsCloseIfEndReached = unchecked(0x02);
-
- private const int FlagsReturnResumeKeys = unchecked(0x04);
-
- private const int FlagsResumeFromPreviousEnd = unchecked(0x08);
-
- private const int FlagsFindWithBackupIntent = unchecked(0x10);
-
- private const int DefaultListSize = 65535;
-
- private const int DefaultListCount = 200;
-
- private int _searchAttributes;
-
- private int _flags;
-
- private int _informationLevel;
-
- private int _searchStorageType = 0;
-
- private string _wildcard;
-
- internal const int SmbInfoStandard = 1;
-
- internal const int SmbInfoQueryEaSize = 2;
-
- internal const int SmbInfoQueryEasFromList = 3;
-
- internal const int SmbFindFileDirectoryInfo = unchecked(0x101);
-
- internal const int SmbFindFileFullDirectoryInfo = unchecked(0x102);
-
- internal const int SmbFileNamesInfo = unchecked(0x103);
-
- internal const int SmbFileBothDirectoryInfo = unchecked(0x104);
-
- internal static readonly int ListSize = Config.GetInt("jcifs.smb.client.listSize"
- , DefaultListSize);
-
- internal static readonly int ListCount = Config.GetInt("jcifs.smb.client.listCount"
- , DefaultListCount);
-
- internal Trans2FindFirst2(string filename, string wildcard, int searchAttributes)
- {
- // flags
- // information levels
- if (filename.Equals("\\"))
- {
- Path = filename;
- }
- else
- {
- Path = filename + "\\";
- }
- this._wildcard = wildcard;
- this._searchAttributes = searchAttributes & unchecked(0x37);
- Command = SmbComTransaction2;
- SubCommand = Trans2FindFirst2;
- _flags = unchecked(0x00);
- _informationLevel = SmbFileBothDirectoryInfo;
- TotalDataCount = 0;
- MaxParameterCount = 10;
- MaxDataCount = ListSize;
- MaxSetupCount = 0;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- dst[dstIndex++] = SubCommand;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- return 2;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- WriteInt2(_searchAttributes, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(ListCount, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(_flags, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(_informationLevel, dst, dstIndex);
- dstIndex += 2;
- WriteInt4(_searchStorageType, dst, dstIndex);
- dstIndex += 4;
- dstIndex += WriteString(Path + _wildcard, dst, dstIndex);
- return dstIndex - start;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "Trans2FindFirst2[" + base.ToString() + ",searchAttributes=0x"
- + Hexdump.ToHexString(_searchAttributes, 2) + ",searchCount=" + ListCount + ",flags=0x"
- + Hexdump.ToHexString(_flags, 2) + ",informationLevel=0x" + Hexdump.ToHexString(
- _informationLevel, 3) + ",searchStorageType=" + _searchStorageType + ",filename="
- + Path + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2FindFirst2Response.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2FindFirst2Response.cs
deleted file mode 100644
index 71f780ff3..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2FindFirst2Response.cs
+++ /dev/null
@@ -1,262 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class Trans2FindFirst2Response : SmbComTransactionResponse
- {
- internal const int SmbInfoStandard = 1;
-
- internal const int SmbInfoQueryEaSize = 2;
-
- internal const int SmbInfoQueryEasFromList = 3;
-
- internal const int SmbFindFileDirectoryInfo = unchecked(0x101);
-
- internal const int SmbFindFileFullDirectoryInfo = unchecked(0x102);
-
- internal const int SmbFileNamesInfo = unchecked(0x103);
-
- internal const int SmbFileBothDirectoryInfo = unchecked(0x104);
-
- internal class SmbFindFileBothDirectoryInfo : IFileEntry
- {
- internal int NextEntryOffset;
-
- internal int FileIndex;
-
- internal long CreationTime;
-
- internal long LastAccessTime;
-
- internal long LastWriteTime;
-
- internal long ChangeTime;
-
- internal long EndOfFile;
-
- internal long AllocationSize;
-
- internal int ExtFileAttributes;
-
- internal int FileNameLength;
-
- internal int EaSize;
-
- internal int ShortNameLength;
-
- internal string ShortName;
-
- internal string Filename;
-
- // information levels
- public virtual string GetName()
- {
- return Filename;
- }
-
- public virtual int GetType()
- {
- return SmbFile.TypeFilesystem;
- }
-
- public virtual int GetAttributes()
- {
- return ExtFileAttributes;
- }
-
- public virtual long CreateTime()
- {
- return CreationTime;
- }
-
- public virtual long LastModified()
- {
- return LastWriteTime;
- }
-
- public virtual long Length()
- {
- return EndOfFile;
- }
-
- public override string ToString()
- {
- return "SmbFindFileBothDirectoryInfo[" + "nextEntryOffset=" + NextEntryOffset
- + ",fileIndex=" + FileIndex + ",creationTime=" + Extensions.CreateDate
- (CreationTime) + ",lastAccessTime=" + Extensions.CreateDate(LastAccessTime
- ) + ",lastWriteTime=" + Extensions.CreateDate(LastWriteTime) + ",changeTime="
- + Extensions.CreateDate(ChangeTime) + ",endOfFile=" + EndOfFile
- + ",allocationSize=" + AllocationSize + ",extFileAttributes=" + ExtFileAttributes
- + ",fileNameLength=" + FileNameLength + ",eaSize=" + EaSize + ",shortNameLength="
- + ShortNameLength + ",shortName=" + ShortName + ",filename=" + Filename
- + "]";
- }
-
- internal SmbFindFileBothDirectoryInfo(Trans2FindFirst2Response enclosing)
- {
- this._enclosing = enclosing;
- }
-
- private readonly Trans2FindFirst2Response _enclosing;
- }
-
- internal int Sid;
-
- internal bool IsEndOfSearch;
-
- internal int EaErrorOffset;
-
- internal int LastNameOffset;
-
- internal int LastNameBufferIndex;
-
- internal string LastName;
-
- internal int ResumeKey;
-
- public Trans2FindFirst2Response()
- {
- Command = SmbComTransaction2;
- SubCommand = Smb.SmbComTransaction.Trans2FindFirst2;
- }
-
- internal virtual string ReadString(byte[] src, int srcIndex, int len)
- {
- string str = null;
- try
- {
- if (UseUnicode)
- {
- // should Unicode alignment be corrected for here?
- str = Runtime.GetStringForBytes(src, srcIndex, len, SmbConstants.UniEncoding);
- }
- else
- {
- if (len > 0 && src[srcIndex + len - 1] == '\0')
- {
- len--;
- }
- str = Runtime.GetStringForBytes(src, srcIndex, len, SmbConstants.OemEncoding
- );
- }
- }
- catch (UnsupportedEncodingException uee)
- {
- if (Log.Level > 1)
- {
- Runtime.PrintStackTrace(uee, Log);
- }
- }
- return str;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- int start = bufferIndex;
- if (SubCommand == Smb.SmbComTransaction.Trans2FindFirst2)
- {
- Sid = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- }
- NumEntries = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- IsEndOfSearch = (buffer[bufferIndex] & unchecked(0x01)) == unchecked(0x01) ? true : false;
- bufferIndex += 2;
- EaErrorOffset = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- LastNameOffset = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- return bufferIndex - start;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- int start = bufferIndex;
- SmbFindFileBothDirectoryInfo e;
- LastNameBufferIndex = bufferIndex + LastNameOffset;
- Results = new SmbFindFileBothDirectoryInfo[NumEntries];
- for (int i = 0; i < NumEntries; i++)
- {
- Results[i] = e = new SmbFindFileBothDirectoryInfo(this);
- e.NextEntryOffset = ReadInt4(buffer, bufferIndex);
- e.FileIndex = ReadInt4(buffer, bufferIndex + 4);
- e.CreationTime = ReadTime(buffer, bufferIndex + 8);
- // e.lastAccessTime = readTime( buffer, bufferIndex + 16 );
- e.LastWriteTime = ReadTime(buffer, bufferIndex + 24);
- // e.changeTime = readTime( buffer, bufferIndex + 32 );
- e.EndOfFile = ReadInt8(buffer, bufferIndex + 40);
- // e.allocationSize = readInt8( buffer, bufferIndex + 48 );
- e.ExtFileAttributes = ReadInt4(buffer, bufferIndex + 56);
- e.FileNameLength = ReadInt4(buffer, bufferIndex + 60);
- // e.eaSize = readInt4( buffer, bufferIndex + 64 );
- // e.shortNameLength = buffer[bufferIndex + 68] & 0xFF;
- // e.shortName = readString( buffer, bufferIndex + 70, e.shortNameLength );
- e.Filename = ReadString(buffer, bufferIndex + 94, e.FileNameLength);
- if (LastNameBufferIndex >= bufferIndex && (e.NextEntryOffset == 0 || LastNameBufferIndex
- < (bufferIndex + e.NextEntryOffset)))
- {
- LastName = e.Filename;
- ResumeKey = e.FileIndex;
- }
- bufferIndex += e.NextEntryOffset;
- }
- //return bufferIndex - start;
- return DataCount;
- }
-
- public override string ToString()
- {
- string c;
- if (SubCommand == Smb.SmbComTransaction.Trans2FindFirst2)
- {
- c = "Trans2FindFirst2Response[";
- }
- else
- {
- c = "Trans2FindNext2Response[";
- }
- return c + base.ToString() + ",sid=" + Sid + ",searchCount=" + NumEntries
- + ",isEndOfSearch=" + IsEndOfSearch + ",eaErrorOffset=" + EaErrorOffset + ",lastNameOffset="
- + LastNameOffset + ",lastName=" + LastName + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2FindNext2.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2FindNext2.cs
deleted file mode 100644
index cb860f799..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2FindNext2.cs
+++ /dev/null
@@ -1,109 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-
-namespace SharpCifs.Smb
-{
- internal class Trans2FindNext2 : SmbComTransaction
- {
- private int _sid;
-
- private int _informationLevel;
-
- private int _resumeKey;
-
- private int _flags;
-
- private string _filename;
-
- internal Trans2FindNext2(int sid, int resumeKey, string filename)
- {
- this._sid = sid;
- this._resumeKey = resumeKey;
- this._filename = filename;
- Command = SmbComTransaction2;
- SubCommand = Trans2FindNext2;
- _informationLevel = Smb.Trans2FindFirst2.SmbFileBothDirectoryInfo;
- _flags = unchecked(0x00);
- MaxParameterCount = 8;
- MaxDataCount = Smb.Trans2FindFirst2.ListSize;
- MaxSetupCount = 0;
- }
-
- internal override void Reset(int resumeKey, string lastName)
- {
- base.Reset();
- this._resumeKey = resumeKey;
- _filename = lastName;
- Flags2 = 0;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- dst[dstIndex++] = SubCommand;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- return 2;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- WriteInt2(_sid, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(Smb.Trans2FindFirst2.ListCount, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(_informationLevel, dst, dstIndex);
- dstIndex += 2;
- WriteInt4(_resumeKey, dst, dstIndex);
- dstIndex += 4;
- WriteInt2(_flags, dst, dstIndex);
- dstIndex += 2;
- dstIndex += WriteString(_filename, dst, dstIndex);
- return dstIndex - start;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "Trans2FindNext2[" + base.ToString() + ",sid=" + _sid + ",searchCount="
- + Smb.Trans2FindFirst2.ListSize + ",informationLevel=0x" + Hexdump.ToHexString(_informationLevel
- , 3) + ",resumeKey=0x" + Hexdump.ToHexString(_resumeKey, 4) + ",flags=0x" + Hexdump
- .ToHexString(_flags, 2) + ",filename=" + _filename + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2GetDfsReferral.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2GetDfsReferral.cs
deleted file mode 100644
index c83de7973..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2GetDfsReferral.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class Trans2GetDfsReferral : SmbComTransaction
- {
- private int _maxReferralLevel = 3;
-
- internal Trans2GetDfsReferral(string filename)
- {
- Path = filename;
- Command = SmbComTransaction2;
- SubCommand = Trans2GetDfsReferral;
- TotalDataCount = 0;
- MaxParameterCount = 0;
- MaxDataCount = 4096;
- MaxSetupCount = unchecked(unchecked(0x00));
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- dst[dstIndex++] = SubCommand;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- return 2;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- WriteInt2(_maxReferralLevel, dst, dstIndex);
- dstIndex += 2;
- dstIndex += WriteString(Path, dst, dstIndex);
- return dstIndex - start;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "Trans2GetDfsReferral[" + base.ToString() + ",maxReferralLevel=0x"
- + _maxReferralLevel + ",filename=" + Path + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2GetDfsReferralResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2GetDfsReferralResponse.cs
deleted file mode 100644
index 5fa4a795d..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2GetDfsReferralResponse.cs
+++ /dev/null
@@ -1,179 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class Trans2GetDfsReferralResponse : SmbComTransactionResponse
- {
- internal class Referral
- {
- private int _version;
-
- private int _size;
-
- private int _serverType;
-
- private int _flags;
-
- private int _proximity;
-
- private int _pathOffset;
-
- private int _altPathOffset;
-
- private int _nodeOffset;
-
- private string _altPath;
-
- internal int Ttl;
-
- internal string Path;
-
- internal string Node;
-
- internal virtual int ReadWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- int start = bufferIndex;
- _version = ReadInt2(buffer, bufferIndex);
- if (_version != 3 && _version != 1)
- {
- throw new RuntimeException("Version " + _version + " referral not supported. Please report this to jcifs at samba dot org."
- );
- }
- bufferIndex += 2;
- _size = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- _serverType = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- _flags = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- if (_version == 3)
- {
- _proximity = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- Ttl = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- _pathOffset = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- _altPathOffset = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- _nodeOffset = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- Path = _enclosing.ReadString(buffer, start + _pathOffset, len, (_enclosing.Flags2 & SmbConstants.Flags2Unicode) != 0);
- if (_nodeOffset > 0)
- {
- Node = _enclosing.ReadString(buffer, start + _nodeOffset, len, (_enclosing.Flags2 & SmbConstants.Flags2Unicode) != 0);
- }
- }
- else
- {
- if (_version == 1)
- {
- Node = _enclosing.ReadString(buffer, bufferIndex, len, (_enclosing
- .Flags2 & SmbConstants.Flags2Unicode) != 0);
- }
- }
- return _size;
- }
-
- public override string ToString()
- {
- return "Referral[" + "version=" + _version + ",size=" + _size
- + ",serverType=" + _serverType + ",flags=" + _flags + ",proximity=" + _proximity + ",ttl=" + Ttl + ",pathOffset=" + _pathOffset + ",altPathOffset="
- + _altPathOffset + ",nodeOffset=" + _nodeOffset + ",path=" + Path
- + ",altPath=" + _altPath + ",node=" + Node + "]";
- }
-
- internal Referral(Trans2GetDfsReferralResponse enclosing)
- {
- this._enclosing = enclosing;
- }
-
- private readonly Trans2GetDfsReferralResponse _enclosing;
- }
-
- internal int PathConsumed;
-
- internal int NumReferrals;
-
- internal int flags;
-
- internal Referral[] Referrals;
-
- public Trans2GetDfsReferralResponse()
- {
- SubCommand = Smb.SmbComTransaction.Trans2GetDfsReferral;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- int start = bufferIndex;
- PathConsumed = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- if ((Flags2 & SmbConstants.Flags2Unicode) != 0)
- {
- PathConsumed /= 2;
- }
- NumReferrals = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- flags = ReadInt2(buffer, bufferIndex);
- bufferIndex += 4;
- Referrals = new Referral[NumReferrals];
- for (int ri = 0; ri < NumReferrals; ri++)
- {
- Referrals[ri] = new Referral(this);
- bufferIndex += Referrals[ri].ReadWireFormat(buffer, bufferIndex, len);
- }
- return bufferIndex - start;
- }
-
- public override string ToString()
- {
- return "Trans2GetDfsReferralResponse[" + base.ToString() + ",pathConsumed="
- + PathConsumed + ",numReferrals=" + NumReferrals + ",flags=" + flags + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryFSInformation.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryFSInformation.cs
deleted file mode 100644
index 27b350e53..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryFSInformation.cs
+++ /dev/null
@@ -1,80 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-
-namespace SharpCifs.Smb
-{
- internal class Trans2QueryFsInformation : SmbComTransaction
- {
- private int _informationLevel;
-
- internal Trans2QueryFsInformation(int informationLevel)
- {
- Command = SmbComTransaction2;
- SubCommand = Trans2QueryFsInformation;
- this._informationLevel = informationLevel;
- TotalParameterCount = 2;
- TotalDataCount = 0;
- MaxParameterCount = 0;
- MaxDataCount = 800;
- MaxSetupCount = 0;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- dst[dstIndex++] = SubCommand;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- return 2;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- WriteInt2(_informationLevel, dst, dstIndex);
- dstIndex += 2;
- return dstIndex - start;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "Trans2QueryFSInformation[" + base.ToString() + ",informationLevel=0x"
- + Hexdump.ToHexString(_informationLevel, 3) + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryFSInformationResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryFSInformationResponse.cs
deleted file mode 100644
index 2253e7b6f..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryFSInformationResponse.cs
+++ /dev/null
@@ -1,192 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class Trans2QueryFsInformationResponse : SmbComTransactionResponse
- {
- internal const int SMB_INFO_ALLOCATION = 1;
-
- internal const int SmbQueryFsSizeInfo = unchecked(0x103);
-
- internal const int SmbFsFullSizeInformation = 1007;
-
- internal class SmbInfoAllocation : IAllocInfo
- {
- internal long Alloc;
-
- internal long Free;
-
- internal int SectPerAlloc;
-
- internal int BytesPerSect;
-
- // information levels
- // Also handles SmbQueryFSSizeInfo
- public virtual long GetCapacity()
- {
- return Alloc * SectPerAlloc * BytesPerSect;
- }
-
- public virtual long GetFree()
- {
- return Free * SectPerAlloc * BytesPerSect;
- }
-
- public override string ToString()
- {
- return "SmbInfoAllocation[" + "alloc=" + Alloc + ",free=" + Free + ",sectPerAlloc=" + SectPerAlloc + ",bytesPerSect=" + BytesPerSect
- + "]";
- }
-
- internal SmbInfoAllocation(Trans2QueryFsInformationResponse enclosing)
- {
- this._enclosing = enclosing;
- }
-
- private readonly Trans2QueryFsInformationResponse _enclosing;
- }
-
- private int _informationLevel;
-
- internal IAllocInfo Info;
-
- internal Trans2QueryFsInformationResponse(int informationLevel)
- {
- this._informationLevel = informationLevel;
- Command = SmbComTransaction2;
- SubCommand = Smb.SmbComTransaction.Trans2QueryFsInformation;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- switch (_informationLevel)
- {
- case SMB_INFO_ALLOCATION:
- {
- return ReadSmbInfoAllocationWireFormat(buffer, bufferIndex);
- }
-
- case SmbQueryFsSizeInfo:
- {
- return ReadSmbQueryFsSizeInfoWireFormat(buffer, bufferIndex);
- }
-
- case SmbFsFullSizeInformation:
- {
- return ReadFsFullSizeInformationWireFormat(buffer, bufferIndex);
- }
-
- default:
- {
- return 0;
- }
- }
- }
-
- internal virtual int ReadSmbInfoAllocationWireFormat(byte[] buffer, int bufferIndex
- )
- {
- int start = bufferIndex;
- SmbInfoAllocation info = new SmbInfoAllocation
- (this);
- bufferIndex += 4;
- // skip idFileSystem
- info.SectPerAlloc = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- info.Alloc = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- info.Free = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- info.BytesPerSect = ReadInt2(buffer, bufferIndex);
- bufferIndex += 4;
- this.Info = info;
- return bufferIndex - start;
- }
-
- internal virtual int ReadSmbQueryFsSizeInfoWireFormat(byte[] buffer, int bufferIndex
- )
- {
- int start = bufferIndex;
- SmbInfoAllocation info = new SmbInfoAllocation
- (this);
- info.Alloc = ReadInt8(buffer, bufferIndex);
- bufferIndex += 8;
- info.Free = ReadInt8(buffer, bufferIndex);
- bufferIndex += 8;
- info.SectPerAlloc = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- info.BytesPerSect = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- this.Info = info;
- return bufferIndex - start;
- }
-
- internal virtual int ReadFsFullSizeInformationWireFormat(byte[] buffer, int bufferIndex
- )
- {
- int start = bufferIndex;
- SmbInfoAllocation info = new SmbInfoAllocation
- (this);
- // Read total allocation units.
- info.Alloc = ReadInt8(buffer, bufferIndex);
- bufferIndex += 8;
- // read caller available allocation units
- info.Free = ReadInt8(buffer, bufferIndex);
- bufferIndex += 8;
- // skip actual free units
- bufferIndex += 8;
- info.SectPerAlloc = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- info.BytesPerSect = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- this.Info = info;
- return bufferIndex - start;
- }
-
- public override string ToString()
- {
- return "Trans2QueryFSInformationResponse[" + base.ToString() + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryPathInformation.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryPathInformation.cs
deleted file mode 100644
index b3db64790..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryPathInformation.cs
+++ /dev/null
@@ -1,85 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-
-namespace SharpCifs.Smb
-{
- internal class Trans2QueryPathInformation : SmbComTransaction
- {
- private int _informationLevel;
-
- internal Trans2QueryPathInformation(string filename, int informationLevel)
- {
- Path = filename;
- this._informationLevel = informationLevel;
- Command = SmbComTransaction2;
- SubCommand = Trans2QueryPathInformation;
- TotalDataCount = 0;
- MaxParameterCount = 2;
- MaxDataCount = 40;
- MaxSetupCount = unchecked(unchecked(0x00));
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- dst[dstIndex++] = SubCommand;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- return 2;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- WriteInt2(_informationLevel, dst, dstIndex);
- dstIndex += 2;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- dst[dstIndex++] = unchecked(unchecked(0x00));
- dst[dstIndex++] = unchecked(unchecked(0x00));
- dst[dstIndex++] = unchecked(unchecked(0x00));
- dstIndex += WriteString(Path, dst, dstIndex);
- return dstIndex - start;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "Trans2QueryPathInformation[" + base.ToString() + ",informationLevel=0x"
- + Hexdump.ToHexString(_informationLevel, 3) + ",filename=" + Path + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryPathInformationResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryPathInformationResponse.cs
deleted file mode 100644
index 50650df62..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2QueryPathInformationResponse.cs
+++ /dev/null
@@ -1,227 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using SharpCifs.Util;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class Trans2QueryPathInformationResponse : SmbComTransactionResponse
- {
- internal const int SMB_QUERY_FILE_BASIC_INFO = unchecked(0x101);
-
- internal const int SMB_QUERY_FILE_STANDARD_INFO = unchecked(0x102);
-
- internal class SmbQueryFileBasicInfo : IInfo
- {
- internal long CreateTime;
-
- internal long LastAccessTime;
-
- internal long LastWriteTime;
-
- internal long ChangeTime;
-
- internal int Attributes;
-
- // information levels
- public virtual int GetAttributes()
- {
- return Attributes;
- }
-
- public virtual long GetCreateTime()
- {
- return CreateTime;
- }
-
- public virtual long GetLastWriteTime()
- {
- return LastWriteTime;
- }
-
- public virtual long GetSize()
- {
- return 0L;
- }
-
- public override string ToString()
- {
- return "SmbQueryFileBasicInfo[" + "createTime=" + Extensions.CreateDate
- (CreateTime) + ",lastAccessTime=" + Extensions.CreateDate(LastAccessTime
- ) + ",lastWriteTime=" + Extensions.CreateDate(LastWriteTime) + ",changeTime="
- + Extensions.CreateDate(ChangeTime) + ",attributes=0x" + Hexdump.ToHexString
- (Attributes, 4) + "]";
- }
-
- internal SmbQueryFileBasicInfo(Trans2QueryPathInformationResponse enclosing)
- {
- this._enclosing = enclosing;
- }
-
- private readonly Trans2QueryPathInformationResponse _enclosing;
- }
-
- internal class SmbQueryFileStandardInfo : IInfo
- {
- internal long AllocationSize;
-
- internal long EndOfFile;
-
- internal int NumberOfLinks;
-
- internal bool DeletePending;
-
- internal bool Directory;
-
- public virtual int GetAttributes()
- {
- return 0;
- }
-
- public virtual long GetCreateTime()
- {
- return 0L;
- }
-
- public virtual long GetLastWriteTime()
- {
- return 0L;
- }
-
- public virtual long GetSize()
- {
- return EndOfFile;
- }
-
- public override string ToString()
- {
- return "SmbQueryInfoStandard[" + "allocationSize=" + AllocationSize
- + ",endOfFile=" + EndOfFile + ",numberOfLinks=" + NumberOfLinks + ",deletePending="
- + DeletePending + ",directory=" + Directory + "]";
- }
-
- internal SmbQueryFileStandardInfo(Trans2QueryPathInformationResponse enclosing)
- {
- this._enclosing = enclosing;
- }
-
- private readonly Trans2QueryPathInformationResponse _enclosing;
- }
-
- private int _informationLevel;
-
- internal IInfo Info;
-
- internal Trans2QueryPathInformationResponse(int informationLevel)
- {
- this._informationLevel = informationLevel;
- SubCommand = Smb.SmbComTransaction.Trans2QueryPathInformation;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- // observed two zero bytes here with at least win98
- return 2;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- switch (_informationLevel)
- {
- case SMB_QUERY_FILE_BASIC_INFO:
- {
- return ReadSmbQueryFileBasicInfoWireFormat(buffer, bufferIndex);
- }
-
- case SMB_QUERY_FILE_STANDARD_INFO:
- {
- return ReadSmbQueryFileStandardInfoWireFormat(buffer, bufferIndex);
- }
-
- default:
- {
- return 0;
- }
- }
- }
-
- internal virtual int ReadSmbQueryFileStandardInfoWireFormat(byte[] buffer, int bufferIndex
- )
- {
- int start = bufferIndex;
- SmbQueryFileStandardInfo info = new SmbQueryFileStandardInfo
- (this);
- info.AllocationSize = ReadInt8(buffer, bufferIndex);
- bufferIndex += 8;
- info.EndOfFile = ReadInt8(buffer, bufferIndex);
- bufferIndex += 8;
- info.NumberOfLinks = ReadInt4(buffer, bufferIndex);
- bufferIndex += 4;
- info.DeletePending = (buffer[bufferIndex++] & unchecked(0xFF)) > 0;
- info.Directory = (buffer[bufferIndex++] & unchecked(0xFF)) > 0;
- this.Info = info;
- return bufferIndex - start;
- }
-
- internal virtual int ReadSmbQueryFileBasicInfoWireFormat(byte[] buffer, int bufferIndex
- )
- {
- int start = bufferIndex;
- SmbQueryFileBasicInfo info = new SmbQueryFileBasicInfo
- (this);
- info.CreateTime = ReadTime(buffer, bufferIndex);
- bufferIndex += 8;
- info.LastAccessTime = ReadTime(buffer, bufferIndex);
- bufferIndex += 8;
- info.LastWriteTime = ReadTime(buffer, bufferIndex);
- bufferIndex += 8;
- info.ChangeTime = ReadTime(buffer, bufferIndex);
- bufferIndex += 8;
- info.Attributes = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- this.Info = info;
- return bufferIndex - start;
- }
-
- public override string ToString()
- {
- return "Trans2QueryPathInformationResponse[" + base.ToString() + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2SetFileInformation.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2SetFileInformation.cs
deleted file mode 100644
index 289cab866..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2SetFileInformation.cs
+++ /dev/null
@@ -1,105 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class Trans2SetFileInformation : SmbComTransaction
- {
- internal const int SmbFileBasicInfo = unchecked(0x101);
-
- private int _fid;
-
- private int _attributes;
-
- private long _createTime;
-
- private long _lastWriteTime;
-
- internal Trans2SetFileInformation(int fid, int attributes, long createTime, long
- lastWriteTime)
- {
- this._fid = fid;
- this._attributes = attributes;
- this._createTime = createTime;
- this._lastWriteTime = lastWriteTime;
- Command = SmbComTransaction2;
- SubCommand = Trans2SetFileInformation;
- MaxParameterCount = 6;
- MaxDataCount = 0;
- MaxSetupCount = unchecked(unchecked(0x00));
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- dst[dstIndex++] = SubCommand;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- return 2;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- WriteInt2(_fid, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(SmbFileBasicInfo, dst, dstIndex);
- dstIndex += 2;
- WriteInt2(0, dst, dstIndex);
- dstIndex += 2;
- return dstIndex - start;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- int start = dstIndex;
- WriteTime(_createTime, dst, dstIndex);
- dstIndex += 8;
- WriteInt8(0L, dst, dstIndex);
- dstIndex += 8;
- WriteTime(_lastWriteTime, dst, dstIndex);
- dstIndex += 8;
- WriteInt8(0L, dst, dstIndex);
- dstIndex += 8;
- WriteInt2(unchecked(0x80) | _attributes, dst, dstIndex);
- dstIndex += 2;
- WriteInt8(0L, dst, dstIndex);
- dstIndex += 6;
- return dstIndex - start;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "Trans2SetFileInformation[" + base.ToString() + ",fid=" + _fid +
- "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2SetFileInformationResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2SetFileInformationResponse.cs
deleted file mode 100644
index b21f356b4..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/Trans2SetFileInformationResponse.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class Trans2SetFileInformationResponse : SmbComTransactionResponse
- {
- public Trans2SetFileInformationResponse()
- {
- SubCommand = Smb.SmbComTransaction.Trans2SetFileInformation;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "Trans2SetFileInformationResponse[" + base.ToString() + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransCallNamedPipe.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/TransCallNamedPipe.cs
deleted file mode 100644
index 404af0aaa..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransCallNamedPipe.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-
-namespace SharpCifs.Smb
-{
- internal class TransCallNamedPipe : SmbComTransaction
- {
- private byte[] _pipeData;
-
- private int _pipeDataOff;
-
- private int _pipeDataLen;
-
- internal TransCallNamedPipe(string pipeName, byte[] data, int off, int len)
- {
- Name = pipeName;
- _pipeData = data;
- _pipeDataOff = off;
- _pipeDataLen = len;
- Command = SmbComTransaction;
- SubCommand = TransCallNamedPipe;
- Timeout = unchecked((int)(0xFFFFFFFF));
- MaxParameterCount = 0;
- MaxDataCount = unchecked(0xFFFF);
- MaxSetupCount = unchecked(unchecked(0x00));
- SetupCount = 2;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- dst[dstIndex++] = SubCommand;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- // this says "Transaction priority" in netmon
- dst[dstIndex++] = unchecked(unchecked(0x00));
- // no FID
- dst[dstIndex++] = unchecked(unchecked(0x00));
- return 4;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- if ((dst.Length - dstIndex) < _pipeDataLen)
- {
- if (Log.Level >= 3)
- {
- Log.WriteLine("TransCallNamedPipe data too long for buffer");
- }
- return 0;
- }
- Array.Copy(_pipeData, _pipeDataOff, dst, dstIndex, _pipeDataLen);
- return _pipeDataLen;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "TransCallNamedPipe[" + base.ToString() + ",pipeName=" + Name +
- "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransCallNamedPipeResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/TransCallNamedPipeResponse.cs
deleted file mode 100644
index b86cc7fdb..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransCallNamedPipeResponse.cs
+++ /dev/null
@@ -1,77 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class TransCallNamedPipeResponse : SmbComTransactionResponse
- {
- private SmbNamedPipe _pipe;
-
- internal TransCallNamedPipeResponse(SmbNamedPipe pipe)
- {
- this._pipe = pipe;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- if (_pipe.PipeIn != null)
- {
- TransactNamedPipeInputStream @in = (TransactNamedPipeInputStream)_pipe.PipeIn;
- lock (@in.Lock)
- {
- @in.Receive(buffer, bufferIndex, len);
- Runtime.Notify(@in.Lock);
- }
- }
- return len;
- }
-
- public override string ToString()
- {
- return "TransCallNamedPipeResponse[" + base.ToString() + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransPeekNamedPipe.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/TransPeekNamedPipe.cs
deleted file mode 100644
index 9b80bbe1e..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransPeekNamedPipe.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class TransPeekNamedPipe : SmbComTransaction
- {
- private int _fid;
-
- internal TransPeekNamedPipe(string pipeName, int fid)
- {
- Name = pipeName;
- this._fid = fid;
- Command = SmbComTransaction;
- SubCommand = TransPeekNamedPipe;
- Timeout = unchecked((int)(0xFFFFFFFF));
- MaxParameterCount = 6;
- MaxDataCount = 1;
- MaxSetupCount = unchecked(unchecked(0x00));
- SetupCount = 2;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- dst[dstIndex++] = SubCommand;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- // this says "Transaction priority" in netmon
- WriteInt2(_fid, dst, dstIndex);
- return 4;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "TransPeekNamedPipe[" + base.ToString() + ",pipeName=" + Name +
- "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransPeekNamedPipeResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/TransPeekNamedPipeResponse.cs
deleted file mode 100644
index 6bcf2d07e..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransPeekNamedPipeResponse.cs
+++ /dev/null
@@ -1,84 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class TransPeekNamedPipeResponse : SmbComTransactionResponse
- {
- private SmbNamedPipe _pipe;
-
- private int _head;
-
- internal const int StatusDisconnected = 1;
-
- internal const int StatusListening = 2;
-
- internal const int StatusConnectionOk = 3;
-
- internal const int StatusServerEndClosed = 4;
-
- internal int status;
-
- internal int Available;
-
- internal TransPeekNamedPipeResponse(SmbNamedPipe pipe)
- {
- this._pipe = pipe;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- Available = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- _head = ReadInt2(buffer, bufferIndex);
- bufferIndex += 2;
- status = ReadInt2(buffer, bufferIndex);
- return 6;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "TransPeekNamedPipeResponse[" + base.ToString() + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransTransactNamedPipe.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/TransTransactNamedPipe.cs
deleted file mode 100644
index 1b6ec9cca..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransTransactNamedPipe.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-
-namespace SharpCifs.Smb
-{
- internal class TransTransactNamedPipe : SmbComTransaction
- {
- private byte[] _pipeData;
-
- private int _pipeFid;
-
- private int _pipeDataOff;
-
- private int _pipeDataLen;
-
- internal TransTransactNamedPipe(int fid, byte[] data, int off, int len)
- {
- _pipeFid = fid;
- _pipeData = data;
- _pipeDataOff = off;
- _pipeDataLen = len;
- Command = SmbComTransaction;
- SubCommand = TransTransactNamedPipe;
- MaxParameterCount = 0;
- MaxDataCount = unchecked(0xFFFF);
- MaxSetupCount = unchecked(unchecked(0x00));
- SetupCount = 2;
- Name = "\\PIPE\\";
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- dst[dstIndex++] = SubCommand;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- WriteInt2(_pipeFid, dst, dstIndex);
- dstIndex += 2;
- return 4;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- if ((dst.Length - dstIndex) < _pipeDataLen)
- {
- if (Log.Level >= 3)
- {
- Log.WriteLine("TransTransactNamedPipe data too long for buffer");
- }
- return 0;
- }
- Array.Copy(_pipeData, _pipeDataOff, dst, dstIndex, _pipeDataLen);
- return _pipeDataLen;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "TransTransactNamedPipe[" + base.ToString() + ",pipeFid=" + _pipeFid
- + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransTransactNamedPipeResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/TransTransactNamedPipeResponse.cs
deleted file mode 100644
index b8d14781c..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransTransactNamedPipeResponse.cs
+++ /dev/null
@@ -1,77 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class TransTransactNamedPipeResponse : SmbComTransactionResponse
- {
- private SmbNamedPipe _pipe;
-
- internal TransTransactNamedPipeResponse(SmbNamedPipe pipe)
- {
- this._pipe = pipe;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- if (_pipe.PipeIn != null)
- {
- TransactNamedPipeInputStream @in = (TransactNamedPipeInputStream)_pipe.PipeIn;
- lock (@in.Lock)
- {
- @in.Receive(buffer, bufferIndex, len);
- Runtime.Notify(@in.Lock);
- }
- }
- return len;
- }
-
- public override string ToString()
- {
- return "TransTransactNamedPipeResponse[" + base.ToString() + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransWaitNamedPipe.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/TransWaitNamedPipe.cs
deleted file mode 100644
index a184665aa..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransWaitNamedPipe.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class TransWaitNamedPipe : SmbComTransaction
- {
- internal TransWaitNamedPipe(string pipeName)
- {
- Name = pipeName;
- Command = SmbComTransaction;
- SubCommand = TransWaitNamedPipe;
- Timeout = unchecked((int)(0xFFFFFFFF));
- MaxParameterCount = 0;
- MaxDataCount = 0;
- MaxSetupCount = unchecked(unchecked(0x00));
- SetupCount = 2;
- }
-
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- dst[dstIndex++] = SubCommand;
- dst[dstIndex++] = unchecked(unchecked(0x00));
- dst[dstIndex++] = unchecked(unchecked(0x00));
- // no FID
- dst[dstIndex++] = unchecked(unchecked(0x00));
- return 4;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "TransWaitNamedPipe[" + base.ToString() + ",pipeName=" + Name +
- "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransWaitNamedPipeResponse.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/TransWaitNamedPipeResponse.cs
deleted file mode 100644
index a62a82ec7..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransWaitNamedPipeResponse.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class TransWaitNamedPipeResponse : SmbComTransactionResponse
- {
- // not much to this one is there :~)
- internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
- {
- return 0;
- }
-
- internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
- )
- {
- return 0;
- }
-
- internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
- len)
- {
- return 0;
- }
-
- internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
- {
- return 0;
- }
-
- public override string ToString()
- {
- return "TransWaitNamedPipeResponse[" + base.ToString() + "]";
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransactNamedPipeInputStream.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/TransactNamedPipeInputStream.cs
deleted file mode 100644
index 46d418582..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransactNamedPipeInputStream.cs
+++ /dev/null
@@ -1,180 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using System.IO;
-using SharpCifs.Util.Sharpen;
-
-namespace SharpCifs.Smb
-{
- internal class TransactNamedPipeInputStream : SmbFileInputStream
- {
- private const int InitPipeSize = 4096;
-
- private byte[] _pipeBuf = new byte[InitPipeSize];
-
- private int _begIdx;
-
- private int _nxtIdx;
-
- private int _used;
-
- private bool _dcePipe;
-
- internal object Lock;
-
- /// <exception cref="SharpCifs.Smb.SmbException"></exception>
- /// <exception cref="System.UriFormatException"></exception>
- /// <exception cref="UnknownHostException"></exception>
- internal TransactNamedPipeInputStream(SmbNamedPipe pipe) : base(pipe, (pipe.PipeType
- & unchecked((int)(0xFFFF00FF))) | SmbFile.OExcl)
- {
- _dcePipe = (pipe.PipeType & SmbNamedPipe.PipeTypeDceTransact) != SmbNamedPipe
- .PipeTypeDceTransact;
- Lock = new object();
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- public override int Read()
- {
- int result = -1;
- lock (Lock)
- {
- try
- {
- while (_used == 0)
- {
- Runtime.Wait(Lock);
- }
- }
- catch (Exception ie)
- {
- throw new IOException(ie.Message);
- }
- result = _pipeBuf[_begIdx] & unchecked(0xFF);
- _begIdx = (_begIdx + 1) % _pipeBuf.Length;
- }
- return result;
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- public override int Read(byte[] b)
- {
- return Read(b, 0, b.Length);
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- public override int Read(byte[] b, int off, int len)
- {
- int result = -1;
- int i;
- if (len <= 0)
- {
- return 0;
- }
- lock (Lock)
- {
- try
- {
- while (_used == 0)
- {
- Runtime.Wait(Lock);
- }
- }
- catch (Exception ie)
- {
- throw new IOException(ie.Message);
- }
- i = _pipeBuf.Length - _begIdx;
- result = len > _used ? _used : len;
- if (_used > i && result > i)
- {
- Array.Copy(_pipeBuf, _begIdx, b, off, i);
- off += i;
- Array.Copy(_pipeBuf, 0, b, off, result - i);
- }
- else
- {
- Array.Copy(_pipeBuf, _begIdx, b, off, result);
- }
- _used -= result;
- _begIdx = (_begIdx + result) % _pipeBuf.Length;
- }
- return result;
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- public override int Available()
- {
- if (File.Log.Level >= 3)
- {
- File.Log.WriteLine("Named Pipe available() does not apply to TRANSACT Named Pipes"
- );
- }
- return 0;
- }
-
- internal virtual int Receive(byte[] b, int off, int len)
- {
- int i;
- if (len > (_pipeBuf.Length - _used))
- {
- byte[] tmp;
- int newSize;
- newSize = _pipeBuf.Length * 2;
- if (len > (newSize - _used))
- {
- newSize = len + _used;
- }
- tmp = _pipeBuf;
- _pipeBuf = new byte[newSize];
- i = tmp.Length - _begIdx;
- if (_used > i)
- {
- Array.Copy(tmp, _begIdx, _pipeBuf, 0, i);
- Array.Copy(tmp, 0, _pipeBuf, i, _used - i);
- }
- else
- {
- Array.Copy(tmp, _begIdx, _pipeBuf, 0, _used);
- }
- _begIdx = 0;
- _nxtIdx = _used;
- tmp = null;
- }
- i = _pipeBuf.Length - _nxtIdx;
- if (len > i)
- {
- Array.Copy(b, off, _pipeBuf, _nxtIdx, i);
- off += i;
- Array.Copy(b, off, _pipeBuf, 0, len - i);
- }
- else
- {
- Array.Copy(b, off, _pipeBuf, _nxtIdx, len);
- }
- _nxtIdx = (_nxtIdx + len) % _pipeBuf.Length;
- _used += len;
- return len;
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- public virtual int Dce_read(byte[] b, int off, int len)
- {
- return base.Read(b, off, len);
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransactNamedPipeOutputStream.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/TransactNamedPipeOutputStream.cs
deleted file mode 100644
index d3e8d3e1a..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/TransactNamedPipeOutputStream.cs
+++ /dev/null
@@ -1,86 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- internal class TransactNamedPipeOutputStream : SmbFileOutputStream
- {
- private string _path;
-
- private SmbNamedPipe _pipe;
-
- private byte[] _tmp = new byte[1];
-
- private bool _dcePipe;
-
- /// <exception cref="System.IO.IOException"></exception>
- internal TransactNamedPipeOutputStream(SmbNamedPipe pipe) : base(pipe, false, (pipe
- .PipeType & unchecked((int)(0xFFFF00FF))) | SmbFile.OExcl)
- {
- this._pipe = pipe;
- _dcePipe = (pipe.PipeType & SmbNamedPipe.PipeTypeDceTransact) == SmbNamedPipe
- .PipeTypeDceTransact;
- _path = pipe.Unc;
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- public override void Close()
- {
- _pipe.Close();
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- public override void Write(int b)
- {
- _tmp[0] = unchecked((byte)b);
- Write(_tmp, 0, 1);
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- public override void Write(byte[] b)
- {
- Write(b, 0, b.Length);
- }
-
- /// <exception cref="System.IO.IOException"></exception>
- public override void Write(byte[] b, int off, int len)
- {
- if (len < 0)
- {
- len = 0;
- }
- if ((_pipe.PipeType & SmbNamedPipe.PipeTypeCall) == SmbNamedPipe.PipeTypeCall)
- {
- _pipe.Send(new TransWaitNamedPipe(_path), new TransWaitNamedPipeResponse());
- _pipe.Send(new TransCallNamedPipe(_path, b, off, len), new TransCallNamedPipeResponse
- (_pipe));
- }
- else
- {
- if ((_pipe.PipeType & SmbNamedPipe.PipeTypeTransact) == SmbNamedPipe.PipeTypeTransact)
- {
- EnsureOpen();
- TransTransactNamedPipe req = new TransTransactNamedPipe(_pipe.Fid, b, off, len);
- if (_dcePipe)
- {
- req.MaxDataCount = 1024;
- }
- _pipe.Send(req, new TransTransactNamedPipeResponse(_pipe));
- }
- }
- }
- }
-}
diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/WinError.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/WinError.cs
deleted file mode 100644
index daecc5407..000000000
--- a/Emby.Server.Implementations/IO/SharpCifs/Smb/WinError.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-// This code is derived from jcifs smb client library <jcifs at samba dot org>
-// Ported by J. Arturo <webmaster at komodosoft dot net>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-namespace SharpCifs.Smb
-{
- public static class WinError
- {
- public static int ErrorSuccess = 0;
-
- public static int ErrorAccessDenied = 5;
-
- public static int ErrorReqNotAccep = 71;
-
- public static int ErrorBadPipe = 230;
-
- public static int ErrorPipeBusy = 231;
-
- public static int ErrorNoData = 232;
-
- public static int ErrorPipeNotConnected = 233;
-
- public static int ErrorMoreData = 234;
-
- public static int ErrorNoBrowserServersFound = 6118;
-
- public static int[] WinerrCodes = { ErrorSuccess, ErrorAccessDenied,
- ErrorReqNotAccep, ErrorBadPipe, ErrorPipeBusy, ErrorNoData, ErrorPipeNotConnected
- , ErrorMoreData, ErrorNoBrowserServersFound };
-
- public static string[] WinerrMessages = { "The operation completed successfully."
- , "Access is denied.", "No more connections can be made to this remote computer at this time because there are already as many connections as the computer can accept."
- , "The pipe state is invalid.", "All pipe instances are busy.", "The pipe is being closed."
- , "No process is on the other end of the pipe.", "More data is available.", "The list of servers for this workgroup is not currently available."
- };
- }
-}