Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
5.6 KiB

  1. //Copyright (c) Microsoft Corporation. All rights reserved.
  2. #ifndef _MYUTIL_H
  3. #define _MYUTIL_H
  4. #include <winsock2.h>
  5. #define MAX_ROWS 300
  6. #define MAX_COLS 300
  7. #define MAX_STRING_LENGTH 256
  8. #define SUSPEND_THREAD_SUCCESS 0xFFFFFFFF
  9. #define MAX_ATTEMPTS 200
  10. #define INHERITABLE_NULL_DESCRIPTOR_ATTRIBUTE( sa ) \
  11. sa.nLength = sizeof( SECURITY_ATTRIBUTES ); \
  12. sa.bInheritHandle = TRUE; \
  13. sa.lpSecurityDescriptor = NULL;
  14. enum{ READ_PIPE, WRITE_PIPE };
  15. extern HANDLE g_hSyncCloseHandle;
  16. extern PSID administratorsSid, everyoneSid , localSystemSid ,localLocalSid ,localNetworkSid;
  17. #define SETREGISTRYDW( constVal, keyHandle1, keyHandle2, keyName, val, size )\
  18. val = constVal ; \
  19. if( RegSetValueEx( keyHandle2, keyName, 0, REG_DWORD, (LPBYTE)&val, size \
  20. ) != ERROR_SUCCESS ) \
  21. { \
  22. if( keyHandle1 ) \
  23. RegCloseKey( keyHandle1 ); \
  24. RegCloseKey( keyHandle2 ); \
  25. LogEvent( EVENTLOG_ERROR_TYPE, MSG_REGISTRYKEY, keyName ); \
  26. return ( false ); \
  27. }\
  28. #define SETREGISTRYSZ( keyHandle1, keyHandle2, keyName, val, size ) \
  29. if( RegSetValueEx( keyHandle2, keyName, 0, REG_SZ, val, size ) \
  30. != ERROR_SUCCESS ) \
  31. { \
  32. if( keyHandle1 ) \
  33. RegCloseKey( keyHandle1 ); \
  34. RegCloseKey( keyHandle2 ); \
  35. LogEvent( EVENTLOG_ERROR_TYPE, MSG_REGISTRYKEY, keyName ); \
  36. return ( false ); \
  37. }
  38. bool IsThisMachineDC();
  39. bool GetDomainHostedByThisMc( LPWSTR );
  40. bool GetRegistryDW( HKEY, HKEY, LPTSTR, DWORD*, DWORD , BOOL);
  41. bool GetRegistryString( HKEY, HKEY, LPTSTR, LPTSTR *, LPTSTR, BOOL );
  42. bool ConvertSChartoWChar(char *, LPWSTR * );
  43. bool ConvertSChartoWChar(char *, LPWSTR );
  44. bool AllocateNExpandEnvStrings( LPWSTR, LPWSTR * );
  45. bool AllocNCpyWStr(LPWSTR*, LPWSTR );
  46. bool WriteToPipe( HANDLE, UCHAR, LPOVERLAPPED);
  47. bool WriteToPipe( HANDLE, LPVOID, DWORD, LPOVERLAPPED);
  48. bool StuffEscapeIACs( UCHAR bufDest[], UCHAR bufSrc[], DWORD* pdwSize );
  49. void FillProcessStartupInfo( STARTUPINFO *, HANDLE, HANDLE, HANDLE, WCHAR *);
  50. void LogToTlntsvrLog( HANDLE, WORD, DWORD, LPCTSTR* );
  51. void GetErrMsgString( DWORD, LPTSTR * );
  52. bool DecodeWSAErrorCodes( DWORD, ... );
  53. bool DecodeSocketStartupErrorCodes( DWORD );
  54. void LogEvent( WORD, DWORD , LPCTSTR, ... );
  55. bool FinishIncompleteIo( HANDLE, LPOVERLAPPED, LPDWORD );
  56. bool GetProductType ( LPWSTR * );
  57. void LogFormattedGetLastError( WORD, DWORD, DWORD );
  58. bool GetWindowsVersion( bool* );
  59. void InitializeOverlappedStruct( LPOVERLAPPED );
  60. bool CreateReadOrWritePipe ( LPHANDLE, LPHANDLE, SECURITY_DESCRIPTOR*, bool );
  61. bool GetUniquePipeName ( LPTSTR pszPipeName, SECURITY_ATTRIBUTES *sa );
  62. int SafeSetSocketOptions(SOCKET s);
  63. extern "C" void TlntCloseHandle(
  64. BOOL synchronize,
  65. HANDLE *handle_to_close
  66. );
  67. #define TELNET_CLOSE_HANDLE(_Handle_) TlntCloseHandle(FALSE, &(_Handle_))
  68. #define TELNET_SYNC_CLOSE_HANDLE(_Handle_) TlntCloseHandle(TRUE, &(_Handle_))
  69. extern "C" bool TlntSynchronizeOn(
  70. HANDLE object
  71. );
  72. VOID TnFreeStandardSids(void);
  73. BOOL TnInitializeStandardSids(void);
  74. PSID TnGetAdministratorsSid(void);
  75. PSID TnGetLocalSystemSid(void);
  76. PSID TnGetLocalLocalSid(void);
  77. PSID TnGetLocalNetworkSid(void);
  78. PSID TnGetEveryoneSid(void);
  79. HANDLE TnCreateFile(LPCTSTR lpFileName,
  80. DWORD dwDesiredAccess,
  81. DWORD dwSharedMode,
  82. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  83. DWORD dwCreationDisposition,
  84. DWORD dwFlagsAndAttributes,
  85. HANDLE hTemplateFile
  86. );
  87. HANDLE TnCreateFileEx(LPCTSTR lpFileName,
  88. DWORD dwDesiredAccess,
  89. DWORD dwSharedMode,
  90. LPSECURITY_ATTRIBUTES *lplpSecurityAttributes,
  91. DWORD dwCreationDisposition,
  92. DWORD dwFlagsAndAttributes,
  93. HANDLE hTemplateFile
  94. );
  95. BOOL TnCreateDirectory(LPCTSTR lpPathName,
  96. LPSECURITY_ATTRIBUTES lpSecurityAttributes
  97. );
  98. BOOL TnCreateDirectoryEx(LPCTSTR lpPathName,
  99. LPSECURITY_ATTRIBUTES *lplpSecurityAttributes
  100. );
  101. HANDLE TnCreateMutex(LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  102. BOOL bInitialOwner,
  103. LPCTSTR lpName
  104. );
  105. HANDLE TnCreateMutexEx (LPSECURITY_ATTRIBUTES *lplpSecurityAttributes,
  106. BOOL bInitialOwner,
  107. LPCTSTR lpName
  108. );
  109. BOOL TnCreateDefaultSecurityAttributes(LPSECURITY_ATTRIBUTES *lplpSecurityAttributes );
  110. VOID TnFreeSecurityAttributes(LPSECURITY_ATTRIBUTES *lplpSecurityAttributes);
  111. BOOL TnCreateDefaultSecDesc ( PSECURITY_DESCRIPTOR *pSecDesc, DWORD EveryoneAccessMask );
  112. LONG TnSecureRegCreateKeyEx(
  113. HKEY hKey, // handle to open key
  114. LPCTSTR lpSubKey, // subkey name
  115. DWORD Reserved, // reserved
  116. LPTSTR lpClass, // class string
  117. DWORD dwOptions, // special options
  118. REGSAM samDesired, // desired security access
  119. LPSECURITY_ATTRIBUTES lpSecurityAttributes, // inheritance
  120. PHKEY phkResult, // key handle
  121. LPDWORD lpdwDisposition, // disposition value buffer
  122. DWORD EveryoneAccessMask
  123. );
  124. #endif //_MYUTIL_H_