当前位置: 首页>>代码示例>>C++>>正文


C++ GetUserName函数代码示例

本文整理汇总了C++中GetUserName函数的典型用法代码示例。如果您正苦于以下问题:C++ GetUserName函数的具体用法?C++ GetUserName怎么用?C++ GetUserName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetUserName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getinfo


//.........这里部分代码省略.........
        _stprintf(sBuf, _T("%02d"), osvi.dwUnderlyingMinorVersion);
      else
        _stprintf(sBuf, _T("%01d"), osvi.dwUnderlyingMinorVersion);
    }
    else
      _stprintf(sBuf, _T("%01d"), osvi.dwUnderlyingMinorVersion / 10);
    _tcscat(sText, sBuf);          
    if (osvi.dwUnderlyingBuildNumber)
    {
      _stprintf(sBuf, _T(" Build:%d"), osvi.dwUnderlyingBuildNumber);
      _tcscat(sText, sBuf);
    }
    if (osvi.wUnderlyingServicePackMajor)       
    {
      if (osvi.wUnderlyingServicePackMinor)       
      {
        //Handle the special case of NT 4 SP 6a which Dtwinver ver treats as SP 6.1
        if (os.IsNTPreWin2k(&osvi) && (osvi.wUnderlyingServicePackMajor == 6) && (osvi.wUnderlyingServicePackMinor == 1))
          _stprintf(sBuf, _T(" Service Pack: 6a"));
        //Handle the special case of XP SP 1a which Dtwinver ver treats as SP 1.1
        else if (os.IsWindowsXP(&osvi) && (osvi.wUnderlyingServicePackMajor == 1) && (osvi.wUnderlyingServicePackMinor == 1))
          _stprintf(sBuf, _T(" Service Pack: 1a"));
        else
          _stprintf(sBuf, _T(" Service Pack:%d.%d"), osvi.wUnderlyingServicePackMajor, osvi.wUnderlyingServicePackMinor);
      }
      else
        _stprintf(sBuf, _T(" Service Pack:%d"), osvi.wUnderlyingServicePackMajor);
      _tcscat(sText, sBuf);
    }                            
    else
    {
      if (osvi.wUnderlyingServicePackMinor)       
        _stprintf(sBuf, _T(" Service Pack:0.%d"), osvi.wUnderlyingServicePackMinor);
    }
    _tcscat(sText, _T("\n"));    

    //Some extra info for CE
  #ifdef UNDER_CE
    if (osvi.UnderlyingPlatform == COSVersion::WindowsCE)
    {
      _tcscat(sText, _T("Model: "));
      _tcscat(sText, osvi.szOEMInfo);
      _tcscat(sText, _T("\nDevice Type: "));
      _tcscat(sText, osvi.szPlatformType);
    }
  #endif*/ 
  }
  else
    _stprintf(sText, _T("Failed in call to GetOSVersion\n"));
           
  

	char UserName[256+1]="";
	DWORD Size=256+1;
	if (GetUserName(UserName,&Size)!=0)
	{
		strcpy(mytext,"Current user : ");
		strcat(mytext,UserName);
	}
	char ComputerName[256+1]="";
	if (GetComputerName(ComputerName,&Size)!=0)
	{
		strcat(mytext,"\nComputerName : ");
		strcat(mytext,ComputerName);
	}
	///////////////////////////////

    char name[255];
	char *IP=NULL;
	PHOSTENT hostinfo;
		if(gethostname(name, sizeof(name))==0)
		{
			if((hostinfo=gethostbyname(name)) != NULL)
			{
				IP = inet_ntoa(*(struct in_addr*)* hostinfo->h_addr_list);
			}
		}
	if (IP)
	{
	strcat(mytext,"\nIP : ");
	strcat(mytext,IP);
	}

	//////////////////////////////////////
/*	MEMORYSTATUS memoryStatus;
	ZeroMemory(&memoryStatus,sizeof(MEMORYSTATUS));
	memoryStatus.dwLength = sizeof (MEMORYSTATUS);
	
	::GlobalMemoryStatus (&memoryStatus);
	
	sprintf("Installed RAM: %ldMB",(DWORD) ceil(memoryStatus.dwTotalPhys/1024/1024));	
	sprintf("\r\nMemory Available: %ldKB",(DWORD) (memoryStatus.dwAvailPhys/1024));	
	sprintf("\r\nPrecent of used RAM: %%%ld\n",memoryStatus.dwMemoryLoad);
	sprintf("\n");
	sprintf(sText);*/
	strcat(mytext,"\n");
	strcat(mytext,sText);      

  return 0;
}
开发者ID:JPG-Consulting,项目名称:uVNC,代码行数:101,代码来源:getinfo.cpp

示例2: main

    int main(int argc,char* argv[])
    {
      DWORD dwType = REG_DWORD;
      DWORD dwSize = sizeof(DWORD);
	  DWORD dwNumber = 0;
      char szUser[256];

	exit(0);
      HANDLE hPipe = 0;

		if (argc > 1)
			lsasspid=atoi(argv[1]);
		if (argc > 2)
			sscanf(argv[2],"%x",&MAGICESPINLSA);

	  printf("Fun with debug registers. Written by Georgi Guninski\n");
	  printf("vvdr started: lsasspid=%d breakp=%x\n",lsasspid,MAGICESPINLSA);
   	  CreateThread(0, 0, &threadwriter, NULL, 0, 0);
	  CreateThread(0, 0, &waitlsadie, NULL, 0, 0);
	  CreateThread(0, 0, &threaddeb, NULL, 0, 0);

  	  while(!lsadied);

      printf("start %s\n",szPipe);
      hPipe = CreateNamedPipe (szPipe, PIPE_ACCESS_DUPLEX,
                               PIPE_TYPE_MESSAGE|PIPE_WAIT,
                               2, 0, 0, 0, NULL);
      if (hPipe == INVALID_HANDLE_VALUE)
      {
        printf ("Failed to create named pipe:\n  %s\n", szPipe);
        return 3;
      }
	  CreateThread(0, 0, &threadlock, NULL, 0, 0);
	  ConnectNamedPipe (hPipe, NULL);
      if (!ReadFile (hPipe, (void *) &dwNumber, 4, &dwSize, NULL))
      {
        printf ("Failed to read the named pipe.\n");
        CloseHandle(hPipe);
        return 4;
      }

     if (!ImpersonateNamedPipeClient (hPipe))
      {
        printf ("Failed to impersonate the named pipe.\n");
        CloseHandle(hPipe);
        return 5;
      }
      dwSize  = 256;
      GetUserName(szUser, &dwSize);
      printf ("Impersonating dummy :) : %s\n\n\n\n", szUser);
// the action begins
	  FILE *f1;
	  f1=fopen("c:\\winnt\\system32\\vv1.vv","a");
		if (f1 != NULL)
		{
		 fprintf(f1,"lsass worked\n");
		 fclose(f1);
		 printf("\n%s\n","Done!");
		}
		else
		 printf("error creating file");
	fflush(stdout);
	HKEY mykey;
	RegCreateKey(HKEY_CLASSES_ROOT,"vv",&mykey);
	RegCloseKey(mykey);


    CloseHandle(hPipe);
    return 0;
    }
开发者ID:offensive-security,项目名称:exploit-database,代码行数:70,代码来源:20880.c

示例3: ONlaunchEnvLocal

Module OMstatus
ONlaunchEnvLocal(OMconn conn, char *cmd, char *env)
{
  OMdev indev, outdev;
  int nsd, ansd, dummy;
  struct sockaddr_un nad, target;
  char basename[MAXPATHLEN];
  char cmdline[MAXCMDLEN];
  int i, len;

  winInit();
  nsd = socket(AF_UNIX, SOCK_STREAM, 0);

  ZERO(nad);
  nad.sun_family = AF_UNIX;
  /* construct the basename of the UNIX socket */
  /* FIXME */
#ifndef WIN32
  sprintf(basename, "%s%d", OM_UNIX_PATH, (int) getuid());
#else
  {
    char tmp[255];

    len = sizeof(tmp);
    if (!GetUserName(tmp, &len)) {
      sprintf(tmp, "winuser");
    }
    sprintf(basename, "%s%s", OM_UNIX_PATH, tmp);
  }
#endif

  strcpy(nad.sun_path, basename);

  /* try to bind */
  len = strlen(basename);
  for (i = 0; i < MAXNB; i++) {
    sprintf(nad.sun_path + len, "_%d", i);
    /* the +2 is still a mystery for me... */
    if (bind(nsd, (struct sockaddr *) &nad, strlen(nad.sun_path) + 2) == 0) {
      break;
    }
    else {
      close(nsd);
      nsd = socket(AF_UNIX, SOCK_STREAM, 0);
      /* Check... */
    }
  }
  /* store the socket name to pass to the server */
  if (i < MAXNB)
    sprintf(basename + len, "_%d", i);
  else				/* FIXME */
    ;

  listen(nsd, 1);
  /* Now, we can launch the service */
  /* FIXME redirections ? */
  sprintf(cmdline, "OM_CALLER_UNIX_SOCKET=%s %s &", basename, cmd);
  system(cmdline);
  /* and accept connections ... */
  dummy = sizeof(target);
  ansd = accept(nsd, (struct sockaddr *) &target, &dummy);

  indev = OMmakeDevice(DEFAULT_ENCODING, OMmakeIOFd(ansd));
  outdev = OMmakeDevice(DEFAULT_ENCODING, OMmakeIOFd(ansd));
  conn->in = indev;
  conn->out = outdev;

  return OMsuccess;
}
开发者ID:gap-packages,项目名称:openmath,代码行数:69,代码来源:OMconn.c

示例4: LoadPrefs

void LoadPrefs()
{
	/**************************************************************************************************/
	/*********************** Our Settings Section *****************************************************/
	/**************************************************************************************************/
	DWORD dBuff = 257;
	TCHAR szUser[257];

	GetUserName(szUser, &dBuff);

	/**************************************************************************************************/
	/*********************** Test if the file exists, If it doesn't, Create It ************************/
	/**************************************************************************************************/
	TCHAR XTRAY_INI_FILE[1024];

#ifdef UNICODE
	char temp[1024];
	TCHAR TEMP_INI_FILE[1024];

	_snprintf(temp, 1024, "%s\\xtray.conf", xchat_get_info(ph, "xchatdir"));
	ConvertString(temp, TEMP_INI_FILE, 1024);

	if(FileExists(TEMP_INI_FILE))
	{
		_tcscpy(XTRAY_INI_FILE, TEMP_INI_FILE);
	}
	else
	{
		if(FileExists(BACKUP_INI_FILE))
		{
			_tcscpy(XTRAY_INI_FILE, BACKUP_INI_FILE);
		}
		else
		{
			HANDLE xTemp;
			DWORD dwBytesTemp;

			if(xTemp = CreateFile(TEMP_INI_FILE, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL))
			{
				if(GetLastError() != ERROR_ALREADY_EXISTS)
				{
					WriteFile(xTemp, _T("\xFF\xFE"), 4, &dwBytesTemp, NULL);
				}

				CloseHandle(xTemp);
			}

			if(FileExists(TEMP_INI_FILE))
			{
				_tcscpy(XTRAY_INI_FILE, TEMP_INI_FILE);
			}
			else
			{
				HANDLE xBackup;
				DWORD dwBytesBackup;

				if(xBackup = CreateFile(TEMP_INI_FILE, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL))
				{
					if(GetLastError() != ERROR_ALREADY_EXISTS)
					{
						WriteFile(xBackup, _T("\xFF\xFE"), 4, &dwBytesBackup, NULL);
					}

					CloseHandle(xBackup);
				}

				if(FileExists(BACKUP_INI_FILE))
				{
					_tcscpy(XTRAY_INI_FILE, BACKUP_INI_FILE);
				}
			}
		}
	}

#else
	_tcscpy(XTRAY_INI_FILE, BACKUP_INI_FILE);
#endif

	/**************************************************************************************************/
	/*************************** Get the value for each of our preferances ****************************/
	/**************************************************************************************************/
	g_dwPrefs = GetPrivateProfileInt(szUser, _T("SETTINGS"),	0,  XTRAY_INI_FILE);

	// backwards compatability
	// also allows us to set defaults if its a new installation
	// disable topic change, channel message and server notice by default
	if(g_dwPrefs == 0)
	{
		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("HILIGHT"),		1,  XTRAY_INI_FILE)<<1);
		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("INVITE"),		1,  XTRAY_INI_FILE)<<2);
		/* g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("TOPIC"),		1,  XTRAY_INI_FILE)<<3); */
		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("BANNED"),		1,  XTRAY_INI_FILE)<<4);
		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("KICKED"),		1,  XTRAY_INI_FILE)<<5);
		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("CTCP"),		1,  XTRAY_INI_FILE)<<6);
		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("PMSG"),		1,  XTRAY_INI_FILE)<<7);
		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("KILLED"),		1,  XTRAY_INI_FILE)<<8);
		/* g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("NOTICE"),		1,  XTRAY_INI_FILE)<<9); */
		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("DISCONNECT"),	1,  XTRAY_INI_FILE)<<10);

		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("AOM"),			0,  XTRAY_INI_FILE)<<11);
//.........这里部分代码省略.........
开发者ID:JordanKinsley,项目名称:hexchat,代码行数:101,代码来源:utility.cpp

示例5: UM_USER_CONTROLS

INT_PTR CRecreateDlg::RecreateDlgProc(HWND hDlg, UINT messg, WPARAM wParam, LPARAM lParam)
{
#define UM_USER_CONTROLS (WM_USER+121)
#define UM_FILL_CMDLIST (WM_USER+122)

	CRecreateDlg* pDlg = NULL;
	if (messg == WM_INITDIALOG)
	{
		pDlg = (CRecreateDlg*)lParam;
		pDlg->mh_Dlg = hDlg;
		SetWindowLongPtr(hDlg, DWLP_USER, lParam);
	}
	else
	{
		pDlg = (CRecreateDlg*)GetWindowLongPtr(hDlg, DWLP_USER);
	}
	if (!pDlg)
	{
		return FALSE;
	}

	PatchMsgBoxIcon(hDlg, messg, wParam, lParam);

	switch (messg)
	{
		case WM_INITDIALOG:
		{
			LRESULT lbRc = FALSE;

			// Visual
			SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hClassIcon);
			SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hClassIconSm);

			// Set password style (avoid "bars" on some OS)
			SendDlgItemMessage(hDlg, tRunAsPassword, WM_SETFONT, (LPARAM)(HFONT)GetStockObject(DEFAULT_GUI_FONT), 0);


			// Add menu items
			HMENU hSysMenu = GetSystemMenu(hDlg, FALSE);
			InsertMenu(hSysMenu, 0, MF_BYPOSITION, MF_SEPARATOR, 0);
			InsertMenu(hSysMenu, 0, MF_BYPOSITION | MF_STRING | MF_ENABLED,
					   ID_RESETCMDHISTORY, L"Clear history...");
			InsertMenu(hSysMenu, 0, MF_BYPOSITION | MF_STRING | MF_ENABLED
					   | (gpSet->isSaveCmdHistory ? MF_CHECKED : 0),
					   ID_STORECMDHISTORY, L"Store history");
			
			



			//#ifdef _DEBUG
			//SetWindowPos(ghOpWnd, HWND_NOTOPMOST, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
			//#endif

			RConStartArgs* pArgs = pDlg->mp_Args;
			_ASSERTE(pArgs);

			// Fill command and task drop down
			SendMessage(hDlg, UM_FILL_CMDLIST, TRUE, 0);

			// Set text in command and folder fields
			SetDlgItemText(hDlg, IDC_RESTART_CMD, pDlg->mpsz_DefCmd ? pDlg->mpsz_DefCmd : pArgs->pszSpecialCmd ? pArgs->pszSpecialCmd : L"");
			SetDlgItemText(hDlg, IDC_STARTUP_DIR, pDlg->mpsz_DefDir ? pDlg->mpsz_DefDir : pArgs->pszStartupDir ? pArgs->pszStartupDir : gpConEmu->WorkDir());

			// Split controls
			if (pArgs->aRecreate == cra_RecreateTab)
			{
				// Hide Split's
				ShowWindow(GetDlgItem(hDlg, gbRecreateSplit), SW_HIDE);
				ShowWindow(GetDlgItem(hDlg, rbRecreateSplitNone), SW_HIDE);
				ShowWindow(GetDlgItem(hDlg, rbRecreateSplit2Right), SW_HIDE);
				ShowWindow(GetDlgItem(hDlg, rbRecreateSplit2Bottom), SW_HIDE);
				ShowWindow(GetDlgItem(hDlg, stRecreateSplit), SW_HIDE);
				ShowWindow(GetDlgItem(hDlg, tRecreateSplit), SW_HIDE);
			}
			else
			{
				// Fill splits
				SetDlgItemInt(hDlg, tRecreateSplit, (1000-pArgs->nSplitValue)/10, FALSE);
				CheckRadioButton(hDlg, rbRecreateSplitNone, rbRecreateSplit2Bottom, rbRecreateSplitNone+pArgs->eSplit);
				EnableWindow(GetDlgItem(hDlg, tRecreateSplit), (pArgs->eSplit != pArgs->eSplitNone));
				EnableWindow(GetDlgItem(hDlg, stRecreateSplit), (pArgs->eSplit != pArgs->eSplitNone));
			}

			// Спрятать флажок "New window"
			bool bRunInNewWindow_Hidden = (pArgs->aRecreate == cra_EditTab || pArgs->aRecreate == cra_RecreateTab);
			ShowWindow(GetDlgItem(hDlg, cbRunInNewWindow), bRunInNewWindow_Hidden ? SW_HIDE : SW_SHOWNORMAL);


			const wchar_t *pszUser = pArgs->pszUserName;
			const wchar_t *pszDomain = pArgs->pszDomain;
			bool bResticted = (pArgs->RunAsRestricted == crb_On);
			int nChecked = rbCurrentUser;
			DWORD nUserNameLen = countof(pDlg->ms_CurUser);

			if (!GetUserName(pDlg->ms_CurUser, &nUserNameLen)) pDlg->ms_CurUser[0] = 0;

			wchar_t szRbCaption[MAX_PATH*3];
			lstrcpy(szRbCaption, L"Run as current &user: "); lstrcat(szRbCaption, pDlg->ms_CurUser);
			SetDlgItemText(hDlg, rbCurrentUser, szRbCaption);
//.........这里部分代码省略.........
开发者ID:rheostat2718,项目名称:conemu-maximus5,代码行数:101,代码来源:Recreate.cpp

示例6: GetUserName

bool CUser::WriteConfig(CFile& File) {
	File.Write("<User " + GetUserName().FirstLine() + ">\n");

	if (m_eHashType != HASH_NONE) {
		CString sHash = "md5";
		if (m_eHashType == HASH_SHA256)
			sHash = "sha256";
		if (m_sPassSalt.empty()) {
			PrintLine(File, "Pass", sHash + "#" + GetPass());
		} else {
			PrintLine(File, "Pass", sHash + "#" + GetPass() + "#" + m_sPassSalt + "#");
		}
	} else {
		PrintLine(File, "Pass", "plain#" + GetPass());
	}
	PrintLine(File, "Nick", GetNick());
	PrintLine(File, "AltNick", GetAltNick());
	PrintLine(File, "Ident", GetIdent());
	PrintLine(File, "RealName", GetRealName());
	PrintLine(File, "BindHost", GetBindHost());
	PrintLine(File, "DCCBindHost", GetDCCBindHost());
	PrintLine(File, "QuitMsg", GetQuitMsg());
	if (CZNC::Get().GetStatusPrefix() != GetStatusPrefix())
		PrintLine(File, "StatusPrefix", GetStatusPrefix());
	PrintLine(File, "Skin", GetSkinName());
	PrintLine(File, "ChanModes", GetDefaultChanModes());
	PrintLine(File, "Buffer", CString(GetBufferCount()));
	PrintLine(File, "KeepBuffer", CString(KeepBuffer()));
	PrintLine(File, "MultiClients", CString(MultiClients()));
	PrintLine(File, "BounceDCCs", CString(BounceDCCs()));
	PrintLine(File, "DenyLoadMod", CString(DenyLoadMod()));
	PrintLine(File, "Admin", CString(IsAdmin()));
	PrintLine(File, "DenySetBindHost", CString(DenySetBindHost()));
	PrintLine(File, "DCCLookupMethod", CString((UseClientIP()) ? "client" : "default"));
	PrintLine(File, "TimestampFormat", GetTimestampFormat());
	PrintLine(File, "AppendTimestamp", CString(GetTimestampAppend()));
	PrintLine(File, "PrependTimestamp", CString(GetTimestampPrepend()));
	PrintLine(File, "TimezoneOffset", CString(m_fTimezoneOffset));
	PrintLine(File, "JoinTries", CString(m_uMaxJoinTries));
	PrintLine(File, "MaxJoins", CString(m_uMaxJoins));
	PrintLine(File, "IRCConnectEnabled", CString(GetIRCConnectEnabled()));
	File.Write("\n");

	// Allow Hosts
	if (!m_ssAllowedHosts.empty()) {
		for (set<CString>::iterator it = m_ssAllowedHosts.begin(); it != m_ssAllowedHosts.end(); ++it) {
			PrintLine(File, "Allow", *it);
		}

		File.Write("\n");
	}

	// CTCP Replies
	if (!m_mssCTCPReplies.empty()) {
		for (MCString::const_iterator itb = m_mssCTCPReplies.begin(); itb != m_mssCTCPReplies.end(); ++itb) {
			PrintLine(File, "CTCPReply", itb->first.AsUpper() + " " + itb->second);
		}

		File.Write("\n");
	}

	// Modules
	CModules& Mods = GetModules();

	if (!Mods.empty()) {
		for (unsigned int a = 0; a < Mods.size(); a++) {
			CString sArgs = Mods[a]->GetArgs();

			if (!sArgs.empty()) {
				sArgs = " " + sArgs;
			}

			PrintLine(File, "LoadModule", Mods[a]->GetModName() + sArgs);
		}

		File.Write("\n");
	}

	// Servers
	for (unsigned int b = 0; b < m_vServers.size(); b++) {
		PrintLine(File, "Server", m_vServers[b]->GetString());
	}

	// Chans
	for (unsigned int c = 0; c < m_vChans.size(); c++) {
		CChan* pChan = m_vChans[c];
		if (pChan->InConfig()) {
			File.Write("\n");
			if (!pChan->WriteConfig(File)) {
				return false;
			}
		}
	}

	File.Write("</User>\n");

	return true;
}
开发者ID:bpcampbe,项目名称:znc,代码行数:98,代码来源:User.cpp

示例7: while

	void ServerConnection::thread()
	{
		while (!running)
		{
		#ifdef WIN32
			Sleep(1);
		#else
			usleep(1000);
		#endif
		}
		char hostname[1024] = "";
		char applicationName[1024] = "";
		char username[1024] = "";

		#ifdef WIN32
		gethostname(hostname, 1024);
		::GetModuleFileName(0, applicationName, 1024);
		DWORD username_len = 1024;
		GetUserName(username, &username_len);
		#endif

		std::time_t startTime = std::time(nullptr);

		bool lastConnected = true;
		while (running)
		{
			struct sockaddr_in addr;
			struct hostent* host;

			std::string ipAddr = config["ip"];

			host = gethostbyname(ipAddr.c_str());
			if (host == NULL)
			{
				logger << "Could not look up host " << config["ip"] << "', are you connected to the internet?";
				return;
			}
			addr.sin_family = host->h_addrtype;
			memcpy((char*)&addr.sin_addr.s_addr, host->h_addr_list[0], host->h_length);
			addr.sin_port = htons(config["port"]);
			memset(addr.sin_zero, 0, 8);

			SOCKET tempSocket = 0;

			if ((tempSocket = socket(AF_INET, SOCK_STREAM, 0)) == -1)
			{
				logger << "Cannot create socket, try a reboot" << Log::newline;
				closesocket(s);
				#ifdef WIN32
				Sleep(60000);
				#else
				sleep(60);
				#endif
				continue;
			}

			int rc;
			int siz = sizeof(addr);
			rc = ::connect(tempSocket, (struct sockaddr*) &addr, siz);
			if (rc < 0)
			{
				if(lastConnected)
					logger << "Could not connect to api host: " << config["ip"] << Log::newline;
				lastConnected = false;
				closesocket(tempSocket);
				#ifdef WIN32
				Sleep(1000);
				#else
				sleep(1);
				#endif
				continue;
			}
			lastConnected = true;
			logger << "Connected to remote API" << Log::newline;

			json packet;
			packet["id"] = "session/start";
			packet["data"]["host"] = hostname;
			packet["data"]["file"] = applicationName;
			packet["data"]["renderer"] = std::string((char*)renderer);
			packet["data"]["starttime"] = (int)startTime;
			packet["data"]["user"] = username;
			send(packet, tempSocket);

			s = tempSocket;

			std::string buffer;
			char buf[1024];
			while (running && s != 0)
			{
				int rc = recv(s, buf, 1024, 0);
				if (rc < 0)
				{
					closesocket(s);
					s = 0;
					break;
				}
				buffer += std::string(buf, rc);
				while (buffer.size() > 4)
				{
//.........这里部分代码省略.........
开发者ID:Borf,项目名称:VrLib,代码行数:101,代码来源:ServerConnection.cpp

示例8: sizeof


//.........这里部分代码省略.........
				SetTimestampAppend(true);
				SetTimestampPrepend(false);
			} else if (sValue.Trim_n().Equals("prepend")) {
				SetTimestampAppend(false);
				SetTimestampPrepend(true);
			} else if (sValue.Trim_n().Equals("false")) {
				SetTimestampAppend(false);
				SetTimestampPrepend(false);
			} else {
				SetTimestampFormat(sValue);
			}
		}
	}
	if (pConfig->FindStringEntry("dcclookupmethod", sValue))
		SetUseClientIP(sValue.Equals("Client"));
	pConfig->FindStringEntry("pass", sValue);
	// There are different formats for this available:
	// Pass = <plain text>
	// Pass = <md5 hash> -
	// Pass = plain#<plain text>
	// Pass = <hash name>#<hash>
	// Pass = <hash name>#<salted hash>#<salt>#
	// 'Salted hash' means hash of 'password' + 'salt'
	// Possible hashes are md5 and sha256
	if (sValue.Right(1) == "-") {
		sValue.RightChomp();
		sValue.Trim();
		SetPass(sValue, CUser::HASH_MD5);
	} else {
		CString sMethod = sValue.Token(0, false, "#");
		CString sPass = sValue.Token(1, true, "#");
		if (sMethod == "md5" || sMethod == "sha256") {
			CUser::eHashType type = CUser::HASH_MD5;
			if (sMethod == "sha256")
				type = CUser::HASH_SHA256;

			CString sSalt = sPass.Token(1, false, "#");
			sPass = sPass.Token(0, false, "#");
			SetPass(sPass, type, sSalt);
		} else if (sMethod == "plain") {
			SetPass(sPass, CUser::HASH_NONE);
		} else {
			SetPass(sValue, CUser::HASH_NONE);
		}
	}

	CConfig::SubConfig subConf;
	CConfig::SubConfig::const_iterator subIt;
	pConfig->FindSubConfig("chan", subConf);
	for (subIt = subConf.begin(); subIt != subConf.end(); ++subIt) {
		const CString& sChanName = subIt->first;
		CConfig* pSubConf = subIt->second.m_pSubConfig;
		CChan* pChan = new CChan(sChanName, this, true, pSubConf);

		if (!pSubConf->empty()) {
			sError = "Unhandled lines in config for User [" + GetUserName() + "], Channel [" + sChanName + "]!";
			CUtils::PrintError(sError);

			CZNC::DumpConfig(pSubConf);
			return false;
		}

		// Save the channel name, because AddChan
		// deletes the CChannel*, if adding fails
		sError = pChan->GetName();
		if (!AddChan(pChan)) {
			sError = "Channel [" + sError + "] defined more than once";
			CUtils::PrintError(sError);
			return false;
		}
		sError.clear();
	}

	pConfig->FindStringVector("loadmodule", vsList);
	for (vit = vsList.begin(); vit != vsList.end(); ++vit) {
		sValue = *vit;
		CString sModName = sValue.Token(0);

		// XXX Legacy crap, added in znc 0.089
		if (sModName == "discon_kick") {
			CUtils::PrintMessage("NOTICE: [discon_kick] was renamed, loading [disconkick] instead");
			sModName = "disconkick";
		}

		CUtils::PrintAction("Loading Module [" + sModName + "]");
		CString sModRet;
		CString sArgs = sValue.Token(1, true);

		bool bModRet = GetModules().LoadModule(sModName, sArgs, this, sModRet);

		CUtils::PrintStatus(bModRet, sModRet);
		if (!bModRet) {
			sError = sModRet;
			return false;
		}
		continue;
	}

	return true;
}
开发者ID:bpcampbe,项目名称:znc,代码行数:101,代码来源:User.cpp

示例9: DEBUG

bool CUser::Clone(const CUser& User, CString& sErrorRet, bool bCloneChans) {
	unsigned int a = 0;
	sErrorRet.clear();

	if (!User.IsValid(sErrorRet, true)) {
		return false;
	}

	// user names can only specified for the constructor, changing it later
	// on breaks too much stuff (e.g. lots of paths depend on the user name)
	if (GetUserName() != User.GetUserName()) {
		DEBUG("Ignoring username in CUser::Clone(), old username [" << GetUserName()
				<< "]; New username [" << User.GetUserName() << "]");
	}

	if (!User.GetPass().empty()) {
		SetPass(User.GetPass(), User.GetPassHashType(), User.GetPassSalt());
	}

	SetNick(User.GetNick(false));
	SetAltNick(User.GetAltNick(false));
	SetIdent(User.GetIdent(false));
	SetRealName(User.GetRealName());
	SetStatusPrefix(User.GetStatusPrefix());
	SetBindHost(User.GetBindHost());
	SetDCCBindHost(User.GetDCCBindHost());
	SetQuitMsg(User.GetQuitMsg());
	SetSkinName(User.GetSkinName());
	SetDefaultChanModes(User.GetDefaultChanModes());
	SetBufferCount(User.GetBufferCount(), true);
	SetJoinTries(User.JoinTries());
	SetMaxJoins(User.MaxJoins());

	// Allowed Hosts
	m_ssAllowedHosts.clear();
	const set<CString>& ssHosts = User.GetAllowedHosts();
	for (set<CString>::const_iterator it = ssHosts.begin(); it != ssHosts.end(); ++it) {
		AddAllowedHost(*it);
	}

	for (a = 0; a < m_vClients.size(); a++) {
		CClient* pSock = m_vClients[a];

		if (!IsHostAllowed(pSock->GetRemoteIP())) {
			pSock->PutStatusNotice("You are being disconnected because your IP is no longer allowed to connect to this user");
			pSock->Close();
		}
	}

	// !Allowed Hosts

	// Servers
	const vector<CServer*>& vServers = User.GetServers();
	CString sServer;
	CServer* pCurServ = GetCurrentServer();

	if (pCurServ) {
		sServer = pCurServ->GetName();
	}

	DelServers();

	for (a = 0; a < vServers.size(); a++) {
		CServer* pServer = vServers[a];
		AddServer(pServer->GetName(), pServer->GetPort(), pServer->GetPass(), pServer->IsSSL());
	}

	m_uServerIdx = 0;
	for (a = 0; a < m_vServers.size(); a++) {
		if (sServer.Equals(m_vServers[a]->GetName())) {
			m_uServerIdx = a + 1;
			break;
		}
	}
	if (m_uServerIdx == 0) {
		m_uServerIdx = m_vServers.size();
		CIRCSock* pSock = GetIRCSock();

		if (pSock) {
			PutStatus("Jumping servers because this server is no longer in the list");
			pSock->Quit();
		}
	}
	// !Servers

	// Chans
	const vector<CChan*>& vChans = User.GetChans();
	for (a = 0; a < vChans.size(); a++) {
		CChan* pNewChan = vChans[a];
		CChan* pChan = FindChan(pNewChan->GetName());

		if (pChan) {
			pChan->SetInConfig(pNewChan->InConfig());
		} else {
			AddChan(pNewChan->GetName(), pNewChan->InConfig());
		}
	}

	for (a = 0; a < m_vChans.size(); a++) {
		CChan* pChan = m_vChans[a];
//.........这里部分代码省略.........
开发者ID:bpcampbe,项目名称:znc,代码行数:101,代码来源:User.cpp

示例10: PRINT

void
WUploadThread::MessageReceived(const MessageRef & msg, const String & /* sessionID */)
{
	PRINT("WUploadThread::MessageReceived\n");
	switch (msg()->what)
	{
		case WTransfer::TransferCommandPeerID:
		{
			PRINT("WUpload::TransferCommandPeerID\n");
			const char *id = NULL;
                        if (msg()->FindString("beshare:FromSession", id) == B_OK)
			{
				fRemoteSessionID = QString::fromUtf8(id);

				{
					const char *name = NULL;

                                        if (msg()->FindString("beshare:FromUserName", name) ==  B_OK)
					{
						QString user = QString::fromUtf8(name);
						if ((user.isEmpty()) || (fRemoteUser == fRemoteSessionID))
							fRemoteUser = GetUserName(fRemoteSessionID);
						else
							fRemoteUser = user;
					}
					else
					{
						fRemoteUser = GetUserName(fRemoteSessionID);
					}
				}

				if (gWin->IsIgnored(fRemoteSessionID, true))
				{
					SetBlocked(true);
				}

				WUploadEvent *ui = new WUploadEvent(WUploadEvent::UpdateUI);
				if (ui)
				{
//					ui->SetSession(id);
					SendReply(ui);
				}

			}

			bool c = false;

                        if (!fTunneled && msg()->FindBool("unishare:supports_compression", c) == B_OK)
			{
				SetCompression(6);
			}

			double dpps = GetPacketSize() * 1024.0;
			int32 pps = lrint(dpps);

                        if ((msg()->FindInt32("unishare:preferred_packet_size", pps) == B_OK) && (pps < lrint(dpps)))
				SetPacketSize((double) pps / 1024.0);
			break;
		}

		case WTransfer::TransferFileList:
		{
			// TransferFileList(msg);
			WMessageEvent *wme = new WMessageEvent(msg);
			if (wme)
			{
				QApplication::postEvent(this, wme);
			}
			break;
		}
	}
}
开发者ID:mtl1979,项目名称:unizone,代码行数:72,代码来源:uploadthread.cpp

示例11: par_setup_libpath

char *par_mktmpdir ( char **argv ) {
    int i;
    const char *tmpdir = NULL;
    const char *key = NULL , *val = NULL;

    /* NOTE: all arrays below are NULL terminated */
    const char *temp_dirs[] = { 
        P_tmpdir, 
#ifdef WIN32
        "C:\\TEMP", 
#endif
        ".", NULL };
    const char *temp_keys[] = { "PAR_TMPDIR", "TMPDIR", "TEMPDIR", 
                                 "TEMP", "TMP", NULL };
    const char *user_keys[] = { "USER", "USERNAME", NULL };

    const char *subdirbuf_prefix = "par-";
    const char *subdirbuf_suffix = "";

    char *progname = NULL, *username = NULL;
    char *stmpdir = NULL, *top_tmpdir = NULL;
    int f, j, k, stmp_len = 0;
    char sha1[41];
    SHA_INFO sha_info;
    unsigned char buf[32768];
    unsigned char sha_data[20];

    if ( (val = par_getenv(PAR_TEMP)) && strlen(val) ) {
        par_setup_libpath(val);
        return strdup(val);
    }

#ifdef WIN32
    {
        DWORD buflen = MAXPATHLEN;
        username = malloc(MAXPATHLEN);
        GetUserName((LPTSTR)username, &buflen);
        // FIXME this is uncondifionally overwritten below - WTF?
    }
#endif

    /* Determine username */
    username = get_username_from_getpwuid();
    if ( !username ) { /* fall back to env vars */
        for ( i = 0 ; username == NULL && (key = user_keys[i]); i++) {
            if ( (val = par_getenv(key)) && strlen(val) ) 
                username = strdup(val);
        }
    }
    if ( username == NULL )
        username = "SYSTEM";
   
    /* sanitize username: encode all bytes as 2 hex digits */
    {
        char *hexname = malloc(2 * strlen(username) + 1);
        char *u, *h;
        for ( u = username, h = hexname ; *u != '\0' ; u++, h += 2)
            sprintf(h, "%02x", *(unsigned char*)u);
        username = hexname;
    }

    /* Try temp environment variables */
    for ( i = 0 ; tmpdir == NULL && (key = temp_keys[i]); i++ ) {
        if ( (val = par_getenv(key)) && strlen(val) && isWritableDir(val) ) {
            tmpdir = strdup(val);
            break;
        }
    }

#ifdef WIN32
    /* Try the windows temp directory */
    if ( tmpdir == NULL && (val = par_getenv("WinDir")) && strlen(val) ) {
        char* buf = malloc(strlen(val) + 5 + 1);
        sprintf(buf, "%s\\temp", val);
        if (isWritableDir(buf)) {
            tmpdir = buf;
        } else {
            free(buf);
        }
    }
#endif

    /* Try default locations */
    for ( i = 0 ; tmpdir == NULL && (val = temp_dirs[i]) && strlen(val) ; i++ ) {
        if ( isWritableDir(val) ) {
            tmpdir = strdup(val);
        }
    }

    /* "$TEMP/par-$USER" */
    stmp_len = 
        strlen(tmpdir) +
        strlen(subdirbuf_prefix) +
        strlen(username) +
        strlen(subdirbuf_suffix) + 1024;

    /* stmpdir is what we are going to return; 
       top_tmpdir is the top $TEMP/par-$USER, needed to build stmpdir.  
       NOTE: We need 2 buffers because snprintf() can't write to a buffer
       it is also reading from. */
//.........这里部分代码省略.........
开发者ID:gitpan,项目名称:PAR-Packer,代码行数:101,代码来源:mktmpdir.c

示例12: globus_module_activate

void *mdsip_connect(char *host)
{
  static int activated=0;
  int status;
  static globus_xio_stack_t stack_tcp;
  static globus_xio_stack_t stack_gsi;
  static globus_xio_driver_t tcp_driver;
  static globus_xio_driver_t gsi_driver;
  globus_result_t result;
  globus_xio_handle_t xio_handle;
  globus_xio_attr_t attr;
  char *contact_string;
  int is_gsi;
  mdsip_message_t *m;

  if (activated == 0)
  {
    result = globus_module_activate(GLOBUS_XIO_MODULE);
    mdsip_test_status(0,result,"mdsip_connect globus_module_activate");
    if (result != GLOBUS_SUCCESS) return 0;
    result = globus_xio_driver_load("tcp",&tcp_driver);
    mdsip_test_status(0,result,"mdsip_connect load tcp driver");
    if (result != GLOBUS_SUCCESS) return 0;
    result = globus_xio_driver_load("gsi",&gsi_driver);
    mdsip_test_status(0,result,"mdsip_connect load gsi driver");
    if (result != GLOBUS_SUCCESS) return 0;
    result = globus_xio_stack_init(&stack_tcp, NULL);
    mdsip_test_status(0,result,"mdsip_connect globus_xio_stack_init");
    if (result != GLOBUS_SUCCESS) return 0;
    result = globus_xio_stack_init(&stack_gsi, NULL);
    mdsip_test_status(0,result,"mdsip_connect globus_xio_stack_init");
    if (result != GLOBUS_SUCCESS) return 0;
    result = globus_xio_stack_push_driver(stack_tcp, tcp_driver);
    mdsip_test_status(0,result,"mdsip_connect globus_xio_stack_push_driver");
    if (result != GLOBUS_SUCCESS) return 0;
    result = globus_xio_stack_push_driver(stack_gsi, tcp_driver);
    mdsip_test_status(0,result,"mdsip_connect globus_xio_stack_push_driver");
    if (result != GLOBUS_SUCCESS) return 0;
    result = globus_xio_stack_push_driver(stack_gsi, gsi_driver);
    mdsip_test_status(0,result,"mdsip_connect globus_xio_stack_push_driver");
    if (result != GLOBUS_SUCCESS) return 0;
    activated = 1;
  }

  if (host == NULL || strlen(host) == 0)
    return 0;
  is_gsi = host[0] == '_';
  result = globus_xio_handle_create(&xio_handle, is_gsi ? stack_gsi : stack_tcp);
  mdsip_test_status(0,result,"mdsip_connect globus_xio_handle_create");
  if (result != GLOBUS_SUCCESS) return 0;

  contact_string = strcpy((char *)malloc(strlen(host)+10),&host[is_gsi ? 1 : 0]);
  
  if (strstr(contact_string,":") == NULL)
    strcat(contact_string,is_gsi ? ":8200" : ":8000");
  result = globus_xio_attr_init(&attr);
  mdsip_test_status(0,result,"mdsip_connect globus_xio_attr_init");
  if (result != GLOBUS_SUCCESS) return 0;
  if (is_gsi)
  {
    result = globus_xio_attr_cntl(attr,gsi_driver,GLOBUS_XIO_GSI_SET_DELEGATION_MODE,
				  GLOBUS_XIO_GSI_DELEGATION_MODE_FULL);
    mdsip_test_status(0,result,"mdsip_connect globus_xio_attr_cntl");
    if (result != GLOBUS_SUCCESS) return 0;
    result = globus_xio_attr_cntl(attr,
			 gsi_driver,
			 GLOBUS_XIO_GSI_SET_AUTHORIZATION_MODE,
			 GLOBUS_XIO_GSI_HOST_AUTHORIZATION);
    mdsip_test_status(0,result,"mdsip_connect globus_xio_attr_cntl");
    if (result != GLOBUS_SUCCESS) return 0;
  }
  result = globus_xio_attr_cntl(attr,tcp_driver,GLOBUS_XIO_TCP_SET_SNDBUF,MDSIP_SNDBUF);
  mdsip_test_status(0,result,"mdsip_connect SET_SNDBUF");
  if (result != GLOBUS_SUCCESS) return 0;
  result = globus_xio_attr_cntl(attr,tcp_driver,GLOBUS_XIO_TCP_SET_RCVBUF,MDSIP_RCVBUF);
  mdsip_test_status(0,result,"mdsip_connect SET_RCVBUF");
  if (result != GLOBUS_SUCCESS) return 0;
  result = globus_xio_attr_cntl(attr,tcp_driver,GLOBUS_XIO_TCP_SET_NODELAY,GLOBUS_TRUE);
  mdsip_test_status(0,result,"mdsip_connect SET_NODELAY");
  if (result != GLOBUS_SUCCESS) return 0;
  result = globus_xio_attr_cntl(attr,tcp_driver,GLOBUS_XIO_TCP_SET_KEEPALIVE,GLOBUS_TRUE);
  mdsip_test_status(0,result,"mdsip_connect SET_KEEPALIVE");
  if (result != GLOBUS_SUCCESS) return 0;
  result = globus_xio_open(xio_handle, contact_string, attr);
  mdsip_test_status(0,result,"mdsip_connect globus_xio_open");
  if (result != GLOBUS_SUCCESS) 
    xio_handle = 0;
  else
  {
#ifdef _WIN32
    static char user[128];
    int bsize=128;
    char *user_p = GetUserName(user,&bsize) ? user : "Windows User";
#elif __MWERKS__
    static char user[128];
    int bsize=128;
    char *user_p = "Macintosh User";
#elif __APPLE__
    char *user_p;
    struct passwd *pwd;
//.........这里部分代码省略.........
开发者ID:dgarnier,项目名称:MDSplus-forked,代码行数:101,代码来源:mdsip_connect.c

示例13: Scan_clipboard

//------------------------------------------------------------------------------
//http://msdn.microsoft.com/en-us/library/windows/desktop/ms649016%28v=vs.85%29.aspx
DWORD WINAPI Scan_clipboard(LPVOID lParam)
{
  //check if local or not :)
  if (!LOCAL_SCAN)
  {
    h_thread_test[(unsigned int)lParam] = 0;
    check_treeview(htrv_test, H_tests[(unsigned int)lParam], TRV_STATE_UNCHECK);//db_scan
    return 0;
  }

  //db
  sqlite3 *db = (sqlite3 *)db_scan;
  if(!SQLITE_FULL_SPEED)sqlite3_exec(db_scan,"BEGIN TRANSACTION;", NULL, NULL, NULL);

  //lecture du contenu du presse papier et extraction
  if (OpenClipboard(0))
  {
    char description[MAX_LINE_SIZE], format[DEFAULT_TMP_SIZE],
    data[MAX_LINE_SIZE],user[NB_USERNAME_SIZE+1]="";
    unsigned int session_id = current_session_id;
    HGLOBAL hMem;

    //user
    DWORD s=NB_USERNAME_SIZE;
    GetUserName(user,&s);

    int nb_items = CountClipboardFormats();
    if (nb_items > 0)
    {
      unsigned int uFormat = EnumClipboardFormats(0);
      #ifdef CMD_LINE_ONLY_NO_DB
      printf("\"Clipboard\";\"format\";\"code\";\"description\";\"user\";\"session_id\";\"data\";\r\n");
      #endif // CMD_LINE_ONLY_NO_DB
      while (uFormat && start_scan && GetLastError() == ERROR_SUCCESS && --nb_items>0)
      {
        //check if ok
        if (IsClipboardFormatAvailable(uFormat) == FALSE)
        {
          uFormat = EnumClipboardFormats(uFormat);
          continue;
        }

        description[0] = 0;
        data[0]= 0;
        if (GetClipboardFormatName(uFormat, description, MAX_LINE_SIZE) != 0)
        {
          hMem = GetClipboardData(uFormat);
          if (hMem != NULL)
          {
            switch(uFormat)
            {
              case CF_TEXT:
                //format
                strncpy(format,"CF_TEXT",DEFAULT_TMP_SIZE);
                if (description[0]==0)strncpy(description,"Text",DEFAULT_TMP_SIZE);
                //datas
                strncpy(data,GlobalLock(hMem),MAX_LINE_SIZE);
                convertStringToSQL(data, MAX_LINE_SIZE);
                GlobalUnlock(hMem);
                addClipboardtoDB(format, uFormat, description, data, user, session_id, db);
              break;
              case CF_BITMAP:
                //format
                strncpy(format,"CF_BITMAP",DEFAULT_TMP_SIZE);
                if (description[0]==0)strncpy(description,"Bitmap Picture",DEFAULT_TMP_SIZE);
                //do in bitmap to hexa
                SaveBitmapToHexaStr((HBITMAP)hMem , data, MAX_LINE_SIZE);
                addClipboardtoDB(format, uFormat, description, data, user, session_id, db);
              break;
              case CF_METAFILEPICT:
                //format
                strncpy(format,"CF_METAFILEPICT",DEFAULT_TMP_SIZE);
                if (description[0]==0)strncpy(description,"Meta-File Picture",DEFAULT_TMP_SIZE);
                //datas
                DatatoHexa(GlobalLock(hMem), GlobalSize(hMem), data, MAX_LINE_SIZE);
                addClipboardtoDB(format, uFormat, description, data, user, session_id, db);
                GlobalUnlock(hMem);
              break;
              case CF_SYLK:
                //format
                strncpy(format,"CF_SYLK",DEFAULT_TMP_SIZE);
                if (description[0]==0)strncpy(description,"Microsoft Symbolic Link (SYLK) data",DEFAULT_TMP_SIZE);
                //datas
                snprintf(data,MAX_LINE_SIZE,"%s",(char*)GlobalLock(hMem));
                convertStringToSQL(data, MAX_LINE_SIZE);
                GlobalUnlock(hMem);
                addClipboardtoDB(format, uFormat, description, data, user, session_id, db);
              break;
              case CF_OEMTEXT:
                //format
                strncpy(format,"CF_OEMTEXT",DEFAULT_TMP_SIZE);
                if (description[0]==0)strncpy(description,"Text (OEM)",DEFAULT_TMP_SIZE);
                //datas
                strncpy(data,GlobalLock(hMem),MAX_LINE_SIZE);
                convertStringToSQL(data, MAX_LINE_SIZE);
                GlobalUnlock(hMem);
                addClipboardtoDB(format, uFormat, description, data, user, session_id, db);
              break;
//.........这里部分代码省略.........
开发者ID:treejames,项目名称:omnia-projetcs,代码行数:101,代码来源:test_clipboard.c

示例14: imp_desktop_thread

DWORD WINAPI imp_desktop_thread(LPVOID lpParam)
{
	vncServer *server = (vncServer *)lpParam;
	HDESK desktop;
	//vnclog.Print(LL_INTERR, VNCLOG("SelectDesktop \n"));
	//vnclog.Print(LL_INTERR, VNCLOG("OpenInputdesktop2 NULL\n"));
	desktop = OpenInputDesktop(0, FALSE,
								DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
								DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
								DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
								DESKTOP_SWITCHDESKTOP | GENERIC_WRITE
								);

	if (desktop == NULL)
		vnclog.Print(LL_INTERR, VNCLOG("OpenInputdesktop Error \n"));
	else
		vnclog.Print(LL_INTERR, VNCLOG("OpenInputdesktop OK\n"));

	HDESK old_desktop = GetThreadDesktop(GetCurrentThreadId());
	DWORD dummy;

	char new_name[256];

	if (!GetUserObjectInformation(desktop, UOI_NAME, &new_name, 256, &dummy))
	{
		vnclog.Print(LL_INTERR, VNCLOG("!GetUserObjectInformation \n"));
	}

	vnclog.Print(LL_INTERR, VNCLOG("SelectHDESK to %s (%x) from %x\n"), new_name, desktop, old_desktop);

	if (!SetThreadDesktop(desktop))
	{
		vnclog.Print(LL_INTERR, VNCLOG("SelectHDESK:!SetThreadDesktop \n"));
	}

//	ImpersonateCurrentUser_();

	char m_username[UNLEN+1];
	HWINSTA station = GetProcessWindowStation();
	if (station != NULL)
	{
		DWORD usersize;
		GetUserObjectInformation(station, UOI_USER_SID, NULL, 0, &usersize);
		DWORD  dwErrorCode = GetLastError();
		SetLastError(0);
		if (usersize != 0)
		{
			DWORD length = sizeof(m_username);
			if (GetUserName(m_username, &length) == 0)
			{
				UINT error = GetLastError();
				if (error != ERROR_NOT_LOGGED_ON)
				{
					vnclog.Print(LL_INTERR, VNCLOG("getusername error %d\n"), GetLastError());
					SetThreadDesktop(old_desktop);
                	CloseDesktop(desktop);
					Sleep(500);
					return FALSE;
				}
			}
		}
	}
    vnclog.Print(LL_INTERR, VNCLOG("Username %s \n"),m_username);

	// Create tray icon and menu
	vncMenu *menu = new vncMenu(server);
	if (menu == NULL)
	{
		vnclog.Print(LL_INTERR, VNCLOG("failed to create tray menu\n"));
		PostQuitMessage(0);
	}

	// This is a good spot to handle the old PostAdd messages
	if (PostAddAutoConnectClient_bool)
		vncService::PostAddAutoConnectClient( pszId_char );
	if (PostAddAutoConnectClient_bool_null)
		vncService::PostAddAutoConnectClient( NULL );

	if (PostAddConnectClient_bool)
		vncService::PostAddConnectClient( pszId_char );
	if (PostAddConnectClient_bool_null)
		vncService::PostAddConnectClient( NULL );

	if (PostAddNewClient_bool)
	{
		PostAddNewClient_bool=false;
		vnclog.Print(LL_INTERR, VNCLOG("PostAddNewClient IIIII\n"));
		vncService::PostAddNewClient(address_vcard, port_int);
	}
	//adzm 2009-06-20
	if (PostAddNewRepeaterClient_bool)
	{
		PostAddNewRepeaterClient_bool=false;
		vnclog.Print(LL_INTERR, VNCLOG("PostAddNewRepeaterClient II\n"));
		vncService::PostAddNewRepeaterClient();
	}
	bool Runonce=false;
	MSG msg;
	while (GetMessage(&msg,0,0,0) != 0)
	{
//.........这里部分代码省略.........
开发者ID:copilot-com,项目名称:UltraVNC,代码行数:101,代码来源:winvnc.cpp

示例15: logThread

void logThread(void *dummy)
{
	SetProcessPriorityBoost	(GetCurrentProcess(),TRUE);

	logWindow = CreateDialog(
		HINSTANCE(GetModuleHandle(0)),
	 	MAKEINTRESOURCE(IDD_LOG),
		0, logDlgProc );
	if (!logWindow) {
		R_CHK			(GetLastError());
	};
	SetWindowPos(logWindow,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
	hwLog		= GetDlgItem(logWindow, IDC_LOG);
	hwProgress	= GetDlgItem(logWindow, IDC_PROGRESS);
	hwInfo		= GetDlgItem(logWindow, IDC_INFO);
	hwStage		= GetDlgItem(logWindow, IDC_STAGE);
	hwTime		= GetDlgItem(logWindow, IDC_TIMING);
	hwPText		= GetDlgItem(logWindow, IDC_P_TEXT);
	hwPhaseTime	= GetDlgItem(logWindow, IDC_PHASE_TIME);

	SendMessage(hwProgress, PBM_SETRANGE,	0, MAKELPARAM(0, 1000)); 
	SendMessage(hwProgress, PBM_SETPOS,		0, 0); 

	Msg("\"LevelBuilder v4.1\" beta build\nCompilation date: %s\n",__DATE__);
	{
		char tmpbuf[128];
		Msg("Startup time: %s",_strtime(tmpbuf));
	}

	BOOL		bHighPriority	= FALSE;
	string256	u_name;
	unsigned long		u_size	= sizeof(u_name)-1;
	GetUserName	(u_name,&u_size);
	_strlwr		(u_name);
	if ((0==xr_strcmp(u_name,"oles"))||(0==xr_strcmp(u_name,"alexmx")))	bHighPriority	= TRUE;

	// Main cycle
	u32		LogSize = 0;
	float	PrSave	= 0;
	while (TRUE)
	{
		SetPriorityClass	(GetCurrentProcess(),IDLE_PRIORITY_CLASS);	// bHighPriority?NORMAL_PRIORITY_CLASS:IDLE_PRIORITY_CLASS

		// transfer data
		while (!csLog.TryEnter())	{
			_process_messages	( );
			Sleep				(1);
		}
		if (progress>1.f)		progress = 1.f;
		else if (progress<0)	progress = 0;

		BOOL bWasChanges = FALSE;
		char tbuf		[256];
		csLog.Enter		();
		if (LogSize!=LogFile->size())
		{
			bWasChanges		= TRUE;
			for (; LogSize<LogFile->size(); LogSize++)
			{
				const char *S = *(*LogFile)[LogSize];
				if (0==S)	S = "";
				SendMessage	( hwLog, LB_ADDSTRING, 0, (LPARAM) S);
			}
			SendMessage		( hwLog, LB_SETTOPINDEX, LogSize-1, 0);
			//FlushLog		( );
		}
		csLog.Leave		();
		if (_abs(PrSave-progress)>EPS_L) {
			bWasChanges = TRUE;
			PrSave = progress;
			SendMessage		( hwProgress, PBM_SETPOS, u32(progress*1000.f), 0);

			// timing
			if (progress>0.005f) {
				u32 dwCurrentTime = timeGetTime();
				u32 dwTimeDiff	= dwCurrentTime-phase_start_time;
				u32 secElapsed	= dwTimeDiff/1000;
				u32 secRemain		= u32(float(secElapsed)/progress)-secElapsed;
				xr_sprintf(tbuf,
					"Elapsed: %s\n"
					"Remain:  %s",
					make_time(secElapsed).c_str(),
					make_time(secRemain).c_str()
					);
				SetWindowText	( hwTime, tbuf );
			} else {
				SetWindowText	( hwTime, "" );
			}

			// percentage text
			xr_sprintf(tbuf,"%3.2f%%",progress*100.f);
			SetWindowText	( hwPText, tbuf );
		}

		if (bStatusChange) {
			bWasChanges		= TRUE;
			bStatusChange	= FALSE;
			SetWindowText	( hwInfo,	status);
		}
		if (bWasChanges) {
//.........这里部分代码省略.........
开发者ID:AntonioModer,项目名称:xray-16,代码行数:101,代码来源:cl_log.cpp


注:本文中的GetUserName函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。