@@ -209,8 +209,12 @@ public static LocalGroup[] getLocalGroups(String serverName) {
209
209
ArrayList <LocalGroup > result = new ArrayList <LocalGroup >();
210
210
for (LOCALGROUP_INFO_1 lgpi : groups ) {
211
211
LocalGroup lgp = new LocalGroup ();
212
- lgp .name = lgpi .lgrui1_name .toString ();
213
- lgp .comment = lgpi .lgrui1_comment .toString ();;
212
+ if (lgpi .lgrui1_name != null ) {
213
+ lgp .name = lgpi .lgrui1_name .toString ();
214
+ }
215
+ if (lgpi .lgrui1_comment != null ) {
216
+ lgp .comment = lgpi .lgrui1_comment .toString ();
217
+ }
214
218
result .add (lgp );
215
219
}
216
220
return result .toArray (new LocalGroup [0 ]);
@@ -254,8 +258,12 @@ public static Group[] getGlobalGroups(String serverName) {
254
258
ArrayList <LocalGroup > result = new ArrayList <LocalGroup >();
255
259
for (LMAccess .GROUP_INFO_1 lgpi : groups ) {
256
260
LocalGroup lgp = new LocalGroup ();
257
- lgp .name = lgpi .grpi1_name .toString ();
258
- lgp .comment = lgpi .grpi1_comment .toString ();;
261
+ if (lgpi .grpi1_name != null ) {
262
+ lgp .name = lgpi .grpi1_name .toString ();
263
+ }
264
+ if (lgpi .grpi1_comment != null ) {
265
+ lgp .comment = lgpi .grpi1_comment .toString ();
266
+ }
259
267
result .add (lgp );
260
268
}
261
269
return result .toArray (new LocalGroup [0 ]);
@@ -287,19 +295,21 @@ public static User[] getUsers(String serverName) {
287
295
IntByReference entriesRead = new IntByReference ();
288
296
IntByReference totalEntries = new IntByReference ();
289
297
try {
290
- int rc = Netapi32 .INSTANCE .NetUserEnum (serverName , 1 , 0 , bufptr ,
291
- LMCons .MAX_PREFERRED_LENGTH , entriesRead ,
292
- totalEntries , null );
298
+ int rc = Netapi32 .INSTANCE .NetUserEnum (
299
+ serverName , 1 , 0 , bufptr ,
300
+ LMCons .MAX_PREFERRED_LENGTH , entriesRead ,
301
+ totalEntries , null );
293
302
if (LMErr .NERR_Success != rc || bufptr .getValue () == Pointer .NULL ) {
294
303
throw new Win32Exception (rc );
295
304
}
296
305
LMAccess .USER_INFO_1 user = new LMAccess .USER_INFO_1 (bufptr .getValue ());
297
306
LMAccess .USER_INFO_1 [] users = (LMAccess .USER_INFO_1 []) user .toArray (entriesRead .getValue ());
298
-
299
307
ArrayList <User > result = new ArrayList <User >();
300
308
for (LMAccess .USER_INFO_1 lu : users ) {
301
309
User auser = new User ();
302
- auser .name = lu .usri1_name .toString ();
310
+ if (lu .usri1_name != null ) {
311
+ auser .name = lu .usri1_name .toString ();
312
+ }
303
313
result .add (auser );
304
314
}
305
315
return result .toArray (new User [0 ]);
@@ -318,8 +328,7 @@ public static User[] getUsers(String serverName) {
318
328
* @return Local groups.
319
329
*/
320
330
public static Group [] getCurrentUserLocalGroups () {
321
- return getUserLocalGroups (Secur32Util .getUserNameEx (
322
- EXTENDED_NAME_FORMAT .NameSamCompatible ));
331
+ return getUserLocalGroups (Secur32Util .getUserNameEx (EXTENDED_NAME_FORMAT .NameSamCompatible ));
323
332
}
324
333
325
334
/**
@@ -342,8 +351,9 @@ public static Group[] getUserLocalGroups(String userName, String serverName) {
342
351
IntByReference entriesread = new IntByReference ();
343
352
IntByReference totalentries = new IntByReference ();
344
353
try {
345
- int rc = Netapi32 .INSTANCE .NetUserGetLocalGroups (serverName , userName ,
346
- 0 , 0 , bufptr , LMCons .MAX_PREFERRED_LENGTH , entriesread , totalentries );
354
+ int rc = Netapi32 .INSTANCE .NetUserGetLocalGroups (
355
+ serverName , userName ,
356
+ 0 , 0 , bufptr , LMCons .MAX_PREFERRED_LENGTH , entriesread , totalentries );
347
357
if (rc != LMErr .NERR_Success ) {
348
358
throw new Win32Exception (rc );
349
359
}
@@ -352,7 +362,9 @@ public static Group[] getUserLocalGroups(String userName, String serverName) {
352
362
ArrayList <Group > result = new ArrayList <Group >();
353
363
for (LOCALGROUP_USERS_INFO_0 lgpi : lgroups ) {
354
364
LocalGroup lgp = new LocalGroup ();
355
- lgp .name = lgpi .lgrui0_name .toString ();
365
+ if (lgpi .lgrui0_name != null ) {
366
+ lgp .name = lgpi .lgrui0_name .toString ();
367
+ }
356
368
result .add (lgp );
357
369
}
358
370
return result .toArray (new Group [0 ]);
@@ -386,8 +398,9 @@ public static Group[] getUserGroups(String userName, String serverName) {
386
398
IntByReference entriesread = new IntByReference ();
387
399
IntByReference totalentries = new IntByReference ();
388
400
try {
389
- int rc = Netapi32 .INSTANCE .NetUserGetGroups (serverName , userName ,
390
- 0 , bufptr , LMCons .MAX_PREFERRED_LENGTH , entriesread , totalentries );
401
+ int rc = Netapi32 .INSTANCE .NetUserGetGroups (
402
+ serverName , userName ,
403
+ 0 , bufptr , LMCons .MAX_PREFERRED_LENGTH , entriesread , totalentries );
391
404
if (rc != LMErr .NERR_Success ) {
392
405
throw new Win32Exception (rc );
393
406
}
@@ -396,7 +409,9 @@ public static Group[] getUserGroups(String userName, String serverName) {
396
409
ArrayList <Group > result = new ArrayList <Group >();
397
410
for (GROUP_USERS_INFO_0 lgpi : lgroups ) {
398
411
Group lgp = new Group ();
399
- lgp .name = lgpi .grui0_name .toString ();
412
+ if (lgpi .grui0_name != null ) {
413
+ lgp .name = lgpi .grui0_name .toString ();
414
+ }
400
415
result .add (lgp );
401
416
}
402
417
return result .toArray (new Group [0 ]);
@@ -462,14 +477,24 @@ public static DomainController getDC() {
462
477
throw new Win32Exception (rc );
463
478
}
464
479
DomainController dc = new DomainController ();
465
- dc .address = pdci .dci .DomainControllerAddress .toString ();
480
+ if (pdci .dci .DomainControllerAddress != null ) {
481
+ dc .address = pdci .dci .DomainControllerAddress .toString ();
482
+ }
466
483
dc .addressType = pdci .dci .DomainControllerAddressType ;
467
- dc .clientSiteName = pdci .dci .ClientSiteName .toString ();
468
- dc .dnsForestName = pdci .dci .DnsForestName .toString ();
484
+ if (pdci .dci .ClientSiteName != null ) {
485
+ dc .clientSiteName = pdci .dci .ClientSiteName .toString ();
486
+ }
487
+ if (pdci .dci .DnsForestName != null ) {
488
+ dc .dnsForestName = pdci .dci .DnsForestName .toString ();
489
+ }
469
490
dc .domainGuid = pdci .dci .DomainGuid ;
470
- dc .domainName = pdci .dci .DomainName .toString ();
491
+ if (pdci .dci .DomainName != null ) {
492
+ dc .domainName = pdci .dci .DomainName .toString ();
493
+ }
471
494
dc .flags = pdci .dci .Flags ;
472
- dc .name = pdci .dci .DomainControllerName .toString ();
495
+ if (pdci .dci .DomainControllerName != null ) {
496
+ dc .name = pdci .dci .DomainControllerName .toString ();
497
+ }
473
498
rc = Netapi32 .INSTANCE .NetApiBufferFree (pdci .dci .getPointer ());
474
499
if (LMErr .NERR_Success != rc ) {
475
500
throw new Win32Exception (rc );
@@ -596,8 +621,8 @@ public static DomainTrust[] getDomainTrusts() {
596
621
public static DomainTrust [] getDomainTrusts (String serverName ) {
597
622
NativeLongByReference domainCount = new NativeLongByReference ();
598
623
PDS_DOMAIN_TRUSTS .ByReference domains = new PDS_DOMAIN_TRUSTS .ByReference ();
599
- int rc = Netapi32 .INSTANCE .DsEnumerateDomainTrusts (
600
- serverName , new NativeLong (DsGetDC .DS_DOMAIN_VALID_FLAGS ), domains , domainCount );
624
+ int rc = Netapi32 .INSTANCE .DsEnumerateDomainTrusts (serverName ,
625
+ new NativeLong (DsGetDC .DS_DOMAIN_VALID_FLAGS ), domains , domainCount );
601
626
if (W32Errors .NO_ERROR != rc ) {
602
627
throw new Win32Exception (rc );
603
628
}
@@ -606,13 +631,23 @@ public static DomainTrust[] getDomainTrusts(String serverName) {
606
631
ArrayList <DomainTrust > trusts = new ArrayList <DomainTrust >(domainCountValue );
607
632
for (DS_DOMAIN_TRUSTS trust : domains .getTrusts (domainCountValue )) {
608
633
DomainTrust t = new DomainTrust ();
609
- t .DnsDomainName = trust .DnsDomainName .toString ();
610
- t .NetbiosDomainName = trust .NetbiosDomainName .toString ();
634
+ if (trust .DnsDomainName != null ) {
635
+ t .DnsDomainName = trust .DnsDomainName .toString ();
636
+ }
637
+ if (trust .NetbiosDomainName != null ) {
638
+ t .NetbiosDomainName = trust .NetbiosDomainName .toString ();
639
+ }
611
640
t .DomainSid = trust .DomainSid ;
612
- t .DomainSidString = Advapi32Util .convertSidToStringSid (trust .DomainSid );
641
+ if (trust .DomainSid != null ) {
642
+ t .DomainSidString = Advapi32Util .convertSidToStringSid (trust .DomainSid );
643
+ }
613
644
t .DomainGuid = trust .DomainGuid ;
614
- t .DomainGuidString = Ole32Util .getStringFromGUID (trust .DomainGuid );
615
- t .flags = trust .Flags .intValue ();
645
+ if (trust .DomainGuid != null ) {
646
+ t .DomainGuidString = Ole32Util .getStringFromGUID (trust .DomainGuid );
647
+ }
648
+ if (trust .Flags != null ) {
649
+ t .flags = trust .Flags .intValue ();
650
+ }
616
651
trusts .add (t );
617
652
}
618
653
return trusts .toArray (new DomainTrust [0 ]);
@@ -636,11 +671,19 @@ public static UserInfo getUserInfo(String accountName, String domainName) {
636
671
if (rc == LMErr .NERR_Success ) {
637
672
USER_INFO_23 info_23 = new USER_INFO_23 (bufptr .getValue ());
638
673
UserInfo userInfo = new UserInfo ();
639
- userInfo .comment = info_23 .usri23_comment .toString ();
674
+ if (info_23 .usri23_comment != null ) {
675
+ userInfo .comment = info_23 .usri23_comment .toString ();
676
+ }
640
677
userInfo .flags = info_23 .usri23_flags ;
641
- userInfo .fullName = info_23 .usri23_full_name .toString ();
642
- userInfo .name = info_23 .usri23_name .toString ();
643
- userInfo .sidString = Advapi32Util .convertSidToStringSid (info_23 .usri23_user_sid );
678
+ if (info_23 .usri23_full_name != null ) {
679
+ userInfo .fullName = info_23 .usri23_full_name .toString ();
680
+ }
681
+ if (info_23 .usri23_name != null ) {
682
+ userInfo .name = info_23 .usri23_name .toString ();
683
+ }
684
+ if (info_23 .usri23_user_sid != null ) {
685
+ userInfo .sidString = Advapi32Util .convertSidToStringSid (info_23 .usri23_user_sid );
686
+ }
644
687
userInfo .sid = info_23 .usri23_user_sid ;
645
688
return userInfo ;
646
689
} else {
0 commit comments