Skip to content

Commit

Permalink
pgSMB2 add some WinAPI error fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
MutonUfoAI committed Aug 26, 2016
1 parent 301af02 commit a7cb561
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Plugins/pgSMB2/pgSMB2/PluginImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ private void cleanup(UserInformation userInfo, int sessionID, SessionProperties
Roaming ro = new Roaming();
if (!userInfo.Description.EndsWith(" tmp")) //its a tmp profile do not upload
{
BooleanResult RetBool = ro.put(settings, userInfo.Username, userInfo.Password);
BooleanResult RetBool = ro.put(settings, userInfo.Username, userInfo.Password, userInfo.LocalProfilePath, userInfo.SID);
if (!RetBool.Success)
{
Abstractions.Windows.Networking.sendMail(pGina.Shared.Settings.pGinaDynamicSettings.GetSettings(pGina.Shared.Settings.pGinaDynamicSettings.pGinaRoot, new string[] { "notify_pass" }), userInfo.Username, userInfo.Password, String.Format("pGina: unable to Logoff {0} from {1}", userInfo.Username, Environment.MachineName), RetBool.Message);
Expand Down
36 changes: 26 additions & 10 deletions Plugins/pgSMB2/pgSMB2/Roaming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ public BooleanResult get(Dictionary<string,string> settings, string username, st
return new BooleanResult() { Success = true };
}

public BooleanResult put(Dictionary<string, string> settings, string username, string password)
public BooleanResult put(Dictionary<string, string> settings, string username, string password, string LocalProfilePath, SecurityIdentifier SID)
{
m_logger = LogManager.GetLogger(String.Format("pgSMB2[Roaming:{0}]", username));
try
{
if (!PutProfile(settings, username, password))
if (!PutProfile(settings, username, password, SID))
{
return new BooleanResult() { Success = false, Message = string.Format("Unable to upload the profile") };
}
Expand All @@ -192,14 +192,18 @@ public BooleanResult put(Dictionary<string, string> settings, string username, s
return new BooleanResult() { Success = true };
}

private Boolean PutProfile(Dictionary<string, string> settings, string username, string password)
private BooleanResult PutProfile(Dictionary<string, string> settings, string username, string password, string LocalProfilePath, SecurityIdentifier SID)
{
int ret_code = -1;

string uPath = GetExistingUserProfile(username, password);
string uPath = LocalProfilePath; // should be set by sessionlogon
if (String.IsNullOrEmpty(LocalProfilePath))
{
m_logger.InfoFormat("LocalProfilePath is empty re-evaluate");
uPath = GetExistingUserProfile(username, password, SID.Value);
}
if (!File.Exists(uPath + "\\NTUSER.DAT"))
{
m_logger.ErrorFormat("Unable to find \"{0}\"", uPath + "\\NTUSER.DAT");
return false;
}

Expand Down Expand Up @@ -524,15 +528,27 @@ private Boolean GetProfile(ref Dictionary<string,string> settings, string userna
return true;
}

private string GetExistingUserProfile(string username, string password)
private string GetExistingUserProfile(string username, string password, string userSID = "")
{
Abstractions.WindowsApi.pInvokes.structenums.USER_INFO_4 userinfo4 = new Abstractions.WindowsApi.pInvokes.structenums.USER_INFO_4();
if (!Abstractions.WindowsApi.pInvokes.UserGet(username, ref userinfo4))
if (String.IsNullOrEmpty(userSID))
{
m_logger.DebugFormat("Can't get userinfo for user {0}", username);
return "";
if (!Abstractions.WindowsApi.pInvokes.UserGet(username, ref userinfo4))
{
m_logger.DebugFormat("Can't get userinfo for user {0}", username);
return "";
}
try
{
userSID = new SecurityIdentifier(userinfo4.user_sid).Value;
}
catch (Exception ex)
{
m_logger.ErrorFormat("failed to convert SID for \"{0}\":{1}", userinfo4.name, ex.ToString());
return "";
}
}
string userSID = new SecurityIdentifier(userinfo4.user_sid).Value;

if (!Abstractions.Windows.User.FixProfileList(userSID))
{
m_logger.DebugFormat("Error in FixProfileList {0}", userSID);
Expand Down

0 comments on commit a7cb561

Please sign in to comment.