~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to src/include/miscadmin.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * miscadmin.h
 
4
 *        This file contains general postgres administration and initialization
 
5
 *        stuff that used to be spread out between the following files:
 
6
 *              globals.h                                               global variables
 
7
 *              pdir.h                                                  directory path crud
 
8
 *              pinit.h                                                 postgres initialization
 
9
 *              pmod.h                                                  processing modes
 
10
 *        Over time, this has also become the preferred place for widely known
 
11
 *        resource-limitation stuff, such as work_mem and check_stack_depth().
 
12
 *
 
13
 * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
 
14
 * Portions Copyright (c) 1994, Regents of the University of California
 
15
 *
 
16
 * src/include/miscadmin.h
 
17
 *
 
18
 * NOTES
 
19
 *        some of the information in this file should be moved to other files.
 
20
 *
 
21
 *-------------------------------------------------------------------------
 
22
 */
 
23
#ifndef MISCADMIN_H
 
24
#define MISCADMIN_H
 
25
 
 
26
#include "pgtime.h"                             /* for pg_time_t */
 
27
 
 
28
 
 
29
#define PG_BACKEND_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
 
30
 
 
31
 
 
32
/*****************************************************************************
 
33
 *        System interrupt and critical section handling
 
34
 *
 
35
 * There are two types of interrupts that a running backend needs to accept
 
36
 * without messing up its state: QueryCancel (SIGINT) and ProcDie (SIGTERM).
 
37
 * In both cases, we need to be able to clean up the current transaction
 
38
 * gracefully, so we can't respond to the interrupt instantaneously ---
 
39
 * there's no guarantee that internal data structures would be self-consistent
 
40
 * if the code is interrupted at an arbitrary instant.  Instead, the signal
 
41
 * handlers set flags that are checked periodically during execution.
 
42
 *
 
43
 * The CHECK_FOR_INTERRUPTS() macro is called at strategically located spots
 
44
 * where it is normally safe to accept a cancel or die interrupt.  In some
 
45
 * cases, we invoke CHECK_FOR_INTERRUPTS() inside low-level subroutines that
 
46
 * might sometimes be called in contexts that do *not* want to allow a cancel
 
47
 * or die interrupt.  The HOLD_INTERRUPTS() and RESUME_INTERRUPTS() macros
 
48
 * allow code to ensure that no cancel or die interrupt will be accepted,
 
49
 * even if CHECK_FOR_INTERRUPTS() gets called in a subroutine.  The interrupt
 
50
 * will be held off until CHECK_FOR_INTERRUPTS() is done outside any
 
51
 * HOLD_INTERRUPTS() ... RESUME_INTERRUPTS() section.
 
52
 *
 
53
 * Special mechanisms are used to let an interrupt be accepted when we are
 
54
 * waiting for a lock or when we are waiting for command input (but, of
 
55
 * course, only if the interrupt holdoff counter is zero).      See the
 
56
 * related code for details.
 
57
 *
 
58
 * A related, but conceptually distinct, mechanism is the "critical section"
 
59
 * mechanism.  A critical section not only holds off cancel/die interrupts,
 
60
 * but causes any ereport(ERROR) or ereport(FATAL) to become ereport(PANIC)
 
61
 * --- that is, a system-wide reset is forced.  Needless to say, only really
 
62
 * *critical* code should be marked as a critical section!      Currently, this
 
63
 * mechanism is only used for XLOG-related code.
 
64
 *
 
65
 *****************************************************************************/
 
66
 
 
67
/* in globals.c */
 
68
/* these are marked volatile because they are set by signal handlers: */
 
69
extern PGDLLIMPORT volatile bool InterruptPending;
 
70
extern volatile bool QueryCancelPending;
 
71
extern volatile bool ProcDiePending;
 
72
 
 
73
/* these are marked volatile because they are examined by signal handlers: */
 
74
extern volatile bool ImmediateInterruptOK;
 
75
extern PGDLLIMPORT volatile uint32 InterruptHoldoffCount;
 
76
extern PGDLLIMPORT volatile uint32 CritSectionCount;
 
77
 
 
78
/* in tcop/postgres.c */
 
79
extern void ProcessInterrupts(void);
 
80
 
 
81
#ifndef WIN32
 
82
 
 
83
#define CHECK_FOR_INTERRUPTS() \
 
84
do { \
 
85
        if (InterruptPending) \
 
86
                ProcessInterrupts(); \
 
87
} while(0)
 
88
#else                                                   /* WIN32 */
 
89
 
 
90
#define CHECK_FOR_INTERRUPTS() \
 
91
do { \
 
92
        if (UNBLOCKED_SIGNAL_QUEUE()) \
 
93
                pgwin32_dispatch_queued_signals(); \
 
94
        if (InterruptPending) \
 
95
                ProcessInterrupts(); \
 
96
} while(0)
 
97
#endif   /* WIN32 */
 
98
 
 
99
 
 
100
#define HOLD_INTERRUPTS()  (InterruptHoldoffCount++)
 
101
 
 
102
#define RESUME_INTERRUPTS() \
 
103
do { \
 
104
        Assert(InterruptHoldoffCount > 0); \
 
105
        InterruptHoldoffCount--; \
 
106
} while(0)
 
107
 
 
108
#define START_CRIT_SECTION()  (CritSectionCount++)
 
109
 
 
110
#define END_CRIT_SECTION() \
 
111
do { \
 
112
        Assert(CritSectionCount > 0); \
 
113
        CritSectionCount--; \
 
114
} while(0)
 
115
 
 
116
 
 
117
/*****************************************************************************
 
118
 *        globals.h --                                                                                                                   *
 
119
 *****************************************************************************/
 
120
 
 
121
/*
 
122
 * from utils/init/globals.c
 
123
 */
 
124
extern pid_t PostmasterPid;
 
125
extern bool IsPostmasterEnvironment;
 
126
extern PGDLLIMPORT bool IsUnderPostmaster;
 
127
extern bool IsBinaryUpgrade;
 
128
 
 
129
extern bool ExitOnAnyError;
 
130
 
 
131
extern PGDLLIMPORT char *DataDir;
 
132
 
 
133
extern PGDLLIMPORT int NBuffers;
 
134
extern int      MaxBackends;
 
135
extern int      MaxConnections;
 
136
 
 
137
extern PGDLLIMPORT int MyProcPid;
 
138
extern PGDLLIMPORT pg_time_t MyStartTime;
 
139
extern PGDLLIMPORT struct Port *MyProcPort;
 
140
extern long MyCancelKey;
 
141
extern int      MyPMChildSlot;
 
142
 
 
143
extern char OutputFileName[];
 
144
extern PGDLLIMPORT char my_exec_path[];
 
145
extern char pkglib_path[];
 
146
 
 
147
#ifdef EXEC_BACKEND
 
148
extern char postgres_exec_path[];
 
149
#endif
 
150
 
 
151
/*
 
152
 * done in storage/backendid.h for now.
 
153
 *
 
154
 * extern BackendId    MyBackendId;
 
155
 */
 
156
extern PGDLLIMPORT Oid MyDatabaseId;
 
157
 
 
158
extern PGDLLIMPORT Oid MyDatabaseTableSpace;
 
159
 
 
160
/*
 
161
 * Date/Time Configuration
 
162
 *
 
163
 * DateStyle defines the output formatting choice for date/time types:
 
164
 *      USE_POSTGRES_DATES specifies traditional Postgres format
 
165
 *      USE_ISO_DATES specifies ISO-compliant format
 
166
 *      USE_SQL_DATES specifies Oracle/Ingres-compliant format
 
167
 *      USE_GERMAN_DATES specifies German-style dd.mm/yyyy
 
168
 *
 
169
 * DateOrder defines the field order to be assumed when reading an
 
170
 * ambiguous date (anything not in YYYY-MM-DD format, with a four-digit
 
171
 * year field first, is taken to be ambiguous):
 
172
 *      DATEORDER_YMD specifies field order yy-mm-dd
 
173
 *      DATEORDER_DMY specifies field order dd-mm-yy ("European" convention)
 
174
 *      DATEORDER_MDY specifies field order mm-dd-yy ("US" convention)
 
175
 *
 
176
 * In the Postgres and SQL DateStyles, DateOrder also selects output field
 
177
 * order: day comes before month in DMY style, else month comes before day.
 
178
 *
 
179
 * The user-visible "DateStyle" run-time parameter subsumes both of these.
 
180
 */
 
181
 
 
182
/* valid DateStyle values */
 
183
#define USE_POSTGRES_DATES              0
 
184
#define USE_ISO_DATES                   1
 
185
#define USE_SQL_DATES                   2
 
186
#define USE_GERMAN_DATES                3
 
187
#define USE_XSD_DATES                   4
 
188
 
 
189
/* valid DateOrder values */
 
190
#define DATEORDER_YMD                   0
 
191
#define DATEORDER_DMY                   1
 
192
#define DATEORDER_MDY                   2
 
193
 
 
194
extern int      DateStyle;
 
195
extern int      DateOrder;
 
196
 
 
197
/*
 
198
 * IntervalStyles
 
199
 *       INTSTYLE_POSTGRES                         Like Postgres < 8.4 when DateStyle = 'iso'
 
200
 *       INTSTYLE_POSTGRES_VERBOSE         Like Postgres < 8.4 when DateStyle != 'iso'
 
201
 *       INTSTYLE_SQL_STANDARD             SQL standard interval literals
 
202
 *       INTSTYLE_ISO_8601                         ISO-8601-basic formatted intervals
 
203
 */
 
204
#define INTSTYLE_POSTGRES                       0
 
205
#define INTSTYLE_POSTGRES_VERBOSE       1
 
206
#define INTSTYLE_SQL_STANDARD           2
 
207
#define INTSTYLE_ISO_8601                       3
 
208
 
 
209
extern int      IntervalStyle;
 
210
 
 
211
/*
 
212
 * HasCTZSet is true if user has set timezone as a numeric offset from UTC.
 
213
 * If so, CTimeZone is the timezone offset in seconds (using the Unix-ish
 
214
 * sign convention, ie, positive offset is west of UTC, rather than the
 
215
 * SQL-ish convention that positive is east of UTC).
 
216
 */
 
217
extern bool HasCTZSet;
 
218
extern int      CTimeZone;
 
219
 
 
220
#define MAXTZLEN                10              /* max TZ name len, not counting tr. null */
 
221
 
 
222
extern bool enableFsync;
 
223
extern bool allowSystemTableMods;
 
224
extern PGDLLIMPORT int work_mem;
 
225
extern PGDLLIMPORT int maintenance_work_mem;
 
226
 
 
227
extern int      VacuumCostPageHit;
 
228
extern int      VacuumCostPageMiss;
 
229
extern int      VacuumCostPageDirty;
 
230
extern int      VacuumCostLimit;
 
231
extern int      VacuumCostDelay;
 
232
 
 
233
extern int      VacuumCostBalance;
 
234
extern bool VacuumCostActive;
 
235
 
 
236
 
 
237
/* in tcop/postgres.c */
 
238
extern void check_stack_depth(void);
 
239
 
 
240
/* in tcop/utility.c */
 
241
extern void PreventCommandIfReadOnly(const char *cmdname);
 
242
extern void PreventCommandDuringRecovery(const char *cmdname);
 
243
 
 
244
/* in utils/misc/guc.c */
 
245
extern int      trace_recovery_messages;
 
246
extern int      trace_recovery(int trace_level);
 
247
 
 
248
/*****************************************************************************
 
249
 *        pdir.h --                                                                                                                              *
 
250
 *                      POSTGRES directory path definitions.                                                     *
 
251
 *****************************************************************************/
 
252
 
 
253
/* flags to be OR'd to form sec_context */
 
254
#define SECURITY_LOCAL_USERID_CHANGE    0x0001
 
255
#define SECURITY_RESTRICTED_OPERATION   0x0002
 
256
 
 
257
extern char *DatabasePath;
 
258
 
 
259
/* now in utils/init/miscinit.c */
 
260
extern void SetDatabasePath(const char *path);
 
261
 
 
262
extern char *GetUserNameFromId(Oid roleid);
 
263
extern Oid      GetUserId(void);
 
264
extern Oid      GetOuterUserId(void);
 
265
extern Oid      GetSessionUserId(void);
 
266
extern void GetUserIdAndSecContext(Oid *userid, int *sec_context);
 
267
extern void SetUserIdAndSecContext(Oid userid, int sec_context);
 
268
extern bool InLocalUserIdChange(void);
 
269
extern bool InSecurityRestrictedOperation(void);
 
270
extern void GetUserIdAndContext(Oid *userid, bool *sec_def_context);
 
271
extern void SetUserIdAndContext(Oid userid, bool sec_def_context);
 
272
extern void InitializeSessionUserId(const char *rolename);
 
273
extern void InitializeSessionUserIdStandalone(void);
 
274
extern void SetSessionAuthorization(Oid userid, bool is_superuser);
 
275
extern Oid      GetCurrentRoleId(void);
 
276
extern void SetCurrentRoleId(Oid roleid, bool is_superuser);
 
277
 
 
278
extern void SetDataDir(const char *dir);
 
279
extern void ChangeToDataDir(void);
 
280
extern char *make_absolute_path(const char *path);
 
281
 
 
282
/* in utils/misc/superuser.c */
 
283
extern bool superuser(void);    /* current user is superuser */
 
284
extern bool superuser_arg(Oid roleid);  /* given user is superuser */
 
285
 
 
286
 
 
287
/*****************************************************************************
 
288
 *        pmod.h --                                                                                                                              *
 
289
 *                      POSTGRES processing mode definitions.                                                    *
 
290
 *****************************************************************************/
 
291
 
 
292
/*
 
293
 * Description:
 
294
 *              There are three processing modes in POSTGRES.  They are
 
295
 * BootstrapProcessing or "bootstrap," InitProcessing or
 
296
 * "initialization," and NormalProcessing or "normal."
 
297
 *
 
298
 * The first two processing modes are used during special times. When the
 
299
 * system state indicates bootstrap processing, transactions are all given
 
300
 * transaction id "one" and are consequently guaranteed to commit. This mode
 
301
 * is used during the initial generation of template databases.
 
302
 *
 
303
 * Initialization mode: used while starting a backend, until all normal
 
304
 * initialization is complete.  Some code behaves differently when executed
 
305
 * in this mode to enable system bootstrapping.
 
306
 *
 
307
 * If a POSTGRES binary is in normal mode, then all code may be executed
 
308
 * normally.
 
309
 */
 
310
 
 
311
typedef enum ProcessingMode
 
312
{
 
313
        BootstrapProcessing,            /* bootstrap creation of template database */
 
314
        InitProcessing,                         /* initializing system */
 
315
        NormalProcessing                        /* normal processing */
 
316
} ProcessingMode;
 
317
 
 
318
extern ProcessingMode Mode;
 
319
 
 
320
#define IsBootstrapProcessingMode() ((bool)(Mode == BootstrapProcessing))
 
321
#define IsInitProcessingMode() ((bool)(Mode == InitProcessing))
 
322
#define IsNormalProcessingMode() ((bool)(Mode == NormalProcessing))
 
323
 
 
324
#define SetProcessingMode(mode) \
 
325
        do { \
 
326
                AssertArg((mode) == BootstrapProcessing || \
 
327
                                  (mode) == InitProcessing || \
 
328
                                  (mode) == NormalProcessing); \
 
329
                Mode = (mode); \
 
330
        } while(0)
 
331
 
 
332
#define GetProcessingMode() Mode
 
333
 
 
334
 
 
335
/*****************************************************************************
 
336
 *        pinit.h --                                                                                                                     *
 
337
 *                      POSTGRES initialization and cleanup definitions.                                 *
 
338
 *****************************************************************************/
 
339
 
 
340
/* in utils/init/postinit.c */
 
341
extern void pg_split_opts(char **argv, int *argcp, char *optstr);
 
342
extern void InitPostgres(const char *in_dbname, Oid dboid, const char *username,
 
343
                         char *out_dbname);
 
344
extern void BaseInit(void);
 
345
 
 
346
/* in utils/init/miscinit.c */
 
347
extern bool IgnoreSystemIndexes;
 
348
extern PGDLLIMPORT bool process_shared_preload_libraries_in_progress;
 
349
extern char *shared_preload_libraries_string;
 
350
extern char *local_preload_libraries_string;
 
351
 
 
352
/*
 
353
 * As of 9.1, the contents of the data-directory lock file are:
 
354
 *
 
355
 * line #
 
356
 *              1       postmaster PID (or negative of a standalone backend's PID)
 
357
 *              2       data directory path
 
358
 *              3       postmaster start timestamp (time_t representation)
 
359
 *              4       port number
 
360
 *              5       socket directory path (empty on Windows)
 
361
 *              6       first listen_address (IP address or "*"; empty if no TCP port)
 
362
 *              7       shared memory key (not present on Windows)
 
363
 *
 
364
 * Lines 6 and up are added via AddToDataDirLockFile() after initial file
 
365
 * creation; they have to be ordered according to time of addition.
 
366
 *
 
367
 * The socket lock file, if used, has the same contents as lines 1-5.
 
368
 */
 
369
#define LOCK_FILE_LINE_PID                      1
 
370
#define LOCK_FILE_LINE_DATA_DIR         2
 
371
#define LOCK_FILE_LINE_START_TIME       3
 
372
#define LOCK_FILE_LINE_PORT                     4
 
373
#define LOCK_FILE_LINE_SOCKET_DIR       5
 
374
#define LOCK_FILE_LINE_LISTEN_ADDR      6
 
375
#define LOCK_FILE_LINE_SHMEM_KEY        7
 
376
 
 
377
extern void CreateDataDirLockFile(bool amPostmaster);
 
378
extern void CreateSocketLockFile(const char *socketfile, bool amPostmaster);
 
379
extern void TouchSocketLockFile(void);
 
380
extern void AddToDataDirLockFile(int target_line, const char *str);
 
381
extern void ValidatePgVersion(const char *path);
 
382
extern void process_shared_preload_libraries(void);
 
383
extern void process_local_preload_libraries(void);
 
384
extern void pg_bindtextdomain(const char *domain);
 
385
extern bool is_authenticated_user_replication_role(void);
 
386
 
 
387
/* in access/transam/xlog.c */
 
388
extern bool BackupInProgress(void);
 
389
extern void CancelBackup(void);
 
390
 
 
391
#endif   /* MISCADMIN_H */