public override NativeResultCode CloseKey(RegistryRequest request)
 {
   // In the transparent registry keys are closed in one of the following two ways:
   // - If hKey is an alias, the alias is removed.
   // - If hKey is not an alias, hKey is removed from the internal dictionary by base.DeleteKey()
   //   BUT if hKey has aliases pointing to it, the removal needs to wait until all aliases are closed.
   uint realKey;
   if (IsAlias(request.Handle, out realKey))
   {
     RemoveAlias(request.Handle);
     lock (_keysPendingClosureSyncRoot)
       if (_keysPendingClosure.Contains(realKey)
           && !HasAliases(realKey))
       {
         base.DeleteKey(new RegistryRequest {Handle = realKey});
         _keysPendingClosure.Remove(realKey);
       }
     return NativeResultCode.Success;
   }
   if (!HasAliases(request.Handle))
     return base.DeleteKey(request);
   lock (_keysPendingClosureSyncRoot)
     if (!_keysPendingClosure.Contains(request.Handle))
       _keysPendingClosure.Add(request.Handle);
   return NativeResultCode.Success;
 }
Exemplo n.º 2
0
        public static byte[] processModificationRequest(Command command)
        {
            RegistryRequest request    = (RegistryRequest)Util.Serialization.deserialize(command.data);
            bool            success    = false;
            String          errMessage = null;

            if (RegistryIndex.data.ContainsKey((RegistryHive)request.hive))
            {
                RegistryKeyData entry = Util.Metadata.Find(RegistryIndex.data[(RegistryHive)request.hive], request.data);
                if (entry != null)
                {
                    try
                    {
                        entry.value.SetValue(request.newValue.name, request.newValue.value);
                        success = true;
                    }
                    catch (Exception e)
                    {
                        errMessage = e.Message;
                    }
                }
                else
                {
                    errMessage = "Error with internal storage of registry client-side";
                }
            }
            return(Util.Serialization.serialize(new RegistryResponse
            {
                error = (success) ? "Success!" : (errMessage == null) ? "Unknown error!" : errMessage,
                keyData = null
            }));
        }
Exemplo n.º 3
0
        public override NativeResultCode CloseKey(RegistryRequest request)
        {
            // In the transparent registry keys are closed in one of the following two ways:
            // - If hKey is an alias, the alias is removed.
            // - If hKey is not an alias, hKey is removed from the internal dictionary by base.DeleteKey()
            //   BUT if hKey has aliases pointing to it, the removal needs to wait until all aliases are closed.
            uint realKey;

            if (IsAlias(request.Handle, out realKey))
            {
                RemoveAlias(request.Handle);
                lock (_keysPendingClosureSyncRoot)
                    if (_keysPendingClosure.Contains(realKey) &&
                        !HasAliases(realKey))
                    {
                        base.DeleteKey(new RegistryRequest {
                            Handle = realKey
                        });
                        _keysPendingClosure.Remove(realKey);
                    }
                return(NativeResultCode.Success);
            }
            if (!HasAliases(request.Handle))
            {
                return(base.DeleteKey(request));
            }
            lock (_keysPendingClosureSyncRoot)
                if (!_keysPendingClosure.Contains(request.Handle))
                {
                    _keysPendingClosure.Add(request.Handle);
                }
            return(NativeResultCode.Success);
        }
 public override NativeResultCode CreateKey(RegistryRequest request, out RegCreationDisposition creationDisposition)
 {
   var virtualKeyPath = RegistryTranslator.ToVirtualPath(request.KeyFullPath);
   var virtReq = new RegistryRequest(request) {KeyFullPath = virtualKeyPath};
   var result = base.CreateKey(virtReq, out creationDisposition);
   request.Handle = virtReq.Handle;
   return result;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Closes the key handle specified in <paramref name="request"/>.
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public virtual NativeResultCode CloseKey(RegistryRequest request)
 {
     if (!IsKnownKey(request))
     {
         return(NativeResultCode.InvalidHandle);
     }
     // Aliases should always be freed. Removing items from _keys is implemented by DeleteKey()
     RemoveAlias(request.Handle);
     return(NativeResultCode.Success);
 }
Exemplo n.º 6
0
        public async Task <bool> RegistryExecutor()
        {
            var registryBody = new RegistryRequest
            {
                Key  = _options.ExecutorAppName,
                Host = _options.ExecutorUrl
            };

            return(await InnnerAdminHttpClient <string>(CreateRestRequest($"{_options.ApiUriSegments}/registry", registryBody), "注册执行器"));
        }
Exemplo n.º 7
0
        public override NativeResultCode CreateKey(RegistryRequest request, out RegCreationDisposition creationDisposition)
        {
            var virtualKeyPath = RegistryTranslator.ToVirtualPath(request.KeyFullPath);
            var virtReq        = new RegistryRequest(request)
            {
                KeyFullPath = virtualKeyPath
            };
            var result = base.CreateKey(virtReq, out creationDisposition);

            request.Handle = virtReq.Handle;
            return(result);
        }
Exemplo n.º 8
0
 public override NativeResultCode OpenKey(RegistryRequest request)
 {
     // Always create a new VirtualRegistryKey, no matter if if one already exists for keyName.
     // Why? There is no counter for the number of users of each handle.
     // => if one user closes the handle, other users won't be able to use it anymore.
     if (HostRegistry.KeyExists(request.KeyFullPath))
     {
         request.Handle = BufferKey(request.KeyFullPath);
         return(NativeResultCode.Success);
     }
     request.Handle = 0;
     return(NativeResultCode.FileNotFound);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Opens the key from the specified path.
        /// The open handle is set to <paramref name="request.Handle"/>.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public virtual NativeResultCode OpenKey(RegistryRequest request)
        {
            VirtualRegistryKey key;

            using (_keysSynchronizationLock.EnterDisposableReadLock())
                key = _keys.Values.FirstOrDefault(k => k.Path.ToLowerInvariant() == request.KeyFullPath.ToLowerInvariant());
            if (key == null)
            {
                return(NativeResultCode.FileNotFound);
            }
            request.Handle = key.Handle;
            return(NativeResultCode.Success);
        }
 public override NativeResultCode OpenKey(RegistryRequest request)
 {
   // Always create a new VirtualRegistryKey, no matter if if one already exists for keyName.
   // Why? There is no counter for the number of users of each handle.
   // => if one user closes the handle, other users won't be able to use it anymore.
   if (HostRegistry.KeyExists(request.KeyFullPath))
   {
     request.Handle = BufferKey(request.KeyFullPath);
     return NativeResultCode.Success;
   }
   request.Handle = 0;
   return NativeResultCode.FileNotFound;
 }
 public override NativeResultCode CreateKey(RegistryRequest request, out RegCreationDisposition creationDisposition)
 {
   // Create the key in the real registry.
   var registryKey = HostRegistry.CreateKey(request.KeyFullPath, out creationDisposition);
   if (registryKey != null)
   {
     registryKey.Close();
     request.Handle = BufferKey(request.KeyFullPath);
     return NativeResultCode.Success;
   }
   request.Handle = 0;
   return NativeResultCode.AccessDenied;
 }
Exemplo n.º 12
0
        public override NativeResultCode CreateKey(RegistryRequest request, out RegCreationDisposition creationDisposition)
        {
            // Create the key in the real registry.
            var registryKey = HostRegistry.CreateKey(request.KeyFullPath, out creationDisposition);

            if (registryKey != null)
            {
                registryKey.Close();
                request.Handle = BufferKey(request.KeyFullPath);
                return(NativeResultCode.Success);
            }
            request.Handle = 0;
            return(NativeResultCode.AccessDenied);
        }
Exemplo n.º 13
0
 /// <summary>
 /// Deletes the key associated with the handle specified in <paramref name="request"/>.
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public virtual NativeResultCode DeleteKey(RegistryRequest request)
 {
     using (_keysSynchronizationLock.EnterDisposableWriteLock())
     {
         request.Handle = EnsureHandleIsNoAlias(request.Handle);
         if (!_keys.ContainsKey(request.Handle))
         {
             return(NativeResultCode.InvalidHandle);
         }
         RemoveAliasesFor(request.Handle);
         _keys.Remove(request.Handle);
     }
     _indexGenerator.Release(request.Handle);
     return(NativeResultCode.Success);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Creates a key with the specified path.
 /// The open handle is set to <paramref name="request.Handle"/>.
 /// </summary>
 /// <param name="request"></param>
 /// <param name="creationDisposition">Whether the key is opened or created.</param>
 /// <returns></returns>
 public virtual NativeResultCode CreateKey(RegistryRequest request, out RegCreationDisposition creationDisposition)
 {
     if (OpenKey(request) == NativeResultCode.Success)
     {
         creationDisposition = RegCreationDisposition.OpenedExistingKey;
     }
     else
     {
         creationDisposition = RegCreationDisposition.CreatedNewKey;
         var regKey = ConstructRegistryKey(request.KeyFullPath);
         WriteKey(regKey);
         request.Handle = regKey.Handle;
     }
     return(NativeResultCode.Success);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Returns whether the database knows a key with the handle specified in <paramref name="request"/>.
 /// The full path of the key is set to <paramref name="request.KeyFullPath"/> if the key is known.
 /// </summary>
 /// <param name="request">The index to search a key for.</param>
 /// <returns></returns>
 public bool IsKnownKey(RegistryRequest request)
 {
     using (_keysSynchronizationLock.EnterDisposableReadLock())
     {
         if (_keyAliases.ContainsKey(request.Handle))
         {
             request.Handle = _keyAliases[request.Handle];
         }
         if (_keys.Keys.Contains(request.Handle))
         {
             request.KeyFullPath = _keys[request.Handle].Path;
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 16
0
 public override NativeResultCode OpenKey(RegistryRequest request)
 {
   var virtualKeyPath = RegistryTranslator.ToVirtualPath(request.KeyFullPath);
   var virtReq = new RegistryRequest(request) { KeyFullPath = virtualKeyPath };
   if (base.OpenKey(virtReq) == NativeResultCode.Success)
   {
     request.Handle = virtReq.Handle;
     return NativeResultCode.Success;
   }
   if (request.VirtualizationType == VirtualizationType.Virtual
       || !HostRegistry.KeyExists(request.KeyFullPath))
     return NativeResultCode.FileNotFound;
   var virtualRegistryKey = ConstructRegistryKey(virtualKeyPath);
   WriteKey(virtualRegistryKey, true);
   request.Handle = virtualRegistryKey.Handle;
   return NativeResultCode.Success;
 }
Exemplo n.º 17
0
        private RegistryRequest Build_Test01()
        {
            var request = new RegistryRequest
            {
                Id      = "urn:xdskit:com:c7ptmx37tfbcwy8ky7a",
                Comment = "This is a comment",
                Slots   = new List <Slot>
                {
                    new Slot
                    {
                        Name   = "creationTime",
                        Type   = "urn:xdskit:com:c7ptmx37tfbcwy8ky7b",
                        Values = new List <string> {
                            "2015-01-01"
                        }
                    },
                    new Slot
                    {
                        Name   = "languageCode",
                        Type   = "urn:xdskit:com:c7ptmx37tfbcwy8ky7c",
                        Values = new List <string> {
                            "en-US", "en-GB", "en-AU"
                        }
                    },
                    new Slot
                    {
                        Name   = "serviceStartTime",
                        Values = new List <string> {
                            "2015-01-01T09:00:00"
                        }
                    },
                    new Slot
                    {
                        Name   = "serviceStopTime",
                        Values = new List <string> {
                            "2015-01-01T21:00:00"
                        }
                    }
                }
            };

            return(request);
        }
Exemplo n.º 18
0
        public static byte[] getRegistrySubkeys(Command command)
        {
            RegistryRequest request = (RegistryRequest)Util.Serialization.deserialize(command.data);

            byte[] data;
            if (request.buildHive && request.hive != null)
            {
                RegistryIndex.index((RegistryHive)request.hive, RegistryView.Default);
                data = Util.Serialization.serialize(new RegistryResponse
                {
                    error        = String.Empty,
                    isDictionary = false,
                    keyData      = RegistryIndex.data[(RegistryHive)request.hive],
                    hive         = (RegistryHive)request.hive
                });
            }
            else if (request.hive == null)
            {
                data = Util.Serialization.serialize(new RegistryResponse
                {
                    error        = String.Empty,
                    isDictionary = true,
                    dictionary   = RegistryIndex.data
                });
            }
            else
            {
                data = Util.Serialization.serialize(new RegistryResponse
                {
                    error        = String.Empty,
                    isDictionary = false,
                    keyData      = RegistryIndex.data[(RegistryHive)request.hive],
                    hive         = (RegistryHive)request.hive
                });
            }
            return(data);
        }
Exemplo n.º 19
0
        public override NativeResultCode OpenKey(RegistryRequest request)
        {
            var virtualKeyPath = RegistryTranslator.ToVirtualPath(request.KeyFullPath);
            var virtReq        = new RegistryRequest(request)
            {
                KeyFullPath = virtualKeyPath
            };

            if (base.OpenKey(virtReq) == NativeResultCode.Success)
            {
                request.Handle = virtReq.Handle;
                return(NativeResultCode.Success);
            }
            if (request.VirtualizationType == VirtualizationType.Virtual ||
                !HostRegistry.KeyExists(request.KeyFullPath))
            {
                return(NativeResultCode.FileNotFound);
            }
            var virtualRegistryKey = ConstructRegistryKey(virtualKeyPath);

            WriteKey(virtualRegistryKey, true);
            request.Handle = virtualRegistryKey.Handle;
            return(NativeResultCode.Success);
        }
Exemplo n.º 20
0
        public override NativeResultCode DeleteKey(RegistryRequest request)
        {
            // Overriden, first delete the real key.
            if (HiveHelper.IsHiveHandle(request.Handle))
            {
                return(NativeResultCode.AccessDenied);
            }
            if (!IsKnownKey(request))
            {
                return(NativeResultCode.InvalidHandle);
            }
            var index       = request.KeyFullPath.LastIndexOf(@"\");
            var subKeyName  = request.KeyFullPath.Substring(index + 1);
            var keyFullPath = request.KeyFullPath.Substring(0, index);
            var registryKey = HostRegistry.OpenKey(keyFullPath, true);

            try
            {
                if (registryKey != null)
                {
                    registryKey.DeleteSubKeyTree(subKeyName);
                }
            }
            catch (ArgumentException)
            {
                // Key is not found in real registry, call base to delete it from the buffer.
                base.DeleteKey(request);
                return(NativeResultCode.FileNotFound);
            }
            catch
            {
                return(NativeResultCode.AccessDenied);
            }
            // Real key is deleted, now delete the virtual one.
            return(base.DeleteKey(request));
        }
Exemplo n.º 21
0
 /// <summary>
 /// Returns whether the database knows a key with the handle specified in <paramref name="request"/>.
 /// The full path of the key is set to <paramref name="request.KeyFullPath"/> if the key is known.
 /// </summary>
 /// <param name="request">The index to search a key for.</param>
 /// <returns></returns>
 public bool IsKnownKey(RegistryRequest request)
 {
   using (_keysSynchronizationLock.EnterDisposableReadLock())
   {
     if (_keyAliases.ContainsKey(request.Handle))
       request.Handle = _keyAliases[request.Handle];
     if (_keys.Keys.Contains(request.Handle))
     {
       request.KeyFullPath = _keys[request.Handle].Path;
       return true;
     }
   }
   return false;
 }
Exemplo n.º 22
0
 /// <summary>
 /// Closes the key handle specified in <paramref name="request"/>.
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public virtual NativeResultCode CloseKey(RegistryRequest request)
 {
   if (!IsKnownKey(request))
     return NativeResultCode.InvalidHandle;
   // Aliases should always be freed. Removing items from _keys is implemented by DeleteKey()
   RemoveAlias(request.Handle);
   return NativeResultCode.Success;
 }
Exemplo n.º 23
0
 public RegistryValueRequest(RegistryRequest request)
     : base(request)
 {
     Value = new VirtualRegistryValue(null, null, ValueType.INVALID);
 }
Exemplo n.º 24
0
 /// <summary>
 /// Deletes the key associated with the handle specified in <paramref name="request"/>.
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public virtual NativeResultCode DeleteKey(RegistryRequest request)
 {
   using (_keysSynchronizationLock.EnterDisposableWriteLock())
   {
     request.Handle = EnsureHandleIsNoAlias(request.Handle);
     if (!_keys.ContainsKey(request.Handle))
       return NativeResultCode.InvalidHandle;
     RemoveAliasesFor(request.Handle);
     _keys.Remove(request.Handle);
   }
   _indexGenerator.Release(request.Handle);
   return NativeResultCode.Success;
 }
Exemplo n.º 25
0
 /// <summary>
 /// Creates a key with the specified path.
 /// The open handle is set to <paramref name="request.Handle"/>.
 /// </summary>
 /// <param name="request"></param>
 /// <param name="creationDisposition">Whether the key is opened or created.</param>
 /// <returns></returns>
 public virtual NativeResultCode CreateKey(RegistryRequest request, out RegCreationDisposition creationDisposition)
 {
   if (OpenKey(request) == NativeResultCode.Success)
   {
     creationDisposition = RegCreationDisposition.OpenedExistingKey;
   }
   else
   {
     creationDisposition = RegCreationDisposition.CreatedNewKey;
     var regKey = ConstructRegistryKey(request.KeyFullPath);
     WriteKey(regKey);
     request.Handle = regKey.Handle;
   }
   return NativeResultCode.Success;
 }
 public override NativeResultCode DeleteKey(RegistryRequest request)
 {
   // Overriden, first delete the real key.
   if (HiveHelper.IsHiveHandle(request.Handle))
     return NativeResultCode.AccessDenied;
   if (!IsKnownKey(request))
     return NativeResultCode.InvalidHandle;
   var index = request.KeyFullPath.LastIndexOf(@"\");
   var subKeyName = request.KeyFullPath.Substring(index + 1);
   var keyFullPath = request.KeyFullPath.Substring(0, index);
   var registryKey = HostRegistry.OpenKey(keyFullPath, true);
   try
   {
     if (registryKey != null)
       registryKey.DeleteSubKeyTree(subKeyName);
   }
   catch (ArgumentException)
   {
     // Key is not found in real registry, call base to delete it from the buffer.
     base.DeleteKey(request);
     return NativeResultCode.FileNotFound;
   }
   catch
   {
     return NativeResultCode.AccessDenied;
   }
   // Real key is deleted, now delete the virtual one.
   return base.DeleteKey(request);
 }
 public RegistryValueRequest(RegistryRequest request)
   : base(request)
 {
   Value = new VirtualRegistryValue(null, null, ValueType.INVALID);
 }
Exemplo n.º 28
0
 /// <summary>
 /// Opens the key from the specified path.
 /// The open handle is set to <paramref name="request.Handle"/>.
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public virtual NativeResultCode OpenKey(RegistryRequest request)
 {
   VirtualRegistryKey key;
   using (_keysSynchronizationLock.EnterDisposableReadLock())
     key = _keys.Values.FirstOrDefault(k => k.Path.ToLowerInvariant() == request.KeyFullPath.ToLowerInvariant());
   if (key == null)
     return NativeResultCode.FileNotFound;
   request.Handle = key.Handle;
   return NativeResultCode.Success;
 }