-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpambase.py
executable file
·127 lines (109 loc) · 3.87 KB
/
pambase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python3
import argparse
from jinja2 import Template, Environment, FileSystemLoader
import pathlib
def main():
parser = argparse.ArgumentParser(description="basic Gentoo PAM configuration files")
parser.add_argument(
"--gnome-keyring",
action="store_true",
help="enable pam_gnome_keyring.so module",
)
parser.add_argument("--caps", action="store_true", help="enable pam_cap.so module")
parser.add_argument(
"--passwdqc", action="store_true", help="enable pam_passwdqc.so module"
)
parser.add_argument(
"--pwhistory", action="store_true", help="enable pam_pwhistory.so module"
)
parser.add_argument(
"--pwquality", action="store_true", help="enable pam_pwquality.so module"
)
parser.add_argument(
"--openrc", action="store_true", help="enable pam_openrc.so module"
)
parser.add_argument(
"--elogind", action="store_true", help="enable pam_elogind.so module"
)
parser.add_argument(
"--systemd", action="store_true", help="enable pam_systemd.so module"
)
parser.add_argument(
"--homed", action="store_true", help="enable pam_systemd_home.so module"
)
parser.add_argument(
"--selinux", action="store_true", help="enable pam_selinux.so module"
)
parser.add_argument(
"--mktemp", action="store_true", help="enable pam_mktemp.so module"
)
parser.add_argument(
"--pam-ssh", action="store_true", help="enable pam_ssh.so module"
)
parser.add_argument(
"--securetty", action="store_true", help="enable pam_securetty.so module"
)
parser.add_argument(
"--shells", action="store_true", help="enable pam_shells.so module"
)
parser.add_argument("--sssd", action="store_true", help="enable sssd.so module")
parser.add_argument(
"--encrypt",
choices=["md5", "sha256", "sha512", "blowfish", "gost_yescrypt", "yescrypt"],
default="md5",
help="select encryption to use for passwords stored by pam_unix.so module",
)
parser.add_argument("--krb5", action="store_true", help="enable pam_krb5.so module")
parser.add_argument(
"--minimal", action="store_true", help="install minimalistic PAM stack"
)
parser.add_argument(
"--debug",
action="store_const",
const="debug",
default="",
help="enable debug for selected modules",
)
parser.add_argument(
"--nullok",
action="store_const",
const="nullok",
default="",
help="enable nullok option for pam_unix.so module",
)
parsed_args = parser.parse_args()
processed = process_args(parsed_args)
parse_templates(processed)
def process_args(args):
# make sure that output directory exists
pathlib.Path("stack").mkdir(parents=True, exist_ok=True)
output = vars(args)
return output
def parse_templates(processed_args):
load = FileSystemLoader("")
env = Environment(
loader=load, trim_blocks=True, lstrip_blocks=True, keep_trailing_newline=True
)
templates = [
"login",
"other",
"passwd",
"system-local-login",
"system-remote-login",
"su",
"system-auth",
"system-login",
"system-services",
]
for template_name in templates:
template = env.get_template("templates/{0}.tpl".format(template_name))
with open("stack/{0}".format(template_name), "w+") as output:
rendered_template = template.render(processed_args)
# Strip all intermediate lines to not worry about appeasing Jinja
lines = rendered_template.split("\n")
lines = [line.strip() for line in lines if line]
rendered_template = "\n".join(lines)
if rendered_template:
output.write(rendered_template + "\n")
if __name__ == "__main__":
main()