diff options
author | Colin Guthrie <colin@mageia.org> | 2014-11-17 16:43:34 +0000 |
---|---|---|
committer | Colin Guthrie <colin@mageia.org> | 2014-11-17 17:43:42 +0000 |
commit | deb5fedd10f1e367973f55ba82677c41e7ca4643 (patch) | |
tree | 914b4bb0eba542d899fb96cbbd92d0fc14567042 /lib/MDK/Common | |
parent | 492787b2ccc455e9b5970a544103a6c0776e9931 (diff) | |
download | perl-MDK-Common-deb5fedd10f1e367973f55ba82677c41e7ca4643.tar perl-MDK-Common-deb5fedd10f1e367973f55ba82677c41e7ca4643.tar.gz perl-MDK-Common-deb5fedd10f1e367973f55ba82677c41e7ca4643.tar.bz2 perl-MDK-Common-deb5fedd10f1e367973f55ba82677c41e7ca4643.tar.xz perl-MDK-Common-deb5fedd10f1e367973f55ba82677c41e7ca4643.zip |
Fix list_users() to filter on new uid range.
The first assigned uid has now changed to 1000 (from 500)
to fall in line with most other distros.
This number seems hardcoded in a few places to try to
do a little bit of refactoring and add a new exported
function, is_real_user(), to try and centralise this
logic a little.
This should ultimately fix the likes of drakboot's
autologin user list.
mga#14346
Diffstat (limited to 'lib/MDK/Common')
-rw-r--r-- | lib/MDK/Common/System.pm | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/MDK/Common/System.pm b/lib/MDK/Common/System.pm index cbd4d07..851a4f1 100644 --- a/lib/MDK/Common/System.pm +++ b/lib/MDK/Common/System.pm @@ -55,6 +55,10 @@ where each entry is [ magic_name, offset, string, offset, string, ... ]. return the list of users as given by C<getpwent> (see perlfunc) +=item is_real_user() + +checks whether or not the user is a system user or a real user + =item list_home() return the list of home (eg: /home/foo, /home/pixel, ...) @@ -65,8 +69,8 @@ return the directories where we can find dot files: homes, /root and /etc/skel =item list_users() -return the list of unprivilegied users (aka those whose uid is greater -than 500 and who are not "nobody"). +return the list of unprivilegied users (uses the is_real_user function to filter +out system users from the full list) =item syscall_(NAME, PARA) @@ -199,7 +203,7 @@ use MDK::Common::DataStructure; use Exporter; our @ISA = qw(Exporter); -our @EXPORT_OK = qw(%compat_arch $printable_chars $sizeof_int $bitof_int arch distrib typeFromMagic list_passwd list_home list_skels list_users syscall_ psizeof availableMemory availableRamMB gettimeofday unix2dos whereis_binary getVarsFromSh setVarsInSh setVarsInShMode addVarsInSh addVarsInShMode setExportedVarsInSh setExportedVarsInCsh template2file template2userfile read_gnomekderc update_gnomekderc fuzzy_pidofs); #); +our @EXPORT_OK = qw(%compat_arch $printable_chars $sizeof_int $bitof_int arch distrib typeFromMagic list_passwd is_real_user list_home list_skels list_users syscall_ psizeof availableMemory availableRamMB gettimeofday unix2dos whereis_binary getVarsFromSh setVarsInSh setVarsInShMode addVarsInSh addVarsInShMode setExportedVarsInSh setExportedVarsInCsh template2file template2userfile read_gnomekderc update_gnomekderc fuzzy_pidofs); #); our %EXPORT_TAGS = (all => [ @EXPORT_OK ]); @@ -288,8 +292,20 @@ sub list_passwd() { endpwent(); @l; } +sub is_real_user { + my ($username, $uid, $homedir, $shell) = @_; + + # We consider real users to be those users who: + # Have a UID >= 1000 + # or + # Have a UID >= 500 + # and have a homedir that is not / or does not start with /var or /run + # and have a shell that does not end in "nologin" or "false" + + ($uid >= 1000 || ($uid >= 500 && $homedir !~ /^\/($|var\/|run\/)/ && $shell !~ /(nologin|false)$/)) && $username ne "nobody"; +} sub list_home() { - MDK::Common::DataStructure::uniq(map { $_->[7] } grep { $_->[2] >= 500 } list_passwd()); + MDK::Common::DataStructure::uniq(map { $_->[7] } grep { is_real_user($_->[0], $_->[2], $_->[7], $_->[8]) } list_passwd()); } sub list_skels { my ($prefix, $suffix) = @_; @@ -297,7 +313,7 @@ sub list_skels { } sub list_users() { - MDK::Common::DataStructure::uniq(map { 500 <= $_->[2] && $_->[0] ne "nobody" ? $_->[0] : () } list_passwd()); + MDK::Common::DataStructure::uniq(map { is_real_user($_->[0], $_->[2], $_->[7], $_->[8]) ? $_->[0] : () } list_passwd()); } |