You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by fb...@apache.org on 2015/04/30 20:42:38 UTC

ambari git commit: AMBARI-10508 [WinTP2] Ambari common: Ensure the child processes can be run under domain accounts

Repository: ambari
Updated Branches:
  refs/heads/trunk 2be054d18 -> 3fda2bcca


AMBARI-10508 [WinTP2] Ambari common: Ensure the child processes can be run under domain accounts

Adjusted the LogonUser parameters to allow the use of domain accounts


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/3fda2bcc
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3fda2bcc
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3fda2bcc

Branch: refs/heads/trunk
Commit: 3fda2bcca040233b208be23f8c54c837f6e12551
Parents: 2be054d
Author: Florian Barca <fb...@hortonworks.com>
Authored: Thu Apr 30 11:42:28 2015 -0700
Committer: Florian Barca <fb...@hortonworks.com>
Committed: Thu Apr 30 11:42:28 2015 -0700

----------------------------------------------------------------------
 .../src/main/python/ambari_commons/os_windows.py | 19 ++++++++++---------
 .../core/providers/windows/system.py             |  5 ++++-
 2 files changed, 14 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3fda2bcc/ambari-common/src/main/python/ambari_commons/os_windows.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/os_windows.py b/ambari-common/src/main/python/ambari_commons/os_windows.py
index 38db310..3df44af 100644
--- a/ambari-common/src/main/python/ambari_commons/os_windows.py
+++ b/ambari-common/src/main/python/ambari_commons/os_windows.py
@@ -706,23 +706,24 @@ class UserHelper(object):
   ACTION_FAILED = -1
 
   def __init__(self, userName):
-    self.domainName, self.dcName, self.userName = UserHelper._parse_user_name(userName)
+    self.domainName, self.userName = UserHelper.parse_user_name(userName)
+    if self.domainName:
+      self.dcName = win32net.NetGetDCName(None, self.domainName)
+    else:
+      self.dcName = None
     self._policy = win32security.LsaOpenPolicy(self.dcName,
                                                win32security.POLICY_CREATE_ACCOUNT | win32security.POLICY_LOOKUP_NAMES)
 
   @staticmethod
-  def _parse_user_name(userName):
-    dcName = None
-    domainName = None
+  def parse_user_name(userName, defDomain=None):
+    domainName = defDomain
     domainSepIndex = userName.find('\\')
     if domainSepIndex != -1:
       domainName = userName[0:domainSepIndex]
       userName = userName[domainSepIndex + 1:]
-      if domainName == '.' or domainName == win32api.GetComputerName():
-        domainName = None
-      else:
-        dcName = win32net.NetGetDCName(None, domainName)
-    return (domainName, dcName, userName)
+      if not domainName or domainName == '.' or domainName == win32api.GetComputerName():
+        domainName = defDomain
+    return (domainName, userName)
 
   def create_user(self, password, comment="Ambari user"):
     user_info = {}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3fda2bcc/ambari-common/src/main/python/resource_management/core/providers/windows/system.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/core/providers/windows/system.py b/ambari-common/src/main/python/resource_management/core/providers/windows/system.py
index dac44ec..a410e9c 100644
--- a/ambari-common/src/main/python/resource_management/core/providers/windows/system.py
+++ b/ambari-common/src/main/python/resource_management/core/providers/windows/system.py
@@ -18,6 +18,7 @@ limitations under the License.
 Ambari Agent
 
 """
+from ambari_commons.os_windows import UserHelper
 
 from resource_management.core.providers import Provider
 from resource_management.core.logger import Logger
@@ -149,6 +150,8 @@ def _call_command(command, logoutput=False, cwd=None, env=None, wait_for_finish=
   # TODO implement timeout, wait_for_finish
   Logger.info("Executing %s" % (command))
   if user:
+    domain, username = UserHelper.parse_user_name(user, ".")
+
     proc_token = OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES)
 
     old_states = []
@@ -163,7 +166,7 @@ def _call_command(command, logoutput=False, cwd=None, env=None, wait_for_finish=
       AdjustPrivilege(proc_token, priv)
       QueryPrivilegeState(proc_token, priv)
 
-    user_token = LogonUser(user, ".", Script.get_password(user), win32con.LOGON32_LOGON_SERVICE,
+    user_token = LogonUser(username, domain, Script.get_password(user), win32con.LOGON32_LOGON_SERVICE,
                            win32con.LOGON32_PROVIDER_DEFAULT)
     env_token = DuplicateTokenEx(user_token, SecurityIdentification, TOKEN_QUERY, TokenPrimary)
     # getting updated environment for impersonated user and merge it with custom env