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.

213 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1993-1993 Microsoft Corporation
  3. Module Name:
  4. nwsutil.c
  5. Abstract:
  6. This module implements IsNetWareInstalled()
  7. Author:
  8. Congpa You (CongpaY) 02-Dec-1993 Crested
  9. Revision History:
  10. --*/
  11. #include "nt.h"
  12. #include "ntrtl.h"
  13. #include "nturtl.h"
  14. #include "windef.h"
  15. #include "winerror.h"
  16. #include "winbase.h"
  17. #include "ntlsa.h"
  18. #include "nwsutil.h"
  19. #include "crypt.h"
  20. #include <fpnwcomm.h>
  21. #include <usrprop.h>
  22. NTSTATUS
  23. GetRemoteNcpSecretKey (
  24. PUNICODE_STRING SystemName,
  25. CHAR *pchNWSecretKey
  26. )
  27. {
  28. //
  29. // this function returns the FPNW LSA Secret for the specified domain
  30. //
  31. NTSTATUS ntstatus;
  32. OBJECT_ATTRIBUTES ObjAttributes;
  33. LSA_HANDLE PolicyHandle = NULL;
  34. LSA_HANDLE SecretHandle = NULL;
  35. UNICODE_STRING SecretNameString;
  36. PUNICODE_STRING punicodeCurrentValue;
  37. PUNICODE_STRING punicodeOldValue;
  38. InitializeObjectAttributes( &ObjAttributes,
  39. NULL,
  40. 0L,
  41. NULL,
  42. NULL );
  43. ntstatus = LsaOpenPolicy( SystemName,
  44. &ObjAttributes,
  45. POLICY_CREATE_SECRET,
  46. &PolicyHandle );
  47. if ( !NT_SUCCESS( ntstatus ))
  48. {
  49. return( ntstatus );
  50. }
  51. RtlInitUnicodeString( &SecretNameString, NCP_LSA_SECRET_KEY );
  52. ntstatus = LsaOpenSecret( PolicyHandle,
  53. &SecretNameString,
  54. SECRET_QUERY_VALUE,
  55. &SecretHandle );
  56. if ( !NT_SUCCESS( ntstatus ))
  57. {
  58. LsaClose( PolicyHandle );
  59. return( ntstatus );
  60. }
  61. //
  62. // Do not need the policy handle anymore.
  63. //
  64. LsaClose( PolicyHandle );
  65. ntstatus = LsaQuerySecret( SecretHandle,
  66. &punicodeCurrentValue,
  67. NULL,
  68. &punicodeOldValue,
  69. NULL );
  70. //
  71. // Do not need the secret handle anymore.
  72. //
  73. LsaClose( SecretHandle );
  74. if ( NT_SUCCESS(ntstatus) && ( punicodeCurrentValue->Buffer != NULL))
  75. {
  76. memcpy( pchNWSecretKey,
  77. punicodeCurrentValue->Buffer,
  78. min(punicodeCurrentValue->Length, USER_SESSION_KEY_LENGTH));
  79. }
  80. LsaFreeMemory( punicodeCurrentValue );
  81. LsaFreeMemory( punicodeOldValue );
  82. return( ntstatus );
  83. }
  84. NTSTATUS
  85. GetNcpSecretKey (
  86. CHAR *pchNWSecretKey
  87. )
  88. {
  89. //
  90. // simply return the LSA Secret for the local domain
  91. //
  92. return GetRemoteNcpSecretKey( NULL, pchNWSecretKey );
  93. }
  94. BOOL IsNetWareInstalled( VOID )
  95. {
  96. CHAR pszNWSecretKey[USER_SESSION_KEY_LENGTH];
  97. return( !NT_SUCCESS( GetNcpSecretKey (pszNWSecretKey))
  98. ? FALSE
  99. : (pszNWSecretKey[0] != 0));
  100. }
  101. NTSTATUS InstallNetWare( LPWSTR lpNcpSecretKey )
  102. {
  103. NTSTATUS ntstatus;
  104. OBJECT_ATTRIBUTES ObjAttributes;
  105. LSA_HANDLE PolicyHandle;
  106. LSA_HANDLE SecretHandle;
  107. UNICODE_STRING SecretNameString;
  108. UNICODE_STRING unicodeCurrentValue;
  109. UNICODE_STRING unicodeOldValue;
  110. InitializeObjectAttributes( &ObjAttributes,
  111. NULL,
  112. 0L,
  113. NULL,
  114. NULL);
  115. ntstatus = LsaOpenPolicy( NULL,
  116. &ObjAttributes,
  117. POLICY_CREATE_SECRET,
  118. &PolicyHandle );
  119. if ( !NT_SUCCESS( ntstatus ))
  120. {
  121. return( ntstatus );
  122. }
  123. RtlInitUnicodeString( &SecretNameString, NCP_LSA_SECRET_KEY );
  124. ntstatus = LsaCreateSecret( PolicyHandle,
  125. &SecretNameString,
  126. SECRET_SET_VALUE | DELETE,
  127. &SecretHandle );
  128. if ( ntstatus == STATUS_OBJECT_NAME_COLLISION )
  129. {
  130. ntstatus = LsaOpenSecret( PolicyHandle,
  131. &SecretNameString,
  132. SECRET_SET_VALUE,
  133. &SecretHandle );
  134. }
  135. if ( NT_SUCCESS( ntstatus ))
  136. {
  137. RtlInitUnicodeString( &unicodeOldValue, NULL );
  138. RtlInitUnicodeString( &unicodeCurrentValue, lpNcpSecretKey );
  139. ntstatus = LsaSetSecret( SecretHandle,
  140. &unicodeCurrentValue,
  141. &unicodeOldValue );
  142. LsaClose( SecretHandle );
  143. }
  144. LsaClose( PolicyHandle );
  145. return( ntstatus );
  146. }
  147. ULONG
  148. MapRidToObjectId(
  149. DWORD dwRid,
  150. LPWSTR pszUserName,
  151. BOOL fNTAS,
  152. BOOL fBuiltin )
  153. {
  154. (void) fBuiltin ; // unused for now.
  155. if (pszUserName && (lstrcmpi(pszUserName, SUPERVISOR_NAME_STRING)==0))
  156. return SUPERVISOR_USERID ;
  157. return ( fNTAS ? (dwRid | 0x10000000) : dwRid ) ;
  158. }
  159. ULONG SwapObjectId( ULONG ulObjectId )
  160. {
  161. return (MAKELONG(HIWORD(ulObjectId),SWAPWORD(LOWORD(ulObjectId)))) ;
  162. }