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.UnicodeString;
018    import jcifs.dcerpc.ndr.NdrBuffer;
019    import jcifs.dcerpc.ndr.NdrObject;
020    import jcifs.dcerpc.rpc;
021    
022    /**
023     * @author Marcellus Tavares
024     */
025    public class NetlogonIdentityInfo extends NdrObject {
026    
027            public NetlogonIdentityInfo(
028                    String logonDomainName, int parameterControl, int reservedLow,
029                    int reservedHigh, String userName, String workstation) {
030    
031                    _logonDomainName = new UnicodeString(logonDomainName, false);
032                    _parameterControl= parameterControl;
033                    _reservedLow = reservedLow;
034                    _reservedHigh = reservedHigh;
035                    _userName = new UnicodeString(userName, false);
036                    _workstation = new UnicodeString(workstation, false);
037            }
038    
039            @Override
040            public void decode(NdrBuffer ndrBuffer) {
041            }
042    
043            @Override
044            public void encode(NdrBuffer ndrBuffer) {
045                    ndrBuffer.enc_ndr_short(_logonDomainName.length);
046                    ndrBuffer.enc_ndr_short(_logonDomainName.maximum_length);
047                    ndrBuffer.enc_ndr_referent(_logonDomainName.buffer, 1);
048                    ndrBuffer.enc_ndr_long(_parameterControl);
049                    ndrBuffer.enc_ndr_long(_reservedLow);
050                    ndrBuffer.enc_ndr_long(_reservedHigh);
051                    ndrBuffer.enc_ndr_short(_userName.length);
052                    ndrBuffer.enc_ndr_short(_userName.maximum_length);
053                    ndrBuffer.enc_ndr_referent(_userName.buffer, 1);
054                    ndrBuffer.enc_ndr_short(_workstation.length);
055                    ndrBuffer.enc_ndr_short(_workstation.maximum_length);
056                    ndrBuffer.enc_ndr_referent(_workstation.buffer, 1);
057            }
058    
059            public void encodeLogonDomainName(NdrBuffer ndrBuffer) {
060                    encodeUnicodeString(ndrBuffer, _logonDomainName);
061            }
062    
063            public void encodeUserName(NdrBuffer ndrBuffer) {
064                    encodeUnicodeString(ndrBuffer, _userName);
065            }
066    
067            public void encodeWorkStationName(NdrBuffer ndrBuffer) {
068                    encodeUnicodeString(ndrBuffer, _workstation);
069            }
070    
071            protected void encodeUnicodeString(
072                    NdrBuffer ndrBuffer, rpc.unicode_string string ) {
073    
074                    ndrBuffer = ndrBuffer.deferred;
075    
076                    int stringBufferl = string.length / 2;
077                    int stringBuffers = string.maximum_length / 2;
078    
079                    ndrBuffer.enc_ndr_long(stringBuffers);
080                    ndrBuffer.enc_ndr_long(0);
081                    ndrBuffer.enc_ndr_long(stringBufferl);
082    
083                    int stringBufferIndex = ndrBuffer.index;
084    
085                    ndrBuffer.advance(2 * stringBufferl);
086    
087                    ndrBuffer = ndrBuffer.derive(stringBufferIndex);
088    
089                    for (int _i = 0; _i < stringBufferl; _i++) {
090                            ndrBuffer.enc_ndr_short(string.buffer[_i]);
091                    }
092            }
093    
094            private rpc.unicode_string _logonDomainName;
095            private int _parameterControl;
096            private int _reservedHigh;
097            private int _reservedLow;
098            private rpc.unicode_string _userName;
099            private rpc.unicode_string _workstation;
100    
101    }