]> git.sur5r.net Git - bacula/bacula/commitdiff
Major part of Win32 BackupRead/Write done
authorKern Sibbald <kern@sibbald.com>
Sun, 18 May 2003 20:42:15 +0000 (20:42 +0000)
committerKern Sibbald <kern@sibbald.com>
Sun, 18 May 2003 20:42:15 +0000 (20:42 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@517 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/kernstodo
bacula/src/filed/backup.c
bacula/src/filed/job.c
bacula/src/filed/status.c
bacula/src/filed/win32/winmain.cpp
bacula/src/filed/win32/winservice.cpp
bacula/src/findlib/attribs.c
bacula/src/findlib/bfile.c
bacula/src/findlib/bfile.h
bacula/src/findlib/create_file.c
bacula/src/findlib/protos.h

index 8351a53da20f097372df31bd9b870cd4bc5fd03a..909f328a67a2c01cb7d4150587bdee38b2072064 100644 (file)
@@ -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
index 81ced4d798a7e3014ee6881b159c6a137a17bbab..2338290b4b156b4eb3c158a72f6abc55b4dc0873 100644 (file)
@@ -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);
index 8cb24a5672ed42105d429c6735aaa0f8601255ec..814b7e003b3aff1177c2ab60d396a205c5fb9ad4 100644 (file)
@@ -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);
 }
index e0c1054de6c9fcac7ac43234d70d7bd978d954ea..24ac1891704227b3102504bfe8490ca2392f057e 100755 (executable)
@@ -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];
 
index 4acbb3c2d0480d47662af10fe6d79b7a658870bd..ccb1cfff6e2b749e5ef3e93e44d259faa8c22b00 100755 (executable)
@@ -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);
index 8c1deb6669a157b95f8d253d697c1c3c58043724..aa6bcafffcccdd18beebe890758bf776bd6a0c19 100755 (executable)
@@ -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) 
index fc137d6b91820f50f781885ef4f3064a3ef76283..c8e91655d0a96165004dd94c5cf6dfe815c8160e 100755 (executable)
@@ -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);
 }
 
index 9f4ab897ef25716db966f444d39a6c24b77d15e8..30378c3d291513d22e622c655d3f9d78c0629d4f 100644 (file)
@@ -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;
 }
 
index 3fced23ea53ce78a233c17e8e732736e0ceae6b7..1b917fa54b5c37fe9e2c25bb783a099ed86955d2 100644 (file)
 #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;
 
index 4fef6e50f87252e7c0ea934c71721d4a8d2c0844..bf31722815d7e6fcf1c227e1117d4cd75fcb3dd6 100644 (file)
@@ -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:
index 8fbec6d79fa7dfd22b4116696fa9e368511ff08a..f34f33b376cf7fd4e648d829a3c40dacd4622c74 100644 (file)
@@ -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 */
-