aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/ifupdown.c146
1 files changed, 51 insertions, 95 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 68ea01a67..a794bf76a 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -584,32 +584,24 @@ static const struct address_family_t addr_inet = {
584 584
585static char *next_word(char **buf) 585static char *next_word(char **buf)
586{ 586{
587 unsigned short length; 587 unsigned length;
588 char *word; 588 char *word;
589 589
590 if (!buf || !*buf || !**buf) {
591 return NULL;
592 }
593
594 /* Skip over leading whitespace */ 590 /* Skip over leading whitespace */
595 word = skip_whitespace(*buf); 591 word = skip_whitespace(*buf);
596 592
597 /* Skip over comments */ 593 /* Stop on EOL/comments */
598 if (*word == '#') { 594 if (*word == '#' || *word == '\0')
599 return NULL; 595 return NULL;
600 }
601 596
602 /* Find the length of this word */ 597 /* Find the length of this word (can't be 0) */
603 length = strcspn(word, " \t\n"); 598 length = strcspn(word, " \t\n");
604 if (length == 0) { 599
605 return NULL; 600 /* Unless we are already at NUL, store NUL and advance */
606 } 601 if (word[length] != '\0')
602 word[length++] = '\0';
603
607 *buf = word + length; 604 *buf = word + length;
608 /*DBU:[dave@cray.com] if we are already at EOL dont't increment beyond it */
609 if (**buf) {
610 **buf = '\0';
611 (*buf)++;
612 }
613 605
614 return word; 606 return word;
615} 607}
@@ -686,27 +678,26 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
686 678
687 if (strcmp(firstword, "mapping") == 0) { 679 if (strcmp(firstword, "mapping") == 0) {
688#if ENABLE_FEATURE_IFUPDOWN_MAPPING 680#if ENABLE_FEATURE_IFUPDOWN_MAPPING
689 currmap = xzalloc(sizeof(struct mapping_defn_t)); 681 currmap = xzalloc(sizeof(*currmap));
690 682
691 while ((firstword = next_word(&buf_ptr)) != NULL) { 683 while ((firstword = next_word(&buf_ptr)) != NULL) {
692 if (currmap->max_matches == currmap->n_matches) { 684 if (currmap->n_matches >= currmap->max_matches) {
693 currmap->max_matches = currmap->max_matches * 2 + 1; 685 currmap->max_matches = currmap->max_matches * 2 + 1;
694 currmap->match = xrealloc(currmap->match, sizeof(currmap->match) * currmap->max_matches); 686 currmap->match = xrealloc(currmap->match, sizeof(*currmap->match) * currmap->max_matches);
695 } 687 }
696
697 currmap->match[currmap->n_matches++] = xstrdup(firstword); 688 currmap->match[currmap->n_matches++] = xstrdup(firstword);
698 } 689 }
699 currmap->max_mappings = 0; 690 /*currmap->max_mappings = 0; - done by xzalloc */
700 currmap->n_mappings = 0; 691 /*currmap->n_mappings = 0;*/
701 currmap->mapping = NULL; 692 /*currmap->mapping = NULL;*/
702 currmap->script = NULL; 693 /*currmap->script = NULL;*/
703 { 694 {
704 struct mapping_defn_t **where = &defn->mappings; 695 struct mapping_defn_t **where = &defn->mappings;
705 while (*where != NULL) { 696 while (*where != NULL) {
706 where = &(*where)->next; 697 where = &(*where)->next;
707 } 698 }
708 *where = currmap; 699 *where = currmap;
709 currmap->next = NULL; 700 /*currmap->next = NULL;*/
710 } 701 }
711 debug_noise("Added mapping\n"); 702 debug_noise("Added mapping\n");
712#endif 703#endif
@@ -727,44 +718,36 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
727 char *method_name; 718 char *method_name;
728 llist_t *iface_list; 719 llist_t *iface_list;
729 720
730 currif = xzalloc(sizeof(struct interface_defn_t)); 721 currif = xzalloc(sizeof(*currif));
731 iface_name = next_word(&buf_ptr); 722 iface_name = next_word(&buf_ptr);
732 address_family_name = next_word(&buf_ptr); 723 address_family_name = next_word(&buf_ptr);
733 method_name = next_word(&buf_ptr); 724 method_name = next_word(&buf_ptr);
734 725
735 if (buf_ptr == NULL) { 726 if (method_name == NULL)
736 bb_error_msg("too few parameters for line \"%s\"", buf); 727 bb_error_msg_and_die("too few parameters for line \"%s\"", buf);
737 return NULL;
738 }
739 728
740 /* ship any trailing whitespace */ 729 /* ship any trailing whitespace */
741 buf_ptr = skip_whitespace(buf_ptr); 730 buf_ptr = skip_whitespace(buf_ptr);
742 731
743 if (buf_ptr[0] != '\0') { 732 if (buf_ptr[0] != '\0' /* && buf_ptr[0] != '#' */)
744 bb_error_msg("too many parameters \"%s\"", buf); 733 bb_error_msg_and_die("too many parameters \"%s\"", buf);
745 return NULL;
746 }
747 734
748 currif->iface = xstrdup(iface_name); 735 currif->iface = xstrdup(iface_name);
749 736
750 currif->address_family = get_address_family(addr_fams, address_family_name); 737 currif->address_family = get_address_family(addr_fams, address_family_name);
751 if (!currif->address_family) { 738 if (!currif->address_family)
752 bb_error_msg("unknown address type \"%s\"", address_family_name); 739 bb_error_msg_and_die("unknown address type \"%s\"", address_family_name);
753 return NULL;
754 }
755 740
756 currif->method = get_method(currif->address_family, method_name); 741 currif->method = get_method(currif->address_family, method_name);
757 if (!currif->method) { 742 if (!currif->method)
758 bb_error_msg("unknown method \"%s\"", method_name); 743 bb_error_msg_and_die("unknown method \"%s\"", method_name);
759 return NULL;
760 }
761 744
762 for (iface_list = defn->ifaces; iface_list; iface_list = iface_list->link) { 745 for (iface_list = defn->ifaces; iface_list; iface_list = iface_list->link) {
763 struct interface_defn_t *tmp = (struct interface_defn_t *) iface_list->data; 746 struct interface_defn_t *tmp = (struct interface_defn_t *) iface_list->data;
764 if ((strcmp(tmp->iface, currif->iface) == 0) && 747 if ((strcmp(tmp->iface, currif->iface) == 0)
765 (tmp->address_family == currif->address_family)) { 748 && (tmp->address_family == currif->address_family)
766 bb_error_msg("duplicate interface \"%s\"", tmp->iface); 749 ) {
767 return NULL; 750 bb_error_msg_and_die("duplicate interface \"%s\"", tmp->iface);
768 } 751 }
769 } 752 }
770 llist_add_to_end(&(defn->ifaces), (char*)currif); 753 llist_add_to_end(&(defn->ifaces), (char*)currif);
@@ -787,73 +770,50 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
787 } else { 770 } else {
788 switch (currently_processing) { 771 switch (currently_processing) {
789 case IFACE: 772 case IFACE:
790 { 773 if (buf_ptr[0] == '\0')
774 bb_error_msg_and_die("option with empty value \"%s\"", buf);
775
776 if (strcmp(firstword, "up") != 0
777 && strcmp(firstword, "down") != 0
778 && strcmp(firstword, "pre-up") != 0
779 && strcmp(firstword, "post-down") != 0
780 ) {
791 int i; 781 int i;
792 782 for (i = 0; i < currif->n_options; i++) {
793 if (strlen(buf_ptr) == 0) { 783 if (strcmp(currif->option[i].name, firstword) == 0)
794 bb_error_msg("option with empty value \"%s\"", buf); 784 bb_error_msg_and_die("duplicate option \"%s\"", buf);
795 return NULL;
796 }
797
798 if (strcmp(firstword, "up") != 0
799 && strcmp(firstword, "down") != 0
800 && strcmp(firstword, "pre-up") != 0
801 && strcmp(firstword, "post-down") != 0) {
802 for (i = 0; i < currif->n_options; i++) {
803 if (strcmp(currif->option[i].name, firstword) == 0) {
804 bb_error_msg("duplicate option \"%s\"", buf);
805 return NULL;
806 }
807 }
808 } 785 }
809 } 786 }
810 if (currif->n_options >= currif->max_options) { 787 if (currif->n_options >= currif->max_options) {
811 struct variable_t *opt; 788 currif->max_options += 10;
812 789 currif->option = xrealloc(currif->option, sizeof(*currif->option) * currif->max_options);
813 currif->max_options = currif->max_options + 10;
814 opt = xrealloc(currif->option, sizeof(*opt) * currif->max_options);
815 currif->option = opt;
816 } 790 }
791 debug_noise("\t%s=%s\n", firstword, buf_ptr);
817 currif->option[currif->n_options].name = xstrdup(firstword); 792 currif->option[currif->n_options].name = xstrdup(firstword);
818 currif->option[currif->n_options].value = xstrdup(buf_ptr); 793 currif->option[currif->n_options].value = xstrdup(buf_ptr);
819 if (!currif->option[currif->n_options].name) {
820 perror(filename);
821 return NULL;
822 }
823 if (!currif->option[currif->n_options].value) {
824 perror(filename);
825 return NULL;
826 }
827 debug_noise("\t%s=%s\n", currif->option[currif->n_options].name,
828 currif->option[currif->n_options].value);
829 currif->n_options++; 794 currif->n_options++;
830 break; 795 break;
831 case MAPPING: 796 case MAPPING:
832#if ENABLE_FEATURE_IFUPDOWN_MAPPING 797#if ENABLE_FEATURE_IFUPDOWN_MAPPING
833 if (strcmp(firstword, "script") == 0) { 798 if (strcmp(firstword, "script") == 0) {
834 if (currmap->script != NULL) { 799 if (currmap->script != NULL)
835 bb_error_msg("duplicate script in mapping \"%s\"", buf); 800 bb_error_msg_and_die("duplicate script in mapping \"%s\"", buf);
836 return NULL; 801 currmap->script = xstrdup(next_word(&buf_ptr));
837 } else {
838 currmap->script = xstrdup(next_word(&buf_ptr));
839 }
840 } else if (strcmp(firstword, "map") == 0) { 802 } else if (strcmp(firstword, "map") == 0) {
841 if (currmap->max_mappings == currmap->n_mappings) { 803 if (currmap->n_mappings >= currmap->max_mappings) {
842 currmap->max_mappings = currmap->max_mappings * 2 + 1; 804 currmap->max_mappings = currmap->max_mappings * 2 + 1;
843 currmap->mapping = xrealloc(currmap->mapping, sizeof(char *) * currmap->max_mappings); 805 currmap->mapping = xrealloc(currmap->mapping, sizeof(char *) * currmap->max_mappings);
844 } 806 }
845 currmap->mapping[currmap->n_mappings] = xstrdup(next_word(&buf_ptr)); 807 currmap->mapping[currmap->n_mappings] = xstrdup(next_word(&buf_ptr));
846 currmap->n_mappings++; 808 currmap->n_mappings++;
847 } else { 809 } else {
848 bb_error_msg("misplaced option \"%s\"", buf); 810 bb_error_msg_and_die("misplaced option \"%s\"", buf);
849 return NULL;
850 } 811 }
851#endif 812#endif
852 break; 813 break;
853 case NONE: 814 case NONE:
854 default: 815 default:
855 bb_error_msg("misplaced option \"%s\"", buf); 816 bb_error_msg_and_die("misplaced option \"%s\"", buf);
856 return NULL;
857 } 817 }
858 } 818 }
859 free(buf); 819 free(buf);
@@ -1138,7 +1098,7 @@ static llist_t *read_iface_state(void)
1138int ifupdown_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 1098int ifupdown_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1139int ifupdown_main(int argc, char **argv) 1099int ifupdown_main(int argc, char **argv)
1140{ 1100{
1141 int (*cmds)(struct interface_defn_t *) = NULL; 1101 int (*cmds)(struct interface_defn_t *);
1142 struct interfaces_file_t *defn; 1102 struct interfaces_file_t *defn;
1143 llist_t *target_list = NULL; 1103 llist_t *target_list = NULL;
1144 const char *interfaces = "/etc/network/interfaces"; 1104 const char *interfaces = "/etc/network/interfaces";
@@ -1161,10 +1121,6 @@ int ifupdown_main(int argc, char **argv)
1161 defn = read_interfaces(interfaces); 1121 defn = read_interfaces(interfaces);
1162 debug_noise("\ndone reading %s\n\n", interfaces); 1122 debug_noise("\ndone reading %s\n\n", interfaces);
1163 1123
1164 if (!defn) {
1165 return EXIT_FAILURE;
1166 }
1167
1168 startup_PATH = getenv("PATH"); 1124 startup_PATH = getenv("PATH");
1169 if (!startup_PATH) startup_PATH = ""; 1125 if (!startup_PATH) startup_PATH = "";
1170 1126