a number of common places for the SQLite files.],
 [
   if test "$withval" != "no"; then
-        if test "$withval" = "yes"; then
-                if test -f /usr/local/include/sqlite.h; then
-                        SQLITE_INCDIR=/usr/local/include
-                        SQLITE_LIBDIR=/usr/local/lib
-                        SQLITE_BINDIR=/usr/local/bin
-                elif test -f /usr/include/sqlite.h; then
-                        SQLITE_INCDIR=/usr/include
-                        SQLITE_LIBDIR=/usr/lib
-                        SQLITE_BINDIR=/usr/bin      
-                else
-                   AC_MSG_RESULT(no)
-                   AC_MSG_ERROR(Unable to find sqlite.h in standard locations)
-                fi
+     if test "$withval" = "yes"; then
+        if test -f /usr/local/include/sqlite.h; then
+           SQLITE_INCDIR=/usr/local/include
+           SQLITE_LIBDIR=/usr/local/lib
+           SQLITE_BINDIR=/usr/local/bin
+        elif test -f /usr/include/sqlite.h; then
+           SQLITE_INCDIR=/usr/include
+           SQLITE_LIBDIR=/usr/lib
+           SQLITE_BINDIR=/usr/bin      
         else
-                if test -f $withval/sqlite.h; then
-                        SQLITE_INCDIR=$withval
-                        SQLITE_LIBDIR=$withval
-                        SQLITE_BINDIR=$withval
-                else
-                   AC_MSG_RESULT(no)
-                   AC_MSG_ERROR(Invalid SQLite directory $withval - unable to find sqlite.h under $withval)
-                fi
+           AC_MSG_RESULT(no)
+           AC_MSG_ERROR(Unable to find sqlite.h in standard locations)
         fi
-    SQL_INCLUDE=-I$SQLITE_INCDIR
-    SQL_LFLAGS="-L$SQLITE_LIBDIR -lsqlite"
-    SQL_BINDIR=$SQLITE_BINDIR
+     else
+        if test -f $withval/sqlite.h; then
+           SQLITE_INCDIR=$withval
+           SQLITE_LIBDIR=$withval
+           SQLITE_BINDIR=$withval
+        else
+           AC_MSG_RESULT(no)
+           AC_MSG_ERROR(Invalid SQLite directory $withval - unable to find sqlite.h under $withval)
+        fi
+     fi
+     SQL_INCLUDE=-I$SQLITE_INCDIR
+     SQL_LFLAGS="-L$SQLITE_LIBDIR -lsqlite"
+     SQL_BINDIR=$SQLITE_BINDIR
 
-    AC_DEFINE(HAVE_SQLITE)
-    AC_MSG_RESULT(yes)
-    db_found=yes
-    support_sqlite=yes
-    db_name=SQLite
-    DB_NAME=sqlite
+     AC_DEFINE(HAVE_SQLITE)
+     AC_MSG_RESULT(yes)
+     db_found=yes
+     support_sqlite=yes
+     db_name=SQLite
+     DB_NAME=sqlite
 
   else
-        AC_MSG_RESULT(no)
+     AC_MSG_RESULT(no)
   fi
 ],[
   AC_MSG_RESULT(no)
 
   withval="$with_sqlite"
 
   if test "$withval" != "no"; then
-        if test "$withval" = "yes"; then
-                if test -f /usr/local/include/sqlite.h; then
-                        SQLITE_INCDIR=/usr/local/include
-                        SQLITE_LIBDIR=/usr/local/lib
-                        SQLITE_BINDIR=/usr/local/bin
-                elif test -f /usr/include/sqlite.h; then
-                        SQLITE_INCDIR=/usr/include
-                        SQLITE_LIBDIR=/usr/lib
-                        SQLITE_BINDIR=/usr/bin
-                else
-                   echo "$as_me:$LINENO: result: no" >&5
+     if test "$withval" = "yes"; then
+        if test -f /usr/local/include/sqlite.h; then
+           SQLITE_INCDIR=/usr/local/include
+           SQLITE_LIBDIR=/usr/local/lib
+           SQLITE_BINDIR=/usr/local/bin
+        elif test -f /usr/include/sqlite.h; then
+           SQLITE_INCDIR=/usr/include
+           SQLITE_LIBDIR=/usr/lib
+           SQLITE_BINDIR=/usr/bin
+        else
+           echo "$as_me:$LINENO: result: no" >&5
 echo "${ECHO_T}no" >&6
-                   { { echo "$as_me:$LINENO: error: Unable to find sqlite.h in standard locations" >&5
+           { { echo "$as_me:$LINENO: error: Unable to find sqlite.h in standard locations" >&5
 echo "$as_me: error: Unable to find sqlite.h in standard locations" >&2;}
    { (exit 1); exit 1; }; }
-                fi
+        fi
+     else
+        if test -f $withval/sqlite.h; then
+           SQLITE_INCDIR=$withval
+           SQLITE_LIBDIR=$withval
+           SQLITE_BINDIR=$withval
         else
-                if test -f $withval/sqlite.h; then
-                        SQLITE_INCDIR=$withval
-                        SQLITE_LIBDIR=$withval
-                        SQLITE_BINDIR=$withval
-                else
-                   echo "$as_me:$LINENO: result: no" >&5
+           echo "$as_me:$LINENO: result: no" >&5
 echo "${ECHO_T}no" >&6
-                   { { echo "$as_me:$LINENO: error: Invalid SQLite directory $withval - unable to find sqlite.h under $withval" >&5
+           { { echo "$as_me:$LINENO: error: Invalid SQLite directory $withval - unable to find sqlite.h under $withval" >&5
 echo "$as_me: error: Invalid SQLite directory $withval - unable to find sqlite.h under $withval" >&2;}
    { (exit 1); exit 1; }; }
-                fi
         fi
-    SQL_INCLUDE=-I$SQLITE_INCDIR
-    SQL_LFLAGS="-L$SQLITE_LIBDIR -lsqlite"
-    SQL_BINDIR=$SQLITE_BINDIR
+     fi
+     SQL_INCLUDE=-I$SQLITE_INCDIR
+     SQL_LFLAGS="-L$SQLITE_LIBDIR -lsqlite"
+     SQL_BINDIR=$SQLITE_BINDIR
 
-    cat >>confdefs.h <<\_ACEOF
+     cat >>confdefs.h <<\_ACEOF
 #define HAVE_SQLITE 1
 _ACEOF
 
-    echo "$as_me:$LINENO: result: yes" >&5
+     echo "$as_me:$LINENO: result: yes" >&5
 echo "${ECHO_T}yes" >&6
-    db_found=yes
-    support_sqlite=yes
-    db_name=SQLite
-    DB_NAME=sqlite
+     db_found=yes
+     support_sqlite=yes
+     db_name=SQLite
+     DB_NAME=sqlite
 
   else
-        echo "$as_me:$LINENO: result: no" >&5
+     echo "$as_me:$LINENO: result: no" >&5
 echo "${ECHO_T}no" >&6
   fi
 
 
--- /dev/null
+#!/bin/sh
+# script for creating / stopping a ssh-tunnel to a backupclient
+# Stephan Holl<sholl@gmx.net>
+#
+#
+
+# variables
+USER=xxxx
+CLIENT=domain.com
+CLIENT_PORT=9112
+LOCAL=192.168.2.4
+LOCAL_PORT=$CLIENT_PORT
+SSH=/usr/bin/ssh
+
+
+case "$1" in
+ start)
+    # create ssh-tunnel 
+
+    echo "Start SSH-tunnel to $CLIENT..."
+    $SSH -vfnCNg2 -o PreferredAuthentications=publickey -i /var/lib/bacula/.ssh/id_dsa -l $USER -L $CLIENT_PORT:$CLIENT:$LOCAL_PORT -R 9101:$LOCAL:9101 -R 9103:$LOCAL:9103 $CLIENT  
+    exit 0
+    ;;
+
+ stop)
+    # remove tunnel 
+    echo "Stop SSH-tunnel to $CLIENT..."
+
+    # find PID killem
+    PID=`ps ax|grep "/usr/bin/ssh -vfnCNg2 -o PreferredAuthentications=publickey -i /var/lib/bacula/.ssh/id_dsa -l $USER -L $CLIENT_PORT:$CLIENT:$LOCAL_PORT -R 9101:$LOCAL:9101 -R 9103:$LOCAL:9103 $CLIENT &"|cut -d" " -f1`
+    kill $PID
+    exit 0
+    ;;
+ *)
+    #  usage:
+    echo "             "
+    echo "      Start SSH-tunnel to client-host"
+    echo "      to bacula-director and storage-daemon"
+    echo "            "
+    echo "      USAGE:"
+    echo "      ssh-tunnel.sh {start|stop}"
+    echo "                            "
+    exit 1
+    ;;
+esac
+
+        
 
                    22 July 2004
 
 1.35 Items to do:
+- Add bscan to four-concurrent-jobs regression.
 - Do tape alerts -- see tapealert.txt
 - Fix errno handling in win32 compat routines.
 - Add better error codes to run_program (10000+)
   bscan-test.
 - Fix restore ++++ that get intermingled with "Building directory tree"
 - Solve the termcap.h problem on Solaris configure.
+- Fix ./configure to handle installed SQLite
 
 Documentation to do: (any release a little bit at a time)
 - Document query file format.
    Building directory tree for JobId 856 ...
    Building directory tree for JobId 797 ...3 
    Jobs inserted into the tree.
-
 
    va_start(arg_ptr, fmt);
    bs->msglen = bvsnprintf(mp_chr(bs->msg), maxlen, fmt, arg_ptr);
    va_end(arg_ptr);
-   if (bs->msglen < 0 || bs->msglen >= maxlen) {
+   if (bs->msglen < 0 || bs->msglen >= (maxlen-5)) {
       bs->msg = realloc_pool_memory(bs->msg, maxlen + maxlen / 2);
       goto again;
    }
 
       va_start(arg_ptr, fmt);
       len = bvsnprintf(pool_buf+i, maxlen, fmt, arg_ptr);
       va_end(arg_ptr);
-      if (len < 0 || len >= maxlen) {
+      if (len < 0 || len >= (maxlen-5)) {
         pool_buf = realloc_pool_memory(pool_buf, maxlen + i + maxlen/2);
         continue;
       }
 
 /*
  * Edit a message into a Pool memory buffer, with file:lineno
- */
+ */                                                 
 int m_msg(const char *file, int line, POOLMEM **pool_buf, const char *fmt, ...)
 {
    va_list   arg_ptr;
       va_start(arg_ptr, fmt);
       len = bvsnprintf(*pool_buf+i, maxlen, fmt, arg_ptr);
       va_end(arg_ptr);
-      if (len < 0 || len >= maxlen) {
+      if (len < 0 || len >= (maxlen-5)) {
         *pool_buf = realloc_pool_memory(*pool_buf, maxlen + i + maxlen/2);
         continue;
       }
       va_start(arg_ptr, fmt);
       len = bvsnprintf(*pool_buf, maxlen, fmt, arg_ptr);
       va_end(arg_ptr);
-      if (len < 0 || len >= maxlen) {
+      if (len < 0 || len >= (maxlen-5)) {
         *pool_buf = realloc_pool_memory(*pool_buf, maxlen + maxlen/2);
         continue;
       }
       va_start(arg_ptr, fmt);
       len = bvsnprintf(pool_buf, maxlen, fmt, arg_ptr);
       va_end(arg_ptr);
-      if (len < 0 || len >= maxlen) {
+      if (len < 0 || len >= (maxlen-5)) {
         pool_buf = realloc_pool_memory(pool_buf, maxlen + maxlen/2);
         continue;
       }
    jcr->msg_queue->destroy();
    jcr->dequeuing = false;
    V(msg_queue_mutex);
-}
+}                                                
 
 
 /*
       va_start(arg_ptr, fmt);
       len = bvsnprintf(pool_buf+i, maxlen, fmt, arg_ptr);
       va_end(arg_ptr);
-      if (len < 0 || len >= maxlen) {
+      if (len < 0 || len >= (maxlen-5)) {
         pool_buf = realloc_pool_memory(pool_buf, maxlen + i + maxlen/2);
         continue;
       }
 
    } else {
       Jmsg2(jcr, M_ERROR, 0, _("BAD ERROR: release_device %s, Volume \"%s\" not in use.\n"), 
            dev_name(dev), NPRT(jcr->VolumeName));
+      Jmsg2(jcr, M_ERROR, 0, _("num_writers=%d state=%x\n"), dev->num_writers, dev->state);
    }
 // detach_jcr_from_device(dev, jcr);
    if (dev->prev && !dev_state(dev, ST_READ) && !dev->num_writers) {
 
 static bool bscan_mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
 {
    Dmsg1(100, "Walk attached jcrs. Volume=%s\n", dev->VolCatInfo.VolCatName);
-#ifdef xxx
-   for (JCR *mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) {
-      DCR *dcr = mjcr->dcr;
-#endif
    DCR *dcr;
    foreach_dlist(dcr, dev->attached_dcrs) {
       JCR *mjcr = dcr->jcr;
+      if (mjcr->JobId == 0) {
+        continue;
+      }
       if (verbose) {
          Pmsg1(000, _("Create JobMedia for Job %s\n"), mjcr->Job);
       }
     * have the Volume list, but we get attached.
     */
    bool stat = mount_next_read_volume(jcr, dev, block);
-   /* we must once more detach ourselves (attached by mount_next ...) */
-   detach_jcr_from_device(dev, jcr); /* detach bscan jcr */
    return stat;
 }
 
    memset(&fr, 0, sizeof(fr));
 
    /* Detach bscan's jcr as we are not a real Job on the tape */
-   detach_jcr_from_device(dev, bjcr);
 
    read_records(bjcr->dcr, record_cb, bscan_mount_next_read_volume);
-   release_device(bjcr);
+// release_device(bjcr);
 
    free_attr(attr);
 }
 
 /*
- * Returns: true if OK
+ * Returns: true  if OK
  *         false if error
  */
 static bool record_cb(JCR *bjcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
             Pmsg1(000, _("Media type \"%s\" is OK.\n"), mr.MediaType);
         }
         /* Reset some JCR variables */
-        for (mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) {
-           dcr = mjcr->dcr;
+        foreach_dlist(dcr, dev->attached_dcrs) {
            dcr->VolFirstIndex = dcr->FileIndex = 0;
            dcr->StartBlock = dcr->EndBlock = 0;
            dcr->StartFile = dcr->EndFile = 0;
 
         /* Create JobMedia record */
         create_jobmedia_record(db, mjcr);
-        detach_jcr_from_device(dev, mjcr);
+        dev->attached_dcrs->remove(mjcr->dcr);
         free_jcr(mjcr);
 
         break;
          *   them.
          */
         if (update_db) {
-           mjcr=next_attached_jcr(dev, NULL);
-           for ( ; mjcr; ) {
-              JCR *njcr; 
+           DCR *mdcr;
+           foreach_dlist(mdcr, dev->attached_dcrs) {
+              JCR *mjcr = mdcr->jcr;
+              if (!mjcr || mjcr->JobId == 0) {
+                 continue;
+              }
               jr.JobId = mjcr->JobId;
+              /* Mark Job as Error Terimined */
               jr.JobStatus = JS_ErrorTerminated;
               jr.JobFiles = mjcr->JobFiles;
               jr.JobBytes = mjcr->JobBytes;
               if (!db_update_job_end_record(bjcr, db, &jr)) {
                   Pmsg1(0, _("Could not update job record. ERR=%s\n"), db_strerror(db));
               }
-              njcr = mjcr->next_dev;
+              mjcr->dcr = NULL;
               free_jcr(mjcr);
-              mjcr = njcr;
            }
         }
         mr.VolFiles = rec->File;
       return 0;
    }
    if (verbose) {
-      Pmsg1(000, _("Updated Job termination record for new JobId=%u\n"), jr->JobId);
+      Pmsg2(000, _("Updated Job termination record for JobId=%u TermStat=%c\n"), jr->JobId,
+        jr->JobStatus);
    }
    if (verbose > 1) {
       const char *term_msg;
 
  */
 int main(int margc, char *margv[])
 {
-   int ch;
+   int ch, i;
+   uint32_t x32, y32;
+   uint64_t x64, y64;
+   char buf[1000];
 
    /* Sanity checks */
    if (TAPE_BSIZE % DEV_BSIZE != 0 || TAPE_BSIZE / DEV_BSIZE == 0) {
    if (TAPE_BSIZE != (1 << (ffs(TAPE_BSIZE)-1))) {
       Emsg1(M_ABORT, 0, "Tape block size (%d) is not a power of 2\n", TAPE_BSIZE);
    }
+   if (sizeof(off_t) < 8) {
+      Pmsg1(-1, "\n\n!!!! Warning large disk addressing disabled. off_t=%d should be 8 or more !!!!!\n\n\n",
+        sizeof(off_t));
+   }
+   x32 = 123456789;
+   bsnprintf(buf, sizeof(buf), "%u", x32);
+   i = bsscanf(buf, "%u", &y32);
+   if (i != 1 || x32 != y32) {
+      Pmsg3(-1, "32 bit printf/scanf problem. i=%d x32=%u y32=%u\n", i, x32, y32);
+      exit(1);
+   }
+   x64 = 123456789012345678;
+   bsnprintf(buf, sizeof(buf), "%" llu, x64);
+   i = bsscanf(buf, "%llu", &y64);
+   if (i != 1 || x64 != y64) {
+      Pmsg3(-1, "64 bit printf/scanf problem. i=%d x64=%" llu " y64=%" llu "\n", i, x64, y64);
+      exit(1);
+   }
 
    printf("Tape block granularity is %d bytes.\n", TAPE_BSIZE);
 
 
    }
 }
 
+#ifdef xxxx
 /*
  * We attach a jcr to the device so that when
  *   the Volume is full during writing, a  
    }
    return jcr->next_dev;
 }
+#endif
 
 /*
  * This routine initializes the device wait timers
 
     * Walk through all attached jcrs indicating the volume has changed  
     */
    Dmsg1(100, "Walk attached jcrs. Volume=%s\n", dev->VolCatInfo.VolCatName);
-   for (JCR *mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) {
+// for (JCR *mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) {
+   DCR *mdcr;
+   foreach_dlist(mdcr, dev->attached_dcrs) {
+      JCR *mjcr = mdcr->jcr;
       if (mjcr->JobId == 0) {
         continue;                 /* ignore console */
       }
-      mjcr->dcr->NewVol = true;
+      mdcr->NewVol = true;
       if (jcr != mjcr) {
         pm_strcpy(&mjcr->VolumeName, jcr->VolumeName);  /* get a copy of the new volume */
-        bstrncpy(mjcr->dcr->VolumeName, jcr->VolumeName, sizeof(mjcr->dcr->VolumeName));
+        bstrncpy(mdcr->VolumeName, jcr->VolumeName, sizeof(mdcr->VolumeName));
       }
    }
 
 
 /* */
 #undef  VERSION
 #define VERSION "1.35.1"
-#define BDATE   "22 July 2004"
-#define LSMDATE "22Jul04"
+#define BDATE   "24 July 2004"
+#define LSMDATE "24Jul04"
 
 /* Debug flags */
 #undef  DEBUG
 
 
 To build it:
 - Make sure nmake is on your PATH.
+- Make sure your COMSPEC is properly setup (see full dump of
+  my cygwin environment below).
 - The build is done in an rxvt window under the latest version
   of cygwin.
 - You need the Platform SDK installed.
 - You need Visual Studio installed.
+- You need to load depkgs-win32, then
+    cd depkgs-win32
+    cd wx
+    ./configure
+    (try doing a make, but it will probably fail)   
 - You may have to build wx with VC++ (as was the case for me).
   After starting VC++, use File->Open Workspace then
   open wx/src/wxWindows.dsw then use
   Build->Build All or Build->build wxmsw.lib should work too.
+- Then 
+    cd depkgs-win32
+    make
+  this will build pthreads and zlib
 - cd bacula
   ./configure --enable-client-only
   cd src/win32