]> git.sur5r.net Git - bacula/bacula/commitdiff
Replace explicit checks for "/" with calls to IsPathSeparator, strchr with first_path...
authorRobert Nelson <robertn@the-nelsons.org>
Tue, 21 Nov 2006 16:45:13 +0000 (16:45 +0000)
committerRobert Nelson <robertn@the-nelsons.org>
Tue, 21 Nov 2006 16:45:13 +0000 (16:45 +0000)
Use serialization routines for crypto length fix.

Fix 64 bit offset problems on Windows by replacing off_t with new boffset_t.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3671 91ce42f0-d328-0410-95d8-f526ca767f89

44 files changed:
bacula/src/baconfig.h
bacula/src/cats/bdb.c
bacula/src/cats/sql.c
bacula/src/dird/inc_conf.c
bacula/src/dird/ua_restore.c
bacula/src/dird/ua_run.c
bacula/src/dird/ua_tree.c
bacula/src/filed/acl.c
bacula/src/filed/backup.c
bacula/src/filed/job.c
bacula/src/filed/restore.c
bacula/src/filed/status.c
bacula/src/findlib/attribs.c
bacula/src/findlib/bfile.c
bacula/src/findlib/bfile.h
bacula/src/findlib/create_file.c
bacula/src/findlib/find.c
bacula/src/findlib/find_one.c
bacula/src/findlib/makepath.c
bacula/src/findlib/match.c
bacula/src/lib/attr.c
bacula/src/lib/enh_fnmatch.c
bacula/src/lib/fnmatch.c
bacula/src/lib/idcache.c
bacula/src/lib/message.c
bacula/src/lib/parse_conf.c
bacula/src/lib/protos.h
bacula/src/lib/scan.c
bacula/src/lib/signal.c
bacula/src/lib/tree.c
bacula/src/lib/util.c
bacula/src/stored/bextract.c
bacula/src/stored/block.c
bacula/src/stored/btape.c
bacula/src/stored/butil.c
bacula/src/stored/dev.c
bacula/src/stored/dev.h
bacula/src/stored/dvd.c
bacula/src/stored/protos.h
bacula/src/stored/scan.c
bacula/src/stored/spool.c
bacula/src/stored/stored.c
bacula/src/tools/dbcheck.c
bacula/src/tools/testfind.c

index 4debd4f4440d86d7c102ae2975a4601279ccbfb0..d417d77c8aff1bfa0f726942c8ca18acbf715fd2 100644 (file)
@@ -324,7 +324,13 @@ typedef int (INTHANDLER)();
 #define MODE_RW 0666
 #endif
 
-#ifdef DEBUG_MUTEX
+#if defined(HAVE_WIN32)
+typedef int64_t   boffset_t;
+#else
+typedef off_t     boffset_t;
+#endif
+
+#if defined(DEBUG_MUTEX)
 extern void _p(char *file, int line, pthread_mutex_t *m);
 extern void _v(char *file, int line, pthread_mutex_t *m);
 
@@ -538,7 +544,7 @@ int  m_msg(const char *file, int line, POOLMEM *&pool_buf, const char *fmt, ...)
 #define REPLACE_NEVER    'n'
 #define REPLACE_IFOLDER  'o'
 
-/* This probably should be done on a machine by machine basic, but it works */
+/* This probably should be done on a machine by machine basis, but it works */
 /* This is critical for the smartalloc routines to properly align memory */
 #define ALIGN_SIZE (sizeof(double))
 #define BALIGN(x) (((x) + ALIGN_SIZE - 1) & ~(ALIGN_SIZE -1))
@@ -595,15 +601,25 @@ extern "C" int mknod ( const char *path, int mode, dev_t device );
 #endif
 
 
+#if defined(HAVE_WIN32)
+#define DEFAULT_CONFIGDIR "C:\\Documents and Settings\\All Users\\Application Data\\Bacula"
+
+inline bool IsPathSeparator(int ch) { return ch == '/' || ch == '\\'; }
+inline char *first_path_separator(char *path) { return strpbrk(path, ":/\\"); }
+inline const char *first_path_separator(const char *path) { return strpbrk(path, ":/\\"); }
+
+#else
 /* Define Winsock functions if we aren't on Windows */
-#if !defined HAVE_WIN32
+
 #define WSA_Init() 0 /* 0 = success */
 #define WSACleanup() 0 /* 0 = success */
-#endif
 
-#ifdef HAVE_AIX_OS
+inline bool IsPathSeparator(int ch) { return ch == '/'; }
+inline char *first_path_separator(char *path) { return strchr(path, '/'); }
+inline const char *first_path_separator(const char *path) { return strchr(path, '/'); }
 #endif
 
+
 /* HP-UX 11 specific workarounds */
 
 #ifdef HAVE_HPUX_OS
@@ -627,12 +643,6 @@ extern "C" long gethostid(void);
 #endif
 
 
-/* Added by KES to deal with Win32 systems */
-#ifndef S_ISWIN32
-#define S_ISWIN32 020000
-#endif
-
-
 /* Disabled because it breaks internationalisation...
 #undef HAVE_SETLOCALE
 #ifdef HAVE_SETLOCALE
index b5979f18c9e9bf26240549cbec80b8951db99586..6ef501f16d9def8f4cb1424d7698e912f348a282 100644 (file)
@@ -65,7 +65,7 @@ static POOLMEM *make_filename(B_DB *mdb, char *name)
    POOLMEM *dbf;
 
    dbf = get_pool_memory(PM_FNAME);
-   if (working_directory[strlen(working_directory)-1] == '/') {
+   if (IsPathSeparator(working_directory[strlen(working_directory)-1])) {
       sep = 0;
    } else {
       sep = '/';
index dc84a6594132cccf5a00b6fe8e7d80ac00a13010..02bc8ca0484f16e8731834ee68ce42d6f3349d7b 100644 (file)
@@ -387,11 +387,11 @@ void split_path_and_file(JCR *jcr, B_DB *mdb, const char *fname)
     * must be a path name (e.g. c:).
     */
    for (p=f=fname; *p; p++) {
-      if (*p == '/') {
+      if (IsPathSeparator(*p)) {
          f = p;                       /* set pos of last slash */
       }
    }
-   if (*f == '/') {                   /* did we find a slash? */
+   if (IsPathSeparator(*f)) {                   /* did we find a slash? */
       f++;                            /* yes, point to filename */
    } else {                           /* no, whole thing must be path name */
       f = p;
index dc7a2ba74cb8f3c5917df61a024f5c62d6fd3be1..3052449d111d0a4e0c8571fd32a9e1c83366707e 100644 (file)
@@ -508,7 +508,7 @@ static void store_wild(LEX *lc, RES_ITEM *item, int index, int pass)
             res_incexe.current_opts->wilddir.append(bstrdup(lc->str));
             newsize = res_incexe.current_opts->wilddir.size();
          } else if (item->code == 2) {
-            if (strchr(lc->str, '/') != NULL) {
+            if (strpbrk(lc->str, "/\\") != NULL) {
                type = "wildfile";
                res_incexe.current_opts->wildfile.append(bstrdup(lc->str));
                newsize = res_incexe.current_opts->wildfile.size();
index b20fb4b9f382beb4e1fdd7c9e2515d2989f4d3b9..104dca9db50b27aeb89ef97813c5962ef64564bb 100644 (file)
@@ -613,7 +613,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx)
                break;
             }
             /* Add trailing slash to end of directory names */
-            if (ua->cmd[0] != '<' && ua->cmd[len-1] != '/') {
+            if (ua->cmd[0] != '<' && !IsPathSeparator(ua->cmd[len-1])) {
                strcat(ua->cmd, "/");
             }
             insert_one_file_or_dir(ua, rx, date, true);
@@ -825,11 +825,11 @@ static void split_path_and_filename(RESTORE_CTX *rx, char *name)
     * must be a path name (e.g. c:).
     */
    for (p=f=name; *p; p++) {
-      if (*p == '/') {
+      if (IsPathSeparator(*p)) {
          f = p;                       /* set pos of last slash */
       }
    }
-   if (*f == '/') {                   /* did we find a slash? */
+   if (IsPathSeparator(*f)) {         /* did we find a slash? */
       f++;                            /* yes, point to filename */
    } else {                           /* no, whole thing must be path name */
       f = p;
index a37fd9a9a10cef5ace68338af44ac17efe733eb7..55b60907b902819d0f32f27f210facbace40dcc0 100644 (file)
@@ -907,7 +907,7 @@ try_again:
             free(jcr->where);
             jcr->where = NULL;
          }
-         if (ua->cmd[0] == '/' && ua->cmd[1] == 0) {
+         if (IsPathSeparator(ua->cmd[0]) && ua->cmd[1] == '\0') {
             ua->cmd[0] = 0;
          }
          jcr->where = bstrdup(ua->cmd);
index 0c232a8be41aed0c6559b31a84e7f930bac95fbd..f1b433030982b519005cb706456af9963f8a7c8f 100644 (file)
@@ -174,8 +174,8 @@ int insert_tree_handler(void *ctx, int num_fields, char **row)
 
 // Dmsg4(000, "Path=%s%s FI=%s JobId=%s\n", row[0], row[1],
 //    row[2], row[3]);
-   if (*row[1] == 0) {                /* no filename => directory */
-      if (*row[0] != '/') {           /* Must be Win32 directory */
+   if (*row[1] == 0) {                 /* no filename => directory */
+      if (!IsPathSeparator(*row[0])) { /* Must be Win32 directory */
          type = TN_DIR_NLS;
       } else {
          type = TN_DIR;
index cd7270162517bfdd6ddef3cbfa75db4f0774ece0..6829cf646677f05c6af5620bf0f8cc87e5bb84be 100644 (file)
@@ -431,7 +431,7 @@ int main(int argc, char **argv)
       return EXIT_FAILURE;
    }
 
-   prgname = strrchr(argv[0], '/');
+   prgname = last_path_separator(argv[0]);
    if (prgname == NULL || *++prgname == '\0') {
       prgname = argv[0];
    }
index d811abe5d487241a3e20043080d036fedadc7399..eee6590ea6b3d7691ea69a7ba529f3d2c3b9d19c 100644 (file)
@@ -736,8 +736,7 @@ int send_data(JCR *jcr, int stream, FF_PKT *ff_pkt, DIGEST *digest,
 #ifdef HAVE_LIBZ
       /* Do compression if turned on */
       if (!sparseBlock && (ff_pkt->flags & FO_GZIP) && jcr->pZLIB_compress_workset) {
-         Dmsg4(400, "cbuf=0x%x len=%u rbuf=0x%x len=%u\n", cbuf, compress_len,
-            rbuf, sd->msglen);
+         Dmsg3(400, "cbuf=0x%x rbuf=0x%x len=%u\n", cbuf, rbuf, sd->msglen);
          
          ((z_stream*)jcr->pZLIB_compress_workset)->next_in   = (Bytef *)rbuf;
                 ((z_stream*)jcr->pZLIB_compress_workset)->avail_in  = sd->msglen;
@@ -767,16 +766,20 @@ int send_data(JCR *jcr, int stream, FF_PKT *ff_pkt, DIGEST *digest,
 
       if (!sparseBlock && (ff_pkt->flags & FO_ENCRYPT)) {
          uint32_t initial_len = 0;
+         ser_declare;
 
          if (ff_pkt->flags & FO_SPARSE) {
             cipher_input_len += SPARSE_FADDR_SIZE;
          }
 
          /* Encrypt the length of the input block */
-         uint32_t packet_len = htonl(cipher_input_len);
+         uint8_t packet_len[sizeof(uint32_t)];
+
+         ser_begin(packet_len, sizeof(uint32_t));
+         ser_uint32(cipher_input_len);    /* store fileAddr in begin of buffer */
 
-         if (!crypto_cipher_update(cipher_ctx, (const u_int8_t *)&packet_len, 
-              sizeof(packet_len), (u_int8_t *)jcr->crypto_buf, &initial_len)) {
+         if (!crypto_cipher_update(cipher_ctx, packet_len, sizeof(packet_len),
+                  (u_int8_t *)jcr->crypto_buf, &initial_len)) {
             /* Encryption failed. Shouldn't happen. */
             Jmsg(jcr, M_FATAL, 0, _("Encryption error\n"));
             goto err;
index 318290700868e2b826f59b0b6b21082542bc2a51..14adba986e11814c135381ed441d51edf2cd5e6e 100644 (file)
@@ -1565,8 +1565,8 @@ static int restore_cmd(JCR *jcr)
       *where = 0;
    }
    /* Turn / into nothing */
-   if (where[0] == '/' && where[1] == 0) {
-      where[0] = 0;
+   if (IsPathSeparator(where[0]) && where[1] == '\0') {
+      where[0] = '\0';
    }
 
    Dmsg2(150, "Got replace %c, where=%s\n", replace, where);
index 5f9238609fba2d1ded75d94b0d829cef675f768a..160f854c68218079a1141ecd7ea2c6626a6e8088 100644 (file)
@@ -56,10 +56,10 @@ bool flush_cipher(JCR *jcr, BFILE *bfd, int flags, CIPHER_CONTEXT *cipher, uint3
  * Close a bfd check that we are at the expected file offset.
  * Makes some code in set_attributes().
  */
-int bclose_chksize(JCR *jcr, BFILE *bfd, off_t osize)
+int bclose_chksize(JCR *jcr, BFILE *bfd, boffset_t osize)
 {
    char ec1[50], ec2[50];
-   off_t fsize;
+   boffset_t fsize;
 
    fsize = blseek(bfd, 0, SEEK_CUR);
    bclose(bfd);                              /* first close file */
@@ -808,6 +808,7 @@ int32_t extract_data(JCR *jcr, BFILE *bfd, POOLMEM *buf, int32_t buflen,
 
    if (flags & FO_ENCRYPT) {
       ASSERT(cipher);
+      unser_declare;
 
       while (jcr->crypto_size > 0 && jcr->crypto_count > 0 && wsize > 0) {
          uint32_t chunk_size = 16;
@@ -892,7 +893,9 @@ int32_t extract_data(JCR *jcr, BFILE *bfd, POOLMEM *buf, int32_t buflen,
       jcr->crypto_count += decrypted_len;
 
       if (jcr->crypto_size == 0 && jcr->crypto_count >= 4) {
-         jcr->crypto_size = ntohl(*(uint32_t *)&jcr->crypto_buf[0]) + 4;
+         unser_begin(&jcr->crypto_buf[0], sizeof(uint32_t));
+         unser_uint32(jcr->crypto_size);
+         jcr->crypto_size += 4;
       }
 
       if (jcr->crypto_size == 0 || jcr->crypto_count < jcr->crypto_size) {
@@ -904,14 +907,14 @@ int32_t extract_data(JCR *jcr, BFILE *bfd, POOLMEM *buf, int32_t buflen,
    }
 
    if (flags & FO_SPARSE) {
-      ser_declare;
+      unser_declare;
       uint64_t faddr;
       char ec1[50];
-      ser_begin(wbuf, SPARSE_FADDR_SIZE);
+      unser_begin(wbuf, SPARSE_FADDR_SIZE);
       unser_uint64(faddr);
       if (*addr != faddr) {
          *addr = faddr;
-         if (blseek(bfd, (off_t)*addr, SEEK_SET) < 0) {
+         if (blseek(bfd, (boffset_t)*addr, SEEK_SET) < 0) {
             berrno be;
             Jmsg3(jcr, M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
                   edit_uint64(*addr, ec1), jcr->last_fname, 
index af81a8d63b9366bec597f992a6eb090136105f39..85f1565b3fe604ab3d3ad32216a05e26aa9f8faf 100755 (executable)
@@ -117,8 +117,8 @@ void output_status(void sendit(const char *msg, int len, void *sarg), void *arg)
          edit_uint64_with_commas(sm_buffers, b3),
          edit_uint64_with_commas(sm_max_buffers, b4));
    sendit(msg, len, arg);
-   len = Mmsg(msg, _(" Sizeof: off_t=%d size_t=%d debug=%d trace=%d\n"),
-         sizeof(off_t), sizeof(size_t), debug_level, get_trace());
+   len = Mmsg(msg, _(" Sizeof: boffset_t=%d size_t=%d debug=%d trace=%d\n"),
+         sizeof(boffset_t), sizeof(size_t), debug_level, get_trace());
    sendit(msg, len, arg);
 
    /*
index ce8fc960fcdf8be80475b03f74eb78efe948bdcb..25b15180f6aaf227c899fc523f0b386d05eca593 100755 (executable)
@@ -357,7 +357,7 @@ bool set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
    struct utimbuf ut;
    mode_t old_mask;
    bool ok = true;
-   off_t fsize;
+   boffset_t fsize;
 
 #if defined(HAVE_WIN32)
    if (attr->stream == STREAM_UNIX_ATTRIBUTES_EX &&
@@ -390,7 +390,7 @@ bool set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
       char ec1[50], ec2[50];
       fsize = blseek(ofd, 0, SEEK_END);
       bclose(ofd);                    /* first close file */
-      if (attr->type == FT_REG && fsize > 0 && fsize != (off_t)attr->statp.st_size) {
+      if (attr->type == FT_REG && fsize > 0 && fsize != (boffset_t)attr->statp.st_size) {
          Jmsg3(jcr, M_ERROR, 0, _("File size of restored file %s not correct. Original %s, restored %s.\n"),
             attr->ofname, edit_uint64(attr->statp.st_size, ec1),
             edit_uint64(fsize, ec2));
index 8f930ed5d2c9f187aa4e46d78f9c160edd3794b5..d593cd9711f5247df505b3b350169ee36ebf4e81 100644 (file)
@@ -148,7 +148,7 @@ void int32_LE2BE(int32_t* pBE, const int32_t v)
 
 
 bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize)
-{   
+{
    /* pByte contains the buffer 
       dwSize the len to be processed.  function assumes to be
       called in successive incremental order over the complete
@@ -165,12 +165,11 @@ bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize)
     */
    int32_t dwSizeHeader = 20; 
 
-   do {               
-      if (pContext->liNextHeader >= dwSize) {                        
+   do {
+      if (pContext->liNextHeader >= dwSize) {
          dwDataLen = dwSize-dwDataOffset;
          bContinue = false; /* 1 iteration is enough */
-      }
-      else {                        
+      } else {
          dwDataLen = pContext->liNextHeader-dwDataOffset;
          bContinue = true; /* multiple iterations may be necessary */
       }
@@ -179,34 +178,34 @@ bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize)
       /* copy block of real DATA */
       if (pContext->bIsInData) {
          if (bwrite(bfd, ((char *)pBuffer)+dwDataOffset, dwDataLen) != (ssize_t)dwDataLen)
-            return false;         
+            return false;
       }
 
       if (pContext->liNextHeader < dwSize) {/* is a header in this block ? */
          int32_t dwOffsetTarget;
          int32_t dwOffsetSource;
-            
+
          if (pContext->liNextHeader < 0) {
             /* start of header was before this block, so we
              * continue with the part in the current block 
              */
-            dwOffsetTarget = -pContext->liNextHeader;        
-            dwOffsetSource = 0;                            
+            dwOffsetTarget = -pContext->liNextHeader;
+            dwOffsetSource = 0;
          } else {
             /* start of header is inside of this block */
             dwOffsetTarget = 0;
-            dwOffsetSource = pContext->liNextHeader;                        
+            dwOffsetSource = pContext->liNextHeader;
          }
 
          int32_t dwHeaderPartLen = dwSizeHeader-dwOffsetTarget;
          bool bHeaderIsComplete;
 
-         if (dwHeaderPartLen <= dwSize-dwOffsetSource) 
+         if (dwHeaderPartLen <= dwSize-dwOffsetSource) {
             /* header (or rest of header) is completely available
                in current block 
              */
             bHeaderIsComplete = true;
-         else  {
+         } else {
             /* header will continue in next block */
             bHeaderIsComplete = false;
             dwHeaderPartLen = dwSize-dwOffsetSource;
@@ -221,22 +220,21 @@ bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize)
             int32_t dwNameSize; 
             int32_LE2BE (&dwNameSize, pContext->header_stream.dwStreamNameSize);
             dwDataOffset = dwNameSize+pContext->liNextHeader+dwSizeHeader;
-            
+
             /* convert stream size (64 bit little endian) to machine type */
             int64_LE2BE (&(pContext->liNextHeader), pContext->header_stream.Size);
             pContext->liNextHeader += dwDataOffset;
 
             pContext->bIsInData = pContext->header_stream.dwStreamId == WIN32_BACKUP_DATA;
             if (dwDataOffset == dwSize)
-                  bContinue = false;
-         }
-         else {
+               bContinue = false;
+         } else {
             /* stop and continue with next block */
             bContinue = false;
             pContext->bIsInData = false;
          }
-      }                
-   } while (bContinue);    
+      }
+   } while (bContinue);
 
    /* set "NextHeader" relative to the beginning of the next block */
    pContext->liNextHeader-= dwSize;
@@ -259,7 +257,6 @@ void unix_name_to_win32(POOLMEM **win32_name, char *name);
 extern "C" HANDLE get_osfhandle(int fd);
 
 
-
 void binit(BFILE *bfd)
 {
    memset(bfd, 0, sizeof(BFILE));
@@ -309,7 +306,6 @@ bool have_win32_api()
 }
 
 
-
 /*
  * Return true  if we support the stream
  *        false if we do not support the stream
@@ -385,7 +381,7 @@ int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode)
    if (!(p_CreateFileA || p_CreateFileW))
       return 0;
 
-   if (p_CreateFileW && p_MultiByteToWideChar)               
+   if (p_CreateFileW && p_MultiByteToWideChar)
       make_win32_path_UTF8_2_wchar(&win32_fname_wchar, fname);
 
    if (flags & O_CREAT) {             /* Create */
@@ -620,10 +616,19 @@ bool is_bopen(BFILE *bfd)
    return bfd->mode != BF_CLOSED;
 }
 
-off_t blseek(BFILE *bfd, off_t offset, int whence)
+boffset_t blseek(BFILE *bfd, boffset_t offset, int whence)
 {
-   /* ****FIXME**** this must be implemented if we want to read Win32 Archives */
-   return -1;
+   LONG  offset_low = (LONG)offset;
+   LONG  offset_high = (LONG)(offset >> 32);
+   DWORD dwResult;
+
+   dwResult = SetFilePointer(bfd->fh, offset_low, &offset_high, whence);
+
+   if (dwResult == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) {
+      return (boffset_t)-1;
+   }
+
+   return ((boffset_t)offset_high << 32) | dwResult;
 }
 
 #else  /* Unix systems */
@@ -854,10 +859,10 @@ bool is_bopen(BFILE *bfd)
    return bfd->fid >= 0;
 }
 
-off_t blseek(BFILE *bfd, off_t offset, int whence)
+boffset_t blseek(BFILE *bfd, boffset_t offset, int whence)
 {
-    off_t pos;
-    pos = lseek(bfd->fid, offset, whence);
+    boffset_t pos;
+    pos = (boffset_t)lseek(bfd->fid, (off_t)offset, whence);
     bfd->berrno = errno;
     return pos;
 }
index e6d4c34a0608f28de25a424e0c808c1895247283..6bc5ad5f21c4a82ff1515fc3233db8f86b639f03 100644 (file)
@@ -133,7 +133,7 @@ int     bopen_rsrc(BFILE *bfd, const char *fname, int flags, mode_t mode);
 int     bclose(BFILE *bfd);
 ssize_t bread(BFILE *bfd, void *buf, size_t count);
 ssize_t bwrite(BFILE *bfd, void *buf, size_t count);
-off_t   blseek(BFILE *bfd, off_t offset, int whence);
+boffset_t blseek(BFILE *bfd, boffset_t offset, int whence);
 const char   *stream_to_ascii(int stream);
 
 bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize);
index 3f845c1508e491b3a7956659d527f0663399b989..7460549b553db91c76b43e950a2467970a45c7d4 100644 (file)
@@ -304,7 +304,9 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
             be.set_errno(bfd->berrno);
 #ifdef HAVE_WIN32
             /* Check for trying to create a drive, if so, skip */
-            if (attr->ofname[1] == ':' && attr->ofname[2] == '/' && attr->ofname[3] == 0) {
+            if (attr->ofname[1] == ':' && 
+                IsPathSeparator(attr->ofname[2]) && 
+                attr->ofname[3] == '\0') {
                return CF_SKIP;
             }
 #endif
@@ -349,22 +351,22 @@ static int separate_path_and_file(JCR *jcr, char *fname, char *ofile)
    /* Separate pathname and filename */
    for (q=p=f=ofile; *p; p++) {
 #ifdef HAVE_WIN32
-      if (*p == '\\' || *p == '/') {
+      if (IsPathSeparator(*p)) {
          f = q;
-         if (p[1] == '\\' || p[1] == '/') {
+         if (IsPathSeparator(p[1])) {
             p++;
          }
       }
       *q++ = *p;                   /* copy data */
 #else
-      if (*p == '/') {
+      if (IsPathSeparator(*p)) {
          f = q;                    /* possible filename */
       }
       q++;
 #endif
    }
 
-   if (*f == '/') {
+   if (IsPathSeparator(*f)) {
       f++;
    }
    *q = 0;                         /* terminate string */
index 95ee92e1499b2530444903ca8401edc15df6fef7..90b66bcc94bffda34f4ba97352ab5d6a977710b1 100644 (file)
@@ -200,7 +200,7 @@ static bool accept_file(FF_PKT *ff)
 
    if (ff->flags & FO_ENHANCEDWILD) {
       match_func = enh_fnmatch;
-      if ((basename = strrchr(ff->fname, '/')) != NULL)
+      if ((basename = last_path_separator(ff->fname)) != NULL)
          basename++;
       else
          basename = ff->fname;
@@ -209,7 +209,7 @@ static bool accept_file(FF_PKT *ff)
       basename = ff->fname;
    }
 
-   for (j=0; j<incexe->opts_list.size(); j++) {
+   for (j = 0; j < incexe->opts_list.size(); j++) {
       findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
       ff->flags = fo->flags;
       ff->GZIP_level = fo->GZIP_level;
index 152cda924b4d3d169916430c0a796602da49b88b..c05a489c5985f3b1e575c3ba4feed84772d7965f 100755 (executable)
@@ -335,7 +335,7 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
 
    /* This is not a link to a previously dumped file, so dump it.  */
    if (S_ISREG(ff_pkt->statp.st_mode)) {
-      off_t sizeleft;
+      boffset_t sizeleft;
 
       sizeleft = ff_pkt->statp.st_size;
 
@@ -416,7 +416,7 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
       link = (char *)bmalloc(link_len + 2);
       bstrncpy(link, fname, link_len);
       /* Strip all trailing slashes */
-      while (len >= 1 && link[len - 1] == '/')
+      while (len >= 1 && IsPathSeparator(link[len - 1]))
         len--;
       link[len++] = '/';             /* add back one */
       link[len] = 0;
index dbb873b2baaeb0837483fc4cc38e0cc8bfc9a326..36660a0d26d86b97709fefc828cfd42b609b42cb 100644 (file)
@@ -137,9 +137,9 @@ int
 isAbsolute(const char *path)
 {
 #if defined(HAVE_WIN32)
-    return path[1] == ':' || *path == '/' || *path == '\\';     /* drivespec:/blah is absolute */
+    return path[1] == ':' || IsPathSeparator(*path);     /* drivespec:/blah is absolute */
 #else
-    return *path == '/';
+    return IsPathSeparator(*path);
 #endif
 }
 
@@ -255,31 +255,19 @@ make_path(
       }
 
       /* Skip over leading slashes.  */
-#if defined(HAVE_WIN32)
-      while (*slash == '/' || *slash == '\\')
-         slash++;
-#else
-      while (*slash == '/')
+      while (IsPathSeparator(*slash))
          slash++;
-#endif
-      while (1) {
+
+      for ( ; ; ) {
           int newly_created_dir;
           int fail;
 
           /* slash points to the leftmost unprocessed component of dirpath.  */
           basename_dir = slash;
-
-#if defined(HAVE_WIN32)
-          slash = strpbrk(slash, ":/\\");
-          if (slash == NULL) {
-             break;
-          }
-#else
-          slash = strchr (slash, '/');
+          slash = first_path_separator(slash);
           if (slash == NULL) {
              break;
           }
-#endif
 
           /* If we're *not* doing chdir before each mkdir, then we have to refer
              to the target using the full (multi-component) directory name.  */
@@ -338,13 +326,8 @@ make_path(
 
           /* Avoid unnecessary calls to `stat' when given
              pathnames containing multiple adjacent slashes.  */
-#if defined(HAVE_WIN32)
-         while (*slash == '/' || *slash == '\\')
-            slash++;
-#else
-         while (*slash == '/')
+         while (IsPathSeparator(*slash))
             slash++;
-#endif
       } /* end while (1) */
 
       if (!cwd.do_chdir) {
index 2e5bc262407655b0c1e7a433b86fbc85eab575e7..9b187c0f968d81e960838d16fe28706746409f03 100644 (file)
@@ -199,7 +199,7 @@ void add_fname_to_include_list(FF_PKT *ff, int prefixed, const char *fname)
    len = strlen(p);
    /* Zap trailing slashes.  */
    p += len - 1;
-   while (p > inc->fname && *p == '/') {
+   while (p > inc->fname && IsPathSeparator(*p)) {
       *p-- = 0;
       len--;
    }
@@ -246,11 +246,7 @@ void add_fname_to_exclude_list(FF_PKT *ff, const char *fname)
 
    Dmsg1(20, "Add name to exclude: %s\n", fname);
 
-#if defined(HAVE_WIN32)
-   if (strchr(fname, '/') || strchr(fname, '\\')) {
-#else
-   if (strchr(fname, '/')) {
-#endif
+   if (first_path_separator(fname) != NULL) {
       list = &ff->excluded_paths_list;
    } else {
       list = &ff->excluded_files_list;
@@ -322,11 +318,11 @@ int file_is_included(FF_PKT *ff, const char *file)
       if (inc->len == len && strcmp(inc->fname, file) == 0) {
          return 1;
       }
-      if (inc->len < len && file[inc->len] == '/' &&
+      if (inc->len < len && IsPathSeparator(file[inc->len]) &&
           strncmp(inc->fname, file, inc->len) == 0) {
          return 1;
       }
-      if (inc->len == 1 && inc->fname[0] == '/') {
+      if (inc->len == 1 && IsPathSeparator(inc->fname[0])) {
          return 1;
       }
    }
@@ -382,7 +378,7 @@ int file_is_excluded(FF_PKT *ff, const char *file)
    /* Try each component */
    for (p = file; *p; p++) {
       /* Match from the beginning of a component only */
-      if ((p == file || (*p != '/' && *(p-1) == '/'))
+      if ((p == file || (!IsPathSeparator(*p) && IsPathSeparator(p[-1])))
            && file_in_excluded_list(ff->excluded_files_list, p)) {
          return 1;
       }
index ae6ca36454adf6606879035ebcc2d7eb5faa6939..47a5ee1b9ed172652bc333dd6122b45f11a69394 100644 (file)
@@ -121,11 +121,11 @@ static void strip_double_slashes(char *fname)
 {
    char *p = fname;
    while (p && *p) {
-      p = strchr(p, '/');
-      if (p && p[1] == '/') {
-         strcpy(p, p+1);
-      }      
-      if (p) {
+      p = strpbrk(p, "/\\");
+      if (p != NULL) {
+         if (IsPathSeparator(p[1])) {
+            strcpy(p, p+1);
+         }
          p++;
       }
    }
@@ -162,7 +162,7 @@ void build_attr_output_fnames(JCR *jcr, ATTR *attr)
 #endif
       fn = attr->fname;            /* take whole name */
       /* Ensure where is terminated with a slash */
-      if (jcr->where[wherelen-1] != '/' && fn[0] != '/') {
+      if (!IsPathSeparator(jcr->where[wherelen-1]) && !IsPathSeparator(fn[0])) {
          pm_strcat(attr->ofname, "/");
       }
       pm_strcat(attr->ofname, fn); /* copy rest of name */
@@ -174,7 +174,7 @@ void build_attr_output_fnames(JCR *jcr, ATTR *attr)
          /* Always add prefix to hard links (FT_LNKSAVED) and
           *  on user request to soft links
           */
-         if (attr->lname[0] == '/' &&
+         if (IsPathSeparator(attr->lname[0]) &&
              (attr->type == FT_LNKSAVED || jcr->prefix_links)) {
             pm_strcpy(attr->olname, jcr->where);
             add_link = true;
@@ -190,15 +190,17 @@ void build_attr_output_fnames(JCR *jcr, ATTR *attr)
 #endif
          fn = attr->lname;       /* take whole name */
          /* Ensure where is terminated with a slash */
-         if (add_link && jcr->where[wherelen-1] != '/' && fn[0] != '/') {
+         if (add_link && 
+            !IsPathSeparator(jcr->where[wherelen-1]) && 
+            !IsPathSeparator(fn[0])) {
             pm_strcat(attr->olname, "/");
          }
          pm_strcat(attr->olname, fn);     /* copy rest of link */
       }
    }
 #if defined(HAVE_WIN32)
-      strip_double_slashes(attr->ofname);
-      strip_double_slashes(attr->olname);
+   strip_double_slashes(attr->ofname);
+   strip_double_slashes(attr->olname);
 #endif
 }
 
index 090f68efdb1462f5083a31ddc4cc7671fb418048..b3e79b47ee0884777dbcd763af9dec994362067b 100644 (file)
@@ -42,10 +42,10 @@ enh_fnmatch_sub(const char *pattern, const char *string, int patternlen, int fla
         case '?':
           if (*n == '\0')
             return 0;
-          else if ((flags & FNM_FILE_NAME) && *n == '/')
+          else if ((flags & FNM_FILE_NAME) && IsPathSeparator(*n))
             return 0;
           else if ((flags & FNM_PERIOD) && *n == '.' &&
-                   (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
+                   (n == string || ((flags & FNM_FILE_NAME) && IsPathSeparator(n[-1]))))
             return 0;
           break;
 
@@ -65,7 +65,7 @@ enh_fnmatch_sub(const char *pattern, const char *string, int patternlen, int fla
 
         case '*':
           if ((flags & FNM_PERIOD) && *n == '.' &&
-              (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
+              (n == string || ((flags & FNM_FILE_NAME) && IsPathSeparator(n[-1]))))
             return FNM_NOMATCH;
 
           if ((p - pattern) >= patternlen)
@@ -73,7 +73,7 @@ enh_fnmatch_sub(const char *pattern, const char *string, int patternlen, int fla
 
           for (c = *p++; ((p - pattern) <= patternlen) && (c == '?' || c == '*'); c = *p++)
             {
-              if ((flags & FNM_FILE_NAME) && *n == '/')
+              if ((flags & FNM_FILE_NAME) && IsPathSeparator(*n))
                 /* A slash does not match a wildcard under FNM_FILE_NAME.  */
                 return 0;
               else if (c == '?')
@@ -109,7 +109,7 @@ enh_fnmatch_sub(const char *pattern, const char *string, int patternlen, int fla
                   }
                 else
                   {
-                    if ((flags & FNM_FILE_NAME) && *n == '/')
+                    if ((flags & FNM_FILE_NAME) && IsPathSeparator(*n))
                       return 0;    /* A slash does not match a wildcard under FNM_FILE_NAME.  */
                   }
 
@@ -179,7 +179,7 @@ enh_fnmatch_sub(const char *pattern, const char *string, int patternlen, int fla
               return 0;
 
             if ((flags & FNM_PERIOD) && *n == '.' &&
-                (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
+                (n == string || ((flags & FNM_FILE_NAME) && IsPathSeparator(n[-1]))))
               return 0;
 
             nnot = (*p == '!' || *p == '^');
@@ -205,7 +205,7 @@ enh_fnmatch_sub(const char *pattern, const char *string, int patternlen, int fla
                 c = *p++;
                 c = FOLD (c);
 
-                if ((flags & FNM_FILE_NAME) && c == '/')
+                if ((flags & FNM_FILE_NAME) && IsPathSeparator(c))
                   /* [/] can never match.  */
                   return 0;
 
@@ -277,7 +277,7 @@ enh_fnmatch(const char *pattern, const char *string, int flags)
   if (string[matchlen] == '\0')
     return 0;
 
-  if ((flags & FNM_LEADING_DIR) && string[matchlen] == '/')
+  if ((flags & FNM_LEADING_DIR) && IsPathSeparator(string[matchlen]))
     /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz".  */
     return 0;
 
index ef1fab559c5e23d90b410dc0ee1eb769359ce641..29dad5ac118a75a6e7f138039831cc5b4e16db07 100644 (file)
@@ -41,10 +41,10 @@ fnmatch (const char *pattern, const char *string, int flags)
         case '?':
           if (*n == '\0')
             return FNM_NOMATCH;
-          else if ((flags & FNM_FILE_NAME) && *n == '/')
+          else if ((flags & FNM_FILE_NAME) && IsPathSeparator(*n))
             return FNM_NOMATCH;
           else if ((flags & FNM_PERIOD) && *n == '.' &&
-                   (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
+                   (n == string || ((flags & FNM_FILE_NAME) && IsPathSeparator(n[-1]))))
             return FNM_NOMATCH;
           break;
 
@@ -63,12 +63,12 @@ fnmatch (const char *pattern, const char *string, int flags)
 
         case '*':
           if ((flags & FNM_PERIOD) && *n == '.' &&
-              (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
+              (n == string || ((flags & FNM_FILE_NAME) && IsPathSeparator(n[-1]))))
             return FNM_NOMATCH;
 
           for (c = *p++; c == '?' || c == '*'; c = *p++)
             {
-              if ((flags & FNM_FILE_NAME) && *n == '/')
+              if ((flags & FNM_FILE_NAME) && IsPathSeparator(*n))
                 /* A slash does not match a wildcard under FNM_FILE_NAME.  */
                 return FNM_NOMATCH;
               else if (c == '?')
@@ -107,7 +107,7 @@ fnmatch (const char *pattern, const char *string, int flags)
               return FNM_NOMATCH;
 
             if ((flags & FNM_PERIOD) && *n == '.' &&
-                (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
+                (n == string || ((flags & FNM_FILE_NAME) && IsPathSeparator(n[-1]))))
               return FNM_NOMATCH;
 
             nnot = (*p == '!' || *p == '^');
@@ -135,7 +135,7 @@ fnmatch (const char *pattern, const char *string, int flags)
                 c = *p++;
                 c = FOLD (c);
 
-                if ((flags & FNM_FILE_NAME) && c == '/')
+                if ((flags & FNM_FILE_NAME) && IsPathSeparator(c))
                   /* [/] can never match.  */
                   return FNM_NOMATCH;
 
@@ -194,7 +194,7 @@ fnmatch (const char *pattern, const char *string, int flags)
   if (*n == '\0')
     return 0;
 
-  if ((flags & FNM_LEADING_DIR) && *n == '/')
+  if ((flags & FNM_LEADING_DIR) && IsPathSeparator(*n))
     /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz".  */
     return 0;
 
index 99c7362b05186fdb96f83a2e76774dceefc11bf9..d3e78f8762b1c0beb01645d4d1d904b0e09f465a 100644 (file)
@@ -37,40 +37,43 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 
 char *getuser(uid_t uid, char *name, int len)
 {
-  register struct userid *tail;
-  struct passwd *pwent;
-  char usernum_string[20];
-
-  P(mutex);
-  for (tail = user_alist; tail; tail = tail->next) {
-    if (tail->id.u == uid) {
-      goto uid_done;
-    }
-  }
+   register struct userid *tail;
+   char usernum_string[20];
+
+   P(mutex);
+   for (tail = user_alist; tail; tail = tail->next) {
+      if (tail->id.u == uid) {
+         goto uid_done;
+      }
+   }
+
+   tail = (struct userid *)malloc(sizeof (struct userid));
+   tail->id.u = uid;
+   tail->name = NULL;
+
+#if !defined(HAVE_WIN32)
+   {
+      struct passwd *pwent = getpwuid(uid);
+
+      if (pwent != NULL && strcmp(pwent->pw_name, "????????") != 0) {
+         tail->name = bstrdup(pwent->pw_name);
+      }
+   }
+#endif
 
-  pwent = getpwuid(uid);
-  tail = (struct userid *)malloc(sizeof (struct userid));
-  tail->id.u = uid;
-#ifndef HAVE_WIN32
-  if (pwent == NULL || strcmp(pwent->pw_name, "????????") == 0) {
+   if (tail->name == NULL) {
       sprintf(usernum_string, "%u", (uint32_t)uid);
       tail->name = bstrdup(usernum_string);
-  } else {
-      tail->name = bstrdup(pwent->pw_name);
-  }
-#else
-      sprintf(usernum_string, "%u", (uint32_t)uid);
-      tail->name = bstrdup(usernum_string);
-#endif
+   }
 
-  /* Add to the head of the list, so most recently used is first.  */
-  tail->next = user_alist;
-  user_alist = tail;
+   /* Add to the head of the list, so most recently used is first.  */
+   tail->next = user_alist;
+   user_alist = tail;
 
 uid_done:
-  bstrncpy(name, tail->name, len);
-  V(mutex);
-  return name;
+   bstrncpy(name, tail->name, len);
+   V(mutex);
+   return name;
 }
 
 void free_getuser_cache()
@@ -91,42 +94,46 @@ void free_getuser_cache()
 
 
 /* Translate GID to a group name or a stringified number,
-   with cache. */
+   with cache. */
 char *getgroup(gid_t gid, char *name, int len)
 {
-  register struct userid *tail;
-  struct group *grent;
-  char groupnum_string[20];
-
-  P(mutex);
-  for (tail = group_alist; tail; tail = tail->next) {
-    if (tail->id.g == gid) {
-      goto gid_done;
-    }
-  }
+   register struct userid *tail;
+   char groupnum_string[20];
+
+   P(mutex);
+   for (tail = group_alist; tail; tail = tail->next) {
+      if (tail->id.g == gid) {
+         goto gid_done;
+      }
+   }
+
+   tail = (struct userid *)malloc(sizeof (struct userid));
+   tail->id.g = gid;
+   tail->name = NULL;
+
+#if !defined(HAVE_WIN32)
+   {
+      struct group *grent = getgrgid(gid);
+
+      if (grent != NULL && strcmp(grent->gr_name, "????????") != 0) {
+         tail->name = bstrdup(grent->gr_name);
+      }
+   }
+#endif
 
-  grent = getgrgid(gid);
-  tail = (struct userid *)malloc(sizeof (struct userid));
-  tail->id.g = gid;
-#ifndef HAVE_WIN32
-  if (grent == NULL || strcmp(grent->gr_name, "????????") == 0) {
+   if (tail->name == NULL) {
       sprintf (groupnum_string, "%u", (uint32_t)gid);
       tail->name = bstrdup(groupnum_string);
-  } else {
-      tail->name = bstrdup(grent->gr_name);
-  }
-#else
-      sprintf (groupnum_string, "%u", (uint32_t)gid);
-      tail->name = bstrdup(groupnum_string);
-#endif
-  /* Add to the head of the list, so most recently used is first.  */
-  tail->next = group_alist;
-  group_alist = tail;
+   }
+
+   /* Add to the head of the list, so most recently used is first. */
+   tail->next = group_alist;
+   group_alist = tail;
 
 gid_done:
-  bstrncpy(name, tail->name, len);
-  V(mutex);
-  return name;
+   bstrncpy(name, tail->name, len);
+   V(mutex);
+   return name;
 }
 
 void free_getgroup_cache()
index f786d781a79624abeb5fe1bf8320c095d4c3eb01..dc91de9e470d86b54f1c59df10eca479d166f8b0 100755 (executable)
@@ -105,11 +105,11 @@ void my_name_is(int argc, char *argv[], const char *name)
    if (argc>0 && argv && argv[0]) {
       /* strip trailing filename and save exepath */
       for (l=p=argv[0]; *p; p++) {
-         if (*p == '/') {
+         if (IsPathSeparator(*p)) {
             l = p;                       /* set pos of last slash */
          }
       }
-      if (*l == '/') {
+      if (IsPathSeparator(*l)) {
          l++;
       } else {
          l = argv[0];
@@ -135,7 +135,7 @@ void my_name_is(int argc, char *argv[], const char *name)
          *q++ = *p++;
       }
       *q = 0;
-      if (strchr(exepath, '.') || exepath[0] != '/') {
+      if (strchr(exepath, '.') || !IsPathSeparator(exepath[0])) {
          if (getcwd(cpath, sizeof(cpath))) {
             free(exepath);
             exepath = (char *)malloc(strlen(cpath) + 1 + len);
index a76aacc39603207c06981cfb27a74bed5f3483aa..ecce0a4cfdd1c04846e0ec5375e4450f5abbb934 100755 (executable)
@@ -929,8 +929,6 @@ parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error, int err_type)
 const char *get_default_configdir()
 {
 #if defined(HAVE_WIN32)
-#define DEFAULT_CONFIGDIR "C:\\Documents and Settings\\All Users\\Application Data\\Bacula"
-
    HRESULT hr;
    static char szConfigDir[MAX_PATH + 1] = { 0 };
 
@@ -952,15 +950,9 @@ const char *get_default_configdir()
 bool
 find_config_file(const char *config_file, char *full_path)
 {
-#if defined(HAVE_WIN32)
-   if (strpbrk(config_file, ":/\\") != NULL) {
-      return false;
-   }
-#else
-   if (strchr(config_file, '/') != NULL) {
+   if (first_path_separator(config_file) != NULL) {
       return false;
    }
-#endif
 
    struct stat st;
 
@@ -978,8 +970,7 @@ find_config_file(const char *config_file, char *full_path)
 
    memcpy(full_path, config_dir, dir_length + 1);
 
-   if (full_path[dir_length - 1] != '/' && 
-       full_path[dir_length - 1] != '\\') {
+   if (!IsPathSeparator(full_path[dir_length - 1])) {
       full_path[dir_length++] = '/';
    }
 
index 20e11a5841e4431acbc6e9c2fb9672a1c9934821..5b2d8d4e0a80c4f5549d2550bc7c395c4d87bcd4 100644 (file)
@@ -311,8 +311,9 @@ const char *     job_type_to_str         (int type);
 const char *     job_status_to_str       (int stat);
 const char *     job_level_to_str        (int level);
 void             make_session_key        (char *key, char *seed, int mode);
-POOLMEM         *edit_job_codes(JCR *jcr, char *omsg, char *imsg, const char *to);
-void             set_working_directory(char *wd);
+POOLMEM *        edit_job_codes          (JCR *jcr, char *omsg, char *imsg, const char *to);
+void             set_working_directory   (char *wd);
+const char *     last_path_separator     (const char *str);
 
 
 /* watchdog.c */
index d4b4fab1694b1f54e05c48bf05b14799f22a1a0f..bbbe9913b3879396b9b528b7c3e048accdb29b63 100644 (file)
@@ -79,7 +79,7 @@ void strip_trailing_slashes(char *dir)
    p = dir + strlen(dir) - 1;
 
    /* strip trailing slashes */
-   while ((p >= dir) && (*p == '/'))
+   while (p >= dir && IsPathSeparator(*p))
       *p-- = 0;
 }
 
@@ -288,16 +288,16 @@ void split_path_and_filename(const char *fname, POOLMEM **path, int *pnl,
     */
    f = fname + len - 1;
    /* "strip" any trailing slashes */
-   while (slen > 1 && *f == '/') {
+   while (slen > 1 && IsPathSeparator(*f)) {
       slen--;
       f--;
    }
    /* Walk back to last slash -- begin of filename */
-   while (slen > 0 && *f != '/') {
+   while (slen > 0 && !IsPathSeparator(*f)) {
       slen--;
       f--;
    }
-   if (*f == '/') {                   /* did we find a slash? */
+   if (IsPathSeparator(*f)) {         /* did we find a slash? */
       f++;                            /* yes, point to filename */
    } else {                           /* no, whole thing must be path name */
       f = fname;
index 50bfcc21b93439d95075e1e682827d13dfa420c1..18b4e797e92c5dc7ebcbb86d76a5451befb0bf27 100644 (file)
@@ -112,12 +112,12 @@ extern "C" void signal_handler(int sig)
          bstrncpy(btpath, "btraceback", sizeof(btpath));
       } else {
          bstrncpy(btpath, exepath, sizeof(btpath));
-         if (btpath[exelen-1] == '/') {
+         if (IsPathSeparator(btpath[exelen-1])) {
             btpath[exelen-1] = 0;
          }
          bstrncat(btpath, "/btraceback", sizeof(btpath));
       }
-      if (exepath[exelen-1] != '/') {
+      if (!IsPathSeparator(exepath[exelen - 1])) {
          strcat(exepath, "/");
       }
       strcat(exepath, exename);
index 62b9aa154d47fd959e58fa518b55ebd576a3d7cc..0d8f24db8c155fa51b6bb543b8058eb73196adea 100755 (executable)
@@ -191,7 +191,7 @@ TREE_NODE *insert_tree_node(char *path, char *fname, int type,
     */
    if (path_len > 0) {
       q = path + path_len - 1;
-      if (*q == '/') {
+      if (IsPathSeparator(*q)) {
          *q = 0;                      /* strip trailing slash */
       } else {
          q = NULL;                    /* no trailing slash */
@@ -201,10 +201,10 @@ TREE_NODE *insert_tree_node(char *path, char *fname, int type,
    }
    /* If no filename, strip last component of path as "filename" */
    if (*fname == 0) {
-      p = strrchr(path, '/');         /* separate path and filename */
+      p = (char *)last_path_separator(path);  /* separate path and filename */
       if (p) {
          fname = p + 1;               /* set new filename */
-         *p = 0;                      /* terminate new path */
+         *p = '\0';                   /* terminate new path */
       }
    } else {
       p = NULL;
@@ -258,7 +258,7 @@ TREE_NODE *make_tree_path(char *path, TREE_ROOT *root)
       Dmsg0(100, "make_tree_path: parent=*root*\n");
       return (TREE_NODE *)root;
    }
-   p = strrchr(path, '/');           /* get last dir component of path */
+   p = (char *)last_path_separator(path);           /* get last dir component of path */
    if (p) {
       fname = p + 1;
       *p = 0;                         /* terminate path */
@@ -332,15 +332,15 @@ int tree_getpath(TREE_NODE *node, char *buf, int buf_size)
     *    there is only a / in the buffer, remove it since
     *    win32 names don't generally start with /
     */
-   if (node->type == TN_DIR_NLS && buf[0] == '/' && buf[1] == 0) {
-      buf[0] = 0;
+   if (node->type == TN_DIR_NLS && IsPathSeparator(buf[0]) && buf[1] == '\0') {
+      buf[0] = '\0';
    }
    bstrncat(buf, node->fname, buf_size);
    /* Add a slash for all directories unless we are at the root,
     *  also add a slash to a soft linked file if it has children
     *  i.e. it is linked to a directory.
     */
-   if ((node->type != TN_FILE && !(buf[0] == '/' && buf[1] == 0)) ||
+   if ((node->type != TN_FILE && !(IsPathSeparator(buf[0]) && buf[1] == '\0')) ||
        (node->soft_link && tree_node_has_child(node))) {
       bstrncat(buf, "/", buf_size);
    }
@@ -364,7 +364,7 @@ TREE_NODE *tree_cwd(char *path, TREE_ROOT *root, TREE_NODE *node)
          return tree_cwd(path+3, root, parent);
       }
    }
-   if (path[0] == '/') {
+   if (IsPathSeparator(path[0])) {
       Dmsg0(100, "Doing absolute lookup.\n");
       return tree_relcwd(path+1, root, (TREE_NODE *)root);
    }
@@ -386,8 +386,7 @@ TREE_NODE *tree_relcwd(char *path, TREE_ROOT *root, TREE_NODE *node)
       return node;
    }
    /* Check the current segment only */
-   p = strchr(path, '/');
-   if (p) {
+   if ((p = first_path_separator(path)) != NULL) {
       len = p - path;
    } else {
       len = strlen(path);
index 154965b9d51583970abc9eb1722ac1df9de8c068..0519cb5d530d0d486e8c4fc637e13c241c933fd9 100644 (file)
@@ -700,3 +700,16 @@ void set_working_directory(char *wd)
    }
    working_directory = wd;            /* set global */
 }
+
+const char *last_path_separator(const char *str)
+{
+   if (*str != '\0') {
+      for (const char *p = &str[strlen(str) - 1]; p >= str; p--) {
+         if (IsPathSeparator(*p)) {
+            return p;
+         }
+      }
+   }
+   return NULL;
+}
+
index 9b6c1213b21be3c466951c0a5dc40f7a6c5a5a2f..428e9a04bb1b4b23861c2623928e406ceb3a298f 100644 (file)
@@ -339,7 +339,7 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
             unser_uint64(faddr);
             if (fileAddr != faddr) {
                fileAddr = faddr;
-               if (blseek(&bfd, (off_t)fileAddr, SEEK_SET) < 0) {
+               if (blseek(&bfd, (boffset_t)fileAddr, SEEK_SET) < 0) {
                   berrno be;
                   Emsg2(M_ERROR_TERM, 0, _("Seek error on %s: %s\n"),
                      attr->ofname, be.strerror());
@@ -379,7 +379,7 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
             unser_uint64(faddr);
             if (fileAddr != faddr) {
                fileAddr = faddr;
-               if (blseek(&bfd, (off_t)fileAddr, SEEK_SET) < 0) {
+               if (blseek(&bfd, (boffset_t)fileAddr, SEEK_SET) < 0) {
                   berrno be;
                   Emsg3(M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
                      edit_uint64(fileAddr, ec1), attr->ofname, be.strerror());
index 5e380b7a301b965c01ef11f26cdb55591b2f010d..bb675a20082a1d4fe0f19459697fea1d9c900534 100644 (file)
@@ -1042,7 +1042,7 @@ reread:
          }
       } else {
          Dmsg0(200, "Seek to beginning of block for reread.\n");
-         off_t pos = dev->lseek(dcr, (off_t)0, SEEK_CUR); /* get curr pos */
+         boffset_t pos = dev->lseek(dcr, (boffset_t)0, SEEK_CUR); /* get curr pos */
          pos -= block->read_len;
          dev->lseek(dcr, pos, SEEK_SET);
          dev->file_addr = pos;
@@ -1114,7 +1114,7 @@ reread:
    Dmsg0(200, "At end of read block\n");
    if (block->read_len > block->block_len && !dev->is_tape()) {
       char ed1[50];
-      off_t pos = dev->lseek(dcr, (off_t)0, SEEK_CUR); /* get curr pos */
+      boffset_t pos = dev->lseek(dcr, (boffset_t)0, SEEK_CUR); /* get curr pos */
       Dmsg1(200, "Current lseek pos=%s\n", edit_int64(pos, ed1));
       pos -= (block->read_len - block->block_len);
       dev->lseek(dcr, pos, SEEK_SET);
index 3cd41fa656101394c707fca827f8c7ec500ce830..50e30914f31c076ac0b3c5ebf93b031ed265eac8 100644 (file)
@@ -163,9 +163,9 @@ int main(int margc, char *margv[])
    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));
+   if (sizeof(boffset_t) < 8) {
+      Pmsg1(-1, _("\n\n!!!! Warning large disk addressing disabled. boffset_t=%d should be 8 or more !!!!!\n\n\n"),
+         sizeof(boffset_t));
    }
    x32 = 123456789;
    bsnprintf(buf, sizeof(buf), "%u", x32);
@@ -2100,7 +2100,7 @@ static void unfillcmd()
 static void do_unfill()
 {
    DEV_BLOCK *block = dcr->block;
-   bool autochanger;
+   int autochanger;
 
    dumped = 0;
    VolBytes = 0;
@@ -2143,7 +2143,7 @@ static void do_unfill()
          dev->offline();
       }
       autochanger = autoload_device(dcr, 1, NULL);
-      if (!autochanger) {
+      if (autochanger != 1) {
          dev->close();
          get_cmd(_("Mount first tape. Press enter when ready: "));
       }
@@ -2205,7 +2205,7 @@ static void do_unfill()
    set_volume_name("TestVolume2", 2);
 
    autochanger = autoload_device(dcr, 1, NULL);
-   if (!autochanger) {
+   if (autochanger != 1) {
       dev->close();
       get_cmd(_("Mount second tape. Press enter when ready: "));
    }
@@ -2726,7 +2726,7 @@ bool dir_ask_sysop_to_mount_volume(DCR *dcr)
 
 bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr)
 {
-   bool autochanger;
+   int autochanger;
    DEVICE *dev = dcr->dev;
    Dmsg0(20, "Enter dir_ask_sysop_to_create_appendable_volume\n");
    if (stop == 0) {
@@ -2739,7 +2739,7 @@ bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr)
       dev->offline();
    }
    autochanger = autoload_device(dcr, 1, NULL);
-   if (!autochanger) {
+   if (autochanger != 1) {
       fprintf(stderr, _("Mount blank Volume on device %s and press return when ready: "),
          dev->print_name());
       dev->close();
index 43a8088a8f909425cd9c8dacddb39afc687db04c..f2817562483589a58b88efcff641473663a65cab 100644 (file)
@@ -140,9 +140,9 @@ static DCR *setup_to_access_device(JCR *jcr, char *dev_name,
          /* Try stripping file part */
          p = dev_name + strlen(dev_name);
 
-         while (p >= dev_name && *p != '/')
+         while (p >= dev_name && !IsPathSeparator(*p))
             p--;
-         if (*p == '/') {
+         if (IsPathSeparator(*p)) {
             bstrncpy(VolName, p+1, sizeof(VolName));
             *p = 0;
          }
index 231f3c15666bb04996475c792d83ff7044505a36..ffb02c9641529ce8087adf4a8fb7c6043f440e4d 100644 (file)
@@ -447,7 +447,7 @@ void DEVICE::open_file_device(DCR *dcr, int omode)
          return;
       }
 
-      if (archive_name.c_str()[strlen(archive_name.c_str())-1] != '/') {
+      if (!IsPathSeparator(archive_name.c_str()[strlen(archive_name.c_str())-1])) {
          pm_strcat(archive_name, "/");
       }
       pm_strcat(archive_name, VolCatInfo.VolCatName);
@@ -752,7 +752,7 @@ bool DEVICE::rewind(DCR *dcr)
          break;
       }
    } else if (is_file() || is_dvd()) {
-      if (lseek(dcr, (off_t)0, SEEK_SET) < 0) {
+      if (lseek(dcr, (boffset_t)0, SEEK_SET) < 0) {
          berrno be;
          dev_errno = errno;
          Mmsg2(errmsg, _("lseek error on %s. ERR=%s.\n"),
@@ -835,7 +835,7 @@ bool DEVICE::eod(DCR *dcr)
    struct mtop mt_com;
    struct mtget mt_stat;
    bool ok = true;
-   off_t pos;
+   boffset_t pos;
 
    if (fd < 0) {
       dev_errno = EBADF;
@@ -859,7 +859,7 @@ bool DEVICE::eod(DCR *dcr)
       return true;
    }
    if (!is_tape()) {
-      pos = lseek(dcr, (off_t)0, SEEK_END);
+      pos = lseek(dcr, (boffset_t)0, SEEK_END);
 //    Dmsg1(100, "====== Seek to %lld\n", pos);
       if (pos >= 0) {
          update_pos(dcr);
@@ -985,7 +985,7 @@ bool DEVICE::eod(DCR *dcr)
  */
 bool DEVICE::update_pos(DCR *dcr)
 {
-   off_t pos;
+   boffset_t pos;
    bool ok = true;
 
    if (!is_open()) {
@@ -999,7 +999,7 @@ bool DEVICE::update_pos(DCR *dcr)
    if (is_file() || is_dvd()) {
       file = 0;
       file_addr = 0;
-      pos = lseek(dcr, (off_t)0, SEEK_CUR);
+      pos = lseek(dcr, (boffset_t)0, SEEK_CUR);
       if (pos < 0) {
          berrno be;
          dev_errno = errno;
@@ -1568,9 +1568,9 @@ bool DEVICE::reposition(DCR *dcr, uint32_t rfile, uint32_t rblock)
    }
 
    if (!is_tape()) {
-      off_t pos = (((off_t)rfile)<<32) + (off_t)rblock;
+      boffset_t pos = (((boffset_t)rfile)<<32) | rblock;
       Dmsg1(100, "===== lseek to %d\n", (int)pos);
-      if (lseek(dcr, pos, SEEK_SET) == (off_t)-1) {
+      if (lseek(dcr, pos, SEEK_SET) == (boffset_t)-1) {
          berrno be;
          dev_errno = errno;
          Mmsg2(errmsg, _("lseek error on %s. ERR=%s.\n"),
@@ -1893,14 +1893,18 @@ void DEVICE::close_part(DCR *dcr)
    dcr->VolCatInfo = saveVolCatInfo;  /* structure assignment */
 }
 
-off_t DEVICE::lseek(DCR *dcr, off_t offset, int whence)
+boffset_t DEVICE::lseek(DCR *dcr, boffset_t offset, int whence)
 {
    switch (dev_type) {
    case B_DVD_DEV:
       return lseek_dvd(dcr, offset, whence);
    case B_FILE_DEV:
-      return ::lseek(fd, offset, whence);
-   }  
+#if defined(HAVE_WIN32)
+      return ::_lseeki64(fd, (__int64)offset, whence);
+#else
+      return ::lseek(fd, (off_t)offset, whence);
+#endif
+   }
    return -1;
 }
 
index dfc4cd7e4634faa36d0e5bff483a6805e157f5da..c6ffc63e1c50dd71651a11ed5a2e08d8c0201b5d 100644 (file)
@@ -368,7 +368,7 @@ public:
    bool scan_dir_for_volume(DCR *dcr); /* in scan.c */
    bool reposition(DCR *dcr, uint32_t rfile, uint32_t rblock); /* in dev.c */
    void clrerror(int func);      /* in dev.c */
-   off_t lseek(DCR *dcr, off_t offset, int whence); /* in dev.c */
+   boffset_t lseek(DCR *dcr, boffset_t offset, int whence); /* in dev.c */
    bool update_pos(DCR *dcr);    /* in dev.c */
    bool update_freespace();      /* in dvd.c */
 
index 5fd7ea7d7503a26fbcac6a0e62a36260c165e0df..8a45fd78c3917d8538039d1a065671b07ab406e9 100644 (file)
@@ -52,7 +52,7 @@ static void add_file_and_part_name(DEVICE *dev, POOL_MEM &archive_name)
 {
    char partnumber[20];
 
-   if (archive_name.c_str()[strlen(archive_name.c_str())-1] != '/') {
+   if (!IsPathSeparator(archive_name.c_str()[strlen(archive_name.c_str())-1])) {
       pm_strcat(archive_name, "/");
    }
 
@@ -416,10 +416,10 @@ static bool dvd_open_first_part(DCR *dcr, int mode)
 /* 
  * Do an lseek on a DVD handling all the different parts
  */
-off_t lseek_dvd(DCR *dcr, off_t offset, int whence)
+boffset_t lseek_dvd(DCR *dcr, boffset_t offset, int whence)
 {
    DEVICE *dev = dcr->dev;
-   off_t pos;
+   boffset_t pos;
    char ed1[50], ed2[50];
    
    Dmsg5(400, "Enter lseek_dvd fd=%d off=%s w=%d part=%d nparts=%d\n", dev->fd,
@@ -433,7 +433,12 @@ off_t lseek_dvd(DCR *dcr, off_t offset, int whence)
          if ((uint64_t)offset == dev->part_start || 
              (uint64_t)offset < dev->part_start+dev->part_size) {
             /* We are staying in the current part, just seek */
-            if ((pos = lseek(dev->fd, offset-dev->part_start, SEEK_SET)) < 0) {
+#if defined(HAVE_WIN32)
+            pos = _lseeki64(dev->fd, offset-dev->part_start, SEEK_SET);
+#else
+            pos = lseek(dev->fd, offset-dev->part_start, SEEK_SET);
+#endif
+            if (pos < 0) {
                return pos;
             } else {
                return pos + dev->part_start;
@@ -721,7 +726,7 @@ bool check_can_write_on_non_blank_dvd(DCR *dcr)
             /* Found a file, checking it is empty */
             POOL_MEM filename(PM_FNAME);
             pm_strcpy(filename, dev->device->mount_point);
-            if (filename.c_str()[strlen(filename.c_str())-1] != '/') {
+            if (!IsPathSeparator(filename.c_str()[strlen(filename.c_str())-1])) {
                pm_strcat(filename, "/");
             }
             pm_strcat(filename, result->d_name);
index e31d8f98e6b224e1dd34898e8440dbd0afaa8b6e..0bab20269f16403d87e014a4702c50ce3059bd82 100644 (file)
@@ -106,7 +106,7 @@ void    make_spooled_dvd_filename(DEVICE *dev, POOL_MEM &archive_name);
 bool    truncate_dvd(DCR *dcr);
 bool    check_can_write_on_non_blank_dvd(DCR *dcr);
 int     find_num_dvd_parts(DCR *dcr);
-off_t   lseek_dvd(DCR *dcr, off_t offset, int whence);
+boffset_t   lseek_dvd(DCR *dcr, boffset_t offset, int whence);
 void    dvd_remove_empty_part(DCR *dcr);
 
 /* From device.c */
index 2be050fa6d4f182ada10aa3c909477fa7a647c82..80f8f76957a5b008ce9429d6422cace71aeed9e9 100644 (file)
@@ -64,7 +64,7 @@ bool DEVICE::scan_dir_for_volume(DCR *dcr)
    
    len = strlen(mount_point);
    if (len > 0) {
-      need_slash = mount_point[len - 1] != '/';
+      need_slash = !IsPathSeparator(mount_point[len - 1]);
    }
    entry = (struct dirent *)malloc(sizeof(struct dirent) + name_max + 1000);
    for ( ;; ) {
index a896cbae03f4f7d16f2f0dd89406b399ed31929e..74c89ae9b483d3f013b3cb1a6f167f98efe0be12 100644 (file)
@@ -462,7 +462,12 @@ static bool write_spool_header(DCR *dcr)
       if (stat != (ssize_t)sizeof(hdr)) {
          /* If we wrote something, truncate it, then despool */
          if (stat != -1) {
-            if (ftruncate(dcr->spool_fd, lseek(dcr->spool_fd, (off_t)0, SEEK_CUR) - stat) != 0) {
+#if defined(HAVE_WIN32)
+            boffset_t   pos = _lseeki64(dcr->spool_fd, (__int64)0, SEEK_CUR);
+#else
+            boffset_t   pos = lseek(dcr->spool_fd, (off_t)0, SEEK_CUR);
+#endif
+            if (ftruncate(dcr->spool_fd, pos - stat) != 0) {
                berrno be;
                Jmsg(dcr->jcr, M_FATAL, 0, _("Ftruncate spool file failed: ERR=%s\n"),
                   be.strerror());
@@ -499,8 +504,12 @@ static bool write_spool_data(DCR *dcr)
           * If we wrote something, truncate it and the header, then despool
           */
          if (stat != -1) {
-            if (ftruncate(dcr->spool_fd, lseek(dcr->spool_fd, (off_t)0, SEEK_CUR)
-                      - stat - sizeof(spool_hdr)) != 0) {
+#if defined(HAVE_WIN32)
+            boffset_t   pos = _lseeki64(dcr->spool_fd, (__int64)0, SEEK_CUR);
+#else
+            boffset_t   pos = lseek(dcr->spool_fd, (off_t)0, SEEK_CUR);
+#endif
+            if (ftruncate(dcr->spool_fd, pos - stat - sizeof(spool_hdr)) != 0) {
                berrno be;
                Jmsg(dcr->jcr, M_FATAL, 0, _("Ftruncate spool file failed: ERR=%s\n"),
                   be.strerror());
index aa6c47ad07c7f319bb329f92920507264bdb531f..df2648c35a2ff6df031ac81db97b796276d7bc53 100644 (file)
@@ -424,11 +424,7 @@ static void cleanup_old_files()
    pm_strcpy(cleanup, "/bin/rm -f ");
 #endif
    pm_strcat(cleanup, me->working_directory);
-   if (len > 0 && me->working_directory[len-1] != '/'
-#if defined(HAVE_WIN32)
-       && me->working_directory[len-1] != '\\'
-#endif
-       ) {
+   if (len > 0 && !IsPathSeparator(me->working_directory[len-1])) {
       pm_strcat(cleanup, "/");
    }
    pm_strcat(cleanup, my_name);
index d473899c3681b5560a3aa045f8e4e7526993feb2..b9e83fd7ad49e519d06e7555eabc1e751469f271 100644 (file)
@@ -1035,7 +1035,7 @@ static void repair_bad_filenames()
             printf("%s\n", db_strerror(db));
          }
          /* Strip trailing slash(es) */
-         for (len=strlen(name); len > 0 && name[len-1]=='/'; len--)
+         for (len=strlen(name); len > 0 && IsPathSeparator(name[len-1]); len--)
             {  }
          if (len == 0) {
             len = 1;
index 3b7876912fccd53f44070374ba1d648840386947..441c1f2a87b1183e7a1542d82b7e3511e955aa46 100644 (file)
@@ -338,11 +338,11 @@ static void count_files(FF_PKT *ar)
     * must be a path name (e.g. c:).
     */
    for (p=l=ar->fname; *p; p++) {
-      if (*p == '/') {
+      if (IsPathSeparator(*p)) {
          l = p;                       /* set pos of last slash */
       }
    }
-   if (*l == '/') {                   /* did we find a slash? */
+   if (IsPathSeparator(*l)) {                   /* did we find a slash? */
       l++;                            /* yes, point to filename */
    } else {                           /* no, whole thing must be path name */
       l = p;