1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(clippy::unreadable_literal)]
#![allow(clippy::redundant_static_lifetimes)]

use std::env;

use std::os::raw::{c_char};

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

#[cfg(feature = "deprecated")]
mod deprecated {
	use crate::*;
	use std::os::raw::{c_int, c_void};

	// Functions (might be deprecated)
	extern "C" {
		#[deprecated(note = "Use `ldap_control_create` instead")]
		pub fn ldap_create_control(
			requestOID: *const c_char,
			ber: *mut BerElement,
			iscritical: c_int,
			ctrlp: *mut *mut LDAPControl,
		) -> c_int;
		#[deprecated(note = "Use `ldap_control_find` instead")]
		pub fn ldap_find_control(oid: *const c_char, ctrls: *mut *mut LDAPControl) -> c_int;

		#[deprecated(note = "Use `ldap_abandon_ext` instead")]
		pub fn ldap_abandon(ld: *mut LDAP, msg_id: c_int) -> c_int;

		#[deprecated(note = "Use `ldap_add_ext` instead")]
		pub fn ldap_add(ld: *mut LDAP, dn: *const c_char, attrs: *mut *mut LDAPMod) -> c_int;
		#[deprecated(note = "USE `ldap_add_ext_s` instead")]
		pub fn ldap_add_s(ld: *mut LDAP, dn: *const c_char, attrs: *mut *mut LDAPMod) -> c_int;

		#[deprecated(note = "Use `ldap_sasl_bind` instead")]
		pub fn ldap_bind(
			ld: *mut LDAP,
			who: *const c_char,
			passwd: *const c_char,
			authmethod: c_int,
		) -> c_int;
		#[deprecated(note = "Use `ldap_sasl_bind_s` instead")]
		pub fn ldap_bind_s(
			ld: *mut LDAP,
			who: *const c_char,
			passwd: *const c_char,
			authmethod: c_int,
		) -> c_int;
		#[deprecated(note = "Use `ldap_sasl_bind` instead")]
		pub fn ldap_simple_bind(ld: *mut LDAP, who: *const c_char, passwd: *const c_char) -> c_int;
		#[deprecated(note = "Use `ldap_sasl_bind_s` instead")]
		pub fn ldap_simple_bind_s(ld: *mut LDAP, who: *const c_char, passwd: *const c_char) -> c_int;

		#[deprecated(note = "Use `ldap_compare_ext` instead")]
		pub fn ldap_compare(
			ld: *mut LDAP,
			dn: *const c_char,
			attr: *const c_char,
			value: *const c_char,
		) -> c_int;
		#[deprecated(note = "Use `ldap_compare_ext_s` instead")]
		pub fn ldap_compare_s(
			ld: *mut LDAP,
			dn: *const c_char,
			attr: *const c_char,
			value: *const c_char,
		) -> c_int;

		#[deprecated(note = "Use `ldap_delete_ext` instead")]
		pub fn ldap_delete(ld: *mut LDAP, dn: *const c_char) -> c_int;
		#[deprecated(note = "Use `ldap_delete_ext_s` instead")]
		pub fn ldap_delete_s(ld: *mut LDAP, dn: *const c_char) -> c_int;

		#[deprecated(note = "Use `ldap_parse_result` instead")]
		pub fn ldap_result2error(ld: *mut LDAP, r: *mut LDAPMessage, freeit: c_int) -> c_int;
		#[deprecated(note = "Use `ldap_err2string` instead")]
		pub fn ldap_perror(ld: *mut LDAP, s: *const c_char) -> c_void;

		#[deprecated(note = "Use `ldap_modify_ext` instead")]
		pub fn ldap_modify(ld: *mut LDAP, dn: *const c_char, mods: *mut *mut LDAPMod) -> c_int;
		#[deprecated(note = "Use `ldap_modify_ext_s` instead")]
		pub fn ldap_modify_s(ld: *mut LDAP, dn: *const c_char, mods: *mut *mut LDAPMod) -> c_int;

		#[deprecated(note = "Use `ldap_rename` instead")]
		pub fn ldap_rename2(
			ld: *mut LDAP,
			dn: *const c_char,
			newrdn: *const c_char,
			new_superior: *const c_char,
			deleteoldrdn: c_int,
		) -> c_int;
		#[deprecated(note = "Use `ldap_rename_s` instead")]
		pub fn ldap_rename2_s(
			ld: *mut LDAP,
			dn: *const c_char,
			newrdn: *const c_char,
			newSuperior: *const c_char,
			deleteoldrdn: c_int,
		) -> c_int;
		#[deprecated(note = "Use `ldap_rename` instead")]
		pub fn ldap_modrdn(ld: *mut LDAP, dn: *const c_char, newrdn: *const c_char) -> c_int;
		#[deprecated(note = "Use `ldap_rename_s` instead")]
		pub fn ldap_modrdn_s(ld: *mut LDAP, dn: *const c_char, newrdn: *const c_char) -> c_int;
		#[deprecated(note = "Use `ldap_rename` instead")]
		pub fn ldap_modrdn2(
			ld: *mut LDAP,
			dn: *const c_char,
			newrdn: *const c_char,
			deleteoldrdn: c_int,
		) -> c_int;
		#[deprecated(note = "Use `ldap_rename_s` instead")]
		pub fn ldap_modrdn2_s(
			ld: *mut LDAP,
			dn: *const c_char,
			newrdn: *const c_char,
			deleteoldrdn: c_int,
		) -> c_int;

		#[deprecated(note = "Use `ldap_initialize`")]
		pub fn ldap_init(host: *const c_char, port: c_int) -> *mut LDAP;
		#[deprecated(note = "Use `ldap_initialize`")]
		pub fn ldap_open(host: *const c_char, port: c_int) -> *mut LDAP;

		#[deprecated(note = "Use `ldap_get_values_len` instead")]
		pub fn ldap_get_values(
			ld: *mut LDAP,
			entry: *mut LDAPMessage,
			target: *const c_char,
		) -> *mut *mut c_char;
		#[deprecated(note = "Use `ldap_count_values_len` instead")]
		pub fn ldap_count_values(vals: *mut *mut c_char) -> c_int;

		#[deprecated(note = "Use `ldap-value_free_len` instead")]
		pub fn ldap_value_free(vals: *mut *mut c_char);

		#[deprecated(note = "Use `ldap_search_ext` instead")]
		pub fn ldap_search(
			ld: *mut LDAP,
			base: *const c_char,
			scope: c_int,
			filter: *const c_char,
			attrs: *mut *mut c_char,
			attrsonly: c_int,
		) -> c_int;
		#[deprecated(note = "Use `ldap_search_ext_s` instead")]
		pub fn ldap_search_s(
			ld: *mut LDAP,
			base: *const c_char,
			scope: c_int,
			filter: *const c_char,
			attrs: *mut *mut c_char,
			attrsonly: c_int,
			res: *mut *mut LDAPMessage,
		) -> c_int;
		#[deprecated(note = "Use `ldap_search_ext_s` instead")]
		pub fn ldap_search_st(
			ld: *mut LDAP,
			base: *const c_char,
			scope: c_int,
			filter: *const c_char,
			attrs: *mut *mut c_char,
			attrsonly: c_int,
			timeout: *const timeval,
			res: *mut *mut LDAPMessage,
		) -> c_int;

		#[deprecated(note = "Use `ldap_unbind_ext` instead")]
		pub fn ldap_unbind(ld: *mut LDAP) -> c_int;
		#[deprecated(note = "Use `ldap_unbind_ext_s` instead")]
		pub fn ldap_unbind_s(ld: *mut LDAP) -> c_int;

		#[deprecated(note = "Use `ldap_parse_pageresponse_control` instead")]
		pub fn ldap_parse_page_control(ld: *mut LDAP, ctrls: *mut *mut LDAPControl, count: *mut ber_int_t, cookie: *mut *mut berval);
	}

	#[deprecated]
	pub type LDAP_SORT_AD_CMP_PROC = extern "C" fn(left: *const c_char, right: *const c_char) -> c_int;
	#[deprecated]
	pub type LDAP_SORT_AV_CMP_PROC = extern "C" fn(left: *const c_void, right: *const c_void) -> c_int;

	extern "C" {
		#[allow(deprecated)]
		#[deprecated]
		pub fn ldap_sort_entries(ld: *mut LDAP, vals: *mut *mut c_char, cmp: *mut LDAP_SORT_AV_CMP_PROC) -> c_int;
	}
}

#[cfg(feature = "deprecated")]
pub use crate::deprecated::*;

// Constants and methods BINDGEN does not seem to care about

pub const LDAP_TAG_SYNC_NEW_COOKIE: ber_tag_t = 0x80;
pub const LDAP_TAG_SYNC_REFRESH_DELETE: ber_tag_t = 0xa1;
pub const LDAP_TAG_SYNC_REFRESH_PRESENT: ber_tag_t = 0xa2;
pub const LDAP_TAG_SYNC_ID_SET: ber_tag_t = 0xa3;

pub const LDAP_TAG_SYNC_COOKIE: ber_tag_t = 0x04;
pub const LDAP_TAG_REFRESHDELETES: ber_tag_t = 0x01;
pub const LDAP_TAG_REFERESHDONE: ber_tag_t = 0x01;
pub const LDAP_TAG_RELOAD_HINT: ber_tag_t = 0x01;

pub const LDAP_TAG_EXOP_MODIFY_PASSWD_ID: ber_tag_t = 0x80;
pub const LDAP_TAG_EXOP_MODIFY_PASSWD_OLD: ber_tag_t = 0x81;
pub const LDAP_TAG_EXOP_MODIFY_PASSWD_NEW: ber_tag_t = 0x82;
pub const LDAP_TAG_EXOP_MODIFY_PASSWD_GEN: ber_tag_t = 0x80;

pub const LDAP_TAG_EXOP_REFRESH_REQ_DN: ber_tag_t = 0x80;
pub const LDAP_TAG_EXOP_REFRESH_REQ_TTL: ber_tag_t = 0x81;
pub const LDAP_TAG_EXOP_REFRESH_RES_TTL: ber_tag_t = 0x81;

pub const LDAP_TAG_MESSAGE: ber_tag_t = 0x30;
pub const LDAP_TAG_MSGID: ber_tag_t = 0x02;
pub const LDAP_TAG_LDAPDN: ber_tag_t = 0x04;
pub const LDAP_TAG_LDAPCRED: ber_tag_t = 0x04;

pub const LDAP_TAG_CONTROLS: ber_tag_t = 0xa0;
pub const LDAP_TAG_REFERRAL: ber_tag_t = 0xa3;

pub const LDAP_TAG_NEWSUPERIOR: ber_tag_t = 0x80;

pub const LDAP_TAG_EXOP_REQ_OID: ber_tag_t = 0x80;
pub const LDAP_TAG_EXOP_REQ_VALUE: ber_tag_t = 0x81;
pub const LDAP_TAG_EXOP_RES_OID: ber_tag_t = 0x8a;
pub const LDAP_TAG_EXOP_RES_VALUE: ber_tag_t = 0x8b;

pub const LDAP_TAG_IM_RES_OID: ber_tag_t = 0x80;
pub const LDAP_TAG_IM_RES_VALUE: ber_tag_t = 0x81;

pub const LDAP_TAG_SASL_RES_CREDS: ber_tag_t = 0x87;

// LDAP Request Message
pub const LDAP_REQ_BIND: ber_tag_t = 0x60;
pub const LDAP_REQ_UNBIND: ber_tag_t = 0x42;
pub const LDAP_REQ_SEARCH: ber_tag_t = 0x63;
pub const LDAP_REQ_MODIFY: ber_tag_t = 0x66;
pub const LDAP_REQ_ADD: ber_tag_t = 0x68;
pub const LDAP_REQ_DELETE: ber_tag_t = 0x4a;
pub const LDAP_REQ_MODDN: ber_tag_t = 0x6c;
pub const LDAP_REQ_MODRDN: ber_tag_t = LDAP_REQ_MODDN;
pub const LDAP_REQ_RENAME: ber_tag_t = LDAP_REQ_MODDN;
pub const LDAP_REQ_COMPARE: ber_tag_t = 0x6e;
pub const LDAP_REQ_ABANDON: ber_tag_t = 0x50;
pub const LDAP_REQ_EXTENDED: ber_tag_t = 0x77;

// LDAP Response Messages
pub const LDAP_RES_BIND: ber_tag_t = 0x61;
pub const LDAP_RES_SEARCH_ENTRY: ber_tag_t = 0x64;
pub const LDAP_RES_SEARCH_REFERENCE: ber_tag_t = 0x73;
pub const LDAP_RES_SEARCH_RESULT: ber_tag_t = 0x65;
pub const LDAP_RES_MODIFY: ber_tag_t = 0x67;
pub const LDAP_RES_ADD: ber_tag_t = 0x69;
pub const LDAP_RES_DELETE: ber_tag_t = 0x6b;
pub const LDAP_RES_MODDN: ber_tag_t = 0x6d;
pub const LDAP_RES_MODRDN: ber_tag_t = LDAP_RES_MODDN;
pub const LDAP_RES_RENAME: ber_tag_t = LDAP_RES_MODDN;
pub const LDAP_RES_COMPARE: ber_tag_t = 0x6f;
pub const LDAP_RES_EXTENDED: ber_tag_t = 0x78;
pub const LDAP_RES_INTERMEDIATE: ber_tag_t = 0x79;

// sasl methods
pub const LDAP_SASL_SIMPLE: *const c_char = std::ptr::null();

// authentication methods available
pub const LDAP_AUTH_NONE: ber_tag_t = 0x00;
pub const LDAP_AUTH_SIMPLE: ber_tag_t = 0x80;
pub const LDAP_AUTH_SASL: ber_tag_t = 0xa3;
pub const LDAP_AUTH_KRBV4: ber_tag_t = 0xff;
pub const LDAP_AUTH_KRBV41: ber_tag_t = 0x81;
pub const LDAP_AUTH_KRBV42: ber_tag_t = 0x82;

/// Used by the Windows API but not used on the wire
pub const LDAP_AUTH_NEGOTIATE: ber_tag_t = 0x04FF;

// Filter types
pub const LDAP_FILTER_AND: ber_tag_t = 0xa0;
pub const LDAP_FILTER_OR: ber_tag_t = 0xa1;
pub const LADP_FILTER_NOT: ber_tag_t = 0xa2;
pub const LDAP_FILTER_EQUALITY: ber_tag_t = 0xa3;
pub const LDAP_FILTER_SUBSTRINGS: ber_tag_t = 0xa4;
pub const LDAP_FILTER_GE: ber_tag_t = 0xa5;
pub const LDAP_FILTER_LE: ber_tag_t = 0xa6;
pub const LDAP_FILTER_PRESENT: ber_tag_t = 0x87;
pub const LDAP_FILTER_APPROX: ber_tag_t = 0xa8;
pub const LDAP_FILTER_EXT: ber_tag_t = 0xa9;

// Extended filter component types
pub const LDAP_FILTER_EXT_OID: ber_tag_t = 0x81;
pub const LDAP_FILTER_EXT_TYPE: ber_tag_t = 0x82;
pub const LDAP_FILTER_EXT_VALUE: ber_tag_t = 0x83;
pub const LDAP_FILTER_EXT_DNATTRS: ber_tag_t = 0x84;

// Substring filter component types
pub const LDAP_SUBSTRING_INITIAL: ber_tag_t = 0x80;
pub const LDAP_SUBSTRING_ANY: ber_tag_t = 0x81;
pub const LDAP_SUBSTRING_FINAL: ber_tag_t = 0x82;

// Search scopes
pub const LDAP_SCOPE_BASE: ber_int_t = 0x0000;
pub const LDAP_SCOPE_BASEOBJECT: ber_int_t = LDAP_SCOPE_BASE;
pub const LDAP_SCOPE_ONELEVEL: ber_int_t = 0x0001;
pub const LDAP_SCOPE_ONE: ber_int_t = LDAP_SCOPE_ONELEVEL;
pub const LDAP_SCOPE_SUBTREE: ber_int_t = 0x0002;
pub const LDAP_SCOPE_SUB: ber_int_t = LDAP_SCOPE_SUBTREE;
pub const LDAP_SCOPE_SUBORDINATE: ber_int_t = 0x0003; // OpenLDAP Extension
pub const LDAP_SCOPE_CHILDREN: ber_int_t = LDAP_SCOPE_SUBORDINATE;
pub const LDAP_SCOPE_DEFAULT: ber_int_t = -1; // OpenLDAP Extension