Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. !/usr/bin/perl
  2. #
  3. # This code was forked from the LiveJournal project owned and operated
  4. # by Live Journal, Inc. The code has been modified and expanded by
  5. # Dreamwidth Studios, LLC. These files were originally licensed under
  6. # the terms of the license supplied by Live Journal, Inc, which can
  7. # currently be found at:
  8. #
  9. # http://code.livejournal.org/trac/livejournal/browser/trunk/LICENSE-LiveJournal.txt
  10. #
  11. # In accordance with the original license, this code and all its
  12. # modifications are provided under the GNU General Public License.
  13. # A copy of that license can be found in the LICENSE file included as
  14. # part of this distribution.
  15.  
  16. use strict;
  17. BEGIN {
  18. require "$ENV{LJHOME}/cgi-bin/ljlib.pl";
  19. }
  20.  
  21. my $dbh = LJ::get_dbh("master");
  22.  
  23. print "
  24. This tool will create your $LJ::SITENAMESHORT 'system' account and
  25. set its password. Or, if you already have a system user, it'll change
  26. its password to whatever you specify.
  27. ";
  28.  
  29. print "Enter password for the 'system' account: ";
  30. my $pass = <STDIN>;
  31. chomp $pass;
  32.  
  33. print "\n";
  34.  
  35. print "Creating system account...\n";
  36. my $u = LJ::User->create( user => 'system',
  37. name => 'System Account',
  38. password => $pass );
  39. unless ( $u ) {
  40. print "Already exists.\nModifying 'system' account...\n";
  41. my $id = LJ::get_userid("system");
  42. $dbh->do("UPDATE password SET password=? WHERE userid=?",
  43. undef, $pass, $id);
  44. }
  45.  
  46. $u ||= LJ::load_user( "system" );
  47. unless ( $u ) {
  48. print "ERROR: can't find newly-created system account.\n";
  49. exit 1;
  50. }
  51.  
  52. print "Checking password for consistency using several methods...\n";
  53. my $stored_password = $u->password;
  54. if ( $stored_password ne $pass ) {
  55. print "WARNING: inconsistency using ->password (expected=$pass, stored=$stored_password)\n";
  56. }
  57.  
  58. use LJ::Auth;
  59. my $chal = LJ::challenge_generate( );
  60. print "WARNING: challenge_check_login returned 0\n"
  61. unless ( LJ::challenge_check_login( $u, $chal, Digest::MD5::md5_hex( $chal . Digest::MD5::md5_hex( $pass ) ) ) );
  62.  
  63. print "Giving 'system' account 'admin' priv on all areas...\n";
  64. if ( $u->has_priv( "admin", "*" ) ) {
  65. print "Already has it.\n";
  66. } else {
  67. my $sth = $dbh->prepare("INSERT INTO priv_map (userid, prlid, arg) ".
  68. "SELECT $u->{'userid'}, prlid, '*' ".
  69. "FROM priv_list WHERE privcode='admin'");
  70. $sth->execute;
  71. if ($dbh->err || $sth->rows == 0) {
  72. print "Couldn't grant system account admin privs\n";
  73. exit 1;
  74. }
  75. }
  76.  
  77. print "Done.\n\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement