major source structure and module name changes -continue
This commit is contained in:
122
CASA/micasad/common/WinUser.cs
Normal file
122
CASA/micasad/common/WinUser.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
|
||||
*
|
||||
* 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
|
||||
* Library Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, Novell, Inc.
|
||||
*
|
||||
* To contact Novell about this file by physical or electronic mail,
|
||||
* you may find current contact information at www.novell.com.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
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()
|
||||
{
|
||||
CSSSLogger.DbgLog("WinUser:GetUserHomeDir - Entered");
|
||||
if (m_sUserHome == null || m_sUserHome.Length < 1)
|
||||
{
|
||||
CSSSLogger.DbgLog("WinUser:GetUserHomeDir is empty");
|
||||
//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]
|
||||
CSSSLogger.DbgLog("Reading Reg: SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\" + sSIDString);
|
||||
string sProfile = ReadRegKey(Registry.LocalMachine, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\" + sSIDString, "ProfileImagePath");
|
||||
|
||||
if (sProfile == null)
|
||||
CSSSLogger.DbgLog("WinUser:GetUserHomeDir get Profile return null");
|
||||
else
|
||||
m_sUserHome = sProfile;
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
CSSSLogger.DbgLog("WinUser:GetUserHomeDir - Exited: "+m_sUserHome);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user