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