Discussion:
[pve-devel] [PATCH access-control] api/ticket: move getting cluster name into an eval
Thomas Lamprecht
2018-11-26 13:55:02 UTC
Permalink
to avoid a failed login if a broken corosync config is setup

Signed-off-by: Thomas Lamprecht <***@proxmox.com>
---
PVE/API2/AccessControl.pm | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/PVE/API2/AccessControl.pm b/PVE/API2/AccessControl.pm
index 93f384a..7e6ad39 100644
--- a/PVE/API2/AccessControl.pm
+++ b/PVE/API2/AccessControl.pm
@@ -281,11 +281,14 @@ __PACKAGE__->register_method ({

if (PVE::Corosync::check_conf_exists(1)) {
if ($rpcenv->check($username, '/', ['Sys.Audit'], 1)) {
- my $conf = cfs_read_file('corosync.conf');
- my $totem = PVE::Corosync::totem_config($conf);
- if ($totem->{cluster_name}) {
- $res->{clustername} = $totem->{cluster_name};
- }
+ eval {
+ my $conf = cfs_read_file('corosync.conf');
+ my $totem = PVE::Corosync::totem_config($conf);
+ if ($totem->{cluster_name}) {
+ $res->{clustername} = $totem->{cluster_name};
+ }
+ };
+ warn "$@\n" if $@;
}
}
--
2.19.1
Dominik Csapak
2018-11-26 14:35:19 UTC
Permalink
Post by Thomas Lamprecht
to avoid a failed login if a broken corosync config is setup
---
PVE/API2/AccessControl.pm | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/PVE/API2/AccessControl.pm b/PVE/API2/AccessControl.pm
index 93f384a..7e6ad39 100644
--- a/PVE/API2/AccessControl.pm
+++ b/PVE/API2/AccessControl.pm
@@ -281,11 +281,14 @@ __PACKAGE__->register_method ({
if (PVE::Corosync::check_conf_exists(1)) {
if ($rpcenv->check($username, '/', ['Sys.Audit'], 1)) {
- my $conf = cfs_read_file('corosync.conf');
- my $totem = PVE::Corosync::totem_config($conf);
- if ($totem->{cluster_name}) {
- $res->{clustername} = $totem->{cluster_name};
- }
+ eval {
+ my $conf = cfs_read_file('corosync.conf');
+ my $totem = PVE::Corosync::totem_config($conf);
+ if ($totem->{cluster_name}) {
+ $res->{clustername} = $totem->{cluster_name};
+ }
+ };
}
}
Thomas Lamprecht
2018-11-26 14:52:01 UTC
Permalink
thanks for test/review! applied with your tag.
Post by Thomas Lamprecht
to avoid a failed login if a broken corosync config is setup
---
  PVE/API2/AccessControl.pm | 13 ++++++++-----
  1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/PVE/API2/AccessControl.pm b/PVE/API2/AccessControl.pm
index 93f384a..7e6ad39 100644
--- a/PVE/API2/AccessControl.pm
+++ b/PVE/API2/AccessControl.pm
@@ -281,11 +281,14 @@ __PACKAGE__->register_method ({
        if (PVE::Corosync::check_conf_exists(1)) {
          if ($rpcenv->check($username, '/', ['Sys.Audit'], 1)) {
-        my $conf = cfs_read_file('corosync.conf');
-        my $totem = PVE::Corosync::totem_config($conf);
-        if ($totem->{cluster_name}) {
-            $res->{clustername} = $totem->{cluster_name};
-        }
+        eval {
+            my $conf = cfs_read_file('corosync.conf');
+            my $totem = PVE::Corosync::totem_config($conf);
+            if ($totem->{cluster_name}) {
+            $res->{clustername} = $totem->{cluster_name};
+            }
+        };
          }
      }
 
Loading...