1010 * Written by Peter Eisentraut <peter_e@gmx.net>.
1111 *
1212 * IDENTIFICATION
13- * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.195 2004/04/01 21:28:45 tgl Exp $
13+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.196 2004/04/05 02:48:09 momjian Exp $
1414 *
1515 *--------------------------------------------------------------------
1616 */
@@ -2571,8 +2571,7 @@ set_config_option(const char *name, const char *value,
25712571{
25722572struct config_generic * record ;
25732573int elevel ;
2574- bool makeDefault ;
2575- bool changeVal_orig ;
2574+ bool makeDefault ,changeValOrig = changeVal ;
25762575
25772576if (context == PGC_SIGHUP || source == PGC_S_DEFAULT )
25782577elevel = DEBUG2 ;
@@ -2694,7 +2693,6 @@ set_config_option(const char *name, const char *value,
26942693 * to set the reset/session values even if we can't set the variable
26952694 * itself.
26962695 */
2697- changeVal_orig = changeVal ;/* we might have to reverse this later */
26982696if (record -> source > source )
26992697{
27002698if (changeVal && !makeDefault )
@@ -2703,11 +2701,15 @@ set_config_option(const char *name, const char *value,
27032701name );
27042702return true;
27052703}
2706- changeVal = false;/*we won't change the variable itself */
2704+ changeVal = false;/*this might be reset in USERLIMIT */
27072705}
27082706
27092707/*
2710- * Evaluate value and set variable
2708+ * Evaluate value and set variable.
2709+ * USERLIMIT checks two things: 1) is the user making a change
2710+ * that is blocked by an administrator setting. 2) is the administrator
2711+ * changing a setting and doing a SIGHUP that requires us to override
2712+ * a user setting.
27112713 */
27122714switch (record -> vartype )
27132715{
@@ -2726,26 +2728,30 @@ set_config_option(const char *name, const char *value,
27262728name )));
27272729return false;
27282730}
2729- /* Limit non-superuser changes */
27302731if (record -> context == PGC_USERLIMIT &&
2731- source > PGC_S_UNPRIVILEGED &&
2732- newval < conf -> reset_val &&
2733- !superuser ())
2732+ IsUnderPostmaster && !superuser ())
27342733{
2735- ereport (elevel ,
2736- (errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
2737- errmsg ("permission denied to set parameter \"%s\"" ,
2738- name ),
2739- errhint ("Must be superuser to change this value to false." )));
2740- return false;
2734+ if (newval < conf -> reset_val )
2735+ {
2736+ /* Limit non-superuser changes */
2737+ if (source > PGC_S_UNPRIVILEGED )
2738+ {
2739+ ereport (elevel ,
2740+ (errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
2741+ errmsg ("permission denied to set parameter \"%s\"" ,
2742+ name ),
2743+ errhint ("Must be superuser to change this value to false." )));
2744+ return false;
2745+ }
2746+ }
2747+ if (newval > * conf -> variable )
2748+ {
2749+ /* Allow change if admin should override */
2750+ if (source < PGC_S_UNPRIVILEGED &&
2751+ record -> source > PGC_S_UNPRIVILEGED )
2752+ changeVal = changeValOrig ;
2753+ }
27412754}
2742- /* Honor change to config file with SIGHUP */
2743- if (record -> context == PGC_USERLIMIT &&
2744- source < PGC_S_UNPRIVILEGED &&
2745- record -> reset_source > PGC_S_UNPRIVILEGED &&
2746- newval > conf -> reset_val &&
2747- !superuser ())
2748- changeVal = changeVal_orig ;
27492755}
27502756else
27512757{
@@ -2822,27 +2828,35 @@ set_config_option(const char *name, const char *value,
28222828newval ,name ,conf -> min ,conf -> max )));
28232829return false;
28242830}
2825- /* Limit non-superuser changes */
28262831if (record -> context == PGC_USERLIMIT &&
2827- source > PGC_S_UNPRIVILEGED &&
2828- conf -> reset_val != 0 &&
2829- (newval > conf -> reset_val || newval == 0 )&&
2830- !superuser ())
2832+ IsUnderPostmaster && !superuser ())
28312833{
2832- ereport (elevel ,
2833- (errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
2834- errmsg ("permission denied to set parameter \"%s\"" ,
2835- name ),
2836- errhint ("Must be superuser to increase this value or set it to zero." )));
2837- return false;
2834+ /* handle log_min_duration_statement, -1=disable */
2835+ if ((newval != -1 && conf -> reset_val != -1 &&
2836+ newval > conf -> reset_val )|| /* increase duration */
2837+ (newval == -1 && conf -> reset_val != -1 ))/* turn off */
2838+ {
2839+ /* Limit non-superuser changes */
2840+ if (source > PGC_S_UNPRIVILEGED )
2841+ {
2842+ ereport (elevel ,
2843+ (errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
2844+ errmsg ("permission denied to set parameter \"%s\"" ,
2845+ name ),
2846+ errhint ("Must be superuser to increase this value or turn it off." )));
2847+ return false;
2848+ }
2849+ }
2850+ /* Allow change if admin should override */
2851+ if ((newval != -1 && * conf -> variable != -1 &&
2852+ newval < * conf -> variable )|| /* decrease duration */
2853+ (newval != -1 && * conf -> variable == -1 ))/* turn on */
2854+ {
2855+ if (source < PGC_S_UNPRIVILEGED &&
2856+ record -> source > PGC_S_UNPRIVILEGED )
2857+ changeVal = changeValOrig ;
2858+ }
28382859}
2839- /* Honor change to config file with SIGHUP */
2840- if (record -> context == PGC_USERLIMIT &&
2841- source < PGC_S_UNPRIVILEGED &&
2842- record -> reset_source > PGC_S_UNPRIVILEGED &&
2843- newval < conf -> reset_val && newval != 0 &&
2844- !superuser ())
2845- changeVal = changeVal_orig ;
28462860}
28472861else
28482862{
@@ -2919,26 +2933,25 @@ set_config_option(const char *name, const char *value,
29192933newval ,name ,conf -> min ,conf -> max )));
29202934return false;
29212935}
2922- /* Limit non-superuser changes */
29232936if (record -> context == PGC_USERLIMIT &&
2924- source > PGC_S_UNPRIVILEGED &&
2925- newval > conf -> reset_val &&
2926- !superuser ())
2937+ IsUnderPostmaster && !superuser ())
2938+ /* No REAL PGC_USERLIMIT */
29272939{
2928- ereport (elevel ,
2929- (errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
2930- errmsg ("permission denied to set parameter \"%s\"" ,
2931- name ),
2932- errhint ("Must be superuser to increase this value." )));
2933- return false;
2940+ /* Limit non-superuser changes */
2941+ if (source > PGC_S_UNPRIVILEGED )
2942+ {
2943+ ereport (elevel ,
2944+ (errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
2945+ errmsg ("permission denied to set parameter \"%s\"" ,
2946+ name ),
2947+ errhint ("Must be superuser to increase this value or turn it off." )));
2948+ return false;
2949+ }
2950+ /* Allow change if admin should override */
2951+ if (source < PGC_S_UNPRIVILEGED &&
2952+ record -> source > PGC_S_UNPRIVILEGED )
2953+ changeVal = false;
29342954}
2935- /* Honor change to config file with SIGHUP */
2936- if (record -> context == PGC_USERLIMIT &&
2937- source < PGC_S_UNPRIVILEGED &&
2938- record -> reset_source > PGC_S_UNPRIVILEGED &&
2939- newval < conf -> reset_val &&
2940- !superuser ())
2941- changeVal = changeVal_orig ;
29422955}
29432956else
29442957{
@@ -3009,34 +3022,38 @@ set_config_option(const char *name, const char *value,
30093022}
30103023
30113024if (record -> context == PGC_USERLIMIT &&
3012- * conf -> variable )
3025+ IsUnderPostmaster && ! superuser () )
30133026{
30143027int old_int_value ,
30153028new_int_value ;
30163029
30173030/* all USERLIMIT strings are message levels */
3018- assign_msglvl (& old_int_value ,conf -> reset_val ,
3019- true,source );
30203031assign_msglvl (& new_int_value ,newval ,
30213032 true,source );
3022- /* Limit non-superuser changes */
3023- if (source > PGC_S_UNPRIVILEGED &&
3024- new_int_value > old_int_value &&
3025- !superuser ())
3033+ assign_msglvl (& old_int_value ,conf -> reset_val ,
3034+ true,source );
3035+ if (new_int_value > old_int_value )
30263036{
3027- ereport (elevel ,
3028- (errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
3037+ /* Limit non-superuser changes */
3038+ if (source > PGC_S_UNPRIVILEGED )
3039+ {
3040+ ereport (elevel ,
3041+ (errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
30293042errmsg ("permission denied to set parameter \"%s\"" ,
30303043name ),
3031- errhint ("Must be superuser to increase this value." )));
3032- return false;
3044+ errhint ("Must be superuser to increase this value." )));
3045+ return false;
3046+ }
3047+ }
3048+ /* Allow change if admin should override */
3049+ assign_msglvl (& old_int_value ,* conf -> variable ,
3050+ true,source );
3051+ if (new_int_value < old_int_value )
3052+ {
3053+ if (source < PGC_S_UNPRIVILEGED &&
3054+ record -> source > PGC_S_UNPRIVILEGED )
3055+ changeVal = changeValOrig ;
30333056}
3034- /* Honor change to config file with SIGHUP */
3035- if (source < PGC_S_UNPRIVILEGED &&
3036- record -> reset_source > PGC_S_UNPRIVILEGED &&
3037- newval < conf -> reset_val &&
3038- !superuser ())
3039- changeVal = changeVal_orig ;
30403057}
30413058}
30423059else if (conf -> reset_val )