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;
 }
Example #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
            }));
        }
Example #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;
 }
Example #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);
 }
        public async Task <bool> RegistryExecutor()
        {
            var registryBody = new RegistryRequest
            {
                Key  = _options.ExecutorAppName,
                Host = _options.ExecutorUrl
            };

            return(await InnnerAdminHttpClient <string>(CreateRestRequest($"{_options.ApiUriSegments}/registry", registryBody), "注册执行器"));
        }
Example #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);
        }
Example #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);
 }
Example #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;
 }
Example #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);
        }
Example #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);
 }
Example #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);
 }
Example #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);
 }
 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;
 }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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));
        }
 /// <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;
 }
 /// <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;
 }
Example #23
0
 public RegistryValueRequest(RegistryRequest request)
     : base(request)
 {
     Value = new VirtualRegistryValue(null, null, ValueType.INVALID);
 }
 /// <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;
 }
 /// <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);
 }
 /// <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;
 }