Example #1
0
        protected override long GetLength(NodeBase node)
        {
            try
            {
                long length = 0L;

                if (node.NodeType == NodeType.File)
                {
                    WindowsIdentity.RunImpersonated(_userToken, () =>
                    {
                        var file = SmbFileSystemHelper.FilePathToCIFS(_userMount + node.Path.StringPath);

                        length = file.Length;
                    });
                }
                else
                {
                    throw new NotImplementedException();
                }

                return(length);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #2
0
        protected override NodeBase SetAttributes(NodeBase node, NodeAttributes attributes)
        {
            try
            {
                if (node.NodeType == NodeType.Directory)
                {
                    WindowsIdentity.RunImpersonated(_userToken, () =>
                    {
                        var folder = SmbFileSystemHelper.FolderPathToCIFS(_userMount + node.Path.StringPath);

                        folder.Attributes = attributes.FileAttributes;
                    });
                }
                else if (node.NodeType == NodeType.File)
                {
                    WindowsIdentity.RunImpersonated(_userToken, () =>
                    {
                        var file = SmbFileSystemHelper.FilePathToCIFS(_userMount + node.Path.StringPath);

                        file.Attributes = attributes.FileAttributes;
                    });
                }
                else
                {
                    throw new NotImplementedException();
                }

                return(node);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #3
0
        protected override NodeContent GetContent(NodeBase node, NodeContentParameters contentParameters)
        {
            var callPath = $"{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}";

            try
            {
                if (!node.Exists())
                {
                    return(NodeContent.CreateDelayedWriteContent(new MemoryStream()));
                }

                NodeContent content = null;

                if (node.NodeType == NodeType.File)
                {
                    WindowsIdentity.RunImpersonated(_userToken, () =>
                    {
                        var file = SmbFileSystemHelper.FilePathToCIFS(_userMount + node.Path.StringPath);

                        content = NodeContent.CreateDelayedWriteContent(File.Open(file.FullName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite));
                    });
                }
                else
                {
                    throw new NotImplementedException();
                }

                return(content);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #4
0
        protected override NodeBase GetChild(string name, DirectoryNode parent)
        {
            try
            {
                NodeBase child = null;

                WindowsIdentity.RunImpersonated(_userToken, () =>
                {
                    var folder = SmbFileSystemHelper.FolderPathToCIFS(_userMount + parent.Path.StringPath
                                                                      + Path.DirectorySeparatorChar + name);

                    if (folder.Exists)
                    {
                        child = new DirectoryNode(name, parent,
                                                  new NodeTimeInfo(folder.CreationTime, folder.LastAccessTime, folder.LastWriteTime));
                    }

                    var file = SmbFileSystemHelper.FilePathToCIFS(_userMount + parent.Path.StringPath
                                                                  + Path.DirectorySeparatorChar + name);

                    if (file.Exists)
                    {
                        child = new FileNode(name, parent,
                                             new NodeTimeInfo(file.CreationTime, file.LastAccessTime, file.LastWriteTime));
                    }
                });

                return(child);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #5
0
        protected override FileNode CreateFile(DirectoryNode parent, FileNode child)
        {
            try
            {
                WindowsIdentity.RunImpersonated(_userToken, () =>
                {
                    var folder = SmbFileSystemHelper.FolderPathToCIFS(_userMount + parent.Path.StringPath);

                    if (!folder.Exists)
                    {
                        folder.Create();
                    }

                    var file = SmbFileSystemHelper.FilePathToCIFS(_userMount + child.Path.StringPath);

                    using (var fs = new FileStream(file.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) { }
                });

                return(child);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #6
0
        protected override NodeBase Rename(NodeBase node, string newName)
        {
            var callPath = $"{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}";

            try
            {
                NodeBase newNode      = null;
                var      parentFolder = SmbFileSystemHelper.FolderPathToCIFS(_userMount + node.Parent.Path.StringPath);

                if (node.NodeType == NodeType.Directory)
                {
                    WindowsIdentity.RunImpersonated(_userToken, () =>
                    {
                        var folder    = SmbFileSystemHelper.FolderPathToCIFS(_userMount + node.Path.StringPath);
                        var newFolder = SmbFileSystemHelper.FolderPathToCIFS(_userMount + node.Parent.Path.StringPath
                                                                             + Path.DirectorySeparatorChar + newName);

                        folder.MoveTo(newFolder.FullName);

                        Log.Information($"'{callPath}' '{_userEntity.IdentityAlias}' from '{folder.Name}' [{folder.FullName}] to '{newFolder.Name}' [{newFolder.FullName}]" +
                                        $" run as '{WindowsIdentity.GetCurrent().Name}'");
                    });

                    newNode = new DirectoryNode(newName, node.Parent);
                }
                else if (node.NodeType == NodeType.File)
                {
                    WindowsIdentity.RunImpersonated(_userToken, () =>
                    {
                        var file    = SmbFileSystemHelper.FilePathToCIFS(_userMount + node.Path.StringPath);
                        var newFile = SmbFileSystemHelper.FilePathToCIFS(_userMount + node.Parent.Path.StringPath
                                                                         + Path.DirectorySeparatorChar + newName);

                        file.MoveTo(newFile.FullName);

                        Log.Information($"'{callPath}' '{_userEntity.IdentityAlias}' from '{file.Name}' [{file.FullName}] to '{newFile.Name}' [{newFile.FullName}]" +
                                        $" run as '{WindowsIdentity.GetCurrent().Name}'");
                    });

                    newNode = new FileNode(newName, node.Parent);
                }
                else
                {
                    throw new NotImplementedException();
                }

                return(newNode);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #7
0
        protected override NodeBase SaveContent(NodeBase node, NodeContent content)
        {
            var callPath = $"{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}";

            DirectoryInfo folder = null;
            FileInfo      file   = null;

            try
            {
                if (!node.Exists())
                {
                    return(node);
                }

                if (node.NodeType == NodeType.File)
                {
                    WindowsIdentity.RunImpersonated(_userToken, () =>
                    {
                        folder = SmbFileSystemHelper.FolderPathToCIFS(_userMount + node.Parent.Path.StringPath);

                        if (!folder.Exists)
                        {
                            folder.Create();
                        }

                        file = SmbFileSystemHelper.FilePathToCIFS(_userMount + node.Path.StringPath);

                        using (var fs = new FileStream(file.FullName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                            content.GetStream().CopyTo(fs);

                        Log.Information($"'{callPath}' '{_userEntity.IdentityAlias}' file '{node.Path}' to '{file.FullName}'" +
                                        $" run as '{WindowsIdentity.GetCurrent().Name}'");
                    });
                }
                else
                {
                    throw new NotImplementedException();
                }

                return(node);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #8
0
        protected override NodeBase Delete(NodeBase node)
        {
            var callPath = $"{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}";

            try
            {
                if (!node.Exists())
                {
                    return(node);
                }

                if (node.NodeType == NodeType.Directory)
                {
                    WindowsIdentity.RunImpersonated(_userToken, () =>
                    {
                        var folder = SmbFileSystemHelper.FolderPathToCIFS(_userMount + node.Path.StringPath);
                        folder.Delete();

                        Log.Information($"'{callPath}' '{_userEntity.IdentityAlias}' folder '{node.Path}' from '{folder.FullName}'" +
                                        $" run as '{WindowsIdentity.GetCurrent().Name}'");
                    });
                }
                else if (node.NodeType == NodeType.File)
                {
                    WindowsIdentity.RunImpersonated(_userToken, () =>
                    {
                        var file = SmbFileSystemHelper.FilePathToCIFS(_userMount + node.Path.StringPath);
                        file.Delete();

                        Log.Information($"'{callPath}' '{_userEntity.IdentityAlias}' file '{node.Path}' from '{file.FullName}'" +
                                        $" run as '{WindowsIdentity.GetCurrent().Name}'");
                    });
                }
                else
                {
                    throw new NotImplementedException();
                }

                return(node);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #9
0
        protected override bool Exists(NodePath path, NodeType nodeType)
        {
            try
            {
                bool exists = false;

                if (nodeType == NodeType.Directory)
                {
                    WindowsIdentity.RunImpersonated(_userToken, () =>
                    {
                        var folder = SmbFileSystemHelper.FolderPathToCIFS(_userMount + path.StringPath);

                        if (folder.Exists)
                        {
                            exists = true;
                        }
                    });
                }
                else if (nodeType == NodeType.File)
                {
                    WindowsIdentity.RunImpersonated(_userToken, () =>
                    {
                        var file = SmbFileSystemHelper.FilePathToCIFS(_userMount + path.StringPath);

                        if (file.Exists)
                        {
                            exists = true;
                        }
                    });
                }
                else
                {
                    throw new NotImplementedException();
                }

                return(exists);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #10
0
        protected override NodeBase SetTimeInfo(NodeBase node, NodeTimeInfo newTimeInfo)
        {
            try
            {
                if (node.NodeType == NodeType.Directory)
                {
                    WindowsIdentity.RunImpersonated(_userToken, () =>
                    {
                        var folder = SmbFileSystemHelper.FolderPathToCIFS(_userMount + node.Path.StringPath);

                        folder.CreationTime   = newTimeInfo.CreationTime;
                        folder.LastAccessTime = newTimeInfo.LastAccessTime;
                        folder.LastWriteTime  = newTimeInfo.LastWriteTime;
                    });
                }
                else if (node.NodeType == NodeType.File)
                {
                    WindowsIdentity.RunImpersonated(_userToken, () =>
                    {
                        var file = SmbFileSystemHelper.FilePathToCIFS(_userMount + node.Path.StringPath);

                        file.CreationTime   = newTimeInfo.CreationTime;
                        file.LastAccessTime = newTimeInfo.LastAccessTime;
                        file.LastWriteTime  = newTimeInfo.LastWriteTime;
                    });
                }
                else
                {
                    throw new NotImplementedException();
                }

                return(node);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }