No subject


Tue Dec 2 03:01:20 GMT 2003


about Multi-Byte treatment problem existing in trim_string later.


There are three major changes I did against original trim_string().
That is
1) Changed parameters.
2) Changed how you trim front string.
3) Changed how you trim back string.


1) Changed parameters:
  Original trim_string() looks like this:

BOOL trim_string(char *s,const char *front,const char *back)

The new code looks like this:

BOOL trim_string( char *s, long s_len, const char *front, const long front_len,const char *back, const long back_len )

Now each string have it's length right after.

reason:
	If you look carefully at the diff patch, you'll find that
	most of the parameter front, and back, are ether
	NULL, or string literal.

	For string literal, we found out that equasion

	strlen( <string literal> ) + sizeof( char )
	 == sizeof( <string literal> )

	is always true. This is true for any C compiler which meets
	K&R v1 or later. At least I, nor SUG-J people, could not
        find any exceptions.

	So, instead of running strlen() for each parameter everytime
	it's nessasary, I simply added *_len parameter and made
	let caller fill what they know at compile time.

2) front trimming.

Let's suppose that we have "./././abcde" as original string,
and "./" for 'front'.

Original code does something like this:

  2-1-1) Look for front match.
    "./././abcde"
     == found!
  2-2-2) move string forward.
    "./././abcde"  -> "././abcde"
  2-1-3) Look for front match.
    "././abcde"
     == found!
  2-2-4) move string forward.
    "././abcde"  -> "./abcde"
  2-1-5) Look for front match.
    "./abcde"
     == found!
  2-2-6) move string forward.
    "./abcde"  -> "abcde"
  2-2-7) Look for front match.
    "abcde"
    fail.
  2-2-8) done.

As you can see, it's actually moving string eachtime it found the
front match. We know better way. New code now does like this:

  2-2-1) set head pointer to first character
     head
     v
    "./././abcde"

  2-2-2) Look for front match from 'head'.
     head
     v
    "./././abcde"
     == found!
  2-2-3) slide head to one after maching end.
       head
       v
    "./././abcde"
  2-2-4) Look for front match from 'head'.
       head
       v
    "./././abcde"
       == found!
  2-2-5) slide head to one after maching end.
         head
         v
    "./././abcde"
  2-2-6) Look for front match from 'head'.
         head
         v
    "./././abcde"
         == found!
  2-2-7) slide head to one after maching end.
           head
           v
    "./././abcde"
  2-2-8) Look for front match from 'head'.
           head
           v
    "./././abcde"
                failed.

  2-2-9) memmove ( string starting address, head, length of string from head )
           head
           v
    "./././abcde"  -> "abcde"


The current code will run tail trimming part before we do step 2-2-9,
so that only very last part of string is needed to be moved.


3) tail trimming.
Current tail trimming does something like this.
Suppose we have "abcde/./." and 'tail' as = "/."

  3-1-1) look for tail match
    "abcde/./."
            == found!
  3-1-2) scan from head to see if found point is really
         character starting point
     -------V  ! it is
    "abcde/./."
            ==
  3-1-3) trim the tail
     -------V
    "abcde/./." -> "abcde/."
            ==
  3-1-4) look for tail match
    "abcde/."
          == found!
  3-1-5) scan from head to see if found point is really
         character starting point
     -----V  ! it is
    "abcde/."
          ==
  3-1-6) trim the tail
     -----V
    "abcde/." -> "abcde"
          ==
  3-1-7) look for tail match
    "abcde"
              fail

According to comment, this "scan from head" is required to be done
each time, for Multibyte treatment. And since so, they made special
cases against all ASCII string. But this is not true. We don't need
to run like this. Now the new code does like this:

  3-2-1) set tail pointer to very tail
              V--- tailP
    "abcde/./."

  3-2-2) scan string backward looking for tail match
              V--- tailP
    "abcde/./."
            ==  found!
  3-2-3) slide tailP to top of found.
            V--- tailP
    "abcde/./."
  3-2-4) scan string backward looking for tail match
            V--- tailP
    "abcde/./."
          ==  found!
  3-2-5) slide tailP to top of found.
          V--- tailP
    "abcde/./."
  3-2-6) scan string backward looking for tail match
          V--- tailP
    "abcde/./."
		not found.
  3-2-7) scan from head if tailP is pointing at first byte of
         characters.
        i) if it is, simply trim at tailP.

                  V--- tailP
            "abcde/./."  -> "abcde"
             -----*
        ii) if it isn't ( suppose that character 'e' is 1st byte of
            multi-byte character ), slide tailP toward tail by
            one 'tail_len - sizeof( char )'. That's where next 
	    trimming candidate exist, and CONTINUE SCANNING.

                  V--- tailP            V--- tailP
            "abcde/./."      -> "abcde/./."
             ------*             -------*

            If we found first key point, then that's where we should
	    tail trim the string at. We all know that any trimming
            candidate existing after current point is first byte of
            character, even with Multibyte-cases. 


Now, new trim_string only need to scan string only once.


I tried to look for performance gain due to this fix, using Linux
kernel 2.4.0-test8 + gcc2.95.2 + -pg options. I've found the way to
re-start profiling signal after fork() on Linux.

# For those who don't know about this problem;
# Linux stops profiling signal when you fork(). And since so,
# you can't get time information about child processes.
# This, I think, is one of the Linux's bug. Usually, it is
# at exec() point where we should stop profiling signal.
# BTW, if you exec()-ed the child process to other program
# which is compiled with -pg options, it will re-start
# profiling again, because profiler initialization routine
# will be called at crt0.o, before main() is being called.
# So, this bug is one of very hard to find ones.

What I found was, when you run 660sec course of netbench against
Netfinity with 500MHz P-III and 256Mbyte of ram, smbd will require
only 67sec, that is, sampling signal was held only 6700 times, while
function call is being held 57Mega-times.

This tells us that gprof's sampling rate is too low, and that we
can't find any difference according to this changes. Not only,
priority lists generated by gprof is untrustable, what it's listing
is not heavy CPU time eater, but rather, UNLUCKY functions. So, I
don't really know how fast it became.
            


Okey, now here comes trim_string()'s weakpoint.

To understand this, Let's not think about real Multi-byte from
beginning. Instead, think about world that ASCII character set not
having capital letters as for example.

Since we all know that ASCII only uses from 0x01 - 0x7e, we can have
two way to solve how to describe Capital letters.

1) let's use, currently unused 0x80 bit as "CAPITAL" flags.
   this means, coding character like:
    0x80 | 'a' = 'A'

2) let's create "CAPITAL MARKING" letters.
   For example, let's surround characters we want to make capital
   with '<' and '>':
     { '<', 'a', '>' } = 'A'

Same with Multi-bytes. We have both type-1 and type-2 Multi-byte
codes.

Tipical Type-1 code is EUC, and SJIS( or should I call it Microsoft
Kanji ). Thanks to SUG-J's work, current trim_string() can handle
EUC and SJIS very well. They even made patch so that 3byte-EUC can
be treated as good as 2byte-EUC.

Tipical Type-2 code is JIS and ISO-2022. They both have surrounding
characters( not single byte, though ), and current trim_string()
can't handle this type of character set. To tell the truth, current
samba's string treatment algorithm can't handle this type at all.

We can't handle Type-2 because of many, many reasons, but let me
show you one of the most tipical cases.

  Suppose we want to describe string "HTTP". There's many way to
  do this:

     * '<http>'
     * '<h><ttp>'
     * '<ht><tp>'
     * '<htt><p>'
     * '<h><t><tp>'
     * '<h><tt><p>'
     * '<ht><t><p>'
     * '<h><t><t><p>'

  What's so bad about this is that all the above, have to match
  equivalently with each other, for they are describing exactly the
  same thing.

  Also, we have to be careful about what we will get if we remove
  very first character "H".
# Looking for maching point is itself hard problem, but we do have
# algorithm, so don't worry.

     * '<ttp>'
     * '<t><tp>'
     * '<tt><p>'
     * '<t><t><p>'

  We can have any one of these from any one of the given above.
  So, sometimes, trimming string might cause string length longer,
  which is not a good news, and even if it didn't, we still don't 
  know how many bytes will be removed.

  Currently, samba uses type 'pstring' and uses "COPY BACK" for
  function interface. Though this is not so good idea from
  performance point of view, it does works for ASCII, and Type-1
  Multi-byte strings. But it will fail with Type-2.


"So what? we're moving to Unicode", you might say.

Well, here comes real bad news. Unicode is not 'unified, character
per word, encoding' as Unicode work groups have declared. Unicode is
really "TYPE-2 Multi-word" character set. This is true for all
UCS-2, UCS-4, and UTF-8, which Windows uses.

Unicode merged kanji's which have same meaning, without deep
thinking. As result, we now have same character code for same
meaning but with extreamely different out-looking, and wishing to
have them distinguished.

http://charts.unicode.org/unihan/unihan.acgi$0x9aa8

have most famous example. The glyphs you will look, means Bone, and
for this reason, we call it "Bone-problem".

# Here, please let me use "<BONE>" for chinese glyph of this
# character, and "{BONE}" for Japanese glyph. "[BONE]" for
# Korian glyph.

Think about statement like this:

   Though Kanji started from China, we have different glyph.
   <BONE> for chinese and {BONE} for Japanese is good example.

Now, Since <BONE> and {BONE} have exactly same character code, we
can't tell the difference of these two on Unicode charset.  And
since glyphs are being selected according to country code, Unicode
simply requested to added "Switching Country code" before and after
each <BONE> and {BONE} characters.


This means, we now have NON-DISPLAYABLE MARKER which have same
problems as that of ISO-2022, or JIS. We have to make this country
codes into our mind, when treating Unicode.

And this case, we have to face for case even worse than case of JIS.
Now we have to face strings like

    *[BONE<{<<< >>>as for } ><BONE>]
    *[BONE] as for <BONE>
    *{[BONE] as for <BONE>}
    etc.......

kind of tricky examples coming as pathnames. We can' suppose that
passed PATH is cleanly normalized, for Microsoft never talked about
such a normalizations.

Even worse, if you are connecting to Chinese Windows, it will pass
character "BONE" as if it is declared "<BONE>", while Japanese
Windows will pass character "BONE" as if it is declared "{BONE}",
and same story comes for "[BONE]" for Korian version. This is
because we have "DEFAULT" treatment.

We have to treat all these three as different filename.


Even current Head branch have not even thought about this kind of
Unicode nightmares. But thinking about all these cases is what
really Multilingualization really means. And in my understanding,
current samba's string treating strategy can't handle this kind of
problems.

So, we have to re-write trim_string() as well as entire Samba's
filename treatings from scratch.


This, is weakpoint of current (including new) trim_string().
Current trim_string() nor current trim_string_w() can't treat
Unicode correctly.



Okey. Thanks for reading all the above, here comes diffs.
All the problems are for Jeremy and Andrew to solve (^o^).
# Well, I do have solution, but I don't think they'll like it.
# And I've been claiming for over and overs (^o-).

Enjoy.
---- 
Kenichi Okuyama at Tokyo Research Lab, IBM-Japan, Co.




diff -r -u samba-2.2.orig/source/client/client.c samba-2.2/source/client/client.c
--- samba-2.2.orig/source/client/client.c	Wed Dec 27 11:18:21 2000
+++ samba-2.2/source/client/client.c	Wed Dec 27 11:53:28 2000
@@ -958,7 +958,9 @@
 		*ddir2 = 0;
 		
 		pstrcpy(ddir,mask);
-		trim_string(ddir,".",NULL);
+		trim_string(ddir, strlen( ddir ) + 1,
+                            ".", sizeof( "." ),
+                            NULL, 0 );
 		p = strtok(ddir,"/\\");
 		while (p) {
 			pstrcat(ddir2,p);
@@ -1121,7 +1123,9 @@
 	pstring s;
 	while (!feof(f)) {
 		if (!fgets(s,sizeof(s),f)) return(False);
-		trim_string(s,"./","\n");
+		trim_string( s, strlen( s ) + 1,
+                             "./", sizeof( "./" ),
+                             "\n", sizeof( "\n" ));
 		if (strncmp(s,name,strlen(name)) != 0) {
 			pstrcpy(name,s);
 			return(True);
@@ -1175,7 +1179,9 @@
 			pstring quest;
 
 			if (!fgets(lname,sizeof(lname),f)) break;
-			trim_string(lname,"./","\n");
+			trim_string(lname, strlen( lname ) + 1,
+                                    "./", sizeof( "./" ),
+                                    "\n", sizeof( "\n" ));
 			
 		again1:
 			
diff -r -u samba-2.2.orig/source/lib/util.c samba-2.2/source/lib/util.c
--- samba-2.2.orig/source/lib/util.c	Wed Dec 27 11:18:23 2000
+++ samba-2.2/source/lib/util.c	Wed Dec 27 11:56:42 2000
@@ -369,7 +369,7 @@
       pstrcat(s,s1);
     }  
 
-  trim_string(s,NULL,"\\..");
+  trim_string(s, strlen( s ) + 1, NULL, 0, "\\..", sizeof("\\.."));
 
   all_string_sub(s, "\\.\\", "\\", 0);
 }
@@ -388,7 +388,7 @@
 
   /* Remove leading ./ characters */
   if(strncmp(s, "./", 2) == 0) {
-    trim_string(s, "./", NULL);
+    trim_string(s, strlen(s)+1, "./", sizeof( "./" ), NULL, 0);
     if(*s == 0)
       pstrcpy(s,"./");
   }
@@ -407,7 +407,7 @@
       pstrcat(s,s1);
     }  
 
-  trim_string(s,NULL,"/..");
+  trim_string(s, strlen( s ) + 1, NULL, 0, "/..", sizeof( "/.." ));
 }
 
 /****************************************************************************
@@ -1752,7 +1752,7 @@
 	static pstring fname;
 
 	pstrcpy(fname,lp_lockdir());
-	trim_string(fname,"","/");
+	trim_string(fname, strlen( fname ) + 1, "", sizeof( "" ), "/", sizeof( "/" ));
 	
 	if (!directory_exist(fname,NULL)) {
 		mkdir(fname,0755);
diff -r -u samba-2.2.orig/source/lib/util_str.c samba-2.2/source/lib/util_str.c
--- samba-2.2.orig/source/lib/util_str.c	Wed Dec 27 11:18:23 2000
+++ samba-2.2/source/lib/util_str.c	Wed Dec 27 11:44:23 2000
@@ -534,108 +534,115 @@
 }
 
 /*******************************************************************
-trim the specified elements off the front and back of a string
+ * trim the specified elements off the front and back of a string
+ * 
+ * s_len, front_len, back_len is length of string including '\0' at end.
+ * If, s, front, or back was NULL then each length should be 0.
+ * if "", then it should be 1, and so-on.
+ * if front or back was "string literal", then, lenght is equal to
+ * sizeof() that string literal.
 ********************************************************************/
 
-BOOL trim_string(char *s,const char *front,const char *back)
+BOOL trim_string( char *s, long s_len, const char *front, const long front_len,const char *back, const long back_len )
+                  
+                  
 {
   BOOL ret = False;
-  size_t front_len = (front && *front) ? strlen(front) : 0;
-  size_t back_len = (back && *back) ? strlen(back) : 0;
-  size_t s_len;
-
-  while (front_len && strncmp(s, front, front_len) == 0)
-  {
-    char *p = s;
-    ret = True;
-    while (1)
-    {
-      if (!(*p = p[front_len]))
-        break;
-      p++;
-    }
-  }
+    char	*sP;
 
-  /*
-   * We split out the multibyte code page
-   * case here for speed purposes. Under a
-   * multibyte code page we need to walk the
-   * string forwards only and multiple times.
-   * Thanks to John Blair for finding this
-   * one. JRA.
-   */
-
-  if(back_len)
-  {
-    if(!global_is_multibyte_codepage)
-    {
-      s_len = strlen(s);
-      while ((s_len >= back_len) && 
-             (strncmp(s + s_len - back_len, back, back_len)==0))  
-      {
-        ret = True;
-        s[s_len - back_len] = '\0';
-        s_len = strlen(s);
-      }
+    if ( !s ) {
+        return False;
     }
-    else
-    {
+    sP	= s;
 
-      /*
-       * Multibyte code page case.
-       * Keep going through the string, trying
-       * to match the 'back' string with the end
-       * of the string. If we get a match, truncate
-       * 'back' off the end of the string and
-       * go through the string again from the
-       * start. Keep doing this until we have
-       * gone through the string with no match
-       * at the string end.
-       */
-
-      size_t mb_back_len = str_charnum(back);
-      size_t mb_s_len = str_charnum(s);
-
-      while(mb_s_len >= mb_back_len)
-      {
-        size_t charcount = 0;
-        char *mbp = s;
+    /*
+     * remove "front" string from given "s", if it matches front part,
+     * recursively.
+     */
+    if ( front && front_len > 1 ) {
+        while (( s_len >= front_len )&&
+               ( memcmp( sP, front, front_len - 1 )) == 0 ) {
+            ret		= True;
+            sP		+= ( front_len - 1 );
+            s_len	-= ( front_len - 1 );
+        }
+    }
 
-        /*
-         * sbcs optimization.
-         */
-        if(!global_is_multibyte_codepage) {
-          while(charcount < (mb_s_len - mb_back_len)) {
-            mbp += 1;
-            charcount++;
-          }
-        } else {
-          while(charcount < (mb_s_len - mb_back_len)) {
-            size_t skip = skip_multibyte_char(*mbp);
-            mbp += (skip ? skip : 1);
-            charcount++;
-          }
+    /*
+     * we'll memmove sP to s later, after we're done with
+     * back part removal, for minimizing copy.
+     */
+
+
+    /*
+     * We split out the multibyte code page
+     * case here for speed purposes. Under a
+     * multibyte code page we need to walk the
+     * string forwards only and multiple times.
+     * Thanks to John Blair for finding this
+     * one. JRA.
+     */
+    /*
+     * This JRA's comment is partly correct, but partly wrong.
+     * You can always check from "end" part, and if it did not match,
+     * it means there is no possibility of finding one.
+     * If you found matching point, mark them, then look from front
+     * if marking point suits multi-byte string rule.
+     * Kenichi Okuyama.
+     */
+
+    if ( back && back_len > 1 ) {
+        char	*bP	= sP + s_len - back_len;
+        long	b_len	= s_len;
+
+        while (( b_len >= back_len )&&
+               ( memcmp( bP, back, back_len - 1 ) == 0 )) {
+            bP		-= ( back_len - 1 );
+            b_len	-= ( back_len - 1 );
         }
 
         /*
-         * mbp now points at mb_back_len multibyte
-         * characters from the end of s.
+         * You're here, means you ether have found match multiple times,
+         * or you found none. If you've found match, then bP should be
+         * moving.
          */
+        if ( bP != sP + s_len - back_len ) {
+            bP	+= ( back_len - 1 ); /* slide bP to first matching point. */
 
-        if(strcmp(mbp, back) == 0)
-        {
-          ret = True;
-          *mbp = '\0';
-          mb_s_len = str_charnum(s);
-          mbp = s;
+            if( !global_is_multibyte_codepage ) {
+                /* simply terminate */
+                (*bP)	= '\0';
+                s_len	= b_len;
+                ret	= True;
+            } else {
+                /* trace string from start. */
+                char	*cP	= sP;
+                while ( cP < sP + s_len - back_len ) {
+                    size_t	skip;
+                    skip	= skip_multibyte_char( *cP );
+                    cP	+= ( skip ? skip : 1 );
+                    if ( cP == bP ) {
+                        /* you found the match */
+                        (*bP)	= '\0';
+                        ret	= True;
+                        s_len	= b_len;
+                        break;
+                    }
+                    while (( cP > bP )&&( bP < sP + s_len - back_len )) {
+                        bP	+= ( back_len - 1 );
+                        b_len	+= ( back_len - 1 );
+                    }
+                }
+            }
         }
-        else
-          break;
-      } /* end while mb_s_len... */
-    } /* end else .. */
-  } /* end if back_len .. */
+    }
 
-  return(ret);
+    /* if front found matching point */
+    if ( sP != s ) {
+        /* slide string to buffer top */
+        memmove( s, sP, s_len );
+    }
+    return ret;
 }
 
 
diff -r -u samba-2.2.orig/source/libsmb/clifile.c samba-2.2/source/libsmb/clifile.c
--- samba-2.2.orig/source/libsmb/clifile.c	Wed Dec 27 11:18:23 2000
+++ samba-2.2/source/libsmb/clifile.c	Wed Dec 27 12:58:47 2000
@@ -705,7 +705,7 @@
 	char *p;
 	
 	safe_strcpy(path2,path,sizeof(pstring));
-	trim_string(path2,NULL,"\\");
+	trim_string(path2, strlen( path2 )+1, NULL, 0, "\\", sizeof("\\"));
 	if (!*path2) *path2 = '\\';
 	
 	memset(cli->outbuf,'\0',smb_size);
diff -r -u samba-2.2.orig/source/libsmb/namequery.c samba-2.2/source/libsmb/namequery.c
--- samba-2.2.orig/source/libsmb/namequery.c	Wed Dec 27 11:18:24 2000
+++ samba-2.2/source/libsmb/namequery.c	Wed Dec 27 12:59:19 2000
@@ -62,7 +62,8 @@
 	p++;
 	for (i=0;i< *num_names;i++) {
 		StrnCpy(ret[i].name,p,15);
-		trim_string(ret[i].name,NULL," ");
+		trim_string(ret[i].name, strlen( ret[i].name )+1,
+                            NULL, 0, " ", sizeof( " " ));
 		ret[i].type = CVAL(p,15);
 		ret[i].flags = p[16];
 		p += 18;
diff -r -u samba-2.2.orig/source/msdfs/msdfs.c samba-2.2/source/msdfs/msdfs.c
--- samba-2.2.orig/source/msdfs/msdfs.c	Wed Dec 27 11:18:26 2000
+++ samba-2.2/source/msdfs/msdfs.c	Wed Dec 27 13:00:34 2000
@@ -51,7 +51,7 @@
 
   ZERO_STRUCTP(pdp);
 
-  trim_string(temp,"\\","\\");
+  trim_string(temp, strlen( temp ) + 1, "\\", sizeof( "\\" ),"\\", sizeof( "\\" ));
   DEBUG(10,("temp in parse_dfs_path: .%s. after trimming \\'s\n",temp));
 
   /* now tokenize */
@@ -633,7 +633,7 @@
     {
       char* refpath = jn->referral_list[i].alternate_path;
       
-      trim_string(refpath, "\\", "\\");
+      trim_string(refpath, strlen( refpath ), "\\", sizeof( "\\" ), "\\", sizeof( "\\" ));
       if(*refpath == '\0')
 	continue;
       
diff -r -u samba-2.2.orig/source/nmbd/nmbd.c samba-2.2/source/nmbd/nmbd.c
--- samba-2.2.orig/source/nmbd/nmbd.c	Wed Dec 27 11:18:26 2000
+++ samba-2.2/source/nmbd/nmbd.c	Wed Dec 27 13:01:10 2000
@@ -610,7 +610,7 @@
   my_netbios_names[namecount++] = NULL;
   
   fstrcpy( local_machine, global_myname );
-  trim_string( local_machine, " ", " " );
+  trim_string( local_machine, strlen( local_machine )+1," ",sizeof(" ") , " ", sizeof( " " ));
   p = strchr( local_machine, ' ' );
   if (p)
     *p = 0;
diff -r -u samba-2.2.orig/source/nmbd/nmbd_browsesync.c samba-2.2/source/nmbd/nmbd_browsesync.c
--- samba-2.2.orig/source/nmbd/nmbd_browsesync.c	Wed Dec 27 11:18:26 2000
+++ samba-2.2/source/nmbd/nmbd_browsesync.c	Wed Dec 27 13:01:47 2000
@@ -217,7 +217,7 @@
       StrnCpy(qname,p,15);
       name_type = CVAL(p,15);
       nb_flags = get_nb_flags(&p[16]);
-      trim_string(qname,NULL," ");
+      trim_string(qname,strlen( qname )+1, NULL, 0," ",sizeof( " " ));
 
       p += 18;
 
@@ -448,7 +448,7 @@
       StrnCpy(qname,p,15);
       name_type = CVAL(p,15);
       nb_flags = get_nb_flags(&p[16]);
-      trim_string(qname,NULL," ");
+      trim_string(qname, strlen( qname )+1,NULL,0," "sizeof(" "));
 
       p += 18;
 
diff -r -u samba-2.2.orig/source/nmbd/nmbd_serverlistdb.c samba-2.2/source/nmbd/nmbd_serverlistdb.c
--- samba-2.2.orig/source/nmbd/nmbd_serverlistdb.c	Wed Dec 27 11:18:26 2000
+++ samba-2.2/source/nmbd/nmbd_serverlistdb.c	Wed Dec 27 13:02:07 2000
@@ -339,7 +339,7 @@
   updatecount++;
     
   pstrcpy(fname,lp_lockdir());
-  trim_string(fname,NULL,"/");
+  trim_string(fname,strlen( fname )+1,NULL, 0,"/",sizeof( "/" ));
   pstrcat(fname,"/");
   pstrcat(fname,SERVER_LIST);
   pstrcpy(fnamenew,fname);
diff -r -u samba-2.2.orig/source/param/loadparm.c samba-2.2/source/param/loadparm.c
--- samba-2.2.orig/source/param/loadparm.c	Wed Dec 27 11:18:26 2000
+++ samba-2.2/source/param/loadparm.c	Wed Dec 27 13:14:23 2000
@@ -1342,7 +1342,7 @@
 	else
 		StrnCpy(ret, s, len);
 
-	trim_string(ret, "\"", "\"");
+	trim_string(ret, strlen( ret )+1, "\"",sizeof("\""), "\"",sizeof("\""));
 
 	standard_sub_basic(ret);
 	return (ret);
diff -r -u samba-2.2.orig/source/printing/lpq_parse.c samba-2.2/source/printing/lpq_parse.c
--- samba-2.2.orig/source/printing/lpq_parse.c	Wed Dec 27 11:18:26 2000
+++ samba-2.2/source/printing/lpq_parse.c	Wed Dec 27 13:16:08 2000
@@ -833,14 +833,14 @@
 
   /* Make sure the status is valid */
   parse_line.space2 = '\0';
-  trim_string(parse_line.status, NULL, " ");
+  trim_string(parse_line.status, strlen(parse_line.status)+1, NULL, 0, " ",sizeof(" "));
   if (!strequal(parse_line.status, LPRNT_PRINTING) &&
       !strequal(parse_line.status, LPRNT_PAUSED) &&
       !strequal(parse_line.status, LPRNT_WAITING))
     return(False);
   
   parse_line.space3 = '\0';
-  trim_string(parse_line.jobname, NULL, " ");
+  trim_string(parse_line.jobname, strlen(parse_line.jobname),NULL,0, " ",sizeof(" "));
 
   buf->job = atoi(parse_line.jobid);
   buf->priority = 0;
@@ -904,7 +904,7 @@
 
   /* Get the job name */
   parse_line.space2[0] = '\0';
-  trim_string(parse_line.jobname, NULL, " ");
+  trim_string(parse_line.jobname,strlen(parse_line.jobname), NULL,0, " ",sizeof(" "));
   StrnCpy(buf->file, parse_line.jobname, sizeof(buf->file)-1);
 
   buf->priority = 0;
@@ -917,7 +917,7 @@
 
   /* Make sure we have a valid status */
   parse_line.space4[0] = '\0';
-  trim_string(parse_line.status, NULL, " ");
+  trim_string(parse_line.status,strlen(parse_line.status)+1, NULL,0, " ",sizeof(" "));
   if (!strequal(parse_line.status, LPROS2_PRINTING) &&
       !strequal(parse_line.status, LPROS2_PAUSED) &&
       !strequal(parse_line.status, LPROS2_WAITING))
diff -r -u samba-2.2.orig/source/printing/nt_printing.c samba-2.2/source/printing/nt_printing.c
--- samba-2.2.orig/source/printing/nt_printing.c	Wed Dec 27 11:18:26 2000
+++ samba-2.2/source/printing/nt_printing.c	Wed Dec 27 13:19:37 2000
@@ -1509,16 +1509,16 @@
     DEBUGADD(10,("info3->configfile      [%s]\n", info3->configfile));
 
 	/*pstrcat(line, info3->name);             pstrcat(line, ":");*/
-	trim_string(info3->configfile, "\\print$\\WIN40\\0\\", 0);
+	trim_string(info3->configfile,strlen(info3->configfile)+1, "\\print$\\WIN40\\0\\",sizeof("\\print$\\WIN40\\0\\"), NULL,0);
 	pstrcat(line, info3->configfile);
     pstrcat(line, ":");
-	trim_string(info3->datafile, "\\print$\\WIN40\\0\\", 0);
+	trim_string(info3->datafile,strlen(info3->datafile)+1, "\\print$\\WIN40\\0\\",sizeof("\\print$\\WIN40\\0\\"), NULL,0);
 	pstrcat(line, info3->datafile);
     pstrcat(line, ":");
-	trim_string(info3->helpfile, "\\print$\\WIN40\\0\\", 0);
+	trim_string(info3->helpfile,strlen(info3->helpfile)+1, "\\print$\\WIN40\\0\\",sizeof("\\print$\\WIN40\\0\\"),NULL, 0);
 	pstrcat(line, info3->helpfile);
     pstrcat(line, ":");
-	trim_string(info3->monitorname, "\\print$\\WIN40\\0\\", 0);
+	trim_string(info3->monitorname,strlen(info3->monitorname)+1, "\\print$\\WIN40\\0\\",sizeof("\\print$\\WIN40\\0\\"), NULL,0);
 	pstrcat(line, info3->monitorname);
     pstrcat(line, ":");
 	pstrcat(line, "RAW");                /*info3->defaultdatatype);*/
@@ -1527,7 +1527,7 @@
 	for (i=0; info3->dependentfiles &&
 		 *info3->dependentfiles[i]; i++) {
 		if (i) pstrcat(line, ",");               /* don't end in a "," */
-		trim_string(info3->dependentfiles[i], "\\print$\\WIN40\\0\\", 0);
+		trim_string(info3->dependentfiles[i],strlen(info3->dependentfiles[i])+1, "\\print$\\WIN40\\0\\",sizeof("\\print$\\WIN40\\0\\"), NULL,0);
 		pstrcat(line, info3->dependentfiles[i]);
 	}
 	
@@ -1705,8 +1705,8 @@
 	 */
 
 	if (info->servername[0]!='\0') {
-		trim_string(info->printername, info->servername, NULL);
-		trim_string(info->printername, "\\", NULL);
+		trim_string(info->printername,strlen(info->printername)+1, info->servername,strlen(info->servername)+1, NULL,0);
+		trim_string(info->printername,strlen(info->printername)+1, "\\",sizeof("\\"), NULL,0);
 		info->servername[0]='\0';
 	}
 
diff -r -u samba-2.2.orig/source/rpc_server/srv_dfs.c samba-2.2/source/rpc_server/srv_dfs.c
--- samba-2.2.orig/source/rpc_server/srv_dfs.c	Wed Dec 27 11:18:26 2000
+++ samba-2.2/source/rpc_server/srv_dfs.c	Wed Dec 27 13:20:27 2000
@@ -170,7 +170,7 @@
 	{
 	  pstring refpath;
 	  pstrcpy(refpath,jn.referral_list[i].alternate_path);
-	  trim_string(refpath, "\\", "\\");
+	  trim_string(refpath,strlen(refpath)+1, "\\",sizeof("\\"), "\\",sizeof("\\"));
 	  if(strequal(refpath, altpath))
 	    {
 	      *(jn.referral_list[i].alternate_path)='\0';
@@ -275,7 +275,7 @@
 	  struct referral* ref = &(j[i].referral_list[ii]);
 	  
 	  pstrcpy(path, ref->alternate_path);
-	  trim_string(path,"\\","");
+	  trim_string(path,strlen(path)+1,"\\",sizeof("\\"),"",sizeof(""));
 	  p = strrchr(path,'\\');
 	  if(p==NULL)
 	    {
diff -r -u samba-2.2.orig/source/smbd/connection.c samba-2.2/source/smbd/connection.c
--- samba-2.2.orig/source/smbd/connection.c	Wed Dec 27 11:18:27 2000
+++ samba-2.2/source/smbd/connection.c	Wed Dec 27 13:21:15 2000
@@ -562,13 +562,13 @@
 	/* For w-files, first look for explicit "wtmp dir" */
 	if (uw_name[0] == 'w') {
 		pstrcpy(dirname,lp_wtmpdir());
-		trim_string(dirname,"","/");
+		trim_string(dirname,strlen(dirname)+1,"",sizeof(""),"/",sizeof("/"));
 	}
 
 	/* For u-files and non-explicit w-dir, look for "utmp dir" */
 	if (dirname == 0 || strlen(dirname) == 0) {
 		pstrcpy(dirname,lp_utmpdir());
-		trim_string(dirname,"","/");
+		trim_string(dirname,strlen(dirname)+1,""sizeof(""),"/",sizeof("/"));
 	}
 
 	/* If explicit directory above, use it */
diff -r -u samba-2.2.orig/source/smbd/filename.c samba-2.2/source/smbd/filename.c
--- samba-2.2.orig/source/smbd/filename.c	Wed Dec 27 11:18:28 2000
+++ samba-2.2/source/smbd/filename.c	Wed Dec 27 13:21:36 2000
@@ -159,7 +159,7 @@
    * also trim trailing /'s.
    */
 
-  trim_string(name,"/","/");
+  trim_string(name,strlen(name)+1,"/",sizeof("/"),"/",sizeof("/"));
 
   /*
    * If we trimmed down to a single '\0' character
diff -r -u samba-2.2.orig/source/smbd/groupname.c samba-2.2/source/smbd/groupname.c
--- samba-2.2.orig/source/smbd/groupname.c	Wed Dec 27 11:18:28 2000
+++ samba-2.2/source/smbd/groupname.c	Wed Dec 27 13:22:10 2000
@@ -134,8 +134,8 @@
     if(!next_token(&s,windows_name, "\t\n\r=", sizeof(windows_name)))
       continue;
 
-    trim_string(unixname, " ", " ");
-    trim_string(windows_name, " ", " ");
+    trim_string(unixname,strlen(unixname)+1, " ",sizeof(" "), " ",sizeof(" "));
+    trim_string(windows_name,strlen(windows_name)+1, " ",sizeof(" "), " ",sizeof(" "));
 
     if (!*windows_name)
       continue;
diff -r -u samba-2.2.orig/source/smbd/password.c samba-2.2/source/smbd/password.c
--- samba-2.2.orig/source/smbd/password.c	Wed Dec 27 11:18:28 2000
+++ samba-2.2/source/smbd/password.c	Wed Dec 27 13:22:34 2000
@@ -892,7 +892,7 @@
   if (! lines) return False;
   for (i=0; lines[i]; i++) {
     char *buf = lines[i];
-    trim_string(buf," "," ");
+    trim_string(buf,strlen(buf)+1," ",sizeof(" ")," ",sizeof(" "));
 
     if (buf[0] != '#' && buf[0] != '\n') 
     {
diff -r -u samba-2.2.orig/source/smbd/reply.c samba-2.2/source/smbd/reply.c
--- samba-2.2.orig/source/smbd/reply.c	Wed Dec 27 11:18:28 2000
+++ samba-2.2/source/smbd/reply.c	Wed Dec 27 13:23:22 2000
@@ -96,7 +96,7 @@
 
 		fstrcpy(remote_machine,name2);
 		remote_machine[15] = 0;
-		trim_string(remote_machine," "," ");
+		trim_string(remote_machine,strlen(remove_machine)+1," ",sizeof(" ")," ",sizeof(" "));
 		strlower(remote_machine);
 
 		fstrcpy(local_machine,name1);
@@ -105,7 +105,7 @@
 			name_type = local_machine[15];
 			local_machine[15] = 0;
 		}
-		trim_string(local_machine," "," ");
+		trim_string(local_machine,strlen(local_machine)+1," ",sizeof(" ")," ",sizeof(" "));
 		strlower(local_machine);
 
 		if (name_type == 'R') {




More information about the samba-technical mailing list