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

Commit 8a57e21

Browse files
committed
Incorporate patch from Matt(maycock@intelliquest.com) for dumping ACLs
Clean up formatting of code Integrate new functions into dumpTable This is not tested yet...have to recompile server due to patches from Todd...but this compiles cleanly as it stands now
1 parent a91ad1a commit 8a57e21

File tree

2 files changed

+135
-7
lines changed

2 files changed

+135
-7
lines changed

src/bin/pg_dump/pg_dump.c

+124-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*
2323
* IDENTIFICATION
24-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.55 1997/12/01 22:02:32 momjian Exp $
24+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.56 1997/12/04 01:31:27 scrappy Exp $
2525
*
2626
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2727
*
@@ -2138,6 +2138,117 @@ dumpAggs(FILE *fout, AggInfo *agginfo, int numAggs,
21382138
}
21392139
}
21402140

2141+
/*
2142+
* These are some support functions to fix the acl problem of pg_dump
2143+
*
2144+
* Matthew C. Aycock 12/02/97
2145+
*/
2146+
/*
2147+
* This will return a new string: "s,add"
2148+
*/
2149+
char *AddAcl(char *s, const char *add)
2150+
{
2151+
char *t;
2152+
2153+
if (s == (char *)NULL)
2154+
return (strdup(add));
2155+
2156+
t=(char *)calloc((strlen(s) + strlen(add)+1),sizeof(char));
2157+
sprintf(t,"%s,%s",s,add);
2158+
2159+
return(t);
2160+
}
2161+
/*
2162+
* This will take a string of 'arwR' and return a
2163+
* comma delimited string of SELECT,INSERT,UPDATE,DELETE,RULE
2164+
*/
2165+
char *GetPrivledges(char *s)
2166+
{
2167+
char *acls=NULL;
2168+
2169+
/*Grant All == arwR */
2170+
/* INSERT == ar */
2171+
/* UPDATE/DELETE == rw */
2172+
/* SELECT == r */
2173+
/* RULE == R */
2174+
2175+
if (strstr(s,"arwR"))
2176+
return(strdup("ALL"));
2177+
2178+
if (strstr(s,"ar"))
2179+
acls=AddAcl(acls,"INSERT");
2180+
2181+
if (strstr(s,"rw"))
2182+
acls=AddAcl(acls,"UPDATE,DELETE");
2183+
else
2184+
if (strchr(s,'r'))
2185+
acls=AddAcl(acls,"SELECT");
2186+
2187+
if (strchr(s,'R'))
2188+
acls=AddAcl(acls,"RULES");
2189+
2190+
return(acls);
2191+
}
2192+
/* This will parse the acl string of TableInfo
2193+
* into a two deminsional aray:
2194+
* user | Privledges
2195+
* So to reset the acls I need to grant these priviledges
2196+
* to user
2197+
*/
2198+
ACL *ParseACL(const char *acls,int *count)
2199+
{
2200+
ACL *ParsedAcl=NULL;
2201+
int i,
2202+
len,
2203+
NumAcls=1, /*There is always public*/
2204+
AclLen=0;
2205+
char *s=NULL,
2206+
*user=NULL,
2207+
*priv=NULL,
2208+
*tok;
2209+
2210+
AclLen=strlen(acls);
2211+
2212+
if (AclLen == 0) {
2213+
*count=0;
2214+
return (ACL *) NULL;
2215+
}
2216+
2217+
for (i=0;i<AclLen;i++)
2218+
if (acls[i] == ',')
2219+
NumAcls++;
2220+
2221+
ParsedAcl=(ACL *)calloc(AclLen,sizeof(ACL));
2222+
if (!ParsedAcl) {
2223+
fprintf(stderr,"Could not allocate space for ACLS!\n");
2224+
return (ACL *)NULL;
2225+
}
2226+
2227+
s=strdup(acls);
2228+
2229+
/* Setup up public*/
2230+
ParsedAcl[0].user=strdup("Public");
2231+
tok=strtok(s,",");
2232+
ParsedAcl[0].privledges=GetPrivledges(strchr(tok,'='));
2233+
2234+
/*Do the rest of the users*/
2235+
i=1;
2236+
while ((i < NumAcls) && ((tok=strtok(NULL,",")) != (char *)NULL)) {
2237+
/*User name is string up to = in tok*/
2238+
len=strchr(tok,'=') - tok -1 ;
2239+
user=(char*)calloc(len+1,sizeof(char));
2240+
strncpy(user,tok+1,len);
2241+
if (user[len-1] == '\"')
2242+
user[len-1]=(char)NULL;
2243+
priv=GetPrivledges(tok+len+2);
2244+
ParsedAcl[i].user=user;
2245+
ParsedAcl[i].privledges=priv;
2246+
i++;
2247+
}
2248+
2249+
*count=NumAcls;
2250+
return (ParsedAcl);
2251+
}
21412252
/*
21422253
* dumpTables:
21432254
* write out to fout all the user-define tables
@@ -2151,11 +2262,13 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
21512262
{
21522263
int i,
21532264
j,
2154-
k;
2265+
k,
2266+
l;
21552267
char q[MAXQUERYLEN];
21562268
char **parentRels; /* list of names of parent relations */
21572269
int numParents;
21582270
int actual_atts; /* number of attrs in this CREATE statment */
2271+
ACL *ACLlist;
21592272

21602273
/* First - dump SEQUENCEs */
21612274
for (i = 0; i < numTables; i++)
@@ -2267,10 +2380,15 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
22672380
strcat(q, ";\n");
22682381
fputs(q, fout);
22692382

2270-
if (acls)
2271-
fprintf(fout,
2272-
"UPDATE pg_class SET relacl='%s' where relname='%s';\n",
2273-
tblinfo[i].relacl, tblinfo[i].relname);
2383+
if (acls) {
2384+
ACLlist = ParseACL(tblinfo[i].relacl, &l);
2385+
for(k = 0; k < l; k++) {
2386+
fprintf(fout,
2387+
"GRANT %s on %s to %s;\n",
2388+
ACLlist[k].privledges, tblinfo[i].relname,
2389+
ACLlist[k].user);
2390+
}
2391+
}
22742392
}
22752393
}
22762394
}

src/bin/pg_dump/pg_dump.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: pg_dump.h,v 1.27 1997/11/21 18:11:41 momjian Exp $
8+
* $Id: pg_dump.h,v 1.28 1997/12/04 01:31:28 scrappy Exp $
99
*
1010
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1111
*
@@ -151,6 +151,16 @@ typedef struct _oprInfo
151151
char *usename;
152152
} OprInfo;
153153

154+
/*
155+
* This is some support functions to fix the acl problem of pg_dump
156+
*
157+
* Matthew C. Aycock 12/02/97
158+
*/
159+
typedef struct _AclType {
160+
char *user;
161+
char *privledges;
162+
} ACL;
163+
154164

155165
/* global decls */
156166
extern bool g_verbose; /* verbose flag */

0 commit comments

Comments
 (0)