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.

318 lines
8.4 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. nwcfg.cxx
  7. netware configuration source code.
  8. history:
  9. terryk 05/07/93 Created
  10. */
  11. #if defined(DEBUG)
  12. static const char szFileName[] = __FILE__;
  13. #define _FILENAME_DEFINED_ONCE szFileName
  14. #endif
  15. #define APIERR LONG
  16. extern "C"
  17. {
  18. #include <windows.h>
  19. #include <port1632.h>
  20. #include <winspool.h>
  21. // exported functions
  22. BOOL FAR PASCAL AddNetwarePrinterProvidor( DWORD nArgs, LPSTR apszArgs[], LPSTR * ppszResult );
  23. BOOL FAR PASCAL DeleteNetwarePrinterProvidor( DWORD nArgs, LPSTR apszArgs[], LPSTR * ppszResult );
  24. BOOL FAR PASCAL AppendSzToFile( DWORD nArgs, LPSTR apszArgs[], LPSTR * ppszResult );
  25. BOOL FAR PASCAL GetKernelVersion( DWORD nArgs, LPSTR apszArgs[], LPSTR * ppszResult );
  26. extern HINSTANCE ThisDLLHandle;
  27. }
  28. #define UNREFERENCED(x) ((void)(x))
  29. #include <nwcfg.hxx>
  30. #include <nwcfg.h>
  31. /*******************************************************************
  32. NAME: AddNetwarePrinterProvidor
  33. SYNOPSIS: This is a wrapper routine for called AddPrintProvidor. It
  34. should be called from inf file if the user installs netware.
  35. ENTRY: NONE from inf file.
  36. RETURN: BOOL - TRUE for success.
  37. HISTORY:
  38. terryk 07-May-1993 Created
  39. ********************************************************************/
  40. #define PROVIDER_DLL_NAME "nwprovau.dll"
  41. #define MAX_PROVIDER_NAME_LEN 512
  42. typedef BOOL (WINAPI *T_AddPrintProvidor)(LPSTR pName,DWORD Level,LPBYTE pMonitors);
  43. typedef BOOL (WINAPI *T_DeletePrintProvidor)(LPSTR pName,LPSTR pEnv, LPSTR pMon);
  44. BOOL FAR PASCAL AddNetwarePrinterProvidor( DWORD nArgs, LPSTR apszArgs[], LPSTR * ppszResult )
  45. {
  46. UNREFERENCED( nArgs );
  47. PROVIDOR_INFO_1 ProvidorInfo1;
  48. ProvidorInfo1.pEnvironment = (LPSTR) NULL;
  49. ProvidorInfo1.pDLLName = PROVIDER_DLL_NAME;
  50. APIERR err = 0;
  51. do {
  52. CHAR buf[MAX_PROVIDER_NAME_LEN];
  53. LPSTR lpProviderName = (LPSTR)buf;
  54. if ( lpProviderName == NULL )
  55. {
  56. err = ERROR_NOT_ENOUGH_MEMORY;
  57. break;
  58. }
  59. if ( !LoadString( ThisDLLHandle,
  60. PROVIDER_NAME,
  61. lpProviderName,
  62. MAX_PROVIDER_NAME_LEN ) )
  63. {
  64. err = ::GetLastError();
  65. break;
  66. }
  67. ProvidorInfo1.pName = lpProviderName;
  68. HINSTANCE hDll = ::LoadLibraryA( "winspool.drv" );
  69. if ( hDll == NULL )
  70. {
  71. err = ::GetLastError();
  72. break;
  73. }
  74. FARPROC pAddPrintProvidor = ::GetProcAddress( hDll, "AddPrintProvidorA" );
  75. if ( pAddPrintProvidor == NULL )
  76. {
  77. err = ::GetLastError();
  78. } else if ( !(*(T_AddPrintProvidor)pAddPrintProvidor)((LPSTR) NULL,1,(LPBYTE)&ProvidorInfo1))
  79. {
  80. err = ::GetLastError();
  81. }
  82. if ( hDll )
  83. ::FreeLibrary( hDll );
  84. } while (FALSE);
  85. wsprintfA( achBuff, "{\"%d\"}", err );
  86. *ppszResult = achBuff;
  87. return TRUE;
  88. }
  89. BOOL FAR PASCAL DeleteNetwarePrinterProvidor( DWORD nArgs, LPSTR apszArgs[], LPSTR * ppszResult )
  90. {
  91. UNREFERENCED( nArgs );
  92. UNREFERENCED( apszArgs );
  93. APIERR err = 0;
  94. do {
  95. HINSTANCE hDll = ::LoadLibraryA( "winspool.drv" );
  96. if ( hDll == NULL )
  97. {
  98. err = ::GetLastError();
  99. break;
  100. }
  101. FARPROC pDeletePrintProvidor = ::GetProcAddress( hDll, "DeletePrintProvidorA" );
  102. if ( pDeletePrintProvidor == NULL )
  103. {
  104. err = ::GetLastError();
  105. }
  106. else
  107. {
  108. CHAR buf[MAX_PROVIDER_NAME_LEN];
  109. LPSTR lpProviderName = (LPSTR)buf;
  110. if ( lpProviderName == NULL )
  111. {
  112. err = ERROR_NOT_ENOUGH_MEMORY;
  113. break;
  114. }
  115. if ( nArgs == 1 )
  116. {
  117. lpProviderName = apszArgs[0];
  118. } else
  119. {
  120. if ( !LoadString( ThisDLLHandle,
  121. PROVIDER_NAME,
  122. lpProviderName,
  123. MAX_PROVIDER_NAME_LEN ) )
  124. {
  125. err = ::GetLastError();
  126. }
  127. }
  128. if ( !(*(T_DeletePrintProvidor)pDeletePrintProvidor)( (LPSTR) NULL,
  129. (LPSTR) NULL,
  130. lpProviderName))
  131. {
  132. err = ::GetLastError();
  133. }
  134. }
  135. if ( hDll )
  136. ::FreeLibrary ( hDll );
  137. } while (FALSE);
  138. wsprintfA( achBuff, "{\"%d\"}", err );
  139. *ppszResult = achBuff;
  140. return TRUE;
  141. }
  142. /*******************************************************************
  143. NAME: AppendSzToFile
  144. SYNOPSIS: Append a string to a file.
  145. ENTRY: Args[0] - FileName string
  146. Args[1] - String to be added to the file
  147. RETURN: BOOL - TRUE for success.
  148. HISTORY:
  149. terryk 07-May-1993 Created
  150. ********************************************************************/
  151. BOOL FAR PASCAL
  152. AppendSzToFile( DWORD nArgs, LPSTR apszArgs[], LPSTR * ppszResult )
  153. {
  154. UNREFERENCED( nArgs );
  155. DWORD BytesWritten;
  156. HANDLE hfile;
  157. LPSTR szFileName = apszArgs[0];
  158. LPSTR szAddOnSz = apszArgs[1];
  159. //
  160. // Open the file
  161. //
  162. hfile = CreateFile(
  163. szFileName,
  164. GENERIC_WRITE | GENERIC_READ,
  165. FILE_SHARE_READ,
  166. (struct _SECURITY_ATTRIBUTES *) NULL,
  167. OPEN_ALWAYS,
  168. FILE_ATTRIBUTE_NORMAL,
  169. NULL
  170. );
  171. if (hfile == INVALID_HANDLE_VALUE) {
  172. wsprintfA( achBuff, "{ Cannot Open File: \"%s\"}", szFileName );
  173. *ppszResult = achBuff;
  174. return FALSE;
  175. }
  176. //
  177. // Go to end of file
  178. //
  179. SetFilePointer (
  180. hfile,
  181. 0,
  182. (PLONG) NULL,
  183. FILE_END
  184. );
  185. //
  186. // Append string passed in at the end of the file
  187. //
  188. WriteFile (
  189. hfile,
  190. szAddOnSz,
  191. lstrlen( szAddOnSz ),
  192. &BytesWritten,
  193. (struct _OVERLAPPED *) NULL
  194. );
  195. CloseHandle (hfile);
  196. wsprintfA( achBuff, "{\"%d\"}", 0 );
  197. *ppszResult = achBuff;
  198. return TRUE;
  199. }
  200. /*******************************************************************
  201. NAME: GetKernelVersion
  202. SYNOPSIS: Get the current kernel version number
  203. ENTRY: NONE from inf file.
  204. RETURN: BOOL - TRUE for success.
  205. The return number is the kernel build number.
  206. {"MajorVerion","MinorVersion","BuildNumber","PatchNumber"}
  207. HISTORY:
  208. terryk 24-Sept-1993 Created
  209. ********************************************************************/
  210. BOOL FAR PASCAL
  211. GetKernelVersion( DWORD nArgs, LPSTR apszArgs[], LPSTR * ppszResult )
  212. {
  213. UNREFERENCED( nArgs );
  214. DWORD wVer;
  215. LONG nSubVersion;
  216. LONG nVersion;
  217. LPCSTR lpszRegName = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
  218. HKEY hsubkey ;
  219. DWORD dwZero = 0;
  220. DWORD dwRegValueType;
  221. DWORD dwRegValue;
  222. DWORD cbRegValue;
  223. wVer = GetVersion();
  224. nSubVersion = GETMINORVERSION(wVer);
  225. nVersion = GETMAJORVERSION(wVer);
  226. cbRegValue = sizeof(dwRegValue);
  227. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  228. lpszRegName, dwZero, KEY_QUERY_VALUE, &hsubkey) ||
  229. RegQueryValueEx(hsubkey, "CSDVersion", (LPDWORD)NULL,
  230. &dwRegValueType, (LPBYTE)&dwRegValue, &cbRegValue) ||
  231. dwRegValueType != REG_DWORD
  232. ) {
  233. wsprintf(achBuff,"{\"%d\",\"%d\",\"%d\",\"%d\"}", nVersion, nSubVersion, wVer >> 16, 0);
  234. } else {
  235. wsprintf(achBuff,"{\"%d\",\"%d\",\"%d\",\"%d\"}", nVersion, nSubVersion, wVer >> 16, dwRegValue);
  236. }
  237. if (hsubkey != NULL) {
  238. RegCloseKey (hsubkey);
  239. }
  240. *ppszResult = achBuff;
  241. return TRUE;
  242. }