예제 #1
0
BOOL __declspec(dllexport) RemoteFreeLibraryNT(DWORD dwTargetProcessID, HMODULE hModule)
{
	if (!IsWindowsNT())
	{
		::SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
		return FALSE;
	}

	LPTHREAD_START_ROUTINE lpfn = (LPTHREAD_START_ROUTINE)::GetProcAddress(::GetModuleHandleA("kernel32.dll"), "FreeLibrary");
	if (lpfn == NULL)
		return FALSE;
	
	HANDLE hRemoteProc = OpenProcessForRemoteExecute(dwTargetProcessID);
	if (hRemoteProc == NULL)
		return FALSE;

	DWORD dwExitCode = 0;
	DWORD dwErrorCode = ERROR_SUCCESS;
	BOOL bOK = RemoteExecute(hRemoteProc, lpfn, (LPVOID)hModule, dwExitCode, dwErrorCode);
	::CloseHandle(hRemoteProc);
	if (!bOK)
	{
		::SetLastError(dwErrorCode);
		return FALSE;
	}

	if (dwExitCode == 0)
	{
		::SetLastError(ERROR_MOD_NOT_FOUND);
		return FALSE;
	}

	return TRUE;
}
예제 #2
0
파일: drivemap.cpp 프로젝트: bagdxk/openafs
BOOL fCanIssuePIOCTL (void)
{
   if (!IsWindowsNT())
      {
      TCHAR szGateway[ 256 ] = TEXT("");
      GetClientNetbiosName (szGateway);
      return (szGateway[0]) ? TRUE : FALSE;
      }

   SERVICE_STATUS Status;
   memset (&Status, 0x00, sizeof(Status));
   Status.dwCurrentState = SERVICE_STOPPED;

   SC_HANDLE hManager;
   if ((hManager = OpenSCManager (NULL, NULL, GENERIC_READ)) != NULL)
      {
      SC_HANDLE hService;
      if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"), GENERIC_READ)) != NULL)
         {
         QueryServiceStatus (hService, &Status);
         CloseServiceHandle (hService);
         }

      CloseServiceHandle (hManager);
      }

   return (Status.dwCurrentState == SERVICE_RUNNING) ? TRUE : FALSE;
}
예제 #3
0
HMODULE __declspec(dllexport) RemoteLoadLibraryNTA(DWORD dwTargetProcessID, LPCSTR lpszDllPath)
{	
	if (lpszDllPath == NULL || lpszDllPath[0] == 0)
	{
		::SetLastError(ERROR_MOD_NOT_FOUND);
		return NULL;
	}

	if (!IsWindowsNT())
	{
		::SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
		return NULL;
	}

	LPTHREAD_START_ROUTINE lpfn = (LPTHREAD_START_ROUTINE)::GetProcAddress(::GetModuleHandleA("kernel32.dll"), "LoadLibraryA");
	if (lpfn == NULL)
		return NULL;

	DWORD dwExitCode = 0;
	DWORD dwErrorCode = ERROR_SUCCESS;
	BOOL bOK = RemoteExecute(dwTargetProcessID, lpfn, (LPCVOID)lpszDllPath, (::strlen(lpszDllPath) + 1) * sizeof(char), dwExitCode, dwErrorCode);
	if (!bOK)
	{
		::SetLastError(dwErrorCode);
		return NULL;
	}

	if (dwExitCode == 0)
	{
		::SetLastError(ERROR_FILE_NOT_FOUND);
		return NULL;
	}

	return (HMODULE)dwExitCode;
}
예제 #4
0
/*------------------------------------------------------------------------
Procedure:     DoStartOcaml ID:1
Purpose:       Starts the ocaml interpreter ocaml.exe. The standard
input of the interpreter will be connected to a pipe,
and the standard output and standard error to another
pipe. The interpreter starts as a hidden process,
showing only in the task list. Since this is in an
own thread, its workings are independent of the rest
of the program. After starting the interpreter, the
thread waits in case the interpreter exits, for
instance if the user or some program types #quit;;.
In this case, the waiting thread awakens and exits
the user interface.
Input:         Not used. It uses the OcamlPath global variable, that
is supposed to be correct, no test for its validity
are done here.
Output:        None visible
Errors:        If any system call for whatever reason fails, the
thread will exit. No error message is shown.
------------------------------------------------------------------------*/
DWORD WINAPI DoStartOcaml(LPVOID param)
{
        HWND hwndParent = (HWND) param;
	char *cmdline;
	int processStarted;
	LPSECURITY_ATTRIBUTES lpsa=NULL;
	SECURITY_ATTRIBUTES sa;
	SECURITY_DESCRIPTOR sd;

	sa.nLength = sizeof(SECURITY_ATTRIBUTES);
	// Under windows NT/2000/Whistler we have to initialize the security descriptors
	// This is not necessary under windows 98/95.
	if (IsWindowsNT()) {
		InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
		SetSecurityDescriptorDacl(&sd,TRUE,NULL,FALSE);
		sa.bInheritHandle = TRUE;
		sa.lpSecurityDescriptor = &sd;
		lpsa = &sa;
	}
	memset(&startInfo,0,sizeof(STARTUPINFO));
	startInfo.cb = sizeof(STARTUPINFO);
	// Create a pipe for the child process's STDOUT.
	if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &sa, 0))
		return 0;
	// Create a pipe for the child process's STDIN.
	if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &sa, 0))
		return 0;
	// Setup the start info structure
	startInfo.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
	startInfo.wShowWindow = SW_HIDE;
	startInfo.hStdOutput = hChildStdoutWr;
	startInfo.hStdError = hChildStdoutWr;
	startInfo.hStdInput = hChildStdinRd;
	cmdline = OcamlPath;
	// Set the OCAMLLIB environment variable
	SetEnvironmentVariable("OCAMLLIB", LibDir);
	// Let's go: start the ocaml interpreter
	processStarted = CreateProcess(NULL,cmdline,lpsa,lpsa,1,
		CREATE_NEW_PROCESS_GROUP|NORMAL_PRIORITY_CLASS,
		NULL,ProgramParams.CurrentWorkingDir,&startInfo,&pi);
	if (processStarted) {
		WaitForSingleObject(pi.hProcess,INFINITE);
		GetExitCodeProcess(pi.hProcess,(unsigned long *)&OcamlStatus);
		CloseHandle(pi.hProcess);
		PostMessage(hwndMain,WM_QUITOCAML,0,0);
	}
	else {
		char *msg = malloc(1024);
		wsprintf(msg,"Impossible to start ocaml.exe in:\n%s",cmdline);
		ShowDbgMsg(msg);
		free(msg);
	}
	return 0;
}
예제 #5
0
파일: drivemap.cpp 프로젝트: bagdxk/openafs
void QueryDriveMapList_FindNetworkDrives (PDRIVEMAPLIST pList, BOOL *pfFoundNew)
{
   for (TCHAR chDrive = chDRIVE_A; chDrive <= chDRIVE_Z; ++chDrive)
      {
      TCHAR szSubmount[ MAX_PATH ];
      if (!GetDriveSubmount (chDrive, szSubmount))
         continue;

      // We've got a mapping!  Drive {chDrive} is mapped to submount
      // {szSubmount}. See if that submount makes sense.
      //
      if (!IsWindowsNT())
         {
         size_t iDrive = chDrive - chDRIVE_A;
         if (pList->aDriveMap[ iDrive ].szMapping[0] != TEXT('\0'))
            {
            pList->aDriveMap[ iDrive ].fActive = TRUE;
            lstrcpy (pList->aDriveMap[ iDrive ].szSubmount, szSubmount);
            }
         continue;
         }
      else // (IsWindowsNT())
         {
         TCHAR szAfsPath[ MAX_PATH ];
         if (!SubmountToPath (pList, szAfsPath, szSubmount, TRUE))
            continue;

         // Okay, we know that drive {chDrive} is mapped to afs path {szAfsPath}.
         // If this drive is a global afs drive, then reject it.  Otherwise, look
         // at pList->aDriveMap, to see if this drive mapping is already in our
         // list. If not, add it and set pfFoundNew.
         //
         if (DriveIsGlobalAfsDrive(chDrive))
            continue;

         size_t iDrive = chDrive - chDRIVE_A;
         if (lstrcmpi (pList->aDriveMap[ iDrive ].szMapping, szAfsPath))
            {
            *pfFoundNew = TRUE;
            pList->aDriveMap[ iDrive ].fPersistent = TRUE;
            }
         pList->aDriveMap[ iDrive ].fActive = TRUE;
         pList->aDriveMap[ iDrive ].chDrive = chDrive;
         lstrcpy (pList->aDriveMap[ iDrive ].szSubmount, szSubmount);
         AdjustAfsPath (pList->aDriveMap[ iDrive ].szMapping, szAfsPath, TRUE, TRUE);
         }
      }
}
예제 #6
0
void CSysInfo::Init()
{
	// Init routines. It must be called before getting system information.

/* #ifdef NET_INFO
	m_nNumAdaptersIphlpapi=0;
	if((m_hmIphlpapiDll=::LoadLibrary(_T("iphlpapi.dll")))!=NULL)
	{
		// FARPROC GetProcAddress(
		//		HMODULE hModule,    // handle to DLL module
		//		LPCSTR lpProcName   // function name
		// );
		m_bIphlpapiDll=TRUE;
		m_GetAdaptersInfo=(pGetAdaptersInfo)::GetProcAddress(m_hmIphlpapiDll,"GetAdaptersInfo");
		m_GetIfEntry=(pGetIfEntry)::GetProcAddress(m_hmIphlpapiDll,"GetIfEntry");
	};
#ifdef MIB
	m_bMibDll=m_mib.Init();
#endif MIB
#endif NET_INFO*/

	if (IsWindowsNT())
	{
		if((m_hmPsapiDll=::LoadLibrary(_T("psapi.dll")))!=NULL)
		{
			m_bPsapiDll=TRUE;
			m_GetProcessMemoryInfo=(pGetProcessMemoryInfo)::GetProcAddress(m_hmPsapiDll,"GetProcessMemoryInfo");
		};
	};

	DetectOSType();
	DetectNumProcessors();
	DetectCPUType();
	DetectMemory();
	DetectIEVersion();
	DetectADOVersion();
/* #ifdef NET_INFO
	DetectAdaptersIphlpapi();
#ifdef MIB
	MIBRefreshAddresses();
	DetectAdaptersMIB();
#endif MIB
#endif NET_INFO*/
	DetectUserAdmin();
	DetectLoginUserName();
	DetectWorkingDir();
}
예제 #7
0
int _tmain(int argc, _TCHAR* argv[])
{
	if(argc < 3) {
		printf("Usage: %s program.exe library.dll\n", argv[0]);
		return 0;
	}
	OutputDebugString("Starting up");
    if(IsWindowsNT()) {
        //unsigned long pid = GetTargetProcessIdFromProcname((char *)"guiTest.exe");
		unsigned long pid = GetTargetProcessIdFromProcname(argv[1]);
		if(pid == 0) {
			MessageBox(0, "Process not found", "Error!", 0);
			return 0;
		}
        printf("PID: %u\n", pid);
        LoadDll(argv[1], argv[2]);
    } else {
        MessageBox(0, "Your system does not support this method", "Error!", 0);
    }
	return 0;
}
예제 #8
0
파일: drivemap.cpp 프로젝트: bagdxk/openafs
BOOL SubmountToPath (PDRIVEMAPLIST pList, LPTSTR pszPath, LPTSTR pszSubmount, BOOL fMarkInUse)
{
   // We can't do this translation unless we're under Windows NT.
   //
   if (!IsWindowsNT())
      return FALSE;

   // \\computer-afs\all always maps to "/afs"
   //
   if (!lstrcmpi (pszSubmount, TEXT("all")))
      {
      lstrcpy (pszPath, cm_slash_mount_root);
      return TRUE;
      }

   // Otherwise, look up our list of submounts.
   //
#ifdef AFSIFS
    AdjustAfsPath (pszPath, pszSubmount, TRUE, TRUE);
#endif
    for (size_t ii = 0; ii < pList->cSubmounts; ++ii)
    {
        BOOL b;
#ifndef AFSIFS
        b = !lstrcmpi (pList->aSubmounts[ii].szSubmount, pszSubmount);
#else
        b = !lstrcmpi (pList->aSubmounts[ii].szMapping, pszPath);
#endif
        if (b)
        {
            if (fMarkInUse)
                pList->aSubmounts[ii].fInUse = TRUE;
            AdjustAfsPath (pszPath, pList->aSubmounts[ii].szMapping, TRUE, TRUE);
            return TRUE;
        }
    }

    return FALSE;
}
예제 #9
0
HMODULE __declspec(dllexport) RemoteGetModuleHandleNTW(DWORD dwTargetProcessID, LPCWSTR lpszDllPath)
{
	if (g_kernel32.GetModuleHandleW == NULL)
	{
		::SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
		return NULL;
	}

	if (lpszDllPath && lpszDllPath[0] == 0)
	{
		::SetLastError(ERROR_MOD_NOT_FOUND);
		return NULL;
	}
		
	if (!IsWindowsNT())
	{
		::SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
		return NULL;
	}
	
	DWORD dwExitCode = 0;
	DWORD dwErrorCode = ERROR_SUCCESS;
	BOOL bOK = RemoteExecute(dwTargetProcessID, (LPTHREAD_START_ROUTINE)g_kernel32.GetModuleHandleW, (LPCVOID)lpszDllPath, lpszDllPath ? (::wcslen(lpszDllPath) + 1) * sizeof(wchar_t) : 0, dwExitCode, dwErrorCode);
	if (!bOK)
	{
		::SetLastError(dwErrorCode);
		return NULL;
	}

	if (dwExitCode == 0)
	{
		::SetLastError(ERROR_FILE_NOT_FOUND);
		return NULL;
	}

	return (HMODULE)dwExitCode;
}
예제 #10
0
static BOOL Is32BitEnvironment(void)
{
   return IsWindowsNT() || IsWindows95();
}
예제 #11
0
void
File::Delete (/*[in]*/ const PathName &		path,
                       /*[in]*/ bool			tryHarder,
                       /*[in]*/ bool			updateFndb)
{
    if (updateFndb
            && SessionImpl::GetSession()->IsTEXMFFile(path.Get(), 0, 0)
            && Fndb::FileExists(path))
    {
        Fndb::Remove (path);
    }

    FileAttributes attributes = File::GetAttributes(path);

    bool done;

    try
    {
        if ((attributes & FileAttributes::ReadOnly) != 0)
        {
            attributes &= ~ FileAttributes(FileAttributes::ReadOnly);
            File::SetAttributes (path, attributes);
        }
        File::Delete (path);
        done = true;
    }

    catch (const UnauthorizedAccessException &)
    {
#if defined(MIKTEX_WINDOWS)
        if (! tryHarder)
        {
            throw;
        }
        done = false;
#else
        throw;
#endif
    }

#if defined(MIKTEX_WINDOWS)
    if (! done)
    {
        // move the file out of the way
        PathName absPath (path);
        if (! Utils::IsAbsolutePath(path.Get()))
        {
            absPath.MakeAbsolute ();
        }
        wchar_t szDir[BufferSizes::MaxPath];
        if (IsWindowsNT())
        {
            DllProc3<BOOL, LPCWSTR, LPWSTR, DWORD>
            getVolumePathNameW ("Kernel32.dll",  "GetVolumePathNameW");
            if (! getVolumePathNameW(absPath.ToWideCharString().c_str(),
                                     szDir,
                                     BufferSizes::MaxPath))
            {
                FATAL_WINDOWS_ERROR ("GetVolumePathNameA", absPath.Get());
            }
        }
        else
        {
#if defined(MIKTEX_SUPPORT_LEGACY_WINDOWS)
            dir = absPath;
            dir.RemoveFileSpec ();
#else
            UNSUPPORTED_PLATFORM ();
#endif
        }
        wchar_t szTemp[BufferSizes::MaxPath];
        if (GetTempFileNameW(szDir, L"mik", 0, szTemp) == 0)
        {
            FATAL_WINDOWS_ERROR ("GetTempFileNameW", WU_(szDir));
        }
        File::Delete (szTemp);
        File::Move (absPath, szTemp);
        SessionImpl::GetSession()->ScheduleFileRemoval (PathName(szTemp).Get());
    }
#endif
}
예제 #12
0
//
// Does the current user have administrator rights ?
//
void CSysInfo::DetectUserAdmin()
{
	if (!IsWindowsNT())
	{
		m_bUserAdmin=TRUE;
		return;
	};

    HANDLE hAccessToken       = NULL;
    PBYTE  pInfoBuffer        = NULL;
    DWORD  dwInfoBufferSize   = 1024;
    PTOKEN_GROUPS ptgGroups   = NULL;
    PSID   psidAdministrators = NULL;
    SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
    BOOL   bResult = FALSE;
    
    __try
    {
		// init security token
        if( !AllocateAndInitializeSid( 
            &siaNtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
            DOMAIN_ALIAS_RID_ADMINS, 0,0,0,0,0,0, &psidAdministrators ) )
                __leave;
        
        // for Windows NT 4.0 only
        if( !OpenProcessToken( GetCurrentProcess(),TOKEN_QUERY,&hAccessToken ) )
            __leave;

        do
        {
            if( pInfoBuffer )
                delete pInfoBuffer;
            pInfoBuffer = new BYTE[dwInfoBufferSize];
            if( !pInfoBuffer )
                __leave;
            SetLastError( 0 );
            if( !GetTokenInformation( 
                    hAccessToken, 
                    TokenGroups, pInfoBuffer,
                    dwInfoBufferSize, &dwInfoBufferSize ) &&
                ( ERROR_INSUFFICIENT_BUFFER != GetLastError() )
               )
                __leave;
            else
                ptgGroups = (PTOKEN_GROUPS)pInfoBuffer;
        }
        while( GetLastError() );
        
        for( UINT i = 0; i < ptgGroups->GroupCount; i++ )
        {
            if( EqualSid(psidAdministrators,ptgGroups->Groups[i].Sid) )
            {
                m_bUserAdmin=TRUE;
                __leave;
            }
        } 
    }

    __finally
    {
        if( hAccessToken )
            CloseHandle( hAccessToken );
        if( pInfoBuffer )
            delete pInfoBuffer;
        if( psidAdministrators )
            FreeSid( psidAdministrators );
    }
}
예제 #13
0
//
//  Detect a type of operation system
//
void CSysInfo::DetectOSType()
{
	BOOL bOSINFOEXWorking=FALSE;

	OSVERSIONINFO v;
	ZeroMemory(&v,sizeof(OSVERSIONINFO));
	v.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
	GetVersionEx((LPOSVERSIONINFO)&v);

	m_dwWinMajor=v.dwMajorVersion;
	m_dwWinMinor=v.dwMinorVersion;
	m_dwBuildNumber=v.dwBuildNumber;

	if (!IsWindowsNT())
	{
		// Windows 9x/ME.
		if (m_dwWinMinor==0)  { m_sOSType=_T(W95_s); };
		if (m_dwWinMinor==10) { m_sOSType=_T(W98_s); };
		if (m_dwWinMinor==90) { m_sOSType=_T(WME_s); };
		m_sOSType+=v.szCSDVersion;
		return;
	};

	// Get Service Pack number
	int n=0,j=-1; CString sSvcPack; TCHAR szNum[10];
	sSvcPack=v.szCSDVersion;
	for (n=1;n<=9;n++) {
		_stprintf(szNum,_T("%d"),n);
		j=sSvcPack.Find(szNum);
		if (j>=0) break;
	};
	if (j>=0) m_dwServicePack=n;

	// Check for OSVERSIONINFOEX-compatibility
	// It works only on Windows NT 4.0 Service Pack 6 or better
	if ((m_dwWinMajor>=5) || (m_dwServicePack>=6))
		{ bOSINFOEXWorking=TRUE; };

	if (m_dwWinMajor==4)
	{
		// Windows NT 4.0
		m_sOSType=_T(NT4_s);
	}
	else
	{
		if (m_dwWinMajor>=5)
		{
			if (m_dwWinMinor==0) { m_sOSType=_T(W2K_s); };  // Windows 2000
			if (m_dwWinMinor==1) { m_sOSType=_T(WXP_s); };  // Windows XP
		};
	};

	if (bOSINFOEXWorking)
	{
		MYOSVERSIONINFOEX osvi;
		BOOL bOsVersionInfoEx;
		ZeroMemory(&osvi,sizeof(MYOSVERSIONINFOEX));
		osvi.dwOSVersionInfoSize = sizeof(MYOSVERSIONINFOEX);
		bOsVersionInfoEx=GetVersionEx((LPOSVERSIONINFO)&osvi);

		if (bOsVersionInfoEx)
		{
			if (osvi.wProductType==MY_VER_NT_WORKSTATION)
			{
				if ((osvi.dwMajorVersion==5) && (osvi.dwMinorVersion==1))
				{
					// Windows XP
					if (osvi.wSuiteMask & MY_VER_SUITE_PERSONAL)
						{ m_sOSType+=_T(XHE_s); }
					else
						{ m_sOSType+=_T(XPR_s); };
				};

				if ((osvi.dwMajorVersion==5) && (osvi.dwMinorVersion==0))
				{
					// Windows 2000 Professional
					m_sOSType+=_T(PRO_s);
				};

				if (osvi.dwMajorVersion==4)
				{
					// Windows NT 4.0 Workstation
					m_sOSType+=_T(WKS_s);
				};
			};

			if ((osvi.wProductType==MY_VER_NT_SERVER) || (osvi.wProductType==MY_VER_NT_DOMAIN_CONTROLLER))
			{
				if (osvi.dwMajorVersion==5)
				{
					if (osvi.wSuiteMask & MY_VER_SUITE_ENTERPRISE) { m_sOSType+=_T(ADV_s); };
					if (osvi.wSuiteMask & MY_VER_SUITE_DATACENTER) { m_sOSType+=_T(DTC_s); };
					if (osvi.wSuiteMask & MY_VER_SUITE_TERMINAL) { m_sOSType+=_T(TER_s); };
					if (osvi.wSuiteMask & MY_VER_SUITE_BACKOFFICE) { m_sOSType+=_T(BOF_s); };
					m_sOSType+=_T(SER_s);
				};
				if (osvi.dwMajorVersion==4 && osvi.dwMinorVersion==0) { m_sOSType+=_T(SER_s); };
			};

			if (osvi.wProductType==MY_VER_NT_DOMAIN_CONTROLLER)
				{ m_sOSType+=_T(DOM_s); };
		};
	};

	if (m_dwServicePack>0)
	{
		m_sOSType+=_T(" ");
		m_sOSType+=v.szCSDVersion;
	};
}
예제 #14
0
파일: drivemap.cpp 프로젝트: bagdxk/openafs
BOOL GetDriveSubmount (TCHAR chDrive, LPTSTR pszSubmountNow)
{
	BOOL isWinNT = IsWindowsNT();

	TCHAR szDrive[] = TEXT("*:");
    szDrive[0] = chDrive;

    TCHAR szMapping[ _MAX_PATH ] = TEXT("");

    if (isWinNT && !QueryDosDevice (szDrive, szMapping, MAX_PATH))
           return FALSE;

    LPTSTR pszSubmount = szMapping;

	TCHAR szNetBiosName[32];
    memset(szNetBiosName, '\0', sizeof(szNetBiosName));
    GetClientNetbiosName(szNetBiosName);
    _tcscat(szNetBiosName, TEXT("\\"));

   if (isWinNT)
   {
      // Now if this is an AFS network drive mapping, {szMapping} will be:
      //
      //   \Device\LanmanRedirector\<Drive>:\<netbiosname>\submount
      //
      // on Windows NT. On Windows 2000, it will be:
      //
      //   \Device\LanmanRedirector\;<Drive>:0\<netbiosname>\submount
      //
      // (This is presumably to support multiple drive mappings with
      // Terminal Server).
      //
      // on Windows XP and 2003, it will be :
      //   \Device\LanmanRedirector\;<Drive>:<AuthID>\<netbiosname>\submount
      //
      //   where : <Drive> : DOS drive letter
      //           <AuthID>: Authentication ID, 16 char hex.
      //           <netbiosname>: Netbios name of server
      //
      BOOL b;
#ifndef AFSIFS
      b = _tcsnicmp(szMapping, cszLANMANDEVICE, _tcslen(cszLANMANDEVICE));
#else
      const TCHAR ker_sub_path[] = "\\Device\\afsrdr\\";
      b = _tcsnicmp(szMapping, ker_sub_path, _tcslen(ker_sub_path));
#endif
       if (b)
         return FALSE;
#ifndef AFSIFS
      pszSubmount = &szMapping[ _tcslen(cszLANMANDEVICE) ];
#else
      pszSubmount = &szMapping[ _tcslen(ker_sub_path) ];
#endif

#ifdef AFSIFS
       if (*(pszSubmount) < '0' ||
            *(pszSubmount) > '9')
           return FALSE;
       ++pszSubmount;
#else
      if (IsWindows2000())
      {
          if (*(pszSubmount) != TEXT(';'))
             return FALSE;
      } else
          --pszSubmount;

      if (toupper(*(++pszSubmount)) != chDrive)
         return FALSE;

      if (*(++pszSubmount) != TEXT(':'))
         return FALSE;

#ifdef COMMENT
       // No longer a safe assumption on XP
      if (IsWindows2000())
          if (*(++pszSubmount) != TEXT('0'))
             return FALSE;
#endif

      // scan for next "\"
      while (*(++pszSubmount) != TEXT('\\'))
      {
	  if (*pszSubmount==0)
              return FALSE;
      }

       // note that szNetBiosName has a '\\' tagged in the end earlier
      for (++pszSubmount; *pszSubmount && (*pszSubmount != TEXT('\\')); ++pszSubmount)
         if (!_tcsncicmp(pszSubmount, szNetBiosName, _tcslen(szNetBiosName)))
            break;
      if ((!*pszSubmount) || (*pszSubmount == TEXT('\\')))
         return FALSE;

       pszSubmount += _tcslen(szNetBiosName);
#endif
      }
   else // (!IsWindowsNT())
      {
      DWORD dwSize = MAX_PATH;
      if (WNetGetConnection (szDrive, szMapping, &dwSize) != NO_ERROR)
         return FALSE;
      if (*(pszSubmount++) != TEXT('\\'))
         return FALSE;
      if (*(pszSubmount++) != TEXT('\\'))
         return FALSE;
      for ( ; *pszSubmount && (*pszSubmount != TEXT('\\')); ++pszSubmount)
         if (!lstrncmpi (pszSubmount, szNetBiosName, lstrlen(szNetBiosName)))
            break;
      if ((!*pszSubmount) || (*pszSubmount == TEXT('\\')))
         return FALSE;
      pszSubmount += lstrlen(szNetBiosName);
      }

   if (!pszSubmount || !*pszSubmount)
      return FALSE;

#ifndef AFSIFS
   lstrcpy (pszSubmountNow, pszSubmount);
#else
   lstrcpy (pszSubmountNow, "\\afs");
   lstrcat (pszSubmountNow, pszSubmount);
#endif
   return TRUE;
}
예제 #15
0
파일: drivemap.cpp 프로젝트: bagdxk/openafs
void QueryDriveMapList_ReadSubmounts (PDRIVEMAPLIST pList)
{
    if (IsWindowsNT())
    {
        HKEY hkSubmounts;

        RegCreateKeyEx( HKEY_LOCAL_MACHINE,
                        cszSECTION_SUBMOUNTS,
                        0,
                        "AFS",
                        REG_OPTION_NON_VOLATILE,
                        KEY_READ|KEY_QUERY_VALUE,
                        NULL,
                        &hkSubmounts,
                        NULL );

        DWORD dwSubmounts;
        RegQueryInfoKey( hkSubmounts,
                         NULL,  /* lpClass */
                         NULL,  /* lpcClass */
                         NULL,  /* lpReserved */
                         NULL,  /* lpcSubKeys */
                         NULL,  /* lpcMaxSubKeyLen */
                         NULL,  /* lpcMaxClassLen */
                         &dwSubmounts, /* lpcValues */
                         NULL,  /* lpcMaxValueNameLen */
                         NULL,  /* lpcMaxValueLen */
                         NULL,  /* lpcbSecurityDescriptor */
                         NULL   /* lpftLastWriteTime */
                         );

        for ( DWORD dwIndex = 0; dwIndex < dwSubmounts; dwIndex ++ ) {
            TCHAR submountPath[MAX_PATH] = "";
            DWORD submountPathLen = MAX_PATH;
            TCHAR submountName[MAX_PATH];
            DWORD submountNameLen = MAX_PATH;
            DWORD dwType = 0;

            RegEnumValue( hkSubmounts, dwIndex, submountName, &submountNameLen, NULL,
                          &dwType, (LPBYTE)submountPath, &submountPathLen);

            if (dwType == REG_EXPAND_SZ) {
                char buf[MAX_PATH];
                StringCbCopyA(buf, MAX_PATH, submountPath);
                submountPathLen = ExpandEnvironmentStrings(buf, submountPath, MAX_PATH);
                if (submountPathLen > MAX_PATH)
                    continue;
            }

            SUBMOUNT Submount;
            memset (&Submount, 0x00, sizeof(SUBMOUNT));
            lstrcpy (Submount.szSubmount, submountName);

            if ( submountPath[0] != TEXT('\0') ) {
                AdjustAfsPath (Submount.szMapping, submountPath, FALSE, TRUE);

                size_t ii;
                for (ii = 0; ii < pList->cSubmounts; ++ii)
                {
                    if (!pList->aSubmounts[ii].szSubmount[0])
                        break;
                }
                if (REALLOC (pList->aSubmounts, pList->cSubmounts, 1+ii, cREALLOC_SUBMOUNTS))
                {
                    memcpy (&pList->aSubmounts[ii], &Submount, sizeof(SUBMOUNT));
                }
            }

        }
        RegCloseKey(hkSubmounts);
    }
}
예제 #16
0
extern "C" LONG APIENTRY CPlApplet(HWND hwndCPl, UINT uMsg, LONG lParam1, LONG lParam2)
{
    LPNEWCPLINFO lpNewCPlInfo;
    LPCPLINFO lpCPlInfo;
    SHELLEXECUTEINFO shellExecInfo;

    switch (uMsg) {
        case CPL_INIT:      /* first message, sent once  */
            hinst = GetModuleHandle("afs_cpa.cpl");
            hinstResources = TaLocale_LoadCorrespondingModule (hinst);
            CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
            return (hinst != 0);

        case CPL_GETCOUNT:  /* second message, sent once */
            return 1;

        case CPL_INQUIRE:  /* in case we receive this we should indicate that we like NEWINQUIRE better. */
            lpCPlInfo = (CPLINFO *) lParam2;
            lpCPlInfo->idIcon = ((IsClientInstalled() || !IsWindowsNT())? IDI_AFSD : IDI_CCENTER);
            lpCPlInfo->idName = CPL_DYNAMIC_RES;
            lpCPlInfo->idInfo = CPL_DYNAMIC_RES;
            lpCPlInfo->lData = 0;
            break;

        case CPL_NEWINQUIRE: /* third message, sent once per app */
            lpNewCPlInfo = (LPNEWCPLINFO) lParam2;

            lpNewCPlInfo->dwSize = (DWORD) sizeof(NEWCPLINFO);
            lpNewCPlInfo->dwFlags = 0;
            lpNewCPlInfo->dwHelpContext = 0;
            lpNewCPlInfo->lData = 0;
	    if (IsClientInstalled() || !IsWindowsNT())
	       lpNewCPlInfo->hIcon = TaLocale_LoadIcon(IDI_AFSD);
	    else
	       lpNewCPlInfo->hIcon = TaLocale_LoadIcon(IDI_CCENTER);
            lpNewCPlInfo->szHelpFile[0] = '\0';

            GetString (lpNewCPlInfo->szName, (!IsWindowsNT()) ? IDS_CPL_NAME_95 : (!IsClientInstalled()) ? IDS_CPL_NAME_CCENTER : IDS_CPL_NAME_NT);
            GetString (lpNewCPlInfo->szInfo, (!IsWindowsNT()) ? IDS_CPL_DESC_95 : (!IsClientInstalled()) ? IDS_CPL_DESC_CCENTER : IDS_CPL_DESC_NT);
            break;

    case CPL_DBLCLK:		/* applet icon double-clicked */
            memset(&shellExecInfo, 0, sizeof(shellExecInfo));
            shellExecInfo.cbSize = sizeof(shellExecInfo);
            shellExecInfo.nShow = SW_SHOWNORMAL;
            shellExecInfo.hwnd = hwndCPl;
            shellExecInfo.lpFile = "afs_config.exe";
	    if (!IsClientInstalled() && IsWindowsNT())
                shellExecInfo.lpParameters = "/c";

            ShellExecuteEx(&shellExecInfo);
            break;

    case CPL_EXIT:
            CoUninitialize();
            if (hinstResources)
                FreeLibrary (hinstResources);
            break;
    }

    return 0;
}