Bugs fixed
authorAndrey Zabolotnyi <a.zabolotnyi@samsung.com>
Tue, 18 Apr 2017 15:42:09 +0000 (18:42 +0300)
committerAndrey Zabolotnyi <a.zabolotnyi@samsung.com>
Tue, 18 Apr 2017 15:42:09 +0000 (18:42 +0300)
network-manager/agent/main.cpp
network-manager/nmlib/dpm/inc/dpm.h
network-manager/nmlib/dpm/src/dpm.cpp

index 4292fc2..367efe6 100644 (file)
@@ -34,6 +34,22 @@ bool prest[4];
 
 void pack_restrict(int mode, bool on)
 {
+       DPM::package_mode pmod;
+
+       if (mode == 0) pmod = DPM::PACKAGE_INSTALL;
+       if (mode == 1) pmod = DPM::PACKAGE_UNINSTALL;
+       if (mode == 2) pmod = DPM::PACKAGE_REINSTALL;
+       if (mode == 3) pmod = DPM::PACKAGE_MOVE;
+       if (mode == 4) pmod = DPM::PACKAGE_ALL;
+
+       dpm_error err;
+       err = dpm->set_package_restriction(pmod, on);
+
+       if (err == DPM_OK)
+               printf("%s\n", on ? "Restricted" : "Allowed");
+       else
+               printf("Error: %s\n", dpm->get_error_string(err));
+
        if (mode == 4)
        {
                prest[0] = on;
@@ -41,43 +57,60 @@ void pack_restrict(int mode, bool on)
                prest[2] = on;
                prest[3] = on;
 
-               if (on)
-                       printf("All restricted\n");
-               else
-                       printf("All allowed\n");
+//             if (on)
+//                     printf("All restricted\n");
+//             else
+//                     printf("All allowed\n");
        }
        else if (mode >= 0 && mode < 4)
        {
                prest[mode] = on;
 
-               if (mode == 0) printf("Package install ");
-               if (mode == 1) printf("Package uninstall ");
-               if (mode == 2) printf("Package reinstall ");
-               if (mode == 3) printf("Package move ");
-               printf("%s\n", on ? "restricted" : "allowed");
+//             if (mode == 0) printf("Package install ");
+//             if (mode == 1) printf("Package uninstall ");
+//             if (mode == 2) printf("Package reinstall ");
+//             if (mode == 3) printf("Package move ");
+//             printf("%s\n", on ? "restricted" : "allowed");
        }
 }
 
 void priv_list(const char *name, bool add)
 {
+       dpm_error err;
+
        if (add)
-               printf("Privelege <%s> added\n", name);
+               err = dpm->add_privilege_to_blacklist(name);
        else
-               printf("Privelege <%s> removed\n", name);
-}
+               err = dpm->remove_privilege_from_blacklist(name);
 
-//##################
+       if (err == DPM_OK)
+       {
+               if (add)
+                       printf("Privilege <%s> added\n", name);
+               else
+                       printf("Privilege <%s> removed\n", name);
+       }
+       else
+               printf("Error: %s\n", dpm->get_error_string(err));
+}
 
-void menu_package()
+void pack_state(char *st)
 {
-       char st[256];
-
        sprintf(st, " %s: %s\n %s: %s\n %s: %s\n %s: %s\n",
                "Package install", prest[0] ? "restricted" : "allowed",
                "Package uninstall", prest[1] ? "restricted" : "allowed",
                "Package reinstall", prest[2] ? "restricted" : "allowed",
                "Package move", prest[3] ? "restricted" : "allowed"
                );
+}
+
+//##################
+
+void menu_package()
+{
+       char st[256];
+
+       pack_state(st);
 
        BEGIN(st,
                " 1 - Package install restriction on\n"
@@ -101,7 +134,10 @@ void menu_package()
                else if (!strcmp(s, "8")) pack_restrict(3, false);
                else if (!strcmp(s, "9")) pack_restrict(4, true);
                else if (!strcmp(s, "0")) pack_restrict(4, false);
-               END
+               else printf("Wrong input\n");
+               pack_state(st);
+               printf("State:\n%s\n", st);
+       }
 }
 
 void menu_app()
@@ -149,7 +185,16 @@ void dev_bl(const char *mac, bool add)
 
 void uuid_bl(const char *uuid, bool add)
 {
-       printf("UUID %s %s\n", uuid, add ? "added" : "removed");
+       dpm_error err;
+       if (add)
+               err = dpm->bluetooth_add_uuid_to_blacklist(uuid);
+       else
+               err = dpm->bluetooth_remove_uuid_from_blacklist(uuid);
+
+       if (err == DPM_OK)
+               printf("UUID %s %s\n", uuid, add ? "added" : "removed");
+       else
+               printf("Error: %s\n", dpm->get_error_string(err));
 }
 
 bool device_restriction;
@@ -159,6 +204,14 @@ void menu_bt()
 {
        char st[256];
 
+       dpm_error err;
+       err = dpm->bluetooth_is_device_restricted(device_restriction);
+       if (err != DPM_OK)
+               printf("bluetooth_is_device_restricted() error: %s\n", dpm->get_error_string(err));
+       err = dpm->bluetooth_is_uuid_restricted(uuid_restriction);
+       if (err != DPM_OK)
+               printf("bluetooth_is_uuid_restricted() error: %s\n", dpm->get_error_string(err));
+
        sprintf(st, "Bluetooth restrictions:\n %s: %s\n %s: %s\n",
                "Device restriction", device_restriction ? "on" : "off",
                "UUID restriction", uuid_restriction ? "on" : "off"
@@ -373,7 +426,6 @@ void menu_restrict()
        static char items[1024];
        char *p = items;
        dpm_error err = DPM_OK;
-       bool allow;
 
        get_rst_state(st);
 
index 4ef36a5..c03c40b 100644 (file)
@@ -71,7 +71,8 @@ public:
                PACKAGE_INSTALL    , /**< Package install restriction */
                PACKAGE_UNINSTALL  , /**< Package uninstall restriction */
                PACKAGE_REINSTALL  , /**< Package reinstall restriction */
-               PACKAGE_MOVE         /**< Package move restriction */
+               PACKAGE_MOVE       , /**< Package move restriction */
+               PACKAGE_ALL       , /**< Package move restriction */
        };
 
        dpm_error set_package_restriction(package_mode mode, bool allow);
index 0baf50e..be40931 100644 (file)
@@ -271,6 +271,7 @@ dpm_error DPM::set_package_restriction(package_mode mode, bool allow)
        else if (mode == PACKAGE_UNINSTALL) m = DPM_PACKAGE_RESTRICTION_MODE_UNINSTALL;
        else if (mode == PACKAGE_REINSTALL) m = DPM_PACKAGE_RESTRICTION_MODE_REINSTALL;
        else if (mode == PACKAGE_MOVE) m = DPM_PACKAGE_RESTRICTION_MODE_MOVE;
+       else if (mode == PACKAGE_ALL) m = DPM_PACKAGE_RESTRICTION_MODE_ALL;
        else
                return DPM_INVALID_PARAMETER;