int win32_utime(const char *fname, struct utimbuf *times) { FILETIME acc; FILETIME mod; char tmpbuf[5000]; conv_unix_to_win32_path(fname, tmpbuf, 5000); cvt_utime_to_ftime(times->actime, acc); cvt_utime_to_ftime(times->modtime, mod); HANDLE h=INVALID_HANDLE_VALUE; if(p_CreateFileW) { char* pwszBuf=sm_get_pool_memory(PM_FNAME); make_win32_path_UTF8_2_wchar(&pwszBuf, tmpbuf); h=p_CreateFileW((LPCWSTR)pwszBuf, FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE |FILE_SHARE_READ |FILE_SHARE_DELETE, NULL, OPEN_EXISTING, // required for directories FILE_FLAG_BACKUP_SEMANTICS, NULL); sm_free_pool_memory(pwszBuf); } else if(p_CreateFileA) { h=p_CreateFileA(tmpbuf, FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE |FILE_SHARE_READ |FILE_SHARE_DELETE, NULL, OPEN_EXISTING, // required for directories FILE_FLAG_BACKUP_SEMANTICS, NULL); } if(h==INVALID_HANDLE_VALUE) { const char *err=errorString(); fprintf(stderr, "Cannot open %s for utime(): ERR=%s\n", tmpbuf, err); LocalFree((void *)err); errno=b_errno_win32; return -1; } int rval=SetFileTime(h, NULL, &acc, &mod)?0:-1; CloseHandle(h); if(rval==-1) errno=b_errno_win32; return rval; }
static inline int bopen_nonencrypted(BFILE *bfd, const char *fname, int flags, mode_t mode) { POOLMEM *win32_fname; POOLMEM *win32_fname_wchar; DWORD dwaccess, dwflags, dwshare; /* * Convert to Windows path format */ win32_fname = get_pool_memory(PM_FNAME); win32_fname_wchar = get_pool_memory(PM_FNAME); unix_name_to_win32(&win32_fname, (char *)fname); if (bfd->cmd_plugin && plugin_bopen) { int rtnstat; Dmsg1(50, "call plugin_bopen fname=%s\n", fname); rtnstat = plugin_bopen(bfd, fname, flags, mode); Dmsg1(50, "return from plugin_bopen status=%d\n", rtnstat); if (rtnstat >= 0) { if (flags & O_CREAT || flags & O_WRONLY) { /* Open existing for write */ Dmsg1(50, "plugin_open for write OK file=%s.\n", fname); bfd->mode = BF_WRITE; } else { Dmsg1(50, "plugin_open for read OK file=%s.\n", fname); bfd->mode = BF_READ; } } else { bfd->mode = BF_CLOSED; Dmsg1(000, "==== plugin_bopen returned bad status=%d\n", rtnstat); } free_pool_memory(win32_fname_wchar); free_pool_memory(win32_fname); return bfd->mode == BF_CLOSED ? -1 : 1; } Dmsg0(50, "=== NO plugin\n"); if (!(p_CreateFileA || p_CreateFileW)) { Dmsg0(50, "No CreateFileA and no CreateFileW!!!!!\n"); return 0; } if (p_CreateFileW && p_MultiByteToWideChar) { make_win32_path_UTF8_2_wchar(&win32_fname_wchar, fname); } if (flags & O_CREAT) { /* Create */ if (bfd->use_backup_api) { dwaccess = GENERIC_WRITE | FILE_ALL_ACCESS | WRITE_OWNER | WRITE_DAC | ACCESS_SYSTEM_SECURITY; dwflags = FILE_FLAG_BACKUP_SEMANTICS; } else { dwaccess = GENERIC_WRITE; dwflags = 0; } /* * Unicode open for create write */ if (p_CreateFileW && p_MultiByteToWideChar) { Dmsg1(100, "Create CreateFileW=%s\n", win32_fname); bfd->fh = p_CreateFileW((LPCWSTR)win32_fname_wchar, dwaccess, /* Requested access */ 0, /* Shared mode */ NULL, /* SecurityAttributes */ CREATE_ALWAYS, /* CreationDisposition */ dwflags, /* Flags and attributes */ NULL); /* TemplateFile */ } else { /* * ASCII open */ Dmsg1(100, "Create CreateFileA=%s\n", win32_fname); bfd->fh = p_CreateFileA(win32_fname, dwaccess, /* Requested access */ 0, /* Shared mode */ NULL, /* SecurityAttributes */ CREATE_ALWAYS, /* CreationDisposition */ dwflags, /* Flags and attributes */ NULL); /* TemplateFile */ } bfd->mode = BF_WRITE; } else if (flags & O_WRONLY) { /* * Open existing for write */ if (bfd->use_backup_api) { dwaccess = GENERIC_WRITE | WRITE_OWNER | WRITE_DAC; if (flags & O_NOFOLLOW) { dwflags = FILE_FLAG_BACKUP_SEMANTICS; } else { dwflags = FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT; } } else { dwaccess = GENERIC_WRITE; dwflags = 0; } if (p_CreateFileW && p_MultiByteToWideChar) { /* * unicode open for open existing write */ Dmsg1(100, "Write only CreateFileW=%s\n", win32_fname); bfd->fh = p_CreateFileW((LPCWSTR)win32_fname_wchar, dwaccess, /* Requested access */ 0, /* Shared mode */ NULL, /* SecurityAttributes */ OPEN_EXISTING, /* CreationDisposition */ dwflags, /* Flags and attributes */ NULL); /* TemplateFile */ } else { /* * ASCII open */ Dmsg1(100, "Write only CreateFileA=%s\n", win32_fname); bfd->fh = p_CreateFileA(win32_fname, dwaccess, /* Requested access */ 0, /* Shared mode */ NULL, /* SecurityAttributes */ OPEN_EXISTING, /* CreationDisposition */ dwflags, /* Flags and attributes */ NULL); /* TemplateFile */ } bfd->mode = BF_WRITE; } else { /* * Open existing for read */ if (bfd->use_backup_api) { dwaccess = GENERIC_READ | READ_CONTROL | ACCESS_SYSTEM_SECURITY; if (flags & O_NOFOLLOW) { dwflags = FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_SEQUENTIAL_SCAN; } else { dwflags = FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OPEN_REPARSE_POINT; } dwshare = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; } else { dwaccess = GENERIC_READ; dwflags = 0; dwshare = FILE_SHARE_READ | FILE_SHARE_WRITE; } if (p_CreateFileW && p_MultiByteToWideChar) { /* * Unicode open for open existing read */ Dmsg1(100, "Read CreateFileW=%s\n", win32_fname); bfd->fh = p_CreateFileW((LPCWSTR)win32_fname_wchar, dwaccess, /* Requested access */ dwshare, /* Share modes */ NULL, /* SecurityAttributes */ OPEN_EXISTING, /* CreationDisposition */ dwflags, /* Flags and attributes */ NULL); /* TemplateFile */ } else { /* * ASCII open for open existing read */ Dmsg1(100, "Read CreateFileA=%s\n", win32_fname); bfd->fh = p_CreateFileA(win32_fname, dwaccess, /* Requested access */ dwshare, /* Share modes */ NULL, /* SecurityAttributes */ OPEN_EXISTING, /* CreationDisposition */ dwflags, /* Flags and attributes */ NULL); /* TemplateFile */ } bfd->mode = BF_READ; } if (bfd->fh == INVALID_HANDLE_VALUE) { bfd->lerror = GetLastError(); bfd->berrno = b_errno_win32; errno = b_errno_win32; bfd->mode = BF_CLOSED; } bfd->errmsg = NULL; bfd->lpContext = NULL; bfd->win32DecompContext.bIsInData = false; bfd->win32DecompContext.liNextHeader = 0; free_pool_memory(win32_fname_wchar); free_pool_memory(win32_fname); bfd->encrypted = false; return bfd->mode == BF_CLOSED ? -1 : 1; }