private static void EnsureDirectoryPermissions(string path, uint userId)
{
Interop.Sys.FileStatus dirStat;
if (Interop.Sys.Stat(path, out dirStat) != 0)
{
Interop.ErrorInfo error = Interop.Sys.GetLastErrorInfo();
throw new CryptographicException(
SR.Cryptography_FileStatusError,
new IOException(error.GetErrorMessage(), error.RawErrno));
}
if (dirStat.Uid != userId)
{
throw new CryptographicException(SR.Format(SR.Cryptography_OwnerNotCurrentUser, path));
}
if ((dirStat.Mode & (int)Interop.Sys.Permissions.S_IRWXU) != (int)Interop.Sys.Permissions.S_IRWXU)
{
throw new CryptographicException(SR.Format(SR.Cryptography_InvalidDirectoryPermissions, path));
}
}