diff --git a/doc/src/sgml/ref/copy.sgml b/doc/src/sgml/ref/copy.sgml index 2850b47..eb53ddf 100644 --- a/doc/src/sgml/ref/copy.sgml +++ b/doc/src/sgml/ref/copy.sgml @@ -44,6 +44,7 @@ COPY { table_name [ ( column_name [, ...] ) FORCE_NULL ( column_name [, ...] ) ENCODING 'encoding_name' + NO READ ACCESS @@ -356,7 +357,17 @@ COPY { table_name [ ( - + + + NO READ ACCESS + + + This specifies, do not give any read access to non instance owner members. + If this option is omitted, copy gives read access to all members, which is the default behaviour. + + + + diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 8db1b35..367d430 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -133,7 +133,7 @@ typedef struct CopyStateData bool convert_selectively; /* do selective binary conversion? */ List *convert_select; /* list of column names (can be NIL) */ bool *convert_select_flags; /* per-column CSV/TEXT CS flags */ - + bool is_no_read_acc; /* these are just for error messages, see CopyFromErrorCallback */ const char *cur_relname; /* table name for error messages */ int cur_lineno; /* line number for error messages */ @@ -1153,6 +1153,14 @@ ProcessCopyOptions(CopyState cstate, errmsg("argument to option \"%s\" must be a valid encoding name", defel->defname))); } + else if (strcmp(defel->defname, "is_no_read_acc") == 0) + { + if (cstate->is_no_read_acc) + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("conflicting or redundant options"))); + cstate->is_no_read_acc = true; + } else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -1302,6 +1310,11 @@ ProcessCopyOptions(CopyState cstate, ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("CSV quote character must not appear in the NULL specification"))); + + if ( cstate->is_no_read_acc && is_from ) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("COPY owner access only available using COPY TO file"))); } /* @@ -1723,7 +1736,11 @@ BeginCopyTo(Relation rel, (errcode(ERRCODE_INVALID_NAME), errmsg("relative path not allowed for COPY to file"))); - oumask = umask(S_IWGRP | S_IWOTH); + if (cstate->is_no_read_acc) + oumask = umask(S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH); + else + oumask = umask(S_IWGRP | S_IWOTH); + cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W); umask(oumask); if (cstate->copy_file == NULL) diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 1efc6d6..5dc5cbd 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -2712,6 +2712,10 @@ copy_opt_item: { $$ = makeDefElem("encoding", (Node *)makeString($2)); } + | NO READ ACCESS + { + $$ = makeDefElem("is_no_read_acc", (Node *)makeInteger(TRUE)); + } ; /* The following exist for backward compatibility with very old versions */