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