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

Function GUCArrayReset

src/backend/utils/misc/guc.c:11818–11879  ·  view source on GitHub ↗

* Given a GUC array, delete all settings from it that our permission * level allows: if superuser, delete them all; if regular user, only * those that are PGC_USERSET */

Source from the content-addressed store, hash-verified

11816 * those that are PGC_USERSET
11817 */
11818ArrayType *
11819GUCArrayReset(ArrayType *array)
11820{
11821 ArrayType *newarray;
11822 int i;
11823 int index;
11824
11825 /* if array is currently null, nothing to do */
11826 if (!array)
11827 return NULL;
11828
11829 /* if we're superuser, we can delete everything, so just do it */
11830 if (superuser())
11831 return NULL;
11832
11833 newarray = NULL;
11834 index = 1;
11835
11836 for (i = 1; i <= ARR_DIMS(array)[0]; i++)
11837 {
11838 Datum d;
11839 char *val;
11840 char *eqsgn;
11841 bool isnull;
11842
11843 d = array_ref(array, 1, &i,
11844 -1 /* varlenarray */ ,
11845 -1 /* TEXT's typlen */ ,
11846 false /* TEXT's typbyval */ ,
11847 TYPALIGN_INT /* TEXT's typalign */ ,
11848 &isnull);
11849 if (isnull)
11850 continue;
11851 val = TextDatumGetCString(d);
11852
11853 eqsgn = strchr(val, '=');
11854 *eqsgn = '\0';
11855
11856 /* skip if we have permission to delete it */
11857 if (validate_option_array_item(val, NULL, true))
11858 continue;
11859
11860 /* else add it to the output array */
11861 if (newarray)
11862 newarray = array_set(newarray, 1, &index,
11863 d,
11864 false,
11865 -1 /* varlenarray */ ,
11866 -1 /* TEXT's typlen */ ,
11867 false /* TEXT's typbyval */ ,
11868 TYPALIGN_INT /* TEXT's typalign */ );
11869 else
11870 newarray = construct_array(&d, 1,
11871 TEXTOID,
11872 -1, false, TYPALIGN_INT);
11873
11874 index++;
11875 pfree(val);

Callers 1

AlterSettingFunction · 0.85

Calls 6

superuserFunction · 0.85
array_refFunction · 0.85
array_setFunction · 0.85
construct_arrayFunction · 0.85
pfreeFunction · 0.50

Tested by

no test coverage detected