|
7 | 7 | *
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.58 1997/03/12 21:19:14 scrappy Exp $ |
| 10 | + * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.59 1997/04/10 11:54:29 scrappy Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -82,6 +82,7 @@ handleCopyIn(PGresult * res, const bool mustprompt,
|
82 | 82 | FILE * copystream);
|
83 | 83 | static int tableList(PsqlSettings * ps, bool deep_tablelist);
|
84 | 84 | static int tableDesc(PsqlSettings * ps, char *table);
|
| 85 | +static int rightsList(PsqlSettings * ps); |
85 | 86 | static void prompt_for_password(char *username, char *password);
|
86 | 87 | static char * make_connect_string(char *host, char *port, char *dbname,
|
87 | 88 | char *username, char *password);
|
@@ -173,6 +174,7 @@ slashUsage(PsqlSettings * ps)
|
173 | 174 | fprintf(stderr, " \\t -- toggle table headings and row count (currently %s)\n", on(ps->opt.header));
|
174 | 175 | fprintf(stderr, " \\T [<html>] -- set html3.0 <table ...> options (currently '%s')\n", ps->opt.tableOpt ? ps->opt.tableOpt : "");
|
175 | 176 | fprintf(stderr, " \\x -- toggle expanded output (currently %s)\n", on(ps->opt.expanded));
|
| 177 | + fprintf(stderr, " \\z -- list current grant/revoke permissions\n"); |
176 | 178 | fprintf(stderr, " \\! [<cmd>] -- shell escape or command\n");
|
177 | 179 | }
|
178 | 180 |
|
@@ -301,6 +303,53 @@ tableList(PsqlSettings * ps, bool deep_tablelist)
|
301 | 303 | }
|
302 | 304 | }
|
303 | 305 |
|
| 306 | +/* |
| 307 | + * List Tables Grant/Revoke Permissions returns 0 if all went well |
| 308 | + * |
| 309 | + */ |
| 310 | +int |
| 311 | +rightsList(PsqlSettings * ps) |
| 312 | +{ |
| 313 | + char listbuf[256]; |
| 314 | + int nColumns; |
| 315 | + int i; |
| 316 | + |
| 317 | + PGresult *res; |
| 318 | + |
| 319 | + listbuf[0] = '\0'; |
| 320 | + strcat(listbuf, "SELECT relname, relacl"); |
| 321 | + strcat(listbuf, " FROM pg_class, pg_user "); |
| 322 | + strcat(listbuf, "WHERE ( relkind = 'r' OR relkind = 'i') "); |
| 323 | + strcat(listbuf, " and relname !~ '^pg_'"); |
| 324 | + strcat(listbuf, " and relname !~ '^Inv[0-9]+'"); |
| 325 | + strcat(listbuf, " and usesysid = relowner"); |
| 326 | + strcat(listbuf, " ORDER BY relname "); |
| 327 | + if (!(res = PSQLexec(ps, listbuf))) |
| 328 | + return -1; |
| 329 | + |
| 330 | + nColumns = PQntuples(res); |
| 331 | + if(nColumns > 0) { |
| 332 | + /* Display the information */ |
| 333 | + |
| 334 | + printf("\nDatabase = %s\n", PQdb(ps->db)); |
| 335 | + printf(" +------------------+----------------------------------------------------+\n"); |
| 336 | + printf(" | Relation | Grant/Revoke Permissions |\n"); |
| 337 | + printf(" +------------------+----------------------------------------------------+\n"); |
| 338 | + |
| 339 | + /* next, print out the instances */ |
| 340 | + for (i = 0; i < PQntuples(res); i++) { |
| 341 | + printf(" | %-16.16s", PQgetvalue(res, i, 0)); |
| 342 | + printf(" | %-50.50s | ", PQgetvalue(res, i, 1)); |
| 343 | + printf("\n"); |
| 344 | + } |
| 345 | + printf(" +------------------+----------------------------------------------------+\n"); |
| 346 | + PQclear(res); |
| 347 | + return (0); |
| 348 | + } else { |
| 349 | + fprintf(stderr, "Couldn't find any tables!\n"); |
| 350 | + return (-1); |
| 351 | + } |
| 352 | +} |
304 | 353 | /*
|
305 | 354 | * Describe a table
|
306 | 355 | *
|
@@ -1193,6 +1242,9 @@ HandleSlashCmds(PsqlSettings * settings,
|
1193 | 1242 | fprintf(stderr, "field separater changed to '%s'\n", settings->opt.fieldSep);
|
1194 | 1243 | }
|
1195 | 1244 | break;
|
| 1245 | + case 'z': /* list table rights (grant/revoke) */ |
| 1246 | + rightsList(settings); |
| 1247 | + break; |
1196 | 1248 | case 't': /* toggle headers */
|
1197 | 1249 | toggle(settings, &settings->opt.header, "output headings and row count");
|
1198 | 1250 | break;
|
|
0 commit comments