[ENBD] Re: ENBD 2.4.25

Peter T. Breuer ptb@it.uc3m.es
Thu, 19 Apr 2001 01:24:29 +0200 (MET DST)


"A month of sundays ago Jason A. Pattie wrote:"
> I'm still running into the same issue with the .pid file not being able 
> to be created when launching the nbd-server.  I think you might want to 
> look into limiting the range of characters you translate the random 
> sequence into, or escaping all characters in the string before using it 
> as a filename.

You're quite right. Can you be a guinea pig and change getrandsig() in
nbd-server.c into

  static int getrandsig(char * buf, int n) {
        int i;
        int u = open("/dev/random",O_RDONLY);
        if (u < 0)
          return u;
        for (i = 0; i < n; i++) {
          char c = 0;
          int paranoia = 1000;
          while (!isdigit(c) && !isalpha(c) && c != '_' && paranoia-- > 0) {
            if (read(u, &c, 1) < 1) {
              close(u);;
              return -1;
            }
          }
          if (paranoia < 0)
            c = 'X';
          buf[i] = c;
        }
        // PTB the 0 terminator is taken care of by the caller.
        //buf[i] = 0;
        close(u);;
        return 0;
  }

and change the only call to:

      if (!has_sig)
        //has_sig = !getrandsig(signature, NBD_SIGLEN);
        has_sig = !getrandsig(signature, 6);

so that we get exactly 6 letters or digits as the random part of the
pidfile name when the session identifier (-i) is not given on the
command line.

> What about tmpname (or tmpnam? or something)?

Won't work. Only the last 6 chars are variable. Need foo-XXXXXX.pid.
And I can't find out the file name it makes.

Peter