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.

154 lines
5.2 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <winsock2.h>
  6. #include <wsipx.h>
  7. #include <svcguid.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <rpc.h>
  11. #include <rpcdce.h>
  12. GUID ServiceClassId = { /* 5b50962a-e5a5-11cf-a555-00c04fd8d4ac */
  13. 0x5b50962a,
  14. 0xe5a5,
  15. 0x11cf,
  16. {0xa5, 0x55, 0x00, 0xc0, 0x4f, 0xd8, 0xd4, 0xac}
  17. };
  18. WCHAR ServiceInstanceName[] = L"GlennC on GLENNC_PRO";
  19. _cdecl
  20. main(int argc, char **argv)
  21. {
  22. DWORD ret;
  23. WSADATA wsaData;
  24. WSAQUERYSET QuerySet;
  25. CSADDR_INFO CSAddrInfo[6];
  26. SOCKADDR SocketAddress1;
  27. SOCKADDR SocketAddress2;
  28. SOCKADDR SocketAddress3;
  29. SOCKADDR SocketAddress4;
  30. SOCKADDR SocketAddress5;
  31. ANSI_STRING asServiceInstanceName;
  32. UNICODE_STRING usServiceInstanceName;
  33. WCHAR UnicodeStringBuf[1024];
  34. if ( argc == 2 )
  35. {
  36. usServiceInstanceName.Length = 0;
  37. usServiceInstanceName.MaximumLength = 1024;
  38. usServiceInstanceName.Buffer = UnicodeStringBuf;
  39. RtlInitAnsiString( &asServiceInstanceName, argv[1] );
  40. RtlAnsiStringToUnicodeString( &usServiceInstanceName,
  41. &asServiceInstanceName,
  42. FALSE );
  43. }
  44. RtlZeroMemory( (LPBYTE) &QuerySet, sizeof( WSAQUERYSET ) );
  45. RtlZeroMemory( (LPBYTE) &CSAddrInfo[0], sizeof( CSADDR_INFO ) );
  46. RtlZeroMemory( (LPBYTE) &CSAddrInfo[1], sizeof( CSADDR_INFO ) );
  47. RtlZeroMemory( (LPBYTE) &CSAddrInfo[2], sizeof( CSADDR_INFO ) );
  48. RtlZeroMemory( (LPBYTE) &CSAddrInfo[3], sizeof( CSADDR_INFO ) );
  49. RtlZeroMemory( (LPBYTE) &CSAddrInfo[4], sizeof( CSADDR_INFO ) );
  50. RtlZeroMemory( (LPBYTE) &CSAddrInfo[5], sizeof( CSADDR_INFO ) );
  51. SocketAddress1.sa_family = AF_UNIX;
  52. RtlFillMemory( (LPBYTE) &SocketAddress1.sa_data, 14, 1 );
  53. SocketAddress2.sa_family = AF_INET;
  54. RtlFillMemory( (LPBYTE) &SocketAddress2.sa_data, 14, 2 );
  55. SocketAddress3.sa_family = AF_IPX;
  56. RtlFillMemory( (LPBYTE) &SocketAddress3.sa_data, 14, 6 );
  57. SocketAddress4.sa_family = AF_ISO;
  58. RtlFillMemory( (LPBYTE) &SocketAddress4.sa_data, 14, 7 );
  59. SocketAddress5.sa_family = AF_ECMA;
  60. RtlFillMemory( (LPBYTE) &SocketAddress5.sa_data, 14, 8 );
  61. CSAddrInfo[0].LocalAddr.iSockaddrLength = sizeof( SOCKADDR );
  62. CSAddrInfo[0].LocalAddr.lpSockaddr = &SocketAddress2;
  63. CSAddrInfo[0].RemoteAddr.iSockaddrLength = sizeof( SOCKADDR );
  64. CSAddrInfo[0].RemoteAddr.lpSockaddr = &SocketAddress2;
  65. CSAddrInfo[0].iSocketType = SOCK_RAW;
  66. CSAddrInfo[0].iProtocol = PF_INET;
  67. CSAddrInfo[1].LocalAddr.iSockaddrLength = sizeof( SOCKADDR );
  68. CSAddrInfo[1].LocalAddr.lpSockaddr = &SocketAddress2;
  69. CSAddrInfo[1].RemoteAddr.iSockaddrLength = sizeof( SOCKADDR );
  70. CSAddrInfo[1].RemoteAddr.lpSockaddr = &SocketAddress2;
  71. CSAddrInfo[1].iSocketType = SOCK_STREAM;
  72. CSAddrInfo[1].iProtocol = PF_INET;
  73. CSAddrInfo[2].LocalAddr.iSockaddrLength = sizeof( SOCKADDR );
  74. CSAddrInfo[2].LocalAddr.lpSockaddr = &SocketAddress1;
  75. CSAddrInfo[2].RemoteAddr.iSockaddrLength = sizeof( SOCKADDR );
  76. CSAddrInfo[2].RemoteAddr.lpSockaddr = &SocketAddress1;
  77. CSAddrInfo[2].iSocketType = SOCK_STREAM;
  78. CSAddrInfo[2].iProtocol = PF_UNIX;
  79. CSAddrInfo[3].LocalAddr.iSockaddrLength = sizeof( SOCKADDR );
  80. CSAddrInfo[3].LocalAddr.lpSockaddr = &SocketAddress3;
  81. CSAddrInfo[3].RemoteAddr.iSockaddrLength = 0;
  82. CSAddrInfo[3].RemoteAddr.lpSockaddr = NULL;
  83. CSAddrInfo[3].iSocketType = SOCK_STREAM;
  84. CSAddrInfo[3].iProtocol = PF_IPX;
  85. CSAddrInfo[4].LocalAddr.iSockaddrLength = sizeof( SOCKADDR );
  86. CSAddrInfo[4].LocalAddr.lpSockaddr = &SocketAddress4;
  87. CSAddrInfo[4].RemoteAddr.iSockaddrLength = 0;
  88. CSAddrInfo[4].RemoteAddr.lpSockaddr = NULL;
  89. CSAddrInfo[4].iSocketType = SOCK_STREAM;
  90. CSAddrInfo[4].iProtocol = PF_ISO;
  91. CSAddrInfo[5].LocalAddr.iSockaddrLength = sizeof( SOCKADDR );
  92. CSAddrInfo[5].LocalAddr.lpSockaddr = &SocketAddress5;
  93. CSAddrInfo[5].RemoteAddr.iSockaddrLength = sizeof( SOCKADDR );
  94. CSAddrInfo[5].RemoteAddr.lpSockaddr = &SocketAddress5;
  95. CSAddrInfo[5].iSocketType = SOCK_STREAM;
  96. CSAddrInfo[5].iProtocol = PF_ECMA;
  97. QuerySet.dwSize = sizeof( WSAQUERYSET );
  98. QuerySet.lpServiceClassId = &ServiceClassId;
  99. if ( argc == 2 )
  100. {
  101. QuerySet.lpszServiceInstanceName = usServiceInstanceName.Buffer;
  102. }
  103. else
  104. {
  105. QuerySet.lpszServiceInstanceName = ServiceInstanceName;
  106. }
  107. QuerySet.dwNameSpace = NS_ALL;
  108. QuerySet.dwNumberOfCsAddrs = 6;
  109. QuerySet.lpcsaBuffer = &CSAddrInfo;
  110. WSAStartup( MAKEWORD(1, 1), &wsaData );
  111. ret = WSASetService( &QuerySet,
  112. RNRSERVICE_DELETE,
  113. SERVICE_MULTIPLE );
  114. if ( ret )
  115. {
  116. printf("Error: WSASetService returned 0x%X\n", ret );
  117. printf(" GetLastError returned 0x%X\n", GetLastError() );
  118. WSACleanup();
  119. return -1;
  120. }
  121. printf( "SetService was successful.\n" );
  122. WSACleanup();
  123. return(0);
  124. }