3 # Update privilege grants on some table/view/index
5 require './postgresql-lib.pl';
7 $access{'users'} || &error($text{'grant_ecannot'});
9 # Remove old privileges on object
10 if (&supports_schemas($in{'db'})) {
11 $s = &execute_sql($in{'db'}, 'select relname, relacl, nspname from pg_class, pg_namespace where relnamespace = pg_namespace.oid and (relkind = \'r\' OR relkind = \'S\') and relname !~ \'^pg_\' order by relname');
15 $s = &execute_sql($in{'db'}, 'select relname, relacl, \'public\' from pg_class where (relkind = \'r\' OR relkind = \'S\') and relname !~ \'^pg_\' order by relname');
18 foreach $g (@{$s->{'data'}}) {
19 if ($g->[0] eq $in{'table'} &&
20 $g->[2] eq $in{'ns'}) {
21 $g->[1] =~ s/^\{//; $g->[1] =~ s/\}$//;
22 @grant = map { /^"(.*)=(.*)"$/ || /^(.*)=(.*)$/; [ $1, $2 ] }
26 $qt = $ss ? "e_table($in{'ns'}.".".$in{'table'})
27 : "e_table($in{'table'});
33 elsif ($g->[0] =~ /group\s+(\S+)/) {
34 $who = "group \"$1\"";
39 &execute_sql_logged($in{'db'}, "revoke all on $qt from $who");
42 # Grant new privileges
43 for($i=0; defined($in{"user_$i"}); $i++) {
44 @what = split(/\0/, $in{"what_$i"});
45 next if (!$in{"user_$i"} || !@what);
46 if ($in{"user_$i"} eq "public") {
49 elsif ($in{"user_$i"} =~ /^group\s+(\S+)$/) {
50 $who = "group \"$1\"";
53 $who = "\"".$in{"user_$i"}."\"";
55 &execute_sql_logged($in{'db'}, "grant ".join(",", @what)." on ".
59 &webmin_log("grant", undef, $in{'table'}, \%in);
60 &redirect("list_grants.cgi?search=".&urlize($in{'search'}));