From ef0cec938165fdf3531f92dc8f4c2930ff95fa5e Mon Sep 17 00:00:00 2001 From: Anshul Gangwar Date: Wed, 11 Jun 2014 11:04:35 +0530 Subject: [PATCH] CLOUDSTACK-6872: [hyperv] removed the redundant connectToRemote, DisconnectRemote methods which in turn fixes this bug. connectToRemote was used to connect to share, but once the share is domain joined we don't need this method as we already have required permissions (cherry picked from commit cef29948a708fbbae1261dbd8b6a13e4da19c703) --- .../HypervResourceController.cs | 15 --------- .../ServerResource/HypervResource/Utils.cs | 33 ------------------- .../HypervResource/WmiCallsV2.cs | 3 +- 3 files changed, 1 insertion(+), 50 deletions(-) diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs index b6f9a019445..1a46b501f97 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs @@ -236,7 +236,6 @@ namespace HypervResource { TemplateObjectTO dataStore = disk.templateObjectTO; NFSTO share = dataStore.nfsDataStoreTO; - Utils.ConnectToRemote(share.UncPath, share.Domain, share.User, share.Password); string diskPath = Utils.NormalizePath(Path.Combine(share.UncPath, dataStore.path)); wmiCallsV2.AttachIso(vmName, diskPath); result = true; @@ -244,11 +243,6 @@ namespace HypervResource else if (disk.type.Equals("DATADISK")) { VolumeObjectTO volume = disk.volumeObjectTO; - PrimaryDataStoreTO primary = volume.primaryDataStore; - if (!primary.isLocal) - { - Utils.ConnectToRemote(primary.UncPath, primary.Domain, primary.User, primary.Password); - } string diskPath = Utils.NormalizePath(volume.FullFileName); wmiCallsV2.AttachDisk(vmName, diskPath, disk.diskSequence); result = true; @@ -991,7 +985,6 @@ namespace HypervResource hostPath = Utils.NormalizePath(share.UncPath); // Check access to share. - Utils.ConnectToRemote(share.UncPath, share.Domain, share.User, share.Password); Utils.GetShareDetails(share.UncPath, out capacityBytes, out availableBytes); config.setPrimaryStorage((string)cmd.pool.uuid, hostPath); } @@ -1283,7 +1276,6 @@ namespace HypervResource { volumePath = @"\\" + primary.uri.Host + primary.uri.LocalPath + @"\" + volumeName; volumePath = Utils.NormalizePath(volumePath); - Utils.ConnectToRemote(primary.UncPath, primary.Domain, primary.User, primary.Password); } volume.path = volume.uuid; wmiCallsV2.CreateDynamicVirtualHardDisk(volumeSize, volumePath); @@ -1558,17 +1550,10 @@ namespace HypervResource if (destTemplateObjectTO.primaryDataStore != null) { destFile = destTemplateObjectTO.FullFileName; - if (!destTemplateObjectTO.primaryDataStore.isLocal) - { - PrimaryDataStoreTO primary = destTemplateObjectTO.primaryDataStore; - Utils.ConnectToRemote(primary.UncPath, primary.Domain, primary.User, primary.Password); - } } else if (destTemplateObjectTO.nfsDataStoreTO != null) { destFile = destTemplateObjectTO.FullFileName; - NFSTO store = destTemplateObjectTO.nfsDataStoreTO; - Utils.ConnectToRemote(store.UncPath, store.Domain, store.User, store.Password); } } diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/Utils.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/Utils.cs index d0d3d838288..07dd78b84b3 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/Utils.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/Utils.cs @@ -128,32 +128,6 @@ namespace HypervResource } } - public static void ConnectToRemote(string remoteUNC, string domain, string username, string password) - { - NETRESOURCE nr = new NETRESOURCE(); - nr.dwType = RESOURCETYPE_DISK; - nr.lpRemoteName = Utils.NormalizePath(remoteUNC); - if (domain != null) - { - username = domain + @"\" + username; - } - - int ret = WNetUseConnection(IntPtr.Zero, nr, password, username, 0, null, null, null); - if (ret != NO_ERROR) - { - throw new ArgumentException("net use of share " + remoteUNC + "failed with "+ getErrorForNumber(ret)); - } - } - - public static void DisconnectRemote(string remoteUNC) - { - int ret = WNetCancelConnection2(remoteUNC, CONNECT_UPDATE_PROFILE, false); - if (ret != NO_ERROR) - { - throw new ArgumentException("net disconnect of share " + remoteUNC + "failed with " + getErrorForNumber(ret)); - } - } - public static void GetShareDetails(string remoteUNC, out long capacity, out long available) { ulong freeBytesAvailable; @@ -228,13 +202,6 @@ namespace HypervResource [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)] public extern static bool DuplicateToken(IntPtr existingTokenHandle, int SECURITY_IMPERSONATION_LEVEL, ref IntPtr duplicateTokenHandle); - [DllImport("Mpr.dll")] - private static extern int WNetUseConnection(IntPtr hwndOwner, NETRESOURCE lpNetResource, string lpPassword, string lpUserID, int dwFlags, - string lpAccessName, string lpBufferSize, string lpResult); - - [DllImport("Mpr.dll")] - private static extern int WNetCancelConnection2(string lpName, int dwFlags, bool fForce); - [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] private static extern bool GetDiskFreeSpaceEx(string lpDirectoryName, out ulong lpFreeBytesAvailable, diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs index d8dd3bb0a2a..c1f6bcf7be5 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs @@ -1,4 +1,4 @@ -// Licensed to the Apache Software Foundation (ASF) under one +// Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file @@ -333,7 +333,6 @@ namespace HypervResource else if (templateInfo != null && templateInfo.nfsDataStoreTO != null) { NFSTO share = templateInfo.nfsDataStoreTO; - Utils.ConnectToRemote(share.UncPath, share.Domain, share.User, share.Password); // The share is mapped, now attach the iso isoPath = Utils.NormalizePath(Path.Combine(share.UncPath, templateInfo.path)); }