return out;
}
+static DWORD symlink_file_flags = 0, symlink_directory_flags = 1;
+
enum phantom_symlink_result {
PHANTOM_SYMLINK_RETRY,
PHANTOM_SYMLINK_DONE,
return PHANTOM_SYMLINK_DONE;
/* otherwise recreate the symlink with directory flag */
- if (DeleteFileW(wlink) && CreateSymbolicLinkW(wlink, wtarget, 1))
+ if (DeleteFileW(wlink) &&
+ CreateSymbolicLinkW(wlink, wtarget, symlink_directory_flags))
return PHANTOM_SYMLINK_DIRECTORY;
errno = err_win_to_posix(GetLastError());
wtarget[len] = '\\';
/* create file symlink */
- if (!CreateSymbolicLinkW(wlink, wtarget, 0)) {
+ if (!CreateSymbolicLinkW(wlink, wtarget, symlink_file_flags)) {
errno = err_win_to_posix(GetLastError());
return -1;
}
GENERIC_WRITE, FILE_FLAG_NO_BUFFERING);
}
+static void adjust_symlink_flags(void)
+{
+ /*
+ * Starting with Windows 10 Build 14972, symbolic links can be created
+ * using CreateSymbolicLink() without elevation by passing the flag
+ * SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE (0x02) as last
+ * parameter, provided the Developer Mode has been enabled. Some
+ * earlier Windows versions complain about this flag with an
+ * ERROR_INVALID_PARAMETER, hence we have to test the build number
+ * specifically.
+ */
+ if (GetVersion() >= 14972 << 16) {
+ symlink_file_flags |= 2;
+ symlink_directory_flags |= 2;
+ }
+
+}
+
#ifdef _MSC_VER
#ifdef _DEBUG
#include <crtdbg.h>
#endif
maybe_redirect_std_handles();
+ adjust_symlink_flags();
/* determine size of argv and environ conversion buffer */
maxlen = wcslen(wargv[0]);