Commit 1e9b80a2 authored by Marc G. Fournier's avatar Marc G. Fournier

modifications to pg_dump towards supporting dumping of ACLs (doesn't work yet!)

modification to c.h so that bool isn't typedef'd under __cplusplus
parent bb0a1741
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.10 1997/02/13 08:31:17 scrappy Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.11 1997/04/12 09:23:59 scrappy Exp $
* *
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2 * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
* *
...@@ -192,7 +192,10 @@ strInArray(const char* pattern, char** arr, int arr_size) ...@@ -192,7 +192,10 @@ strInArray(const char* pattern, char** arr, int arr_size)
*/ */
TableInfo * TableInfo *
dumpSchema(FILE *fout, int *numTablesPtr, const char *tablename) dumpSchema(FILE *fout,
int *numTablesPtr,
const char *tablename,
const bool acls)
{ {
int numTypes; int numTypes;
int numFuncs; int numFuncs;
...@@ -249,7 +252,7 @@ if (fout) { ...@@ -249,7 +252,7 @@ if (fout) {
if (g_verbose) fprintf(stderr,"%s dumping out tables %s\n", if (g_verbose) fprintf(stderr,"%s dumping out tables %s\n",
g_comment_start, g_comment_end); g_comment_start, g_comment_end);
dumpTables(fout, tblinfo, numTables, inhinfo, numInherits, dumpTables(fout, tblinfo, numTables, inhinfo, numInherits,
tinfo, numTypes, tablename); tinfo, numTypes, tablename, acls);
} }
if (!tablename && fout) { if (!tablename && fout) {
......
...@@ -13,14 +13,15 @@ ...@@ -13,14 +13,15 @@
* indices * indices
* aggregates * aggregates
* operators * operators
* ACL - grant/revoke
* *
* the output script is SQL that is understood by Postgres95 * the output script is SQL that is understood by PostgreSQL
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.26 1997/04/02 04:17:21 vadim Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.27 1997/04/12 09:24:07 scrappy Exp $
* *
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
* *
...@@ -110,6 +111,8 @@ usage(const char* progname) ...@@ -110,6 +111,8 @@ usage(const char* progname)
"\t -t table \t\t dump for this table only\n"); "\t -t table \t\t dump for this table only\n");
fprintf(stderr, fprintf(stderr,
"\t -o \t\t dump object id's (oids)\n"); "\t -o \t\t dump object id's (oids)\n");
fprintf(stderr,
"\t -z \t\t dump ACLs (grant/revoke)\n");
fprintf(stderr, fprintf(stderr,
"\nIf dbname is not supplied, then the DATABASE environment " "\nIf dbname is not supplied, then the DATABASE environment "
"variable value is used.\n"); "variable value is used.\n");
...@@ -390,20 +393,16 @@ main(int argc, char** argv) ...@@ -390,20 +393,16 @@ main(int argc, char** argv)
{ {
int c; int c;
const char* progname; const char* progname;
const char* filename; const char* filename = NULL;
const char* dbname; const char* dbname = NULL;
const char *pghost = NULL; const char *pghost = NULL;
const char *pgport = NULL; const char *pgport = NULL;
const char *tablename; const char *tablename = NULL;
int oids; int oids = 0, acls = 0;
TableInfo *tblinfo; TableInfo *tblinfo;
int numTables; int numTables;
dbname = NULL;
filename = NULL;
tablename = NULL;
g_verbose = false; g_verbose = false;
oids = 0;
strcpy(g_comment_start,"-- "); strcpy(g_comment_start,"-- ");
g_comment_end[0] = '\0'; g_comment_end[0] = '\0';
...@@ -413,7 +412,7 @@ main(int argc, char** argv) ...@@ -413,7 +412,7 @@ main(int argc, char** argv)
progname = *argv; progname = *argv;
while ((c = getopt(argc, argv,"f:H:p:t:vSDdDao")) != EOF) { while ((c = getopt(argc, argv,"f:H:p:t:vSDdDaoz")) != EOF) {
switch(c) { switch(c) {
case 'f': /* output file name */ case 'f': /* output file name */
filename = optarg; filename = optarg;
...@@ -446,6 +445,9 @@ main(int argc, char** argv) ...@@ -446,6 +445,9 @@ main(int argc, char** argv)
case 'o': /* Dump oids */ case 'o': /* Dump oids */
oids = 1; oids = 1;
break; break;
case 'z': /* Dump oids */
acls = 1;
break;
default: default:
usage(progname); usage(progname);
break; break;
...@@ -488,10 +490,10 @@ main(int argc, char** argv) ...@@ -488,10 +490,10 @@ main(int argc, char** argv)
if (g_verbose) if (g_verbose)
fprintf(stderr, "%s last builtin oid is %d %s\n", fprintf(stderr, "%s last builtin oid is %d %s\n",
g_comment_start, g_last_builtin_oid, g_comment_end); g_comment_start, g_last_builtin_oid, g_comment_end);
tblinfo = dumpSchema(g_fout, &numTables, tablename); tblinfo = dumpSchema(g_fout, &numTables, tablename, acls);
} }
else else
tblinfo = dumpSchema(NULL, &numTables, tablename); tblinfo = dumpSchema(NULL, &numTables, tablename, acls);
if (!schemaOnly) { if (!schemaOnly) {
dumpClasses(tblinfo, numTables, g_fout, tablename, oids); dumpClasses(tblinfo, numTables, g_fout, tablename, oids);
...@@ -924,6 +926,7 @@ getTables(int *numTables) ...@@ -924,6 +926,7 @@ getTables(int *numTables)
int i_relname; int i_relname;
int i_relarch; int i_relarch;
int i_relkind; int i_relkind;
int i_relacl;
/* find all the user-defined tables (no indices and no catalogs), /* find all the user-defined tables (no indices and no catalogs),
ordering by oid is important so that we always process the parent ordering by oid is important so that we always process the parent
...@@ -940,7 +943,7 @@ getTables(int *numTables) ...@@ -940,7 +943,7 @@ getTables(int *numTables)
PQclear(res); PQclear(res);
sprintf(query, sprintf(query,
"SELECT oid, relname, relarch, relkind from pg_class " "SELECT oid, relname, relarch, relkind, relacl from pg_class "
"where (relkind = 'r' or relkind = 'S') and relname !~ '^pg_' " "where (relkind = 'r' or relkind = 'S') and relname !~ '^pg_' "
"and relname !~ '^Xinv' order by oid;"); "and relname !~ '^Xinv' order by oid;");
...@@ -961,11 +964,13 @@ getTables(int *numTables) ...@@ -961,11 +964,13 @@ getTables(int *numTables)
i_relname = PQfnumber(res,"relname"); i_relname = PQfnumber(res,"relname");
i_relarch = PQfnumber(res,"relarch"); i_relarch = PQfnumber(res,"relarch");
i_relkind = PQfnumber(res,"relkind"); i_relkind = PQfnumber(res,"relkind");
i_relacl = PQfnumber(res,"relacl");
for (i=0;i<ntups;i++) { for (i=0;i<ntups;i++) {
tblinfo[i].oid = strdup(PQgetvalue(res,i,i_oid)); tblinfo[i].oid = strdup(PQgetvalue(res,i,i_oid));
tblinfo[i].relname = strdup(PQgetvalue(res,i,i_relname)); tblinfo[i].relname = strdup(PQgetvalue(res,i,i_relname));
tblinfo[i].relarch = strdup(PQgetvalue(res,i,i_relarch)); tblinfo[i].relarch = strdup(PQgetvalue(res,i,i_relarch));
tblinfo[i].relacl = strdup(PQgetvalue(res,i,i_relacl));
tblinfo[i].sequence = (strcmp (PQgetvalue(res,i,i_relkind), "S") == 0); tblinfo[i].sequence = (strcmp (PQgetvalue(res,i,i_relkind), "S") == 0);
} }
...@@ -1504,7 +1509,8 @@ dumpAggs(FILE* fout, AggInfo* agginfo, int numAggs, ...@@ -1504,7 +1509,8 @@ dumpAggs(FILE* fout, AggInfo* agginfo, int numAggs,
void dumpTables(FILE* fout, TableInfo *tblinfo, int numTables, void dumpTables(FILE* fout, TableInfo *tblinfo, int numTables,
InhInfo *inhinfo, int numInherits, InhInfo *inhinfo, int numInherits,
TypeInfo *tinfo, int numTypes, const char *tablename) TypeInfo *tinfo, int numTypes, const char *tablename,
const bool acls)
{ {
int i,j,k; int i,j,k;
char q[MAXQUERYLEN]; char q[MAXQUERYLEN];
...@@ -1611,6 +1617,11 @@ void dumpTables(FILE* fout, TableInfo *tblinfo, int numTables, ...@@ -1611,6 +1617,11 @@ void dumpTables(FILE* fout, TableInfo *tblinfo, int numTables,
q, q,
archiveMode); archiveMode);
fputs(q,fout); fputs(q,fout);
if(acls)
fprintf(fout,
"UPDATE pg_class SET relacl='%s' where relname='%s';\n",
tblinfo[i].relacl, tblinfo[i].relname);
} }
} }
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_dump.h,v 1.11 1997/04/02 04:17:27 vadim Exp $ * $Id: pg_dump.h,v 1.12 1997/04/12 09:24:14 scrappy Exp $
* *
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2 * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
* *
...@@ -55,6 +55,7 @@ typedef struct _tableInfo { ...@@ -55,6 +55,7 @@ typedef struct _tableInfo {
char *oid; char *oid;
char *relname; char *relname;
char *relarch; char *relarch;
char *relacl;
bool sequence; bool sequence;
int numatts; /* number of attributes */ int numatts; /* number of attributes */
int *inhAttrs; /* an array of flags, one for each attribute int *inhAttrs; /* an array of flags, one for each attribute
...@@ -143,9 +144,15 @@ extern char g_opaque_type[10]; /* name for the opaque type */ ...@@ -143,9 +144,15 @@ extern char g_opaque_type[10]; /* name for the opaque type */
* common utility functions * common utility functions
*/ */
extern TableInfo* dumpSchema(FILE* fout, int *numTablesPtr, const char *tablename); extern TableInfo* dumpSchema(FILE* fout,
extern void dumpSchemaIdx(FILE* fout, int *numTablesPtr, const char *tablename, int *numTablesPtr,
TableInfo* tblinfo, int numTables); const char *tablename,
const bool acls);
extern void dumpSchemaIdx(FILE* fout,
int *numTablesPtr,
const char *tablename,
TableInfo* tblinfo,
int numTables);
extern char* findTypeByOid(TypeInfo* tinfo, int numTypes, const char* oid); extern char* findTypeByOid(TypeInfo* tinfo, int numTypes, const char* oid);
extern char* findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid); extern char* findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid);
...@@ -188,7 +195,8 @@ extern void dumpOneFunc(FILE* fout, FuncInfo* finfo, int i, ...@@ -188,7 +195,8 @@ extern void dumpOneFunc(FILE* fout, FuncInfo* finfo, int i,
TypeInfo *tinfo, int numTypes); TypeInfo *tinfo, int numTypes);
extern void dumpTables(FILE* fout, TableInfo* tbinfo, int numTables, extern void dumpTables(FILE* fout, TableInfo* tbinfo, int numTables,
InhInfo *inhinfo, int numInherits, InhInfo *inhinfo, int numInherits,
TypeInfo *tinfo, int numTypes, const char *tablename); TypeInfo *tinfo, int numTypes, const char *tablename,
const bool acls);
extern void dumpIndices(FILE* fout, IndInfo* indinfo, int numIndices, extern void dumpIndices(FILE* fout, IndInfo* indinfo, int numIndices,
TableInfo* tbinfo, int numTables, const char *tablename); TableInfo* tbinfo, int numTables, const char *tablename);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: c.h,v 1.9 1997/02/14 04:18:27 momjian Exp $ * $Id: c.h,v 1.10 1997/04/12 09:24:23 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -60,7 +60,9 @@ ...@@ -60,7 +60,9 @@
*/ */
#define false ((char) 0) #define false ((char) 0)
#define true ((char) 1) #define true ((char) 1)
#ifndef __cplusplus
typedef char bool; typedef char bool;
#endif /* not C++ */
typedef bool *BoolPtr; typedef bool *BoolPtr;
#ifndef TRUE #ifndef TRUE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment