diff -Nru ifupdown-0.6.8ubuntu9/addrfam.c ifupdown-0.6.8ubuntu10/addrfam.c --- ifupdown-0.6.8ubuntu9/addrfam.c 2008-06-21 23:30:44.000000000 +0100 +++ ifupdown-0.6.8ubuntu10/addrfam.c 2008-10-11 13:34:51.000000000 +0100 @@ -1,23 +1,23 @@ -#line 450 "ifupdown.nw" +#line 451 "ifupdown.nw" #include #include "header.h" -#line 3904 "ifupdown.nw" +#line 3937 "ifupdown.nw" extern address_family addr_inet; -#line 4096 "ifupdown.nw" +#line 4129 "ifupdown.nw" extern address_family addr_inet6; -#line 4179 "ifupdown.nw" +#line 4212 "ifupdown.nw" extern address_family addr_ipx; -#line 455 "ifupdown.nw" +#line 456 "ifupdown.nw" address_family *addr_fams[] = { -#line 3908 "ifupdown.nw" +#line 3941 "ifupdown.nw" &addr_inet, -#line 4100 "ifupdown.nw" +#line 4133 "ifupdown.nw" &addr_inet6, -#line 4183 "ifupdown.nw" +#line 4216 "ifupdown.nw" &addr_ipx, -#line 457 "ifupdown.nw" +#line 458 "ifupdown.nw" NULL }; diff -Nru /tmp/JbHIRqSutJ/ifupdown-0.6.8ubuntu9/archlinux.c /tmp/snYwT58QIS/ifupdown-0.6.8ubuntu10/archlinux.c --- ifupdown-0.6.8ubuntu9/archlinux.c 2008-06-21 23:30:44.000000000 +0100 +++ ifupdown-0.6.8ubuntu10/archlinux.c 2008-10-11 13:34:51.000000000 +0100 @@ -1,4 +1,4 @@ -#line 3857 "ifupdown.nw" +#line 3890 "ifupdown.nw" #include #include #include diff -Nru /tmp/JbHIRqSutJ/ifupdown-0.6.8ubuntu9/archlinux.h /tmp/snYwT58QIS/ifupdown-0.6.8ubuntu10/archlinux.h --- ifupdown-0.6.8ubuntu9/archlinux.h 2008-06-21 23:30:44.000000000 +0100 +++ ifupdown-0.6.8ubuntu10/archlinux.h 2008-10-11 13:34:51.000000000 +0100 @@ -1,4 +1,4 @@ -#line 3851 "ifupdown.nw" +#line 3884 "ifupdown.nw" unsigned int mylinuxver(); unsigned int mylinux(int,int,int); int execable(char *); diff -Nru /tmp/JbHIRqSutJ/ifupdown-0.6.8ubuntu9/config.c /tmp/snYwT58QIS/ifupdown-0.6.8ubuntu10/config.c --- ifupdown-0.6.8ubuntu9/config.c 2008-06-21 23:30:44.000000000 +0100 +++ ifupdown-0.6.8ubuntu10/config.c 2008-10-11 13:34:51.000000000 +0100 @@ -1,52 +1,52 @@ -#line 1033 "ifupdown.nw" +#line 1034 "ifupdown.nw" #include #include #include #include #include -#line 1044 "ifupdown.nw" +#line 1045 "ifupdown.nw" #include "header.h" -#line 1272 "ifupdown.nw" +#line 1273 "ifupdown.nw" #include -#line 1406 "ifupdown.nw" +#line 1407 "ifupdown.nw" #include -#line 1249 "ifupdown.nw" +#line 1250 "ifupdown.nw" static int get_line(char **result, size_t *result_len, FILE *f, int *line); -#line 1476 "ifupdown.nw" +#line 1477 "ifupdown.nw" static char *next_word(char *buf, char *word, int maxlen); -#line 1713 "ifupdown.nw" +#line 1714 "ifupdown.nw" static address_family *get_address_family(address_family *af[], char *name); -#line 1748 "ifupdown.nw" +#line 1749 "ifupdown.nw" static method *get_method(address_family *af, char *name); -#line 1809 "ifupdown.nw" +#line 1810 "ifupdown.nw" static int duplicate_if(interface_defn *ifa, interface_defn *ifb); -#line 1951 "ifupdown.nw" +#line 1952 "ifupdown.nw" allowup_defn *get_allowup(allowup_defn **allowups, char *name); -#line 1989 "ifupdown.nw" +#line 1990 "ifupdown.nw" allowup_defn *add_allow_up(char *filename, int line, allowup_defn *allow_up, char *iface_name); -#line 1174 "ifupdown.nw" +#line 1175 "ifupdown.nw" interfaces_file *read_interfaces(char *filename) { -#line 1219 "ifupdown.nw" +#line 1220 "ifupdown.nw" FILE *f; int line; -#line 1256 "ifupdown.nw" +#line 1257 "ifupdown.nw" char *buf = NULL; size_t buf_len = 0; -#line 1456 "ifupdown.nw" +#line 1457 "ifupdown.nw" interface_defn *currif = NULL; mapping_defn *currmap = NULL; enum { NONE, IFACE, MAPPING } currently_processing = NONE; -#line 1467 "ifupdown.nw" +#line 1468 "ifupdown.nw" char firstword[80]; char *rest; -#line 1176 "ifupdown.nw" +#line 1177 "ifupdown.nw" interfaces_file *defn; -#line 1196 "ifupdown.nw" +#line 1197 "ifupdown.nw" defn = malloc(sizeof(interfaces_file)); if (defn == NULL) { return NULL; @@ -54,36 +54,36 @@ defn->allowups = NULL; defn->mappings = NULL; defn->ifaces = NULL; -#line 1179 "ifupdown.nw" +#line 1180 "ifupdown.nw" -#line 1224 "ifupdown.nw" +#line 1225 "ifupdown.nw" f = fopen(filename, "r"); if ( f == NULL ) return NULL; line = 0; -#line 1181 "ifupdown.nw" +#line 1182 "ifupdown.nw" while ( -#line 1264 "ifupdown.nw" +#line 1265 "ifupdown.nw" get_line(&buf,&buf_len,f,&line) -#line 1181 "ifupdown.nw" +#line 1182 "ifupdown.nw" ) { -#line 1503 "ifupdown.nw" +#line 1504 "ifupdown.nw" rest = next_word(buf, firstword, 80); if (rest == NULL) continue; /* blank line */ if (strcmp(firstword, "mapping") == 0) { -#line 1555 "ifupdown.nw" +#line 1556 "ifupdown.nw" currmap = malloc(sizeof(mapping_defn)); if (currmap == NULL) { -#line 2040 "ifupdown.nw" +#line 2041 "ifupdown.nw" perror(filename); return NULL; -#line 1558 "ifupdown.nw" +#line 1559 "ifupdown.nw" } -#line 1562 "ifupdown.nw" +#line 1563 "ifupdown.nw" currmap->max_matches = 0; currmap->n_matches = 0; currmap->match = NULL; @@ -97,23 +97,23 @@ if (tmp == NULL) { currmap->max_matches = (currmap->max_matches - 1) / 2; -#line 2040 "ifupdown.nw" +#line 2041 "ifupdown.nw" perror(filename); return NULL; -#line 1575 "ifupdown.nw" +#line 1576 "ifupdown.nw" } currmap->match = tmp; } currmap->match[currmap->n_matches++] = strdup(firstword); } -#line 1584 "ifupdown.nw" +#line 1585 "ifupdown.nw" currmap->script = NULL; currmap->max_mappings = 0; currmap->n_mappings = 0; currmap->mapping = NULL; -#line 1592 "ifupdown.nw" +#line 1593 "ifupdown.nw" { mapping_defn **where = &defn->mappings; while(*where != NULL) { @@ -122,107 +122,107 @@ *where = currmap; currmap->next = NULL; } -#line 1508 "ifupdown.nw" +#line 1509 "ifupdown.nw" currently_processing = MAPPING; } else if (strcmp(firstword, "iface") == 0) { -#line 1644 "ifupdown.nw" +#line 1645 "ifupdown.nw" { -#line 1677 "ifupdown.nw" +#line 1678 "ifupdown.nw" char iface_name[80]; char address_family_name[80]; char method_name[80]; -#line 1647 "ifupdown.nw" +#line 1648 "ifupdown.nw" -#line 1665 "ifupdown.nw" +#line 1666 "ifupdown.nw" currif = malloc(sizeof(interface_defn)); if (!currif) { -#line 2040 "ifupdown.nw" +#line 2041 "ifupdown.nw" perror(filename); return NULL; -#line 1668 "ifupdown.nw" +#line 1669 "ifupdown.nw" } -#line 1649 "ifupdown.nw" +#line 1650 "ifupdown.nw" -#line 1683 "ifupdown.nw" +#line 1684 "ifupdown.nw" rest = next_word(rest, iface_name, 80); rest = next_word(rest, address_family_name, 80); rest = next_word(rest, method_name, 80); if (rest == NULL) { -#line 2045 "ifupdown.nw" +#line 2046 "ifupdown.nw" fprintf(stderr, "%s:%d: too few parameters for iface line\n", filename, line); return NULL; -#line 1689 "ifupdown.nw" +#line 1690 "ifupdown.nw" } if (rest[0] != '\0') { -#line 2050 "ifupdown.nw" +#line 2051 "ifupdown.nw" fprintf(stderr, "%s:%d: too many parameters for iface line\n", filename, line); return NULL; -#line 1693 "ifupdown.nw" +#line 1694 "ifupdown.nw" } -#line 1651 "ifupdown.nw" +#line 1652 "ifupdown.nw" -#line 1699 "ifupdown.nw" +#line 1700 "ifupdown.nw" currif->logical_iface = strdup(iface_name); if (!currif->logical_iface) { -#line 2040 "ifupdown.nw" +#line 2041 "ifupdown.nw" perror(filename); return NULL; -#line 1702 "ifupdown.nw" +#line 1703 "ifupdown.nw" } -#line 1652 "ifupdown.nw" +#line 1653 "ifupdown.nw" -#line 1717 "ifupdown.nw" +#line 1718 "ifupdown.nw" currif->address_family = get_address_family(addr_fams, address_family_name); if (!currif->address_family) { -#line 2055 "ifupdown.nw" +#line 2056 "ifupdown.nw" fprintf(stderr, "%s:%d: unknown address type\n", filename, line); return NULL; -#line 1720 "ifupdown.nw" +#line 1721 "ifupdown.nw" } -#line 1653 "ifupdown.nw" +#line 1654 "ifupdown.nw" -#line 1752 "ifupdown.nw" +#line 1753 "ifupdown.nw" currif->method = get_method(currif->address_family, method_name); if (!currif->method) { -#line 2060 "ifupdown.nw" +#line 2061 "ifupdown.nw" fprintf(stderr, "%s:%d: unknown method\n", filename, line); return NULL; -#line 1755 "ifupdown.nw" +#line 1756 "ifupdown.nw" return NULL; /* FIXME */ } -#line 1654 "ifupdown.nw" +#line 1655 "ifupdown.nw" -#line 1775 "ifupdown.nw" +#line 1776 "ifupdown.nw" currif->automatic = 1; currif->max_options = 0; currif->n_options = 0; currif->option = NULL; -#line 1656 "ifupdown.nw" +#line 1657 "ifupdown.nw" -#line 1791 "ifupdown.nw" +#line 1792 "ifupdown.nw" { interface_defn **where = &defn->ifaces; while(*where != NULL) { if (duplicate_if(*where, currif)) { -#line 2065 "ifupdown.nw" +#line 2066 "ifupdown.nw" fprintf(stderr, "%s:%d: duplicate interface\n", filename, line); return NULL; -#line 1796 "ifupdown.nw" +#line 1797 "ifupdown.nw" } where = &(*where)->next; } @@ -230,67 +230,67 @@ *where = currif; currif->next = NULL; } -#line 1657 "ifupdown.nw" +#line 1658 "ifupdown.nw" } -#line 1511 "ifupdown.nw" +#line 1512 "ifupdown.nw" currently_processing = IFACE; } else if (strcmp(firstword, "auto") == 0) { -#line 1930 "ifupdown.nw" +#line 1931 "ifupdown.nw" allowup_defn *auto_ups = get_allowup(&defn->allowups, "auto"); if (!auto_ups) { -#line 2040 "ifupdown.nw" +#line 2041 "ifupdown.nw" perror(filename); return NULL; -#line 1933 "ifupdown.nw" +#line 1934 "ifupdown.nw" } while((rest = next_word(rest, firstword, 80))) { if (!add_allow_up(filename, line, auto_ups, firstword)) return NULL; } -#line 1514 "ifupdown.nw" +#line 1515 "ifupdown.nw" currently_processing = NONE; } else if (strncmp(firstword, "allow-", 6) == 0 && strlen(firstword) > 6) { -#line 1940 "ifupdown.nw" +#line 1941 "ifupdown.nw" allowup_defn *allow_ups = get_allowup(&defn->allowups, firstword + 6); if (!allow_ups) { -#line 2040 "ifupdown.nw" +#line 2041 "ifupdown.nw" perror(filename); return NULL; -#line 1943 "ifupdown.nw" +#line 1944 "ifupdown.nw" } while((rest = next_word(rest, firstword, 80))) { if (!add_allow_up(filename, line, allow_ups, firstword)) return NULL; } -#line 1517 "ifupdown.nw" +#line 1518 "ifupdown.nw" currently_processing = NONE; } else { -#line 1524 "ifupdown.nw" +#line 1525 "ifupdown.nw" switch(currently_processing) { case IFACE: -#line 1830 "ifupdown.nw" +#line 1831 "ifupdown.nw" if (strcmp(firstword, "post-up") == 0) { strcpy(firstword, "up"); } if (strcmp(firstword, "pre-down") == 0) { strcpy(firstword, "down"); } -#line 1839 "ifupdown.nw" +#line 1840 "ifupdown.nw" { int i; if (strlen (rest) == 0) { -#line 2091 "ifupdown.nw" +#line 2092 "ifupdown.nw" fprintf(stderr, "%s:%d: option with empty value\n", filename, line); return NULL; -#line 1844 "ifupdown.nw" +#line 1845 "ifupdown.nw" } if (strcmp(firstword, "pre-up") != 0 @@ -301,32 +301,32 @@ for (i = 0; i < currif->n_options; i++) { if (strcmp(currif->option[i].name, firstword) == 0) { -#line 2076 "ifupdown.nw" +#line 2077 "ifupdown.nw" fprintf(stderr, "%s:%d: duplicate option\n", filename, line); return NULL; -#line 1854 "ifupdown.nw" +#line 1855 "ifupdown.nw" } } } } -#line 1866 "ifupdown.nw" +#line 1867 "ifupdown.nw" if (currif->n_options >= currif->max_options) { -#line 1911 "ifupdown.nw" +#line 1912 "ifupdown.nw" { variable *opt; currif->max_options = currif->max_options + 10; opt = realloc(currif->option, sizeof(*opt) * currif->max_options); if (opt == NULL) { -#line 2040 "ifupdown.nw" +#line 2041 "ifupdown.nw" perror(filename); return NULL; -#line 1917 "ifupdown.nw" +#line 1918 "ifupdown.nw" } currif->option = opt; } -#line 1868 "ifupdown.nw" +#line 1869 "ifupdown.nw" } currif->option[currif->n_options].name = strdup(firstword); @@ -334,102 +334,102 @@ if (!currif->option[currif->n_options].name) { -#line 2040 "ifupdown.nw" +#line 2041 "ifupdown.nw" perror(filename); return NULL; -#line 1875 "ifupdown.nw" +#line 1876 "ifupdown.nw" } if (!currif->option[currif->n_options].value) { -#line 2040 "ifupdown.nw" +#line 2041 "ifupdown.nw" perror(filename); return NULL; -#line 1879 "ifupdown.nw" +#line 1880 "ifupdown.nw" } currif->n_options++; -#line 1527 "ifupdown.nw" +#line 1528 "ifupdown.nw" break; case MAPPING: -#line 1607 "ifupdown.nw" +#line 1608 "ifupdown.nw" if (strcmp(firstword, "script") == 0) { -#line 1617 "ifupdown.nw" +#line 1618 "ifupdown.nw" if (currmap->script != NULL) { -#line 2081 "ifupdown.nw" +#line 2082 "ifupdown.nw" fprintf(stderr, "%s:%d: duplicate script in mapping\n", filename, line); return NULL; -#line 1619 "ifupdown.nw" +#line 1620 "ifupdown.nw" } else { currmap->script = strdup(rest); } -#line 1609 "ifupdown.nw" +#line 1610 "ifupdown.nw" } else if (strcmp(firstword, "map") == 0) { -#line 1625 "ifupdown.nw" +#line 1626 "ifupdown.nw" if (currmap->max_mappings == currmap->n_mappings) { char **opt; currmap->max_mappings = currmap->max_mappings * 2 + 1; opt = realloc(currmap->mapping, sizeof(*opt) * currmap->max_mappings); if (opt == NULL) { -#line 2040 "ifupdown.nw" +#line 2041 "ifupdown.nw" perror(filename); return NULL; -#line 1631 "ifupdown.nw" +#line 1632 "ifupdown.nw" } currmap->mapping = opt; } currmap->mapping[currmap->n_mappings] = strdup(rest); currmap->n_mappings++; -#line 1611 "ifupdown.nw" +#line 1612 "ifupdown.nw" } else { -#line 2086 "ifupdown.nw" +#line 2087 "ifupdown.nw" fprintf(stderr, "%s:%d: misplaced option\n", filename, line); return NULL; -#line 1613 "ifupdown.nw" +#line 1614 "ifupdown.nw" } -#line 1530 "ifupdown.nw" +#line 1531 "ifupdown.nw" break; case NONE: default: -#line 2086 "ifupdown.nw" +#line 2087 "ifupdown.nw" fprintf(stderr, "%s:%d: misplaced option\n", filename, line); return NULL; -#line 1534 "ifupdown.nw" +#line 1535 "ifupdown.nw" } -#line 1520 "ifupdown.nw" +#line 1521 "ifupdown.nw" } -#line 1183 "ifupdown.nw" +#line 1184 "ifupdown.nw" } if ( -#line 1276 "ifupdown.nw" +#line 1277 "ifupdown.nw" ferror(f) != 0 -#line 1184 "ifupdown.nw" +#line 1185 "ifupdown.nw" ) { -#line 2040 "ifupdown.nw" +#line 2041 "ifupdown.nw" perror(filename); return NULL; -#line 1186 "ifupdown.nw" +#line 1187 "ifupdown.nw" } -#line 1230 "ifupdown.nw" +#line 1231 "ifupdown.nw" fclose(f); line = -1; -#line 1189 "ifupdown.nw" +#line 1190 "ifupdown.nw" -#line 1206 "ifupdown.nw" +#line 1207 "ifupdown.nw" currif = defn->ifaces; while (currif) { -#line 1889 "ifupdown.nw" +#line 1890 "ifupdown.nw" int metric_search_i = 0; int metric_definition_found = 0; for (; metric_search_i < currif->n_options; metric_search_i++) { @@ -441,50 +441,50 @@ if (!metric_definition_found) { -#line 1911 "ifupdown.nw" +#line 1912 "ifupdown.nw" { variable *opt; currif->max_options = currif->max_options + 10; opt = realloc(currif->option, sizeof(*opt) * currif->max_options); if (opt == NULL) { -#line 2040 "ifupdown.nw" +#line 2041 "ifupdown.nw" perror(filename); return NULL; -#line 1917 "ifupdown.nw" +#line 1918 "ifupdown.nw" } currif->option = opt; } -#line 1900 "ifupdown.nw" +#line 1901 "ifupdown.nw" currif->option[currif->n_options].name = strdup("metric"); currif->option[currif->n_options].value = strdup("100"); currif->n_options++; } -#line 1209 "ifupdown.nw" +#line 1210 "ifupdown.nw" currif = currif->next; } -#line 1191 "ifupdown.nw" +#line 1192 "ifupdown.nw" return defn; } -#line 1289 "ifupdown.nw" +#line 1290 "ifupdown.nw" static int get_line(char **result, size_t *result_len, FILE *f, int *line) { -#line 1314 "ifupdown.nw" +#line 1315 "ifupdown.nw" size_t pos; -#line 1292 "ifupdown.nw" +#line 1293 "ifupdown.nw" do { -#line 1321 "ifupdown.nw" +#line 1322 "ifupdown.nw" pos = 0; -#line 1294 "ifupdown.nw" +#line 1295 "ifupdown.nw" -#line 1332 "ifupdown.nw" +#line 1333 "ifupdown.nw" do { -#line 1353 "ifupdown.nw" +#line 1354 "ifupdown.nw" if (*result_len - pos < 10) { char *newstr = realloc(*result, *result_len * 2 + 80); if (newstr == NULL) { @@ -493,33 +493,33 @@ *result = newstr; *result_len = *result_len * 2 + 80; } -#line 1334 "ifupdown.nw" +#line 1335 "ifupdown.nw" -#line 1382 "ifupdown.nw" +#line 1383 "ifupdown.nw" if (!fgets(*result + pos, *result_len - pos, f)) { if (ferror(f) == 0 && pos == 0) return 0; if (ferror(f) != 0) return 0; } pos += strlen(*result + pos); -#line 1335 "ifupdown.nw" +#line 1336 "ifupdown.nw" } while( -#line 1373 "ifupdown.nw" +#line 1374 "ifupdown.nw" pos == *result_len - 1 && (*result)[pos-1] != '\n' -#line 1335 "ifupdown.nw" +#line 1336 "ifupdown.nw" ); -#line 1394 "ifupdown.nw" +#line 1395 "ifupdown.nw" if (pos != 0 && (*result)[pos-1] == '\n') { (*result)[--pos] = '\0'; } -#line 1339 "ifupdown.nw" +#line 1340 "ifupdown.nw" (*line)++; assert( (*result)[pos] == '\0' ); -#line 1295 "ifupdown.nw" +#line 1296 "ifupdown.nw" -#line 1410 "ifupdown.nw" +#line 1411 "ifupdown.nw" { int first = 0; while (isspace((*result)[first]) && (*result)[first]) { @@ -529,27 +529,27 @@ memmove(*result, *result + first, pos - first + 1); pos -= first; } -#line 1296 "ifupdown.nw" +#line 1297 "ifupdown.nw" } while ( -#line 1434 "ifupdown.nw" +#line 1435 "ifupdown.nw" (*result)[0] == '#' -#line 1296 "ifupdown.nw" +#line 1297 "ifupdown.nw" ); while ( -#line 1438 "ifupdown.nw" +#line 1439 "ifupdown.nw" (*result)[pos-1] == '\\' -#line 1298 "ifupdown.nw" +#line 1299 "ifupdown.nw" ) { -#line 1442 "ifupdown.nw" +#line 1443 "ifupdown.nw" (*result)[--pos] = '\0'; -#line 1300 "ifupdown.nw" +#line 1301 "ifupdown.nw" -#line 1332 "ifupdown.nw" +#line 1333 "ifupdown.nw" do { -#line 1353 "ifupdown.nw" +#line 1354 "ifupdown.nw" if (*result_len - pos < 10) { char *newstr = realloc(*result, *result_len * 2 + 80); if (newstr == NULL) { @@ -558,44 +558,44 @@ *result = newstr; *result_len = *result_len * 2 + 80; } -#line 1334 "ifupdown.nw" +#line 1335 "ifupdown.nw" -#line 1382 "ifupdown.nw" +#line 1383 "ifupdown.nw" if (!fgets(*result + pos, *result_len - pos, f)) { if (ferror(f) == 0 && pos == 0) return 0; if (ferror(f) != 0) return 0; } pos += strlen(*result + pos); -#line 1335 "ifupdown.nw" +#line 1336 "ifupdown.nw" } while( -#line 1373 "ifupdown.nw" +#line 1374 "ifupdown.nw" pos == *result_len - 1 && (*result)[pos-1] != '\n' -#line 1335 "ifupdown.nw" +#line 1336 "ifupdown.nw" ); -#line 1394 "ifupdown.nw" +#line 1395 "ifupdown.nw" if (pos != 0 && (*result)[pos-1] == '\n') { (*result)[--pos] = '\0'; } -#line 1339 "ifupdown.nw" +#line 1340 "ifupdown.nw" (*line)++; assert( (*result)[pos] == '\0' ); -#line 1301 "ifupdown.nw" +#line 1302 "ifupdown.nw" } -#line 1422 "ifupdown.nw" +#line 1423 "ifupdown.nw" while (isspace((*result)[pos-1])) { /* remove trailing whitespace */ pos--; } (*result)[pos] = '\0'; -#line 1305 "ifupdown.nw" +#line 1306 "ifupdown.nw" return 1; } -#line 1480 "ifupdown.nw" +#line 1481 "ifupdown.nw" static char *next_word(char *buf, char *word, int maxlen) { if (!buf) return NULL; if (!*buf) return NULL; @@ -610,7 +610,7 @@ return buf; } -#line 1729 "ifupdown.nw" +#line 1730 "ifupdown.nw" static address_family *get_address_family(address_family *af[], char *name) { int i; for (i = 0; af[i]; i++) { @@ -620,7 +620,7 @@ } return NULL; } -#line 1760 "ifupdown.nw" +#line 1761 "ifupdown.nw" static method *get_method(address_family *af, char *name) { int i; for (i = 0; i < af->n_methods; i++) { @@ -630,13 +630,13 @@ } return NULL; } -#line 1813 "ifupdown.nw" +#line 1814 "ifupdown.nw" static int duplicate_if(interface_defn *ifa, interface_defn *ifb) { if (strcmp(ifa->logical_iface, ifb->logical_iface) != 0) return 0; if (ifa->address_family != ifb->address_family) return 0; return 1; } -#line 1954 "ifupdown.nw" +#line 1955 "ifupdown.nw" allowup_defn *get_allowup(allowup_defn **allowups, char *name) { for (; *allowups; allowups = &(*allowups)->next) { if (strcmp((*allowups)->when, name) == 0) break; @@ -652,7 +652,7 @@ } return *allowups; } -#line 1979 "ifupdown.nw" +#line 1980 "ifupdown.nw" allowup_defn *find_allowup(interfaces_file *defn, char *name) { allowup_defn *allowups = defn->allowups; for (; allowups; allowups = allowups->next) { @@ -660,29 +660,29 @@ } return allowups; } -#line 1994 "ifupdown.nw" +#line 1995 "ifupdown.nw" allowup_defn *add_allow_up(char *filename, int line, allowup_defn *allow_up, char *iface_name) { -#line 2004 "ifupdown.nw" +#line 2005 "ifupdown.nw" { int i; for (i = 0; i < allow_up->n_interfaces; i++) { if (strcmp(iface_name, allow_up->interfaces[i]) == 0) { -#line 2070 "ifupdown.nw" +#line 2071 "ifupdown.nw" fprintf(stderr, "%s:%d: interface %s declared allow-%s twice\n", filename, line, iface_name, allow_up->when); return NULL; -#line 2010 "ifupdown.nw" +#line 2011 "ifupdown.nw" } } } -#line 1998 "ifupdown.nw" +#line 1999 "ifupdown.nw" -#line 2016 "ifupdown.nw" +#line 2017 "ifupdown.nw" if (allow_up->n_interfaces == allow_up->max_interfaces) { char **tmp; allow_up->max_interfaces *= 2; @@ -691,16 +691,16 @@ sizeof(*tmp) * allow_up->max_interfaces); if (tmp == NULL) { -#line 2040 "ifupdown.nw" +#line 2041 "ifupdown.nw" perror(filename); return NULL; -#line 2024 "ifupdown.nw" +#line 2025 "ifupdown.nw" } allow_up->interfaces = tmp; } allow_up->interfaces[allow_up->n_interfaces] = strdup(iface_name); allow_up->n_interfaces++; -#line 1999 "ifupdown.nw" +#line 2000 "ifupdown.nw" return allow_up; } diff -Nru /tmp/JbHIRqSutJ/ifupdown-0.6.8ubuntu9/debian/changelog /tmp/snYwT58QIS/ifupdown-0.6.8ubuntu10/debian/changelog --- ifupdown-0.6.8ubuntu9/debian/changelog 2008-06-21 23:30:44.000000000 +0100 +++ ifupdown-0.6.8ubuntu10/debian/changelog 2008-10-11 13:34:51.000000000 +0100 @@ -1,3 +1,15 @@ +ifupdown (0.6.8ubuntu10) intrepid; urgency=low + + https://lists.ubuntu.com/archives/ubuntu-devel/2008-October/026656.html: + + * stop ifupdown to auto-up/down interfaces if network-manager's + ifupdown plugin is in managed=true mode + - add iniparser3.0b sources + + add dictionary.c,dictionary.h,iniparser.c,iniparser.h + - Makefile: add iniparser objects to build (aka OBJ) + + -- Alexander Sack Thu, 09 Oct 2008 16:46:47 +0200 + ifupdown (0.6.8ubuntu9) intrepid; urgency=low * debian/ifupdown.rules: (the udev rule) ensure that the init script diff -Nru /tmp/JbHIRqSutJ/ifupdown-0.6.8ubuntu9/dictionary.c /tmp/snYwT58QIS/ifupdown-0.6.8ubuntu10/dictionary.c --- ifupdown-0.6.8ubuntu9/dictionary.c 1970-01-01 01:00:00.000000000 +0100 +++ ifupdown-0.6.8ubuntu10/dictionary.c 2008-10-11 13:34:51.000000000 +0100 @@ -0,0 +1,428 @@ +/* + Copyright (c) 2000-2007 by Nicolas Devillard. + MIT License + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/*-------------------------------------------------------------------------*/ +/** + @file dictionary.c + @author N. Devillard + @date Sep 2007 + @version $Revision: 1.27 $ + @brief Implements a dictionary for string variables. + + This module implements a simple dictionary object, i.e. a list + of string/string associations. This object is useful to store e.g. + informations retrieved from a configuration file (ini files). +*/ +/*--------------------------------------------------------------------------*/ + +/* + $Id: dictionary.c,v 1.27 2007-11-23 21:39:18 ndevilla Exp $ + $Revision: 1.27 $ +*/ +/*--------------------------------------------------------------------------- + Includes + ---------------------------------------------------------------------------*/ +#include "dictionary.h" + +#include +#include +#include +#include + +/** Maximum value size for integers and doubles. */ +#define MAXVALSZ 1024 + +/** Minimal allocated number of entries in a dictionary */ +#define DICTMINSZ 128 + +/** Invalid key token */ +#define DICT_INVALID_KEY ((char*)-1) + +/*--------------------------------------------------------------------------- + Private functions + ---------------------------------------------------------------------------*/ + +/* Doubles the allocated size associated to a pointer */ +/* 'size' is the current allocated size. */ +static void * mem_double(void * ptr, int size) +{ + void * newptr ; + + newptr = calloc(2*size, 1); + if (newptr==NULL) { + return NULL ; + } + memcpy(newptr, ptr, size); + free(ptr); + return newptr ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Duplicate a string + @param s String to duplicate + @return Pointer to a newly allocated string, to be freed with free() + + This is a replacement for strdup(). This implementation is provided + for systems that do not have it. + */ +/*--------------------------------------------------------------------------*/ +static char * xstrdup(char * s) +{ + char * t ; + if (!s) + return NULL ; + t = malloc(strlen(s)+1) ; + if (t) { + strcpy(t,s); + } + return t ; +} + +/*--------------------------------------------------------------------------- + Function codes + ---------------------------------------------------------------------------*/ +/*-------------------------------------------------------------------------*/ +/** + @brief Compute the hash key for a string. + @param key Character string to use for key. + @return 1 unsigned int on at least 32 bits. + + This hash function has been taken from an Article in Dr Dobbs Journal. + This is normally a collision-free function, distributing keys evenly. + The key is stored anyway in the struct so that collision can be avoided + by comparing the key itself in last resort. + */ +/*--------------------------------------------------------------------------*/ +unsigned dictionary_hash(char * key) +{ + int len ; + unsigned hash ; + int i ; + + len = strlen(key); + for (hash=0, i=0 ; i>6) ; + } + hash += (hash <<3); + hash ^= (hash >>11); + hash += (hash <<15); + return hash ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Create a new dictionary object. + @param size Optional initial size of the dictionary. + @return 1 newly allocated dictionary objet. + + This function allocates a new dictionary object of given size and returns + it. If you do not know in advance (roughly) the number of entries in the + dictionary, give size=0. + */ +/*--------------------------------------------------------------------------*/ +dictionary * dictionary_new(int size) +{ + dictionary * d ; + + /* If no size was specified, allocate space for DICTMINSZ */ + if (sizesize = size ; + d->val = (char **)calloc(size, sizeof(char*)); + d->key = (char **)calloc(size, sizeof(char*)); + d->hash = (unsigned int *)calloc(size, sizeof(unsigned)); + return d ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Delete a dictionary object + @param d dictionary object to deallocate. + @return void + + Deallocate a dictionary object and all memory associated to it. + */ +/*--------------------------------------------------------------------------*/ +void dictionary_del(dictionary * d) +{ + int i ; + + if (d==NULL) return ; + for (i=0 ; isize ; i++) { + if (d->key[i]!=NULL) + free(d->key[i]); + if (d->val[i]!=NULL) + free(d->val[i]); + } + free(d->val); + free(d->key); + free(d->hash); + free(d); + return ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get a value from a dictionary. + @param d dictionary object to search. + @param key Key to look for in the dictionary. + @param def Default value to return if key not found. + @return 1 pointer to internally allocated character string. + + This function locates a key in a dictionary and returns a pointer to its + value, or the passed 'def' pointer if no such key can be found in + dictionary. The returned character pointer points to data internal to the + dictionary object, you should not try to free it or modify it. + */ +/*--------------------------------------------------------------------------*/ +char * dictionary_get(dictionary * d, char * key, char * def) +{ + unsigned hash ; + int i ; + + hash = dictionary_hash(key); + for (i=0 ; isize ; i++) { + if (d->key[i]==NULL) + continue ; + /* Compare hash */ + if (hash==d->hash[i]) { + /* Compare string, to avoid hash collisions */ + if (!strcmp(key, d->key[i])) { + return d->val[i] ; + } + } + } + return def ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Set a value in a dictionary. + @param d dictionary object to modify. + @param key Key to modify or add. + @param val Value to add. + @return int 0 if Ok, anything else otherwise + + If the given key is found in the dictionary, the associated value is + replaced by the provided one. If the key cannot be found in the + dictionary, it is added to it. + + It is Ok to provide a NULL value for val, but NULL values for the dictionary + or the key are considered as errors: the function will return immediately + in such a case. + + Notice that if you dictionary_set a variable to NULL, a call to + dictionary_get will return a NULL value: the variable will be found, and + its value (NULL) is returned. In other words, setting the variable + content to NULL is equivalent to deleting the variable from the + dictionary. It is not possible (in this implementation) to have a key in + the dictionary without value. + + This function returns non-zero in case of failure. + */ +/*--------------------------------------------------------------------------*/ +int dictionary_set(dictionary * d, char * key, char * val) +{ + int i ; + unsigned hash ; + + if (d==NULL || key==NULL) return -1 ; + + /* Compute hash for this key */ + hash = dictionary_hash(key) ; + /* Find if value is already in dictionary */ + if (d->n>0) { + for (i=0 ; isize ; i++) { + if (d->key[i]==NULL) + continue ; + if (hash==d->hash[i]) { /* Same hash value */ + if (!strcmp(key, d->key[i])) { /* Same key */ + /* Found a value: modify and return */ + if (d->val[i]!=NULL) + free(d->val[i]); + d->val[i] = val ? xstrdup(val) : NULL ; + /* Value has been modified: return */ + return 0 ; + } + } + } + } + /* Add a new value */ + /* See if dictionary needs to grow */ + if (d->n==d->size) { + + /* Reached maximum size: reallocate dictionary */ + d->val = (char **)mem_double(d->val, d->size * sizeof(char*)) ; + d->key = (char **)mem_double(d->key, d->size * sizeof(char*)) ; + d->hash = (unsigned int *)mem_double(d->hash, d->size * sizeof(unsigned)) ; + if ((d->val==NULL) || (d->key==NULL) || (d->hash==NULL)) { + /* Cannot grow dictionary */ + return -1 ; + } + /* Double size */ + d->size *= 2 ; + } + + /* Insert key in the first empty slot */ + for (i=0 ; isize ; i++) { + if (d->key[i]==NULL) { + /* Add key here */ + break ; + } + } + /* Copy key */ + d->key[i] = xstrdup(key); + d->val[i] = val ? xstrdup(val) : NULL ; + d->hash[i] = hash; + d->n ++ ; + return 0 ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Delete a key in a dictionary + @param d dictionary object to modify. + @param key Key to remove. + @return void + + This function deletes a key in a dictionary. Nothing is done if the + key cannot be found. + */ +/*--------------------------------------------------------------------------*/ +void dictionary_unset(dictionary * d, char * key) +{ + unsigned hash ; + int i ; + + if (key == NULL) { + return; + } + + hash = dictionary_hash(key); + for (i=0 ; isize ; i++) { + if (d->key[i]==NULL) + continue ; + /* Compare hash */ + if (hash==d->hash[i]) { + /* Compare string, to avoid hash collisions */ + if (!strcmp(key, d->key[i])) { + /* Found key */ + break ; + } + } + } + if (i>=d->size) + /* Key not found */ + return ; + + free(d->key[i]); + d->key[i] = NULL ; + if (d->val[i]!=NULL) { + free(d->val[i]); + d->val[i] = NULL ; + } + d->hash[i] = 0 ; + d->n -- ; + return ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Dump a dictionary to an opened file pointer. + @param d Dictionary to dump + @param f Opened file pointer. + @return void + + Dumps a dictionary onto an opened file pointer. Key pairs are printed out + as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr as + output file pointers. + */ +/*--------------------------------------------------------------------------*/ +void dictionary_dump(dictionary * d, FILE * out) +{ + int i ; + + if (d==NULL || out==NULL) return ; + if (d->n<1) { + fprintf(out, "empty dictionary\n"); + return ; + } + for (i=0 ; isize ; i++) { + if (d->key[i]) { + fprintf(out, "%20s\t[%s]\n", + d->key[i], + d->val[i] ? d->val[i] : "UNDEF"); + } + } + return ; +} + + +/* Test code */ +#ifdef TESTDIC +#define NVALS 20000 +int main(int argc, char *argv[]) +{ + dictionary * d ; + char * val ; + int i ; + char cval[90] ; + + /* Allocate dictionary */ + printf("allocating...\n"); + d = dictionary_new(0); + + /* Set values in dictionary */ + printf("setting %d values...\n", NVALS); + for (i=0 ; in != 0) { + printf("error deleting values\n"); + } + printf("deallocating...\n"); + dictionary_del(d); + return 0 ; +} +#endif +/* vim: set ts=4 et sw=4 tw=75 */ diff -Nru /tmp/JbHIRqSutJ/ifupdown-0.6.8ubuntu9/dictionary.h /tmp/snYwT58QIS/ifupdown-0.6.8ubuntu10/dictionary.h --- ifupdown-0.6.8ubuntu9/dictionary.h 1970-01-01 01:00:00.000000000 +0100 +++ ifupdown-0.6.8ubuntu10/dictionary.h 2008-10-11 13:34:51.000000000 +0100 @@ -0,0 +1,196 @@ +/* + Copyright (c) 2000-2007 by Nicolas Devillard. + MIT License + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/*-------------------------------------------------------------------------*/ +/** + @file dictionary.h + @author N. Devillard + @date Sep 2007 + @version $Revision: 1.12 $ + @brief Implements a dictionary for string variables. + + This module implements a simple dictionary object, i.e. a list + of string/string associations. This object is useful to store e.g. + informations retrieved from a configuration file (ini files). +*/ +/*--------------------------------------------------------------------------*/ + +/* + $Id: dictionary.h,v 1.12 2007-11-23 21:37:00 ndevilla Exp $ + $Author: ndevilla $ + $Date: 2007-11-23 21:37:00 $ + $Revision: 1.12 $ +*/ + +#ifndef _DICTIONARY_H_ +#define _DICTIONARY_H_ + +/*--------------------------------------------------------------------------- + Includes + ---------------------------------------------------------------------------*/ + +#include +#include +#include +#include + +/*--------------------------------------------------------------------------- + New types + ---------------------------------------------------------------------------*/ + + +/*-------------------------------------------------------------------------*/ +/** + @brief Dictionary object + + This object contains a list of string/string associations. Each + association is identified by a unique string key. Looking up values + in the dictionary is speeded up by the use of a (hopefully collision-free) + hash function. + */ +/*-------------------------------------------------------------------------*/ +typedef struct _dictionary_ { + int n ; /** Number of entries in dictionary */ + int size ; /** Storage size */ + char ** val ; /** List of string values */ + char ** key ; /** List of string keys */ + unsigned * hash ; /** List of hash values for keys */ +} dictionary ; + + +/*--------------------------------------------------------------------------- + Function prototypes + ---------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------*/ +/** + @brief Compute the hash key for a string. + @param key Character string to use for key. + @return 1 unsigned int on at least 32 bits. + + This hash function has been taken from an Article in Dr Dobbs Journal. + This is normally a collision-free function, distributing keys evenly. + The key is stored anyway in the struct so that collision can be avoided + by comparing the key itself in last resort. + */ +/*--------------------------------------------------------------------------*/ +unsigned dictionary_hash(char * key); + +/*-------------------------------------------------------------------------*/ +/** + @brief Create a new dictionary object. + @param size Optional initial size of the dictionary. + @return 1 newly allocated dictionary objet. + + This function allocates a new dictionary object of given size and returns + it. If you do not know in advance (roughly) the number of entries in the + dictionary, give size=0. + */ +/*--------------------------------------------------------------------------*/ +dictionary * dictionary_new(int size); + +/*-------------------------------------------------------------------------*/ +/** + @brief Delete a dictionary object + @param d dictionary object to deallocate. + @return void + + Deallocate a dictionary object and all memory associated to it. + */ +/*--------------------------------------------------------------------------*/ +void dictionary_del(dictionary * vd); + +/*-------------------------------------------------------------------------*/ +/** + @brief Get a value from a dictionary. + @param d dictionary object to search. + @param key Key to look for in the dictionary. + @param def Default value to return if key not found. + @return 1 pointer to internally allocated character string. + + This function locates a key in a dictionary and returns a pointer to its + value, or the passed 'def' pointer if no such key can be found in + dictionary. The returned character pointer points to data internal to the + dictionary object, you should not try to free it or modify it. + */ +/*--------------------------------------------------------------------------*/ +char * dictionary_get(dictionary * d, char * key, char * def); + + +/*-------------------------------------------------------------------------*/ +/** + @brief Set a value in a dictionary. + @param d dictionary object to modify. + @param key Key to modify or add. + @param val Value to add. + @return int 0 if Ok, anything else otherwise + + If the given key is found in the dictionary, the associated value is + replaced by the provided one. If the key cannot be found in the + dictionary, it is added to it. + + It is Ok to provide a NULL value for val, but NULL values for the dictionary + or the key are considered as errors: the function will return immediately + in such a case. + + Notice that if you dictionary_set a variable to NULL, a call to + dictionary_get will return a NULL value: the variable will be found, and + its value (NULL) is returned. In other words, setting the variable + content to NULL is equivalent to deleting the variable from the + dictionary. It is not possible (in this implementation) to have a key in + the dictionary without value. + + This function returns non-zero in case of failure. + */ +/*--------------------------------------------------------------------------*/ +int dictionary_set(dictionary * vd, char * key, char * val); + +/*-------------------------------------------------------------------------*/ +/** + @brief Delete a key in a dictionary + @param d dictionary object to modify. + @param key Key to remove. + @return void + + This function deletes a key in a dictionary. Nothing is done if the + key cannot be found. + */ +/*--------------------------------------------------------------------------*/ +void dictionary_unset(dictionary * d, char * key); + + +/*-------------------------------------------------------------------------*/ +/** + @brief Dump a dictionary to an opened file pointer. + @param d Dictionary to dump + @param f Opened file pointer. + @return void + + Dumps a dictionary onto an opened file pointer. Key pairs are printed out + as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr as + output file pointers. + */ +/*--------------------------------------------------------------------------*/ +void dictionary_dump(dictionary * d, FILE * out); + +#endif diff -Nru /tmp/JbHIRqSutJ/ifupdown-0.6.8ubuntu9/execute.c /tmp/snYwT58QIS/ifupdown-0.6.8ubuntu10/execute.c --- ifupdown-0.6.8ubuntu9/execute.c 2008-06-21 23:30:44.000000000 +0100 +++ ifupdown-0.6.8ubuntu10/execute.c 2008-10-11 13:34:51.000000000 +0100 @@ -1,4 +1,4 @@ -#line 2108 "ifupdown.nw" +#line 2109 "ifupdown.nw" #include #include #include @@ -6,48 +6,48 @@ #include #include "header.h" -#line 2730 "ifupdown.nw" +#line 2731 "ifupdown.nw" #include -#line 2916 "ifupdown.nw" +#line 2917 "ifupdown.nw" #include -#line 2939 "ifupdown.nw" +#line 2940 "ifupdown.nw" #include #include -#line 2192 "ifupdown.nw" +#line 2193 "ifupdown.nw" static char **environ = NULL; -#line 2169 "ifupdown.nw" +#line 2170 "ifupdown.nw" static int check(char *str); -#line 2199 "ifupdown.nw" +#line 2200 "ifupdown.nw" static void set_environ(interface_defn *iface, char *mode, char *phase); -#line 2277 "ifupdown.nw" +#line 2278 "ifupdown.nw" static char *setlocalenv(char *format, char *name, char *value); -#line 2390 "ifupdown.nw" +#line 2391 "ifupdown.nw" static int doit(char *str); -#line 2557 "ifupdown.nw" +#line 2558 "ifupdown.nw" static char *parse(char *command, interface_defn *ifd); -#line 2604 "ifupdown.nw" +#line 2605 "ifupdown.nw" void addstr(char **buf, size_t *len, size_t *pos, char *str, size_t strlen); -#line 2811 "ifupdown.nw" +#line 2812 "ifupdown.nw" int strncmpz(char *l, char *r, size_t llen); -#line 2828 "ifupdown.nw" +#line 2829 "ifupdown.nw" char *get_var(char *id, size_t idlen, interface_defn *ifd); -#line 2920 "ifupdown.nw" +#line 2921 "ifupdown.nw" static int popen2(FILE **in, FILE **out, char *command, ...); -#line 2173 "ifupdown.nw" +#line 2174 "ifupdown.nw" static int check(char *str) { return str != NULL; } -#line 2205 "ifupdown.nw" +#line 2206 "ifupdown.nw" static void set_environ(interface_defn *iface, char *mode, char *phase) { -#line 2234 "ifupdown.nw" +#line 2235 "ifupdown.nw" char **environend; -#line 2207 "ifupdown.nw" +#line 2208 "ifupdown.nw" int i; const int n_env_entries = iface->n_options + 8; -#line 2247 "ifupdown.nw" +#line 2248 "ifupdown.nw" if (environ != NULL) { char **ppch; for (ppch = environ; *ppch; ppch++) { @@ -57,15 +57,15 @@ free(environ); environ = NULL; } -#line 2241 "ifupdown.nw" +#line 2242 "ifupdown.nw" environ = malloc(sizeof(char*) * (n_env_entries + 1 /* for final NULL */)); environend = environ; *environend = NULL; -#line 2212 "ifupdown.nw" +#line 2213 "ifupdown.nw" for (i = 0; i < iface->n_options; i++) { -#line 2261 "ifupdown.nw" +#line 2262 "ifupdown.nw" if (strcmp(iface->option[i].name, "pre-up") == 0 || strcmp(iface->option[i].name, "up") == 0 || strcmp(iface->option[i].name, "down") == 0 @@ -74,63 +74,63 @@ continue; } -#line 2215 "ifupdown.nw" +#line 2216 "ifupdown.nw" -#line 2283 "ifupdown.nw" +#line 2284 "ifupdown.nw" *(environend++) = setlocalenv("IF_%s=%s", iface->option[i].name, iface->option[i].value); *environend = NULL; -#line 2216 "ifupdown.nw" +#line 2217 "ifupdown.nw" } -#line 2289 "ifupdown.nw" +#line 2290 "ifupdown.nw" *(environend++) = setlocalenv("%s=%s", "IFACE", iface->real_iface); *environend = NULL; -#line 2219 "ifupdown.nw" +#line 2220 "ifupdown.nw" -#line 2294 "ifupdown.nw" +#line 2295 "ifupdown.nw" *(environend++) = setlocalenv("%s=%s", "LOGICAL", iface->logical_iface); *environend = NULL; -#line 2220 "ifupdown.nw" +#line 2221 "ifupdown.nw" -#line 2319 "ifupdown.nw" +#line 2320 "ifupdown.nw" *(environend++) = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name); *environend = NULL; -#line 2221 "ifupdown.nw" +#line 2222 "ifupdown.nw" -#line 2324 "ifupdown.nw" +#line 2325 "ifupdown.nw" *(environend++) = setlocalenv("%s=%s", "METHOD", iface->method->name); *environend = NULL; -#line 2223 "ifupdown.nw" +#line 2224 "ifupdown.nw" -#line 2299 "ifupdown.nw" +#line 2300 "ifupdown.nw" *(environend++) = setlocalenv("%s=%s", "MODE", mode); *environend = NULL; -#line 2224 "ifupdown.nw" +#line 2225 "ifupdown.nw" -#line 2304 "ifupdown.nw" +#line 2305 "ifupdown.nw" *(environend++) = setlocalenv("%s=%s", "PHASE", phase); *environend = NULL; -#line 2225 "ifupdown.nw" +#line 2226 "ifupdown.nw" -#line 2314 "ifupdown.nw" +#line 2315 "ifupdown.nw" *(environend++) = setlocalenv("%s=%s", "VERBOSITY", verbose ? "1" : "0"); *environend = NULL; -#line 2226 "ifupdown.nw" +#line 2227 "ifupdown.nw" -#line 2309 "ifupdown.nw" +#line 2310 "ifupdown.nw" *(environend++) = setlocalenv("%s=%s", "PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"); *environend = NULL; -#line 2227 "ifupdown.nw" +#line 2228 "ifupdown.nw" } -#line 2331 "ifupdown.nw" +#line 2332 "ifupdown.nw" static char *setlocalenv(char *format, char *name, char *value) { char *result; -#line 2349 "ifupdown.nw" +#line 2350 "ifupdown.nw" result = malloc(strlen(format) /* -4 for the two %s's */ + strlen(name) + strlen(value) @@ -140,11 +140,11 @@ exit(1); } -#line 2336 "ifupdown.nw" +#line 2337 "ifupdown.nw" sprintf(result, format, name, value); -#line 2365 "ifupdown.nw" +#line 2366 "ifupdown.nw" { char *here, *there; @@ -160,10 +160,10 @@ memmove(here, there, strlen(there) + 1); } -#line 2340 "ifupdown.nw" +#line 2341 "ifupdown.nw" return result; } -#line 2394 "ifupdown.nw" +#line 2395 "ifupdown.nw" static int doit(char *str) { assert(str); @@ -190,7 +190,7 @@ } return 1; } -#line 2440 "ifupdown.nw" +#line 2441 "ifupdown.nw" int execute_all(interface_defn *ifd, execfn *exec, char *opt) { int i; char buf[100]; @@ -209,7 +209,7 @@ return 1; } -#line 2470 "ifupdown.nw" +#line 2471 "ifupdown.nw" int iface_up(interface_defn *iface) { if (!iface->method->up(iface,check)) return -1; @@ -223,7 +223,7 @@ return 1; } -#line 2486 "ifupdown.nw" +#line 2487 "ifupdown.nw" int iface_down(interface_defn *iface) { if (!iface->method->down(iface,check)) return -1; @@ -237,7 +237,7 @@ return 1; } -#line 2515 "ifupdown.nw" +#line 2516 "ifupdown.nw" int execute(char *command, interface_defn *ifd, execfn *exec) { char *out; int ret; @@ -250,27 +250,27 @@ free(out); return ret; } -#line 2561 "ifupdown.nw" +#line 2562 "ifupdown.nw" static char *parse(char *command, interface_defn *ifd) { -#line 2586 "ifupdown.nw" +#line 2587 "ifupdown.nw" char *result = NULL; size_t pos = 0, len = 0; -#line 2680 "ifupdown.nw" +#line 2681 "ifupdown.nw" size_t old_pos[MAX_OPT_DEPTH] = {0}; int okay[MAX_OPT_DEPTH] = {1}; int opt_depth = 1; -#line 2564 "ifupdown.nw" +#line 2565 "ifupdown.nw" while(*command) { switch(*command) { -#line 2634 "ifupdown.nw" +#line 2635 "ifupdown.nw" default: addstr(&result, &len, &pos, command, 1); command++; break; -#line 2647 "ifupdown.nw" +#line 2648 "ifupdown.nw" case '\\': if (command[1]) { addstr(&result, &len, &pos, command+1, 1); @@ -280,7 +280,7 @@ command++; } break; -#line 2695 "ifupdown.nw" +#line 2696 "ifupdown.nw" case '[': if (command[1] == '[' && opt_depth < MAX_OPT_DEPTH) { old_pos[opt_depth] = pos; @@ -292,7 +292,7 @@ command++; } break; -#line 2709 "ifupdown.nw" +#line 2710 "ifupdown.nw" case ']': if (command[1] == ']' && opt_depth > 1) { opt_depth--; @@ -306,17 +306,17 @@ command++; } break; -#line 2764 "ifupdown.nw" +#line 2765 "ifupdown.nw" case '%': { -#line 2789 "ifupdown.nw" +#line 2790 "ifupdown.nw" char *nextpercent; -#line 2767 "ifupdown.nw" +#line 2768 "ifupdown.nw" char *varvalue; -#line 2793 "ifupdown.nw" +#line 2794 "ifupdown.nw" command++; nextpercent = strchr(command, '%'); if (!nextpercent) { @@ -325,12 +325,12 @@ return NULL; } -#line 2771 "ifupdown.nw" +#line 2772 "ifupdown.nw" -#line 2852 "ifupdown.nw" +#line 2853 "ifupdown.nw" varvalue = get_var(command, nextpercent - command, ifd); -#line 2773 "ifupdown.nw" +#line 2774 "ifupdown.nw" if (varvalue) { addstr(&result, &len, &pos, varvalue, strlen(varvalue)); } else { @@ -338,18 +338,18 @@ } -#line 2803 "ifupdown.nw" +#line 2804 "ifupdown.nw" command = nextpercent + 1; -#line 2781 "ifupdown.nw" +#line 2782 "ifupdown.nw" break; } -#line 2567 "ifupdown.nw" +#line 2568 "ifupdown.nw" } } -#line 2739 "ifupdown.nw" +#line 2740 "ifupdown.nw" if (opt_depth > 1) { errno = EUNBALBRACK; free(result); @@ -362,13 +362,13 @@ return NULL; } -#line 2572 "ifupdown.nw" +#line 2573 "ifupdown.nw" -#line 2593 "ifupdown.nw" +#line 2594 "ifupdown.nw" return result; -#line 2573 "ifupdown.nw" +#line 2574 "ifupdown.nw" } -#line 2608 "ifupdown.nw" +#line 2609 "ifupdown.nw" void addstr(char **buf, size_t *len, size_t *pos, char *str, size_t strlen) { assert(*len >= *pos); assert(*len == 0 || (*buf)[*pos] == '\0'); @@ -390,7 +390,7 @@ } (*buf)[*pos] = '\0'; } -#line 2815 "ifupdown.nw" +#line 2816 "ifupdown.nw" int strncmpz(char *l, char *r, size_t llen) { int i = strncmp(l, r, llen); if (i == 0) @@ -398,7 +398,7 @@ else return i; } -#line 2832 "ifupdown.nw" +#line 2833 "ifupdown.nw" char *get_var(char *id, size_t idlen, interface_defn *ifd) { int i; @@ -414,32 +414,32 @@ return NULL; } -#line 2871 "ifupdown.nw" +#line 2872 "ifupdown.nw" int run_mapping(char *physical, char *logical, int len, mapping_defn *map) { FILE *in, *out; int i, status; pid_t pid; -#line 2930 "ifupdown.nw" +#line 2931 "ifupdown.nw" pid = popen2(&in, &out, map->script, physical, NULL); if (pid == 0) { return 0; } -#line 2877 "ifupdown.nw" +#line 2878 "ifupdown.nw" -#line 2889 "ifupdown.nw" +#line 2890 "ifupdown.nw" for (i = 0; i < map->n_mappings; i++) { fprintf(in, "%s\n", map->mapping[i]); } fclose(in); -#line 2878 "ifupdown.nw" +#line 2879 "ifupdown.nw" -#line 2896 "ifupdown.nw" +#line 2897 "ifupdown.nw" waitpid(pid, &status, 0); -#line 2879 "ifupdown.nw" +#line 2880 "ifupdown.nw" -#line 2900 "ifupdown.nw" +#line 2901 "ifupdown.nw" if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { if (fgets(logical, len, out)) { char *pch = logical + strlen(logical) - 1; @@ -449,10 +449,10 @@ } fclose(out); -#line 2881 "ifupdown.nw" +#line 2882 "ifupdown.nw" return 1; } -#line 2944 "ifupdown.nw" +#line 2945 "ifupdown.nw" static int popen2(FILE **in, FILE **out, char *command, ...) { va_list ap; char *argv[11] = {command}; diff -Nru /tmp/JbHIRqSutJ/ifupdown-0.6.8ubuntu9/header.h /tmp/snYwT58QIS/ifupdown-0.6.8ubuntu10/header.h --- ifupdown-0.6.8ubuntu9/header.h 2008-06-21 23:30:44.000000000 +0100 +++ ifupdown-0.6.8ubuntu10/header.h 2008-10-11 13:34:51.000000000 +0100 @@ -2,41 +2,41 @@ #ifndef HEADER_H #define HEADER_H -#line 392 "ifupdown.nw" +#line 393 "ifupdown.nw" typedef struct address_family address_family; -#line 425 "ifupdown.nw" +#line 426 "ifupdown.nw" typedef struct method method; -#line 1069 "ifupdown.nw" +#line 1070 "ifupdown.nw" typedef struct interfaces_file interfaces_file; -#line 1085 "ifupdown.nw" +#line 1086 "ifupdown.nw" typedef struct allowup_defn allowup_defn; -#line 1104 "ifupdown.nw" +#line 1105 "ifupdown.nw" typedef struct interface_defn interface_defn; -#line 1129 "ifupdown.nw" +#line 1130 "ifupdown.nw" typedef struct variable variable; -#line 1145 "ifupdown.nw" +#line 1146 "ifupdown.nw" typedef struct mapping_defn mapping_defn; -#line 441 "ifupdown.nw" +#line 442 "ifupdown.nw" typedef int (execfn)(char *command); typedef int (command_set)(interface_defn *ifd, execfn *e); -#line 396 "ifupdown.nw" +#line 397 "ifupdown.nw" struct address_family { char *name; int n_methods; method *method; }; -#line 429 "ifupdown.nw" +#line 430 "ifupdown.nw" struct method { char *name; command_set *up, *down; }; -#line 1073 "ifupdown.nw" +#line 1074 "ifupdown.nw" struct interfaces_file { allowup_defn *allowups; interface_defn *ifaces; mapping_defn *mappings; }; -#line 1089 "ifupdown.nw" +#line 1090 "ifupdown.nw" struct allowup_defn { allowup_defn *next; @@ -45,7 +45,7 @@ int n_interfaces; char **interfaces; }; -#line 1108 "ifupdown.nw" +#line 1109 "ifupdown.nw" struct interface_defn { interface_defn *next; @@ -61,12 +61,12 @@ int n_options; variable *option; }; -#line 1133 "ifupdown.nw" +#line 1134 "ifupdown.nw" struct variable { char *name; char *value; }; -#line 1149 "ifupdown.nw" +#line 1150 "ifupdown.nw" struct mapping_defn { mapping_defn *next; @@ -80,30 +80,30 @@ int n_mappings; char **mapping; }; -#line 2676 "ifupdown.nw" +#line 2677 "ifupdown.nw" #define MAX_OPT_DEPTH 10 -#line 2734 "ifupdown.nw" +#line 2735 "ifupdown.nw" #define EUNBALBRACK 10001 #define EUNDEFVAR 10002 -#line 2759 "ifupdown.nw" +#line 2760 "ifupdown.nw" #define MAX_VARNAME 32 #define EUNBALPER 10000 -#line 408 "ifupdown.nw" +#line 409 "ifupdown.nw" extern address_family *addr_fams[]; -#line 1170 "ifupdown.nw" +#line 1171 "ifupdown.nw" interfaces_file *read_interfaces(char *filename); -#line 1975 "ifupdown.nw" +#line 1976 "ifupdown.nw" allowup_defn *find_allowup(interfaces_file *defn, char *name); -#line 2428 "ifupdown.nw" +#line 2429 "ifupdown.nw" int execute_all(interface_defn *ifd, execfn *exec, char *opt); -#line 2465 "ifupdown.nw" +#line 2466 "ifupdown.nw" int iface_up(interface_defn *iface); int iface_down(interface_defn *iface); -#line 2508 "ifupdown.nw" +#line 2509 "ifupdown.nw" int execute(char *command, interface_defn *ifd, execfn *exec); -#line 2867 "ifupdown.nw" +#line 2868 "ifupdown.nw" int run_mapping(char *physical, char *logical, int len, mapping_defn *map); -#line 3193 "ifupdown.nw" +#line 3196 "ifupdown.nw" extern int no_act; extern int verbose; diff -Nru /tmp/JbHIRqSutJ/ifupdown-0.6.8ubuntu9/ifupdown.nw /tmp/snYwT58QIS/ifupdown-0.6.8ubuntu10/ifupdown.nw --- ifupdown-0.6.8ubuntu9/ifupdown.nw 2008-06-21 23:30:44.000000000 +0100 +++ ifupdown-0.6.8ubuntu10/ifupdown.nw 2008-10-11 13:34:51.000000000 +0100 @@ -113,7 +113,8 @@ DEFNFILES := inet.defn ipx.defn inet6.defn OBJ := main.o addrfam.o execute.o config.o \ - $(patsubst %.defn,%.o,$(DEFNFILES)) archlinux.o + $(patsubst %.defn,%.o,$(DEFNFILES)) archlinux.o \ + dictionary.o iniparser.o MAN := $(patsubst %.defn,%.man,$(DEFNFILES)) @@ -3009,6 +3010,8 @@ #include #include "header.h" + +#include "iniparser.h" @ Now, after all the above modules, our main program doesn't have too @@ -3199,6 +3202,7 @@ int verbose = 0; char *statefile = "/var/run/network/ifstate"; char *tmpstatefile = "/var/run/network/.ifstate.tmp"; +char *nm_system_settings = "/etc/NetworkManager/nm-system-settings.conf"; @ <>= @@ -3217,6 +3221,7 @@ static void usage(char *execname); static void help(char *execname); static void version(char *execname); +static int auto_disabled (); @ <
>= @@ -3260,6 +3265,30 @@ } @ +<
>= +static int auto_disabled() { + static int initialized = 0; + static int auto_up_disabled = 0; + + if (!initialized) { + dictionary *ini_dict; + initialized = 1; + + ini_dict = iniparser_load (nm_system_settings); + if (ini_dict) { + int managed = iniparser_getboolean (ini_dict, "ifupdown:managed", -1); + auto_up_disabled = managed ? 1 : 0; + iniparser_freedict (ini_dict); + ini_dict = 0; + } else { + auto_up_disabled = 0; + } + } + + return auto_up_disabled; +} +@ + Now, the meat of argument parsing is done with [[getopt()]] and a [[switch]], like so: @@ -3542,12 +3571,16 @@ <>= if (do_all) { - if (<>) { + if ((<>) && auto_disabled() == 0) { allowup_defn *autos = find_allowup(defn, "auto"); target_iface = autos ? autos->interfaces : NULL; n_target_ifaces = autos ? autos->n_interfaces : 0; } else if (<>) { read_all_state(argv[0], &target_iface, &n_target_ifaces); + } else if (auto_disabled() != 0) { + printf("WARNING: ifup -a is disabled in favour of NetworkManager.\n" + " Set ifupdown:managed=false in /etc/NetworkManager/nm-system-settings.conf.\n"); + exit (0); } else { assert(0); } diff -Nru /tmp/JbHIRqSutJ/ifupdown-0.6.8ubuntu9/iniparser.c /tmp/snYwT58QIS/ifupdown-0.6.8ubuntu10/iniparser.c --- ifupdown-0.6.8ubuntu9/iniparser.c 1970-01-01 01:00:00.000000000 +0100 +++ ifupdown-0.6.8ubuntu10/iniparser.c 2008-10-11 13:34:51.000000000 +0100 @@ -0,0 +1,667 @@ +/* + Copyright (c) 2000-2007 by Nicolas Devillard. + MIT License + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/*-------------------------------------------------------------------------*/ +/** + @file iniparser.c + @author N. Devillard + @date Sep 2007 + @version 3.0 + @brief Parser for ini files. +*/ +/*--------------------------------------------------------------------------*/ +/* + $Id: iniparser.c,v 2.18 2008-01-03 18:35:39 ndevilla Exp $ + $Revision: 2.18 $ + $Date: 2008-01-03 18:35:39 $ +*/ +/*---------------------------- Includes ------------------------------------*/ +#include +#include "iniparser.h" + +/*---------------------------- Defines -------------------------------------*/ +#define ASCIILINESZ (1024) +#define INI_INVALID_KEY ((char*)-1) + +/*--------------------------------------------------------------------------- + Private to this module + ---------------------------------------------------------------------------*/ +/** + * This enum stores the status for each parsed line (internal use only). + */ +typedef enum _line_status_ { + LINE_UNPROCESSED, + LINE_ERROR, + LINE_EMPTY, + LINE_COMMENT, + LINE_SECTION, + LINE_VALUE +} line_status ; + +/*-------------------------------------------------------------------------*/ +/** + @brief Convert a string to lowercase. + @param s String to convert. + @return ptr to statically allocated string. + + This function returns a pointer to a statically allocated string + containing a lowercased version of the input string. Do not free + or modify the returned string! Since the returned string is statically + allocated, it will be modified at each function call (not re-entrant). + */ +/*--------------------------------------------------------------------------*/ +static char * strlwc(const char * s) +{ + static char l[ASCIILINESZ+1]; + int i ; + + if (s==NULL) return NULL ; + memset(l, 0, ASCIILINESZ+1); + i=0 ; + while (s[i] && i l) { + if (!isspace((int)*(last-1))) + break ; + last -- ; + } + *last = (char)0; + return (char*)l ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get number of sections in a dictionary + @param d Dictionary to examine + @return int Number of sections found in dictionary + + This function returns the number of sections found in a dictionary. + The test to recognize sections is done on the string stored in the + dictionary: a section name is given as "section" whereas a key is + stored as "section:key", thus the test looks for entries that do not + contain a colon. + + This clearly fails in the case a section name contains a colon, but + this should simply be avoided. + + This function returns -1 in case of error. + */ +/*--------------------------------------------------------------------------*/ +int iniparser_getnsec(dictionary * d) +{ + int i ; + int nsec ; + + if (d==NULL) return -1 ; + nsec=0 ; + for (i=0 ; isize ; i++) { + if (d->key[i]==NULL) + continue ; + if (strchr(d->key[i], ':')==NULL) { + nsec ++ ; + } + } + return nsec ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get name for section n in a dictionary. + @param d Dictionary to examine + @param n Section number (from 0 to nsec-1). + @return Pointer to char string + + This function locates the n-th section in a dictionary and returns + its name as a pointer to a string statically allocated inside the + dictionary. Do not free or modify the returned string! + + This function returns NULL in case of error. + */ +/*--------------------------------------------------------------------------*/ +char * iniparser_getsecname(dictionary * d, int n) +{ + int i ; + int foundsec ; + + if (d==NULL || n<0) return NULL ; + foundsec=0 ; + for (i=0 ; isize ; i++) { + if (d->key[i]==NULL) + continue ; + if (strchr(d->key[i], ':')==NULL) { + foundsec++ ; + if (foundsec>n) + break ; + } + } + if (foundsec<=n) { + return NULL ; + } + return d->key[i] ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Dump a dictionary to an opened file pointer. + @param d Dictionary to dump. + @param f Opened file pointer to dump to. + @return void + + This function prints out the contents of a dictionary, one element by + line, onto the provided file pointer. It is OK to specify @c stderr + or @c stdout as output files. This function is meant for debugging + purposes mostly. + */ +/*--------------------------------------------------------------------------*/ +void iniparser_dump(dictionary * d, FILE * f) +{ + int i ; + + if (d==NULL || f==NULL) return ; + for (i=0 ; isize ; i++) { + if (d->key[i]==NULL) + continue ; + if (d->val[i]!=NULL) { + fprintf(f, "[%s]=[%s]\n", d->key[i], d->val[i]); + } else { + fprintf(f, "[%s]=UNDEF\n", d->key[i]); + } + } + return ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Save a dictionary to a loadable ini file + @param d Dictionary to dump + @param f Opened file pointer to dump to + @return void + + This function dumps a given dictionary into a loadable ini file. + It is Ok to specify @c stderr or @c stdout as output files. + */ +/*--------------------------------------------------------------------------*/ +void iniparser_dump_ini(dictionary * d, FILE * f) +{ + int i, j ; + char keym[ASCIILINESZ+1]; + int nsec ; + char * secname ; + int seclen ; + + if (d==NULL || f==NULL) return ; + + nsec = iniparser_getnsec(d); + if (nsec<1) { + /* No section in file: dump all keys as they are */ + for (i=0 ; isize ; i++) { + if (d->key[i]==NULL) + continue ; + fprintf(f, "%s = %s\n", d->key[i], d->val[i]); + } + return ; + } + for (i=0 ; isize ; j++) { + if (d->key[j]==NULL) + continue ; + if (!strncmp(d->key[j], keym, seclen+1)) { + fprintf(f, + "%-30s = %s\n", + d->key[j]+seclen+1, + d->val[j] ? d->val[j] : ""); + } + } + } + fprintf(f, "\n"); + return ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key + @param d Dictionary to search + @param key Key string to look for + @param def Default value to return if key not found. + @return pointer to statically allocated character string + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the pointer passed as 'def' is returned. + The returned char pointer is pointing to a string allocated in + the dictionary, do not free or modify it. + */ +/*--------------------------------------------------------------------------*/ +char * iniparser_getstring(dictionary * d, const char * key, char * def) +{ + char * lc_key ; + char * sval ; + + if (d==NULL || key==NULL) + return def ; + + lc_key = strlwc(key); + sval = dictionary_get(d, lc_key, def); + return sval ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to an int + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return integer + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the notfound value is returned. + + Supported values for integers include the usual C notation + so decimal, octal (starting with 0) and hexadecimal (starting with 0x) + are supported. Examples: + + "42" -> 42 + "042" -> 34 (octal -> decimal) + "0x42" -> 66 (hexa -> decimal) + + Warning: the conversion may overflow in various ways. Conversion is + totally outsourced to strtol(), see the associated man page for overflow + handling. + + Credits: Thanks to A. Becker for suggesting strtol() + */ +/*--------------------------------------------------------------------------*/ +int iniparser_getint(dictionary * d, const char * key, int notfound) +{ + char * str ; + + str = iniparser_getstring(d, key, INI_INVALID_KEY); + if (str==INI_INVALID_KEY) return notfound ; + return (int)strtol(str, NULL, 0); +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to a double + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return double + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the notfound value is returned. + */ +/*--------------------------------------------------------------------------*/ +double iniparser_getdouble(dictionary * d, char * key, double notfound) +{ + char * str ; + + str = iniparser_getstring(d, key, INI_INVALID_KEY); + if (str==INI_INVALID_KEY) return notfound ; + return atof(str); +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to a boolean + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return integer + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the notfound value is returned. + + A true boolean is found if one of the following is matched: + + - A string starting with 'y' + - A string starting with 'Y' + - A string starting with 't' + - A string starting with 'T' + - A string starting with '1' + + A false boolean is found if one of the following is matched: + + - A string starting with 'n' + - A string starting with 'N' + - A string starting with 'f' + - A string starting with 'F' + - A string starting with '0' + + The notfound value returned if no boolean is identified, does not + necessarily have to be 0 or 1. + */ +/*--------------------------------------------------------------------------*/ +int iniparser_getboolean(dictionary * d, const char * key, int notfound) +{ + char * c ; + int ret ; + + c = iniparser_getstring(d, key, INI_INVALID_KEY); + if (c==INI_INVALID_KEY) return notfound ; + if (c[0]=='y' || c[0]=='Y' || c[0]=='1' || c[0]=='t' || c[0]=='T') { + ret = 1 ; + } else if (c[0]=='n' || c[0]=='N' || c[0]=='0' || c[0]=='f' || c[0]=='F') { + ret = 0 ; + } else { + ret = notfound ; + } + return ret; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Finds out if a given entry exists in a dictionary + @param ini Dictionary to search + @param entry Name of the entry to look for + @return integer 1 if entry exists, 0 otherwise + + Finds out if a given entry exists in the dictionary. Since sections + are stored as keys with NULL associated values, this is the only way + of querying for the presence of sections in a dictionary. + */ +/*--------------------------------------------------------------------------*/ +int iniparser_find_entry( + dictionary * ini, + char * entry +) +{ + int found=0 ; + if (iniparser_getstring(ini, entry, INI_INVALID_KEY)!=INI_INVALID_KEY) { + found = 1 ; + } + return found ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Set an entry in a dictionary. + @param ini Dictionary to modify. + @param entry Entry to modify (entry name) + @param val New value to associate to the entry. + @return int 0 if Ok, -1 otherwise. + + If the given entry can be found in the dictionary, it is modified to + contain the provided value. If it cannot be found, -1 is returned. + It is Ok to set val to NULL. + */ +/*--------------------------------------------------------------------------*/ +int iniparser_set(dictionary * ini, char * entry, char * val) +{ + return dictionary_set(ini, strlwc(entry), val) ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Delete an entry in a dictionary + @param ini Dictionary to modify + @param entry Entry to delete (entry name) + @return void + + If the given entry can be found, it is deleted from the dictionary. + */ +/*--------------------------------------------------------------------------*/ +void iniparser_unset(dictionary * ini, char * entry) +{ + dictionary_unset(ini, strlwc(entry)); +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Load a single line from an INI file + @param input_line Input line, may be concatenated multi-line input + @param section Output space to store section + @param key Output space to store key + @param value Output space to store value + @return line_status value + */ +/*--------------------------------------------------------------------------*/ +static line_status iniparser_line( + char * input_line, + char * section, + char * key, + char * value) +{ + line_status sta ; + char line[ASCIILINESZ+1]; + int len ; + + strcpy(line, strstrip(input_line)); + len = (int)strlen(line); + + sta = LINE_UNPROCESSED ; + if (len<1) { + /* Empty line */ + sta = LINE_EMPTY ; + } else if (line[0]=='#') { + /* Comment line */ + sta = LINE_COMMENT ; + } else if (line[0]=='[' && line[len-1]==']') { + /* Section name */ + sscanf(line, "[%[^]]", section); + strcpy(section, strstrip(section)); + strcpy(section, strlwc(section)); + sta = LINE_SECTION ; + } else if (sscanf (line, "%[^=] = \"%[^\"]\"", key, value) == 2 + || sscanf (line, "%[^=] = '%[^\']'", key, value) == 2 + || sscanf (line, "%[^=] = %[^;#]", key, value) == 2) { + /* Usual key=value, with or without comments */ + strcpy(key, strstrip(key)); + strcpy(key, strlwc(key)); + strcpy(value, strstrip(value)); + /* + * sscanf cannot handle '' or "" as empty values + * this is done here + */ + if (!strcmp(value, "\"\"") || (!strcmp(value, "''"))) { + value[0]=0 ; + } + sta = LINE_VALUE ; + } else if (sscanf(line, "%[^=] = %[;#]", key, value)==2 + || sscanf(line, "%[^=] %[=]", key, value) == 2) { + /* + * Special cases: + * key= + * key=; + * key=# + */ + strcpy(key, strstrip(key)); + strcpy(key, strlwc(key)); + value[0]=0 ; + sta = LINE_VALUE ; + } else { + /* Generate syntax error */ + sta = LINE_ERROR ; + } + return sta ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Parse an ini file and return an allocated dictionary object + @param ininame Name of the ini file to read. + @return Pointer to newly allocated dictionary + + This is the parser for ini files. This function is called, providing + the name of the file to be read. It returns a dictionary object that + should not be accessed directly, but through accessor functions + instead. + + The returned dictionary must be freed using iniparser_freedict(). + */ +/*--------------------------------------------------------------------------*/ +dictionary * iniparser_load(const char * ininame) +{ + FILE * in ; + + char line [ASCIILINESZ+1] ; + char section [ASCIILINESZ+1] ; + char key [ASCIILINESZ+1] ; + char tmp [ASCIILINESZ+1] ; + char val [ASCIILINESZ+1] ; + + int last=0 ; + int len ; + int lineno=0 ; + int errs=0; + + dictionary * dict ; + + if ((in=fopen(ininame, "r"))==NULL) { + return NULL ; + } + + dict = dictionary_new(0) ; + if (!dict) { + fclose(in); + return NULL ; + } + + memset(line, 0, ASCIILINESZ); + memset(section, 0, ASCIILINESZ); + memset(key, 0, ASCIILINESZ); + memset(val, 0, ASCIILINESZ); + last=0 ; + + while (fgets(line+last, ASCIILINESZ-last, in)!=NULL) { + lineno++ ; + len = (int)strlen(line)-1; + /* Safety check against buffer overflows */ + if (line[len]!='\n') { + fprintf(stderr, + "iniparser: input line too long in %s (%d)\n", + ininame, + lineno); + dictionary_del(dict); + fclose(in); + return NULL ; + } + /* Get rid of \n and spaces at end of line */ + while ((len>=0) && + ((line[len]=='\n') || (isspace(line[len])))) { + line[len]=0 ; + len-- ; + } + /* Detect multi-line */ + if (line[len]=='\\') { + /* Multi-line value */ + last=len ; + continue ; + } else { + last=0 ; + } + switch (iniparser_line(line, section, key, val)) { + case LINE_EMPTY: + case LINE_COMMENT: + break ; + + case LINE_SECTION: + errs = dictionary_set(dict, section, NULL); + break ; + + case LINE_VALUE: + sprintf(tmp, "%s:%s", section, key); + errs = dictionary_set(dict, tmp, val) ; + break ; + + case LINE_ERROR: + fprintf(stderr, "iniparser: syntax error in %s (%d):\n", + ininame, + lineno); + fprintf(stderr, "-> %s\n", line); + errs++ ; + break; + + default: + break ; + } + memset(line, 0, ASCIILINESZ); + last=0; + if (errs<0) { + fprintf(stderr, "iniparser: memory allocation failure\n"); + break ; + } + } + if (errs) { + dictionary_del(dict); + dict = NULL ; + } + fclose(in); + return dict ; +} + +/*-------------------------------------------------------------------------*/ +/** + @brief Free all memory associated to an ini dictionary + @param d Dictionary to free + @return void + + Free all memory associated to an ini dictionary. + It is mandatory to call this function before the dictionary object + gets out of the current context. + */ +/*--------------------------------------------------------------------------*/ +void iniparser_freedict(dictionary * d) +{ + dictionary_del(d); +} + +/* vim: set ts=4 et sw=4 tw=75 */ diff -Nru /tmp/JbHIRqSutJ/ifupdown-0.6.8ubuntu9/iniparser.h /tmp/snYwT58QIS/ifupdown-0.6.8ubuntu10/iniparser.h --- ifupdown-0.6.8ubuntu9/iniparser.h 1970-01-01 01:00:00.000000000 +0100 +++ ifupdown-0.6.8ubuntu10/iniparser.h 2008-10-11 13:34:51.000000000 +0100 @@ -0,0 +1,302 @@ +/* + Copyright (c) 2000-2007 by Nicolas Devillard. + MIT License + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/*-------------------------------------------------------------------------*/ +/** + @file iniparser.h + @author N. Devillard + @date Sep 2007 + @version 3.0 + @brief Parser for ini files. +*/ +/*--------------------------------------------------------------------------*/ + +/* + $Id: iniparser.h,v 1.24 2007-11-23 21:38:19 ndevilla Exp $ + $Revision: 1.24 $ +*/ + +#ifndef _INIPARSER_H_ +#define _INIPARSER_H_ + +/*--------------------------------------------------------------------------- + Includes + ---------------------------------------------------------------------------*/ + +#include +#include +#include + +/* + * The following #include is necessary on many Unixes but not Linux. + * It is not needed for Windows platforms. + * Uncomment it if needed. + */ +/* #include */ + +#include "dictionary.h" + +/*--------------------------------------------------------------------------- + Macros + ---------------------------------------------------------------------------*/ +/** For backwards compatibility only */ +#define iniparser_getstr(d, k) iniparser_getstring(d, k, NULL) +#define iniparser_setstr iniparser_setstring + +/*-------------------------------------------------------------------------*/ +/** + @brief Get number of sections in a dictionary + @param d Dictionary to examine + @return int Number of sections found in dictionary + + This function returns the number of sections found in a dictionary. + The test to recognize sections is done on the string stored in the + dictionary: a section name is given as "section" whereas a key is + stored as "section:key", thus the test looks for entries that do not + contain a colon. + + This clearly fails in the case a section name contains a colon, but + this should simply be avoided. + + This function returns -1 in case of error. + */ +/*--------------------------------------------------------------------------*/ + +int iniparser_getnsec(dictionary * d); + + +/*-------------------------------------------------------------------------*/ +/** + @brief Get name for section n in a dictionary. + @param d Dictionary to examine + @param n Section number (from 0 to nsec-1). + @return Pointer to char string + + This function locates the n-th section in a dictionary and returns + its name as a pointer to a string statically allocated inside the + dictionary. Do not free or modify the returned string! + + This function returns NULL in case of error. + */ +/*--------------------------------------------------------------------------*/ + +char * iniparser_getsecname(dictionary * d, int n); + + +/*-------------------------------------------------------------------------*/ +/** + @brief Save a dictionary to a loadable ini file + @param d Dictionary to dump + @param f Opened file pointer to dump to + @return void + + This function dumps a given dictionary into a loadable ini file. + It is Ok to specify @c stderr or @c stdout as output files. + */ +/*--------------------------------------------------------------------------*/ + +void iniparser_dump_ini(dictionary * d, FILE * f); + +/*-------------------------------------------------------------------------*/ +/** + @brief Dump a dictionary to an opened file pointer. + @param d Dictionary to dump. + @param f Opened file pointer to dump to. + @return void + + This function prints out the contents of a dictionary, one element by + line, onto the provided file pointer. It is OK to specify @c stderr + or @c stdout as output files. This function is meant for debugging + purposes mostly. + */ +/*--------------------------------------------------------------------------*/ +void iniparser_dump(dictionary * d, FILE * f); + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key + @param d Dictionary to search + @param key Key string to look for + @param def Default value to return if key not found. + @return pointer to statically allocated character string + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the pointer passed as 'def' is returned. + The returned char pointer is pointing to a string allocated in + the dictionary, do not free or modify it. + */ +/*--------------------------------------------------------------------------*/ +char * iniparser_getstring(dictionary * d, const char * key, char * def); + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to an int + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return integer + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the notfound value is returned. + + Supported values for integers include the usual C notation + so decimal, octal (starting with 0) and hexadecimal (starting with 0x) + are supported. Examples: + + - "42" -> 42 + - "042" -> 34 (octal -> decimal) + - "0x42" -> 66 (hexa -> decimal) + + Warning: the conversion may overflow in various ways. Conversion is + totally outsourced to strtol(), see the associated man page for overflow + handling. + + Credits: Thanks to A. Becker for suggesting strtol() + */ +/*--------------------------------------------------------------------------*/ +int iniparser_getint(dictionary * d, const char * key, int notfound); + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to a double + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return double + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the notfound value is returned. + */ +/*--------------------------------------------------------------------------*/ +double iniparser_getdouble(dictionary * d, char * key, double notfound); + +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to a boolean + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return integer + + This function queries a dictionary for a key. A key as read from an + ini file is given as "section:key". If the key cannot be found, + the notfound value is returned. + + A true boolean is found if one of the following is matched: + + - A string starting with 'y' + - A string starting with 'Y' + - A string starting with 't' + - A string starting with 'T' + - A string starting with '1' + + A false boolean is found if one of the following is matched: + + - A string starting with 'n' + - A string starting with 'N' + - A string starting with 'f' + - A string starting with 'F' + - A string starting with '0' + + The notfound value returned if no boolean is identified, does not + necessarily have to be 0 or 1. + */ +/*--------------------------------------------------------------------------*/ +int iniparser_getboolean(dictionary * d, const char * key, int notfound); + + +/*-------------------------------------------------------------------------*/ +/** + @brief Set an entry in a dictionary. + @param ini Dictionary to modify. + @param entry Entry to modify (entry name) + @param val New value to associate to the entry. + @return int 0 if Ok, -1 otherwise. + + If the given entry can be found in the dictionary, it is modified to + contain the provided value. If it cannot be found, -1 is returned. + It is Ok to set val to NULL. + */ +/*--------------------------------------------------------------------------*/ +int iniparser_setstring(dictionary * ini, char * entry, char * val); + + +/*-------------------------------------------------------------------------*/ +/** + @brief Delete an entry in a dictionary + @param ini Dictionary to modify + @param entry Entry to delete (entry name) + @return void + + If the given entry can be found, it is deleted from the dictionary. + */ +/*--------------------------------------------------------------------------*/ +void iniparser_unset(dictionary * ini, char * entry); + +/*-------------------------------------------------------------------------*/ +/** + @brief Finds out if a given entry exists in a dictionary + @param ini Dictionary to search + @param entry Name of the entry to look for + @return integer 1 if entry exists, 0 otherwise + + Finds out if a given entry exists in the dictionary. Since sections + are stored as keys with NULL associated values, this is the only way + of querying for the presence of sections in a dictionary. + */ +/*--------------------------------------------------------------------------*/ +int iniparser_find_entry(dictionary * ini, char * entry) ; + +/*-------------------------------------------------------------------------*/ +/** + @brief Parse an ini file and return an allocated dictionary object + @param ininame Name of the ini file to read. + @return Pointer to newly allocated dictionary + + This is the parser for ini files. This function is called, providing + the name of the file to be read. It returns a dictionary object that + should not be accessed directly, but through accessor functions + instead. + + The returned dictionary must be freed using iniparser_freedict(). + */ +/*--------------------------------------------------------------------------*/ +dictionary * iniparser_load(const char * ininame); + +/*-------------------------------------------------------------------------*/ +/** + @brief Free all memory associated to an ini dictionary + @param d Dictionary to free + @return void + + Free all memory associated to an ini dictionary. + It is mandatory to call this function before the dictionary object + gets out of the current context. + */ +/*--------------------------------------------------------------------------*/ +void iniparser_freedict(dictionary * d); + +#endif diff -Nru /tmp/JbHIRqSutJ/ifupdown-0.6.8ubuntu9/main.c /tmp/snYwT58QIS/ifupdown-0.6.8ubuntu10/main.c --- ifupdown-0.6.8ubuntu9/main.c 2008-06-21 23:30:44.000000000 +0100 +++ ifupdown-0.6.8ubuntu10/main.c 2008-10-11 13:34:51.000000000 +0100 @@ -1,4 +1,4 @@ -#line 3004 "ifupdown.nw" +#line 3005 "ifupdown.nw" #include #include #include @@ -7,34 +7,38 @@ #include #include "header.h" -#line 3043 "ifupdown.nw" + +#include "iniparser.h" +#line 3046 "ifupdown.nw" #include #include -#line 3169 "ifupdown.nw" +#line 3172 "ifupdown.nw" #include -#line 3441 "ifupdown.nw" +#line 3470 "ifupdown.nw" #include -#line 3198 "ifupdown.nw" +#line 3201 "ifupdown.nw" int no_act = 0; int verbose = 0; char *statefile = "/var/run/network/ifstate"; char *tmpstatefile = "/var/run/network/.ifstate.tmp"; -#line 3217 "ifupdown.nw" +char *nm_system_settings = "/etc/NetworkManager/nm-system-settings.conf"; +#line 3221 "ifupdown.nw" static void usage(char *execname); static void help(char *execname); static void version(char *execname); -#line 3596 "ifupdown.nw" +static int auto_disabled (); +#line 3629 "ifupdown.nw" static const char *read_state(const char *argv0, const char *iface); static void read_all_state(const char *argv0, char ***ifaces, int *n_ifaces); static void update_state(const char *argv0, const char *iface, const char *liface); -#line 3715 "ifupdown.nw" +#line 3748 "ifupdown.nw" static int lock_fd (int fd); -#line 3223 "ifupdown.nw" +#line 3228 "ifupdown.nw" static void usage(char *execname) { fprintf(stderr, "%s: Use --help for help\n", execname); exit(1); } -#line 3230 "ifupdown.nw" +#line 3235 "ifupdown.nw" static void version(char *execname) { printf("%s version " IFUPDOWN_VERSION "\n", execname); printf("Copyright (c) 1999-2005 Anthony Towns\n\n"); @@ -48,7 +52,7 @@ ); exit(0); } -#line 3246 "ifupdown.nw" +#line 3251 "ifupdown.nw" static void help(char *execname) { printf("Usage: %s \n\n", execname); printf("Options:\n"); @@ -64,14 +68,36 @@ printf("\t--force\t\t\tforce de/configuration\n"); exit(0); } -#line 3607 "ifupdown.nw" +#line 3269 "ifupdown.nw" +static int auto_disabled() { + static int initialized = 0; + static int auto_up_disabled = 0; + + if (!initialized) { + dictionary *ini_dict; + initialized = 1; + + ini_dict = iniparser_load (nm_system_settings); + if (ini_dict) { + int managed = iniparser_getboolean (ini_dict, "ifupdown:managed", -1); + auto_up_disabled = managed ? 1 : 0; + iniparser_freedict (ini_dict); + ini_dict = 0; + } else { + auto_up_disabled = 0; + } + } + + return auto_up_disabled; +} +#line 3640 "ifupdown.nw" static const char * read_state (const char *argv0, const char *iface) { char *ret = NULL; -#line 3736 "ifupdown.nw" +#line 3769 "ifupdown.nw" FILE *state_fp; char buf[80]; char *p; @@ -107,10 +133,10 @@ } } -#line 3614 "ifupdown.nw" +#line 3647 "ifupdown.nw" while((p = fgets(buf, sizeof buf, state_fp)) != NULL) { -#line 3773 "ifupdown.nw" +#line 3806 "ifupdown.nw" char *pch; pch = buf + strlen(buf) - 1; @@ -120,7 +146,7 @@ pch = buf; while(isspace(*pch)) pch++; -#line 3617 "ifupdown.nw" +#line 3650 "ifupdown.nw" if (strncmp(iface, pch, strlen(iface)) == 0) { if (pch[strlen(iface)] == '=') { ret = pch + strlen(iface) + 1; @@ -130,22 +156,22 @@ } -#line 3784 "ifupdown.nw" +#line 3817 "ifupdown.nw" noact: if (state_fp != NULL) { fclose(state_fp); state_fp = NULL; } -#line 3627 "ifupdown.nw" +#line 3660 "ifupdown.nw" return ret; } -#line 3635 "ifupdown.nw" +#line 3668 "ifupdown.nw" static void read_all_state (const char *argv0, char ***ifaces, int *n_ifaces) { -#line 3736 "ifupdown.nw" +#line 3769 "ifupdown.nw" FILE *state_fp; char buf[80]; char *p; @@ -181,13 +207,13 @@ } } -#line 3640 "ifupdown.nw" +#line 3673 "ifupdown.nw" *n_ifaces = 0; *ifaces = NULL; while((p = fgets(buf, sizeof buf, state_fp)) != NULL) { -#line 3773 "ifupdown.nw" +#line 3806 "ifupdown.nw" char *pch; pch = buf + strlen(buf) - 1; @@ -197,28 +223,28 @@ pch = buf; while(isspace(*pch)) pch++; -#line 3646 "ifupdown.nw" +#line 3679 "ifupdown.nw" (*n_ifaces)++; *ifaces = realloc (*ifaces, sizeof (**ifaces) * *n_ifaces); (*ifaces)[(*n_ifaces)-1] = strdup (pch); } -#line 3784 "ifupdown.nw" +#line 3817 "ifupdown.nw" noact: if (state_fp != NULL) { fclose(state_fp); state_fp = NULL; } -#line 3652 "ifupdown.nw" +#line 3685 "ifupdown.nw" } -#line 3662 "ifupdown.nw" +#line 3695 "ifupdown.nw" static void update_state(const char *argv0, const char *iface, const char *state) { FILE *tmp_fp; -#line 3736 "ifupdown.nw" +#line 3769 "ifupdown.nw" FILE *state_fp; char buf[80]; char *p; @@ -254,7 +280,7 @@ } } -#line 3668 "ifupdown.nw" +#line 3701 "ifupdown.nw" if (no_act) goto noact; @@ -268,7 +294,7 @@ while((p = fgets(buf, sizeof buf, state_fp)) != NULL) { -#line 3773 "ifupdown.nw" +#line 3806 "ifupdown.nw" char *pch; pch = buf + strlen(buf) - 1; @@ -278,7 +304,7 @@ pch = buf; while(isspace(*pch)) pch++; -#line 3682 "ifupdown.nw" +#line 3715 "ifupdown.nw" if (strncmp(iface, pch, strlen(iface)) == 0) { if (pch[strlen(iface)] == '=') { if (state != NULL) { @@ -306,15 +332,15 @@ } -#line 3784 "ifupdown.nw" +#line 3817 "ifupdown.nw" noact: if (state_fp != NULL) { fclose(state_fp); state_fp = NULL; } -#line 3709 "ifupdown.nw" +#line 3742 "ifupdown.nw" } -#line 3719 "ifupdown.nw" +#line 3752 "ifupdown.nw" static int lock_fd (int fd) { struct flock lock; @@ -329,12 +355,12 @@ return 0; } -#line 3021 "ifupdown.nw" +#line 3024 "ifupdown.nw" int main(int argc, char **argv) { -#line 3079 "ifupdown.nw" +#line 3082 "ifupdown.nw" int (*cmds)(interface_defn *) = NULL; -#line 3173 "ifupdown.nw" +#line 3176 "ifupdown.nw" struct option long_opts[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, @@ -348,22 +374,22 @@ {"force", no_argument, NULL, 2 }, {0,0,0,0} }; -#line 3205 "ifupdown.nw" +#line 3209 "ifupdown.nw" int do_all = 0; int run_mappings = 1; int force = 0; char *allow_class = NULL; char *interfaces = "/etc/network/interfaces"; char *excludeint = NULL ; -#line 3371 "ifupdown.nw" +#line 3400 "ifupdown.nw" interfaces_file *defn; -#line 3533 "ifupdown.nw" +#line 3562 "ifupdown.nw" int n_target_ifaces; char **target_iface; -#line 3024 "ifupdown.nw" +#line 3027 "ifupdown.nw" -#line 3048 "ifupdown.nw" +#line 3051 "ifupdown.nw" { int i; for (i = 0; i <= 2; i++) { @@ -384,22 +410,22 @@ } } -#line 3026 "ifupdown.nw" +#line 3029 "ifupdown.nw" -#line 3085 "ifupdown.nw" +#line 3088 "ifupdown.nw" { char *command; -#line 3096 "ifupdown.nw" +#line 3099 "ifupdown.nw" if ((command = strrchr(argv[0],'/'))) { command++; /* first char after / */ } else { command = argv[0]; /* no /'s in argv[0] */ } -#line 3089 "ifupdown.nw" +#line 3092 "ifupdown.nw" -#line 3104 "ifupdown.nw" +#line 3107 "ifupdown.nw" if (strcmp(command, "ifup")==0) { cmds = iface_up; } else if (strcmp(command, "ifdown")==0) { @@ -408,11 +434,11 @@ fprintf(stderr,"This command should be called as ifup or ifdown\n"); exit(1); } -#line 3090 "ifupdown.nw" +#line 3093 "ifupdown.nw" } -#line 3027 "ifupdown.nw" +#line 3030 "ifupdown.nw" -#line 3267 "ifupdown.nw" +#line 3296 "ifupdown.nw" for(;;) { int c; c = getopt_long(argc, argv, "e:s:i:hVvna", long_opts, NULL); @@ -420,66 +446,66 @@ switch(c) { -#line 3285 "ifupdown.nw" +#line 3314 "ifupdown.nw" case 'i': interfaces = strdup(optarg); break; -#line 3290 "ifupdown.nw" +#line 3319 "ifupdown.nw" case 'v': verbose = 1; break; -#line 3295 "ifupdown.nw" +#line 3324 "ifupdown.nw" case 'a': do_all = 1; break; -#line 3300 "ifupdown.nw" +#line 3329 "ifupdown.nw" case 3: allow_class = strdup(optarg); break; -#line 3305 "ifupdown.nw" +#line 3334 "ifupdown.nw" case 'n': no_act = 1; break; -#line 3310 "ifupdown.nw" +#line 3339 "ifupdown.nw" case 1: run_mappings = 0; break; -#line 3315 "ifupdown.nw" +#line 3344 "ifupdown.nw" case 2: force = 1; break; -#line 3320 "ifupdown.nw" +#line 3349 "ifupdown.nw" case 'e': excludeint = strdup(optarg); break; -#line 3328 "ifupdown.nw" +#line 3357 "ifupdown.nw" case 'h': help(argv[0]); break; -#line 3333 "ifupdown.nw" +#line 3362 "ifupdown.nw" case 'V': version(argv[0]); break; -#line 3342 "ifupdown.nw" +#line 3371 "ifupdown.nw" default: usage(argv[0]); break; -#line 3274 "ifupdown.nw" +#line 3303 "ifupdown.nw" } } -#line 3354 "ifupdown.nw" +#line 3383 "ifupdown.nw" if (argc - optind > 0 && do_all) { usage(argv[0]); } -#line 3360 "ifupdown.nw" +#line 3389 "ifupdown.nw" if (argc - optind == 0 && !do_all) { usage(argv[0]); } -#line 3029 "ifupdown.nw" +#line 3032 "ifupdown.nw" -#line 3375 "ifupdown.nw" +#line 3404 "ifupdown.nw" defn = read_interfaces(interfaces); if ( !defn ) { fprintf(stderr, "%s: couldn't read interfaces file \"%s\"\n", @@ -487,24 +513,28 @@ exit(1); } -#line 3031 "ifupdown.nw" +#line 3034 "ifupdown.nw" -#line 3544 "ifupdown.nw" +#line 3573 "ifupdown.nw" if (do_all) { - if ( -#line 3119 "ifupdown.nw" + if (( +#line 3122 "ifupdown.nw" (cmds == iface_up) -#line 3545 "ifupdown.nw" - ) { +#line 3574 "ifupdown.nw" + ) && auto_disabled() == 0) { allowup_defn *autos = find_allowup(defn, "auto"); target_iface = autos ? autos->interfaces : NULL; n_target_ifaces = autos ? autos->n_interfaces : 0; } else if ( -#line 3123 "ifupdown.nw" +#line 3126 "ifupdown.nw" (cmds == iface_down) -#line 3549 "ifupdown.nw" +#line 3578 "ifupdown.nw" ) { read_all_state(argv[0], &target_iface, &n_target_ifaces); + } else if (auto_disabled() != 0) { + printf("WARNING: ifup -a is disabled in favour of NetworkManager.\n" + " Set ifupdown:managed=false in /etc/NetworkManager/nm-system-settings.conf.\n"); + exit (0); } else { assert(0); } @@ -512,19 +542,19 @@ target_iface = argv + optind; n_target_ifaces = argc - optind; } -#line 3389 "ifupdown.nw" +#line 3418 "ifupdown.nw" { int i; for ( -#line 3538 "ifupdown.nw" +#line 3567 "ifupdown.nw" i = 0; i < n_target_ifaces; i++ -#line 3391 "ifupdown.nw" +#line 3420 "ifupdown.nw" ) { char iface[80], liface[80]; const char *current_state; -#line 3561 "ifupdown.nw" +#line 3594 "ifupdown.nw" strncpy(iface, target_iface[i], sizeof(iface)); iface[sizeof(iface)-1] = '\0'; @@ -539,16 +569,16 @@ liface[sizeof(liface)-1] = '\0'; } } -#line 3396 "ifupdown.nw" +#line 3425 "ifupdown.nw" current_state = read_state(argv[0], iface); if (!force) { -#line 3796 "ifupdown.nw" +#line 3829 "ifupdown.nw" { if ( -#line 3119 "ifupdown.nw" +#line 3122 "ifupdown.nw" (cmds == iface_up) -#line 3797 "ifupdown.nw" +#line 3830 "ifupdown.nw" ) { if (current_state != NULL) { if (!do_all) { @@ -559,9 +589,9 @@ continue; } } else if ( -#line 3123 "ifupdown.nw" +#line 3126 "ifupdown.nw" (cmds == iface_down) -#line 3806 "ifupdown.nw" +#line 3839 "ifupdown.nw" ) { if (current_state == NULL) { if (!do_all) { @@ -576,17 +606,17 @@ assert(0); } } -#line 3399 "ifupdown.nw" +#line 3428 "ifupdown.nw" } if ( -#line 3132 "ifupdown.nw" +#line 3135 "ifupdown.nw" (allow_class != NULL) -#line 3401 "ifupdown.nw" +#line 3430 "ifupdown.nw" ) { -#line 3135 "ifupdown.nw" +#line 3138 "ifupdown.nw" { int i; allowup_defn *allowup = find_allowup(defn, allow_class); @@ -600,62 +630,62 @@ if (i >= allowup->n_interfaces) continue; } -#line 3403 "ifupdown.nw" +#line 3432 "ifupdown.nw" } if ( -#line 3157 "ifupdown.nw" +#line 3160 "ifupdown.nw" (excludeint != NULL && strstr(iface,excludeint) != NULL) -#line 3405 "ifupdown.nw" +#line 3434 "ifupdown.nw" ) continue; if ( -#line 3119 "ifupdown.nw" +#line 3122 "ifupdown.nw" (cmds == iface_up) -#line 3408 "ifupdown.nw" +#line 3437 "ifupdown.nw" && run_mappings) { -#line 3424 "ifupdown.nw" +#line 3453 "ifupdown.nw" { mapping_defn *currmap; for (currmap = defn->mappings; currmap; currmap = currmap->next) { int i; for (i = 0; i < currmap->n_matches; i++) { -#line 3445 "ifupdown.nw" +#line 3474 "ifupdown.nw" if (fnmatch(currmap->match[i], liface, 0) != 0) continue; -#line 3430 "ifupdown.nw" +#line 3459 "ifupdown.nw" -#line 3453 "ifupdown.nw" +#line 3482 "ifupdown.nw" if (verbose) { fprintf(stderr, "Running mapping script %s on %s\n", currmap->script, liface); } run_mapping(iface, liface, sizeof(liface), currmap); -#line 3431 "ifupdown.nw" +#line 3460 "ifupdown.nw" break; } } } -#line 3410 "ifupdown.nw" +#line 3439 "ifupdown.nw" } -#line 3463 "ifupdown.nw" +#line 3492 "ifupdown.nw" { interface_defn *currif; int okay = 0; int failed = 0; -#line 3826 "ifupdown.nw" +#line 3859 "ifupdown.nw" { if ( -#line 3119 "ifupdown.nw" +#line 3122 "ifupdown.nw" (cmds == iface_up) -#line 3827 "ifupdown.nw" +#line 3860 "ifupdown.nw" ) { if (current_state == NULL) { if (failed == 1) { @@ -668,9 +698,9 @@ update_state (argv[0], iface, liface); } } else if ( -#line 3123 "ifupdown.nw" +#line 3126 "ifupdown.nw" (cmds == iface_down) -#line 3838 "ifupdown.nw" +#line 3871 "ifupdown.nw" ) { update_state (argv[0], iface, NULL); } else { @@ -678,13 +708,13 @@ } } -#line 3470 "ifupdown.nw" +#line 3499 "ifupdown.nw" for (currif = defn->ifaces; currif; currif = currif->next) { if (strcmp(liface, currif->logical_iface) == 0) { okay = 1; -#line 3493 "ifupdown.nw" +#line 3522 "ifupdown.nw" { currif->real_iface = iface; @@ -716,7 +746,7 @@ currif->real_iface = NULL; } -#line 3476 "ifupdown.nw" +#line 3505 "ifupdown.nw" if (failed) break; /* Otherwise keep going: this interface may have * match with other address families */ @@ -729,12 +759,12 @@ update_state (argv[0], iface, NULL); } else { -#line 3826 "ifupdown.nw" +#line 3859 "ifupdown.nw" { if ( -#line 3119 "ifupdown.nw" +#line 3122 "ifupdown.nw" (cmds == iface_up) -#line 3827 "ifupdown.nw" +#line 3860 "ifupdown.nw" ) { if (current_state == NULL) { if (failed == 1) { @@ -747,22 +777,22 @@ update_state (argv[0], iface, liface); } } else if ( -#line 3123 "ifupdown.nw" +#line 3126 "ifupdown.nw" (cmds == iface_down) -#line 3838 "ifupdown.nw" +#line 3871 "ifupdown.nw" ) { update_state (argv[0], iface, NULL); } else { assert(0); } } -#line 3488 "ifupdown.nw" +#line 3517 "ifupdown.nw" } } -#line 3413 "ifupdown.nw" +#line 3442 "ifupdown.nw" } } -#line 3033 "ifupdown.nw" +#line 3036 "ifupdown.nw" return 0; } diff -Nru /tmp/JbHIRqSutJ/ifupdown-0.6.8ubuntu9/Makefile /tmp/snYwT58QIS/ifupdown-0.6.8ubuntu10/Makefile --- ifupdown-0.6.8ubuntu9/Makefile 2008-06-21 23:30:44.000000000 +0100 +++ ifupdown-0.6.8ubuntu10/Makefile 2008-10-11 13:34:51.000000000 +0100 @@ -7,7 +7,8 @@ DEFNFILES := inet.defn ipx.defn inet6.defn OBJ := main.o addrfam.o execute.o config.o \ - $(patsubst %.defn,%.o,$(DEFNFILES)) archlinux.o + $(patsubst %.defn,%.o,$(DEFNFILES)) archlinux.o \ + dictionary.o iniparser.o MAN := $(patsubst %.defn,%.man,$(DEFNFILES))