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.

164 lines
4.8 KiB

  1. /****************************************************************************
  2. Microsoft RPC Version 1`1
  3. Copyright Microsoft Corp. 1992
  4. Hello Example
  5. FILE: helloc.c
  6. USAGE: client -n network_address
  7. -p protocol_sequence
  8. -e endpoint
  9. -o options
  10. -u uuid
  11. PURPOSE: Client side of RPC distributed application
  12. FUNCTIONS: main() - binds to server and calls remote procedure
  13. COMMENTS:
  14. This distributed application prints a string such as "hello, world"
  15. on the server. The client manages its connection to the server.
  16. The client uses the binding handle hello_IfHandle defined in the
  17. file hello.h.
  18. ****************************************************************************/
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <stdlib.h>
  22. #include <rpc.h> // RPC API functions, types
  23. #include "hello2.h" // header file generated by MIDL compiler
  24. int __cdecl
  25. hello2_main (argc, argv)
  26. int argc;
  27. char *argv[];
  28. {
  29. RPC_STATUS status; // returned by RPC API function
  30. unsigned char * pszUuid = "12345678-1234-1234-1234-123456789ABD";
  31. unsigned char * pszProtocolSequence = "ncacn_ip_tcp";
  32. unsigned char * pszNetworkAddress = NULL;
  33. unsigned char * pszEndpoint = "760";
  34. unsigned char * pszOptions = NULL;
  35. unsigned char * pszStringBinding = NULL;
  36. unsigned char * pszString = "hello, world";
  37. int i;
  38. // allow the user to override settings with command line switches
  39. for (i = 1; i < argc; i++) {
  40. if ((*argv[i] == '-') || (*argv[i] == '/')) {
  41. switch (tolower(*(argv[i]+1))) {
  42. case 'p': // protocol sequence
  43. pszProtocolSequence = argv[++i];
  44. break;
  45. case 'n': // network address
  46. pszNetworkAddress = argv[++i];
  47. break;
  48. case 'e':
  49. pszEndpoint = argv[++i];
  50. break;
  51. case 'o':
  52. pszOptions = argv[++i];
  53. break;
  54. case 'u':
  55. pszUuid = argv[++i];
  56. break;
  57. case 's':
  58. pszString = argv[++i];
  59. break;
  60. case 'h':
  61. case '?':
  62. default:
  63. Usage(argv[0]);
  64. }
  65. } else {
  66. Usage(argv[0]);
  67. }
  68. }
  69. // Use a convenience function to concatenate the elements of
  70. // the string binding into the proper sequence.
  71. status = RpcStringBindingCompose(pszUuid,
  72. pszProtocolSequence,
  73. pszNetworkAddress,
  74. pszEndpoint,
  75. pszOptions,
  76. &pszStringBinding);
  77. if (status) {
  78. printf("RpcStringBindingCompose returned 0x%x\n", status);
  79. exit(2);
  80. }
  81. printf("pszStringBinding = %s\n", pszStringBinding);
  82. //
  83. // Set the binding handle that will be used to bind to the server.
  84. //
  85. status = RpcBindingFromStringBinding(pszStringBinding,
  86. &hello2_IfHandle);
  87. if (status) {
  88. printf("RpcBindingFromStringBinding returned 0x%x\n", status);
  89. exit(2);
  90. }
  91. //
  92. // Tell RPC to do the security thing.
  93. //
  94. status = RpcBindingSetAuthInfo(
  95. hello2_IfHandle,
  96. "makalu\\suzannep",
  97. RPC_C_AUTHN_LEVEL_CONNECT,
  98. RPC_C_AUTHN_DCE_PRIVATE,
  99. NULL,
  100. RPC_C_AUTHZ_NAME );
  101. if ( status ) {
  102. printf("RpcBindingSetAuthInfo returned %ld\n", status);
  103. exit(2);
  104. }
  105. //
  106. // Do the actual RPC calls to the server.
  107. //
  108. printf(" print the string '%s' on the server\n", pszString);
  109. RpcTryExcept {
  110. int i;
  111. for ( i=0; i<10 ; i++ ) {
  112. HelloProc2(pszString); // make call with user message
  113. }
  114. // Shutdown2(); // shut down the server side
  115. } RpcExcept(1) {
  116. printf("Runtime library reported an exception 0x%lx\n",
  117. RpcExceptionCode());
  118. } RpcEndExcept
  119. // The calls to the remote procedures are complete.
  120. // Free the string and the binding handle
  121. status = RpcStringFree(&pszStringBinding); // remote calls done; unbind
  122. if (status) {
  123. printf("RpcStringFree returned 0x%x\n", status);
  124. exit(2);
  125. }
  126. status = RpcBindingFree(&hello2_IfHandle); // remote calls done; unbind
  127. if (status) {
  128. printf("RpcBindingFree returned 0x%x\n", status);
  129. exit(2);
  130. }
  131. return 0;
  132. }
  133. /* end file helloc.c */