From 4d39952ebe06e1767c3e5bf01a534a6d2510aa06 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Wed, 3 Jul 2013 15:32:01 +0100 Subject: [PATCH] Change signature of ACL filter functions Change the ACL filter functions to use a 'bool' return type instead of a tri-state 'int' return type. The callers of these functions don't want to distinguish 'auth failed' from other errors. Signed-off-by: Daniel P. Berrange --- src/rpc/gendispatch.pl | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index ff154741c3..fdf5a798f6 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -1762,8 +1762,21 @@ elsif ($mode eq "client") { push @argdecls, "unsigned int flags"; } + my $ret; + my $pass; + my $fail; + if ($action eq "Check") { + $ret = "bool"; + $pass = "true"; + $fail = "false"; + } else { + $ret = "int"; + $pass = "0"; + $fail = "-1"; + } + if ($mode eq "aclheader") { - print "extern int $apiname(" . join(", ", @argdecls) . ");\n"; + print "extern $ret $apiname(" . join(", ", @argdecls) . ");\n"; } else { my @argvars; push @argvars, "mgr"; @@ -1775,18 +1788,18 @@ elsif ($mode eq "client") { push @argvars, $arg; } - if ($action eq "Check") { - print "/* Returns: -1 on error, 0 on denied, 1 on allowed */\n"; - } else { - print "/* Returns: -1 on error (denied==error), 0 on allowed */\n"; - } - print "int $apiname(" . join(", ", @argdecls) . ")\n"; + print "/* Returns: $fail on error/denied, $pass on allowed */\n"; + print "$ret $apiname(" . join(", ", @argdecls) . ")\n"; print "{\n"; print " virAccessManagerPtr mgr;\n"; print " int rv;\n"; print "\n"; - print " if (!(mgr = virAccessManagerGetDefault()))\n"; - print " return -1;\n"; + print " if (!(mgr = virAccessManagerGetDefault())) {\n"; + if ($action eq "Check") { + print " virResetLastError();\n"; + } + print " return $fail;\n"; + print " }\n"; print "\n"; foreach my $acl (@acl) { @@ -1811,20 +1824,17 @@ elsif ($mode eq "client") { if ($action eq "Ensure") { print " if (rv == 0)\n"; print " virReportError(VIR_ERR_ACCESS_DENIED, NULL);\n"; - print " return -1;\n"; + print " return $fail;\n"; } else { - print " return rv;\n"; + print " virResetLastError();\n"; + print " return $fail;\n"; } print " }"; print "\n"; } print " virObjectUnref(mgr);\n"; - if ($action eq "Check") { - print " return 1;\n"; - } else { - print " return 0;\n"; - } + print " return $pass;\n"; print "}\n\n"; } } -- GitLab