From a7bfff0243d524cecae67d7bd39b101f3a5095bc Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 22 Feb 2004 17:41:19 +0000 Subject: [PATCH] Fix compat.cpp times git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1066 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/findlib/enable_priv.c | 4 +- bacula/src/findlib/makepath.c | 2 +- bacula/src/lib/util.c | 41 +++++++++-------- bacula/src/version.h | 4 +- bacula/src/win32/.cvsignore | 2 + bacula/src/win32/compat/.cvsignore | 2 + bacula/src/win32/compat/compat.cpp | 74 +++++++++++++++--------------- 7 files changed, 69 insertions(+), 60 deletions(-) create mode 100644 bacula/src/win32/.cvsignore create mode 100644 bacula/src/win32/compat/.cvsignore diff --git a/bacula/src/findlib/enable_priv.c b/bacula/src/findlib/enable_priv.c index 4095ef2296..5a35d842ee 100755 --- a/bacula/src/findlib/enable_priv.c +++ b/bacula/src/findlib/enable_priv.c @@ -37,7 +37,7 @@ /* */ /*=============================================================*/ -#if !defined(HAVE_CYGWIN) && !defined(WIN32) +#if !defined(HAVE_CYGWIN) && !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(WIN32) +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) void win_error(JCR *jcr, char *prefix, DWORD lerror); diff --git a/bacula/src/findlib/makepath.c b/bacula/src/findlib/makepath.c index 2932b83e4a..69ef9c9e97 100644 --- a/bacula/src/findlib/makepath.c +++ b/bacula/src/findlib/makepath.c @@ -135,7 +135,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(WIN32) +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) return path[1] == ':' || *path == '/' || *path == '\\'; /* drivespec:/blah is absolute */ #else return *path == '/'; diff --git a/bacula/src/lib/util.c b/bacula/src/lib/util.c index 8f30486689..013c9102d3 100644 --- a/bacula/src/lib/util.c +++ b/bacula/src/lib/util.c @@ -385,12 +385,15 @@ int do_shell_expansion(char *name, int name_len) pm_strcat(&cmd, name); pm_strcat(&cmd, "\""); Dmsg1(400, "Send: %s\n", cmd); - bpipe = open_bpipe(cmd, 0, "r"); - *line = 0; - fgets(line, sizeof(line), bpipe->rfd); - strip_trailing_junk(line); - stat = close_bpipe(bpipe); - Dmsg2(400, "stat=%d got: %s\n", stat, line); + if ((bpipe = open_bpipe(cmd, 0, "r"))) { + *line = 0; + fgets(line, sizeof(line), bpipe->rfd); + strip_trailing_junk(line); + stat = close_bpipe(bpipe); + Dmsg2(400, "stat=%d got: %s\n", stat, line); + } else { + stat = 1; /* error */ + } free_pool_memory(cmd); if (stat == 0) { bstrncpy(name, line, name_len); @@ -416,7 +419,7 @@ void make_session_key(char *key, char *seed, int mode) s[0] = 0; if (seed != NULL) { - strcat(s, seed); + bstrncat(s, seed, sizeof(s)); } /* The following creates a seed for the session key generator @@ -426,11 +429,11 @@ void make_session_key(char *key, char *seed, int mode) available on your machine, replace it with something equivalent or, if you like, just delete it. */ - sprintf(s + strlen(s), "%lu", (unsigned long) getpid()); - sprintf(s + strlen(s), "%lu", (unsigned long) getppid()); + sprintf(s + strlen(s), "%lu", (unsigned long)getpid()); + sprintf(s + strlen(s), "%lu", (unsigned long)getppid()); getcwd(s + strlen(s), 256); - sprintf(s + strlen(s), "%lu", (unsigned long) clock()); - sprintf(s + strlen(s), "%lu", (unsigned long) time(NULL)); + sprintf(s + strlen(s), "%lu", (unsigned long)clock()); + sprintf(s + strlen(s), "%lu", (unsigned long)time(NULL)); #ifdef Solaris sysinfo(SI_HW_SERIAL,s + strlen(s), 12); #endif @@ -446,27 +449,27 @@ void make_session_key(char *key, char *seed, int mode) MD5Init(&md5c); MD5Update(&md5c, (unsigned char *)s, strlen(s)); MD5Final(md5key, &md5c); - sprintf(s + strlen(s), "%lu", (unsigned long) ((time(NULL) + 65121) ^ 0x375F)); + sprintf(s + strlen(s), "%lu", (unsigned long)((time(NULL) + 65121) ^ 0x375F)); MD5Init(&md5c); MD5Update(&md5c, (unsigned char *)s, strlen(s)); MD5Final(md5key1, &md5c); #define nextrand (md5key[j] ^ md5key1[j]) if (mode) { for (j = k = 0; j < 16; j++) { - unsigned char rb = nextrand; + unsigned char rb = nextrand; #define Rad16(x) ((x) + 'A') - key[k++] = Rad16((rb >> 4) & 0xF); - key[k++] = Rad16(rb & 0xF); + key[k++] = Rad16((rb >> 4) & 0xF); + key[k++] = Rad16(rb & 0xF); #undef Rad16 - if (j & 1) { - key[k++] = '-'; - } + if (j & 1) { + key[k++] = '-'; + } } key[--k] = 0; } else { for (j = 0; j < 16; j++) { - key[j] = nextrand; + key[j] = nextrand; } } } diff --git a/bacula/src/version.h b/bacula/src/version.h index d63412bcd5..55693f2402 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -2,8 +2,8 @@ #undef VERSION #define VERSION "1.33.4" #define VSTRING "1" -#define BDATE "18 Feb 2004" -#define LSMDATE "18Feb04" +#define BDATE "22 Feb 2004" +#define LSMDATE "22Feb04" /* Debug flags */ #undef DEBUG diff --git a/bacula/src/win32/.cvsignore b/bacula/src/win32/.cvsignore new file mode 100644 index 0000000000..0a398786e7 --- /dev/null +++ b/bacula/src/win32/.cvsignore @@ -0,0 +1,2 @@ +install +install-debug diff --git a/bacula/src/win32/compat/.cvsignore b/bacula/src/win32/compat/.cvsignore new file mode 100644 index 0000000000..0a398786e7 --- /dev/null +++ b/bacula/src/win32/compat/.cvsignore @@ -0,0 +1,2 @@ +install +install-debug diff --git a/bacula/src/win32/compat/compat.cpp b/bacula/src/win32/compat/compat.cpp index ebdf82ba82..048a11a985 100644 --- a/bacula/src/win32/compat/compat.cpp +++ b/bacula/src/win32/compat/compat.cpp @@ -176,15 +176,18 @@ srandom(unsigned int seed) // convert from Windows concept of time to Unix concept of time // ///////////////////////////////////////////////////////////////// time_t -cvt(const FILETIME &time) +cvt_ftime_to_utime(const FILETIME &time) { uint64_t mstime = time.dwHighDateTime; mstime <<= 32; mstime |= time.dwLowDateTime; - mstime /= 10000000; // convert to seconds. - mstime -= 3234336I64*3600I64; // difference between jan 1, 1601 +// mstime /= 10000000; // convert to seconds. +// mstime -= 3234336I64*3600I64; // difference between jan 1, 1601 // and jan, 1 1970 + mstime -= 116444736000000000; // convert to 1 Jan 1970 + mstime /= 10000000; // convert to seconds. + return (time_t) (mstime & 0xffffffff); } @@ -211,11 +214,10 @@ static int statDir(const char *file, struct stat *sb) { WIN32_FIND_DATA info; // window's file info - sb->st_mode |= S_IFDIR; - if (file[1] == ':' && file[2] == 0) - { + if (file[1] == ':' && file[2] == 0) { d_msg(__FILE__, __LINE__, 99, "faking ROOT attrs(%s).\n", file); + sb->st_mode = S_IFDIR; sb->st_mode |= S_IREAD|S_IEXEC|S_IWRITE; time(&sb->st_ctime); time(&sb->st_mtime); @@ -232,22 +234,23 @@ statDir(const char *file, struct stat *sb) return -1; } - sb->st_mode |= (S_IREAD | S_IEXEC); - if (!(info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) - sb->st_mode |= S_IWRITE; - + sb->st_mode = 0777; /* start with everything */ + if (info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) + sb->st_mode &= ~(S_IRUSR|S_IRGRP|S_IROTH); if (info.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) - sb->st_mode |= S_IRGRP; + sb->st_mode &= ~S_IRWXO; /* remove everything for other */ if (info.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) - sb->st_mode |= S_IROTH; + sb->st_mode |= S_ISVTX; /* use sticky bit -> hidden */ + sb->st_mode |= S_IFDIR; + sb->st_size = info.nFileSizeHigh; sb->st_size <<= 32; sb->st_size |= info.nFileSizeLow; sb->st_blksize = 4096; sb->st_blocks = (uint32_t)(sb->st_size + 4095)/4096; - sb->st_atime = cvt(info.ftLastAccessTime); - sb->st_mtime = cvt(info.ftLastWriteTime); - sb->st_ctime = cvt(info.ftCreationTime); + sb->st_atime = cvt_ftime_to_utime(info.ftLastAccessTime); + sb->st_mtime = cvt_ftime_to_utime(info.ftLastWriteTime); + sb->st_ctime = cvt_ftime_to_utime(info.ftLastWriteTime); return 0; } @@ -275,8 +278,6 @@ stat2(const char *file, struct stat *sb) if (attr & FILE_ATTRIBUTE_DIRECTORY) return statDir(tmpbuf, sb); - sb->st_mode |= S_IFREG; - h = CreateFile(tmpbuf, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); @@ -305,22 +306,24 @@ stat2(const char *file, struct stat *sb) sb->st_ino <<= 32; sb->st_ino |= info.nFileIndexLow; sb->st_nlink = (short)info.nNumberOfLinks; - sb->st_mode |= (S_IREAD | S_IEXEC); - if (!(info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) - sb->st_mode |= S_IWRITE; + sb->st_mode = 0777; /* start with everything */ + if (info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) + sb->st_mode &= ~(S_IRUSR|S_IRGRP|S_IROTH); if (info.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) - sb->st_mode |= S_IRGRP; + sb->st_mode &= ~S_IRWXO; /* remove everything for other */ if (info.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) - sb->st_mode |= S_IROTH; + sb->st_mode |= S_ISVTX; /* use sticky bit -> hidden */ + sb->st_mode |= S_IFREG; + sb->st_size = info.nFileSizeHigh; sb->st_size <<= 32; sb->st_size |= info.nFileSizeLow; sb->st_blksize = 4096; sb->st_blocks = (uint32_t)(sb->st_size + 4095)/4096; - sb->st_atime = cvt(info.ftLastAccessTime); - sb->st_mtime = cvt(info.ftLastWriteTime); - sb->st_ctime = cvt(info.ftCreationTime); + sb->st_atime = cvt_ftime_to_utime(info.ftLastAccessTime); + sb->st_mtime = cvt_ftime_to_utime(info.ftLastWriteTime); + sb->st_ctime = cvt_ftime_to_utime(info.ftLastWriteTime); error: CloseHandle(h); @@ -341,28 +344,27 @@ stat(const char *file, struct stat *sb) if (!GetFileAttributesEx(file, GetFileExInfoStandard, &data)) return stat2(file, sb); + sb->st_mode = 0777; /* start with everything */ + if (data.dwFileAttributes & FILE_ATTRIBUTE_READONLY) + sb->st_mode &= ~(S_IRUSR|S_IRGRP|S_IROTH); + if (data.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) + sb->st_mode &= ~S_IRWXO; /* remove everything for other */ + if (data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) + sb->st_mode |= S_ISVTX; /* use sticky bit -> hidden */ if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) sb->st_mode |= S_IFDIR; else sb->st_mode |= S_IFREG; sb->st_nlink = 1; - sb->st_mode |= (S_IREAD | S_IEXEC); - if (!(data.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) - sb->st_mode |= S_IWRITE; - - if (data.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) - sb->st_mode |= S_IRGRP; - if (data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) - sb->st_mode |= S_IROTH; sb->st_size = data.nFileSizeHigh; sb->st_size <<= 32; sb->st_size |= data.nFileSizeLow; sb->st_blksize = 4096; sb->st_blocks = (uint32_t)(sb->st_size + 4095)/4096; - sb->st_atime = cvt(data.ftLastAccessTime); - sb->st_mtime = cvt(data.ftLastWriteTime); - sb->st_ctime = cvt(data.ftCreationTime); + sb->st_atime = cvt_ftime_to_utime(data.ftLastAccessTime); + sb->st_mtime = cvt_ftime_to_utime(data.ftLastWriteTime); + sb->st_ctime = cvt_ftime_to_utime(data.ftLastWriteTime); return 0; } -- 2.39.5