Click here to Skip to main content
15,919,422 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Catching file system updates? Pin
Beer2630-Jul-03 12:37
Beer2630-Jul-03 12:37 
GeneralRe: Catching file system updates? Pin
kaladorn30-Jul-03 13:46
kaladorn30-Jul-03 13:46 
GeneralRe: Catching file system updates? Pin
Beer2630-Jul-03 14:11
Beer2630-Jul-03 14:11 
GeneralRe: Catching file system updates? Pin
kaladorn30-Jul-03 14:15
kaladorn30-Jul-03 14:15 
GeneralRe: Catching file system updates? Pin
Beer2630-Jul-03 14:16
Beer2630-Jul-03 14:16 
GeneralRe: Catching file system updates? Pin
Beer2630-Jul-03 14:18
Beer2630-Jul-03 14:18 
GeneralAdjustTokenPrivileges Pin
Anonymous30-Jul-03 11:31
Anonymous30-Jul-03 11:31 
GeneralRe: AdjustTokenPrivileges Pin
Mike Dimmick30-Jul-03 23:38
Mike Dimmick30-Jul-03 23:38 
Security structures in the Windows API tend to be of the 'extensible array' type, where the last field is declared as an array of 1 element, but Windows will actually accept bigger arrays. You can consider the structure you declare as being a header for the full structure.

Let's say, for the sake of argument, that you want to disable the SE_TAKE_OWNERSHIP_NAME privilege (which permits the principal to change the owner of a resource, even if they don't have Write Owner access) and the SE_DEBUG_NAME privilege, which permits the principal to debug processes they don't own.

You would write something like the following:
DWORD dwPrivsSize = 
   sizeof( DWORD ) + 2 * sizeof( LUID_AND_ATTRIBUTES );
 
TOKEN_PRIVILEGES* pPrivsIn = 
   (TOKEN_PRIVILEGES*) malloc( dwPrivsSize );
 
// TODO: Check pPrivsIn for NULL
 
pPrivsIn->PrivilegeCount = 2;
 
// Look up the privilege LUIDs on the local system
 
LookupPrivilegeValue( 
   NULL, 
   SE_TAKE_OWNERSHIP_NAME, 
   &( pPrivsIn->Privileges[0].Luid )
);
 
LookupPrivilegeValue( 
   NULL, 
   SE_DEBUG_NAME, 
   &( pPrivsIn->Privileges[1].Luid )
);
 
// Set the attributes - 0 means disable
 
pPrivsIn->Privileges[0].Attributes = 0;
pPrivsIn->Privileges[1].Attributes = 0;
 
HANDLE hToken = NULL;
 
OpenThreadToken(
   GetCurrentThread(),
   TOKEN_ADJUST_PRIVILEGES,
   FALSE,
   &hToken
);
 
AdjustTokenPrivileges(
   hToken,
   FALSE,
   pPrivsIn,
   dwPrivsSize,
   NULL,
   NULL
);
 
CloseHandle( hToken );
 
free( (void*) pPrivsIn );
You should save the previous state of the privileges somewhere if you want to re-enable them later. You should also check the return values of all the functions called - this is especially critical in security code.

No warranties for the above code; I just typed it straight into CP's editor Big Grin | :-D

On Server 2003, you can specify SE_PRIVILEGE_REMOVED for the attributes to cause AdjustTokenPrivileges to remove the privileges from the token permanently - they cannot be re-enabled except by creating a new token.
Generalmy exe's small icon Pin
Marissa18230-Jul-03 11:02
Marissa18230-Jul-03 11:02 
GeneralRe: my exe's small icon Pin
Beer2630-Jul-03 11:49
Beer2630-Jul-03 11:49 
GeneralShut Down the pc Pin
Anonymous30-Jul-03 10:48
Anonymous30-Jul-03 10:48 
GeneralRe: Shut Down the pc Pin
User 665830-Jul-03 10:51
User 665830-Jul-03 10:51 
GeneralRe: Shut Down the pc Pin
Anonymous30-Jul-03 11:30
Anonymous30-Jul-03 11:30 
GeneralRe: Shut Down the pc Pin
John M. Drescher30-Jul-03 11:47
John M. Drescher30-Jul-03 11:47 
GeneralNon MDI /SDI Pin
act_x30-Jul-03 10:20
act_x30-Jul-03 10:20 
QuestionHow to make a function that you can pass any type of array to?? Pin
johnstonsk30-Jul-03 10:02
johnstonsk30-Jul-03 10:02 
AnswerRe: How to make a function that you can pass any type of array to?? Pin
Dean Goodman30-Jul-03 10:20
Dean Goodman30-Jul-03 10:20 
GeneralRe: How to make a function that you can pass any type of array to?? Pin
johnstonsk30-Jul-03 10:33
johnstonsk30-Jul-03 10:33 
GeneralRe: How to make a function that you can pass any type of array to?? Pin
Ian Darling30-Jul-03 11:19
Ian Darling30-Jul-03 11:19 
GeneralRe: How to make a function that you can pass any type of array to?? Pin
Dean Goodman30-Jul-03 11:42
Dean Goodman30-Jul-03 11:42 
AnswerRe: How to make a function that you can pass any type of array to?? Pin
Neville Franks30-Jul-03 10:33
Neville Franks30-Jul-03 10:33 
AnswerRe: How to make a function that you can pass any type of array to?? Pin
Ian Darling30-Jul-03 11:12
Ian Darling30-Jul-03 11:12 
GeneralRe: How to make a function that you can pass any type of array to?? Pin
Jörgen Sigvardsson30-Jul-03 11:55
Jörgen Sigvardsson30-Jul-03 11:55 
GeneralRe: How to make a function that you can pass any type of array to?? Pin
Ian Darling30-Jul-03 12:58
Ian Darling30-Jul-03 12:58 
AnswerRe: How to make a function that you can pass any type of array to?? Pin
John M. Drescher30-Jul-03 11:53
John M. Drescher30-Jul-03 11:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.