From 7313af1d71e8bc6c95792526d437973369ab5a35 Mon Sep 17 00:00:00 2001 From: Robert Nelson Date: Fri, 30 Jun 2006 04:06:34 +0000 Subject: [PATCH] Merge in all the low-risk changes from the Windows branch. Add all the new files from the Windows branch. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3094 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/baconfig.h | 9 +- bacula/src/bacula.h | 4 +- bacula/src/bc_types.h | 4 - bacula/src/cats/Makefile.in | 3 + bacula/src/cats/bdb.c | 12 +- bacula/src/cats/bdb_create.c | 6 +- bacula/src/cats/bdb_find.c | 3 +- bacula/src/cats/bdb_get.c | 5 +- bacula/src/cats/make_mysql_tables.in | 22 +-- bacula/src/cats/protos.h | 2 +- bacula/src/cats/sql_create.c | 12 +- bacula/src/cats/sql_get.c | 2 + bacula/src/cats/sql_list.c | 2 +- bacula/src/cats/sql_update.c | 14 +- bacula/src/console/console.c | 14 +- bacula/src/console/console_conf.c | 5 +- bacula/src/dird/backup.c | 2 +- bacula/src/dird/bsr.c | 2 +- bacula/src/dird/catreq.c | 2 +- bacula/src/dird/dird.c | 10 +- bacula/src/dird/dird_conf.c | 6 + bacula/src/dird/dird_conf.h | 14 +- bacula/src/dird/expand.c | 2 +- bacula/src/dird/fd_cmds.c | 4 +- bacula/src/dird/inc_conf.c | 8 +- bacula/src/dird/job.c | 2 +- bacula/src/dird/run_conf.c | 6 + bacula/src/dird/scheduler.c | 6 +- bacula/src/dird/sql_cmds.c | 8 +- bacula/src/dird/ua_cmds.c | 2 +- bacula/src/dird/ua_output.c | 4 +- bacula/src/dird/ua_prune.c | 34 ++-- bacula/src/dird/ua_query.c | 2 +- bacula/src/dird/ua_restore.c | 22 +-- bacula/src/dird/ua_run.c | 2 +- bacula/src/dird/ua_update.c | 2 +- bacula/src/filed/estimate.c | 1 + bacula/src/filed/filed.c | 2 +- bacula/src/filed/filed_conf.c | 5 +- bacula/src/filed/job.c | 10 +- bacula/src/filed/status.c | 8 +- bacula/src/findlib/attribs.c | 13 +- bacula/src/findlib/bfile.c | 2 +- bacula/src/findlib/bfile.h | 4 +- bacula/src/findlib/drivetype.c | 116 +++++++++++ bacula/src/findlib/enable_priv.c | 6 +- bacula/src/findlib/find.c | 7 +- bacula/src/findlib/makepath.c | 8 +- bacula/src/findlib/match.c | 8 +- bacula/src/lib/base64.c | 2 +- bacula/src/lib/berrno.c | 3 +- bacula/src/lib/bnet.c | 6 +- bacula/src/lib/bpipe.c | 4 +- bacula/src/lib/bshm.c | 4 +- bacula/src/lib/bsys.c | 6 +- bacula/src/lib/btime.c | 16 +- bacula/src/lib/daemon.c | 4 +- bacula/src/lib/enh_fnmatch.c | 285 +++++++++++++++++++++++++++ bacula/src/lib/enh_fnmatch.h | 51 +++++ bacula/src/lib/events.c | 4 +- bacula/src/lib/lex.c | 2 +- bacula/src/lib/md5.c | 2 +- bacula/src/lib/message.c | 36 ++-- bacula/src/lib/parse_conf.c | 5 +- bacula/src/lib/protos.h | 2 +- bacula/src/lib/res.c | 11 -- bacula/src/lib/runscript.c | 2 - bacula/src/lib/sha1.c | 2 +- bacula/src/stored/bextract.c | 6 +- bacula/src/stored/bls.c | 4 +- bacula/src/stored/bscan.c | 2 +- bacula/src/stored/btape.c | 12 +- bacula/src/stored/dev.c | 4 +- bacula/src/stored/dev.h | 2 +- bacula/src/stored/dircmd.c | 2 +- bacula/src/stored/fd_cmds.c | 2 +- bacula/src/stored/spool.c | 2 +- bacula/src/stored/stored_conf.c | 6 + bacula/src/stored/stored_conf.h | 2 +- bacula/src/tools/bwild.c | 1 - bacula/src/tools/drivetype.c | 94 +++++++++ bacula/src/tools/fstype.c | 2 +- bacula/src/tools/testfind.c | 2 +- bacula/src/tools/testls.c | 6 +- 84 files changed, 796 insertions(+), 249 deletions(-) create mode 100644 bacula/src/findlib/drivetype.c create mode 100644 bacula/src/lib/enh_fnmatch.c create mode 100644 bacula/src/lib/enh_fnmatch.h create mode 100644 bacula/src/tools/drivetype.c diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index 16e9cfe424..f052b13cde 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -65,7 +65,7 @@ /* Allow printing of NULL pointers */ #define NPRT(x) (x)?(x):_("*None*") -#ifdef WIN32 +#if defined(HAVE_WIN32) #undef ENABLE_NLS #endif @@ -218,6 +218,7 @@ * or saved */ #define FT_DIRBEGIN 18 /* Directory at beginning (not saved) */ #define FT_INVALIDFS 19 /* File system not allowed for */ +#define FT_INVALIDDT 20 /* Drive type not allowed for */ /* Definitions for upper part of type word (see above). */ #define AR_DATA_STREAM (1<<16) /* Data stream id present */ @@ -562,13 +563,9 @@ extern "C" int getdomainname(char *name, int len); extern "C" int mknod ( const char *path, int mode, dev_t device ); #endif -#ifdef HAVE_CYGWIN -/* They don't really have it */ -#undef HAVE_GETDOMAINNAME -#endif /* Define Winsock functions if we aren't on Windows */ -#if (!defined HAVE_WIN32) || (defined HAVE_CYGWIN) +#if !defined HAVE_WIN32 #define WSA_Init() 0 /* 0 = success */ #define WSACleanup() 0 /* 0 = success */ #endif diff --git a/bacula/src/bacula.h b/bacula/src/bacula.h index daedd83bd3..f677f2458a 100644 --- a/bacula/src/bacula.h +++ b/bacula/src/bacula.h @@ -26,8 +26,8 @@ #define _LANGUAGE_C_PLUS_PLUS 1 #endif -#ifdef WIN32 -#ifdef HAVE_MINGW +#if defined(HAVE_WIN32) +#if defined(HAVE_MINGW) #include "mingwconfig.h" #include "winhost.h" #define _STAT_H /* don't pull in MinGW stat.h */ diff --git a/bacula/src/bc_types.h b/bacula/src/bc_types.h index 75950bd32d..81595edb9e 100644 --- a/bacula/src/bc_types.h +++ b/bacula/src/bc_types.h @@ -173,10 +173,6 @@ typedef float float32_t; /* Unix time (time_t) widened to 64 bits */ #define utime_t int64_t -#ifdef HAVE_CYGWIN -#define int_least16_t int32_t -#endif - #ifndef HAVE_SOCKLEN_T #define socklen_t int #endif diff --git a/bacula/src/cats/Makefile.in b/bacula/src/cats/Makefile.in index 44ec71b360..0a3495610e 100644 --- a/bacula/src/cats/Makefile.in +++ b/bacula/src/cats/Makefile.in @@ -81,6 +81,9 @@ realclean: clean $(RMF) create_sqlite_database update_sqlite_tables make_sqlite_tables $(RMF) grant_sqlite_privileges drop_sqlite_tables drop_sqlite_database + $(RMF) create_sqlite3_database update_sqlite3_tables make_sqlite3_tables + $(RMF) grant_sqlite3_privileges drop_sqlite3_tables drop_sqlite3_database + $(RMF) mysql sqlite postgresql $(RMF) make_catalog_backup delete_catalog_backup diff --git a/bacula/src/cats/bdb.c b/bacula/src/cats/bdb.c index a0836efc9f..43cc175e2b 100644 --- a/bacula/src/cats/bdb.c +++ b/bacula/src/cats/bdb.c @@ -296,7 +296,7 @@ int bdb_open_jobs_file(B_DB *mdb) if (!mdb->jobfd) { dbf = make_filename(mdb, DB_JOBS_FILENAME); - mdb->jobfd = fopen(dbf, "r+"); + mdb->jobfd = fopen(dbf, "r+b"); if (!mdb->jobfd) { Mmsg2(&mdb->errmsg, "Error opening DB Jobs file %s: ERR=%s\n", dbf, strerror(errno)); @@ -318,7 +318,7 @@ int bdb_open_jobmedia_file(B_DB *mdb) if (!mdb->jobmediafd) { dbf = make_filename(mdb, DB_JOBMEDIA_FILENAME); - mdb->jobmediafd = fopen(dbf, "r+"); + mdb->jobmediafd = fopen(dbf, "r+b"); if (!mdb->jobmediafd) { Mmsg2(&mdb->errmsg, "Error opening DB JobMedia file %s: ERR=%s\n", dbf, strerror(errno)); @@ -341,7 +341,7 @@ int bdb_open_pools_file(B_DB *mdb) if (!mdb->poolfd) { dbf = make_filename(mdb, DB_POOLS_FILENAME); - mdb->poolfd = fopen(dbf, "r+"); + mdb->poolfd = fopen(dbf, "r+b"); if (!mdb->poolfd) { Mmsg2(&mdb->errmsg, "Error opening DB Pools file %s: ERR=%s\n", dbf, strerror(errno)); @@ -364,7 +364,7 @@ int bdb_open_client_file(B_DB *mdb) if (!mdb->clientfd) { dbf = make_filename(mdb, DB_CLIENT_FILENAME); - mdb->clientfd = fopen(dbf, "r+"); + mdb->clientfd = fopen(dbf, "r+b"); if (!mdb->clientfd) { Mmsg2(&mdb->errmsg, "Error opening DB Clients file %s: ERR=%s\n", dbf, strerror(errno)); @@ -386,7 +386,7 @@ int bdb_open_fileset_file(B_DB *mdb) if (!mdb->filesetfd) { dbf = make_filename(mdb, DB_CLIENT_FILENAME); - mdb->filesetfd = fopen(dbf, "r+"); + mdb->filesetfd = fopen(dbf, "r+b"); if (!mdb->filesetfd) { Mmsg2(&mdb->errmsg, "Error opening DB FileSet file %s: ERR=%s\n", dbf, strerror(errno)); @@ -410,7 +410,7 @@ int bdb_open_media_file(B_DB *mdb) if (!mdb->mediafd) { dbf = make_filename(mdb, DB_MEDIA_FILENAME); - mdb->mediafd = fopen(dbf, "r+"); + mdb->mediafd = fopen(dbf, "r+b"); if (!mdb->mediafd) { Mmsg2(&mdb->errmsg, "Error opening DB Media file %s: ERR=%s\n", dbf, strerror(errno)); diff --git a/bacula/src/cats/bdb_create.c b/bacula/src/cats/bdb_create.c index 3228d42e08..07d7b9a711 100644 --- a/bacula/src/cats/bdb_create.c +++ b/bacula/src/cats/bdb_create.c @@ -23,8 +23,8 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - the file LICENSE for additional details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + file LICENSE for additional details. */ @@ -71,7 +71,7 @@ int db_create_file_item(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) * Returns: 0 on failure * 1 on success */ -int db_create_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) +bool db_create_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) { int len; diff --git a/bacula/src/cats/bdb_find.c b/bacula/src/cats/bdb_find.c index 6c5bd3b117..f63a5354dc 100644 --- a/bacula/src/cats/bdb_find.c +++ b/bacula/src/cats/bdb_find.c @@ -16,6 +16,7 @@ * * Version $Id$ */ + /* Copyright (C) 2001-2006 Kern Sibbald @@ -171,7 +172,7 @@ db_find_next_volume(JCR *jcr, B_DB *mdb, int item, bool InChanger, MEDIA_DBR *mr return stat; } -int +bool db_find_last_jobid(JCR *jcr, B_DB *mdb, const char *Name, JOB_DBR *jr) { return 0; } diff --git a/bacula/src/cats/bdb_get.c b/bacula/src/cats/bdb_get.c index 8fd20b0fa3..3a1e7d8174 100644 --- a/bacula/src/cats/bdb_get.c +++ b/bacula/src/cats/bdb_get.c @@ -15,6 +15,7 @@ * * Version $Id$ */ + /* Copyright (C) 2001-2006 Kern Sibbald @@ -26,7 +27,7 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - the file LICENSE for additional details. + file LICENSE for additional details. */ @@ -59,7 +60,7 @@ * 1 on success */ -int db_get_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) +bool db_get_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) { JOB_DBR ojr; faddr_t rec_addr; diff --git a/bacula/src/cats/make_mysql_tables.in b/bacula/src/cats/make_mysql_tables.in index 541e2d8863..d0f7f3108d 100644 --- a/bacula/src/cats/make_mysql_tables.in +++ b/bacula/src/cats/make_mysql_tables.in @@ -92,21 +92,21 @@ CREATE TABLE Job ( Name TINYBLOB NOT NULL, Type BINARY(1) NOT NULL, Level BINARY(1) NOT NULL, - ClientId INTEGER NOT NULL REFERENCES Client, + ClientId INTEGER NOT NULL DEFAULT 0 REFERENCES Client, JobStatus BINARY(1) NOT NULL, SchedTime DATETIME NOT NULL, - StartTime DATETIME NOT NULL, - EndTime DATETIME NOT NULL, - RealEndTime DATETIME NOT NULL, + StartTime DATETIME NOT NULL DEFAULT 0, + EndTime DATETIME NOT NULL DEFAULT 0, + RealEndTime DATETIME NOT NULL DEFAULT 0, JobTDate BIGINT UNSIGNED NOT NULL, VolSessionId INTEGER UNSIGNED NOT NULL DEFAULT 0, VolSessionTime INTEGER UNSIGNED NOT NULL DEFAULT 0, JobFiles INTEGER UNSIGNED NOT NULL DEFAULT 0, - JobBytes BIGINT UNSIGNED NOT NULL, + JobBytes BIGINT UNSIGNED NOT NULL DEFAULT 0, JobErrors INTEGER UNSIGNED NOT NULL DEFAULT 0, JobMissingFiles INTEGER UNSIGNED NOT NULL DEFAULT 0, - PoolId INTEGER UNSIGNED NOT NULL REFERENCES Pool, - FileSetId INTEGER UNSIGNED NOT NULL REFERENCES FileSet, + PoolId INTEGER UNSIGNED NOT NULL DEFAULT 0 REFERENCES Pool, + FileSetId INTEGER UNSIGNED NOT NULL DEFAULT 0 REFERENCES FileSet, PriorJobId INTEGER UNSIGNED DEFAULT 0 REFERENCES Job, PurgedFiles TINYINT NOT NULL DEFAULT 0, HasBase TINYINT NOT NULL DEFAULT 0, @@ -157,9 +157,9 @@ CREATE TABLE Media ( MediaType TINYBLOB NOT NULL, MediaTypeId INTEGER UNSIGNED NOT NULL REFERENCES MediaType, LabelType TINYINT NOT NULL DEFAULT 0, - FirstWritten DATETIME NOT NULL, - LastWritten DATETIME NOT NULL, - LabelDate DATETIME NOT NULL, + FirstWritten DATETIME NOT NULL DEFAULT 0, + LastWritten DATETIME NOT NULL DEFAULT 0, + LabelDate DATETIME NOT NULL DEFAULT 0, VolJobs INTEGER UNSIGNED NOT NULL DEFAULT 0, VolFiles INTEGER UNSIGNED NOT NULL DEFAULT 0, VolBlocks INTEGER UNSIGNED NOT NULL DEFAULT 0, @@ -188,7 +188,7 @@ CREATE TABLE Media ( EndBlock INTEGER UNSIGNED NOT NULL DEFAULT 0, LocationId INTEGER UNSIGNED DEFAULT 0 REFERENCES Location, RecycleCount INTEGER UNSIGNED DEFAULT 0, - InitialWrite DATETIME NOT NULL, + InitialWrite DATETIME NOT NULL DEFAULT 0, ScratchPoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool, RecyclePoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool, PRIMARY KEY(MediaId), diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index fd3aa6d818..dcc84f7cb8 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -93,7 +93,7 @@ void db_list_job_totals(JCR *jcr, B_DB *db, JOB_DBR *jr, DB_LIST_HANDLER sendit, void db_list_files_for_job(JCR *jcr, B_DB *db, uint32_t jobid, DB_LIST_HANDLER sendit, void *ctx); void db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type); void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, JobId_t JobId, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type); -int db_list_sql_query(JCR *jcr, B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, void *ctx, int verbose, e_list_type type); +int db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query, DB_LIST_HANDLER *sendit, void *ctx, int verbose, e_list_type type); void db_list_client_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type); /* update.c */ diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index f42f2cd3d3..7b1cc909d7 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -71,8 +71,8 @@ db_create_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) stime = jr->SchedTime; ASSERT(stime != 0); - localtime_r(&stime, &tm); - strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm); + (void)localtime_r(&stime, &tm); + strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", &tm); JobTDate = (utime_t)stime; /* Must create it */ @@ -443,8 +443,8 @@ db_create_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) if (mr->LabelDate == 0) { mr->LabelDate = time(NULL); } - localtime_r(&mr->LabelDate, &tm); - strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm); + (void)localtime_r(&mr->LabelDate, &tm); + strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", &tm); Mmsg(mdb->cmd, "UPDATE Media SET LabelDate='%s' " "WHERE MediaId=%d", dt, mr->MediaId); stat = UPDATE_DB(jcr, mdb, mdb->cmd); @@ -615,8 +615,8 @@ bool db_create_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr) if (fsr->CreateTime == 0 && fsr->cCreateTime[0] == 0) { fsr->CreateTime = time(NULL); } - localtime_r(&fsr->CreateTime, &tm); - strftime(fsr->cCreateTime, sizeof(fsr->cCreateTime), "%Y-%m-%d %T", &tm); + (void)localtime_r(&fsr->CreateTime, &tm); + strftime(fsr->cCreateTime, sizeof(fsr->cCreateTime), "%Y-%m-%d %H:%M:%S", &tm); /* Must create it */ Mmsg(mdb->cmd, "INSERT INTO FileSet (FileSet,MD5,CreateTime) " diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index 4068dfbaec..0fcc2dabd5 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -407,6 +407,8 @@ int db_get_job_volume_parameters(JCR *jcr, B_DB *mdb, JobId_t JobId, VOL_PARAMS if (stat > 0) { *VolParams = Vols = (VOL_PARAMS *)malloc(stat * sizeof(VOL_PARAMS)); SId = (DBId_t *)malloc(stat * sizeof(DBId_t)); + } else { + SId = NULL; } for (i=0; i < stat; i++) { if ((row = sql_fetch_row(mdb)) == NULL) { diff --git a/bacula/src/cats/sql_list.c b/bacula/src/cats/sql_list.c index ff71728cc3..cbc9413738 100644 --- a/bacula/src/cats/sql_list.c +++ b/bacula/src/cats/sql_list.c @@ -45,7 +45,7 @@ extern int QueryDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_ /* * Submit general SQL query */ -int db_list_sql_query(JCR *jcr, B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, +int db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query, DB_LIST_HANDLER *sendit, void *ctx, int verbose, e_list_type type) { db_lock(mdb); diff --git a/bacula/src/cats/sql_update.c b/bacula/src/cats/sql_update.c index 736d94fb31..b276c671bd 100644 --- a/bacula/src/cats/sql_update.c +++ b/bacula/src/cats/sql_update.c @@ -96,7 +96,7 @@ db_update_job_start_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) char ed1[50], ed2[50], ed3[50], ed4[50]; stime = jr->StartTime; - localtime_r(&stime, &tm); + (void)localtime_r(&stime, &tm); strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", &tm); JobTDate = (btime_t)stime; @@ -157,14 +157,14 @@ db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) } ttime = jr->EndTime; - localtime_r(&ttime, &tm); + (void)localtime_r(&ttime, &tm); strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", &tm); if (jr->RealEndTime == 0) { jr->RealEndTime = jr->EndTime; } ttime = jr->RealEndTime; - localtime_r(&ttime, &tm); + (void)localtime_r(&ttime, &tm); strftime(rdt, sizeof(rdt), "%Y-%m-%d %H:%M:%S", &tm); JobTDate = ttime; @@ -178,7 +178,7 @@ db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) (char)(jr->JobStatus), dt, ClientId, edit_uint64(jr->JobBytes, ed1), jr->JobFiles, jr->JobErrors, jr->VolSessionId, jr->VolSessionTime, PoolId, FileSetId, edit_uint64(JobTDate, ed2), - rdt, + rdt, PriorJobId, edit_int64(jr->JobId, ed3)); @@ -312,7 +312,7 @@ db_update_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) if (mr->set_first_written) { Dmsg1(400, "Set FirstWritten Vol=%s\n", mr->VolumeName); ttime = mr->FirstWritten; - localtime_r(&ttime, &tm); + (void)localtime_r(&ttime, &tm); strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", &tm); Mmsg(mdb->cmd, "UPDATE Media SET FirstWritten='%s'" " WHERE VolumeName='%s'", dt, mr->VolumeName); @@ -326,7 +326,7 @@ db_update_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) if (ttime == 0) { ttime = time(NULL); } - localtime_r(&ttime, &tm); + (void)localtime_r(&ttime, &tm); strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", &tm); Mmsg(mdb->cmd, "UPDATE Media SET LabelDate='%s' " "WHERE VolumeName='%s'", dt, mr->VolumeName); @@ -335,7 +335,7 @@ db_update_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) if (mr->LastWritten != 0) { ttime = mr->LastWritten; - localtime_r(&ttime, &tm); + (void)localtime_r(&ttime, &tm); strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", &tm); Mmsg(mdb->cmd, "UPDATE Media Set LastWritten='%s' " "WHERE VolumeName='%s'", dt, mr->VolumeName); diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index 38a12f89ca..b4392f2b06 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -44,11 +44,7 @@ /* Exported variables */ -#ifdef HAVE_CYGWIN -int rl_catch_signals; -#else extern int rl_catch_signals; -#endif #ifdef HAVE_MINGW /* Remove when we have real lib in src/lib */ int enable_vss; @@ -383,9 +379,9 @@ int main(int argc, char *argv[]) init_signals(terminate_console); } + #if !defined(HAVE_WIN32) /* Override Bacula default signals */ -// signal(SIGCHLD, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGTSTP, got_sigstop); signal(SIGCONT, got_sigcontinue); @@ -533,7 +529,7 @@ try_again: FILE *fd; pm_strcpy(&UA_sock->msg, env); pm_strcat(&UA_sock->msg, "/.bconsolerc"); - fd = fopen(UA_sock->msg, "r"); + fd = fopen(UA_sock->msg, "rb"); if (fd) { read_and_process_input(fd, UA_sock); fclose(fd); @@ -780,7 +776,7 @@ static int inputcmd(FILE *input, BSOCK *UA_sock) sendit(_("First argument to input command must be a filename.\n")); return 1; } - fd = fopen(argk[1], "r"); + fd = fopen(argk[1], "rb"); if (!fd) { senditf(_("Cannot open file %s for input. ERR=%s\n"), argk[1], strerror(errno)); @@ -809,7 +805,7 @@ static int outputcmd(FILE *input, BSOCK *UA_sock) static int do_outputcmd(FILE *input, BSOCK *UA_sock) { FILE *fd; - const char *mode = "a+"; + const char *mode = "a+b"; if (argc > 3) { sendit(_("Too many arguments on output/tee command.\n")); @@ -855,7 +851,7 @@ static int timecmd(FILE *input, BSOCK *UA_sock) char sdt[50]; time_t ttime = time(NULL); struct tm tm; - localtime_r(&ttime, &tm); + (void)localtime_r(&ttime, &tm); strftime(sdt, sizeof(sdt), "%d-%b-%Y %H:%M:%S", &tm); sendit("\n"); return 1; diff --git a/bacula/src/console/console_conf.c b/bacula/src/console/console_conf.c index 8112adfac3..0336a957cb 100644 --- a/bacula/src/console/console_conf.c +++ b/bacula/src/console/console_conf.c @@ -54,15 +54,14 @@ RES **res_head = sres_head; * then move it to allocated memory when the resource * scan is complete. */ -#if defined(HAVE_WIN32) && !defined(HAVE_CYGWIN) && !defined(HAVE_MINGW) +#if defined(_MSC_VER) extern "C" { // work around visual compiler mangling variables URES res_all; - int res_all_size = sizeof(res_all); } #else URES res_all; -int res_all_size = sizeof(res_all); #endif +int res_all_size = sizeof(res_all); /* Definition of records permitted within each * resource with the routine to process the record diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index fe7cbc292c..ef845c7233 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -499,7 +499,7 @@ void update_bootstrap_file(JCR *jcr) fd = bpipe ? bpipe->wfd : NULL; } else { /* ***FIXME*** handle BASE */ - fd = fopen(fname, jcr->JobLevel==L_FULL?"w+":"a+"); + fd = fopen(fname, jcr->JobLevel==L_FULL?"w+b":"a+b"); } if (fd) { VolCount = db_get_job_volume_parameters(jcr, jcr->db, jcr->JobId, diff --git a/bacula/src/dird/bsr.c b/bacula/src/dird/bsr.c index 2b2e77526e..ae4317c452 100644 --- a/bacula/src/dird/bsr.c +++ b/bacula/src/dird/bsr.c @@ -227,7 +227,7 @@ uint32_t write_bsr_file(UAContext *ua, RESTORE_CTX &rx) JobId_t JobId; make_unique_restore_filename(ua, &fname); - fd = fopen(fname, "w+"); + fd = fopen(fname, "w+b"); if (!fd) { berrno be; bsendmsg(ua, _("Unable to create bootstrap file %s. ERR=%s\n"), diff --git a/bacula/src/dird/catreq.c b/bacula/src/dird/catreq.c index 02514e8d49..f40b39a41a 100644 --- a/bacula/src/dird/catreq.c +++ b/bacula/src/dird/catreq.c @@ -415,7 +415,7 @@ void catalog_update(JCR *jcr, BSOCK *bs) Jmsg(jcr, M_WARNING, 0, _("Got %s but not same File as attributes\n"), stream_to_ascii(Stream)); } else { /* Update digest in catalog */ - char digestbuf[CRYPTO_DIGEST_MAX_SIZE]; + char digestbuf[BASE64_SIZE(CRYPTO_DIGEST_MAX_SIZE)]; int len = 0; int type = CRYPTO_DIGEST_NONE; diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index a5f65266e8..26af749a6a 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -60,8 +60,14 @@ extern int r_first, r_last; /* first and last resources */ extern RES_TABLE resources[]; extern RES **res_head; extern RES_ITEM job_items[]; -extern URES res_all; +#if defined(_MSC_VER) +extern "C" { // work around visual compiler mangling variables + extern URES res_all; +} +#else +extern URES res_all; +#endif #define CONFIG_FILE "./bacula-dir.conf" /* default configuration file */ @@ -250,6 +256,8 @@ int main (int argc, char *argv[]) } terminate_dird(0); + + return 0; } /* Cleanup and then exit */ diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index 9eedba0e6f..e7ba378dd4 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -72,7 +72,13 @@ static void store_short_runscript(LEX *lc, RES_ITEM *item, int index, int pass); * then move it to allocated memory when the resource * scan is complete. */ +#if defined(_MSC_VER) +extern "C" { // work around visual compiler mangling variables + URES res_all; +} +#else URES res_all; +#endif int res_all_size = sizeof(res_all); diff --git a/bacula/src/dird/dird_conf.h b/bacula/src/dird/dird_conf.h index f6a80fea97..56efa2fb2d 100644 --- a/bacula/src/dird/dird_conf.h +++ b/bacula/src/dird/dird_conf.h @@ -77,13 +77,13 @@ struct s_jt { /* Definition of the contents of each Resource */ /* Needed for forward references */ -struct SCHED; -struct CLIENT; -struct FILESET; -struct POOL; -struct RUN; -struct DEVICE; -struct RUNSCRIPT; +class SCHED; +class CLIENT; +class FILESET; +class POOL; +class RUN; +class DEVICE; +class RUNSCRIPT; /* * Director Resource diff --git a/bacula/src/dird/expand.c b/bacula/src/dird/expand.c index f7d9167b7b..3a41434215 100644 --- a/bacula/src/dird/expand.c +++ b/bacula/src/dird/expand.c @@ -37,7 +37,7 @@ static int date_item(JCR *jcr, int code, { struct tm tm; time_t now = time(NULL); - localtime_r(&now, &tm); + (void)localtime_r(&now, &tm); int val = 0; char buf[10]; diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index febd1873d8..3d884f4663 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -341,7 +341,7 @@ static bool send_fileset(JCR *jcr) break; case '<': p++; /* skip over < */ - if ((ffd = fopen(p, "r")) == NULL) { + if ((ffd = fopen(p, "rb")) == NULL) { berrno be; Jmsg(jcr, M_FATAL, 0, _("Cannot open included file: %s. ERR=%s\n"), p, be.strerror()); @@ -435,7 +435,7 @@ bool send_bootstrap_file(JCR *jcr, BSOCK *sock) if (!jcr->RestoreBootstrap) { return true; } - bs = fopen(jcr->RestoreBootstrap, "r"); + bs = fopen(jcr->RestoreBootstrap, "rb"); if (!bs) { berrno be; Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"), diff --git a/bacula/src/dird/inc_conf.c b/bacula/src/dird/inc_conf.c index dff8eae194..3b5e0d8d52 100644 --- a/bacula/src/dird/inc_conf.c +++ b/bacula/src/dird/inc_conf.c @@ -51,7 +51,13 @@ static void setup_current_opts(void); * then move it to allocated memory when the resource * scan is complete. */ +#if defined(_MSC_VER) +extern "C" { // work around visual compiler mangling variables + extern URES res_all; +} +#else extern URES res_all; +#endif extern int res_all_size; /* We build the current new Include and Exclude items here */ @@ -246,7 +252,7 @@ static void scan_include_options(LEX *lc, int keyword, char *opts, int optlen) */ } else { for (i=0; FS_options[i].name; i++) { - if (strcasecmp(lc->str, FS_options[i].name) == 0 && FS_options[i].keyword == keyword) { + if (FS_options[i].keyword == keyword && strcasecmp(lc->str, FS_options[i].name) == 0) { /* NOTE! maximum 2 letters here or increase option[3] */ option[0] = FS_options[i].option[0]; option[1] = FS_options[i].option[1]; diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 09499daa3e..984f932041 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -771,7 +771,7 @@ void create_unique_job_name(JCR *jcr, const char *base_name) V(mutex); /* allow creation of jobs */ jcr->start_time = now; /* Form Unique JobName */ - localtime_r(&now, &tm); + (void)localtime_r(&now, &tm); /* Use only characters that are permitted in Windows filenames */ strftime(dt, sizeof(dt), "%Y-%m-%d_%H.%M.%S", &tm); bstrncpy(name, base_name, sizeof(name)); diff --git a/bacula/src/dird/run_conf.c b/bacula/src/dird/run_conf.c index 44337d50fb..b7eb4896d0 100644 --- a/bacula/src/dird/run_conf.c +++ b/bacula/src/dird/run_conf.c @@ -25,7 +25,13 @@ #include "bacula.h" #include "dird.h" +#if defined(_MSC_VER) +extern "C" { // work around visual compiler mangling variables + extern URES res_all; +} +#else extern URES res_all; +#endif extern struct s_jl joblevels[]; /* Forward referenced subroutines */ diff --git a/bacula/src/dird/scheduler.c b/bacula/src/dird/scheduler.c index 498bef71f7..ada34c437a 100644 --- a/bacula/src/dird/scheduler.c +++ b/bacula/src/dird/scheduler.c @@ -259,7 +259,7 @@ static void find_runs() /* compute values for time now */ now = time(NULL); - localtime_r(&now, &tm); + (void)localtime_r(&now, &tm); hour = tm.tm_hour; minute = tm.tm_min; mday = tm.tm_mday - 1; @@ -274,7 +274,7 @@ static void find_runs() * sleeping. */ next_hour = now + 3600; - localtime_r(&next_hour, &tm); + (void)localtime_r(&next_hour, &tm); nh_hour = tm.tm_hour; nh_mday = tm.tm_mday - 1; nh_wday = tm.tm_wday; @@ -336,7 +336,7 @@ static void find_runs() Dmsg3(dbglvl, "run@%p: run_now=%d run_nh=%d\n", run, run_now, run_nh); /* find time (time_t) job is to be run */ - localtime_r(&now, &tm); /* reset tm structure */ + (void)localtime_r(&now, &tm); /* reset tm structure */ tm.tm_min = run->minute; /* set run minute */ tm.tm_sec = 0; /* zero secs */ if (run_now) { diff --git a/bacula/src/dird/sql_cmds.c b/bacula/src/dird/sql_cmds.c index a5291a751c..de34bead73 100644 --- a/bacula/src/dird/sql_cmds.c +++ b/bacula/src/dird/sql_cmds.c @@ -69,14 +69,13 @@ const char *drop_deltabs[] = { /* List of SQL commands to create temp table and indicies */ const char *create_deltabs[] = { "CREATE TEMPORARY TABLE DelCandidates (" -#ifdef HAVE_MYSQL +#if defined(HAVE_MYSQL) "JobId INTEGER UNSIGNED NOT NULL, " "PurgedFiles TINYINT, " "FileSetId INTEGER UNSIGNED, " "JobFiles INTEGER UNSIGNED, " "JobStatus BINARY(1))", -#else -#ifdef HAVE_POSTGRESQL +#elif defined(HAVE_POSTGRESQL) "JobId INTEGER NOT NULL, " "PurgedFiles SMALLINT, " "FileSetId INTEGER, " @@ -88,7 +87,6 @@ const char *create_deltabs[] = { "FileSetId INTEGER UNSIGNED, " "JobFiles INTEGER UNSIGNED, " "JobStatus CHAR)", -#endif #endif "CREATE INDEX DelInx1 ON DelCandidates (JobId)", NULL}; @@ -194,7 +192,7 @@ const char *uar_file = "AND Job.JobId=File.JobId " "AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId " "AND Filename.Name='%s' ORDER BY StartTime DESC LIMIT 20"; - #endif +#endif /* diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 9b19f765c7..7e71408bb4 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -1084,7 +1084,7 @@ static int time_cmd(UAContext *ua, const char *cmd) char sdt[50]; time_t ttime = time(NULL); struct tm tm; - localtime_r(&ttime, &tm); + (void)localtime_r(&ttime, &tm); strftime(sdt, sizeof(sdt), "%d-%b-%Y %H:%M:%S", &tm); bsendmsg(ua, "%s\n", sdt); return 1; diff --git a/bacula/src/dird/ua_output.c b/bacula/src/dird/ua_output.c index d53d41ad11..a738dfe326 100644 --- a/bacula/src/dird/ua_output.c +++ b/bacula/src/dird/ua_output.c @@ -537,7 +537,7 @@ RUN *find_next_run(RUN *run, JOB *job, time_t &runtime, int ndays) future = now + (day * 60 * 60 * 24); /* Break down the time into components */ - localtime_r(&future, &tm); + (void)localtime_r(&future, &tm); mday = tm.tm_mday - 1; wday = tm.tm_wday; month = tm.tm_mon; @@ -571,7 +571,7 @@ RUN *find_next_run(RUN *run, JOB *job, time_t &runtime, int ndays) Dmsg1(000, "%s", buf); #endif /* find time (time_t) job is to be run */ - localtime_r(&future, &runtm); + (void)localtime_r(&future, &runtm); for (i= 0; i < 24; i++) { if (bit_is_set(i, run->hour)) { runtm.tm_hour = i; diff --git a/bacula/src/dird/ua_prune.c b/bacula/src/dird/ua_prune.c index e6d65dd512..bfbaf8f748 100644 --- a/bacula/src/dird/ua_prune.c +++ b/bacula/src/dird/ua_prune.c @@ -33,23 +33,23 @@ #define MAX_DEL_LIST_LEN 2000000 /* Imported variables */ -extern char *select_job; -extern char *drop_deltabs[]; -extern char *create_deltabs[]; -extern char *insert_delcand; -extern char *select_backup_del; -extern char *select_verify_del; -extern char *select_restore_del; -extern char *select_admin_del; -extern char *cnt_File; -extern char *del_File; -extern char *upd_Purged; -extern char *cnt_DelCand; -extern char *del_Job; -extern char *del_MAC; -extern char *del_JobMedia; -extern char *cnt_JobMedia; -extern char *sel_JobMedia; +extern const char *select_job; +extern const char *drop_deltabs[]; +extern const char *create_deltabs[]; +extern const char *insert_delcand; +extern const char *select_backup_del; +extern const char *select_verify_del; +extern const char *select_restore_del; +extern const char *select_admin_del; +extern const char *cnt_File; +extern const char *del_File; +extern const char *upd_Purged; +extern const char *cnt_DelCand; +extern const char *del_Job; +extern const char *del_MAC; +extern const char *del_JobMedia; +extern const char *cnt_JobMedia; +extern const char *sel_JobMedia; /* In memory list of JobIds */ diff --git a/bacula/src/dird/ua_query.c b/bacula/src/dird/ua_query.c index ba8cd81534..6e1a3c2b84 100644 --- a/bacula/src/dird/ua_query.c +++ b/bacula/src/dird/ua_query.c @@ -55,7 +55,7 @@ int querycmd(UAContext *ua, const char *cmd) if (!open_db(ua)) { goto bail_out; } - if ((fd=fopen(query_file, "r")) == NULL) { + if ((fd=fopen(query_file, "rb")) == NULL) { bsendmsg(ua, _("Could not open %s: ERR=%s\n"), query_file, strerror(errno)); goto bail_out; diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index a625da14c9..78889be8ff 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -36,15 +36,15 @@ extern void print_bsr(UAContext *ua, RBSR *bsr); /* Imported variables */ -extern char *uar_list_jobs, *uar_file, *uar_sel_files; -extern char *uar_del_temp, *uar_del_temp1, *uar_create_temp; -extern char *uar_create_temp1, *uar_last_full, *uar_full; -extern char *uar_inc, *uar_list_temp, *uar_sel_jobid_temp; -extern char *uar_sel_all_temp1, *uar_sel_fileset, *uar_mediatype; -extern char *uar_jobid_fileindex, *uar_dif, *uar_sel_all_temp; -extern char *uar_count_files, *uar_jobids_fileindex; -extern char *uar_jobid_fileindex_from_dir; -extern char *uar_jobid_fileindex_from_table; +extern const char *uar_list_jobs, *uar_file, *uar_sel_files; +extern const char *uar_del_temp, *uar_del_temp1, *uar_create_temp; +extern const char *uar_create_temp1, *uar_last_full, *uar_full; +extern const char *uar_inc, *uar_list_temp, *uar_sel_jobid_temp; +extern const char *uar_sel_all_temp1, *uar_sel_fileset, *uar_mediatype; +extern const char *uar_jobid_fileindex, *uar_dif, *uar_sel_all_temp; +extern const char *uar_count_files, *uar_jobids_fileindex; +extern const char *uar_jobid_fileindex_from_dir; +extern const char *uar_jobid_fileindex_from_table; @@ -276,7 +276,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) char date[MAX_TIME_LENGTH]; bool have_date = false; JobId_t JobId; - JOB_DBR jr; + JOB_DBR jr = { (JobId_t)-1 }; bool done = false; int i, j; const char *list[] = { @@ -678,7 +678,7 @@ static void insert_one_file_or_dir(UAContext *ua, RESTORE_CTX *rx, char *date, b switch (*p) { case '<': p++; - if ((ffd = fopen(p, "r")) == NULL) { + if ((ffd = fopen(p, "rb")) == NULL) { berrno be; bsendmsg(ua, _("Cannot open file %s: ERR=%s\n"), p, be.strerror()); diff --git a/bacula/src/dird/ua_run.c b/bacula/src/dird/ua_run.c index 52315f6976..5aa292d101 100644 --- a/bacula/src/dird/ua_run.c +++ b/bacula/src/dird/ua_run.c @@ -866,7 +866,7 @@ try_again: } if (ua->cmd[0] != 0) { jcr->RestoreBootstrap = bstrdup(ua->cmd); - fd = fopen(jcr->RestoreBootstrap, "r"); + fd = fopen(jcr->RestoreBootstrap, "rb"); if (!fd) { bsendmsg(ua, _("Warning cannot open %s: ERR=%s\n"), jcr->RestoreBootstrap, strerror(errno)); diff --git a/bacula/src/dird/ua_update.c b/bacula/src/dird/ua_update.c index ccf7db8916..75a1a3489d 100644 --- a/bacula/src/dird/ua_update.c +++ b/bacula/src/dird/ua_update.c @@ -26,7 +26,7 @@ #include "dird.h" /* External variables */ -extern char *list_pool; /* in sql_cmds.c */ +extern const char *list_pool; /* in sql_cmds.c */ /* Imported functions */ void update_slots(UAContext *ua); diff --git a/bacula/src/filed/estimate.c b/bacula/src/filed/estimate.c index 1651f2d457..ccf2e660f3 100644 --- a/bacula/src/filed/estimate.c +++ b/bacula/src/filed/estimate.c @@ -67,6 +67,7 @@ static int tally_file(FF_PKT *ff_pkt, void *ijcr, bool top_level) case FT_NORECURSE: case FT_NOFSCHG: case FT_INVALIDFS: + case FT_INVALIDDT: case FT_DIREND: case FT_SPEC: case FT_RAW: diff --git a/bacula/src/filed/filed.c b/bacula/src/filed/filed.c index ae021bbf2c..5145735a1c 100644 --- a/bacula/src/filed/filed.c +++ b/bacula/src/filed/filed.c @@ -74,7 +74,7 @@ static void usage() * Main Bacula Unix Client Program * */ -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) #define main BaculaMain #endif diff --git a/bacula/src/filed/filed_conf.c b/bacula/src/filed/filed_conf.c index e20709827d..f06d921eff 100644 --- a/bacula/src/filed/filed_conf.c +++ b/bacula/src/filed/filed_conf.c @@ -57,15 +57,14 @@ RES **res_head = sres_head; * then move it to allocated memory when the resource * scan is complete. */ -#if defined(HAVE_WIN32) && !defined(HAVE_CYGWIN) +#if defined(_MSC_VER) extern "C" { // work around visual compiler mangling variables URES res_all; - int res_all_size = sizeof(res_all); } #else URES res_all; -int res_all_size = sizeof(res_all); #endif +int res_all_size = sizeof(res_all); /* Definition of records permitted within each * resource with the routine to process the record diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 1e6835c780..96365bff36 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -338,9 +338,7 @@ static int cancel_cmd(JCR *jcr) if (cjcr->store_bsock) { cjcr->store_bsock->timed_out = 1; cjcr->store_bsock->terminated = 1; -#if !defined(HAVE_CYGWIN) pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL); -#endif } set_jcr_job_status(cjcr, JS_Canceled); free_jcr(cjcr); @@ -400,7 +398,7 @@ static int job_cmd(JCR *jcr) { BSOCK *dir = jcr->dir_bsock; POOLMEM *sd_auth_key; - + sd_auth_key = get_memory(dir->msglen); if (sscanf(dir->msg, jobcmd, &jcr->JobId, jcr->Job, &jcr->VolSessionId, &jcr->VolSessionTime, @@ -604,7 +602,7 @@ static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *filese case '<': Dmsg0(100, "Doing < include on client.\n"); p++; /* skip over < */ - if ((ffd = fopen(p, "r")) == NULL) { + if ((ffd = fopen(p, "rb")) == NULL) { berrno be; Jmsg(jcr, M_FATAL, 0, _("Cannot open FileSet input file: %s. ERR=%s\n"), p, be.strerror()); @@ -1011,7 +1009,7 @@ static int bootstrap_cmd(JCR *jcr) jcr->Job); Dmsg1(400, "bootstrap=%s\n", fname); jcr->RestoreBootstrap = fname; - bs = fopen(fname, "a+"); /* create file */ + bs = fopen(fname, "a+b"); /* create file */ if (!bs) { berrno be; Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"), @@ -1695,7 +1693,7 @@ static int send_bootstrap_file(JCR *jcr) if (!jcr->RestoreBootstrap) { return 1; } - bs = fopen(jcr->RestoreBootstrap, "r"); + bs = fopen(jcr->RestoreBootstrap, "rb"); if (!bs) { berrno be; Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"), diff --git a/bacula/src/filed/status.c b/bacula/src/filed/status.c index e96060aead..2c90d7a0a9 100755 --- a/bacula/src/filed/status.c +++ b/bacula/src/filed/status.c @@ -40,7 +40,7 @@ static char qstatus[] = ".status %s\n"; static char OKqstatus[] = "2000 OK .status\n"; static char DotStatusJob[] = "JobId=%d JobStatus=%c JobErrors=%d\n"; -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) static int privs = 0; #endif #ifdef WIN32_VSS @@ -71,7 +71,7 @@ static void do_status(void sendit(const char *msg, int len, void *sarg), void *a len = Mmsg(msg, _("Daemon started %s, %d Job%s run since started.\n"), dt, num_jobs_run, num_jobs_run == 1 ? "" : "s"); sendit(msg, len, arg); -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) if (debug_level > 0) { if (!privs) { privs = enable_backup_privileges(NULL, 1); @@ -402,7 +402,7 @@ static const char *level_to_str(int level) } -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) #include int bacstat = 0; @@ -493,4 +493,4 @@ done: return buf; } -#endif /* HAVE_CYGWIN */ +#endif /* HAVE_WIN32 */ diff --git a/bacula/src/findlib/attribs.c b/bacula/src/findlib/attribs.c index 3988eae7aa..fdf0c67322 100755 --- a/bacula/src/findlib/attribs.c +++ b/bacula/src/findlib/attribs.c @@ -26,7 +26,7 @@ #include "bacula.h" #include "find.h" -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) #include "../lib/winapi.h" @@ -36,7 +36,7 @@ static bool set_win32_attributes(JCR *jcr, ATTR *attr, BFILE *ofd); void unix_name_to_win32(POOLMEM **win32_name, char *name); void win_error(JCR *jcr, char *prefix, POOLMEM *ofile); HANDLE bget_handle(BFILE *bfd); -#endif +#endif /* HAVE_WIN32 */ /* For old systems that don't have lchown() use chown() */ #ifndef HAVE_LCHOWN @@ -219,6 +219,7 @@ void encode_stat(char *buf, FF_PKT *ff_pkt, int data_stream) #endif #endif + /* Decode a stat packet from base64 characters */ int decode_stat(char *buf, struct stat *statp, int32_t *LinkFI) { @@ -362,7 +363,7 @@ bool set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd) bool ok = true; off_t fsize; -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) if (attr->stream == STREAM_UNIX_ATTRIBUTES_EX && set_win32_attributes(jcr, attr, ofd)) { if (is_bopen(ofd)) { @@ -467,7 +468,7 @@ bool set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd) /* */ /*=============================================================*/ -#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) +#if !defined(HAVE_WIN32) /* * It is possible to piggyback additional data e.g. ACLs on @@ -507,7 +508,7 @@ int encode_attribsEx(JCR *jcr, char *attribsEx, FF_PKT *ff_pkt) /* */ /*=============================================================*/ -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) int encode_attribsEx(JCR *jcr, char *attribsEx, FF_PKT *ff_pkt) { @@ -726,4 +727,4 @@ void unix_name_to_win32(POOLMEM **win32_name, char *name) conv_unix_to_win32_path(name, *win32_name, dwSize); } -#endif /* HAVE_CYGWIN */ +#endif /* HAVE_WIN32 */ diff --git a/bacula/src/findlib/bfile.c b/bacula/src/findlib/bfile.c index 21ea1705bd..8f930ed5d2 100644 --- a/bacula/src/findlib/bfile.c +++ b/bacula/src/findlib/bfile.c @@ -253,7 +253,7 @@ bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize) * =============================================================== */ -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) void unix_name_to_win32(POOLMEM **win32_name, char *name); extern "C" HANDLE get_osfhandle(int fd); diff --git a/bacula/src/findlib/bfile.h b/bacula/src/findlib/bfile.h index 46b58cc1c7..69cce6fb68 100644 --- a/bacula/src/findlib/bfile.h +++ b/bacula/src/findlib/bfile.h @@ -64,7 +64,7 @@ typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT { * * ======================================================= */ -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) #include #include "../lib/winapi.h" @@ -79,7 +79,7 @@ enum { /* Basic Win32 low level I/O file packet */ struct BFILE { - int use_backup_api; /* set if using BackupRead/Write */ + bool use_backup_api; /* set if using BackupRead/Write */ int mode; /* set if file is open */ HANDLE fh; /* Win32 file handle */ int fid; /* fd if doing Unix style */ diff --git a/bacula/src/findlib/drivetype.c b/bacula/src/findlib/drivetype.c new file mode 100644 index 0000000000..a12fef363b --- /dev/null +++ b/bacula/src/findlib/drivetype.c @@ -0,0 +1,116 @@ +/* + * Implement routines to determine drive type (Windows specific). + * + * Written by Robert Nelson, June 2006 + * + * Version $Id$ + */ + +/* + Copyright (C) 2006 Kern Sibbald + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. + + */ + +#ifndef TEST_PROGRAM + +#include "bacula.h" +#include "find.h" + +#else /* Set up for testing a stand alone program */ + +#include +#include +#include +#define SUPPORTEDOSES \ + "HAVE_WIN32\n" +#define false 0 +#define true 1 +#define bstrncpy strncpy +#define Dmsg0(n,s) fprintf(stderr, s) +#define Dmsg1(n,s,a1) fprintf(stderr, s, a1) +#define Dmsg2(n,s,a1,a2) fprintf(stderr, s, a1, a2) +#endif + +/* + * These functions should be implemented for each OS + * + * bool drivetype(const char *fname, char *dt, int dtlen); + */ + +#if defined (HAVE_WIN32) +/* Windows */ + +bool drivetype(const char *fname, char *dt, int dtlen) +{ + CHAR rootpath[4]; + UINT type; + + /* Copy Drive Letter, colon, and backslash to rootpath */ + bstrncpy(rootpath, fname, 3); + rootpath[3] = '\0'; + + type = GetDriveType(rootpath); + + switch (type) { + case DRIVE_REMOVABLE: bstrncpy(dt, "removable", dtlen); return true; + case DRIVE_FIXED: bstrncpy(dt, "fixed", dtlen); return true; + case DRIVE_REMOTE: bstrncpy(dt, "remote", dtlen); return true; + case DRIVE_CDROM: bstrncpy(dt, "cdrom", dtlen); return true; + case DRIVE_RAMDISK: bstrncpy(dt, "ramdisk", dtlen); return true; + case DRIVE_UNKNOWN: + case DRIVE_NO_ROOT_DIR: + default: + return false; + } +} +/* Windows */ + +#else /* No recognised OS */ + +bool drivetype(const char *fname, char *dt, int dtlen) +{ + Dmsg0(10, "!!! drivetype() not implemented for this OS. !!!\n"); +#ifdef TEST_PROGRAM + Dmsg1(10, "Please define one of the following when compiling:\n\n%s\n", + SUPPORTEDOSES); + exit(EXIT_FAILURE); +#endif + + return false; +} +#endif + +#ifdef TEST_PROGRAM +int main(int argc, char **argv) +{ + char *p; + char dt[1000]; + int status = 0; + + if (argc < 2) { + p = (argc < 1) ? "drivetype" : argv[0]; + printf("usage:\t%s path ...\n" + "\t%s prints the drive type and pathname of the paths.\n", + p, p); + return EXIT_FAILURE; + } + while (*++argv) { + if (!drivetype(*argv, dt, sizeof(dt))) { + status = EXIT_FAILURE; + } else { + printf("%s\t%s\n", dt, *argv); + } + } + return status; +} +#endif diff --git a/bacula/src/findlib/enable_priv.c b/bacula/src/findlib/enable_priv.c index 8fd78fbd9c..34539eb8eb 100755 --- a/bacula/src/findlib/enable_priv.c +++ b/bacula/src/findlib/enable_priv.c @@ -37,7 +37,7 @@ /* */ /*=============================================================*/ -#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) +#if !defined(HAVE_WIN32) int enable_backup_privileges(JCR *jcr, int ignore_errors) { return 0; } @@ -53,7 +53,7 @@ int enable_backup_privileges(JCR *jcr, int ignore_errors) /* */ /*=============================================================*/ -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) void win_error(JCR *jcr, char *prefix, DWORD lerror); @@ -155,4 +155,4 @@ int enable_backup_privileges(JCR *jcr, int ignore_errors) return stat; } -#endif /* HAVE_CYGWIN */ +#endif /* HAVE_WIN32 */ diff --git a/bacula/src/findlib/find.c b/bacula/src/findlib/find.c index 1565234489..8fde075a35 100644 --- a/bacula/src/findlib/find.c +++ b/bacula/src/findlib/find.c @@ -97,7 +97,7 @@ get_win32_driveletters(FF_PKT *ff, char* szDrives) { /* szDrives must be at least 27 bytes long */ -#ifndef WIN32 +#if !defined(HAVE_WIN32) return 0; #endif @@ -209,9 +209,9 @@ static bool accept_file(FF_PKT *ff) if (ff->flags & FO_EXCLUDE) { Dmsg2(100, "Exclude wilddir: %s file=%s\n", (char *)fo->wilddir.get(k), ff->fname); - return false; /* reject file */ + return false; /* reject dir */ } - return true; /* accept file */ + return true; /* accept dir */ } } } else { @@ -325,6 +325,7 @@ static int our_callback(FF_PKT *ff, void *hpkt, bool top_level) case FT_NORECURSE: case FT_NOFSCHG: case FT_INVALIDFS: + case FT_INVALIDDT: case FT_NOOPEN: // return ff->callback(ff, hpkt, top_level); diff --git a/bacula/src/findlib/makepath.c b/bacula/src/findlib/makepath.c index 11eb9f804e..70e7feaf4c 100644 --- a/bacula/src/findlib/makepath.c +++ b/bacula/src/findlib/makepath.c @@ -136,7 +136,7 @@ make_dir(JCR *jcr, const char *dir, const char *dirpath, mode_t mode, int *creat int isAbsolute(const char *path) { -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) return path[1] == ':' || *path == '/' || *path == '\\'; /* drivespec:/blah is absolute */ #else return *path == '/'; @@ -213,12 +213,6 @@ make_path( re_protect = 0; } -#if defined(HAVE_CYGWIN) - /* Because of silly Win32 security, we allow everything */ - tmp_mode = S_IRWXUGO; - re_protect = 0; - -#endif #if defined(HAVE_WIN32) // chdir can fail if permissions are sufficiently restricted since I don't think // backup/restore security rights affect ChangeWorkingDirectory diff --git a/bacula/src/findlib/match.c b/bacula/src/findlib/match.c index a5d9d8f713..4c239840a9 100644 --- a/bacula/src/findlib/match.c +++ b/bacula/src/findlib/match.c @@ -39,7 +39,7 @@ #endif /* Fold case in fnmatch() on Win32 */ -#ifdef WIN32 +#ifdef HAVE_WIN32 static const int fnmode = FNM_CASEFOLD; #else static const int fnmode = 0; @@ -213,7 +213,7 @@ void add_fname_to_include_list(FF_PKT *ff, int prefixed, const char *fname) break; } } -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) /* Convert any \'s into /'s */ for (p=inc->fname; *p; p++) { if (*p == '\\') { @@ -247,7 +247,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_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) if (strchr(fname, '/') || strchr(fname, '\\')) { #else if (strchr(fname, '/')) { @@ -263,7 +263,7 @@ void add_fname_to_exclude_list(FF_PKT *ff, const char *fname) exc->next = *list; exc->len = len; strcpy(exc->fname, fname); -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) /* Convert any \'s into /'s */ for (char *p=exc->fname; *p; p++) { if (*p == '\\') { diff --git a/bacula/src/lib/base64.c b/bacula/src/lib/base64.c index d81b00cd18..19e83ce49d 100644 --- a/bacula/src/lib/base64.c +++ b/bacula/src/lib/base64.c @@ -157,7 +157,7 @@ bin_to_base64(char *buf, char *bin, int len) } save = reg; reg >>= (rem - 6); - buf[j++] = base64_digits[reg & (uint32_t)0x3F]; + buf[j++] = base64_digits[reg & 0x3F]; reg = save; rem -= 6; } diff --git a/bacula/src/lib/berrno.c b/bacula/src/lib/berrno.c index 03b4eb381a..76641fd49b 100644 --- a/bacula/src/lib/berrno.c +++ b/bacula/src/lib/berrno.c @@ -36,12 +36,13 @@ extern int execvp_errors[]; const char *berrno::strerror() { - int stat = 0; #ifdef HAVE_WIN32 if (berrno_ & b_errno_win32) { return (const char *)buf_; } #else + int stat = 0; + if (berrno_ & b_errno_exit) { stat = (berrno_ & ~b_errno_exit); /* remove bit */ if (stat == 0) { diff --git a/bacula/src/lib/bnet.c b/bacula/src/lib/bnet.c index eb58d956b4..7ebaecd940 100644 --- a/bacula/src/lib/bnet.c +++ b/bacula/src/lib/bnet.c @@ -1003,7 +1003,7 @@ bool bnet_set_buffer_size(BSOCK * bs, uint32_t size, int rw) * Returns previous socket flag */ int bnet_set_nonblocking (BSOCK *bsock) { -#ifndef WIN32 +#ifndef HAVE_WIN32 int oflags; /* Get current flags */ @@ -1038,7 +1038,7 @@ int bnet_set_nonblocking (BSOCK *bsock) { */ int bnet_set_blocking (BSOCK *bsock) { -#ifndef WIN32 +#ifndef HAVE_WIN32 int oflags; /* Get current flags */ if ((oflags = fcntl(bsock->fd, F_GETFL, 0)) < 0) { @@ -1071,7 +1071,7 @@ int bnet_set_blocking (BSOCK *bsock) */ void bnet_restore_blocking (BSOCK *bsock, int flags) { -#ifndef WIN32 +#ifndef HAVE_WIN32 if ((fcntl(bsock->fd, F_SETFL, flags)) < 0) { berrno be; Jmsg1(bsock->jcr, M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.strerror()); diff --git a/bacula/src/lib/bpipe.c b/bacula/src/lib/bpipe.c index a28f3650b3..12a5d8b925 100644 --- a/bacula/src/lib/bpipe.c +++ b/bacula/src/lib/bpipe.c @@ -32,7 +32,7 @@ int execvp_errors[] = { E2BIG, ENAMETOOLONG, ENOMEM, -#ifndef WIN32 +#ifndef HAVE_WIN32 ETXTBSY, #endif ENOENT @@ -232,7 +232,7 @@ int close_bpipe(BPIPE *bpipe) } Dmsg1(800, "child status=%d\n", stat & ~b_errno_exit); } else if (WIFSIGNALED(chldstatus)) { /* process died */ -#ifndef WIN32 +#ifndef HAVE_WIN32 stat = WTERMSIG(chldstatus); #else #warning "WTERMSIG undefined in Win32 !!!" diff --git a/bacula/src/lib/bshm.c b/bacula/src/lib/bshm.c index 41f62cf4d8..7849266e39 100644 --- a/bacula/src/lib/bshm.c +++ b/bacula/src/lib/bshm.c @@ -38,7 +38,7 @@ #include "bacula.h" -#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) +#if !defined(HAVE_WIN32) #ifdef NEED_SHARED_MEMORY #define SHM_KEY 0x0BACB01 /* key for shared memory */ @@ -145,6 +145,6 @@ void shm_destroy(BSHM *shm) #endif } -#endif /* ! HAVE_CYGWIN */ +#endif /* ! HAVE_WIN32 */ #endif diff --git a/bacula/src/lib/bsys.c b/bacula/src/lib/bsys.c index 7ccfa0f9b3..26a9b72cae 100644 --- a/bacula/src/lib/bsys.c +++ b/bacula/src/lib/bsys.c @@ -417,7 +417,7 @@ void b_memset(const char *file, int line, void *mem, int val, size_t num) } #endif -#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) +#if !defined(HAVE_WIN32) static int del_pid_file_ok = FALSE; #endif @@ -426,7 +426,7 @@ static int del_pid_file_ok = FALSE; */ void create_pid_file(char *dir, const char *progname, int port) { -#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) +#if !defined(HAVE_WIN32) int pidfd, len; int oldpid; char pidbuf[20]; @@ -469,7 +469,7 @@ void create_pid_file(char *dir, const char *progname, int port) */ int delete_pid_file(char *dir, const char *progname, int port) { -#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) +#if !defined(HAVE_WIN32) POOLMEM *fname = get_pool_memory(PM_FNAME); if (!del_pid_file_ok) { diff --git a/bacula/src/lib/btime.c b/bacula/src/lib/btime.c index 943a886088..79fc7578f9 100644 --- a/bacula/src/lib/btime.c +++ b/bacula/src/lib/btime.c @@ -48,7 +48,7 @@ char *bstrftime(char *dt, int maxlen, utime_t tim) struct tm tm; /* ***FIXME**** the format and localtime_r() should be user configurable */ - localtime_r(&ttime, &tm); + (void)localtime_r(&ttime, &tm); strftime(dt, maxlen, "%d-%b-%Y %H:%M", &tm); return dt; } @@ -60,7 +60,7 @@ char *bstrftimes(char *dt, int maxlen, utime_t tim) struct tm tm; /* ***FIXME**** the format and localtime_r() should be user configurable */ - localtime_r(&ttime, &tm); + (void)localtime_r(&ttime, &tm); strftime(dt, maxlen, "%d-%b-%Y %H:%M:%S", &tm); return dt; } @@ -73,7 +73,7 @@ char *bstrftime_ny(char *dt, int maxlen, utime_t tim) struct tm tm; /* ***FIXME**** the format and localtime_r() should be user configurable */ - localtime_r(&ttime, &tm); + (void)localtime_r(&ttime, &tm); strftime(dt, maxlen, "%d-%b %H:%M", &tm); return dt; } @@ -86,7 +86,7 @@ char *bstrftime_nc(char *dt, int maxlen, utime_t tim) struct tm tm; /* ***FIXME**** the format and localtime_r() should be user configurable */ - localtime_r(&ttime, &tm); + (void)localtime_r(&ttime, &tm); /* NOTE! since the compiler complains about %y, I use %y and cut the century */ strftime(dt, maxlen, "%d-%b-%Y %H:%M", &tm); strcpy(dt+7, dt+9); @@ -99,7 +99,7 @@ char *bstrutime(char *dt, int maxlen, utime_t tim) { time_t ttime = (time_t)tim; struct tm tm; - localtime_r(&ttime, &tm); + (void)localtime_r(&ttime, &tm); strftime(dt, maxlen, "%Y-%m-%d %H:%M:%S", &tm); return dt; } @@ -197,12 +197,12 @@ int tm_woy(time_t stime) time_t time4; struct tm tm; memset(&tm, 0, sizeof(struct tm)); - localtime_r(&stime, &tm); + (void)localtime_r(&stime, &tm); tm_yday = tm.tm_yday; tm.tm_mon = 0; tm.tm_mday = 4; time4 = mktime(&tm); - localtime_r(&time4, &tm); + (void)localtime_r(&time4, &tm); fty = 1 - tm.tm_wday; if (fty <= 0) { fty += 7; @@ -221,7 +221,7 @@ void get_current_time(struct date_time *dt) time_t now; now = time(NULL); - gmtime_r(&now, &tm); + (void)gmtime_r(&now, &tm); Dmsg6(200, "m=%d d=%d y=%d h=%d m=%d s=%d\n", tm.tm_mon+1, tm.tm_mday, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec); tm_encode(dt, &tm); diff --git a/bacula/src/lib/daemon.c b/bacula/src/lib/daemon.c index 871a25e169..540c5f711e 100644 --- a/bacula/src/lib/daemon.c +++ b/bacula/src/lib/daemon.c @@ -34,7 +34,7 @@ extern int debug_level; void daemon_start() { -#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) +#if !defined(HAVE_WIN32) int i; pid_t cpid; mode_t oldmask; @@ -101,6 +101,6 @@ daemon_start() } } -#endif /* HAVE_CYGWIN */ +#endif /* HAVE_WIN32 */ Dmsg0(900, "Exit daemon_start\n"); } diff --git a/bacula/src/lib/enh_fnmatch.c b/bacula/src/lib/enh_fnmatch.c new file mode 100644 index 0000000000..090f68efdb --- /dev/null +++ b/bacula/src/lib/enh_fnmatch.c @@ -0,0 +1,285 @@ +/* Copyright (C) 1991, 1992, 1993, 1996, 1997 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* Modified version of fnmatch.c - Robert Nelson */ + +#include "bacula.h" +#include "enh_fnmatch.h" + +# ifndef errno +extern int errno; +# endif + +int +enh_fnmatch_sub(const char *pattern, const char *string, int patternlen, int flags) +{ + register const char *p = pattern, *n = string; + register char c; + +/* Note that this evaluates C many times. */ +# define FOLD(c) ((flags & FNM_CASEFOLD) && B_ISUPPER (c) ? tolower (c) : (c)) + + while ((p - pattern) < patternlen) + { + c = *p++; + c = FOLD (c); + + switch (c) + { + case '?': + if (*n == '\0') + return 0; + else if ((flags & FNM_FILE_NAME) && *n == '/') + return 0; + else if ((flags & FNM_PERIOD) && *n == '.' && + (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/'))) + return 0; + break; + + case '\\': + if (!(flags & FNM_NOESCAPE)) + { + if ((p - pattern) >= patternlen) + /* Trailing \ loses. */ + return 0; + + c = *p++; + c = FOLD(c); + } + if (FOLD (*n) != c) + return 0; + break; + + case '*': + if ((flags & FNM_PERIOD) && *n == '.' && + (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/'))) + return FNM_NOMATCH; + + if ((p - pattern) >= patternlen) + return patternlen; + + for (c = *p++; ((p - pattern) <= patternlen) && (c == '?' || c == '*'); c = *p++) + { + if ((flags & FNM_FILE_NAME) && *n == '/') + /* A slash does not match a wildcard under FNM_FILE_NAME. */ + return 0; + else if (c == '?') + { + /* A ? needs to match one character. */ + if (*n == '\0') + /* There isn't another character; no match. */ + return 0; + else + /* One character of the string is consumed in matching + this ? wildcard, so *??? won't match if there are + less than three characters. */ + ++n; + } + } + + if ((p - pattern) >= patternlen) + return patternlen; + + { + char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c; + c1 = FOLD (c1); + for (--p; *n != '\0'; ++n) + { + if (c == '[' || c == '{' || FOLD((unsigned char)*n) == c1) + { + int len; + + len = enh_fnmatch_sub(p, n, (int)(patternlen - (p - pattern)), flags & ~FNM_PERIOD); + + if (len > 0 && n[len] == '\0') + return (int)(n - string + len); + } + else + { + if ((flags & FNM_FILE_NAME) && *n == '/') + return 0; /* A slash does not match a wildcard under FNM_FILE_NAME. */ + } + + } + return 0; + } + + case '{': + { + const char *pstart = p; + + while ((p - pattern) < patternlen) + { + c = *p++; + + if (!(flags & FNM_NOESCAPE) && c == '\\') + { + if ((p - pattern) >= patternlen) + return 0; + + ++p; + continue; + } + + if (c == ',' || c == '}') + { + int matchlen; + + matchlen = enh_fnmatch_sub(pstart, n, (int)(p - pstart - 1), flags & ~FNM_PERIOD); + + if (matchlen > 0) + { + n += matchlen - 1; + while (c != '}') + { + if (!(flags & FNM_NOESCAPE) && c == '\\') + { + if ((p - pattern) >= patternlen) + return 0; + + ++p; + } + + if ((p - pattern) >= patternlen) + return 0; + + c = *p++; + } + break; + } + + if (c == '}') + return 0; + + pstart = p; + } + } + break; + } + + case '[': + { + /* Nonzero if the sense of the character class is inverted. */ + register int nnot; + + if (*n == '\0') + return 0; + + if ((flags & FNM_PERIOD) && *n == '.' && + (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/'))) + return 0; + + nnot = (*p == '!' || *p == '^'); + if (nnot) + ++p; + + if ((p - pattern) >= patternlen) + /* [ (unterminated) loses. */ + return 0; + + c = *p++; + + for (;;) + { + register char cstart, cend; + + cstart = cend = FOLD (c); + + if ((p - pattern) >= patternlen) + /* [ (unterminated) loses. */ + return 0; + + c = *p++; + c = FOLD (c); + + if ((flags & FNM_FILE_NAME) && c == '/') + /* [/] can never match. */ + return 0; + + if (c == '-' && *p != ']') + { + if ((p - pattern) >= patternlen) + return 0; + + cend = *p++; + + cend = FOLD (cend); + + if ((p - pattern) >= patternlen) + return 0; + + c = *p++; + } + + if (FOLD (*n) >= cstart && FOLD (*n) <= cend) + goto matched; + + if (c == ']') + break; + } + if (!nnot) + return 0; + break; + + matched:; + /* Skip the rest of the [...] that already matched. */ + while (c != ']') + { + if ((p - pattern) >= patternlen) + return 0; + + c = *p++; + } + if (nnot) + return 0; + } + break; + + default: + if (c != FOLD (*n)) + return 0; + break; + } + + ++n; + } + + return (int)(n - string); + +# undef FOLD +} + +/* Match STRING against the filename pattern PATTERN, returning number of characters + in STRING that were matched if all of PATTERN matches, nonzero if not. */ +int +enh_fnmatch(const char *pattern, const char *string, int flags) +{ + int matchlen; + + matchlen = enh_fnmatch_sub(pattern, string, (int)strlen(pattern), flags); + + if (matchlen == 0) + return FNM_NOMATCH; + + if (string[matchlen] == '\0') + return 0; + + if ((flags & FNM_LEADING_DIR) && string[matchlen] == '/') + /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */ + return 0; + + return FNM_NOMATCH; +} diff --git a/bacula/src/lib/enh_fnmatch.h b/bacula/src/lib/enh_fnmatch.h new file mode 100644 index 0000000000..0a530163cc --- /dev/null +++ b/bacula/src/lib/enh_fnmatch.h @@ -0,0 +1,51 @@ +/* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc. + +NOTE: The canonical source of this file is maintained with the GNU C Library. +Bugs can be reported to bug-glibc@prep.ai.mit.edu. + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software Foundation, +Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* Modified version of fnmatch.h - Robert Nelson */ + +#ifndef _ENH_FNMATCH_H + +#define _ENH_FNMATCH_H 1 + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined (__cplusplus) || (defined (__STDC__) && __STDC__) +#undef __P +#define __P(protos) protos +#else /* Not C++ or ANSI C. */ +#undef __P +#define __P(protos) () +/* We can get away without defining `const' here only because in this file + it is used only inside the prototype for `fnmatch', which is elided in + non-ANSI C where `const' is problematical. */ +#endif /* C++ or ANSI C. */ + + +/* Match STRING against the filename pattern PATTERN, + returning zero if it matches, FNM_NOMATCH if not. */ +extern int enh_fnmatch __P ((const char *__pattern, const char *__string, + int __flags)); + +#ifdef __cplusplus +} +#endif + +#endif /* fnmatch.h */ diff --git a/bacula/src/lib/events.c b/bacula/src/lib/events.c index 861c8c8b78..782778e12a 100644 --- a/bacula/src/lib/events.c +++ b/bacula/src/lib/events.c @@ -138,7 +138,7 @@ bailout: #endif /* IMPLEMENTED */ -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) #include @@ -172,4 +172,4 @@ void FillEventsBox(HWND hwnd, int idlist) return; } -#endif /* HAVE_CYGWIN */ +#endif /* HAVE_WIN32 */ diff --git a/bacula/src/lib/lex.c b/bacula/src/lib/lex.c index 11b9af0156..13b2cb9ab2 100644 --- a/bacula/src/lib/lex.c +++ b/bacula/src/lib/lex.c @@ -155,7 +155,7 @@ LEX *lex_open_file(LEX *lf, const char *filename, LEX_ERROR_HANDLER *scan_error) char *fname = bstrdup(filename); - if ((fd = fopen(fname, "r")) == NULL) { + if ((fd = fopen(fname, "rb")) == NULL) { return NULL; } Dmsg1(400, "Open config file: %s\n", fname); diff --git a/bacula/src/lib/md5.c b/bacula/src/lib/md5.c index 0725dc5eaa..d5b5bf7e4e 100644 --- a/bacula/src/lib/md5.c +++ b/bacula/src/lib/md5.c @@ -298,7 +298,7 @@ int main(int argc, char *argv[]) exit(1); } - fd = fopen(argv[0], "r"); + fd = fopen(argv[0], "rb"); if (!fd) { printf("Could not open %s: ERR=%s\n", argv[0], strerror(errno)); exit(1); diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index a394f0dac5..1c4b685d9a 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -26,11 +26,9 @@ #include "bacula.h" #include "jcr.h" -#if !defined(HAVE_CONSOLE) -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if !defined(HAVE_CONSOLE) && defined(HAVE_WIN32) #include #endif -#endif #define FULL_LOCATION 1 /* set for file:line in Debug messages */ @@ -52,19 +50,15 @@ FILE *con_fd = NULL; /* Console file descriptor */ brwlock_t con_lock; /* Console lock structure */ -#ifdef HAVE_POSTGRESQL +#if defined(HAVE_POSTGRESQL) char catalog_db[] = "PostgreSQL"; -#else -#ifdef HAVE_MYSQL +#elif defined(HAVE_MYSQL) char catalog_db[] = "MySQL"; -#else -#ifdef HAVE_SQLITE +#elif defined(HAVE_SQLITE) char catalog_db[] = "SQLite"; #else char catalog_db[] = "Internal"; #endif -#endif -#endif const char *host_os = HOST_OS; const char *distname = DISTNAME; @@ -117,7 +111,7 @@ void my_name_is(int argc, char *argv[], const char *name) l++; } else { l = argv[0]; -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) /* On Windows allow c: junk */ if (l[1] == ':') { l += 2; @@ -162,7 +156,9 @@ void init_msg(JCR *jcr, MSGS *msg) { DEST *d, *dnew, *temp_chain = NULL; +#ifndef HAVE_WIN32 int i; +#endif if (jcr == NULL && msg == NULL) { init_last_jobs_list(); @@ -193,7 +189,7 @@ init_msg(JCR *jcr, MSGS *msg) if (msg == NULL) { daemon_msgs = (MSGS *)malloc(sizeof(MSGS)); memset(daemon_msgs, 0, sizeof(MSGS)); -#ifndef WIN32 +#ifndef HAVE_WIN32 for (i=1; i<=M_MAX; i++) { add_msg_dest(daemon_msgs, MD_STDOUT, i, NULL, NULL); } @@ -258,7 +254,7 @@ void init_console_msg(const char *wd) console_msg_pending = 1; } close(fd); - con_fd = fopen(con_fname, "a+"); + con_fd = fopen(con_fname, "a+b"); if (!con_fd) { berrno be; Emsg2(M_ERROR, 0, _("Could not open console message file %s: ERR=%s\n"), @@ -606,7 +602,7 @@ void dispatch_message(JCR *jcr, int type, time_t mtime, char *msg) case MD_CONSOLE: Dmsg1(850, "CONSOLE for following msg: %s", msg); if (!con_fd) { - con_fd = fopen(con_fname, "a+"); + con_fd = fopen(con_fname, "a+b"); Dmsg0(850, "Console file not open.\n"); } if (con_fd) { @@ -630,7 +626,7 @@ void dispatch_message(JCR *jcr, int type, time_t mtime, char *msg) } break; case MD_SYSLOG: - Dmsg1(850, "SYSLOG for collowing msg: %s\n", msg); + Dmsg1(850, "SYSLOG for following msg: %s\n", msg); /* * We really should do an openlog() here. */ @@ -661,7 +657,7 @@ void dispatch_message(JCR *jcr, int type, time_t mtime, char *msg) if (!d->fd) { POOLMEM *name = get_pool_memory(PM_MESSAGE); make_unique_mail_filename(jcr, name, d); - d->fd = fopen(name, "w+"); + d->fd = fopen(name, "w+b"); if (!d->fd) { berrno be; d->fd = stdout; @@ -683,7 +679,7 @@ void dispatch_message(JCR *jcr, int type, time_t mtime, char *msg) case MD_FILE: Dmsg1(850, "FILE for following msg: %s", msg); if (!d->fd) { - d->fd = fopen(d->where, "w+"); + d->fd = fopen(d->where, "w+b"); if (!d->fd) { berrno be; d->fd = stdout; @@ -699,7 +695,7 @@ void dispatch_message(JCR *jcr, int type, time_t mtime, char *msg) case MD_APPEND: Dmsg1(850, "APPEND for following msg: %s", msg); if (!d->fd) { - d->fd = fopen(d->where, "a"); + d->fd = fopen(d->where, "ab"); if (!d->fd) { berrno be; d->fd = stdout; @@ -789,7 +785,7 @@ d_msg(const char *file, int line, int level, const char *fmt,...) if (!trace_fd) { char fn[200]; bsnprintf(fn, sizeof(fn), "%s/bacula.trace", working_directory ? working_directory : "."); - trace_fd = fopen(fn, "a+"); + trace_fd = fopen(fn, "a+b"); } if (trace_fd) { fputs(buf, trace_fd); @@ -885,7 +881,7 @@ t_msg(const char *file, int line, int level, const char *fmt,...) if (level <= debug_level) { if (!trace_fd) { bsnprintf(buf, sizeof(buf), "%s/bacula.trace", working_directory); - trace_fd = fopen(buf, "a+"); + trace_fd = fopen(buf, "a+b"); } #ifdef FULL_LOCATION diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index 8e53477325..f95b609485 100755 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -61,15 +61,14 @@ extern int r_last; extern RES_TABLE resources[]; extern RES **res_head; -#ifdef HAVE_WIN32 +#if defined(_MSC_VER) // work around visual studio name manling preventing external linkage since res_all // is declared as a different type when instantiated. extern "C" CURES res_all; -extern "C" int res_all_size; #else extern CURES res_all; -extern int res_all_size; #endif +extern int res_all_size; extern brwlock_t res_lock; /* resource lock */ diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index 118989c0de..9198e74b97 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -76,7 +76,7 @@ BSOCK * bnet_connect (JCR *jcr, int retry_interval, void bnet_close (BSOCK *bsock); BSOCK * init_bsock (JCR *jcr, int sockfd, const char *who, const char *ip, int port, struct sockaddr *client_addr); -#ifdef WIN32 +#ifdef HAVE_WIN32 #ifndef socklen_t #define socklen_t int #endif diff --git a/bacula/src/lib/res.c b/bacula/src/lib/res.c index 9c6e360100..c35fb68ee5 100644 --- a/bacula/src/lib/res.c +++ b/bacula/src/lib/res.c @@ -34,17 +34,6 @@ extern int r_last; extern RES_TABLE resources[]; extern RES **res_head; -#ifdef HAVE_WIN32 -// work around visual studio name manling preventing external linkage since res_all -// is declared as a different type when instantiated. -extern "C" CURES res_all; -extern "C" int res_all_size; -#else -extern CURES res_all; -extern int res_all_size; -#endif - - brwlock_t res_lock; /* resource lock */ static int res_locked = 0; /* set when resource chains locked -- for debug */ diff --git a/bacula/src/lib/runscript.c b/bacula/src/lib/runscript.c index 8b9b92c6ae..c73cc1012c 100644 --- a/bacula/src/lib/runscript.c +++ b/bacula/src/lib/runscript.c @@ -25,8 +25,6 @@ #include "bacula.h" #include "jcr.h" -#define USE_RUNSCRIPT - #include "runscript.h" RUNSCRIPT *new_runscript() diff --git a/bacula/src/lib/sha1.c b/bacula/src/lib/sha1.c index 136d8a7f17..063fad0e94 100644 --- a/bacula/src/lib/sha1.c +++ b/bacula/src/lib/sha1.c @@ -490,7 +490,7 @@ int main(int argc, char *argv[]) printf("Must have filename\n"); exit(1); } - fd = fopen(argv[1], "r"); + fd = fopen(argv[1], "rb"); if (!fd) { printf("Could not open %s: ERR=%s\n", argv[1], strerror(errno)); exit(1); diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index 4d1cf2051d..1856539ac3 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -26,7 +26,7 @@ #include "stored.h" #include "findlib/find.h" -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) int win32_client = 1; #else int win32_client = 0; @@ -122,7 +122,7 @@ int main (int argc, char *argv[]) break; case 'e': /* exclude list */ - if ((fd = fopen(optarg, "r")) == NULL) { + if ((fd = fopen(optarg, "rb")) == NULL) { berrno be; Pmsg2(0, _("Could not open exclude file: %s, ERR=%s\n"), optarg, be.strerror()); @@ -137,7 +137,7 @@ int main (int argc, char *argv[]) break; case 'i': /* include list */ - if ((fd = fopen(optarg, "r")) == NULL) { + if ((fd = fopen(optarg, "rb")) == NULL) { berrno be; Pmsg2(0, _("Could not open include file: %s, ERR=%s\n"), optarg, be.strerror()); diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index 933af258c2..40d348ccae 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -124,7 +124,7 @@ int main (int argc, char *argv[]) break; case 'e': /* exclude list */ - if ((fd = fopen(optarg, "r")) == NULL) { + if ((fd = fopen(optarg, "rb")) == NULL) { Pmsg2(0, _("Could not open exclude file: %s, ERR=%s\n"), optarg, strerror(errno)); exit(1); @@ -138,7 +138,7 @@ int main (int argc, char *argv[]) break; case 'i': /* include list */ - if ((fd = fopen(optarg, "r")) == NULL) { + if ((fd = fopen(optarg, "rb")) == NULL) { Pmsg2(0, _("Could not open include file: %s, ERR=%s\n"), optarg, strerror(errno)); exit(1); diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index d88a10991a..6d979c96f5 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -52,7 +52,7 @@ static int update_digest_record(B_DB *db, char *digest, DEV_RECORD *rec, int typ /* Global variables */ -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) int win32_client = 1; #else int win32_client = 0; diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index fd9338b9ad..4575531848 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -1881,8 +1881,8 @@ static void fillcmd() */ jcr->dcr->VolFirstIndex = 0; time(&jcr->run_time); /* start counting time for rates */ - localtime_r(&jcr->run_time, &tm); - strftime(buf1, sizeof(buf1), "%T", &tm); + (void)localtime_r(&jcr->run_time, &tm); + strftime(buf1, sizeof(buf1), "%H:%M:%S", &tm); if (simple) { Pmsg1(-1, _("%s Begin writing Bacula records to tape ...\n"), buf1); } else { @@ -1935,8 +1935,8 @@ static void fillcmd() */ if ((block->BlockNumber % 32000) == 0) { now = time(NULL); - localtime_r(&now, &tm); - strftime(buf1, sizeof(buf1), "%T", &tm); + (void)localtime_r(&now, &tm); + strftime(buf1, sizeof(buf1), "%H:%M:%S", &tm); Pmsg1(-1, _("%s Flush block, write EOF\n"), buf1); flush_block(block, 0); dev->weof(1); @@ -2012,8 +2012,8 @@ static void fillcmd() } now = time(NULL); - localtime_r(&now, &tm); - strftime(buf1, sizeof(buf1), "%T", &tm); + (void)localtime_r(&now, &tm); + strftime(buf1, sizeof(buf1), "%H:%M:%S", &tm); if (simple) { Pmsg3(-1, _("\n\n%s Done filling tape at %d:%d. Now beginning re-read of tape ...\n"), buf1, jcr->dcr->dev->file, jcr->dcr->dev->block_num); diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 99be022c91..6373a8e39f 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -12,7 +12,7 @@ * to carry out operations without worrying about who * set what lock (i.e. race conditions). * - * Note, this is the device dependent code, and my have + * Note, this is the device dependent code, and may have * to be modified for each system, but is meant to * be as "generic" as possible. * @@ -103,7 +103,7 @@ init_dev(JCR *jcr, DEVRES *device) DCR *dcr = NULL; DEVICE *dev; - + /* If no device type specified, try to guess */ if (!device->dev_type) { /* Check that device is available */ diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 4ca8fb6da7..e52f19e0c0 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -181,7 +181,7 @@ typedef struct s_steal_lock { int dev_prev_blocked; /* previous blocked state */ } bsteal_lock_t; -struct DEVRES; /* Device resource defined in stored_conf.h */ +class DEVRES; /* Device resource defined in stored_conf.h */ class DCR; /* forward reference */ /* diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index b00f425233..c2a429378e 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -873,7 +873,7 @@ static bool changer_cmd(JCR *jcr) if (dcr) { dev = dcr->dev; P(dev->mutex); /* Use P to avoid indefinite block */ - if (!dev->device->changer_res) { + if (!dev->device->changer_res) { bnet_fsend(dir, _("3995 Device %s is not an autochanger.\n"), dev->print_name()); /* Under certain "safe" conditions, we can steal the lock */ diff --git a/bacula/src/stored/fd_cmds.c b/bacula/src/stored/fd_cmds.c index 41df7eae30..af51981731 100644 --- a/bacula/src/stored/fd_cmds.c +++ b/bacula/src/stored/fd_cmds.c @@ -324,7 +324,7 @@ bool get_bootstrap_file(JCR *jcr, BSOCK *sock) jcr->Job); Dmsg1(400, "bootstrap=%s\n", fname); jcr->RestoreBootstrap = fname; - bs = fopen(fname, "a+"); /* create file */ + bs = fopen(fname, "a+b"); /* create file */ if (!bs) { Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"), jcr->RestoreBootstrap, strerror(errno)); diff --git a/bacula/src/stored/spool.c b/bacula/src/stored/spool.c index 9cf930447b..e57326ccc1 100644 --- a/bacula/src/stored/spool.c +++ b/bacula/src/stored/spool.c @@ -579,7 +579,7 @@ bool open_attr_spool_file(JCR *jcr, BSOCK *bs) POOLMEM *name = get_pool_memory(PM_MESSAGE); make_unique_spool_filename(jcr, &name, bs->fd); - bs->spool_fd = fopen(name, "w+"); + bs->spool_fd = fopen(name, "w+b"); if (!bs->spool_fd) { berrno be; Jmsg(jcr, M_FATAL, 0, _("fopen attr spool file %s failed: ERR=%s\n"), name, diff --git a/bacula/src/stored/stored_conf.c b/bacula/src/stored/stored_conf.c index 51b7dd76b7..cb9766cd6f 100644 --- a/bacula/src/stored/stored_conf.c +++ b/bacula/src/stored/stored_conf.c @@ -39,7 +39,13 @@ static void store_devtype(LEX *lc, RES_ITEM *item, int index, int pass); /* We build the current resource here statically, * then move it to dynamic memory */ +#if defined(_MSC_VER) +extern "C" { // work around visual compiler mangling variables + URES res_all; +} +#else URES res_all; +#endif int res_all_size = sizeof(res_all); /* Definition of records permitted within each diff --git a/bacula/src/stored/stored_conf.h b/bacula/src/stored/stored_conf.h index e1db10d0bc..77a759eb06 100644 --- a/bacula/src/stored/stored_conf.h +++ b/bacula/src/stored/stored_conf.h @@ -85,7 +85,7 @@ public: TLS_CONTEXT *tls_ctx; /* Shared TLS Context */ }; -typedef struct s_res_store STORES; +typedef class s_res_store STORES; class AUTOCHANGER { public: diff --git a/bacula/src/tools/bwild.c b/bacula/src/tools/bwild.c index 65b6a2d647..a7b0977046 100644 --- a/bacula/src/tools/bwild.c +++ b/bacula/src/tools/bwild.c @@ -19,7 +19,6 @@ #include "bacula.h" #include "lib/fnmatch.h" - static void usage() { fprintf(stderr, diff --git a/bacula/src/tools/drivetype.c b/bacula/src/tools/drivetype.c new file mode 100644 index 0000000000..b778ade3a4 --- /dev/null +++ b/bacula/src/tools/drivetype.c @@ -0,0 +1,94 @@ +/* + * Program for determining drive type + * + * Written by Robert Nelson, June 2006 + * + * Version $Id$ + * + */ +/* + Copyright (C) 2006 Kern Sibbald + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + file LICENSE for additional details. + + */ + +#include "bacula.h" +#include "findlib/find.h" + +/* Dummy functions */ +int generate_daemon_event(JCR *jcr, const char *event) + { return 1; } + +static void usage() +{ + fprintf(stderr, _( +"\n" +"Usage: drivetype [-v] path ...\n" +"\n" +" Print the drive type a given file/directory is on.\n" +" The following options are supported:\n" +"\n" +" -v print both path and file system type.\n" +" -? print this message.\n" +"\n")); + + exit(1); +} + + +int +main (int argc, char *const *argv) +{ + char dt[100]; + int verbose = 0; + int status = 0; + int ch, i; + + setlocale(LC_ALL, ""); + bindtextdomain("bacula", LOCALEDIR); + textdomain("bacula"); + + while ((ch = getopt(argc, argv, "v?")) != -1) { + switch (ch) { + case 'v': + verbose = 1; + break; + case '?': + default: + usage(); + + } + } + argc -= optind; + argv += optind; + + if (argc < 1) { + usage(); + } + + OSDependentInit(); + + for (i = 0; i < argc; --argc, ++argv) { + if (drivetype(*argv, dt, sizeof(dt))) { + if (verbose) { + printf("%s: %s\n", *argv, dt); + } else { + puts(dt); + } + } else { + fprintf(stderr, _("%s: unknown\n"), *argv); + status = 1; + } + } + + exit(status); +} diff --git a/bacula/src/tools/fstype.c b/bacula/src/tools/fstype.c index e671257908..796588d9a6 100644 --- a/bacula/src/tools/fstype.c +++ b/bacula/src/tools/fstype.c @@ -32,7 +32,7 @@ static void usage() { fprintf(stderr, _( "\n" -"Usage: fstype [-d debug_level] path ...\n" +"Usage: fstype [-v] path ...\n" "\n" " Print the file system type a given file/directory is on.\n" " The following options are supported:\n" diff --git a/bacula/src/tools/testfind.c b/bacula/src/tools/testfind.c index 851c3a8794..fe4c21a2e6 100644 --- a/bacula/src/tools/testfind.c +++ b/bacula/src/tools/testfind.c @@ -20,7 +20,7 @@ #include "findlib/find.h" -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) int win32_client = 1; #else int win32_client = 0; diff --git a/bacula/src/tools/testls.c b/bacula/src/tools/testls.c index e48df2e6cc..78ff15d3ec 100755 --- a/bacula/src/tools/testls.c +++ b/bacula/src/tools/testls.c @@ -19,7 +19,7 @@ #include "bacula.h" #include "findlib/find.h" -#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +#if defined(HAVE_WIN32) int win32_client = 1; #else int win32_client = 0; @@ -125,7 +125,7 @@ main (int argc, char *const *argv) } } if (inc) { - fd = fopen(inc, "r"); + fd = fopen(inc, "rb"); if (!fd) { printf(_("Could not open include file: %s\n"), inc); exit(1); @@ -138,7 +138,7 @@ main (int argc, char *const *argv) } if (exc) { - fd = fopen(exc, "r"); + fd = fopen(exc, "rb"); if (!fd) { printf(_("Could not open exclude file: %s\n"), exc); exit(1); -- 2.39.5