/// <summary> /// Use GetOriginatorProcessId to get the process ID (PID) of the process that originated the operation. /// Call this method only from the callback / event handlers. /// Do not call this method from handlers for OnReadFile, OnWriteFile and other callbacks that work with opened /// files, as that callbacks can be initiated by the system components (cache manager, memory manager etc.). /// Instead do the following: /// Call GetOriginatorProcessId from OnCreateFile or OnOpenFile event handlers / callbacks; /// Store obtained information somewhere and store the reference to this information in the UserContext; /// When you need to check the originator information in some file-related callback, access the stored information via UserContext /// </summary> /// <remarks> /// Note that the PID is guaranteed to be unique only during lifetime of the process. When the process is /// terminated, it's PID can (in theory) be used by other process. In fact this never happens, but such /// possibility is documented by Microsoft. /// </remarks> /// <returns></returns> protected int GetProcessId() { uint processId = 0; CbFs.GetOriginatorProcessId(ref processId); processId = ProcessIdentity.CheckForNTAuthority(processId); return((int)processId); }
public static void AclListenUrls(ProcessIdentity userContext, params string[] urlsToAcl) { string userName = SecurityHelper.UserIdToUserName(userContext); AclListenUrls(userName, urlsToAcl); }
public static string UserIdToUserName(ProcessIdentity userContext) { return standardUserNames[(int)userContext]; }