/* Allow printing of NULL pointers */
#define NPRT(x) (x)?(x):_("*None*")
-#ifdef WIN32
+#if defined(HAVE_WIN32)
#undef ENABLE_NLS
#endif
* 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 */
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
#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 */
/* 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
$(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
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));
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));
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));
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));
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));
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));
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.
*/
* 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;
*
* Version $Id$
*/
+
/*
Copyright (C) 2001-2006 Kern Sibbald
return stat;
}
-int
+bool
db_find_last_jobid(JCR *jcr, B_DB *mdb, const char *Name, JOB_DBR *jr)
{ return 0; }
*
* Version $Id$
*/
+
/*
Copyright (C) 2001-2006 Kern Sibbald
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.
*/
* 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;
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,
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,
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),
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 */
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 */
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);
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) "
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) {
/*
* 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);
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;
}
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;
(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));
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);
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);
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);
/* 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;
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);
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);
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));
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"));
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;
* 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
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,
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"),
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;
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 */
}
terminate_dird(0);
+
+ return 0;
}
/* Cleanup and then exit */
* 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);
/* 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
{
struct tm tm;
time_t now = time(NULL);
- localtime_r(&now, &tm);
+ (void)localtime_r(&now, &tm);
int val = 0;
char buf[10];
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());
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"),
* 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 */
*/
} 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];
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));
#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 */
/* 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;
* 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;
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) {
/* 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, "
"FileSetId INTEGER UNSIGNED, "
"JobFiles INTEGER UNSIGNED, "
"JobStatus CHAR)",
-#endif
#endif
"CREATE INDEX DelInx1 ON DelCandidates (JobId)",
NULL};
"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
/*
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;
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;
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;
#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 */
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;
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;
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[] = {
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());
}
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));
#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);
case FT_NORECURSE:
case FT_NOFSCHG:
case FT_INVALIDFS:
+ case FT_INVALIDDT:
case FT_DIREND:
case FT_SPEC:
case FT_RAW:
* Main Bacula Unix Client Program
*
*/
-#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+#if defined(HAVE_WIN32)
#define main BaculaMain
#endif
* 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
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);
{
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,
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());
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"),
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"),
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
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);
}
-#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+#if defined(HAVE_WIN32)
#include <windows.h>
int bacstat = 0;
return buf;
}
-#endif /* HAVE_CYGWIN */
+#endif /* HAVE_WIN32 */
#include "bacula.h"
#include "find.h"
-#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+#if defined(HAVE_WIN32)
#include "../lib/winapi.h"
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
#endif
#endif
+
/* Decode a stat packet from base64 characters */
int decode_stat(char *buf, struct stat *statp, int32_t *LinkFI)
{
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)) {
/* */
/*=============================================================*/
-#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
+#if !defined(HAVE_WIN32)
/*
* It is possible to piggyback additional data e.g. ACLs on
/* */
/*=============================================================*/
-#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+#if defined(HAVE_WIN32)
int encode_attribsEx(JCR *jcr, char *attribsEx, FF_PKT *ff_pkt)
{
conv_unix_to_win32_path(name, *win32_name, dwSize);
}
-#endif /* HAVE_CYGWIN */
+#endif /* HAVE_WIN32 */
* ===============================================================
*/
-#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);
*
* =======================================================
*/
-#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+#if defined(HAVE_WIN32)
#include <windows.h>
#include "../lib/winapi.h"
/* 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 */
--- /dev/null
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#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
/* */
/*=============================================================*/
-#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
+#if !defined(HAVE_WIN32)
int enable_backup_privileges(JCR *jcr, int ignore_errors)
{ return 0; }
/* */
/*=============================================================*/
-#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+#if defined(HAVE_WIN32)
void win_error(JCR *jcr, char *prefix, DWORD lerror);
return stat;
}
-#endif /* HAVE_CYGWIN */
+#endif /* HAVE_WIN32 */
{
/* szDrives must be at least 27 bytes long */
-#ifndef WIN32
+#if !defined(HAVE_WIN32)
return 0;
#endif
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 {
case FT_NORECURSE:
case FT_NOFSCHG:
case FT_INVALIDFS:
+ case FT_INVALIDDT:
case FT_NOOPEN:
// return ff->callback(ff, hpkt, top_level);
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 == '/';
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
#endif
/* Fold case in fnmatch() on Win32 */
-#ifdef WIN32
+#ifdef HAVE_WIN32
static const int fnmode = FNM_CASEFOLD;
#else
static const int fnmode = 0;
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 == '\\') {
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, '/')) {
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 == '\\') {
}
save = reg;
reg >>= (rem - 6);
- buf[j++] = base64_digits[reg & (uint32_t)0x3F];
+ buf[j++] = base64_digits[reg & 0x3F];
reg = save;
rem -= 6;
}
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) {
* Returns previous socket flag
*/
int bnet_set_nonblocking (BSOCK *bsock) {
-#ifndef WIN32
+#ifndef HAVE_WIN32
int oflags;
/* Get current flags */
*/
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) {
*/
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());
E2BIG,
ENAMETOOLONG,
ENOMEM,
-#ifndef WIN32
+#ifndef HAVE_WIN32
ETXTBSY,
#endif
ENOENT
}
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 !!!"
#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 */
#endif
}
-#endif /* ! HAVE_CYGWIN */
+#endif /* ! HAVE_WIN32 */
#endif
}
#endif
-#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
+#if !defined(HAVE_WIN32)
static int del_pid_file_ok = FALSE;
#endif
*/
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];
*/
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) {
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;
}
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;
}
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;
}
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);
{
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;
}
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;
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);
void
daemon_start()
{
-#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
+#if !defined(HAVE_WIN32)
int i;
pid_t cpid;
mode_t oldmask;
}
}
-#endif /* HAVE_CYGWIN */
+#endif /* HAVE_WIN32 */
Dmsg0(900, "Exit daemon_start\n");
}
--- /dev/null
+/* 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;
+}
--- /dev/null
+/* 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 */
#endif /* IMPLEMENTED */
-#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+#if defined(HAVE_WIN32)
#include <windows.h>
return;
}
-#endif /* HAVE_CYGWIN */
+#endif /* HAVE_WIN32 */
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);
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);
#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 <windows.h>
#endif
-#endif
#define FULL_LOCATION 1 /* set for file:line in Debug messages */
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;
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;
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();
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);
}
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"),
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) {
}
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.
*/
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;
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;
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;
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);
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
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 */
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
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 */
#include "bacula.h"
#include "jcr.h"
-#define USE_RUNSCRIPT
-
#include "runscript.h"
RUNSCRIPT *new_runscript()
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);
#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;
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());
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());
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);
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);
/* Global variables */
-#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+#if defined(HAVE_WIN32)
int win32_client = 1;
#else
int win32_client = 0;
*/
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 {
*/
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);
}
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);
* 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.
*
DCR *dcr = NULL;
DEVICE *dev;
-
+
/* If no device type specified, try to guess */
if (!device->dev_type) {
/* Check that device is available */
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 */
/*
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 */
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));
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,
/* 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
TLS_CONTEXT *tls_ctx; /* Shared TLS Context */
};
-typedef struct s_res_store STORES;
+typedef class s_res_store STORES;
class AUTOCHANGER {
public:
#include "bacula.h"
#include "lib/fnmatch.h"
-
static void usage()
{
fprintf(stderr,
--- /dev/null
+/*
+ * 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);
+}
{
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"
#include "findlib/find.h"
-#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+#if defined(HAVE_WIN32)
int win32_client = 1;
#else
int win32_client = 0;
#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;
}
}
if (inc) {
- fd = fopen(inc, "r");
+ fd = fopen(inc, "rb");
if (!fd) {
printf(_("Could not open include file: %s\n"), inc);
exit(1);
}
if (exc) {
- fd = fopen(exc, "r");
+ fd = fopen(exc, "rb");
if (!fd) {
printf(_("Could not open exclude file: %s\n"), exc);
exit(1);