001    /**
002     * Copyright (c) 2000-2013 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.DcerpcMessage;
018    import jcifs.dcerpc.ndr.NdrBuffer;
019    
020    /**
021     * @author Marcellus Tavares
022     */
023    public class NetrServerReqChallenge extends DcerpcMessage {
024    
025            public NetrServerReqChallenge(
026                    String primaryName, String computerName, byte[] clientChallenge,
027                    byte[] serverChallenge) {
028    
029                    _primaryName = primaryName;
030                    _computerName = computerName;
031                    _clientChallenge = clientChallenge;
032                    _serverChallenge = serverChallenge;
033    
034                    ptype = 0;
035                    flags = DCERPC_FIRST_FRAG | DCERPC_LAST_FRAG;
036            }
037    
038            @Override
039            public void decode_out(NdrBuffer ndrBuffer) {
040                    int index = ndrBuffer.index;
041    
042                    ndrBuffer.advance(8);
043    
044                    ndrBuffer = ndrBuffer.derive(index);
045    
046                    for (int i = 0; i < 8; i++) {
047                            _serverChallenge[i] = (byte)ndrBuffer.dec_ndr_small();
048                    }
049    
050                    _status = ndrBuffer.dec_ndr_long();
051            }
052    
053            @Override
054            public void encode_in(NdrBuffer ndrBuffer) {
055                    ndrBuffer.enc_ndr_referent(_primaryName, 1);
056                    ndrBuffer.enc_ndr_string(_primaryName);
057                    ndrBuffer.enc_ndr_string(_computerName);
058    
059                    int index = ndrBuffer.index;
060    
061                    ndrBuffer.advance(8);
062    
063                    ndrBuffer = ndrBuffer.derive(index);
064    
065                    for (int i = 0; i < 8; i++) {
066                            ndrBuffer.enc_ndr_small(_clientChallenge[i]);
067                    }
068            }
069    
070            @Override
071            public int getOpnum() {
072                    return 4;
073            }
074    
075            public byte[] getServerChallenge() {
076                    return _serverChallenge;
077            }
078    
079            public int getStatus() {
080                    return _status;
081            }
082    
083            private byte[] _clientChallenge;
084            private String _computerName;
085            private String _primaryName;
086            private byte[] _serverChallenge;
087            private int _status;
088    
089    }