PROPID_M_SENDERID

 

Applies To: Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server Technical Preview, Windows Vista

The PROPID_M_SENDERID property identifies who sent the message.

Property ID

PROPID_M_SENDERID

Type Indicator

VT_VECTOR | VT_UI1

MQPROPVARIANT Field

caub

Property Value

An array of bytes generated by Message Queuing.

Remarks

PROPID_M_SENDERID is used primarily by the destination queue manager when authenticating a message. The destination queue manager uses the sender identifier in this property to verify who sent the message and to verify that the access rights for placing messages in the destination queue are allowed for the sender. For information on how Message Queuing authenticates messages, see Message Authentication.

By default, Message Queuing sets this property when the message is sent. However, Message Queuing will not attach the sender identifier to the message if the sending application has set PROPID_M_SENDERID_TYPE to MQMSG_SENDERID_TYPE_NONE. This is only done if the sending application does not want Message Queuing to validate who sent the message.

The sending application can specify the sender identifier of a message by setting the PROPID_M_SENDERID and PROPID_M_CONNECTOR_TYPE properties (in this case Message Queuing does not attempt to set the sender identifier). An error is returned if PROPID_M_SENDERID is set without the connector property

The receiving application may use PROPID_M_SENDERID to retrieve the SID of the user who sent the message. However, in the case of authenticated messages the information in PROPID_M_SENDERID D is only trustworthy if the message was authenticated.

To retrieve the sender identifier from a message, specify PROPID_M_SENDERID and PROPID_M_SENDERID_LEN in the MQMSGPROPS structure (the length property is used to verify that the sender identifier was sent with the message). Then call MQReceiveMessage or MQReceiveMessageByLookupId and examine the returned values.

If MQReceiveMessage or MQReceiveMessageByLookupId fails, returning an MQ_ERROR_SENDERID_BUFFER_TOO_SMALL error, use the returned value of PROPID_M_SENDERID_LEN to reallocate the sender identifier buffer and call the applicable function again.

Before using the sender identifier, always check the length property PROPID_M_SENDERID_LEN to see if the sender identifier was sent with the message. If the returned value of PROPID_M_SENDERID_LEN is 0, no identifier was sent with the message. If the returned value is non-0, PROPID_M_SENDERID contains the identifier of the sender.

Equivalent COM Property

With COM components, the equivalent property is MSMQMessage.SenderId.

Example Code

The following code fragments show how PROPID_M_SENDERID is specified in arrays that can be used to initialize an MQMSGPROPS structure when setting and retrieving the sender identifier:

To Set the Sender Identifier

PSID pWorldSid = NULL;  
SID_IDENTIFIER_AUTHORITY WorldAuth = SECURITY_WORLD_SID_AUTHORITY;  
BOOL fRet = AllocateAndInitializeSid(&WorldAuth,  
                                     1,  
                                     SECURITY_WORLD_RID,  
                                     0,  
                                     0,  
                                     0,  
                                     0,  
                                     0,  
                                     0,  
                                     0,  
                                     &pWorldSid);  
ASSERT(fRet);  
  
aMsgPropId[i] = PROPID_M_SENDERID;          // Property ID  
aMsgPropVar[i].vt = VT_VECTOR|VT_UI1;       // Type indicator  
aMsgPropVar[i].caub.cElems = GetLengthSid(pWorldSid);  
aMsgPropVar[i].caub.pElems = (unsigned char *)pWorldSid;  
i++;  
aMsgPropId[i] = PROPID_M_CONNECTOR_TYPE;    // Property ID  
aMsgPropVar[i].vt = VT_CLSID;               // Type indicator  
aMsgPropVar[i].puuid = &guidConnectorType;  
i++;  

To Retrieve the Sender Identifier

ULONG ulSenderIdBufferSize = 256;  
UCHAR * pucSenderIdBuffer = NULL;  
pucSenderIdBuffer = (UCHAR *)malloc(ulSenderIdBufferSize);  
if (pucSenderIdBuffer == NULL)  
{  
  return MQ_ERROR_INSUFFICIENT_RESOURCES;  
}  
memset(pucSenderIdBuffer, 0, ulSenderIdBufferSize);  
aMsgPropId[i] = PROPID_M_SENDERID_LEN;                     // Property ID  
aMsgPropVar[i].vt = VT_NULL;                               // Type indicator  
i++;  
  
aMsgPropId[i] = PROPID_M_SENDERID;                         // Property ID  
aMsgPropVar[i].vt = VT_VECTOR | VT_UI1;                    // Type indicator  
aMsgPropVar[i].caub.pElems = pucSenderIdBuffer;  
aMsgPropVar[i].caub.cElems = ulSenderIdBufferSize;  
i++;  
  
// Reallocate memory for the sender identifier buffer if necessary.  
ulSenderIdBufferSize = aMsgPropVar[0].ulVal*sizeof(UCHAR);  
pucSenderIdBuffer = (UCHAR*)realloc(pucSenderIdBuffer, ulSenderIdBufferSize);  
if (pucSenderIdBuffer == NULL)  
{  
  return MQ_ERROR_INSUFFICIENT_RESOURCES;  
}  
memset(pucSenderIdBuffer, 0, ulSenderIdBufferSize);  
aMsgPropVar[1].caub.pElems = (UCHAR*)pucSenderIdBuffer;  // Pointer to the new buffer  
aMsgPropVar[1].caub.cElems = ulSenderIdBufferSize;       // New buffer size  

See Also

Message Properties
MQMSGPROPS
MQReceiveMessage
MQReceiveMessageByLookupId
MQSendMessage
PROPID_M_SENDERID_LEN
PROPID_M_SENDERID_TYPE