This file is indexed.

/usr/lib/xen-tools/intrepid.d/35-setup-users is in xen-tools 4.2.1-1.

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

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
#!/usr/bin/perl -w
#
#  This script attempts to copy all user accounts from the host to
# the guest.  It does this by copying all user accounts which are not
# already present.
#
#  NOTE:  Unless '--accounts' was specified upon the 'xen-create-image'
# command line we don't do this.
#
# Steve
# --
# http://www.steve.org.uk/


use strict;
use Env;


my $prefix = shift;

die "Prefix must be given"       unless defined( $prefix );
die "Prefix must be a directory" unless ( -d $prefix );


#
#  Exit unless the 'accounts' variable is set.
#
exit unless ( $ENV{'accounts'} );

#
#  Make sure we have $prefix/etc
#
die "Prefix is missing /etc : $prefix" unless ( -d $prefix . "/etc" );


#
#  Read all accounts from the installed /etc/passwd on the guest.
#
my %present;
if ( -e $prefix . "/etc/passwd" )
{
    %present = readAccounts( $prefix . "/etc/passwd" );
}


#
#  Now read the accounts on the host.
#
my %host = readAccounts( "/etc/passwd" );


#
#  For each account not present on new installation then add it
#
foreach my $account ( sort keys( %host ) )
{
    if ( ! $present{ $account } )
    {
        print "Adding: $account\n";
        addAccount( $account );

        #
        #  Find any groups the user is member of on the host
        # and add them on the guest system
        #
        addGroups( $account );
    }
}



#
#  Read the accounts which are already present on the guest image.
#
sub readAccounts
{
    my ( $file ) = ( @_ );


    my %found;

    open( EXISTING, "<", $file );
    foreach my $line ( <EXISTING> )
    {
        #
        #  Record the userid + username
        #
        if ( $line =~ /^([^:]+):([^:]+):([^:]+)/ )
        {
            my $user = $1;
            my $pass = $2;
            my $uid  = $3;

            $found{$user} = 1;
        }
    }
    close( EXISTING );

    return( %found );
}




#
#  Add the passwd + shadow accounts for the given user.
#
sub addAccount
{
    my ( $user ) = ( @_ );

    #
    #  passwd file.
    #
    open( PASSWD, "<", "/etc/passwd" );
    foreach my $line ( <PASSWD> )
    {
        chomp( $line );
        if ( $line =~ /^\Q$user\E:/ )
        {
            #
            #  Add the line
            #
            open( OUTY, ">>", $prefix . "/etc/passwd" );
            print OUTY $line . "\n";
            close( OUTY );
        }
    }
    close( PASSWD );


    #
    #  shadow file.
    #
    open( SHADOW, "<", "/etc/shadow" ) or die "Failed to open : $!";
    foreach my $line ( <SHADOW> )
    {
        chomp( $line );
        if ( $line =~ /^\Q$user\E:/ )
        {
            #
            #  Add the line
            #
            open( OUTY, ">>", $prefix . "/etc/shadow" );
            print OUTY $line . "\n";
            close( OUTY );
        }
    }
    close( SHADOW );
}



#
#  Find the groups a user is member of on the host, and add them to
# those groups on the new guest.
#
sub addGroups
{
    my( $username ) = ( @_ );

    #
    #  Get the groups.
    #
    my $groups = `groups $username`;
    # split off the usernmame.
    if ( $groups =~ /^([^:]+):(.*)/ )
    {
        $groups = $2;
        print "User: $username is member of the groups: $groups\n";
    }

    foreach my $g ( split( / /, $groups ) )
    {
        # Make sure the group exists.
        system( "chroot $prefix /usr/sbin/addgroup $g" );

        # add the user to it.
        system( "chroot $prefix /usr/sbin/adduser $username $g" );
    }
}