diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-26 14:34:39 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-26 14:34:39 +0000 |
commit | 0c9ca79b2eb820c3266e9117f3ba9179cbdc2ff1 (patch) | |
tree | 434cab0d8aa45a4edc2cf9bd91c89bf3f2d5061b /src/util/strings.c | |
parent | aeb922926c639ffdd992f96cd125e47bb0e2c301 (diff) | |
download | gnunet-0c9ca79b2eb820c3266e9117f3ba9179cbdc2ff1.tar.gz gnunet-0c9ca79b2eb820c3266e9117f3ba9179cbdc2ff1.zip |
-converting regular expressions of vpn/pt to non-binary format and adding proper policy parsing
Diffstat (limited to 'src/util/strings.c')
-rw-r--r-- | src/util/strings.c | 220 |
1 files changed, 166 insertions, 54 deletions
diff --git a/src/util/strings.c b/src/util/strings.c index c50669e62..2fc647f7b 100644 --- a/src/util/strings.c +++ b/src/util/strings.c | |||
@@ -993,22 +993,24 @@ GNUNET_STRINGS_parse_uri (const char *path, char **scheme_part, | |||
993 | 993 | ||
994 | 994 | ||
995 | /** | 995 | /** |
996 | * Check whether 'filename' is absolute or not, and if it's an URI | 996 | * Check whether @a filename is absolute or not, and if it's an URI |
997 | * | 997 | * |
998 | * @param filename filename to check | 998 | * @param filename filename to check |
999 | * @param can_be_uri GNUNET_YES to check for being URI, GNUNET_NO - to | 999 | * @param can_be_uri #GNUNET_YES to check for being URI, #GNUNET_NO - to |
1000 | * assume it's not URI | 1000 | * assume it's not URI |
1001 | * @param r_is_uri a pointer to an int that is set to GNUNET_YES if 'filename' | 1001 | * @param r_is_uri a pointer to an int that is set to #GNUNET_YES if @a filename |
1002 | * is URI and to GNUNET_NO otherwise. Can be NULL. If 'can_be_uri' is | 1002 | * is URI and to #GNUNET_NO otherwise. Can be NULL. If @a can_be_uri is |
1003 | * not GNUNET_YES, *r_is_uri is set to GNUNET_NO. | 1003 | * not #GNUNET_YES, `* r_is_uri` is set to #GNUNET_NO. |
1004 | * @param r_uri_scheme a pointer to a char * that is set to a pointer to URI scheme. | 1004 | * @param r_uri_scheme a pointer to a char * that is set to a pointer to URI scheme. |
1005 | * The string is allocated by the function, and should be freed with | 1005 | * The string is allocated by the function, and should be freed with |
1006 | * GNUNET_free (). Can be NULL. | 1006 | * GNUNET_free(). Can be NULL. |
1007 | * @return GNUNET_YES if 'filename' is absolute, GNUNET_NO otherwise. | 1007 | * @return #GNUNET_YES if @a filename is absolute, #GNUNET_NO otherwise. |
1008 | */ | 1008 | */ |
1009 | int | 1009 | int |
1010 | GNUNET_STRINGS_path_is_absolute (const char *filename, int can_be_uri, | 1010 | GNUNET_STRINGS_path_is_absolute (const char *filename, |
1011 | int *r_is_uri, char **r_uri_scheme) | 1011 | int can_be_uri, |
1012 | int *r_is_uri, | ||
1013 | char **r_uri_scheme) | ||
1012 | { | 1014 | { |
1013 | #if WINDOWS | 1015 | #if WINDOWS |
1014 | size_t len; | 1016 | size_t len; |
@@ -1067,12 +1069,12 @@ GNUNET_STRINGS_path_is_absolute (const char *filename, int can_be_uri, | |||
1067 | 1069 | ||
1068 | 1070 | ||
1069 | /** | 1071 | /** |
1070 | * Perform 'checks' on 'filename' | 1072 | * Perform @a checks on @a filename. |
1071 | * | 1073 | * |
1072 | * @param filename file to check | 1074 | * @param filename file to check |
1073 | * @param checks checks to perform | 1075 | * @param checks checks to perform |
1074 | * @return GNUNET_YES if all checks pass, GNUNET_NO if at least one of them | 1076 | * @return #GNUNET_YES if all checks pass, #GNUNET_NO if at least one of them |
1075 | * fails, GNUNET_SYSERR when a check can't be performed | 1077 | * fails, #GNUNET_SYSERR when a check can't be performed |
1076 | */ | 1078 | */ |
1077 | int | 1079 | int |
1078 | GNUNET_STRINGS_check_filename (const char *filename, | 1080 | GNUNET_STRINGS_check_filename (const char *filename, |
@@ -1111,11 +1113,12 @@ GNUNET_STRINGS_check_filename (const char *filename, | |||
1111 | * The string is expected to have the format "[ABCD::01]:80". | 1113 | * The string is expected to have the format "[ABCD::01]:80". |
1112 | * | 1114 | * |
1113 | * @param zt_addr 0-terminated string. May be mangled by the function. | 1115 | * @param zt_addr 0-terminated string. May be mangled by the function. |
1114 | * @param addrlen length of zt_addr (not counting 0-terminator). | 1116 | * @param addrlen length of @a zt_addr (not counting 0-terminator). |
1115 | * @param r_buf a buffer to fill. Initially gets filled with zeroes, | 1117 | * @param r_buf a buffer to fill. Initially gets filled with zeroes, |
1116 | * then its sin6_port, sin6_family and sin6_addr are set appropriately. | 1118 | * then its sin6_port, sin6_family and sin6_addr are set appropriately. |
1117 | * @return GNUNET_OK if conversion succeded. GNUNET_SYSERR otherwise, in which | 1119 | * @return #GNUNET_OK if conversion succeded. |
1118 | * case the contents of r_buf are undefined. | 1120 | * #GNUNET_SYSERR otherwise, in which |
1121 | * case the contents of @a r_buf are undefined. | ||
1119 | */ | 1122 | */ |
1120 | int | 1123 | int |
1121 | GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, | 1124 | GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, |
@@ -1182,10 +1185,11 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, | |||
1182 | * The string is expected to have the format "1.2.3.4:80". | 1185 | * The string is expected to have the format "1.2.3.4:80". |
1183 | * | 1186 | * |
1184 | * @param zt_addr 0-terminated string. May be mangled by the function. | 1187 | * @param zt_addr 0-terminated string. May be mangled by the function. |
1185 | * @param addrlen length of zt_addr (not counting 0-terminator). | 1188 | * @param addrlen length of @a zt_addr (not counting 0-terminator). |
1186 | * @param r_buf a buffer to fill. | 1189 | * @param r_buf a buffer to fill. |
1187 | * @return GNUNET_OK if conversion succeded. GNUNET_SYSERR otherwise, in which case | 1190 | * @return #GNUNET_OK if conversion succeded. |
1188 | * the contents of r_buf are undefined. | 1191 | * #GNUNET_SYSERR otherwise, in which case |
1192 | * the contents of @a r_buf are undefined. | ||
1189 | */ | 1193 | */ |
1190 | int | 1194 | int |
1191 | GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, uint16_t addrlen, | 1195 | GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, uint16_t addrlen, |
@@ -1217,14 +1221,14 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, uint16_t addrlen, | |||
1217 | 1221 | ||
1218 | 1222 | ||
1219 | /** | 1223 | /** |
1220 | * Tries to convert 'addr' string to an IP (v4 or v6) address. | 1224 | * Tries to convert @a addr string to an IP (v4 or v6) address. |
1221 | * Will automatically decide whether to treat 'addr' as v4 or v6 address. | 1225 | * Will automatically decide whether to treat 'addr' as v4 or v6 address. |
1222 | * | 1226 | * |
1223 | * @param addr a string, may not be 0-terminated. | 1227 | * @param addr a string, may not be 0-terminated. |
1224 | * @param addrlen number of bytes in addr (if addr is 0-terminated, | 1228 | * @param addrlen number of bytes in @a addr (if addr is 0-terminated, |
1225 | * 0-terminator should not be counted towards addrlen). | 1229 | * 0-terminator should not be counted towards addrlen). |
1226 | * @param r_buf a buffer to fill. | 1230 | * @param r_buf a buffer to fill. |
1227 | * @return GNUNET_OK if conversion succeded. GNUNET_SYSERR otherwise, in which | 1231 | * @return #GNUNET_OK if conversion succeded. GNUNET_SYSERR otherwise, in which |
1228 | * case the contents of r_buf are undefined. | 1232 | * case the contents of r_buf are undefined. |
1229 | */ | 1233 | */ |
1230 | int | 1234 | int |
@@ -1233,8 +1237,12 @@ GNUNET_STRINGS_to_address_ip (const char *addr, | |||
1233 | struct sockaddr_storage *r_buf) | 1237 | struct sockaddr_storage *r_buf) |
1234 | { | 1238 | { |
1235 | if (addr[0] == '[') | 1239 | if (addr[0] == '[') |
1236 | return GNUNET_STRINGS_to_address_ipv6 (addr, addrlen, (struct sockaddr_in6 *) r_buf); | 1240 | return GNUNET_STRINGS_to_address_ipv6 (addr, |
1237 | return GNUNET_STRINGS_to_address_ipv4 (addr, addrlen, (struct sockaddr_in *) r_buf); | 1241 | addrlen, |
1242 | (struct sockaddr_in6 *) r_buf); | ||
1243 | return GNUNET_STRINGS_to_address_ipv4 (addr, | ||
1244 | addrlen, | ||
1245 | (struct sockaddr_in *) r_buf); | ||
1238 | } | 1246 | } |
1239 | 1247 | ||
1240 | 1248 | ||
@@ -1243,7 +1251,8 @@ GNUNET_STRINGS_to_address_ip (const char *addr, | |||
1243 | * freed with a single call to GNUNET_free (); | 1251 | * freed with a single call to GNUNET_free (); |
1244 | */ | 1252 | */ |
1245 | static char *const * | 1253 | static char *const * |
1246 | _make_continuous_arg_copy (int argc, char *const *argv) | 1254 | _make_continuous_arg_copy (int argc, |
1255 | char *const *argv) | ||
1247 | { | 1256 | { |
1248 | size_t argvsize = 0; | 1257 | size_t argvsize = 0; |
1249 | int i; | 1258 | int i; |
@@ -1276,7 +1285,7 @@ _make_continuous_arg_copy (int argc, char *const *argv) | |||
1276 | * @param argv argv (as given by main()) | 1285 | * @param argv argv (as given by main()) |
1277 | * @param u8argc a location to store new argc in (though it's th same as argc) | 1286 | * @param u8argc a location to store new argc in (though it's th same as argc) |
1278 | * @param u8argv a location to store new argv in | 1287 | * @param u8argv a location to store new argv in |
1279 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | 1288 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1280 | */ | 1289 | */ |
1281 | int | 1290 | int |
1282 | GNUNET_STRINGS_get_utf8_args (int argc, char *const *argv, int *u8argc, char *const **u8argv) | 1291 | GNUNET_STRINGS_get_utf8_args (int argc, char *const *argv, int *u8argc, char *const **u8argv) |
@@ -1330,18 +1339,65 @@ GNUNET_STRINGS_get_utf8_args (int argc, char *const *argv, int *u8argc, char *co | |||
1330 | 1339 | ||
1331 | 1340 | ||
1332 | /** | 1341 | /** |
1342 | * Parse the given port policy. The format is | ||
1343 | * "[!]SPORT[-DPORT]". | ||
1344 | * | ||
1345 | * @param port_policy string to parse | ||
1346 | * @param pp policy to fill in | ||
1347 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the | ||
1348 | * @a port_policy is malformed | ||
1349 | */ | ||
1350 | static int | ||
1351 | parse_port_policy (const char *port_policy, | ||
1352 | struct GNUNET_STRINGS_PortPolicy *pp) | ||
1353 | { | ||
1354 | const char *pos; | ||
1355 | int s; | ||
1356 | int e; | ||
1357 | |||
1358 | pos = port_policy; | ||
1359 | if ('!' == *pos) | ||
1360 | { | ||
1361 | pp->negate_portrange = GNUNET_YES; | ||
1362 | pos++; | ||
1363 | } | ||
1364 | if (2 == sscanf (pos, | ||
1365 | "%u-%u", | ||
1366 | &s, &e)) | ||
1367 | { | ||
1368 | pp->start_port = (uint16_t) s; | ||
1369 | pp->end_port = (uint16_t) e; | ||
1370 | return GNUNET_OK; | ||
1371 | } | ||
1372 | if (1 == sscanf (pos, | ||
1373 | "%u", | ||
1374 | &s)) | ||
1375 | { | ||
1376 | pp->start_port = (uint16_t) s; | ||
1377 | pp->end_port = (uint16_t) s; | ||
1378 | return GNUNET_OK; | ||
1379 | } | ||
1380 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1381 | _("Malformed port policy `%s'\n"), | ||
1382 | port_policy); | ||
1383 | return GNUNET_SYSERR; | ||
1384 | } | ||
1385 | |||
1386 | |||
1387 | /** | ||
1333 | * Parse an IPv4 network policy. The argument specifies a list of | 1388 | * Parse an IPv4 network policy. The argument specifies a list of |
1334 | * subnets. The format is <tt>[network/netmask;]*</tt> (no whitespace, | 1389 | * subnets. The format is |
1335 | * must be terminated with a semicolon). The network must be given in | 1390 | * <tt>(network[/netmask][:SPORT[-DPORT]];)*</tt> (no whitespace, must |
1391 | * be terminated with a semicolon). The network must be given in | ||
1336 | * dotted-decimal notation. The netmask can be given in CIDR notation | 1392 | * dotted-decimal notation. The netmask can be given in CIDR notation |
1337 | * (/16) or in dotted-decimal (/255.255.0.0). | 1393 | * (/16) or in dotted-decimal (/255.255.0.0). |
1338 | * | 1394 | * |
1339 | * @param routeList a string specifying the IPv4 subnets | 1395 | * @param routeListX a string specifying the IPv4 subnets |
1340 | * @return the converted list, terminated with all zeros; | 1396 | * @return the converted list, terminated with all zeros; |
1341 | * NULL if the synatx is flawed | 1397 | * NULL if the synatx is flawed |
1342 | */ | 1398 | */ |
1343 | struct GNUNET_STRINGS_IPv4NetworkPolicy * | 1399 | struct GNUNET_STRINGS_IPv4NetworkPolicy * |
1344 | GNUNET_STRINGS_parse_ipv4_policy (const char *routeList) | 1400 | GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX) |
1345 | { | 1401 | { |
1346 | unsigned int count; | 1402 | unsigned int count; |
1347 | unsigned int i; | 1403 | unsigned int i; |
@@ -1352,12 +1408,16 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeList) | |||
1352 | unsigned int temps[8]; | 1408 | unsigned int temps[8]; |
1353 | int slash; | 1409 | int slash; |
1354 | struct GNUNET_STRINGS_IPv4NetworkPolicy *result; | 1410 | struct GNUNET_STRINGS_IPv4NetworkPolicy *result; |
1411 | int colon; | ||
1412 | int end; | ||
1413 | char *routeList; | ||
1355 | 1414 | ||
1356 | if (NULL == routeList) | 1415 | if (NULL == routeListX) |
1357 | return NULL; | 1416 | return NULL; |
1358 | len = strlen (routeList); | 1417 | len = strlen (routeListX); |
1359 | if (0 == len) | 1418 | if (0 == len) |
1360 | return NULL; | 1419 | return NULL; |
1420 | routeList = GNUNET_strdup (routeListX); | ||
1361 | count = 0; | 1421 | count = 0; |
1362 | for (i = 0; i < len; i++) | 1422 | for (i = 0; i < len; i++) |
1363 | if (routeList[i] == ';') | 1423 | if (routeList[i] == ';') |
@@ -1367,18 +1427,45 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeList) | |||
1367 | pos = 0; | 1427 | pos = 0; |
1368 | while (i < count) | 1428 | while (i < count) |
1369 | { | 1429 | { |
1430 | for (colon = pos; ':' != routeList[colon]; colon++) | ||
1431 | if ( (';' == routeList[colon]) || | ||
1432 | ('\0' == routeList[colon]) ) | ||
1433 | break; | ||
1434 | end = colon; | ||
1435 | for (end = colon; ';' != routeList[end]; end++) | ||
1436 | if ('\0' == routeList[end]) | ||
1437 | break; | ||
1438 | if ('\0' == routeList[end]) | ||
1439 | break; | ||
1440 | routeList[end] = '\0'; | ||
1441 | if (':' == routeList[colon]) | ||
1442 | { | ||
1443 | routeList[colon] = '\0'; | ||
1444 | if (GNUNET_OK != parse_port_policy (&routeList[colon + 1], | ||
1445 | &result[i].pp)) | ||
1446 | break; | ||
1447 | } | ||
1370 | cnt = | 1448 | cnt = |
1371 | SSCANF (&routeList[pos], "%u.%u.%u.%u/%u.%u.%u.%u;", &temps[0], | 1449 | SSCANF (&routeList[pos], |
1372 | &temps[1], &temps[2], &temps[3], &temps[4], &temps[5], | 1450 | "%u.%u.%u.%u/%u.%u.%u.%u", |
1373 | &temps[6], &temps[7]); | 1451 | &temps[0], |
1452 | &temps[1], | ||
1453 | &temps[2], | ||
1454 | &temps[3], | ||
1455 | &temps[4], | ||
1456 | &temps[5], | ||
1457 | &temps[6], | ||
1458 | &temps[7]); | ||
1374 | if (8 == cnt) | 1459 | if (8 == cnt) |
1375 | { | 1460 | { |
1376 | for (j = 0; j < 8; j++) | 1461 | for (j = 0; j < 8; j++) |
1377 | if (temps[j] > 0xFF) | 1462 | if (temps[j] > 0xFF) |
1378 | { | 1463 | { |
1379 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"), | 1464 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1465 | _("Invalid format for IP: `%s'\n"), | ||
1380 | &routeList[pos]); | 1466 | &routeList[pos]); |
1381 | GNUNET_free (result); | 1467 | GNUNET_free (result); |
1468 | GNUNET_free (routeList); | ||
1382 | return NULL; | 1469 | return NULL; |
1383 | } | 1470 | } |
1384 | result[i].network.s_addr = | 1471 | result[i].network.s_addr = |
@@ -1387,24 +1474,29 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeList) | |||
1387 | result[i].netmask.s_addr = | 1474 | result[i].netmask.s_addr = |
1388 | htonl ((temps[4] << 24) + (temps[5] << 16) + (temps[6] << 8) + | 1475 | htonl ((temps[4] << 24) + (temps[5] << 16) + (temps[6] << 8) + |
1389 | temps[7]); | 1476 | temps[7]); |
1390 | while (routeList[pos] != ';') | 1477 | pos = end + 1; |
1391 | pos++; | ||
1392 | pos++; | ||
1393 | i++; | 1478 | i++; |
1394 | continue; | 1479 | continue; |
1395 | } | 1480 | } |
1396 | /* try second notation */ | 1481 | /* try second notation */ |
1397 | cnt = | 1482 | cnt = |
1398 | SSCANF (&routeList[pos], "%u.%u.%u.%u/%u;", &temps[0], &temps[1], | 1483 | SSCANF (&routeList[pos], |
1399 | &temps[2], &temps[3], &slash); | 1484 | "%u.%u.%u.%u/%u", |
1485 | &temps[0], | ||
1486 | &temps[1], | ||
1487 | &temps[2], | ||
1488 | &temps[3], | ||
1489 | &slash); | ||
1400 | if (5 == cnt) | 1490 | if (5 == cnt) |
1401 | { | 1491 | { |
1402 | for (j = 0; j < 4; j++) | 1492 | for (j = 0; j < 4; j++) |
1403 | if (temps[j] > 0xFF) | 1493 | if (temps[j] > 0xFF) |
1404 | { | 1494 | { |
1405 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"), | 1495 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1496 | _("Invalid format for IP: `%s'\n"), | ||
1406 | &routeList[pos]); | 1497 | &routeList[pos]); |
1407 | GNUNET_free (result); | 1498 | GNUNET_free (result); |
1499 | GNUNET_free (routeList); | ||
1408 | return NULL; | 1500 | return NULL; |
1409 | } | 1501 | } |
1410 | result[i].network.s_addr = | 1502 | result[i].network.s_addr = |
@@ -1420,9 +1512,7 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeList) | |||
1420 | slash--; | 1512 | slash--; |
1421 | } | 1513 | } |
1422 | result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); | 1514 | result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); |
1423 | while (';' != routeList[pos]) | 1515 | pos = end + 1; |
1424 | pos++; | ||
1425 | pos++; | ||
1426 | i++; | 1516 | i++; |
1427 | continue; | 1517 | continue; |
1428 | } | 1518 | } |
@@ -1432,6 +1522,7 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeList) | |||
1432 | _("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."), | 1522 | _("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."), |
1433 | slash); | 1523 | slash); |
1434 | GNUNET_free (result); | 1524 | GNUNET_free (result); |
1525 | GNUNET_free (routeList); | ||
1435 | return NULL; /* error */ | 1526 | return NULL; /* error */ |
1436 | } | 1527 | } |
1437 | } | 1528 | } |
@@ -1439,7 +1530,7 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeList) | |||
1439 | slash = 32; | 1530 | slash = 32; |
1440 | cnt = | 1531 | cnt = |
1441 | SSCANF (&routeList[pos], | 1532 | SSCANF (&routeList[pos], |
1442 | "%u.%u.%u.%u;", | 1533 | "%u.%u.%u.%u", |
1443 | &temps[0], | 1534 | &temps[0], |
1444 | &temps[1], | 1535 | &temps[1], |
1445 | &temps[2], | 1536 | &temps[2], |
@@ -1453,6 +1544,7 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeList) | |||
1453 | _("Invalid format for IP: `%s'\n"), | 1544 | _("Invalid format for IP: `%s'\n"), |
1454 | &routeList[pos]); | 1545 | &routeList[pos]); |
1455 | GNUNET_free (result); | 1546 | GNUNET_free (result); |
1547 | GNUNET_free (routeList); | ||
1456 | return NULL; | 1548 | return NULL; |
1457 | } | 1549 | } |
1458 | result[i].network.s_addr = | 1550 | result[i].network.s_addr = |
@@ -1465,9 +1557,7 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeList) | |||
1465 | slash--; | 1557 | slash--; |
1466 | } | 1558 | } |
1467 | result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); | 1559 | result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); |
1468 | while (routeList[pos] != ';') | 1560 | pos = end + 1; |
1469 | pos++; | ||
1470 | pos++; | ||
1471 | i++; | 1561 | i++; |
1472 | continue; | 1562 | continue; |
1473 | } | 1563 | } |
@@ -1475,6 +1565,7 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeList) | |||
1475 | _("Invalid format for IP: `%s'\n"), | 1565 | _("Invalid format for IP: `%s'\n"), |
1476 | &routeList[pos]); | 1566 | &routeList[pos]); |
1477 | GNUNET_free (result); | 1567 | GNUNET_free (result); |
1568 | GNUNET_free (routeList); | ||
1478 | return NULL; /* error */ | 1569 | return NULL; /* error */ |
1479 | } | 1570 | } |
1480 | if (pos < strlen (routeList)) | 1571 | if (pos < strlen (routeList)) |
@@ -1483,18 +1574,21 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeList) | |||
1483 | _("Invalid format for IP: `%s'\n"), | 1574 | _("Invalid format for IP: `%s'\n"), |
1484 | &routeList[pos]); | 1575 | &routeList[pos]); |
1485 | GNUNET_free (result); | 1576 | GNUNET_free (result); |
1577 | GNUNET_free (routeList); | ||
1486 | return NULL; /* oops */ | 1578 | return NULL; /* oops */ |
1487 | } | 1579 | } |
1580 | GNUNET_free (routeList); | ||
1488 | return result; /* ok */ | 1581 | return result; /* ok */ |
1489 | } | 1582 | } |
1490 | 1583 | ||
1491 | 1584 | ||
1492 | /** | 1585 | /** |
1493 | * Parse an IPv6 network policy. The argument specifies a list of | 1586 | * Parse an IPv6 network policy. The argument specifies a list of |
1494 | * subnets. The format is <tt>[network/netmask;]*</tt> (no whitespace, | 1587 | * subnets. The format is <tt>(network[/netmask[:SPORT[-DPORT]]];)*</tt> |
1495 | * must be terminated with a semicolon). The network must be given in | 1588 | * (no whitespace, must be terminated with a semicolon). The network |
1496 | * colon-hex notation. The netmask must be given in CIDR notation | 1589 | * must be given in colon-hex notation. The netmask must be given in |
1497 | * (/16) or can be omitted to specify a single host. | 1590 | * CIDR notation (/16) or can be omitted to specify a single host. |
1591 | * Note that the netmask is mandatory if ports are specified. | ||
1498 | * | 1592 | * |
1499 | * @param routeListX a string specifying the policy | 1593 | * @param routeListX a string specifying the policy |
1500 | * @return the converted list, 0-terminated, NULL if the synatx is flawed | 1594 | * @return the converted list, 0-terminated, NULL if the synatx is flawed |
@@ -1514,6 +1608,7 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX) | |||
1514 | unsigned int bits; | 1608 | unsigned int bits; |
1515 | unsigned int off; | 1609 | unsigned int off; |
1516 | int save; | 1610 | int save; |
1611 | int colon; | ||
1517 | 1612 | ||
1518 | if (NULL == routeListX) | 1613 | if (NULL == routeListX) |
1519 | return NULL; | 1614 | return NULL; |
@@ -1545,19 +1640,36 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX) | |||
1545 | slash = pos; | 1640 | slash = pos; |
1546 | while ((slash >= start) && (routeList[slash] != '/')) | 1641 | while ((slash >= start) && (routeList[slash] != '/')) |
1547 | slash--; | 1642 | slash--; |
1643 | |||
1548 | if (slash < start) | 1644 | if (slash < start) |
1549 | { | 1645 | { |
1550 | memset (&result[i].netmask, 0xFF, sizeof (struct in6_addr)); | 1646 | memset (&result[i].netmask, |
1647 | 0xFF, | ||
1648 | sizeof (struct in6_addr)); | ||
1551 | slash = pos; | 1649 | slash = pos; |
1552 | } | 1650 | } |
1553 | else | 1651 | else |
1554 | { | 1652 | { |
1555 | routeList[pos] = '\0'; | 1653 | routeList[pos] = '\0'; |
1654 | for (colon = pos; ':' != routeList[colon]; colon--) | ||
1655 | if ('/' == routeList[colon]) | ||
1656 | break; | ||
1657 | if (':' == routeList[colon]) | ||
1658 | { | ||
1659 | routeList[colon] = '\0'; | ||
1660 | if (GNUNET_OK != parse_port_policy (&routeList[colon + 1], | ||
1661 | &result[i].pp)) | ||
1662 | { | ||
1663 | GNUNET_free (result); | ||
1664 | GNUNET_free (routeList); | ||
1665 | return NULL; | ||
1666 | } | ||
1667 | } | ||
1556 | ret = inet_pton (AF_INET6, &routeList[slash + 1], &result[i].netmask); | 1668 | ret = inet_pton (AF_INET6, &routeList[slash + 1], &result[i].netmask); |
1557 | if (ret <= 0) | 1669 | if (ret <= 0) |
1558 | { | 1670 | { |
1559 | save = errno; | 1671 | save = errno; |
1560 | if ((1 != SSCANF (&routeList[slash + 1], "%u", &bits)) || (bits >= 128)) | 1672 | if ((1 != SSCANF (&routeList[slash + 1], "%u", &bits)) || (bits > 128)) |
1561 | { | 1673 | { |
1562 | if (0 == ret) | 1674 | if (0 == ret) |
1563 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1675 | LOG (GNUNET_ERROR_TYPE_ERROR, |