Пример #1
0
int encode_attribsEx(JCR *jcr, char *attribsEx, FF_PKT *ff_pkt)
{
   char *p = attribsEx;
   WIN32_FILE_ATTRIBUTE_DATA atts;
   ULARGE_INTEGER li;

   attribsEx[0] = 0;                  /* no extended attributes */

   if (jcr->cmd_plugin || ff_pkt->type == FT_DELETED) {
      return STREAM_UNIX_ATTRIBUTES;
   }

   unix_name_to_win32(&ff_pkt->sys_fname, ff_pkt->fname);

   /** try unicode version */
   if (p_GetFileAttributesExW)  {
      POOLMEM* pwszBuf = get_pool_memory(PM_FNAME);   
      make_win32_path_UTF8_2_wchar(&pwszBuf, ff_pkt->fname);

      BOOL b=p_GetFileAttributesExW((LPCWSTR)pwszBuf, GetFileExInfoStandard, 
                                    (LPVOID)&atts);
      free_pool_memory(pwszBuf);

      if (!b) {
         win_error(jcr, "GetFileAttributesExW:", ff_pkt->sys_fname);
         return STREAM_UNIX_ATTRIBUTES;
      }
   }
   else {
      if (!p_GetFileAttributesExA)
         return STREAM_UNIX_ATTRIBUTES;      

      if (!p_GetFileAttributesExA(ff_pkt->sys_fname, GetFileExInfoStandard,
                              (LPVOID)&atts)) {
         win_error(jcr, "GetFileAttributesExA:", ff_pkt->sys_fname);
         return STREAM_UNIX_ATTRIBUTES;
      }
   }

   p += to_base64((uint64_t)atts.dwFileAttributes, p);
   *p++ = ' ';                        /* separate fields with a space */
   li.LowPart = atts.ftCreationTime.dwLowDateTime;
   li.HighPart = atts.ftCreationTime.dwHighDateTime;
   p += to_base64((uint64_t)li.QuadPart, p);
   *p++ = ' ';
   li.LowPart = atts.ftLastAccessTime.dwLowDateTime;
   li.HighPart = atts.ftLastAccessTime.dwHighDateTime;
   p += to_base64((uint64_t)li.QuadPart, p);
   *p++ = ' ';
   li.LowPart = atts.ftLastWriteTime.dwLowDateTime;
   li.HighPart = atts.ftLastWriteTime.dwHighDateTime;
   p += to_base64((uint64_t)li.QuadPart, p);
   *p++ = ' ';
   p += to_base64((uint64_t)atts.nFileSizeHigh, p);
   *p++ = ' ';
   p += to_base64((uint64_t)atts.nFileSizeLow, p);
   *p = 0;
   return STREAM_UNIX_ATTRIBUTES_EX;
}
Пример #2
0
BOOL make_relative_sid(PSID* answer, PSID base, ULONG relative_id)
{
  int     count;
  int     i;

  if (answer == NULL)
    return print_error(L"Error in make_relative_sid: answer is NULL.\n");

  if (base == NULL)
    return print_error(L"Error in make_relative_sid: base is NULL.\n");

  if (!IsValidSid(base))
    return print_error(L"Error in make_relative_sid: base is not a valid SID.\n");

  count = *GetSidSubAuthorityCount(base);
  if (count > 7)
    return print_error(L"Error in make_relative_sid: base has too many sub-authorities.\n");

  if (!AllocateAndInitializeSid( GetSidIdentifierAuthority(base)
                               , 1 + count
                               , 0, 0, 0, 0, 0, 0, 0, 0, answer))
    return win_error(GetLastError(), L"AllocateAndInitializeSid");

  for(i=0; i<count; i++)
  {
    *GetSidSubAuthority(*answer, i) = *GetSidSubAuthority(base, i);
  }

  *GetSidSubAuthority(*answer, count) = relative_id;

  return TRUE;
}
Пример #3
0
static int
create_pipes(p_options *info)
{ int i;
  SECURITY_ATTRIBUTES sa;

  sa.nLength = sizeof(sa);          /* Length in bytes */
  sa.bInheritHandle = 1;            /* the child must inherit these handles */
  sa.lpSecurityDescriptor = NULL;

  for(i=0; i<3; i++)
  { p_stream *s = &info->streams[i];

    if ( s->term )
    { if ( i == 2 && info->streams[1].term &&
	   PL_compare(info->streams[1].term, info->streams[2].term) == 0 )
      { s->fd[0] = info->streams[1].fd[0];
	s->fd[1] = info->streams[1].fd[1];
      } else
      { if ( !CreatePipe(&s->fd[0], &s->fd[1], &sa, 1<<13) )
	{ return win_error("CreatePipe");
	}
      }
    }
  }

  return TRUE;
}
Пример #4
0
void gcb_set_filedump(GtkWidget *w, GtkWidget *entry)
{
	char *file;
	struct encdata *enc;

	enc = (struct encdata *) g_object_get_data(G_OBJECT(entry), "enc");
	
	/* encoder is configured yet */

	if(GTK_TOGGLE_BUTTON(w)->active) {
		file = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
		notice(_("enc->outchan->dump_start(%s)"), file);	

		if((strlen(file)))
			enc->outchan->dump_start(
			g_filename_from_utf8(file, -1, NULL, NULL, NULL));
		else {
			error(_("gcb_set_filedump:: Not a valid filename"));
			win_error(_("You have to insert a filename!!"));
		}
		g_free(file);
	}
	else
		enc->outchan->dump_stop(); 
}
Пример #5
0
win_error impl_fuse_context::create_file(LPCWSTR file_name, DWORD access_mode, 
								   DWORD share_mode, DWORD creation_disposition, 
								   DWORD flags_and_attributes, 
								   PDOKAN_FILE_INFO dokan_file_info)
{
	std::string fname=unixify(wchar_to_utf8_cstr(file_name));
	dokan_file_info->Context=0;

	if (!ops_.getattr)
		return -EINVAL;

	struct FUSE_STAT stbuf={0};
	//Check if the target file/directory exists
	if (ops_.getattr(fname.c_str(),&stbuf)<0)
	{
		//Nope.		
		if (dokan_file_info->IsDirectory) 
			return -EINVAL; //We can't create directories using CreateFile
		return do_create_file(file_name, creation_disposition, share_mode, access_mode,
			dokan_file_info);
	} else
	{		
		if (S_ISLNK(stbuf.st_mode))
		{
			//Get link's target
			CHECKED(resolve_symlink(fname,&fname));
			CHECKED(ops_.getattr(fname.c_str(),&stbuf));
		}

		if ((stbuf.st_mode&S_IFDIR)==S_IFDIR)
		{
			//Existing directory
			//TODO: add access control
			dokan_file_info->IsDirectory=TRUE;
			return do_open_dir(file_name,dokan_file_info);
		} else
		{
			//Existing file
			//Check if we'll be able to truncate or delete the opened file
			//TODO: race condition here?
			if (creation_disposition==CREATE_ALWAYS)
			{
				if (!ops_.unlink) return -EINVAL;
				CHECKED(ops_.unlink(fname.c_str())); //Delete file
				//And create it!
				return do_create_file(file_name,creation_disposition, share_mode,
					access_mode,dokan_file_info);
			} else if (creation_disposition==TRUNCATE_EXISTING)
			{
				if (!ops_.truncate) return -EINVAL;
				CHECKED(ops_.truncate(fname.c_str(),0));
			} else if (creation_disposition==CREATE_NEW)
			{
				return win_error(ERROR_FILE_EXISTS, true);
			}

			return do_open_file(file_name, share_mode, access_mode, dokan_file_info);
		}
	}
}
Пример #6
0
void GSWndWGL::CloseWGLDisplay()
{
	if (m_NativeDisplay && !ReleaseDC(m_NativeWindow, m_NativeDisplay))
		win_error("Release Device Context Failed.");

	m_NativeDisplay = NULL;
}
Пример #7
0
void gcb_enc_save(struct encdata *enc)
{
	char *profile;
	struct encprof *tmp;
	
	profile = gtk_editable_get_chars(GTK_EDITABLE(profentry), 0, -1); 
	if(profile[0] == '\0') {
		win_error(_("You should insert a name for this profile"));
		g_free(profile);
		return;
	}
	tmp = enc2prof(profile, enc);
	g_free(profile);

	if(enc->outchan->tipo == MP3) {
		lameprof = g_list_append(lameprof, (void *) tmp);
		profile_lame_write();
	} else {
		vorbisprof = g_list_append(vorbisprof, (void *) tmp);
		profile_vorbis_write();
	}
	
	/* add profile in menu */
	enc_profmenu(enc);
}
Пример #8
0
static BOOL CALLBACK emutls_init(PINIT_ONCE p0, PVOID p1, PVOID *p2) {
    emutls_mutex = (LPCRITICAL_SECTION)_aligned_malloc(sizeof(CRITICAL_SECTION), 16);
    if (!emutls_mutex) {
        win_error(GetLastError(), "_aligned_malloc");
        return FALSE;
    }
    InitializeCriticalSection(emutls_mutex);

    emutls_tls_index = TlsAlloc();
    if (emutls_tls_index == TLS_OUT_OF_INDEXES) {
        emutls_exit();
        win_error(GetLastError(), "TlsAlloc");
        return FALSE;
    }
    atexit(&emutls_exit);
    return TRUE;
}
Пример #9
0
static int
wait_process_handle(HANDLE process, ULONG *rc, DWORD timeout)
{ DWORD wc;

retry:
  wc = MsgWaitForMultipleObjects(1,
				 &process,
				 FALSE,	/* return on any event */
				 timeout,
				 QS_ALLINPUT);

  switch(wc)
  { case WAIT_OBJECT_0:
      if ( !GetExitCodeProcess(process, rc) )
      { win_error("GetExitCodeProcess");
	CloseHandle(process);
	return FALSE;
      }
      CloseHandle(process);
      return TRUE;
    case WAIT_OBJECT_0+1:
    { MSG msg;

      while( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
      { TranslateMessage(&msg);
	DispatchMessage(&msg);
	if ( PL_handle_signals() < 0 )
	  return FALSE;
      }
      goto retry;
    }
    case WAIT_TIMEOUT:
      return WP_TIMEOUT;
    default:
      win_error("WaitForSingleObject");
      CloseHandle(process);
      return FALSE;
  }
}
Пример #10
0
void GSWndWGL::OpenWGLDisplay()
{
	GLuint	  PixelFormat;			// Holds The Results After Searching For A Match
	PIXELFORMATDESCRIPTOR pfd =			 // pfd Tells Windows How We Want Things To Be

	{
		sizeof(PIXELFORMATDESCRIPTOR),			  // Size Of This Pixel Format Descriptor
		1,										  // Version Number
		PFD_DRAW_TO_WINDOW |						// Format Must Support Window
		PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL
		PFD_DOUBLEBUFFER,						   // Must Support Double Buffering
		PFD_TYPE_RGBA,							  // Request An RGBA Format
		32,										 // Select Our Color Depth
		0, 0, 0, 0, 0, 0,						   // Color Bits Ignored
		0,										  // 8bit Alpha Buffer
		0,										  // Shift Bit Ignored
		0,										  // No Accumulation Buffer
		0, 0, 0, 0,								 // Accumulation Bits Ignored
		0,										 // 24Bit Z-Buffer (Depth Buffer)
		8,										  // 8bit Stencil Buffer
		0,										  // No Auxiliary Buffer
		PFD_MAIN_PLANE,							 // Main Drawing Layer
		0,										  // Reserved
		0, 0, 0									 // Layer Masks Ignored
	};

	m_NativeDisplay = GetDC(m_NativeWindow);
	if (!m_NativeDisplay)
		win_error("(1) Can't Create A GL Device Context.");

	PixelFormat = ChoosePixelFormat(m_NativeDisplay, &pfd);
	if (!PixelFormat)
		win_error("(2) Can't Find A Suitable PixelFormat.");

	if (!SetPixelFormat(m_NativeDisplay, PixelFormat, &pfd))
		win_error("(3) Can't Set The PixelFormat.", false);
}
Пример #11
0
void gcb_add_file(GtkWidget *w, GtkFileSelection *fw)
{
	unsigned int idx = 0;
	struct gchan *o;
	gchar **cist; 
	//const gchar *cist;
	gint i;
	GtkTreeSelection *select;
	bool res=false;

	cist=NULL;
	
	idx= *(unsigned int *) g_object_get_data(G_OBJECT(GTK_FILE_SELECTION(fw)->ok_button), "chan");
	func(_("GTK_GUI::gcb_add_file : idx %u"), idx);
	cist = gtk_file_selection_get_selections(GTK_FILE_SELECTION(fw));
	//cist = gtk_file_selection_get_filename(GTK_FILE_SELECTION(fw));

	o = (struct gchan *) list_get_data(listachan, idx, 0);
	/*if(!cist[0]) {
		win_warning(_("You have to insert a filename!!"));
		return;
	}*/
	
	/* muse core'll add file into GtkTreeModel */
	for(i = 0; cist[i] != NULL; i++) {
		res = mixer->add_to_playlist(idx-1, cist[i]);
		//res = mixer->add_to_playlist(idx-1, cist);
		if(!res) { 
			func(_("gcb_add_file:: mixer->add_to_playlist(%u, %s) failed"),
					idx-1, cist[i]);
			win_error(_("Problem adding file :\\"));
		} else {
			//func(_("Added %s"), cist[i]);
			/* saves last directory visited */
			if(pathfile) 
				g_free(pathfile);
			pathfile = g_strdup(cist[i]);
			//pathfile = g_strdup(cist);
			int i = strlen(pathfile);
			while(pathfile[i] != '/') i--;
				pathfile[i+1]= '\0';
		}
	}
	g_strfreev(cist);
	select = gtk_tree_view_get_selection(GTK_TREE_VIEW(o->tree));
	gtk_tree_selection_unselect_all(select);
	gtk_widget_destroy((GtkWidget *)fw);

}
Пример #12
0
void httpinsert(GtkWidget *w, struct gchan *o)
{
	gchar *s = NULL;

	s = gtk_editable_get_chars(GTK_EDITABLE(o->httpentry), 0, -1);
	if(s[0] == 0) {
		g_free(s);
		win_warning(_("You have to insert an url!!"));
		winh = NULL;
		return;
	}
	act(_("httpinsert() url is %s"), s);
	if(!(mixer->add_to_playlist(o->idx-1, s))) {
		error(_("GTK_GUI:: httpinsert problem adding url"));
		win_error(_("Problem adding url"));
	}
	g_free(s);
	winh = NULL;
}
Пример #13
0
BOOL lsp(LSA_HANDLE lsa_handle)
{
  LPTSTR  command_line;
  LPWSTR* command_argv;
  int     command_argc;
  BOOL    success;

  command_line = GetCommandLineW();
  command_argv = CommandLineToArgvW(command_line, &command_argc);

  if (command_argv == NULL)
    success = win_error(GetLastError(), L"CommandLineToArgvW");
  else
    success = lsp_command(lsa_handle, command_argc, command_argv);

  LocalFree(command_argv);

  return success ? 0 : 1;
}
Пример #14
0
static foreign_t
process_kill(term_t pid, term_t signal)
{ int p;

  if ( !get_pid(pid, &p) )
    return FALSE;

{
#ifdef __WINDOWS__
  HANDLE h;

  if ( !(h=find_process_from_pid(p, "process_kill")) )
    return FALSE;

  if ( TerminateProcess(h, 255) )
    return TRUE;

  return win_error("TerminateProcess");
#else /*__WINDOWS__*/
  int sig;

  if ( !PL_get_signum_ex(signal, &sig) )
    return FALSE;

  if ( kill(p, sig) == 0 )
    return TRUE;

  switch(errno)
  { case EPERM:
      return pl_error("process_kill", 2, NULL, ERR_PERMISSION,
		      pid, "kill", "process");
    case ESRCH:
      return pl_error("process_kill", 2, NULL, ERR_EXISTENCE,
		      "process", pid);
    default:
      return pl_error("process_kill", 2, "kill", ERR_ERRNO, errno, "kill", "process", pid);
  }
#endif /*__WINDOWS__*/
}
}
Пример #15
0
static int DOKAN_CALLBACK FuseCreateFile(
				 LPCWSTR				FileName,
				 DWORD					AccessMode,
				 DWORD					ShareMode,
				 DWORD					CreationDisposition,
				 DWORD					FlagsAndAttributes,
				 PDOKAN_FILE_INFO		DokanFileInfo)
{
	impl_fuse_context *impl=the_impl;
	if (impl->debug()) {
		FWPRINTF(stderr, L"CreateFile : %s\n", FileName);
		DebugConstantBit("\tAccessMode", AccessMode,  cAccessMode);
		DebugConstantBit("\tShareMode",  ShareMode,   cShareMode);
		DebugConstant("\tDisposition",   CreationDisposition, cDisposition);
		FWPRINTF(stderr, L"\tFlags: %u (0x%x)\n", FlagsAndAttributes, FlagsAndAttributes);
		fflush(stderr);
	}
	
	impl_chain_guard guard(impl,DokanFileInfo->ProcessId);
	return -win_error(impl->create_file(FileName,AccessMode,ShareMode,
		CreationDisposition,FlagsAndAttributes,DokanFileInfo));
}
Пример #16
0
static NTSTATUS DOKAN_CALLBACK FuseCreateFile(
				 LPCWSTR						FileName,
				 PDOKAN_IO_SECURITY_CONTEXT		SecurityContext,
				 ACCESS_MASK					DesiredAccess,
				 ULONG							FileAttributes,
				 ULONG							ShareAccess,
				 ULONG							CreateDisposition,
				 ULONG							CreateOptions,
				 PDOKAN_FILE_INFO				DokanFileInfo)
{
	impl_fuse_context *impl = the_impl;

	if (impl->debug()) {
		FWPRINTF(stderr, L"CreateFile : %s\n", FileName);
		DebugConstantBit("\tDesiredAccess", DesiredAccess, cAccessMode);
		DebugConstantBit("\tShareAccess", ShareAccess, cShareMode);
		DebugConstant("\tDisposition", CreateDisposition, cDisposition);
		FWPRINTF(stderr, L"\tAttributes: %u (0x%x)\n", FileAttributes, FileAttributes);
		FWPRINTF(stderr, L"\tOptions: %u (0x%x)\n", CreateOptions, CreateOptions);
		fflush(stderr);
	}

	impl_chain_guard guard(impl,DokanFileInfo->ProcessId);

	if((CreateOptions & FILE_DIRECTORY_FILE) == FILE_DIRECTORY_FILE) {

		if(CreateDisposition == FILE_CREATE || CreateDisposition == FILE_OPEN_IF) {
			return errno_to_ntstatus_error(impl->create_directory(FileName, DokanFileInfo));
		}
		else if(CreateDisposition == FILE_OPEN) {

			return errno_to_ntstatus_error(impl->open_directory(FileName, DokanFileInfo));
		}
	}

	return -win_error(impl->create_file(FileName, CreateDisposition, ShareAccess, DesiredAccess, FileAttributes,
		DokanFileInfo));
}
Пример #17
0
BOOL lsa_error(NTSTATUS nt_status, LPCTSTR function)
{
  return win_error(LsaNtStatusToWinError(nt_status), function);
}
Пример #18
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;

    /** 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);

    /** 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, 0); /* attempt to open the file */
    }

    /*
     * Restore file attributes and times on the restored file.
     */
    if (!win32_restore_file_attributes(attr->ofname, bget_handle(ofd), &atts)) {
        win_error(jcr, "win32_restore_file_attributes:", attr->ofname);
    }

    if (is_bopen(ofd)) {
        bclose(ofd);
    }

    return true;
}
Пример #19
0
static int
do_create_process(p_options *info)
{ int flags = 0;
  PROCESS_INFORMATION pi;
  STARTUPINFOW si;

  switch(info->window)
  { case MAYBE:
      if ( !console_app() )
	flags |= CREATE_NO_WINDOW;
      break;
    case TRUE:
      break;
    case FALSE:
      flags |= CREATE_NO_WINDOW;
      break;
  }

  if ( info->detached )
    flags |= CREATE_BREAKAWAY_FROM_JOB;

  memset(&si, 0, sizeof(si));
  si.cb = sizeof(si);
  si.dwFlags = STARTF_USESTDHANDLES;

				      /* stdin */
  switch( info->streams[0].type )
  { case std_pipe:
      si.hStdInput = info->streams[0].fd[0];
      SetHandleInformation(info->streams[0].fd[1],
			   HANDLE_FLAG_INHERIT, FALSE);
      break;
    case std_null:
      si.hStdInput = open_null_stream(GENERIC_READ);
      break;
    case std_std:
      si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
      break;
  }
				      /* stdout */
  switch( info->streams[1].type )
  { case std_pipe:
      si.hStdOutput = info->streams[1].fd[1];
      SetHandleInformation(info->streams[1].fd[0],
			   HANDLE_FLAG_INHERIT, FALSE);
      break;
    case std_null:
      si.hStdOutput = open_null_stream(GENERIC_WRITE);
      break;
    case std_std:
      si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
      break;
  }
				      /* stderr */
  switch( info->streams[2].type )
  { case std_pipe:
      si.hStdError = info->streams[2].fd[1];
      SetHandleInformation(info->streams[2].fd[0],
			   HANDLE_FLAG_INHERIT, FALSE);
      break;
    case std_null:
      si.hStdError = open_null_stream(GENERIC_WRITE);
      break;
    case std_std:
      si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
      break;
  }

  if ( CreateProcessW(info->exe,
		      info->cmdline,
		      NULL,		/* Process security */
		      NULL,		/* Thread security */
		      TRUE,		/* Inherit handles */
		      flags,		/* Creation flags */
		      info->envbuf.buffer, /* Environment */
		      info->cwd,	/* Directory */
		      &si,		/* Startup info */
		      &pi) )		/* Process information */
  { CloseHandle(pi.hThread);

    if ( info->pipes > 0 && info->pid == 0 )
    { IOSTREAM *s;
      process_context *pc = PL_malloc(sizeof(*pc));

      DEBUG(Sdprintf("Wait on pipes\n"));

      memset(pc, 0, sizeof(*pc));
      pc->magic  = PROCESS_MAGIC;
      pc->handle = pi.hProcess;

      if ( info->streams[0].type == std_pipe )
      { CloseHandle(info->streams[0].fd[0]);
	s = open_process_pipe(pc, 0, info->streams[0].fd[1]);
	PL_unify_stream(info->streams[0].term, s);
      }
      if ( info->streams[1].type == std_pipe )
      { CloseHandle(info->streams[1].fd[1]);
	s = open_process_pipe(pc, 1, info->streams[1].fd[0]);
	PL_unify_stream(info->streams[1].term, s);
      }
      if ( info->streams[2].type == std_pipe )
      { CloseHandle(info->streams[2].fd[1]);
	s = open_process_pipe(pc, 2, info->streams[2].fd[0]);
	PL_unify_stream(info->streams[2].term, s);
      }

      return TRUE;
    } else if ( info->pipes > 0 )
    { IOSTREAM *s;

      if ( info->streams[0].type == std_pipe )
      { CloseHandle(info->streams[0].fd[0]);
	s = Sopen_handle(info->streams[0].fd[1], "w");
	PL_unify_stream(info->streams[0].term, s);
      }
      if ( info->streams[1].type == std_pipe )
      { CloseHandle(info->streams[1].fd[1]);
	s = Sopen_handle(info->streams[1].fd[0], "r");
	PL_unify_stream(info->streams[1].term, s);
      }
      if ( info->streams[2].type == std_pipe )
      { CloseHandle(info->streams[2].fd[1]);
	s = Sopen_handle(info->streams[2].fd[0], "r");
	PL_unify_stream(info->streams[2].term, s);
      }
    }

    if ( info->pid )
    { register_process(pi.dwProcessId, pi.hProcess);
      return PL_unify_integer(info->pid, pi.dwProcessId);
    }

    return win_wait_success(info->exe_name, pi.hProcess);
  } else
  { return win_error("CreateProcess");
  }
}
Пример #20
0
void GSWndWGL::CreateContext(int major, int minor)
{
	if (!m_NativeDisplay || !m_NativeWindow)
	{
		win_error("Wrong display/window", false);
		exit(1);
	}

	ASSERT(major >= 3);

	// GL2 context are quite easy but we need GL3 which is another painful story...
	m_context = wglCreateContext(m_NativeDisplay);
	if (!m_context)
		win_error("Failed to create a 2.0 context");

	// FIXME test it
	// Note: albeit every tutorial said that we need an opengl context to use the GL function wglCreateContextAttribsARB
	// On linux it works without the extra temporary context, not sure the limitation still applied
	AttachContext();

	// Create a context
	int context_attribs[] =
	{
		WGL_CONTEXT_MAJOR_VERSION_ARB, major,
		WGL_CONTEXT_MINOR_VERSION_ARB, minor,
		// FIXME : Request a debug context to ease opengl development
		// Note: don't support deprecated feature (pre openg 3.1)
		//GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB | GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
		WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
#ifdef ENABLE_OGL_DEBUG
			| WGL_CONTEXT_DEBUG_BIT_ARB
#else
			| GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR
#endif
			,
		WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
		0
	};

	PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
	if (!wglCreateContextAttribsARB)
		win_error("Failed to init wglCreateContextAttribsARB function pointer");

	HGLRC context30 = wglCreateContextAttribsARB(m_NativeDisplay, NULL, context_attribs);
	if (!context30) {
		win_error("Failed to create a 3.x context with standard flags", false);
		// retry with more compatible option for (Mesa on Windows, OpenGL on WINE)
		context_attribs[2*2+1] = 0;

		context30 = wglCreateContextAttribsARB(m_NativeDisplay, NULL, context_attribs);
	}

	DetachContext();
	wglDeleteContext(m_context);

	if (!context30)
		win_error("Failed to create a 3.x context with compatible flags");

	m_context = context30;
	fprintf(stderr, "3.x GL context successfully created\n");
}
Пример #21
0
static __inline void win_abort(DWORD last_err, const char *hint) {
    win_error(last_err, hint);
    abort();
}
Пример #22
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;
}
Пример #23
0
/*
 * Restore all file attributes like owner, mode and file times.
 */
static inline bool restore_file_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
{
    bool ok = true;
    bool suppress_errors;
#if defined(HAVE_FCHOWN) || defined(HAVE_FCHMOD) || defined(HAVE_FUTIMES) || defined(FUTIMENS)
    bool file_is_open;

    /*
     * Save if we are working on an open file.
     */
    file_is_open = is_bopen(ofd);
#endif

    /*
     * See if we want to print errors.
     */
    suppress_errors = (debug_level >= 100 || my_uid != 0);

    /*
     * Restore owner and group.
     */
#ifdef HAVE_FCHOWN
    if (file_is_open) {
        if (fchown(ofd->fid, attr->statp.st_uid, attr->statp.st_gid) < 0 && !suppress_errors) {
            berrno be;

            Jmsg2(jcr, M_ERROR, 0, _("Unable to set file owner %s: ERR=%s\n"), attr->ofname, be.bstrerror());
            ok = false;
        }
    } else {
#else
    {
#endif
        if (lchown(attr->ofname, attr->statp.st_uid, attr->statp.st_gid) < 0 && !suppress_errors) {
            berrno be;

            Jmsg2(jcr, M_ERROR, 0, _("Unable to set file owner %s: ERR=%s\n"), attr->ofname, be.bstrerror());
            ok = false;
        }
    }

    /*
     * Restore filemode.
     */
#ifdef HAVE_FCHMOD
    if (file_is_open) {
        if (fchmod(ofd->fid, attr->statp.st_mode) < 0 && !suppress_errors) {
            berrno be;

            Jmsg2(jcr, M_ERROR, 0, _("Unable to set file modes %s: ERR=%s\n"), attr->ofname, be.bstrerror());
            ok = false;
        }
    } else {
#else
    {
#endif
#if defined(HAVE_WIN32)
        if (win32_chmod(attr->ofname, attr->statp.st_mode, attr->statp.st_rdev) < 0 && !suppress_errors) {
#else
        if (lchmod(attr->ofname, attr->statp.st_mode) < 0 && !suppress_errors) {
#endif
            berrno be;

            Jmsg2(jcr, M_ERROR, 0, _("Unable to set file modes %s: ERR=%s\n"), attr->ofname, be.bstrerror());
            ok = false;
        }
    }

    /*
     * Reset file times.
     */
#if defined(HAVE_FUTIMES)
    if (file_is_open) {
        struct timeval restore_times[2];

        restore_times[0].tv_sec = attr->statp.st_atime;
        restore_times[0].tv_usec = 0;
        restore_times[1].tv_sec = attr->statp.st_mtime;
        restore_times[1].tv_usec = 0;

        if (futimes(ofd->fid, restore_times) < 0 && !suppress_errors) {
            berrno be;

            Jmsg2(jcr, M_ERROR, 0, _("Unable to set file times %s: ERR=%s\n"), attr->ofname, be.bstrerror());
            ok = false;
        }
    } else {
#elif defined(HAVE_FUTIMENS)
    if (file_is_open) {
        struct timespec restore_times[2];

        restore_times[0].tv_sec = attr->statp.st_atime;
        restore_times[0].tv_nsec = 0;
        restore_times[1].tv_sec = attr->statp.st_mtime;
        restore_times[1].tv_nsec = 0;

        if (futimens(ofd->fid, restore_times) < 0 && !suppress_errors) {
            berrno be;

            Jmsg2(jcr, M_ERROR, 0, _("Unable to set file times %s: ERR=%s\n"), attr->ofname, be.bstrerror());
            ok = false;
        }
    } else {
#else
    {
#endif
#if defined(HAVE_LUTIMES)
        struct timeval restore_times[2];

        restore_times[0].tv_sec = attr->statp.st_atime;
        restore_times[0].tv_usec = 0;
        restore_times[1].tv_sec = attr->statp.st_mtime;
        restore_times[1].tv_usec = 0;

        if (lutimes(attr->ofname, restore_times) < 0 && !suppress_errors) {
            berrno be;

            Jmsg2(jcr, M_ERROR, 0, _("Unable to set file times %s: ERR=%s\n"), attr->ofname, be.bstrerror());
            ok = false;
        }
#elif defined(HAVE_UTIMES)
        struct timeval restore_times[2];

        restore_times[0].tv_sec = attr->statp.st_atime;
        restore_times[0].tv_usec = 0;
        restore_times[1].tv_sec = attr->statp.st_mtime;
        restore_times[1].tv_usec = 0;

        if (utimes(attr->ofname, restore_times) < 0 && !suppress_errors) {
            berrno be;

            Jmsg2(jcr, M_ERROR, 0, _("Unable to set file times %s: ERR=%s\n"), attr->ofname, be.bstrerror());
            ok = false;
        }
#else
        struct utimbuf restore_times;

        restore_times.actime = attr->statp.st_atime;
        restore_times.modtime = attr->statp.st_mtime;

        if (utime(attr->ofname, &restore_times) < 0 && !suppress_errors) {
            berrno be;

            Jmsg2(jcr, M_ERROR, 0, _("Unable to set file times %s: ERR=%s\n"), attr->ofname, be.bstrerror());
            ok = false;
        }
#endif /* HAVE_LUTIMES */
    }

    return ok;
}

/**
 * Set file modes, permissions and times
 *
 *  fname is the original filename
 *  ofile is the output filename (may be in a different directory)
 *
 * Returns:  true  on success
 *           false on failure
 */
bool set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
{
    mode_t old_mask;
    bool ok = true;
    bool suppress_errors;

    if (uid_set) {
        my_uid = getuid();
        my_gid = getgid();
        uid_set = true;
    }

    /*
     * See if we want to print errors.
     */
    suppress_errors = (debug_level >= 100 || my_uid != 0);

#if defined(HAVE_WIN32)
    if (attr->stream == STREAM_UNIX_ATTRIBUTES_EX &&
            set_win32_attributes(jcr, attr, ofd)) {
        if (is_bopen(ofd)) {
            bclose(ofd);
        }
        pm_strcpy(attr->ofname, "*None*");
        return true;
    }

    if (attr->data_stream == STREAM_WIN32_DATA ||
            attr->data_stream == STREAM_WIN32_GZIP_DATA ||
            attr->data_stream == STREAM_WIN32_COMPRESSED_DATA) {
        if (is_bopen(ofd)) {
            bclose(ofd);
        }
        pm_strcpy(attr->ofname, "*None*");
        return true;
    }

    /**
     * If Windows stuff failed, e.g. attempt to restore Unix file to Windows, simply fall
     * through and we will do it the universal way.
     */
#endif

    old_mask = umask(0);
    if (is_bopen(ofd)) {
        boffset_t fsize;
        char ec1[50], ec2[50];

        fsize = blseek(ofd, 0, SEEK_END);
        if (attr->type == FT_REG &&
                fsize > 0 &&
                attr->statp.st_size > 0 &&
                fsize != (boffset_t)attr->statp.st_size) {
            Jmsg3(jcr, M_ERROR, 0, _("File size of restored file %s not correct. Original %s, restored %s.\n"),
                  attr->ofname, edit_uint64(attr->statp.st_size, ec1), edit_uint64(fsize, ec2));
        }
    } else {
        struct stat st;
        char ec1[50], ec2[50];

        if (lstat(attr->ofname, &st) == 0) {
            if (attr->type == FT_REG &&
                    st.st_size > 0 &&
                    attr->statp.st_size > 0 &&
                    st.st_size != attr->statp.st_size) {
                Jmsg3(jcr, M_ERROR, 0, _("File size of restored file %s not correct. Original %s, restored %s.\n"),
                      attr->ofname, edit_uint64(attr->statp.st_size, ec1), edit_uint64(st.st_size, ec2));
            }
        }
    }

    /**
     * We do not restore sockets, so skip trying to restore their attributes.
     */
    if (attr->type == FT_SPEC && S_ISSOCK(attr->statp.st_mode)) {
        goto bail_out;
    }

    /* ***FIXME**** optimize -- don't do if already correct */
    /**
     * For link, change owner of link using lchown, but don't try to do a chmod as that will update the file behind it.
     */
    if (attr->type == FT_LNK) {
        /*
         * Change owner of link, not of real file
         */
        if (lchown(attr->ofname, attr->statp.st_uid, attr->statp.st_gid) < 0 && !suppress_errors) {
            berrno be;

            Jmsg2(jcr, M_ERROR, 0, _("Unable to set file owner %s: ERR=%s\n"), attr->ofname, be.bstrerror());
            ok = false;
        }

#ifdef HAVE_LCHMOD
        if (lchmod(attr->ofname, attr->statp.st_mode) < 0 && !suppress_errors) {
            berrno be;

            Jmsg2(jcr, M_ERROR, 0, _("Unable to set file modes %s: ERR=%s\n"), attr->ofname, be.bstrerror());
            ok = false;
        }
#endif
    } else {
        if (!ofd->cmd_plugin) {
            ok = restore_file_attributes(jcr, attr, ofd);

#ifdef HAVE_CHFLAGS
            /**
             * FreeBSD user flags
             *
             * Note, this should really be done before the utime() above,
             * but if the immutable bit is set, it will make the utimes()
             * fail.
             */
            if (chflags(attr->ofname, attr->statp.st_flags) < 0 && !suppress_errors) {
                berrno be;
                Jmsg2(jcr, M_ERROR, 0, _("Unable to set file flags %s: ERR=%s\n"), attr->ofname, be.bstrerror());
                ok = false;
            }
#endif
        }
    }

bail_out:
    if (is_bopen(ofd)) {
        bclose(ofd);
    }

    pm_strcpy(attr->ofname, "*None*");
    umask(old_mask);

    return ok;
}

#if !defined(HAVE_WIN32)
/*=============================================================*/
/*                                                             */
/*                 * * *  U n i x * * * *                      */
/*                                                             */
/*=============================================================*/

/**
 * It is possible to piggyback additional data e.g. ACLs on
 *   the encode_stat() data by returning the extended attributes
 *   here.  They must be "self-contained" (i.e. you keep track
 *   of your own length), and they must be in ASCII string
 *   format. Using this feature is not recommended.
 * The code below shows how to return nothing.  See the Win32
 *   code below for returning something in the attributes.
 */
int encode_attribsEx(JCR *jcr, char *attribsEx, FF_PKT *ff_pkt)
{
#ifdef HAVE_DARWIN_OS
    /**
     * We save the Mac resource fork length so that on a
     * restore, we can be sure we put back the whole resource.
     */
    char *p;

    *attribsEx = 0;                 /* no extended attributes (yet) */
    if (jcr->cmd_plugin || ff_pkt->type == FT_DELETED) {
        return STREAM_UNIX_ATTRIBUTES;
    }
    p = attribsEx;
    if (bit_is_set(FO_HFSPLUS, ff_pkt->flags)) {
        p += to_base64((uint64_t)(ff_pkt->hfsinfo.rsrclength), p);
    }
    *p = 0;
#else
    *attribsEx = 0;                    /* no extended attributes */
#endif
    return STREAM_UNIX_ATTRIBUTES;
}
#else
/*=============================================================*/
/*                                                             */
/*                 * * *  W i n 3 2 * * * *                    */
/*                                                             */
/*=============================================================*/
int encode_attribsEx(JCR *jcr, char *attribsEx, FF_PKT *ff_pkt)
{
    char *p = attribsEx;
    WIN32_FILE_ATTRIBUTE_DATA atts;
    ULARGE_INTEGER li;

    attribsEx[0] = 0;                  /* no extended attributes */

    if (jcr->cmd_plugin || ff_pkt->type == FT_DELETED) {
        return STREAM_UNIX_ATTRIBUTES;
    }

    unix_name_to_win32(ff_pkt->sys_fname, ff_pkt->fname);
    if (p_GetFileAttributesExW)  {
        /**
         * Try unicode version
         */
        POOLMEM* pwszBuf = get_pool_memory(PM_FNAME);
        make_win32_path_UTF8_2_wchar(pwszBuf, ff_pkt->fname);

        BOOL b=p_GetFileAttributesExW((LPCWSTR)pwszBuf, GetFileExInfoStandard,
                                      (LPVOID)&atts);
        free_pool_memory(pwszBuf);

        if (!b) {
            win_error(jcr, "GetFileAttributesExW:", ff_pkt->sys_fname);
            return STREAM_UNIX_ATTRIBUTES;
        }
    } else {
        if (!p_GetFileAttributesExA)
            return STREAM_UNIX_ATTRIBUTES;

        if (!p_GetFileAttributesExA(ff_pkt->sys_fname, GetFileExInfoStandard,
                                    (LPVOID)&atts)) {
            win_error(jcr, "GetFileAttributesExA:", ff_pkt->sys_fname);
            return STREAM_UNIX_ATTRIBUTES;
        }
    }

    /*
     * Instead of using the current dwFileAttributes use the
     * ff_pkt->statp.st_rdev which contains the actual fileattributes we
     * want to save for this file.
     */
    atts.dwFileAttributes = ff_pkt->statp.st_rdev;

    p += to_base64((uint64_t)atts.dwFileAttributes, p);
    *p++ = ' ';                        /* separate fields with a space */
    li.LowPart = atts.ftCreationTime.dwLowDateTime;
    li.HighPart = atts.ftCreationTime.dwHighDateTime;
    p += to_base64((uint64_t)li.QuadPart, p);
    *p++ = ' ';
    li.LowPart = atts.ftLastAccessTime.dwLowDateTime;
    li.HighPart = atts.ftLastAccessTime.dwHighDateTime;
    p += to_base64((uint64_t)li.QuadPart, p);
    *p++ = ' ';
    li.LowPart = atts.ftLastWriteTime.dwLowDateTime;
    li.HighPart = atts.ftLastWriteTime.dwHighDateTime;
    p += to_base64((uint64_t)li.QuadPart, p);
    *p++ = ' ';
    p += to_base64((uint64_t)atts.nFileSizeHigh, p);
    *p++ = ' ';
    p += to_base64((uint64_t)atts.nFileSizeLow, p);
    *p = 0;

    return STREAM_UNIX_ATTRIBUTES_EX;
}