65
65
class DbSchema(dict):
66
groups = None # List of groups defined in the db
67
users = None # List of users defined in the db
66
groups = None # List of groups defined in the db
67
users = None # List of users defined in the db
69
69
def __init__(self, con):
70
70
super(DbSchema, self).__init__()
159
159
config.read([configfile_name])
161
161
con = connect(options.dbuser)
162
cur = CursorWrapper(con.cursor())
164
163
if options.cluster:
165
164
nodes = replication.helpers.get_nodes(con, 1)
172
171
node.nickname, node.connection_string))
173
172
reset_permissions(
174
173
psycopg2.connect(node.connection_string), config, options)
176
175
log.warning("--cluster requested, but not a Slony-I cluster.")
177
176
log.info("Resetting permissions on single database")
178
177
reset_permissions(con, config, options)
181
181
def list_identifiers(identifiers):
388
388
log.debug("%s not in any roles", user)
390
# Change ownership of all objects to OWNER
391
for obj in schema.values():
392
if obj.type in ("function", "sequence"):
393
pass # Can't change ownership of functions or sequences
395
if obj.owner != options.owner:
396
log.info("Resetting ownership of %s", obj.fullname)
397
cur.execute("ALTER TABLE %s OWNER TO %s" % (
398
obj.fullname, quote_identifier(options.owner)))
400
390
if options.revoke:
391
# Change ownership of all objects to OWNER.
392
# We skip this in --no-revoke mode as ownership changes may
393
# block on a live system.
394
for obj in schema.values():
395
if obj.type in ("function", "sequence"):
396
pass # Can't change ownership of functions or sequences
398
if obj.owner != options.owner:
399
log.info("Resetting ownership of %s", obj.fullname)
400
cur.execute("ALTER TABLE %s OWNER TO %s" % (
401
obj.fullname, quote_identifier(options.owner)))
401
403
# Revoke all privs from known groups. Don't revoke anything for
402
404
# users or groups not defined in our security.cfg.
403
405
table_revocations = PermissionGatherer("TABLE")
429
431
function_revocations.revoke(cur)
430
432
sequence_revocations.revoke(cur)
434
log.info("Not resetting ownership of database objects")
432
435
log.info("Not revoking permissions on database objects")
434
437
# Set of all tables we have granted permissions on. After we have assigned