Added other_safe_chars to alpha_strcpy(). Needs testing but is a better
authorJeremy Allison <jra@samba.org>
Sat, 23 Jun 2001 07:22:16 +0000 (07:22 +0000)
committerJeremy Allison <jra@samba.org>
Sat, 23 Jun 2001 07:22:16 +0000 (07:22 +0000)
fix for the problem.
Jeremy.
(This used to be commit e059fffd03a1382fb2b7059b6de369d9fc765a17)

source3/include/smb.h
source3/lib/util_str.c
source3/lib/util_unistr.c
source3/smbd/message.c
source3/smbd/reply.c

index c4c9664c5ce42d820c3d164bb8524f3fe6f0b221..7a7c2bcedecd5c2f9b263935106b07a145c54858 100644 (file)
@@ -1662,6 +1662,8 @@ typedef struct user_struct
 #define MAP_TO_GUEST_ON_BAD_USER 1
 #define MAP_TO_GUEST_ON_BAD_PASSWORD 2
 
+#define SAFE_NETBIOS_CHARS ". -_"
+
 #include "nsswitch/winbindd_nss.h"
 #include "smb_acls.h"
 
index f1376fe0f7b45313028b9ad6a0984221ad25f4a3..1c1b31a83c00b1db7bed39bf564d5f6b22d806fb 100644 (file)
@@ -933,11 +933,12 @@ char *safe_strcat(char *dest, const char *src, size_t maxlength)
 
 /*******************************************************************
  Paranoid strcpy into a buffer of given length (includes terminating
- zero. Strips out all but 'a-Z0-9' and replaces with '_'. Deliberately
- does *NOT* check for multibyte characters. Don't change it !
+ zero. Strips out all but 'a-Z0-9' and the character in other_safe_chars
+ and replaces with '_'. Deliberately does *NOT* check for multibyte
+ characters. Don't change it !
 ********************************************************************/
 
-char *alpha_strcpy(char *dest, const char *src, size_t maxlength)
+char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength)
 {
        size_t len, i;
 
@@ -955,9 +956,12 @@ char *alpha_strcpy(char *dest, const char *src, size_t maxlength)
        if (len >= maxlength)
                len = maxlength - 1;
 
+       if (!other_safe_chars)
+               other_safe_chars = "";
+
        for(i = 0; i < len; i++) {
                int val = (src[i] & 0xff);
-               if(isupper(val) ||islower(val) || isdigit(val))
+               if(isupper(val) || islower(val) || isdigit(val) || strchr(other_safe_chars, val))
                        dest[i] = src[i];
                else
                        dest[i] = '_';
index 70586651456e385376aa55c1691dd7683e988957..96aa62a283c5bb4562f65a3f3a4d5a512c65a22b 100644 (file)
@@ -1453,9 +1453,10 @@ BOOL str_is_all_w(const smb_ucs2_t *s,smb_ucs2_t c)
  maxlength is in ucs2 units.
 ********************************************************************/
 
-smb_ucs2_t *alpha_strcpy_w(smb_ucs2_t *dest, const smb_ucs2_t *src, size_t maxlength)
+smb_ucs2_t *alpha_strcpy_w(smb_ucs2_t *dest, const smb_ucs2_t *src, const smb_ucs2_t *other_safe_chars, size_t maxlength)
 {
        size_t len, i;
+       smb_ucs2_t nullstr_w = (smb_ucs2_t)0;
 
        if (!dest) {
                DEBUG(0,("ERROR: NULL dest in alpha_strcpy_w\n"));
@@ -1471,9 +1472,12 @@ smb_ucs2_t *alpha_strcpy_w(smb_ucs2_t *dest, const smb_ucs2_t *src, size_t maxle
        if (len >= maxlength)
                len = maxlength - 1;
 
+       if (!other_safe_chars)
+               other_safe_chars = &nullstr_w;
+
        for(i = 0; i < len; i++) {
                smb_ucs2_t val = src[i];
-               if(isupper_w(val) ||islower_w(val) || isdigit_w(val))
+               if(isupper_w(val) ||islower_w(val) || isdigit_w(val) || strchr_w(other_safe_chars, val))
                        dest[i] = src[i];
                else
                        dest[i] = (smb_ucs2_t)'_';
index a023650c74abd321a230e9b0925f63f704989900..bae9f6c906a6b614650dfd29523cb799bc74a056 100644 (file)
@@ -86,8 +86,8 @@ static void msg_deliver(void)
       pstring s;
 
       pstrcpy(s,lp_msg_command());
-      pstring_sub(s,"%f",alpha_strcpy(alpha_msgfrom,msgfrom,sizeof(alpha_msgfrom)));
-      pstring_sub(s,"%t",alpha_strcpy(alpha_msgto,msgto,sizeof(alpha_msgto)));
+      pstring_sub(s,"%f",alpha_strcpy(alpha_msgfrom,msgfrom,NULL,sizeof(alpha_msgfrom)));
+      pstring_sub(s,"%t",alpha_strcpy(alpha_msgto,msgto,NULL,sizeof(alpha_msgto)));
       standard_sub_basic(s);
       pstring_sub(s,"%s",name);
       smbrun(s,NULL);
index 0c40e5f2b3a98e7c318b485471adcd6ee40b73ed..da4659dfa159b1aaeba00d4835246112b2268767 100644 (file)
@@ -96,7 +96,7 @@ int reply_special(char *inbuf,char *outbuf)
                remote_machine[15] = 0;
                trim_string(remote_machine," "," ");
                strlower(remote_machine);
-               alpha_strcpy(remote_machine,remote_machine,sizeof(remote_machine)-1);
+               alpha_strcpy(remote_machine,remote_machine,SAFE_NETBIOS_CHARS,sizeof(remote_machine)-1);
 
                fstrcpy(local_machine,name1);
                len = strlen(local_machine);
@@ -106,7 +106,7 @@ int reply_special(char *inbuf,char *outbuf)
                }
                trim_string(local_machine," "," ");
                strlower(local_machine);
-               alpha_strcpy(local_machine,local_machine,sizeof(local_machine)-1);
+               alpha_strcpy(local_machine,local_machine,SAFE_NETBIOS_CHARS,sizeof(local_machine)-1);
 
                if (name_type == 'R') {
                        /* We are being asked for a pathworks session ---