Minor changes

parent 66b6f10f
......@@ -29,20 +29,12 @@ enabled = yes
[date_time]
enabled = yes
[pam_authentication]
enabled = yes
[package_updates]
enabled = yes
[network]
enabled = yes
[postfix]
enabled = yes
[ssl]
enabled = yes
[maild]
enabled = yes
[ssl]
certificate_dir = /etc/opt/drweb.com/certs
# -*- coding: utf-8 -*-
import socket
import os
from yaml import dump, safe_load
from settingsd import const
from settingsd import config
from settingsd import service
from settingsd import shared
from settingsd import logger
import settingsd.tools as tools
from settingsd.tools.process import execProcess
import settingsd.tools.editors
from os import path
from jinja2 import Template
from jinja2.exceptions import TemplateSyntaxError
##### Private constants #####
SERVICE_NAME = "maild"
MAILD_METHODS_NAMESPACE = "maild"
MAILD_DRWEB_INI = "/etc/opt/drweb.com/drweb.ini"
MAILD_MILTER_HOOK = "/etc/opt/drweb.com/milterhook.lua"
##### Private classes #####
class MailD(service.FunctionObject) :
### DBus methods ###
@service.functionMethod(MAILD_METHODS_NAMESPACE, in_signature="sss", out_signature="s")
def regenerateDrwebIni(self, config_filename, drweb_ini_templates_dir, lua_templates_dir):
with open(config_filename, 'r') as maild_config:
config = safe_load(maild_config.read())
try:
lists_ctx = {
'links_blacklist': config['links_blacklist'],
'links_whitelist': config['links_whitelist']
}
self.renderTemplate(
config['template'], drweb_ini_templates_dir, config['settings'], MAILD_DRWEB_INI,
context=lists_ctx
)
self.renderTemplate(
config['template'], lua_templates_dir, config['settings'], MAILD_MILTER_HOOK,
context=lists_ctx
)
return ''
except TemplateSyntaxError as exc:
return str(exc)
def renderTemplate(self, template, templates_dir, settings, output_filename, context={}):
template_filename = path.join(templates_dir, template + '.tpl')
with open(template_filename, 'r') as template_text:
template = Template(template_text.read())
content = template.render(settings=settings, **context)
with open(output_filename, 'w+') as outfile:
outfile.write(content)
##### Public classes #####
class Service(service.Service) :
### Public ###
def initService(self) :
shared.Functions.addSharedObject(SERVICE_NAME, MailD(SERVICE_NAME, self))
### Private ###
@classmethod
def serviceName(self) :
return SERVICE_NAME
import os
from settingsd import const
from settingsd import config
from settingsd import service
from settingsd import shared
from pamela import authenticate, change_password, PAMError
SERVICE_NAME = "pam_authentication"
PAM_SERVICE_NAME = "settingsd"
class PamAuthentication(service.FunctionObject) :
@service.functionMethod("pam", in_signature="ss", out_signature="b")
def authenticate(self, login, password):
try:
authenticate(login, password, service=PAM_SERVICE_NAME)
return True
except PAMError:
return False
@service.functionMethod("pam", in_signature="sss", out_signature="b")
def change_password(self, login, old_password, new_password):
if len(new_password) == 0:
return False
if not self.authenticate(login, old_password):
return False
try:
change_password(login, new_password, service=PAM_SERVICE_NAME)
return True
except PAMError as err:
return False
@service.functionMethod("pam")
def restore_testing_user(self):
try:
with open('/etc/testing-user', 'r') as file:
login, password = file.read().split(' ', 1)
print(login, password)
change_password(login.strip(), password.strip(), service=PAM_SERVICE_NAME)
except FileNotFoundError:
pass
class Service(service.Service) :
def initService(self):
shared.Functions.addSharedObject(SERVICE_NAME, PamAuthentication(SERVICE_NAME, self))
@classmethod
def serviceName(self):
return SERVICE_NAME
# -*- coding: utf-8 -*-
import socket
import os
from yaml import dump, safe_load
from settingsd import const
from settingsd import config
from settingsd import service
from settingsd import shared
from settingsd import logger
import settingsd.tools as tools
from settingsd.tools.process import execProcess
import settingsd.tools.editors
from os import path
from jinja2 import Template
from jinja2.exceptions import TemplateSyntaxError
##### Private constants #####
SERVICE_NAME = "postfix"
POSTFIX_METHODS_NAMESPACE = "postfix"
POSTFIX_MAIN_CF = "/etc/postfix/main.cf"
##### Private classes #####
class Postfix(service.FunctionObject) :
### DBus methods ###
@service.functionMethod(POSTFIX_METHODS_NAMESPACE, in_signature="ss")
def generateAccessTable(self, filters_file_path, access_file_path):
with open(filters_file_path, 'r') as filters_file:
lists = safe_load(filters_file.read())
entries = []
for item in lists['whitelist']:
entries.append([item['key'], 'OK'])
for item in lists['blacklist']:
entries.append([item['key'], item['action'].upper()])
with open(access_file_path, 'w+') as access_file:
access_file.write('\n'.join([ ' '.join(pair) for pair in entries ]))
@service.functionMethod(POSTFIX_METHODS_NAMESPACE, in_signature="ss", out_signature="s")
def regenerateMainCf(self, config_filename, templates_dir):
with open(config_filename, 'r') as postfix_config:
config = safe_load(postfix_config.read())
try:
template_filename = path.join(templates_dir, config['template'] + '.tpl')
with open(template_filename, 'r') as template_text:
template = Template(template_text.read())
config_text = template.render(settings=config['settings'])
with open(POSTFIX_MAIN_CF, 'w+') as main_cf:
main_cf.write(config_text)
return ''
except TemplateSyntaxError as exc:
return str(exc)
##### Public classes #####
class Service(service.Service) :
### Public ###
def initService(self) :
shared.Functions.addSharedObject(SERVICE_NAME, Postfix(SERVICE_NAME, self))
### Private ###
@classmethod
def serviceName(self) :
return SERVICE_NAME
Metadata-Version: 2.1
Name: pamela
Version: 1.0.0
Summary: PAM interface using ctypes
Home-page: https://github.com/minrk/pamela
Author: Min RK
Author-email: benjaminrk@gmail.com
License: MIT
Keywords: pam,authentication
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Systems Administration :: Authentication/Directory
Description-Content-Type: text/markdown
# Pamela: yet another Python wrapper for PAM
There seems to be a glut of Python wrappers for PAM that have since been abandoned.
This repo merges two separate efforts:
- [gnosek/python-pam](https://github.com/gnosek/python-pam)
- adds wrappers for a few more calls, e.g. opening sessions
- raises PamError on failure instead of returning False, with informative error messages
- [simplepam](https://github.com/leonnnn/python3-simplepam)
- adds Python 3 support
- resets credentials after authentication, apparently for kerberos users
## Why?
Both projects appear to be abandoned, with no response to issues or pull requests in at least a year, and I need it for [JupyterHub](https://github.com/jupyter/jupyterhub).
## Use it
Install:
pip install pamela
Test:
python -m pamela -a `whoami`
__pycache__/pamela.cpython-36.pyc,,
pamela-1.0.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
pamela-1.0.0.dist-info/METADATA,sha256=Jq2Zs9sa58NCeMbwM8d6Oz_cfPEV6eIMLQqQogRgP90,1527
pamela-1.0.0.dist-info/RECORD,,
pamela-1.0.0.dist-info/WHEEL,sha256=J3CsTk7Mf2JNUyhImI-mjX-fmI4oDjyiXgWT4qgZiCE,110
pamela-1.0.0.dist-info/top_level.txt,sha256=sYmDCHiuiyLrWh33a_Rn49nqOVTmFg_MAtDQDbAWwwg,7
pamela.py,sha256=Q-4JPrPImmAArr2hDneNO2Wc40amVY0d8QmHK1XAF-c,15137
Wheel-Version: 1.0
Generator: bdist_wheel (0.31.0)
Root-Is-Purelib: true
Tag: py2-none-any
Tag: py3-none-any
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment