This file is indexed.

/usr/share/system-tools-backends-2.0/scripts/Users/Groups.pm is in system-tools-backends 2.10.2-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#-*- 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)
#
#
# 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::Groups;

# enum like for verbose group array positions
my $i = 0;
my $LOGIN  = $i++;
my $PASSWD = $i++;
my $GID    = $i++;
my $USERS  = $i++;

# quite generic data
$group_names = "/etc/group";

# Where are the tools?
$cmd_groupdel = &Utils::File::locate_tool ("groupdel");
$cmd_groupadd = &Utils::File::locate_tool ("groupadd");
$cmd_groupmod = &Utils::File::locate_tool ("groupmod");

$cmd_delgroup = &Utils::File::locate_tool ("delgroup");
$cmd_addgroup = &Utils::File::locate_tool ("addgroup");

$cmd_usermod  = &Utils::File::locate_tool ("usermod");
$cmd_gpasswd  = &Utils::File::locate_tool ("gpasswd");	
$cmd_pw       = &Utils::File::locate_tool ("pw");

sub del_group
{
  my ($group) = @_;

  # Make backups manually, otherwise they don't get backed up.
  &Utils::File::do_backup ($group_names);

  if ($Utils::Backend::tool{"system"} eq "FreeBSD")
  {
    @command = ($cmd_pw, "groupdel", "-n", $$group[$LOGIN]);
  }
  else
  {
    @command  = (($cmd_delgroup) ? $cmd_delgroup : $cmd_groupdel,
                 $$group[$LOGIN]);
  }

  &Utils::File::run (@command);
}

# This is only for Linux and SunOS,
# pw groupadd manages this in FreeBSD
sub add_user_to_group
{
  my ($group, $user) = @_;
  my (@command);

  if ($Utils::Backend::tool{"system"} eq "SunOS")
  {
    my ($groups, @arr);

    $groups = &Utils::File::run_backtick ("groups $user");
    $groups =~ s/.*://;
    chomp ($groups);

    @arr = split (/ /, $groups);
    push @arr, $group;
    $groups = join (',', @arr);
    $groups =~ s/^,//;
    $groups =~ s/,$//;

    @command = ($cmd_usermod, "-G", $groups, $user);
  }
  else
  {
    @command = ($cmd_gpasswd, "-a", $user, $group);
  }

  &Utils::File::run (@command);
}

# This is only for Linux and SunOS,
# pw groupdel manages this in FreeBSD
sub delete_user_from_group
{
  my ($group, $user) = @_;
  my (@command);

  if ($Utils::Backend::tool{"system"} eq "SunOS")
  {
    my ($groups, @groups_arr);

    $groups = &Utils::File::run_backtick ("groups $user");
    $groups =~ s/.*://;
    chomp ($groups);

    # delete the user
    $groups =~ s/[ \t]+$group//;

    @groups_arr = split (/ /, $groups);
    
    @command = ($cmd_usermod, "-G", @groups_arr, $user);
  }
  else
  {
    @command = ($cmd_gpasswd, "-d", $user, $group);
  }

  &Utils::File::run (@command);
}

sub add_group
{
  my ($group) = @_;
  my ($u, $user, @users);

  # Make backups manually, otherwise they don't get backed up.
  &Utils::File::do_backup ($group_names);

  $u = $$group[$USERS];

  # max value means default UID or GID here
  $real_gid = ($$group[$GID] != 0xFFFFFFFF);

  if ($Utils::Backend::tool{"system"} eq "FreeBSD")
  {
    @users = sort @$u;


    @command = ($cmd_pw, "groupadd", "-n", $$group[$LOGIN],
                                     "-M", @users);

    push (@command, ("-g", $$group[$GID])) if $real_gid;

    &Utils::File::run (@command);
  }
  else
  {
    if ($cmd_addgroup)
    {
      @command = ($cmd_addgroup, $$group[$LOGIN]);
      push (@command, ("--gid", $$group[$GID])) if $real_gid;
    }
    else
    {
      @command = ($cmd_groupadd, $$group[$LOGIN]);
      push (@command, ("-g", $$group[$GID])) if $real_gid;
    }

    &Utils::File::run (@command);

    foreach $user (sort @$u)
    {
      &add_user_to_group ($$group[$LOGIN], $user);
    }
  }
}

sub change_group
{
	my ($old_group, $new_group) = @_;
  my (%users, %user, $users_arr, $str);

	my ($n, $o, $users, $i, $j, $max_n, $max_o, $r, @tmp); # for iterations

  if ($Utils::Backend::tool{"system"} eq "FreeBSD")
  {
    if (($$old_group[$GID] != $$new_group[$GID]) || ($$old_group[$LOGIN] ne $$new_group[$LOGIN])
        || !Utils::Util::struct_eq ($$new_group[$USERS], $$old_group[$USERS]))
    {
      $users_arr = $$new_group[$USERS];
      $str = join (",", sort @$users_arr);

      @command = ($cmd_pw, "groupmod", "-n", $$old_group[$LOGIN],
                                       "-g", $$new_group[$GID],
                                       "-l", $$new_group[$LOGIN],
                                       "-M", $str);

      &Utils::File::run (@command);
    }
  }
  else
  {
    if (($$old_group[$GID] != $$new_group[$GID]) || ($$old_group[$LOGIN] ne $$new_group[$LOGIN]))
    {
      @command = ($cmd_groupmod, "-g", $$new_group[$GID],
                                 "-n", $$new_group[$LOGIN],
                                       $$old_group[$LOGIN]);
  
      &Utils::File::run (@command);
    }

    # Let's see if the users that compose the group have changed.
    if (!Utils::Util::struct_eq ($$new_group[$USERS], $$old_group[$USERS]))
    {
      $users{$_} |= 1 foreach (@{$$new_group[$USERS]});
      $users{$_} |= 2 foreach (@{$$old_group[$USERS]});

      foreach $user (keys %users)
      {
        $state = $users{$user};

        if ($state == 2)
        {
          # users with state 2 are those that only appeared
          # in the old group configuration, so we must delete them
          &delete_user_from_group ($$new_group [$LOGIN], $user);
        }
        elsif ($state == 1)
        {
          # users with state 1 are those who were added
          # to the new group configuration
          &add_user_to_group ($$new_group[$LOGIN], $user);
        }
      }
    }
  }
}

sub get_group
{
  my ($login) = @_;
  my ($groups) = &get ();

  foreach $group (@$groups)
  {
    next if ($login != $$group[$LOGIN]);
    return $group;
  }

  return NULL;
}

sub set_group
{
  my ($new_group) = @_;
  my ($groups) = &get ();

  # Make backups manually, otherwise they don't get backed up.
  &Utils::File::do_backup ($group_names);

  foreach $group (@$groups)
  {
    if ($$new_group[$LOGIN] eq $$group[$LOGIN])
    {
      &change_group ($group, $new_group);
      return;
    }
  }
}

sub get
{
  my ($ifh, @groups, $group_last_modified);
  my (@line, $copy, @a);

  $ifh = &Utils::File::open_read_from_names($group_names);
  return unless ($ifh);

  # Parse the file.
  @groups = ();

  while (<$ifh>)
  {
    chomp;

    # FreeBSD allows comments in the group file. */
    next if &Utils::Util::ignore_line ($_);

    @line = split ':', $_, 4;
    @a = split ',', pop @line;
    push @line, [@a];
    $copy = [@line];
    push (@groups, $copy);
  }

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

  return \@groups;
}

sub get_files
{
  my @arr;

  push @arr, $group_names;
  return \@arr;
}

sub set
{
  my ($config) = @_;
  my ($groups) = &get ();
  my ($new_group, $group);

  return if (!$config);


  # Make backups manually, otherwise they don't get backed up.
  &Utils::File::do_backup ($group_names);

  # Change groups that are present in both old and new config.
  # Groups won't be removed or added this way, for more safety.
  foreach $new_group (@$config)
  {
    foreach $group (@$groups)
    {
      if ($$new_group[$LOGIN] eq $$group[$LOGIN])
      {
        &change_group ($group, $new_group);
        break;
      }
  }
  }
}

1;