From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from re-prd-fep-042.btinternet.com (mailomta32-re.btinternet.com [213.120.69.125]) by sourceware.org (Postfix) with ESMTPS id 758D3385E453 for ; Fri, 8 Mar 2024 18:36:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 758D3385E453 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dronecode.org.uk Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dronecode.org.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 758D3385E453 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=213.120.69.125 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709922977; cv=none; b=oA/ZIUAT1UTHHnQYioboiRH/lR5JCIhEuW5EJ/R29gxkuQI21r+gq5Z6rlR/cIIn8Fl2BdM2j7QeUeVjUOhJYVF9/y2U0EJz0Xiz10qODdBTQKlT8yDbQgpV4CYEsk5Hdtm5OQFUyx1X08vy1zqjM3fNb5QPNbqlzBw0gJnFHZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709922977; c=relaxed/simple; bh=7Cp2+6Qt9qkX5jpRKAGUF/Pve0hwrpNOZSzak6hDFV0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=eLIHeooXzohqy9d5cm71P+/WFeqJL+yMsndgigikUNBsZxH0no8YQk6L6LaOuBZs/wiIdNeV66ln2mw8cgD/bVK0rFH1V3xum1P6ph4p7M/C7vzYmEa23YSzvIxZ2L5c8BJznWTL2UKScQ/zF2HYoOs7adlueTj4e7mpN7H2NjY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from re-prd-rgout-004.btmx-prd.synchronoss.net ([10.2.54.7]) by re-prd-fep-042.btinternet.com with ESMTP id <20240308183613.LKBB4314.re-prd-fep-042.btinternet.com@re-prd-rgout-004.btmx-prd.synchronoss.net>; Fri, 8 Mar 2024 18:36:13 +0000 Authentication-Results: btinternet.com; none X-SNCR-Rigid: 6577B87C0AB06A0A X-Originating-IP: [81.153.98.185] X-OWM-Source-IP: 81.153.98.185 X-OWM-Env-Sender: jon.turney@dronecode.org.uk X-VadeSecure-score: verdict=clean score=0/300, class=clean X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvledrieehgdduudegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheplfhonhcuvfhurhhnvgihuceojhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukheqnecuggftrfgrthhtvghrnhepudevleegtdduudeltedugeeuhefgteegkeeuhfeukeetkeduteekvdfgiefguddvnecuffhomhgrihhnpehgnhhurdhorhhgnecukfhppeekuddrudehfedrleekrddukeehnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehhvghloheplhhotggrlhhhohhsthdrlhhotggrlhguohhmrghinhdpihhnvghtpeekuddrudehfedrleekrddukeehpdhmrghilhhfrhhomhepjhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukhdpnhgspghrtghpthhtohepvddprhgtphhtthhopegthihgfihinhdqrghpphhssegthihgfihinhdrtghomhdprhgtphhtthhopehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkpdhrvghvkffrpehhohhsthekuddqudehfedqleekqddukeehrdhrrghnghgvkeduqdduheefrdgsthgtvghnthhrrghlphhluhhsrdgtohhmpdgruhhthhgpuhhsvghrpehjohhnthhurhhnvgihsegsthhi nhhtvghrnhgvthdrtghomhdpghgvohfkrfepifeupdfovfetjfhoshhtpehrvgdqphhrugdqrhhgohhuthdqtddtge X-RazorGate-Vade-Verdict: clean 0 X-RazorGate-Vade-Classification: clean Received: from localhost.localdomain (81.153.98.185) by re-prd-rgout-004.btmx-prd.synchronoss.net (authenticated as jonturney@btinternet.com) id 6577B87C0AB06A0A; Fri, 8 Mar 2024 18:36:13 +0000 From: Jon Turney To: cygwin-apps@cygwin.com Cc: Jon Turney Subject: [PATCH setup 12/16] Spit out GetNetAuth from NetIO Date: Fri, 8 Mar 2024 18:34:31 +0000 Message-ID: <20240308183440.4263-13-jon.turney@dronecode.org.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240308183440.4263-1-jon.turney@dronecode.org.uk> References: <20240308183440.4263-1-jon.turney@dronecode.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: There's still all kinds of janky stuff here: The network proxy configuration fetched by ConnectionSetting is stored into static members of the NetIO class, rather than held there and accessed. Again, define a virtual class as the interface through which user interaction takes place, and implement that for GUI and CLI clients. While we're at it, we arrange for the GUI dialogs for network auth to be properly parented. --- GetNetAuth.h | 30 ++++++++++ Makefile.am | 2 + cli/CliGetNetAuth.cc | 45 ++++++++++++++ cli/CliGetNetAuth.h | 32 ++++++++++ gui/GuiGetNetAuth.cc | 138 +++++++++++++++++++++++++++++++++++++++++++ gui/GuiGetNetAuth.h | 38 ++++++++++++ net.cc | 5 ++ netio.cc | 125 +-------------------------------------- netio.h | 19 ++---- nio-ie5.cc | 4 +- 10 files changed, 298 insertions(+), 140 deletions(-) create mode 100644 GetNetAuth.h create mode 100644 cli/CliGetNetAuth.cc create mode 100644 cli/CliGetNetAuth.h create mode 100644 gui/GuiGetNetAuth.cc create mode 100644 gui/GuiGetNetAuth.h diff --git a/GetNetAuth.h b/GetNetAuth.h new file mode 100644 index 0000000..0a26e85 --- /dev/null +++ b/GetNetAuth.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2000, Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by DJ Delorie + * + */ + +#ifndef SETUP_GETNETAUTH_H +#define SETUP_GETNETAUTH_H + +class GetNetAuth +{ +public: + /* Helper functions for http/ftp protocols. Both return nonzero for + "cancel", zero for "ok". They set net_proxy_user, etc, in + state.h */ + virtual int get_auth () = 0; + virtual int get_proxy_auth () = 0; + virtual int get_ftp_auth () = 0; +}; + +#endif /* SETUP_GETNETAUTH_H */ diff --git a/Makefile.am b/Makefile.am index de066b7..f257e3a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -182,6 +182,8 @@ endif gpg-packet.cc \ gpg-packet.h \ gui/GuiParseFeedback.cc \ + gui/GuiGetNetAuth.cc \ + gui/GuiGetNetAuth.h \ gui/GuiGetUrlFeedback.cc \ gui/GuiFeedback.h \ ini.cc \ diff --git a/cli/CliGetNetAuth.cc b/cli/CliGetNetAuth.cc new file mode 100644 index 0000000..a1fde3b --- /dev/null +++ b/cli/CliGetNetAuth.cc @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2000, 2001, Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + */ + +/* Query user for auth information required */ + +#include "netio.h" +#include "CliGetNetAuth.h" + +#include "LogFile.h" + +static int +auth_common(const char *mode) +{ + Log (LOG_PLAIN) << mode << " not implemented" << endLog; + Logger ().exit (1); + return 1; +} + +int +CliGetNetAuth::get_auth () +{ + return auth_common("get_auth"); +} + +int +CliGetNetAuth::get_proxy_auth () +{ + return auth_common("get_proxy_auth"); +} + +int +CliGetNetAuth::get_ftp_auth () +{ + return auth_common("get_ftp_auth"); +} diff --git a/cli/CliGetNetAuth.h b/cli/CliGetNetAuth.h new file mode 100644 index 0000000..7ff4520 --- /dev/null +++ b/cli/CliGetNetAuth.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2000, Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by DJ Delorie + * + */ + +#ifndef SETUP_CLI_GETNETAUTH_H +#define SETUP_CLI_GETNETAUTH_H + +#include "GetNetAuth.h" + +class CliGetNetAuth : public GetNetAuth +{ +public: + /* Helper functions for http/ftp protocols. Both return nonzero for + "cancel", zero for "ok". They set net_proxy_user, etc, in + state.h */ + int get_auth (); + int get_proxy_auth (); + int get_ftp_auth (); +}; + +#endif /* SETUP_CLI_GETNETAUTH_H */ diff --git a/gui/GuiGetNetAuth.cc b/gui/GuiGetNetAuth.cc new file mode 100644 index 0000000..a6d4917 --- /dev/null +++ b/gui/GuiGetNetAuth.cc @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2000, 2001, Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + */ + +/* Query user for auth information required */ + +#include "netio.h" +#include "GuiGetNetAuth.h" + +#include "LogFile.h" + +#include "resource.h" +#include "dialog.h" + +static char **user, **passwd; +static int loading = 0; + +static void +check_if_enable_ok (HWND h) +{ + int e = 0; + if (*user) + e = 1; + EnableWindow (GetDlgItem (h, IDOK), e); +} + +static void +load_dialog (HWND h) +{ + loading = 1; + eset (h, IDC_NET_USER, *user); + eset (h, IDC_NET_PASSWD, *passwd); + check_if_enable_ok (h); + loading = 0; +} + +static void +save_dialog (HWND h) +{ + *user = eget (h, IDC_NET_USER, *user); + *passwd = eget (h, IDC_NET_PASSWD, *passwd); + if (! *passwd) { + *passwd = new char[1]; + (*passwd)[0] = '\0'; + } +} + +static BOOL +auth_cmd (HWND h, int id, HWND hwndctl, UINT code) +{ + switch (id) + { + + case IDC_NET_USER: + case IDC_NET_PASSWD: + if (code == EN_CHANGE && !loading) + { + save_dialog (h); + check_if_enable_ok (h); + } + break; + + case IDOK: + save_dialog (h); + EndDialog (h, 0); + break; + + case IDCANCEL: + EndDialog (h, 1); + Logger ().exit (1); + break; + } + return 0; +} + +static INT_PTR CALLBACK +auth_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_INITDIALOG: + load_dialog (h); + return FALSE; + case WM_COMMAND: + auth_cmd (h, LOWORD(wParam), (HWND)lParam, HIWORD(wParam)); + return 0; + } + return FALSE; +} + +static int +auth_common (int id, HWND owner) +{ + return DialogBox (NULL, MAKEINTRESOURCE (id), owner, auth_proc); +} + +int +GuiGetNetAuth::get_auth () +{ + user = &NetIO::net_user; + passwd = &NetIO::net_passwd; + return auth_common (IDD_NET_AUTH, owner); +} + +int +GuiGetNetAuth::get_proxy_auth () +{ + user = &NetIO::net_proxy_user; + passwd = &NetIO::net_proxy_passwd; + return auth_common (IDD_PROXY_AUTH, owner); +} + +int +GuiGetNetAuth::get_ftp_auth () +{ + if (NetIO::net_ftp_user) + { + delete[] NetIO::net_ftp_user; + NetIO::net_ftp_user = NULL; + } + if (NetIO::net_ftp_passwd) + { + delete[] NetIO::net_ftp_passwd; + NetIO::net_ftp_passwd = NULL; + } + user = &NetIO::net_ftp_user; + passwd = &NetIO::net_ftp_passwd; + return auth_common (IDD_FTP_AUTH, owner); +} diff --git a/gui/GuiGetNetAuth.h b/gui/GuiGetNetAuth.h new file mode 100644 index 0000000..21758f2 --- /dev/null +++ b/gui/GuiGetNetAuth.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2000, Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by DJ Delorie + * + */ + +#ifndef SETUP_GUI_GETNETAUTH_H +#define SETUP_GUI_GETNETAUTH_H + +#include "win32.h" +#include "GetNetAuth.h" + +class GuiGetNetAuth : public GetNetAuth +{ +public: + GuiGetNetAuth (HWND owner_) : owner(owner_) { }; + + /* Helper functions for http/ftp protocols. Both return nonzero for + "cancel", zero for "ok". They set net_proxy_user, etc, in + state.h */ + int get_auth (); + int get_proxy_auth (); + int get_ftp_auth (); + +private: + HWND owner; +}; + +#endif /* SETUP_GUI_GETNETAUTH_H */ diff --git a/net.cc b/net.cc index f460efc..ee84e64 100644 --- a/net.cc +++ b/net.cc @@ -33,6 +33,8 @@ #include "propsheet.h" #include "threebar.h" #include "ConnectionSetting.h" +#include "gui/GuiGetNetAuth.h" + extern ThreeBarProgressPage Progress; static StringOption ProxyOption ("", 'p', "proxy", IDS_HELPTEXT_PROXY, false); @@ -113,6 +115,9 @@ NetPage::OnInit () if (!NetIO::net_method) NetIO::net_method = IDC_NET_PRECONFIG; + // install the interactive network auth getter + NetIO::auth_getter = new GuiGetNetAuth(GetHWND()); + if (proxyString.size ()) { unsigned int pos = proxyString.find_last_of (':'); diff --git a/netio.cc b/netio.cc index d6bfc24..7d32f9f 100644 --- a/netio.cc +++ b/netio.cc @@ -21,17 +21,10 @@ #include "LogFile.h" -#include -#include -#include - #include #include "resource.h" -#include "state.h" -#include "msg.h" #include "nio-ie5.h" -#include "dialog.h" int NetIO::net_method; char *NetIO::net_proxy_host; @@ -43,6 +36,7 @@ char *NetIO::net_proxy_user; char *NetIO::net_proxy_passwd; char *NetIO::net_ftp_user; char *NetIO::net_ftp_passwd; +GetNetAuth *NetIO::auth_getter; int NetIO::ok () @@ -107,123 +101,6 @@ NetIO::open (char const *url, bool cachable) return rv; } - -static char **user, **passwd; -static int loading = 0; - -static void -check_if_enable_ok (HWND h) -{ - int e = 0; - if (*user) - e = 1; - EnableWindow (GetDlgItem (h, IDOK), e); -} - -static void -load_dialog (HWND h) -{ - loading = 1; - eset (h, IDC_NET_USER, *user); - eset (h, IDC_NET_PASSWD, *passwd); - check_if_enable_ok (h); - loading = 0; -} - -static void -save_dialog (HWND h) -{ - *user = eget (h, IDC_NET_USER, *user); - *passwd = eget (h, IDC_NET_PASSWD, *passwd); - if (! *passwd) { - *passwd = new char[1]; - (*passwd)[0] = '\0'; - } -} - -static BOOL -auth_cmd (HWND h, int id, HWND hwndctl, UINT code) -{ - switch (id) - { - - case IDC_NET_USER: - case IDC_NET_PASSWD: - if (code == EN_CHANGE && !loading) - { - save_dialog (h); - check_if_enable_ok (h); - } - break; - - case IDOK: - save_dialog (h); - EndDialog (h, 0); - break; - - case IDCANCEL: - EndDialog (h, 1); - Logger ().exit (1); - break; - } - return 0; -} - -static INT_PTR CALLBACK -auth_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch (message) - { - case WM_INITDIALOG: - load_dialog (h); - return FALSE; - case WM_COMMAND: - auth_cmd (h, LOWORD(wParam), (HWND)lParam, HIWORD(wParam)); - return 0; - } - return FALSE; -} - -static int -auth_common (int id, HWND owner) -{ - return DialogBox (NULL, MAKEINTRESOURCE (id), owner, auth_proc); -} - -int -NetIO::get_auth (HWND owner) -{ - user = &net_user; - passwd = &net_passwd; - return auth_common (IDD_NET_AUTH, owner); -} - -int -NetIO::get_proxy_auth (HWND owner) -{ - user = &net_proxy_user; - passwd = &net_proxy_passwd; - return auth_common (IDD_PROXY_AUTH, owner); -} - -int -NetIO::get_ftp_auth (HWND owner) -{ - if (net_ftp_user) - { - delete[] net_ftp_user; - net_ftp_user = NULL; - } - if (net_ftp_passwd) - { - delete[] net_ftp_passwd; - net_ftp_passwd = NULL; - } - user = &net_ftp_user; - passwd = &net_ftp_passwd; - return auth_common (IDD_FTP_AUTH, owner); -} - const char * NetIO::net_method_name () { diff --git a/netio.h b/netio.h index f2ecfdd..98d435b 100644 --- a/netio.h +++ b/netio.h @@ -16,23 +16,22 @@ #ifndef SETUP_NETIO_H #define SETUP_NETIO_H -#include "win32.h" +#include "GetNetAuth.h" /* This is the parent class for all the access methods known to setup (i.e. ways to download files from the internet or other sources */ class NetIO { -protected: +public: static char *net_user; static char *net_passwd; static char *net_proxy_user; static char *net_proxy_passwd; static char *net_ftp_user; static char *net_ftp_passwd; + static GetNetAuth *auth_getter; - -public: /* if nonzero, this is the estimated total file size */ int file_size; @@ -40,9 +39,8 @@ public: virtual ~ NetIO () {}; /* The user calls this function to create a suitable accessor for - the given URL. It uses the network setup state in state.h. If - anything fails, either the return values is NULL or the returned - object is !ok() */ + the given URL. If anything fails, either the return values is NULL + or the returned object is !ok() */ static NetIO *open (char const *url, bool cachable); /* If !ok() that means the transfer isn't happening. */ @@ -57,13 +55,6 @@ public: static int net_proxy_port; static const char *net_method_name(); - - /* Helper functions for http/ftp protocols. Both return nonzero for - "cancel", zero for "ok". They set net_proxy_user, etc, in - state.h */ - int get_auth (HWND owner); - int get_proxy_auth (HWND owner); - int get_ftp_auth (HWND owner); }; #endif /* SETUP_NETIO_H */ diff --git a/nio-ie5.cc b/nio-ie5.cc index 2117e33..2c7e85a 100644 --- a/nio-ie5.cc +++ b/nio-ie5.cc @@ -274,14 +274,14 @@ try_again: if (type == 401) /* authorization required */ { flush_io (); - get_auth (NULL); + auth_getter->get_auth (); resend = 1; goto try_again; } else if (type == 407) /* proxy authorization required */ { flush_io (); - get_proxy_auth (NULL); + auth_getter->get_proxy_auth (); resend = 1; goto try_again; } -- 2.43.0