File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 933933 'arguments ' => [
934934 '$response ' => '@response ' ,
935935 '$sql ' => '@sql ' ,
936- '$dbi ' => '@dbi ' ,
937936 '$pageSettings ' => '@ ' . PageSettings::class,
938937 '$bookmarkRepository ' => '@bookmarkRepository ' ,
939938 '$config ' => '@config ' ,
Original file line number Diff line number Diff line change @@ -618,13 +618,7 @@ public function __invoke(ServerRequest $request): Response
618618 ResponseRenderer::$ reload = $ reloadNeeded ;
619619
620620 // Check if User is allowed to issue a 'DROP DATABASE' Statement
621- if (
622- $ this ->sql ->hasNoRightsToDropDatabase (
623- $ statementInfo ,
624- $ this ->config ->settings ['AllowUserDropDatabase ' ],
625- $ this ->dbi ->isSuperUser (),
626- )
627- ) {
621+ if ($ this ->sql ->hasNoRightsToDropDatabase ($ statementInfo )) {
628622 Generator::mysqlDie (
629623 __ ('"DROP DATABASE" statements are disabled. ' ),
630624 '' ,
Original file line number Diff line number Diff line change 1010use PhpMyAdmin \Controllers \InvocableController ;
1111use PhpMyAdmin \Core ;
1212use PhpMyAdmin \Current ;
13- use PhpMyAdmin \Dbal \DatabaseInterface ;
1413use PhpMyAdmin \Html \Generator ;
1514use PhpMyAdmin \Http \Response ;
1615use PhpMyAdmin \Http \ServerRequest ;
3534 public function __construct (
3635 private ResponseRenderer $ response ,
3736 private Sql $ sql ,
38- private DatabaseInterface $ dbi ,
3937 private PageSettings $ pageSettings ,
4038 private BookmarkRepository $ bookmarkRepository ,
4139 private Config $ config ,
@@ -134,13 +132,7 @@ public function __invoke(ServerRequest $request): Response
134132 * but since a malicious user may pass this variable by url/form, we don't take
135133 * into account this case.
136134 */
137- if (
138- $ this ->sql ->hasNoRightsToDropDatabase (
139- $ statementInfo ,
140- $ this ->config ->settings ['AllowUserDropDatabase ' ],
141- $ this ->dbi ->isSuperUser (),
142- )
143- ) {
135+ if ($ this ->sql ->hasNoRightsToDropDatabase ($ statementInfo )) {
144136 Generator::mysqlDie (
145137 __ ('"DROP DATABASE" statements are disabled. ' ),
146138 '' ,
Original file line number Diff line number Diff line change @@ -414,18 +414,12 @@ private function isDeleteTransformationInfo(StatementInfo $statementInfo): bool
414414 || $ statementInfo ->flags ->queryType === StatementType::Drop;
415415 }
416416
417- /**
418- * Function to check whether the user has rights to drop the database
419- *
420- * @param bool $allowUserDropDatabase whether the user is allowed to drop db
421- * @param bool $isSuperUser whether this user is a superuser
422- */
423417 public function hasNoRightsToDropDatabase (
424418 StatementInfo $ statementInfo ,
425- bool $ allowUserDropDatabase ,
426- bool $ isSuperUser ,
427419 ): bool {
428- return ! $ allowUserDropDatabase && $ statementInfo ->flags ->dropDatabase && ! $ isSuperUser ;
420+ return ! $ this ->config ->settings ['AllowUserDropDatabase ' ]
421+ && $ statementInfo ->flags ->dropDatabase
422+ && ! $ this ->dbi ->isSuperUser ();
429423 }
430424
431425 /**
Original file line number Diff line number Diff line change @@ -113,7 +113,6 @@ public function testReplace(): void
113113 $ bookmarkRepository ,
114114 $ config ,
115115 ),
116- $ dbi ,
117116 $ pageSettings ,
118117 $ bookmarkRepository ,
119118 $ config ,
Original file line number Diff line number Diff line change @@ -197,27 +197,26 @@ public function testIsDeleteTransformationInfo(): void
197197 */
198198 public function testHasNoRightsToDropDatabase (): void
199199 {
200+ $ this ->dummyDbi ->addResult (
201+ 'SELECT 1 FROM mysql.user LIMIT 1 ' ,
202+ [],
203+ );
204+
200205 self ::assertTrue (
201206 $ this ->sql ->hasNoRightsToDropDatabase (
202207 ParseAnalyze::sqlQuery ('DROP DATABASE db ' , Current::$ database )[0 ],
203- false ,
204- false ,
205208 ),
206209 );
207210
208211 self ::assertFalse (
209212 $ this ->sql ->hasNoRightsToDropDatabase (
210213 ParseAnalyze::sqlQuery ('DROP TABLE tbl ' , Current::$ database )[0 ],
211- false ,
212- false ,
213214 ),
214215 );
215216
216217 self ::assertFalse (
217218 $ this ->sql ->hasNoRightsToDropDatabase (
218219 ParseAnalyze::sqlQuery ('SELECT * from tbl ' , Current::$ database )[0 ],
219- false ,
220- false ,
221220 ),
222221 );
223222 }
You can’t perform that action at this time.
0 commit comments