|
|
049c96 |
From a8e630258cafd1e93e85fd8ee7227583a28fb7cd Mon Sep 17 00:00:00 2001
|
|
|
049c96 |
From: Phil Sutter <psutter@redhat.com>
|
|
|
049c96 |
Date: Thu, 18 Feb 2016 15:31:08 +0100
|
|
|
049c96 |
Subject: [PATCH] batch: support quoted strings
|
|
|
049c96 |
|
|
|
049c96 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1272593
|
|
|
049c96 |
Upstream Status: iproute2.git commit 39e3d3836c138
|
|
|
049c96 |
|
|
|
049c96 |
commit 39e3d3836c1384506d0a76a496133c5361940770
|
|
|
049c96 |
Author: Christophe Gouault <christophe.gouault@6wind.com>
|
|
|
049c96 |
Date: Fri Oct 2 11:59:37 2015 +0200
|
|
|
049c96 |
|
|
|
049c96 |
batch: support quoted strings
|
|
|
049c96 |
|
|
|
049c96 |
Support quoting strings with " or ' in an iproute2 batch file.
|
|
|
049c96 |
|
|
|
049c96 |
Enables to configure empty crypto keys (for ESP-null) or keys with
|
|
|
049c96 |
spaces:
|
|
|
049c96 |
|
|
|
049c96 |
xfrm state add src 1.1.1.1 dst 2.2.2.2 proto ah spi 0x1 \
|
|
|
049c96 |
mode tunnel auth hmac(sha1) "r4ezR/@kd6'749f2 6zf$"
|
|
|
049c96 |
|
|
|
049c96 |
xfrm state add src 5.5.5.5 dst 2.2.2.2 proto esp spi 0x2 \
|
|
|
049c96 |
mode tunnel enc cipher_null ""
|
|
|
049c96 |
|
|
|
049c96 |
Signed-off-by: Christophe Gouault <christophe.gouault@6wind.com>
|
|
|
049c96 |
---
|
|
|
049c96 |
lib/utils.c | 21 ++++++++++++++++++++-
|
|
|
049c96 |
1 file changed, 20 insertions(+), 1 deletion(-)
|
|
|
049c96 |
|
|
|
049c96 |
diff --git a/lib/utils.c b/lib/utils.c
|
|
|
049c96 |
index 8c5cd46..1cd4fdd 100644
|
|
|
049c96 |
--- a/lib/utils.c
|
|
|
049c96 |
+++ b/lib/utils.c
|
|
|
049c96 |
@@ -907,12 +907,31 @@ int makeargs(char *line, char *argv[], int maxargs)
|
|
|
049c96 |
char *cp;
|
|
|
049c96 |
int argc = 0;
|
|
|
049c96 |
|
|
|
049c96 |
- for (cp = strtok(line, ws); cp; cp = strtok(NULL, ws)) {
|
|
|
049c96 |
+ for (cp = line + strspn(line, ws); *cp; cp += strspn(cp, ws)) {
|
|
|
049c96 |
if (argc >= (maxargs - 1)) {
|
|
|
049c96 |
fprintf(stderr, "Too many arguments to command\n");
|
|
|
049c96 |
exit(1);
|
|
|
049c96 |
}
|
|
|
049c96 |
+
|
|
|
049c96 |
+ /* word begins with quote */
|
|
|
049c96 |
+ if (*cp == '\'' || *cp == '"') {
|
|
|
049c96 |
+ char quote = *cp++;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ argv[argc++] = cp;
|
|
|
049c96 |
+ /* find ending quote */
|
|
|
049c96 |
+ cp = strchr(cp, quote);
|
|
|
049c96 |
+ if (cp == NULL) {
|
|
|
049c96 |
+ fprintf(stderr, "Unterminated quoted string\n");
|
|
|
049c96 |
+ exit(1);
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ *cp++ = 0;
|
|
|
049c96 |
+ continue;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
argv[argc++] = cp;
|
|
|
049c96 |
+ /* find end of word */
|
|
|
049c96 |
+ cp += strcspn(cp, ws);
|
|
|
049c96 |
+ *cp++ = 0;
|
|
|
049c96 |
}
|
|
|
049c96 |
argv[argc] = NULL;
|
|
|
049c96 |
|
|
|
049c96 |
--
|
|
|
049c96 |
1.8.3.1
|
|
|
049c96 |
|