File: convert_users

package info (click to toggle)
xisp 2.5p4-1
  • links: PTS
  • area: contrib
  • in suites: slink
  • size: 1,328 kB
  • ctags: 1,908
  • sloc: ansic: 16,648; asm: 214; sh: 210; makefile: 202; perl: 55
file content (69 lines) | stat: -rw-r--r-- 1,833 bytes parent folder | download
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
#!/usr/bin/perl
#  Copyright (C)1996 Austin Donnelly <and1000@cam.ac.uk>.
#  This is free software; you may modify and distribute it under the
#  terms of the GNU General Public Licence as published by the Free
#  Software Foundation, version 2 or at your option any later version.
#  There is NO WARRANTY.

# Originaly used for fvwm2, I adapted it for use with xisp 
# - Martin Bialasinski

$CONVPROG="./xisprccv";

# Syscall number for setgroups(), from /usr/include/sys/syscall.h
$SYS_SETGROUPS=81; # valid for linux, fill in for your flavour of unix
die "I need configuring" if (!defined($SYS_SETGROUPS));

print "Checking which users have old ~/.xisprc files...\n";

# Read password file & build list of affected users
@todo=();
setpwent();
($name,$passwd,$uid,$gid,
 $quota,$comment,$gcos,$dir,$shell) = getpwent();
while(defined($uid))
{
    push(@todo, "$uid:$gid:$name:$dir")
	if (-f "$dir/.xisprc");
    ($name,$passwd,$uid,$gid,
     $quota,$comment,$gcos,$dir,$shell) = getpwent();
}
endpwent();

# Do all the files
$unum=1;
foreach $line (@todo)
{
    &translate($line);
}
exit 0;

###########################

# run $CONVPROG
sub translate
{
    my ($line) = shift;
    my ($uid, $gid, $name, $dir);

    ($uid, $gid, $name, $dir) = split /:/, $line;

    # fork, child drops privs & does work, while parent waits for child
    $pid=fork();
    die "fork() failed: $!\n" if ($pid==-1);
    if ($pid==0) # child
    {
#	syscall($SYS_SETGROUPS, 0, 0); # SYS_setgroups(0, NULL); /* nasty! */
	$( = $) = $gid;  # real, eff gid
	$< = $> = $uid;  # real, eff uid
	# ok, now plain mortal, so run conversion
        print "User $name: ";
	exec($CONVPROG);
	die "exec() of $CONVPROG failed: $!\n";
    } else {
	# parent
	waitpid($pid, 0);
	$ret=$?>>8;
	die "Child returned with non-zero exit status($ret)\n" if ($ret);
    }
}