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 NetrServerAuthenticate3 extends DcerpcMessage {
024    
025            public NetrServerAuthenticate3(
026                    String primaryName, String accountName, int secureChannelType,
027                    String computerName, byte[] clientCredential, byte[] serverCredential,
028                    int negotiateFlags) {
029    
030                    _primaryName = primaryName;
031                    _accountName = accountName;
032                    _secureChannelType = (short)secureChannelType;
033                    _computerName = computerName;
034                    _clientCredential = clientCredential;
035                    _serverCredential = serverCredential;
036                    _negotiateFlags = negotiateFlags;
037    
038                    ptype = 0;
039                    flags = DCERPC_FIRST_FRAG | DCERPC_LAST_FRAG;
040            }
041    
042            @Override
043            public void decode_out(NdrBuffer ndrBuffer) {
044                    int index = ndrBuffer.index;
045    
046                    ndrBuffer.advance(8);
047    
048                    ndrBuffer = ndrBuffer.derive(index);
049    
050                    for (int i = 0; i < 8; i++) {
051                            _serverCredential[i] = (byte)ndrBuffer.dec_ndr_small();
052                    }
053    
054                    _negotiateFlags = ndrBuffer.dec_ndr_long();
055                    _accountRid = ndrBuffer.dec_ndr_long();
056                    _status = ndrBuffer.dec_ndr_long();
057            }
058    
059            @Override
060            public void encode_in(NdrBuffer ndrBuffer) {
061                    ndrBuffer.enc_ndr_referent(_primaryName, 1);
062                    ndrBuffer.enc_ndr_string(_primaryName);
063                    ndrBuffer.enc_ndr_string(_accountName);
064                    ndrBuffer.enc_ndr_short(_secureChannelType);
065                    ndrBuffer.enc_ndr_string(_computerName);
066    
067                    int index = ndrBuffer.index;
068    
069                    ndrBuffer.advance(8);
070    
071                    NdrBuffer derivedNrdBuffer = ndrBuffer.derive(index);
072    
073                    for (int i = 0; i < 8; i++) {
074                            derivedNrdBuffer.enc_ndr_small(_clientCredential[i]);
075                    }
076    
077                    ndrBuffer.enc_ndr_long(_negotiateFlags);
078            }
079    
080            public int getAccountRid() {
081                    return _accountRid;
082            }
083    
084            public int getNegotiatedFlags() {
085                    return _negotiateFlags;
086            }
087    
088            @Override
089            public int getOpnum() {
090                    return 26;
091            }
092    
093            public byte[] getServerCredential() {
094                    return _serverCredential;
095            }
096    
097            public int getStatus() {
098                    return _status;
099            }
100    
101            private String _accountName;
102            private int _accountRid;
103            private byte[] _clientCredential;
104            private String _computerName;
105            private int _negotiateFlags;
106            private String _primaryName;
107            private short _secureChannelType;
108            private byte[] _serverCredential;
109            private int _status;
110    
111    }