From: Bborie Park Date: Sun, 13 Apr 2014 22:02:16 +0000 (+0000) Subject: If GUC postgis.gdal_enabled_drivers = 'DISABLE_ALL', use of GDALOpen and GDALOpenShar... X-Git-Tag: 2.2.0rc1~1127 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e79b6ab3fba1b7ee583f8169f857fa3f127f0b4a;p=postgis If GUC postgis.gdal_enabled_drivers = 'DISABLE_ALL', use of GDALOpen and GDALOpenShared is disabled. git-svn-id: http://svn.osgeo.org/postgis/trunk@12477 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_core/librtcore.h b/raster/rt_core/librtcore.h index 2d0cd298d..c69429d4e 100644 --- a/raster/rt_core/librtcore.h +++ b/raster/rt_core/librtcore.h @@ -2000,9 +2000,15 @@ extern void *rtalloc(size_t size); extern void *rtrealloc(void *mem, size_t size); extern void rtdealloc(void *mem); +/* + * GDAL driver flags + */ +#define GDAL_ENABLE_ALL "ENABLE_ALL" +#define GDAL_DISABLE_ALL "DISABLE_ALL" -/* Set of functions to clamp double to int of different size +/* + * Set of functions to clamp double to int of different size */ #if !defined(POSTGIS_RASTER_WARN_ON_TRUNCATION) @@ -2115,7 +2121,8 @@ rt_util_gdal_supported_sr(const char *srs); * * @return ES_NONE on success, ES_ERROR on error */ -rt_errorstate rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode); +rt_errorstate +rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode); /* is GDAL configured correctly? @@ -2135,6 +2142,12 @@ rt_util_gdal_register_all(int force_register_all); int rt_util_gdal_driver_registered(const char *drv); +/* + wrapper for GDALOpen and GDALOpenShared +*/ +GDALDatasetH +rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared); + void rt_util_from_ogr_envelope( OGREnvelope env, diff --git a/raster/rt_core/rt_band.c b/raster/rt_core/rt_band.c index 1e714b032..c4dd6f563 100644 --- a/raster/rt_core/rt_band.c +++ b/raster/rt_core/rt_band.c @@ -354,9 +354,9 @@ rt_band_load_offline_data(rt_band band) { rt_util_gdal_register_all(0); /* - hdsSrc = GDALOpenShared(band->data.offline.path, GA_ReadOnly); + hdsSrc = rt_util_gdal_open(band->data.offline.path, GA_ReadOnly, 1); */ - hdsSrc = GDALOpen(band->data.offline.path, GA_ReadOnly); + hdsSrc = rt_util_gdal_open(band->data.offline.path, GA_ReadOnly, 0); if (hdsSrc == NULL) { rterror("rt_band_load_offline_data: Cannot open offline raster: %s", band->data.offline.path); return ES_ERROR; @@ -450,8 +450,6 @@ rt_band_load_offline_data(rt_band band) { _rast = rt_raster_from_gdal_dataset(hdsDst); GDALClose(hdsDst); - /* XXX: need to find a way to clean up the GDALOpenShared datasets at end of transaction */ - /* GDALClose(hdsSrc); */ GDALClose(hdsSrc); /* { diff --git a/raster/rt_core/rt_util.c b/raster/rt_core/rt_util.c index 6960c6e17..4b62deedb 100644 --- a/raster/rt_core/rt_util.c +++ b/raster/rt_core/rt_util.c @@ -328,6 +328,8 @@ int rt_util_gdal_configured(void) { return 1; } +char *gdal_enabled_drivers = NULL; + /* register all GDAL drivers */ @@ -370,6 +372,27 @@ rt_util_gdal_driver_registered(const char *drv) { return 0; } +/* + wrapper for GDALOpen and GDALOpenShared +*/ +GDALDatasetH +rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared) { + assert(NULL != fn); + + if ( + gdal_enabled_drivers != NULL && + strstr(gdal_enabled_drivers, GDAL_DISABLE_ALL) != NULL + ) { + rterror("rt_util_gdal_open: Cannot open file. All GDAL drivers disabled"); + return NULL; + } + + if (shared) + return GDALOpenShared(fn, fn_access); + else + return GDALOpen(fn, fn_access); +} + void rt_util_from_ogr_envelope( OGREnvelope env, diff --git a/raster/rt_pg/rtpg_create.c b/raster/rt_pg/rtpg_create.c index 1dd5f5a6b..67388ad52 100644 --- a/raster/rt_pg/rtpg_create.c +++ b/raster/rt_pg/rtpg_create.c @@ -726,7 +726,7 @@ Datum RASTER_addBandOutDB(PG_FUNCTION_ARGS) /* open outdb raster file */ rt_util_gdal_register_all(0); - hdsOut = GDALOpenShared(outdbfile, GA_ReadOnly); + hdsOut = rt_util_gdal_open(outdbfile, GA_ReadOnly, 0); if (hdsOut == NULL) { if (pgraster != NULL) { rt_raster_destroy(raster); diff --git a/raster/rt_pg/rtpg_gdal.c b/raster/rt_pg/rtpg_gdal.c index e787bafd7..35b253df8 100644 --- a/raster/rt_pg/rtpg_gdal.c +++ b/raster/rt_pg/rtpg_gdal.c @@ -97,7 +97,7 @@ Datum RASTER_fromGDALRaster(PG_FUNCTION_ARGS) rt_util_gdal_register_all(0); /* open GDAL raster */ - hdsSrc = GDALOpenShared("/vsimem/in.dat", GA_ReadOnly); + hdsSrc = rt_util_gdal_open("/vsimem/in.dat", GA_ReadOnly, 1); if (hdsSrc == NULL) { VSIFCloseL(vsifp); PG_FREE_IF_COPY(bytea_data, 0); diff --git a/raster/rt_pg/rtpostgis.c b/raster/rt_pg/rtpostgis.c index 0c750e702..387202dd3 100644 --- a/raster/rt_pg/rtpostgis.c +++ b/raster/rt_pg/rtpostgis.c @@ -152,8 +152,8 @@ void _PG_init(void); /* PostGIS raster GUCs */ /* ---------------------------------------------------------------- */ -static char *gdaldatapath = NULL; -static char *gdalenableddrivers = NULL; +static char *gdal_datapath = NULL; +extern char *gdal_enabled_drivers; /* postgis.gdal_datapath */ static void @@ -173,8 +173,6 @@ rtpg_assignHookGDALDataPath(const char *newpath, void *extra) { } /* postgis.gdal_enabled_drivers */ -#define ENABLE_ALL "ENABLE_ALL" -#define DISABLE_ALL "DISABLE_ALL" static void rtpg_assignHookGDALEnabledDrivers(const char *enabled_drivers, void *extra) { int enable_all = 0; @@ -207,17 +205,17 @@ rtpg_assignHookGDALEnabledDrivers(const char *enabled_drivers, void *extra) { /* scan for keywords DISABLE_ALL and ENABLE_ALL */ disable_all = 0; enable_all = 0; - if (strstr(enabled_drivers, DISABLE_ALL) != NULL) { + if (strstr(enabled_drivers, GDAL_DISABLE_ALL) != NULL) { for (i = 0; i < enabled_drivers_count; i++) { - if (strstr(enabled_drivers_array[i], DISABLE_ALL) != NULL) { + if (strstr(enabled_drivers_array[i], GDAL_DISABLE_ALL) != NULL) { disable_all = 1; break; } } } - else if (strstr(enabled_drivers, ENABLE_ALL) != NULL) { + else if (strstr(enabled_drivers, GDAL_ENABLE_ALL) != NULL) { for (i = 0; i < enabled_drivers_count; i++) { - if (strstr(enabled_drivers_array[i], ENABLE_ALL) != NULL) { + if (strstr(enabled_drivers_array[i], GDAL_ENABLE_ALL) != NULL) { enable_all = 1; break; } @@ -308,7 +306,7 @@ _PG_init(void) { "postgis.gdal_datapath", /* name */ "Path to GDAL data files.", /* short_desc */ "Physical path to directory containing GDAL data files (sets the GDAL_DATA config option).", /* long_desc */ - &gdaldatapath, /* valueAddr */ + &gdal_datapath, /* valueAddr */ NULL, /* bootValue */ PGC_SUSET, /* GucContext context */ 0, /* int flags */ @@ -333,8 +331,8 @@ _PG_init(void) { "postgis.gdal_enabled_drivers", /* name */ "Enabled GDAL drivers.", /* short_desc */ "List of enabled GDAL drivers by short name. To enable/disable all drivers, use 'ENABLE_ALL' or 'DISABLE_ALL' (sets the GDAL_SKIP config option).", /* long_desc */ - &gdalenableddrivers, /* valueAddr */ - DISABLE_ALL, /* bootValue */ + &gdal_enabled_drivers, /* valueAddr */ + GDAL_DISABLE_ALL, /* bootValue */ PGC_SUSET, /* GucContext context */ GUC_LIST_INPUT, /* int flags */ #if POSTGIS_PGSQL_VERSION >= 91