2011-01-24 09:44:48 +08:00
|
|
|
/* -------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* contrib/sepgsql/schema.c
|
|
|
|
*
|
|
|
|
* Routines corresponding to schema objects
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010-2011, PostgreSQL Global Development Group
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
2011-02-03 12:39:43 +08:00
|
|
|
#include "catalog/dependency.h"
|
2011-01-24 09:44:48 +08:00
|
|
|
#include "catalog/pg_namespace.h"
|
|
|
|
#include "commands/seclabel.h"
|
|
|
|
#include "utils/lsyscache.h"
|
|
|
|
|
|
|
|
#include "sepgsql.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sepgsql_schema_post_create
|
|
|
|
*
|
|
|
|
* This routine assigns a default security label on a newly defined
|
|
|
|
* schema.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sepgsql_schema_post_create(Oid namespaceId)
|
|
|
|
{
|
2011-04-10 23:42:00 +08:00
|
|
|
char *scontext = sepgsql_get_client_label();
|
|
|
|
char *tcontext;
|
|
|
|
char *ncontext;
|
|
|
|
ObjectAddress object;
|
2011-01-24 09:44:48 +08:00
|
|
|
|
|
|
|
/*
|
2011-04-10 23:42:00 +08:00
|
|
|
* FIXME: Right now, we assume pg_database object has a fixed security
|
|
|
|
* label, because pg_seclabel does not support to store label of shared
|
|
|
|
* database objects.
|
2011-01-24 09:44:48 +08:00
|
|
|
*/
|
|
|
|
tcontext = "system_u:object_r:sepgsql_db_t:s0";
|
|
|
|
|
|
|
|
/*
|
2011-04-10 23:42:00 +08:00
|
|
|
* Compute a default security label when we create a new schema object
|
|
|
|
* under the working database.
|
2011-01-24 09:44:48 +08:00
|
|
|
*/
|
|
|
|
ncontext = sepgsql_compute_create(scontext, tcontext,
|
|
|
|
SEPG_CLASS_DB_SCHEMA);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assign the default security label on a new procedure
|
|
|
|
*/
|
|
|
|
object.classId = NamespaceRelationId;
|
|
|
|
object.objectId = namespaceId;
|
|
|
|
object.objectSubId = 0;
|
|
|
|
SetSecurityLabel(&object, SEPGSQL_LABEL_TAG, ncontext);
|
|
|
|
|
|
|
|
pfree(ncontext);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sepgsql_schema_relabel
|
|
|
|
*
|
|
|
|
* It checks privileges to relabel the supplied schema
|
|
|
|
* by the `seclabel'.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sepgsql_schema_relabel(Oid namespaceId, const char *seclabel)
|
|
|
|
{
|
|
|
|
char *scontext = sepgsql_get_client_label();
|
|
|
|
char *tcontext;
|
|
|
|
char *audit_name;
|
|
|
|
|
2011-02-03 12:39:43 +08:00
|
|
|
audit_name = getObjectDescriptionOids(NamespaceRelationId, namespaceId);
|
2011-01-24 09:44:48 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check db_schema:{setattr relabelfrom} permission
|
|
|
|
*/
|
|
|
|
tcontext = sepgsql_get_label(NamespaceRelationId, namespaceId, 0);
|
|
|
|
|
|
|
|
sepgsql_check_perms(scontext,
|
|
|
|
tcontext,
|
|
|
|
SEPG_CLASS_DB_SCHEMA,
|
|
|
|
SEPG_DB_SCHEMA__SETATTR |
|
|
|
|
SEPG_DB_SCHEMA__RELABELFROM,
|
|
|
|
audit_name,
|
|
|
|
true);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check db_schema:{relabelto} permission
|
|
|
|
*/
|
|
|
|
sepgsql_check_perms(scontext,
|
|
|
|
seclabel,
|
|
|
|
SEPG_CLASS_DB_SCHEMA,
|
|
|
|
SEPG_DB_SCHEMA__RELABELTO,
|
|
|
|
audit_name,
|
|
|
|
true);
|
|
|
|
|
|
|
|
pfree(tcontext);
|
|
|
|
pfree(audit_name);
|
|
|
|
}
|