1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.security.ntlm.msrpc;
16  
17  import jcifs.dcerpc.ndr.NdrBuffer;
18  import jcifs.dcerpc.ndr.NdrObject;
19  
20  /**
21   * <a href="NetlogonNetworkInfo.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author Marcellus Tavares
24   */
25  public class NetlogonNetworkInfo extends NdrObject {
26  
27      public NetlogonNetworkInfo(
28          NetlogonIdentityInfo netlogonIdentityInfo, byte[] lmChallenge,
29          byte[] ntChallengeResponse, byte[] lmChallengeResponse) {
30  
31          _netlogonIdentityInfo = netlogonIdentityInfo;
32          _lmChallenge = lmChallenge;
33          _ntChallengeResponse = ntChallengeResponse;
34          _lmChallengeResponse = lmChallengeResponse;
35      }
36  
37      public void decode(NdrBuffer ndrBuffer) {
38      }
39  
40      public void encode(NdrBuffer ndrBuffer) {
41          ndrBuffer.align(4);
42  
43          _netlogonIdentityInfo.encode(ndrBuffer);
44  
45          int lmChallengeIndex = ndrBuffer.index;
46  
47          ndrBuffer.advance(8);
48  
49          ndrBuffer.enc_ndr_short((short)_ntChallengeResponse.length);
50          ndrBuffer.enc_ndr_short((short)_ntChallengeResponse.length);
51          ndrBuffer.enc_ndr_referent(_ntChallengeResponse, 1);
52  
53          ndrBuffer.enc_ndr_short((short)_lmChallengeResponse.length);
54          ndrBuffer.enc_ndr_short((short)_lmChallengeResponse.length);
55          ndrBuffer.enc_ndr_referent(_lmChallengeResponse, 1);
56  
57          _netlogonIdentityInfo.encodeLogonDomainName(ndrBuffer);
58          _netlogonIdentityInfo.encodeUserName(ndrBuffer);
59          _netlogonIdentityInfo.encodeWorkStationName(ndrBuffer);
60  
61          ndrBuffer = ndrBuffer.derive(lmChallengeIndex);
62  
63          for (int i = 0; i < 8; i++) {
64              ndrBuffer.enc_ndr_small(_lmChallenge[i]);
65          }
66  
67          encodeChallengeResponse(ndrBuffer, _ntChallengeResponse);
68          encodeChallengeResponse(ndrBuffer, _lmChallengeResponse);
69      }
70  
71      protected void encodeChallengeResponse(
72          NdrBuffer ndrBuffer, byte[] challenge) {
73  
74          ndrBuffer = ndrBuffer.deferred;
75  
76          ndrBuffer.enc_ndr_long(challenge.length);
77          ndrBuffer.enc_ndr_long(0);
78          ndrBuffer.enc_ndr_long(challenge.length);
79  
80          int index = ndrBuffer.index;
81  
82          ndrBuffer.advance(challenge.length);
83  
84          ndrBuffer = ndrBuffer.derive(index);
85  
86          for (int i = 0; i < challenge.length; i++) {
87              ndrBuffer.enc_ndr_small(challenge[i]);
88          }
89      }
90  
91      private byte[] _lmChallenge;
92      private byte[] _lmChallengeResponse;
93      private NetlogonIdentityInfo _netlogonIdentityInfo;
94      private byte[] _ntChallengeResponse;
95  
96  }