Changeset 79514 in vbox for trunk/src/VBox/NetworkServices/Dhcpd/Config.cpp
- Timestamp:
- Jul 4, 2019 8:01:58 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/Dhcpd/Config.cpp
r79509 r79514 18 18 #include "Config.h" 19 19 20 #include <iprt/ types.h>20 #include <iprt/ctype.h> 21 21 #include <iprt/net.h> /* NB: must come before getopt.h */ 22 22 #include <iprt/getopt.h> … … 88 88 89 89 90 void Config::setNetwork(const std::string &aStrNetwork)91 { 92 AssertReturnVoid(m_strNetwork. empty());90 void Config::setNetwork(const RTCString &aStrNetwork) 91 { 92 AssertReturnVoid(m_strNetwork.isEmpty()); 93 93 94 94 m_strNetwork = aStrNetwork; … … 104 104 int Config::logInit() 105 105 { 106 int rc; 107 size_t cch; 108 109 if (m_strHome.empty() || m_strBaseName.empty()) 110 return VERR_GENERAL_FAILURE; 106 if (m_strHome.isEmpty() || m_strBaseName.isEmpty()) 107 return VERR_PATH_ZERO_LENGTH; 111 108 112 109 /* default log file name */ 113 110 char szLogFile[RTPATH_MAX]; 114 cch = RTStrPrintf(szLogFile, sizeof(szLogFile),115 "%s%c%s-Dhcpd.log",116 m_strHome.c_str(), RTPATH_DELIMITER, m_strBaseName.c_str());117 if (cch >= sizeof(szLogFile))111 ssize_t cch = RTStrPrintf2(szLogFile, sizeof(szLogFile), 112 "%s%c%s-Dhcpd.log", 113 m_strHome.c_str(), RTPATH_DELIMITER, m_strBaseName.c_str()); 114 if (cch <= 0) 118 115 return VERR_BUFFER_OVERFLOW; 119 116 120 121 /* get a writable copy of the base name */ 122 char szBaseName[RTPATH_MAX]; 123 rc = RTStrCopy(szBaseName, sizeof(szBaseName), m_strBaseName.c_str()); 124 if (RT_FAILURE(rc)) 125 return rc; 126 127 /* sanitize base name some more to be usable in an environment variable name */ 128 for (char *p = szBaseName; *p != '\0'; ++p) 129 { 130 if ( *p != '_' 131 && (*p < '0' || '9' < *p) 132 && (*p < 'a' || 'z' < *p) 133 && (*p < 'A' || 'Z' < *p)) 134 { 117 /* Sanitize base name some more to be usable in an environment variable name: */ 118 char szEnvVarBase[128]; 119 cch = RTStrPrintf(szEnvVarBase, sizeof(szEnvVarBase), "VBOXDHCP_%s_RELEASE_LOG", m_strBaseName.c_str()); 120 if (cch <= 0) 121 return VERR_BUFFER_OVERFLOW; 122 for (char *p = szEnvVarBase; *p != '\0'; ++p) 123 if (*p != '_' && !RT_C_IS_ALNUM(*p)) 135 124 *p = '_'; 136 } 137 } 138 139 140 /* name of the environment variable to control logging */ 141 char szEnvVarBase[128]; 142 cch = RTStrPrintf(szEnvVarBase, sizeof(szEnvVarBase), 143 "VBOXDHCP_%s_RELEASE_LOG", szBaseName); 144 if (cch >= sizeof(szEnvVarBase)) 145 return VERR_BUFFER_OVERFLOW; 146 147 148 rc = com::VBoxLogRelCreate("DHCP Server", 149 szLogFile, 150 RTLOGFLAGS_PREFIX_TIME_PROG, 151 "all all.restrict -default.restrict", 152 szEnvVarBase, 153 RTLOGDEST_FILE 125 126 127 int rc = com::VBoxLogRelCreate("DHCP Server", 128 szLogFile, 129 RTLOGFLAGS_PREFIX_TIME_PROG, 130 "all all.restrict -default.restrict", 131 szEnvVarBase, 132 RTLOGDEST_FILE 154 133 #ifdef DEBUG 155 | RTLOGDEST_STDERR134 | RTLOGDEST_STDERR 156 135 #endif 157 ,158 32768 /* cMaxEntriesPerGroup */,159 0 /* cHistory */,160 0 /* uHistoryFileTime */,161 0 /* uHistoryFileSize */,162 NULL /* pErrInfo */);136 , 137 32768 /* cMaxEntriesPerGroup */, 138 0 /* cHistory */, 139 0 /* uHistoryFileTime */, 140 0 /* uHistoryFileSize */, 141 NULL /* pErrInfo */); 163 142 164 143 return rc; … … 170 149 int rc; 171 150 172 if (m_strNetwork. empty())151 if (m_strNetwork.isEmpty()) 173 152 { 174 153 LogDHCP(("network name is not specified\n")); … … 212 191 213 192 /* valid netmask */ 214 int iPrefixLengh;215 rc = RTNetMaskToPrefixIPv4(&m_IPv4Netmask, & iPrefixLengh);216 if (RT_FAILURE(rc) || iPrefixLengh== 0)193 int cPrefixBits; 194 rc = RTNetMaskToPrefixIPv4(&m_IPv4Netmask, &cPrefixBits); 195 if (RT_FAILURE(rc) || cPrefixBits == 0) 217 196 { 218 197 LogDHCP(("IP mask is not valid: %RTnaipv4\n", m_IPv4Netmask.u)); … … 224 203 { 225 204 LogDHCP(("first pool address is outside the network %RTnaipv4/%d: %RTnaipv4\n", 226 (m_IPv4Address.u & m_IPv4Netmask.u), iPrefixLengh, 227 m_IPv4PoolFirst.u)); 205 (m_IPv4Address.u & m_IPv4Netmask.u), cPrefixBits, m_IPv4PoolFirst.u)); 228 206 return VERR_GENERAL_FAILURE; 229 207 } … … 233 211 { 234 212 LogDHCP(("last pool address is outside the network %RTnaipv4/%d: %RTnaipv4\n", 235 (m_IPv4Address.u & m_IPv4Netmask.u), iPrefixLengh, 236 m_IPv4PoolLast.u)); 213 (m_IPv4Address.u & m_IPv4Netmask.u), cPrefixBits, m_IPv4PoolLast.u)); 237 214 return VERR_GENERAL_FAILURE; 238 215 } … … 257 234 if (!fMACGenerated) 258 235 LogDHCP(("MAC address %RTmac\n", &m_MacAddress)); 259 LogDHCP(("IP address %RTnaipv4/%d\n", m_IPv4Address.u, iPrefixLengh));236 LogDHCP(("IP address %RTnaipv4/%d\n", m_IPv4Address.u, cPrefixBits)); 260 237 LogDHCP(("address pool %RTnaipv4 - %RTnaipv4\n", m_IPv4PoolFirst.u, m_IPv4PoolLast.u)); 261 238 … … 387 364 388 365 case 'n': /* --network */ 389 if (!config->m_strNetwork. empty())366 if (!config->m_strNetwork.isEmpty()) 390 367 { 391 368 RTMsgError("Duplicate --network option"); … … 396 373 397 374 case 't': /* --trunk-name */ 398 if (!config->m_strTrunk. empty())375 if (!config->m_strTrunk.isEmpty()) 399 376 { 400 377 RTMsgError("Duplicate --trunk-name option"); … … 641 618 throw ConfigFileError("DHCPServer/@networkName missing"); 642 619 643 setNetwork(strNetworkName .c_str());620 setNetwork(strNetworkName); 644 621 645 622 RTCString strTrunkType; … … 663 640 if (!server->getAttributeValue("trunkName", &strTrunk)) 664 641 throw ConfigFileError("DHCPServer/@trunkName missing"); 665 m_strTrunk = strTrunk .c_str();642 m_strTrunk = strTrunk; 666 643 } 667 644 else … … 848 825 void Config::sanitizeBaseName() 849 826 { 850 int rc; 851 852 if (m_strNetwork.empty()) 853 return; 854 855 char szBaseName[RTPATH_MAX]; 856 rc = RTStrCopy(szBaseName, sizeof(szBaseName), m_strNetwork.c_str()); 857 if (RT_FAILURE(rc)) 858 return; 859 860 char ch; 827 if (m_strNetwork.isNotEmpty()) 828 { 829 m_strBaseName = m_strNetwork; 830 831 char ch; 861 832 #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) 862 static const char s_szIllegals[] = "/\\\"*:<>?|\t\v\n\r\f\a\b"; /** @todo all control chars... */863 for (char *p = szBaseName; (ch = *p) != '\0'; ++p)864 if (strchr(s_szIllegals, ch))865 *p= '_';833 static const char s_szIllegals[] = "/\\\"*:<>?|\t\v\n\r\f\a\b"; /** @todo all control chars... */ 834 for (char *psz = m_strBaseName.mutableRaw(); (ch = *psz) != '\0'; ++psz) 835 if (strchr(s_szIllegals, ch)) 836 *psz = '_'; 866 837 #else 867 for (char *p = szBaseName; (ch = *p) != '\0'; ++p)868 if (RTPATH_IS_SEP(ch))869 *p= '_';838 for (char *psz = m_strBaseName.mutableRaw(); (ch = *psz) != '\0'; ++psz) 839 if (RTPATH_IS_SEP(ch)) 840 *psz = '_'; 870 841 #endif 871 872 m_strBaseName.assign(szBaseName); 842 m_strBaseName.jolt(); /* Not really necessary, but it's protocol. */ 843 } 844 else 845 m_strBaseName.setNull(); 873 846 } 874 847
Note:
See TracChangeset
for help on using the changeset viewer.