1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-04-01 18:50:41 +03:00

system_id: refactor check for allowed system_id

Refactor the code that checks for an allowable system_id
so that it can be used from other places.
This commit is contained in:
David Teigland 2015-11-30 11:46:55 -06:00
parent d3ca18e489
commit 05ac836798
2 changed files with 34 additions and 17 deletions

View File

@ -1238,4 +1238,6 @@ int validate_vg_rename_params(struct cmd_context *cmd,
int is_lockd_type(const char *lock_type);
int is_system_id_allowed(struct cmd_context *cmd, const char *system_id);
#endif

View File

@ -4854,6 +4854,35 @@ static int _access_vg_lock_type(struct cmd_context *cmd, struct volume_group *vg
return 1;
}
int is_system_id_allowed(struct cmd_context *cmd, const char *system_id)
{
/*
* A VG without a system_id can be accessed by anyone.
*/
if (!system_id || !system_id[0])
return 1;
/*
* Allowed if the host and VG system_id's match.
*/
if (cmd->system_id && !strcmp(cmd->system_id, system_id))
return 1;
/*
* Allowed if a host's extra system_id matches.
*/
if (cmd->system_id && _allow_extra_system_id(cmd, system_id))
return 1;
/*
* Not allowed if the host does not have a system_id
* and the VG does, or if the host and VG's system_id's
* do not match.
*/
return 0;
}
static int _access_vg_systemid(struct cmd_context *cmd, struct volume_group *vg)
{
/*
@ -4865,28 +4894,13 @@ static int _access_vg_systemid(struct cmd_context *cmd, struct volume_group *vg)
return 0;
}
/*
* A VG without a system_id can be accessed by anyone.
*/
if (!vg->system_id || !vg->system_id[0])
return 1;
/*
* A few commands allow read-only access to foreign VGs.
*/
if (cmd->include_foreign_vgs)
return 1;
/*
* A host can access a VG with a matching system_id.
*/
if (cmd->system_id && !strcmp(vg->system_id, cmd->system_id))
return 1;
/*
* A host can access a VG if the VG's system_id is in extra_system_ids list.
*/
if (cmd->system_id && _allow_extra_system_id(cmd, vg->system_id))
if (is_system_id_allowed(cmd, vg->system_id))
return 1;
/*
@ -4901,7 +4915,8 @@ static int _access_vg_systemid(struct cmd_context *cmd, struct volume_group *vg)
}
/*
* A host without a system_id cannot access a VG with a system_id.
* Print an error when reading a VG that has a system_id
* and the host system_id is unknown.
*/
if (!cmd->system_id || cmd->unknown_system_id) {
log_error("Cannot access VG %s with system ID %s with unknown local system ID.",