~ubuntu-branches/ubuntu/natty/postgresql-8.4/natty-security

« back to all changes in this revision

Viewing changes to src/bin/pg_dump/pg_dumpall.c

Tags: upstream-8.4.0
ImportĀ upstreamĀ versionĀ 8.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * Portions Copyright (c) 1994, Regents of the University of California
7
7
 *
8
8
 *
9
 
 * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.125 2009/05/10 02:51:44 tgl Exp $
 
9
 * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.126 2009/06/11 14:49:07 momjian Exp $
10
10
 *
11
11
 *-------------------------------------------------------------------------
12
12
 */
51
51
 
52
52
static int      runPgDump(const char *dbname);
53
53
static PGconn *connectDatabase(const char *dbname, const char *pghost, const char *pgport,
54
 
                          const char *pguser, enum trivalue prompt_password, bool fail_on_error);
 
54
          const char *pguser, enum trivalue prompt_password, bool fail_on_error);
55
55
static PGresult *executeQuery(PGconn *conn, const char *query);
56
56
static void executeCommand(PGconn *conn, const char *query);
57
57
 
279
279
                                        disable_dollar_quoting = 1;
280
280
                                else if (strcmp(optarg, "disable-triggers") == 0)
281
281
                                        disable_triggers = 1;
282
 
                                else if (strcmp(optarg, "no-tablespaces") == 0) 
 
282
                                else if (strcmp(optarg, "no-tablespaces") == 0)
283
283
                                        no_tablespaces = 1;
284
284
                                else if (strcmp(optarg, "use-set-session-authorization") == 0)
285
285
                                        use_setsessauth = 1;
455
455
        if (!data_only)
456
456
        {
457
457
                /*
458
 
                 * If asked to --clean, do that first.  We can avoid detailed
 
458
                 * If asked to --clean, do that first.  We can avoid detailed
459
459
                 * dependency analysis because databases never depend on each other,
460
 
                 * and tablespaces never depend on each other.  Roles could have
 
460
                 * and tablespaces never depend on each other.  Roles could have
461
461
                 * grants to each other, but DROP ROLE will clean those up silently.
462
462
                 */
463
463
                if (output_clean)
476
476
                }
477
477
 
478
478
                /*
479
 
                 * Now create objects as requested.  Be careful that option logic
480
 
                 * here is the same as for drops above.
 
479
                 * Now create objects as requested.  Be careful that option logic here
 
480
                 * is the same as for drops above.
481
481
                 */
482
482
                if (!tablespaces_only)
483
483
                {
550
550
        printf(_("  --no-tablespaces            do not dump tablespace assignments\n"));
551
551
        printf(_("  --role=ROLENAME             do SET ROLE before dump\n"));
552
552
        printf(_("  --use-set-session-authorization\n"
553
 
                 "                              use SET SESSION AUTHORIZATION commands instead of\n"
554
 
                 "                              ALTER OWNER commands to set ownership\n"));
 
553
                         "                              use SET SESSION AUTHORIZATION commands instead of\n"
 
554
        "                              ALTER OWNER commands to set ownership\n"));
555
555
 
556
556
        printf(_("\nConnection options:\n"));
557
557
        printf(_("  -h, --host=HOSTNAME      database server host or socket directory\n"));
562
562
        printf(_("  -W, --password           force password prompt (should happen automatically)\n"));
563
563
 
564
564
        printf(_("\nIf -f/--file is not used, then the SQL script will be written to the standard\n"
565
 
                "output.\n\n"));
 
565
                         "output.\n\n"));
566
566
        printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
567
567
}
568
568
 
707
707
 
708
708
                /*
709
709
                 * We dump CREATE ROLE followed by ALTER ROLE to ensure that the role
710
 
                 * will acquire the right properties even if it already exists (ie,
711
 
                 * it won't hurt for the CREATE to fail).  This is particularly
712
 
                 * important for the role we are connected as, since even with --clean
713
 
                 * we will have failed to drop it.
 
710
                 * will acquire the right properties even if it already exists (ie, it
 
711
                 * won't hurt for the CREATE to fail).  This is particularly important
 
712
                 * for the role we are connected as, since even with --clean we will
 
713
                 * have failed to drop it.
714
714
                 */
715
715
                appendPQExpBuffer(buf, "CREATE ROLE %s;\n", fmtId(rolename));
716
716
                appendPQExpBuffer(buf, "ALTER ROLE %s WITH", fmtId(rolename));
1090
1090
         * commands for just those databases with values different from defaults.
1091
1091
         *
1092
1092
         * We consider template0's encoding and locale (or, pre-7.1, template1's)
1093
 
         * to define the installation default.  Pre-8.4 installations do not
1094
 
         * have per-database locale settings; for them, every database must
1095
 
         * necessarily be using the installation default, so there's no need to
1096
 
         * do anything (which is good, since in very old versions there is no
1097
 
         * good way to find out what the installation locale is anyway...)
 
1093
         * to define the installation default.  Pre-8.4 installations do not have
 
1094
         * per-database locale settings; for them, every database must necessarily
 
1095
         * be using the installation default, so there's no need to do anything
 
1096
         * (which is good, since in very old versions there is no good way to find
 
1097
         * out what the installation locale is anyway...)
1098
1098
         */
1099
1099
        if (server_version >= 80400)
1100
1100
                res = executeQuery(conn,
1144
1144
                                                   "SELECT datname, "
1145
1145
                                                   "coalesce(rolname, (select rolname from pg_authid where oid=(select datdba from pg_database where datname='template0'))), "
1146
1146
                                                   "pg_encoding_to_char(d.encoding), "
1147
 
                                                   "null::text AS datcollate, null::text AS datctype, datfrozenxid, "
 
1147
                   "null::text AS datcollate, null::text AS datctype, datfrozenxid, "
1148
1148
                                                   "datistemplate, datacl, datconnlimit, "
1149
1149
                                                   "(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace "
1150
1150
                          "FROM pg_database d LEFT JOIN pg_authid u ON (datdba = u.oid) "
1154
1154
                                                   "SELECT datname, "
1155
1155
                                                   "coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), "
1156
1156
                                                   "pg_encoding_to_char(d.encoding), "
1157
 
                                                   "null::text AS datcollate, null::text AS datctype, datfrozenxid, "
 
1157
                   "null::text AS datcollate, null::text AS datctype, datfrozenxid, "
1158
1158
                                                   "datistemplate, datacl, -1 as datconnlimit, "
1159
1159
                                                   "(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace "
1160
1160
                   "FROM pg_database d LEFT JOIN pg_shadow u ON (datdba = usesysid) "
1164
1164
                                                   "SELECT datname, "
1165
1165
                                                   "coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), "
1166
1166
                                                   "pg_encoding_to_char(d.encoding), "
1167
 
                                                   "null::text AS datcollate, null::text AS datctype, datfrozenxid, "
 
1167
                   "null::text AS datcollate, null::text AS datctype, datfrozenxid, "
1168
1168
                                                   "datistemplate, datacl, -1 as datconnlimit, "
1169
1169
                                                   "'pg_default' AS dattablespace "
1170
1170
                   "FROM pg_database d LEFT JOIN pg_shadow u ON (datdba = usesysid) "
1206
1206
                char       *dbencoding = PQgetvalue(res, i, 2);
1207
1207
                char       *dbcollate = PQgetvalue(res, i, 3);
1208
1208
                char       *dbctype = PQgetvalue(res, i, 4);
1209
 
                uint32     dbfrozenxid = atooid(PQgetvalue(res, i, 5));
 
1209
                uint32          dbfrozenxid = atooid(PQgetvalue(res, i, 5));
1210
1210
                char       *dbistemplate = PQgetvalue(res, i, 6);
1211
1211
                char       *dbacl = PQgetvalue(res, i, 7);
1212
1212
                char       *dbconnlimit = PQgetvalue(res, i, 8);
1527
1527
 */
1528
1528
static PGconn *
1529
1529
connectDatabase(const char *dbname, const char *pghost, const char *pgport,
1530
 
                                const char *pguser, enum trivalue prompt_password, bool fail_on_error)
 
1530
           const char *pguser, enum trivalue prompt_password, bool fail_on_error)
1531
1531
{
1532
1532
        PGconn     *conn;
1533
1533
        bool            new_pass;
1605
1605
        }
1606
1606
 
1607
1607
        /*
1608
 
         * We allow the server to be back to 7.0, and up to any minor release
1609
 
         * of our own major version.  (See also version check in pg_dump.c.)
 
1608
         * We allow the server to be back to 7.0, and up to any minor release of
 
1609
         * our own major version.  (See also version check in pg_dump.c.)
1610
1610
         */
1611
1611
        if (my_version != server_version
1612
1612
                && (server_version < 70000 ||
1727
1727
                        appendPQExpBufferChar(buf, *p);
1728
1728
        }
1729
1729
        appendPQExpBufferChar(buf, '\'');
1730
 
 
1731
 
#else /* WIN32 */
 
1730
#else                                                   /* WIN32 */
1732
1731
 
1733
1732
        appendPQExpBufferChar(buf, '"');
1734
1733
        for (p = str; *p; p++)
1739
1738
                        appendPQExpBufferChar(buf, *p);
1740
1739
        }
1741
1740
        appendPQExpBufferChar(buf, '"');
1742
 
#endif /* WIN32 */
 
1741
#endif   /* WIN32 */
1743
1742
}