summaryrefslogtreecommitdiff
path: root/source/smbd/mangle.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/smbd/mangle.c')
-rw-r--r--source/smbd/mangle.c193
1 files changed, 128 insertions, 65 deletions
diff --git a/source/smbd/mangle.c b/source/smbd/mangle.c
index 8f1490c528d..829e307a85b 100644
--- a/source/smbd/mangle.c
+++ b/source/smbd/mangle.c
@@ -2,7 +2,7 @@
Unix SMB/Netbios implementation.
Version 1.9.
Name mangling
- Copyright (C) Andrew Tridgell 1992-1995
+ Copyright (C) Andrew Tridgell 1992-1997
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,7 +20,6 @@
*/
#include "includes.h"
-#include "loadparm.h"
extern int DEBUGLEVEL;
extern int case_default;
@@ -80,7 +79,7 @@ static BOOL is_reserved_msdos(char *fname)
/****************************************************************************
return True if a name is in 8.3 dos format
****************************************************************************/
-BOOL is_8_3(char *fname)
+BOOL is_8_3(char *fname, BOOL check_case)
{
int len;
char *dot_pos;
@@ -90,11 +89,9 @@ BOOL is_8_3(char *fname)
if (slash_pos) fname = slash_pos+1;
len = strlen(fname);
- dot_pos = strchr(fname,'.');
-
DEBUG(5,("checking %s for 8.3\n",fname));
- if (case_mangle)
+ if (check_case && case_mangle)
switch (case_default)
{
case CASE_LOWER:
@@ -122,32 +119,38 @@ BOOL is_8_3(char *fname)
/* %%% A nice improvment to name mangling would be to translate
filename to ANSI charset on the smb server host */
+ dot_pos = strchr(fname,'.');
+
{
char *p = fname;
-#ifdef KANJI
- dot_pos = 0;
- while (*p)
+ if(lp_client_code_page() == KANJI_CODEPAGE)
+ {
+ dot_pos = 0;
+ while (*p)
{
- if (is_shift_jis (*p)) {
- p += 2;
- } else if (is_kana (*p)) {
- p ++;
- } else {
- if (*p == '.' && !dot_pos)
- dot_pos = (char *) p;
- if (!isdoschar(*p))
- return(False);
- p++;
- }
- }
-#else
- while (*p)
+ if (is_shift_jis (*p))
+ p += 2;
+ else if (is_kana (*p))
+ p ++;
+ else
+ {
+ if (*p == '.' && !dot_pos)
+ dot_pos = (char *) p;
+ if (!isdoschar(*p))
+ return(False);
+ p++;
+ }
+ }
+ }
+ else
+ {
+ while (*p)
{
- if (!isdoschar(*p))
- return(False);
- p++;
+ if (!isdoschar(*p))
+ return(False);
+ p++;
}
-#endif /* KANJI */
+ }
}
/* no dot and less than 9 means OK */
@@ -270,7 +273,7 @@ BOOL check_mangled_stack(char *s)
}
if (check_extension && !strchr(mangled_stack[i],'.'))
{
- strcpy(tmpname,mangled_stack[i]);
+ pstrcpy(tmpname,mangled_stack[i]);
strcat(tmpname,extension);
mangle_name_83(tmpname);
if (strequal(tmpname,s))
@@ -304,7 +307,7 @@ static char *map_filename(char *s, /* This is null terminated */
pstring pat;
StrnCpy(pat, pattern, len); /* Get pattern into a proper string! */
- strcpy(matching_bit,""); /* Match but no star gets this. */
+ pstrcpy(matching_bit,""); /* Match but no star gets this. */
pp = pat; /* Initialise the pointers. */
sp = s;
if ((len == 1) && (*pattern == '*')) {
@@ -384,13 +387,10 @@ BOOL is_mangled(char *s)
/****************************************************************************
return a base 36 character. v must be from 0 to 35.
****************************************************************************/
-static char base36(int v)
+static char base36(unsigned int v)
{
- v = v % 36;
- if (v < 10)
- return('0'+v);
- else /* needed to work around a DEC C compiler bug */
- return('A' + (v-10));
+ static char basechars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ return basechars[v % 36];
}
@@ -418,9 +418,9 @@ static void do_fwd_mangled_map(char *s, char *MangledMap)
while (*start) {
while ((*start) && (*start != '('))
start++;
- start++; /* Skip the ( */
if (!*start)
continue; /* Always check for the end. */
+ start++; /* Skip the ( */
end = start; /* Search for the ' ' or a ')' */
DEBUG(5,("Start of first in pair '%s'\n", start));
while ((*end) && !((*end == ' ') || (*end == ')')))
@@ -446,7 +446,7 @@ static void do_fwd_mangled_map(char *s, char *MangledMap)
continue; /* Always check for the end. */
}
if (*end == '*') {
- strcpy(np, match_string);
+ pstrcpy(np, match_string);
np += strlen(match_string);
end++; /* Skip the '*' */
while ((*end) /* Not the end of string. */
@@ -460,7 +460,7 @@ static void do_fwd_mangled_map(char *s, char *MangledMap)
}
*np++ = '\0'; /* NULL terminate it. */
DEBUG(5,("End of second in pair '%s'\n", end));
- strcpy(s, new_string); /* Substitute with the new name. */
+ pstrcpy(s, new_string); /* Substitute with the new name. */
DEBUG(5,("s is now '%s'\n", s));
}
start = end; /* Skip a bit which cannot be wanted */
@@ -502,30 +502,90 @@ void mangle_name_83(char *s)
DEBUG(5,("Mangling name %s to ",s));
if (p)
- {
- if (p == s)
- strcpy(extension,"___");
- else
+ {
+ if (p == s)
+ strcpy(extension,"___");
+ else
{
*p++ = 0;
while (*p && extlen < 3)
- {
- if (isdoschar(*p) && *p != '.')
- extension[extlen++] = *p;
- p++;
- }
+ {
+ if(lp_client_code_page() == KANJI_CODEPAGE)
+ {
+ if (is_shift_jis (*p))
+ {
+ if (extlen < 2)
+ {
+ extension[extlen++] = p[0];
+ extension[extlen++] = p[1];
+ }
+ else
+ {
+ extension[extlen++] = base36 (((unsigned char) *p) % 36);
+ }
+ p += 2;
+ }
+ else if (is_kana (*p))
+ {
+ extension[extlen++] = p[0];
+ p++;
+ }
+ else
+ {
+ if (isdoschar (*p) && *p != '.')
+ extension[extlen++] = p[0];
+ p++;
+ }
+ }
+ else
+ {
+ if (isdoschar(*p) && *p != '.')
+ extension[extlen++] = *p;
+ p++;
+ }
+ }
extension[extlen] = 0;
- }
}
+ }
p = s;
while (*p && baselen < 5)
+ {
+ if(lp_client_code_page() == KANJI_CODEPAGE)
+ {
+ if (is_shift_jis (*p))
+ {
+ if (baselen < 4)
+ {
+ base[baselen++] = p[0];
+ base[baselen++] = p[1];
+ }
+ else
+ {
+ base[baselen++] = base36 (((unsigned char) *p) % 36);
+ }
+ p += 2;
+ }
+ else if (is_kana (*p))
+ {
+ base[baselen++] = p[0];
+ p++;
+ }
+ else
+ {
+ if (isdoschar (*p) && *p != '.')
+ base[baselen++] = p[0];
+ p++;
+ }
+ }
+ else
{
if (isdoschar(*p) && *p != '.')
- base[baselen++] = *p;
+ base[baselen++] = *p;
p++;
}
+ }
base[baselen] = 0;
csum = csum % (36*36);
@@ -551,8 +611,9 @@ static BOOL illegal_name(char *name)
static BOOL initialised=False;
unsigned char *s;
- if (!initialised) {
- char *ill = "*\\/?<>|\":{}";
+ if (!initialised)
+ {
+ char *ill = "*\\/?<>|\":";
initialised = True;
bzero((char *)illegal,256);
@@ -560,21 +621,23 @@ static BOOL illegal_name(char *name)
illegal[*s] = True;
}
-#ifdef KANJI
- for (s = (unsigned char *)name; *s;) {
- if (is_shift_jis (*s)) {
- s += 2;
- } else if (illegal[*s]) {
- return(True);
- } else {
- s++;
+ if(lp_client_code_page() == KANJI_CODEPAGE)
+ {
+ for (s = (unsigned char *)name; *s;) {
+ if (is_shift_jis (*s)) {
+ s += 2;
+ } else if (illegal[*s]) {
+ return(True);
+ } else {
+ s++;
+ }
}
}
-#else
- for (s = (unsigned char *)name;*s;s++)
- if (illegal[*s]) return(True);
-#endif
-
+ else
+ {
+ for (s = (unsigned char *)name;*s;s++)
+ if (illegal[*s]) return(True);
+ }
return(False);
}
@@ -597,7 +660,7 @@ BOOL name_map_mangle(char *OutName,BOOL need83,int snum)
}
/* check if it's already in 8.3 format */
- if (need83 && !is_8_3(OutName)) {
+ if (need83 && !is_8_3(OutName, True)) {
if (!lp_manglednames(snum)) return(False);
/* mangle it into 8.3 */