Add managing author package and put their infomation in manifest 72/84572/3
authorSungbae Yoo <sungbae.yoo@samsung.com>
Fri, 19 Aug 2016 09:38:56 +0000 (18:38 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Fri, 26 Aug 2016 05:27:44 +0000 (14:27 +0900)
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Change-Id: Ie0b3891958ad256258faf861a9d414564ee1117b

server/manager.cpp
server/server.cpp
server/server.h

index 5d6bc03..0bf09d0 100644 (file)
@@ -514,7 +514,9 @@ Manager::~Manager()
 
 int Manager::createKrate(const std::string& name, const std::string& manifest)
 {
-       auto provisioningWorker = [name, manifest, this]() {
+       const std::string& pkgId = context.getPeerPackageId();
+
+       auto provisioningWorker = [name, manifest, pkgId, this]() {
                std::unique_ptr<xml::Document> manifestFile;
 
                try {
@@ -537,10 +539,13 @@ int Manager::createKrate(const std::string& name, const std::string& manifest)
                        maskUserServices(user);
 
                        manifestFile.reset(xml::Parser::parseString(manifest));
+                       //write container author info
+                       if (!pkgId.empty()) {
+                               std::cout << manifestFile->getRootNode().getName() << std::endl;
+                               manifestFile->getRootNode().addNewChild("author").setContent(pkgId);
+                       }
                        manifestFile->write(CONF_PATH "/" + name + ".xml", "UTF-8", true);
 
-                       //TODO: write container owner info
-
                        //unlock the user
                        setKrateState(user.getUid(), 1);
 
@@ -564,6 +569,23 @@ int Manager::createKrate(const std::string& name, const std::string& manifest)
 
 int Manager::removeKrate(const std::string& name)
 {
+       const std::string& pkgId = context.getPeerPackageId();
+       std::unique_ptr<xml::Document> manifestFile;
+       bool canRemove = false;
+
+       manifestFile.reset(xml::Parser::parseFile(CONF_PATH "/" + name + ".xml"));
+       xml::Node::NodeList authors = manifestFile->evaluate("/manifest/author");
+       for (const xml::Node& author : authors) {
+               if (author.getContent() == pkgId) {
+                       canRemove = true;
+                       break;
+               }
+       }
+
+       if (!canRemove) {
+               return -1;
+       }
+
        if (lockKrate(name) != 0) {
                return -1;
        }
index 4db963d..227429f 100644 (file)
@@ -15,6 +15,7 @@
  */
 #include <functional>
 
+#include <aul.h>
 #include <cynara-client.h>
 #include <cynara-session.h>
 
@@ -65,6 +66,17 @@ void Server::terminate()
        service->stop();
 }
 
+const std::string Server::getPeerPackageId() const
+{
+       char pkgid[PATH_MAX];
+
+       if (aul_app_get_pkgid_bypid_for_uid(getPeerPid(), pkgid, sizeof(pkgid), getPeerUid()) != AUL_R_OK) {
+               return "";
+       }
+
+       return pkgid;
+}
+
 runtime::FileDescriptor Server::registerNotificationSubscriber(const std::string& name)
 {
        return runtime::FileDescriptor(service->subscribeNotification(name), true);
index 6d07bbe..a8a1850 100644 (file)
@@ -60,6 +60,8 @@ public:
                return service->getPeerPid();
        }
 
+       const std::string getPeerPackageId() const;
+
        void createNotification(const std::string& name)
        {
                service->createNotification(name);