lib/util_unistr.c:
authorJeremy Allison <jra@samba.org>
Wed, 10 May 2000 22:47:09 +0000 (22:47 +0000)
committerJeremy Allison <jra@samba.org>
Wed, 10 May 2000 22:47:09 +0000 (22:47 +0000)
libsmb/clilist.c:
rpc_server/srv_spoolss_nt.c:
smbd/trans2.c: Changed unistr_to_ascii to unistr_to_dos - do codepage conversion.
msdfs/msdfs.c: Removed stub unistr_to_dos.
libsmb/pwd_cache.c: Removed obfuscation functions as they don't do anything and
don't add any security.
Jeremy.
(This used to be commit 1ed146467e764e6a81d8f78cd58fb5765ebf5d21)

source3/include/proto.h
source3/lib/util_unistr.c
source3/libsmb/clilist.c
source3/libsmb/pwd_cache.c
source3/msdfs/msdfs.c
source3/rpc_server/srv_spoolss_nt.c
source3/smbd/trans2.c

index 626820ae0eff95af111e47ad98b4caf32214cdee..de27782fdee3f0bf729f336c42a4a190f1026876 100644 (file)
@@ -496,8 +496,8 @@ char *string_truncate(char *s, int length);
 /*The following definitions come from  lib/util_unistr.c  */
 
 int dos_PutUniCode(char *dst,const char *src, ssize_t len, BOOL null_terminate);
-void ascii_to_unistr(char *dest, const char *src, int maxlen);
-void unistr_to_ascii(char *dest, char *src, int len);
+void ascii_to_unistr(char *dest, const char *src, size_t maxlen);
+void unistr_to_dos(char *dest, char *src, size_t len);
 char *skip_unibuf(char *src, size_t len);
 char *dos_unistrn2(uint16 *src, int len);
 char *dos_unistr2(uint16 *src);
@@ -771,7 +771,6 @@ BOOL remote_password_change(const char *remote_machine, const char *user_name,
 /*The following definitions come from  libsmb/pwd_cache.c  */
 
 void pwd_init(struct pwd_info *pwd);
-void pwd_obfuscate_key(struct pwd_info *pwd, uint32 int_key, char *str_key);
 BOOL pwd_compare(struct pwd_info *pwd1, struct pwd_info *pwd2);
 void pwd_read(struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt);
 void pwd_set_nullpwd(struct pwd_info *pwd);
@@ -881,7 +880,6 @@ int setup_dfs_referral(char* pathname, int max_referral_level,
 int dfs_path_error(char* inbuf, char* outbuf);
 int setup_dfs_referral(char* pathname, int max_referral_level, 
                       char** ppdata);
-void unistr_to_dos(char* dst,char* src)               ;
 
 /*The following definitions come from  msdfs/msdfs_tdb.c  */
 
index 0ca148ba949f9e060097cc7aa7868cb8d80c2db3..4a66adc0fdf2c035f49c685095af1cd63311ef3c 100644 (file)
@@ -91,7 +91,7 @@ int dos_PutUniCode(char *dst,const char *src, ssize_t len, BOOL null_terminate)
  Help ! Fix Me ! Fix Me !
 ********************************************************************/
 
-void ascii_to_unistr(char *dest, const char *src, int maxlen)
+void ascii_to_unistr(char *dest, const char *src, size_t maxlen)
 {
        char *destend = dest + maxlen;
        char c;
@@ -107,24 +107,28 @@ void ascii_to_unistr(char *dest, const char *src, int maxlen)
 }
 
 /*******************************************************************
- Pull an ASCII string out of a UNICODE array .
-
- Warning: doesn't do any codepage !!! BAD !!!
- Help ! Fix Me ! Fix Me !
+ Pull a DOS codepage string out of a UNICODE array. len is in bytes.
 ********************************************************************/
 
-void unistr_to_ascii(char *dest, char *src, int len)
+void unistr_to_dos(char *dest, char *src, size_t len)
 {
        char *destend = dest + len;
-       uint16 c;
 
        while (dest < destend) {
-               c = SVAL(src, 0);
+               uint16 ucs2_val = SVAL(src,0);
+               uint16 cp_val = ucs2_to_doscp[ucs2_val];
+
                src += 2;
-               if (c == 0) break;
 
-               *(dest++) = (char)c;
+               if (ucs2_val == 0)
+                       break;
+
+               if (cp_val < 256)
+                       *dest++ = (char)cp_val;
+               else {
+                       *dest++ = (cp_val >> 8) & 0xff;
+                       *dest++ = (cp_val & 0xff);
+               }
        }
 
        *dest = 0;
index f3e40335398639f031bfab284165e951cfbef0d4..2e904e06b7d285627f64b9044ce4041b7f63432f 100644 (file)
@@ -126,7 +126,7 @@ static int interpret_long_filename(int level,char *p,file_info *finfo)
                                p += 2; 
                                if (p[1] == 0 && slen > 1) {
                                        /* NT has stuffed up again */
-                                       unistr_to_ascii(finfo->short_name, p, slen/2);
+                                       unistr_to_dos(finfo->short_name, p, slen/2);
                                } else {
                                        strncpy(finfo->short_name, p, 12);
                                        finfo->short_name[12] = 0;
index 4f02c42efbdcc2ca851e971b34c54fa35815851c..1c5f8b51761aac3b69f753347dc9c681dc0b88db 100644 (file)
@@ -40,47 +40,20 @@ void pwd_init(struct pwd_info *pwd)
        pwd->crypted   = False;
 }
 
-/****************************************************************************
-de-obfuscates a password
-****************************************************************************/
-static void pwd_deobfuscate(struct pwd_info *pwd)
-{
-}
-
-/****************************************************************************
-obfuscates a password
-****************************************************************************/
-static void pwd_obfuscate(struct pwd_info *pwd)
-{
-}
-
-/****************************************************************************
-sets the obfuscation key info
-****************************************************************************/
-void pwd_obfuscate_key(struct pwd_info *pwd, uint32 int_key, char *str_key)
-{
-}
-
 /****************************************************************************
 compares two passwords.  hmm, not as trivial as expected.  hmm.
 ****************************************************************************/
 BOOL pwd_compare(struct pwd_info *pwd1, struct pwd_info *pwd2)
 {
-       pwd_deobfuscate(pwd1);
-       pwd_deobfuscate(pwd2);
        if (pwd1->cleartext && pwd2->cleartext)
        {
                if (strequal(pwd1->password, pwd2->password))
                {
-                       pwd_obfuscate(pwd1);
-                       pwd_obfuscate(pwd2);
                        return True;
                }
        }
        if (pwd1->null_pwd && pwd2->null_pwd)
        {
-               pwd_obfuscate(pwd1);
-               pwd_obfuscate(pwd2);
                return True;
        }
 
@@ -94,8 +67,6 @@ BOOL pwd_compare(struct pwd_info *pwd1, struct pwd_info *pwd2)
 #endif
                if (memcmp(pwd1->smb_nt_pwd, pwd2->smb_nt_pwd, 16) == 0)
                {
-                       pwd_obfuscate(pwd1);
-                       pwd_obfuscate(pwd2);
                        return True;
                }
 #ifdef DEBUG_PASSWORD
@@ -105,13 +76,9 @@ BOOL pwd_compare(struct pwd_info *pwd1, struct pwd_info *pwd2)
 #endif
                if (memcmp(pwd1->smb_lm_pwd, pwd2->smb_lm_pwd, 16) == 0)
                {
-                       pwd_obfuscate(pwd1);
-                       pwd_obfuscate(pwd2);
                        return True;
                }
        }
-       pwd_obfuscate(pwd1);
-       pwd_obfuscate(pwd2);
        return False;
 }
 
@@ -164,8 +131,6 @@ void pwd_set_cleartext(struct pwd_info *pwd, char *clr)
        pwd->cleartext = True;
        pwd->null_pwd  = False;
        pwd->crypted   = False;
-
-       pwd_obfuscate(pwd);
 }
 
 /****************************************************************************
@@ -173,7 +138,6 @@ void pwd_set_cleartext(struct pwd_info *pwd, char *clr)
  ****************************************************************************/
 void pwd_get_cleartext(struct pwd_info *pwd, char *clr)
 {
-       pwd_deobfuscate(pwd);
        if (pwd->cleartext)
        {
                fstrcpy(clr, pwd->password);
@@ -183,7 +147,6 @@ void pwd_get_cleartext(struct pwd_info *pwd, char *clr)
        {
                clr[0] = 0;
        }
-       pwd_obfuscate(pwd);
 }
 
 /****************************************************************************
@@ -214,8 +177,6 @@ void pwd_set_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
        pwd->null_pwd  = False;
        pwd->cleartext = False;
        pwd->crypted   = False;
-
-       pwd_obfuscate(pwd);
 }
 
 /****************************************************************************
@@ -223,7 +184,6 @@ void pwd_set_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
  ****************************************************************************/
 void pwd_get_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
 {
-       pwd_deobfuscate(pwd);
        if (lm_pwd != NULL)
        {
                memcpy(lm_pwd, pwd->smb_lm_pwd, 16);
@@ -232,7 +192,6 @@ void pwd_get_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
        {
                memcpy(nt_pwd, pwd->smb_nt_pwd, 16);
        }
-       pwd_obfuscate(pwd);
 }
 
 /****************************************************************************
@@ -251,8 +210,6 @@ void pwd_make_lm_nt_16(struct pwd_info *pwd, char *clr)
        pwd->null_pwd  = False;
        pwd->cleartext = False;
        pwd->crypted = False;
-
-       pwd_obfuscate(pwd);
 }
 
 /****************************************************************************
@@ -260,7 +217,6 @@ void pwd_make_lm_nt_16(struct pwd_info *pwd, char *clr)
  ****************************************************************************/
 void pwd_make_lm_nt_owf(struct pwd_info *pwd, uchar cryptkey[8])
 {
-       pwd_deobfuscate(pwd);
 
 #ifdef DEBUG_PASSWORD
        DEBUG(100,("client cryptkey: "));
@@ -286,8 +242,6 @@ void pwd_make_lm_nt_owf(struct pwd_info *pwd, uchar cryptkey[8])
 #endif
 
        pwd->crypted = True;
-
-       pwd_obfuscate(pwd);
 }
 
 /****************************************************************************
@@ -295,7 +249,6 @@ void pwd_make_lm_nt_owf(struct pwd_info *pwd, uchar cryptkey[8])
  ****************************************************************************/
 void pwd_get_lm_nt_owf(struct pwd_info *pwd, uchar lm_owf[24], uchar nt_owf[24])
 {
-       pwd_deobfuscate(pwd);
        if (lm_owf != NULL)
        {
                memcpy(lm_owf, pwd->smb_lm_owf, 24);
@@ -304,5 +257,4 @@ void pwd_get_lm_nt_owf(struct pwd_info *pwd, uchar lm_owf[24], uchar nt_owf[24])
        {
                memcpy(nt_owf, pwd->smb_nt_owf, 24);
        }
-       pwd_obfuscate(pwd);
 }
index f1b19dfe02efea5d39dd5aecdc28b25b9e5804b4..aadc63f04e03275e6d4b48ac67bc218642f1b51f 100644 (file)
@@ -438,19 +438,3 @@ int setup_dfs_referral(char* pathname, int max_referral_level,
 }
 
 #endif
-
-/* Trivial fn that chops off upper bytes to convert unicode to dos */
-void unistr_to_dos(char* dst,char* src)               
-{
-  pstring s;
-  int i=0;
-
-  for(i=0;SVAL(src,i*2) && i<1024;i++)
-    {
-      s[i]= SVAL(src,i*2) & 0xff;
-    }
-  s[i]=0;
-
-  safe_strcpy(dst,s,1024);
-  DEBUG(10,("converted unistring to %s\n",s));
-}
index 43f0c9498744af986a964a82720d0087a03c19c3..34e459d72bec494a97991143e0ff3629c4070ad9 100644 (file)
@@ -582,8 +582,8 @@ static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *u
 
 static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode)
 {
-       unistr_to_ascii(nt_devmode->devicename, (char *)devmode.devicename.buffer, 31);
-       unistr_to_ascii(nt_devmode->formname, (char *)devmode.formname.buffer, 31);
+       unistr_to_dos(nt_devmode->devicename, (char *)devmode.devicename.buffer, 31);
+       unistr_to_dos(nt_devmode->formname, (char *)devmode.formname.buffer, 31);
 
        nt_devmode->specversion=devmode.specversion;
        nt_devmode->driverversion=devmode.driverversion;
index 55c0b306b078c968f6ddcbecf74cf77a40a48b6d..e0156c083dbe365cf3f343f489efaacc0b22854f 100644 (file)
@@ -2118,7 +2118,7 @@ static int call_trans2getdfsreferral(connection_struct *conn, char* inbuf,
   /* NT always sends in UNICODE, may not set UNICODE flag */
   if(NT_arch || (SVAL(inbuf,smb_flg2) & FLAGS2_UNICODE_STRINGS))
     {
-      unistr_to_dos(pathname, &params[2]);
+      unistr_to_dos(pathname, &params[2], sizeof(pathname));
       DEBUG(10,("UNICODE referral for %s\n",pathname));
     }
   else