io.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* io.c - ber general i/o routines */
/*
* Copyright (c) 1990 Regents of the University of Michigan.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of Michigan at Ann Arbor. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
*/
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include <poll.h>
#include "msdos.h"
#endif /* DOS || _WIN32 */
#ifdef MACOS
#include <stdlib.h>
#include "macos.h"
#else /* MACOS */
#include <stdlib.h>
#else /* next || vms */
#include <malloc.h>
#endif /* next || vms */
#include <errno.h>
#ifdef PCNFS
#include <tklib.h>
#endif /* PCNFS */
#endif /* MACOS */
#ifdef SUN
#include <unistd.h>
#endif
#ifndef VMS
#include <memory.h>
#endif
#include <string.h>
#include "lber.h"
#include "ldap.h"
#include "ldap-private.h"
#include "ldap-int.h"
#ifdef _WIN32
#include <winsock.h>
#include <io.h>
#endif /* _WIN32 */
#ifdef NEEDPROTOS
#ifdef PCNFS
#endif /* PCNFS */
#else
int ber_filbuf();
int BerRead();
int ber_realloc();
#endif /* NEEDPROTOS */
#ifdef MACOS
/*
*/
#define MAX_WRITE 65535
#define BerWrite( sb, b, l ) tcpwrite( sb->sb_sd, (unsigned char *)(b), (l<MAX_WRITE)? l : MAX_WRITE )
#else /* MACOS */
#ifdef DOS
#ifdef PCNFS
/*
* PCNFS (under DOS)
*/
#endif /* PCNFS */
#ifdef NCSA
/*
*/
#endif /* NCSA */
#ifdef WINSOCK
/*
*/
#endif /* WINSOCK */
#else /* DOS */
#ifdef _WIN32
/*
* 32-bit Windows Socket API (under Windows NT or Windows 95)
*/
#else /* _WIN32 */
#ifdef VMS
/*
* VMS -- each write must be 64K or smaller
*/
#define MAX_WRITE 65535
#else /* VMS */
/*
*/
#endif /* VMS */
#endif /* _WIN32 */
#endif /* DOS */
#endif /* MACOS */
#ifndef udp_read
#endif /* udp_read */
#define EXBUFSIZ 1024
int
{
#ifdef CLDAP
int addrlen;
#endif /* CLDAP */
NULL )
return( -1 );
}
#ifdef CLDAP
#ifdef LDAP_DEBUG
if ( lber_debug ) {
(int)rc );
}
#endif /* LDAP_DEBUG */
#else /* CLDAP */
rc = -1;
#endif /* CLDAP */
#ifdef LDAP_SSL
(len < READBUFSIZ)) ?
len : READBUFSIZ );
#endif /* LDAP_SSL */
} else {
int loop=2;
while (loop>0) {
--loop;
(len < READBUFSIZ)) ?
len : READBUFSIZ );
/*
* if packet not here yet, wait 10 seconds to let it arrive
*/
/* nothing received or error, just abandon the read */
break;
} /* end if */
} else {
break;
} /* end if */
} /* end while */
}
if ( rc > 0 ) {
}
return( -1 );
}
int
{
int c;
int nread = 0;
while ( len > 0 ) {
if ( nread > 0 )
break;
return( c );
}
*buf++ = (char)c;
nread++;
len--;
}
return( nread );
}
int
{
return( (int)actuallen );
}
int
{
return( -1 );
}
return( len );
} else {
return( -1 );
}
return( len );
}
}
int
{
Seqorset *s;
char *oldbuf;
return( -1 );
return( -1 );
/*
* If the stinking thing was moved, we need to go through and
* reset all the sos and ber pointers. Offsets would've been
* a better idea... oh well.
*/
}
}
return( 0 );
}
void
{
}
}
int
{
}
#ifdef LDAP_DEBUG
if ( lber_debug ) {
(void) fprintf( stderr, catgets(slapdcat, 1, 76, "ber_flush: %1$ld bytes to sd %2$ld%s\n"), towrite,
: "" );
if ( lber_debug > 1 )
}
#endif
#ifdef LDAP_SSL
if ( rc < 0 ) {
}
} else {
#endif /* LDAP_SSL */
return( (int)rc );
}
#ifdef LDAP_SSL
}
#endif /* LDAP_SSL */
}
#endif
nwritten = 0;
do {
#ifdef CLDAP
#else /* CLDAP */
rc = -1;
#endif /* CLDAP */
if ( rc <= 0 )
return( -1 );
/* fake error if write was not atomic */
#endif
return( -1 );
}
} else {
#ifdef LDAP_SSL
return( -1 );
}
} else
#endif /* LDAP_SSL */
return( -1 );
}
}
} while ( towrite > 0 );
if ( freeit )
return( 0 );
}
ber_alloc_t( int options )
{
return( NULLBER );
return( ber );
}
{
return( ber_alloc_t( 0 ) );
}
{
return( ber_alloc_t( LBER_USE_DER ) );
}
{
return( NULLBER );
return( new );
}
{
return (NULLBER);
return (NULLBER);
return (NULLBER);
}
return (new);
}
void
{
}
void
{
if ( was_writing ) {
} else {
}
}
#ifdef LDAP_DEBUG
void
{
(void) fprintf( stderr, catgets(slapdcat, 1, 77, "ber_dump: buf 0x%1$lx, ptr 0x%2$lx, end 0x%3$lx\n"),
if ( inout == 1 ) {
} else {
}
}
void
{
while ( sos != NULLSEQORSET ) {
(void) fprintf( stderr, catgets(slapdcat, 1, 80, "ber_sos_dump: clen %1$ld first 0x%2$lx ptr 0x%3$lx\n"),
}
}
#endif
/* return the tag - LBER_DEFAULT returned means trouble */
static unsigned int
{
unsigned char xbyte;
unsigned int tag;
char *tagp;
int i;
return( LBER_DEFAULT );
return( (unsigned int) xbyte );
for ( i = 1; i < sizeof(int); i++ ) {
return( LBER_DEFAULT );
if ( ! (xbyte & LBER_MORE_TAG_MASK) )
break;
}
/* tag too big! */
if ( i == sizeof(int) )
return( LBER_DEFAULT );
/* want leading, not trailing 0's */
return( tag >> (sizeof(int) - i - 1) );
}
unsigned int
{
unsigned char lc;
int rc;
#ifdef LDAP_DEBUG
if ( lber_debug )
#endif
/*
* Any ber element looks like this: tag length contents.
* Assuming everything's ok, we return the tag byte (we
* can assume a single byte), return the length in len,
* and the rest of the undecoded element in buf.
*
* Assumptions:
* 1) small tags (less than 128)
* 2) definite lengths
* 3) primitive encodings used whenever possible
*/
/*
* first time through - malloc the buffer, set up ptrs, and
* read the tag and the length and as much of the rest as we can
*/
/*
* First, we read the tag.
*/
return( LBER_DEFAULT );
}
/*
* Next, read the length. The first byte contains the length
* of the length. If bit 8 is set, the length is the int
* form, otherwise it's the short form. We don't allow a
* length that's greater than what we can hold in an unsigned
* int.
*/
return( LBER_DEFAULT );
}
if ( lc & 0x80 ) {
if ( noctets > sizeof(unsigned int) )
return( LBER_DEFAULT );
noctets ) {
return( LBER_DEFAULT );
}
} else {
}
/*
* Finally, malloc a buffer for the contents and read it in.
* It's this buffer that's passed to all the other ber decoding
* routines.
*/
return( LBER_DEFAULT );
}
#endif /* DOS && !_WIN32 */
return( LBER_DEFAULT );
}
return( LBER_DEFAULT );
}
}
do {
return( LBER_DEFAULT );
}
} while ( toread != 0 ); /* DF SUN for LINT */
#ifdef LDAP_DEBUG
if ( lber_debug ) {
(void) fprintf( stderr, catgets(slapdcat, 1, 84, "ber_get_next: tag 0x%1$lx len %2$ld contents:\n"),
if ( lber_debug > 1 )
}
#endif
}