KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > dcerpc > info > UserInfo


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.smb.dcerpc.info;
18
19 import java.util.BitSet JavaDoc;
20
21 import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
22 import org.alfresco.filesys.smb.dcerpc.DCEBufferException;
23 import org.alfresco.filesys.smb.dcerpc.DCEReadable;
24
25 /**
26  * User Information Class
27  * <p>
28  * Contains the details of a user account on a remote server.
29  */

30 public class UserInfo implements DCEReadable
31 {
32
33     // Information levels supported
34

35     public static final int InfoLevel1 = 1;
36     public static final int InfoLevel3 = 3;
37     public static final int InfoLevel21 = 21;
38
39     // public static final int InfoLevel2 = 2;
40
// public static final int InfoLevel4 = 4;
41
// public static final int InfoLevel5 = 5;
42
// public static final int InfoLevel6 = 6;
43
// public static final int InfoLevel7 = 7;
44
// public static final int InfoLevel8 = 8;
45
// public static final int InfoLevel9 = 9;
46
// public static final int InfoLevel10 = 10;
47
// public static final int InfoLevel11 = 11;
48
// public static final int InfoLevel12 = 12;
49
// public static final int InfoLevel13 = 13;
50
// public static final int InfoLevel14 = 14;
51
// public static final int InfoLevel16 = 16;
52
// public static final int InfoLevel17 = 17;
53
// public static final int InfoLevel20 = 20;
54

55     // Account privilege levels
56

57     public static final int PrivGuest = 0;
58     public static final int PrivUser = 1;
59     public static final int PrivAdmin = 2;
60
61     // Account operator privileges
62

63     public static final int OperPrint = 0;
64     public static final int OperComm = 1;
65     public static final int OperServer = 2;
66     public static final int OperAccounts = 3;
67
68     // Account flags
69

70     private static final int AccountDisabled = 0x0001;
71     private static final int AccountHomeDirRequired = 0x0002;
72     private static final int AccountPasswordNotRequired = 0x0004;
73     private static final int AccountTemporaryDuplicate = 0x0008;
74     private static final int AccountNormal = 0x0010;
75     private static final int AccountMNSUser = 0x0020;
76     private static final int AccountDomainTrust = 0x0040;
77     private static final int AccountWorkstationTrust = 0x0080;
78     private static final int AccountServerTrust = 0x0100;
79     private static final int AccountPasswordNotExpire = 0x0200;
80     private static final int AccountAutoLocked = 0x0400;
81
82     // Information level
83

84     private int m_infoLevel;
85
86     // User information
87

88     private String JavaDoc m_userName;
89
90     private int m_pwdAge;
91     private int m_priv;
92
93     private String JavaDoc m_homeDir;
94     private String JavaDoc m_comment;
95     private String JavaDoc m_description;
96     private String JavaDoc m_accComment;
97
98     private int m_flags;
99
100     private String JavaDoc m_scriptPath;
101     // private int m_authFlags;
102

103     private String JavaDoc m_fullName;
104     private String JavaDoc m_appParam;
105     private String JavaDoc m_workStations;
106
107     private long m_lastLogon;
108     private long m_lastLogoff;
109     private long m_acctExpires;
110     private long m_lastPwdChange;
111     private long m_pwdCanChange;
112     private long m_pwdMustchange;
113
114     // private int m_maxStorage;
115
private int m_unitsPerWeek;
116     private byte[] m_logonHoursRaw;
117     private BitSet JavaDoc m_logonHours;
118
119     private int m_badPwdCount;
120     private int m_numLogons;
121     private String JavaDoc logonSrv;
122
123     private int m_countryCode;
124     private int m_codePage;
125
126     private int m_userRID;
127     private int m_groupRID;
128     // private SID m_userSID;
129

130     private String JavaDoc m_profile;
131     private String JavaDoc m_homeDirDrive;
132
133     private int m_pwdExpired;
134
135     private String JavaDoc m_callBack;
136     private String JavaDoc m_unknown1;
137     private String JavaDoc m_unknown2;
138     private String JavaDoc m_unknown3;
139
140     /**
141      * Default constructor
142      */

143     public UserInfo()
144     {
145     }
146
147     /**
148      * Class constructor
149      *
150      * @param lev int
151      */

152     public UserInfo(int lev)
153     {
154         m_infoLevel = lev;
155     }
156
157     /**
158      * Get the information level
159      *
160      * @return int
161      */

162     public final int getInformationLevel()
163     {
164         return m_infoLevel;
165     }
166
167     /**
168      * Return the logon server name
169      *
170      * @return String
171      */

172     public final String JavaDoc getLogonServer()
173     {
174         return logonSrv;
175     }
176
177     /**
178      * Return the date/time the account expires, or NTTime.Infinity if it does not expire
179      *
180      * @return long
181      */

182     public final long getAccountExpires()
183     {
184         return m_acctExpires;
185     }
186
187     /**
188      * Return the application parameter string
189      *
190      * @return String
191      */

192     public final String JavaDoc getApplicationParameter()
193     {
194         return m_appParam;
195     }
196
197     /**
198      * Return the bad password count
199      *
200      * @return int
201      */

202     public final int getBadPasswordCount()
203     {
204         return m_badPwdCount;
205     }
206
207     /**
208      * Return the code page
209      *
210      * @return int
211      */

212     public final int getCodePage()
213     {
214         return m_codePage;
215     }
216
217     /**
218      * Return the account comment
219      *
220      * @return String
221      */

222     public final String JavaDoc getComment()
223     {
224         return m_comment;
225     }
226
227     /**
228      * Return the account description
229      *
230      * @return String
231      */

232     public final String JavaDoc getDescription()
233     {
234         return m_description;
235     }
236
237     /**
238      * Return the country code
239      *
240      * @return int
241      */

242     public final int getCountryCode()
243     {
244         return m_countryCode;
245     }
246
247     /**
248      * Return the account flags
249      *
250      * @return int
251      */

252     public final int getFlags()
253     {
254         return m_flags;
255     }
256
257     /**
258      * Check if the account is disabled
259      *
260      * @return boolean
261      */

262     public final boolean isDisabled()
263     {
264         return (m_flags & AccountDisabled) != 0 ? true : false;
265     }
266
267     /**
268      * Check if the account does not require a home directory
269      *
270      * @return boolean
271      */

272     public final boolean requiresHomeDirectory()
273     {
274         return (m_flags & AccountHomeDirRequired) != 0 ? true : false;
275     }
276
277     /**
278      * Check if the account does not require a password
279      *
280      * @return boolean
281      */

282     public final boolean requiresPassword()
283     {
284         return (m_flags & AccountPasswordNotRequired) != 0 ? false : true;
285     }
286
287     /**
288      * Check if the account is a normal user account
289      *
290      * @return boolean
291      */

292     public final boolean isNormalUser()
293     {
294         return (m_flags & AccountNormal) != 0 ? true : false;
295     }
296
297     /**
298      * Check if the account is a domain trust account
299      *
300      * @return boolean
301      */

302     public final boolean isDomainTrust()
303     {
304         return (m_flags & AccountDomainTrust) != 0 ? true : false;
305     }
306
307     /**
308      * Check if the account is a workstation trust account
309      *
310      * @return boolean
311      */

312     public final boolean isWorkstationTrust()
313     {
314         return (m_flags & AccountWorkstationTrust) != 0 ? true : false;
315     }
316
317     /**
318      * Check if the account is a server trust account
319      *
320      * @return boolean
321      */

322     public final boolean isServerTrust()
323     {
324         return (m_flags & AccountServerTrust) != 0 ? true : false;
325     }
326
327     /**
328      * Check if the account password expires
329      *
330      * @return boolean
331      */

332     public final boolean passwordExpires()
333     {
334         return (m_flags & AccountPasswordNotExpire) != 0 ? false : true;
335     }
336
337     /**
338      * Check if the account is auto locked
339      *
340      * @return boolean
341      */

342     public final boolean isAutoLocked()
343     {
344         return (m_flags & AccountAutoLocked) != 0 ? true : false;
345     }
346
347     /**
348      * Return the full account name
349      *
350      * @return String
351      */

352     public final String JavaDoc getFullName()
353     {
354         return m_fullName;
355     }
356
357     /**
358      * Return the group resource id
359      *
360      * @return int
361      */

362     public final int getGroupRID()
363     {
364         return m_groupRID;
365     }
366
367     /**
368      * Return the home directory path
369      *
370      * @return String
371      */

372     public final String JavaDoc getHomeDirectory()
373     {
374         return m_homeDir;
375     }
376
377     /**
378      * Return the home drive
379      *
380      * @return String
381      */

382     public final String JavaDoc getHomeDirectoryDrive()
383     {
384         return m_homeDirDrive;
385     }
386
387     /**
388      * Return the date/time of last logoff
389      *
390      * @return long
391      */

392     public final long getLastLogoff()
393     {
394         return m_lastLogoff;
395     }
396
397     /**
398      * Return the date/time of last logon, to this server
399      *
400      * @return long
401      */

402     public final long getLastLogon()
403     {
404         return m_lastLogon;
405     }
406
407     /**
408      * Return the allowed logon hours bit set
409      *
410      * @return BitSet
411      */

412     public final BitSet JavaDoc getLogonHours()
413     {
414         return m_logonHours;
415     }
416
417     /**
418      * Return the number of logons for the account, to this server
419      *
420      * @return int
421      */

422     public final int numberOfLogons()
423     {
424         return m_numLogons;
425     }
426
427     /**
428      * Return the account provileges
429      *
430      * @return int
431      */

432     public final int getPrivileges()
433     {
434         return m_priv;
435     }
436
437     /**
438      * Return the profile path
439      *
440      * @return String
441      */

442     public final String JavaDoc getProfile()
443     {
444         return m_profile;
445     }
446
447     /**
448      * Return the password expired flag
449      *
450      * @return int
451      */

452     public final int getPasswordExpired()
453     {
454         return m_pwdExpired;
455     }
456
457     /**
458      * Return the logon script path
459      *
460      * @return String
461      */

462     public final String JavaDoc getLogonScriptPath()
463     {
464         return m_scriptPath;
465     }
466
467     /**
468      * Return the allowed units per week
469      *
470      * @return int
471      */

472     public final int getUnitsPerWeek()
473     {
474         return m_unitsPerWeek;
475     }
476
477     /**
478      * Return the account name
479      *
480      * @return String
481      */

482     public final String JavaDoc getUserName()
483     {
484         return m_userName;
485     }
486
487     /**
488      * Return the user resource id
489      *
490      * @return int
491      */

492     public final int getUserRID()
493     {
494         return m_userRID;
495     }
496
497     /**
498      * Return the workstations that the account is allowed to logon from
499      *
500      * @return String
501      */

502     public final String JavaDoc getWorkStations()
503     {
504         return m_workStations;
505     }
506
507     /**
508      * Return the date/time of the last password change
509      *
510      * @return long
511      */

512     public final long getLastPasswordChange()
513     {
514         return m_lastPwdChange;
515     }
516
517     /**
518      * Return the date/time that the password must be changed by
519      *
520      * @return long
521      */

522     public final long getPasswordMustChangeBy()
523     {
524         return m_pwdMustchange;
525     }
526
527     /**
528      * Clear all string values
529      */

530     private final void clearStrings()
531     {
532
533         // Clear the string values
534

535         m_appParam = null;
536         m_comment = null;
537         m_fullName = null;
538         m_homeDir = null;
539         m_homeDirDrive = null;
540         m_profile = null;
541         m_scriptPath = null;
542         m_userName = null;
543         m_workStations = null;
544         m_description = null;
545         m_accComment = null;
546     }
547
548     /**
549      * Read the user information from the DCE buffer
550      *
551      * @param buf DCEBuffer
552      * @throws DCEBufferException
553      */

554     public void readObject(DCEBuffer buf) throws DCEBufferException
555     {
556
557         // clear all existing string values
558

559         clearStrings();
560
561         // Unpack the user information
562

563         int ival = 0;
564         int pval = 0;
565
566         switch (getInformationLevel())
567         {
568
569         // Information level 1
570

571         case InfoLevel1:
572             m_userName = buf.getCharArrayPointer();
573             m_fullName = buf.getCharArrayPointer();
574             m_groupRID = buf.getInt();
575             m_description = buf.getCharArrayPointer();
576             m_comment = buf.getCharArrayPointer();
577             break;
578
579         // Information level 3
580

581         case InfoLevel3:
582             m_userName = buf.getCharArrayPointer();
583             m_fullName = buf.getCharArrayPointer();
584
585             m_userRID = buf.getInt();
586             m_groupRID = buf.getInt();
587
588             m_homeDir = buf.getCharArrayPointer();
589             m_homeDirDrive = buf.getCharArrayPointer();
590             m_scriptPath = buf.getCharArrayPointer();
591             m_profile = buf.getCharArrayPointer();
592             m_workStations = buf.getCharArrayPointer();
593
594             m_lastLogon = buf.getNTTime();
595             m_lastLogoff = buf.getNTTime();
596             m_lastPwdChange = buf.getNTTime();
597             buf.skipBytes(8); // allow password change NT time
598
buf.skipBytes(8); // force password change NT time
599

600             ival = buf.getShort(DCEBuffer.ALIGN_INT);
601             pval = buf.getPointer();
602
603             if (ival != 0 && pval != 0)
604                 m_logonHoursRaw = new byte[ival / 8];
605
606             m_badPwdCount = buf.getShort();
607             m_numLogons = buf.getShort();
608
609             m_flags = buf.getInt();
610             break;
611
612         // Information level 21
613

614         case InfoLevel21:
615             m_lastLogon = buf.getNTTime();
616             m_lastLogoff = buf.getNTTime();
617             m_lastPwdChange = buf.getNTTime();
618             m_acctExpires = buf.getNTTime();
619             m_pwdCanChange = buf.getNTTime();
620             m_pwdMustchange = buf.getNTTime();
621
622             m_userName = buf.getCharArrayPointer();
623             m_fullName = buf.getCharArrayPointer();
624
625             m_homeDir = buf.getCharArrayPointer();
626             m_homeDirDrive = buf.getCharArrayPointer();
627             m_scriptPath = buf.getCharArrayPointer();
628             m_profile = buf.getCharArrayPointer();
629             m_description = buf.getCharArrayPointer();
630             m_workStations = buf.getCharArrayPointer();
631             m_accComment = buf.getCharArrayPointer();
632
633             m_callBack = buf.getCharArrayPointer();
634             m_unknown1 = buf.getCharArrayPointer();
635             m_unknown2 = buf.getCharArrayPointer();
636             m_unknown3 = buf.getCharArrayPointer();
637
638             buf.skipBytes(8); // buffer length and pointer
639

640             m_userRID = buf.getInt();
641             m_groupRID = buf.getInt();
642
643             m_flags = buf.getInt();
644
645             buf.getInt(); // fields present flags
646

647             ival = buf.getShort(DCEBuffer.ALIGN_INT);
648             pval = buf.getPointer();
649
650             if (ival != 0 && pval != 0)
651                 m_logonHoursRaw = new byte[ival / 8];
652
653             m_badPwdCount = buf.getShort();
654             m_numLogons = buf.getShort();
655
656             m_countryCode = buf.getShort();
657             m_codePage = buf.getShort();
658
659             buf.skipBytes(2); // NT and LM pwd set flags
660

661             m_pwdExpired = buf.getByte(DCEBuffer.ALIGN_INT);
662             break;
663         }
664     }
665
666     /**
667      * Read the strings for this user information from the DCE buffer
668      *
669      * @param buf DCEBuffer
670      * @throws DCEBufferException
671      */

672     public void readStrings(DCEBuffer buf) throws DCEBufferException
673     {
674
675         // Read the strings/structures for this user information
676

677         switch (getInformationLevel())
678         {
679
680         // Information level 1
681

682         case InfoLevel1:
683             m_userName = buf.getCharArrayNotNull(m_userName, DCEBuffer.ALIGN_INT);
684             m_fullName = buf.getCharArrayNotNull(m_fullName, DCEBuffer.ALIGN_INT);
685
686             m_description = buf.getCharArrayNotNull(m_description, DCEBuffer.ALIGN_INT);
687             m_comment = buf.getCharArrayNotNull(m_comment, DCEBuffer.ALIGN_INT);
688             break;
689
690         // Information level 3
691

692         case InfoLevel3:
693             m_userName = buf.getCharArrayNotNull(m_userName, DCEBuffer.ALIGN_INT);
694             m_fullName = buf.getCharArrayNotNull(m_fullName, DCEBuffer.ALIGN_INT);
695
696             m_homeDir = buf.getCharArrayNotNull(m_homeDir, DCEBuffer.ALIGN_INT);
697             m_homeDirDrive = buf.getCharArrayNotNull(m_homeDirDrive, DCEBuffer.ALIGN_INT);
698
699             m_scriptPath = buf.getCharArrayNotNull(m_scriptPath, DCEBuffer.ALIGN_INT);
700             m_profile = buf.getCharArrayNotNull(m_profile, DCEBuffer.ALIGN_INT);
701             m_workStations = buf.getCharArrayNotNull(m_workStations, DCEBuffer.ALIGN_INT);
702
703             m_logonHoursRaw = buf.getByteStructure(m_logonHoursRaw);
704             break;
705
706         // Information level 21
707

708         case InfoLevel21:
709             m_userName = buf.getCharArrayNotNull(m_userName, DCEBuffer.ALIGN_INT);
710             m_fullName = buf.getCharArrayNotNull(m_fullName, DCEBuffer.ALIGN_INT);
711
712             m_homeDir = buf.getCharArrayNotNull(m_homeDir, DCEBuffer.ALIGN_INT);
713             m_homeDirDrive = buf.getCharArrayNotNull(m_homeDirDrive, DCEBuffer.ALIGN_INT);
714
715             m_scriptPath = buf.getCharArrayNotNull(m_scriptPath, DCEBuffer.ALIGN_INT);
716             m_profile = buf.getCharArrayNotNull(m_profile, DCEBuffer.ALIGN_INT);
717             m_description = buf.getCharArrayNotNull(m_description, DCEBuffer.ALIGN_INT);
718             m_workStations = buf.getCharArrayNotNull(m_workStations, DCEBuffer.ALIGN_INT);
719             m_accComment = buf.getCharArrayNotNull(m_profile, DCEBuffer.ALIGN_INT);
720
721             m_callBack = buf.getCharArrayNotNull(m_callBack, DCEBuffer.ALIGN_INT);
722             m_unknown1 = buf.getCharArrayNotNull(m_unknown1, DCEBuffer.ALIGN_INT);
723             m_unknown2 = buf.getCharArrayNotNull(m_unknown2, DCEBuffer.ALIGN_INT);
724             m_unknown3 = buf.getCharArrayNotNull(m_unknown3, DCEBuffer.ALIGN_INT);
725
726             m_logonHoursRaw = buf.getByteStructure(m_logonHoursRaw);
727             break;
728         }
729     }
730
731     /**
732      * Return an account type as a string
733      *
734      * @param typ int
735      * @return String
736      */

737     public final static String JavaDoc getAccountTypeAsString(int typ)
738     {
739         String JavaDoc ret = "";
740         switch (typ)
741         {
742         case PrivGuest:
743             ret = "Guest";
744             break;
745         case PrivUser:
746             ret = "User";
747             break;
748         case PrivAdmin:
749             ret = "Administrator";
750             break;
751         }
752         return ret;
753     }
754
755     /**
756      * Return the user information as a string
757      *
758      * @return String
759      */

760     public String JavaDoc toString()
761     {
762         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
763
764         str.append("[");
765         str.append(getUserName());
766         str.append(":");
767         str.append(getInformationLevel());
768         str.append(":");
769
770         str.append("]");
771         return str.toString();
772     }
773 }
Popular Tags