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.ndr.NdrBuffer;
018    import jcifs.dcerpc.ndr.NdrObject;
019    
020    /**
021     * @author Marcellus Tavares
022     */
023    public class NetlogonAuthenticator extends NdrObject {
024    
025            public NetlogonAuthenticator() {
026                    _credential = new byte[8];
027            }
028    
029            public NetlogonAuthenticator(byte[] credential, int timestamp) {
030                    _credential = credential;
031                    _timestamp = timestamp;
032            }
033    
034            @Override
035            public void decode(NdrBuffer ndrBuffer) {
036                    ndrBuffer.align(4);
037    
038                    int index = ndrBuffer.index;
039    
040                    ndrBuffer.advance(8);
041    
042                    _timestamp = ndrBuffer.dec_ndr_long();
043    
044                    ndrBuffer = ndrBuffer.derive(index);
045    
046                    for (int i = 0; i < 8; i++) {
047                            _credential[i] = (byte)ndrBuffer.dec_ndr_small();
048                    }
049            }
050    
051            @Override
052            public void encode(NdrBuffer ndrBuffer) {
053                    ndrBuffer.align(4);
054    
055                    int index = ndrBuffer.index;
056    
057                    ndrBuffer.advance(8);
058    
059                    ndrBuffer.enc_ndr_long(_timestamp);
060    
061                    ndrBuffer = ndrBuffer.derive(index);
062    
063                    for (int i = 0; i < 8; i++) {
064                            ndrBuffer.enc_ndr_small(_credential[i]);
065                    }
066            }
067    
068            private byte[] _credential;
069            private int _timestamp;
070    
071    }