item_updater: Return NotAllowed when attempting to clear FieldMode

Clearing FieldMode used to be a no-op, but by returning success, the
user wouldn't necessarily know that the PUT request did not take effect,
unless they checked the property value.
Changed it to return an error to let the user know that their request
did not take effect.

Tested: Verified an error is returned if the property is requested to
be cleared when it's already set, but no error is returned if it's
already cleared:

$ curl -b cjar -k -H "X-Auth-Token:$sha" -X PUT -d '{"data":"false"}' https://$bmc/xyz/openbmc_project/software/attr/FieldModeEnabled
{
  "data": null,
  "message": "200 OK",
  "status": "ok"
}
$ curl -b cjar -k -H "X-Auth-Token:$sha" -X PUT -d '{"data":"true"}' https://$bmc/xyz/openbmc_project/software/attr/FieldModeEnabled
{
  "data": null,
  "message": "200 OK",
  "status": "ok"
$ curl -b cjar -k -H "X-Auth-Token: $sha" -X PUT -d '{"data":"false"}' https://$bmc/xyz/openbmc_project/software/attr/FieldModeEnabled
{
  "data": {
    "description": "The specified property cannot be created"
  },
  "message": "Input/output error",
  "status": "error"
}

May 01 19:36:16 witherspoon phosphor-image-updater[1465]: The operation is not allowed

"MESSAGE" : "The operation is not allowed",
"REASON" : "FieldMode is not allowed to be cleared",
"SYSLOG_IDENTIFIER" : "phosphor-image-updater",

Change-Id: I1c0226c58956a28d903a85dfe98ac11daca4c7d4
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index 173ee29..21fb6e0 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -7,14 +7,15 @@
 #include "version.hpp"
 #include "xyz/openbmc_project/Software/Version/server.hpp"
 
-#include <elog-errors.hpp>
 #include <experimental/filesystem>
 #include <fstream>
+#include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
 #include <phosphor-logging/log.hpp>
 #include <queue>
 #include <set>
 #include <string>
+#include <xyz/openbmc_project/Common/error.hpp>
 #include <xyz/openbmc_project/Software/Image/error.hpp>
 
 namespace phosphor
@@ -32,6 +33,7 @@
 using namespace sdbusplus::xyz::openbmc_project::Software::Image::Error;
 using namespace phosphor::software::image;
 namespace fs = std::experimental::filesystem;
+using NotAllowed = sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
 
 void ItemUpdater::createActivation(sdbusplus::message::message& msg)
 {
@@ -458,6 +460,11 @@
 
         helper.enableFieldMode();
     }
+    else if (!value && control::FieldMode::fieldModeEnabled())
+    {
+        elog<NotAllowed>(xyz::openbmc_project::Common::NotAllowed::REASON(
+            "FieldMode is not allowed to be cleared"));
+    }
 
     return control::FieldMode::fieldModeEnabled();
 }