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.

119 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. rtsymlnk.c
  5. Abstract:
  6. NT level registry symbolic link test program
  7. Turns a key into a symbolic link.
  8. rtsymlnk <KeyPath> <SymbolicLink>
  9. Example:
  10. rtsymlnk \Registry\User\The_User\Foo \Registry\User\The_User\Bar
  11. Author:
  12. John Vert (jvert) 29-Apr-92
  13. Revision History:
  14. --*/
  15. #include "cmp.h"
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. void
  20. __cdecl main(
  21. int argc,
  22. char *argv[]
  23. )
  24. {
  25. NTSTATUS Status;
  26. OBJECT_ATTRIBUTES ObjectAttributes;
  27. UNICODE_STRING KeyName;
  28. UNICODE_STRING LinkName;
  29. UNICODE_STRING NullName;
  30. ANSI_STRING AnsiKeyName;
  31. ANSI_STRING AnsiLinkName;
  32. HANDLE KeyHandle;
  33. //
  34. // Process args
  35. //
  36. if (argc != 3) {
  37. printf("Usage: %s <KeyPath> <SymLink>\n",argv[0]);
  38. exit(1);
  39. }
  40. RtlInitAnsiString(&AnsiKeyName, argv[1]);
  41. Status = RtlAnsiStringToUnicodeString(&KeyName, &AnsiKeyName, TRUE);
  42. if (!NT_SUCCESS(Status)) {
  43. printf("RtlAnsiStringToUnicodeString failed %lx\n",Status);
  44. exit(1);
  45. }
  46. RtlInitAnsiString(&AnsiLinkName, argv[2]);
  47. Status = RtlAnsiStringToUnicodeString(&LinkName, &AnsiLinkName, TRUE);
  48. if (!NT_SUCCESS(Status)) {
  49. printf("RtlAnsiStringToUnicodeString failed %lx\n",Status);
  50. exit(1);
  51. }
  52. printf("rtsetsec: starting\n");
  53. //
  54. // Open node that we want to make a symbolic link.
  55. //
  56. InitializeObjectAttributes(
  57. &ObjectAttributes,
  58. &KeyName,
  59. OBJ_CASE_INSENSITIVE,
  60. (HANDLE)NULL,
  61. NULL
  62. );
  63. Status = NtCreateKey(&KeyHandle,
  64. KEY_READ | KEY_WRITE,
  65. &ObjectAttributes,
  66. 0,
  67. NULL,
  68. 0,
  69. NULL);
  70. if (!NT_SUCCESS(Status)) {
  71. printf("rtsymlnk: NtCreateKey failed: %08lx\n", Status);
  72. exit(1);
  73. }
  74. NullName.Length = NullName.MaximumLength = 0;
  75. NullName.Buffer = NULL;
  76. Status = NtSetValueKey(KeyHandle,
  77. &NullName,
  78. 0,
  79. REG_LINK,
  80. LinkName.Buffer,
  81. LinkName.Length);
  82. if (!NT_SUCCESS(Status)) {
  83. printf("rtsymlnk: NtSetValueKey failed: %08lx\n",Status);
  84. exit(1);
  85. }
  86. Status = NtClose(KeyHandle);
  87. if (!NT_SUCCESS(Status)) {
  88. printf("rtsymlnk: NtClose failed: %08lx\n", Status);
  89. exit(1);
  90. }
  91. printf("rtsymlnk: successful\n");
  92. }