Merge pull request #2662 from xenserver/feature/REQ-821

CP-33433: Limit XE client to PUT the files in the initial XE commands.
This commit is contained in:
Konstantina Chremmou 2020-04-28 13:56:05 +01:00 committed by GitHub
commit a89615b4d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -37,6 +37,7 @@ using System.Net.Security;
using System.IO;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Linq;
@ -77,6 +78,7 @@ namespace CommandLib
public int major = 0;
public int minor = 1;
public bool dropOut;
public List<string> EnteredParamValues;
public thinCLIProtocol(delegateGlobalError dGlobalError,
delegateGlobalUsage dGlobalUsage,
@ -98,6 +100,7 @@ namespace CommandLib
this.dProgress = dProgress;
this.conf = conf;
dropOut = false;
EnteredParamValues = new List<string>();
}
}
@ -495,6 +498,15 @@ namespace CommandLib
}
}
public static void CheckUploadFiles(String filename, thinCLIProtocol tCLIprotocol)
{
if (!(tCLIprotocol.EnteredParamValues.Any(filename.StartsWith)))
{
throw new Exception(string.Format("The file '{0}' to upload is not the same as the one entered at the command line.", filename));
}
}
public static void interpreter(Stream stream, thinCLIProtocol tCLIprotocol)
{
string filename = "";
@ -560,11 +572,13 @@ namespace CommandLib
break;
case Messages.tag.Load:
filename = Types.unmarshal_string(stream);
CheckUploadFiles(filename, tCLIprotocol);
tCLIprotocol.dGlobalDebug("Read: Load " + filename, tCLIprotocol);
Messages.load(stream, filename, tCLIprotocol);
break;
case Messages.tag.HttpPut:
filename = Types.unmarshal_string(stream);
CheckUploadFiles(filename, tCLIprotocol);
path = Types.unmarshal_string(stream);
Uri uri = ParseUri(path, tCLIprotocol);
tCLIprotocol.dGlobalDebug("Read: HttpPut " + filename + " -> " + uri, tCLIprotocol);

View File

@ -86,6 +86,10 @@ namespace ThinCLI
}
else
{
if (s.Contains("="))
{
tCliProtocol.EnteredParamValues.Add(s.Split(eqsep)[1]);
}
body += s + "\n";
}
}