4 $ptdump = "/var/local/ptdump";
7 # make sure process is unlimited
8 `csh -fc 'limit datasize'` =~ /datasize\s*(\w*) kbytes/;
10 die "Must 'unlimit' before running this script!\n";
14 &quelcmd("set autocommit on");
16 if (!$skip_to_members) {
18 open(AUSERS, "rsh $host $ptdump 2>&1 |") || die "Couldn't get to $host\n";
21 if (/Ubik Version number changed during execution/) {
24 print "AFS database changed, trying again.\n";
27 if (/Name: (\w*) ID: (\d*)/ && $2<32767) {
33 print "Got the users from AFS\n";
35 $AUSERS{"nobody"} = 32767;
36 delete $AUSERS{"anonymous"};
38 #delete $AUSERS{"clu"};
39 #$AUSERS{"Saltzer"} = 994;
40 #delete $AUSERS{"saltzer"};
42 @VAL = &quelcmd("select login, uid from users where status=1 or status=2");
43 printf("Got %d users from Moira\n", scalar(@VAL));
45 open(OUT, ">user.add") || die "Couldn't open output file\n";
47 while ($_ = shift @VAL) {
49 if ($_ =~ /\|(\w*)\s*\|\s*(\d*)\|/) {
50 if ($AUSERS{$1} == $2) {
53 print OUT "/moira/bin/pts createuser -name $1 -id $2\n";
59 open(OUT, ">user.del") || die "Couldn't open output file\n";
61 foreach $login (keys %AUSERS) {
62 print OUT "/moira/bin/pts delete $login\n";
68 print "Done processing users\n";
71 open(AGROUP, "rsh $host $ptdump -g 2>&1 |") || die "Couldn't get to $host\n";
74 if (/Ubik Version number changed during execution/) {
77 print "AFS database changed, trying again.\n";
80 if (/Name: system:(\w*) ID: -(\d*)/ && $2<32767) {
86 print "Got the groups from AFS\n";
89 delete $AGROUP{"anyuser"};
90 #$AGROUP{"CLU"} = 184;
91 #delete $AGROUP{"clu"};
92 #$AGROUP{"Saltzer"} = 185;
93 #delete $AGROUP{"saltzer"};
95 @VAL = &quelcmd("select name, gid from list where active=1 and grouplist=1");
96 printf("Got %d groups from Moira\n", scalar(@VAL));
97 open(OUT, ">group.add") || die "Couldn't open output file\n";
99 while ($_ = shift @VAL) {
101 if ($_ =~ /\|(\w*)\s*\|\s*(\d*)\|/) {
102 if ($AGROUP{$1} == $2) {
105 print OUT "/moira/bin/pts creategroup -name system:$1 -owner system:administrators -id -$2\n";
111 open(OUT, ">group.del") || die "Couldn't open output file\n";
113 foreach $group (keys %AGROUP) {
114 print OUT "/moira/bin/pts delete system:$group\n";
120 print "Done processing groups\n";
124 open(AMEM, "rsh $host $ptdump -g -c 2>&1 |") || die "Couldn't get to $host\n";
127 if (/Ubik Version number changed during execution/) {
130 print "AFS database changed, trying again.\n";
133 if (/Group: system:([^\s]*)/) {
135 } elsif (/Group: /) {
137 } elsif (/Member: ([^\s.]*)$/) {
139 push(@AMEM, $list . " " . $1);
141 } elsif (/Member\(co\): ([^\s.]*)$/) {
143 push(@AMEM, $list . " " . $1);
149 printf("Got %d members from AFS\n", scalar(@AMEM));
151 @VAL = &quelcmd("select l.name, u.login from list l, users u, imembers m where l.list_id=m.list_id and u.users_id=m.member_id and m.member_type='USER' and l.grouplist=1 and l.active=1 and (u.status=1 or u.status=2)");
152 printf("Got %d members from Moira\n", scalar(@VAL));
154 while ($_ = shift @VAL) {
156 if ($_ =~ /\|([^\s\|]*)\s*\|([^\s\|]*)\s*\|/) {
157 push(@MMEM, $1 . " " . $2);
161 # throw away column headings
167 open(OUT, ">member.del") || die "Couldn't open output file\n";
168 open(OUT1, ">member.add") || die "Couldn't open output file\n";
170 while ($#AMEM1 + $#MMEM1 > 0) {
171 if ($AMEM1[0] eq $MMEM1[0]) {
174 } elsif ($AMEM1[0] lt $MMEM1[0] && $#AMEM1 > 0) {
175 ($list, $user) = split(/ /, shift @AMEM1);
176 print OUT "/moira/bin/pts removeuser -user $user -group system:$list\n";
177 } elsif ($MMEM1[0] lt $AMEM1[0] && $#MMEM1 > 0) {
178 ($list, $user) = split(/ /, shift @MMEM1);
179 if (($user eq "login" && $list eq "name") || $user eq "root") {
182 print OUT1 "/moira/bin/pts adduser -user $user -group system:$list\n";
191 print "Done processing members.\n";
193 system("cat member.del group.del user.del user.add group.add member.add > fixit");
200 $SIG{'INT'} = $SIG{'TERM'} = $SIG{'HUP'} = 'handler';
201 $ENV{"TERM"} = "glass";
204 select(QUELIN), $|=1;
209 open(STDOUT, ">&COUT");
210 open(STDERR, ">/dev/null");
211 open(STDIN, "<&CREAD");
221 print QUELIN $_[0], "\\g\n";
222 while (($_ = <QUELOUT>) !~ /Executing \. \. \./) { next; }
223 while (($_ = <QUELOUT>) !~ /^continue$/) { push(@RETVAL, $_); }
228 print QUELIN "\\q\n";
236 kill "HUP", $quelpid;
237 print("Caught a signal $sig\n");