From f35b01ba05a51b53a91e66d5a180ff4b2e268c46 Mon Sep 17 00:00:00 2001
From: "Rob Swindell (on Windows 11)" <rob@synchro.net>
Date: Thu, 2 Jan 2025 20:40:44 -0800
Subject: [PATCH] Support auto-timezone, delete cryptlib.key and ssl.cert when
 changing syspass

If the timezone is set to automatic and it's not a new install, don't display
"UTC0:01" as the time zone (that's weird), display "Automatic (UTC[+/-]HH:MM)"
instead.

When changing the system password via this config wizard, the cryptlib.key
and ssl.cert files, if they exist, will be invalid, so delete them.
---
 src/sbbs3/ctrl/ConfigWizardUnit.cpp | 26 ++++++++++++++++++++++----
 src/sbbs3/ctrl/ConfigWizardUnit.h   |  1 +
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/sbbs3/ctrl/ConfigWizardUnit.cpp b/src/sbbs3/ctrl/ConfigWizardUnit.cpp
index 7373711e98..0d516872bd 100644
--- a/src/sbbs3/ctrl/ConfigWizardUnit.cpp
+++ b/src/sbbs3/ctrl/ConfigWizardUnit.cpp
@@ -137,6 +137,7 @@ void __fastcall TConfigWizard::FormShow(TObject *Sender)
         Close();
         return;
     }
+	SysPass = scfg.sys_pass;
 
     if(scfg.new_install) {
         TIME_ZONE_INFORMATION tz;
@@ -229,15 +230,18 @@ void __fastcall TConfigWizard::FormShow(TObject *Sender)
             SAFECOPY(str,tz_str[i]);
         TimeZoneComboBox->Items->Add(str);
     }
-   	sprintf(str,"Other (%s)",smb_zonestr(scfg.sys_timezone,NULL));
+	if(scfg.sys_timezone == SYS_TIMEZONE_AUTO)
+		snprintf(str, sizeof str, "Automatic (%s)", smb_zonestr(sys_timezone(&scfg), NULL));
+	else
+		snprintf(str, sizeof str, "Other (%s)",smb_zonestr(scfg.sys_timezone,NULL));
     TimeZoneComboBox->Items->Add(str);
 
     for(i=0;i<sizeof(tz_val)/sizeof(tz_val[0]);i++)
         if((scfg.sys_timezone&((short)~DAYLIGHT))==tz_val[i])
             break;
     TimeZoneComboBox->ItemIndex=i;
-    DaylightCheckBox->Enabled=scfg.sys_timezone&US_ZONE;
-    DaylightCheckBox->Checked=scfg.sys_timezone&DAYLIGHT;
+    DaylightCheckBox->Enabled = SMB_TZ_HAS_DST(scfg.sys_timezone);
+    DaylightCheckBox->Checked = DaylightCheckBox->Enabled && (scfg.sys_timezone & DAYLIGHT);
     if(scfg.sys_misc&SM_MILITARY)
         Time24hrRadioButton->Checked=true;
     else
@@ -314,8 +318,22 @@ void __fastcall TConfigWizard::NextButtonClick(TObject *Sender)
         if(!save_cfg(&scfg)) {
         	Application->MessageBox("Error saving configuration"
             	,"ERROR",MB_OK|MB_ICONEXCLAMATION);
-        } else
+        } else {
+			if(strcmp(scfg.sys_pass, SysPass.c_str()) != 0) {
+				char path[MAX_PATH + 1];
+				snprintf(path, sizeof path, "%scryptlib.key", scfg.ctrl_dir);
+				if(fexist(path) && remove(path) != 0)
+					Application->MessageBox(path, "ERROR Removing File"
+						,MB_OK|MB_ICONEXCLAMATION);
+				else {
+					snprintf(path, sizeof path, "%sssl.cert", scfg.ctrl_dir);
+					if(fexist(path) && remove(path) != 0)
+						Application->MessageBox(path, "ERROR Removing File"
+							,MB_OK|MB_ICONEXCLAMATION);
+				}
+			}
         	refresh_cfg(&scfg);
+		}
         Close();
         return;
     }
diff --git a/src/sbbs3/ctrl/ConfigWizardUnit.h b/src/sbbs3/ctrl/ConfigWizardUnit.h
index 229f5dbe5c..a7d107286a 100644
--- a/src/sbbs3/ctrl/ConfigWizardUnit.h
+++ b/src/sbbs3/ctrl/ConfigWizardUnit.h
@@ -101,6 +101,7 @@ __published:	// IDE-managed Components
     void __fastcall NewUsersCheckBoxClick(TObject *Sender);
 private:	// User declarations
     scfg_t  scfg;
+	AnsiString SysPass;
 public:		// User declarations
     __fastcall TConfigWizard(TComponent* Owner);
 };
-- 
GitLab