]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/keychain.c
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / keychain.c
index aca3b9e2eab5ef26e67ee2c6aa3e022a00a0395f..601b44a4f1abe71b2da86129fdd6e736e9f098a3 100644 (file)
@@ -1,22 +1,22 @@
 /* key-chain for authentication.
  Copyright (C) 2000 Kunihiro Ishiguro
-
-This file is part of GNU Zebra.
-
-GNU Zebra is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published
-by the Free Software Foundation; either version 2, or (at your
-option) any later version.
-
-GNU Zebra is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Zebra; see the file COPYING.  If not, write to the
-Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
* Copyright (C) 2000 Kunihiro Ishiguro
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
 
 #include <zebra.h>
 
@@ -119,12 +119,12 @@ static void keychain_delete(struct keychain *keychain)
        if (keychain->name)
                XFREE(MTYPE_KEYCHAIN, keychain->name);
 
-       list_delete(keychain->key);
+       list_delete(&keychain->key);
        listnode_delete(keychain_list, keychain);
        keychain_free(keychain);
 }
 
-static struct key *key_lookup(const struct keychain *keychain, u_int32_t index)
+static struct key *key_lookup(const struct keychain *keychain, uint32_t index)
 {
        struct listnode *node;
        struct key *key;
@@ -137,7 +137,7 @@ static struct key *key_lookup(const struct keychain *keychain, u_int32_t index)
 }
 
 struct key *key_lookup_for_accept(const struct keychain *keychain,
-                                 u_int32_t index)
+                                 uint32_t index)
 {
        struct listnode *node;
        struct key *key;
@@ -172,7 +172,7 @@ struct key *key_match_for_accept(const struct keychain *keychain,
                if (key->accept.start == 0
                    || (key->accept.start <= now
                        && (key->accept.end >= now || key->accept.end == -1)))
-                       if (strncmp(key->string, auth_str, 16) == 0)
+                       if (key->string && (strncmp(key->string, auth_str, 16) == 0))
                                return key;
        }
        return NULL;
@@ -197,7 +197,7 @@ struct key *key_lookup_for_send(const struct keychain *keychain)
        return NULL;
 }
 
-static struct key *key_get(const struct keychain *keychain, u_int32_t index)
+static struct key *key_get(const struct keychain *keychain, uint32_t index)
 {
        struct key *key;
 
@@ -252,9 +252,8 @@ DEFUN (no_key_chain,
        keychain = keychain_lookup(argv[idx_word]->arg);
 
        if (!keychain) {
-               vty_out(vty, "Can't find keychain %s%s", argv[idx_word]->arg,
-                       VTY_NEWLINE);
-               return CMD_WARNING;
+               vty_out(vty, "Can't find keychain %s\n", argv[idx_word]->arg);
+               return CMD_WARNING_CONFIG_FAILED;
        }
 
        keychain_delete(keychain);
@@ -271,9 +270,9 @@ DEFUN_NOSH (key,
        int idx_number = 1;
        VTY_DECLVAR_CONTEXT(keychain, keychain);
        struct key *key;
-       u_int32_t index;
+       uint32_t index;
 
-       VTY_GET_INTEGER("key identifier", index, argv[idx_number]->arg);
+       index = strtoul(argv[idx_number]->arg, NULL, 10);
        key = key_get(keychain, index);
        VTY_PUSH_CONTEXT_SUB(KEYCHAIN_KEY_NODE, key);
 
@@ -290,13 +289,13 @@ DEFUN (no_key,
        int idx_number = 2;
        VTY_DECLVAR_CONTEXT(keychain, keychain);
        struct key *key;
-       u_int32_t index;
+       uint32_t index;
 
-       VTY_GET_INTEGER("key identifier", index, argv[idx_number]->arg);
+       index = strtoul(argv[idx_number]->arg, NULL, 10);
        key = key_lookup(keychain, index);
        if (!key) {
-               vty_out(vty, "Can't find key %d%s", index, VTY_NEWLINE);
-               return CMD_WARNING;
+               vty_out(vty, "Can't find key %d\n", index);
+               return CMD_WARNING_CONFIG_FAILED;
        }
 
        key_delete(keychain, key);
@@ -441,20 +440,19 @@ static int key_lifetime_set(struct vty *vty, struct key_range *krange,
 
        time_start = key_str2time(stime_str, sday_str, smonth_str, syear_str);
        if (time_start < 0) {
-               vty_out(vty, "Malformed time value%s", VTY_NEWLINE);
-               return CMD_WARNING;
+               vty_out(vty, "Malformed time value\n");
+               return CMD_WARNING_CONFIG_FAILED;
        }
        time_end = key_str2time(etime_str, eday_str, emonth_str, eyear_str);
 
        if (time_end < 0) {
-               vty_out(vty, "Malformed time value%s", VTY_NEWLINE);
-               return CMD_WARNING;
+               vty_out(vty, "Malformed time value\n");
+               return CMD_WARNING_CONFIG_FAILED;
        }
 
        if (time_end <= time_start) {
-               vty_out(vty, "Expire time is not later than start time%s",
-                       VTY_NEWLINE);
-               return CMD_WARNING;
+               vty_out(vty, "Expire time is not later than start time\n");
+               return CMD_WARNING_CONFIG_FAILED;
        }
 
        krange->start = time_start;
@@ -471,16 +469,16 @@ static int key_lifetime_duration_set(struct vty *vty, struct key_range *krange,
                                     const char *duration_str)
 {
        time_t time_start;
-       u_int32_t duration;
+       uint32_t duration;
 
        time_start = key_str2time(stime_str, sday_str, smonth_str, syear_str);
        if (time_start < 0) {
-               vty_out(vty, "Malformed time value%s", VTY_NEWLINE);
-               return CMD_WARNING;
+               vty_out(vty, "Malformed time value\n");
+               return CMD_WARNING_CONFIG_FAILED;
        }
        krange->start = time_start;
 
-       VTY_GET_INTEGER("duration", duration, duration_str);
+       duration = strtoul(duration_str, NULL, 10);
        krange->duration = 1;
        krange->end = time_start + duration;
 
@@ -497,8 +495,8 @@ static int key_lifetime_infinite_set(struct vty *vty, struct key_range *krange,
 
        time_start = key_str2time(stime_str, sday_str, smonth_str, syear_str);
        if (time_start < 0) {
-               vty_out(vty, "Malformed time value%s", VTY_NEWLINE);
-               return CMD_WARNING;
+               vty_out(vty, "Malformed time value\n");
+               return CMD_WARNING_CONFIG_FAILED;
        }
        krange->start = time_start;
 
@@ -635,7 +633,7 @@ DEFUN (accept_lifetime_infinite_day_month,
        "Day of th month to start\n"
        "Month of the year to start\n"
        "Year to start\n"
-       "Never expires")
+       "Never expires\n")
 {
        int idx_hhmmss = 1;
        int idx_number = 2;
@@ -656,7 +654,7 @@ DEFUN (accept_lifetime_infinite_month_day,
        "Month of the year to start\n"
        "Day of th month to start\n"
        "Year to start\n"
-       "Never expires")
+       "Never expires\n")
 {
        int idx_hhmmss = 1;
        int idx_month = 2;
@@ -717,6 +715,24 @@ DEFUN (accept_lifetime_duration_month_day,
                argv[idx_number_3]->arg);
 }
 
+DEFUN (no_accept_lifetime,
+       no_accept_lifetime_cmd,
+       "no accept-lifetime",
+       NO_STR
+       "Unset accept-lifetime\n")
+{
+       VTY_DECLVAR_CONTEXT_SUB(key, key);
+
+       if (key->accept.start)
+               key->accept.start = 0;
+       if (key->accept.end)
+               key->accept.end = 0;
+       if (key->accept.duration)
+               key->accept.duration = 0;
+
+       return CMD_SUCCESS;
+}
+
 DEFUN (send_lifetime_day_month_day_month,
        send_lifetime_day_month_day_month_cmd,
        "send-lifetime HH:MM:SS (1-31) MONTH (1993-2035) HH:MM:SS (1-31) MONTH (1993-2035)",
@@ -845,7 +861,7 @@ DEFUN (send_lifetime_infinite_day_month,
        "Day of th month to start\n"
        "Month of the year to start\n"
        "Year to start\n"
-       "Never expires")
+       "Never expires\n")
 {
        int idx_hhmmss = 1;
        int idx_number = 2;
@@ -866,7 +882,7 @@ DEFUN (send_lifetime_infinite_month_day,
        "Month of the year to start\n"
        "Day of th month to start\n"
        "Year to start\n"
-       "Never expires")
+       "Never expires\n")
 {
        int idx_hhmmss = 1;
        int idx_month = 2;
@@ -927,6 +943,24 @@ DEFUN (send_lifetime_duration_month_day,
                argv[idx_number_3]->arg);
 }
 
+DEFUN (no_send_lifetime,
+       no_send_lifetime_cmd,
+       "no send-lifetime",
+       NO_STR
+       "Unset send-lifetime\n")
+{
+       VTY_DECLVAR_CONTEXT_SUB(key, key);
+
+       if (key->send.start)
+               key->send.start = 0;
+       if (key->send.end)
+               key->send.end = 0;
+       if (key->send.duration)
+               key->send.duration = 0;
+
+       return CMD_SUCCESS;
+}
+
 static struct cmd_node keychain_node = {KEYCHAIN_NODE, "%s(config-keychain)# ",
                                        1};
 
@@ -954,14 +988,13 @@ static int keychain_config_write(struct vty *vty)
        char buf[BUFSIZ];
 
        for (ALL_LIST_ELEMENTS_RO(keychain_list, node, keychain)) {
-               vty_out(vty, "key chain %s%s", keychain->name, VTY_NEWLINE);
+               vty_out(vty, "key chain %s\n", keychain->name);
 
                for (ALL_LIST_ELEMENTS_RO(keychain->key, knode, key)) {
-                       vty_out(vty, " key %d%s", key->index, VTY_NEWLINE);
+                       vty_out(vty, " key %d\n", key->index);
 
                        if (key->string)
-                               vty_out(vty, "  key-string %s%s", key->string,
-                                       VTY_NEWLINE);
+                               vty_out(vty, "  key-string %s\n", key->string);
 
                        if (key->accept.start) {
                                keychain_strftime(buf, BUFSIZ,
@@ -979,7 +1012,7 @@ static int keychain_config_write(struct vty *vty)
                                                          &key->accept.end);
                                        vty_out(vty, " %s", buf);
                                }
-                               vty_out(vty, "%s", VTY_NEWLINE);
+                               vty_out(vty, "\n");
                        }
 
                        if (key->send.start) {
@@ -998,10 +1031,10 @@ static int keychain_config_write(struct vty *vty)
                                                          &key->send.end);
                                        vty_out(vty, " %s", buf);
                                }
-                               vty_out(vty, "%s", VTY_NEWLINE);
+                               vty_out(vty, "\n");
                        }
                }
-               vty_out(vty, "!%s", VTY_NEWLINE);
+               vty_out(vty, "!\n");
        }
 
        return 0;
@@ -1050,6 +1083,7 @@ void keychain_init()
                        &accept_lifetime_duration_day_month_cmd);
        install_element(KEYCHAIN_KEY_NODE,
                        &accept_lifetime_duration_month_day_cmd);
+       install_element(KEYCHAIN_KEY_NODE, &no_accept_lifetime_cmd);
 
        install_element(KEYCHAIN_KEY_NODE,
                        &send_lifetime_day_month_day_month_cmd);
@@ -1067,4 +1101,5 @@ void keychain_init()
                        &send_lifetime_duration_day_month_cmd);
        install_element(KEYCHAIN_KEY_NODE,
                        &send_lifetime_duration_month_day_cmd);
+       install_element(KEYCHAIN_KEY_NODE, &no_send_lifetime_cmd);
 }