Пример #1
0
 // Opens virtual key not for regular operation, but just
 // when RegOpen*/RegCreate* is called, so access checking is not so strict
 // as for operation
 // TODO: don't check security access mode on open,
 // make just a reg function call check it
 internal VirtualKey OpenKeyPreliminarily(KeyIdentity existingBase, KeyIdentity identity, KeySecurity samDesired)
 {
     foreach (KeyDisposition disposition in VirtualKey.HIVES_ORDER)
     {
         try
         {
             VirtualKey key;
             if (TryOpenKey(existingBase, disposition, identity, samDesired, out key))
             {
                 return(key);
             }
             // Key not found
             if (!samDesired.IsOnlyForRead())
             {
                 // Key not present in reghive and write access requested
                 // we can't give it in hives other than DIFF_HIVE
                 throw new FileNotFoundException();
             }
         }
         catch (AccessDeniedException)
         {
             if (!identity.IsSystemKey() || disposition == KeyDisposition.WINDOWS_REG)
             {
                 // Access denied in reghive (may happen if key is system key)
                 // but if not a system key
                 throw;
             }
         }
         if (identity.IsSystemKey() && !samDesired.IsOnlyForRead())
         {
             // Relaxing access (some apps request write access and do not use it
             // we want to make them work
             samDesired.RelaxToReadAccess();
         }
     }
     throw new FileNotFoundException();
 }
Пример #2
0
 private static bool CheckSystemKeyAccess(KeyDisposition disposition,
                                          KeyIdentity identity, KeySecurity samDesired)
 {
     // This way we redirect system registry locations into windows registry
     // and make it fail for write operations
     if (disposition != KeyDisposition.WINDOWS_REG &&
         identity.IsSystemKey())
     {
         if (samDesired.IsOnlyForRead())
         {
             // So that it retries to read from system registry
             return(false);
         }
         // So that user gets appropriate error code
         throw new AccessDeniedException();
     }
     return(true);
 }
Пример #3
0
 internal bool IsMarkedAsDeleted(KeyIdentity existingBase, KeyIdentity identity)
 {
     if (identity.IsSystemKey())
     {
         return(false);
     }
     try
     {
         return(DoesntExistOrMarkedAsDeleted(existingBase, identity,
                                             IMAD_pData_.Ptr, IMAD_pcbData_.Ptr) == DoesntExistOrMarkedAsDeletedState.MarkedAsDeleted);
     }
     catch (FileNotFoundException)
     {
         // We don't know anything about the key, so it was not marked as deleted
         return(false);
     }
     catch (Win32Exception ex)
     {
         DebugLogger.WriteLine("IsDeleted exception " + ex.ToString());
         throw;
     }
 }