home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / system-tools-backends-2.0 / scripts / Users / Shells.pm < prev    next >
Encoding:
Perl POD Document  |  2006-08-14  |  2.3 KB  |  100 lines

  1. #-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. #
  3. # Copyright (C) 2000-2001 Ximian, Inc.
  4. #
  5. # Authors: Hans Petter Jansson <hpj@ximian.com>,
  6. #          Arturo Espinosa <arturo@ximian.com>,
  7. #          Tambet Ingo <tambet@ximian.com>.
  8. #          Grzegorz Golawski <grzegol@pld-linux.org> (PLD Support)
  9. #          Carlos Garnacho <carlosg@gnome.org>
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU Library General Public License as published
  13. # by the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. # GNU Library General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU Library General Public License
  22. # along with this program; if not, write to the Free Software
  23. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  24.  
  25. package Users::Shells;
  26.  
  27. use Utils::Util;
  28. use Utils::Report;
  29. use Utils::File;
  30. use Utils::Replace;
  31.  
  32. # Totally generic atm
  33. $shells_file = "/etc/shells";
  34.  
  35. sub get_files
  36. {
  37.   return $shells_file;
  38. }
  39.  
  40. sub get
  41. {
  42.   my ($ifh, @shells);
  43.  
  44.   # Init @shells, I think every *nix has /bin/false.
  45.   if (stat ("/bin/false"))
  46.   {
  47.     push @shells, "/bin/false";
  48.   }
  49.   
  50.   $ifh = &Utils::File::open_read_from_names($shells_file);
  51.   return unless $ifh;
  52.  
  53.   while (<$ifh>)
  54.   {
  55.     next if &Utils::Util::ignore_line ($_);
  56.     chomp;
  57.     push @shells, $_ if (stat ($_));
  58.   }
  59.  
  60.   &Utils::File::close_file ($ifh);
  61.  
  62.   return \@shells;
  63. }
  64.  
  65. sub set
  66. {
  67.   my ($shells) = @_;
  68.   my ($buff, $line, $nline);
  69.  
  70.   $buff = &Utils::File::load_buffer ($shells_file);
  71.   return unless $buff;
  72.  
  73.   &Utils::File::join_buffer_lines ($buff);
  74.   $nline = 0;
  75.  
  76.   # delete all file entries that really exist,
  77.   # this is done for not deleting entries that
  78.   # might be installed later
  79.   while ($nline <= $#$buff)
  80.   {
  81.     $line = $$buff[$nline];
  82.     chomp $line;
  83.  
  84.     if (!&Utils::Util::ignore_line ($line))
  85.     {
  86.       delete $$buff[$nline] if (stat ($line));
  87.     }
  88.  
  89.     $nline++;
  90.   }
  91.  
  92.   # Add shells list
  93.   foreach $line (@$shells)
  94.   {
  95.     push @$buff, "$line\n" if (stat ($line));
  96.   }
  97.  
  98.   &Utils::File::save_buffer ($buff, $shells_file);
  99. }
  100.