ucb/source/ucp/webdav-curl/webdavcontent.cxx |   35 +++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 5 deletions(-)

New commits:
commit 014336e8d45fc192960b9240d362604577e78553
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Mon Nov 22 16:35:48 2021 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue Nov 23 12:06:27 2021 +0100

    ucb: webdav-curl: fix some issues caused by missing authentication
    
    * DAV_HTTP_NOAUTH wasn't actually handled anywhere; treat it the same as
      DAV_HTTP_AUTH for now
    * Content::getResourceType() would just determine that the server
      doesn't support DAV if there is any authentication missing
    * Content::getResourceOptions() would cache authentication error that is
      caused by executing the command without any XCommandEnvironment and
      therefore no XInteractionHandler
    
    Change-Id: Ie319a505da4b0f6bde01d6611262b8b1dad33d2f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125665
    Tested-by: Michael Stahl <michael.st...@allotropia.de>
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/ucb/source/ucp/webdav-curl/webdavcontent.cxx 
b/ucb/source/ucp/webdav-curl/webdavcontent.cxx
index 6d70ff77f8bc..eb19e0265659 100644
--- a/ucb/source/ucp/webdav-curl/webdavcontent.cxx
+++ b/ucb/source/ucp/webdav-curl/webdavcontent.cxx
@@ -3272,6 +3272,7 @@ void Content::lock(
                         false );
             }
             break;
+            case DAVException::DAV_HTTP_NOAUTH:
             case DAVException::DAV_HTTP_AUTH:
             {
                 SAL_WARN( "ucb.ucp.webdav", "lock(): DAVException 
Authentication error - URL: <"
@@ -3697,6 +3698,7 @@ bool Content::shouldAccessNetworkAfterException( const 
DAVException & e )
          ( e.getError() == DAVException::DAV_HTTP_TIMEOUT ) ||
          ( e.getError() == DAVException::DAV_HTTP_LOOKUP ) ||
          ( e.getError() == DAVException::DAV_HTTP_CONNECT ) ||
+         ( e.getError() == DAVException::DAV_HTTP_NOAUTH ) ||
          ( e.getError() == DAVException::DAV_HTTP_AUTH ) ||
          ( e.getError() == DAVException::DAV_HTTP_AUTHPROXY ) )
         return false;
@@ -3880,7 +3882,10 @@ Content::ResourceType Content::getResourceType(
             rResAccess->resetUri();
 
             // first check if the cached error can be mapped to 
DAVException::DAV_HTTP_TIMEOUT or mapped to DAVException::DAV_HTTP_CONNECT
-            if ( aDAVOptions.getHttpResponseStatusCode() == 
USC_CONNECTION_TIMED_OUT )
+            if (aDAVOptions.getHttpResponseStatusCode() == 
USC_CONNECTION_TIMED_OUT
+                // can't get any reliable info without auth => cancel request
+                || aDAVOptions.getHttpResponseStatusCode() == USC_AUTH_FAILED
+                || aDAVOptions.getHttpResponseStatusCode() == 
USC_AUTHPROXY_FAILED)
             {
                 // behave same as DAVException::DAV_HTTP_TIMEOUT or 
DAVException::DAV_HTTP_CONNECT was thrown
                 try
@@ -3889,7 +3894,22 @@ Content::ResourceType Content::getResourceType(
                     CurlUri   theUri( rResAccess->getURL() );
                     OUString  aHostName  = theUri.GetHost();
                     sal_Int32 nPort      = theUri.GetPort();
-                    throw DAVException( DAVException::DAV_HTTP_TIMEOUT,
+                    DAVException::ExceptionCode e{};
+                    switch (aDAVOptions.getHttpResponseStatusCode())
+                    {
+                        case USC_CONNECTION_TIMED_OUT:
+                            e = DAVException::DAV_HTTP_TIMEOUT;
+                            break;
+                        case USC_AUTH_FAILED:
+                            e = DAVException::DAV_HTTP_AUTH;
+                            break;
+                        case USC_AUTHPROXY_FAILED:
+                            e = DAVException::DAV_HTTP_AUTHPROXY;
+                            break;
+                        default:
+                            assert(false);
+                    }
+                    throw DAVException( e,
                                         ConnectionEndPointString(aHostName, 
nPort) );
                 }
                 catch ( DAVException& exp )
@@ -3907,7 +3927,8 @@ Content::ResourceType Content::getResourceType(
             {
                 //resource doesn't exist
                 if ( networkAccessAllowed != nullptr )
-                    *networkAccessAllowed = false;            }
+                    *networkAccessAllowed = false;
+            }
         }
     }
 
@@ -4054,6 +4075,7 @@ void Content::getResourceOptions(
                     }
                 }
                 break;
+                case DAVException::DAV_HTTP_NOAUTH:
                 case DAVException::DAV_HTTP_AUTH:
                 {
                     SAL_WARN( "ucb.ucp.webdav", "OPTIONS - DAVException: 
DAV_HTTP_AUTH for URL <" << m_xIdentifier->getContentIdentifier() << ">" );
@@ -4064,8 +4086,11 @@ void Content::getResourceOptions(
                     //   though possibly DAV enabled
                     aDAVOptions.setHttpResponseStatusCode( USC_AUTH_FAILED );
                     // used only internally, so the text doesn't really 
matter..
-                    aStaticDAVOptionsCache.addDAVOptions( aDAVOptions,
-                                                          
m_nOptsCacheLifeNotFound );
+                    if (xEnv && xEnv->getInteractionHandler())
+                    {   // only cache if there actually was a chance to 
request auth
+                        aStaticDAVOptionsCache.addDAVOptions( aDAVOptions,
+                                                              
m_nOptsCacheLifeNotFound );
+                    }
                     if ( networkAccessAllowed != nullptr )
                     {
                         *networkAccessAllowed = *networkAccessAllowed

Reply via email to