From faa3ca9bf8383d72d1e61e70d174e1da21a6708c Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Tue, 6 Dec 2016 08:36:19 +0100 Subject: [PATCH] In Windows 10 allow creation of symlinks by unpriviliged user It's a new feature of Windows 10 build 14972 --- cmdline/mingw.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmdline/mingw.c b/cmdline/mingw.c index a625d8a0..781d6e39 100644 --- a/cmdline/mingw.c +++ b/cmdline/mingw.c @@ -1457,16 +1457,28 @@ int windows_link(const char* existing, const char* file) return 0; } +/** + * In Windows 10 allow creationg of symblink by not priviliged user. + * + * See: Symlinks in Windows 10! + * https://blogs.windows.com/buildingapps/2016/12/02/symlinks-windows-10/#cQG7cx48oGH86lkI.97 + * "Specify this flag to allow creation of symbolic links when the process is not elevated" + */ +#ifndef SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE +#define SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE 0x2 +#endif + int windows_symlink(const char* existing, const char* file) { wchar_t conv_buf_file[CONV_MAX]; wchar_t conv_buf_existing[CONV_MAX]; + DWORD flags = SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE; /* We must convert to the extended-length \\?\ format if the path is too long */ /* otherwise the link creation fails. */ /* But we don't want to always convert it, to avoid to recreate */ /* user symlinks different than they were before */ - if (!CreateSymbolicLinkW(convert(conv_buf_file, file), convert_if_required(conv_buf_existing, existing), 0)) { + if (!CreateSymbolicLinkW(convert(conv_buf_file, file), convert_if_required(conv_buf_existing, existing), flags)) { windows_errno(GetLastError()); return -1; }