1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- /* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
- *
- * You can redistribute this program and/or modify it under the terms of
- * the GNU Lesser Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- */
- using System;
- using System.Collections.Generic;
- using SMBLibrary.Authentication;
- using SMBLibrary.SMB2;
- using Utilities;
- namespace SMBLibrary.Server.SMB2
- {
- public class SetInfoHelper
- {
- internal static SMB2Command GetSetInfoResponse(SetInfoRequest request, ISMBShare share, SMB2ConnectionState state)
- {
- SMB2Session session = state.GetSession(request.Header.SessionID);
- if (request.InfoType == InfoType.File)
- {
- OpenFileObject openFile = session.GetOpenFileObject(request.FileId.Persistent);
- if (openFile == null)
- {
- return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
- }
- if (share is FileSystemShare)
- {
- IFileSystem fileSystem = ((FileSystemShare)share).FileSystem;
- if (!((FileSystemShare)share).HasWriteAccess(session.UserName))
- {
- return new ErrorResponse(request.CommandName, NTStatus.STATUS_ACCESS_DENIED);
- }
- FileInformation information;
- try
- {
- information = FileInformation.GetFileInformation(request.Buffer, 0, request.FileInformationClass);
- }
- catch (UnsupportedInformationLevelException)
- {
- return new ErrorResponse(request.CommandName, NTStatus.STATUS_INVALID_INFO_CLASS);
- }
- catch (NotImplementedException)
- {
- return new ErrorResponse(request.CommandName, NTStatus.STATUS_NOT_SUPPORTED);
- }
- catch (Exception)
- {
- return new ErrorResponse(request.CommandName, NTStatus.STATUS_INVALID_PARAMETER);
- }
- NTStatus status = NTFileSystemHelper.SetFileInformation(fileSystem, openFile, information, state);
- if (status != NTStatus.STATUS_SUCCESS)
- {
- state.LogToServer(Severity.Verbose, "SetFileInformation on '{0}' failed. Information class: {1}, NTStatus: {2}", openFile.Path, information.FileInformationClass, status);
- return new ErrorResponse(request.CommandName, status);
- }
- return new SetInfoResponse();
- }
- }
- return new ErrorResponse(request.CommandName, NTStatus.STATUS_NOT_SUPPORTED);
- }
- }
- }
|