Edit File: unsuspendmysqlusers
#!/usr/local/cpanel/3rdparty/bin/perl # cpanel - unsuspendmysqlusers Copyright 2011 cPanel, Inc. # All rights Reserved. # copyright@cpanel.net http://cpanel.net # This code is subject to the cPanel license. Unauthorized copying is prohibited package scripts::unsuspendmysqlusers; use strict; use warnings; use Cpanel::DB::Map::Reader (); use Cpanel::DB::Utils (); use Cpanel::MysqlUtils (); use Cpanel::MysqlUtils::Connect (); use Cpanel::Logger (); if ( !caller() ) { my $user = shift @ARGV; if ( !$user ) { print "USAGE: $0 <user>\n"; exit 1; } unsuspend($user); } sub unsuspend { my ($user) = @_; my $logger = Cpanel::Logger->new(); my $map = Cpanel::DB::Map::Reader->new( 'cpuser' => $user, engine => 'mysql' ); my @user_list = $map->get_dbusers_plus_cpses(); # Case48428 - Need to include the parent user associated with the database and not just virtual users # when suspending accounts in MySQL. # Also, the DB map datastore might have a different owner name associated with the user # account which the databases are tied to. my @db_owner = ( $user, Cpanel::DB::Utils::username_to_dbowner($user), ); push @user_list, @db_owner; Cpanel::MysqlUtils::Connect::connect(); my $user_list = join ',', map { Cpanel::MysqlUtils::quote($_) } @user_list; my $result = Cpanel::MysqlUtils::sqlcmd("SELECT User, Host, Password from mysql.user WHERE user IN ($user_list);") || ''; my @lines = split /\n/, $result; my %result; foreach my $line (@lines) { my ( $key, $host, $value ) = split /\s+/, $line, 3; $result{$key}{$host} = $value || '*' x 41; } foreach my $user ( keys %result ) { foreach my $host ( keys %{ $result{$user} } ) { if ( length( $result{$user}{$host} ) == 41 ) { # New style suspension if ( $result{$user}{$host} =~ m/^\-/ ) { $result{$user}{$host} =~ s/\-//; # Handling for NULL passwords if ( $result{$user}{$host} =~ m/^\*+$/ ) { $logger->info("MySQL user $user has a blank password!"); $result{$user}{$host} = ''; } else { $result{$user}{$host} = reverse $result{$user}{$host}; $result{$user}{$host} = '*' . $result{$user}{$host}; } } # Legacy suspension elsif ( $result{$user}{$host} =~ m/^\+/ ) { $result{$user}{$host} =~ s/\+/\*/; } } elsif ( length( $result{$user}{$host} ) == 40 ) { $result{$user}{$host} = '*' . $result{$user}{$host}; if ( $result{$user}{$host} =~ m/^\*+$/ ) { $result{$user}{$host} = ''; } } else { # Case 76857 $result{$user}{$host} =~ s/^!([0-9a-f]{16})/reverse($1)/e; } } } my @sql_cmds; foreach my $user ( keys %result ) { foreach my $host ( keys %{ $result{$user} } ) { my $pass = $result{$user}{$host}; my $dbuser = Cpanel::MysqlUtils::quote($user); my $dbhost = Cpanel::MysqlUtils::quote($host); $pass = Cpanel::MysqlUtils::quote($pass); push @sql_cmds, "UPDATE mysql.user SET Password=$pass WHERE user=$dbuser AND host=$dbhost;"; } } Cpanel::MysqlUtils::sqlcmd( \@sql_cmds ) if @sql_cmds; # This must be done in the foreground or pkgacct will break. Cpanel::MysqlUtils::sqlcmd('FLUSH PRIVILEGES'); return 1; } 1;