Skip to content

Commit 0c74ac1

Browse files
committed
luci-app-acl: enforce password policy
Password policy is enforced on acl if it is defined via plugin. Signed-off-by: Christian Korber <ckorber@tdt.de>
1 parent c7a456a commit 0c74ac1

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

applications/luci-app-acl/htdocs/luci-static/resources/view/system/acl.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
'require uci';
88
'require form';
99
'require tools.widgets as widgets';
10+
'require tools.password as pwtool';
1011

1112
const aclList = {};
1213

@@ -17,6 +18,28 @@ const callSetPassword = rpc.declare({
1718
expect: { result: 1}
1819
});
1920

21+
function checkPassword(value) {
22+
const uuid = '51af4ae847774aac863d4c94a9ba6d58';
23+
const pw_length = uci.get('luci_plugins', uuid, 'pw_length');
24+
const pw_digits = uci.get('luci_plugins', uuid, 'digits');
25+
const pw_ul = uci.get('luci_plugins', uuid, 'uc_lc');
26+
const special = uci.get('luci_plugins', uuid, 'special_characters');
27+
28+
if (pw_length && !pwtool.checkLength(value, pw_length))
29+
return _('Policy: min. length of %s characters').format(pw_length);
30+
31+
if (pw_digits && !pwtool.checkDigits(value))
32+
return _('Policy: contain digits');
33+
34+
if (pw_ul && !pwtool.checkUpperLower(value))
35+
return _('Policy: contain uppercase/lowercase');
36+
37+
if (special && !pwtool.checkSpecialChars(value))
38+
return _('Policy: contain special characters');
39+
40+
return true;
41+
}
42+
2043
function globListToRegExp(section_id, option) {
2144
const list = L.toArray(uci.get('rpcd', section_id, option));
2245
const positivePatterns = [];
@@ -170,7 +193,9 @@ return view.extend({
170193
return L.resolveDefault(fs.list('/usr/share/rpcd/acl.d'), []).then(function(entries) {
171194
const tasks = [
172195
L.resolveDefault(fs.stat('/usr/sbin/uhttpd'), null),
173-
fs.lines('/etc/passwd')
196+
fs.lines('/etc/passwd'),
197+
uci.load('rpcd'),
198+
uci.load('luci_plugins')
174199
];
175200

176201
for (let e of entries)
@@ -181,7 +206,7 @@ return view.extend({
181206
});
182207
},
183208

184-
render([has_uhttpd, passwd, ...acls]) {
209+
render([has_uhttpd, passwd, uci_rpcd, plugins, ...acls]) {
185210
ui.addNotification(null, E('p', [
186211
_('The LuCI ACL management is in an experimental stage! It does not yet work reliably with all applications')
187212
]), 'warning');
@@ -275,7 +300,7 @@ return view.extend({
275300
return _('Cannot encrypt plaintext password since uhttpd is not installed.');
276301
}
277302

278-
return true;
303+
return checkPassword(value);
279304
};
280305
o.write = function(section_id, value) {
281306
const variant = this.map.lookupOption('_variant', section_id)[0];

applications/luci-app-acl/root/usr/share/rpcd/acl.d/luci-app-acl.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"/usr/share/rpcd/acl.d": [ "list" ],
1111
"/usr/share/rpcd/acl.d/*.json": [ "read" ]
1212
},
13-
"uci": [ "rpcd" ]
13+
"uci": [ "rpcd", "luci_plugins" ]
1414
},
1515
"write": {
1616
"uci": [ "rpcd" ],

0 commit comments

Comments
 (0)