summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/MDK/Common/System.pm28
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/MDK/Common/System.pm b/lib/MDK/Common/System.pm
index 851a4f1..4319593 100644
--- a/lib/MDK/Common/System.pm
+++ b/lib/MDK/Common/System.pm
@@ -59,6 +59,10 @@ return the list of users as given by C<getpwent> (see perlfunc)
checks whether or not the user is a system user or a real user
+=item is_real_group()
+
+checks whether or not the group is a system group or a real group
+
=item list_home()
return the list of home (eg: /home/foo, /home/pixel, ...)
@@ -203,7 +207,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 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_OK = qw(%compat_arch $printable_chars $sizeof_int $bitof_int arch distrib typeFromMagic list_passwd is_real_user is_real_group 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 ]);
@@ -304,6 +308,28 @@ sub is_real_user {
($uid >= 1000 || ($uid >= 500 && $homedir !~ /^\/($|var\/|run\/)/ && $shell !~ /(nologin|false)$/)) && $username ne "nobody";
}
+sub is_real_group {
+ my ($groupname, $gid) = @_;
+
+ return 0 if $groupname eq "nogroup" || $gid < 500;
+ return 1 if $gid >= 1000;
+
+ # We are in the range 500-1000, so we need some heuristic.
+ # We consider ourselves a "real" group if this is the primary group of a user
+ # with the same name, or we have any member users who are "real"
+
+ my ($username,undef,$uid,$egid,undef,undef,undef,$homedir,$shell,undef) = getpwnam($groupname);
+ return 1 if $username == $groupname && $egid == $gid;
+
+ my (undef,undef,$egid,$members) = getgrnam($groupname);
+ return 0 if $egid != $gid;
+
+ foreach (split(' ', $members)) {
+ my ($username,undef,$uid,undef,undef,undef,undef,$homedir,$shell,undef) = getpwnam($_);
+ return 1 if is_real_user($username, $uid, $homedir, $shell);
+ }
+ return 0;
+}
sub list_home() {
MDK::Common::DataStructure::uniq(map { $_->[7] } grep { is_real_user($_->[0], $_->[2], $_->[7], $_->[8]) } list_passwd());
}