Skip to content

Commit baca9d8

Browse files
committed
On Linux, ask for HTTPS password by invoking the app with a special argument
1 parent 452ebb3 commit baca9d8

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

Diff for: ClassCommandLine.cs

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Collections.Specialized;
44
using System.IO;
5+
using System.Windows.Forms;
56

67
namespace GitForce
78
{
@@ -97,6 +98,19 @@ public static bool Execute(Arguments commandLine)
9798
Console.WriteLine("Logging: " + App.AppLog);
9899
}
99100

101+
// --passwd This is not a user option. It is used when the app is called to provide password echoed on a command line.
102+
if (commandLine["passwd"] == "true")
103+
{
104+
ReturnCode = -1;
105+
FormHttpsAuth httpsAuth = new FormHttpsAuth(false);
106+
if (httpsAuth.ShowDialog() == DialogResult.OK)
107+
{
108+
Console.WriteLine(httpsAuth.Password);
109+
ReturnCode = 0;
110+
}
111+
runGitForce = false;
112+
}
113+
100114
// WAR: On Windows, detach the console when we are done. Mono does not need that to use Console class.
101115
if (!ClassUtils.IsMono())
102116
NativeMethods.FreeConsole();

Diff for: ClassHttpsPasswd.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ public ClassHttpsPasswd()
1919
string pathPasswordBatchHelper;
2020
if (ClassUtils.IsMono())
2121
{
22-
// Mono: Use the Shell script
22+
// Mono: Use the Shell script which tests if $PASSWORD is defined and echoes it,
23+
// and if not defined, it calls GitForce application with a special argument that opens
24+
// only password dialog
2325
pathPasswordBatchHelper = Path.Combine(App.AppHome, "passwd.sh");
24-
File.WriteAllText(pathPasswordBatchHelper, "echo $PASSWORD" + Environment.NewLine);
25-
26+
File.WriteAllText(pathPasswordBatchHelper, "#!/bin/sh" + Environment.NewLine +
27+
"if [ \"$PASSWORD\" = \"\" ]; then" + Environment.NewLine +
28+
App.AppPath + " --passwd" + Environment.NewLine +
29+
"else" + Environment.NewLine +
30+
"echo $PASSWORD" + Environment.NewLine +
31+
"fi" );
2632
// Set the execute bit
2733
if (Exec.Run("chmod", "+x " + pathPasswordBatchHelper).Success() == false)
2834
App.PrintLogMessage("ClassHttpsPasswd: Unable to chmod +x on " + pathPasswordBatchHelper, MessageType.Error);

Diff for: FormHttps.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private void BtEditClick(object sender, EventArgs e)
175175
/// </summary>
176176
private void AddEdit(string machine)
177177
{
178-
FormHttpsAuth formHttpsAuth = new FormHttpsAuth();
178+
FormHttpsAuth formHttpsAuth = new FormHttpsAuth(true);
179179
if (netrc.ContainsKey(machine))
180180
{
181181
formHttpsAuth.Username = netrc[machine].Item1;

Diff for: FormHttpsAuth.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ public string Password
2222
/// <summary>
2323
/// Form constructor
2424
/// </summary>
25-
public FormHttpsAuth()
25+
public FormHttpsAuth(bool enableUsername)
2626
{
2727
InitializeComponent();
2828
ClassWinGeometry.Restore(this);
29+
30+
textUsername.Enabled = enableUsername;
2931
}
3032

3133
/// <summary>
@@ -57,7 +59,7 @@ private void ValidateOk(object sender, System.EventArgs e)
5759
// We simply want to avoid some 'dangerous' characters, including spaces
5860
string password = textPassword.Text.Trim();
5961

60-
btOK.Enabled = r.IsMatch(username) && (password.Length > 0) && password.IndexOfAny(@" \/".ToCharArray()) == -1;
62+
btOK.Enabled = (!textUsername.Enabled || r.IsMatch(username)) && (password.Length > 0) && password.IndexOfAny(@" \/".ToCharArray()) == -1;
6163
}
6264
}
6365
}

0 commit comments

Comments
 (0)