Security Audit - Remove assumption of username.

This commit is contained in:
Jim Norman
2006-12-18 11:13:23 +00:00
parent 174b0eb88c
commit 8b6a60e9ab
4 changed files with 59 additions and 36 deletions

View File

@@ -36,10 +36,10 @@ public class ICASAPol
static string GetPolicyFilePath()
{
return GetPolicyFilePath(null);
return GetPolicyFilePath(null, null);
}
static string GetPolicyFilePath(string sUserHomeDir)
static string GetPolicyFilePath(string sUserHomeDir, string sUserName)
{
try
@@ -64,14 +64,17 @@ public class ICASAPol
homeDir = System.Environment.GetEnvironmentVariable("HOME");
}
// get users name
string sUsername = homeDir.Substring(homeDir.LastIndexOf("/") + 1);
if (sUsername != null)
// get users name
if (sUserName == null)
{
sUserName = System.Environment.GetEnvironmentVariable("USER");
}
if (sUserName != null)
{
// check for existing files
string sOldLocation = homeDir + XmlConsts.policyFileName;
string sNewLocation = "/home/.casa/" + sUsername + XmlConsts.policyFileName;
string sOldLocation = homeDir + XmlConsts.policyFileName;
string sNewLocation = "/home/.casa/" + sUserName + XmlConsts.policyFileName;
// move file if needed
if ((!File.Exists(sNewLocation)) && (File.Exists(sOldLocation)))
@@ -421,18 +424,18 @@ public class ICASAPol
static public CASAPol GetPolicy(CASAPolType policyType)
{
return GetPolicy(policyType, null);
return GetPolicy(policyType, null, null);
}
static public CASAPol GetPolicy(CASAPolType policyType, string sDir)
static public CASAPol GetPolicy(CASAPolType policyType, string sDir, string sUserName)
{
CASAPol pol = null;
try
{
XmlDocument doc = new XmlDocument();
if(!File.Exists(GetPolicyFilePath(sDir)))
if(!File.Exists(GetPolicyFilePath(sDir, sUserName)))
return null;
doc.Load(GetPolicyFilePath(sDir));
doc.Load(GetPolicyFilePath(sDir, sUserName));
switch(policyType)
{
case CASAPolType.AGGREGATION_POL: