Source code of Windows XP (NT5)
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.

198 lines
4.5 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. AddObj.c
  5. Abstract:
  6. Command line test tool for adding an object to a NDS tree.
  7. Author:
  8. Glenn Curtis [glennc] 05-Jan-96
  9. ***/
  10. #include <utils.c>
  11. #include <string.h>
  12. int
  13. _cdecl main( int argc, char **argv )
  14. {
  15. DWORD status = NO_ERROR;
  16. LPBYTE lpTemp = NULL, lpValue = NULL;
  17. DWORD dwValue;
  18. HANDLE hParentObject = NULL;
  19. HANDLE hOperationData = NULL;
  20. OEM_STRING OemArg;
  21. UNICODE_STRING ParentObjectName;
  22. WCHAR lpParentObjectName[256];
  23. UNICODE_STRING ObjectName;
  24. WCHAR lpObjectName[256];
  25. UNICODE_STRING ClassName;
  26. WCHAR lpClassName[256];
  27. ASN1_TYPE_3 asn1Type3;
  28. ParentObjectName.Length = 0;
  29. ParentObjectName.MaximumLength = sizeof( lpParentObjectName );
  30. ParentObjectName.Buffer = lpParentObjectName;
  31. //
  32. // Check the arguments.
  33. //
  34. if ( argc != 4 )
  35. {
  36. printf( "\nUsage: addobj <parent object DN> <object name> <object class>\n" );
  37. printf( "\n where:\n" );
  38. printf( " parent object DN = \\\\tree\\xxx.yyy.zzz\n" );
  39. printf( " object name = Fred\n" );
  40. printf( " object class = User\n" );
  41. printf( "\nFor Example:\n" );
  42. printf( " addobj \\\\MARSDEV\\OU=DEV.O=MARS Fred User\n\n" );
  43. return -1;
  44. }
  45. OemArg.Length = strlen( argv[1] );
  46. OemArg.MaximumLength = OemArg.Length;
  47. OemArg.Buffer = argv[1];
  48. RtlOemStringToUnicodeString( &ParentObjectName, &OemArg, FALSE );
  49. status = NwNdsOpenObject( ParentObjectName.Buffer,
  50. NULL,
  51. NULL,
  52. &hParentObject,
  53. NULL,
  54. NULL,
  55. NULL,
  56. NULL,
  57. NULL );
  58. if ( status )
  59. {
  60. printf( "\nError: NwNdsOpenObject returned status 0x%.8X\n\n", status );
  61. return -1;
  62. }
  63. //
  64. // Give the new object some initial attributes
  65. //
  66. status = NwNdsCreateBuffer( NDS_OBJECT_ADD, &hOperationData );
  67. if ( status )
  68. {
  69. printf( "\nError: NwNdsCreateBuffer returned status 0x%.8X\n\n",
  70. status );
  71. return -1;
  72. }
  73. //
  74. // Get the new object's name
  75. //
  76. OemArg.Length = strlen( argv[2] );
  77. OemArg.MaximumLength = OemArg.Length;
  78. OemArg.Buffer = argv[2];
  79. ObjectName.Length = 0;
  80. ObjectName.MaximumLength = sizeof( lpObjectName );
  81. ObjectName.Buffer = lpObjectName;
  82. RtlOemStringToUnicodeString( &ObjectName, &OemArg, FALSE );
  83. asn1Type3.CaseIgnoreString = ObjectName.Buffer;
  84. OemArg.Length = strlen( argv[3] );
  85. OemArg.MaximumLength = OemArg.Length;
  86. OemArg.Buffer = argv[3];
  87. ClassName.Length = 0;
  88. ClassName.MaximumLength = sizeof( lpClassName );
  89. ClassName.Buffer = lpClassName;
  90. RtlOemStringToUnicodeString( &ClassName, &OemArg, FALSE );
  91. if ( !_wcsicmp( ClassName.Buffer, L"User" ) )
  92. {
  93. status = NwNdsPutInBuffer( NDS_SURNAME,
  94. &asn1Type3,
  95. 1,
  96. 0,
  97. hOperationData );
  98. if ( status )
  99. {
  100. printf( "\nError: NwNdsPutInBuffer returned status 0x%.8X\n\n", status );
  101. return -1;
  102. }
  103. }
  104. asn1Type3.CaseIgnoreString = ClassName.Buffer;
  105. status = NwNdsPutInBuffer( NDS_OBJECT_CLASS,
  106. &asn1Type3,
  107. 1,
  108. 0,
  109. hOperationData );
  110. if ( status )
  111. {
  112. printf( "\nError: NwNdsPutInBuffer returned status 0x%.8X\n\n",
  113. status );
  114. return -1;
  115. }
  116. printf( "Adding the new object to tree\n" );
  117. status = NwNdsAddObject( hParentObject,
  118. ObjectName.Buffer,
  119. hOperationData );
  120. if ( status )
  121. {
  122. printf( "\nError: NwNdsAddObject returned status 0x%.8X\n\n", status );
  123. return -1;
  124. }
  125. status = NwNdsCloseObject( hParentObject );
  126. if ( status )
  127. {
  128. printf( "\nError: NwNdsCloseObject returned status 0x%.8X\n\n", status );
  129. return -1;
  130. }
  131. (void) LocalFree( lpValue );
  132. status = NwNdsFreeBuffer( hOperationData );
  133. if ( status )
  134. {
  135. printf( "\nError: NwNdsFreeBuffer returned status 0x%.8X\n\n", status );
  136. return -1;
  137. }
  138. printf( "\nSuccess!\n\n" );
  139. return status;
  140. }