Skip to content

Commit cef2994

Browse files
anshulgangwardevdeep
authored andcommitted
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
1 parent 2e49ef7 commit cef2994

3 files changed

Lines changed: 1 addition & 50 deletions

File tree

‎plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -236,19 +236,13 @@ public JContainer AttachCommand([FromBody]dynamic cmd)
236236
{
237237
TemplateObjectTO dataStore = disk.templateObjectTO;
238238
NFSTO share = dataStore.nfsDataStoreTO;
239-
Utils.ConnectToRemote(share.UncPath, share.Domain, share.User, share.Password);
240239
string diskPath = Utils.NormalizePath(Path.Combine(share.UncPath, dataStore.path));
241240
wmiCallsV2.AttachIso(vmName, diskPath);
242241
result = true;
243242
}
244243
else if (disk.type.Equals("DATADISK"))
245244
{
246245
VolumeObjectTO volume = disk.volumeObjectTO;
247-
PrimaryDataStoreTO primary = volume.primaryDataStore;
248-
if (!primary.isLocal)
249-
{
250-
Utils.ConnectToRemote(primary.UncPath, primary.Domain, primary.User, primary.Password);
251-
}
252246
string diskPath = Utils.NormalizePath(volume.FullFileName);
253247
wmiCallsV2.AttachDisk(vmName, diskPath, disk.diskSequence);
254248
result = true;
@@ -989,7 +983,6 @@ public JContainer ModifyStoragePoolCommand([FromBody]dynamic cmd)
989983
hostPath = Utils.NormalizePath(share.UncPath);
990984

991985
// Check access to share.
992-
Utils.ConnectToRemote(share.UncPath, share.Domain, share.User, share.Password);
993986
Utils.GetShareDetails(share.UncPath, out capacityBytes, out availableBytes);
994987
config.setPrimaryStorage((string)cmd.pool.uuid, hostPath);
995988
}
@@ -1281,7 +1274,6 @@ public JContainer CreateObjectCommand([FromBody]dynamic cmd)
12811274
{
12821275
volumePath = @"\\" + primary.uri.Host + primary.uri.LocalPath + @"\" + volumeName;
12831276
volumePath = Utils.NormalizePath(volumePath);
1284-
Utils.ConnectToRemote(primary.UncPath, primary.Domain, primary.User, primary.Password);
12851277
}
12861278
volume.path = volume.uuid;
12871279
wmiCallsV2.CreateDynamicVirtualHardDisk(volumeSize, volumePath);
@@ -1554,17 +1546,10 @@ public JContainer CopyCommand(dynamic cmd)
15541546
if (destTemplateObjectTO.primaryDataStore != null)
15551547
{
15561548
destFile = destTemplateObjectTO.FullFileName;
1557-
if (!destTemplateObjectTO.primaryDataStore.isLocal)
1558-
{
1559-
PrimaryDataStoreTO primary = destTemplateObjectTO.primaryDataStore;
1560-
Utils.ConnectToRemote(primary.UncPath, primary.Domain, primary.User, primary.Password);
1561-
}
15621549
}
15631550
else if (destTemplateObjectTO.nfsDataStoreTO != null)
15641551
{
15651552
destFile = destTemplateObjectTO.FullFileName;
1566-
NFSTO store = destTemplateObjectTO.nfsDataStoreTO;
1567-
Utils.ConnectToRemote(store.UncPath, store.Domain, store.User, store.Password);
15681553
}
15691554
}
15701555

‎plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/Utils.cs‎

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -128,32 +128,6 @@ public static void DownloadCifsFileToLocalFile(string filePathRelativeToShare, N
128128
}
129129
}
130130

131-
public static void ConnectToRemote(string remoteUNC, string domain, string username, string password)
132-
{
133-
NETRESOURCE nr = new NETRESOURCE();
134-
nr.dwType = RESOURCETYPE_DISK;
135-
nr.lpRemoteName = Utils.NormalizePath(remoteUNC);
136-
if (domain != null)
137-
{
138-
username = domain + @"\" + username;
139-
}
140-
141-
int ret = WNetUseConnection(IntPtr.Zero, nr, password, username, 0, null, null, null);
142-
if (ret != NO_ERROR)
143-
{
144-
throw new ArgumentException("net use of share " + remoteUNC + "failed with "+ getErrorForNumber(ret));
145-
}
146-
}
147-
148-
public static void DisconnectRemote(string remoteUNC)
149-
{
150-
int ret = WNetCancelConnection2(remoteUNC, CONNECT_UPDATE_PROFILE, false);
151-
if (ret != NO_ERROR)
152-
{
153-
throw new ArgumentException("net disconnect of share " + remoteUNC + "failed with " + getErrorForNumber(ret));
154-
}
155-
}
156-
157131
public static void GetShareDetails(string remoteUNC, out long capacity, out long available)
158132
{
159133
ulong freeBytesAvailable;
@@ -228,13 +202,6 @@ public static void ExecuteTask(string command, string args)
228202
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
229203
public extern static bool DuplicateToken(IntPtr existingTokenHandle, int SECURITY_IMPERSONATION_LEVEL, ref IntPtr duplicateTokenHandle);
230204

231-
[DllImport("Mpr.dll")]
232-
private static extern int WNetUseConnection(IntPtr hwndOwner, NETRESOURCE lpNetResource, string lpPassword, string lpUserID, int dwFlags,
233-
string lpAccessName, string lpBufferSize, string lpResult);
234-
235-
[DllImport("Mpr.dll")]
236-
private static extern int WNetCancelConnection2(string lpName, int dwFlags, bool fForce);
237-
238205
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
239206
private static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
240207
out ulong lpFreeBytesAvailable,

‎plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the Apache Software Foundation (ASF) under one
1+
// Licensed to the Apache Software Foundation (ASF) under one
22
// or more contributor license agreements. See the NOTICE file
33
// distributed with this work for additional information
44
// regarding copyright ownership. The ASF licenses this file
@@ -333,7 +333,6 @@ public ComputerSystem DeployVirtualMachine(dynamic jsonObj, string systemVmIso)
333333
else if (templateInfo != null && templateInfo.nfsDataStoreTO != null)
334334
{
335335
NFSTO share = templateInfo.nfsDataStoreTO;
336-
Utils.ConnectToRemote(share.UncPath, share.Domain, share.User, share.Password);
337336
// The share is mapped, now attach the iso
338337
isoPath = Utils.NormalizePath(Path.Combine(share.UncPath, templateInfo.path));
339338
}

0 commit comments

Comments
 (0)