10Sstevel@tonic-gate /*
20Sstevel@tonic-gate *
3*3857Sstevel * Copyright 1999 Sun Microsystems, Inc. All rights reserved.
4*3857Sstevel * Use is subject to license terms.
50Sstevel@tonic-gate *
60Sstevel@tonic-gate *
70Sstevel@tonic-gate * Comments:
80Sstevel@tonic-gate *
90Sstevel@tonic-gate */
100Sstevel@tonic-gate
110Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
120Sstevel@tonic-gate
130Sstevel@tonic-gate #include <stdio.h>
140Sstevel@tonic-gate #include <string.h>
150Sstevel@tonic-gate
160Sstevel@tonic-gate #ifdef MACOS
170Sstevel@tonic-gate #include "macos.h"
180Sstevel@tonic-gate #endif /* MACOS */
190Sstevel@tonic-gate
200Sstevel@tonic-gate #if !defined( MACOS ) && !defined( DOS )
210Sstevel@tonic-gate #include <sys/types.h>
220Sstevel@tonic-gate #include <sys/socket.h>
230Sstevel@tonic-gate #endif
240Sstevel@tonic-gate
250Sstevel@tonic-gate #include "lber.h"
260Sstevel@tonic-gate #include "ldap.h"
270Sstevel@tonic-gate #include "ldap-private.h"
280Sstevel@tonic-gate #include "ldap-int.h"
290Sstevel@tonic-gate
ldap_create_page_control(LDAP * ld,unsigned int pagesize,struct berval * cookie,char isCritical,LDAPControl ** output)300Sstevel@tonic-gate int ldap_create_page_control(LDAP *ld, unsigned int pagesize, struct berval *cookie, char isCritical, LDAPControl **output)
310Sstevel@tonic-gate {
320Sstevel@tonic-gate BerElement *ber;
330Sstevel@tonic-gate int rc;
340Sstevel@tonic-gate
350Sstevel@tonic-gate if (NULL == ld || NULL == output)
360Sstevel@tonic-gate return (LDAP_PARAM_ERROR);
370Sstevel@tonic-gate
380Sstevel@tonic-gate if ((ber = ber_alloc_t(LBER_USE_DER)) == NULLBER){
390Sstevel@tonic-gate return (LDAP_NO_MEMORY);
400Sstevel@tonic-gate }
410Sstevel@tonic-gate
420Sstevel@tonic-gate if (ber_printf(ber, "{io}", pagesize,
430Sstevel@tonic-gate (cookie && cookie->bv_val) ? cookie->bv_val : "",
440Sstevel@tonic-gate (cookie && cookie->bv_val) ? cookie->bv_len : 0)
450Sstevel@tonic-gate == LBER_ERROR) {
460Sstevel@tonic-gate ber_free(ber, 1);
470Sstevel@tonic-gate return (LDAP_ENCODING_ERROR);
480Sstevel@tonic-gate }
490Sstevel@tonic-gate
500Sstevel@tonic-gate rc = ldap_build_control(LDAP_CONTROL_SIMPLE_PAGE, ber, 1, isCritical,
510Sstevel@tonic-gate output);
520Sstevel@tonic-gate
530Sstevel@tonic-gate ld->ld_errno = rc;
540Sstevel@tonic-gate return (rc);
550Sstevel@tonic-gate }
560Sstevel@tonic-gate
ldap_parse_page_control(LDAP * ld,LDAPControl ** controls,unsigned int * totalcount,struct berval ** cookie)570Sstevel@tonic-gate int ldap_parse_page_control(LDAP *ld, LDAPControl **controls, unsigned int *totalcount, struct berval **cookie)
580Sstevel@tonic-gate {
590Sstevel@tonic-gate int i, rc;
600Sstevel@tonic-gate BerElement *theBer;
610Sstevel@tonic-gate LDAPControl *listCtrlp;
620Sstevel@tonic-gate
630Sstevel@tonic-gate for (i = 0; controls[i] != NULL; i++){
640Sstevel@tonic-gate if (strcmp(controls[i]->ldctl_oid, "1.2.840.113556.1.4.319") == 0) {
650Sstevel@tonic-gate listCtrlp = controls[i];
660Sstevel@tonic-gate if ((theBer = ber_init(&listCtrlp->ldctl_value)) == NULLBER){
670Sstevel@tonic-gate return (LDAP_NO_MEMORY);
680Sstevel@tonic-gate }
690Sstevel@tonic-gate if ((rc = ber_scanf(theBer, "{iO}", totalcount, cookie)) == LBER_ERROR){
700Sstevel@tonic-gate ber_free(theBer, 1);
710Sstevel@tonic-gate return (LDAP_DECODING_ERROR);
720Sstevel@tonic-gate }
730Sstevel@tonic-gate ber_free(theBer, 1);
740Sstevel@tonic-gate return (LDAP_SUCCESS);
750Sstevel@tonic-gate }
760Sstevel@tonic-gate }
770Sstevel@tonic-gate return (LDAP_CONTROL_NOT_FOUND);
780Sstevel@tonic-gate }
790Sstevel@tonic-gate
80