ac7d03
From 65579492d3d545d6acabaedc019c457551c32063 Mon Sep 17 00:00:00 2001
ac7d03
From: Alexander Bokovoy <abokovoy@redhat.com>
ac7d03
Date: Mon, 3 Apr 2017 10:29:21 +0300
ac7d03
Subject: [PATCH] ipaserver/dcerpc: unify error processing
ac7d03
ac7d03
Samba error code reporting changes from version to version but we also
ac7d03
did not provide proper input into DCE RPC error processing method we
ac7d03
have.
ac7d03
ac7d03
Unify error processing and add few more fallback entries.
ac7d03
ac7d03
With Samba 4.7 we'll have to change it again because error code
ac7d03
processing for Samba Python modules will change with introduction of
ac7d03
samba.ntstatus and samba.werror modules.
ac7d03
ac7d03
Note that this commit also changes a message returned for error code
ac7d03
-1073741772 (NT_STATUS_OBJECT_NOT_FOUND) because it is more general one.
ac7d03
ac7d03
Fixes https://pagure.io/freeipa/issue/6859
ac7d03
ac7d03
Reviewed-By: Martin Basti <mbasti@redhat.com>
ac7d03
---
ac7d03
 ipaserver/dcerpc.py | 23 +++++++++++++++++------
ac7d03
 1 file changed, 17 insertions(+), 6 deletions(-)
ac7d03
ac7d03
diff --git a/ipaserver/dcerpc.py b/ipaserver/dcerpc.py
ac7d03
index 2d9d7e5577f1cac6f35701dd277199f9a37387f8..d684a17cabe43bbbd43d29f75f534b6e50fccd12 100644
ac7d03
--- a/ipaserver/dcerpc.py
ac7d03
+++ b/ipaserver/dcerpc.py
ac7d03
@@ -117,19 +117,27 @@ dcerpc_error_codes = {
ac7d03
                   # we simply will skip the binding
ac7d03
         access_denied_error,
ac7d03
     -1073741772:  # NT_STATUS_OBJECT_NAME_NOT_FOUND
ac7d03
-        errors.RemoteRetrieveError(
ac7d03
-            reason=_('CIFS server configuration does not allow '
ac7d03
-                     'access to \\\\pipe\\lsarpc')),
ac7d03
+        errors.NotFound(
ac7d03
+            reason=_('Cannot find specified domain or server name')),
ac7d03
 }
ac7d03
 
ac7d03
 dcerpc_error_messages = {
ac7d03
     "NT_STATUS_OBJECT_NAME_NOT_FOUND":
ac7d03
         errors.NotFound(
ac7d03
             reason=_('Cannot find specified domain or server name')),
ac7d03
+    "The object name is not found.":
ac7d03
+        errors.NotFound(
ac7d03
+            reason=_('Cannot find specified domain or server name')),
ac7d03
     "WERR_NO_LOGON_SERVERS":
ac7d03
         errors.RemoteRetrieveError(
ac7d03
             reason=_('AD DC was unable to reach any IPA domain controller. '
ac7d03
                      'Most likely it is a DNS or firewall issue')),
ac7d03
+    # This is a very long key, don't change it
ac7d03
+    "There are currently no logon servers available to "
ac7d03
+    "service the logon request.":
ac7d03
+        errors.RemoteRetrieveError(
ac7d03
+            reason=_('AD DC was unable to reach any IPA domain controller. '
ac7d03
+                     'Most likely it is a DNS or firewall issue')),
ac7d03
     "NT_STATUS_INVALID_PARAMETER_MIX":
ac7d03
         errors.RequirementError(
ac7d03
             name=_('At least the domain or IP address should be specified')),
ac7d03
@@ -802,7 +810,8 @@ class DomainValidator(object):
ac7d03
 
ac7d03
         # Both methods should not fail at the same time
ac7d03
         if finddc_error and len(info['gc']) == 0:
ac7d03
-            raise assess_dcerpc_exception(message=str(finddc_error))
ac7d03
+            num, message = e.args  # pylint: disable=unpacking-non-sequence
ac7d03
+            raise assess_dcerpc_exception(num=num, message=message)
ac7d03
 
ac7d03
         self._info[domain] = info
ac7d03
         return info
ac7d03
@@ -908,7 +917,8 @@ class TrustDomainInstance(object):
ac7d03
             else:
ac7d03
                 result = netrc.finddc(address=remote_host, flags=flags)
ac7d03
         except RuntimeError as e:
ac7d03
-            raise assess_dcerpc_exception(message=str(e))
ac7d03
+            num, message = e.args  # pylint: disable=unpacking-non-sequence
ac7d03
+            raise assess_dcerpc_exception(num=num, message=message)
ac7d03
 
ac7d03
         if not result:
ac7d03
             return False
ac7d03
@@ -1408,7 +1418,8 @@ def fetch_domains(api, mydomain, trustdomain, creds=None, server=None):
ac7d03
             result = netrc.finddc(domain=trustdomain,
ac7d03
                                   flags=nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS)
ac7d03
     except RuntimeError as e:
ac7d03
-        raise assess_dcerpc_exception(message=str(e))
ac7d03
+        num, message = e.args  # pylint: disable=unpacking-non-sequence
ac7d03
+        raise assess_dcerpc_exception(num=num, message=message)
ac7d03
 
ac7d03
     td.info['dc'] = unicode(result.pdc_dns_name)
ac7d03
     td.info['name'] = unicode(result.dns_domain)
ac7d03
-- 
ac7d03
2.9.3
ac7d03