PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
variable.c File Reference
#include "postgres.h"
#include <ctype.h>
#include "access/htup_details.h"
#include "access/parallel.h"
#include "access/xact.h"
#include "access/xlog.h"
#include "catalog/pg_authid.h"
#include "commands/variable.h"
#include "miscadmin.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/syscache.h"
#include "utils/snapmgr.h"
#include "utils/timestamp.h"
#include "utils/varlena.h"
#include "mb/pg_wchar.h"
Include dependency graph for variable.c:

Go to the source code of this file.

Data Structures

struct  role_auth_extra
 

Functions

bool check_datestyle (char **newval, void **extra, GucSource source)
 
void assign_datestyle (const char *newval, void *extra)
 
bool check_timezone (char **newval, void **extra, GucSource source)
 
void assign_timezone (const char *newval, void *extra)
 
const char * show_timezone (void)
 
bool check_log_timezone (char **newval, void **extra, GucSource source)
 
void assign_log_timezone (const char *newval, void *extra)
 
const char * show_log_timezone (void)
 
bool check_transaction_read_only (bool *newval, void **extra, GucSource source)
 
bool check_XactIsoLevel (char **newval, void **extra, GucSource source)
 
void assign_XactIsoLevel (const char *newval, void *extra)
 
const char * show_XactIsoLevel (void)
 
bool check_transaction_deferrable (bool *newval, void **extra, GucSource source)
 
bool check_random_seed (double *newval, void **extra, GucSource source)
 
void assign_random_seed (double newval, void *extra)
 
const char * show_random_seed (void)
 
bool check_client_encoding (char **newval, void **extra, GucSource source)
 
void assign_client_encoding (const char *newval, void *extra)
 
bool check_session_authorization (char **newval, void **extra, GucSource source)
 
void assign_session_authorization (const char *newval, void *extra)
 
bool check_role (char **newval, void **extra, GucSource source)
 
void assign_role (const char *newval, void *extra)
 
const char * show_role (void)
 

Variables

char * role_string
 

Function Documentation

void assign_client_encoding ( const char *  newval,
void *  extra 
)

Definition at line 751 of file variable.c.

References elog, encoding, ereport, errcode(), errmsg(), ERROR, InitializingParallelWorker, IsParallelWorker, LOG, and SetClientEncoding().

752 {
753  int encoding = *((int *) extra);
754 
755  /*
756  * Parallel workers send data to the leader, not the client. They always
757  * send data using the database encoding.
758  */
759  if (IsParallelWorker())
760  {
761  /*
762  * During parallel worker startup, we want to accept the leader's
763  * client_encoding setting so that anyone who looks at the value in
764  * the worker sees the same value that they would see in the leader.
765  */
767  return;
768 
769  /*
770  * A change other than during startup, for example due to a SET clause
771  * attached to a function definition, should be rejected, as there is
772  * nothing we can do inside the worker to make it take effect.
773  */
774  ereport(ERROR,
775  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
776  errmsg("cannot change client_encoding during a parallel operation")));
777  }
778 
779  /* We do not expect an error if PrepareClientEncoding succeeded */
780  if (SetClientEncoding(encoding) < 0)
781  elog(LOG, "SetClientEncoding(%d) failed", encoding);
782 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define LOG
Definition: elog.h:26
#define ERROR
Definition: elog.h:43
int SetClientEncoding(int encoding)
Definition: mbutils.c:212
#define ereport(elevel, rest)
Definition: elog.h:122
#define IsParallelWorker()
Definition: parallel.h:52
static char * encoding
Definition: initdb.c:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool InitializingParallelWorker
Definition: parallel.c:100
#define elog
Definition: elog.h:219
void assign_datestyle ( const char *  newval,
void *  extra 
)

Definition at line 236 of file variable.c.

References DateOrder, and DateStyle.

237 {
238  int *myextra = (int *) extra;
239 
240  DateStyle = myextra[0];
241  DateOrder = myextra[1];
242 }
int DateOrder
Definition: globals.c:108
int DateStyle
Definition: globals.c:107
void assign_log_timezone ( const char *  newval,
void *  extra 
)

Definition at line 446 of file variable.c.

References log_timezone.

447 {
448  log_timezone = *((pg_tz **) extra);
449 }
pg_tz * log_timezone
Definition: pgtz.c:31
Definition: pgtz.h:59
void assign_random_seed ( double  newval,
void *  extra 
)

Definition at line 655 of file variable.c.

References DirectFunctionCall1, Float8GetDatum(), and setseed().

656 {
657  /* We'll do this at most once for any setting of the GUC variable */
658  if (*((int *) extra))
660  *((int *) extra) = 0;
661 }
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
Datum Float8GetDatum(float8 X)
Definition: fmgr.c:1815
Datum setseed(PG_FUNCTION_ARGS)
Definition: float.c:2431
#define newval
void assign_role ( const char *  newval,
void *  extra 
)

Definition at line 930 of file variable.c.

References role_auth_extra::is_superuser, role_auth_extra::roleid, and SetCurrentRoleId().

931 {
932  role_auth_extra *myextra = (role_auth_extra *) extra;
933 
934  SetCurrentRoleId(myextra->roleid, myextra->is_superuser);
935 }
void SetCurrentRoleId(Oid roleid, bool is_superuser)
Definition: miscinit.c:657
bool is_superuser
Definition: variable.c:793
void assign_session_authorization ( const char *  newval,
void *  extra 
)

Definition at line 843 of file variable.c.

References role_auth_extra::is_superuser, role_auth_extra::roleid, and SetSessionAuthorization().

844 {
845  role_auth_extra *myextra = (role_auth_extra *) extra;
846 
847  /* Do nothing for the boot_val default of NULL */
848  if (!myextra)
849  return;
850 
851  SetSessionAuthorization(myextra->roleid, myextra->is_superuser);
852 }
void SetSessionAuthorization(Oid userid, bool is_superuser)
Definition: miscinit.c:611
bool is_superuser
Definition: variable.c:793
void assign_timezone ( const char *  newval,
void *  extra 
)

Definition at line 373 of file variable.c.

References session_timezone.

374 {
375  session_timezone = *((pg_tz **) extra);
376 }
Definition: pgtz.h:59
pg_tz * session_timezone
Definition: pgtz.c:28
void assign_XactIsoLevel ( const char *  newval,
void *  extra 
)

Definition at line 586 of file variable.c.

References XactIsoLevel.

587 {
588  XactIsoLevel = *((int *) extra);
589 }
int XactIsoLevel
Definition: xact.c:74
bool check_client_encoding ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 675 of file variable.c.

References encoding, free, GetDatabaseEncodingName(), GUC_check_errcode(), GUC_check_errdetail, IsTransactionState(), malloc, pg_encoding_to_char(), pg_valid_client_encoding(), and PrepareClientEncoding().

676 {
677  int encoding;
678  const char *canonical_name;
679 
680  /* Look up the encoding by name */
681  encoding = pg_valid_client_encoding(*newval);
682  if (encoding < 0)
683  return false;
684 
685  /* Get the canonical name (no aliases, uniform case) */
686  canonical_name = pg_encoding_to_char(encoding);
687 
688  /*
689  * If we are not within a transaction then PrepareClientEncoding will not
690  * be able to look up the necessary conversion procs. If we are still
691  * starting up, it will return "OK" anyway, and InitializeClientEncoding
692  * will fix things once initialization is far enough along. After
693  * startup, we'll fail. This would only happen if someone tries to change
694  * client_encoding in postgresql.conf and then SIGHUP existing sessions.
695  * It seems like a bad idea for client_encoding to change that way anyhow,
696  * so we don't go out of our way to support it.
697  *
698  * Note: in the postmaster, or any other process that never calls
699  * InitializeClientEncoding, PrepareClientEncoding will always succeed,
700  * and so will SetClientEncoding; but they won't do anything, which is OK.
701  */
702  if (PrepareClientEncoding(encoding) < 0)
703  {
704  if (IsTransactionState())
705  {
706  /* Must be a genuine no-such-conversion problem */
707  GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
708  GUC_check_errdetail("Conversion between %s and %s is not supported.",
709  canonical_name,
711  }
712  else
713  {
714  /* Provide a useful complaint */
715  GUC_check_errdetail("Cannot change \"client_encoding\" now.");
716  }
717  return false;
718  }
719 
720  /*
721  * Replace the user-supplied string with the encoding's canonical name.
722  * This gets rid of aliases and case-folding variations.
723  *
724  * XXX Although canonicalizing seems like a good idea in the abstract, it
725  * breaks pre-9.1 JDBC drivers, which expect that if they send "UNICODE"
726  * as the client_encoding setting then it will read back the same way. As
727  * a workaround, don't replace the string if it's "UNICODE". Remove that
728  * hack when pre-9.1 JDBC drivers are no longer in use.
729  */
730  if (strcmp(*newval, canonical_name) != 0 &&
731  strcmp(*newval, "UNICODE") != 0)
732  {
733  free(*newval);
734  *newval = strdup(canonical_name);
735  if (!*newval)
736  return false;
737  }
738 
739  /*
740  * Save the encoding's ID in *extra, for use by assign_client_encoding.
741  */
742  *extra = malloc(sizeof(int));
743  if (!*extra)
744  return false;
745  *((int *) *extra) = encoding;
746 
747  return true;
748 }
int PrepareClientEncoding(int encoding)
Definition: mbutils.c:114
#define GUC_check_errdetail
Definition: guc.h:407
int pg_valid_client_encoding(const char *name)
Definition: encnames.c:487
void GUC_check_errcode(int sqlerrcode)
Definition: guc.c:9784
#define malloc(a)
Definition: header.h:50
static char * encoding
Definition: initdb.c:122
#define free(a)
Definition: header.h:65
const char * pg_encoding_to_char(int encoding)
Definition: encnames.c:607
const char * GetDatabaseEncodingName(void)
Definition: mbutils.c:1021
#define newval
bool IsTransactionState(void)
Definition: xact.c:350
bool check_datestyle ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 44 of file variable.c.

References check_datestyle(), DateOrder, DATEORDER_DMY, DATEORDER_MDY, DATEORDER_YMD, DateStyle, free, GetConfigOptionResetString(), GUC_check_errdetail, lfirst, list_free(), malloc, NULL, pfree(), pg_strcasecmp(), pg_strncasecmp(), pstrdup(), result, SplitIdentifierString(), USE_GERMAN_DATES, USE_ISO_DATES, USE_POSTGRES_DATES, and USE_SQL_DATES.

Referenced by check_datestyle().

45 {
46  int newDateStyle = DateStyle;
47  int newDateOrder = DateOrder;
48  bool have_style = false;
49  bool have_order = false;
50  bool ok = true;
51  char *rawstring;
52  int *myextra;
53  char *result;
54  List *elemlist;
55  ListCell *l;
56 
57  /* Need a modifiable copy of string */
58  rawstring = pstrdup(*newval);
59 
60  /* Parse string into list of identifiers */
61  if (!SplitIdentifierString(rawstring, ',', &elemlist))
62  {
63  /* syntax error in list */
64  GUC_check_errdetail("List syntax is invalid.");
65  pfree(rawstring);
66  list_free(elemlist);
67  return false;
68  }
69 
70  foreach(l, elemlist)
71  {
72  char *tok = (char *) lfirst(l);
73 
74  /* Ugh. Somebody ought to write a table driven version -- mjl */
75 
76  if (pg_strcasecmp(tok, "ISO") == 0)
77  {
78  if (have_style && newDateStyle != USE_ISO_DATES)
79  ok = false; /* conflicting styles */
80  newDateStyle = USE_ISO_DATES;
81  have_style = true;
82  }
83  else if (pg_strcasecmp(tok, "SQL") == 0)
84  {
85  if (have_style && newDateStyle != USE_SQL_DATES)
86  ok = false; /* conflicting styles */
87  newDateStyle = USE_SQL_DATES;
88  have_style = true;
89  }
90  else if (pg_strncasecmp(tok, "POSTGRES", 8) == 0)
91  {
92  if (have_style && newDateStyle != USE_POSTGRES_DATES)
93  ok = false; /* conflicting styles */
94  newDateStyle = USE_POSTGRES_DATES;
95  have_style = true;
96  }
97  else if (pg_strcasecmp(tok, "GERMAN") == 0)
98  {
99  if (have_style && newDateStyle != USE_GERMAN_DATES)
100  ok = false; /* conflicting styles */
101  newDateStyle = USE_GERMAN_DATES;
102  have_style = true;
103  /* GERMAN also sets DMY, unless explicitly overridden */
104  if (!have_order)
105  newDateOrder = DATEORDER_DMY;
106  }
107  else if (pg_strcasecmp(tok, "YMD") == 0)
108  {
109  if (have_order && newDateOrder != DATEORDER_YMD)
110  ok = false; /* conflicting orders */
111  newDateOrder = DATEORDER_YMD;
112  have_order = true;
113  }
114  else if (pg_strcasecmp(tok, "DMY") == 0 ||
115  pg_strncasecmp(tok, "EURO", 4) == 0)
116  {
117  if (have_order && newDateOrder != DATEORDER_DMY)
118  ok = false; /* conflicting orders */
119  newDateOrder = DATEORDER_DMY;
120  have_order = true;
121  }
122  else if (pg_strcasecmp(tok, "MDY") == 0 ||
123  pg_strcasecmp(tok, "US") == 0 ||
124  pg_strncasecmp(tok, "NONEURO", 7) == 0)
125  {
126  if (have_order && newDateOrder != DATEORDER_MDY)
127  ok = false; /* conflicting orders */
128  newDateOrder = DATEORDER_MDY;
129  have_order = true;
130  }
131  else if (pg_strcasecmp(tok, "DEFAULT") == 0)
132  {
133  /*
134  * Easiest way to get the current DEFAULT state is to fetch the
135  * DEFAULT string from guc.c and recursively parse it.
136  *
137  * We can't simply "return check_datestyle(...)" because we need
138  * to handle constructs like "DEFAULT, ISO".
139  */
140  char *subval;
141  void *subextra = NULL;
142 
143  subval = strdup(GetConfigOptionResetString("datestyle"));
144  if (!subval)
145  {
146  ok = false;
147  break;
148  }
149  if (!check_datestyle(&subval, &subextra, source))
150  {
151  free(subval);
152  ok = false;
153  break;
154  }
155  myextra = (int *) subextra;
156  if (!have_style)
157  newDateStyle = myextra[0];
158  if (!have_order)
159  newDateOrder = myextra[1];
160  free(subval);
161  free(subextra);
162  }
163  else
164  {
165  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
166  pfree(rawstring);
167  list_free(elemlist);
168  return false;
169  }
170  }
171 
172  pfree(rawstring);
173  list_free(elemlist);
174 
175  if (!ok)
176  {
177  GUC_check_errdetail("Conflicting \"datestyle\" specifications.");
178  return false;
179  }
180 
181  /*
182  * Prepare the canonical string to return. GUC wants it malloc'd.
183  */
184  result = (char *) malloc(32);
185  if (!result)
186  return false;
187 
188  switch (newDateStyle)
189  {
190  case USE_ISO_DATES:
191  strcpy(result, "ISO");
192  break;
193  case USE_SQL_DATES:
194  strcpy(result, "SQL");
195  break;
196  case USE_GERMAN_DATES:
197  strcpy(result, "German");
198  break;
199  default:
200  strcpy(result, "Postgres");
201  break;
202  }
203  switch (newDateOrder)
204  {
205  case DATEORDER_YMD:
206  strcat(result, ", YMD");
207  break;
208  case DATEORDER_DMY:
209  strcat(result, ", DMY");
210  break;
211  default:
212  strcat(result, ", MDY");
213  break;
214  }
215 
216  free(*newval);
217  *newval = result;
218 
219  /*
220  * Set up the "extra" struct actually used by assign_datestyle.
221  */
222  myextra = (int *) malloc(2 * sizeof(int));
223  if (!myextra)
224  return false;
225  myextra[0] = newDateStyle;
226  myextra[1] = newDateOrder;
227  *extra = (void *) myextra;
228 
229  return true;
230 }
#define GUC_check_errdetail
Definition: guc.h:407
char * pstrdup(const char *in)
Definition: mcxt.c:1077
return result
Definition: formatting.c:1633
#define USE_SQL_DATES
Definition: miscadmin.h:212
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
#define USE_ISO_DATES
Definition: miscadmin.h:211
#define malloc(a)
Definition: header.h:50
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
void pfree(void *pointer)
Definition: mcxt.c:950
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3260
#define USE_POSTGRES_DATES
Definition: miscadmin.h:210
int DateOrder
Definition: globals.c:108
#define DATEORDER_YMD
Definition: miscadmin.h:217
bool check_datestyle(char **newval, void **extra, GucSource source)
Definition: variable.c:44
#define DATEORDER_DMY
Definition: miscadmin.h:218
#define DATEORDER_MDY
Definition: miscadmin.h:219
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106
#define newval
int DateStyle
Definition: globals.c:107
#define USE_GERMAN_DATES
Definition: miscadmin.h:213
void list_free(List *list)
Definition: list.c:1133
Definition: pg_list.h:45
const char * GetConfigOptionResetString(const char *name)
Definition: guc.c:6763
bool check_log_timezone ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 408 of file variable.c.

References GUC_check_errdetail, GUC_check_errmsg, malloc, pg_tz_acceptable(), and pg_tzset().

409 {
410  pg_tz *new_tz;
411 
412  /*
413  * Assume it is a timezone name, and try to load it.
414  */
415  new_tz = pg_tzset(*newval);
416 
417  if (!new_tz)
418  {
419  /* Doesn't seem to be any great value in errdetail here */
420  return false;
421  }
422 
423  if (!pg_tz_acceptable(new_tz))
424  {
425  GUC_check_errmsg("time zone \"%s\" appears to use leap seconds",
426  *newval);
427  GUC_check_errdetail("PostgreSQL does not support leap seconds.");
428  return false;
429  }
430 
431  /*
432  * Pass back data for assign_log_timezone to use
433  */
434  *extra = malloc(sizeof(pg_tz *));
435  if (!*extra)
436  return false;
437  *((pg_tz **) *extra) = new_tz;
438 
439  return true;
440 }
#define GUC_check_errdetail
Definition: guc.h:407
#define GUC_check_errmsg
Definition: guc.h:403
#define malloc(a)
Definition: header.h:50
pg_tz * pg_tzset(const char *tzname)
Definition: pgtz.c:243
bool pg_tz_acceptable(pg_tz *tz)
Definition: localtime.c:1845
Definition: pgtz.h:59
#define newval
bool check_random_seed ( double *  newval,
void **  extra,
GucSource  source 
)

Definition at line 643 of file variable.c.

References malloc, and PGC_S_INTERACTIVE.

644 {
645  *extra = malloc(sizeof(int));
646  if (!*extra)
647  return false;
648  /* Arm the assign only if source of value is an interactive SET */
649  *((int *) *extra) = (source >= PGC_S_INTERACTIVE);
650 
651  return true;
652 }
#define malloc(a)
Definition: header.h:50
bool check_role ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 865 of file variable.c.

References AUTHNAME, GetSessionUserId(), GETSTRUCT, GUC_check_errcode(), GUC_check_errmsg, HeapTupleGetOid, HeapTupleIsValid, InitializingParallelWorker, InvalidOid, is_member_of_role(), role_auth_extra::is_superuser, is_superuser(), IsTransactionState(), malloc, PointerGetDatum, ReleaseSysCache(), role_auth_extra::roleid, and SearchSysCache1.

866 {
867  HeapTuple roleTup;
868  Oid roleid;
869  bool is_superuser;
870  role_auth_extra *myextra;
871 
872  if (strcmp(*newval, "none") == 0)
873  {
874  /* hardwired translation */
875  roleid = InvalidOid;
876  is_superuser = false;
877  }
878  else
879  {
880  if (!IsTransactionState())
881  {
882  /*
883  * Can't do catalog lookups, so fail. The result of this is that
884  * role cannot be set in postgresql.conf, which seems like a good
885  * thing anyway, so we don't work hard to avoid it.
886  */
887  return false;
888  }
889 
890  /* Look up the username */
892  if (!HeapTupleIsValid(roleTup))
893  {
894  GUC_check_errmsg("role \"%s\" does not exist", *newval);
895  return false;
896  }
897 
898  roleid = HeapTupleGetOid(roleTup);
899  is_superuser = ((Form_pg_authid) GETSTRUCT(roleTup))->rolsuper;
900 
901  ReleaseSysCache(roleTup);
902 
903  /*
904  * Verify that session user is allowed to become this role, but skip
905  * this in parallel mode, where we must blindly recreate the parallel
906  * leader's state.
907  */
910  {
911  GUC_check_errcode(ERRCODE_INSUFFICIENT_PRIVILEGE);
912  GUC_check_errmsg("permission denied to set role \"%s\"",
913  *newval);
914  return false;
915  }
916  }
917 
918  /* Set up "extra" struct for assign_role to use */
919  myextra = (role_auth_extra *) malloc(sizeof(role_auth_extra));
920  if (!myextra)
921  return false;
922  myextra->roleid = roleid;
923  myextra->is_superuser = is_superuser;
924  *extra = (void *) myextra;
925 
926  return true;
927 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define PointerGetDatum(X)
Definition: postgres.h:562
#define GUC_check_errmsg
Definition: guc.h:403
unsigned int Oid
Definition: postgres_ext.h:31
void GUC_check_errcode(int sqlerrcode)
Definition: guc.c:9784
Oid GetSessionUserId(void)
Definition: miscinit.c:318
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define malloc(a)
Definition: header.h:50
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:72
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define InvalidOid
Definition: postgres_ext.h:36
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4837
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define newval
bool IsTransactionState(void)
Definition: xact.c:350
static bool is_superuser(Archive *fout)
Definition: pg_dump.c:3745
bool InitializingParallelWorker
Definition: parallel.c:100
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
bool is_superuser
Definition: variable.c:793
bool check_session_authorization ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 797 of file variable.c.

References AUTHNAME, GETSTRUCT, GUC_check_errmsg, HeapTupleGetOid, HeapTupleIsValid, role_auth_extra::is_superuser, is_superuser(), IsTransactionState(), malloc, NULL, PointerGetDatum, ReleaseSysCache(), role_auth_extra::roleid, and SearchSysCache1.

798 {
799  HeapTuple roleTup;
800  Oid roleid;
801  bool is_superuser;
802  role_auth_extra *myextra;
803 
804  /* Do nothing for the boot_val default of NULL */
805  if (*newval == NULL)
806  return true;
807 
808  if (!IsTransactionState())
809  {
810  /*
811  * Can't do catalog lookups, so fail. The result of this is that
812  * session_authorization cannot be set in postgresql.conf, which seems
813  * like a good thing anyway, so we don't work hard to avoid it.
814  */
815  return false;
816  }
817 
818  /* Look up the username */
820  if (!HeapTupleIsValid(roleTup))
821  {
822  GUC_check_errmsg("role \"%s\" does not exist", *newval);
823  return false;
824  }
825 
826  roleid = HeapTupleGetOid(roleTup);
827  is_superuser = ((Form_pg_authid) GETSTRUCT(roleTup))->rolsuper;
828 
829  ReleaseSysCache(roleTup);
830 
831  /* Set up "extra" struct for assign_session_authorization to use */
832  myextra = (role_auth_extra *) malloc(sizeof(role_auth_extra));
833  if (!myextra)
834  return false;
835  myextra->roleid = roleid;
836  myextra->is_superuser = is_superuser;
837  *extra = (void *) myextra;
838 
839  return true;
840 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define PointerGetDatum(X)
Definition: postgres.h:562
#define GUC_check_errmsg
Definition: guc.h:403
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define malloc(a)
Definition: header.h:50
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:72
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
#define newval
bool IsTransactionState(void)
Definition: xact.c:350
static bool is_superuser(Archive *fout)
Definition: pg_dump.c:3745
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
bool is_superuser
Definition: variable.c:793
bool check_timezone ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 253 of file variable.c.

References CStringGetDatum, DatumGetIntervalP, Interval::day, DirectFunctionCall3, GUC_check_errdetail, GUC_check_errmsg, Int32GetDatum, interval_in(), InvalidOid, malloc, Interval::month, newval, ObjectIdGetDatum, pfree(), pg_strncasecmp(), pg_tz_acceptable(), pg_tzset(), pg_tzset_offset(), pstrdup(), SECS_PER_HOUR, Interval::time, USECS_PER_SEC, and val.

254 {
255  pg_tz *new_tz;
256  long gmtoffset;
257  char *endptr;
258  double hours;
259 
260  if (pg_strncasecmp(*newval, "interval", 8) == 0)
261  {
262  /*
263  * Support INTERVAL 'foo'. This is for SQL spec compliance, not
264  * because it has any actual real-world usefulness.
265  */
266  const char *valueptr = *newval;
267  char *val;
269 
270  valueptr += 8;
271  while (isspace((unsigned char) *valueptr))
272  valueptr++;
273  if (*valueptr++ != '\'')
274  return false;
275  val = pstrdup(valueptr);
276  /* Check and remove trailing quote */
277  endptr = strchr(val, '\'');
278  if (!endptr || endptr[1] != '\0')
279  {
280  pfree(val);
281  return false;
282  }
283  *endptr = '\0';
284 
285  /*
286  * Try to parse it. XXX an invalid interval format will result in
287  * ereport(ERROR), which is not desirable for GUC. We did what we
288  * could to guard against this in flatten_set_variable_args, but a
289  * string coming in from postgresql.conf might contain anything.
290  */
292  CStringGetDatum(val),
294  Int32GetDatum(-1)));
295 
296  pfree(val);
297  if (interval->month != 0)
298  {
299  GUC_check_errdetail("Cannot specify months in time zone interval.");
300  pfree(interval);
301  return false;
302  }
303  if (interval->day != 0)
304  {
305  GUC_check_errdetail("Cannot specify days in time zone interval.");
306  pfree(interval);
307  return false;
308  }
309 
310  /* Here we change from SQL to Unix sign convention */
311  gmtoffset = -(interval->time / USECS_PER_SEC);
312  new_tz = pg_tzset_offset(gmtoffset);
313 
314  pfree(interval);
315  }
316  else
317  {
318  /*
319  * Try it as a numeric number of hours (possibly fractional).
320  */
321  hours = strtod(*newval, &endptr);
322  if (endptr != *newval && *endptr == '\0')
323  {
324  /* Here we change from SQL to Unix sign convention */
325  gmtoffset = -hours * SECS_PER_HOUR;
326  new_tz = pg_tzset_offset(gmtoffset);
327  }
328  else
329  {
330  /*
331  * Otherwise assume it is a timezone name, and try to load it.
332  */
333  new_tz = pg_tzset(*newval);
334 
335  if (!new_tz)
336  {
337  /* Doesn't seem to be any great value in errdetail here */
338  return false;
339  }
340 
341  if (!pg_tz_acceptable(new_tz))
342  {
343  GUC_check_errmsg("time zone \"%s\" appears to use leap seconds",
344  *newval);
345  GUC_check_errdetail("PostgreSQL does not support leap seconds.");
346  return false;
347  }
348  }
349  }
350 
351  /* Test for failure in pg_tzset_offset, which we assume is out-of-range */
352  if (!new_tz)
353  {
354  GUC_check_errdetail("UTC timezone offset is out of range.");
355  return false;
356  }
357 
358  /*
359  * Pass back data for assign_timezone to use
360  */
361  *extra = malloc(sizeof(pg_tz *));
362  if (!*extra)
363  return false;
364  *((pg_tz **) *extra) = new_tz;
365 
366  return true;
367 }
#define DatumGetIntervalP(X)
Definition: timestamp.h:29
#define USECS_PER_SEC
Definition: timestamp.h:94
#define GUC_check_errdetail
Definition: guc.h:407
Datum interval_in(PG_FUNCTION_ARGS)
Definition: timestamp.c:876
char * pstrdup(const char *in)
Definition: mcxt.c:1077
#define GUC_check_errmsg
Definition: guc.h:403
int32 day
Definition: timestamp.h:47
#define malloc(a)
Definition: header.h:50
pg_tz * pg_tzset(const char *tzname)
Definition: pgtz.c:243
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
void pfree(void *pointer)
Definition: mcxt.c:950
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define CStringGetDatum(X)
Definition: postgres.h:584
TimeOffset time
Definition: timestamp.h:45
#define SECS_PER_HOUR
Definition: timestamp.h:87
pg_tz * pg_tzset_offset(long gmtoffset)
Definition: pgtz.c:329
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:588
int32 month
Definition: timestamp.h:48
bool pg_tz_acceptable(pg_tz *tz)
Definition: localtime.c:1845
Definition: pgtz.h:59
#define InvalidOid
Definition: postgres_ext.h:36
#define newval
#define Int32GetDatum(X)
Definition: postgres.h:485
long val
Definition: informix.c:689
bool check_transaction_deferrable ( bool newval,
void **  extra,
GucSource  source 
)

Definition at line 615 of file variable.c.

References FirstSnapshotSet, GUC_check_errcode(), GUC_check_errmsg, and IsSubTransaction().

616 {
617  if (IsSubTransaction())
618  {
619  GUC_check_errcode(ERRCODE_ACTIVE_SQL_TRANSACTION);
620  GUC_check_errmsg("SET TRANSACTION [NOT] DEFERRABLE cannot be called within a subtransaction");
621  return false;
622  }
623  if (FirstSnapshotSet)
624  {
625  GUC_check_errcode(ERRCODE_ACTIVE_SQL_TRANSACTION);
626  GUC_check_errmsg("SET TRANSACTION [NOT] DEFERRABLE must be called before any query");
627  return false;
628  }
629 
630  return true;
631 }
#define GUC_check_errmsg
Definition: guc.h:403
void GUC_check_errcode(int sqlerrcode)
Definition: guc.c:9784
bool FirstSnapshotSet
Definition: snapmgr.c:203
bool IsSubTransaction(void)
Definition: xact.c:4400
bool check_transaction_read_only ( bool newval,
void **  extra,
GucSource  source 
)

Definition at line 486 of file variable.c.

References FirstSnapshotSet, GUC_check_errcode(), GUC_check_errmsg, InitializingParallelWorker, IsSubTransaction(), IsTransactionState(), RecoveryInProgress(), and XactReadOnly.

487 {
489  {
490  /* Can't go to r/w mode inside a r/o transaction */
491  if (IsSubTransaction())
492  {
493  GUC_check_errcode(ERRCODE_ACTIVE_SQL_TRANSACTION);
494  GUC_check_errmsg("cannot set transaction read-write mode inside a read-only transaction");
495  return false;
496  }
497  /* Top level transaction can't change to r/w after first snapshot. */
498  if (FirstSnapshotSet)
499  {
500  GUC_check_errcode(ERRCODE_ACTIVE_SQL_TRANSACTION);
501  GUC_check_errmsg("transaction read-write mode must be set before any query");
502  return false;
503  }
504  /* Can't go to r/w mode while recovery is still active */
505  if (RecoveryInProgress())
506  {
507  GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
508  GUC_check_errmsg("cannot set transaction read-write mode during recovery");
509  return false;
510  }
511  }
512 
513  return true;
514 }
#define GUC_check_errmsg
Definition: guc.h:403
bool RecoveryInProgress(void)
Definition: xlog.c:7878
void GUC_check_errcode(int sqlerrcode)
Definition: guc.c:9784
bool FirstSnapshotSet
Definition: snapmgr.c:203
bool XactReadOnly
Definition: xact.c:77
#define newval
bool IsTransactionState(void)
Definition: xact.c:350
bool IsSubTransaction(void)
Definition: xact.c:4400
bool InitializingParallelWorker
Definition: parallel.c:100
bool check_XactIsoLevel ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 525 of file variable.c.

References DefaultXactIsoLevel, FirstSnapshotSet, GUC_check_errcode(), GUC_check_errhint, GUC_check_errmsg, IsSubTransaction(), IsTransactionState(), malloc, RecoveryInProgress(), XACT_READ_COMMITTED, XACT_READ_UNCOMMITTED, XACT_REPEATABLE_READ, XACT_SERIALIZABLE, and XactIsoLevel.

526 {
527  int newXactIsoLevel;
528 
529  if (strcmp(*newval, "serializable") == 0)
530  {
531  newXactIsoLevel = XACT_SERIALIZABLE;
532  }
533  else if (strcmp(*newval, "repeatable read") == 0)
534  {
535  newXactIsoLevel = XACT_REPEATABLE_READ;
536  }
537  else if (strcmp(*newval, "read committed") == 0)
538  {
539  newXactIsoLevel = XACT_READ_COMMITTED;
540  }
541  else if (strcmp(*newval, "read uncommitted") == 0)
542  {
543  newXactIsoLevel = XACT_READ_UNCOMMITTED;
544  }
545  else if (strcmp(*newval, "default") == 0)
546  {
547  newXactIsoLevel = DefaultXactIsoLevel;
548  }
549  else
550  return false;
551 
552  if (newXactIsoLevel != XactIsoLevel && IsTransactionState())
553  {
554  if (FirstSnapshotSet)
555  {
556  GUC_check_errcode(ERRCODE_ACTIVE_SQL_TRANSACTION);
557  GUC_check_errmsg("SET TRANSACTION ISOLATION LEVEL must be called before any query");
558  return false;
559  }
560  /* We ignore a subtransaction setting it to the existing value. */
561  if (IsSubTransaction())
562  {
563  GUC_check_errcode(ERRCODE_ACTIVE_SQL_TRANSACTION);
564  GUC_check_errmsg("SET TRANSACTION ISOLATION LEVEL must not be called in a subtransaction");
565  return false;
566  }
567  /* Can't go to serializable mode while recovery is still active */
568  if (newXactIsoLevel == XACT_SERIALIZABLE && RecoveryInProgress())
569  {
570  GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
571  GUC_check_errmsg("cannot use serializable mode in a hot standby");
572  GUC_check_errhint("You can use REPEATABLE READ instead.");
573  return false;
574  }
575  }
576 
577  *extra = malloc(sizeof(int));
578  if (!*extra)
579  return false;
580  *((int *) *extra) = newXactIsoLevel;
581 
582  return true;
583 }
#define XACT_REPEATABLE_READ
Definition: xact.h:30
#define XACT_READ_UNCOMMITTED
Definition: xact.h:28
#define GUC_check_errmsg
Definition: guc.h:403
int DefaultXactIsoLevel
Definition: xact.c:73
bool RecoveryInProgress(void)
Definition: xlog.c:7878
void GUC_check_errcode(int sqlerrcode)
Definition: guc.c:9784
#define XACT_SERIALIZABLE
Definition: xact.h:31
#define malloc(a)
Definition: header.h:50
bool FirstSnapshotSet
Definition: snapmgr.c:203
#define XACT_READ_COMMITTED
Definition: xact.h:29
#define newval
int XactIsoLevel
Definition: xact.c:74
bool IsTransactionState(void)
Definition: xact.c:350
bool IsSubTransaction(void)
Definition: xact.c:4400
#define GUC_check_errhint
Definition: guc.h:411
const char* show_log_timezone ( void  )

Definition at line 455 of file variable.c.

References log_timezone, NULL, and pg_get_timezone_name().

456 {
457  const char *tzn;
458 
459  /* Always show the zone's canonical name */
461 
462  if (tzn != NULL)
463  return tzn;
464 
465  return "unknown";
466 }
pg_tz * log_timezone
Definition: pgtz.c:31
const char * pg_get_timezone_name(pg_tz *tz)
Definition: localtime.c:1830
#define NULL
Definition: c.h:229
const char* show_random_seed ( void  )

Definition at line 664 of file variable.c.

665 {
666  return "unavailable";
667 }
const char* show_role ( void  )

Definition at line 938 of file variable.c.

References GetCurrentRoleId(), OidIsValid, and role_string.

939 {
940  /*
941  * Check whether SET ROLE is active; if not return "none". This is a
942  * kluge to deal with the fact that SET SESSION AUTHORIZATION logically
943  * resets SET ROLE to NONE, but we cannot set the GUC role variable from
944  * assign_session_authorization (because we haven't got enough info to
945  * call set_config_option).
946  */
948  return "none";
949 
950  /* Otherwise we can just use the GUC string */
951  return role_string ? role_string : "none";
952 }
#define OidIsValid(objectId)
Definition: c.h:538
Oid GetCurrentRoleId(void)
Definition: miscinit.c:636
char * role_string
Definition: guc.c:522
const char* show_timezone ( void  )

Definition at line 382 of file variable.c.

References NULL, pg_get_timezone_name(), and session_timezone.

383 {
384  const char *tzn;
385 
386  /* Always show the zone's canonical name */
388 
389  if (tzn != NULL)
390  return tzn;
391 
392  return "unknown";
393 }
const char * pg_get_timezone_name(pg_tz *tz)
Definition: localtime.c:1830
#define NULL
Definition: c.h:229
pg_tz * session_timezone
Definition: pgtz.c:28
const char* show_XactIsoLevel ( void  )

Definition at line 592 of file variable.c.

References XACT_READ_COMMITTED, XACT_READ_UNCOMMITTED, XACT_REPEATABLE_READ, XACT_SERIALIZABLE, and XactIsoLevel.

593 {
594  /* We need this because we don't want to show "default". */
595  switch (XactIsoLevel)
596  {
598  return "read uncommitted";
599  case XACT_READ_COMMITTED:
600  return "read committed";
602  return "repeatable read";
603  case XACT_SERIALIZABLE:
604  return "serializable";
605  default:
606  return "bogus";
607  }
608 }
#define XACT_REPEATABLE_READ
Definition: xact.h:30
#define XACT_READ_UNCOMMITTED
Definition: xact.h:28
#define XACT_SERIALIZABLE
Definition: xact.h:31
#define XACT_READ_COMMITTED
Definition: xact.h:29
int XactIsoLevel
Definition: xact.c:74

Variable Documentation

char* role_string

Definition at line 522 of file guc.c.

Referenced by show_role().