CR/LF problem

Jeroen Vriesman joenix at xs4all.nl
Wed Nov 5 10:38:47 GMT 1997


Hi,

I wrote a message some time ago about the CR/LF problem when using Unix
ASCII files on a samba server, because Unix only uses newlines and DOS
uses CR/LF users get 'strange' files sometimes, it gets even more
confusing when they use DOS programs to process the unix ASCII files.

For as far as I know now there is no way to translate these files 'on
the fly'.

So now I try to make it myself.

First of all unix needs to know the file type, therefore I added some
lines to server.c:

At the beginning of the open_file routine in server.c:

static void open_file(int fnum,int cnum,char *fname1,int flags,int mode,
struct stat *sbuf)
{
  extern struct current_user current_user;
  pstring fname;
  FILE  *fpout;                   /* added */
  char  line[120];                /* added */
  pstring filecmd="file ";        /* added */
  pid_t forkpid;


And somewhere near the end of open_file:

	}
      strncat(filecmd,fname,strlen(filecmd)+strlen(fname));
      if ( (fpout = popen(filecmd, "r")) == NULL)
          DEBUG(0,("popen error"));
      while ( fgets(line, 120, fpout) != NULL ) 
          DEBUG(0,(line));
      if ( pclose(fpout) == -1)
          DEBUG(0,("pclose error"));
      DEBUG(2,("%s %s opened file %s read=%s write=% ......

That works fine, I can see the output of the 'file' command in the log
files, it works under linux, svr4, unixware and AIX.

After that I made a routine which created two pipes, forked and execlp
to call a 'filter', which can be any routine using standard in and out
to process data, ofcourse I want the filter to depend on the output of
the 'file' command, I don't thingk that would be a problem, it's just
not finished.
The real problem is buffering, the filter doesn't use fflush, because it
can be any filter written bij anyone, so it buffers the file competely,
which is alright for small files, but a disaster for large files.
The solution to that is to put a pseudo-terminal between the pipes (so
the filter starts to line-buffer), I know how to do that for svr4 or
unixware, but I also know that these things are very system-dependent.
So now I'm looking for a system-independent way to make pipes with a
pseudo terminal in between.

I think this filter thing would not just be a solution to the CR/LF
problem, but it would make it possible to put data-processing between
the server and the client (try that with windoze!).

The idea is to finaly have a line in smb.conf which says:

outfilter = reg_expr filter_progam

In which reg_exp is a regulair expression which does or does not match
the output of the file command, and on a match the filter would be
inserted.
I don't think performnce would suffer if the file command isn't executed
when there is no filter definition with that share (didn't made it that
way yet..)

Could anyone give me some hints on the pseudo-terminal thing, or any
hints at all (am I doing this the samba way??).

Thanks,

Jeroen Vriesman.


More information about the samba mailing list