forked from arkhipov/acl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.c
132 lines (105 loc) · 3.02 KB
/
util.c
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
/* -------------------------------------------------------------------------
*
* util.c
*
* Copyright (c) 2015-2016 Vladislav Arkhipov <[email protected]>
*
* -------------------------------------------------------------------------
*/
#include "util.h"
static void check_who_array(ArrayType *who_array);
bool
check_access_extract_args(FunctionCallInfo fcinfo, ArrayType **acl,
uint32 *mask, ArrayType **who, bool *implicit_allow,
bool extract_who, bool has_who_argument)
{
if (PG_ARGISNULL(0))
*acl = NULL;
else
*acl = PG_GETARG_ARRAYTYPE_P(0);
if (PG_ARGISNULL(1))
return false;
*mask = PG_GETARG_UINT32(1);
if (has_who_argument && PG_ARGISNULL(2))
return false;
if (extract_who)
{
*who = PG_GETARG_ARRAYTYPE_P(2);
check_who_array(*who);
}
if (PG_ARGISNULL(has_who_argument ? 3 : 2))
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("allow_implicit argument must be not null")));
*implicit_allow = PG_GETARG_BOOL(3);
return true;
}
bool
check_access_text_mask_extract_args(FunctionCallInfo fcinfo, ArrayType **acl,
text **mask, ArrayType **who,
bool *implicit_allow, bool extract_who,
bool has_who_argument)
{
if (PG_ARGISNULL(0))
*acl = NULL;
else
*acl = PG_GETARG_ARRAYTYPE_P(0);
if (PG_ARGISNULL(1))
return false;
*mask = PG_GETARG_TEXT_P(1);
if (has_who_argument && PG_ARGISNULL(2))
return false;
if (extract_who)
{
*who = PG_GETARG_ARRAYTYPE_P(2);
check_who_array(*who);
}
if (PG_ARGISNULL(has_who_argument ? 3 : 2))
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("allow_implicit argument must be not null")));
*implicit_allow = PG_GETARG_BOOL(3);
return true;
}
void
merge_acls_extract_args(FunctionCallInfo fcinfo, ArrayType **parent,
ArrayType **child, bool *container, bool *deny_first)
{
if (PG_ARGISNULL(0))
*parent = NULL;
else
*parent = PG_GETARG_ARRAYTYPE_P(0);
if (PG_ARGISNULL(1))
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("ACL must be not null")));
*child = PG_GETARG_ARRAYTYPE_P(1);
if (PG_ARGISNULL(2))
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("container argument must be not null")));
*container = PG_GETARG_BOOL(2);
if (PG_ARGISNULL(3))
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("deny_first argument must be not null")));
*deny_first = PG_GETARG_BOOL(3);
}
static void
check_who_array(ArrayType *who_array)
{
if (ARR_HASNULL(who_array))
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("Who array must not contain null values")));
if (ARR_NDIM(who_array) > 1)
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("wrong number of dimensions of who array"),
errdetail("Who array must be one dimensional.")));
if (ARR_NDIM(who_array) > 0 && ARR_LBOUND(who_array)[0] != 1)
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("wrong range of who array"),
errdetail("Lower bound of who array must be one.")));
}