Caller permission with declarator permission

I read about delegates on MSDN and saw a line saying

" Note:  Delegates are run under caller permissions, not declarator permissions."

What does it mean?

+4
source share
1 answer

Assuming the question is about Windows permissions, not .Net Code Access Security (CAS).

Regardless of which account code was run when the delegate was created (for example, box admin), Windows permissions will be calculated at the time of the actual call, which may differ from the one that was created.

, , ( Windows) :

// run under "account1" - has access to c:\myFile.txt
// current Environment.UserName = "account2"
Func<string,string> readAllFile = fileName => File.ReadAllText(fileName);

// start impersonation of account2 - has access to c:\otherFile.txt, 
// but not c:\myFile.txt
ImpersonateAccount("account2", readAllFile);
....

...ImpersonateAccout(string name, Func<string,string> readAllFile)
{
  // .... impersonation code omitted
  // current Environment.UserName = "account2"
  var text1 = readAllFile(@"c:\otherFile.txt"); // success
  var text2 = readAllFile(@"c:\myFile.txt"); // failure
  ....

readAllFile, account1, "" , c:\myFile.txt, "account2" .

, "" #, , , , . Windows, .Net(, ).

+2

All Articles