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