]> granicus.if.org Git - icinga2/commitdiff
Windows wizard: Sanitize user inputs from text forms
authorMichael Friedrich <michael.friedrich@icinga.com>
Fri, 3 Nov 2017 12:51:45 +0000 (13:51 +0100)
committerMichael Friedrich <michael.friedrich@icinga.com>
Fri, 3 Nov 2017 13:10:56 +0000 (14:10 +0100)
This avoids white space problems with tickets and host names.

refs #5681
refs #5705

agent/windows-setup-agent/SetupWizard.cs

index b14acf2ac2f3e9e52a514a62986899c1528e3bb6..b95ba98aeec4c7d9b390000fb6b6ba00951891ba 100644 (file)
@@ -194,18 +194,21 @@ namespace Icinga
                                string master_host, master_port;
                                GetMasterHostPort(out master_host, out master_port);
 
-                               args += " --master_host " + master_host + "," + master_port;
+                               args += " --master_host " + Convert.ToString(master_host).Trim()
+                                   + "," + Convert.ToString(master_port).Trim();
 
                                foreach (ListViewItem lvi in lvwEndpoints.Items) {
-                                       args += " --endpoint " + lvi.SubItems[0].Text;
+                                       args += " --endpoint " + Convert.ToString(lvi.SubItems[0].Text).Trim();
 
-                                       if (lvi.SubItems.Count > 1)
-                                               args += "," + lvi.SubItems[1].Text + "," + lvi.SubItems[2].Text;
+                                       if (lvi.SubItems.Count > 1) {
+                                               args += "," + Convert.ToString(lvi.SubItems[1].Text).Trim()
+                                                   + "," + Convert.ToString(lvi.SubItems[2].Text).Trim();
+                                       }
                                }
                        });
 
                        if (rdoListener.Checked)
-                               args += " --listen ::," + txtListenerPort.Text;
+                               args += " --listen ::," + Convert.ToString(txtListenerPort.Text).Trim();
 
                        if (chkAcceptConfig.Checked)
                                args += " --accept-config";
@@ -213,12 +216,14 @@ namespace Icinga
                        if (chkAcceptCommands.Checked)
                                args += " --accept-commands";
 
-                       if (txtTicket.Text != "")
-                               args += " --ticket \"" + txtTicket.Text + "\"";
+                       string ticket = Convert.ToString(txtTicket.Text).Trim();
+
+                       if (ticket.Length > 0)
+                               args += " --ticket \"" + ticket + "\"";
 
                        args += " --trustedcert \"" + _TrustedFile + "\"";
-                       args += " --cn \"" + txtInstanceName.Text + "\"";
-                       args += " --zone \"" + txtInstanceName.Text + "\"";
+                       args += " --cn \"" + Convert.ToString(txtInstanceName.Text).Trim() + "\"";
+                       args += " --zone \"" + Convert.ToString(txtInstanceName.Text) + "\"";
 
                        if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
                                "node setup" + args,
@@ -228,16 +233,19 @@ namespace Icinga
                        }
 
                        SetConfigureStatus(50, "Setting ACLs for the Icinga 2 directory...");
+
+                       string serviceUser = Convert.ToString(txtUser.Text).Trim();
+
                        DirectoryInfo di = new DirectoryInfo(Program.Icinga2InstallDir);
                        DirectorySecurity ds = di.GetAccessControl();
-                       FileSystemAccessRule rule = new FileSystemAccessRule(txtUser.Text,
+                       FileSystemAccessRule rule = new FileSystemAccessRule(serviceUser,
                                FileSystemRights.Modify,
                                InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow);
                        try {
                                ds.AddAccessRule(rule);
                                di.SetAccessControl(ds);
                        } catch (System.Security.Principal.IdentityNotMappedException) {
-                               ShowErrorText("Could not set ACLs for \"" + txtUser.Text + "\". Identitiy is not mapped.\n");
+                               ShowErrorText("Could not set ACLs for user \"" + serviceUser + "\". Identitiy is not mapped.\n");
                                return;
                        }
 
@@ -255,10 +263,10 @@ namespace Icinga
                        }
 
                        if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
-                               "--scm-install --scm-user \"" + txtUser.Text + "\" daemon",
+                               "--scm-install --scm-user \"" + serviceUser + "\" daemon",
                                out output)) {
                                ShowErrorText("\nRunning command 'icinga2.exe --scm-install --scm-user \"" +
-                                       txtUser.Text + "\" daemon' produced the following output:\n" + output);
+                                       serviceUser + "\" daemon' produced the following output:\n" + output);
                                return;
                        }
 
@@ -278,7 +286,7 @@ namespace Icinga
                        lblSetupCompleted.Text = "The Icinga 2 Windows client was set up successfully.";
 
                        // Add a note for the user for ticket-less signing
-                       if (txtTicket.Text == "") {
+                       if (ticket.Length == 0) {
                                lblSetupCompleted.Text += "\n\nTicket was not specified. Please sign the certificate request on the Icinga 2 master node (requires v2.8+).";
                        }
 
@@ -335,7 +343,7 @@ namespace Icinga
                                }
 
                                if (txtUser.Text.Length == 0) {
-                                       Warning("Icinga 2 user may not be empty.");
+                                       Warning("Icinga 2 service user may not be empty.");
                                        return;
                                }
                        }