Example #1
0
        public NTStatus CreateFile(out object handle, out FileStatus fileStatus, string path, AccessMask desiredAccess, FileAttributes fileAttributes, ShareAccess shareAccess, CreateDisposition createDisposition, CreateOptions createOptions, SecurityContext securityContext)
        {
            handle     = null;
            fileStatus = FileStatus.FILE_DOES_NOT_EXIST;
            CreateRequest request = new CreateRequest();

            request.Name               = path;
            request.DesiredAccess      = desiredAccess;
            request.FileAttributes     = fileAttributes;
            request.ShareAccess        = shareAccess;
            request.CreateDisposition  = createDisposition;
            request.CreateOptions      = createOptions;
            request.ImpersonationLevel = ImpersonationLevel.Impersonation;
            TrySendCommand(request);

            SMB2Command response = m_client.WaitForCommand(SMB2CommandName.Create);

            if (response != null)
            {
                if (response.Header.Status == NTStatus.STATUS_SUCCESS && response is CreateResponse)
                {
                    CreateResponse createResponse = ((CreateResponse)response);
                    handle     = createResponse.FileId;
                    fileStatus = ToFileStatus(createResponse.CreateAction);
                }
                return(response.Header.Status);
            }

            return(NTStatus.STATUS_INVALID_SMB);
        }
Example #2
0
 private SMB2Command WaitForCommand(SMB2CommandName commandName)
 {
     return(m_client.WaitForCommand(commandName));
 }
Example #3
0
        public async Task <(NTStatus status, object handle, FileStatus fileStatus)> CreateFile(string path, AccessMask desiredAccess, FileAttributes fileAttributes, ShareAccess shareAccess, CreateDisposition createDisposition, CreateOptions createOptions, SecurityContext securityContext, CancellationToken cancellationToken)
        {
            CreateRequest request = new CreateRequest();

            request.Name               = path;
            request.DesiredAccess      = desiredAccess;
            request.FileAttributes     = fileAttributes;
            request.ShareAccess        = shareAccess;
            request.CreateDisposition  = createDisposition;
            request.CreateOptions      = createOptions;
            request.ImpersonationLevel = ImpersonationLevel.Impersonation;
            await TrySendCommandAsync(request, cancellationToken);

            SMB2Command response = m_client.WaitForCommand(SMB2CommandName.Create);

            var fileStatus = FileStatus.FILE_DOES_NOT_EXIST;

            if (response != null)
            {
                object handle = null;

                if (response.Header.Status == NTStatus.STATUS_SUCCESS && response is CreateResponse)
                {
                    CreateResponse createResponse = ((CreateResponse)response);
                    handle     = createResponse.FileId;
                    fileStatus = ToFileStatus(createResponse.CreateAction);
                }
                return(response.Header.Status, handle, fileStatus);
            }

            return(NTStatus.STATUS_INVALID_SMB, null, fileStatus);
        }