Printing Limits and mktemp()

Morgan Hughes kyhm at mars.ark.com
Tue Sep 28 22:56:25 GMT 1999


  Say, has anyone run into this problem?  While testing one of my Samba 
  (2.0.3) servers after 63 prints to the same smbd process, I began to 
  get errors...  I had 63 files like so:

    usagi.a03411 usagi.b03411 ... usagi.y03411 usagi.z03411 
    usagi.A03411 usagi.B03411 ... usagi.Y03411 usagi.Z03411 
    usagi.003411 usagi.103411 ... usagi.803411 usagi.903411 
    usagi.

  Anyways, it seems that in unix_convert() in smbd/filename.c uses mktemp()
  to calculate the spoolfile name.  And since mktemp() can only provide
  63 unique filenames per pid, printing failed when it had used up its 
  supply of letters and numbers.

  I changed the code (patches attached) so it uses 
    <machine>.<serial>.<pid> 
  and increments serial until a stat() fails on the name.  It seems to 
  work on my Linux boxes...  One patch works for 2.0.3 and 2.0.4, and 
  the other for 2.0.5a.

  Comments welcome...

--
   Morgan Hughes
   C programmer and highly caffeinated mammal
   kyhm at email.com
-- Today is Monday, cleverly disguised as Tuesday.
-------------- next part --------------
--- smbd/filename.c.orig	Tue Jul 20 18:25:20 1999
+++ smbd/filename.c	Tue Sep 28 15:39:25 1999
@@ -406,9 +406,17 @@
    */
   if (conn->printer) {
     if ((! *name) || strchr(name,'/') || !is_8_3(name, True)) {
-      char *s;
-      fstring name2;
-      slprintf(name2,sizeof(name2)-1,"%.6s.XXXXXX",remote_machine);
+      char        *s;
+      fstring      name2;
+      int          serial = 0;
+      struct stat  sb;
+      
+      do
+      { 
+        slprintf(name2,sizeof(name2)-1,"%.6s.%d.%d", 
+	         remote_machine, serial++, getpid());
+      }
+      while ( !stat(name2, &sb) );
 
       /* 
        * Sanitise the name.
@@ -416,7 +424,7 @@
 
       for (s=name2 ; *s ; s++)
         if (!issafe(*s)) *s = '_';
-      pstrcpy(name,(char *)smbd_mktemp(name2));	  
+      pstrcpy(name,name2);	  
     }      
     return(True);
   }
-------------- next part --------------
--- smbd/filename.c-orig	Tue Sep 28 14:49:04 1999
+++ smbd/filename.c	Tue Sep 28 15:00:37 1999
@@ -406,9 +406,17 @@
    */
   if (conn->printer) {
     if ((! *name) || strchr(name,'/') || !is_8_3(name, True)) {
-      char *s;
-      fstring name2;
-      slprintf(name2,sizeof(name2)-1,"%.6s.XXXXXX",remote_machine);
+      char        *s;
+      fstring      name2;
+      int          serial = 0;
+      struct stat  sb;
+      
+      do
+      { 
+        slprintf(name2,sizeof(name2)-1,"%.6s.%d.%d", 
+	         remote_machine, serial++, getpid());
+      }
+      while ( !stat(name2, &sb) );
 
       /* 
        * Sanitise the name.
@@ -416,7 +424,7 @@
 
       for (s=name2 ; *s ; s++)
         if (!issafe(*s)) *s = '_';
-      pstrcpy(name,(char *)mktemp(name2));	  
+      pstrcpy(name,name2);	  
     }      
     return(True);
   }


More information about the samba-technical mailing list