Skip to content

Commit 501dc90

Browse files
committed
Fix: #78 NPE platform.win32.Netapi32Util.getDomainTrusts.
1 parent b2c3c58 commit 501dc90

File tree

1 file changed

+76
-33
lines changed

1 file changed

+76
-33
lines changed

contrib/platform/src/com/sun/jna/platform/win32/Netapi32Util.java

+76-33
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,12 @@ public static LocalGroup[] getLocalGroups(String serverName) {
209209
ArrayList<LocalGroup> result = new ArrayList<LocalGroup>();
210210
for(LOCALGROUP_INFO_1 lgpi : groups) {
211211
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+
}
214218
result.add(lgp);
215219
}
216220
return result.toArray(new LocalGroup[0]);
@@ -254,8 +258,12 @@ public static Group[] getGlobalGroups(String serverName) {
254258
ArrayList<LocalGroup> result = new ArrayList<LocalGroup>();
255259
for(LMAccess.GROUP_INFO_1 lgpi : groups) {
256260
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+
}
259267
result.add(lgp);
260268
}
261269
return result.toArray(new LocalGroup[0]);
@@ -287,19 +295,21 @@ public static User[] getUsers(String serverName) {
287295
IntByReference entriesRead = new IntByReference();
288296
IntByReference totalEntries = new IntByReference();
289297
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);
293302
if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) {
294303
throw new Win32Exception(rc);
295304
}
296305
LMAccess.USER_INFO_1 user = new LMAccess.USER_INFO_1(bufptr.getValue());
297306
LMAccess.USER_INFO_1[] users = (LMAccess.USER_INFO_1[]) user.toArray(entriesRead.getValue());
298-
299307
ArrayList<User> result = new ArrayList<User>();
300308
for(LMAccess.USER_INFO_1 lu : users) {
301309
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+
}
303313
result.add(auser);
304314
}
305315
return result.toArray(new User[0]);
@@ -318,8 +328,7 @@ public static User[] getUsers(String serverName) {
318328
* @return Local groups.
319329
*/
320330
public static Group[] getCurrentUserLocalGroups() {
321-
return getUserLocalGroups(Secur32Util.getUserNameEx(
322-
EXTENDED_NAME_FORMAT.NameSamCompatible));
331+
return getUserLocalGroups(Secur32Util.getUserNameEx(EXTENDED_NAME_FORMAT.NameSamCompatible));
323332
}
324333

325334
/**
@@ -342,8 +351,9 @@ public static Group[] getUserLocalGroups(String userName, String serverName) {
342351
IntByReference entriesread = new IntByReference();
343352
IntByReference totalentries = new IntByReference();
344353
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);
347357
if (rc != LMErr.NERR_Success) {
348358
throw new Win32Exception(rc);
349359
}
@@ -352,7 +362,9 @@ public static Group[] getUserLocalGroups(String userName, String serverName) {
352362
ArrayList<Group> result = new ArrayList<Group>();
353363
for (LOCALGROUP_USERS_INFO_0 lgpi : lgroups) {
354364
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+
}
356368
result.add(lgp);
357369
}
358370
return result.toArray(new Group[0]);
@@ -386,8 +398,9 @@ public static Group[] getUserGroups(String userName, String serverName) {
386398
IntByReference entriesread = new IntByReference();
387399
IntByReference totalentries = new IntByReference();
388400
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);
391404
if (rc != LMErr.NERR_Success) {
392405
throw new Win32Exception(rc);
393406
}
@@ -396,7 +409,9 @@ public static Group[] getUserGroups(String userName, String serverName) {
396409
ArrayList<Group> result = new ArrayList<Group>();
397410
for (GROUP_USERS_INFO_0 lgpi : lgroups) {
398411
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+
}
400415
result.add(lgp);
401416
}
402417
return result.toArray(new Group[0]);
@@ -462,14 +477,24 @@ public static DomainController getDC() {
462477
throw new Win32Exception(rc);
463478
}
464479
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+
}
466483
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+
}
469490
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+
}
471494
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+
}
473498
rc = Netapi32.INSTANCE.NetApiBufferFree(pdci.dci.getPointer());
474499
if (LMErr.NERR_Success != rc) {
475500
throw new Win32Exception(rc);
@@ -596,8 +621,8 @@ public static DomainTrust[] getDomainTrusts() {
596621
public static DomainTrust[] getDomainTrusts(String serverName) {
597622
NativeLongByReference domainCount = new NativeLongByReference();
598623
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);
601626
if(W32Errors.NO_ERROR != rc) {
602627
throw new Win32Exception(rc);
603628
}
@@ -606,13 +631,23 @@ public static DomainTrust[] getDomainTrusts(String serverName) {
606631
ArrayList<DomainTrust> trusts = new ArrayList<DomainTrust>(domainCountValue);
607632
for(DS_DOMAIN_TRUSTS trust : domains.getTrusts(domainCountValue)) {
608633
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+
}
611640
t.DomainSid = trust.DomainSid;
612-
t.DomainSidString = Advapi32Util.convertSidToStringSid(trust.DomainSid);
641+
if (trust.DomainSid != null) {
642+
t.DomainSidString = Advapi32Util.convertSidToStringSid(trust.DomainSid);
643+
}
613644
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+
}
616651
trusts.add(t);
617652
}
618653
return trusts.toArray(new DomainTrust[0]);
@@ -636,11 +671,19 @@ public static UserInfo getUserInfo(String accountName, String domainName) {
636671
if (rc == LMErr.NERR_Success) {
637672
USER_INFO_23 info_23 = new USER_INFO_23(bufptr.getValue());
638673
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+
}
640677
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+
}
644687
userInfo.sid = info_23.usri23_user_sid;
645688
return userInfo;
646689
} else {

0 commit comments

Comments
 (0)