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/smbd/mangle_hash2.c

    r414 r745  
    5050*/
    5151
     52/*
     53 * ============================================================================
     54 * Whenever you change anything in the FLAG_ or other fields,
     55 * re-initialize the tables char_flags and base_reverse by running the
     56 * init_tables() routine once and dump its results. To do this, a
     57 * single smbd run with
     58 *
     59 * #define DYNAMIC_MANGLE_TABLES 1
     60 *
     61 * and debug level 10 should be sufficient.
     62 * ============================================================================
     63 */
     64
    5265
    5366#include "includes.h"
     67#include "smbd/smbd.h"
    5468#include "smbd/globals.h"
     69#include "memcache.h"
     70#include "mangle.h"
    5571
    5672#if 1
     
    93109{ "AUX", "LOCK$", "CON", "COM1", "COM2", "COM3", "COM4",
    94110  "LPT1", "LPT2", "LPT3", "NUL", "PRN", NULL };
     111
     112#define DYNAMIC_MANGLE_TABLES 0
     113
     114#if DYNAMIC_MANGLE_TABLES
     115
     116/* these tables are used to provide fast tests for characters */
     117static unsigned char char_flags[256];
     118static unsigned char base_reverse[256];
     119
     120/* initialise the flags table
     121
     122  we allow only a very restricted set of characters as 'ascii' in this
     123  mangling backend. This isn't a significant problem as modern clients
     124  use the 'long' filenames anyway, and those don't have these
     125  restrictions.
     126*/
     127static void init_tables(void)
     128{
     129        int i;
     130
     131        memset(char_flags, 0, sizeof(char_flags));
     132
     133        for (i=1;i<128;i++) {
     134                if (i <= 0x1f) {
     135                        /* Control characters. */
     136                        char_flags[i] |= FLAG_ILLEGAL;
     137                }
     138
     139                if ((i >= '0' && i <= '9') ||
     140                    (i >= 'a' && i <= 'z') ||
     141                    (i >= 'A' && i <= 'Z')) {
     142                        char_flags[i] |=  (FLAG_ASCII | FLAG_BASECHAR);
     143                }
     144                if (strchr("_-$~", i)) {
     145                        char_flags[i] |= FLAG_ASCII;
     146                }
     147
     148                if (strchr("*\\/?<>|\":", i)) {
     149                        char_flags[i] |= FLAG_ILLEGAL;
     150                }
     151
     152                if (strchr("*?\"<>", i)) {
     153                        char_flags[i] |= FLAG_WILDCARD;
     154                }
     155        }
     156
     157        memset(base_reverse, 0, sizeof(base_reverse));
     158        for (i=0;i<36;i++) {
     159                base_reverse[(unsigned char)base_forward(i)] = i;
     160        }
     161
     162        /* fill in the reserved names flags. These are used as a very
     163           fast filter for finding possible DOS reserved filenames */
     164        for (i=0; reserved_names[i]; i++) {
     165                unsigned char c1, c2, c3, c4;
     166
     167                c1 = (unsigned char)reserved_names[i][0];
     168                c2 = (unsigned char)reserved_names[i][1];
     169                c3 = (unsigned char)reserved_names[i][2];
     170                c4 = (unsigned char)reserved_names[i][3];
     171
     172                char_flags[c1] |= FLAG_POSSIBLE1;
     173                char_flags[c2] |= FLAG_POSSIBLE2;
     174                char_flags[c3] |= FLAG_POSSIBLE3;
     175                char_flags[c4] |= FLAG_POSSIBLE4;
     176                char_flags[tolower_m(c1)] |= FLAG_POSSIBLE1;
     177                char_flags[tolower_m(c2)] |= FLAG_POSSIBLE2;
     178                char_flags[tolower_m(c3)] |= FLAG_POSSIBLE3;
     179                char_flags[tolower_m(c4)] |= FLAG_POSSIBLE4;
     180
     181                char_flags[(unsigned char)'.'] |= FLAG_POSSIBLE4;
     182        }
     183
     184#if 0
     185        DEBUG(10, ("char_flags\n"));
     186        dump_data(10, char_flags, sizeof(char_flags));
     187
     188        DEBUG(10, ("base_reverse\n"));
     189        dump_data(10, base_reverse, sizeof(base_reverse));
     190#endif
     191}
     192
     193#else
     194
     195/*
     196 * These tables were initialized by a single run of the above
     197 * init_tables() routine, dumping the tables and a simple emacs macro.
     198 *
     199 * Technically we could leave out the 0's at the end of the array
     200 * initializers, but I'll leave it in: less surprise.
     201 */
     202
     203static uint8_t char_flags[256] = {
     204        0x80, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
     205        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
     206        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
     207        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
     208        0x00, 0x00, 0x0C, 0x00, 0x02, 0x00, 0x00, 0x00,
     209        0x00, 0x00, 0x0C, 0x00, 0x00, 0x02, 0x80, 0x04,
     210        0x03, 0x83, 0x83, 0x83, 0x83, 0x03, 0x03, 0x03,
     211        0x03, 0x03, 0x04, 0x00, 0x0C, 0x00, 0x0C, 0x0C,
     212        0x00, 0x13, 0x03, 0x53, 0x03, 0x03, 0x03, 0x03,
     213        0x03, 0x03, 0x03, 0x83, 0x53, 0x43, 0x53, 0x23,
     214        0x33, 0x03, 0x23, 0x03, 0x43, 0x23, 0x03, 0x03,
     215        0x43, 0x03, 0x03, 0x00, 0x04, 0x00, 0x00, 0x02,
     216        0x00, 0x13, 0x03, 0x53, 0x03, 0x03, 0x03, 0x03,
     217        0x03, 0x03, 0x03, 0x83, 0x53, 0x43, 0x53, 0x23,
     218        0x33, 0x03, 0x23, 0x03, 0x43, 0x23, 0x03, 0x03,
     219        0x43, 0x03, 0x03, 0x00, 0x04, 0x00, 0x02, 0x00,
     220        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     221        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     222        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     223        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     224        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     225        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     226        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     227        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     228        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     229        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     230        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     231        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     232        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     233        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     234        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     235        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
     236};
     237
     238static uint8_t base_reverse[256] = {
     239        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     240        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     241        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     242        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     243        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     244        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     245        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
     246        0x08, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     247        0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,
     248        0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
     249        0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
     250        0x21, 0x22, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00,
     251        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     252        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     253        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     254        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     255        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     256        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     257        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     258        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     259        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     260        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     261        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     262        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     263        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     264        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     265        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     266        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     267        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     268        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     269        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     270        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
     271};
     272
     273#endif
    95274
    96275/*
     
    556735                        lead_chars[i] = '_';
    557736                }
    558                 lead_chars[i] = toupper_ascii(lead_chars[i]);
     737                lead_chars[i] = toupper_m(lead_chars[i]);
    559738        }
    560739        for (;i<mangle_prefix;i++) {
     
    577756                        if (FLAG_CHECK(c, FLAG_ASCII)) {
    578757                                extension[extension_length++] =
    579                                         toupper_ascii(c);
     758                                        toupper_m(c);
    580759                        }
    581760                }
     
    614793
    615794        return True;
    616 }
    617 
    618 /* initialise the flags table
    619 
    620   we allow only a very restricted set of characters as 'ascii' in this
    621   mangling backend. This isn't a significant problem as modern clients
    622   use the 'long' filenames anyway, and those don't have these
    623   restrictions.
    624 */
    625 static void init_tables(void)
    626 {
    627         int i;
    628 
    629         memset(char_flags, 0, sizeof(char_flags));
    630 
    631         for (i=1;i<128;i++) {
    632                 if (i <= 0x1f) {
    633                         /* Control characters. */
    634                         char_flags[i] |= FLAG_ILLEGAL;
    635                 }
    636 
    637                 if ((i >= '0' && i <= '9') ||
    638                     (i >= 'a' && i <= 'z') ||
    639                     (i >= 'A' && i <= 'Z')) {
    640                         char_flags[i] |=  (FLAG_ASCII | FLAG_BASECHAR);
    641                 }
    642                 if (strchr("_-$~", i)) {
    643                         char_flags[i] |= FLAG_ASCII;
    644                 }
    645 
    646                 if (strchr("*\\/?<>|\":", i)) {
    647                         char_flags[i] |= FLAG_ILLEGAL;
    648                 }
    649 
    650                 if (strchr("*?\"<>", i)) {
    651                         char_flags[i] |= FLAG_WILDCARD;
    652                 }
    653         }
    654 
    655         memset(base_reverse, 0, sizeof(base_reverse));
    656         for (i=0;i<36;i++) {
    657                 base_reverse[(unsigned char)base_forward(i)] = i;
    658         }
    659 
    660         /* fill in the reserved names flags. These are used as a very
    661            fast filter for finding possible DOS reserved filenames */
    662         for (i=0; reserved_names[i]; i++) {
    663                 unsigned char c1, c2, c3, c4;
    664 
    665                 c1 = (unsigned char)reserved_names[i][0];
    666                 c2 = (unsigned char)reserved_names[i][1];
    667                 c3 = (unsigned char)reserved_names[i][2];
    668                 c4 = (unsigned char)reserved_names[i][3];
    669 
    670                 char_flags[c1] |= FLAG_POSSIBLE1;
    671                 char_flags[c2] |= FLAG_POSSIBLE2;
    672                 char_flags[c3] |= FLAG_POSSIBLE3;
    673                 char_flags[c4] |= FLAG_POSSIBLE4;
    674                 char_flags[tolower_ascii(c1)] |= FLAG_POSSIBLE1;
    675                 char_flags[tolower_ascii(c2)] |= FLAG_POSSIBLE2;
    676                 char_flags[tolower_ascii(c3)] |= FLAG_POSSIBLE3;
    677                 char_flags[tolower_ascii(c4)] |= FLAG_POSSIBLE4;
    678 
    679                 char_flags[(unsigned char)'.'] |= FLAG_POSSIBLE4;
    680         }
    681795}
    682796
     
    705819        }
    706820
     821#if DYNAMIC_MANGLE_TABLES
    707822        init_tables();
     823#endif
    708824        mangle_reset();
    709825
Note: See TracChangeset for help on using the changeset viewer.