summaryrefslogtreecommitdiff
path: root/Users/Shells.pm
blob: 1c473ec71beb8c14fece16229f75550831a316fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
#
# Copyright (C) 2000-2001 Ximian, Inc.
#
# Authors: Hans Petter Jansson <hpj@ximian.com>,
#          Arturo Espinosa <arturo@ximian.com>,
#          Tambet Ingo <tambet@ximian.com>.
#          Grzegorz Golawski <grzegol@pld-linux.org> (PLD Support)
#          Carlos Garnacho <carlosg@gnome.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as published
# by the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

package Users::Shells;

use Utils::Util;
use Utils::Report;
use Utils::File;
use Utils::Replace;

# Totally generic atm
$shells_file = "/etc/shells";

sub get_files
{
  return $shells_file;
}

sub get
{
  my ($ifh, @shells);

  # Init @shells, I think every *nix has /bin/false.
  if (stat ("/bin/false"))
  {
    push @shells, "/bin/false";
  }
  
  $ifh = &Utils::File::open_read_from_names($shells_file);
  return unless $ifh;

  while (<$ifh>)
  {
    next if &Utils::Util::ignore_line ($_);
    chomp;
    push @shells, $_ if (stat ($_));
  }

  &Utils::File::close_file ($ifh);

  return \@shells;
}

sub set
{
  my ($shells) = @_;
  my ($buff, $line, $nline);

  $buff = &Utils::File::load_buffer ($shells_file);
  return unless $buff;

  &Utils::File::join_buffer_lines ($buff);
  $nline = 0;

  # delete all file entries that really exist,
  # this is done for not deleting entries that
  # might be installed later
  while ($nline <= $#$buff)
  {
    $line = $$buff[$nline];
    chomp $line;

    if (!&Utils::Util::ignore_line ($line))
    {
      delete $$buff[$nline] if (stat ($line));
    }

    $nline++;
  }

  # Add shells list
  foreach $line (@$shells)
  {
    push @$buff, "$line\n" if (stat ($line));
  }

  &Utils::File::save_buffer ($buff, $shells_file);
}