* sepgsql_utility_command * * It tries to rough-grained control on utility commands; some of them can * break whole of the things if nefarious user would use. */
| 311 | * break whole of the things if nefarious user would use. |
| 312 | */ |
| 313 | static void |
| 314 | sepgsql_utility_command(PlannedStmt *pstmt, |
| 315 | const char *queryString, |
| 316 | bool readOnlyTree, |
| 317 | ProcessUtilityContext context, |
| 318 | ParamListInfo params, |
| 319 | QueryEnvironment *queryEnv, |
| 320 | DestReceiver *dest, |
| 321 | QueryCompletion *qc) |
| 322 | { |
| 323 | Node *parsetree = pstmt->utilityStmt; |
| 324 | sepgsql_context_info_t saved_context_info = sepgsql_context_info; |
| 325 | ListCell *cell; |
| 326 | |
| 327 | PG_TRY(); |
| 328 | { |
| 329 | /* |
| 330 | * Check command tag to avoid nefarious operations, and save the |
| 331 | * current contextual information to determine whether we should apply |
| 332 | * permission checks here, or not. |
| 333 | */ |
| 334 | sepgsql_context_info.cmdtype = nodeTag(parsetree); |
| 335 | |
| 336 | switch (nodeTag(parsetree)) |
| 337 | { |
| 338 | case T_CreatedbStmt: |
| 339 | |
| 340 | /* |
| 341 | * We hope to reference name of the source database, but it |
| 342 | * does not appear in system catalog. So, we save it here. |
| 343 | */ |
| 344 | foreach(cell, ((CreatedbStmt *) parsetree)->options) |
| 345 | { |
| 346 | DefElem *defel = (DefElem *) lfirst(cell); |
| 347 | |
| 348 | if (strcmp(defel->defname, "template") == 0) |
| 349 | { |
| 350 | sepgsql_context_info.createdb_dtemplate |
| 351 | = strVal(defel->arg); |
| 352 | break; |
| 353 | } |
| 354 | } |
| 355 | break; |
| 356 | |
| 357 | case T_LoadStmt: |
| 358 | |
| 359 | /* |
| 360 | * We reject LOAD command across the board on enforcing mode, |
| 361 | * because a binary module can arbitrarily override hooks. |
| 362 | */ |
| 363 | if (sepgsql_getenforce()) |
| 364 | { |
| 365 | ereport(ERROR, |
| 366 | (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 367 | errmsg("SELinux: LOAD is not permitted"))); |
| 368 | } |
| 369 | break; |
| 370 | default: |
nothing calls this directly
no test coverage detected