2006-01-19 00:34:21 +01:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
2006-02-01 18:48:29 +01:00
|
|
|
* Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-01-31 23:01:47 +01:00
|
|
|
* Library Lesser General Public License for more details.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-01-31 23:01:47 +01:00
|
|
|
* License along with this library; if not, Novell, Inc.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* To contact Novell about this file by physical or electronic mail,
|
|
|
|
* you may find current contact information at www.novell.com.
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
|
|
|
|
2005-10-11 21:51:00 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.IO;
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
|
|
|
using sscs.cache;
|
|
|
|
using sscs.common;
|
|
|
|
using sscs.constants;
|
|
|
|
|
|
|
|
namespace sscs.common
|
|
|
|
{
|
|
|
|
internal class WinUser : User
|
|
|
|
{
|
|
|
|
private string m_sUserHome = "";
|
|
|
|
|
|
|
|
internal WinUser()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
internal WinUser(UserIdentifier winUserId)
|
|
|
|
{
|
|
|
|
userId = winUserId;
|
|
|
|
secretStore = new SecretStore(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
override internal void SetUserName(string username)
|
|
|
|
{
|
|
|
|
userName = username;
|
|
|
|
}
|
|
|
|
|
|
|
|
override internal string GetUserName()
|
|
|
|
{
|
|
|
|
return userName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A method to find the user's home dir on windows needs to be added.
|
|
|
|
*/
|
|
|
|
override internal string GetUserHomeDir()
|
|
|
|
{
|
2005-10-17 21:43:06 +02:00
|
|
|
CSSSLogger.DbgLog("WinUser:GetUserHomeDir - Entered");
|
|
|
|
if (m_sUserHome == null || m_sUserHome.Length < 1)
|
2005-10-11 21:51:00 +02:00
|
|
|
{
|
2005-10-17 21:43:06 +02:00
|
|
|
CSSSLogger.DbgLog("WinUser:GetUserHomeDir is empty");
|
2005-10-11 21:51:00 +02:00
|
|
|
//Console.WriteLine("read registry");
|
|
|
|
// get the users home drive and homepath from the registry
|
|
|
|
//
|
|
|
|
string sSIDString = ((WinUserIdentifier)userId).GetSID();
|
|
|
|
|
|
|
|
// look up Profile path
|
|
|
|
// [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-21-1757981266-436374069-725345543-1006]
|
2005-10-17 21:43:06 +02:00
|
|
|
CSSSLogger.DbgLog("Reading Reg: SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\" + sSIDString);
|
2005-10-11 21:51:00 +02:00
|
|
|
string sProfile = ReadRegKey(Registry.LocalMachine, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\" + sSIDString, "ProfileImagePath");
|
2005-10-17 21:43:06 +02:00
|
|
|
|
|
|
|
if (sProfile == null)
|
|
|
|
CSSSLogger.DbgLog("WinUser:GetUserHomeDir get Profile return null");
|
|
|
|
else
|
|
|
|
m_sUserHome = sProfile;
|
2005-10-11 21:51:00 +02:00
|
|
|
|
|
|
|
//string sHomeDrive = ReadRegKey(Registry.Users, sSIDString+"\\Volatile Environment", "HOMEDRIVE");
|
|
|
|
//string sHomeDir = ReadRegKey(Registry.Users, sSIDString+"\\Volatile Environment", "HOMEPATH");
|
|
|
|
//m_sUserHome = sHomeDrive+sHomeDir;
|
|
|
|
//Console.WriteLine("Homedir: "+ m_sUserHome);
|
|
|
|
}
|
2005-10-17 21:43:06 +02:00
|
|
|
|
|
|
|
CSSSLogger.DbgLog("WinUser:GetUserHomeDir - Exited: "+m_sUserHome);
|
2005-10-11 21:51:00 +02:00
|
|
|
|
|
|
|
return m_sUserHome;
|
|
|
|
}
|
|
|
|
|
|
|
|
private string ReadRegKey(RegistryKey rk, string sSubKey, string KeyName)
|
|
|
|
{
|
|
|
|
// Opening the registry key
|
|
|
|
// RegistryKey rk = Registry.Users;
|
|
|
|
// Open a subKey as read-only
|
|
|
|
RegistryKey sk1 = rk.OpenSubKey(sSubKey);
|
|
|
|
// If the RegistrySubKey doesn't exist -> (null)
|
|
|
|
if ( sk1 == null )
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// If the RegistryKey exists I get its value
|
|
|
|
// or null is returned.
|
|
|
|
return (string)sk1.GetValue(KeyName.ToUpper());
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
//ShowErrorMessage(e, "Reading registry " + KeyName.ToUpper());
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|