aboutsummaryrefslogtreecommitdiffstats
path: root/filter_plugins
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2018-03-17 14:04:34 +0800
committerAaron LI <aly@aaronly.me>2018-03-17 14:04:34 +0800
commite4367653d0f5d2a2b94b1f4e68f8dacd25086f76 (patch)
tree31be747a4aaed6a3c8a2c6b304e2a5cd5edb75d7 /filter_plugins
parentca8703974ede3950eaed0589dc55b7e606224f98 (diff)
downloadansible-dfly-vps-e4367653d0f5d2a2b94b1f4e68f8dacd25086f76.tar.bz2
Add custom filter mail.py with dovecot_makepass
Diffstat (limited to 'filter_plugins')
-rw-r--r--filter_plugins/mail.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/filter_plugins/mail.py b/filter_plugins/mail.py
new file mode 100644
index 0000000..1735e62
--- /dev/null
+++ b/filter_plugins/mail.py
@@ -0,0 +1,34 @@
+# Copyright (c) 2018 Aaron LI <aly@aaronly.me>
+# MIT License
+
+"""
+Custom Ansible template filters for "mail" role.
+"""
+
+import os
+import base64
+import crypt
+
+
+def dovecot_makepass(p):
+ """
+ Generate the salted hashed password for Dovecot using the
+ SHA512-CRYPT scheme.
+
+ Implement the "doveadm pw -s SHA512-CRYPT" command.
+
+ Dovecot password format: {<scheme>}$<type>$<salt>$<hash>
+ """
+ method, htype = "SHA512", "$6$"
+ scheme = method + "-CRYPT"
+ saltlen = 16
+ salt = os.urandom(saltlen)
+ salt = base64.b64encode(salt)[:saltlen]
+ return "{%s}%s" % (scheme, crypt.crypt(p, htype+salt))
+
+
+class FilterModule(object):
+ def filters(self):
+ return {
+ "dovecot_makepass": dovecot_makepass,
+ }