]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/winapi.c
- Fix seg fault if user labels a drive directory bug #513
[bacula/bacula] / bacula / src / lib / winapi.c
index 9a5f6532cf936323d2e279ad51b7b4e39a35142a..c23d25f4cdf61026e59e17401e8ca58db2f881ea 100644 (file)
@@ -6,22 +6,17 @@
  *     Kern Sibbald MMIII
  */
 /*
-   Copyright (C) 2000-2005 Kern Sibbald
+   Copyright (C) 2003-2005 Kern Sibbald
 
    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 of
-   the License, or (at your option) any later version.
+   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 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.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
 
 #include "winapi.h"
 
+#ifdef WIN32_VSS
+#include "vss.h"   
+#endif
+
 // init with win9x, but maybe set to NT in InitWinAPI
 DWORD  g_platform_id = VER_PLATFORM_WIN32_WINDOWS;
+#ifdef WIN32_VSS
+/* preset VSSClient to NULL */
+VSSClient *g_pVSSClient = NULL;
+#endif
 
 
 /* API Pointers */
@@ -50,9 +53,6 @@ t_wunlink p_wunlink = NULL;
 t_wmkdir p_wmkdir = NULL;
 t_wopen p_wopen = NULL;
 
-t_cgetws p_cgetws = NULL;
-t_cwprintf p_cwprintf = NULL;
-
 t_GetFileAttributesA    p_GetFileAttributesA = NULL;
 t_GetFileAttributesW    p_GetFileAttributesW = NULL;
 
@@ -78,6 +78,17 @@ t_SetCurrentDirectoryW p_SetCurrentDirectoryW = NULL;
 t_GetCurrentDirectoryA p_GetCurrentDirectoryA = NULL;
 t_GetCurrentDirectoryW p_GetCurrentDirectoryW = NULL;
 
+t_GetVolumePathNameW p_GetVolumePathNameW = NULL;
+t_GetVolumeNameForVolumeMountPointW p_GetVolumeNameForVolumeMountPointW = NULL;
+
+#ifdef WIN32_VSS
+void 
+VSSCleanup()
+{
+   if (g_pVSSClient)
+      delete (g_pVSSClient);
+}
+#endif
 
 void 
 InitWinAPIWrapper() 
@@ -135,6 +146,14 @@ InitWinAPIWrapper()
           GetProcAddress(hLib, "GetCurrentDirectoryA");
       p_GetCurrentDirectoryW = (t_GetCurrentDirectoryW)
           GetProcAddress(hLib, "GetCurrentDirectoryW");      
+
+      /* some special stuff we need for VSS
+         but statically linkage doesn't work on Win 9x */
+      p_GetVolumePathNameW = (t_GetVolumePathNameW)
+          GetProcAddress(hLib, "GetVolumePathNameW");
+      p_GetVolumeNameForVolumeMountPointW = (t_GetVolumeNameForVolumeMountPointW)
+          GetProcAddress(hLib, "GetVolumeNameForVolumeMountPointW");
+    
       FreeLibrary(hLib);
    }
    
@@ -149,14 +168,7 @@ InitWinAPIWrapper()
       /* wopen */
       p_wopen = (t_wopen)
       GetProcAddress(hLib, "_wopen");
-      
-      /* cgetws */
-      p_cgetws = (t_cgetws)
-      GetProcAddress (hLib, "_cgetws");
-      /* cwprintf */
-      p_cwprintf = (t_cwprintf)
-      GetProcAddress (hLib, "_cwprintf");
-      
+        
       FreeLibrary(hLib);
    }
    
@@ -172,16 +184,21 @@ InitWinAPIWrapper()
    }
 
    // do we run on win 9x ???
-   OSVERSIONINFO osversioninfo;
+   OSVERSIONINFO osversioninfo;   
    osversioninfo.dwOSVersionInfoSize = sizeof(osversioninfo);
 
+   DWORD dwMinorVersion;
+
    // Get the current OS version
    if (!GetVersionEx(&osversioninfo)) {
       g_platform_id = 0;
+      dwMinorVersion = 0;
    } else {
       g_platform_id = osversioninfo.dwPlatformId;
+      dwMinorVersion = osversioninfo.dwMinorVersion;
    }
 
+   /* deinitialize some routines on win95 - they're not implemented well */
    if (g_platform_id == VER_PLATFORM_WIN32_WINDOWS) {
       p_BackupRead = NULL;
       p_BackupWrite = NULL;
@@ -200,6 +217,24 @@ InitWinAPIWrapper()
       p_wunlink = NULL;
       p_wmkdir = NULL;
       p_wopen = NULL;
+
+      p_GetVolumePathNameW = NULL;
+      p_GetVolumeNameForVolumeMountPointW = NULL;
    }   
+
+   /* decide which vss class to initialize */
+#ifdef WIN32_VSS
+   switch (dwMinorVersion) {
+      case 1: 
+         g_pVSSClient = new VSSClientXP();
+         atexit(VSSCleanup);
+         break;
+      case 2: 
+         g_pVSSClient = new VSSClient2003();
+         atexit(VSSCleanup);
+         break;
+   }
+#endif /* WIN32_VSS */
 }
+
 #endif