From 818c0796ddc6797a9542077e98a2aaab43adea79 Mon Sep 17 00:00:00 2001 From: Jim Norman Date: Fri, 22 Sep 2006 17:35:40 +0000 Subject: [PATCH] Move .CASAPolicy.xml file to /home/.casa/username --- CASA/CASA.changes | 5 ++ CASA/gui/CasaMain.cs | 7 +- CASA/micasad/cache/SecretStore.cs | 47 +++++++++++- .../lib/communication/MiCasaRequestReply.cs | 1 + CASA/micasad/verbs/ObjectSerialization.cs | 10 +++ CASA/policy/Makefile.am | 4 +- CASA/policy/PolicyImpl.cs | 75 ++++++++++++++++--- 7 files changed, 132 insertions(+), 17 deletions(-) diff --git a/CASA/CASA.changes b/CASA/CASA.changes index a8f69ef1..afa2de07 100644 --- a/CASA/CASA.changes +++ b/CASA/CASA.changes @@ -1,3 +1,8 @@ +-------------------------------------------------------------------- +Fri Sep 22 11:32:00 MST 2006 - jnorman@novell.com +- SLED is planning to encypt the user home directory + Move the .CASAPolicy files to /home/.casa/username + -------------------------------------------------------------------- Thu Jul 06 14:32:53 MST 2006 - jnorman@novell.com - Bug 173648. Exec CASAManager.exe in the forground. diff --git a/CASA/gui/CasaMain.cs b/CASA/gui/CasaMain.cs index 8b4c70c2..e73cfcbd 100644 --- a/CASA/gui/CasaMain.cs +++ b/CASA/gui/CasaMain.cs @@ -241,7 +241,12 @@ namespace Novell.CASA.GUI Logger.DbgLog("GUI:CasaMain.CasaMain() - BEGIN"); if( false == Common.CheckForSingleInstance() ) - { + { + + // setup the users policy directory + MiCasaRequestReply.Send(MiCasaRequestReply.VERB_CREATE_POLICY_DIR); + + MasterPasswordAuthentication(); if (Common.IsTrayAvailable()) // && Common.IsArgSet(args, Common.ARG_SHOW_TRAY_ICON)) { diff --git a/CASA/micasad/cache/SecretStore.cs b/CASA/micasad/cache/SecretStore.cs index bafbb146..464d429c 100644 --- a/CASA/micasad/cache/SecretStore.cs +++ b/CASA/micasad/cache/SecretStore.cs @@ -57,6 +57,7 @@ namespace sscs.cache private LocalStorage lss = null; bool bIsStorePersistent = false; string m_persistenceDirectory = null; + private static string POLICY_DIRECTORY = "/home/.casa"; private MPFileWatcher mpWatcher = null; @@ -89,8 +90,9 @@ namespace sscs.cache ssMutex = new Mutex(); - - + // create the policy directory for this user + CreatePolicyDirectory(); + // start a MPFileWatcher if necessary if (mpWatcher == null) { @@ -907,6 +909,47 @@ namespace sscs.cache } } + internal void CreatePolicyDirectory() + { +#if LINUX + // set up mask + Mono.Unix.Native.FilePermissions permissions = Mono.Unix.Native.Syscall.umask( + Mono.Unix.Native.FilePermissions.S_IWGRP | + Mono.Unix.Native.FilePermissions.S_IWOTH); + + // create the directory if necessary + if (!Directory.Exists(POLICY_DIRECTORY)) + { + Directory.CreateDirectory(POLICY_DIRECTORY); + } + + // create the directory for this user + Mono.Unix.UnixUserInfo uui = new Mono.Unix.UnixUserInfo(user.UserIdentifier.GetUID()); + + string sUsername = uui.UserName; + if (sUsername != null) + { + if (!Directory.Exists(POLICY_DIRECTORY+"/"+sUsername)) + { + Directory.CreateDirectory(POLICY_DIRECTORY+"/"+sUsername); + + // make this user the owner + + if (uui != null) + { + Mono.Unix.Native.Syscall.chown(POLICY_DIRECTORY+"/"+sUsername, (uint)uui.UserId, (uint)uui.GroupId); + } + } + } + else + { + Console.WriteLine("no username"); + } + + // restore umask + Mono.Unix.Native.Syscall.umask(permissions); +#endif + } } } diff --git a/CASA/micasad/lib/communication/MiCasaRequestReply.cs b/CASA/micasad/lib/communication/MiCasaRequestReply.cs index 8659b241..2e292b14 100644 --- a/CASA/micasad/lib/communication/MiCasaRequestReply.cs +++ b/CASA/micasad/lib/communication/MiCasaRequestReply.cs @@ -59,6 +59,7 @@ namespace Novell.CASA.MiCasa.Communication public const int VERB_EXPORT_SECRETS = 21; public const int VERB_ADD_XML_SECRETS = 22; public const int VERB_CHANGE_PERSIST_DIR = 23; + public const int VERB_CREATE_POLICY_DIR = 24; public const int VERB_DUMP_LINKED_KEYS = 96; public const int VERB_CREATE_TEST_SECRETS = 97; diff --git a/CASA/micasad/verbs/ObjectSerialization.cs b/CASA/micasad/verbs/ObjectSerialization.cs index 0258435d..86ba8f63 100644 --- a/CASA/micasad/verbs/ObjectSerialization.cs +++ b/CASA/micasad/verbs/ObjectSerialization.cs @@ -231,6 +231,10 @@ namespace sscs.verbs { return DoChangePersistentDir(ssStore, wo); } + case MiCasaRequestReply.VERB_CREATE_POLICY_DIR: + { + return DoCreatePolicyDir(ssStore, wo); + } default: { @@ -252,6 +256,12 @@ namespace sscs.verbs } + private WrappedObject DoCreatePolicyDir(SecretStore ssStore, WrappedObject wo) + { + ssStore.CreatePolicyDirectory(); + return wo; + } + private WrappedObject DoChangePersistentDir(SecretStore ssStore, WrappedObject wo) { CSSSLogger.ExecutionTrace(this); diff --git a/CASA/policy/Makefile.am b/CASA/policy/Makefile.am index 346b0fdb..d4325393 100644 --- a/CASA/policy/Makefile.am +++ b/CASA/policy/Makefile.am @@ -57,7 +57,7 @@ CSFILES = $(srcdir)/AssemblyInfo.cs \ CSFILES_CSC := $(subst /,$(SEP),$(CSFILES)) CS_FLAGS = $(CSC_LIBFLAG) CS_RESOURCES = -CS_LIBS = +CS_LIBS = Mono.Posix.dll CS_LIBPATH = OBJDIR = ./$(TARGET_CFG)/$(LIB) @@ -76,7 +76,7 @@ vpath %.cpp $(PLATFORMDEPENDENTSOURCEDIR) $(PLATFORMINDEPENDENTSOURCEDIR) vpath %.cs $(PLATFORMDEPENDENTSOURCEDIR) $(PLATFORMINDEPENDENTSOURCEDIR) $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT): $(OBJDIR) $(CSFILES) - $(CSC) $(CS_FLAGS) $(CS_EXTRA_FLAGS) -out:$@ $(CSFILES_CSC) + $(CSC) $(CS_FLAGS) $(CS_EXTRA_FLAGS) $(CS_LIBS:%=/r:%) -out:$@ $(CSFILES_CSC) cp -f $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT) $(CASALIBDIR)/$(TARGET_CFG)/$(MODULE_NAME).$(MODULE_EXT) $(OBJDIR): diff --git a/CASA/policy/PolicyImpl.cs b/CASA/policy/PolicyImpl.cs index 6308e6b6..23e17a55 100644 --- a/CASA/policy/PolicyImpl.cs +++ b/CASA/policy/PolicyImpl.cs @@ -32,34 +32,85 @@ using System.Text; namespace Novell.CASA.CASAPolicy { public class ICASAPol -{ +{ + static string GetPolicyFilePath() { return GetPolicyFilePath(null); } - static string GetPolicyFilePath(string sUserDir) + static string GetPolicyFilePath(string sUserHomeDir) { - if (sUserDir != null) - { - return sUserDir + XmlConsts.policyFileName; - } try { /* There needs to be a better way to get the HOME dir, - * if this is used by miCASAd(as it runs as root). + * if this is used by miCASAd(as it runs as root). + * UPDATE: micasad passes in the Home Directory */ int platform = (int)Environment.OSVersion.Platform; string homeDir; if ( (platform == 128) || ( platform == 4) ) - { - homeDir = System.Environment.GetEnvironmentVariable("HOME"); - } - else - { + { + // if sUserHomeDir is passed + if (sUserHomeDir != null) + { + homeDir = sUserHomeDir; + } + else + { + homeDir = System.Environment.GetEnvironmentVariable("HOME"); + } + + // get users name + string sUsername = homeDir.Substring(homeDir.LastIndexOf("/") + 1); + + if (sUsername != null) + { + // check for existing files + string sOldLocation = homeDir + XmlConsts.policyFileName; + string sNewLocation = "/home/.casa/" + sUsername + XmlConsts.policyFileName; + + // move file if needed + if ((!File.Exists(sNewLocation)) && (File.Exists(sOldLocation))) + { + + try + { + File.Copy(sOldLocation, sNewLocation); + + +#if LINUX + // make the user the owner of the file + Mono.Unix.UnixUserInfo uui = new Mono.Unix.UnixUserInfo(sUsername); + if (uui != null) + { + Mono.Unix.Native.Syscall.chown(sNewLocation, (uint)uui.UserId, (uint)uui.GroupId); + } +#endif + File.Delete(sOldLocation); + } + catch (Exception) + { + + } + + } + + return (sNewLocation); + + } + + } + else // is windows + { + if (sUserHomeDir != null) + { + return sUserHomeDir + XmlConsts.policyFileName; + } + homeDir = (System.Environment.GetEnvironmentVariable("USERPROFILE")); }