Exemplo n.º 1
0
 private LoginResponsePDU GetLoginResponsePDU(LoginRequestPDU request, ConnectionParameters connection)
 {
     // RFC 3720: The numbering fields (StatSN, ExpCmdSN, MaxCmdSN) are only valid if status-Class is 0.
     // RFC 3720: Command numbering starts with the first login request on the first connection of a session
     if (request.Continue)
     {
         connection.AddTextToSequence(request.InitiatorTaskTag, request.LoginParametersText);
         return(GetPartialLoginResponsePDU(request, connection));
     }
     else
     {
         string text = connection.AddTextToSequence(request.InitiatorTaskTag, request.LoginParametersText);
         connection.RemoveTextSequence(request.InitiatorTaskTag);
         KeyValuePairList <string, string> loginParameters = KeyValuePairUtils.GetKeyValuePairList(text);
         if (connection.Session == null)
         {
             LoginResponseStatusName status = SetUpSession(request, loginParameters, connection);
             if (status != LoginResponseStatusName.Success)
             {
                 LoginResponsePDU response = GetLoginResponseTemplate(request);
                 response.Transit = request.Transit;
                 response.Status  = status;
                 return(response);
             }
         }
         return(GetFinalLoginResponsePDU(request, loginParameters, connection));
     }
 }
Exemplo n.º 2
0
        private TextResponsePDU GetTextResponsePDU(TextRequestPDU request, ConnectionParameters connection)
        {
            TextResponsePDU response = new TextResponsePDU();

            response.Final            = request.Final;
            response.InitiatorTaskTag = request.InitiatorTaskTag;
            if (request.Continue)
            {
                connection.AddTextToSequence(request.InitiatorTaskTag, request.Text);
            }
            else
            {
                string text = connection.AddTextToSequence(request.InitiatorTaskTag, request.Text);
                connection.RemoveTextSequence(request.InitiatorTaskTag);
                KeyValuePairList <string, string> requestParameters = KeyValuePairUtils.GetKeyValuePairList(text);
                // text keys are case sensitive
                if (requestParameters.ContainsKey("SendTargets"))
                {
                    KeyValuePairList <string, string> responseParameters = new KeyValuePairList <string, string>();
                    lock (m_targets.Lock)
                    {
                        foreach (ISCSITarget target in m_targets.GetList())
                        {
                            responseParameters.Add("TargetName", target.TargetName);
                        }
                    }
                    response.TextParameters = responseParameters;
                }
                else if (connection.Session.IsDiscovery || !IsVendorSpecificRequest(requestParameters))
                {
                    KeyValuePairList <string, string> responseParameters = new KeyValuePairList <string, string>();
                    foreach (KeyValuePair <string, string> entry in requestParameters)
                    {
                        responseParameters.Add(entry.Key, "Reject");
                    }
                    response.TextParameters = responseParameters;
                }
                else
                {
                    // RFC 3720: Vendor specific keys MUST ONLY be used in normal sessions
                    // Vendor specific text request, let the target handle it:
                    response.TextParameters = connection.Session.Target.GetTextResponse(requestParameters);
                }
            }
            return(response);
        }