forked from pgaudit/set_user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compatibility.h
228 lines (188 loc) · 5.76 KB
/
compatibility.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/* -------------------------------------------------------------------------
*
* compatibility.h
*
* Definitions for maintaining compatibility across Postgres versions.
*
* Copyright (c) 2010-2021, PostgreSQL Global Development Group
*
* -------------------------------------------------------------------------
*/
#ifndef SET_USER_COMPAT_H
#define SET_USER_COMPAT_H
#ifndef NO_ASSERT_AUTH_UID_ONCE
#define NO_ASSERT_AUTH_UID_ONCE !USE_ASSERT_CHECKING
#endif
/*
* PostgreSQL version 14+
*
* Introduces ReadOnlyTree boolean
*/
#if PG_VERSION_NUM >= 140000
#define _PU_HOOK \
static void PU_hook(PlannedStmt *pstmt, const char *queryString, bool ReadOnlyTree, \
ProcessUtilityContext context, ParamListInfo params, \
QueryEnvironment *queryEnv, \
DestReceiver *dest, QueryCompletion *qc)
#define _prev_hook \
prev_hook(pstmt, queryString, ReadOnlyTree, context, params, queryEnv, dest, qc)
#define _standard_ProcessUtility \
standard_ProcessUtility(pstmt, queryString, ReadOnlyTree, context, params, queryEnv, dest, qc)
#define getObjectIdentity(address) \
getObjectIdentity(address,false)
#endif /* 14+ */
/*
* PostgreSQL version 13+
*
* Introduces QueryCompletion struct
*/
#if PG_VERSION_NUM >= 130000
#ifndef _PU_HOOK
#define _PU_HOOK \
static void PU_hook(PlannedStmt *pstmt, const char *queryString, \
ProcessUtilityContext context, ParamListInfo params, \
QueryEnvironment *queryEnv, \
DestReceiver *dest, QueryCompletion *qc)
#define _prev_hook \
prev_hook(pstmt, queryString, context, params, queryEnv, dest, qc)
#define _standard_ProcessUtility \
standard_ProcessUtility(pstmt, queryString, context, params, queryEnv, dest, qc)
#endif
#define TABLEOPEN
#endif /* 13+ */
/*
* PostgreSQL version 12+
*
* - Removes OID column
*/
#if PG_VERSION_NUM >= 120000
#define HEAP_TUPLE_GET_OID
/*
* _heap_tuple_get_oid
*
* Return the oid of the tuple based on the provided catalogID.
*/
static inline Oid
_heap_tuple_get_oid(HeapTuple tuple, Oid catalogID)
{
switch (catalogID)
{
case ProcedureRelationId:
return ((Form_pg_proc) GETSTRUCT(tuple))->oid;
break;
case AuthIdRelationId:
return ((Form_pg_authid) GETSTRUCT(tuple))->oid;
break;
default:
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("set_user: invalid relation ID provided")));
return 0;
}
}
#include "access/table.h"
#define OBJECTADDRESS
#endif /* 12+ */
/*
* PostgreSQL version 10+
*
* - Introduces PlannedStmt struct
* - Introduces varlena.h
*/
#if PG_VERSION_NUM >= 100000
#ifndef _PU_HOOK
#define _PU_HOOK \
static void PU_hook(PlannedStmt *pstmt, const char *queryString, \
ProcessUtilityContext context, ParamListInfo params, \
QueryEnvironment *queryEnv, \
DestReceiver *dest, char *completionTag)
#define _prev_hook \
prev_hook(pstmt, queryString, context, params, queryEnv, dest, completionTag)
#define _standard_ProcessUtility \
standard_ProcessUtility(pstmt, queryString, context, params, queryEnv, dest, completionTag)
#endif
#include "utils/varlena.h"
#define parsetree ((Node *) pstmt->utilityStmt)
#endif /* 10+ */
/*
* PostgreSQL version 9.5+
*
* - Introduces two-argument GetUserNameFromId
*/
#if PG_VERSION_NUM >= 90500
#define GETUSERNAMEFROMID(ouserid) GetUserNameFromId(ouserid, false)
#define INITSESSIONUSER
#define _InitializeSessionUserId(name,ouserid) InitializeSessionUserId(name,ouserid)
#endif /* 9.5+ */
/*
* PostgreSQL version 9.4+
*
* Lowest supported version.
*/
#if PG_VERSION_NUM >= 90400
#ifndef _PU_HOOK
#define _PU_HOOK \
static void PU_hook(Node *parsetree, const char *queryString, \
ProcessUtilityContext context, ParamListInfo params, \
DestReceiver *dest, char *completionTag)
#define _prev_hook \
prev_hook(parsetree, queryString, context, params, dest, completionTag)
#define _standard_ProcessUtility \
standard_ProcessUtility(parsetree, queryString, context, params, dest, completionTag)
#endif
#ifndef GETUSERNAMEFROMID
#define GETUSERNAMEFROMID(ouserid) GetUserNameFromId(ouserid)
#endif
# ifndef HEAP_TUPLE_GET_OID
static inline Oid
_heap_tuple_get_oid(HeapTuple tup, Oid catalogId)
{
return HeapTupleGetOid(tup);
}
# endif
#ifndef TABLEOPEN
#define table_open(r, l) heap_open(r, l)
#define table_close(r, l) heap_close(r, l)
#endif
#include "access/heapam.h"
#ifndef OBJECTADDRESS
#include "utils/tqual.h"
#endif
#ifndef Anum_pg_proc_oid
#include "access/sysattr.h"
#define Anum_pg_proc_oid ObjectIdAttributeNumber
#define Anum_pg_authid_oid ObjectIdAttributeNumber
#endif
/*
* _scan_key_init
*
* Initialize entry based on the catalogID provided.
*/
static inline void
_scan_key_init(ScanKey entry,
Oid catalogID,
StrategyNumber strategy,
RegProcedure procedure,
Datum argument)
{
switch (catalogID)
{
case ProcedureRelationId:
ScanKeyInit(entry, Anum_pg_proc_oid, strategy, procedure, argument);
break;
default:
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("set_user: invalid relation ID provided")));
}
}
#ifndef INITSESSIONUSER
#define _InitializeSessionUserId(name,ouserid) InitializeSessionUserId(name)
#endif
#endif /* 9.4 */
#if !defined(PG_VERSION_NUM) || PG_VERSION_NUM < 90400
#error "This extension only builds with PostgreSQL 9.4 or later"
#endif
/* Use our version-specific static declaration here */
_PU_HOOK;
#endif /* SET_USER_COMPAT_H */