Changeset 745 for trunk/server/source3/lib/util_str.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/lib/util_str.c
r599 r745 244 244 while (isspace((int)*psz2)) 245 245 psz2++; 246 if (toupper_ ascii(*psz1) != toupper_ascii(*psz2) ||246 if (toupper_m(*psz1) != toupper_m(*psz2) || 247 247 *psz1 == '\0' || *psz2 == '\0') 248 248 break; … … 827 827 for (i=0;i<li;i++) { 828 828 switch (insert[i]) { 829 case '`':830 case '"':831 case '\'':832 case ';':833 829 case '$': 834 830 /* allow a trailing $ … … 838 834 break; 839 835 } 836 case '`': 837 case '"': 838 case '\'': 839 case ';': 840 840 case '%': 841 841 case '\r': … … 909 909 for (i=0;i<li;i++) { 910 910 switch (in[i]) { 911 case '`':912 case '"':913 case '\'':914 case ';':915 911 case '$': 916 912 /* allow a trailing $ … … 919 915 break; 920 916 } 917 case '`': 918 case '"': 919 case '\'': 920 case ';': 921 921 case '%': 922 922 case '\r': … … 1004 1004 for (i=0;i<li;i++) { 1005 1005 switch (in[i]) { 1006 case '`':1007 case '"':1008 case '\'':1009 case ';':1010 1006 case '$': 1011 1007 /* allow a trailing $ … … 1014 1010 break; 1015 1011 } 1012 case '`': 1013 case '"': 1014 case '\'': 1015 case ';': 1016 1016 case '%': 1017 1017 case '\r': … … 1407 1407 1408 1408 while (*s && !(((unsigned char)s[0]) & 0x80)) { 1409 *s = tolower_ ascii((unsigned char)*s);1409 *s = tolower_m((unsigned char)*s); 1410 1410 s++; 1411 1411 } … … 1463 1463 * Calculate the number of units (8 or 16-bit, depending on the 1464 1464 * destination charset), that would be needed to convert the input 1465 * string which is expected to be in in CH_UNIXencoding to the1465 * string which is expected to be in in src_charset encoding to the 1466 1466 * destination charset (which should be a unicode charset). 1467 1467 */ 1468 size_t strlen_m_ext(const char *s, const charset_t dst_charset) 1468 1469 size_t strlen_m_ext(const char *s, const charset_t src_charset, 1470 const charset_t dst_charset) 1469 1471 { 1470 1472 size_t count = 0; … … 1485 1487 while (*s) { 1486 1488 size_t c_size; 1487 codepoint_t c = next_codepoint (s, &c_size);1489 codepoint_t c = next_codepoint_ext(s, src_charset, &c_size); 1488 1490 s += c_size; 1489 1491 1490 switch (dst_charset) {1492 switch (dst_charset) { 1491 1493 case CH_UTF16LE: 1492 1494 case CH_UTF16BE: … … 1528 1530 } 1529 1531 1530 size_t strlen_m_ext_term(const char *s, const charset_t dst_charset) 1532 size_t strlen_m_ext_term(const char *s, const charset_t src_charset, 1533 const charset_t dst_charset) 1531 1534 { 1532 1535 if (!s) { 1533 1536 return 0; 1534 1537 } 1535 return strlen_m_ext(s, dst_charset) + 1; 1536 } 1537 1538 /** 1539 Count the number of UCS2 characters in a string. Normally this will 1540 be the same as the number of bytes in a string for single byte strings, 1541 but will be different for multibyte. 1542 **/ 1538 return strlen_m_ext(s, src_charset, dst_charset) + 1; 1539 } 1540 1541 /** 1542 * Calculate the number of 16-bit units that would bee needed to convert 1543 * the input string which is expected to be in CH_UNIX encoding to UTF16. 1544 * 1545 * This will be the same as the number of bytes in a string for single 1546 * byte strings, but will be different for multibyte. 1547 */ 1543 1548 1544 1549 size_t strlen_m(const char *s) 1545 1550 { 1546 return strlen_m_ext(s, CH_U TF16LE);1551 return strlen_m_ext(s, CH_UNIX, CH_UTF16LE); 1547 1552 } 1548 1553 … … 1577 1582 1578 1583 return len+1; 1579 }1580 /**1581 Return a RFC2254 binary string representation of a buffer.1582 Used in LDAP filters.1583 Caller must free.1584 **/1585 1586 char *binary_string_rfc2254(TALLOC_CTX *mem_ctx, const uint8_t *buf, int len)1587 {1588 char *s;1589 int i, j;1590 const char *hex = "0123456789ABCDEF";1591 s = talloc_array(mem_ctx, char, len * 3 + 1);1592 if (s == NULL) {1593 return NULL;1594 }1595 for (j=i=0;i<len;i++) {1596 s[j] = '\\';1597 s[j+1] = hex[((unsigned char)buf[i]) >> 4];1598 s[j+2] = hex[((unsigned char)buf[i]) & 0xF];1599 j += 3;1600 }1601 s[j] = 0;1602 return s;1603 }1604 1605 char *binary_string(char *buf, int len)1606 {1607 char *s;1608 int i, j;1609 const char *hex = "0123456789ABCDEF";1610 s = (char *)SMB_MALLOC(len * 2 + 1);1611 if (!s)1612 return NULL;1613 for (j=i=0;i<len;i++) {1614 s[j] = hex[((unsigned char)buf[i]) >> 4];1615 s[j+1] = hex[((unsigned char)buf[i]) & 0xF];1616 j += 2;1617 }1618 s[j] = 0;1619 return s;1620 1584 } 1621 1585 … … 2022 1986 { 2023 1987 2024 uint64_t val = -1;1988 uint64_t val = (uint64_t)-1; 2025 1989 const char *p = nptr; 2026 1990 … … 2058 2022 SMB_OFF_T conv_str_size(const char * str) 2059 2023 { 2024 SMB_OFF_T lval_orig; 2060 2025 SMB_OFF_T lval; 2061 2026 char * end; … … 2067 2032 #ifdef HAVE_STRTOULL 2068 2033 if (sizeof(SMB_OFF_T) == 8) { 2069 2034 lval = strtoull(str, &end, 10 /* base */); 2070 2035 } else { 2071 2036 lval = strtoul(str, &end, 10 /* base */); 2072 2037 } 2073 2038 #else … … 2079 2044 } 2080 2045 2081 if (*end) { 2082 SMB_OFF_T lval_orig = lval; 2083 2084 if (strwicmp(end, "K") == 0) { 2085 lval *= (SMB_OFF_T)1024; 2086 } else if (strwicmp(end, "M") == 0) { 2087 lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024); 2088 } else if (strwicmp(end, "G") == 0) { 2089 lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * 2090 (SMB_OFF_T)1024); 2091 } else if (strwicmp(end, "T") == 0) { 2092 lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * 2093 (SMB_OFF_T)1024 * (SMB_OFF_T)1024); 2094 } else if (strwicmp(end, "P") == 0) { 2095 lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * 2096 (SMB_OFF_T)1024 * (SMB_OFF_T)1024 * 2097 (SMB_OFF_T)1024); 2098 } else { 2099 return 0; 2100 } 2101 2102 /* Primitive attempt to detect wrapping on platforms with 2103 * 4-byte SMB_OFF_T. It's better to let the caller handle 2104 * a failure than some random number. 2105 */ 2106 if (lval_orig <= lval) { 2107 return 0; 2108 } 2109 } 2046 if (*end == '\0') { 2047 return lval; 2048 } 2049 2050 lval_orig = lval; 2051 2052 if (strwicmp(end, "K") == 0) { 2053 lval *= (SMB_OFF_T)1024; 2054 } else if (strwicmp(end, "M") == 0) { 2055 lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024); 2056 } else if (strwicmp(end, "G") == 0) { 2057 lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * 2058 (SMB_OFF_T)1024); 2059 } else if (strwicmp(end, "T") == 0) { 2060 lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * 2061 (SMB_OFF_T)1024 * (SMB_OFF_T)1024); 2062 } else if (strwicmp(end, "P") == 0) { 2063 lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * 2064 (SMB_OFF_T)1024 * (SMB_OFF_T)1024 * 2065 (SMB_OFF_T)1024); 2066 } else { 2067 return 0; 2068 } 2069 2070 /* 2071 * Primitive attempt to detect wrapping on platforms with 2072 * 4-byte SMB_OFF_T. It's better to let the caller handle a 2073 * failure than some random number. 2074 */ 2075 if (lval_orig <= lval) { 2076 return 0; 2077 } 2110 2078 2111 2079 return lval; … … 2118 2086 if (*left == NULL) { 2119 2087 *left = (char *)SMB_MALLOC(new_len); 2088 if (*left == NULL) { 2089 return; 2090 } 2120 2091 *left[0] = '\0'; 2121 2092 } else { … … 2301 2272 { 2302 2273 int i; 2274 2275 if (!name) { 2276 return false; 2277 } 2303 2278 2304 2279 for ( i=0; i<max_len && name[i]; i++ ) { … … 2548 2523 return list; 2549 2524 } 2525 2526 char *sanitize_username(TALLOC_CTX *mem_ctx, const char *username) 2527 { 2528 fstring tmp; 2529 2530 alpha_strcpy(tmp, username, ". _-$", sizeof(tmp)); 2531 return talloc_strdup(mem_ctx, tmp); 2532 }
Note:
See TracChangeset
for help on using the changeset viewer.