MCPcopy Create free account
hub / github.com/apache/cloudberry / sepgsql_utility_command

Function sepgsql_utility_command

contrib/sepgsql/hooks.c:313–395  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

311 * break whole of the things if nefarious user would use.
312 */
313static void
314sepgsql_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:

Callers

nothing calls this directly

Calls 5

sepgsql_getenforceFunction · 0.85
standard_ProcessUtilityFunction · 0.85
foreachFunction · 0.50
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected