Exemple #1
0
static int win32_chmod_new(const char *path, int64_t winattr)
{
	//if(winattr & FILE_ATTRIBUTE_ENCRYPTED)
	//	printf("\n   %s was encrypted!\n", path);
	DWORD attr=(DWORD)-1;

	if(p_GetFileAttributesW)
	{
		char *pwszBuf=sm_get_pool_memory(PM_FNAME);
		make_win32_path_UTF8_2_wchar(&pwszBuf, path);

		attr=p_GetFileAttributesW((LPCWSTR) pwszBuf);
		if(attr!=INVALID_FILE_ATTRIBUTES)
			attr=p_SetFileAttributesW((LPCWSTR)pwszBuf,
				winattr & SET_ATTRS);
		sm_free_pool_memory(pwszBuf);
	}
	else if(p_GetFileAttributesA)
	{
		attr=p_GetFileAttributesA(path);
		if(attr!=INVALID_FILE_ATTRIBUTES)
			winattr=p_SetFileAttributesA(path, attr & SET_ATTRS);
	}

	if(attr==(DWORD)-1)
	{
		const char *err=errorString();
		LocalFree((void *)err);
		errno=b_errno_win32;
		return -1;
	}
	return 0;
}
Exemple #2
0
static int win32_chmod_old(const char *path, mode_t mode)
{
	DWORD attr=(DWORD)-1;

	if(p_GetFileAttributesW)
	{
		char *pwszBuf=sm_get_pool_memory(PM_FNAME);
		make_win32_path_UTF8_2_wchar(&pwszBuf, path);

		attr=p_GetFileAttributesW((LPCWSTR)pwszBuf);
		if(attr!=INVALID_FILE_ATTRIBUTES)
		{
			// Use Burp mappings defined in stat() above.
			if(!(mode & (S_IRUSR|S_IRGRP|S_IROTH)))
				attr |= FILE_ATTRIBUTE_READONLY;
			else
				attr &= ~FILE_ATTRIBUTE_READONLY;
			if(!(mode & S_IRWXO))
				attr |= FILE_ATTRIBUTE_SYSTEM;
			else
				attr &= ~FILE_ATTRIBUTE_SYSTEM;
			if(mode & S_ISVTX)
				attr |= FILE_ATTRIBUTE_HIDDEN;
			else
				attr &= ~FILE_ATTRIBUTE_HIDDEN;
			attr=p_SetFileAttributesW((LPCWSTR)pwszBuf, attr);
		}
		sm_free_pool_memory(pwszBuf);
	}
	else if (p_GetFileAttributesA)
	{
		if(!(mode & (S_IRUSR|S_IRGRP|S_IROTH)))
			attr |= FILE_ATTRIBUTE_READONLY;
		else
			attr &= ~FILE_ATTRIBUTE_READONLY;
		if(!(mode & S_IRWXO))
			attr |= FILE_ATTRIBUTE_SYSTEM;
		else
			attr &= ~FILE_ATTRIBUTE_SYSTEM;
		if(mode & S_ISVTX)
			attr |= FILE_ATTRIBUTE_HIDDEN;
		else
			attr &= ~FILE_ATTRIBUTE_HIDDEN;
		attr=p_GetFileAttributesA(path);
		if(attr!=INVALID_FILE_ATTRIBUTES)
			attr=p_SetFileAttributesA(path, attr);
	}

	if(attr==(DWORD)-1)
	{
		const char *err=errorString();
		LocalFree((void *)err);
		errno=b_errno_win32;
		return -1;
	}
	return 0;
}
Exemple #3
0
/**
 * Set Extended File Attributes for Win32
 *
 *  fname is the original filename
 *  ofile is the output filename (may be in a different directory)
 *
 * Returns:  true  on success
 *           false on failure
 */
static bool set_win32_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
{
   char *p = attr->attrEx;
   int64_t val;
   WIN32_FILE_ATTRIBUTE_DATA atts;
   ULARGE_INTEGER li;
   POOLMEM *win32_ofile;

   /** if we have neither Win ansi nor wchar API, get out */
   if (!(p_SetFileAttributesW || p_SetFileAttributesA)) {
      return false;
   }

   if (!p || !*p) {                   /* we should have attributes */
      Dmsg2(100, "Attributes missing. of=%s ofd=%d\n", attr->ofname, ofd->fid);
      if (is_bopen(ofd)) {
         bclose(ofd);
      }
      return false;
   } else {
      Dmsg2(100, "Attribs %s = %s\n", attr->ofname, attr->attrEx);
   }

   p += from_base64(&val, p);
   plug(atts.dwFileAttributes, val);
   p++;                               /* skip space */
   p += from_base64(&val, p);
   li.QuadPart = val;
   atts.ftCreationTime.dwLowDateTime = li.LowPart;
   atts.ftCreationTime.dwHighDateTime = li.HighPart;
   p++;                               /* skip space */
   p += from_base64(&val, p);
   li.QuadPart = val;
   atts.ftLastAccessTime.dwLowDateTime = li.LowPart;
   atts.ftLastAccessTime.dwHighDateTime = li.HighPart;
   p++;                               /* skip space */
   p += from_base64(&val, p);
   li.QuadPart = val;
   atts.ftLastWriteTime.dwLowDateTime = li.LowPart;
   atts.ftLastWriteTime.dwHighDateTime = li.HighPart;
   p++;
   p += from_base64(&val, p);
   plug(atts.nFileSizeHigh, val);
   p++;
   p += from_base64(&val, p);
   plug(atts.nFileSizeLow, val);

   /** Convert to Windows path format */
   win32_ofile = get_pool_memory(PM_FNAME);
   unix_name_to_win32(&win32_ofile, attr->ofname);

   /** At this point, we have reconstructed the WIN32_FILE_ATTRIBUTE_DATA pkt */

   if (!is_bopen(ofd)) {
      Dmsg1(100, "File not open: %s\n", attr->ofname);
      bopen(ofd, attr->ofname, O_WRONLY|O_BINARY, 0);   /* attempt to open the file */
   }

   if (is_bopen(ofd)) {
      Dmsg1(100, "SetFileTime %s\n", attr->ofname);
      if (!SetFileTime(bget_handle(ofd),
                         &atts.ftCreationTime,
                         &atts.ftLastAccessTime,
                         &atts.ftLastWriteTime)) {
         win_error(jcr, "SetFileTime:", win32_ofile);
      }
      bclose(ofd);
   }

   Dmsg1(100, "SetFileAtts %s\n", attr->ofname);
   if (!(atts.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
      if (p_SetFileAttributesW) {
         POOLMEM* pwszBuf = get_pool_memory(PM_FNAME);   
         make_win32_path_UTF8_2_wchar(&pwszBuf, attr->ofname);

         BOOL b=p_SetFileAttributesW((LPCWSTR)pwszBuf, atts.dwFileAttributes & SET_ATTRS);
         free_pool_memory(pwszBuf);
      
         if (!b) 
            win_error(jcr, "SetFileAttributesW:", win32_ofile); 
      }
      else {
         if (!p_SetFileAttributesA(win32_ofile, atts.dwFileAttributes & SET_ATTRS)) {
            win_error(jcr, "SetFileAttributesA:", win32_ofile);
         }
      }
   }
   free_pool_memory(win32_ofile);
   return true;
}
Exemple #4
0
int win32_unlink(const char *filename)
{
	int nRetCode;
	if(p_wunlink)
	{
		char* pwszBuf=sm_get_pool_memory(PM_FNAME);
		make_win32_path_UTF8_2_wchar(&pwszBuf, filename);

		nRetCode=_wunlink((LPCWSTR) pwszBuf);

		/* Special case if file is readonly,
		   we retry but unset attribute before. */
		if(nRetCode==-1
		  && errno==EACCES
		  && p_SetFileAttributesW
		  && p_GetFileAttributesW)
		{
			DWORD dwAttr=p_GetFileAttributesW((LPCWSTR)pwszBuf);
			if(dwAttr!=INVALID_FILE_ATTRIBUTES)
			{
				if(p_SetFileAttributesW((LPCWSTR)pwszBuf,
				  dwAttr & ~FILE_ATTRIBUTE_READONLY))
				{
					nRetCode=_wunlink((LPCWSTR) pwszBuf);
					// Reset to original if it didn't help.
					if(nRetCode==-1)
						p_SetFileAttributesW(
						  (LPCWSTR)pwszBuf, dwAttr);
				}
			}
		}
		sm_free_pool_memory(pwszBuf);
	}
	else
	{
		nRetCode=_unlink(filename);

		/* special case if file is readonly,
		   we retry but unset attribute before. */
		if(nRetCode==-1
		  && errno==EACCES
		  && p_SetFileAttributesA
		  && p_GetFileAttributesA)
		{
			DWORD dwAttr=p_GetFileAttributesA(filename);
			if(dwAttr!=INVALID_FILE_ATTRIBUTES)
			{
				if(p_SetFileAttributesA(filename,
				  dwAttr & ~FILE_ATTRIBUTE_READONLY))
				{
					nRetCode=_unlink(filename);
					// Reset to original if it didn't help.
					if(nRetCode==-1)
						p_SetFileAttributesA(
						  filename, dwAttr);
				}
			}
		}
	}
	return nRetCode;
}