1 USING: alien alien.c-types alien.data alien.syntax arrays continuations
2 destructors generic io.mmap io.ports io.backend.windows io.files.windows
3 kernel libc locals math math.bitwise namespaces quotations sequences windows
4 windows.advapi32 windows.kernel32 windows.types io.backend system accessors
5 io.backend.windows.privileges classes.struct windows.errors ;
6 IN: io.backend.windows.nt.privileges
8 TYPEDEF: TOKEN_PRIVILEGES* PTOKEN_PRIVILEGES
11 ! http://msdn.microsoft.com/msdnmag/issues/05/03/TokenPrivileges/
13 : (open-process-token) ( handle -- handle )
14 { TOKEN_ADJUST_PRIVILEGES TOKEN_QUERY } flags PHANDLE <c-object>
15 [ OpenProcessToken win32-error=0/f ] keep *void* ;
17 : open-process-token ( -- handle )
18 #! remember to CloseHandle
19 GetCurrentProcess (open-process-token) ;
21 : with-process-token ( quot -- )
22 #! quot: ( token-handle -- token-handle )
23 [ open-process-token ] dip
25 [ CloseHandle drop ] [ ] cleanup ; inline
27 : lookup-privilege ( string -- luid )
28 [ f ] dip LUID <struct>
29 [ LookupPrivilegeValue win32-error=0/f ] keep ;
31 :: make-token-privileges ( name enabled? -- obj )
32 TOKEN_PRIVILEGES <struct>
34 LUID_AND_ATTRIBUTES malloc-struct &free
35 enabled? [ SE_PRIVILEGE_ENABLED >>Attributes ] when
36 name lookup-privilege >>Luid
39 M: winnt set-privilege ( name ? -- )
41 -rot 0 -rot make-token-privileges
42 dup byte-length f f AdjustTokenPrivileges win32-error=0/f
43 ] with-process-token ;