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
3.4 KiB

  1. ///**************************************************************
  2. /// Microsoft LAN Manager *
  3. /// Copyright(c) Microsoft Corp., 1990-1992 *
  4. ///**************************************************************
  5. //
  6. // Add and delete access record
  7. //
  8. #include <nt.h> // TIME definition
  9. #include <ntrtl.h> // TIME definition
  10. #include <nturtl.h> // TIME definition
  11. #define NOMINMAX // Avoid redefinition of min and max in stdlib.h
  12. #include <windef.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <lmcons.h>
  17. #include <lmapibuf.h>
  18. #include <netlib.h>
  19. #include <netdebug.h>
  20. #include <lmaccess.h>
  21. #include <lmerr.h>
  22. #include <ntsam.h>
  23. #include <netlogon.h>
  24. #include <logonp.h>
  25. #define TEST_USER1 L"USER1"
  26. #define TEST_PERM1 07
  27. #define TEST_PERM2 31
  28. #define TEST_PERM3 63
  29. #define TEST_RESOURCE L"C:\\UASTEST"
  30. //
  31. // AddAccess
  32. //
  33. //
  34. void
  35. AddAccess(server, username, resource, perms)
  36. LPWSTR server;
  37. LPWSTR resource;
  38. LPWSTR username;
  39. DWORD perms;
  40. {
  41. NET_API_STATUS err;
  42. char ebuf[512];
  43. PACCESS_INFO_1 acc = (PACCESS_INFO_1) ebuf;
  44. PACCESS_LIST acl;
  45. acc->acc1_resource_name = resource;
  46. acc->acc1_attr = 1;
  47. acc->acc1_count = 1;
  48. acl = (PACCESS_LIST) (ebuf + sizeof(ACCESS_INFO_1));
  49. acl->acl_ugname = username;
  50. acl->acl_access = perms;
  51. if (err = NetAccessAdd(server, 1, ebuf, NULL ))
  52. NetpKdPrint(("NetAccessAdd failed, ret = %d\n", err));
  53. else
  54. NetpKdPrint(("%ws added successfully\n", resource));
  55. }
  56. //
  57. // DelAccess
  58. //
  59. void
  60. DelAccess(server, resource)
  61. LPWSTR server;
  62. LPWSTR resource;
  63. {
  64. NET_API_STATUS err;
  65. if (err = NetAccessDel(server, resource))
  66. NetpKdPrint(("NetAccessDel failed, ret = %d\n", err));
  67. else
  68. NetpKdPrint(("%ws deleted successfully\n", resource));
  69. }
  70. //
  71. // GetAccess
  72. //
  73. void
  74. GetAccess(server, resource)
  75. LPWSTR server;
  76. LPWSTR resource;
  77. {
  78. NET_API_STATUS err;
  79. LPBYTE buf;
  80. DWORD level;
  81. for (level = 0; level < 2; level++) {
  82. if (err = NetAccessGetInfo(server, resource, level, &buf))
  83. NetpKdPrint(("NetAccessGetInfo failed, ret = %d\n", err));
  84. else {
  85. NetpKdPrint(("NetAccessGetInfo: Level %d OK\n", level));
  86. NetApiBufferFree( buf );
  87. }
  88. }
  89. }
  90. //
  91. // main driver for NetAccessAdd and NetAccessDel tests
  92. //
  93. //
  94. void
  95. main(argc, argv)
  96. int argc;
  97. char **argv;
  98. {
  99. LPWSTR resource;
  100. LPWSTR user;
  101. LPWSTR server;
  102. DWORD perm;
  103. if ((argc == 1) || (*argv[1] == '?')) {
  104. printf("usage: uastest6 resource user perms server\n");
  105. exit(0);
  106. }
  107. resource = TEST_RESOURCE;
  108. user = TEST_USER1;
  109. perm = TEST_PERM1;
  110. server = NULL;
  111. if (argv[1] != NULL) {
  112. resource = NetpLogonOemToUnicode(argv[1]);
  113. if (argv[2] != NULL) {
  114. user = NetpLogonOemToUnicode(argv[2]);
  115. if (argv[3] != NULL) {
  116. perm = atoi(argv[3]) & 0x3F;
  117. if (argv[4] != NULL)
  118. server = NetpLogonOemToUnicode(argv[4]);
  119. }
  120. }
  121. }
  122. AddAccess(server, user, resource, perm);
  123. GetAccess(server, resource);
  124. DelAccess(server, resource);
  125. }