Skip to content

Commit ed3c03a

Browse files
committed
[windows] Fix handling of Network Service username.
In Windows Server 2016 at least, the Network Service user (the one being used by the CI machine) is returned as Host$, which icacls doesn't understand. Turn the name into something that icacls if we get a name that ends with a dollar.
1 parent da45361 commit ed3c03a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

test/ParseableInterface/Inputs/make-unreadable.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@
2121
buffer = ctypes.create_unicode_buffer(UNLEN + 1)
2222
size = ctypes.c_uint(len(buffer))
2323
GetUserNameW(buffer, ctypes.byref(size))
24+
# For NetworkService, Host$ is returned, so we choose have to turn it back
25+
# into something that icacls understands.
26+
if not buffer.value.endswith('$'):
27+
user_name = buffer.value
28+
else:
29+
user_name = 'NT AUTHORITY\\NetworkService'
2430

2531
for path in sys.argv[1:]:
2632
subprocess.call(['icacls', path, '/deny',
27-
'{}:(R)'.format(buffer.value)])
33+
'{}:(R)'.format(user_name)])
2834
else:
2935
for path in sys.argv[1:]:
3036
subprocess.call(['chmod', 'a-r', path])

0 commit comments

Comments
 (0)