50-patina-first-user.rules (2182B)
1 // The greeter may change a few things on a machine fresh from the install: administer accounts, which 2 // is what makes the first one (ADR-0012), and set the time zone, the computer's name and join a Wi-Fi network (ADR-0019, the setup's steps). 3 // Only while no human account can log in: none exists (uid 1000 up, with a shell), or the ones that 4 // do are all still locked. That is what keeps the window open for the password and for taking the 5 // account back out if that fails, and closes it the moment a password is set. ADR-0012's alternative 6 // to a helper of our own. 7 // 8 // Any doubt closes it: if a check fails, the account counts as able to log in. 9 function noHumanCanLogIn() { 10 try { 11 var humans = polkit.spawn(["/usr/bin/getent", "passwd"]).split("\n") 12 .map(function(line) { return line.split(":"); }) 13 .filter(function(f) { 14 var uid = parseInt(f[2], 10); 15 return uid >= 1000 && uid < 60000 && !/(nologin|false)$/.test(f[6] || ""); 16 }); 17 var canLogIn = humans.filter(function(f) { 18 var locked = polkit.spawn(["/usr/bin/busctl", "--system", "get-property", 19 "org.freedesktop.Accounts", "/org/freedesktop/Accounts/User" + f[2], 20 "org.freedesktop.Accounts.User", "Locked"]); 21 return locked.indexOf("true") === -1; 22 }); 23 return canLogIn.length === 0; 24 } catch (e) { 25 return false; 26 } 27 } 28 29 var firstRunActions = [ 30 "org.freedesktop.accounts.user-administration", 31 "org.freedesktop.timedate1.set-timezone", 32 "org.freedesktop.hostname1.set-static-hostname", 33 // Joining a Wi-Fi network: scan, activate it, and save the connection for every user 34 // (settings.modify.system), which is what lets the account made next have the network too. 35 "org.freedesktop.NetworkManager.wifi.scan", 36 "org.freedesktop.NetworkManager.network-control", 37 "org.freedesktop.NetworkManager.settings.modify.system" 38 ]; 39 40 polkit.addRule(function(action, subject) { 41 if (subject.user !== "greetd") return; 42 if (firstRunActions.indexOf(action.id) === -1) return; 43 if (noHumanCanLogIn()) return polkit.Result.YES; 44 });