mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge branch '2018.3' into fix-run-env-reset
This commit is contained in:
commit
3b02b0bdc1
4 changed files with 872 additions and 553 deletions
|
@ -28,12 +28,15 @@ import salt.utils.stringutils
|
|||
import salt.utils.vt
|
||||
from salt.exceptions import SaltInvocationError, CommandExecutionError
|
||||
|
||||
# Import 3rd-party libs
|
||||
# Import third-party libs
|
||||
from salt.ext import six
|
||||
from salt.ext.six.moves.urllib.parse import urlparse as _urlparse # pylint: disable=no-name-in-module,import-error
|
||||
|
||||
HAS_LIBS = False
|
||||
|
||||
SIGN_PROMPT_RE = re.compile(r'Enter passphrase: ', re.M)
|
||||
REPREPRO_SIGN_PROMPT_RE = re.compile(r'Passphrase: ', re.M)
|
||||
|
||||
try:
|
||||
import gnupg # pylint: disable=unused-import
|
||||
import salt.modules.gpg
|
||||
|
@ -61,7 +64,8 @@ def __virtual__():
|
|||
if HAS_LIBS and not missing_util:
|
||||
return __virtualname__
|
||||
else:
|
||||
return False, 'The debbuild module could not be loaded: requires python-gnupg, gpg, debuild, pbuilder and reprepro utilities to be installed'
|
||||
return False, ('The debbuild module could not be loaded: requires python-gnupg, gpg, debuild, '
|
||||
'pbuilder and reprepro utilities to be installed')
|
||||
else:
|
||||
return (False, 'The debbuild module could not be loaded: unsupported OS family')
|
||||
|
||||
|
@ -78,7 +82,7 @@ def _check_repo_sign_utils_support(name):
|
|||
)
|
||||
|
||||
|
||||
def _check_repo_gpg_phrase_utils_support():
|
||||
def _check_repo_gpg_phrase_utils():
|
||||
'''
|
||||
Check for /usr/lib/gnupg2/gpg-preset-passphrase is installed
|
||||
'''
|
||||
|
@ -270,7 +274,7 @@ def _mk_tree():
|
|||
return basedir
|
||||
|
||||
|
||||
def _get_spec(tree_base, spec, template, saltenv='base'):
|
||||
def _get_spec(tree_base, spec, saltenv='base'):
|
||||
'''
|
||||
Get the spec file (tarball of the debian sub-dir to use)
|
||||
and place it in build area
|
||||
|
@ -294,7 +298,7 @@ def _get_src(tree_base, source, saltenv='base'):
|
|||
shutil.copy(source, dest)
|
||||
|
||||
|
||||
def make_src_pkg(dest_dir, spec, sources, env=None, template=None, saltenv='base'):
|
||||
def make_src_pkg(dest_dir, spec, sources, env=None, saltenv='base'):
|
||||
'''
|
||||
Create a platform specific source package from the given platform spec/control file and sources
|
||||
|
||||
|
@ -304,7 +308,9 @@ def make_src_pkg(dest_dir, spec, sources, env=None, template=None, saltenv='base
|
|||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' pkgbuild.make_src_pkg /var/www/html/ https://raw.githubusercontent.com/saltstack/libnacl/master/pkg/deb/python-libnacl.control.tar.xz https://pypi.python.org/packages/source/l/libnacl/libnacl-1.3.5.tar.gz
|
||||
salt '*' pkgbuild.make_src_pkg /var/www/html/
|
||||
https://raw.githubusercontent.com/saltstack/libnacl/master/pkg/deb/python-libnacl.control.tar.xz
|
||||
https://pypi.python.org/packages/source/l/libnacl/libnacl-1.3.5.tar.gz
|
||||
|
||||
This example command should build the libnacl SOURCE package and place it in
|
||||
/var/www/html/ on the minion
|
||||
|
@ -315,7 +321,7 @@ def make_src_pkg(dest_dir, spec, sources, env=None, template=None, saltenv='base
|
|||
if not os.path.isdir(dest_dir):
|
||||
os.makedirs(dest_dir)
|
||||
|
||||
spec_pathfile = _get_spec(tree_base, spec, template, saltenv)
|
||||
spec_pathfile = _get_spec(tree_base, spec, saltenv)
|
||||
|
||||
# build salt equivalents from scratch
|
||||
if isinstance(sources, six.string_types):
|
||||
|
@ -350,26 +356,36 @@ def make_src_pkg(dest_dir, spec, sources, env=None, template=None, saltenv='base
|
|||
debname += '+ds'
|
||||
debname_orig = debname + '.orig.tar.gz'
|
||||
abspath_debname = os.path.join(tree_base, debname)
|
||||
retrc = 0
|
||||
|
||||
cmd = 'tar -xvzf {0}'.format(salttarball)
|
||||
__salt__['cmd.run'](cmd, cwd=tree_base)
|
||||
retrc = __salt__['cmd.retcode'](cmd, cwd=tree_base)
|
||||
cmd = 'mv {0} {1}'.format(salttar_name, debname)
|
||||
__salt__['cmd.run'](cmd, cwd=tree_base)
|
||||
retrc |= __salt__['cmd.retcode'](cmd, cwd=tree_base)
|
||||
cmd = 'tar -cvzf {0} {1}'.format(os.path.join(tree_base, debname_orig), debname)
|
||||
__salt__['cmd.run'](cmd, cwd=tree_base)
|
||||
retrc |= __salt__['cmd.retcode'](cmd, cwd=tree_base)
|
||||
cmd = 'rm -f {0}'.format(salttarball)
|
||||
__salt__['cmd.run'](cmd, cwd=tree_base)
|
||||
retrc |= __salt__['cmd.retcode'](cmd, cwd=tree_base, env=env)
|
||||
cmd = 'cp {0} {1}'.format(spec_pathfile, abspath_debname)
|
||||
__salt__['cmd.run'](cmd, cwd=abspath_debname)
|
||||
retrc |= __salt__['cmd.retcode'](cmd, cwd=abspath_debname)
|
||||
cmd = 'tar -xvJf {0}'.format(spec_pathfile)
|
||||
__salt__['cmd.run'](cmd, cwd=abspath_debname)
|
||||
retrc |= __salt__['cmd.retcode'](cmd, cwd=abspath_debname, env=env)
|
||||
cmd = 'rm -f {0}'.format(os.path.basename(spec_pathfile))
|
||||
__salt__['cmd.run'](cmd, cwd=abspath_debname)
|
||||
retrc |= __salt__['cmd.retcode'](cmd, cwd=abspath_debname)
|
||||
cmd = 'debuild -S -uc -us -sa'
|
||||
__salt__['cmd.run'](cmd, cwd=abspath_debname, python_shell=True)
|
||||
retrc |= __salt__['cmd.retcode'](cmd, cwd=abspath_debname, python_shell=True, env=env)
|
||||
|
||||
cmd = 'rm -fR {0}'.format(abspath_debname)
|
||||
__salt__['cmd.run'](cmd)
|
||||
retrc |= __salt__['cmd.retcode'](cmd)
|
||||
if retrc != 0:
|
||||
raise SaltInvocationError(
|
||||
'Make source package for destination directory {0}, spec {1}, sources {2}, failed '
|
||||
'with return error {3}, check logs for further details'.format(
|
||||
dest_dir,
|
||||
spec,
|
||||
sources,
|
||||
retrc)
|
||||
)
|
||||
|
||||
for dfile in os.listdir(tree_base):
|
||||
if not dfile.endswith('.build'):
|
||||
|
@ -401,12 +417,15 @@ def build(runas,
|
|||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' pkgbuild.make_src_pkg deb-8-x86_64 /var/www/html https://raw.githubusercontent.com/saltstack/libnacl/master/pkg/deb/python-libnacl.control https://pypi.python.org/packages/source/l/libnacl/libnacl-1.3.5.tar.gz
|
||||
salt '*' pkgbuild.make_src_pkg deb-8-x86_64 /var/www/html
|
||||
https://raw.githubusercontent.com/saltstack/libnacl/master/pkg/deb/python-libnacl.control
|
||||
https://pypi.python.org/packages/source/l/libnacl/libnacl-1.3.5.tar.gz
|
||||
|
||||
This example command should build the libnacl package for Debian using pbuilder
|
||||
and place it in /var/www/html/ on the minion
|
||||
'''
|
||||
ret = {}
|
||||
retrc = 0
|
||||
try:
|
||||
os.makedirs(dest_dir)
|
||||
except OSError as exc:
|
||||
|
@ -414,36 +433,45 @@ def build(runas,
|
|||
raise
|
||||
dsc_dir = tempfile.mkdtemp()
|
||||
try:
|
||||
dscs = make_src_pkg(dsc_dir, spec, sources, env, template, saltenv)
|
||||
dscs = make_src_pkg(dsc_dir, spec, sources, env, saltenv)
|
||||
except Exception as exc:
|
||||
shutil.rmtree(dsc_dir)
|
||||
log.error('Failed to make src package')
|
||||
return ret
|
||||
|
||||
cmd = 'pbuilder --create'
|
||||
__salt__['cmd.run'](cmd, runas=runas, python_shell=True)
|
||||
retrc = __salt__['cmd.retcode'](cmd, runas=runas, python_shell=True, env=env)
|
||||
if retrc != 0:
|
||||
raise SaltInvocationError(
|
||||
'pbuilder create failed with return error {0}, check logs for further details'.format(retrc))
|
||||
|
||||
# use default /var/cache/pbuilder/result
|
||||
results_dir = '/var/cache/pbuilder/result'
|
||||
|
||||
## ensure clean
|
||||
__salt__['cmd.run']('rm -fR {0}'.format(results_dir))
|
||||
# ensure clean
|
||||
retrc |= __salt__['cmd.retcode']('rm -fR {0}'.format(results_dir))
|
||||
|
||||
# dscs should only contain salt orig and debian tarballs and dsc file
|
||||
for dsc in dscs:
|
||||
afile = os.path.basename(dsc)
|
||||
adist = os.path.join(dest_dir, afile)
|
||||
os.path.join(dest_dir, afile)
|
||||
|
||||
if dsc.endswith('.dsc'):
|
||||
dbase = os.path.dirname(dsc)
|
||||
try:
|
||||
__salt__['cmd.run']('chown {0} -R {1}'.format(runas, dbase))
|
||||
retrc |= __salt__['cmd.retcode']('chown {0} -R {1}'.format(runas, dbase))
|
||||
|
||||
cmd = 'pbuilder update --override-config'
|
||||
__salt__['cmd.run'](cmd, runas=runas, python_shell=True)
|
||||
retrc |= __salt__['cmd.retcode'](cmd, runas=runas, python_shell=True, env=env)
|
||||
|
||||
cmd = 'pbuilder build --debbuildopts "-sa" {0}'.format(dsc)
|
||||
__salt__['cmd.run'](cmd, runas=runas, python_shell=True)
|
||||
retrc |= __salt__['cmd.retcode'](cmd, runas=runas, python_shell=True, env=env)
|
||||
|
||||
if retrc != 0:
|
||||
raise SaltInvocationError(
|
||||
'pbuilder build or update failed with return error {0}, '
|
||||
'check logs for further details'.format(retrc)
|
||||
)
|
||||
|
||||
# ignore local deps generated package file
|
||||
for bfile in os.listdir(results_dir):
|
||||
|
@ -487,44 +515,20 @@ def make_repo(repodir,
|
|||
.. versionchanged:: 2016.3.0
|
||||
|
||||
Optional Key ID to use in signing packages and repository.
|
||||
This consists of the last 8 hex digits of the GPG key ID.
|
||||
|
||||
Utilizes Public and Private keys associated with keyid which have
|
||||
been loaded into the minion's Pillar data. Leverages gpg-agent and
|
||||
gpg-preset-passphrase for caching keys, etc.
|
||||
These pillar values are assumed to be filenames which are present
|
||||
in ``gnupghome``. The pillar keys shown below have to match exactly.
|
||||
|
||||
For example, contents from a Pillar data file with named Public
|
||||
and Private keys as follows:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
gpg_pkg_priv_key: |
|
||||
-----BEGIN PGP PRIVATE KEY BLOCK-----
|
||||
Version: GnuPG v1
|
||||
|
||||
lQO+BFciIfQBCADAPCtzx7I5Rl32escCMZsPzaEKWe7bIX1em4KCKkBoX47IG54b
|
||||
w82PCE8Y1jF/9Uk2m3RKVWp3YcLlc7Ap3gj6VO4ysvVz28UbnhPxsIkOlf2cq8qc
|
||||
.
|
||||
.
|
||||
Ebe+8JCQTwqSXPRTzXmy/b5WXDeM79CkLWvuGpXFor76D+ECMRPv/rawukEcNptn
|
||||
R5OmgHqvydEnO4pWbn8JzQO9YX/Us0SMHBVzLC8eIi5ZIopzalvX
|
||||
=JvW8
|
||||
-----END PGP PRIVATE KEY BLOCK-----
|
||||
|
||||
gpg_pkg_priv_keyname: gpg_pkg_key.pem
|
||||
|
||||
gpg_pkg_pub_key: |
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
Version: GnuPG v1
|
||||
|
||||
mQENBFciIfQBCADAPCtzx7I5Rl32escCMZsPzaEKWe7bIX1em4KCKkBoX47IG54b
|
||||
w82PCE8Y1jF/9Uk2m3RKVWp3YcLlc7Ap3gj6VO4ysvVz28UbnhPxsIkOlf2cq8qc
|
||||
.
|
||||
.
|
||||
bYP7t5iwJmQzRMyFInYRt77wkJBPCpJc9FPNebL9vlZcN4zv0KQta+4alcWivvoP
|
||||
4QIxE+/+trC6QRw2m2dHk6aAeq/J0Sc7ilZufwnNA71hf9SzRIwcFXMsLx4iLlki
|
||||
inNqW9c=
|
||||
=s1CX
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
gpg_pkg_pub_keyname: gpg_pkg_key.pub
|
||||
|
||||
env
|
||||
|
@ -571,12 +575,17 @@ def make_repo(repodir,
|
|||
salt '*' pkgbuild.make_repo /var/www/html
|
||||
|
||||
'''
|
||||
res = {'retcode': 1,
|
||||
res = {
|
||||
'retcode': 1,
|
||||
'stdout': '',
|
||||
'stderr': 'initialization value'}
|
||||
'stderr': 'initialization value'
|
||||
}
|
||||
|
||||
SIGN_PROMPT_RE = re.compile(r'Enter passphrase: ', re.M)
|
||||
REPREPRO_SIGN_PROMPT_RE = re.compile(r'Passphrase: ', re.M)
|
||||
retrc = 0
|
||||
|
||||
if gnupghome and env is None:
|
||||
env = {}
|
||||
env['GNUPGHOME'] = gnupghome
|
||||
|
||||
repoconf = os.path.join(repodir, 'conf')
|
||||
if not os.path.isdir(repoconf):
|
||||
|
@ -600,7 +609,6 @@ def make_repo(repodir,
|
|||
# preset passphase and interaction with gpg-agent
|
||||
gpg_info_file = '{0}/gpg-agent-info-salt'.format(gnupghome)
|
||||
gpg_tty_info_file = '{0}/gpg-tty-info-salt'.format(gnupghome)
|
||||
gpg_tty_info_dict = {}
|
||||
|
||||
# if using older than gnupg 2.1, then env file exists
|
||||
older_gnupg = __salt__['file.file_exists'](gpg_info_file)
|
||||
|
@ -639,9 +647,13 @@ def make_repo(repodir,
|
|||
break
|
||||
|
||||
if not older_gnupg:
|
||||
_check_repo_sign_utils_support('gpg2')
|
||||
cmd = '{0} --with-keygrip --list-secret-keys'.format(salt.utils.path.which('gpg2'))
|
||||
local_keys2_keygrip = __salt__['cmd.run'](cmd, runas=runas)
|
||||
try:
|
||||
_check_repo_sign_utils_support('gpg2')
|
||||
cmd = 'gpg2 --with-keygrip --list-secret-keys'
|
||||
except CommandExecutionError:
|
||||
# later gpg versions have dispensed with gpg2 - Ubuntu 18.04
|
||||
cmd = 'gpg --with-keygrip --list-secret-keys'
|
||||
local_keys2_keygrip = __salt__['cmd.run'](cmd, runas=runas, env=env)
|
||||
local_keys2 = iter(local_keys2_keygrip.splitlines())
|
||||
try:
|
||||
for line in local_keys2:
|
||||
|
@ -672,25 +684,25 @@ def make_repo(repodir,
|
|||
for gpg_info_line in gpg_raw_info:
|
||||
gpg_info_line = salt.utils.stringutils.to_unicode(gpg_info_line)
|
||||
gpg_info = gpg_info_line.split('=')
|
||||
gpg_info_dict = {gpg_info[0]: gpg_info[1]}
|
||||
__salt__['environ.setenv'](gpg_info_dict)
|
||||
env[gpg_info[0]] = gpg_info[1]
|
||||
break
|
||||
else:
|
||||
with salt.utils.files.fopen(gpg_tty_info_file, 'r') as fow:
|
||||
gpg_raw_info = fow.readlines()
|
||||
|
||||
for gpg_tty_info_line in gpg_raw_info:
|
||||
gpg_info_line = salt.utils.stringutils.to_unicode(gpg_info_line)
|
||||
gpg_tty_info_line = salt.utils.stringutils.to_unicode(gpg_tty_info_line)
|
||||
gpg_tty_info = gpg_tty_info_line.split('=')
|
||||
gpg_tty_info_dict = {gpg_tty_info[0]: gpg_tty_info[1]}
|
||||
__salt__['environ.setenv'](gpg_tty_info_dict)
|
||||
env[gpg_tty_info[0]] = gpg_tty_info[1]
|
||||
break
|
||||
|
||||
if use_passphrase:
|
||||
_check_repo_gpg_phrase_utils_support()
|
||||
_check_repo_gpg_phrase_utils()
|
||||
phrase = __salt__['pillar.get']('gpg_passphrase')
|
||||
cmd = '/usr/lib/gnupg2/gpg-preset-passphrase --verbose --preset --passphrase "{0}" {1}'.format(phrase, local_keygrip_to_use)
|
||||
__salt__['cmd.run'](cmd, runas=runas)
|
||||
cmd = '/usr/lib/gnupg2/gpg-preset-passphrase --verbose --preset --passphrase "{0}" {1}'.format(
|
||||
phrase,
|
||||
local_keygrip_to_use)
|
||||
retrc |= __salt__['cmd.retcode'](cmd, runas=runas, env=env)
|
||||
|
||||
for debfile in os.listdir(repodir):
|
||||
abs_file = os.path.join(repodir, debfile)
|
||||
|
@ -702,10 +714,12 @@ def make_repo(repodir,
|
|||
if older_gnupg:
|
||||
if local_keyid is not None:
|
||||
cmd = 'debsign --re-sign -k {0} {1}'.format(keyid, abs_file)
|
||||
__salt__['cmd.run'](cmd, cwd=repodir, use_vt=True)
|
||||
retrc |= __salt__['cmd.retcode'](cmd, cwd=repodir, use_vt=True, env=env)
|
||||
|
||||
cmd = 'reprepro --ignore=wrongdistribution --component=main -Vb . includedsc {0} {1}'.format(codename, abs_file)
|
||||
__salt__['cmd.run'](cmd, cwd=repodir, use_vt=True)
|
||||
cmd = 'reprepro --ignore=wrongdistribution --component=main -Vb . includedsc {0} {1}'.format(
|
||||
codename,
|
||||
abs_file)
|
||||
retrc |= __salt__['cmd.retcode'](cmd, cwd=repodir, use_vt=True, env=env)
|
||||
else:
|
||||
# interval of 0.125 is really too fast on some systems
|
||||
interval = 0.5
|
||||
|
@ -715,15 +729,15 @@ def make_repo(repodir,
|
|||
error_msg = 'Failed to debsign file {0}'.format(abs_file)
|
||||
cmd = 'debsign --re-sign -k {0} {1}'.format(keyid, abs_file)
|
||||
try:
|
||||
stdout, stderr = None, None
|
||||
proc = salt.utils.vt.Terminal(
|
||||
cmd,
|
||||
env=env,
|
||||
shell=True,
|
||||
stream_stdout=True,
|
||||
stream_stderr=True
|
||||
)
|
||||
while proc.has_unread_data:
|
||||
stdout, stderr = proc.recv()
|
||||
stdout, _ = proc.recv()
|
||||
if stdout and SIGN_PROMPT_RE.search(stdout):
|
||||
# have the prompt for inputting the passphrase
|
||||
proc.sendline(phrase)
|
||||
|
@ -732,21 +746,24 @@ def make_repo(repodir,
|
|||
|
||||
if times_looped > number_retries:
|
||||
raise SaltInvocationError(
|
||||
'Attempting to sign file {0} failed, timed out after {1} seconds'
|
||||
.format(abs_file, int(times_looped * interval))
|
||||
'Attempting to sign file {0} failed, timed out after {1} seconds'.format(
|
||||
abs_file,
|
||||
int(times_looped * interval))
|
||||
)
|
||||
time.sleep(interval)
|
||||
|
||||
proc_exitstatus = proc.exitstatus
|
||||
if proc_exitstatus != 0:
|
||||
raise SaltInvocationError(
|
||||
'Signing file {0} failed with proc.status {1}'
|
||||
.format(abs_file, proc_exitstatus)
|
||||
'Signing file {0} failed with proc.status {1}'.format(
|
||||
abs_file,
|
||||
proc_exitstatus)
|
||||
)
|
||||
except salt.utils.vt.TerminalException as err:
|
||||
trace = traceback.format_exc()
|
||||
log.error(error_msg, err, trace)
|
||||
res = {'retcode': 1,
|
||||
res = {
|
||||
'retcode': 1,
|
||||
'stdout': '',
|
||||
'stderr': trace}
|
||||
finally:
|
||||
|
@ -755,19 +772,21 @@ def make_repo(repodir,
|
|||
number_retries = timeout / interval
|
||||
times_looped = 0
|
||||
error_msg = 'Failed to reprepro includedsc file {0}'.format(abs_file)
|
||||
cmd = 'reprepro --ignore=wrongdistribution --component=main -Vb . includedsc {0} {1}'.format(codename, abs_file)
|
||||
cmd = 'reprepro --ignore=wrongdistribution --component=main -Vb . includedsc {0} {1}'.format(
|
||||
codename,
|
||||
abs_file)
|
||||
|
||||
try:
|
||||
stdout, stderr = None, None
|
||||
proc = salt.utils.vt.Terminal(
|
||||
cmd,
|
||||
env=env,
|
||||
shell=True,
|
||||
cwd=repodir,
|
||||
env=gpg_tty_info_dict,
|
||||
stream_stdout=True,
|
||||
stream_stderr=True
|
||||
)
|
||||
while proc.has_unread_data:
|
||||
stdout, stderr = proc.recv()
|
||||
stdout, _ = proc.recv()
|
||||
if stdout and REPREPRO_SIGN_PROMPT_RE.search(stdout):
|
||||
# have the prompt for inputting the passphrase
|
||||
proc.sendline(phrase)
|
||||
|
@ -776,26 +795,38 @@ def make_repo(repodir,
|
|||
|
||||
if times_looped > number_retries:
|
||||
raise SaltInvocationError(
|
||||
'Attempting to reprepro includedsc for file {0} failed, timed out after {1} loops'.format(abs_file, times_looped)
|
||||
'Attempting to reprepro includedsc for file {0} failed, timed out after {1} loops'
|
||||
.format(abs_file, times_looped)
|
||||
)
|
||||
time.sleep(interval)
|
||||
|
||||
proc_exitstatus = proc.exitstatus
|
||||
if proc_exitstatus != 0:
|
||||
raise SaltInvocationError(
|
||||
'Reprepro includedsc for codename {0} and file {1} failed with proc.status {2}'.format(codename, abs_file, proc_exitstatus)
|
||||
)
|
||||
'Reprepro includedsc for codename {0} and file {1} failed with proc.status {2}'.format(
|
||||
codename,
|
||||
abs_file,
|
||||
proc_exitstatus)
|
||||
)
|
||||
except salt.utils.vt.TerminalException as err:
|
||||
trace = traceback.format_exc()
|
||||
log.error(error_msg, err, trace)
|
||||
res = {'retcode': 1,
|
||||
res = {
|
||||
'retcode': 1,
|
||||
'stdout': '',
|
||||
'stderr': trace}
|
||||
'stderr': trace
|
||||
}
|
||||
finally:
|
||||
proc.close(terminate=True, kill=True)
|
||||
|
||||
if retrc != 0:
|
||||
raise SaltInvocationError(
|
||||
'Making a repo encountered errors, return error {0}, check logs for further details'.format(retrc))
|
||||
|
||||
if debfile.endswith('.deb'):
|
||||
cmd = 'reprepro --ignore=wrongdistribution --component=main -Vb . includedeb {0} {1}'.format(codename, abs_file)
|
||||
res = __salt__['cmd.run_all'](cmd, cwd=repodir, use_vt=True)
|
||||
cmd = 'reprepro --ignore=wrongdistribution --component=main -Vb . includedeb {0} {1}'.format(
|
||||
codename,
|
||||
abs_file)
|
||||
res = __salt__['cmd.run_all'](cmd, cwd=repodir, use_vt=True, env=env)
|
||||
|
||||
return res
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
r'''
|
||||
Manage the Windows registry
|
||||
|
||||
-----
|
||||
Hives
|
||||
-----
|
||||
Hives are the main sections of the registry and all begin with the word HKEY.
|
||||
- HKEY_LOCAL_MACHINE
|
||||
- HKEY_CURRENT_USER
|
||||
- HKEY_USER
|
||||
|
||||
- HKEY_LOCAL_MACHINE
|
||||
- HKEY_CURRENT_USER
|
||||
- HKEY_USER
|
||||
|
||||
----
|
||||
Keys
|
||||
|
@ -19,10 +20,41 @@ can have a value assigned to them under the (Default)
|
|||
-----------------
|
||||
Values or Entries
|
||||
-----------------
|
||||
Values/Entries are name/data pairs. There can be many values in a key. The
|
||||
(Default) value corresponds to the Key, the rest are their own value pairs.
|
||||
|
||||
:depends: - PyWin32
|
||||
Values or Entries are the name/data pairs beneath the keys and subkeys. All keys
|
||||
have a default name/data pair. The name is ``(Default)`` with a displayed value
|
||||
of ``(value not set)``. The actual value is Null.
|
||||
|
||||
-------
|
||||
Example
|
||||
-------
|
||||
|
||||
The following example is an export from the Windows startup portion of the
|
||||
registry:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
|
||||
"RTHDVCPL"="\"C:\\Program Files\\Realtek\\Audio\\HDA\\RtkNGUI64.exe\" -s"
|
||||
"NvBackend"="\"C:\\Program Files (x86)\\NVIDIA Corporation\\Update Core\\NvBackend.exe\""
|
||||
"BTMTrayAgent"="rundll32.exe \"C:\\Program Files (x86)\\Intel\\Bluetooth\\btmshellex.dll\",TrayApp"
|
||||
|
||||
In this example these are the values for each:
|
||||
|
||||
Hive:
|
||||
``HKEY_LOCAL_MACHINE``
|
||||
|
||||
Key and subkeys:
|
||||
``SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run``
|
||||
|
||||
Value:
|
||||
- There are 3 value names:
|
||||
- `RTHDVCPL`
|
||||
- `NvBackend`
|
||||
- `BTMTrayAgent`
|
||||
- Each value name has a corresponding value
|
||||
|
||||
:depends: - salt.utils.win_reg
|
||||
'''
|
||||
# When production windows installer is using Python 3, Python 2 code can be removed
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
@ -42,7 +74,7 @@ __virtualname__ = 'reg'
|
|||
|
||||
def __virtual__():
|
||||
'''
|
||||
Only works on Windows systems with the PyWin32
|
||||
Only works on Windows systems with PyWin32
|
||||
'''
|
||||
if not salt.utils.platform.is_windows():
|
||||
return (False, 'reg execution module failed to load: '
|
||||
|
@ -56,16 +88,26 @@ def __virtual__():
|
|||
|
||||
|
||||
def key_exists(hive, key, use_32bit_registry=False):
|
||||
'''
|
||||
r'''
|
||||
Check that the key is found in the registry. This refers to keys and not
|
||||
value/data pairs.
|
||||
|
||||
:param str hive: The hive to connect to.
|
||||
:param str key: The key to check
|
||||
:param bool use_32bit_registry: Look in the 32bit portion of the registry
|
||||
Args:
|
||||
|
||||
:return: Returns True if found, False if not found
|
||||
:rtype: bool
|
||||
hive (str): The hive to connect to
|
||||
|
||||
key (str): The key to check
|
||||
|
||||
use_32bit_registry (bool): Look in the 32bit portion of the registry
|
||||
|
||||
Returns:
|
||||
bool: True if exists, otherwise False
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' reg.key_exists HKLM SOFTWARE\Microsoft
|
||||
'''
|
||||
return __utils__['reg.key_exists'](hive=hive,
|
||||
key=key,
|
||||
|
@ -76,13 +118,18 @@ def broadcast_change():
|
|||
'''
|
||||
Refresh the windows environment.
|
||||
|
||||
Returns (bool): True if successful, otherwise False
|
||||
.. note::
|
||||
This will only effect new processes and windows. Services will not see
|
||||
the change until the system restarts.
|
||||
|
||||
Returns:
|
||||
bool: True if successful, otherwise False
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' reg.broadcast_change
|
||||
salt '*' reg.broadcast_change
|
||||
'''
|
||||
return salt.utils.win_functions.broadcast_setting_change('Environment')
|
||||
|
||||
|
@ -91,28 +138,33 @@ def list_keys(hive, key=None, use_32bit_registry=False):
|
|||
'''
|
||||
Enumerates the subkeys in a registry key or hive.
|
||||
|
||||
:param str hive: The name of the hive. Can be one of the following
|
||||
Args:
|
||||
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
hive (str):
|
||||
The name of the hive. Can be one of the following:
|
||||
|
||||
:param str key: The key (looks like a path) to the value name. If a key is
|
||||
not passed, the keys under the hive will be returned.
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
|
||||
:param bool use_32bit_registry: Accesses the 32bit portion of the registry
|
||||
on 64 bit installations. On 32bit machines this is ignored.
|
||||
key (str):
|
||||
The key (looks like a path) to the value name. If a key is not
|
||||
passed, the keys under the hive will be returned.
|
||||
|
||||
:return: A list of keys/subkeys under the hive or key.
|
||||
:rtype: list
|
||||
use_32bit_registry (bool):
|
||||
Accesses the 32bit portion of the registry on 64 bit installations.
|
||||
On 32bit machines this is ignored.
|
||||
|
||||
Returns:
|
||||
list: A list of keys/subkeys under the hive or key.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' reg.list_keys HKLM 'SOFTWARE'
|
||||
salt '*' reg.list_keys HKLM 'SOFTWARE'
|
||||
'''
|
||||
return __utils__['reg.list_keys'](hive=hive,
|
||||
key=key,
|
||||
|
@ -123,30 +175,36 @@ def list_values(hive, key=None, use_32bit_registry=False, include_default=True):
|
|||
'''
|
||||
Enumerates the values in a registry key or hive.
|
||||
|
||||
:param str hive: The name of the hive. Can be one of the following
|
||||
Args:
|
||||
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
hive (str):
|
||||
The name of the hive. Can be one of the following:
|
||||
|
||||
:param str key: The key (looks like a path) to the value name. If a key is
|
||||
not passed, the values under the hive will be returned.
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
|
||||
:param bool use_32bit_registry: Accesses the 32bit portion of the registry
|
||||
on 64 bit installations. On 32bit machines this is ignored.
|
||||
key (str):
|
||||
The key (looks like a path) to the value name. If a key is not
|
||||
passed, the values under the hive will be returned.
|
||||
|
||||
:param bool include_default: Toggle whether to include the '(Default)' value.
|
||||
use_32bit_registry (bool):
|
||||
Accesses the 32bit portion of the registry on 64 bit installations.
|
||||
On 32bit machines this is ignored.
|
||||
|
||||
:return: A list of values under the hive or key.
|
||||
:rtype: list
|
||||
include_default (bool):
|
||||
Toggle whether to include the '(Default)' value.
|
||||
|
||||
Returns:
|
||||
list: A list of values under the hive or key.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' reg.list_values HKLM 'SYSTEM\\CurrentControlSet\\Services\\Tcpip'
|
||||
salt '*' reg.list_values HKLM 'SYSTEM\\CurrentControlSet\\Services\\Tcpip'
|
||||
'''
|
||||
return __utils__['reg.list_values'](hive=hive,
|
||||
key=key,
|
||||
|
@ -156,40 +214,58 @@ def list_values(hive, key=None, use_32bit_registry=False, include_default=True):
|
|||
|
||||
def read_value(hive, key, vname=None, use_32bit_registry=False):
|
||||
r'''
|
||||
Reads a registry value entry or the default value for a key.
|
||||
Reads a registry value entry or the default value for a key. To read the
|
||||
default value, don't pass ``vname``
|
||||
|
||||
:param str hive: The name of the hive. Can be one of the following
|
||||
Args:
|
||||
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
hive (str): The name of the hive. Can be one of the following:
|
||||
|
||||
:param str key: The key (looks like a path) to the value name.
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
|
||||
:param str vname: The value name. These are the individual name/data pairs
|
||||
under the key. If not passed, the key (Default) value will be returned
|
||||
key (str):
|
||||
The key (looks like a path) to the value name.
|
||||
|
||||
:param bool use_32bit_registry: Accesses the 32bit portion of the registry
|
||||
on 64bit installations. On 32bit machines this is ignored.
|
||||
vname (str):
|
||||
The value name. These are the individual name/data pairs under the
|
||||
key. If not passed, the key (Default) value will be returned.
|
||||
|
||||
:return: A dictionary containing the passed settings as well as the
|
||||
value_data if successful. If unsuccessful, sets success to False.
|
||||
use_32bit_registry (bool):
|
||||
Accesses the 32bit portion of the registry on 64bit installations.
|
||||
On 32bit machines this is ignored.
|
||||
|
||||
:rtype: dict
|
||||
Returns:
|
||||
dict: A dictionary containing the passed settings as well as the
|
||||
value_data if successful. If unsuccessful, sets success to False.
|
||||
|
||||
If vname is not passed:
|
||||
bool: Returns False if the key is not found
|
||||
|
||||
- Returns the first unnamed value (Default) as a string.
|
||||
- Returns none if first unnamed value is empty.
|
||||
- Returns False if key not found.
|
||||
If vname is not passed:
|
||||
|
||||
- Returns the first unnamed value (Default) as a string.
|
||||
- Returns none if first unnamed value is empty.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
The following will get the value of the ``version`` value name in the
|
||||
``HKEY_LOCAL_MACHINE\\SOFTWARE\\Salt`` key
|
||||
|
||||
salt '*' reg.read_value HKEY_LOCAL_MACHINE 'SOFTWARE\Salt' 'version'
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' reg.read_value HKEY_LOCAL_MACHINE 'SOFTWARE\Salt' 'version'
|
||||
|
||||
CLI Example:
|
||||
|
||||
The following will get the default value of the
|
||||
``HKEY_LOCAL_MACHINE\\SOFTWARE\\Salt`` key
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' reg.read_value HKEY_LOCAL_MACHINE 'SOFTWARE\Salt'
|
||||
'''
|
||||
return __utils__['reg.read_value'](hive=hive,
|
||||
key=key,
|
||||
|
@ -205,98 +281,114 @@ def set_value(hive,
|
|||
use_32bit_registry=False,
|
||||
volatile=False):
|
||||
'''
|
||||
Sets a registry value entry or the default value for a key.
|
||||
Sets a value in the registry. If ``vname`` is passed, it will be the value
|
||||
for that value name, otherwise it will be the default value for the
|
||||
specified key
|
||||
|
||||
:param str hive: The name of the hive. Can be one of the following
|
||||
Args:
|
||||
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
hive (str):
|
||||
The name of the hive. Can be one of the following
|
||||
|
||||
:param str key: The key (looks like a path) to the value name.
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
|
||||
:param str vname: The value name. These are the individual name/data pairs
|
||||
under the key. If not passed, the key (Default) value will be set.
|
||||
key (str):
|
||||
The key (looks like a path) to the value name.
|
||||
|
||||
:param object vdata: The value data to be set.
|
||||
What the type of this parameter
|
||||
should be is determined by the value of the vtype
|
||||
parameter. The correspondence
|
||||
is as follows:
|
||||
vname (str):
|
||||
The value name. These are the individual name/data pairs under the
|
||||
key. If not passed, the key (Default) value will be set.
|
||||
|
||||
.. glossary::
|
||||
vdata (str, int, list, bytes):
|
||||
The value you'd like to set. If a value name (vname) is passed, this
|
||||
will be the data for that value name. If not, this will be the
|
||||
(Default) value for the key.
|
||||
|
||||
REG_BINARY
|
||||
binary data (i.e. str in python version < 3 and bytes in version >=3)
|
||||
REG_DWORD
|
||||
int
|
||||
REG_EXPAND_SZ
|
||||
str
|
||||
REG_MULTI_SZ
|
||||
list of objects of type str
|
||||
REG_SZ
|
||||
str
|
||||
The type of data this parameter expects is determined by the value
|
||||
type specified in ``vtype``. The correspondence is as follows:
|
||||
|
||||
:param str vtype: The value type.
|
||||
The possible values of the vtype parameter are indicated
|
||||
above in the description of the vdata parameter.
|
||||
- REG_BINARY: Binary data (str in Py2, bytes in Py3)
|
||||
- REG_DWORD: int
|
||||
- REG_EXPAND_SZ: str
|
||||
- REG_MULTI_SZ: list of str
|
||||
- REG_QWORD: int
|
||||
- REG_SZ: str
|
||||
|
||||
:param bool use_32bit_registry: Sets the 32bit portion of the registry on
|
||||
64bit installations. On 32bit machines this is ignored.
|
||||
.. note::
|
||||
When setting REG_BINARY, string data will be converted to
|
||||
binary.
|
||||
|
||||
:param bool volatile: When this parameter has a value of True, the registry key will be
|
||||
made volatile (i.e. it will not persist beyond a system reset or shutdown).
|
||||
This parameter only has an effect when a key is being created and at no
|
||||
other time.
|
||||
.. note::
|
||||
The type for the (Default) value is always REG_SZ and cannot be
|
||||
changed.
|
||||
|
||||
:return: Returns True if successful, False if not
|
||||
:rtype: bool
|
||||
.. note::
|
||||
This parameter is optional. If ``vdata`` is not passed, the Key
|
||||
will be created with no associated item/value pairs.
|
||||
|
||||
vtype (str):
|
||||
The value type. The possible values of the vtype parameter are
|
||||
indicated above in the description of the vdata parameter.
|
||||
|
||||
use_32bit_registry (bool):
|
||||
Sets the 32bit portion of the registry on 64bit installations. On
|
||||
32bit machines this is ignored.
|
||||
|
||||
volatile (bool):
|
||||
When this parameter has a value of True, the registry key will be
|
||||
made volatile (i.e. it will not persist beyond a system reset or
|
||||
shutdown). This parameter only has an effect when a key is being
|
||||
created and at no other time.
|
||||
|
||||
Returns:
|
||||
bool: True if successful, otherwise False
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
This will set the version value to 2015.5.2 in the SOFTWARE\\Salt key in
|
||||
the HKEY_LOCAL_MACHINE hive
|
||||
|
||||
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2'
|
||||
.. code-block:: bash
|
||||
|
||||
This function is strict about the type of vdata. For instance the
|
||||
the next example will fail because vtype has a value of REG_SZ and vdata
|
||||
has a type of int (as opposed to str as expected).
|
||||
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2'
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
This function is strict about the type of vdata. For instance this
|
||||
example will fail because vtype has a value of REG_SZ and vdata has a
|
||||
type of int (as opposed to str as expected).
|
||||
|
||||
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2' \\
|
||||
vtype=REG_SZ vdata=0
|
||||
.. code-block:: bash
|
||||
|
||||
However, this next example where vdata is properly quoted should succeed.
|
||||
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'str_data' 1.2
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
In this next example vdata is properly quoted and should succeed.
|
||||
|
||||
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2' \\
|
||||
vtype=REG_SZ vdata="'0'"
|
||||
.. code-block:: bash
|
||||
|
||||
An example of using vtype REG_BINARY is as follows:
|
||||
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'str_data' vtype=REG_SZ vdata="'1.2'"
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
This is an example of using vtype REG_BINARY.
|
||||
|
||||
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2' \\
|
||||
vtype=REG_BINARY vdata='!!binary d2hhdCdzIHRoZSBwb2ludA=='
|
||||
.. code-block:: bash
|
||||
|
||||
An example of using vtype REG_LIST is as follows:
|
||||
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'bin_data' vtype=REG_BINARY vdata='Salty Data'
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
An example of using vtype REG_MULTI_SZ is as follows:
|
||||
|
||||
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2' \\
|
||||
vtype=REG_LIST vdata='[a,b,c]'
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'list_data' vtype=REG_MULTI_SZ vdata='["Salt", "is", "great"]'
|
||||
'''
|
||||
return __utils__['reg.set_value'](hive=hive,
|
||||
key=key,
|
||||
|
@ -311,33 +403,38 @@ def delete_key_recursive(hive, key, use_32bit_registry=False):
|
|||
'''
|
||||
.. versionadded:: 2015.5.4
|
||||
|
||||
Delete a registry key to include all subkeys.
|
||||
Delete a registry key to include all subkeys and value/data pairs.
|
||||
|
||||
:param hive: The name of the hive. Can be one of the following
|
||||
Args:
|
||||
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
hive (str):
|
||||
The name of the hive. Can be one of the following
|
||||
|
||||
:param key: The key to remove (looks like a path)
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
|
||||
:param bool use_32bit_registry: Deletes the 32bit portion of the registry on
|
||||
64bit installations. On 32bit machines this is ignored.
|
||||
key (str):
|
||||
The key to remove (looks like a path)
|
||||
|
||||
:return: A dictionary listing the keys that deleted successfully as well as
|
||||
those that failed to delete.
|
||||
:rtype: dict
|
||||
use_32bit_registry (bool):
|
||||
Deletes the 32bit portion of the registry on 64bit
|
||||
installations. On 32bit machines this is ignored.
|
||||
|
||||
The following example will remove ``salt`` and all its subkeys from the
|
||||
``SOFTWARE`` key in ``HKEY_LOCAL_MACHINE``:
|
||||
Returns:
|
||||
dict: A dictionary listing the keys that deleted successfully as well as
|
||||
those that failed to delete.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
The following example will remove ``delete_me`` and all its subkeys from the
|
||||
``SOFTWARE`` key in ``HKEY_LOCAL_MACHINE``:
|
||||
|
||||
salt '*' reg.delete_key_recursive HKLM SOFTWARE\\salt
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' reg.delete_key_recursive HKLM SOFTWARE\\delete_me
|
||||
'''
|
||||
return __utils__['reg.delete_key_recursive'](hive=hive,
|
||||
key=key,
|
||||
|
@ -348,30 +445,36 @@ def delete_value(hive, key, vname=None, use_32bit_registry=False):
|
|||
'''
|
||||
Delete a registry value entry or the default value for a key.
|
||||
|
||||
:param str hive: The name of the hive. Can be one of the following
|
||||
Args:
|
||||
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
hive (str):
|
||||
The name of the hive. Can be one of the following
|
||||
|
||||
:param str key: The key (looks like a path) to the value name.
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
|
||||
:param str vname: The value name. These are the individual name/data pairs
|
||||
under the key. If not passed, the key (Default) value will be deleted.
|
||||
key (str):
|
||||
The key (looks like a path) to the value name.
|
||||
|
||||
:param bool use_32bit_registry: Deletes the 32bit portion of the registry on
|
||||
64bit installations. On 32bit machines this is ignored.
|
||||
vname (str):
|
||||
The value name. These are the individual name/data pairs under the
|
||||
key. If not passed, the key (Default) value will be deleted.
|
||||
|
||||
:return: Returns True if successful, False if not
|
||||
:rtype: bool
|
||||
use_32bit_registry (bool):
|
||||
Deletes the 32bit portion of the registry on 64bit installations. On
|
||||
32bit machines this is ignored.
|
||||
|
||||
Return:
|
||||
bool: True if successful, otherwise False
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' reg.delete_value HKEY_CURRENT_USER 'SOFTWARE\\Salt' 'version'
|
||||
salt '*' reg.delete_value HKEY_CURRENT_USER 'SOFTWARE\\Salt' 'version'
|
||||
'''
|
||||
return __utils__['reg.delete_value'](hive=hive,
|
||||
key=key,
|
||||
|
@ -385,32 +488,30 @@ def import_file(source, use_32bit_registry=False):
|
|||
|
||||
.. versionadded:: 2018.3.0
|
||||
|
||||
Usage:
|
||||
Args:
|
||||
|
||||
source (str):
|
||||
The full path of the ``REG`` file. This can be either a local file
|
||||
path or a URL type supported by salt (e.g. ``salt://salt_master_path``)
|
||||
|
||||
use_32bit_registry (bool):
|
||||
If the value of this parameter is ``True`` then the ``REG`` file
|
||||
will be imported into the Windows 32 bit registry. Otherwise the
|
||||
Windows 64 bit registry will be used.
|
||||
|
||||
Returns:
|
||||
bool: True if successful, otherwise an error is raised
|
||||
|
||||
Raises:
|
||||
ValueError: If the value of ``source`` is an invalid path or otherwise
|
||||
causes ``cp.cache_file`` to return ``False``
|
||||
CommandExecutionError: If ``reg.exe`` exits with a non-0 exit code
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
.. code-block:: bash
|
||||
|
||||
salt machine1 reg.import_file salt://win/printer_config/110_Canon/postinstall_config.reg
|
||||
|
||||
:param str source: The full path of the ``REG`` file. This
|
||||
can be either a local file path or a URL type supported by salt
|
||||
(e.g. ``salt://salt_master_path``).
|
||||
|
||||
:param bool use_32bit_registry: If the value of this parameter is ``True``
|
||||
then the ``REG`` file will be imported into the Windows 32 bit registry.
|
||||
Otherwise the Windows 64 bit registry will be used.
|
||||
|
||||
:return: If the value of ``source`` is an invalid path or otherwise
|
||||
causes ``cp.cache_file`` to return ``False`` then
|
||||
the function will not return and
|
||||
a ``ValueError`` exception will be raised.
|
||||
If ``reg.exe`` exits with a non-0 exit code, then
|
||||
a ``CommandExecutionError`` exception will be
|
||||
raised. On success this function will return
|
||||
``True``.
|
||||
|
||||
:rtype: bool
|
||||
salt machine1 reg.import_file salt://win/printer_config/110_Canon/postinstall_config.reg
|
||||
|
||||
'''
|
||||
cache_path = __salt__['cp.cache_file'](source)
|
||||
|
|
|
@ -12,11 +12,12 @@ Hives
|
|||
-----
|
||||
|
||||
This is the top level of the registry. They all begin with HKEY.
|
||||
- HKEY_CLASSES_ROOT (HKCR)
|
||||
- HKEY_CURRENT_USER(HKCU)
|
||||
- HKEY_LOCAL MACHINE (HKLM)
|
||||
- HKEY_USER (HKU)
|
||||
- HKEY_CURRENT_CONFIG
|
||||
|
||||
- HKEY_CLASSES_ROOT (HKCR)
|
||||
- HKEY_CURRENT_USER(HKCU)
|
||||
- HKEY_LOCAL MACHINE (HKLM)
|
||||
- HKEY_USER (HKU)
|
||||
- HKEY_CURRENT_CONFIG
|
||||
|
||||
----
|
||||
Keys
|
||||
|
@ -30,30 +31,38 @@ Values or Entries
|
|||
-----------------
|
||||
|
||||
Values or Entries are the name/data pairs beneath the keys and subkeys. All keys
|
||||
have a default name/data pair. It is usually "(Default)"="(value not set)". The
|
||||
actual value for the name and the date is Null. The registry editor will display
|
||||
"(Default)" and "(value not set)".
|
||||
have a default name/data pair. The name is ``(Default)`` with a displayed value
|
||||
of ``(value not set)``. The actual value is Null.
|
||||
|
||||
-------
|
||||
Example
|
||||
-------
|
||||
|
||||
The following example is taken from the windows startup portion of the registry:
|
||||
```
|
||||
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
|
||||
"RTHDVCPL"="\"C:\\Program Files\\Realtek\\Audio\\HDA\\RtkNGUI64.exe\" -s"
|
||||
"NvBackend"="\"C:\\Program Files (x86)\\NVIDIA Corporation\\Update Core\\NvBackend.exe\""
|
||||
"BTMTrayAgent"="rundll32.exe \"C:\\Program Files (x86)\\Intel\\Bluetooth\\btmshellex.dll\",TrayApp"
|
||||
```
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
|
||||
"RTHDVCPL"="\"C:\\Program Files\\Realtek\\Audio\\HDA\\RtkNGUI64.exe\" -s"
|
||||
"NvBackend"="\"C:\\Program Files (x86)\\NVIDIA Corporation\\Update Core\\NvBackend.exe\""
|
||||
"BTMTrayAgent"="rundll32.exe \"C:\\Program Files (x86)\\Intel\\Bluetooth\\btmshellex.dll\",TrayApp"
|
||||
|
||||
In this example these are the values for each:
|
||||
|
||||
Hive: `HKEY_LOCAL_MACHINE`
|
||||
Hive:
|
||||
``HKEY_LOCAL_MACHINE``
|
||||
|
||||
Key and subkeys: `SOFTWARE\Microsoft\Windows\CurrentVersion\Run`
|
||||
Key and subkeys:
|
||||
``SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run``
|
||||
|
||||
Value:
|
||||
- There are 3 value names: `RTHDVCPL`, `NvBackend`, and `BTMTrayAgent`
|
||||
- There are 3 value names:
|
||||
- `RTHDVCPL`
|
||||
- `NvBackend`
|
||||
- `BTMTrayAgent`
|
||||
- Each value name has a corresponding value
|
||||
|
||||
:depends: - salt.utils.win_reg
|
||||
'''
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
|
@ -70,19 +79,19 @@ def __virtual__():
|
|||
'''
|
||||
if 'reg.read_value' not in __utils__:
|
||||
return (False, 'reg state module failed to load: '
|
||||
'missing module function: reg.read_value')
|
||||
'missing util function: reg.read_value')
|
||||
|
||||
if 'reg.set_value' not in __utils__:
|
||||
return (False, 'reg state module failed to load: '
|
||||
'missing module function: reg.set_value')
|
||||
'missing util function: reg.set_value')
|
||||
|
||||
if 'reg.delete_value' not in __utils__:
|
||||
return (False, 'reg state module failed to load: '
|
||||
'missing module function: reg.delete_value')
|
||||
'missing util function: reg.delete_value')
|
||||
|
||||
if 'reg.delete_key_recursive' not in __utils__:
|
||||
return (False, 'reg state module failed to load: '
|
||||
'missing module function: reg.delete_key_recursive')
|
||||
'missing util function: reg.delete_key_recursive')
|
||||
|
||||
return 'reg'
|
||||
|
||||
|
@ -102,76 +111,145 @@ def present(name,
|
|||
vdata=None,
|
||||
vtype='REG_SZ',
|
||||
use_32bit_registry=False):
|
||||
'''
|
||||
r'''
|
||||
Ensure a registry key or value is present.
|
||||
|
||||
:param str name: A string value representing the full path of the key to
|
||||
include the HIVE, Key, and all Subkeys. For example:
|
||||
Args:
|
||||
|
||||
``HKEY_LOCAL_MACHINE\\SOFTWARE\\Salt``
|
||||
name (str):
|
||||
A string value representing the full path of the key to include the
|
||||
HIVE, Key, and all Subkeys. For example:
|
||||
|
||||
Valid hive values include:
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_USERS or HKU
|
||||
``HKEY_LOCAL_MACHINE\\SOFTWARE\\Salt``
|
||||
|
||||
:param str vname: The name of the value you'd like to create beneath the
|
||||
Key. If this parameter is not passed it will assume you want to set the
|
||||
(Default) value
|
||||
Valid hive values include:
|
||||
|
||||
:param str vdata: The value you'd like to set. If a value name (vname) is
|
||||
passed, this will be the data for that value name. If not, this will be the
|
||||
(Default) value for the key.
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_USERS or HKU
|
||||
|
||||
The type for the (Default) value is always REG_SZ and cannot be changed.
|
||||
This parameter is optional. If not passed, the Key will be created with no
|
||||
associated item/value pairs.
|
||||
vname (str):
|
||||
The name of the value you'd like to create beneath the Key. If this
|
||||
parameter is not passed it will assume you want to set the
|
||||
``(Default)`` value
|
||||
|
||||
:param str vtype: The value type for the data you wish to store in the
|
||||
registry. Valid values are:
|
||||
vdata (str, int, list, bytes):
|
||||
The value you'd like to set. If a value name (``vname``) is passed,
|
||||
this will be the data for that value name. If not, this will be the
|
||||
``(Default)`` value for the key.
|
||||
|
||||
- REG_BINARY
|
||||
- REG_DWORD
|
||||
- REG_EXPAND_SZ
|
||||
- REG_MULTI_SZ
|
||||
- REG_SZ (Default)
|
||||
The type of data this parameter expects is determined by the value
|
||||
type specified in ``vtype``. The correspondence is as follows:
|
||||
|
||||
:param bool use_32bit_registry: Use the 32bit portion of the registry.
|
||||
Applies only to 64bit windows. 32bit Windows will ignore this parameter.
|
||||
Default is False.
|
||||
- REG_BINARY: Binary data (str in Py2, bytes in Py3)
|
||||
- REG_DWORD: int
|
||||
- REG_EXPAND_SZ: str
|
||||
- REG_MULTI_SZ: list of str
|
||||
- REG_QWORD: int
|
||||
- REG_SZ: str
|
||||
|
||||
:return: Returns a dictionary showing the results of the registry operation.
|
||||
:rtype: dict
|
||||
.. note::
|
||||
When setting REG_BINARY, string data will be converted to
|
||||
binary automatically. To pass binary data, use the built-in
|
||||
yaml tag ``!!binary`` to denote the actual binary
|
||||
characters. For example, the following lines will both set
|
||||
the same data in the registry:
|
||||
|
||||
The following example will set the ``(Default)`` value for the
|
||||
``SOFTWARE\\Salt`` key in the ``HKEY_CURRENT_USER`` hive to ``2016.3.1``:
|
||||
- ``vdata: Salty Test``
|
||||
- ``vdata: !!binary U2FsdHkgVGVzdA==\n``
|
||||
|
||||
For more information about the ``!!binary`` tag see
|
||||
`here <http://yaml.org/type/binary.html>`_
|
||||
|
||||
.. note::
|
||||
The type for the ``(Default)`` value is always REG_SZ and cannot
|
||||
be changed. This parameter is optional. If not passed, the Key
|
||||
will be created with no associated item/value pairs.
|
||||
|
||||
vtype (str):
|
||||
The value type for the data you wish to store in the registry. Valid
|
||||
values are:
|
||||
|
||||
- REG_BINARY
|
||||
- REG_DWORD
|
||||
- REG_EXPAND_SZ
|
||||
- REG_MULTI_SZ
|
||||
- REG_QWORD
|
||||
- REG_SZ (Default)
|
||||
|
||||
use_32bit_registry (bool):
|
||||
Use the 32bit portion of the registry. Applies only to 64bit
|
||||
windows. 32bit Windows will ignore this parameter. Default is False.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary showing the results of the registry operation.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: yaml
|
||||
The following example will set the ``(Default)`` value for the
|
||||
``SOFTWARE\\Salt`` key in the ``HKEY_CURRENT_USER`` hive to
|
||||
``2016.3.1``:
|
||||
|
||||
HKEY_CURRENT_USER\\SOFTWARE\\Salt:
|
||||
reg.present:
|
||||
- vdata: 2016.3.1
|
||||
.. code-block:: yaml
|
||||
|
||||
The following example will set the value for the ``version`` entry under the
|
||||
``SOFTWARE\\Salt`` key in the ``HKEY_CURRENT_USER`` hive to ``2016.3.1``. The
|
||||
value will be reflected in ``Wow6432Node``:
|
||||
HKEY_CURRENT_USER\\SOFTWARE\\Salt:
|
||||
reg.present:
|
||||
- vdata: 2016.3.1
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: yaml
|
||||
The following example will set the value for the ``version`` entry under
|
||||
the ``SOFTWARE\\Salt`` key in the ``HKEY_CURRENT_USER`` hive to
|
||||
``2016.3.1``. The value will be reflected in ``Wow6432Node``:
|
||||
|
||||
HKEY_CURRENT_USER\\SOFTWARE\\Salt:
|
||||
reg.present:
|
||||
- vname: version
|
||||
- vdata: 2016.3.1
|
||||
.. code-block:: yaml
|
||||
|
||||
In the above example the path is interpreted as follows:
|
||||
- ``HKEY_CURRENT_USER`` is the hive
|
||||
- ``SOFTWARE\\Salt`` is the key
|
||||
- ``vname`` is the value name ('version') that will be created under the key
|
||||
- ``vdata`` is the data that will be assigned to 'version'
|
||||
HKEY_CURRENT_USER\\SOFTWARE\\Salt:
|
||||
reg.present:
|
||||
- vname: version
|
||||
- vdata: 2016.3.1
|
||||
|
||||
In the above example the path is interpreted as follows:
|
||||
|
||||
- ``HKEY_CURRENT_USER`` is the hive
|
||||
- ``SOFTWARE\\Salt`` is the key
|
||||
- ``vname`` is the value name ('version') that will be created under the key
|
||||
- ``vdata`` is the data that will be assigned to 'version'
|
||||
|
||||
Example:
|
||||
|
||||
Binary data can be set in two ways. The following two examples will set
|
||||
a binary value of ``Salty Test``
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
no_conversion:
|
||||
reg.present:
|
||||
- name: HKLM\SOFTWARE\SaltTesting
|
||||
- vname: test_reg_binary_state
|
||||
- vdata: Salty Test
|
||||
- vtype: REG_BINARY
|
||||
|
||||
conversion:
|
||||
reg.present:
|
||||
- name: HKLM\SOFTWARE\SaltTesting
|
||||
- vname: test_reg_binary_state_with_tag
|
||||
- vdata: !!binary U2FsdHkgVGVzdA==\n
|
||||
- vtype: REG_BINARY
|
||||
|
||||
Example:
|
||||
|
||||
To set a ``REG_MULTI_SZ`` value:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
reg_multi_sz:
|
||||
reg.present:
|
||||
- name: HKLM\SOFTWARE\Salt
|
||||
- vname: reg_multi_sz
|
||||
- vdata:
|
||||
- list item 1
|
||||
- list item 2
|
||||
'''
|
||||
ret = {'name': name,
|
||||
'result': True,
|
||||
|
@ -226,39 +304,42 @@ def absent(name, vname=None, use_32bit_registry=False):
|
|||
'''
|
||||
Ensure a registry value is removed. To remove a key use key_absent.
|
||||
|
||||
:param str name: A string value representing the full path of the key to
|
||||
include the HIVE, Key, and all Subkeys. For example:
|
||||
Args:
|
||||
name (str):
|
||||
A string value representing the full path of the key to include the
|
||||
HIVE, Key, and all Subkeys. For example:
|
||||
|
||||
``HKEY_LOCAL_MACHINE\\SOFTWARE\\Salt``
|
||||
``HKEY_LOCAL_MACHINE\\SOFTWARE\\Salt``
|
||||
|
||||
Valid hive values include:
|
||||
Valid hive values include:
|
||||
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_USERS or HKU
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_USERS or HKU
|
||||
|
||||
:param str vname: The name of the value you'd like to create beneath the
|
||||
Key. If this parameter is not passed it will assume you want to set the
|
||||
(Default) value
|
||||
vname (str):
|
||||
The name of the value you'd like to create beneath the Key. If this
|
||||
parameter is not passed it will assume you want to set the
|
||||
``(Default)`` value
|
||||
|
||||
:param bool use_32bit_registry: Use the 32bit portion of the registry.
|
||||
Applies only to 64bit windows. 32bit Windows will ignore this parameter.
|
||||
Default is False.
|
||||
use_32bit_registry (bool):
|
||||
Use the 32bit portion of the registry. Applies only to 64bit
|
||||
windows. 32bit Windows will ignore this parameter. Default is False.
|
||||
|
||||
:return: Returns a dictionary showing the results of the registry operation.
|
||||
:rtype: dict
|
||||
Returns:
|
||||
dict: A dictionary showing the results of the registry operation.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: yaml
|
||||
.. code-block:: yaml
|
||||
|
||||
'HKEY_CURRENT_USER\\SOFTWARE\\Salt':
|
||||
reg.absent
|
||||
- vname: version
|
||||
'HKEY_CURRENT_USER\\SOFTWARE\\Salt':
|
||||
reg.absent
|
||||
- vname: version
|
||||
|
||||
In the above example the value named ``version`` will be removed from
|
||||
the SOFTWARE\\Salt key in the HKEY_CURRENT_USER hive. If ``vname`` was not
|
||||
passed, the (Default) value would be deleted.
|
||||
In the above example the value named ``version`` will be removed from
|
||||
the SOFTWARE\\Salt key in the HKEY_CURRENT_USER hive. If ``vname`` was
|
||||
not passed, the ``(Default)`` value would be deleted.
|
||||
'''
|
||||
ret = {'name': name,
|
||||
'result': True,
|
||||
|
@ -304,39 +385,43 @@ def key_absent(name, use_32bit_registry=False):
|
|||
r'''
|
||||
.. versionadded:: 2015.5.4
|
||||
|
||||
Ensure a registry key is removed. This will remove a key and all value
|
||||
entries it contains. It will fail if the key contains subkeys.
|
||||
Ensure a registry key is removed. This will remove the key, subkeys, and all
|
||||
value entries.
|
||||
|
||||
:param str name: A string representing the full path to the key to be
|
||||
removed to include the hive and the keypath. The hive can be any of the
|
||||
following:
|
||||
Args:
|
||||
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
name (str):
|
||||
A string representing the full path to the key to be removed to
|
||||
include the hive and the keypath. The hive can be any of the
|
||||
following:
|
||||
|
||||
:param bool use_32bit_registry: Use the 32bit portion of the registry.
|
||||
Applies only to 64bit windows. 32bit Windows will ignore this parameter.
|
||||
Default is False.
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
|
||||
:return: Returns a dictionary showing the results of the registry operation.
|
||||
:rtype: dict
|
||||
use_32bit_registry (bool):
|
||||
Use the 32bit portion of the registry. Applies only to 64bit
|
||||
windows. 32bit Windows will ignore this parameter. Default is False.
|
||||
|
||||
The following example will delete the ``SOFTWARE\Salt`` key and all subkeys
|
||||
under the ``HKEY_CURRENT_USER`` hive.
|
||||
Returns:
|
||||
dict: A dictionary showing the results of the registry operation.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: yaml
|
||||
CLI Example:
|
||||
|
||||
'HKEY_CURRENT_USER\SOFTWARE\Salt':
|
||||
reg.key_absent:
|
||||
- force: True
|
||||
The following example will delete the ``SOFTWARE\DeleteMe`` key in the
|
||||
``HKEY_LOCAL_MACHINE` hive including all its subkeys and value pairs.
|
||||
|
||||
In the above example the path is interpreted as follows:
|
||||
.. code-block:: yaml
|
||||
|
||||
- ``HKEY_CURRENT_USER`` is the hive
|
||||
- ``SOFTWARE\Salt`` is the key
|
||||
remove_key_demo:
|
||||
reg.key_absent:
|
||||
- name: HKEY_CURRENT_USER\SOFTWARE\DeleteMe
|
||||
|
||||
In the above example the path is interpreted as follows:
|
||||
|
||||
- ``HKEY_CURRENT_USER`` is the hive
|
||||
- ``SOFTWARE\DeleteMe`` is the key
|
||||
'''
|
||||
ret = {'name': name,
|
||||
'result': True,
|
||||
|
@ -352,10 +437,10 @@ def key_absent(name, use_32bit_registry=False):
|
|||
ret['comment'] = '{0} is already absent'.format(name)
|
||||
return ret
|
||||
|
||||
ret['changes'] = {'reg': {
|
||||
'Removed': {
|
||||
'Key': r'{0}\{1}'.format(hive, key)
|
||||
}}}
|
||||
ret['changes'] = {
|
||||
'reg': {
|
||||
'Removed': {
|
||||
'Key': r'{0}\{1}'.format(hive, key)}}}
|
||||
|
||||
# Check for test option
|
||||
if __opts__['test']:
|
||||
|
|
|
@ -6,21 +6,23 @@ Manage the Windows registry
|
|||
Hives
|
||||
-----
|
||||
Hives are the main sections of the registry and all begin with the word HKEY.
|
||||
- HKEY_LOCAL_MACHINE
|
||||
- HKEY_CURRENT_USER
|
||||
- HKEY_USER
|
||||
|
||||
- HKEY_LOCAL_MACHINE
|
||||
- HKEY_CURRENT_USER
|
||||
- HKEY_USER
|
||||
|
||||
----
|
||||
Keys
|
||||
----
|
||||
Keys are the folders in the registry. Keys can have many nested subkeys. Keys
|
||||
can have a value assigned to them under the (Default)
|
||||
can have a value assigned to them under the (Default) value name
|
||||
|
||||
-----------------
|
||||
Values or Entries
|
||||
-----------------
|
||||
Values/Entries are name/data pairs. There can be many values in a key. The
|
||||
(Default) value corresponds to the Key, the rest are their own value pairs.
|
||||
(Default) value corresponds to the Key itself, the rest are their own name/value
|
||||
pairs.
|
||||
|
||||
:depends: - PyWin32
|
||||
'''
|
||||
|
@ -91,7 +93,8 @@ def _to_unicode(vdata):
|
|||
|
||||
class Registry(object): # pylint: disable=R0903
|
||||
'''
|
||||
Delay usage until this module is used
|
||||
This was put in a class to delay usage until this module is actually used
|
||||
This class contains all the lookup dicts for working with the registry
|
||||
'''
|
||||
def __init__(self):
|
||||
self.hkeys = {
|
||||
|
@ -157,14 +160,26 @@ class Registry(object): # pylint: disable=R0903
|
|||
|
||||
def key_exists(hive, key, use_32bit_registry=False):
|
||||
'''
|
||||
Check that the key is found in the registry
|
||||
Check that the key is found in the registry. This refers to keys and not
|
||||
value/data pairs.
|
||||
|
||||
:param str hive: The hive to connect to.
|
||||
:param str key: The key to check
|
||||
:param bool use_32bit_registry: Look in the 32bit portion of the registry
|
||||
Args:
|
||||
|
||||
:return: Returns True if found, False if not found
|
||||
:rtype: bool
|
||||
hive (str): The hive to connect to
|
||||
|
||||
key (str): The key to check
|
||||
|
||||
use_32bit_registry (bool): Look in the 32bit portion of the registry
|
||||
|
||||
Returns:
|
||||
bool: True if exists, otherwise False
|
||||
|
||||
Usage:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import salt.utils.win_reg
|
||||
winreg.key_exists(hive='HKLM', key='SOFTWARE\\Microsoft')
|
||||
'''
|
||||
local_hive = _to_unicode(hive)
|
||||
local_key = _to_unicode(key)
|
||||
|
@ -188,13 +203,19 @@ def broadcast_change():
|
|||
'''
|
||||
Refresh the windows environment.
|
||||
|
||||
Returns (bool): True if successful, otherwise False
|
||||
.. note::
|
||||
This will only effect new processes and windows. Services will not see
|
||||
the change until the system restarts.
|
||||
|
||||
CLI Example:
|
||||
Returns:
|
||||
bool: True if successful, otherwise False
|
||||
|
||||
.. code-block:: bash
|
||||
Usage:
|
||||
|
||||
salt '*' reg.broadcast_change
|
||||
.. code-block:: python
|
||||
|
||||
import salt.utils.win_reg
|
||||
winreg.broadcast_change()
|
||||
'''
|
||||
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms644952(v=vs.85).aspx
|
||||
_, res = win32gui.SendMessageTimeout(
|
||||
|
@ -207,28 +228,34 @@ def list_keys(hive, key=None, use_32bit_registry=False):
|
|||
'''
|
||||
Enumerates the subkeys in a registry key or hive.
|
||||
|
||||
:param str hive: The name of the hive. Can be one of the following
|
||||
Args:
|
||||
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
hive (str):
|
||||
The name of the hive. Can be one of the following:
|
||||
|
||||
:param str key: The key (looks like a path) to the value name. If a key is
|
||||
not passed, the keys under the hive will be returned.
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
|
||||
:param bool use_32bit_registry: Accesses the 32bit portion of the registry
|
||||
on 64 bit installations. On 32bit machines this is ignored.
|
||||
key (str):
|
||||
The key (looks like a path) to the value name. If a key is not
|
||||
passed, the keys under the hive will be returned.
|
||||
|
||||
:return: A list of keys/subkeys under the hive or key.
|
||||
:rtype: list
|
||||
use_32bit_registry (bool):
|
||||
Accesses the 32bit portion of the registry on 64 bit installations.
|
||||
On 32bit machines this is ignored.
|
||||
|
||||
CLI Example:
|
||||
Returns:
|
||||
list: A list of keys/subkeys under the hive or key.
|
||||
|
||||
.. code-block:: bash
|
||||
Usage:
|
||||
|
||||
salt '*' reg.list_keys HKLM 'SOFTWARE'
|
||||
.. code-block:: python
|
||||
|
||||
import salt.utils.win_reg
|
||||
winreg.list_keys(hive='HKLM', key='SOFTWARE\\Microsoft')
|
||||
'''
|
||||
|
||||
local_hive = _to_unicode(hive)
|
||||
|
@ -265,30 +292,37 @@ def list_values(hive, key=None, use_32bit_registry=False, include_default=True):
|
|||
'''
|
||||
Enumerates the values in a registry key or hive.
|
||||
|
||||
:param str hive: The name of the hive. Can be one of the following
|
||||
Args:
|
||||
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
hive (str):
|
||||
The name of the hive. Can be one of the following:
|
||||
|
||||
:param str key: The key (looks like a path) to the value name. If a key is
|
||||
not passed, the values under the hive will be returned.
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
|
||||
:param bool use_32bit_registry: Accesses the 32bit portion of the registry
|
||||
on 64 bit installations. On 32bit machines this is ignored.
|
||||
key (str):
|
||||
The key (looks like a path) to the value name. If a key is not
|
||||
passed, the values under the hive will be returned.
|
||||
|
||||
:param bool include_default: Toggle whether to include the '(Default)' value.
|
||||
use_32bit_registry (bool):
|
||||
Accesses the 32bit portion of the registry on 64 bit installations.
|
||||
On 32bit machines this is ignored.
|
||||
|
||||
:return: A list of values under the hive or key.
|
||||
:rtype: list
|
||||
include_default (bool):
|
||||
Toggle whether to include the '(Default)' value.
|
||||
|
||||
CLI Example:
|
||||
Returns:
|
||||
list: A list of values under the hive or key.
|
||||
|
||||
.. code-block:: bash
|
||||
Usage:
|
||||
|
||||
salt '*' reg.list_values HKLM 'SYSTEM\\CurrentControlSet\\Services\\Tcpip'
|
||||
.. code-block:: python
|
||||
|
||||
import salt.utils.win_reg
|
||||
winreg.list_values(hive='HKLM', key='SYSTEM\\CurrentControlSet\\Services\\Tcpip')
|
||||
'''
|
||||
local_hive = _to_unicode(hive)
|
||||
local_key = _to_unicode(key)
|
||||
|
@ -335,40 +369,60 @@ def list_values(hive, key=None, use_32bit_registry=False, include_default=True):
|
|||
|
||||
def read_value(hive, key, vname=None, use_32bit_registry=False):
|
||||
r'''
|
||||
Reads a registry value entry or the default value for a key.
|
||||
Reads a registry value entry or the default value for a key. To read the
|
||||
default value, don't pass ``vname``
|
||||
|
||||
:param str hive: The name of the hive. Can be one of the following
|
||||
Args:
|
||||
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
hive (str): The name of the hive. Can be one of the following:
|
||||
|
||||
:param str key: The key (looks like a path) to the value name.
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
|
||||
:param str vname: The value name. These are the individual name/data pairs
|
||||
under the key. If not passed, the key (Default) value will be returned
|
||||
key (str):
|
||||
The key (looks like a path) to the value name.
|
||||
|
||||
:param bool use_32bit_registry: Accesses the 32bit portion of the registry
|
||||
on 64bit installations. On 32bit machines this is ignored.
|
||||
vname (str):
|
||||
The value name. These are the individual name/data pairs under the
|
||||
key. If not passed, the key (Default) value will be returned.
|
||||
|
||||
:return: A dictionary containing the passed settings as well as the
|
||||
value_data if successful. If unsuccessful, sets success to False.
|
||||
use_32bit_registry (bool):
|
||||
Accesses the 32bit portion of the registry on 64bit installations.
|
||||
On 32bit machines this is ignored.
|
||||
|
||||
:rtype: dict
|
||||
Returns:
|
||||
dict: A dictionary containing the passed settings as well as the
|
||||
value_data if successful. If unsuccessful, sets success to False.
|
||||
|
||||
If vname is not passed:
|
||||
bool: Returns False if the key is not found
|
||||
|
||||
- Returns the first unnamed value (Default) as a string.
|
||||
- Returns none if first unnamed value is empty.
|
||||
- Returns False if key not found.
|
||||
If vname is not passed:
|
||||
|
||||
CLI Example:
|
||||
- Returns the first unnamed value (Default) as a string.
|
||||
- Returns none if first unnamed value is empty.
|
||||
|
||||
.. code-block:: bash
|
||||
Usage:
|
||||
|
||||
salt '*' reg.read_value HKEY_LOCAL_MACHINE 'SOFTWARE\Salt' 'version'
|
||||
The following will get the value of the ``version`` value name in the
|
||||
``HKEY_LOCAL_MACHINE\\SOFTWARE\\Salt`` key
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import salt.utils.win_reg
|
||||
winreg.read_value(hive='HKLM', key='SOFTWARE\\Salt', vname='version')
|
||||
|
||||
Usage:
|
||||
|
||||
The following will get the default value of the
|
||||
``HKEY_LOCAL_MACHINE\\SOFTWARE\\Salt`` key
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import salt.utils.win_reg
|
||||
winreg.read_value(hive='HKLM', key='SOFTWARE\\Salt')
|
||||
'''
|
||||
# If no name is passed, the default value of the key will be returned
|
||||
# The value name is Default
|
||||
|
@ -438,98 +492,125 @@ def set_value(hive,
|
|||
use_32bit_registry=False,
|
||||
volatile=False):
|
||||
'''
|
||||
Sets a registry value entry or the default value for a key.
|
||||
Sets a value in the registry. If ``vname`` is passed, it will be the value
|
||||
for that value name, otherwise it will be the default value for the
|
||||
specified key
|
||||
|
||||
:param str hive: The name of the hive. Can be one of the following
|
||||
Args:
|
||||
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
hive (str):
|
||||
The name of the hive. Can be one of the following
|
||||
|
||||
:param str key: The key (looks like a path) to the value name.
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
|
||||
:param str vname: The value name. These are the individual name/data pairs
|
||||
under the key. If not passed, the key (Default) value will be set.
|
||||
key (str):
|
||||
The key (looks like a path) to the value name.
|
||||
|
||||
:param object vdata: The value data to be set.
|
||||
What the type of this parameter
|
||||
should be is determined by the value of the vtype
|
||||
parameter. The correspondence
|
||||
is as follows:
|
||||
vname (str):
|
||||
The value name. These are the individual name/data pairs under the
|
||||
key. If not passed, the key (Default) value will be set.
|
||||
|
||||
.. glossary::
|
||||
vdata (str, int, list, bytes):
|
||||
The value you'd like to set. If a value name (vname) is passed, this
|
||||
will be the data for that value name. If not, this will be the
|
||||
(Default) value for the key.
|
||||
|
||||
REG_BINARY
|
||||
binary data (i.e. str in python version < 3 and bytes in version >=3)
|
||||
REG_DWORD
|
||||
int
|
||||
REG_EXPAND_SZ
|
||||
str
|
||||
REG_MULTI_SZ
|
||||
list of objects of type str
|
||||
REG_SZ
|
||||
str
|
||||
The type of data this parameter expects is determined by the value
|
||||
type specified in ``vtype``. The correspondence is as follows:
|
||||
|
||||
:param str vtype: The value type.
|
||||
The possible values of the vtype parameter are indicated
|
||||
above in the description of the vdata parameter.
|
||||
- REG_BINARY: Binary data (str in Py2, bytes in Py3)
|
||||
- REG_DWORD: int
|
||||
- REG_EXPAND_SZ: str
|
||||
- REG_MULTI_SZ: list of str
|
||||
- REG_QWORD: int
|
||||
- REG_SZ: str
|
||||
|
||||
:param bool use_32bit_registry: Sets the 32bit portion of the registry on
|
||||
64bit installations. On 32bit machines this is ignored.
|
||||
.. note::
|
||||
When setting REG_BINARY, string data will be converted to
|
||||
binary. You can pass base64 encoded using the ``binascii``
|
||||
built-in module. Use ``binascii.b2a_base64('your data')``
|
||||
|
||||
:param bool volatile: When this parameter has a value of True, the registry key will be
|
||||
made volatile (i.e. it will not persist beyond a system reset or shutdown).
|
||||
This parameter only has an effect when a key is being created and at no
|
||||
other time.
|
||||
.. note::
|
||||
The type for the (Default) value is always REG_SZ and cannot be
|
||||
changed.
|
||||
|
||||
:return: Returns True if successful, False if not
|
||||
:rtype: bool
|
||||
.. note::
|
||||
This parameter is optional. If not passed, the Key will be
|
||||
created with no associated item/value pairs.
|
||||
|
||||
CLI Example:
|
||||
vtype (str):
|
||||
The value type. The possible values of the vtype parameter are
|
||||
indicated above in the description of the vdata parameter.
|
||||
|
||||
.. code-block:: bash
|
||||
use_32bit_registry (bool):
|
||||
Sets the 32bit portion of the registry on 64bit installations. On
|
||||
32bit machines this is ignored.
|
||||
|
||||
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2'
|
||||
volatile (bool):
|
||||
When this parameter has a value of True, the registry key will be
|
||||
made volatile (i.e. it will not persist beyond a system reset or
|
||||
shutdown). This parameter only has an effect when a key is being
|
||||
created and at no other time.
|
||||
|
||||
This function is strict about the type of vdata. For instance the
|
||||
the next example will fail because vtype has a value of REG_SZ and vdata
|
||||
has a type of int (as opposed to str as expected).
|
||||
Returns:
|
||||
bool: True if successful, otherwise False
|
||||
|
||||
CLI Example:
|
||||
Usage:
|
||||
|
||||
.. code-block:: bash
|
||||
This will set the version value to 2015.5.2 in the SOFTWARE\\Salt key in
|
||||
the HKEY_LOCAL_MACHINE hive
|
||||
|
||||
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2' \\
|
||||
vtype=REG_SZ vdata=0
|
||||
.. code-block:: python
|
||||
|
||||
However, this next example where vdata is properly quoted should succeed.
|
||||
import salt.utils.win_reg
|
||||
winreg.set_value(hive='HKLM', key='SOFTWARE\\Salt', vname='version', vdata='2015.5.2')
|
||||
|
||||
CLI Example:
|
||||
Usage:
|
||||
|
||||
.. code-block:: bash
|
||||
This function is strict about the type of vdata. For instance this
|
||||
example will fail because vtype has a value of REG_SZ and vdata has a
|
||||
type of int (as opposed to str as expected).
|
||||
|
||||
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2' \\
|
||||
vtype=REG_SZ vdata="'0'"
|
||||
.. code-block:: python
|
||||
|
||||
An example of using vtype REG_BINARY is as follows:
|
||||
import salt.utils.win_reg
|
||||
winreg.set_value(hive='HKLM', key='SOFTWARE\\Salt', vname='str_data', vdata=1.2)
|
||||
|
||||
CLI Example:
|
||||
Usage:
|
||||
|
||||
.. code-block:: bash
|
||||
In this next example vdata is properly quoted and should succeed.
|
||||
|
||||
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2' \\
|
||||
vtype=REG_BINARY vdata='!!binary d2hhdCdzIHRoZSBwb2ludA=='
|
||||
.. code-block:: python
|
||||
|
||||
An example of using vtype REG_LIST is as follows:
|
||||
import salt.utils.win_reg
|
||||
winreg.set_value(hive='HKLM', key='SOFTWARE\\Salt', vname='str_data', vdata='1.2')
|
||||
|
||||
CLI Example:
|
||||
Usage:
|
||||
|
||||
.. code-block:: bash
|
||||
This is an example of using vtype REG_BINARY. Both ``set_value``
|
||||
commands will set the same value ``Salty Test``
|
||||
|
||||
salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2' \\
|
||||
vtype=REG_LIST vdata='[a,b,c]'
|
||||
.. code-block:: python
|
||||
|
||||
import salt.utils.win_reg
|
||||
winreg.set_value(hive='HKLM', key='SOFTWARE\\Salt', vname='bin_data', vdata='Salty Test', vtype='REG_BINARY')
|
||||
|
||||
import binascii
|
||||
bin_data = binascii.b2a_base64('Salty Test')
|
||||
winreg.set_value(hive='HKLM', key='SOFTWARE\\Salt', vname='bin_data_encoded', vdata=bin_data, vtype='REG_BINARY')
|
||||
|
||||
Usage:
|
||||
|
||||
An example using vtype REG_MULTI_SZ is as follows:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import salt.utils.win_reg
|
||||
winreg.set_value(hive='HKLM', key='SOFTWARE\\Salt', vname='list_data', vdata=['Salt', 'is', 'great'], vtype='REG_MULTI_SZ')
|
||||
'''
|
||||
local_hive = _to_unicode(hive)
|
||||
local_key = _to_unicode(key)
|
||||
|
@ -571,20 +652,29 @@ def cast_vdata(vdata=None, vtype='REG_SZ'):
|
|||
|
||||
Args:
|
||||
|
||||
vdata (str, list, bin): The data to cast
|
||||
vdata (str, int, list, bytes): The data to cast
|
||||
|
||||
vtype (str):
|
||||
The type of data to be written to the registry. Must be one of the
|
||||
following:
|
||||
|
||||
- REG_BINARY
|
||||
- REG_DWORD
|
||||
- REG_EXPAND_SZ
|
||||
- REG_MULTI_SZ
|
||||
- REG_QWORD
|
||||
- REG_SZ
|
||||
|
||||
Returns:
|
||||
The vdata cast to the appropriate type. Will be unicode string, binary,
|
||||
list of unicode strings, or int
|
||||
|
||||
Usage:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import salt.utils.win_reg
|
||||
winreg.cast_vdata(vdata='This is the string', vtype='REG_SZ')
|
||||
'''
|
||||
# Check data type and cast to expected type
|
||||
# int will automatically become long on 64bit numbers
|
||||
|
@ -614,33 +704,39 @@ def delete_key_recursive(hive, key, use_32bit_registry=False):
|
|||
'''
|
||||
.. versionadded:: 2015.5.4
|
||||
|
||||
Delete a registry key to include all subkeys.
|
||||
Delete a registry key to include all subkeys and value/data pairs.
|
||||
|
||||
:param hive: The name of the hive. Can be one of the following
|
||||
Args:
|
||||
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
hive (str):
|
||||
The name of the hive. Can be one of the following
|
||||
|
||||
:param key: The key to remove (looks like a path)
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
|
||||
:param bool use_32bit_registry: Deletes the 32bit portion of the registry on
|
||||
64bit installations. On 32bit machines this is ignored.
|
||||
key (str):
|
||||
The key to remove (looks like a path)
|
||||
|
||||
:return: A dictionary listing the keys that deleted successfully as well as
|
||||
those that failed to delete.
|
||||
:rtype: dict
|
||||
use_32bit_registry (bool):
|
||||
Deletes the 32bit portion of the registry on 64bit
|
||||
installations. On 32bit machines this is ignored.
|
||||
|
||||
The following example will remove ``salt`` and all its subkeys from the
|
||||
``SOFTWARE`` key in ``HKEY_LOCAL_MACHINE``:
|
||||
Returns:
|
||||
dict: A dictionary listing the keys that deleted successfully as well as
|
||||
those that failed to delete.
|
||||
|
||||
CLI Example:
|
||||
Usage:
|
||||
|
||||
.. code-block:: bash
|
||||
The following example will remove ``salt`` and all its subkeys from the
|
||||
``SOFTWARE`` key in ``HKEY_LOCAL_MACHINE``:
|
||||
|
||||
salt '*' reg.delete_key_recursive HKLM SOFTWARE\\salt
|
||||
.. code-block:: python
|
||||
|
||||
import salt.utils.win_reg
|
||||
winreg.delete_key_recursive(hive='HKLM', key='SOFTWARE\\DeleteMe')
|
||||
'''
|
||||
|
||||
local_hive = _to_unicode(hive)
|
||||
|
@ -718,31 +814,37 @@ def delete_value(hive, key, vname=None, use_32bit_registry=False):
|
|||
'''
|
||||
Delete a registry value entry or the default value for a key.
|
||||
|
||||
:param str hive: The name of the hive. Can be one of the following
|
||||
Args:
|
||||
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
hive (str):
|
||||
The name of the hive. Can be one of the following
|
||||
|
||||
:param str key: The key (looks like a path) to the value name.
|
||||
- HKEY_LOCAL_MACHINE or HKLM
|
||||
- HKEY_CURRENT_USER or HKCU
|
||||
- HKEY_USER or HKU
|
||||
- HKEY_CLASSES_ROOT or HKCR
|
||||
- HKEY_CURRENT_CONFIG or HKCC
|
||||
|
||||
:param str vname: The value name. These are the individual name/data pairs
|
||||
under the key. If not passed, the key (Default) value will be deleted.
|
||||
key (str):
|
||||
The key (looks like a path) to the value name.
|
||||
|
||||
:param bool use_32bit_registry: Deletes the 32bit portion of the registry on
|
||||
64bit installations. On 32bit machines this is ignored.
|
||||
vname (str):
|
||||
The value name. These are the individual name/data pairs under the
|
||||
key. If not passed, the key (Default) value will be deleted.
|
||||
|
||||
:return: Returns True if successful, None if the value didn't exist, and
|
||||
False if unsuccessful
|
||||
:rtype: bool
|
||||
use_32bit_registry (bool):
|
||||
Deletes the 32bit portion of the registry on 64bit installations. On
|
||||
32bit machines this is ignored.
|
||||
|
||||
CLI Example:
|
||||
Return:
|
||||
bool: True if successful, otherwise False
|
||||
|
||||
.. code-block:: bash
|
||||
Usage:
|
||||
|
||||
salt '*' reg.delete_value HKEY_CURRENT_USER 'SOFTWARE\\Salt' 'version'
|
||||
.. code-block:: python
|
||||
|
||||
import salt.utils.win_reg
|
||||
winreg.delete_value(hive='HKLM', key='SOFTWARE\\SaltTest', vname='version')
|
||||
'''
|
||||
local_hive = _to_unicode(hive)
|
||||
local_key = _to_unicode(key)
|
||||
|
|
Loading…
Add table
Reference in a new issue