1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * Copyright (c) 2001 by Sun Microsystems, Inc.
3*7c478bd9Sstevel@tonic-gate * All rights reserved.
4*7c478bd9Sstevel@tonic-gate */
5*7c478bd9Sstevel@tonic-gate
6*7c478bd9Sstevel@tonic-gate #include <stdio.h>
7*7c478bd9Sstevel@tonic-gate #include <string.h>
8*7c478bd9Sstevel@tonic-gate
9*7c478bd9Sstevel@tonic-gate #ifdef MACOS
10*7c478bd9Sstevel@tonic-gate #include "macos.h"
11*7c478bd9Sstevel@tonic-gate #endif /* MACOS */
12*7c478bd9Sstevel@tonic-gate
13*7c478bd9Sstevel@tonic-gate #if !defined( MACOS ) && !defined( DOS )
14*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
15*7c478bd9Sstevel@tonic-gate #include <sys/socket.h>
16*7c478bd9Sstevel@tonic-gate #endif
17*7c478bd9Sstevel@tonic-gate
18*7c478bd9Sstevel@tonic-gate #include "lber.h"
19*7c478bd9Sstevel@tonic-gate #include "ldap.h"
20*7c478bd9Sstevel@tonic-gate #include "ldap-int.h"
21*7c478bd9Sstevel@tonic-gate
ldap_create_page_control(LDAP * ld,unsigned int pagesize,struct berval * cookie,char isCritical,LDAPControl ** output)22*7c478bd9Sstevel@tonic-gate int ldap_create_page_control(LDAP *ld, unsigned int pagesize, struct berval *cookie, char isCritical, LDAPControl **output)
23*7c478bd9Sstevel@tonic-gate {
24*7c478bd9Sstevel@tonic-gate BerElement *ber;
25*7c478bd9Sstevel@tonic-gate int rc;
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate if (NULL == ld || NULL == output)
28*7c478bd9Sstevel@tonic-gate return (LDAP_PARAM_ERROR);
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gate if ((ber = ber_alloc_t(LBER_USE_DER)) == NULLBER){
31*7c478bd9Sstevel@tonic-gate return (LDAP_NO_MEMORY);
32*7c478bd9Sstevel@tonic-gate }
33*7c478bd9Sstevel@tonic-gate
34*7c478bd9Sstevel@tonic-gate if (ber_printf(ber, "{io}", pagesize,
35*7c478bd9Sstevel@tonic-gate (cookie && cookie->bv_val) ? cookie->bv_val : "",
36*7c478bd9Sstevel@tonic-gate (cookie && cookie->bv_val) ? cookie->bv_len : 0)
37*7c478bd9Sstevel@tonic-gate == LBER_ERROR) {
38*7c478bd9Sstevel@tonic-gate ber_free(ber, 1);
39*7c478bd9Sstevel@tonic-gate return (LDAP_ENCODING_ERROR);
40*7c478bd9Sstevel@tonic-gate }
41*7c478bd9Sstevel@tonic-gate
42*7c478bd9Sstevel@tonic-gate rc = nsldapi_build_control(LDAP_CONTROL_SIMPLE_PAGE, ber, 1, isCritical,
43*7c478bd9Sstevel@tonic-gate output);
44*7c478bd9Sstevel@tonic-gate
45*7c478bd9Sstevel@tonic-gate ld->ld_errno = rc;
46*7c478bd9Sstevel@tonic-gate return (rc);
47*7c478bd9Sstevel@tonic-gate }
48*7c478bd9Sstevel@tonic-gate
ldap_parse_page_control(LDAP * ld,LDAPControl ** controls,unsigned int * totalcount,struct berval ** cookie)49*7c478bd9Sstevel@tonic-gate int ldap_parse_page_control(LDAP *ld, LDAPControl **controls, unsigned int *totalcount, struct berval **cookie)
50*7c478bd9Sstevel@tonic-gate {
51*7c478bd9Sstevel@tonic-gate int i, rc;
52*7c478bd9Sstevel@tonic-gate BerElement *theBer;
53*7c478bd9Sstevel@tonic-gate LDAPControl *listCtrlp;
54*7c478bd9Sstevel@tonic-gate
55*7c478bd9Sstevel@tonic-gate for (i = 0; controls[i] != NULL; i++){
56*7c478bd9Sstevel@tonic-gate if (strcmp(controls[i]->ldctl_oid, "1.2.840.113556.1.4.319") == 0) {
57*7c478bd9Sstevel@tonic-gate listCtrlp = controls[i];
58*7c478bd9Sstevel@tonic-gate if ((theBer = ber_init(&listCtrlp->ldctl_value)) == NULLBER){
59*7c478bd9Sstevel@tonic-gate return (LDAP_NO_MEMORY);
60*7c478bd9Sstevel@tonic-gate }
61*7c478bd9Sstevel@tonic-gate if ((rc = ber_scanf(theBer, "{iO}", totalcount, cookie)) == LBER_ERROR){
62*7c478bd9Sstevel@tonic-gate ber_free(theBer, 1);
63*7c478bd9Sstevel@tonic-gate return (LDAP_DECODING_ERROR);
64*7c478bd9Sstevel@tonic-gate }
65*7c478bd9Sstevel@tonic-gate ber_free(theBer, 1);
66*7c478bd9Sstevel@tonic-gate return (LDAP_SUCCESS);
67*7c478bd9Sstevel@tonic-gate }
68*7c478bd9Sstevel@tonic-gate }
69*7c478bd9Sstevel@tonic-gate return (LDAP_CONTROL_NOT_FOUND);
70*7c478bd9Sstevel@tonic-gate }
71*7c478bd9Sstevel@tonic-gate
72