Exemplo n.º 1
0
        private Boolean FilterCallback(IntPtr sendDataPtr, IntPtr replyDataPtr)
        {
            bool retVal = true;

            try
            {
                FilterAPI.MessageSendData messageSend = new FilterAPI.MessageSendData();
                messageSend = (FilterAPI.MessageSendData)Marshal.PtrToStructure(sendDataPtr, typeof(FilterAPI.MessageSendData));

                if (FilterAPI.MESSAGE_SEND_VERIFICATION_NUMBER != messageSend.VerificationNumber)
                {
                    EventManager.WriteMessage(139, "FilterCallback", EventLevel.Error, "Received message corrupted.Please check if the MessageSendData structure is correct.");
                    return(false);
                }

                if (messageSend.MessageType == (uint)FilterAPI.FilterCommand.FILTER_REQUEST_ENCRYPTION_IV_AND_KEY)
                {
                    if ((replyDataPtr.ToInt64() != 0))
                    {
                        //this is the customized tag data which was attahced to the encrypted file when it was created.
                        uint   tagDataLength = messageSend.DataBufferLength;
                        byte[] tagData       = messageSend.DataBuffer;

                        FilterAPI.MessageReplyData messageReply = (FilterAPI.MessageReplyData)Marshal.PtrToStructure(replyDataPtr, typeof(FilterAPI.MessageReplyData));
                        messageReply.MessageId   = messageSend.MessageId;
                        messageReply.MessageType = messageSend.MessageType;

                        //get permission for secure shared file from server, here just demo the server in local,
                        //in reality, your server could be in remote computer.
                        retVal = DRServer.GetFileAccessPermission(ref messageSend, ref messageReply);

                        if (retVal)
                        {
                            messageReply.ReturnStatus = (uint)FilterAPI.NTSTATUS.STATUS_SUCCESS;
                        }
                        else
                        {
                            //if you don't want to authorize the process to read the encrytped file,you can set the value as below:
                            messageReply.ReturnStatus = (uint)FilterAPI.NTSTATUS.STATUS_ACCESS_DENIED;
                            messageReply.FilterStatus = (uint)FilterAPI.FilterStatus.FILTER_COMPLETE_PRE_OPERATION;
                        }

                        Marshal.StructureToPtr(messageReply, replyDataPtr, true);

                        if (!retVal)
                        {
                            messageSend.Status = (uint)FilterAPI.NTSTATUS.STATUS_ACCESS_DENIED;
                        }
                    }
                }

                filterMessage.AddMessage(messageSend);
            }
            catch (Exception ex)
            {
                EventManager.WriteMessage(134, "FilterCallback", EventLevel.Error, "filter callback exception." + ex.Message);
                return(false);
            }

            return(retVal);
        }