python / python/cpython

[winreg] support options and opened disposition in CreateKeyEx and OpenKey[Ex]

オープン
#95,461 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

3.13 OS-windows type-feature
主要言語
Python
スター
77.2k
フォーク
36k
PR マージ指標
PR 指標を取得中

説明

winreg.CreateKeyEx() should support the dwOptions and lpdwDisposition parameters of RegCreateKeyExW(), and winreg.OpenKey[Ex]() should support the ulOptions parameter of RegOpenKeyExW(). Also, the REG_LINK data type should be handled as a null-terminated Unicode string instead of as binary data.

The lpdwDisposition parameter can be supported indirectly by a new create_only parameter. If create_only is true and the opened disposition is REG_OPENED_EXISTING_KEY, close the handle and raise FileExistsError.

The dwOptions and ulOptions parameters can be supported as a new options parameter. Currently ulOptions is supported as a parameter named reserved, but RegOpenKeyExW() has been documented to support it since 2015. Unofficially, RegOpenKeyExW() first implemented support for REG_OPTION_OPEN_LINK in NT 4.0 (1996). The misnamed reserved parameter has to be retained for compatibility, but options should override it.

For example:

CreateKeyEx(key, sub_key, reserved=0, access=KEY_WRITE, options=0, create_only=False)
OpenKeyEx(key, sub_key, reserved=0, access=KEY_READ, options=0)

RegCreateKeyExW() supports the following options:

  • REG_OPTION_VOLATILE: create a dynamic key in memory that's never persisted to a hive file. This is useful for keys that should always be newly created for each session (e.g. "HKCU\Volatile Environment") or for test cases that shouldn't permanently modify a hive.
  • REG_OPTION_CREATE_LINK: create a key symbolic link. The NT target path has to be set as a REG_LINK value named "SymbolicLinkValue". The registry API supports creating and modifying symbolic links, but deleting a symbolic link requires NTAPI NtDeleteKey(KeyHandle).
  • REG_OPTION_OPEN_LINK: open a symbolic link to modify its target path or to delete it via NtDeleteKey().
  • REG_OPTION_BACKUP_RESTORE: use backup semantics. If "SeBackupPrivilege" is enabled for the thread or process, then the open is granted read access and system security (SACL) access. If "SeRestorePrivilege" is enabled, then the open is granted write access, delete access, security access, and system security access. All access is granted if both privileges are enabled. If neither privilege is enabled, the call fails with access denied.
  • REG_OPTION_DONT_VIRTUALIZE: disable open, read, and write virtualization for non-admin, interactive logons in legacy 32-bit processes. This isn't relevant to a 32-bit "python[w].exe" process or any 32-bit application that has a "requestedExecutionLevel" in its manifest.

RegOpenKeyExW() supports the following options:

  • REG_OPTION_OPEN_LINK
  • REG_OPTION_BACKUP_RESTORE
  • REG_OPTION_DONT_VIRTUALIZE
Linked PRs
  • gh-129903

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

エントリポイント winreg.CreateKeyEx()、winreg.OpenKey()、winreg.OpenKeyEx() から開始し、それらのパラメーターを RegCreateKeyEx() および RegOpenKeyExW() と比較します。要求されたオプション、create_only の動作、REG_LINK の Unicode 処理を確認し、その後、関連する winreg テストを実行して、新しいキー、既存のキー、シンボリックリンクのケースを検証します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
operating-systems
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。