Ticket #8941: xmlrpc.diff

File xmlrpc.diff, 24.3 KB (added by wnorris, 3 years ago)
  • xmlrpc.php

     
    238238         * @param string $user_login User's username. 
    239239         * @param string $user_pass User's password. 
    240240         * @return bool Whether authentication passed. 
     241         * @deprecated use wp_xmlrpc_server::login 
     242         * @see wp_xmlrpc_server::login 
    241243         */ 
    242244        function login_pass_ok($user_login, $user_pass) { 
    243245                if ( !get_option( 'enable_xmlrpc' ) ) { 
     
    253255        } 
    254256 
    255257        /** 
     258         * Log user in. 
     259         * 
     260         * @since 2.8 
     261         * 
     262         * @param string $username User's username. 
     263         * @param string $password User's password. 
     264         * @return mixed WP_User object if authentication passed, false otherwise 
     265         */ 
     266        function login($username, $password) { 
     267                if ( !get_option( 'enable_xmlrpc' ) ) { 
     268                        $this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this blog.  An admin user can enable them at %s'),  admin_url('options-writing.php') ) ); 
     269                        return false; 
     270                } 
     271 
     272                $user = wp_authenticate($username, $password); 
     273 
     274                if (is_wp_error($user)) { 
     275                        $this->error = new IXR_Error(403, __('Bad login/pass combination.')); 
     276                        return false; 
     277                } 
     278 
     279                set_current_user( $user->ID ); 
     280                return $user; 
     281        } 
     282 
     283        /** 
    256284         * Sanitize string or array of strings for database. 
    257285         * 
    258286         * @since 1.5.2 
     
    417445                $username = $args[0]; 
    418446                $password = $args[1]; 
    419447 
    420                 if( !$this->login_pass_ok( $username, $password ) ) 
     448                if ( !$user = $this->login($username, $password) ) { 
    421449                        return $this->error; 
     450                } 
    422451 
    423452                do_action( 'xmlrpc_call', 'wp.getUsersBlogs' ); 
    424453 
    425                 $user = set_current_user( 0, $username ); 
    426  
    427454                $blogs = (array) get_blogs_of_user( $user->ID ); 
    428455                $struct = array( ); 
    429456 
     
    466493                $username       = $args[2]; 
    467494                $password       = $args[3]; 
    468495 
    469                 if(!$this->login_pass_ok($username, $password)) { 
    470                         return($this->error); 
     496                if ( !$user = $this->login($username, $password) ) { 
     497                        return $this->error; 
    471498                } 
    472499 
    473                 set_current_user( 0, $username ); 
    474500                if( !current_user_can( 'edit_page', $page_id ) ) 
    475501                        return new IXR_Error( 401, __( 'Sorry, you can not edit this page.' ) ); 
    476502 
     
    564590                $password       = $args[2]; 
    565591                $num_pages      = (int) $args[3]; 
    566592 
    567                 if(!$this->login_pass_ok($username, $password)) { 
    568                         return($this->error); 
     593                if ( !$user = $this->login($username, $password) ) { 
     594                        return $this->error; 
    569595                } 
    570596 
    571                 set_current_user( 0, $username ); 
    572597                if( !current_user_can( 'edit_pages' ) ) 
    573598                        return new IXR_Error( 401, __( 'Sorry, you can not edit pages.' ) ); 
    574599 
     
    616641                $page           = $args[3]; 
    617642                $publish        = $args[4]; 
    618643 
    619                 if(!$this->login_pass_ok($username, $password)) { 
    620                         return($this->error); 
     644                if ( !$user = $this->login($username, $password) ) { 
     645                        return $this->error; 
    621646                } 
    622647 
    623648                do_action('xmlrpc_call', 'wp.newPage'); 
    624649 
    625                 // Set the user context and check if they are allowed 
    626                 // to add new pages. 
    627                 $user = set_current_user(0, $username); 
     650                // Make sure the user is allowed to add new pages. 
    628651                if(!current_user_can("publish_pages")) { 
    629652                        return(new IXR_Error(401, __("Sorry, you can not add new pages."))); 
    630653                } 
     
    652675                $password       = $args[2]; 
    653676                $page_id        = (int) $args[3]; 
    654677 
    655                 if(!$this->login_pass_ok($username, $password)) { 
    656                         return($this->error); 
     678                if ( !$user = $this->login($username, $password) ) { 
     679                        return $this->error; 
    657680                } 
    658681 
    659682                do_action('xmlrpc_call', 'wp.deletePage'); 
     
    668691                        return(new IXR_Error(404, __("Sorry, no such page."))); 
    669692                } 
    670693 
    671                 // Set the user context and make sure they can delete pages. 
    672                 set_current_user(0, $username); 
     694                // Make sure the user can delete pages. 
    673695                if(!current_user_can("delete_page", $page_id)) { 
    674696                        return(new IXR_Error(401, __("Sorry, you do not have the right to delete this page."))); 
    675697                } 
     
    700722                $content        = $args[4]; 
    701723                $publish        = $args[5]; 
    702724 
    703                 if(!$this->login_pass_ok($username, $password)) { 
    704                         return($this->error); 
     725                if ( !$user = $this->login($username, $password) ) { 
     726                        return $this->error; 
    705727                } 
    706728 
    707729                do_action('xmlrpc_call', 'wp.editPage'); 
     
    715737                        return(new IXR_Error(404, __("Sorry, no such page."))); 
    716738                } 
    717739 
    718                 // Set the user context and make sure they are allowed to edit pages. 
    719                 set_current_user(0, $username); 
     740                // Make sure the user is allowed to edit pages. 
    720741                if(!current_user_can("edit_page", $page_id)) { 
    721742                        return(new IXR_Error(401, __("Sorry, you do not have the right to edit this page."))); 
    722743                } 
     
    754775                $username                               = $args[1]; 
    755776                $password                               = $args[2]; 
    756777 
    757                 if(!$this->login_pass_ok($username, $password)) { 
    758                         return($this->error); 
     778                if ( !$user = $this->login($username, $password) ) { 
     779                        return $this->error; 
    759780                } 
    760781 
    761                 set_current_user( 0, $username ); 
    762782                if( !current_user_can( 'edit_pages' ) ) 
    763783                        return new IXR_Error( 401, __( 'Sorry, you can not edit pages.' ) ); 
    764784 
     
    808828                $username       = $args[1]; 
    809829                $password       = $args[2]; 
    810830 
    811                 if(!$this->login_pass_ok($username, $password)) { 
    812                         return($this->error); 
     831                if ( !$user = $this->login($username, $password) ) { 
     832                        return $this->error; 
    813833                } 
    814834 
    815                 set_current_user(0, $username); 
    816835                if(!current_user_can("edit_posts")) { 
    817836                        return(new IXR_Error(401, __("Sorry, you can not edit posts on this blog."))); 
    818837                } 
     
    846865                $username               = $args[1]; 
    847866                $password               = $args[2]; 
    848867 
    849                 if( !$this->login_pass_ok( $username, $password ) ) { 
     868                if ( !$user = $this->login($username, $password) ) { 
    850869                        return $this->error; 
    851870                } 
    852871 
    853                 set_current_user( 0, $username ); 
    854872                if( !current_user_can( 'edit_posts' ) ) { 
    855873                        return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this blog in order to view tags.' ) ); 
    856874                } 
     
    891909                $password                               = $args[2]; 
    892910                $category                               = $args[3]; 
    893911 
    894                 if(!$this->login_pass_ok($username, $password)) { 
    895                         return($this->error); 
     912                if ( !$user = $this->login($username, $password) ) { 
     913                        return $this->error; 
    896914                } 
    897915 
    898916                do_action('xmlrpc_call', 'wp.newCategory'); 
    899917 
    900                 // Set the user context and make sure they are 
    901                 // allowed to add a category. 
    902                 set_current_user(0, $username); 
     918                // Make sure the user is allowed to add a category. 
    903919                if(!current_user_can("manage_categories")) { 
    904920                        return(new IXR_Error(401, __("Sorry, you do not have the right to add a category."))); 
    905921                } 
     
    951967                $password               = $args[2]; 
    952968                $category_id    = (int) $args[3]; 
    953969 
    954                 if( !$this->login_pass_ok( $username, $password ) ) { 
     970                if ( !$user = $this->login($username, $password) ) { 
    955971                        return $this->error; 
    956972                } 
    957973 
    958974                do_action('xmlrpc_call', 'wp.deleteCategory'); 
    959975 
    960                 set_current_user(0, $username); 
    961976                if( !current_user_can("manage_categories") ) { 
    962977                        return new IXR_Error( 401, __( "Sorry, you do not have the right to delete a category." ) ); 
    963978                } 
     
    982997                $category                               = $args[3]; 
    983998                $max_results                    = (int) $args[4]; 
    984999 
    985                 if(!$this->login_pass_ok($username, $password)) { 
    986                         return($this->error); 
     1000                if ( !$user = $this->login($username, $password) ) { 
     1001                        return $this->error; 
    9871002                } 
    9881003 
    989                 set_current_user(0, $username); 
    9901004                if( !current_user_can( 'edit_posts' ) ) 
    9911005                        return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts to this blog in order to view categories.' ) ); 
    9921006 
     
    10201034                $password       = $args[2]; 
    10211035                $comment_id     = (int) $args[3]; 
    10221036 
    1023                 if ( !$this->login_pass_ok( $username, $password ) ) 
     1037                if ( !$user = $this->login($username, $password) ) { 
    10241038                        return $this->error; 
     1039                } 
    10251040 
    1026                 set_current_user( 0, $username ); 
    10271041                if ( !current_user_can( 'moderate_comments' ) ) 
    10281042                        return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) ); 
    10291043 
     
    10831097                $password       = $args[2]; 
    10841098                $struct         = $args[3]; 
    10851099 
    1086                 if ( !$this->login_pass_ok($username, $password) ) 
    1087                         return($this->error); 
     1100                if ( !$user = $this->login($username, $password) ) { 
     1101                        return $this->error; 
     1102                } 
    10881103 
    1089                 set_current_user( 0, $username ); 
    10901104                if ( !current_user_can( 'moderate_comments' ) ) 
    10911105                        return new IXR_Error( 401, __( 'Sorry, you can not edit comments.' ) ); 
    10921106 
     
    11431157                $password       = $args[2]; 
    11441158                $comment_ID     = (int) $args[3]; 
    11451159 
    1146                 if ( !$this->login_pass_ok( $username, $password ) ) 
     1160                if ( !$user = $this->login($username, $password) ) { 
    11471161                        return $this->error; 
     1162                } 
    11481163 
    1149                 set_current_user( 0, $username ); 
    11501164                if ( !current_user_can( 'moderate_comments' ) ) 
    11511165                        return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) ); 
    11521166 
     
    11751189                $comment_ID     = (int) $args[3]; 
    11761190                $content_struct = $args[4]; 
    11771191 
    1178                 if ( !$this->login_pass_ok( $username, $password ) ) 
     1192                if ( !$user = $this->login($username, $password) ) { 
    11791193                        return $this->error; 
     1194                } 
    11801195 
    1181                 set_current_user( 0, $username ); 
    11821196                if ( !current_user_can( 'moderate_comments' ) ) 
    11831197                        return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) ); 
    11841198 
     
    12491263 
    12501264                $allow_anon = apply_filters('xmlrpc_allow_anonymous_comments', false); 
    12511265 
    1252                 if ( !$this->login_pass_ok( $username, $password ) ) { 
     1266                $user = $this->login($username, $password); 
     1267 
     1268                if ( !$user ) { 
    12531269                        $logged_in = false; 
    12541270                        if ( $allow_anon && get_option('comment_registration') ) 
    12551271                                return new IXR_Error( 403, __( 'You must be registered to comment' ) ); 
     
    12571273                                return $this->error; 
    12581274                } else { 
    12591275                        $logged_in = true; 
    1260                         set_current_user( 0, $username ); 
    12611276                } 
    12621277 
    12631278                if ( is_numeric($post) ) 
     
    12741289                $comment['comment_post_ID'] = $post_id; 
    12751290 
    12761291                if ( $logged_in ) { 
    1277                         $user = wp_get_current_user(); 
    12781292                        $comment['comment_author'] = $wpdb->escape( $user->display_name ); 
    12791293                        $comment['comment_author_email'] = $wpdb->escape( $user->user_email ); 
    12801294                        $comment['comment_author_url'] = $wpdb->escape( $user->user_url ); 
     
    13261340                $username       = $args[1]; 
    13271341                $password       = $args[2]; 
    13281342 
    1329                 if ( !$this->login_pass_ok( $username, $password ) ) 
     1343                if ( !$user = $this->login($username, $password) ) { 
    13301344                        return $this->error; 
     1345                } 
    13311346 
    1332                 set_current_user( 0, $username ); 
    13331347                if ( !current_user_can( 'moderate_comments' ) ) 
    13341348                        return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) ); 
    13351349 
     
    13541368                $password       = $args[2]; 
    13551369                $post_id        = (int) $args[3]; 
    13561370 
    1357                 if( !$this->login_pass_ok( $username, $password ) ) { 
     1371                if ( !$user = $this->login($username, $password) ) { 
    13581372                        return $this->error; 
    13591373                } 
    13601374 
    1361                 set_current_user( 0, $username ); 
    13621375                if( !current_user_can( 'edit_posts' ) ) { 
    13631376                        return new IXR_Error( 403, __( 'You are not allowed access to details about comments.' ) ); 
    13641377                } 
     
    13891402                $username       = $args[1]; 
    13901403                $password       = $args[2]; 
    13911404 
    1392                 if( !$this->login_pass_ok( $username, $password ) ) { 
     1405                if ( !$user = $this->login($username, $password) ) { 
    13931406                        return $this->error; 
    13941407                } 
    13951408 
    1396                 set_current_user( 0, $username ); 
    13971409                if( !current_user_can( 'edit_posts' ) ) { 
    13981410                        return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) ); 
    13991411                } 
     
    14181430                $username       = $args[1]; 
    14191431                $password       = $args[2]; 
    14201432 
    1421                 if( !$this->login_pass_ok( $username, $password ) ) { 
     1433                if ( !$user = $this->login($username, $password) ) { 
    14221434                        return $this->error; 
    14231435                } 
    14241436 
    1425                 set_current_user( 0, $username ); 
    14261437                if( !current_user_can( 'edit_posts' ) ) { 
    14271438                        return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) ); 
    14281439                } 
     
    14471458                $username       = $args[1]; 
    14481459                $password       = $args[2]; 
    14491460 
    1450                 if( !$this->login_pass_ok( $username, $password ) ) { 
     1461                if ( !$user = $this->login($username, $password) ) { 
    14511462                        return $this->error; 
    14521463                } 
    14531464 
    1454                 set_current_user( 0, $username ); 
    14551465                if( !current_user_can( 'edit_pages' ) ) { 
    14561466                        return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) ); 
    14571467                } 
     
    14781488                $password       = $args[2]; 
    14791489                $options        = (array) $args[3]; 
    14801490 
    1481                 if( !$this->login_pass_ok( $username, $password ) ) 
     1491                if ( !$user = $this->login($username, $password) ) { 
    14821492                        return $this->error; 
     1493                } 
    14831494 
    1484                 $user = set_current_user( 0, $username ); 
    1485  
    14861495                // If no specific options where asked for, return all of them 
    14871496                if (count( $options ) == 0 ) { 
    14881497                        $options = array_keys($this->blog_options); 
     
    15331542                $password       = $args[2]; 
    15341543                $options        = (array) $args[3]; 
    15351544 
    1536                 if( !$this->login_pass_ok( $username, $password ) ) 
     1545                if ( !$user = $this->login($username, $password) ) { 
    15371546                        return $this->error; 
     1547                } 
    15381548 
    1539                 $user = set_current_user( 0, $username ); 
    15401549                if( !current_user_can( 'manage_options' ) ) 
    15411550                        return new IXR_Error( 403, __( 'You are not allowed to update options.' ) ); 
    15421551 
     
    15761585 
    15771586                $this->escape($args); 
    15781587 
    1579                 $user_login = $args[1]; 
    1580                 $user_pass  = $args[2]; 
     1588                $username = $args[1]; 
     1589                $password  = $args[2]; 
    15811590 
    1582                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     1591                if ( !$user = $this->login($username, $password) ) { 
    15831592                        return $this->error; 
    15841593                } 
    15851594 
    15861595                do_action('xmlrpc_call', 'blogger.getUsersBlogs'); 
    15871596 
    1588                 set_current_user(0, $user_login); 
    15891597                $is_admin = current_user_can('manage_options'); 
    15901598 
    15911599                $struct = array( 
     
    16131621 
    16141622                $this->escape($args); 
    16151623 
    1616                 $user_login = $args[1]; 
    1617                 $user_pass  = $args[2]; 
     1624                $username = $args[1]; 
     1625                $password  = $args[2]; 
    16181626 
    1619                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     1627                if ( !$user = $this->login($username, $password) ) { 
    16201628                        return $this->error; 
    16211629                } 
    16221630 
    1623                 set_current_user( 0, $user_login ); 
    16241631                if( !current_user_can( 'edit_posts' ) ) 
    16251632                        return new IXR_Error( 401, __( 'Sorry, you do not have access to user data on this blog.' ) ); 
    16261633 
    16271634                do_action('xmlrpc_call', 'blogger.getUserInfo'); 
    16281635 
    1629                 $user_data = get_userdatabylogin($user_login); 
    1630  
    16311636                $struct = array( 
    1632                         'nickname'  => $user_data->nickname, 
    1633                         'userid'    => $user_data->ID, 
    1634                         'url'       => $user_data->user_url, 
    1635                         'lastname'  => $user_data->last_name, 
    1636                         'firstname' => $user_data->first_name 
     1637                        'nickname'  => $user->nickname, 
     1638                        'userid'    => $user->ID, 
     1639                        'url'       => $user->user_url, 
     1640                        'lastname'  => $user->last_name, 
     1641                        'firstname' => $user->first_name 
    16371642                ); 
    16381643 
    16391644                return $struct; 
     
    16521657                $this->escape($args); 
    16531658 
    16541659                $post_ID    = (int) $args[1]; 
    1655                 $user_login = $args[2]; 
    1656                 $user_pass  = $args[3]; 
     1660                $username = $args[2]; 
     1661                $password  = $args[3]; 
    16571662 
    1658                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     1663                if ( !$user = $this->login($username, $password) ) { 
    16591664                        return $this->error; 
    16601665                } 
    16611666 
    1662                 set_current_user( 0, $user_login ); 
    16631667                if( !current_user_can( 'edit_post', $post_ID ) ) 
    16641668                        return new IXR_Error( 401, __( 'Sorry, you can not edit this post.' ) ); 
    16651669 
     
    16961700                $this->escape($args); 
    16971701 
    16981702                $blog_ID    = (int) $args[1]; /* though we don't use it yet */ 
    1699                 $user_login = $args[2]; 
    1700                 $user_pass  = $args[3]; 
     1703                $username = $args[2]; 
     1704                $password  = $args[3]; 
    17011705                $num_posts  = $args[4]; 
    17021706 
    1703                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     1707                if ( !$user = $this->login($username, $password) ) { 
    17041708                        return $this->error; 
    17051709                } 
    17061710 
     
    17081712 
    17091713                $posts_list = wp_get_recent_posts($num_posts); 
    17101714 
    1711                 set_current_user( 0, $user_login ); 
    1712  
    17131715                if (!$posts_list) { 
    17141716                        $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.')); 
    17151717                        return $this->error; 
     
    17561758                $this->escape($args); 
    17571759 
    17581760                $blog_ID    = (int) $args[1]; 
    1759                 $user_login = $args[2]; 
    1760                 $user_pass  = $args[3]; 
     1761                $username = $args[2]; 
     1762                $password  = $args[3]; 
    17611763                $template   = $args[4]; /* could be 'main' or 'archiveIndex', but we don't use it */ 
    17621764 
    1763                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     1765                if ( !$user = $this->login($username, $password) ) { 
    17641766                        return $this->error; 
    17651767                } 
    17661768 
    17671769                do_action('xmlrpc_call', 'blogger.getTemplate'); 
    17681770 
    1769                 set_current_user(0, $user_login); 
    17701771                if ( !current_user_can('edit_themes') ) { 
    17711772                        return new IXR_Error(401, __('Sorry, this user can not edit the template.')); 
    17721773                } 
     
    17981799                $this->escape($args); 
    17991800 
    18001801                $blog_ID    = (int) $args[1]; 
    1801                 $user_login = $args[2]; 
    1802                 $user_pass  = $args[3]; 
     1802                $username = $args[2]; 
     1803                $password  = $args[3]; 
    18031804                $content    = $args[4]; 
    18041805                $template   = $args[5]; /* could be 'main' or 'archiveIndex', but we don't use it */ 
    18051806 
    1806                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     1807                if ( !$user = $this->login($username, $password) ) { 
    18071808                        return $this->error; 
    18081809                } 
    18091810 
    18101811                do_action('xmlrpc_call', 'blogger.setTemplate'); 
    18111812 
    1812                 set_current_user(0, $user_login); 
    18131813                if ( !current_user_can('edit_themes') ) { 
    18141814                        return new IXR_Error(401, __('Sorry, this user can not edit the template.')); 
    18151815                } 
     
    18411841                $this->escape($args); 
    18421842 
    18431843                $blog_ID    = (int) $args[1]; /* though we don't use it yet */ 
    1844                 $user_login = $args[2]; 
    1845                 $user_pass  = $args[3]; 
     1844                $username = $args[2]; 
     1845                $password  = $args[3]; 
    18461846                $content    = $args[4]; 
    18471847                $publish    = $args[5]; 
    18481848 
    1849                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     1849                if ( !$user = $this->login($username, $password) ) { 
    18501850                        return $this->error; 
    18511851                } 
    18521852 
    18531853                do_action('xmlrpc_call', 'blogger.newPost'); 
    18541854 
    18551855                $cap = ($publish) ? 'publish_posts' : 'edit_posts'; 
    1856                 $user = set_current_user(0, $user_login); 
    18571856                if ( !current_user_can($cap) ) 
    18581857                        return new IXR_Error(401, __('Sorry, you are not allowed to post on this blog.')); 
    18591858 
     
    18971896                $this->escape($args); 
    18981897 
    18991898                $post_ID     = (int) $args[1]; 
    1900                 $user_login  = $args[2]; 
    1901                 $user_pass   = $args[3]; 
     1899                $username  = $args[2]; 
     1900                $password   = $args[3]; 
    19021901                $content     = $args[4]; 
    19031902                $publish     = $args[5]; 
    19041903 
    1905                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     1904                if ( !$user = $this->login($username, $password) ) { 
    19061905                        return $this->error; 
    19071906                } 
    19081907 
     
    19161915 
    19171916                $this->escape($actual_post); 
    19181917 
    1919                 set_current_user(0, $user_login); 
    19201918                if ( !current_user_can('edit_post', $post_ID) ) 
    19211919                        return new IXR_Error(401, __('Sorry, you do not have the right to edit this post.')); 
    19221920 
     
    19531951                $this->escape($args); 
    19541952 
    19551953                $post_ID     = (int) $args[1]; 
    1956                 $user_login  = $args[2]; 
    1957                 $user_pass   = $args[3]; 
     1954                $username  = $args[2]; 
     1955                $password   = $args[3]; 
    19581956                $publish     = $args[4]; 
    19591957 
    1960                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     1958                if ( !$user = $this->login($username, $password) ) { 
    19611959                        return $this->error; 
    19621960                } 
    19631961 
     
    19691967                        return new IXR_Error(404, __('Sorry, no such post.')); 
    19701968                } 
    19711969 
    1972                 set_current_user(0, $user_login); 
    19731970                if ( !current_user_can('edit_post', $post_ID) ) 
    19741971                        return new IXR_Error(401, __('Sorry, you do not have the right to delete this post.')); 
    19751972 
     
    19981995                $this->escape($args); 
    19991996 
    20001997                $blog_ID     = (int) $args[0]; // we will support this in the near future 
    2001                 $user_login  = $args[1]; 
    2002                 $user_pass   = $args[2]; 
     1998                $username  = $args[1]; 
     1999                $password   = $args[2]; 
    20032000                $content_struct = $args[3]; 
    20042001                $publish     = $args[4]; 
    20052002 
    2006                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     2003                if ( !$user = $this->login($username, $password) ) { 
    20072004                        return $this->error; 
    20082005                } 
    2009                 $user = set_current_user(0, $user_login); 
    20102006 
    20112007                do_action('xmlrpc_call', 'metaWeblog.newPost'); 
    20122008 
     
    22782274                $this->escape($args); 
    22792275 
    22802276                $post_ID     = (int) $args[0]; 
    2281                 $user_login  = $args[1]; 
    2282                 $user_pass   = $args[2]; 
     2277                $username  = $args[1]; 
     2278                $password   = $args[2]; 
    22832279                $content_struct = $args[3]; 
    22842280                $publish     = $args[4]; 
    22852281 
    2286                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     2282                if ( !$user = $this->login($username, $password) ) { 
    22872283                        return $this->error; 
    22882284                } 
    2289                 $user = set_current_user(0, $user_login); 
    22902285 
    22912286                do_action('xmlrpc_call', 'metaWeblog.editPost'); 
    22922287 
     
    25462541                $this->escape($args); 
    25472542 
    25482543                $post_ID     = (int) $args[0]; 
    2549                 $user_login  = $args[1]; 
    2550                 $user_pass   = $args[2]; 
     2544                $username  = $args[1]; 
     2545                $password   = $args[2]; 
    25512546 
    2552                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     2547                if ( !$user = $this->login($username, $password) ) { 
    25532548                        return $this->error; 
    25542549                } 
    25552550 
    2556                 set_current_user( 0, $user_login ); 
    25572551                if( !current_user_can( 'edit_post', $post_ID ) ) 
    25582552                        return new IXR_Error( 401, __( 'Sorry, you can not edit this post.' ) ); 
    25592553 
     
    26582652                $this->escape($args); 
    26592653 
    26602654                $blog_ID     = (int) $args[0]; 
    2661                 $user_login  = $args[1]; 
    2662                 $user_pass   = $args[2]; 
     2655                $username  = $args[1]; 
     2656                $password   = $args[2]; 
    26632657                $num_posts   = (int) $args[3]; 
    26642658 
    2665                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     2659                if ( !$user = $this->login($username, $password) ) { 
    26662660                        return $this->error; 
    26672661                } 
    26682662 
     
    26742668                        return array( ); 
    26752669                } 
    26762670 
    2677                 set_current_user( 0, $user_login ); 
    2678  
    26792671                foreach ($posts_list as $entry) { 
    26802672                        if( !current_user_can( 'edit_post', $entry['ID'] ) ) 
    26812673                                continue; 
     
    27622754                $this->escape($args); 
    27632755 
    27642756                $blog_ID     = (int) $args[0]; 
    2765                 $user_login  = $args[1]; 
    2766                 $user_pass   = $args[2]; 
     2757                $username  = $args[1]; 
     2758                $password   = $args[2]; 
    27672759 
    2768                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     2760                if ( !$user = $this->login($username, $password) ) { 
    27692761                        return $this->error; 
    27702762                } 
    27712763 
    2772                 set_current_user( 0, $user_login ); 
    27732764                if( !current_user_can( 'edit_posts' ) ) 
    27742765                        return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this blog in order to view categories.' ) ); 
    27752766 
     
    28102801                global $wpdb; 
    28112802 
    28122803                $blog_ID     = (int) $args[0]; 
    2813                 $user_login  = $wpdb->escape($args[1]); 
    2814                 $user_pass   = $wpdb->escape($args[2]); 
     2804                $username  = $wpdb->escape($args[1]); 
     2805                $password   = $wpdb->escape($args[2]); 
    28152806                $data        = $args[3]; 
    28162807 
    28172808                $name = sanitize_file_name( $data['name'] ); 
     
    28202811 
    28212812                logIO('O', '(MW) Received '.strlen($bits).' bytes'); 
    28222813 
    2823                 if ( !$this->login_pass_ok($user_login, $user_pass) ) 
     2814                if ( !$user = $this->login($username, $password) ) { 
    28242815                        return $this->error; 
     2816                } 
    28252817 
    28262818                do_action('xmlrpc_call', 'metaWeblog.newMediaObject'); 
    28272819 
    2828                 set_current_user(0, $user_login); 
    28292820                if ( !current_user_can('upload_files') ) { 
    28302821                        logIO('O', '(MW) User does not have upload_files capability'); 
    28312822                        $this->error = new IXR_Error(401, __('You are not allowed to upload files to this site.')); 
     
    28952886                $this->escape($args); 
    28962887 
    28972888                $blog_ID     = (int) $args[0]; 
    2898                 $user_login  = $args[1]; 
    2899                 $user_pass   = $args[2]; 
     2889                $username  = $args[1]; 
     2890                $password   = $args[2]; 
    29002891                $num_posts   = (int) $args[3]; 
    29012892 
    2902                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     2893                if ( !$user = $this->login($username, $password) ) { 
    29032894                        return $this->error; 
    29042895                } 
    29052896 
     
    29122903                        return $this->error; 
    29132904                } 
    29142905 
    2915                 set_current_user( 0, $user_login ); 
    2916  
    29172906                foreach ($posts_list as $entry) { 
    29182907                        if( !current_user_can( 'edit_post', $entry['ID'] ) ) 
    29192908                                continue; 
     
    29522941                $this->escape($args); 
    29532942 
    29542943                $blog_ID     = (int) $args[0]; 
    2955                 $user_login  = $args[1]; 
    2956                 $user_pass   = $args[2]; 
     2944                $username  = $args[1]; 
     2945                $password   = $args[2]; 
    29572946 
    2958                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     2947                if ( !$user = $this->login($username, $password) ) { 
    29592948                        return $this->error; 
    29602949                } 
    29612950 
    2962                 set_current_user( 0, $user_login ); 
    29632951                if( !current_user_can( 'edit_posts' ) ) 
    29642952                        return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this blog in order to view categories.' ) ); 
    29652953 
     
    29922980                $this->escape($args); 
    29932981 
    29942982                $post_ID     = (int) $args[0]; 
    2995                 $user_login  = $args[1]; 
    2996                 $user_pass   = $args[2]; 
     2983                $username  = $args[1]; 
     2984                $password   = $args[2]; 
    29972985 
    2998                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     2986                if ( !$user = $this->login($username, $password) ) { 
    29992987                        return $this->error; 
    30002988                } 
    30012989 
    3002                 set_current_user( 0, $user_login ); 
    30032990                if( !current_user_can( 'edit_post', $post_ID ) ) 
    30042991                        return new IXR_Error( 401, __( 'Sorry, you can not edit this post.' ) ); 
    30052992 
     
    30343021                $this->escape($args); 
    30353022 
    30363023                $post_ID     = (int) $args[0]; 
    3037                 $user_login  = $args[1]; 
    3038                 $user_pass   = $args[2]; 
     3024                $username  = $args[1]; 
     3025                $password   = $args[2]; 
    30393026                $categories  = $args[3]; 
    30403027 
    3041                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     3028                if ( !$user = $this->login($username, $password) ) { 
    30423029                        return $this->error; 
    30433030                } 
    30443031 
    30453032                do_action('xmlrpc_call', 'mt.setPostCategories'); 
    30463033 
    3047                 set_current_user(0, $user_login); 
    30483034                if ( !current_user_can('edit_post', $post_ID) ) 
    30493035                        return new IXR_Error(401, __('Sorry, you can not edit this post.')); 
    30503036 
     
    31463132                $this->escape($args); 
    31473133 
    31483134                $post_ID     = (int) $args[0]; 
    3149                 $user_login  = $args[1]; 
    3150                 $user_pass   = $args[2]; 
     3135                $username  = $args[1]; 
     3136                $password   = $args[2]; 
    31513137 
    3152                 if (!$this->login_pass_ok($user_login, $user_pass)) { 
     3138                if ( !$user = $this->login($username, $password) ) { 
    31533139                        return $this->error; 
    31543140                } 
    31553141 
    31563142                do_action('xmlrpc_call', 'mt.publishPost'); 
    31573143 
    3158                 set_current_user(0, $user_login); 
    31593144                if ( !current_user_can('edit_post', $post_ID) ) 
    31603145                        return new IXR_Error(401, __('Sorry, you can not edit this post.')); 
    31613146