Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fa608ad

Browse files
author
Bryan Henderson
committed
Fix bug in checking permissions on table being COPY'd.
1 parent d27c28f commit fa608ad

File tree

1 file changed

+119
-143
lines changed

1 file changed

+119
-143
lines changed

src/backend/tcop/utility.c

Lines changed: 119 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.3 1996/10/31 09:08:10 bryanh Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.4 1996/11/02 02:03:13 bryanh Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -52,25 +52,25 @@
5252

5353

5454
/* ----------------
55-
* CHECK_IF_ABORTED() is used to avoid doing unnecessary
56-
* processing within an aborted transaction block.
55+
* CHECK_IF_ABORTED() is used to avoid doing unnecessary
56+
* processing within an aborted transaction block.
5757
* ----------------
5858
*/
5959
#define CHECK_IF_ABORTED() \
6060
if (IsAbortedTransactionBlockState()) { \
61-
elog(NOTICE, "(transaction aborted): %s", \
62-
"queries ignored until END"); \
63-
commandTag = "*ABORT STATE*"; \
64-
break; \
61+
elog(NOTICE, "(transaction aborted): %s", \
62+
"queries ignored until END"); \
63+
commandTag = "*ABORT STATE*"; \
64+
break; \
6565
} \
6666

6767
/* ----------------
68-
* general utility function invoker
68+
* general utility function invoker
6969
* ----------------
7070
*/
7171
void
7272
ProcessUtility(Node *parsetree,
73-
CommandDest dest)
73+
CommandDest dest)
7474
{
7575
char *commandTag = NULL;
7676
char *relname;
@@ -80,163 +80,139 @@ ProcessUtility(Node *parsetree,
8080
userName = GetPgUserName();
8181

8282
switch (nodeTag(parsetree)) {
83-
/* ********************************
84-
* transactions
85-
* ********************************
86-
*/
83+
/* ********************************
84+
* transactions
85+
* ********************************
86+
*/
8787
case T_TransactionStmt:
88-
{
89-
TransactionStmt *stmt = (TransactionStmt *)parsetree;
90-
switch (stmt->command) {
91-
case BEGIN_TRANS:
92-
commandTag = "BEGIN";
93-
CHECK_IF_ABORTED();
94-
BeginTransactionBlock();
95-
break;
96-
97-
case END_TRANS:
98-
commandTag = "END";
99-
EndTransactionBlock();
100-
break;
101-
102-
case ABORT_TRANS:
103-
commandTag = "ABORT";
104-
UserAbortTransactionBlock();
105-
break;
106-
}
107-
}
108-
break;
88+
{
89+
TransactionStmt *stmt = (TransactionStmt *)parsetree;
90+
switch (stmt->command) {
91+
case BEGIN_TRANS:
92+
commandTag = "BEGIN";
93+
CHECK_IF_ABORTED();
94+
BeginTransactionBlock();
95+
break;
96+
97+
case END_TRANS:
98+
commandTag = "END";
99+
EndTransactionBlock();
100+
break;
101+
102+
case ABORT_TRANS:
103+
commandTag = "ABORT";
104+
UserAbortTransactionBlock();
105+
break;
106+
}
107+
}
108+
break;
109109

110-
/* ********************************
111-
* portal manipulation
112-
* ********************************
113-
*/
110+
/* ********************************
111+
* portal manipulation
112+
* ********************************
113+
*/
114114
case T_ClosePortalStmt:
115-
{
116-
ClosePortalStmt *stmt = (ClosePortalStmt *)parsetree;
117-
118-
commandTag = "CLOSE";
119-
CHECK_IF_ABORTED();
120-
121-
PerformPortalClose(stmt->portalname, dest);
122-
}
123-
break;
115+
{
116+
ClosePortalStmt *stmt = (ClosePortalStmt *)parsetree;
117+
118+
commandTag = "CLOSE";
119+
CHECK_IF_ABORTED();
120+
121+
PerformPortalClose(stmt->portalname, dest);
122+
}
123+
break;
124124

125125
case T_FetchStmt:
126-
{
127-
FetchStmt *stmt = (FetchStmt *)parsetree;
128-
char *portalName = stmt->portalname;
129-
bool forward;
130-
int count;
131-
132-
commandTag = "FETCH";
133-
CHECK_IF_ABORTED();
134-
135-
forward = (bool)(stmt->direction == FORWARD);
136-
137-
/* parser ensures that count is >= 0 and
138-
'fetch ALL' -> 0 */
139-
140-
count = stmt->howMany;
141-
PerformPortalFetch(portalName, forward, count, commandTag, dest);
142-
}
143-
break;
126+
{
127+
FetchStmt *stmt = (FetchStmt *)parsetree;
128+
char *portalName = stmt->portalname;
129+
bool forward;
130+
int count;
131+
132+
commandTag = "FETCH";
133+
CHECK_IF_ABORTED();
134+
135+
forward = (bool)(stmt->direction == FORWARD);
136+
137+
/* parser ensures that count is >= 0 and
138+
'fetch ALL' -> 0 */
139+
140+
count = stmt->howMany;
141+
PerformPortalFetch(portalName, forward, count, commandTag, dest);
142+
}
143+
break;
144144

145-
/* ********************************
146-
* relation and attribute manipulation
147-
* ********************************
148-
*/
145+
/* ********************************
146+
* relation and attribute manipulation
147+
* ********************************
148+
*/
149149
case T_CreateStmt:
150-
commandTag = "CREATE";
151-
CHECK_IF_ABORTED();
150+
commandTag = "CREATE";
151+
CHECK_IF_ABORTED();
152152

153-
DefineRelation((CreateStmt *)parsetree);
154-
break;
153+
DefineRelation((CreateStmt *)parsetree);
154+
break;
155155

156156
case T_DestroyStmt:
157-
{
158-
DestroyStmt *stmt = (DestroyStmt *)parsetree;
159-
List *arg;
160-
List *args = stmt->relNames;
161-
162-
commandTag = "DROP";
163-
CHECK_IF_ABORTED();
164-
165-
foreach (arg, args) {
166-
relname = strVal(lfirst(arg));
167-
if (IsSystemRelationName(relname))
168-
elog(WARN, "class \"%-.*s\" is a system catalog",
169-
NAMEDATALEN, relname);
157+
{
158+
DestroyStmt *stmt = (DestroyStmt *)parsetree;
159+
List *arg;
160+
List *args = stmt->relNames;
161+
162+
commandTag = "DROP";
163+
CHECK_IF_ABORTED();
164+
165+
foreach (arg, args) {
166+
relname = strVal(lfirst(arg));
167+
if (IsSystemRelationName(relname))
168+
elog(WARN, "class \"%-.*s\" is a system catalog",
169+
NAMEDATALEN, relname);
170170
#ifndef NO_SECURITY
171-
if (!pg_ownercheck(userName, relname, RELNAME))
172-
elog(WARN, "you do not own class \"%-.*s\"",
173-
NAMEDATALEN, relname);
171+
if (!pg_ownercheck(userName, relname, RELNAME))
172+
elog(WARN, "you do not own class \"%-.*s\"",
173+
NAMEDATALEN, relname);
174174
#endif
175-
}
176-
foreach (arg, args) {
177-
relname = strVal(lfirst(arg));
178-
RemoveRelation(relname);
179-
}
180-
}
181-
break;
175+
}
176+
foreach (arg, args) {
177+
relname = strVal(lfirst(arg));
178+
RemoveRelation(relname);
179+
}
180+
}
181+
break;
182182

183183
case T_PurgeStmt:
184-
{
185-
PurgeStmt *stmt = (PurgeStmt *)parsetree;
186-
187-
commandTag = "PURGE";
188-
CHECK_IF_ABORTED();
189-
190-
RelationPurge(stmt->relname,
191-
stmt->beforeDate, /* absolute time string */
192-
stmt->afterDate); /* relative time string */
193-
}
194-
break;
184+
{
185+
PurgeStmt *stmt = (PurgeStmt *)parsetree;
186+
187+
commandTag = "PURGE";
188+
CHECK_IF_ABORTED();
189+
190+
RelationPurge(stmt->relname,
191+
stmt->beforeDate, /* absolute time string */
192+
stmt->afterDate); /* relative time string */
193+
}
194+
break;
195195

196196
case T_CopyStmt:
197-
{
198-
CopyStmt *stmt = (CopyStmt *)parsetree;
199-
char *filename;
200-
char *delim;
201-
bool isBinary;
202-
bool isOids;
203-
bool isFrom;
204-
bool pipe = false;
197+
{
198+
CopyStmt *stmt = (CopyStmt *)parsetree;
205199

206200
commandTag = "COPY";
207201
CHECK_IF_ABORTED();
208202

209-
relname = stmt->relname;
210-
isBinary = stmt->binary;
211-
isOids = stmt->oids;
212-
213-
isFrom = (bool)(stmt->direction == FROM);
214-
filename = stmt->filename;
215-
delim = stmt->delimiter;
216-
217-
#ifndef NO_SECURITY
218-
if (isFrom) {
219-
if (!pg_aclcheck(relname, userName, ACL_RD))
220-
elog(WARN, "%s %s", relname, ACL_NO_PRIV_WARNING);
221-
} else {
222-
if (!pg_aclcheck(relname, userName, ACL_WR))
223-
elog(WARN, "%s %s", relname, ACL_NO_PRIV_WARNING);
224-
}
225-
#endif
226-
227203
/* Free up file descriptors - going to do a read... */
228-
229204
closeOneVfd();
230205

231-
/*
232-
* use stdin/stdout if filename is null.
233-
*/
234-
if (filename == NULL)
235-
pipe = true;
236-
237-
if (pipe && IsUnderPostmaster) dest = CopyEnd;
238-
239-
DoCopy(relname, isBinary, isOids, isFrom, pipe, filename, delim);
206+
DoCopy(stmt->relname,
207+
stmt->binary,
208+
stmt->oids,
209+
(bool)(stmt->direction == FROM),
210+
(bool)(stmt->filename == NULL),
211+
/* null filename means copy to/from stdout/stdin,
212+
rather than to/from a file.
213+
*/
214+
stmt->filename,
215+
stmt->delimiter);
240216
}
241217
break;
242218

0 commit comments

Comments
 (0)