1
0
mirror of https://github.com/altlinux/gpupdate.git synced 2025-03-21 10:50:35 +03:00

Merge pull request #1 from altlinux/milestone1

[WIP] Milestone 1 fixes
This commit is contained in:
Evgeny Sinelnikov 2020-01-15 20:06:55 +04:00 committed by GitHub
commit f0f70f9897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 138 additions and 22 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
__pycache__
*~

View File

@ -3,6 +3,7 @@
## Contents
* [Introduction](#introduction)
* [Development](#development)
* [License](#license)
* * *
@ -12,6 +13,21 @@
GPOA is a facility to fetch, reinterpret and apply GPOs from Windows
Active Directory domains in UNIX environments.
## Development
This project needs some additional dependencies for development
purposes (static analisys):
* python3-module-setuptools
* python3-module-pip
* python3-module-pylint
And then you may install prospector like:
```sh
# pip install prospector[with_pyroma]
```
## License
Copyright (C) 2019-2020 BaseALT Ltd.

59
gpoa/.prospector.yaml Normal file
View File

@ -0,0 +1,59 @@
---
allow-shorthand: false
inherits:
- strictness_veryhigh
ignore-patterns:
- ^setup.py$
pylint:
disable:
- trailing-whitespace
- missing-final-newline
- too-few-public-methods
- too-many-public-methods
- deprecated-lambda
- bad-builtin
- star-args
- global-statement
- assignment-from-none
- unused-format-string-key
- W5103
options:
max-locals: 15
max-returns: 6
max-branches: 15
max-statements: 60
min-public-methods: 1
max-public-methods: 20
max-line-length: 99
pep8:
options:
max-line-length: 99
disable:
- E304
- E265
- E266
- W291
- W292
- W391
- N811
- N812
- N813
- N814
pyroma:
disable:
- PYR15
- PYR18
- PYR17
pep257:
disable:
- D400
- D401

View File

@ -32,7 +32,6 @@ import util.preg
from util.logging import slogm
class samba_backend(applier_backend):
__default_policy_path = '/usr/share/local-policy/default'
def __init__(self, sambacreds, username, domain):
self.storage = registry_factory('registry')

View File

@ -112,7 +112,7 @@ class frontend_manager:
self.machine_appliers['shortcuts'].apply()
self.machine_appliers['gsettings'].apply()
self.machine_appliers['cups'].apply()
self.machine_appliers['package'].apply()
#self.machine_appliers['package'].apply()
def user_apply(self):
'''

View File

@ -31,14 +31,14 @@ from .envvars import read_envvars
from .drives import read_drives
import util
import util.preg
from util.paths import (
default_policy_path,
cache_dir,
local_policy_cache
)
from util.logging import slogm
global __default_policy_path
__default_policy_path = '/usr/share/local-policy/default'
class gpt:
__default_policy_path = '/usr/share/local-policy/default'
__user_policy_mode_key = 'Software\\Policies\\Microsoft\\Windows\\System\\UserPolicyMode'
def __init__(self, gpt_path, sid):
@ -126,7 +126,10 @@ class gpt:
'''
search_path = os.path.join(self._machine_path, 'Preferences', 'Shortcuts')
if 'user' == part:
search_path = os.path.join(self._user_path, 'Preferences', 'Shortcuts')
try:
search_path = os.path.join(self._user_path, 'Preferences', 'Shortcuts')
except Exception as exc:
return None
if not search_path:
return None
@ -256,24 +259,27 @@ def lp2gpt():
'''
Convert local-policy to full-featured GPT.
'''
lppath = os.path.join(__default_policy_path, 'local.xml')
machinesettings = os.path.join(__default_policy_path, 'Machine')
lppath = os.path.join(default_policy_path(), 'local.xml')
# Load settings from XML PolFile
polparser = GPPolParser()
polfile = util.preg.load_preg(lppath)
polparser.pol_file = polfile
# Create target default policy directory if missing
destdir = os.path.join(local_policy_cache(), 'Machine')
os.makedirs(destdir, exist_ok=True)
# Write PReg
os.makedirs(machinesettings, exist_ok=True)
polparser.write_binary(os.path.join(machinesettings, 'Registry.pol'))
polparser.write_binary(os.path.join(destdir, 'Registry.pol'))
def get_local_gpt(sid):
'''
Convert default policy to GPT and create object out of it.
'''
logging.debug(slogm('Re-caching Local Policy'))
lp2gpt()
local_policy = gpt(__default_policy_path, sid)
local_policy = gpt(str(local_policy_cache()), sid)
local_policy.set_name('Local Policy')
return local_policy

View File

@ -59,8 +59,8 @@ class printer:
def __init__(self, ptype, name, status):
'''
ptype may be one of:
* LocalPrinter
* SharedPrinter
* LocalPrinter - IPP printer
* SharedPrinter - Samba printer
* PortPrinter
'''
self.printer_type = ptype

View File

@ -34,6 +34,7 @@ from sqlalchemy.orm import (
)
from util.logging import slogm
from util.paths import cache_dir
def mapping_factory(mapper_suffix):
exec(
@ -47,7 +48,7 @@ class mapped_id_{}(object):
return eval('mapped_id_{}'.format(mapper_suffix))
class sqlite_cache(cache):
__cache_dir = 'sqlite:////var/cache/gpupdate'
__cache_dir = 'sqlite:///{}'.format(cache_dir())
def __init__(self, cache_name):
self.cache_name = cache_name

View File

@ -16,9 +16,6 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import logging
from .registry import registry
import os
from sqlalchemy import (
@ -36,6 +33,8 @@ from sqlalchemy.orm import (
)
from util.logging import slogm
from util.paths import cache_dir
from .registry import registry
class samba_preg(object):
'''
@ -80,7 +79,7 @@ class printer_entry(object):
self.printer = pobj.to_json()
class sqlite_registry(registry):
__registry_path = 'sqlite:////var/cache/gpupdate'
__registry_path = 'sqlite:///{}'.format(cache_dir())
def __init__(self, db_name):
self.db_name = db_name

31
gpoa/util/paths.py Normal file
View File

@ -0,0 +1,31 @@
import pathlib
def default_policy_path():
'''
Returns path pointing to Default Policy directory.
'''
return pathlib.Path('/usr/share/local-policy/default')
def cache_dir():
'''
Returns path pointing to gpupdate's cache directory
'''
cachedir = pathlib.Path('/var/cache/gpupdate')
if not cachedir.exists():
cachedir.mkdir(parents=True, exist_ok=True)
return cachedir
def local_policy_cache():
'''
Returns path to directory where lies local policy settings cache
transformed into GPT.
'''
lpcache = pathlib.Path.joinpath(cache_dir(), 'local-policy')
if not lpcache.exists():
lpcache.mkdir(parents=True, exist_ok=True)
return lpcache

View File

@ -7,6 +7,7 @@ Description=gpupdate in userspace
Environment="PATH=/bin:/sbin:/usr/bin:/usr/sbin"
Type=notify
WatchdogSec=3600
TimeoutSec=3000
Restart=always
ExecStart=/usr/sbin/gpoa

View File

@ -3,8 +3,11 @@ Description=Group policy update for machine
After=sssd.service
[Service]
Type=oneshot
RemainAfterExit=true
Environment="PATH=/bin:/sbin:/usr/bin:/usr/sbin"
Type=notify
WatchdogSec=3600
TimeoutSec=3000
Restart=always
ExecStart=/usr/bin/gpupdate
StandardOutput=journal