cmdline: remove deprecated options
authorRobert Swiecki <robert@swiecki.net>
Fri, 1 Jun 2018 15:15:47 +0000 (17:15 +0200)
committerRobert Swiecki <robert@swiecki.net>
Fri, 1 Jun 2018 15:15:47 +0000 (17:15 +0200)
cmdline.cc
net.cc

index b08521b34693b062690a9dc1cacbe5bcbf75438b..50062ad0b19464173cc154def1b056ae98e82aa9 100644 (file)
@@ -151,16 +151,6 @@ struct custom_option custom_opts[] = {
     { { "macvlan_vs_nm", required_argument, NULL, 0x702 }, "Netmask of the 'vs' interface (e.g. \"255.255.255.0\")" },
     { { "macvlan_vs_gw", required_argument, NULL, 0x703 }, "Default GW for the 'vs' interface (e.g. \"192.168.0.1\")" },
 };
-
-struct custom_option deprecated_opts[] = {
-    // Compatibilty flags for MACVLAN.
-    // TODO(rswiecki): Remove this at some point.
-    { { "iface", required_argument, NULL, 'I' }, "Interface which will be cloned (MACVLAN) and put inside the subprocess' namespace as 'vs'" },
-    { { "iface_vs_ip", required_argument, NULL, 0x701 }, "IP of the 'vs' interface (e.g. \"192.168.0.1\")" },
-    { { "iface_vs_nm", required_argument, NULL, 0x702 }, "Netmask of the 'vs' interface (e.g. \"255.255.255.0\")" },
-    { { "iface_vs_gw", required_argument, NULL, 0x703 }, "Default GW for the 'vs' interface (e.g. \"192.168.0.1\")" },
-    { { "enable_clone_newcgroup", no_argument, NULL, 0x0408 }, "Use CLONE_NEWCGROUP (it's enabled by default now)" },
-};
 // clang-format on
 
 static const char* logYesNo(bool yes) {
@@ -184,18 +174,6 @@ static void cmdlineUsage(const char* pname) {
        for (size_t i = 0; i < ARR_SZ(custom_opts); i++) {
                cmdlineOptUsage(&custom_opts[i]);
        }
-       LOG_HELP_BOLD("\nDeprecated options:");
-       for (size_t i = 0; i < ARR_SZ(deprecated_opts); i++) {
-               cmdlineOptUsage(&deprecated_opts[i]);
-               // Find replacement flag.
-               for (size_t j = 0; j < ARR_SZ(custom_opts); j++) {
-                       if (custom_opts[j].opt.val == deprecated_opts[i].opt.val) {
-                               LOG_HELP_BOLD(
-                                   "\tDEPRECATED: Use %s instead.", custom_opts[j].opt.name);
-                               break;
-                       }
-               }
-       }
        LOG_HELP_BOLD("\n Examples: ");
        LOG_HELP(" Wait on a port 31337 for connections, and run /bin/sh");
        LOG_HELP_BOLD("  nsjail -Ml --port 31337 --chroot / -- /bin/sh -i");
@@ -229,7 +207,7 @@ void logParams(nsjconf_t* nsjconf) {
        LOG_I(
            "Jail parameters: hostname:'%s', chroot:'%s', process:'%s', bind:[%s]:%d, "
            "max_conns_per_ip:%u, time_limit:%" PRId64
-           " , personality:%#lx, daemonize:%s, clone_newnet:%s, "
+           ", personality:%#lx, daemonize:%s, clone_newnet:%s, "
            "clone_newuser:%s, clone_newns:%s, clone_newpid:%s, clone_newipc:%s, clonew_newuts:%s, "
            "clone_newcgroup:%s, keep_caps:%s, disable_no_new_privs:%s, max_cpus:%zu",
            nsjconf->hostname.c_str(), nsjconf->chroot.c_str(),
@@ -463,14 +441,11 @@ std::unique_ptr<nsjconf_t> parseArgs(int argc, char* argv[]) {
        std::vector<std::string> tmpfs_mounts;
 
        // Generate options array for getopt_long.
-       size_t options_length = ARR_SZ(custom_opts) + ARR_SZ(deprecated_opts) + 1;
+       size_t options_length = ARR_SZ(custom_opts) + 1;
        struct option opts[options_length];
        for (unsigned i = 0; i < ARR_SZ(custom_opts); i++) {
                opts[i] = custom_opts[i].opt;
        }
-       for (unsigned i = 0; i < ARR_SZ(deprecated_opts); i++) {
-               opts[ARR_SZ(custom_opts) + i] = deprecated_opts[i].opt;
-       }
        // Last, NULL option as a terminator.
        struct option terminator = {NULL, 0, NULL, 0};
        memcpy(&opts[options_length - 1].name, &terminator, sizeof(terminator));
diff --git a/net.cc b/net.cc
index 2969bb5efd353b25a441301f37dabac3f0b491d8..bf93576d99ba4c3ab940fa399c39a73c484c2929 100644 (file)
--- a/net.cc
+++ b/net.cc
@@ -353,8 +353,7 @@ static bool ifaceUp(const char* ifacename) {
                return false;
        }
 
-       struct ifreq ifr;
-       memset(&ifr, '\0', sizeof(ifr));
+       struct ifreq ifr = {};
        snprintf(ifr.ifr_name, IF_NAMESIZE, "%s", ifacename);
 
        if (ioctl(sock, SIOCGIFFLAGS, &ifr) == -1) {
@@ -377,17 +376,13 @@ static bool ifaceUp(const char* ifacename) {
 
 static bool ifaceConfig(const std::string& iface, const std::string& ip, const std::string& mask,
     const std::string& gw) {
-       struct ifreq ifr;
-       memset(&ifr, '\0', sizeof(ifr));
-       snprintf(ifr.ifr_name, IF_NAMESIZE, "%s", iface.c_str());
-       struct in_addr addr;
-
        int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
        if (sock == -1) {
                PLOG_E("socket(AF_INET, SOCK_STREAM, IPPROTO_IP)");
                return false;
        }
 
+       struct in_addr addr;
        if (inet_pton(AF_INET, ip.c_str(), &addr) != 1) {
                PLOG_E("Cannot convert '%s' into an IPv4 address", ip.c_str());
                close(sock);
@@ -399,6 +394,8 @@ static bool ifaceConfig(const std::string& iface, const std::string& ip, const s
                return true;
        }
 
+       struct ifreq ifr = {};
+       snprintf(ifr.ifr_name, IF_NAMESIZE, "%s", iface.c_str());
        struct sockaddr_in* sa = (struct sockaddr_in*)(&ifr.ifr_addr);
        sa->sin_family = AF_INET;
        sa->sin_addr = addr;
@@ -437,9 +434,7 @@ static bool ifaceConfig(const std::string& iface, const std::string& ip, const s
                return true;
        }
 
-       struct rtentry rt;
-       memset(&rt, '\0', sizeof(rt));
-
+       struct rtentry rt = {};
        struct sockaddr_in* sdest = (struct sockaddr_in*)(&rt.rt_dst);
        struct sockaddr_in* smask = (struct sockaddr_in*)(&rt.rt_genmask);
        struct sockaddr_in* sgate = (struct sockaddr_in*)(&rt.rt_gateway);