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.NdrException;
019    import jcifs.dcerpc.ndr.NdrObject;
020    import jcifs.dcerpc.rpc;
021    
022    /**
023     * @author Marcellus Tavares
024     */
025    public class NetlogonValidationSamInfo extends NdrObject {
026    
027            public NetlogonValidationSamInfo() {
028                    _effectiveName = new rpc.unicode_string();
029                    _fullName = new rpc.unicode_string();
030                    _logonScript = new rpc.unicode_string();
031                    _profilePath = new rpc.unicode_string();
032                    _homeDirectory = new rpc.unicode_string();
033                    _homeDirectoryDrive = new rpc.unicode_string();
034                    _logonServer = new rpc.unicode_string();
035                    _logonDomainName = new rpc.unicode_string();
036                    _userSessionKey = new byte[16];
037                    _logonDomain = new rpc.sid_t();
038            }
039    
040            public void decode(NdrBuffer ndrBuffer) throws NdrException {
041                    _logonTime = ndrBuffer.dec_ndr_hyper();
042                    _logoffTime = ndrBuffer.dec_ndr_hyper();
043                    _kickoffTime = ndrBuffer.dec_ndr_hyper();
044                    _passwordLastSet = ndrBuffer.dec_ndr_hyper();
045                    _passwordCanChange = ndrBuffer.dec_ndr_hyper();
046                    _passwordMustChange = ndrBuffer.dec_ndr_hyper();
047    
048                    _effectiveName.length = (short)ndrBuffer.dec_ndr_short();
049                    _effectiveName.maximum_length = (short)ndrBuffer.dec_ndr_short();
050    
051                    int effectiveNamePtr = ndrBuffer.dec_ndr_long();
052    
053                    _fullName.length = (short)ndrBuffer.dec_ndr_short();
054                    _fullName.maximum_length = (short)ndrBuffer.dec_ndr_short();
055    
056                    int fullNamePtr = ndrBuffer.dec_ndr_long();
057    
058                    _logonScript.length = (short)ndrBuffer.dec_ndr_short();
059                    _logonScript.maximum_length = (short)ndrBuffer.dec_ndr_short();
060    
061                    int logonScriptPtr = ndrBuffer.dec_ndr_long();
062    
063                    _profilePath.length = (short)ndrBuffer.dec_ndr_short();
064                    _profilePath.maximum_length = (short)ndrBuffer.dec_ndr_short();
065    
066                    int profilePathPtr = ndrBuffer.dec_ndr_long();
067    
068                    _homeDirectory.length = (short)ndrBuffer.dec_ndr_short();
069                    _homeDirectory.maximum_length = (short)ndrBuffer.dec_ndr_short();
070    
071                    int homeDirectoryPtr = ndrBuffer.dec_ndr_long();
072    
073                    _homeDirectoryDrive.length = (short)ndrBuffer.dec_ndr_short();
074                    _homeDirectoryDrive.maximum_length = (short)ndrBuffer.dec_ndr_short();
075    
076                    int homeDirectoryDrivePtr = ndrBuffer.dec_ndr_long();
077    
078                    _logonCount = (short)ndrBuffer.dec_ndr_short();
079                    _badPasswordCount = (short)ndrBuffer.dec_ndr_short();
080    
081                    _userId = ndrBuffer.dec_ndr_long();
082                    _primaryGroupId = ndrBuffer.dec_ndr_long();
083    
084                    _groupCount = ndrBuffer.dec_ndr_long();
085    
086                    int groupIdsPtr = ndrBuffer.dec_ndr_long();
087    
088                    _userFlags = ndrBuffer.dec_ndr_long();
089    
090                    int userSessionKeyI = ndrBuffer.index;
091    
092                    ndrBuffer.advance(16);
093    
094                    _logonServer.length = (short)ndrBuffer.dec_ndr_short();
095                    _logonServer.maximum_length = (short)ndrBuffer.dec_ndr_short();
096    
097                    int logonServerPtr = ndrBuffer.dec_ndr_long();
098    
099                    _logonDomainName.length = (short)ndrBuffer.dec_ndr_short();
100                    _logonDomainName.maximum_length = (short)ndrBuffer.dec_ndr_short();
101    
102                    int logonDomainNamePtr = ndrBuffer.dec_ndr_long();
103    
104                    int logonDomainPtr = ndrBuffer.dec_ndr_long();
105    
106                    ndrBuffer.advance(40);
107    
108                    if (effectiveNamePtr > 0) {
109                            decodeUnicodeString(ndrBuffer, _effectiveName);
110                    }
111    
112                    if (fullNamePtr > 0) {
113                            decodeUnicodeString(ndrBuffer, _fullName);
114                    }
115    
116                    if (logonScriptPtr > 0) {
117                            decodeUnicodeString(ndrBuffer, _logonScript);
118                    }
119    
120                    if (profilePathPtr > 0) {
121                            decodeUnicodeString(ndrBuffer, _profilePath);
122                    }
123    
124                    if (homeDirectoryPtr > 0) {
125                            decodeUnicodeString(ndrBuffer, _homeDirectory);
126                    }
127    
128                    if (homeDirectoryDrivePtr > 0) {
129                            decodeUnicodeString(ndrBuffer, _homeDirectoryDrive);
130                    }
131    
132                    if (groupIdsPtr > 0) {
133                            _groupIds = new GroupMembership[_groupCount];
134    
135                            ndrBuffer = ndrBuffer.deferred;
136    
137                            int groupIdsS = ndrBuffer.dec_ndr_long();
138                            int groupIdsI = ndrBuffer.index;
139    
140                            ndrBuffer.advance(8 * groupIdsS);
141    
142                            ndrBuffer = ndrBuffer.derive(groupIdsI);
143    
144                            for (int i = 0; i < groupIdsS; i++) {
145                                    if (_groupIds[i] == null) {
146                                            _groupIds[i] = new GroupMembership();
147                                    }
148    
149                                    _groupIds[i].decode(ndrBuffer);
150                            }
151                    }
152    
153                    ndrBuffer = ndrBuffer.derive(userSessionKeyI);
154    
155                    for (int i = 0; i < 16; i++) {
156                            _userSessionKey[i] = (byte) ndrBuffer.dec_ndr_small();
157                    }
158    
159                    if (logonServerPtr > 0) {
160                            decodeUnicodeString(ndrBuffer, _logonServer);
161                    }
162    
163                    if (logonDomainNamePtr > 0) {
164                            decodeUnicodeString(ndrBuffer, _logonDomainName);
165                    }
166    
167                    if (logonDomainPtr > 0) {
168                            ndrBuffer = ndrBuffer.deferred;
169    
170                            _logonDomain.decode(ndrBuffer);
171                    }
172            }
173    
174            public void encode(NdrBuffer ndrBuffer) {
175            }
176    
177            public rpc.unicode_string getEffectiveName() {
178                    return _effectiveName;
179            }
180    
181            protected void decodeUnicodeString(
182                    NdrBuffer ndrBuffer, rpc.unicode_string string) {
183    
184                    ndrBuffer = ndrBuffer.deferred;
185    
186                    int bufferS = ndrBuffer.dec_ndr_long();
187    
188                    ndrBuffer.dec_ndr_long();
189    
190                    int bufferL = ndrBuffer.dec_ndr_long();
191                    int bufferI = ndrBuffer.index;
192    
193                    ndrBuffer.advance(2 * bufferL);
194    
195                    if (string.buffer == null) {
196                            string.buffer = new short[bufferS];
197                    }
198    
199                    ndrBuffer = ndrBuffer.derive(bufferI);
200    
201                    for (int i = 0; i < bufferL; i++) {
202                            string.buffer[i] = (short)ndrBuffer.dec_ndr_short();
203                    }
204            }
205    
206            @SuppressWarnings("unused")
207            private short _badPasswordCount;
208    
209            private rpc.unicode_string _effectiveName;
210            private rpc.unicode_string _fullName;
211            private int _groupCount;
212            private GroupMembership[] _groupIds;
213            private rpc.unicode_string _homeDirectory;
214            private rpc.unicode_string _homeDirectoryDrive;
215    
216            @SuppressWarnings("unused")
217            private long _kickoffTime;
218    
219            @SuppressWarnings("unused")
220            private long _logoffTime;
221    
222            @SuppressWarnings("unused")
223            private short _logonCount;
224    
225            private rpc.sid_t _logonDomain;
226            private rpc.unicode_string _logonDomainName;
227            private rpc.unicode_string _logonScript;
228            private rpc.unicode_string _logonServer;
229    
230            @SuppressWarnings("unused")
231            private long _logonTime;
232    
233            @SuppressWarnings("unused")
234            private long _passwordCanChange;
235    
236            @SuppressWarnings("unused")
237            private long _passwordLastSet;
238    
239            @SuppressWarnings("unused")
240            private long _passwordMustChange;
241    
242            @SuppressWarnings("unused")
243            private int _primaryGroupId;
244    
245            private rpc.unicode_string _profilePath;
246    
247            @SuppressWarnings("unused")
248            private int _userFlags;
249    
250            @SuppressWarnings("unused")
251            private int _userId;
252    
253            private byte[] _userSessionKey;
254    
255    }