2018-06-08 Fred Gleason <fredg@paravelsystems.com>

* Added a sanity check to rddbmgr(8) to prevent reverting from an
	unknown schema.
	* Added a sanity check to rddbmgr(8) to prevent inadvertent
	reversion to an	implied schema.
This commit is contained in:
Fred Gleason
2018-06-08 18:13:49 +00:00
parent 1196cda562
commit 047e2d05be
2 changed files with 35 additions and 17 deletions

View File

@@ -222,23 +222,6 @@ MainObject::MainObject(QObject *parent)
fprintf(stderr,"rddbmgr: exactly one command must be specified\n");
exit(1);
}
if(set_schema>0) {
if((set_schema<242)||(set_schema>RD_VERSION_DATABASE)) {
fprintf(stderr,"rddbmgr: unsupported schema\n");
exit(1);
}
}
else {
if(set_version.isEmpty()) {
set_schema=RD_VERSION_DATABASE;
}
else {
if((set_schema=GetVersionSchema(set_version))==0) {
fprintf(stderr,"invalid/unsupported Rivendell version\n");
exit(1);
}
}
}
if(db_yes&&db_no) {
fprintf(stderr,"rddbmgr: '--yes' and '--no' are mutually exclusive\n");
exit(1);
@@ -318,6 +301,36 @@ MainObject::MainObject(QObject *parent)
RDConfig::createTablePostfix(db_mysql_engine,db_mysql_charset,
db_mysql_collation);
//
// Resolve Target Schema
//
int schema=GetCurrentSchema();
if(schema>RD_VERSION_DATABASE) {
fprintf(stderr,"rddbmgr: unknown current schema [%d]\n",schema);
exit(1);
}
if(set_schema>0) {
if((set_schema<242)||(set_schema>RD_VERSION_DATABASE)) {
fprintf(stderr,"rddbmgr: unsupported schema\n");
exit(1);
}
}
else {
if(set_version.isEmpty()) {
if(set_schema<schema) {
fprintf(stderr,"rddbmgr: reversion implied, you must explicitly specify the target schema\n");
exit(1);
}
set_schema=RD_VERSION_DATABASE;
}
else {
if((set_schema=GetVersionSchema(set_version))==0) {
fprintf(stderr,"invalid/unsupported Rivendell version\n");
exit(1);
}
}
}
//
// Run the Command
//