From: Kien Nguyen Date: Wed, 24 Aug 2022 14:19:35 +0000 (+0900) Subject: Allow symlink creation on MS-Windows without Administrator privileges X-Git-Tag: emacs-29.0.90~1893^2~44 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=34e0a232cd0e7b38a33bc9134134c47665aeb185;p=emacs.git Allow symlink creation on MS-Windows without Administrator privileges * src/w32.c (symlink): Use the SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE flag when available. (Bug#57386) --- diff --git a/src/w32.c b/src/w32.c index cbcfcdd4f6d..44c279602cf 100644 --- a/src/w32.c +++ b/src/w32.c @@ -5992,12 +5992,22 @@ sys_umask (int mode) #ifndef SYMBOLIC_LINK_FLAG_DIRECTORY #define SYMBOLIC_LINK_FLAG_DIRECTORY 0x1 #endif +#ifndef SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE +#define SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE 0x2 +#endif int symlink (char const *filename, char const *linkname) { char linkfn[MAX_UTF8_PATH], *tgtfn; - DWORD flags = 0; + /* The SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE flag is + supported from Windows 10 build 14972. It is only supported if + Developer Mode is enabled, and is ignored if it isn't. */ + DWORD flags = + (os_subtype == OS_SUBTYPE_NT + && (w32_major_version > 10 + || (w32_major_version == 10 && w32_build_number >= 14972))) + ? SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE : 0; int dir_access, filename_ends_in_slash; /* Diagnostics follows Posix as much as possible. */ @@ -6055,7 +6065,7 @@ symlink (char const *filename, char const *linkname) directory. */ filename_ends_in_slash = IS_DIRECTORY_SEP (filename[strlen (filename) - 1]); if (dir_access == 0 || filename_ends_in_slash) - flags = SYMBOLIC_LINK_FLAG_DIRECTORY; + flags |= SYMBOLIC_LINK_FLAG_DIRECTORY; tgtfn = (char *)map_w32_filename (filename, NULL); if (filename_ends_in_slash)