Basic support for User manager service

Basic support for User Manager service methods
are implemented.

Change-Id: Id42432ec6dd421b99971268add931dcd70876f7c
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
diff --git a/users.cpp b/users.cpp
new file mode 100644
index 0000000..c904916
--- /dev/null
+++ b/users.cpp
@@ -0,0 +1,146 @@
+/*
+// Copyright (c) 2018 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <xyz/openbmc_project/Common/error.hpp>
+#include <xyz/openbmc_project/User/Common/error.hpp>
+#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/elog-errors.hpp>
+#include "user_mgr.hpp"
+#include "users.hpp"
+#include "config.h"
+
+namespace phosphor
+{
+namespace user
+{
+
+using namespace phosphor::logging;
+using InsufficientPermission =
+    sdbusplus::xyz::openbmc_project::Common::Error::InsufficientPermission;
+using InternalFailure =
+    sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
+using InvalidArgument =
+    sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
+using NoResource =
+    sdbusplus::xyz::openbmc_project::User::Common::Error::NoResource;
+
+using Argument = xyz::openbmc_project::Common::InvalidArgument;
+
+/** @brief Constructs UserMgr object.
+ *
+ *  @param[in] bus  - sdbusplus handler
+ *  @param[in] path - D-Bus path
+ *  @param[in] groups - users group list
+ *  @param[in] priv - user privilege
+ *  @param[in] enabled - user enabled state
+ *  @param[in] parent - user manager - parent object
+ */
+Users::Users(sdbusplus::bus::bus &bus, const char *path,
+             std::vector<std::string> groups, std::string priv, bool enabled,
+             UserMgr &parent) :
+    UsersIface(bus, path, true),
+    DeleteIface(bus, path),
+    userName(std::experimental::filesystem::path(path).filename()),
+    manager(parent)
+{
+    UsersIface::userPrivilege(priv, true);
+    UsersIface::userGroups(groups, true);
+    UsersIface::userEnabled(enabled, true);
+    UsersIface::emit_object_added();
+}
+
+/** @brief delete user method.
+ *  This method deletes the user as requested
+ *
+ */
+void Users::delete_(void)
+{
+    manager.deleteUser(userName);
+}
+
+/** @brief update user privilege
+ *
+ *  @param[in] value - User privilege
+ */
+std::string Users::userPrivilege(std::string value)
+{
+    if (value == UsersIface::userPrivilege())
+    {
+        return value;
+    }
+    manager.updateGroupsAndPriv(userName, UsersIface::userGroups(), value);
+    return UsersIface::userPrivilege(value);
+}
+
+/** @brief list user privilege
+ *
+ */
+std::string Users::userPrivilege(void) const
+{
+    return UsersIface::userPrivilege();
+}
+
+/** @brief update user groups
+ *
+ *  @param[in] value - User groups
+ */
+std::vector<std::string> Users::userGroups(std::vector<std::string> value)
+{
+    if (value == UsersIface::userGroups())
+    {
+        return value;
+    }
+    std::sort(value.begin(), value.end());
+    manager.updateGroupsAndPriv(userName, value, UsersIface::userPrivilege());
+    return UsersIface::userGroups(value);
+}
+
+/** @brief list user groups
+ *
+ */
+std::vector<std::string> Users::userGroups(void) const
+{
+    return UsersIface::userGroups();
+}
+
+/** @brief lists user enabled state
+ *
+ */
+bool Users::userEnabled(void) const
+{
+    return UsersIface::userEnabled();
+}
+
+/** @brief update user enabled state
+ *
+ *  @param[in] value - bool value
+ */
+bool Users::userEnabled(bool value)
+{
+    if (value == UsersIface::userEnabled())
+    {
+        return value;
+    }
+    manager.userEnable(userName, value);
+    return UsersIface::userEnabled(value);
+}
+
+} // namespace user
+} // namespace phosphor