summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Boreham <dboreham@redhat.com>2005-05-04 23:53:19 +0000
committerDavid Boreham <dboreham@redhat.com>2005-05-04 23:53:19 +0000
commit00672ce8af7c3af0e2120a97da09f1f64a18faf3 (patch)
tree1b972df62ef3c00103a429fb4fbb7133fb65ef6b
parentb07e0183072bc11fe48248823b1e9ca18e9105ef (diff)
downloadds-00672ce8af7c3af0e2120a97da09f1f64a18faf3.tar.gz
ds-00672ce8af7c3af0e2120a97da09f1f64a18faf3.tar.xz
ds-00672ce8af7c3af0e2120a97da09f1f64a18faf3.zip
Fix various bad memory free bugs
-rw-r--r--ldap/servers/ntds/netman/Makefile4
-rw-r--r--ldap/servers/ntds/netman/netman.cpp63
2 files changed, 47 insertions, 20 deletions
diff --git a/ldap/servers/ntds/netman/Makefile b/ldap/servers/ntds/netman/Makefile
index 2ce69421..e8086269 100644
--- a/ldap/servers/ntds/netman/Makefile
+++ b/ldap/servers/ntds/netman/Makefile
@@ -76,10 +76,10 @@ $(JAVA_DEST_DIR)/ntds/jnetman.jar: $(OBJDEST)/jnetman_wrap.cxx
$(OBJDEST)/jnetman.dll: $(OBJDEST)/netman.obj $(OBJDEST)/jnetman_wrap.obj
$(LINK_DLL) /out:$(OBJDEST)/jnetman.dll $(EXTRA_LIBS) netapi32.lib $(OBJDEST)/netman.obj $(OBJDEST)/jnetman_wrap.obj
-$(OBJDEST)/netman.obj:
+$(OBJDEST)/netman.obj: netman.cpp netman.h
$(CC) -c netman.cpp $(CFLAGS) $(MCC_INCLUDE) -Fo$(OBJDEST)/ $(CBSCFLAGS)
-$(OBJDEST)/jnetman_wrap.obj:
+$(OBJDEST)/jnetman_wrap.obj: $(OBJDEST)/jnetman_wrap.cxx
$(CC) -c $(OBJDEST)/jnetman_wrap.cxx $(CFLAGS) $(MCC_INCLUDE) -Fo$(OBJDEST)/ $(CBSCFLAGS) /I$(JAVA_HOME)/include /I$(JAVA_HOME)/include/win32 /I.
veryclean: clean
diff --git a/ldap/servers/ntds/netman/netman.cpp b/ldap/servers/ntds/netman/netman.cpp
index 885c3da7..5d9447b9 100644
--- a/ldap/servers/ntds/netman/netman.cpp
+++ b/ldap/servers/ntds/netman/netman.cpp
@@ -71,36 +71,36 @@ unsigned short* UTF8ToUTF16(char* inString)
}
// ****************************************************************
-// SIDToHexStr
+// BinToHexStr
// ****************************************************************
-int SIDToHexStr(char* sid, unsigned long sidLen, char** hexStr)
+int BinToHexStr(char* bin, unsigned long binLen, char** hexStr)
{
- int hexStrLen = sidLen * 2 + 1;
+ int hexStrLen = binLen * 2 + 1;
*hexStr = (char*)calloc(hexStrLen, sizeof(char));
- for(unsigned long i = 0; i < sidLen; i++)
+ for(unsigned long i = 0; i < binLen; i++)
{
- sprintf(&(*hexStr)[i * 2], "%02X", (unsigned char)sid[i]);
+ sprintf(&(*hexStr)[i * 2], "%02X", (unsigned char)bin[i]);
}
return 0;
}
// ****************************************************************
-// HexStrToSID
+// HexStrToBin
// ****************************************************************
-int HexStrToSID(char* hexStr, char** sid, unsigned long* sidLen)
+int HexStrToBin(char* hexStr, char** bin, unsigned long* binLen)
{
int temp;
- *sidLen = strlen(hexStr) / 2;
+ *binLen = strlen(hexStr) / 2;
- *sid = (char*)malloc(*sidLen);
+ *bin = (char*)malloc(*binLen);
- for(unsigned long i = 0; i < *sidLen; i++)
+ for(unsigned long i = 0; i < *binLen; i++)
{
sscanf(&hexStr[i * 2], "%02X", &temp);
- (*sid)[i] = (unsigned char)temp;
+ (*bin)[i] = (unsigned char)temp;
}
return 0;
@@ -200,7 +200,7 @@ int GetSIDHexStrByAccountName(char* accountName, char** sidHexStr)
}
- SIDToHexStr(sid, sidLen, sidHexStr);
+ BinToHexStr(sid, sidLen, sidHexStr);
return result;
}
@@ -219,7 +219,7 @@ int GetAccountNameBySIDHexStr(char* sidHexStr, char** accountName)
unsigned long accountNameLen = 0;
- HexStrToSID(sidHexStr, &sid, &sidLen);
+ HexStrToBin(sidHexStr, &sid, &sidLen);
if(LookupAccountSid(NULL, sid, NULL, &accountNameLen, NULL, &domainLen, &testType) == 0)
{
@@ -292,7 +292,7 @@ void NTUser::NewUser(char* username)
userInfo = NULL;
}
- userInfo = (USER_INFO_3*)malloc(sizeof(USER_INFO_3));
+ NetApiBufferAllocate(sizeof(USER_INFO_3),(LPVOID*)&userInfo);
memset(userInfo, 0, sizeof(USER_INFO_3));
userInfo->usri3_name = UTF8ToUTF16(username);
@@ -746,7 +746,7 @@ char* NTUser::GetLogonHours()
if(userInfo != NULL)
{
- result = (char*)userInfo->usri3_logon_hours;
+ BinToHexStr((char*)userInfo->usri3_logon_hours, 21, &result);
}
return result;
@@ -758,10 +758,13 @@ char* NTUser::GetLogonHours()
int NTUser::SetLogonHours(char* logonHours)
{
int result = 0;
+ char* binValue;
+ unsigned long binLen = 0;
if(userInfo != NULL)
{
- userInfo->usri3_logon_hours = (unsigned char*)logonHours;
+ HexStrToBin(logonHours, &binValue, &binLen);
+ userInfo->usri3_logon_hours = (unsigned char*)binValue;
}
else
{
@@ -1215,6 +1218,8 @@ char* NTUser::NextLocalGroupName()
// ****************************************************************
NTUserList::NTUserList()
{
+ entriesRead = 0;
+ totalEntries = 0;
bufptr = NULL;
currentEntry = 0;
resumeHandle = 0;
@@ -1287,6 +1292,10 @@ char* NTUserList::nextUsername()
NTGroup::NTGroup()
{
groupInfo = NULL;
+ usersInfo = NULL;
+ currentUserEntry = 0;
+ userEntriesRead = 0;
+ userEntriesTotal = 0;
}
// ****************************************************************
@@ -1299,6 +1308,11 @@ NTGroup::~NTGroup()
NetApiBufferFree(groupInfo);
groupInfo = NULL;
}
+ if(usersInfo != NULL)
+ {
+ NetApiBufferFree(usersInfo);
+ usersInfo = NULL;
+ }
}
// ****************************************************************
@@ -1312,7 +1326,7 @@ void NTGroup::NewGroup(char* groupName)
groupInfo = NULL;
}
- groupInfo = (GROUP_INFO_2*)malloc(sizeof(GROUP_INFO_2));
+ NetApiBufferAllocate(sizeof(GROUP_INFO_2),(LPVOID*)&groupInfo);
memset(groupInfo, 0, sizeof(GROUP_INFO_2));
groupInfo->grpi2_name = UTF8ToUTF16(groupName);
}
@@ -1576,6 +1590,8 @@ char* NTGroup::NextUserName()
// ****************************************************************
NTGroupList::NTGroupList()
{
+ entriesRead = 0;
+ totalEntries = 0;
bufptr = NULL;
currentEntry = 0;
resumeHandle = 0;
@@ -1648,6 +1664,10 @@ char* NTGroupList::nextGroupName()
NTLocalGroup::NTLocalGroup()
{
localGroupInfo = NULL;
+ usersInfo = NULL;
+ currentUserEntry = 0;
+ userEntriesRead = 0;
+ userEntriesTotal = 0;
}
// ****************************************************************
@@ -1660,6 +1680,11 @@ NTLocalGroup::~NTLocalGroup()
NetApiBufferFree(localGroupInfo);
localGroupInfo = NULL;
}
+ if(usersInfo != NULL)
+ {
+ NetApiBufferFree(usersInfo);
+ usersInfo = NULL;
+ }
}
// ****************************************************************
@@ -1673,7 +1698,7 @@ void NTLocalGroup::NewLocalGroup(char* localGroupName)
localGroupInfo = NULL;
}
- localGroupInfo = (LOCALGROUP_INFO_1*)malloc(sizeof(LOCALGROUP_INFO_1));
+ NetApiBufferAllocate(sizeof(LOCALGROUP_INFO_1),(LPVOID*)&localGroupInfo);
memset(localGroupInfo, 0, sizeof(LOCALGROUP_INFO_1));
localGroupInfo->lgrpi1_name = UTF8ToUTF16(localGroupName);
}
@@ -1947,6 +1972,8 @@ char* NTLocalGroup::NextUserName()
// ****************************************************************
NTLocalGroupList::NTLocalGroupList()
{
+ entriesRead = 0;
+ totalEntries = 0;
bufptr = NULL;
currentEntry = 0;
resumeHandle = 0;