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.

113 lines
3.4 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. WCHAR ServiceInstanceComment[] = L"This is a service added via Rnr over LDAP";
  20. _cdecl
  21. main(int argc, char **argv)
  22. {
  23. DWORD ret;
  24. WSAVERSION Version;
  25. WSADATA wsaData;
  26. WSAQUERYSET QuerySet;
  27. CSADDR_INFO CSAddrInfo[2];
  28. SOCKADDR SocketAddress1;
  29. SOCKADDR SocketAddress2;
  30. ANSI_STRING asServiceInstanceName;
  31. UNICODE_STRING usServiceInstanceName;
  32. WCHAR UnicodeStringBuf[1024];
  33. usServiceInstanceName.Length = 0;
  34. usServiceInstanceName.MaximumLength = 1024;
  35. usServiceInstanceName.Buffer = UnicodeStringBuf;
  36. if ( argc != 2 )
  37. {
  38. printf( "\nUsage: regatdn CN=MyService,OU=NTDS,O=Microsoft,C=US\n" );
  39. return( -1 );
  40. }
  41. RtlInitAnsiString( &asServiceInstanceName, argv[1] );
  42. RtlAnsiStringToUnicodeString( &usServiceInstanceName,
  43. &asServiceInstanceName,
  44. FALSE );
  45. RtlZeroMemory( (LPBYTE) &QuerySet, sizeof( WSAQUERYSET ) );
  46. RtlZeroMemory( (LPBYTE) &CSAddrInfo[0], sizeof( CSADDR_INFO ) );
  47. RtlZeroMemory( (LPBYTE) &CSAddrInfo[1], sizeof( CSADDR_INFO ) );
  48. SocketAddress1.sa_family = AF_INET;
  49. RtlFillMemory( (LPBYTE) &SocketAddress1.sa_data, 14, 1 );
  50. SocketAddress2.sa_family = AF_IPX;
  51. RtlFillMemory( (LPBYTE) &SocketAddress2.sa_data, 14, 2 );
  52. CSAddrInfo[0].LocalAddr.iSockaddrLength = sizeof( SOCKADDR );
  53. CSAddrInfo[0].LocalAddr.lpSockaddr = &SocketAddress1;
  54. CSAddrInfo[0].RemoteAddr.iSockaddrLength = 0;
  55. CSAddrInfo[0].RemoteAddr.lpSockaddr = NULL;
  56. CSAddrInfo[0].iSocketType = SOCK_RAW;
  57. CSAddrInfo[0].iProtocol = PF_INET;
  58. CSAddrInfo[1].LocalAddr.iSockaddrLength = sizeof( SOCKADDR );
  59. CSAddrInfo[1].LocalAddr.lpSockaddr = &SocketAddress1;
  60. CSAddrInfo[1].RemoteAddr.iSockaddrLength = sizeof( SOCKADDR );
  61. CSAddrInfo[1].RemoteAddr.lpSockaddr = &SocketAddress2;
  62. CSAddrInfo[1].iSocketType = SOCK_STREAM;
  63. CSAddrInfo[1].iProtocol = PF_IPX;
  64. QuerySet.dwSize = sizeof( WSAQUERYSET );
  65. QuerySet.lpServiceClassId = &ServiceClassId;
  66. QuerySet.lpszServiceInstanceName = usServiceInstanceName.Buffer;
  67. QuerySet.lpszComment = ServiceInstanceComment;
  68. QuerySet.lpVersion = &Version;
  69. QuerySet.lpVersion->dwVersion = 5;
  70. QuerySet.lpVersion->ecHow = COMP_NOTLESS;
  71. QuerySet.dwNameSpace = NS_NTDS;
  72. QuerySet.dwNumberOfCsAddrs = 2;
  73. QuerySet.lpcsaBuffer = &CSAddrInfo;
  74. WSAStartup( MAKEWORD(1, 1), &wsaData );
  75. ret = WSASetService( &QuerySet,
  76. RNRSERVICE_REGISTER,
  77. SERVICE_MULTIPLE );
  78. if ( ret )
  79. {
  80. printf("Error: WSASetService returned 0x%X\n", ret );
  81. printf(" GetLastError returned 0x%X\n", GetLastError() );
  82. WSACleanup();
  83. return -1;
  84. }
  85. printf( "SetService was successful.\n" );
  86. WSACleanup();
  87. return(0);
  88. }