Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/lib/util_str.c

    r599 r745  
    244244                while (isspace((int)*psz2))
    245245                        psz2++;
    246                 if (toupper_ascii(*psz1) != toupper_ascii(*psz2) ||
     246                if (toupper_m(*psz1) != toupper_m(*psz2) ||
    247247                                *psz1 == '\0' || *psz2 == '\0')
    248248                        break;
     
    827827                for (i=0;i<li;i++) {
    828828                        switch (insert[i]) {
    829                         case '`':
    830                         case '"':
    831                         case '\'':
    832                         case ';':
    833829                        case '$':
    834830                                /* allow a trailing $
     
    838834                                        break;
    839835                                }
     836                        case '`':
     837                        case '"':
     838                        case '\'':
     839                        case ';':
    840840                        case '%':
    841841                        case '\r':
     
    909909        for (i=0;i<li;i++) {
    910910                switch (in[i]) {
    911                         case '`':
    912                         case '"':
    913                         case '\'':
    914                         case ';':
    915911                        case '$':
    916912                                /* allow a trailing $
     
    919915                                        break;
    920916                                }
     917                        case '`':
     918                        case '"':
     919                        case '\'':
     920                        case ';':
    921921                        case '%':
    922922                        case '\r':
     
    10041004        for (i=0;i<li;i++) {
    10051005                switch (in[i]) {
    1006                         case '`':
    1007                         case '"':
    1008                         case '\'':
    1009                         case ';':
    10101006                        case '$':
    10111007                                /* allow a trailing $
     
    10141010                                        break;
    10151011                                }
     1012                        case '`':
     1013                        case '"':
     1014                        case '\'':
     1015                        case ';':
    10161016                        case '%':
    10171017                        case '\r':
     
    14071407
    14081408        while (*s && !(((unsigned char)s[0]) & 0x80)) {
    1409                 *s = tolower_ascii((unsigned char)*s);
     1409                *s = tolower_m((unsigned char)*s);
    14101410                s++;
    14111411        }
     
    14631463 * Calculate the number of units (8 or 16-bit, depending on the
    14641464 * destination charset), that would be needed to convert the input
    1465  * string which is expected to be in in CH_UNIX encoding to the
     1465 * string which is expected to be in in src_charset encoding to the
    14661466 * destination charset (which should be a unicode charset).
    14671467 */
    1468 size_t strlen_m_ext(const char *s, const charset_t dst_charset)
     1468
     1469size_t strlen_m_ext(const char *s, const charset_t src_charset,
     1470                    const charset_t dst_charset)
    14691471{
    14701472        size_t count = 0;
     
    14851487        while (*s) {
    14861488                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);
    14881490                s += c_size;
    14891491
    1490                 switch(dst_charset) {
     1492                switch (dst_charset) {
    14911493                case CH_UTF16LE:
    14921494                case CH_UTF16BE:
     
    15281530}
    15291531
    1530 size_t strlen_m_ext_term(const char *s, const charset_t dst_charset)
     1532size_t strlen_m_ext_term(const char *s, const charset_t src_charset,
     1533                         const charset_t dst_charset)
    15311534{
    15321535        if (!s) {
    15331536                return 0;
    15341537        }
    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 */
    15431548
    15441549size_t strlen_m(const char *s)
    15451550{
    1546         return strlen_m_ext(s, CH_UTF16LE);
     1551        return strlen_m_ext(s, CH_UNIX, CH_UTF16LE);
    15471552}
    15481553
     
    15771582
    15781583        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;
    16201584}
    16211585
     
    20221986{
    20231987
    2024         uint64_t val = -1;
     1988        uint64_t val = (uint64_t)-1;
    20251989        const char *p = nptr;
    20261990
     
    20582022SMB_OFF_T conv_str_size(const char * str)
    20592023{
     2024        SMB_OFF_T lval_orig;
    20602025        SMB_OFF_T lval;
    20612026        char * end;
     
    20672032#ifdef HAVE_STRTOULL
    20682033        if (sizeof(SMB_OFF_T) == 8) {
    2069             lval = strtoull(str, &end, 10 /* base */);
     2034                lval = strtoull(str, &end, 10 /* base */);
    20702035        } else {
    2071             lval = strtoul(str, &end, 10 /* base */);
     2036                lval = strtoul(str, &end, 10 /* base */);
    20722037        }
    20732038#else
     
    20792044        }
    20802045
    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        }
    21102078
    21112079        return lval;
     
    21182086        if (*left == NULL) {
    21192087                *left = (char *)SMB_MALLOC(new_len);
     2088                if (*left == NULL) {
     2089                        return;
     2090                }
    21202091                *left[0] = '\0';
    21212092        } else {
     
    23012272{
    23022273        int i;
     2274
     2275        if (!name) {
     2276                return false;
     2277        }
    23032278
    23042279        for ( i=0; i<max_len && name[i]; i++ ) {
     
    25482523        return list;
    25492524}
     2525
     2526char *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.