summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/MDK/Common/System.pm26
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());
}