Skip to content

Commit 09796c7

Browse files
authored
Merge pull request #23723 from drodriguez/fix-network-service-handling
[windows] Fix handling of Network Service username.
2 parents 7c30bff + ed3c03a commit 09796c7

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)