summaryrefslogtreecommitdiff
path: root/vendor/thecodingmachine/safe/generated/ldap.php
blob: 0bfaaaf2bad5b687e7473f69fb9d26bef609f603 (plain)
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
<?php

namespace Safe;

use Safe\Exceptions\LdapException;

/**
 * Translate ISO-8859 characters to t61
 * characters.
 *
 * This function is useful if you have to talk to a legacy
 * LDAPv2 server.
 *
 * @param string $value The text to be translated.
 * @return string Return the t61 translation of
 * value.
 * @throws LdapException
 *
 */
function ldap_8859_to_t61(string $value): string
{
    error_clear_last();
    $result = \ldap_8859_to_t61($value);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
    return $result;
}


/**
 * Add entries in the LDAP directory.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param string $dn The distinguished name of an LDAP entity.
 * @param array $entry An array that specifies the information about the entry. The values in
 * the entries are indexed by individual attributes.
 * In case of multiple values for an attribute, they are indexed using
 * integers starting with 0.
 *
 *
 *
 * ]]>
 *
 *
 * @param array $controls Array of LDAP Controls to send with the request.
 * @throws LdapException
 *
 */
function ldap_add($ldap, string $dn, array $entry, array $controls = null): void
{
    error_clear_last();
    if ($controls !== null) {
        $result = \ldap_add($ldap, $dn, $entry, $controls);
    } else {
        $result = \ldap_add($ldap, $dn, $entry);
    }
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 * Binds to the LDAP directory with specified RDN and password.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param string|null $dn
 * @param string|null $password
 * @throws LdapException
 *
 */
function ldap_bind($ldap, ?string $dn = null, ?string $password = null): void
{
    error_clear_last();
    if ($password !== null) {
        $result = \ldap_bind($ldap, $dn, $password);
    } elseif ($dn !== null) {
        $result = \ldap_bind($ldap, $dn);
    } else {
        $result = \ldap_bind($ldap);
    }
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 * Retrieve the pagination information send by the server.
 *
 * @param resource $link An LDAP resource, returned by ldap_connect.
 * @param resource $result
 * @param string|null $cookie An opaque structure sent by the server.
 * @param int|null $estimated The estimated number of entries to retrieve.
 * @throws LdapException
 *
 */
function ldap_control_paged_result_response($link, $result, ?string &$cookie = null, ?int &$estimated = null): void
{
    error_clear_last();
    $result = \ldap_control_paged_result_response($link, $result, $cookie, $estimated);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 * Enable LDAP pagination by sending the pagination control (page size, cookie...).
 *
 * @param resource $link An LDAP resource, returned by ldap_connect.
 * @param int $pagesize The number of entries by page.
 * @param bool $iscritical Indicates whether the pagination is critical or not.
 * If true and if the server doesn't support pagination, the search
 * will return no result.
 * @param string $cookie An opaque structure sent by the server
 * (ldap_control_paged_result_response).
 * @throws LdapException
 *
 */
function ldap_control_paged_result($link, int $pagesize, bool $iscritical = false, string $cookie = ""): void
{
    error_clear_last();
    $result = \ldap_control_paged_result($link, $pagesize, $iscritical, $cookie);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 * Returns the number of entries stored in the result of previous search
 * operations.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param resource $result An LDAP\Result instance, returned by ldap_list or ldap_search.
 * @return int Returns number of entries in the result.
 * @throws LdapException
 *
 */
function ldap_count_entries($ldap, $result): int
{
    error_clear_last();
    $result = \ldap_count_entries($ldap, $result);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
    return $result;
}


/**
 * Deletes a particular entry in LDAP directory.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param string $dn The distinguished name of an LDAP entity.
 * @param array $controls Array of LDAP Controls to send with the request.
 * @throws LdapException
 *
 */
function ldap_delete($ldap, string $dn, array $controls = null): void
{
    error_clear_last();
    if ($controls !== null) {
        $result = \ldap_delete($ldap, $dn, $controls);
    } else {
        $result = \ldap_delete($ldap, $dn);
    }
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 * Turns the specified dn, into a more user-friendly
 * form, stripping off type names.
 *
 * @param string $dn The distinguished name of an LDAP entity.
 * @return string Returns the user friendly name.
 * @throws LdapException
 *
 */
function ldap_dn2ufn(string $dn): string
{
    error_clear_last();
    $result = \ldap_dn2ufn($dn);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
    return $result;
}


/**
 * Performs a PASSWD extended operation.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param string $user dn of the user to change the password of.
 * @param string $old_password The old password of this user. May be ommited depending of server configuration.
 * @param string $new_password The new password for this user. May be omitted or empty to have a generated password.
 * @param array $controls If provided, a password policy request control is send with the request and this is
 * filled with an array of LDAP Controls
 * returned with the request.
 * @return string|bool Returns the generated password if new_password is empty or omitted.
 * Otherwise returns TRUE on success.
 * @throws LdapException
 *
 */
function ldap_exop_passwd($ldap, string $user = "", string $old_password = "", string $new_password = "", array &$controls = null)
{
    error_clear_last();
    $result = \ldap_exop_passwd($ldap, $user, $old_password, $new_password, $controls);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
    return $result;
}


/**
 * Performs a WHOAMI extended operation and returns the data.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @return string|bool The data returned by the server.
 * @throws LdapException
 *
 */
function ldap_exop_whoami($ldap)
{
    error_clear_last();
    $result = \ldap_exop_whoami($ldap);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
    return $result;
}


/**
 * Performs an extended operation on the specified ldap with
 * request_oid the OID of the operation and
 * request_data the data.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param string $request_oid The extended operation request OID. You may use one of LDAP_EXOP_START_TLS, LDAP_EXOP_MODIFY_PASSWD, LDAP_EXOP_REFRESH, LDAP_EXOP_WHO_AM_I, LDAP_EXOP_TURN, or a string with the OID of the operation you want to send.
 * @param string $request_data The extended operation request data. May be NULL for some operations like LDAP_EXOP_WHO_AM_I, may also need to be BER encoded.
 * @param array|null $controls Array of LDAP Controls to send with the request.
 * @param string|null $response_data Will be filled with the extended operation response data if provided.
 * If not provided you may use ldap_parse_exop on the result object
 * later to get this data.
 * @param string|null $response_oid Will be filled with the response OID if provided, usually equal to the request OID.
 * @return resource|bool When used with response_data, returns TRUE on success.
 * When used without response_data, returns a result identifier.
 * @throws LdapException
 *
 */
function ldap_exop($ldap, string $request_oid, string $request_data = null, ?array $controls = null, ?string &$response_data = null, ?string &$response_oid = null)
{
    error_clear_last();
    if ($response_oid !== null) {
        $result = \ldap_exop($ldap, $request_oid, $request_data, $controls, $response_data, $response_oid);
    } elseif ($response_data !== null) {
        $result = \ldap_exop($ldap, $request_oid, $request_data, $controls, $response_data);
    } elseif ($controls !== null) {
        $result = \ldap_exop($ldap, $request_oid, $request_data, $controls);
    } elseif ($request_data !== null) {
        $result = \ldap_exop($ldap, $request_oid, $request_data);
    } else {
        $result = \ldap_exop($ldap, $request_oid);
    }
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
    return $result;
}


/**
 * Splits the DN returned by ldap_get_dn and breaks it
 * up into its component parts. Each part is known as Relative Distinguished
 * Name, or RDN.
 *
 * @param string $dn The distinguished name of an LDAP entity.
 * @param int $with_attrib Used to request if the RDNs are returned with only values or their
 * attributes as well.  To get RDNs with the attributes (i.e. in
 * attribute=value format) set with_attrib to 0
 * and to get only values set it to 1.
 * @return array Returns an array of all DN components.
 * The first element in the array has count key and
 * represents the number of returned values, next elements are numerically
 * indexed DN components.
 * @throws LdapException
 *
 */
function ldap_explode_dn(string $dn, int $with_attrib): array
{
    error_clear_last();
    $result = \ldap_explode_dn($dn, $with_attrib);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
    return $result;
}


/**
 * Gets the first attribute in the given entry. Remaining attributes are
 * retrieved by calling ldap_next_attribute successively.
 *
 * Similar to reading entries, attributes are also read one by one from a
 * particular entry.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param resource $entry An LDAP\ResultEntry instance.
 * @return string Returns the first attribute in the entry on success and FALSE on
 * error.
 * @throws LdapException
 *
 */
function ldap_first_attribute($ldap, $entry): string
{
    error_clear_last();
    $result = \ldap_first_attribute($ldap, $entry);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
    return $result;
}


/**
 * Returns the entry identifier for first entry in the result. This entry
 * identifier is then supplied to ldap_next_entry
 * routine to get successive entries from the result.
 *
 * Entries in the LDAP result are read sequentially using the
 * ldap_first_entry and
 * ldap_next_entry functions.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param resource $result An LDAP\Result instance, returned by ldap_list or ldap_search.
 * @return resource Returns an LDAP\ResultEntry instance.
 * @throws LdapException
 *
 */
function ldap_first_entry($ldap, $result)
{
    error_clear_last();
    $result = \ldap_first_entry($ldap, $result);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
    return $result;
}


/**
 * Frees up the memory allocated internally to store the result. All result
 * memory will be automatically freed when the script terminates.
 *
 * Typically all the memory allocated for the LDAP result gets freed at the
 * end of the script. In case the script is making successive searches which
 * return large result sets, ldap_free_result could be
 * called to keep the runtime memory usage by the script low.
 *
 * @param resource $result An LDAP\Result instance, returned by ldap_list or ldap_search.
 * @throws LdapException
 *
 */
function ldap_free_result($result): void
{
    error_clear_last();
    $result = \ldap_free_result($result);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 * Reads attributes and values from an entry in the search result.
 *
 * Having located a specific entry in the directory, you can find out what
 * information is held for that entry by using this call. You would use this
 * call for an application which "browses" directory entries and/or where you
 * do not know the structure of the directory entries. In many applications
 * you will be searching for a specific attribute such as an email address or
 * a surname, and won't care what other data is held.
 *
 *
 *
 *
 *
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param resource $entry An LDAP\ResultEntry instance.
 * @return array Returns a complete entry information in a multi-dimensional array
 * on success and FALSE on error.
 * @throws LdapException
 *
 */
function ldap_get_attributes($ldap, $entry): array
{
    error_clear_last();
    $result = \ldap_get_attributes($ldap, $entry);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
    return $result;
}


/**
 * Finds out the DN of an entry in the result.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param resource $entry An LDAP\ResultEntry instance.
 * @return string Returns the DN of the result entry and FALSE on error.
 * @throws LdapException
 *
 */
function ldap_get_dn($ldap, $entry): string
{
    error_clear_last();
    $result = \ldap_get_dn($ldap, $entry);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
    return $result;
}


/**
 * Reads multiple entries from the given result, and then reading the
 * attributes and multiple values.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param resource $result An LDAP\Result instance, returned by ldap_list or ldap_search.
 * @return array Returns a complete result information in a multi-dimensional array on
 * success.
 *
 * The structure of the array is as follows.
 * The attribute index is converted to lowercase. (Attributes are
 * case-insensitive for directory servers, but not when used as
 * array indices.)
 *
 *
 *
 *
 *
 * @throws LdapException
 *
 */
function ldap_get_entries($ldap, $result): array
{
    error_clear_last();
    $result = \ldap_get_entries($ldap, $result);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
    return $result;
}


/**
 * Sets value to the value of the specified option.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param int $option The parameter option can be one of:
 *
 *
 *
 *
 * Option
 * Type
 * since
 *
 *
 *
 *
 * LDAP_OPT_DEREF
 * int
 *
 *
 *
 * LDAP_OPT_SIZELIMIT
 * int
 *
 *
 *
 * LDAP_OPT_TIMELIMIT
 * int
 *
 *
 *
 * LDAP_OPT_NETWORK_TIMEOUT
 * int
 *
 *
 *
 * LDAP_OPT_PROTOCOL_VERSION
 * int
 *
 *
 *
 * LDAP_OPT_ERROR_NUMBER
 * int
 *
 *
 *
 * LDAP_OPT_DIAGNOSTIC_MESSAGE
 * int
 *
 *
 *
 * LDAP_OPT_REFERRALS
 * int
 *
 *
 *
 * LDAP_OPT_RESTART
 * int
 *
 *
 *
 * LDAP_OPT_HOST_NAME
 * string
 *
 *
 *
 * LDAP_OPT_ERROR_STRING
 * string
 *
 *
 *
 * LDAP_OPT_MATCHED_DN
 * string
 *
 *
 *
 * LDAP_OPT_SERVER_CONTROLS
 * array
 *
 *
 *
 * LDAP_OPT_CLIENT_CONTROLS
 * array
 *
 *
 *
 * LDAP_OPT_X_KEEPALIVE_IDLE
 * int
 * 7.1
 *
 *
 * LDAP_OPT_X_KEEPALIVE_PROBES
 * int
 * 7.1
 *
 *
 * LDAP_OPT_X_KEEPALIVE_INTERVAL
 * int
 * 7.1
 *
 *
 * LDAP_OPT_X_TLS_CACERTDIR
 * string
 * 7.1
 *
 *
 * LDAP_OPT_X_TLS_CACERTFILE
 * string
 * 7.1
 *
 *
 * LDAP_OPT_X_TLS_CERTFILE
 * string
 * 7.1
 *
 *
 * LDAP_OPT_X_TLS_CIPHER_SUITE
 * string
 * 7.1
 *
 *
 * LDAP_OPT_X_TLS_CRLCHECK
 * int
 * 7.1
 *
 *
 * LDAP_OPT_X_TLS_CRL_NONE
 * int
 * 7.1
 *
 *
 * LDAP_OPT_X_TLS_CRL_PEER
 * int
 * 7.1
 *
 *
 * LDAP_OPT_X_TLS_CRL_ALL
 * int
 * 7.1
 *
 *
 * LDAP_OPT_X_TLS_CRLFILE
 * string
 * 7.1
 *
 *
 * LDAP_OPT_X_TLS_DHFILE
 * string
 * 7.1
 *
 *
 * LDAP_OPT_X_TLS_KEYFILE
 * string
 * 7.1
 *
 *
 * LDAP_OPT_X_TLS_PACKAGE
 * string
 * 7.1
 *
 *
 * LDAP_OPT_X_TLS_PROTOCOL_MIN
 * int
 * 7.1
 *
 *
 * LDAP_OPT_X_TLS_RANDOM_FILE
 * string
 * 7.1
 *
 *
 * LDAP_OPT_X_TLS_REQUIRE_CERT
 * int
 *
 *
 *
 *
 *
 * @param mixed $value This will be set to the option value.
 * @throws LdapException
 *
 */
function ldap_get_option($ldap, int $option, &$value = null): void
{
    error_clear_last();
    $result = \ldap_get_option($ldap, $option, $value);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 * Reads all the values of the attribute in the entry in the result.
 *
 * This function is used exactly like ldap_get_values
 * except that it handles binary data and not string data.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param resource $entry An LDAP\ResultEntry instance.
 * @param string $attribute
 * @return array Returns an array of values for the attribute on success and FALSE on
 * error. Individual values are accessed by integer index in the array. The
 * first index is 0. The number of values can be found by indexing "count"
 * in the resultant array.
 * @throws LdapException
 *
 */
function ldap_get_values_len($ldap, $entry, string $attribute): array
{
    error_clear_last();
    $result = \ldap_get_values_len($ldap, $entry, $attribute);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
    return $result;
}


/**
 * Reads all the values of the attribute in the entry in the result.
 *
 * This call needs a entry,
 * so needs to be preceded by one of the ldap search calls and one
 * of the calls to get an individual entry.
 *
 * You application will either be hard coded to look for certain
 * attributes (such as "surname" or "mail") or you will have to use
 * the ldap_get_attributes call to work out
 * what attributes exist for a given entry.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param resource $entry An LDAP\ResultEntry instance.
 * @param string $attribute
 * @return array Returns an array of values for the attribute on success and FALSE on
 * error. The number of values can be found by indexing "count" in the
 * resultant array. Individual values are accessed by integer index in the
 * array.  The first index is 0.
 *
 * LDAP allows more than one entry for an attribute, so it can, for example,
 * store a number of email addresses for one person's directory entry all
 * labeled with the attribute "mail"
 *
 *
 * return_value["count"] = number of values for attribute
 * return_value[0] = first value of attribute
 * return_value[i] = ith value of attribute
 *
 *
 * @throws LdapException
 *
 */
function ldap_get_values($ldap, $entry, string $attribute): array
{
    error_clear_last();
    $result = \ldap_get_values($ldap, $entry, $attribute);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
    return $result;
}


/**
 * Adds one or more attribute values to the specified dn.
 * To add a whole new object see ldap_add function.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param string $dn The distinguished name of an LDAP entity.
 * @param array $entry An associative array listing the attirbute values to add. If an attribute was not existing yet it will be added. If an attribute is existing you can only add values to it if it supports multiple values.
 * @param array $controls Array of LDAP Controls to send with the request.
 * @throws LdapException
 *
 */
function ldap_mod_add($ldap, string $dn, array $entry, array $controls = null): void
{
    error_clear_last();
    if ($controls !== null) {
        $result = \ldap_mod_add($ldap, $dn, $entry, $controls);
    } else {
        $result = \ldap_mod_add($ldap, $dn, $entry);
    }
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 * Removes one or more attribute values from the specified dn.
 * Object deletions are done by the
 * ldap_delete function.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param string $dn The distinguished name of an LDAP entity.
 * @param array $entry
 * @param array $controls Array of LDAP Controls to send with the request.
 * @throws LdapException
 *
 */
function ldap_mod_del($ldap, string $dn, array $entry, array $controls = null): void
{
    error_clear_last();
    if ($controls !== null) {
        $result = \ldap_mod_del($ldap, $dn, $entry, $controls);
    } else {
        $result = \ldap_mod_del($ldap, $dn, $entry);
    }
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 * Replaces one or more attributes from the specified dn.
 * It may also add or remove attributes.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param string $dn The distinguished name of an LDAP entity.
 * @param array $entry An associative array listing the attributes to replace. Sending an empty array as value will remove the attribute, while sending an attribute not existing yet on this entry will add it.
 * @param array $controls Array of LDAP Controls to send with the request.
 * @throws LdapException
 *
 */
function ldap_mod_replace($ldap, string $dn, array $entry, array $controls = null): void
{
    error_clear_last();
    if ($controls !== null) {
        $result = \ldap_mod_replace($ldap, $dn, $entry, $controls);
    } else {
        $result = \ldap_mod_replace($ldap, $dn, $entry);
    }
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 * Modifies an existing entry in the LDAP directory. Allows detailed
 * specification of the modifications to perform.
 *
 * @param resource $ldap An LDAP resource, returned by ldap_connect.
 * @param string $dn The distinguished name of an LDAP entity.
 * @param array $modifications_info An array that specifies the modifications to make. Each entry in this
 * array is an associative array with two or three keys:
 * attrib maps to the name of the attribute to modify,
 * modtype maps to the type of modification to perform,
 * and (depending on the type of modification) values
 * maps to an array of attribute values relevant to the modification.
 *
 * Possible values for modtype include:
 *
 *
 * LDAP_MODIFY_BATCH_ADD
 *
 *
 * Each value specified through values is added (as
 * an additional value) to the attribute named by
 * attrib.
 *
 *
 *
 *
 * LDAP_MODIFY_BATCH_REMOVE
 *
 *
 * Each value specified through values is removed
 * from the attribute named by attrib. Any value of
 * the attribute not contained in the values array
 * will remain untouched.
 *
 *
 *
 *
 * LDAP_MODIFY_BATCH_REMOVE_ALL
 *
 *
 * All values are removed from the attribute named by
 * attrib. A values entry must
 * not be provided.
 *
 *
 *
 *
 * LDAP_MODIFY_BATCH_REPLACE
 *
 *
 * All current values of the attribute named by
 * attrib are replaced with the values specified
 * through values.
 *
 *
 *
 *
 *
 * Each value specified through values is added (as
 * an additional value) to the attribute named by
 * attrib.
 *
 * Each value specified through values is removed
 * from the attribute named by attrib. Any value of
 * the attribute not contained in the values array
 * will remain untouched.
 *
 * All values are removed from the attribute named by
 * attrib. A values entry must
 * not be provided.
 *
 * All current values of the attribute named by
 * attrib are replaced with the values specified
 * through values.
 *
 * Note that any value for attrib must be a string, any
 * value for values must be an array of strings, and
 * any value for modtype must be one of the
 * LDAP_MODIFY_BATCH_* constants listed above.
 * @param array $controls Each value specified through values is added (as
 * an additional value) to the attribute named by
 * attrib.
 * @throws LdapException
 *
 */
function ldap_modify_batch($ldap, string $dn, array $modifications_info, array $controls = null): void
{
    error_clear_last();
    if ($controls !== null) {
        $result = \ldap_modify_batch($ldap, $dn, $modifications_info, $controls);
    } else {
        $result = \ldap_modify_batch($ldap, $dn, $modifications_info);
    }
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 * Retrieves the attributes in an entry. The first call to
 * ldap_next_attribute is made with the
 * entry returned from
 * ldap_first_attribute.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param resource $entry An LDAP\ResultEntry instance.
 * @return string Returns the next attribute in an entry on success and FALSE on
 * error.
 * @throws LdapException
 *
 */
function ldap_next_attribute($ldap, $entry): string
{
    error_clear_last();
    $result = \ldap_next_attribute($ldap, $entry);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
    return $result;
}


/**
 * Parse LDAP extended operation data from result object result
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param resource $result An LDAP\Result instance, returned by ldap_list or ldap_search.
 * @param string|null $response_data Will be filled by the response data.
 * @param string|null $response_oid Will be filled by the response OID.
 * @throws LdapException
 *
 */
function ldap_parse_exop($ldap, $result, ?string &$response_data = null, ?string &$response_oid = null): void
{
    error_clear_last();
    $result = \ldap_parse_exop($ldap, $result, $response_data, $response_oid);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 * Parses an LDAP search result.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param resource $result An LDAP\Result instance, returned by ldap_list or ldap_search.
 * @param int|null $error_code A reference to a variable that will be set to the LDAP error code in
 * the result, or 0 if no error occurred.
 * @param string|null $matched_dn A reference to a variable that will be set to a matched DN if one was
 * recognised within the request, otherwise it will be set to NULL.
 * @param string|null $error_message A reference to a variable that will be set to the LDAP error message in
 * the result, or an empty string if no error occurred.
 * @param array|null $referrals A reference to a variable that will be set to an array set
 * to all of the referral strings in the result, or an empty array if no
 * referrals were returned.
 * @param array|null $controls An array of LDAP Controls which have been sent with the response.
 * @throws LdapException
 *
 */
function ldap_parse_result($ldap, $result, ?int &$error_code, ?string &$matched_dn = null, ?string &$error_message = null, ?array &$referrals = null, ?array &$controls = null): void
{
    error_clear_last();
    $result = \ldap_parse_result($ldap, $result, $error_code, $matched_dn, $error_message, $referrals, $controls);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 * The entry specified by dn is renamed/moved.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param string $dn The distinguished name of an LDAP entity.
 * @param string $new_rdn The new RDN.
 * @param string $new_parent The new parent/superior entry.
 * @param bool $delete_old_rdn If TRUE the old RDN value(s) is removed, else the old RDN value(s)
 * is retained as non-distinguished values of the entry.
 * @param array $controls Array of LDAP Controls to send with the request.
 * @throws LdapException
 *
 */
function ldap_rename($ldap, string $dn, string $new_rdn, string $new_parent, bool $delete_old_rdn, array $controls = null): void
{
    error_clear_last();
    if ($controls !== null) {
        $result = \ldap_rename($ldap, $dn, $new_rdn, $new_parent, $delete_old_rdn, $controls);
    } else {
        $result = \ldap_rename($ldap, $dn, $new_rdn, $new_parent, $delete_old_rdn);
    }
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 *
 *
 * @param resource $ldap
 * @param string $dn
 * @param string $password
 * @param string $mech
 * @param string $realm
 * @param string $authc_id
 * @param string $authz_id
 * @param string $props
 * @throws LdapException
 *
 */
function ldap_sasl_bind($ldap, string $dn = null, string $password = null, string $mech = null, string $realm = null, string $authc_id = null, string $authz_id = null, string $props = null): void
{
    error_clear_last();
    if ($props !== null) {
        $result = \ldap_sasl_bind($ldap, $dn, $password, $mech, $realm, $authc_id, $authz_id, $props);
    } elseif ($authz_id !== null) {
        $result = \ldap_sasl_bind($ldap, $dn, $password, $mech, $realm, $authc_id, $authz_id);
    } elseif ($authc_id !== null) {
        $result = \ldap_sasl_bind($ldap, $dn, $password, $mech, $realm, $authc_id);
    } elseif ($realm !== null) {
        $result = \ldap_sasl_bind($ldap, $dn, $password, $mech, $realm);
    } elseif ($mech !== null) {
        $result = \ldap_sasl_bind($ldap, $dn, $password, $mech);
    } elseif ($password !== null) {
        $result = \ldap_sasl_bind($ldap, $dn, $password);
    } elseif ($dn !== null) {
        $result = \ldap_sasl_bind($ldap, $dn);
    } else {
        $result = \ldap_sasl_bind($ldap);
    }
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 * Sets the value of the specified option to be value.
 *
 * @param resource|null $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @param int $option The parameter option can be one of:
 *
 *
 *
 *
 * Option
 * Type
 * Available since
 *
 *
 *
 *
 * LDAP_OPT_DEREF
 * int
 *
 *
 *
 * LDAP_OPT_SIZELIMIT
 * int
 *
 *
 *
 * LDAP_OPT_TIMELIMIT
 * int
 *
 *
 *
 * LDAP_OPT_NETWORK_TIMEOUT
 * int
 *
 *
 *
 * LDAP_OPT_PROTOCOL_VERSION
 * int
 *
 *
 *
 * LDAP_OPT_ERROR_NUMBER
 * int
 *
 *
 *
 * LDAP_OPT_REFERRALS
 * bool
 *
 *
 *
 * LDAP_OPT_RESTART
 * bool
 *
 *
 *
 * LDAP_OPT_HOST_NAME
 * string
 *
 *
 *
 * LDAP_OPT_ERROR_STRING
 * string
 *
 *
 *
 * LDAP_OPT_DIAGNOSTIC_MESSAGE
 * string
 *
 *
 *
 * LDAP_OPT_MATCHED_DN
 * string
 *
 *
 *
 * LDAP_OPT_SERVER_CONTROLS
 * array
 *
 *
 *
 * LDAP_OPT_CLIENT_CONTROLS
 * array
 *
 *
 *
 * LDAP_OPT_X_KEEPALIVE_IDLE
 * int
 * PHP 7.1.0
 *
 *
 * LDAP_OPT_X_KEEPALIVE_PROBES
 * int
 * PHP 7.1.0
 *
 *
 * LDAP_OPT_X_KEEPALIVE_INTERVAL
 * int
 * PHP 7.1.0
 *
 *
 * LDAP_OPT_X_TLS_CACERTDIR
 * string
 * PHP 7.1.0
 *
 *
 * LDAP_OPT_X_TLS_CACERTFILE
 * string
 * PHP 7.1.0
 *
 *
 * LDAP_OPT_X_TLS_CERTFILE
 * string
 * PHP 7.1.0
 *
 *
 * LDAP_OPT_X_TLS_CIPHER_SUITE
 * string
 * PHP 7.1.0
 *
 *
 * LDAP_OPT_X_TLS_CRLCHECK
 * int
 * PHP 7.1.0
 *
 *
 * LDAP_OPT_X_TLS_CRLFILE
 * string
 * PHP 7.1.0
 *
 *
 * LDAP_OPT_X_TLS_DHFILE
 * string
 * PHP 7.1.0
 *
 *
 * LDAP_OPT_X_TLS_KEYFILE
 * string
 * PHP 7.1.0
 *
 *
 * LDAP_OPT_X_TLS_PROTOCOL_MIN
 * int
 * PHP 7.1.0
 *
 *
 * LDAP_OPT_X_TLS_RANDOM_FILE
 * string
 * PHP 7.1.0
 *
 *
 * LDAP_OPT_X_TLS_REQUIRE_CERT
 * int
 * PHP 7.0.5
 *
 *
 *
 *
 *
 * LDAP_OPT_SERVER_CONTROLS and
 * LDAP_OPT_CLIENT_CONTROLS require a list of
 * controls, this means that the value must be an array of controls. A
 * control consists of an oid identifying the control,
 * an optional value, and an optional flag for
 * criticality. In PHP a control is given by an
 * array containing an element with the key oid
 * and string value, and two optional elements. The optional
 * elements are key value with string value
 * and key iscritical with boolean value.
 * iscritical defaults to FALSE
 * if not supplied. See draft-ietf-ldapext-ldap-c-api-xx.txt
 * for details. See also the second example below.
 * @param mixed $value The new value for the specified option.
 * @throws LdapException
 *
 */
function ldap_set_option($ldap, int $option, $value): void
{
    error_clear_last();
    $result = \ldap_set_option($ldap, $option, $value);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}


/**
 * Unbinds from the LDAP directory.
 *
 * @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
 * @throws LdapException
 *
 */
function ldap_unbind($ldap): void
{
    error_clear_last();
    $result = \ldap_unbind($ldap);
    if ($result === false) {
        throw LdapException::createFromPhpError();
    }
}