Skip to content

Commit

Permalink
Fixing Server Side Sort Encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
RockfordWei committed Jan 30, 2017
1 parent 65a9bad commit 3917f10
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions Sources/PerfectLDAP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public class LDAP {
public func string(str: String) -> berval {
guard let i = iconvR else {
return str.withCString { ptr -> berval in
return berval(bv_len: ber_len_t(str.utf8.count), bv_val: strdup(ptr))
return berval(bv_len: ber_len_t(str.utf8.count), bv_val: ber_strdup(ptr))
}//end str
}//end str
return str.withCString { ptr -> berval in
Expand Down Expand Up @@ -274,7 +274,7 @@ public class LDAP {
// simple authorization doesn't mean unsafe - ldaps:// will encode the data
case .SIMPLE:
// simple auth just use password and binddn to login
cred.bv_val = strdup(inf.password)
cred.bv_val = ber_strdup(inf.password)
cred.bv_len = strlen(cred.bv_val)
r = ldap_sasl_bind_s(self.ldap, inf.binddn, nil, &cred, nil, nil, nil)
ber_memfree(cred.bv_val)
Expand Down Expand Up @@ -327,7 +327,7 @@ public class LDAP {

// once
if dflt.isEmpty {
let str = strdup(dflt)
let str = ber_strdup(dflt)
interact.result = unsafeBitCast(str, to: UnsafeRawPointer.self)
interact.len = UInt32(dflt.utf8.count)
def.drop(garbage: str)
Expand Down Expand Up @@ -638,9 +638,9 @@ public class LDAP {

if !sortedBy.isEmpty {
var sortKeyList = UnsafeMutablePointer<UnsafeMutablePointer<LDAPSortKey>?>(bitPattern: 0)
let sortString = strdup(sortedBy)
let sortString = ber_strdup(sortedBy)
var r = ldap_create_sort_keylist(&sortKeyList, sortString)
free(sortString)
ber_memfree(sortString)
if r != 0 {
throw Exception.message(LDAP.error(r))
}//end if
Expand Down Expand Up @@ -711,7 +711,7 @@ public class LDAP {
internal func modAlloc(method: Int32, key: String, values: [String]) -> LDAPMod {
let pValues = values.map { self.string(str: $0) }
let pointers = pValues.asUnsafeNullTerminatedPointers()
return LDAPMod(mod_op: method, mod_type: strdup(key), mod_vals: mod_vals_u(modv_bvals: pointers))
return LDAPMod(mod_op: method, mod_type: ber_strdup(key), mod_vals: mod_vals_u(modv_bvals: pointers))
}//end modAlloc

/// add an attribute to a DN
Expand Down
4 changes: 2 additions & 2 deletions Sources/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public func withCArrayOfString<R>(array: [String] = [], _ body: (UnsafeMutablePo
attr.append(nil)

// duplicate again and turn it into an array of pointers
var parr = attr.map { $0 == nil ? nil : strdup($0!) }
var parr = attr.map { $0 == nil ? nil : ber_strdup($0!) }

// perform the operation
let r = try parr.withUnsafeMutableBufferPointer { try body ($0.baseAddress) }

// release allocated string pointers.
for p in parr { free(UnsafeMutablePointer(mutating: p)) }
for p in parr { ber_memfree(UnsafeMutablePointer(mutating: p)) }

return r
}//end withCArrayOfString
Expand Down
4 changes: 2 additions & 2 deletions Tests/PerfectLDAPTests/PerfectLDAPTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ class PerfectLDAPTests: XCTestCase {
do {
let ldap = try LDAP(url: testURL, loginData:cred, codePage: testCPG)
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
let sort = LDAP.sortingString(sortedBy: [("displayName", .DSC), ("initials", .ASC)])
let sort = LDAP.sortingString(sortedBy: [("description", .ASC)])
print(sort)
let res = try ldap.search(base:testBAS,scope:.SUBTREE, attributes: ["displayName", "initials"], sortedBy: sort)
let res = try ldap.search(base:testBAS,scope:.SUBTREE, attributes: ["displayName", "description"], sortedBy: sort)
print(res)
}catch(let err) {
XCTFail("server control: \(err)")
Expand Down

0 comments on commit 3917f10

Please sign in to comment.