Blame SOURCES/0001-rhbz-1691287-tdf-53029-ui-prompt-for-printer-authent.patch

bf2fec
From f1df94c1415302792d31ce4b6e28b7eb93d769fd Mon Sep 17 00:00:00 2001
bf2fec
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
bf2fec
Date: Tue, 26 Mar 2019 12:09:03 +0000
bf2fec
Subject: [PATCH] rhbz#1691287 tdf#53029 ui prompt for printer authentication
bf2fec
bf2fec
refactor and reuse existing dialog to add potential domain entry
bf2fec
bf2fec
Change-Id: Ib884931f8ccc62aad9b3e92ecf93d1da7ffe607b
bf2fec
---
bf2fec
 vcl/inc/printerinfomanager.hxx        |   2 +
bf2fec
 vcl/uiconfig/ui/cupspassworddialog.ui |  34 +++-
bf2fec
 vcl/unx/generic/printer/cupsmgr.cxx   | 221 ++++++++++++++++++--------
bf2fec
 3 files changed, 183 insertions(+), 74 deletions(-)
bf2fec
bf2fec
diff --git a/vcl/inc/printerinfomanager.hxx b/vcl/inc/printerinfomanager.hxx
bf2fec
index 7691fbeebc6c..4c225a22f91e 100644
bf2fec
--- a/vcl/inc/printerinfomanager.hxx
bf2fec
+++ b/vcl/inc/printerinfomanager.hxx
bf2fec
@@ -52,6 +52,8 @@ struct PrinterInfo : JobData
bf2fec
     // a list of special features separated by ',' not used by psprint
bf2fec
     // but assigned from the outside (currently for "fax","pdf=","autoqueue","external_dialog")
bf2fec
     OUString             m_aFeatures;
bf2fec
+    // auth-info-required, potential [domain],[username],[password] to prompt for to authenticate printing
bf2fec
+    OUString             m_aAuthInfoRequired;
bf2fec
     bool                 m_bPapersizeFromSetup;
bf2fec
 
bf2fec
     PrinterInfo()
bf2fec
diff --git a/vcl/uiconfig/ui/cupspassworddialog.ui b/vcl/uiconfig/ui/cupspassworddialog.ui
bf2fec
index f4fb757209bb..2c17d1397c3e 100644
bf2fec
--- a/vcl/uiconfig/ui/cupspassworddialog.ui
bf2fec
+++ b/vcl/uiconfig/ui/cupspassworddialog.ui
bf2fec
@@ -73,7 +73,7 @@
bf2fec
               </object>
bf2fec
               <packing>
bf2fec
                 <property name="left_attach">0</property>
bf2fec
-                <property name="top_attach">1</property>
bf2fec
+                <property name="top_attach">2</property>
bf2fec
               </packing>
bf2fec
             </child>
bf2fec
             <child>
bf2fec
@@ -87,7 +87,7 @@
bf2fec
               </object>
bf2fec
               <packing>
bf2fec
                 <property name="left_attach">0</property>
bf2fec
-                <property name="top_attach">2</property>
bf2fec
+                <property name="top_attach">3</property>
bf2fec
               </packing>
bf2fec
             </child>
bf2fec
             <child>
bf2fec
@@ -114,7 +114,7 @@
bf2fec
               </object>
bf2fec
               <packing>
bf2fec
                 <property name="left_attach">1</property>
bf2fec
-                <property name="top_attach">1</property>
bf2fec
+                <property name="top_attach">2</property>
bf2fec
               </packing>
bf2fec
             </child>
bf2fec
             <child>
bf2fec
@@ -123,10 +123,36 @@
bf2fec
                 <property name="can_focus">True</property>
bf2fec
                 <property name="hexpand">True</property>
bf2fec
                 <property name="visibility">False</property>
bf2fec
+                <property name="input_purpose">password</property>
bf2fec
               </object>
bf2fec
               <packing>
bf2fec
                 <property name="left_attach">1</property>
bf2fec
-                <property name="top_attach">2</property>
bf2fec
+                <property name="top_attach">3</property>
bf2fec
+              </packing>
bf2fec
+            </child>
bf2fec
+            <child>
bf2fec
+              <object class="GtkLabel" id="label3">
bf2fec
+                <property name="can_focus">False</property>
bf2fec
+                <property name="no_show_all">True</property>
bf2fec
+                <property name="label" translatable="yes" context="cupspassworddialog|label1">_Domain:</property>
bf2fec
+                <property name="use_underline">True</property>
bf2fec
+                <property name="mnemonic_widget">domain</property>
bf2fec
+                <property name="xalign">1</property>
bf2fec
+              </object>
bf2fec
+              <packing>
bf2fec
+                <property name="left_attach">0</property>
bf2fec
+                <property name="top_attach">1</property>
bf2fec
+              </packing>
bf2fec
+            </child>
bf2fec
+            <child>
bf2fec
+              <object class="GtkEntry" id="domain">
bf2fec
+                <property name="can_focus">True</property>
bf2fec
+                <property name="no_show_all">True</property>
bf2fec
+                <property name="hexpand">True</property>
bf2fec
+              </object>
bf2fec
+              <packing>
bf2fec
+                <property name="left_attach">1</property>
bf2fec
+                <property name="top_attach">1</property>
bf2fec
               </packing>
bf2fec
             </child>
bf2fec
           </object>
bf2fec
diff --git a/vcl/unx/generic/printer/cupsmgr.cxx b/vcl/unx/generic/printer/cupsmgr.cxx
bf2fec
index 328e9246e9f5..c872bde70dcf 100644
bf2fec
--- a/vcl/unx/generic/printer/cupsmgr.cxx
bf2fec
+++ b/vcl/unx/generic/printer/cupsmgr.cxx
bf2fec
@@ -319,6 +319,8 @@ void CUPSManager::initialize()
bf2fec
                 aPrinter.m_aInfo.m_aComment=OStringToOUString(pDest->options[k].value, aEncoding);
bf2fec
             if(!strcmp(pDest->options[k].name, "printer-location"))
bf2fec
                 aPrinter.m_aInfo.m_aLocation=OStringToOUString(pDest->options[k].value, aEncoding);
bf2fec
+            if(!strcmp(pDest->options[k].name, "auth-info-required"))
bf2fec
+                aPrinter.m_aInfo.m_aAuthInfoRequired=OStringToOUString(pDest->options[k].value, aEncoding);
bf2fec
         }
bf2fec
 
bf2fec
         OUStringBuffer aBuf( 256 );
bf2fec
@@ -617,6 +619,106 @@ void CUPSManager::getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner
bf2fec
     }
bf2fec
 }
bf2fec
 
bf2fec
+namespace
bf2fec
+{
bf2fec
+    class RTSPWDialog : public ModalDialog
bf2fec
+    {
bf2fec
+        VclPtr<FixedText> m_xText;
bf2fec
+        VclPtr<FixedText> m_xDomainLabel;
bf2fec
+        VclPtr<Edit> m_xDomainEdit;
bf2fec
+        VclPtr<FixedText> m_xUserLabel;
bf2fec
+        VclPtr<Edit> m_xUserEdit;
bf2fec
+        VclPtr<FixedText> m_xPassLabel;
bf2fec
+        VclPtr<Edit> m_xPassEdit;
bf2fec
+
bf2fec
+    public:
bf2fec
+        RTSPWDialog(vcl::Window* pParent, const OString& rServer, const OString& rUserName);
bf2fec
+        virtual void dispose() override;
bf2fec
+        virtual ~RTSPWDialog() override;
bf2fec
+
bf2fec
+        OString getDomain() const
bf2fec
+        {
bf2fec
+            return OUStringToOString( m_xDomainEdit->GetText(), osl_getThreadTextEncoding() );
bf2fec
+        }
bf2fec
+
bf2fec
+        OString getUserName() const
bf2fec
+        {
bf2fec
+            return OUStringToOString( m_xUserEdit->GetText(), osl_getThreadTextEncoding() );
bf2fec
+        }
bf2fec
+
bf2fec
+        OString getPassword() const
bf2fec
+        {
bf2fec
+            return OUStringToOString( m_xPassEdit->GetText(), osl_getThreadTextEncoding() );
bf2fec
+        }
bf2fec
+
bf2fec
+        void SetDomainVisible(bool bShow)
bf2fec
+        {
bf2fec
+            m_xDomainLabel->Show(bShow);
bf2fec
+            m_xDomainEdit->Show(bShow);
bf2fec
+        }
bf2fec
+
bf2fec
+        void SetUserVisible(bool bShow)
bf2fec
+        {
bf2fec
+            m_xUserLabel->Show(bShow);
bf2fec
+            m_xUserEdit->Show(bShow);
bf2fec
+        }
bf2fec
+
bf2fec
+        void SetPassVisible(bool bShow)
bf2fec
+        {
bf2fec
+            m_xPassLabel->Show(bShow);
bf2fec
+            m_xPassEdit->Show(bShow);
bf2fec
+        }
bf2fec
+    };
bf2fec
+
bf2fec
+    RTSPWDialog::RTSPWDialog(vcl::Window* pParent, const OString& rServer, const OString& rUserName)
bf2fec
+        : ModalDialog(pParent, "CUPSPasswordDialog", "vcl/ui/cupspassworddialog.ui")
bf2fec
+    {
bf2fec
+        get(m_xText, "text");
bf2fec
+        get(m_xDomainLabel, "label3");
bf2fec
+        get(m_xUserLabel, "label1");
bf2fec
+        get(m_xUserEdit, "user");
bf2fec
+        get(m_xPassLabel, "label2");
bf2fec
+        get(m_xPassEdit, "pass");
bf2fec
+
bf2fec
+        OUString aText(m_xText->GetText());
bf2fec
+        aText = aText.replaceFirst("%s", OStringToOUString(rServer, osl_getThreadTextEncoding()));
bf2fec
+        m_xText->SetText(aText);
bf2fec
+        m_xUserEdit->SetText(OStringToOUString(rUserName, osl_getThreadTextEncoding()));
bf2fec
+    }
bf2fec
+
bf2fec
+    RTSPWDialog::~RTSPWDialog()
bf2fec
+    {
bf2fec
+        disposeOnce();
bf2fec
+    }
bf2fec
+
bf2fec
+    void RTSPWDialog::dispose()
bf2fec
+    {
bf2fec
+        m_xText.clear();
bf2fec
+        m_xDomainLabel.clear();
bf2fec
+        m_xDomainEdit.clear();
bf2fec
+        m_xUserLabel.clear();
bf2fec
+        m_xUserEdit.clear();
bf2fec
+        m_xPassLabel.clear();
bf2fec
+        m_xPassEdit.clear();
bf2fec
+        ModalDialog::dispose();
bf2fec
+    }
bf2fec
+
bf2fec
+    bool AuthenticateQuery(const OString& rServer, OString& rUserName, OString& rPassword)
bf2fec
+    {
bf2fec
+        bool bRet = false;
bf2fec
+
bf2fec
+        ScopedVclPtrInstance<RTSPWDialog> aDialog(nullptr, rServer, rUserName);
bf2fec
+        if (aDialog->Execute())
bf2fec
+        {
bf2fec
+            rUserName = aDialog->getUserName();
bf2fec
+            rPassword = aDialog->getPassword();
bf2fec
+            bRet = true;
bf2fec
+        }
bf2fec
+
bf2fec
+        return bRet;
bf2fec
+    }
bf2fec
+}
bf2fec
+
bf2fec
 bool CUPSManager::endSpool( const OUString& rPrintername, const OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner, const OUString& rFaxNumber )
bf2fec
 {
bf2fec
     SAL_INFO( "vcl.unx.print", "endSpool: " << rPrintername << "," << rJobTitle << " copy count = " << rDocumentJobData.m_nCopies );
bf2fec
@@ -642,7 +744,55 @@ bool CUPSManager::endSpool( const OUString& rPrintername, const OUString& rJobTi
bf2fec
         // setup cups options
bf2fec
         int nNumOptions = 0;
bf2fec
         cups_option_t* pOptions = nullptr;
bf2fec
-        getOptionsFromDocumentSetup( rDocumentJobData, bBanner, nNumOptions, reinterpret_cast<void**>(&pOptions) );
bf2fec
+        auto ppOptions = reinterpret_cast<void**>(&pOptions);
bf2fec
+        getOptionsFromDocumentSetup( rDocumentJobData, bBanner, nNumOptions, ppOptions );
bf2fec
+
bf2fec
+        PrinterInfo aInfo(getPrinterInfo(rPrintername));
bf2fec
+        if (!aInfo.m_aAuthInfoRequired.isEmpty())
bf2fec
+        {
bf2fec
+            bool bDomain(false), bUser(false), bPass(false);
bf2fec
+            sal_Int32 nIndex = 0;
bf2fec
+            do
bf2fec
+            {
bf2fec
+                OUString aToken = aInfo.m_aAuthInfoRequired.getToken(0, ',', nIndex);
bf2fec
+                if (aToken == "domain")
bf2fec
+                    bDomain = true;
bf2fec
+                else if (aToken == "username")
bf2fec
+                    bUser = true;
bf2fec
+                else if (aToken == "password")
bf2fec
+                    bPass = true;
bf2fec
+            }
bf2fec
+            while (nIndex >= 0);
bf2fec
+
bf2fec
+            if (bDomain || bUser || bPass)
bf2fec
+            {
bf2fec
+                OString sPrinterName(OUStringToOString(rPrintername, RTL_TEXTENCODING_UTF8));
bf2fec
+                RTSPWDialog aDialog(nullptr, sPrinterName, "");
bf2fec
+                aDialog.SetDomainVisible(bDomain);
bf2fec
+                aDialog.SetUserVisible(bUser);
bf2fec
+                aDialog.SetPassVisible(bPass);
bf2fec
+
bf2fec
+                if (aDialog.Execute() == RET_OK)
bf2fec
+                {
bf2fec
+                    OString sAuth;
bf2fec
+                    if (bDomain)
bf2fec
+                        sAuth = aDialog.getDomain().replaceAll(",", "\\,");
bf2fec
+                    if (bUser)
bf2fec
+                    {
bf2fec
+                        if (!sAuth.isEmpty())
bf2fec
+                            sAuth += ",";
bf2fec
+                        sAuth += aDialog.getUserName().replaceAll(",", "\\,");
bf2fec
+                    }
bf2fec
+                    if (bPass)
bf2fec
+                    {
bf2fec
+                        if (!sAuth.isEmpty())
bf2fec
+                            sAuth += ",";
bf2fec
+                        sAuth += aDialog.getPassword().replaceAll(",", "\\,");
bf2fec
+                    }
bf2fec
+                    nNumOptions = cupsAddOption("auth-info", sAuth.getStr(), nNumOptions, &pOptions);
bf2fec
+                }
bf2fec
+            }
bf2fec
+        }
bf2fec
 
bf2fec
         OString sJobName(OUStringToOString(rJobTitle, aEnc));
bf2fec
 
bf2fec
@@ -825,75 +975,6 @@ bool CUPSManager::writePrinterConfig()
bf2fec
     return PrinterInfoManager::writePrinterConfig();
bf2fec
 }
bf2fec
 
bf2fec
-namespace
bf2fec
-{
bf2fec
-    class RTSPWDialog : public ModalDialog
bf2fec
-    {
bf2fec
-        VclPtr<FixedText> m_pText;
bf2fec
-        VclPtr<Edit>      m_pUserEdit;
bf2fec
-        VclPtr<Edit>      m_pPassEdit;
bf2fec
-
bf2fec
-    public:
bf2fec
-        RTSPWDialog(const OString& rServer, const OString& rUserName, vcl::Window* pParent);
bf2fec
-        virtual ~RTSPWDialog() override;
bf2fec
-        virtual void dispose() override;
bf2fec
-        OString getUserName() const;
bf2fec
-        OString getPassword() const;
bf2fec
-    };
bf2fec
-
bf2fec
-    RTSPWDialog::RTSPWDialog( const OString& rServer, const OString& rUserName, vcl::Window* pParent )
bf2fec
-        : ModalDialog(pParent, "CUPSPasswordDialog",
bf2fec
-            "vcl/ui/cupspassworddialog.ui")
bf2fec
-    {
bf2fec
-        get(m_pText, "text");
bf2fec
-        get(m_pUserEdit, "user");
bf2fec
-        get(m_pPassEdit, "pass");
bf2fec
-
bf2fec
-        OUString aText(m_pText->GetText());
bf2fec
-        aText = aText.replaceFirst("%s", OStringToOUString(rServer, osl_getThreadTextEncoding()));
bf2fec
-        m_pText->SetText(aText);
bf2fec
-        m_pUserEdit->SetText( OStringToOUString(rUserName, osl_getThreadTextEncoding()));
bf2fec
-    }
bf2fec
-
bf2fec
-    RTSPWDialog::~RTSPWDialog()
bf2fec
-    {
bf2fec
-        disposeOnce();
bf2fec
-    }
bf2fec
-
bf2fec
-    void RTSPWDialog::dispose()
bf2fec
-    {
bf2fec
-        m_pText.clear();
bf2fec
-        m_pUserEdit.clear();
bf2fec
-        m_pPassEdit.clear();
bf2fec
-        ModalDialog::dispose();
bf2fec
-    }
bf2fec
-
bf2fec
-    OString RTSPWDialog::getUserName() const
bf2fec
-    {
bf2fec
-        return OUStringToOString( m_pUserEdit->GetText(), osl_getThreadTextEncoding() );
bf2fec
-    }
bf2fec
-
bf2fec
-    OString RTSPWDialog::getPassword() const
bf2fec
-    {
bf2fec
-        return OUStringToOString( m_pPassEdit->GetText(), osl_getThreadTextEncoding() );
bf2fec
-    }
bf2fec
-
bf2fec
-    bool AuthenticateQuery(const OString& rServer, OString& rUserName, OString& rPassword)
bf2fec
-    {
bf2fec
-        bool bRet = false;
bf2fec
-
bf2fec
-        ScopedVclPtrInstance<RTSPWDialog> aDialog(rServer, rUserName, nullptr);
bf2fec
-        if (aDialog->Execute())
bf2fec
-        {
bf2fec
-            rUserName = aDialog->getUserName();
bf2fec
-            rPassword = aDialog->getPassword();
bf2fec
-            bRet = true;
bf2fec
-        }
bf2fec
-
bf2fec
-        return bRet;
bf2fec
-    }
bf2fec
-}
bf2fec
-
bf2fec
 const char* CUPSManager::authenticateUser()
bf2fec
 {
bf2fec
     const char* pRet = nullptr;
bf2fec
-- 
bf2fec
2.21.0
bf2fec