Commit bed979f9 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

No longer supported.

parent 54da7d2f
LDAP Macintosh README
The lber and ldap client libraries have been ported to Macintosh.
Build testing was originally done with Think C 5.0.4 and MPW 3.2, both
running under System 7.1. Recently, it has been built using Metrowerks
CodeWarrior 8.0 and Symantec C++ 7.0.3. The libaries have been tested
under System 7.0, 7.1, and 7.5, and are believed to run under any
System later than 6.0. None of the LDAP clients included in the
distribution have been tested on the Mac.
MAKING THE DISTRIBUTION
The instructions included here are for Symantec C 7.0.4, but the steps
are very similar for the other environments.
To build the ldap and lber libraries (easiest to do as one project):
1) create a new project that contains the following files:
libraries/liblber/decode.c
libraries/liblber/encode.c
libraries/liblber/io.c
libraries/macintosh/tcp/dnr.c
libraries/macintosh/tcp/tcp.c
libraries/macintosh/macos-ip.c
libraries/macintosh/strings.c
plus all the .c files in libraries/libldap/, except test.c,
tmpltest.c, and os-ip.c.
2) put all of the .h files in include/, libraries/macintosh/,
libraries/libldap and libraries/macintosh/tcp somewhere
in the same folder where the project is located.
3) Add the MacTraps, MacTraps2, Unix, and ANSI-small libraries
(included with Symantec/ThinkC) to the project.
3) Bring up the Edit menu "Options..." dialog and set the following:
Language Settings:
Strict Prototype Enforcement/Require Prototypes
Prefix:
#define MACOS
#define NEEDPROTOS
#define NEEDGETOPT
#define NO_USERINTERFACE
#define FILTERFILE "ldapfilter.conf"
#define TEMPLATEFILE "ldaptemplates.conf"
If you want to build a version of the library that does
not have any global variables (such as for inclusion in a
driver or other code module), add a "#define NO_GLOBALS"
to the Prefix. The only catch is that the tcp/dnr.c
file needs changes to remove the global variables.
If you want support for referrals (optionally enabled
for each LDAP connection), add '#define LDAP_REFERRALS'
to the prefix list. This is recommended.
4) Compile the project (Bring Up To Date under the Project menu)
5) If you would like to use the libldap/test.c program to test the
library in an ugly console window, you will need to add the
test.c file itself and the full ANSI library (instead of
ANSI-small) to the project, and don't define NO_USERINTERFACE.
BUG REPORTING
Bug reports should be sent to bug-ldap@terminator.cc.umich.edu.
README Last updated 11 April 1996 by Mark Smith
/*
* Copyright (c) 1987 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that: (1) source distributions retain this entire copyright
* notice and comment, and (2) distributions including binaries display
* the following acknowledgement: ``This product includes software
* developed by the University of California, Berkeley and its contributors''
* in the documentation or other materials provided with the distribution
* and in all advertising materials mentioning features or use of this
* software. Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)getopt.c 4.12 (Berkeley) 6/1/90";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <string.h>
#include "lber.h"
#define index strchr
#define rindex strrchr
/*
* get option letter from argument vector
*/
int opterr = 1, /* if error message should be printed */
optind = 1, /* index into parent argv vector */
optopt; /* character checked for validity */
char *optarg; /* argument associated with option */
#define BADCH (int)'?'
#define EMSG ""
getopt(int nargc, char **nargv, char *ostr)
{
static char *place = EMSG; /* option letter processing */
register char *oli; /* option letter list index */
char *p;
if (!*place) { /* update scanning pointer */
if (optind >= nargc || *(place = nargv[optind]) != '-') {
place = EMSG;
return(EOF);
}
if (place[1] && *++place == '-') { /* found "--" */
++optind;
place = EMSG;
return(EOF);
}
} /* option letter okay? */
if ((optopt = (int)*place++) == (int)':' ||
!(oli = index(ostr, optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means EOF.
*/
if (optopt == (int)'-')
return(EOF);
if (!*place)
++optind;
if (opterr) {
if (!(p = rindex(*nargv, '/')))
p = *nargv;
else
++p;
(void)fprintf(stderr, "%s: illegal option -- %c\n",
p, optopt);
}
return(BADCH);
}
if (*++oli != ':') { /* don't need argument */
optarg = NULL;
if (!*place)
++optind;
}
else { /* need an argument */
if (*place) /* no white space */
optarg = place;
else if (nargc <= ++optind) { /* no arg */
place = EMSG;
if (!(p = rindex(*nargv, '/')))
p = *nargv;
else
++p;
if (opterr)
(void)fprintf(stderr,
"%s: option requires an argument -- %c\n",
p, optopt);
return(BADCH);
}
else /* white space */
optarg = nargv[optind];
place = EMSG;
++optind;
}
return(optopt); /* dump back option letter */
}
/*
* Copyright (c) 1992, 1994 Regents of the University of Michigan.
* All rights reserved.
*
* kerberos-macos.c
*/
#ifndef lint
static char copyright[] = "@(#) Copyright (c) 1994 Regents of the University of Michigan.\nAll rights reserved.\n";
#endif
#include "lber.h"
#include "ldap.h"
#ifdef KERBEROS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef THINK_C
#include <pascal.h>
#else /* THINK_C */
#include <Strings.h>
#endif /* THINK_C */
#ifdef AUTHMAN
#include <MixedMode.h>
#include <Errors.h>
#include "authLibrary.h"
#include "ldap-int.h"
/*
* get_kerberosv4_credentials - obtain kerberos v4 credentials for ldap.
*/
/* ARGSUSED */
char *
get_kerberosv4_credentials( LDAP *ld, char *who, char *service, int *len )
{
static short authman_refnum = 0;
char *cred, ticket[ MAX_KTXT_LEN ];
short version, ticketlen, err;
Str255 svcps, instps;
/*
* make sure RJC's Authentication Manager 2.0 or better is available
*/
if ( authman_refnum == 0 && (( err = openAuthMan( &authman_refnum, &version )) != noErr || version < 2 )) {
authman_refnum = 0;
ld->ld_errno = LDAP_AUTH_UNKNOWN;
return( NULL );
}
strcpy( (char *)svcps, service );
CtoPstr( (char *)svcps );
#ifdef LDAP_REFERRALS
strcpy( (char *)instps, ld->ld_defconn->lconn_krbinstance );
#else /* LDAP_REFERRALS */
strcpy( (char *)instps, ld->ld_host );
#endif /* LDAP_REFERRALS */
CtoPstr( (char *)instps );
if (( err = getV4Ticket( authman_refnum, &ticket, &ticketlen, &svcps, &instps,
NULL, INFINITE_LIFETIME, 1 )) != noErr ) {
ld->ld_errno = ( err == userCanceledErr ) ?
LDAP_USER_CANCELLED : LDAP_INVALID_CREDENTIALS;
return( NULL );
}
if (( cred = malloc( ticketlen )) == NULL ) {
ld->ld_errno = LDAP_NO_MEMORY;
return( NULL );
}
*len = ticketlen;
memcpy( cred, (char *)ticket, ticketlen );
return( cred );
}
#endif
#endif
/*
* Copyright (c) 1995 Regents of the University of Michigan.
* All rights reserved.
*
* macos-ip.c -- Macintosh platform-specific TCP & UDP related code
*/
#ifndef lint
static char copyright[] = "@(#) Copyright (c) 1995 Regents of the University of Michigan.\nAll rights reserved.\n";
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <Memory.h>
#include "macos.h"
#include "lber.h"
#include "ldap.h"
#include "ldap-int.h"
int
connect_to_host( Sockbuf *sb, char *host, unsigned long address,
int port, int async )
/*
* if host == NULL, connect using address
* "address" and "port" must be in network byte order
* zero is returned upon success, -1 if fatal error, -2 EINPROGRESS
* async is only used ifndef NO_REFERRALS (non-0 means don't wait for connect)
* XXX async is not used yet!
*/
{
void *tcps;
short i;
#ifdef SUPPORT_OPENTRANSPORT
InetHostInfo hi;
#else /* SUPPORT_OPENTRANSPORT */
struct hostInfo hi;
#endif /* SUPPORT_OPENTRANSPORT */
Debug( LDAP_DEBUG_TRACE, "connect_to_host: %s:%d\n",
( host == NULL ) ? "(by address)" : host, ntohs( port ), 0 );
if ( host != NULL && gethostinfobyname( host, &hi ) != noErr ) {
return( -1 );
}
if (( tcps = tcpopen( NULL, TCP_BUFSIZ )) == NULL ) {
Debug( LDAP_DEBUG_TRACE, "tcpopen failed\n", 0, 0, 0 );
return( -1 );
}
#ifdef SUPPORT_OPENTRANSPORT
for ( i = 0; host == NULL || hi.addrs[ i ] != 0; ++i ) {
if ( host != NULL ) {
SAFEMEMCPY( (char *)&address, (char *)&hi.addrs[ i ], sizeof( long ));
}
#else /* SUPPORT_OPENTRANSPORT */
for ( i = 0; host == NULL || hi.addr[ i ] != 0; ++i ) {
if ( host != NULL ) {
SAFEMEMCPY( (char *)&address, (char *)&hi.addr[ i ], sizeof( long ));
}
#endif /* SUPPORT_OPENTRANSPORT */
if ( tcpconnect( tcps, address, port ) > 0 ) {
sb->sb_sd = (void *)tcps;
return( 0 );
}
if ( host == NULL ) { /* using single address -- not hi.addrs array */
break;
}
}
Debug( LDAP_DEBUG_TRACE, "tcpconnect failed\n", 0, 0, 0 );
tcpclose( tcps );
return( -1 );
}
void
close_connection( Sockbuf *sb )
{
tcpclose( (tcpstream *)sb->sb_sd );
}
#ifdef KERBEROS
char *
host_connected_to( Sockbuf *sb )
{
ip_addr addr;
#ifdef SUPPORT_OPENTRANSPORT
InetHostInfo hi;
#else /* SUPPORT_OPENTRANSPORT */
struct hostInfo hi;
#endif /* SUPPORT_OPENTRANSPORT */
if ( tcpgetpeername( (tcpstream *)sb->sb_sd, &addr, NULL ) != noErr ) {
return( NULL );
}
#ifdef SUPPORT_OPENTRANSPORT
if ( gethostinfobyaddr( addr, &hi ) == noErr ) {
return( strdup( hi.name ));
}
#else /* SUPPORT_OPENTRANSPORT */
if ( gethostinfobyaddr( addr, &hi ) == noErr ) {
return( strdup( hi.cname ));
}
#endif /* SUPPORT_OPENTRANSPORT */
return( NULL );
}
#endif /* KERBEROS */
#ifdef LDAP_REFERRALS
struct tcpstreaminfo {
struct tcpstream *tcpsi_stream;
Boolean tcpsi_check_read;
Boolean tcpsi_is_read_ready;
/* Boolean tcpsi_check_write; /* no write select support needed yet */
/* Boolean tcpsi_is_write_ready; /* ditto */
};
struct selectinfo {
short si_count;
struct tcpstreaminfo *si_streaminfo;
};
void
mark_select_read( LDAP *ld, Sockbuf *sb )
{
struct selectinfo *sip;
struct tcpstreaminfo *tcpsip;
short i;
Debug( LDAP_DEBUG_TRACE, "mark_select_read: stream %x\n", (tcpstream *)sb->sb_sd, 0, 0 );
if (( sip = (struct selectinfo *)ld->ld_selectinfo ) == NULL ) {
return;
}
for ( i = 0; i < sip->si_count; ++i ) { /* make sure stream is not already in the list... */
if ( sip->si_streaminfo[ i ].tcpsi_stream == (tcpstream *)sb->sb_sd ) {
sip->si_streaminfo[ i ].tcpsi_check_read = true;
sip->si_streaminfo[ i ].tcpsi_is_read_ready = false;
return;
}
}
/* add a new stream element to our array... */
if ( sip->si_count <= 0 ) {
tcpsip = (struct tcpstreaminfo *)malloc( sizeof( struct tcpstreaminfo ));
} else {
tcpsip = (struct tcpstreaminfo *)realloc( sip->si_streaminfo,
( sip->si_count + 1 ) * sizeof( struct tcpstreaminfo ));
}
if ( tcpsip != NULL ) {
tcpsip[ sip->si_count ].tcpsi_stream = (tcpstream *)sb->sb_sd;
tcpsip[ sip->si_count ].tcpsi_check_read = true;
tcpsip[ sip->si_count ].tcpsi_is_read_ready = false;
sip->si_streaminfo = tcpsip;
++sip->si_count;
}
}
void
mark_select_clear( LDAP *ld, Sockbuf *sb )
{
struct selectinfo *sip;
short i;
Debug( LDAP_DEBUG_TRACE, "mark_select_clear: stream %x\n", (tcpstream *)sb->sb_sd, 0, 0 );
sip = (struct selectinfo *)ld->ld_selectinfo;
if ( sip != NULL && sip->si_count > 0 && sip->si_streaminfo != NULL ) {
for ( i = 0; i < sip->si_count; ++i ) {
if ( sip->si_streaminfo[ i ].tcpsi_stream == (tcpstream *)sb->sb_sd ) {
break;
}
}
if ( i < sip->si_count ) {
--sip->si_count;
for ( ; i < sip->si_count; ++i ) {
sip->si_streaminfo[ i ] = sip->si_streaminfo[ i + 1 ];
}
/* we don't bother to use realloc to make the si_streaminfo array smaller */
}
}
}
int
is_read_ready( LDAP *ld, Sockbuf *sb )
{
struct selectinfo *sip;
short i;
sip = (struct selectinfo *)ld->ld_selectinfo;
if ( sip != NULL && sip->si_count > 0 && sip->si_streaminfo != NULL ) {
for ( i = 0; i < sip->si_count; ++i ) {
if ( sip->si_streaminfo[ i ].tcpsi_stream == (tcpstream *)sb->sb_sd ) {
#ifdef LDAP_DEBUG
if ( sip->si_streaminfo[ i ].tcpsi_is_read_ready ) {
Debug( LDAP_DEBUG_TRACE, "is_read_ready: stream %x READY\n",
(tcpstream *)sb->sb_sd, 0, 0 );
} else {
Debug( LDAP_DEBUG_TRACE, "is_read_ready: stream %x Not Ready\n",
(tcpstream *)sb->sb_sd, 0, 0 );
}
#endif /* LDAP_DEBUG */
return( sip->si_streaminfo[ i ].tcpsi_is_read_ready ? 1 : 0 );
}
}
}
Debug( LDAP_DEBUG_TRACE, "is_read_ready: stream %x: NOT FOUND\n", (tcpstream *)sb->sb_sd, 0, 0 );
return( 0 );
}
void *
new_select_info()
{
return( (void *)calloc( 1, sizeof( struct selectinfo )));
}
void
free_select_info( void *sip )
{
if ( sip != NULL ) {
free( sip );
}
}
int
do_ldap_select( LDAP *ld, struct timeval *timeout )
{
struct selectinfo *sip;
Boolean ready, gotselecterr;
long ticks, endticks;
short i, err;
Debug( LDAP_DEBUG_TRACE, "do_ldap_select\n", 0, 0, 0 );
if (( sip = (struct selectinfo *)ld->ld_selectinfo ) == NULL ) {
return( -1 );
}
if ( sip->si_count == 0 ) {
return( 1 );
}
if ( timeout != NULL ) {
endticks = 60 * timeout->tv_sec + ( 60 * timeout->tv_usec ) / 1000000 + TickCount();
}
for ( i = 0; i < sip->si_count; ++i ) {
if ( sip->si_streaminfo[ i ].tcpsi_check_read ) {
sip->si_streaminfo[ i ].tcpsi_is_read_ready = false;
}
}
ready = gotselecterr = false;
do {
for ( i = 0; i < sip->si_count; ++i ) {
if ( sip->si_streaminfo[ i ].tcpsi_check_read && !sip->si_streaminfo[ i ].tcpsi_is_read_ready ) {
if (( err = tcpreadready( sip->si_streaminfo[ i ].tcpsi_stream )) > 0 ) {
sip->si_streaminfo[ i ].tcpsi_is_read_ready = ready = true;
} else if ( err < 0 ) {
gotselecterr = true;
}
}
}
if ( !ready && !gotselecterr ) {
Delay( 2L, &ticks );
SystemTask();
}
} while ( !ready && !gotselecterr && ( timeout == NULL || ticks < endticks ));
Debug( LDAP_DEBUG_TRACE, "do_ldap_select returns %d\n", ready ? 1 : ( gotselecterr ? -1 : 0 ), 0, 0 );
return( ready ? 1 : ( gotselecterr ? -1 : 0 ));
}
#endif /* LDAP_REFERRALS */
/*
* macos.h: bridge unix and Mac for LBER/LDAP
*/
#define ntohl( l ) (l)
#define htonl( l ) (l)
#define ntohs( s ) (s)
#define htons( s ) (s)
#ifdef NO_GLOBALS
#ifdef macintosh /* IUMagIDString declared in TextUtils.h under MPW */
#include <TextUtils.h>
#else /* macintosh */ /* IUMagIDString declared in Packages.h under ThinkC */
#include <Packages.h>
#endif /* macintosh */
#define strcasecmp( s1, s2 ) IUMagIDString( s1, s2, strlen( s1 ), \
strlen( s2 ))
#else /* NO_GLOBALS */
int strcasecmp( char *s1, char *s2 );
int strncasecmp( char *s1, char *s2, long n );
#endif NO_GLOBALS
#include <Memory.h> /* to get BlockMove() */
char *strdup( char *s );
#ifndef isascii
#define isascii(c) ((unsigned)(c)<=0177) /* for those who don't have this in ctype.h */
#endif isascii
#include "tcp.h"
/*
* strings.c
*/
#include <string.h>
#include <stdlib.h>
#include "macos.h"
#ifndef NO_GLOBALS
/*
* Copyright (c) 1987 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
/*
* This array is designed for mapping upper and lower case letter
* together for a case independent comparison. The mappings are
* based upon ascii character sequences.
*/
static char charmap[] = {
'\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
'\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
'\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
'\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
'\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
'\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
'\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
'\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
'\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',