From: Kern Sibbald Date: Sun, 18 May 2003 20:42:15 +0000 (+0000) Subject: Major part of Win32 BackupRead/Write done X-Git-Tag: Release-1.31~139 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b94b7863bef292ed161a821573c5e9b75989ed29;p=bacula%2Fbacula Major part of Win32 BackupRead/Write done git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@517 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/kernstodo b/bacula/kernstodo index 8351a53da2..909f328a67 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -19,6 +19,8 @@ Testing to do: (painful) - Figure out how to use ssh or stunnel to protect Bacula communications. For 1.31 release: +- Find a solution for the multiple FileSet problem (when it is changed). + Add date? - Cancel waiting for Client connect in SD if FD goes away. - Testing Tibs job erred and hung director on Storage resource. - Make restore more robust in counting error and not immediately bailing diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index 81ced4d798..2338290b4b 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -51,8 +51,6 @@ int blast_data_to_storage_daemon(JCR *jcr, char *addr) sd = jcr->store_bsock; - get_backup_privileges(jcr, 0); - set_jcr_job_status(jcr, JS_Running); Dmsg1(110, "bfiled: opened data connection %d to stored\n", sd->fd); @@ -194,7 +192,11 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr) /* Open any file with data that we intend to save */ if (ff_pkt->type != FT_LNKSAVED && (S_ISREG(ff_pkt->statp.st_mode) && ff_pkt->statp.st_size > 0) || - ff_pkt->type == FT_RAW || ff_pkt->type == FT_FIFO) { + ff_pkt->type == FT_RAW || ff_pkt->type == FT_FIFO +#ifdef HAVE_CYGWIN + || ff_pkt->type == FT_DIR +#endif + ) { btimer_id tid; if (ff_pkt->type == FT_FIFO) { tid = start_thread_timer(pthread_self(), 60); diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 8cb24a5672..814b7e003b 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -163,6 +163,7 @@ void *handle_client_request(void *dirp) jcr->client_name = get_memory(strlen(my_name) + 1); pm_strcpy(&jcr->client_name, my_name); dir->jcr = (void *)jcr; + get_backup_privileges(NULL, 1 /* ignore_errors */); /**********FIXME******* add command handler error code */ @@ -297,7 +298,6 @@ static int job_cmd(JCR *jcr) } jcr->sd_auth_key = bstrdup(sd_auth_key); free_pool_memory(sd_auth_key); - get_backup_privileges(jcr, 1 /* ignore_errors */); Dmsg2(120, "JobId=%d Auth=%s\n", jcr->JobId, jcr->sd_auth_key); return bnet_fsend(dir, OKjob); } diff --git a/bacula/src/filed/status.c b/bacula/src/filed/status.c index e0c1054de6..24ac189170 100755 --- a/bacula/src/filed/status.c +++ b/bacula/src/filed/status.c @@ -33,6 +33,10 @@ extern char my_name[]; extern struct s_last_job last_job; extern time_t daemon_start_time; +#ifdef HAVE_CYGWIN +static int privs = 0; +#endif + /* * General status generator */ @@ -52,6 +56,22 @@ static void do_status(void sendit(char *msg, int len, void *sarg), void *arg) len = Mmsg(&msg, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs, last_job.NumJobs == 1 ? "" : "s"); sendit(msg, len, arg); +#ifdef HAVE_CYGWIN + if (!privs) { + privs = get_backup_privileges(NULL, 1); + } + len = Mmsg(&msg, + _("Priv 0x%x APIs=%sOPT,%sATP,%sLPV,%sGFAE,%sBR,%sBW,%sSPSP\n"), privs, + p_OpenProcessToken?"":"!", + p_AdjustTokenPrivileges?"":"!", + p_LookupPrivilegeValue?"":"!", + p_GetFileAttributesEx?"":"!", + p_BackupRead?"":"!", + p_BackupWrite?"":"!", + p_SetProcessShutdownParameters?"":"!"); + sendit(msg, len, arg); +#endif + if (last_job.NumJobs > 0) { char termstat[30]; diff --git a/bacula/src/filed/win32/winmain.cpp b/bacula/src/filed/win32/winmain.cpp index 4acbb3c2d0..ccb1cfff6e 100755 --- a/bacula/src/filed/win32/winmain.cpp +++ b/bacula/src/filed/win32/winmain.cpp @@ -337,54 +337,6 @@ int BaculaAppMain() FreeLibrary(hLib); } -#ifdef debug_xxx - char buf[1000]; - buf[0] = 0; - strcat(buf, "GetFileAttributesEx "); - if (p_GetFileAttributesEx) - strcat(buf, "OK\n"); - else - strcat(buf, "NO\n"); - - strcat(buf, "SetProcessShutdownParamaters "); - if (p_SetProcessShutdownParameters) - strcat(buf, "OK\n"); - else - strcat(buf, "NO\n"); - - strcat(buf, "BackupRead "); - if (p_BackupRead) - strcat(buf, "OK\n"); - else - strcat(buf, "NO\n"); - - strcat(buf, "BackupWrite "); - if (p_BackupWrite) - strcat(buf, "OK\n"); - else - strcat(buf, "NO\n"); - - strcat(buf, "OpenProcessToken "); - if (p_OpenProcessToken) - strcat(buf, "OK\n"); - else - strcat(buf, "NO\n"); - - strcat(buf, "AdjustTokenPrivileges "); - if (p_AdjustTokenPrivileges) - strcat(buf, "OK\n"); - else - strcat(buf, "NO\n"); - - strcat(buf, "LookupPrivilegeValue "); - if (p_LookupPrivilegeValue) - strcat(buf, "OK\n"); - else - strcat(buf, "NO\n"); - - MessageBox(NULL, buf, "APIs Available", MB_OK); -#endif - // Set this process to be the last application to be shut down. if (p_SetProcessShutdownParameters) { p_SetProcessShutdownParameters(0x100, 0); diff --git a/bacula/src/filed/win32/winservice.cpp b/bacula/src/filed/win32/winservice.cpp index 8c1deb6669..aa6bcafffc 100755 --- a/bacula/src/filed/win32/winservice.cpp +++ b/bacula/src/filed/win32/winservice.cpp @@ -289,7 +289,7 @@ bacService::BaculaServiceMain() } // And find the RegisterServiceProcess function - DWORD (*RegisterService)(DWORD, DWORD); + DWORD WINAPI (*RegisterService)(DWORD, DWORD); RegisterService = (DWORD (*)(DWORD, DWORD)) GetProcAddress(kerneldll, "RegisterServiceProcess"); if (RegisterService == NULL) { @@ -781,7 +781,7 @@ void LogErrorMsg(char *message, char *fname, int lineno) } LocalFree(msg); } -typedef BOOL (*WinAPI)(SC_HANDLE, DWORD, LPVOID); +typedef BOOL WINAPI (*WinAPI)(SC_HANDLE, DWORD, LPVOID); void set_service_description(SC_HANDLE hSCManager, SC_HANDLE hService, LPSTR lpDesc) diff --git a/bacula/src/findlib/attribs.c b/bacula/src/findlib/attribs.c index fc137d6b91..c8e91655d0 100755 --- a/bacula/src/findlib/attribs.c +++ b/bacula/src/findlib/attribs.c @@ -354,7 +354,6 @@ int set_win32_attributes(void *jcr, char *fname, char *ofile, char *lname, int64_t val; WIN32_FILE_ATTRIBUTE_DATA atts; ULARGE_INTEGER li; - int stat; POOLMEM *win32_ofile; if (!p || !*p) { /* we should have attributes */ @@ -391,12 +390,15 @@ int set_win32_attributes(void *jcr, char *fname, char *ofile, char *lname, p += from_base64(&val, p); atts.nFileSizeLow = val; - /* At this point, we have reconstructed the WIN32_FILE_ATTRIBUTE_DATA pkt */ - /* Convert to Windows path format */ win32_ofile = get_pool_memory(PM_FNAME); unix_name_to_win32(&win32_ofile, ofile); + + + /* At this point, we have reconstructed the WIN32_FILE_ATTRIBUTE_DATA pkt */ + + if (!is_bopen(ofd)) { Dmsg1(100, "File not open: %s\n", ofile); bopen(ofd, ofile, O_WRONLY|O_BINARY, 0); /* attempt to open the file */ @@ -404,20 +406,20 @@ int set_win32_attributes(void *jcr, char *fname, char *ofile, char *lname, if (is_bopen(ofd)) { Dmsg1(100, "SetFileTime %s\n", ofile); - stat = SetFileTime(bget_handle(ofd), + if (!SetFileTime(bget_handle(ofd), &atts.ftCreationTime, &atts.ftLastAccessTime, - &atts.ftLastWriteTime); - if (stat != 1) { + &atts.ftLastWriteTime)) { win_error(jcr, "SetFileTime:", win32_ofile); } bclose(ofd); } Dmsg1(100, "SetFileAtts %s\n", ofile); - stat = SetFileAttributes(win32_ofile, atts.dwFileAttributes & SET_ATTRS); - if (stat != 1) { - win_error(jcr, "SetFileAttributes:", win32_ofile); + if (!(atts.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + if (!SetFileAttributes(win32_ofile, atts.dwFileAttributes & SET_ATTRS)) { + win_error(jcr, "SetFileAttributes:", win32_ofile); + } } free_pool_memory(win32_ofile); return 1; @@ -438,7 +440,7 @@ void win_error(void *vjcr, char *prefix, POOLMEM *win32_ofile) NULL); Dmsg3(100, "Error in %s on file %s: ERR=%s\n", prefix, win32_ofile, msg); strip_trailing_junk(msg); - Jmsg3(jcr, M_INFO, 0, _("Error in %s file %s: ERR=%s\n"), prefix, win32_ofile, msg); + Jmsg(jcr, M_INFO, 0, _("Error in %s file %s: ERR=%s\n"), prefix, win32_ofile, msg); LocalFree(msg); } diff --git a/bacula/src/findlib/bfile.c b/bacula/src/findlib/bfile.c index 9f4ab897ef..30378c3d29 100644 --- a/bacula/src/findlib/bfile.c +++ b/bacula/src/findlib/bfile.c @@ -41,7 +41,6 @@ void binit(BFILE *bfd) { bfd->fid = -1; bfd->mode = BF_CLOSED; - bfd->use_win_api = 1; bfd->use_backup_api = p_BackupRead && p_BackupWrite; bfd->errmsg = NULL; bfd->lpContext = NULL; @@ -71,9 +70,11 @@ int is_win32_data(BFILE *bfd) HANDLE bget_handle(BFILE *bfd) { +#ifdef xxx if (!bfd->use_win_api) { return get_osfhandle(bfd->fid); } +#endif return bfd->fh; } @@ -81,6 +82,7 @@ int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode) { POOLMEM *win32_fname; +#ifdef xxx if (!bfd->use_win_api) { bfd->fid = open(fname, flags, mode); if (bfd->fid >= 0) { @@ -88,41 +90,44 @@ int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode) } return bfd->fid; } +#endif /* Convert to Windows path format */ win32_fname = get_pool_memory(PM_FNAME); unix_name_to_win32(&win32_fname, (char *)fname); - if (flags & O_WRONLY) { /* creating */ + if (flags & O_CREAT) { bfd->fh = CreateFile(win32_fname, - FILE_ALL_ACCESS|WRITE_DAC|ACCESS_SYSTEM_SECURITY, /* access */ - 0, - NULL, /* SecurityAttributes */ - CREATE_ALWAYS, /* CreationDisposition */ - FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS, /* Flags and attributes */ - NULL); /* TemplateFile */ - - if (bfd->fh == INVALID_HANDLE_VALUE) { - bfd->lerror = GetLastError(); - bfd->mode = BF_CLOSED; - } else { - bfd->mode = BF_WRITE; - } + GENERIC_WRITE|FILE_ALL_ACCESS|WRITE_OWNER|WRITE_DAC|ACCESS_SYSTEM_SECURITY, /* access */ + 0, + NULL, /* SecurityAttributes */ + CREATE_ALWAYS, /* CreationDisposition */ + FILE_FLAG_BACKUP_SEMANTICS, /* Flags and attributes */ + NULL); /* TemplateFile */ + bfd->mode = BF_WRITE; + } else if (flags & O_WRONLY) { /* creating */ + bfd->fh = CreateFile(win32_fname, + FILE_ALL_ACCESS|WRITE_OWNER|WRITE_DAC|ACCESS_SYSTEM_SECURITY, /* access */ + 0, + NULL, /* SecurityAttributes */ + OPEN_EXISTING, /* CreationDisposition */ + FILE_FLAG_BACKUP_SEMANTICS, /* Flags and attributes */ + NULL); + bfd->mode = BF_WRITE; } else { bfd->fh = CreateFile(win32_fname, - GENERIC_READ|ACCESS_SYSTEM_SECURITY, /* access */ - FILE_SHARE_READ, /* shared mode */ - NULL, /* SecurityAttributes */ - OPEN_EXISTING, /* CreationDisposition */ - FILE_FLAG_BACKUP_SEMANTICS, /* Flags and attributes */ - NULL); /* TemplateFile */ - - if (bfd->fh == INVALID_HANDLE_VALUE) { - bfd->lerror = GetLastError(); - bfd->mode = BF_CLOSED; - } else { - bfd->mode = BF_READ; - } + GENERIC_READ|READ_CONTROL|ACCESS_SYSTEM_SECURITY, /* access */ + FILE_SHARE_READ, /* shared mode */ + NULL, /* SecurityAttributes */ + OPEN_EXISTING, /* CreationDisposition */ + FILE_FLAG_BACKUP_SEMANTICS, /* Flags and attributes */ + NULL); /* TemplateFile */ + + bfd->mode = BF_READ; + } + if (bfd->fh == INVALID_HANDLE_VALUE) { + bfd->lerror = GetLastError(); + bfd->mode = BF_CLOSED; } bfd->errmsg = NULL; bfd->lpContext = NULL; @@ -136,12 +141,14 @@ int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode) int bclose(BFILE *bfd) { int stat = 0; +#ifdef xxx if (!bfd->use_win_api) { int stat = close(bfd->fid); bfd->fid = -1; bfd->mode = BF_CLOSED; return stat; } +#endif if (bfd->errmsg) { free_pool_memory(bfd->errmsg); bfd->errmsg = NULL; @@ -186,10 +193,11 @@ int bclose(BFILE *bfd) char *berror(BFILE *bfd) { LPTSTR msg; - +#ifdef xxx if (!bfd->use_win_api) { return strerror(errno); } +#endif FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER| FORMAT_MESSAGE_FROM_SYSTEM, NULL, @@ -213,9 +221,11 @@ char *berror(BFILE *bfd) */ ssize_t bread(BFILE *bfd, void *buf, size_t count) { +#ifdef xxx if (!bfd->use_win_api) { return read(bfd->fid, buf, count); } +#endif bfd->rw_bytes = 0; if (bfd->use_backup_api) { @@ -245,9 +255,11 @@ ssize_t bread(BFILE *bfd, void *buf, size_t count) ssize_t bwrite(BFILE *bfd, void *buf, size_t count) { +#ifdef xxx if (!bfd->use_win_api) { return write(bfd->fid, buf, count); } +#endif bfd->rw_bytes = 0; if (bfd->use_backup_api) { @@ -281,9 +293,12 @@ int is_bopen(BFILE *bfd) off_t blseek(BFILE *bfd, off_t offset, int whence) { +#ifdef xxx if (!bfd->use_win_api) { return lseek(bfd->fid, offset, whence); } +#endif + /* ****FIXME**** this is needed if we want to read Win32 Archives */ return -1; } diff --git a/bacula/src/findlib/bfile.h b/bacula/src/findlib/bfile.h index 3fced23ea5..1b917fa54b 100644 --- a/bacula/src/findlib/bfile.h +++ b/bacula/src/findlib/bfile.h @@ -34,31 +34,33 @@ #include "winapi.h" #define BF_CLOSED 0 -#define BF_READ 1 /* BackupRead */ -#define BF_WRITE 2 /* BackupWrite */ +#define BF_READ 1 /* BackupRead */ +#define BF_WRITE 2 /* BackupWrite */ /* In bfile.c */ /* Basic low level I/O file packet */ typedef struct s_bfile { - int use_win_api; /* set if using WinAPI */ - int 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 */ - LPVOID lpContext; /* BackupRead/Write context */ - POOLMEM *errmsg; /* error message buffer */ - DWORD rw_bytes; /* Bytes read or written */ - DWORD lerror; /* Last error code */ +#ifdef xxx + int use_win_api; /* set if using WinAPI */ +#endif + int 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 */ + LPVOID lpContext; /* BackupRead/Write context */ + POOLMEM *errmsg; /* error message buffer */ + DWORD rw_bytes; /* Bytes read or written */ + DWORD lerror; /* Last error code */ } BFILE; HANDLE bget_handle(BFILE *bfd); -#else /* Linux/Unix systems */ +#else /* Linux/Unix systems */ /* Basic low level I/O file packet */ typedef struct s_bfile { - int fid; /* file id on Unix */ + int fid; /* file id on Unix */ int berrno; } BFILE; diff --git a/bacula/src/findlib/create_file.c b/bacula/src/findlib/create_file.c index 4fef6e50f8..bf31722815 100644 --- a/bacula/src/findlib/create_file.c +++ b/bacula/src/findlib/create_file.c @@ -226,7 +226,16 @@ int create_file(void *jcr, char *fname, char *ofile, char *lname, if (make_path(jcr, ofile, new_mode, parent_mode, uid, gid, 0, NULL) != 0) { return CF_ERROR; } +#ifdef HAVE_CYGWIN + if ((bopen(ofd, ofile, O_WRONLY|O_BINARY, 0)) < 0) { + Jmsg2(jcr, M_ERROR, 0, _("Could not open %s: ERR=%s\n"), + ofile, berror(ofd)); + return CF_ERROR; + } + return CF_EXTRACT; +#else return CF_CREATED; +#endif /* The following should not occur */ case FT_NOACCESS: diff --git a/bacula/src/findlib/protos.h b/bacula/src/findlib/protos.h index 8fbec6d79f..f34f33b376 100644 --- a/bacula/src/findlib/protos.h +++ b/bacula/src/findlib/protos.h @@ -59,7 +59,7 @@ int term_find_one(FF_PKT *ff); /* From get_priv.c */ -void get_backup_privileges(void *jcr, int ignore_errors); +int get_backup_privileges(void *jcr, int ignore_errors); /* from makepath.c */ @@ -68,4 +68,3 @@ int make_path(void *jcr, const char *argpath, int mode, int preserve_existing, char *verbose_fmt_string); /* from bfile.c -- see bfile.h */ -