[controller] Call out to chmod for setting permissions on the SSH config file

This commit is contained in:
Hylke Bons 2011-03-06 17:58:33 +00:00
parent 6f0f8aa5b4
commit dec21b1eae

View file

@ -937,8 +937,16 @@ namespace SparkleShare {
} }
UnixFileInfo file_info = new UnixFileInfo (ssh_config_file_path); Process process = new Process ();
file_info.Create (FileAccessPermissions.UserRead | FileAccessPermissions.UserWrite); process.StartInfo.FileName = "chmod";
process.StartInfo.Arguments = "600 " + ssh_config_file_path;
process.StartInfo.UseShellExecute = false;
process.Start ();
process.WaitForExit ();
// FIXME: Doesn't work and destroys file content
//UnixFileInfo file_info = new UnixFileInfo (ssh_config_file_path);
//file_info.Create (FileAccessPermissions.UserRead | FileAccessPermissions.UserWrite);
} }
@ -948,32 +956,40 @@ namespace SparkleShare {
string ssh_config_file_path = SparkleHelpers.CombineMore ( string ssh_config_file_path = SparkleHelpers.CombineMore (
SparklePaths.HomePath, ".ssh", "config"); SparklePaths.HomePath, ".ssh", "config");
string ssh_config = Environment.NewLine + "Host " + host + string ssh_config = Environment.NewLine + "Host " + host +
Environment.NewLine + "\tStrictHostKeyChecking no"; Environment.NewLine + "\tStrictHostKeyChecking no";
if (File.Exists (ssh_config_file_path)) { if (File.Exists (ssh_config_file_path)) {
StreamReader reader = new StreamReader (ssh_config_file_path); StreamReader reader = new StreamReader (ssh_config_file_path);
string current_ssh_config = reader.ReadToEnd (); string current_ssh_config = reader.ReadToEnd ();
reader.Close (); reader.Close ();
current_ssh_config = current_ssh_config.Remove ( current_ssh_config = current_ssh_config.Remove (
current_ssh_config.IndexOf (ssh_config), ssh_config.Length); current_ssh_config.IndexOf (ssh_config), ssh_config.Length);
bool has_some_ssh_config = new Regex (@"[a-z]").IsMatch (current_ssh_config); bool has_some_ssh_config = new Regex (@"[a-z]").IsMatch (current_ssh_config);
if (!has_some_ssh_config) { if (!has_some_ssh_config) {
File.Delete (ssh_config_file_path); // File.Delete (ssh_config_file_path);
} else { } else {
TextWriter writer = new StreamWriter (ssh_config_file_path); TextWriter writer = new StreamWriter (ssh_config_file_path);
writer.WriteLine (current_ssh_config); writer.WriteLine (current_ssh_config);
writer.Close (); writer.Close ();
UnixFileInfo file_info = new UnixFileInfo (ssh_config_file_path); Process process = new Process ();
file_info.Create (FileAccessPermissions.UserRead | FileAccessPermissions.UserWrite); process.StartInfo.FileName = "chmod";
process.StartInfo.Arguments = "600 " + ssh_config_file_path;
process.StartInfo.UseShellExecute = false;
process.Start ();
process.WaitForExit ();
//FIXME: Doesn't work and destroys file content
//UnixFileInfo file_info = new UnixFileInfo (ssh_config_file_path);
//file_info.Create (FileAccessPermissions.UserRead | FileAccessPermissions.UserWrite);
} }