~ubuntu-branches/ubuntu/wily/trafficserver/wily

« back to all changes in this revision

Viewing changes to mgmt/tools/ConfigAPI.cc

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2012-12-17 22:28:16 UTC
  • mfrom: (5.1.8 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121217222816-7xwjsx5k76zkb63d
Tags: 3.2.0-1ubuntu1
* Revert FreeBSD strerror_r() fixes that give errors with glibc 2.16.
* Apply patch from Konstantinos Margaritis to define barriers on ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
  limitations under the License.
22
22
 */
23
23
 
24
 
#if defined(linux) || defined(solaris) || defined(freebsd) || defined(darwin)
 
24
#if defined(linux) || defined(solaris) || defined(freebsd) || defined(darwin) \
 
25
 || defined(openbsd)
25
26
 
26
27
#include "libts.h"
27
28
#include "I_Layout.h"
84
85
  //printf("Inside Config_SetHostname(), hostname = %s\n", hostname);
85
86
 
86
87
  //validate
87
 
  ink_strncpy(old_hostname, "", sizeof(old_hostname));
 
88
  ink_strlcpy(old_hostname, "", sizeof(old_hostname));
88
89
  if (hostname == NULL)
89
90
    return -1;
90
91
 
140
141
  status = Config_GetDefaultRouter(old_router, sizeof(old_router));
141
142
  if (status) {
142
143
    DPRINTF(("Config_SetDefaultRouter: Couldn't read old router name\n"));
143
 
    ink_strncpy(old_router, "", sizeof(old_router));
 
144
    ink_strlcpy(old_router, "", sizeof(old_router));
144
145
  }
145
146
 
146
147
  DPRINTF(("Config_SetDefaultRouter: router %s\n", router));
188
189
  status = Config_GetDomain(old_domain, sizeof(old_domain));
189
190
  if (status) {
190
191
    DPRINTF(("Config_SetDomain: Couldn't retrieve old domain\n"));
191
 
    ink_strncpy(old_domain, "", sizeof(old_domain));
 
192
    ink_strlcpy(old_domain, "", sizeof(old_domain));
192
193
  }
193
194
  status = Net_SetDomain(domain);
194
195
  if (status) {
233
234
  status = Config_GetDNS_Servers(old_dns, sizeof(old_dns));
234
235
  if (status) {
235
236
    DPRINTF(("Config_SetDNS_Servers: falied to retrieve old dns name\n"));
236
 
    ink_strncpy(old_dns, "", sizeof(old_dns));
 
237
    ink_strlcpy(old_dns, "", sizeof(old_dns));
237
238
  }
238
239
  status = Net_SetDNS_Servers(dns);
239
240
  if (status) {
483
484
               const size_t secondSize)
484
485
{
485
486
  int status = -1;
486
 
#if !defined(freebsd) && !defined(darwin) && !defined(solaris)
487
487
  status = Time_GetTime(hour, hourSize, minute, minuteSize, second, secondSize);
488
 
#endif
489
488
  return status;
490
489
}
491
490
 
497
496
  if (hour == NULL || minute == NULL || second == NULL) {
498
497
    return -1;
499
498
  }
500
 
#if !defined(freebsd) && !defined(darwin)
501
499
  status = Time_SetTime(restart, hour, minute, second);
502
 
#endif
503
500
  return status;
504
501
}
505
502
 
507
504
Config_GetDate(char *month, const size_t monthSize, char *day, const size_t daySize, char *year, const size_t yearSize)
508
505
{
509
506
  int status = -1;
510
 
#if !defined(freebsd) && !defined(darwin) && !defined(solaris)
511
507
  status = Time_GetDate(month, monthSize, day, daySize, year, yearSize);
512
 
#endif
513
508
  return status;
514
509
}
515
510
 
521
516
  if (month == NULL || day == NULL || year == NULL) {
522
517
    return -1;
523
518
  }
524
 
#if !defined(freebsd) && !defined(darwin) && !defined(solaris)
525
519
  status = Time_SetDate(restart, month, day, year);
526
 
#endif
527
520
  return status;
528
521
}
529
522
 
634
627
int
635
628
Config_GetNTP_Status(char *status, size_t status_len)
636
629
{
637
 
#if !defined(freebsd) && !defined(darwin) && !defined(solaris)
638
630
  return Time_GetNTP_Status(status, status_len);
639
 
#else
640
 
  return -1;
641
 
#endif
642
631
}
643
632
 
644
633
int
645
634
Config_SetNTP_Off(void)
646
635
{
647
 
#if !defined(freebsd) && !defined(darwin)
648
636
  return Time_SetNTP_Off();
649
 
#else
650
 
  return -1;
651
 
#endif
652
637
}
653
638
 
654
639
int
655
640
Config_User_Root(int *old_euid)
656
641
{
657
 
#if !defined(freebsd) && !defined(darwin)
658
642
  return Sys_User_Root(old_euid);
659
 
#else
660
 
  return -1;
661
 
#endif
662
643
}
663
644
 
664
645
int
665
646
Config_User_Inktomi(int euid)
666
647
{
667
 
#if !defined(freebsd) && !defined(darwin)
668
648
  return Sys_User_Inktomi(euid);
669
 
#else
670
 
  return -1;
671
 
#endif
672
649
}
673
650
 
674
651
int
675
652
Config_Grp_Root(int *old_egid)
676
653
{
677
 
#if !defined(freebsd) && !defined(darwin)
678
654
  return Sys_Grp_Root(old_egid);
679
 
#else
680
 
  return -1;
681
 
#endif
682
655
}
683
656
 
684
657
int
685
658
Config_Grp_Inktomi(int egid)
686
659
{
687
 
#if !defined(freebsd) && !defined(darwin)
688
660
  return Sys_Grp_Inktomi(egid);
689
 
#else
690
 
  return -1;
691
 
#endif
692
661
}
693
662
 
694
663
#if defined(linux)
743
712
    TagValue = netXml.getXmlTagValue("HostName");
744
713
    if (TagValue != NULL) {
745
714
      Config_SetHostname(TagValue);
746
 
      xfree(TagValue);
 
715
      ats_free(TagValue);
747
716
    }
748
717
 
749
718
 
750
719
    TagValue = netXml.getXmlTagValue("DNSSearch");
751
720
    if (TagValue != NULL) {
752
721
      Config_SetDomain(TagValue);
753
 
      xfree(TagValue);
 
722
      ats_free(TagValue);
754
723
    }
755
724
 
756
725
    // Check that we always have eth0. If eth0 is missing, exit.
762
731
      TagValue = netXml.getXmlTagValueAndAttribute(eth, "PerNICDefaultGateway");
763
732
      if (TagValue != NULL) {
764
733
        Config_SetNIC_Gateway(eth, TagValue);
765
 
        xfree(TagValue);
 
734
        ats_free(TagValue);
766
735
      } else if (count == 0)
767
736
        break;
768
737
      snprintf(eth, sizeof(eth), "eth%d", ++count);
779
748
#if defined(linux)
780
749
        activeInterface[count] = 1;
781
750
#endif
782
 
        xfree(TagValue);
 
751
        ats_free(TagValue);
783
752
      } else if (count == 0)
784
753
        break;
785
754
      snprintf(eth, sizeof(eth), "eth%d", ++count);
805
774
      TagValue = netXml.getXmlTagValueAndAttribute(eth, "InterfaceNetmask");
806
775
      if (TagValue != NULL) {
807
776
        Config_SetNIC_Netmask(eth, TagValue);
808
 
        xfree(TagValue);
 
777
        ats_free(TagValue);
809
778
      } else if (count == 0)
810
779
        break;
811
780
      snprintf(eth, sizeof(eth), "eth%d", ++count);
814
783
    TagValue = netXml.getXmlTagValue("DefaultGateway");
815
784
    if (TagValue != NULL) {
816
785
      Config_SetDefaultRouter(TagValue);
817
 
      xfree(TagValue);
 
786
      ats_free(TagValue);
818
787
    }
819
788
 
820
789
 
821
790
    TagValue = netXml.getXmlTagValue("DNSServer");
822
791
    if (TagValue != NULL) {
823
792
      Config_SetDNS_Servers(TagValue);
824
 
      xfree(TagValue);
 
793
      ats_free(TagValue);
825
794
    }
826
795
 
827
796
    TagValue = netXml.getXmlTagValue("NTPServers");
828
797
    if (TagValue != NULL) {
829
798
      Config_SetNTP_Servers(0, TagValue);
830
 
      xfree(TagValue);
 
799
      ats_free(TagValue);
831
800
    }
832
801
 
833
802
    // Get Admin GUI encrypted password.
841
810
          top_action_req = action_need;
842
811
        DPRINTF(("Config_FloppyNetRestore: set new mail_address %s!\n", mail_address));
843
812
      }
844
 
      xfree(mail_address);
 
813
      ats_free(mail_address);
845
814
    }
846
815
 
847
816
    // Make sure this is the last entry in these series. We restart traffic server here and hence
859
828
#endif
860
829
      }
861
830
    }
862
 
    xfree(TagValue);
 
831
    ats_free(TagValue);
863
832
  }
864
833
 
865
834
  setreuid(old_euid, old_euid); //happens only for floppy config
1110
1079
char *
1111
1080
XmlObject::getXmlTagValue(const char *XmlTagName)
1112
1081
{
1113
 
  char XmlTagValue[1024];
1114
 
  ink_strncpy(XmlTagValue, "", sizeof(XmlTagValue));
 
1082
  char XmlTagValue[1024] = "";
1115
1083
 
1116
1084
  for (int parent = 0; parent < xmlDom.getChildCount(); parent++) {
1117
1085
    XMLNode *parentNode = xmlDom.getChildNode(parent);
1119
1087
      int XmlTagCount = parentNode->getChildCount(XmlTagName);
1120
1088
      for (int tagCount = 0; tagCount < XmlTagCount; tagCount++) {
1121
1089
        if (parentNode->getChildNode(XmlTagName, tagCount)->getNodeValue() != NULL) {
1122
 
          strncat(XmlTagValue, parentNode->getChildNode(XmlTagName, tagCount)->getNodeValue(),
1123
 
                  sizeof(XmlTagValue) - strlen(XmlTagValue) - 1);
 
1090
          ink_strlcat(XmlTagValue, parentNode->getChildNode(XmlTagName, tagCount)->getNodeValue(),
 
1091
                  sizeof(XmlTagValue));
1124
1092
          if (tagCount + 1 < XmlTagCount)
1125
 
            strncat(XmlTagValue, " ", sizeof(XmlTagValue) - strlen(XmlTagValue) - 1);
 
1093
            ink_strlcat(XmlTagValue, " ", sizeof(XmlTagValue));
1126
1094
        }
1127
1095
      }
1128
1096
    }
1129
1097
  }
1130
 
  strncat(XmlTagValue, "\0", sizeof(XmlTagValue) - strlen(XmlTagValue) - 1);
1131
1098
  if (strlen(XmlTagValue) == 0)
1132
1099
    return NULL;
1133
 
  return xstrdup(XmlTagValue);
 
1100
  return ats_strdup(XmlTagValue);
1134
1101
}
1135
1102
 
1136
1103
 
1137
1104
char *
1138
1105
XmlObject::getXmlTagValueAndAttribute(char *XmlAttribute, const char *XmlTagName)
1139
1106
{
1140
 
  char XmlTagValue[1024];
1141
 
  ink_strncpy(XmlTagValue, "", sizeof(XmlTagValue));
 
1107
  char XmlTagValue[1024] = "";
1142
1108
 
1143
1109
  for (int parent = 0; parent < xmlDom.getChildCount(); parent++) {
1144
1110
    XMLNode *parentNode = xmlDom.getChildNode(parent);
1151
1117
                                                                                                    tagCount)->
1152
1118
                                                                                       m_pAList[0].pAValue,
1153
1119
                                                                                       XmlAttribute) == 0)) {
1154
 
          strncat(XmlTagValue, parentNode->getChildNode(XmlTagName, tagCount)->getNodeValue(),
1155
 
                  sizeof(XmlTagValue) - strlen(XmlTagValue) - 1);
1156
 
          strncat(XmlTagValue, "\0", sizeof(XmlTagValue) - strlen(XmlTagValue) - 1);
1157
 
          return xstrdup(XmlTagValue);
 
1120
          ink_strlcat(XmlTagValue, parentNode->getChildNode(XmlTagName, tagCount)->getNodeValue(),
 
1121
                  sizeof(XmlTagValue));
 
1122
          return ats_strdup(XmlTagValue);
1158
1123
        }
1159
1124
      }
1160
1125
    }
1169
1134
int
1170
1135
Config_SetSMTP_Server(char *server)
1171
1136
{
1172
 
#if !defined(freebsd) && !defined(darwin)
1173
1137
  return (Net_SetSMTP_Server(server));
1174
 
#else
1175
 
  return -1;
1176
 
#endif
1177
1138
}
1178
1139
 
1179
1140
int
1180
1141
Config_GetSMTP_Server(char *server)
1181
1142
{
1182
 
#if !defined(freebsd) && !defined(darwin)
1183
1143
  return (Net_GetSMTP_Server(server));
1184
 
#else
1185
 
  return -1;
1186
 
#endif
1187
1144
}
1188
1145
 
1189
1146