ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
199 stars 153 forks source link

Use correct P/Invoke signature in WNetAddConnection2. #578

Closed svnscha closed 2 weeks ago

svnscha commented 3 weeks ago
SUMMARY

This commit implements the correct reference-based signature for WNetAddConnection2. On 32-bit systems, the previous implementation led to a significant issue when mapping network drives, causing memory layout corruption and resulting in the function failing with error 487. This commit resolves that issue and corrects the behavior.

ISSUE TYPE
COMPONENT NAME

It's about win_mapped_drive that fails on any 32 bit platform because of using the wrong method signature. Check P/Invoke for reference.

ADDITIONAL INFORMATION

Example log output of failure:

Exception calling "Invoke" with "2" argument(s): "Failed to map Z: to '\\TESTBOX1\Share' with WNetAddConnection2W() (Attempt to access invalid address, Win32ErrorCode 487)"
At line:422 char:17
+ ...             $add_method.Invoke($null, [Object[]]@($letter_root, $path ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : Win32Exception

ScriptStackTrace:
at <ScriptBlock>, <No file>: line 422
fatal: [TW10B-903-1]: FAILED! => {
    "changed": false,
    "msg": "Unhandled exception while executing module: Exception calling \"Invoke\" with \"2\" argument(s): \"Failed to map Z: to '\\\\TESTBOX1\\Share' with WNetAddConnection2W() (Attempt to access invalid address, Win32ErrorCode 487)\""
}
verbatim: n/a
svnscha commented 3 weeks ago

Yes, will do.

svnscha commented 2 weeks ago

@jborean93 added :-)

jborean93 commented 2 weeks ago

Thanks for working on this and fixing it!