Ticket #5313: xmlrpc.php.2.diff

File xmlrpc.php.2.diff, 3.2 kB (added by josephscott, 9 months ago)

Make sure cap checks happen

  • xmlrpc.php

    old new  
    11281128                if (!$this->login_pass_ok($user_login, $user_pass)) { 
    11291129                        return $this->error; 
    11301130                } 
     1131                $user = set_current_user(0, $user_login); 
    11311132 
    11321133                do_action('xmlrpc_call', 'metaWeblog.newPost'); 
    11331134 
    1134                 $cap = ($publish) ? 'publish_posts' : 'edit_posts'; 
    1135                 $user = set_current_user(0, $user_login); 
    1136                 if ( !current_user_can($cap) ) 
    1137                         return new IXR_Error(401, __('Sorry, you are not allowed to post on this blog.')); 
     1135                $cap = ( $publish ) ? 'publish_posts' : 'edit_posts'; 
     1136                $error_message = __( 'Sorry, you are not allowed to publish posts on this blog.' ); 
     1137                $post_type = 'post'; 
     1138                if( !empty( $content_struct['post_type'] ) ) { 
     1139                        if( $content_struct['post_type'] == 'page' ) { 
     1140                                $cap = ( $publish ) ? 'publish_pages' : 'edit_pages'; 
     1141                                $error_message = __( 'Sorry, you are not allowed to publish pages on this blog.' ); 
     1142                                $post_type = 'page'; 
     1143                        } 
     1144                        elseif( $content_type['post_type'] == 'post' ) { 
     1145                                // This is the default, no changes needed 
     1146                        } 
     1147                        else { 
     1148                                // No other post_type values are allowed here 
     1149                                return new IXR_Error( 401, __( 'Invalid post type.' ) ); 
     1150                        } 
     1151                } 
    11381152 
    1139                 // The post_type defaults to post, but could also be page. 
    1140                 $post_type = "post"; 
    1141                 if( 
    1142                         !empty($content_struct["post_type"]) 
    1143                         && ($content_struct["post_type"] == "page") 
    1144                 ) { 
    1145                         $post_type = "page"; 
     1153                if( !current_user_can( $cap ) ) { 
     1154                        return new IXR_Error( 401, $error_message ); 
    11461155                } 
    11471156 
    11481157                // Let WordPress generate the post_name (slug) unless 
     
    13681377                if (!$this->login_pass_ok($user_login, $user_pass)) { 
    13691378                        return $this->error; 
    13701379                } 
     1380                $user = set_current_user(0, $user_login); 
    13711381 
    13721382                do_action('xmlrpc_call', 'metaWeblog.editPost'); 
    13731383 
    1374                 $user = set_current_user(0, $user_login); 
    1375  
    1376                 // The post_type defaults to post, but could also be page. 
    1377                 $post_type = "post"; 
    1378                 if( 
    1379                         !empty($content_struct["post_type"]) 
    1380                         && ($content_struct["post_type"] == "page") 
    1381                 ) { 
    1382                         if( !current_user_can( 'edit_page', $post_ID ) ) { 
    1383                                 return(new IXR_Error(401, __("Sorry, you do not have the right to edit this page."))); 
     1384                $cap = ( $publish ) ? 'publish_posts' : 'edit_posts'; 
     1385                $error_message = __( 'Sorry, you are not allowed to publish posts on this blog.' ); 
     1386                $post_type = 'post'; 
     1387                if( !empty( $content_struct['post_type'] ) ) { 
     1388                        if( $content_struct['post_type'] == 'page' ) { 
     1389                                $cap = ( $publish ) ? 'publish_pages' : 'edit_pages'; 
     1390                                $error_message = __( 'Sorry, you are not allowed to publish pages on this blog.' ); 
     1391                                $post_type = 'page'; 
    13841392                        } 
     1393                        elseif( $content_type['post_type'] == 'post' ) { 
     1394                                // This is the default, no changes needed 
     1395                        } 
     1396                        else { 
     1397                                // No other post_type values are allowed here 
     1398                                return new IXR_Error( 401, __( 'Invalid post type.' ) ); 
     1399                        } 
     1400                } 
    13851401 
    1386                         $post_type = "page"; 
     1402                if( !current_user_can( $cap ) ) { 
     1403                        return new IXR_Error( 401, $error_message ); 
    13871404                } 
    13881405 
    1389                 if ( ( 'post' == $post_type ) && !current_user_can('edit_post', $post_ID) ) 
    1390                         return new IXR_Error(401, __('Sorry, you can not edit this post.')); 
    1391  
    13921406                $postdata = wp_get_single_post($post_ID, ARRAY_A); 
    13931407 
    13941408                // If there is no post data for the give post id, stop