001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.security.ntlm.msrpc;
016    
017    import jcifs.dcerpc.ndr.NdrBuffer;
018    import jcifs.dcerpc.ndr.NdrObject;
019    
020    /**
021     * @author Marcellus Tavares
022     */
023    public class NetlogonNetworkInfo extends NdrObject {
024    
025            public NetlogonNetworkInfo(
026                    NetlogonIdentityInfo netlogonIdentityInfo, byte[] lmChallenge,
027                    byte[] ntChallengeResponse, byte[] lmChallengeResponse) {
028    
029                    _netlogonIdentityInfo = netlogonIdentityInfo;
030                    _lmChallenge = lmChallenge;
031                    _ntChallengeResponse = ntChallengeResponse;
032                    _lmChallengeResponse = lmChallengeResponse;
033            }
034    
035            public void decode(NdrBuffer ndrBuffer) {
036            }
037    
038            public void encode(NdrBuffer ndrBuffer) {
039                    ndrBuffer.align(4);
040    
041                    _netlogonIdentityInfo.encode(ndrBuffer);
042    
043                    int lmChallengeIndex = ndrBuffer.index;
044    
045                    ndrBuffer.advance(8);
046    
047                    ndrBuffer.enc_ndr_short((short)_ntChallengeResponse.length);
048                    ndrBuffer.enc_ndr_short((short)_ntChallengeResponse.length);
049                    ndrBuffer.enc_ndr_referent(_ntChallengeResponse, 1);
050    
051                    ndrBuffer.enc_ndr_short((short)_lmChallengeResponse.length);
052                    ndrBuffer.enc_ndr_short((short)_lmChallengeResponse.length);
053                    ndrBuffer.enc_ndr_referent(_lmChallengeResponse, 1);
054    
055                    _netlogonIdentityInfo.encodeLogonDomainName(ndrBuffer);
056                    _netlogonIdentityInfo.encodeUserName(ndrBuffer);
057                    _netlogonIdentityInfo.encodeWorkStationName(ndrBuffer);
058    
059                    ndrBuffer = ndrBuffer.derive(lmChallengeIndex);
060    
061                    for (int i = 0; i < 8; i++) {
062                            ndrBuffer.enc_ndr_small(_lmChallenge[i]);
063                    }
064    
065                    encodeChallengeResponse(ndrBuffer, _ntChallengeResponse);
066                    encodeChallengeResponse(ndrBuffer, _lmChallengeResponse);
067            }
068    
069            protected void encodeChallengeResponse(
070                    NdrBuffer ndrBuffer, byte[] challenge) {
071    
072                    ndrBuffer = ndrBuffer.deferred;
073    
074                    ndrBuffer.enc_ndr_long(challenge.length);
075                    ndrBuffer.enc_ndr_long(0);
076                    ndrBuffer.enc_ndr_long(challenge.length);
077    
078                    int index = ndrBuffer.index;
079    
080                    ndrBuffer.advance(challenge.length);
081    
082                    ndrBuffer = ndrBuffer.derive(index);
083    
084                    for (int i = 0; i < challenge.length; i++) {
085                            ndrBuffer.enc_ndr_small(challenge[i]);
086                    }
087            }
088    
089            private byte[] _lmChallenge;
090            private byte[] _lmChallengeResponse;
091            private NetlogonIdentityInfo _netlogonIdentityInfo;
092            private byte[] _ntChallengeResponse;
093    
094    }