openldap-2.5.16+dfsg/ 0000755 0001750 0001750 00000000000 14461774414 013704 5 ustar sergio sergio openldap-2.5.16+dfsg/clients/ 0000755 0001750 0001750 00000000000 14461774414 015345 5 ustar sergio sergio openldap-2.5.16+dfsg/clients/Makefile.in 0000644 0001750 0001750 00000001042 14461774414 017407 0 ustar sergio sergio # Clients Makefile.in for OpenLDAP
# $OpenLDAP$
## This work is part of OpenLDAP Software .
##
## Copyright 1998-2022 The OpenLDAP Foundation.
## All rights reserved.
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted only as authorized by the OpenLDAP
## Public License.
##
## A copy of this license is available in the file LICENSE in the
## top-level directory of the distribution or, alternatively, at
## .
SUBDIRS = tools
openldap-2.5.16+dfsg/clients/tools/ 0000755 0001750 0001750 00000000000 14461774414 016505 5 ustar sergio sergio openldap-2.5.16+dfsg/clients/tools/ldapsearch.c 0000644 0001750 0001750 00000164235 14461774414 020772 0 ustar sergio sergio /* ldapsearch -- a tool for searching LDAP directories */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* Portions Copyright 1998-2003 Kurt D. Zeilenga.
* Portions Copyright 1998-2001 Net Boolean Incorporated.
* Portions Copyright 2001-2003 IBM Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* Portions Copyright (c) 1992-1996 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.
*/
/* ACKNOWLEDGEMENTS:
* This work was originally developed by the University of Michigan
* (as part of U-MICH LDAP). Additional significant contributors
* include:
* Jong Hyuk Choi
* Lynn Moss
* Mikhail Sahalaev
* Kurt D. Zeilenga
*/
#include "portable.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef HAVE_FCNTL_H
#include
#endif
#ifdef HAVE_SYS_TYPES_H
#include
#endif
#ifdef HAVE_IO_H
#include
#endif
#include
#include "ldif.h"
#include "lutil.h"
#include "lutil_ldap.h"
#include "ldap_defaults.h"
#include "ldap_pvt.h"
#include "common.h"
#if !LDAP_DEPRECATED
/*
* NOTE: we use this deprecated function only because
* we want ldapsearch to provide some client-side sorting
* capability.
*/
/* from ldap.h */
typedef int (LDAP_SORT_AD_CMP_PROC) LDAP_P(( /* deprecated */
LDAP_CONST char *left,
LDAP_CONST char *right ));
LDAP_F( int ) /* deprecated */
ldap_sort_entries LDAP_P(( LDAP *ld,
LDAPMessage **chain,
LDAP_CONST char *attr,
LDAP_SORT_AD_CMP_PROC *cmp ));
#endif
static int scope = LDAP_SCOPE_SUBTREE;
static int deref = -1;
static int attrsonly;
static int timelimit = -1;
static int sizelimit = -1;
static char *control;
static char *def_tmpdir;
static char *def_urlpre;
#if defined(__CYGWIN__) || defined(__MINGW32__)
/* Turn off commandline globbing, otherwise you cannot search for
* attribute '*'
*/
int _CRT_glob = 0;
#endif
void
usage( void )
{
fprintf( stderr, _("usage: %s [options] [filter [attributes...]]\nwhere:\n"), prog);
fprintf( stderr, _(" filter\tRFC 4515 compliant LDAP search filter\n"));
fprintf( stderr, _(" attributes\twhitespace-separated list of attribute descriptions\n"));
fprintf( stderr, _(" which may include:\n"));
fprintf( stderr, _(" 1.1 no attributes\n"));
fprintf( stderr, _(" * all user attributes\n"));
fprintf( stderr, _(" + all operational attributes\n"));
fprintf( stderr, _("Search options:\n"));
fprintf( stderr, _(" -a deref one of never (default), always, search, or find\n"));
fprintf( stderr, _(" -A retrieve attribute names only (no values)\n"));
fprintf( stderr, _(" -b basedn base dn for search\n"));
fprintf( stderr, _(" -c continuous operation mode (do not stop on errors)\n"));
fprintf( stderr, _(" -E [!][=] search extensions (! indicates criticality)\n"));
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
fprintf( stderr, _(" [!]accountUsability (NetScape Account usability)\n"));
#endif
fprintf( stderr, _(" [!]domainScope (domain scope)\n"));
fprintf( stderr, _(" !dontUseCopy (Don't Use Copy)\n"));
fprintf( stderr, _(" [!]mv= (RFC 3876 matched values filter)\n"));
fprintf( stderr, _(" [!]pr=[/prompt|noprompt] (RFC 2696 paged results/prompt)\n"));
fprintf( stderr, _(" [!]ps=// (draft persistent search)\n"));
fprintf( stderr, _(" [!]sss=[-][/[-]...]\n"));
fprintf( stderr, _(" (RFC 2891 server side sorting)\n"));
fprintf( stderr, _(" [!]subentries[=true|false] (RFC 3672 subentries)\n"));
fprintf( stderr, _(" [!]sync=ro[/] (RFC 4533 LDAP Sync refreshOnly)\n"));
fprintf( stderr, _(" rp[/][/] (refreshAndPersist)\n"));
fprintf( stderr, _(" [!]vlv=/(//|:)\n"));
fprintf( stderr, _(" (ldapv3-vlv-09 virtual list views)\n"));
#ifdef LDAP_CONTROL_X_DEREF
fprintf( stderr, _(" [!]deref=derefAttr:attr[,...][;derefAttr:attr[,...][;...]]\n"));
#endif
#ifdef LDAP_CONTROL_X_DIRSYNC
fprintf( stderr, _(" !dirSync=/[/]\n"));
fprintf( stderr, _(" (MS AD DirSync)\n"));
#endif
#ifdef LDAP_CONTROL_X_EXTENDED_DN
fprintf( stderr, _(" [!]extendedDn= (MS AD Extended DN\n"));
#endif
#ifdef LDAP_CONTROL_X_SHOW_DELETED
fprintf( stderr, _(" [!]showDeleted (MS AD Show Deleted)\n"));
#endif
#ifdef LDAP_CONTROL_X_SERVER_NOTIFICATION
fprintf( stderr, _(" [!]serverNotif (MS AD Server Notification)\n"));
#endif
fprintf( stderr, _(" [!][=:|::] (generic control; no response handling)\n"));
fprintf( stderr, _(" -f file read operations from `file'\n"));
fprintf( stderr, _(" -F prefix URL prefix for files (default: %s)\n"), def_urlpre);
fprintf( stderr, _(" -l limit time limit (in seconds, or \"none\" or \"max\") for search\n"));
fprintf( stderr, _(" -L print responses in LDIFv1 format\n"));
fprintf( stderr, _(" -LL print responses in LDIF format without comments\n"));
fprintf( stderr, _(" -LLL print responses in LDIF format without comments\n"));
fprintf( stderr, _(" and version\n"));
fprintf( stderr, _(" -M enable Manage DSA IT control (-MM to make critical)\n"));
fprintf( stderr, _(" -P version protocol version (default: 3)\n"));
fprintf( stderr, _(" -s scope one of base, one, sub or children (search scope)\n"));
fprintf( stderr, _(" -S attr sort the results by attribute `attr'\n"));
fprintf( stderr, _(" -t write binary values to files in temporary directory\n"));
fprintf( stderr, _(" -tt write all values to files in temporary directory\n"));
fprintf( stderr, _(" -T path write files to directory specified by path (default: %s)\n"), def_tmpdir);
fprintf( stderr, _(" -u include User Friendly entry names in the output\n"));
fprintf( stderr, _(" -z limit size limit (in entries, or \"none\" or \"max\") for search\n"));
tool_common_usage();
exit( EXIT_FAILURE );
}
static void print_entry LDAP_P((
LDAP *ld,
LDAPMessage *entry,
int attrsonly));
static void print_reference(
LDAP *ld,
LDAPMessage *reference );
static void print_extended(
LDAP *ld,
LDAPMessage *extended );
static void print_syncinfo(
BerValue *info );
static void print_partial(
LDAP *ld,
LDAPMessage *partial );
static int print_result(
LDAP *ld,
LDAPMessage *result,
int search );
static int dosearch LDAP_P((
LDAP *ld,
char *base,
int scope,
char *filtpatt,
char *value,
char **attrs,
int attrsonly,
LDAPControl **sctrls,
LDAPControl **cctrls,
struct timeval *timeout,
int sizelimit ));
static char *tmpdir = NULL;
static char *urlpre = NULL;
static char *base = NULL;
static char *sortattr = NULL;
static int includeufn, vals2tmp = 0;
static int subentries = 0, valuesReturnFilter = 0;
static char *vrFilter = NULL;
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
static int accountUsability = 0;
#endif
#ifdef LDAP_CONTROL_DONTUSECOPY
static int dontUseCopy = 0;
#endif
static int domainScope = 0;
static int sss = 0;
static LDAPSortKey **sss_keys = NULL;
static int vlv = 0;
static LDAPVLVInfo vlvInfo;
static struct berval vlvValue;
static int ldapsync = 0;
static struct berval sync_cookie = { 0, NULL };
static int sync_slimit = -1;
static int psearch = 0;
static int ps_chgtypes, ps_chgsonly, ps_echg_ctrls;
/* cookie and morePagedResults moved to common.c */
static int pagedResults = 0;
static int pagePrompt = 1;
static ber_int_t pageSize = 0;
static ber_int_t entriesLeft = 0;
static int npagedresponses;
static int npagedentries;
static int npagedreferences;
static int npagedextended;
static int npagedpartial;
static LDAPControl *c = NULL;
static int nctrls = 0;
static int save_nctrls = 0;
#ifdef LDAP_CONTROL_X_DEREF
static int derefcrit;
static LDAPDerefSpec *ds;
static struct berval derefval;
#endif
#ifdef LDAP_CONTROL_X_DIRSYNC
static int dirSync;
static int dirSyncFlags;
static int dirSyncMaxAttrCount;
static struct berval dirSyncCookie;
#endif
#ifdef LDAP_CONTROL_X_EXTENDED_DN
static int extendedDn;
static int extendedDnFlag;
#endif
#ifdef LDAP_CONTROL_X_SHOW_DELETED
static int showDeleted;
#endif
#ifdef LDAP_CONTROL_X_SERVER_NOTIFICATION
static int serverNotif;
#endif
static int
ctrl_add( void )
{
LDAPControl *tmpc;
nctrls++;
tmpc = realloc( c, sizeof( LDAPControl ) * nctrls );
if ( tmpc == NULL ) {
nctrls--;
fprintf( stderr,
_("unable to make room for control; out of memory?\n"));
return -1;
}
c = tmpc;
return 0;
}
static void
urlize(char *url)
{
char *p;
if (*LDAP_DIRSEP != '/') {
for (p = url; *p; p++) {
if (*p == *LDAP_DIRSEP)
*p = '/';
}
}
}
static int
parse_vlv(char *cvalue)
{
char *keyp, *key2;
int num1, num2;
keyp = cvalue;
if ( sscanf( keyp, "%d/%d", &num1, &num2 ) != 2 ) {
fprintf( stderr,
_("VLV control value \"%s\" invalid\n"),
cvalue );
return -1;
}
vlvInfo.ldvlv_before_count = num1;
vlvInfo.ldvlv_after_count = num2;
keyp = strchr( keyp, '/' ) + 1;
key2 = strchr( keyp, '/' );
if ( key2 ) {
keyp = key2 + 1;
if ( sscanf( keyp, "%d/%d", &num1, &num2 ) != 2 ) {
fprintf( stderr,
_("VLV control value \"%s\" invalid\n"),
cvalue );
return -1;
}
vlvInfo.ldvlv_offset = num1;
vlvInfo.ldvlv_count = num2;
vlvInfo.ldvlv_attrvalue = NULL;
} else {
key2 = strchr( keyp, ':' );
if ( !key2 ) {
fprintf( stderr,
_("VLV control value \"%s\" invalid\n"),
cvalue );
return -1;
}
ber_str2bv( key2+1, 0, 0, &vlvValue );
vlvInfo.ldvlv_attrvalue = &vlvValue;
}
return 0;
}
const char options[] = "a:Ab:cE:F:l:Ls:S:tT:uz:"
"Cd:D:e:f:H:IMnNO:o:P:QR:U:vVw:WxX:y:Y:Z";
int
handle_private_option( int i )
{
int crit, ival;
char *cvalue, *next;
switch ( i ) {
case 'a': /* set alias deref option */
if ( strcasecmp( optarg, "never" ) == 0 ) {
deref = LDAP_DEREF_NEVER;
} else if ( strncasecmp( optarg, "search", sizeof("search")-1 ) == 0 ) {
deref = LDAP_DEREF_SEARCHING;
} else if ( strncasecmp( optarg, "find", sizeof("find")-1 ) == 0 ) {
deref = LDAP_DEREF_FINDING;
} else if ( strcasecmp( optarg, "always" ) == 0 ) {
deref = LDAP_DEREF_ALWAYS;
} else {
fprintf( stderr,
_("alias deref should be never, search, find, or always\n") );
usage();
}
break;
case 'A': /* retrieve attribute names only -- no values */
++attrsonly;
break;
case 'b': /* search base */
base = optarg;
break;
case 'E': /* search extensions */
if( protocol == LDAP_VERSION2 ) {
fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"),
prog, protocol );
exit( EXIT_FAILURE );
}
/* should be extended to support comma separated list of
* [!]key[=value] parameters, e.g. -E !foo,bar=567
*/
crit = 0;
cvalue = NULL;
while ( optarg[0] == '!' ) {
crit++;
optarg++;
}
control = optarg;
if ( (cvalue = strchr( control, '=' )) != NULL ) {
*cvalue++ = '\0';
}
if ( strcasecmp( control, "mv" ) == 0 ) {
/* ValuesReturnFilter control */
if( valuesReturnFilter ) {
fprintf( stderr,
_("ValuesReturnFilter previously specified\n"));
exit( EXIT_FAILURE );
}
valuesReturnFilter= 1 + crit;
if ( cvalue == NULL ) {
fprintf( stderr,
_("missing filter in ValuesReturnFilter control\n"));
exit( EXIT_FAILURE );
}
vrFilter = cvalue;
protocol = LDAP_VERSION3;
} else if ( strcasecmp( control, "pr" ) == 0 ) {
int num, tmp;
/* PagedResults control */
if ( pagedResults != 0 ) {
fprintf( stderr,
_("PagedResultsControl previously specified\n") );
exit( EXIT_FAILURE );
}
if ( vlv != 0 ) {
fprintf( stderr,
_("PagedResultsControl incompatible with VLV\n") );
exit( EXIT_FAILURE );
}
if( cvalue != NULL ) {
char *promptp;
promptp = strchr( cvalue, '/' );
if ( promptp != NULL ) {
*promptp++ = '\0';
if ( strcasecmp( promptp, "prompt" ) == 0 ) {
pagePrompt = 1;
} else if ( strcasecmp( promptp, "noprompt" ) == 0) {
pagePrompt = 0;
} else {
fprintf( stderr,
_("Invalid value for PagedResultsControl,"
" %s/%s.\n"), cvalue, promptp );
exit( EXIT_FAILURE );
}
}
num = sscanf( cvalue, "%d", &tmp );
if ( num != 1 ) {
fprintf( stderr,
_("Invalid value for PagedResultsControl, %s.\n"),
cvalue );
exit( EXIT_FAILURE );
}
} else {
fprintf(stderr, _("Invalid value for PagedResultsControl.\n"));
exit( EXIT_FAILURE );
}
pageSize = (ber_int_t) tmp;
pagedResults = 1 + crit;
} else if ( strcasecmp( control, "ps" ) == 0 ) {
int num;
/* PersistentSearch control */
if ( psearch != 0 ) {
fprintf( stderr,
_("PersistentSearch previously specified\n") );
exit( EXIT_FAILURE );
}
if( cvalue != NULL ) {
num = sscanf( cvalue, "%i/%d/%d", &ps_chgtypes, &ps_chgsonly, &ps_echg_ctrls );
if ( num != 3 ) {
fprintf( stderr,
_("Invalid value for PersistentSearch, %s.\n"),
cvalue );
exit( EXIT_FAILURE );
}
} else {
fprintf(stderr, _("Invalid value for PersistentSearch.\n"));
exit( EXIT_FAILURE );
}
psearch = 1 + crit;
#ifdef LDAP_CONTROL_DONTUSECOPY
} else if ( strcasecmp( control, "dontUseCopy" ) == 0 ) {
if( dontUseCopy ) {
fprintf( stderr,
_("dontUseCopy control previously specified\n"));
exit( EXIT_FAILURE );
}
if( cvalue != NULL ) {
fprintf( stderr,
_("dontUseCopy: no control value expected\n") );
usage();
}
if( !crit ) {
fprintf( stderr,
_("dontUseCopy: critical flag required\n") );
usage();
}
dontUseCopy = 1 + crit;
#endif
} else if ( strcasecmp( control, "domainScope" ) == 0 ) {
if( domainScope ) {
fprintf( stderr,
_("domainScope control previously specified\n"));
exit( EXIT_FAILURE );
}
if( cvalue != NULL ) {
fprintf( stderr,
_("domainScope: no control value expected\n") );
usage();
}
domainScope = 1 + crit;
} else if ( strcasecmp( control, "sss" ) == 0 ) {
char *keyp;
if( sss ) {
fprintf( stderr,
_("server side sorting control previously specified\n"));
exit( EXIT_FAILURE );
}
if( cvalue == NULL ) {
fprintf( stderr,
_("missing specification of sss control\n") );
exit( EXIT_FAILURE );
}
keyp = cvalue;
while ( ( keyp = strchr(keyp, '/') ) != NULL ) {
*keyp++ = ' ';
}
if ( ldap_create_sort_keylist( &sss_keys, cvalue )) {
fprintf( stderr,
_("server side sorting control value \"%s\" invalid\n"),
cvalue );
exit( EXIT_FAILURE );
}
sss = 1 + crit;
} else if ( strcasecmp( control, "subentries" ) == 0 ) {
if( subentries ) {
fprintf( stderr,
_("subentries control previously specified\n"));
exit( EXIT_FAILURE );
}
if( cvalue == NULL || strcasecmp( cvalue, "true") == 0 ) {
subentries = 2;
} else if ( strcasecmp( cvalue, "false") == 0 ) {
subentries = 1;
} else {
fprintf( stderr,
_("subentries control value \"%s\" invalid\n"),
cvalue );
exit( EXIT_FAILURE );
}
if( crit ) subentries *= -1;
} else if ( strcasecmp( control, "sync" ) == 0 ) {
char *cookiep;
char *slimitp;
if ( ldapsync ) {
fprintf( stderr, _("sync control previously specified\n") );
exit( EXIT_FAILURE );
}
if ( cvalue == NULL ) {
fprintf( stderr, _("missing specification of sync control\n"));
exit( EXIT_FAILURE );
}
if ( strncasecmp( cvalue, "ro", 2 ) == 0 ) {
ldapsync = LDAP_SYNC_REFRESH_ONLY;
cookiep = strchr( cvalue, '/' );
if ( cookiep != NULL ) {
cookiep++;
if ( *cookiep != '\0' ) {
ber_str2bv( cookiep, 0, 0, &sync_cookie );
}
}
} else if ( strncasecmp( cvalue, "rp", 2 ) == 0 ) {
ldapsync = LDAP_SYNC_REFRESH_AND_PERSIST;
cookiep = strchr( cvalue, '/' );
if ( cookiep != NULL ) {
*cookiep++ = '\0';
cvalue = cookiep;
}
slimitp = strchr( cvalue, '/' );
if ( slimitp != NULL ) {
*slimitp++ = '\0';
}
if ( cookiep != NULL && *cookiep != '\0' )
ber_str2bv( cookiep, 0, 0, &sync_cookie );
if ( slimitp != NULL && *slimitp != '\0' ) {
ival = strtol( slimitp, &next, 10 );
if ( next == NULL || next[0] != '\0' ) {
fprintf( stderr, _("Unable to parse sync control value \"%s\"\n"), slimitp );
exit( EXIT_FAILURE );
}
sync_slimit = ival;
}
} else {
fprintf( stderr, _("sync control value \"%s\" invalid\n"),
cvalue );
exit( EXIT_FAILURE );
}
if ( crit ) ldapsync *= -1;
} else if ( strcasecmp( control, "vlv" ) == 0 ) {
if( vlv ) {
fprintf( stderr,
_("virtual list view control previously specified\n"));
exit( EXIT_FAILURE );
}
if ( pagedResults != 0 ) {
fprintf( stderr,
_("PagedResultsControl incompatible with VLV\n") );
exit( EXIT_FAILURE );
}
if( cvalue == NULL ) {
fprintf( stderr,
_("missing specification of vlv control\n") );
exit( EXIT_FAILURE );
}
if ( parse_vlv( cvalue ))
exit( EXIT_FAILURE );
vlv = 1 + crit;
#ifdef LDAP_CONTROL_X_DEREF
} else if ( strcasecmp( control, "deref" ) == 0 ) {
int ispecs;
char **specs;
/* cvalue is something like
*
* derefAttr:attr[,attr[...]][;derefAttr:attr[,attr[...]]]"
*/
specs = ldap_str2charray( cvalue, ";" );
if ( specs == NULL ) {
fprintf( stderr, _("deref specs \"%s\" invalid\n"),
cvalue );
exit( EXIT_FAILURE );
}
for ( ispecs = 0; specs[ ispecs ] != NULL; ispecs++ )
/* count'em */ ;
ds = ldap_memcalloc( ispecs + 1, sizeof( LDAPDerefSpec ) );
if ( ds == NULL ) {
perror( "malloc" );
exit( EXIT_FAILURE );
}
for ( ispecs = 0; specs[ ispecs ] != NULL; ispecs++ ) {
char *ptr;
ptr = strchr( specs[ ispecs ], ':' );
if ( ptr == NULL ) {
fprintf( stderr, _("deref specs \"%s\" invalid\n"),
cvalue );
exit( EXIT_FAILURE );
}
ds[ ispecs ].derefAttr = specs[ ispecs ];
*ptr++ = '\0';
ds[ ispecs ].attributes = ldap_str2charray( ptr, "," );
}
derefcrit = 1 + crit;
ldap_memfree( specs );
#endif /* LDAP_CONTROL_X_DEREF */
#ifdef LDAP_CONTROL_X_DIRSYNC
} else if ( strcasecmp( control, "dirSync" ) == 0 ) {
char *maxattrp;
char *cookiep;
int num, tmp;
if( dirSync ) {
fprintf( stderr,
_("dirSync control previously specified\n"));
exit( EXIT_FAILURE );
}
if ( cvalue == NULL ) {
fprintf( stderr, _("missing specification of dirSync control\n"));
exit( EXIT_FAILURE );
}
if( !crit ) {
fprintf( stderr,
_("dirSync: critical flag required\n") );
usage();
}
maxattrp = strchr( cvalue, '/' );
if ( maxattrp == NULL ) {
fprintf( stderr, _("dirSync control value \"%s\" invalid\n"),
cvalue );
exit( EXIT_FAILURE );
}
*maxattrp++ = '\0';
cookiep = strchr( maxattrp, '/' );
if ( cookiep != NULL ) {
if ( cookiep[1] != '\0' ) {
struct berval type;
int freeval;
char save1, save2;
/* dummy type "x"
* to use ldif_parse_line2() */
save1 = cookiep[ -1 ];
save2 = cookiep[ -2 ];
cookiep[ -2 ] = 'x';
cookiep[ -1 ] = ':';
cookiep[ 0 ] = ':';
ldif_parse_line2( &cookiep[ -2 ], &type,
&dirSyncCookie, &freeval );
cookiep[ -1 ] = save1;
cookiep[ -2 ] = save2;
}
*cookiep = '\0';
}
num = sscanf( cvalue, "%i", &tmp );
if ( num != 1 ) {
fprintf( stderr,
_("Invalid value for dirSync, %s.\n"),
cvalue );
exit( EXIT_FAILURE );
}
dirSyncFlags = tmp;
num = sscanf( maxattrp, "%d", &tmp );
if ( num != 1 ) {
fprintf( stderr,
_("Invalid value for dirSync, %s.\n"),
maxattrp );
exit( EXIT_FAILURE );
}
dirSyncMaxAttrCount = tmp;
dirSync = 1 + crit;
#endif /* LDAP_CONTROL_X_DIRSYNC */
#ifdef LDAP_CONTROL_X_EXTENDED_DN
} else if ( strcasecmp( control, "extendedDn" ) == 0 ) {
int num, tmp;
if( extendedDn ) {
fprintf( stderr,
_("extendedDn control previously specified\n"));
exit( EXIT_FAILURE );
}
if ( cvalue == NULL ) {
fprintf( stderr, _("missing specification of extendedDn control\n"));
exit( EXIT_FAILURE );
}
num = sscanf( cvalue, "%d", &tmp );
if ( num != 1 ) {
fprintf( stderr,
_("Invalid value for extendedDn, %s.\n"),
cvalue );
exit( EXIT_FAILURE );
}
extendedDnFlag = tmp;
extendedDn = 1 + crit;
#endif /* LDAP_CONTROL_X_EXTENDED_DN */
#ifdef LDAP_CONTROL_X_SHOW_DELETED
} else if ( strcasecmp( control, "showDeleted" ) == 0 ) {
if( showDeleted ) {
fprintf( stderr,
_("showDeleted control previously specified\n"));
exit( EXIT_FAILURE );
}
if ( cvalue != NULL ) {
fprintf( stderr,
_("showDeleted: no control value expected\n") );
usage();
}
showDeleted = 1 + crit;
#endif /* LDAP_CONTROL_X_SHOW_DELETED */
#ifdef LDAP_CONTROL_X_SERVER_NOTIFICATION
} else if ( strcasecmp( control, "serverNotif" ) == 0 ) {
if( serverNotif ) {
fprintf( stderr,
_("serverNotif control previously specified\n"));
exit( EXIT_FAILURE );
}
if ( cvalue != NULL ) {
fprintf( stderr,
_("serverNotif: no control value expected\n") );
usage();
}
serverNotif = 1 + crit;
#endif /* LDAP_CONTROL_X_SERVER_NOTIFICATION */
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
} else if ( strcasecmp( control, "accountUsability" ) == 0 ) {
if( accountUsability ) {
fprintf( stderr,
_("accountUsability control previously specified\n"));
exit( EXIT_FAILURE );
}
if( cvalue != NULL ) {
fprintf( stderr,
_("accountUsability: no control value expected\n") );
usage();
}
accountUsability = 1 + crit;
#endif /* LDAP_CONTROL_X_ACCOUNT_USABILITY */
} else if ( tool_is_oid( control ) ) {
if ( c != NULL ) {
int i;
for ( i = 0; i < nctrls; i++ ) {
if ( strcmp( control, c[ i ].ldctl_oid ) == 0 ) {
fprintf( stderr, "%s control previously specified\n", control );
exit( EXIT_FAILURE );
}
}
}
if ( ctrl_add() ) {
exit( EXIT_FAILURE );
}
/* OID */
c[ nctrls - 1 ].ldctl_oid = control;
/* value */
if ( cvalue == NULL ) {
c[ nctrls - 1 ].ldctl_value.bv_val = NULL;
c[ nctrls - 1 ].ldctl_value.bv_len = 0;
} else if ( cvalue[ 0 ] == ':' ) {
struct berval type;
struct berval value;
int freeval;
char save_c;
cvalue++;
/* dummy type "x"
* to use ldif_parse_line2() */
save_c = cvalue[ -2 ];
cvalue[ -2 ] = 'x';
ldif_parse_line2( &cvalue[ -2 ], &type,
&value, &freeval );
cvalue[ -2 ] = save_c;
if ( freeval ) {
c[ nctrls - 1 ].ldctl_value = value;
} else {
ber_dupbv( &c[ nctrls - 1 ].ldctl_value, &value );
}
} else {
fprintf( stderr, "unable to parse %s control value\n", control );
exit( EXIT_FAILURE );
}
/* criticality */
c[ nctrls - 1 ].ldctl_iscritical = crit;
} else {
fprintf( stderr, _("Invalid search extension name: %s\n"),
control );
usage();
}
break;
case 'F': /* uri prefix */
if( urlpre ) free( urlpre );
urlpre = optarg;
break;
case 'l': /* time limit */
if ( strcasecmp( optarg, "none" ) == 0 ) {
timelimit = 0;
} else if ( strcasecmp( optarg, "max" ) == 0 ) {
timelimit = LDAP_MAXINT;
} else {
ival = strtol( optarg, &next, 10 );
if ( next == NULL || next[0] != '\0' ) {
fprintf( stderr,
_("Unable to parse time limit \"%s\"\n"), optarg );
exit( EXIT_FAILURE );
}
timelimit = ival;
}
if( timelimit < 0 || timelimit > LDAP_MAXINT ) {
fprintf( stderr, _("%s: invalid timelimit (%d) specified\n"),
prog, timelimit );
exit( EXIT_FAILURE );
}
break;
case 'L': /* print entries in LDIF format */
++ldif;
break;
case 's': /* search scope */
if ( strncasecmp( optarg, "base", sizeof("base")-1 ) == 0 ) {
scope = LDAP_SCOPE_BASE;
} else if ( strncasecmp( optarg, "one", sizeof("one")-1 ) == 0 ) {
scope = LDAP_SCOPE_ONELEVEL;
} else if (( strcasecmp( optarg, "subordinate" ) == 0 )
|| ( strcasecmp( optarg, "children" ) == 0 ))
{
scope = LDAP_SCOPE_SUBORDINATE;
} else if ( strncasecmp( optarg, "sub", sizeof("sub")-1 ) == 0 ) {
scope = LDAP_SCOPE_SUBTREE;
} else {
fprintf( stderr, _("scope should be base, one, or sub\n") );
usage();
}
break;
case 'S': /* sort attribute */
sortattr = optarg;
break;
case 't': /* write attribute values to TMPDIR files */
++vals2tmp;
break;
case 'T': /* tmpdir */
if( tmpdir ) free( tmpdir );
tmpdir = optarg;
break;
case 'u': /* include UFN */
++includeufn;
break;
case 'z': /* size limit */
if ( strcasecmp( optarg, "none" ) == 0 ) {
sizelimit = 0;
} else if ( strcasecmp( optarg, "max" ) == 0 ) {
sizelimit = LDAP_MAXINT;
} else {
ival = strtol( optarg, &next, 10 );
if ( next == NULL || next[0] != '\0' ) {
fprintf( stderr,
_("Unable to parse size limit \"%s\"\n"), optarg );
exit( EXIT_FAILURE );
}
sizelimit = ival;
}
if( sizelimit < 0 || sizelimit > LDAP_MAXINT ) {
fprintf( stderr, _("%s: invalid sizelimit (%d) specified\n"),
prog, sizelimit );
exit( EXIT_FAILURE );
}
break;
default:
return 0;
}
return 1;
}
static void
private_conn_setup( LDAP *ld )
{
if (deref != -1 &&
ldap_set_option( ld, LDAP_OPT_DEREF, (void *) &deref )
!= LDAP_OPT_SUCCESS )
{
fprintf( stderr, _("Could not set LDAP_OPT_DEREF %d\n"), deref );
tool_exit( ld, EXIT_FAILURE );
}
}
int
main( int argc, char **argv )
{
char *filtpattern, **attrs = NULL, line[BUFSIZ];
FILE *fp = NULL;
int rc, rc1, i, first;
LDAP *ld = NULL;
BerElement *ber = NULL;
int err;
tool_init( TOOL_SEARCH );
npagedresponses = npagedentries = npagedreferences =
npagedextended = npagedpartial = 0;
prog = lutil_progname( "ldapsearch", argc, argv );
if((def_tmpdir = getenv("TMPDIR")) == NULL &&
(def_tmpdir = getenv("TMP")) == NULL &&
(def_tmpdir = getenv("TEMP")) == NULL )
{
def_tmpdir = LDAP_TMPDIR;
}
if ( !*def_tmpdir )
def_tmpdir = LDAP_TMPDIR;
def_urlpre = malloc( sizeof("file:////") + strlen(def_tmpdir) );
if( def_urlpre == NULL ) {
perror( "malloc" );
return EXIT_FAILURE;
}
sprintf( def_urlpre, "file:///%s/",
def_tmpdir[0] == *LDAP_DIRSEP ? &def_tmpdir[1] : def_tmpdir );
urlize( def_urlpre );
tool_args( argc, argv );
if ( vlv && !sss ) {
fprintf( stderr,
_("VLV control requires server side sort control\n" ));
return EXIT_FAILURE;
}
if (( argc - optind < 1 ) ||
( *argv[optind] != '(' /*')'*/ &&
( strchr( argv[optind], '=' ) == NULL ) ) )
{
filtpattern = "(objectclass=*)";
} else {
filtpattern = argv[optind++];
}
if ( argv[optind] != NULL ) {
attrs = &argv[optind];
}
if ( infile != NULL ) {
int percent = 0;
if ( infile[0] == '-' && infile[1] == '\0' ) {
fp = stdin;
} else if (( fp = fopen( infile, "r" )) == NULL ) {
perror( infile );
return EXIT_FAILURE;
}
for( i=0 ; filtpattern[i] ; i++ ) {
if( filtpattern[i] == '%' ) {
if( percent ) {
fprintf( stderr, _("Bad filter pattern \"%s\"\n"),
filtpattern );
return EXIT_FAILURE;
}
percent++;
if( filtpattern[i+1] != 's' ) {
fprintf( stderr, _("Bad filter pattern \"%s\"\n"),
filtpattern );
return EXIT_FAILURE;
}
}
}
}
if ( tmpdir == NULL ) {
tmpdir = def_tmpdir;
if ( urlpre == NULL )
urlpre = def_urlpre;
}
if( urlpre == NULL ) {
urlpre = malloc( sizeof("file:////") + strlen(tmpdir) );
if( urlpre == NULL ) {
perror( "malloc" );
return EXIT_FAILURE;
}
sprintf( urlpre, "file:///%s/",
tmpdir[0] == *LDAP_DIRSEP ? &tmpdir[1] : tmpdir );
urlize( urlpre );
}
if ( debug )
ldif_debug = debug;
ld = tool_conn_setup( 0, &private_conn_setup );
tool_bind( ld );
getNextPage:
/* fp may have been closed, need to reopen if code jumps
* back here to getNextPage.
*/
if ( !fp && infile ) {
if (( fp = fopen( infile, "r" )) == NULL ) {
perror( infile );
tool_exit( ld, EXIT_FAILURE );
}
}
save_nctrls = nctrls;
i = nctrls;
if ( nctrls > 0
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
|| accountUsability
#endif
#ifdef LDAP_CONTROL_DONTUSECOPY
|| dontUseCopy
#endif
#ifdef LDAP_CONTROL_X_DEREF
|| derefcrit
#endif
#ifdef LDAP_CONTROL_X_DIRSYNC
|| dirSync
#endif
#ifdef LDAP_CONTROL_X_EXTENDED_DN
|| extendedDn
#endif
#ifdef LDAP_CONTROL_X_SHOW_DELETED
|| showDeleted
#endif
#ifdef LDAP_CONTROL_X_SERVER_NOTIFICATION
|| serverNotif
#endif
|| domainScope
|| pagedResults
|| psearch
|| ldapsync
|| sss
|| subentries
|| valuesReturnFilter
|| vlv )
{
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
if ( accountUsability ) {
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_X_ACCOUNT_USABILITY;
c[i].ldctl_value.bv_val = NULL;
c[i].ldctl_value.bv_len = 0;
c[i].ldctl_iscritical = accountUsability == 2;
i++;
}
#endif
#ifdef LDAP_CONTROL_DONTUSECOPY
if ( dontUseCopy ) {
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_DONTUSECOPY;
c[i].ldctl_value.bv_val = NULL;
c[i].ldctl_value.bv_len = 0;
c[i].ldctl_iscritical = dontUseCopy == 2;
i++;
}
#endif
if ( domainScope ) {
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_X_DOMAIN_SCOPE;
c[i].ldctl_value.bv_val = NULL;
c[i].ldctl_value.bv_len = 0;
c[i].ldctl_iscritical = domainScope > 1;
i++;
}
if ( subentries ) {
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
if (( ber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
tool_exit( ld, EXIT_FAILURE );
}
err = ber_printf( ber, "b", abs(subentries) == 1 ? 0 : 1 );
if ( err == -1 ) {
ber_free( ber, 1 );
fprintf( stderr, _("Subentries control encoding error!\n") );
tool_exit( ld, EXIT_FAILURE );
}
err = ber_flatten2( ber, &c[i].ldctl_value, 1 );
ber_free( ber, 1 );
if ( err == -1 )
tool_exit( ld, EXIT_FAILURE );
c[i].ldctl_oid = LDAP_CONTROL_SUBENTRIES;
c[i].ldctl_iscritical = subentries < 1;
i++;
}
if ( ldapsync ) {
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
if (( ber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
tool_exit( ld, EXIT_FAILURE );
}
if ( sync_cookie.bv_len == 0 ) {
err = ber_printf( ber, "{e}", abs(ldapsync) );
} else {
err = ber_printf( ber, "{eO}", abs(ldapsync),
&sync_cookie );
}
if ( err == -1 ) {
ber_free( ber, 1 );
fprintf( stderr, _("ldap sync control encoding error!\n") );
tool_exit( ld, EXIT_FAILURE );
}
err = ber_flatten2( ber, &c[i].ldctl_value, 1 );
ber_free( ber, 1 );
if ( err == -1 )
tool_exit( ld, EXIT_FAILURE );
c[i].ldctl_oid = LDAP_CONTROL_SYNC;
c[i].ldctl_iscritical = ldapsync < 0;
i++;
}
if ( valuesReturnFilter ) {
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
if (( ber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
tool_exit( ld, EXIT_FAILURE );
}
if ( ( err = ldap_put_vrFilter( ber, vrFilter ) ) == -1 ) {
ber_free( ber, 1 );
fprintf( stderr, _("Bad ValuesReturnFilter: %s\n"), vrFilter );
tool_exit( ld, EXIT_FAILURE );
}
err = ber_flatten2( ber, &c[i].ldctl_value, 1 );
ber_free( ber, 1 );
if ( err == -1 )
tool_exit( ld, EXIT_FAILURE );
c[i].ldctl_oid = LDAP_CONTROL_VALUESRETURNFILTER;
c[i].ldctl_iscritical = valuesReturnFilter > 1;
i++;
}
if ( pagedResults ) {
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
if ( ldap_create_page_control_value( ld,
pageSize, &pr_cookie, &c[i].ldctl_value ) )
{
tool_exit( ld, EXIT_FAILURE );
}
if ( pr_cookie.bv_val != NULL ) {
ber_memfree( pr_cookie.bv_val );
pr_cookie.bv_val = NULL;
pr_cookie.bv_len = 0;
}
c[i].ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
c[i].ldctl_iscritical = pagedResults > 1;
i++;
}
if ( psearch ) {
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
if ( ldap_create_persistentsearch_control_value( ld,
ps_chgtypes, ps_chgsonly, ps_echg_ctrls, &c[i].ldctl_value ) )
{
tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_PERSIST_REQUEST;
c[i].ldctl_iscritical = psearch > 1;
i++;
}
if ( sss ) {
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
if ( ldap_create_sort_control_value( ld,
sss_keys, &c[i].ldctl_value ) )
{
tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_SORTREQUEST;
c[i].ldctl_iscritical = sss > 1;
i++;
}
if ( vlv ) {
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
if ( ldap_create_vlv_control_value( ld,
&vlvInfo, &c[i].ldctl_value ) )
{
tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_VLVREQUEST;
c[i].ldctl_iscritical = vlv > 1;
i++;
}
#ifdef LDAP_CONTROL_X_DEREF
if ( derefcrit ) {
if ( derefval.bv_val == NULL ) {
int i;
assert( ds != NULL );
if ( ldap_create_deref_control_value( ld, ds, &derefval ) != LDAP_SUCCESS ) {
tool_exit( ld, EXIT_FAILURE );
}
for ( i = 0; ds[ i ].derefAttr != NULL; i++ ) {
ldap_memfree( ds[ i ].derefAttr );
ldap_charray_free( ds[ i ].attributes );
}
ldap_memfree( ds );
ds = NULL;
}
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
c[ i ].ldctl_iscritical = derefcrit > 1;
c[ i ].ldctl_oid = LDAP_CONTROL_X_DEREF;
c[ i ].ldctl_value = derefval;
i++;
}
#endif /* LDAP_CONTROL_X_DEREF */
#ifdef LDAP_CONTROL_X_DIRSYNC
if ( dirSync ) {
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
if ( ldap_create_dirsync_value( ld,
dirSyncFlags, dirSyncMaxAttrCount, &dirSyncCookie,
&c[i].ldctl_value ) )
{
tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_X_DIRSYNC;
c[i].ldctl_iscritical = dirSync > 1;
i++;
}
#endif
#ifdef LDAP_CONTROL_X_EXTENDED_DN
if ( extendedDn ) {
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
if ( ldap_create_extended_dn_value( ld,
extendedDnFlag, &c[i].ldctl_value ) )
{
tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_X_EXTENDED_DN;
c[i].ldctl_iscritical = extendedDn > 1;
i++;
}
#endif
#ifdef LDAP_CONTROL_X_SHOW_DELETED
if ( showDeleted ) {
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_X_SHOW_DELETED;
c[i].ldctl_value.bv_val = NULL;
c[i].ldctl_value.bv_len = 0;
c[i].ldctl_iscritical = showDeleted > 1;
i++;
}
#endif
#ifdef LDAP_CONTROL_X_SERVER_NOTIFICATION
if ( serverNotif ) {
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_X_SERVER_NOTIFICATION;
c[i].ldctl_value.bv_val = NULL;
c[i].ldctl_value.bv_len = 0;
c[i].ldctl_iscritical = serverNotif > 1;
i++;
}
#endif
}
tool_server_controls( ld, c, i );
/* free any controls we added */
for ( ; nctrls-- > save_nctrls; ) {
if ( c[nctrls].ldctl_value.bv_val != derefval.bv_val )
ber_memfree( c[nctrls].ldctl_value.bv_val );
}
/* step back to the original number of controls, so that
* those set while parsing args are preserved */
nctrls = save_nctrls;
if ( verbose ) {
fprintf( stderr, _("filter%s: %s\nrequesting: "),
infile != NULL ? _(" pattern") : "",
filtpattern );
if ( attrs == NULL ) {
fprintf( stderr, _("All userApplication attributes") );
} else {
for ( i = 0; attrs[ i ] != NULL; ++i ) {
fprintf( stderr, "%s ", attrs[ i ] );
}
}
fprintf( stderr, "\n" );
}
if ( ldif == 0 ) {
printf( _("# extended LDIF\n") );
} else if ( ldif < 3 ) {
printf( _("version: %d\n\n"), 1 );
}
if (ldif < 2 ) {
char *realbase = base;
if ( realbase == NULL ) {
ldap_get_option( ld, LDAP_OPT_DEFBASE, (void **)(char *)&realbase );
}
printf( "#\n" );
printf(_("# LDAPv%d\n"), protocol);
printf(_("# base <%s>%s with scope %s\n"),
realbase ? realbase : "",
( realbase == NULL || realbase != base ) ? " (default)" : "",
((scope == LDAP_SCOPE_BASE) ? "baseObject"
: ((scope == LDAP_SCOPE_ONELEVEL) ? "oneLevel"
: ((scope == LDAP_SCOPE_SUBORDINATE) ? "children"
: "subtree" ))));
printf(_("# filter%s: %s\n"), infile != NULL ? _(" pattern") : "",
filtpattern);
printf(_("# requesting: "));
if ( attrs == NULL ) {
printf( _("ALL") );
} else {
for ( i = 0; attrs[ i ] != NULL; ++i ) {
printf( "%s ", attrs[ i ] );
}
}
if ( manageDSAit ) {
printf(_("\n# with manageDSAit %scontrol"),
manageDSAit > 1 ? _("critical ") : "" );
}
if ( noop ) {
printf(_("\n# with noop %scontrol"),
noop > 1 ? _("critical ") : "" );
}
if ( subentries ) {
printf(_("\n# with subentries %scontrol: %s"),
subentries < 0 ? _("critical ") : "",
abs(subentries) == 1 ? "false" : "true" );
}
if ( valuesReturnFilter ) {
printf(_("\n# with valuesReturnFilter %scontrol: %s"),
valuesReturnFilter > 1 ? _("critical ") : "", vrFilter );
}
if ( pagedResults ) {
printf(_("\n# with pagedResults %scontrol: size=%d"),
(pagedResults > 1) ? _("critical ") : "",
pageSize );
}
if ( sss ) {
printf(_("\n# with server side sorting %scontrol"),
sss > 1 ? _("critical ") : "" );
}
if ( vlv ) {
printf(_("\n# with virtual list view %scontrol: %d/%d"),
vlv > 1 ? _("critical ") : "",
vlvInfo.ldvlv_before_count, vlvInfo.ldvlv_after_count);
if ( vlvInfo.ldvlv_attrvalue )
printf(":%s", vlvInfo.ldvlv_attrvalue->bv_val );
else
printf("/%d/%d", vlvInfo.ldvlv_offset, vlvInfo.ldvlv_count );
}
#ifdef LDAP_CONTROL_X_DEREF
if ( derefcrit ) {
printf(_("\n# with dereference %scontrol"),
derefcrit > 1 ? _("critical ") : "" );
}
#endif
printf( _("\n#\n\n") );
if ( realbase && realbase != base ) {
ldap_memfree( realbase );
}
}
if ( infile == NULL ) {
rc = dosearch( ld, base, scope, NULL, filtpattern,
attrs, attrsonly, NULL, NULL, NULL, sizelimit );
} else {
rc = 0;
first = 1;
while ( fgets( line, sizeof( line ), fp ) != NULL ) {
line[ strlen( line ) - 1 ] = '\0';
if ( !first ) {
putchar( '\n' );
} else {
first = 0;
}
rc1 = dosearch( ld, base, scope, filtpattern, line,
attrs, attrsonly, NULL, NULL, NULL, sizelimit );
if ( rc1 != 0 ) {
rc = rc1;
if ( !contoper )
break;
}
}
if ( fp != stdin ) {
fclose( fp );
fp = NULL;
}
}
if (( rc == LDAP_SUCCESS ) && pageSize && pr_morePagedResults ) {
char buf[12];
int i, moreEntries, tmpSize;
/* Loop to get the next pages when
* enter is pressed on the terminal.
*/
if ( pagePrompt != 0 ) {
if ( entriesLeft > 0 ) {
printf( _("Estimate entries: %d\n"), entriesLeft );
}
printf( _("Press [size] Enter for the next {%d|size} entries.\n"),
(int)pageSize );
i = 0;
moreEntries = getchar();
while ( moreEntries != EOF && moreEntries != '\n' ) {
if ( i < (int)sizeof(buf) - 1 ) {
buf[i] = moreEntries;
i++;
}
moreEntries = getchar();
}
buf[i] = '\0';
if ( i > 0 && isdigit( (unsigned char)buf[0] ) ) {
int num = sscanf( buf, "%d", &tmpSize );
if ( num != 1 ) {
fprintf( stderr,
_("Invalid value for PagedResultsControl, %s.\n"), buf);
tool_exit( ld, EXIT_FAILURE );
}
pageSize = (ber_int_t)tmpSize;
}
}
goto getNextPage;
}
if (( rc == LDAP_SUCCESS ) && vlv ) {
char buf[BUFSIZ];
int i, moreEntries;
/* Loop to get the next window when
* enter is pressed on the terminal.
*/
printf( _("Press [before/after(/offset/count|:value)] Enter for the next window.\n"));
i = 0;
moreEntries = getchar();
while ( moreEntries != EOF && moreEntries != '\n' ) {
if ( i < (int)sizeof(buf) - 1 ) {
buf[i] = moreEntries;
i++;
}
moreEntries = getchar();
}
buf[i] = '\0';
if ( buf[0] ) {
i = parse_vlv( strdup( buf ));
if ( i )
tool_exit( ld, EXIT_FAILURE );
} else {
vlvInfo.ldvlv_attrvalue = NULL;
vlvInfo.ldvlv_count = vlvCount;
vlvInfo.ldvlv_offset += vlvInfo.ldvlv_after_count;
}
if ( vlvInfo.ldvlv_context )
ber_bvfree( vlvInfo.ldvlv_context );
vlvInfo.ldvlv_context = vlvContext;
goto getNextPage;
}
if ( sss_keys != NULL ) {
ldap_free_sort_keylist( sss_keys );
}
if ( derefval.bv_val != NULL ) {
ldap_memfree( derefval.bv_val );
}
if ( urlpre != NULL ) {
if ( def_urlpre != urlpre )
free( def_urlpre );
free( urlpre );
}
if ( c ) {
for ( ; save_nctrls-- > 0; ) {
ber_memfree( c[ save_nctrls ].ldctl_value.bv_val );
}
free( c );
c = NULL;
}
tool_exit( ld, rc );
}
static int dosearch(
LDAP *ld,
char *base,
int scope,
char *filtpatt,
char *value,
char **attrs,
int attrsonly,
LDAPControl **sctrls,
LDAPControl **cctrls,
struct timeval *timeout,
int sizelimit )
{
char *filter;
int rc, rc2 = LDAP_OTHER;
int nresponses;
int nentries;
int nreferences;
int nextended;
int npartial;
LDAPMessage *res, *msg;
ber_int_t msgid;
char *retoid = NULL;
struct berval *retdata = NULL;
int nresponses_psearch = -1;
int cancel_msgid = -1;
struct timeval tv, *tvp = NULL;
struct timeval tv_timelimit, *tv_timelimitp = NULL;
if( filtpatt != NULL ) {
size_t max_fsize = strlen( filtpatt ) + strlen( value ) + 1, outlen;
filter = malloc( max_fsize );
if( filter == NULL ) {
perror( "malloc" );
return EXIT_FAILURE;
}
outlen = snprintf( filter, max_fsize, filtpatt, value );
if( outlen >= max_fsize ) {
fprintf( stderr, "Bad filter pattern: \"%s\"\n", filtpatt );
free( filter );
return EXIT_FAILURE;
}
if ( verbose ) {
fprintf( stderr, _("filter: %s\n"), filter );
}
if( ldif < 2 ) {
printf( _("#\n# filter: %s\n#\n"), filter );
}
} else {
filter = value;
}
if ( dont ) {
if ( filtpatt != NULL ) {
free( filter );
}
return LDAP_SUCCESS;
}
if ( timelimit > 0 ) {
tv_timelimit.tv_sec = timelimit;
tv_timelimit.tv_usec = 0;
tv_timelimitp = &tv_timelimit;
}
again:
rc = ldap_search_ext( ld, base, scope, filter, attrs, attrsonly,
sctrls, cctrls, tv_timelimitp, sizelimit, &msgid );
if ( filtpatt != NULL ) {
free( filter );
}
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_search_ext", rc, NULL, NULL, NULL, NULL );
return( rc );
}
nresponses = nentries = nreferences = nextended = npartial = 0;
res = NULL;
if ( timelimit > 0 ) {
/* disable timeout */
tv.tv_sec = -1;
tv.tv_usec = 0;
tvp = &tv;
}
if ( backlog == 1 ) {
printf( _("\nWaiting for responses to accumulate, press Enter to continue: "));
fflush( stdout );
getchar();
printf( _("Abandoning msgid %d\n"), msgid );
ldap_abandon_ext( ld, msgid, NULL, NULL );
/* turn off syncrepl control */
ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, NULL );
backlog = 2;
scope = LDAP_SCOPE_BASE;
goto again;
} else if ( backlog == 2 ) {
tv.tv_sec = timelimit;
}
while ((rc = ldap_result( ld, LDAP_RES_ANY,
sortattr ? LDAP_MSG_ALL : LDAP_MSG_ONE,
tvp, &res )) > 0 )
{
if ( tool_check_abandon( ld, msgid ) ) {
return -1;
}
if( sortattr ) {
(void) ldap_sort_entries( ld, &res,
( *sortattr == '\0' ) ? NULL : sortattr, strcasecmp );
}
for ( msg = ldap_first_message( ld, res );
msg != NULL;
msg = ldap_next_message( ld, msg ) )
{
if ( nresponses++ ) putchar('\n');
if ( nresponses_psearch >= 0 )
nresponses_psearch++;
switch( ldap_msgtype( msg ) ) {
case LDAP_RES_SEARCH_ENTRY:
nentries++;
print_entry( ld, msg, attrsonly );
break;
case LDAP_RES_SEARCH_REFERENCE:
nreferences++;
print_reference( ld, msg );
break;
case LDAP_RES_EXTENDED:
nextended++;
print_extended( ld, msg );
if ( ldap_msgid( msg ) == 0 ) {
/* unsolicited extended operation */
goto done;
}
if ( cancel_msgid != -1 &&
cancel_msgid == ldap_msgid( msg ) ) {
printf(_("Cancelled \n"));
printf(_("cancel_msgid = %d\n"), cancel_msgid);
goto done;
}
break;
case LDAP_RES_SEARCH_RESULT:
/* pagedResults stuff is dealt with
* in tool_print_ctrls(), called by
* print_results(). */
rc2 = print_result( ld, msg, 1 );
if ( ldapsync == LDAP_SYNC_REFRESH_AND_PERSIST ) {
break;
}
goto done;
case LDAP_RES_INTERMEDIATE:
npartial++;
ldap_parse_intermediate( ld, msg,
&retoid, &retdata, NULL, 0 );
nresponses_psearch = 0;
if ( strcmp( retoid, LDAP_SYNC_INFO ) == 0 ) {
if ( ldif < 1 ) {
print_syncinfo( retdata );
} else if ( ldif < 2 ) {
printf(_("# SyncInfo Received\n"));
}
ldap_memfree( retoid );
ber_bvfree( retdata );
break;
}
print_partial( ld, msg );
ldap_memfree( retoid );
ber_bvfree( retdata );
goto done;
}
if ( ldapsync && sync_slimit != -1 &&
nresponses_psearch >= sync_slimit ) {
BerElement *msgidber = NULL;
struct berval msgidval;
msgidber = ber_alloc_t(LBER_USE_DER);
ber_printf(msgidber, "{i}", msgid);
ber_flatten2( msgidber, &msgidval, 0 );
ldap_extended_operation(ld, LDAP_EXOP_CANCEL,
&msgidval, NULL, NULL, &cancel_msgid);
ber_free( msgidber, 1 );
nresponses_psearch = -1;
}
}
ldap_msgfree( res );
fflush( stdout );
}
done:
if ( tvp == NULL && rc != LDAP_RES_SEARCH_RESULT ) {
ldap_get_option( ld, LDAP_OPT_RESULT_CODE, (void *)&rc2 );
}
ldap_msgfree( res );
if ( pagedResults ) {
npagedresponses += nresponses;
npagedentries += nentries;
npagedextended += nextended;
npagedpartial += npartial;
npagedreferences += nreferences;
if ( ( pr_morePagedResults == 0 ) && ( ldif < 2 ) ) {
printf( _("\n# numResponses: %d\n"), npagedresponses );
if( npagedentries ) {
printf( _("# numEntries: %d\n"), npagedentries );
}
if( npagedextended ) {
printf( _("# numExtended: %d\n"), npagedextended );
}
if( npagedpartial ) {
printf( _("# numPartial: %d\n"), npagedpartial );
}
if( npagedreferences ) {
printf( _("# numReferences: %d\n"), npagedreferences );
}
}
} else if ( ldif < 2 ) {
printf( _("\n# numResponses: %d\n"), nresponses );
if( nentries ) printf( _("# numEntries: %d\n"), nentries );
if( nextended ) printf( _("# numExtended: %d\n"), nextended );
if( npartial ) printf( _("# numPartial: %d\n"), npartial );
if( nreferences ) printf( _("# numReferences: %d\n"), nreferences );
}
if ( rc != LDAP_RES_SEARCH_RESULT ) {
tool_perror( "ldap_result", rc2, NULL, NULL, NULL, NULL );
}
return( rc2 );
}
/* This is the proposed new way of doing things.
* It is more efficient, but the API is non-standard.
*/
static void
print_entry(
LDAP *ld,
LDAPMessage *entry,
int attrsonly)
{
char *ufn = NULL;
char tmpfname[ 256 ];
char url[ 256 ];
int i, rc;
BerElement *ber = NULL;
struct berval bv, *bvals, **bvp = &bvals;
LDAPControl **ctrls = NULL;
FILE *tmpfp;
rc = ldap_get_dn_ber( ld, entry, &ber, &bv );
if ( ldif < 2 ) {
ufn = ldap_dn2ufn( bv.bv_val );
tool_write_ldif( LDIF_PUT_COMMENT, NULL, ufn, ufn ? strlen( ufn ) : 0 );
}
tool_write_ldif( LDIF_PUT_VALUE, "dn", bv.bv_val, bv.bv_len );
rc = ldap_get_entry_controls( ld, entry, &ctrls );
if( rc != LDAP_SUCCESS ) {
fprintf(stderr, _("print_entry: %d\n"), rc );
tool_perror( "ldap_get_entry_controls", rc, NULL, NULL, NULL, NULL );
tool_exit( ld, EXIT_FAILURE );
}
if( ctrls ) {
tool_print_ctrls( ld, ctrls );
ldap_controls_free( ctrls );
}
if ( includeufn ) {
if( ufn == NULL ) {
ufn = ldap_dn2ufn( bv.bv_val );
}
tool_write_ldif( LDIF_PUT_VALUE, "ufn", ufn, ufn ? strlen( ufn ) : 0 );
}
if( ufn != NULL ) ldap_memfree( ufn );
if ( attrsonly ) bvp = NULL;
for ( rc = ldap_get_attribute_ber( ld, entry, ber, &bv, bvp );
rc == LDAP_SUCCESS;
rc = ldap_get_attribute_ber( ld, entry, ber, &bv, bvp ) )
{
if (bv.bv_val == NULL) break;
if ( attrsonly ) {
tool_write_ldif( LDIF_PUT_NOVALUE, bv.bv_val, NULL, 0 );
} else if ( bvals ) {
for ( i = 0; bvals[i].bv_val != NULL; i++ ) {
if ( vals2tmp > 1 || ( vals2tmp &&
ldif_is_not_printable( bvals[i].bv_val, bvals[i].bv_len )))
{
int tmpfd;
/* write value to file */
snprintf( tmpfname, sizeof tmpfname,
"%s" LDAP_DIRSEP "ldapsearch-%s-XXXXXX",
tmpdir, bv.bv_val );
tmpfp = NULL;
tmpfd = mkstemp( tmpfname );
if ( tmpfd < 0 ) {
perror( tmpfname );
continue;
}
if (( tmpfp = fdopen( tmpfd, "w")) == NULL ) {
perror( tmpfname );
continue;
}
if ( fwrite( bvals[ i ].bv_val,
bvals[ i ].bv_len, 1, tmpfp ) == 0 )
{
perror( tmpfname );
fclose( tmpfp );
continue;
}
fclose( tmpfp );
snprintf( url, sizeof url, "%s%s", urlpre,
&tmpfname[strlen(tmpdir) + sizeof(LDAP_DIRSEP) - 1] );
urlize( url );
tool_write_ldif( LDIF_PUT_URL, bv.bv_val, url, strlen( url ));
} else {
tool_write_ldif( LDIF_PUT_VALUE, bv.bv_val,
bvals[ i ].bv_val, bvals[ i ].bv_len );
}
}
ber_memfree( bvals );
}
}
if( ber != NULL ) {
ber_free( ber, 0 );
}
}
static void print_reference(
LDAP *ld,
LDAPMessage *reference )
{
int rc;
char **refs = NULL;
LDAPControl **ctrls;
if( ldif < 2 ) {
printf(_("# search reference\n"));
}
rc = ldap_parse_reference( ld, reference, &refs, &ctrls, 0 );
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_reference", rc, NULL, NULL, NULL, NULL );
tool_exit( ld, EXIT_FAILURE );
}
if( refs ) {
int i;
for( i=0; refs[i] != NULL; i++ ) {
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
"ref", refs[i], strlen(refs[i]) );
}
ber_memvfree( (void **) refs );
}
if( ctrls ) {
tool_print_ctrls( ld, ctrls );
ldap_controls_free( ctrls );
}
}
static void print_extended(
LDAP *ld,
LDAPMessage *extended )
{
int rc;
char *retoid = NULL;
struct berval *retdata = NULL;
if( ldif < 2 ) {
printf(_("# extended result response\n"));
}
rc = ldap_parse_extended_result( ld, extended,
&retoid, &retdata, 0 );
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL );
tool_exit( ld, EXIT_FAILURE );
}
if ( ldif < 2 ) {
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
"extended", retoid, retoid ? strlen(retoid) : 0 );
}
ber_memfree( retoid );
if(retdata) {
if ( ldif < 2 ) {
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_BINARY,
"data", retdata->bv_val, retdata->bv_len );
}
ber_bvfree( retdata );
}
print_result( ld, extended, 0 );
}
static void print_syncinfo(
BerValue *data )
{
BerElement *syncinfo;
struct berval bv, cookie;
ber_tag_t tag;
ber_len_t len;
if ( (syncinfo = ber_alloc()) == NULL ) {
return;
}
ber_init2( syncinfo, data, 0 );
printf(_("# SyncInfo Received: "));
tag = ber_peek_tag( syncinfo, &len );
switch (tag) {
case LDAP_TAG_SYNC_NEW_COOKIE: {
printf(_("new cookie\n"));
ber_scanf( syncinfo, "m", &cookie );
if ( ldif_is_not_printable( cookie.bv_val, cookie.bv_len ) ) {
bv.bv_len = LUTIL_BASE64_ENCODE_LEN(
cookie.bv_len ) + 1;
bv.bv_val = ber_memalloc( bv.bv_len + 1 );
bv.bv_len = lutil_b64_ntop(
(unsigned char *) cookie.bv_val,
cookie.bv_len,
bv.bv_val, bv.bv_len );
printf(_("# cookie:: %s\n"), bv.bv_val );
ber_memfree( bv.bv_val );
} else {
printf(_("# cookie: %s\n"), cookie.bv_val );
}
} break;
case LDAP_TAG_SYNC_REFRESH_DELETE: {
ber_int_t done = 1;
printf(_("refresh delete\n"));
/* Skip sequence tag first */
ber_skip_tag( syncinfo, &len );
tag = ber_peek_tag( syncinfo, &len );
if ( tag == LDAP_TAG_SYNC_COOKIE ) {
ber_scanf( syncinfo, "m", &cookie );
if ( ldif_is_not_printable( cookie.bv_val, cookie.bv_len ) ) {
bv.bv_len = LUTIL_BASE64_ENCODE_LEN(
cookie.bv_len ) + 1;
bv.bv_val = ber_memalloc( bv.bv_len + 1 );
bv.bv_len = lutil_b64_ntop(
(unsigned char *) cookie.bv_val,
cookie.bv_len,
bv.bv_val, bv.bv_len );
printf(_("# cookie:: %s\n"), bv.bv_val );
ber_memfree( bv.bv_val );
} else {
printf(_("# cookie: %s\n"), cookie.bv_val );
}
tag = ber_peek_tag( syncinfo, &len );
}
if ( tag == LDAP_TAG_REFRESHDONE ) {
ber_get_boolean( syncinfo, &done );
}
if ( done )
printf(_("# refresh done, switching to persist stage\n"));
} break;
case LDAP_TAG_SYNC_REFRESH_PRESENT: {
ber_int_t done = 1;
printf(_("refresh present\n"));
/* Skip sequence tag first */
ber_skip_tag( syncinfo, &len );
tag = ber_peek_tag( syncinfo, &len );
if ( tag == LDAP_TAG_SYNC_COOKIE ) {
ber_scanf( syncinfo, "m", &cookie );
if ( ldif_is_not_printable( cookie.bv_val, cookie.bv_len ) ) {
bv.bv_len = LUTIL_BASE64_ENCODE_LEN(
cookie.bv_len ) + 1;
bv.bv_val = ber_memalloc( bv.bv_len + 1 );
bv.bv_len = lutil_b64_ntop(
(unsigned char *) cookie.bv_val,
cookie.bv_len,
bv.bv_val, bv.bv_len );
printf(_("# cookie:: %s\n"), bv.bv_val );
ber_memfree( bv.bv_val );
} else {
printf(_("# cookie: %s\n"), cookie.bv_val );
}
tag = ber_peek_tag( syncinfo, &len );
}
if ( tag == LDAP_TAG_REFRESHDONE ) {
ber_get_boolean( syncinfo, &done );
}
if ( done )
printf(_("# refresh done, switching to persist stage\n"));
} break;
case LDAP_TAG_SYNC_ID_SET: {
ber_int_t refreshDeletes = 0;
BerVarray uuids;
printf(_("ID Set\n"));
/* Skip sequence tag first */
ber_skip_tag( syncinfo, &len );
tag = ber_peek_tag( syncinfo, &len );
if ( tag == LDAP_TAG_SYNC_COOKIE ) {
ber_scanf( syncinfo, "m", &cookie );
if ( ldif_is_not_printable( cookie.bv_val, cookie.bv_len ) ) {
bv.bv_len = LUTIL_BASE64_ENCODE_LEN(
cookie.bv_len ) + 1;
bv.bv_val = ber_memalloc( bv.bv_len + 1 );
bv.bv_len = lutil_b64_ntop(
(unsigned char *) cookie.bv_val,
cookie.bv_len,
bv.bv_val, bv.bv_len );
printf(_("# cookie:: %s\n"), bv.bv_val );
ber_memfree( bv.bv_val );
} else {
printf(_("# cookie: %s\n"), cookie.bv_val );
}
tag = ber_peek_tag( syncinfo, &len );
}
if ( tag == LDAP_TAG_REFRESHDELETES ) {
ber_get_boolean( syncinfo, &refreshDeletes );
tag = ber_peek_tag( syncinfo, &len );
}
if ( refreshDeletes ) {
printf(_("# following UUIDs no longer match the search\n"));
}
printf(_("# syncUUIDs:\n"));
ber_scanf( syncinfo, "[W]", &uuids );
if ( uuids ) {
char buf[LDAP_LUTIL_UUIDSTR_BUFSIZE];
int i;
for ( i=0; !BER_BVISNULL( &uuids[i] ); i++ ) {
int rc = lutil_uuidstr_from_normalized(
uuids[i].bv_val, uuids[i].bv_len,
buf, LDAP_LUTIL_UUIDSTR_BUFSIZE );
if ( rc <= 0 || rc >= LDAP_LUTIL_UUIDSTR_BUFSIZE ) {
printf(_("#\t(UUID malformed)\n"));
} else {
printf(_("#\t%s\n"), buf);
}
}
ber_bvarray_free( uuids );
}
} break;
case LBER_DEFAULT:
printf(_("empty SyncInfoValue\n"));
default:
printf(_("SyncInfoValue unknown\n"));
break;
}
ber_free( syncinfo, 0 );
}
static void print_partial(
LDAP *ld,
LDAPMessage *partial )
{
int rc;
char *retoid = NULL;
struct berval *retdata = NULL;
LDAPControl **ctrls = NULL;
if( ldif < 2 ) {
printf(_("# extended partial response\n"));
}
rc = ldap_parse_intermediate( ld, partial,
&retoid, &retdata, &ctrls, 0 );
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_intermediate", rc, NULL, NULL, NULL, NULL );
tool_exit( ld, EXIT_FAILURE );
}
if ( ldif < 2 ) {
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
"partial", retoid, retoid ? strlen(retoid) : 0 );
}
ber_memfree( retoid );
if( retdata ) {
if ( ldif < 2 ) {
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_BINARY,
"data", retdata->bv_val, retdata->bv_len );
}
ber_bvfree( retdata );
}
if( ctrls ) {
tool_print_ctrls( ld, ctrls );
ldap_controls_free( ctrls );
}
}
static int print_result(
LDAP *ld,
LDAPMessage *result, int search )
{
int rc;
int err;
char *matcheddn = NULL;
char *text = NULL;
char **refs = NULL;
LDAPControl **ctrls = NULL;
if( search ) {
if ( ldif < 2 ) {
printf(_("# search result\n"));
}
if ( ldif < 1 ) {
printf("%s: %d\n", _("search"), ldap_msgid(result) );
}
}
rc = ldap_parse_result( ld, result,
&err, &matcheddn, &text, &refs, &ctrls, 0 );
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_result", rc, NULL, NULL, NULL, NULL );
tool_exit( ld, EXIT_FAILURE );
}
if( !ldif ) {
printf( _("result: %d %s\n"), err, ldap_err2string(err) );
} else if ( err != LDAP_SUCCESS ) {
fprintf( stderr, "%s (%d)\n", ldap_err2string(err), err );
}
if( matcheddn ) {
if( *matcheddn ) {
if( !ldif ) {
tool_write_ldif( LDIF_PUT_VALUE,
"matchedDN", matcheddn, strlen(matcheddn) );
} else {
fprintf( stderr, _("Matched DN: %s\n"), matcheddn );
}
}
ber_memfree( matcheddn );
}
if( text ) {
if( *text ) {
if( !ldif ) {
if ( err == LDAP_PARTIAL_RESULTS ) {
char *line;
for ( line = text; line != NULL; ) {
char *next = strchr( line, '\n' );
tool_write_ldif( LDIF_PUT_TEXT,
"text", line,
next ? (size_t) (next - line) : strlen( line ));
line = next ? next + 1 : NULL;
}
} else {
tool_write_ldif( LDIF_PUT_TEXT, "text",
text, strlen(text) );
}
} else {
fprintf( stderr, _("Additional information: %s\n"), text );
}
}
ber_memfree( text );
}
if( refs ) {
int i;
for( i=0; refs[i] != NULL; i++ ) {
if( !ldif ) {
tool_write_ldif( LDIF_PUT_VALUE, "ref", refs[i], strlen(refs[i]) );
} else {
fprintf( stderr, _("Referral: %s\n"), refs[i] );
}
}
ber_memvfree( (void **) refs );
}
pr_morePagedResults = 0;
if( ctrls ) {
tool_print_ctrls( ld, ctrls );
ldap_controls_free( ctrls );
}
return err;
}
openldap-2.5.16+dfsg/clients/tools/ldappasswd.c 0000644 0001750 0001750 00000022117 14461774414 021016 0 ustar sergio sergio /* ldappasswd -- a tool for change LDAP passwords */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* Portions Copyright 1998-2003 Kurt D. Zeilenga.
* Portions Copyright 1998-2001 Net Boolean Incorporated.
* Portions Copyright 2001-2003 IBM Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* Portions Copyright (c) 1992-1996 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.
*/
/* ACKNOWLEDGEMENTS:
* The original ldappasswd(1) tool was developed by Dave Storey (F5
* Network), based on other OpenLDAP client tools (which are, of
* course, based on U-MICH LDAP). This version was rewritten
* by Kurt D. Zeilenga (based on other OpenLDAP client tools).
*/
#include "portable.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include "lutil.h"
#include "lutil_ldap.h"
#include "ldap_defaults.h"
#include "common.h"
static struct berval newpw = { 0, NULL };
static struct berval oldpw = { 0, NULL };
static int want_newpw = 0;
static int want_oldpw = 0;
static char *oldpwfile = NULL;
static char *newpwfile = NULL;
void
usage( void )
{
fprintf( stderr, _("Change password of an LDAP user\n\n"));
fprintf( stderr,_("usage: %s [options] [user]\n"), prog);
fprintf( stderr, _(" user: the authentication identity, commonly a DN\n"));
fprintf( stderr, _("Password change options:\n"));
fprintf( stderr, _(" -a secret old password\n"));
fprintf( stderr, _(" -A prompt for old password\n"));
fprintf( stderr, _(" -t file read file for old password\n"));
fprintf( stderr, _(" -s secret new password\n"));
fprintf( stderr, _(" -S prompt for new password\n"));
fprintf( stderr, _(" -T file read file for new password\n"));
tool_common_usage();
exit( EXIT_FAILURE );
}
const char options[] = "a:As:St:T:"
"d:D:e:H:InNO:o:QR:U:vVw:WxX:y:Y:Z";
int
handle_private_option( int i )
{
switch ( i ) {
#if 0
case 'E': /* passwd extensions */ {
int crit;
char *control, *cvalue;
if( protocol == LDAP_VERSION2 ) {
fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"),
prog, protocol );
exit( EXIT_FAILURE );
}
/* should be extended to support comma separated list of
* [!]key[=value] parameters, e.g. -E !foo,bar=567
*/
crit = 0;
cvalue = NULL;
if( optarg[0] == '!' ) {
crit = 1;
optarg++;
}
control = optarg;
if ( (cvalue = strchr( control, '=' )) != NULL ) {
*cvalue++ = '\0';
}
fprintf( stderr, _("Invalid passwd extension name: %s\n"), control );
usage();
}
#endif
case 'a': /* old password (secret) */
oldpw.bv_val = strdup( optarg );
{
char* p;
for( p = optarg; *p != '\0'; p++ ) {
*p = '\0';
}
}
oldpw.bv_len = strlen( oldpw.bv_val );
break;
case 'A': /* prompt for old password */
want_oldpw++;
break;
case 's': /* new password (secret) */
newpw.bv_val = strdup( optarg );
{
char* p;
for( p = optarg; *p != '\0'; p++ ) {
*p = '\0';
}
}
newpw.bv_len = strlen( newpw.bv_val );
break;
case 'S': /* prompt for user password */
want_newpw++;
break;
case 't':
oldpwfile = optarg;
break;
case 'T':
newpwfile = optarg;
break;
default:
return 0;
}
return 1;
}
int
main( int argc, char *argv[] )
{
int rc;
char *user = NULL;
LDAP *ld = NULL;
struct berval bv = {0, NULL};
BerElement *ber = NULL;
int id, code = LDAP_OTHER;
LDAPMessage *res;
char *matcheddn = NULL, *text = NULL, **refs = NULL;
char *retoid = NULL;
struct berval *retdata = NULL;
LDAPControl **ctrls = NULL;
tool_init( TOOL_PASSWD );
prog = lutil_progname( "ldappasswd", argc, argv );
/* LDAPv3 only */
protocol = LDAP_VERSION3;
tool_args( argc, argv );
if( argc - optind > 1 ) {
usage();
} else if ( argc - optind == 1 ) {
user = strdup( argv[optind] );
} else {
user = NULL;
}
if( oldpwfile ) {
rc = lutil_get_filed_password( oldpwfile, &oldpw );
if( rc ) {
rc = EXIT_FAILURE;
goto done;
}
}
if( want_oldpw && oldpw.bv_val == NULL ) {
/* prompt for old password */
char *ckoldpw;
oldpw.bv_val = strdup(getpassphrase(_("Old password: ")));
ckoldpw = getpassphrase(_("Re-enter old password: "));
if( oldpw.bv_val == NULL || ckoldpw == NULL ||
strcmp( oldpw.bv_val, ckoldpw ))
{
fprintf( stderr, _("passwords do not match\n") );
rc = EXIT_FAILURE;
goto done;
}
oldpw.bv_len = strlen( oldpw.bv_val );
}
if( newpwfile ) {
rc = lutil_get_filed_password( newpwfile, &newpw );
if( rc ) {
rc = EXIT_FAILURE;
goto done;
}
}
if( want_newpw && newpw.bv_val == NULL ) {
/* prompt for new password */
char *cknewpw;
newpw.bv_val = strdup(getpassphrase(_("New password: ")));
cknewpw = getpassphrase(_("Re-enter new password: "));
if( newpw.bv_val == NULL || cknewpw == NULL ||
strcmp( newpw.bv_val, cknewpw ))
{
fprintf( stderr, _("passwords do not match\n") );
rc = EXIT_FAILURE;
goto done;
}
newpw.bv_len = strlen( newpw.bv_val );
}
ld = tool_conn_setup( 0, 0 );
tool_bind( ld );
if( user != NULL || oldpw.bv_val != NULL || newpw.bv_val != NULL ) {
/* build the password modify request data */
ber = ber_alloc_t( LBER_USE_DER );
if( ber == NULL ) {
perror( "ber_alloc_t" );
rc = EXIT_FAILURE;
goto done;
}
ber_printf( ber, "{" /*}*/ );
if( user != NULL ) {
ber_printf( ber, "ts",
LDAP_TAG_EXOP_MODIFY_PASSWD_ID, user );
free(user);
}
if( oldpw.bv_val != NULL ) {
ber_printf( ber, "tO",
LDAP_TAG_EXOP_MODIFY_PASSWD_OLD, &oldpw );
free(oldpw.bv_val);
}
if( newpw.bv_val != NULL ) {
ber_printf( ber, "tO",
LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, &newpw );
free(newpw.bv_val);
}
ber_printf( ber, /*{*/ "N}" );
rc = ber_flatten2( ber, &bv, 0 );
if( rc < 0 ) {
perror( "ber_flatten2" );
rc = EXIT_FAILURE;
goto done;
}
}
if ( dont ) {
rc = LDAP_SUCCESS;
goto done;
}
tool_server_controls( ld, NULL, 0);
rc = ldap_extended_operation( ld,
LDAP_EXOP_MODIFY_PASSWD, bv.bv_val ? &bv : NULL,
NULL, NULL, &id );
ber_free( ber, 1 );
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_extended_operation", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto done;
}
for ( ; ; ) {
struct timeval tv;
if ( tool_check_abandon( ld, id ) ) {
tool_exit( ld, LDAP_CANCELLED );
}
tv.tv_sec = 0;
tv.tv_usec = 100000;
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
tool_exit( ld, rc );
}
if ( rc != 0 ) {
break;
}
}
rc = ldap_parse_result( ld, res,
&code, &matcheddn, &text, &refs, &ctrls, 0 );
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_result", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto done;
}
rc = ldap_parse_extended_result( ld, res, &retoid, &retdata, 1 );
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto done;
}
if( retdata != NULL ) {
ber_tag_t tag;
char *s;
ber = ber_init( retdata );
if( ber == NULL ) {
perror( "ber_init" );
rc = EXIT_FAILURE;
goto done;
}
/* we should check the tag */
tag = ber_scanf( ber, "{a}", &s);
if( tag == LBER_ERROR ) {
perror( "ber_scanf" );
} else {
printf(_("New password: %s\n"), s);
ber_memfree( s );
}
ber_free( ber, 1 );
} else if ( code == LDAP_SUCCESS && newpw.bv_val == NULL ) {
tool_perror( "ldap_parse_extended_result", LDAP_DECODING_ERROR,
" new password expected", NULL, NULL, NULL );
}
if( verbose || code != LDAP_SUCCESS ||
( matcheddn && *matcheddn ) || ( text && *text ) || refs || ctrls )
{
printf( _("Result: %s (%d)\n"), ldap_err2string( code ), code );
if( text && *text ) {
printf( _("Additional info: %s\n"), text );
}
if( matcheddn && *matcheddn ) {
printf( _("Matched DN: %s\n"), matcheddn );
}
if( refs ) {
int i;
for( i=0; refs[i]; i++ ) {
printf(_("Referral: %s\n"), refs[i] );
}
}
if( ctrls ) {
tool_print_ctrls( ld, ctrls );
ldap_controls_free( ctrls );
}
}
ber_memfree( text );
ber_memfree( matcheddn );
ber_memvfree( (void **) refs );
ber_memfree( retoid );
ber_bvfree( retdata );
rc = ( code == LDAP_SUCCESS ) ? EXIT_SUCCESS : EXIT_FAILURE;
done:
/* disconnect from server */
tool_exit( ld, rc );
}
openldap-2.5.16+dfsg/clients/tools/ldapexop.c 0000644 0001750 0001750 00000016652 14461774414 020477 0 ustar sergio sergio /* ldapexop.c -- a tool for performing well-known extended operations */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 2005-2022 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* ACKNOWLEDGEMENTS:
* This work was originally developed by Pierangelo Masarati for inclusion
* in OpenLDAP Software based, in part, on other client tools.
*/
#include "portable.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include "ldif.h"
#include "lutil.h"
#include "lutil_ldap.h"
#include "ldap_defaults.h"
#include "common.h"
void
usage( void )
{
fprintf( stderr, _("Issue LDAP extended operations\n\n"));
fprintf( stderr, _("usage: %s [options] \n"), prog);
fprintf( stderr, _(" %s [options] whoami\n"), prog);
fprintf( stderr, _(" %s [options] cancel \n"), prog);
fprintf( stderr, _(" %s [options] refresh []\n"), prog);
tool_common_usage();
exit( EXIT_FAILURE );
}
const char options[] = ""
"d:D:e:H:InNO:o:QR:U:vVw:WxX:y:Y:Z";
int
handle_private_option( int i )
{
switch ( i ) {
default:
return 0;
}
return 1;
}
int
main( int argc, char *argv[] )
{
int rc;
LDAP *ld = NULL;
char *matcheddn = NULL, *text = NULL, **refs = NULL;
LDAPControl **ctrls = NULL;
int id, code;
LDAPMessage *res = NULL;
tool_init( TOOL_EXOP );
prog = lutil_progname( "ldapexop", argc, argv );
/* LDAPv3 only */
protocol = LDAP_VERSION3;
tool_args( argc, argv );
if ( argc - optind < 1 ) {
usage();
}
ld = tool_conn_setup( 0, 0 );
tool_bind( ld );
argv += optind;
argc -= optind;
if ( strcasecmp( argv[ 0 ], "whoami" ) == 0 ) {
tool_server_controls( ld, NULL, 0 );
rc = ldap_whoami( ld, NULL, NULL, &id );
if ( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_extended_operation", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto skip;
}
} else if ( strcasecmp( argv[ 0 ], "cancel" ) == 0 ) {
int cancelid;
switch ( argc ) {
case 2:
if ( lutil_atoi( &cancelid, argv[ 1 ] ) != 0 || cancelid < 0 ) {
fprintf( stderr, "invalid cancelid=%s\n\n", argv[ 1 ] );
usage();
}
break;
default:
fprintf( stderr, "need cancelid\n\n" );
usage();
}
rc = ldap_cancel( ld, cancelid, NULL, NULL, &id );
if ( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_cancel", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto skip;
}
} else if ( strcasecmp( argv[ 0 ], "passwd" ) == 0 ) {
fprintf( stderr, "use ldappasswd(1) instead.\n\n" );
usage();
/* TODO? */
} else if ( strcasecmp( argv[ 0 ], "refresh" ) == 0 ) {
int ttl = 3600;
struct berval dn;
switch ( argc ) {
case 3:
ttl = atoi( argv[ 2 ] );
case 2:
dn.bv_val = argv[ 1 ];
dn.bv_len = strlen( dn.bv_val );
break;
default:
fprintf( stderr, _("need DN [ttl]\n\n") );
usage();
}
tool_server_controls( ld, NULL, 0 );
rc = ldap_refresh( ld, &dn, ttl, NULL, NULL, &id );
if ( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_extended_operation", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto skip;
}
} else {
char *p;
if ( argc != 1 ) {
usage();
}
p = strchr( argv[ 0 ], ':' );
if ( p == argv[ 0 ] ) {
usage();
}
if ( p != NULL )
*p++ = '\0';
if ( tool_is_oid( argv[ 0 ] ) ) {
struct berval reqdata;
struct berval type;
struct berval value;
int freeval;
if ( p != NULL ) {
p[ -1 ] = ':';
ldif_parse_line2( argv[ 0 ], &type, &value, &freeval );
p[ -1 ] = '\0';
if ( freeval ) {
reqdata = value;
} else {
ber_dupbv( &reqdata, &value );
}
}
tool_server_controls( ld, NULL, 0 );
rc = ldap_extended_operation( ld, argv[ 0 ], p ? &reqdata : NULL, NULL, NULL, &id );
if ( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_extended_operation", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto skip;
}
} else {
fprintf( stderr, "unknown exop \"%s\"\n\n", argv[ 0 ] );
usage();
}
}
for ( ; ; ) {
struct timeval tv;
if ( tool_check_abandon( ld, id ) ) {
tool_exit( ld, LDAP_CANCELLED );
}
tv.tv_sec = 0;
tv.tv_usec = 100000;
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto skip;
}
if ( rc != 0 ) {
break;
}
}
rc = ldap_parse_result( ld, res,
&code, &matcheddn, &text, &refs, &ctrls, 0 );
if ( rc == LDAP_SUCCESS ) {
rc = code;
}
if ( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_result", rc, NULL, matcheddn, text, refs );
rc = EXIT_FAILURE;
goto skip;
}
if ( strcasecmp( argv[ 0 ], "whoami" ) == 0 ) {
char *retoid = NULL;
struct berval *retdata = NULL;
rc = ldap_parse_extended_result( ld, res, &retoid, &retdata, 0 );
if ( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto skip;
}
if ( retdata != NULL ) {
if ( retdata->bv_len == 0 ) {
printf(_("anonymous\n") );
} else {
printf("%s\n", retdata->bv_val );
}
}
ber_memfree( retoid );
ber_bvfree( retdata );
} else if ( strcasecmp( argv[ 0 ], "cancel" ) == 0 ) {
/* no extended response; returns specific errors */
assert( 0 );
} else if ( strcasecmp( argv[ 0 ], "passwd" ) == 0 ) {
/* TODO */
} else if ( strcasecmp( argv[ 0 ], "refresh" ) == 0 ) {
int newttl;
rc = ldap_parse_refresh( ld, res, &newttl );
if ( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_refresh", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto skip;
}
printf( "newttl=%d\n", newttl );
} else if ( tool_is_oid( argv[ 0 ] ) ) {
char *retoid = NULL;
struct berval *retdata = NULL;
if( ldif < 2 ) {
printf(_("# extended operation response\n"));
}
rc = ldap_parse_extended_result( ld, res, &retoid, &retdata, 0 );
if ( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto skip;
}
if ( ldif < 2 && retoid != NULL ) {
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
"oid", retoid, strlen(retoid) );
}
ber_memfree( retoid );
if( retdata != NULL ) {
if ( ldif < 2 ) {
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_BINARY,
"data", retdata->bv_val, retdata->bv_len );
}
ber_bvfree( retdata );
}
}
if( verbose || code != LDAP_SUCCESS ||
( matcheddn && *matcheddn ) || ( text && *text ) || refs ) {
printf( _("Result: %s (%d)\n"), ldap_err2string( code ), code );
if( text && *text ) {
printf( _("Additional info: %s\n"), text );
}
if( matcheddn && *matcheddn ) {
printf( _("Matched DN: %s\n"), matcheddn );
}
if( refs ) {
int i;
for( i=0; refs[i]; i++ ) {
printf(_("Referral: %s\n"), refs[i] );
}
}
}
if (ctrls) {
tool_print_ctrls( ld, ctrls );
ldap_controls_free( ctrls );
}
ber_memfree( text );
ber_memfree( matcheddn );
ber_memvfree( (void **) refs );
skip:
/* disconnect from server */
if ( res )
ldap_msgfree( res );
tool_exit( ld, rc );
}
openldap-2.5.16+dfsg/clients/tools/ldapmodrdn.c 0000644 0001750 0001750 00000017665 14461774414 021014 0 ustar sergio sergio /* ldapmodrdn.c - generic program to modify an entry's RDN using LDAP */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* Portions Copyright 1998-2003 Kurt D. Zeilenga.
* Portions Copyright 1998-2001 Net Boolean Incorporated.
* Portions Copyright 2001-2003 IBM Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* Portions Copyright 1999, Juan C. Gomez, All rights reserved.
* This software is not subject to any license of Silicon Graphics
* Inc. or Purdue University.
*
* Redistribution and use in source and binary forms are permitted
* without restriction or fee of any kind as long as this notice
* is preserved.
*/
/* Portions Copyright (c) 1992-1996 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.
*/
/* ACKNOWLEDGEMENTS:
* This work was originally developed by the University of Michigan
* (as part of U-MICH LDAP). Additional significant contributors
* include:
* Kurt D. Zeilenga
* Juan C Gomez
*/
#include "portable.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include "lutil.h"
#include "lutil_ldap.h"
#include "ldap_defaults.h"
#include "common.h"
static char *newSuperior = NULL;
static int remove_old_RDN = 0;
static int domodrdn(
LDAP *ld,
char *dn,
char *rdn,
char *newSuperior,
int remove ); /* flag: remove old RDN */
void
usage( void )
{
fprintf( stderr, _("Rename LDAP entries\n\n"));
fprintf( stderr, _("usage: %s [options] [dn rdn]\n"), prog);
fprintf( stderr, _(" dn rdn: If given, rdn will replace the RDN of the entry specified by DN\n"));
fprintf( stderr, _(" If not given, the list of modifications is read from stdin or\n"));
fprintf( stderr, _(" from the file specified by \"-f file\" (see man page).\n"));
fprintf( stderr, _("Rename options:\n"));
fprintf( stderr, _(" -c continuous operation mode (do not stop on errors)\n"));
fprintf( stderr, _(" -f file read operations from `file'\n"));
fprintf( stderr, _(" -M enable Manage DSA IT control (-MM to make critical)\n"));
fprintf( stderr, _(" -P version protocol version (default: 3)\n"));
fprintf( stderr, _(" -r remove old RDN\n"));
fprintf( stderr, _(" -s newsup new superior entry\n"));
tool_common_usage();
exit( EXIT_FAILURE );
}
const char options[] = "rs:"
"cd:D:e:f:H:IMnNO:o:P:QR:U:vVw:WxX:y:Y:Z";
int
handle_private_option( int i )
{
switch ( i ) {
#if 0
int crit;
char *control, *cvalue;
case 'E': /* modrdn extensions */
if( protocol == LDAP_VERSION2 ) {
fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"),
prog, version );
exit( EXIT_FAILURE );
}
/* should be extended to support comma separated list of
* [!]key[=value] parameters, e.g. -E !foo,bar=567
*/
crit = 0;
cvalue = NULL;
if( optarg[0] == '!' ) {
crit = 1;
optarg++;
}
control = optarg;
if ( (cvalue = strchr( control, '=' )) != NULL ) {
*cvalue++ = '\0';
}
fprintf( stderr, _("Invalid modrdn extension name: %s\n"), control );
usage();
#endif
case 'r': /* remove old RDN */
remove_old_RDN++;
break;
case 's': /* newSuperior */
if( protocol == LDAP_VERSION2 ) {
fprintf( stderr, _("%s: -X incompatible with LDAPv%d\n"),
prog, protocol );
exit( EXIT_FAILURE );
}
newSuperior = optarg;
protocol = LDAP_VERSION3;
break;
default:
return 0;
}
return 1;
}
int
main(int argc, char **argv)
{
char *entrydn = NULL, *rdn = NULL, buf[ 4096 ];
FILE *fp = NULL;
LDAP *ld = NULL;
int rc, retval, havedn;
tool_init( TOOL_MODRDN );
prog = lutil_progname( "ldapmodrdn", argc, argv );
tool_args( argc, argv );
havedn = 0;
if (argc - optind == 2) {
if (( rdn = strdup( argv[argc - 1] )) == NULL ) {
perror( "strdup" );
retval = EXIT_FAILURE;
goto fail;
}
if (( entrydn = strdup( argv[argc - 2] )) == NULL ) {
perror( "strdup" );
retval = EXIT_FAILURE;
goto fail;
}
++havedn;
} else if ( argc - optind != 0 ) {
fprintf( stderr, _("%s: invalid number of arguments (%d), only two allowed\n"), prog, argc-optind );
usage();
}
if ( infile != NULL ) {
if (( fp = fopen( infile, "r" )) == NULL ) {
perror( infile );
retval = EXIT_FAILURE;
goto fail;
}
} else {
fp = stdin;
}
ld = tool_conn_setup( 0, 0 );
tool_bind( ld );
tool_server_controls( ld, NULL, 0 );
retval = rc = 0;
if (havedn)
retval = domodrdn( ld, entrydn, rdn, newSuperior, remove_old_RDN );
else while ((rc == 0 || contoper) && fgets(buf, sizeof(buf), fp) != NULL) {
if ( *buf != '\n' ) { /* blank lines optional, skip */
buf[ strlen( buf ) - 1 ] = '\0'; /* remove nl */
if ( havedn ) { /* have DN, get RDN */
if (( rdn = strdup( buf )) == NULL ) {
perror( "strdup" );
retval = EXIT_FAILURE;
goto fail;
}
rc = domodrdn(ld, entrydn, rdn, newSuperior, remove_old_RDN );
if ( rc != 0 )
retval = rc;
havedn = 0;
free( rdn ); rdn = NULL;
free( entrydn ); entrydn = NULL;
} else if ( !havedn ) { /* don't have DN yet */
if (( entrydn = strdup( buf )) == NULL ) {
retval = EXIT_FAILURE;
goto fail;
}
++havedn;
}
}
}
fail:
if ( fp && fp != stdin ) fclose( fp );
if ( entrydn ) free( entrydn );
if ( rdn ) free( rdn );
tool_exit( ld, retval );
}
static int domodrdn(
LDAP *ld,
char *dn,
char *rdn,
char *newSuperior,
int remove ) /* flag: remove old RDN */
{
int rc, code, id;
char *matcheddn=NULL, *text=NULL, **refs=NULL;
LDAPControl **ctrls = NULL;
LDAPMessage *res;
if ( verbose ) {
printf( _("Renaming \"%s\"\n"), dn );
printf( _("\tnew rdn=\"%s\" (%s old rdn)\n"),
rdn, remove ? _("delete") : _("keep") );
if( newSuperior != NULL ) {
printf(_("\tnew parent=\"%s\"\n"), newSuperior);
}
}
if( dont ) return LDAP_SUCCESS;
rc = ldap_rename( ld, dn, rdn, newSuperior, remove,
NULL, NULL, &id );
if ( rc != LDAP_SUCCESS ) {
fprintf( stderr, "%s: ldap_rename: %s (%d)\n",
prog, ldap_err2string( rc ), rc );
return rc;
}
for ( ; ; ) {
struct timeval tv = { 0, 0 };
if ( tool_check_abandon( ld, id ) ) {
return LDAP_CANCELLED;
}
tv.tv_sec = 0;
tv.tv_usec = 100000;
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
return rc;
}
if ( rc != 0 ) {
break;
}
}
rc = ldap_parse_result( ld, res, &code, &matcheddn, &text, &refs, &ctrls, 1 );
if( rc != LDAP_SUCCESS ) {
fprintf( stderr, "%s: ldap_parse_result: %s (%d)\n",
prog, ldap_err2string( rc ), rc );
return rc;
}
if( verbose || code != LDAP_SUCCESS ||
(matcheddn && *matcheddn) || (text && *text) || (refs && *refs) )
{
printf( _("Rename Result: %s (%d)\n"),
ldap_err2string( code ), code );
if( text && *text ) {
printf( _("Additional info: %s\n"), text );
}
if( matcheddn && *matcheddn ) {
printf( _("Matched DN: %s\n"), matcheddn );
}
if( refs ) {
int i;
for( i=0; refs[i]; i++ ) {
printf(_("Referral: %s\n"), refs[i] );
}
}
}
if (ctrls) {
tool_print_ctrls( ld, ctrls );
ldap_controls_free( ctrls );
}
ber_memfree( text );
ber_memfree( matcheddn );
ber_memvfree( (void **) refs );
return code;
}
openldap-2.5.16+dfsg/clients/tools/ldapvc.c 0000644 0001750 0001750 00000031623 14461774414 020127 0 ustar sergio sergio /* ldapvc.c -- a tool for verifying credentials */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* Portions Copyright 2010 Kurt D. Zeilenga.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* Portions Copyright (c) 1992-1996 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.
*/
/* ACKNOWLEDGEMENTS:
* This work was originally developed by Kurt D. Zeilenga for inclusion
* in OpenLDAP Software based, in part, on other client tools.
*/
#include "portable.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include "lutil.h"
#include "lutil_ldap.h"
#include "ldap_defaults.h"
#include "common.h"
static int req_authzid = 0;
static int req_pp = 0;
#if defined(LDAP_API_FEATURES_VERIFY_CREDENTIALS_INTERACTIVE) && defined(HAVE_CYRUS_SASL)
#define LDAP_SASL_NONE (~0U)
static unsigned vc_sasl = LDAP_SASL_NONE;
static char *vc_sasl_realm = NULL;
static char *vc_sasl_authcid = NULL;
static char *vc_sasl_authzid = NULL;
static char *vc_sasl_mech = NULL;
static char *vc_sasl_secprops = NULL;
#endif
static char * dn = NULL;
static struct berval cred = {0, NULL};
void
usage( void )
{
fprintf( stderr, _("Issue LDAP Verify Credentials operation to verify a user's credentials\n\n"));
fprintf( stderr, _("usage: %s [options] [DN [cred]])\n"), prog);
fprintf( stderr, _("where:\n"));
fprintf( stderr, _(" DN\tDistinguished Name\n"));
fprintf( stderr, _(" cred\tCredentials (prompt if not present)\n"));
fprintf( stderr, _("options:\n"));
fprintf( stderr, _(" -a\tRequest AuthzId\n"));
fprintf( stderr, _(" -b\tRequest Password Policy Information\n"));
fprintf( stderr, _(" -E sasl=(a[utomatic]|i[nteractive]|q[uiet]>\tSASL mode (defaults to automatic if any other -E option provided, otherwise none))\n"));
fprintf( stderr, _(" -E mech=\tSASL mechanism (default "" e.g. Simple)\n"));
fprintf( stderr, _(" -E realm=\tSASL Realm (defaults to none)\n"));
fprintf( stderr, _(" -E authcid=\tSASL Authentication Identity (defaults to USER)\n"));
fprintf( stderr, _(" -E authzid=\tSASL Authorization Identity (defaults to none)\n"));
fprintf( stderr, _(" -E secprops=\tSASL Security Properties (defaults to none)\n"));
tool_common_usage();
exit( EXIT_FAILURE );
}
const char options[] = "abE:"
"d:D:e:H:InNO:o:QR:U:vVw:WxX:y:Y:Z";
int
handle_private_option( int i )
{
switch ( i ) {
char *control, *cvalue;
case 'E': /* vc extension */
if( protocol == LDAP_VERSION2 ) {
fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"),
prog, protocol );
exit( EXIT_FAILURE );
}
/* should be extended to support comma separated list of
* [!]key[=value] parameters, e.g. -E !foo,bar=567
*/
cvalue = NULL;
if( optarg[0] == '!' ) {
optarg++;
}
control = optarg;
if ( (cvalue = strchr( control, '=' )) != NULL ) {
*cvalue++ = '\0';
}
if (strcasecmp(control, "sasl") == 0) {
#if defined(LDAP_API_FEATURES_VERIFY_CREDENTIALS_INTERACTIVE) && defined(HAVE_CYRUS_SASL)
if (vc_sasl != LDAP_SASL_NONE) {
fprintf(stderr,
_("SASL option previously specified\n"));
exit(EXIT_FAILURE);
}
if (cvalue == NULL) {
fprintf(stderr,
_("missing mode in SASL option\n"));
exit(EXIT_FAILURE);
}
switch (*cvalue) {
case 'a':
case 'A':
vc_sasl = LDAP_SASL_AUTOMATIC;
break;
case 'i':
case 'I':
vc_sasl = LDAP_SASL_INTERACTIVE;
break;
case 'q':
case 'Q':
vc_sasl = LDAP_SASL_QUIET;
break;
default:
fprintf(stderr,
_("unknown mode %s in SASL option\n"), cvalue);
exit(EXIT_FAILURE);
}
#else
fprintf(stderr,
_("%s: not compiled with SASL support\n"), prog);
exit(EXIT_FAILURE);
#endif
} else if (strcasecmp(control, "mech") == 0) {
#if defined(LDAP_API_FEATURES_VERIFY_CREDENTIALS_INTERACTIVE) && defined(HAVE_CYRUS_SASL)
if (vc_sasl_mech) {
fprintf(stderr,
_("SASL mech previously specified\n"));
exit(EXIT_FAILURE);
}
if (cvalue == NULL) {
fprintf(stderr,
_("missing mech in SASL option\n"));
exit(EXIT_FAILURE);
}
vc_sasl_mech = ber_strdup(cvalue);
#else
#endif
} else if (strcasecmp(control, "realm") == 0) {
#if defined(LDAP_API_FEATURES_VERIFY_CREDENTIALS_INTERACTIVE) && defined(HAVE_CYRUS_SASL)
if (vc_sasl_realm) {
fprintf(stderr,
_("SASL realm previously specified\n"));
exit(EXIT_FAILURE);
}
if (cvalue == NULL) {
fprintf(stderr,
_("missing realm in SASL option\n"));
exit(EXIT_FAILURE);
}
vc_sasl_realm = ber_strdup(cvalue);
#else
fprintf(stderr,
_("%s: not compiled with SASL support\n"), prog);
exit(EXIT_FAILURE);
#endif
} else if (strcasecmp(control, "authcid") == 0) {
#if defined(LDAP_API_FEATURES_VERIFY_CREDENTIALS_INTERACTIVE) && defined(HAVE_CYRUS_SASL)
if (vc_sasl_authcid) {
fprintf(stderr,
_("SASL authcid previously specified\n"));
exit(EXIT_FAILURE);
}
if (cvalue == NULL) {
fprintf(stderr,
_("missing authcid in SASL option\n"));
exit(EXIT_FAILURE);
}
vc_sasl_authcid = ber_strdup(cvalue);
#else
fprintf(stderr,
_("%s: not compiled with SASL support\n"), prog);
exit(EXIT_FAILURE);
#endif
} else if (strcasecmp(control, "authzid") == 0) {
#if defined(LDAP_API_FEATURES_VERIFY_CREDENTIALS_INTERACTIVE) && defined(HAVE_CYRUS_SASL)
if (vc_sasl_authzid) {
fprintf(stderr,
_("SASL authzid previously specified\n"));
exit(EXIT_FAILURE);
}
if (cvalue == NULL) {
fprintf(stderr,
_("missing authzid in SASL option\n"));
exit(EXIT_FAILURE);
}
vc_sasl_authzid = ber_strdup(cvalue);
#else
fprintf(stderr,
_("%s: not compiled with SASL support\n"), prog);
exit(EXIT_FAILURE);
#endif
} else if (strcasecmp(control, "secprops") == 0) {
#if defined(LDAP_API_FEATURES_VERIFY_CREDENTIALS_INTERACTIVE) && defined(HAVE_CYRUS_SASL)
if (vc_sasl_secprops) {
fprintf(stderr,
_("SASL secprops previously specified\n"));
exit(EXIT_FAILURE);
}
if (cvalue == NULL) {
fprintf(stderr,
_("missing secprops in SASL option\n"));
exit(EXIT_FAILURE);
}
vc_sasl_secprops = ber_strdup(cvalue);
#else
fprintf(stderr,
_("%s: not compiled with SASL support\n"), prog);
exit(EXIT_FAILURE);
#endif
} else {
fprintf( stderr, _("Invalid Verify Credentials extension name: %s\n"), control );
usage();
}
break;
case 'a': /* request authzid */
req_authzid++;
break;
case 'b': /* request authzid */
req_pp++;
break;
default:
return 0;
}
return 1;
}
int
main( int argc, char *argv[] )
{
int rc;
LDAP *ld = NULL;
char *matcheddn = NULL, *text = NULL, **refs = NULL;
int rcode;
char * diag = NULL;
struct berval *scookie = NULL;
struct berval *scred = NULL;
int id, code = 0;
LDAPMessage *res;
LDAPControl **ctrls = NULL;
LDAPControl **vcctrls = NULL;
int nvcctrls = 0;
tool_init( TOOL_VC );
prog = lutil_progname( "ldapvc", argc, argv );
/* LDAPv3 only */
protocol = LDAP_VERSION3;
tool_args( argc, argv );
if (argc - optind > 0) {
dn = argv[optind++];
}
if (argc - optind > 0) {
cred.bv_val = strdup(argv[optind++]);
cred.bv_len = strlen(cred.bv_val);
}
if (argc - optind > 0) {
usage();
}
if (dn
#ifdef LDAP_API_FEATURE_VERIFY_CREDENTIALS_INTERACTIVE
&& !vc_sasl_mech
#endif
&& !cred.bv_val)
{
cred.bv_val = strdup(getpassphrase(_("User's password: ")));
cred.bv_len = strlen(cred.bv_val);
}
#ifdef LDAP_API_FEATURE_VERIFY_CREDENTIALS_INTERACTIVE
if (vc_sasl_mech && (vc_sasl == LDAP_SASL_NONE)) {
vc_sasl = LDAP_SASL_AUTOMATIC;
}
#endif
ld = tool_conn_setup( 0, 0 );
tool_bind( ld );
if ( dont ) {
rc = LDAP_SUCCESS;
goto skip;
}
tool_server_controls( ld, NULL, 0 );
if (req_authzid) {
vcctrls = (LDAPControl **) malloc(3*sizeof(LDAPControl *));
vcctrls[nvcctrls] = (LDAPControl *) malloc(sizeof(LDAPControl));
vcctrls[nvcctrls]->ldctl_oid = ldap_strdup(LDAP_CONTROL_AUTHZID_REQUEST);
vcctrls[nvcctrls]->ldctl_iscritical = 0;
vcctrls[nvcctrls]->ldctl_value.bv_val = NULL;
vcctrls[nvcctrls]->ldctl_value.bv_len = 0;
vcctrls[++nvcctrls] = NULL;
}
if (req_pp) {
if (!vcctrls) vcctrls = (LDAPControl **) malloc(3*sizeof(LDAPControl *));
vcctrls[nvcctrls] = (LDAPControl *) malloc(sizeof(LDAPControl));
vcctrls[nvcctrls]->ldctl_oid = ldap_strdup(LDAP_CONTROL_PASSWORDPOLICYREQUEST);
vcctrls[nvcctrls]->ldctl_iscritical = 0;
vcctrls[nvcctrls]->ldctl_value.bv_val = NULL;
vcctrls[nvcctrls]->ldctl_value.bv_len = 0;
vcctrls[++nvcctrls] = NULL;
}
#ifdef LDAP_API_FEATURE_VERIFY_CREDENTIALS_INTERACTIVE
#ifdef HAVE_CYRUS_SASL
if (vc_sasl_mech) {
int msgid;
void * defaults;
void * context = NULL;
const char *rmech = NULL;
defaults = lutil_sasl_defaults(ld,
vc_sasl_mech,
vc_sasl_realm,
vc_sasl_authcid,
cred.bv_val,
sasl_authz_id);
do {
rc = ldap_verify_credentials_interactive(ld, dn, vc_sasl_mech,
vcctrls, NULL, NULL,
vc_sasl, lutil_sasl_interact, defaults, context,
res, &rmech, &msgid);
if (rc != LDAP_SASL_BIND_IN_PROGRESS) break;
ldap_msgfree(res);
if (ldap_result(ld, msgid, LDAP_MSG_ALL, NULL, &res) == -1 || !res) {
ldap_get_option(ld, LDAP_OPT_RESULT_CODE, (void*) &rc);
ldap_get_option(ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void*) &text);
tool_perror( "ldap_verify_credentials_interactive", rc, NULL, NULL, text, NULL);
ldap_memfree(text);
tool_exit(ld, rc);
}
} while (rc == LDAP_SASL_BIND_IN_PROGRESS);
lutil_sasl_freedefs(defaults);
if( rc != LDAP_SUCCESS ) {
ldap_get_option(ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void*) &text);
tool_perror( "ldap_verify_credentials", rc, NULL, NULL, text, NULL );
rc = EXIT_FAILURE;
goto skip;
}
} else
#endif
#endif
{
rc = ldap_verify_credentials( ld,
NULL,
dn, NULL, cred.bv_val ? &cred: NULL, vcctrls,
NULL, NULL, &id );
if( rc != LDAP_SUCCESS ) {
ldap_get_option(ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void*) &text);
tool_perror( "ldap_verify_credentials", rc, NULL, NULL, text, NULL );
rc = EXIT_FAILURE;
goto skip;
}
for ( ; ; ) {
struct timeval tv;
if ( tool_check_abandon( ld, id ) ) {
tool_exit( ld, LDAP_CANCELLED );
}
tv.tv_sec = 0;
tv.tv_usec = 100000;
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
tool_exit( ld, rc );
}
if ( rc != 0 ) {
break;
}
}
}
ldap_controls_free(vcctrls);
vcctrls = NULL;
rc = ldap_parse_result( ld, res,
&code, &matcheddn, &text, &refs, &ctrls, 0 );
if (rc == LDAP_SUCCESS) rc = code;
if (rc != LDAP_SUCCESS) {
tool_perror( "ldap_parse_result", rc, NULL, matcheddn, text, refs );
rc = EXIT_FAILURE;
goto skip;
}
rc = ldap_parse_verify_credentials( ld, res, &rcode, &diag, &scookie, &scred, &vcctrls );
ldap_msgfree(res);
if (rc != LDAP_SUCCESS) {
tool_perror( "ldap_parse_verify_credentials", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto skip;
}
if (rcode != LDAP_SUCCESS) {
printf(_("Failed: %s (%d)\n"), ldap_err2string(rcode), rcode);
}
if (diag && *diag) {
printf(_("Diagnostic: %s\n"), diag);
}
if (vcctrls) {
tool_print_ctrls( ld, vcctrls );
}
skip:
if ( verbose || code != LDAP_SUCCESS ||
( matcheddn && *matcheddn ) || ( text && *text ) || refs || ctrls )
{
printf( _("Result: %s (%d)\n"), ldap_err2string( code ), code );
if( text && *text ) {
printf( _("Additional info: %s\n"), text );
}
if( matcheddn && *matcheddn ) {
printf( _("Matched DN: %s\n"), matcheddn );
}
if( refs ) {
int i;
for( i=0; refs[i]; i++ ) {
printf(_("Referral: %s\n"), refs[i] );
}
}
if (ctrls) {
tool_print_ctrls( ld, ctrls );
ldap_controls_free( ctrls );
}
}
ber_memfree( text );
ber_memfree( matcheddn );
ber_memvfree( (void **) refs );
ber_bvfree( scookie );
ber_bvfree( scred );
ber_memfree( diag );
free( cred.bv_val );
/* disconnect from server */
tool_exit( ld, code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE );
}
openldap-2.5.16+dfsg/clients/tools/ldapwhoami.c 0000644 0001750 0001750 00000012046 14461774414 021001 0 ustar sergio sergio /* ldapwhoami.c -- a tool for asking the directory "Who Am I?" */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* Portions Copyright 1998-2003 Kurt D. Zeilenga.
* Portions Copyright 1998-2001 Net Boolean Incorporated.
* Portions Copyright 2001-2003 IBM Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* Portions Copyright (c) 1992-1996 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.
*/
/* ACKNOWLEDGEMENTS:
* This work was originally developed by Kurt D. Zeilenga for inclusion
* in OpenLDAP Software based, in part, on other client tools.
*/
#include "portable.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include "lutil.h"
#include "lutil_ldap.h"
#include "ldap_defaults.h"
#include "common.h"
void
usage( void )
{
fprintf( stderr, _("Issue LDAP Who am I? operation to request user's authzid\n\n"));
fprintf( stderr, _("usage: %s [options]\n"), prog);
tool_common_usage();
exit( EXIT_FAILURE );
}
const char options[] = ""
"d:D:e:H:InNO:o:QR:U:vVw:WxX:y:Y:Z";
int
handle_private_option( int i )
{
switch ( i ) {
#if 0
char *control, *cvalue;
int crit;
case 'E': /* whoami extension */
if( protocol == LDAP_VERSION2 ) {
fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"),
prog, protocol );
exit( EXIT_FAILURE );
}
/* should be extended to support comma separated list of
* [!]key[=value] parameters, e.g. -E !foo,bar=567
*/
crit = 0;
cvalue = NULL;
if( optarg[0] == '!' ) {
crit = 1;
optarg++;
}
control = optarg;
if ( (cvalue = strchr( control, '=' )) != NULL ) {
*cvalue++ = '\0';
}
fprintf( stderr, _("Invalid whoami extension name: %s\n"), control );
usage();
#endif
default:
return 0;
}
return 1;
}
int
main( int argc, char *argv[] )
{
int rc;
LDAP *ld = NULL;
char *matcheddn = NULL, *text = NULL, **refs = NULL;
struct berval *authzid = NULL;
int id, code = 0;
LDAPMessage *res = NULL;
LDAPControl **ctrls = NULL;
tool_init( TOOL_WHOAMI );
prog = lutil_progname( "ldapwhoami", argc, argv );
/* LDAPv3 only */
protocol = LDAP_VERSION3;
tool_args( argc, argv );
if( argc - optind > 0 ) {
usage();
}
ld = tool_conn_setup( 0, 0 );
tool_bind( ld );
if ( dont ) {
rc = LDAP_SUCCESS;
goto skip;
}
tool_server_controls( ld, NULL, 0 );
rc = ldap_whoami( ld, NULL, NULL, &id );
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_whoami", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto skip;
}
for ( ; ; ) {
struct timeval tv;
if ( tool_check_abandon( ld, id ) ) {
tool_exit( ld, LDAP_CANCELLED );
}
tv.tv_sec = 0;
tv.tv_usec = 100000;
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
tool_exit( ld, rc );
}
if ( rc != 0 ) {
break;
}
}
rc = ldap_parse_result( ld, res,
&code, &matcheddn, &text, &refs, &ctrls, 0 );
if ( rc == LDAP_SUCCESS ) {
rc = code;
}
if ( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_result", rc, NULL, matcheddn, text, refs );
rc = EXIT_FAILURE;
goto skip;
}
rc = ldap_parse_whoami( ld, res, &authzid );
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_whoami", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto skip;
}
if( authzid != NULL ) {
if( authzid->bv_len == 0 ) {
printf(_("anonymous\n") );
} else {
printf("%s\n", authzid->bv_val );
}
}
skip:
ldap_msgfree(res);
if ( verbose || code != LDAP_SUCCESS ||
( matcheddn && *matcheddn ) || ( text && *text ) || refs || ctrls )
{
printf( _("Result: %s (%d)\n"), ldap_err2string( code ), code );
if( text && *text ) {
printf( _("Additional info: %s\n"), text );
}
if( matcheddn && *matcheddn ) {
printf( _("Matched DN: %s\n"), matcheddn );
}
if( refs ) {
int i;
for( i=0; refs[i]; i++ ) {
printf(_("Referral: %s\n"), refs[i] );
}
}
if (ctrls) {
tool_print_ctrls( ld, ctrls );
ldap_controls_free( ctrls );
}
}
ber_memfree( text );
ber_memfree( matcheddn );
ber_memvfree( (void **) refs );
ber_bvfree( authzid );
/* disconnect from server */
tool_exit( ld, code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE );
}
openldap-2.5.16+dfsg/clients/tools/common.h 0000644 0001750 0001750 00000007073 14461774414 020155 0 ustar sergio sergio /* common.h - common definitions for the ldap client tools */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* ACKNOWLEDGEMENTS:
* This file was initially created by Hallvard B. Furuseth based (in
* part) upon argument parsing code for individual tools located in
* this directory.
*/
#ifndef _CLIENT_TOOLS_COMMON_H_
#define _CLIENT_TOOLS_COMMON_H_
LDAP_BEGIN_DECL
typedef enum tool_type_t {
TOOL_SEARCH = 0x01U,
TOOL_COMPARE = 0x02U,
TOOL_ADD = 0x04U,
TOOL_DELETE = 0x08U,
TOOL_MODIFY = 0x10U,
TOOL_MODRDN = 0x20U,
TOOL_EXOP = 0x40U,
TOOL_WHOAMI = TOOL_EXOP | 0x100U,
TOOL_PASSWD = TOOL_EXOP | 0x200U,
TOOL_VC = TOOL_EXOP | 0x400U,
TOOL_WRITE = (TOOL_ADD|TOOL_DELETE|TOOL_MODIFY|TOOL_MODRDN),
TOOL_READ = (TOOL_SEARCH|TOOL_COMPARE),
TOOL_ALL = 0xFFU
} tool_type_t;
/* input-related vars */
/* misc. parameters */
extern tool_type_t tool_type;
extern int contoper;
extern int debug;
extern char *infile;
extern int dont;
extern int referrals;
extern int verbose;
extern int ldif;
extern ber_len_t ldif_wrap;
extern char *prog;
/* connection */
extern char *ldapuri;
extern int use_tls;
extern int protocol;
extern int version;
/* authc/authz */
extern int authmethod;
extern char *binddn;
extern int want_bindpw;
extern struct berval passwd;
extern char *pw_file;
#ifdef HAVE_CYRUS_SASL
extern unsigned sasl_flags;
extern char *sasl_realm;
extern char *sasl_authc_id;
extern char *sasl_authz_id;
extern char *sasl_mech;
extern char *sasl_secprops;
#endif
/* controls */
extern char *assertion;
extern char *authzid;
extern int manageDIT;
extern int manageDSAit;
extern int noop;
extern int ppolicy;
extern int preread, postread;
extern ber_int_t pr_morePagedResults;
extern struct berval pr_cookie;
#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
extern int chaining;
#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
extern ber_int_t vlvPos;
extern ber_int_t vlvCount;
extern struct berval *vlvContext;
/* features */
extern int backlog;
/* options */
extern struct timeval nettimeout;
/* Defined in common.c, set in main() */
extern const char __Version[];
/* Defined in main program */
extern const char options[];
void usage LDAP_P(( void )) LDAP_GCCATTR((noreturn));
int handle_private_option LDAP_P(( int i ));
/* Defined in common.c */
void tool_init LDAP_P(( tool_type_t type ));
void tool_common_usage LDAP_P(( void ));
void tool_args LDAP_P(( int, char ** ));
LDAP *tool_conn_setup LDAP_P(( int dont, void (*private_setup)( LDAP * ) ));
void tool_bind LDAP_P(( LDAP * ));
void tool_unbind LDAP_P(( LDAP * ));
void tool_destroy LDAP_P(( void ));
void tool_exit LDAP_P(( LDAP *ld, int status )) LDAP_GCCATTR((noreturn));
void tool_server_controls LDAP_P(( LDAP *, LDAPControl *, int ));
int tool_check_abandon LDAP_P(( LDAP *ld, int msgid ));
void tool_perror LDAP_P((
const char *func,
int err,
const char *extra,
const char *matched,
const char *info,
char **refs ));
void tool_print_ctrls LDAP_P(( LDAP *ld, LDAPControl **ctrls ));
int tool_write_ldif LDAP_P(( int type, char *name, char *value, ber_len_t vallen ));
int tool_is_oid LDAP_P(( const char *s ));
LDAP_END_DECL
#endif /* _CLIENT_TOOLS_COMMON_H_ */
openldap-2.5.16+dfsg/clients/tools/ldapdelete.c 0000644 0001750 0001750 00000023150 14461774414 020755 0 ustar sergio sergio /* ldapdelete.c - simple program to delete an entry using LDAP */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* Portions Copyright 1998-2003 Kurt D. Zeilenga.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* Portions Copyright (c) 1992-1996 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.
*/
/* ACKNOWLEDGEMENTS:
* This work was originally developed by the University of Michigan
* (as part of U-MICH LDAP). Additional significant contributors
* include:
* Kurt D. Zeilenga
*/
#include "portable.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include "lutil.h"
#include "lutil_ldap.h"
#include "ldap_defaults.h"
#include "common.h"
static int prune = 0;
static int sizelimit = -1;
static int dodelete LDAP_P((
LDAP *ld,
const char *dn));
static int deletechildren LDAP_P((
LDAP *ld,
const char *dn,
int subentries ));
void
usage( void )
{
fprintf( stderr, _("Delete entries from an LDAP server\n\n"));
fprintf( stderr, _("usage: %s [options] [dn]...\n"), prog);
fprintf( stderr, _(" dn: list of DNs to delete. If not given, it will be read from stdin\n"));
fprintf( stderr, _(" or from the file specified with \"-f file\".\n"));
fprintf( stderr, _("Delete Options:\n"));
fprintf( stderr, _(" -c continuous operation mode (do not stop on errors)\n"));
fprintf( stderr, _(" -f file read operations from `file'\n"));
fprintf( stderr, _(" -M enable Manage DSA IT control (-MM to make critical)\n"));
fprintf( stderr, _(" -P version protocol version (default: 3)\n"));
fprintf( stderr, _(" -r delete recursively\n"));
tool_common_usage();
exit( EXIT_FAILURE );
}
const char options[] = "r"
"cd:D:e:f:H:IMnNO:o:P:QR:U:vVw:WxX:y:Y:z:Z";
int
handle_private_option( int i )
{
int ival;
char *next;
switch ( i ) {
#if 0
int crit;
char *control, *cvalue;
case 'E': /* delete extensions */
if( protocol == LDAP_VERSION2 ) {
fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"),
prog, protocol );
exit( EXIT_FAILURE );
}
/* should be extended to support comma separated list of
* [!]key[=value] parameters, e.g. -E !foo,bar=567
*/
crit = 0;
cvalue = NULL;
if( optarg[0] == '!' ) {
crit = 1;
optarg++;
}
control = optarg;
if ( (cvalue = strchr( control, '=' )) != NULL ) {
*cvalue++ = '\0';
}
fprintf( stderr, _("Invalid delete extension name: %s\n"), control );
usage();
#endif
case 'r':
prune = 1;
break;
case 'z': /* size limit */
if ( strcasecmp( optarg, "none" ) == 0 ) {
sizelimit = 0;
} else if ( strcasecmp( optarg, "max" ) == 0 ) {
sizelimit = LDAP_MAXINT;
} else {
ival = strtol( optarg, &next, 10 );
if ( next == NULL || next[0] != '\0' ) {
fprintf( stderr,
_("Unable to parse size limit \"%s\"\n"), optarg );
exit( EXIT_FAILURE );
}
sizelimit = ival;
}
if( sizelimit < 0 || sizelimit > LDAP_MAXINT ) {
fprintf( stderr, _("%s: invalid sizelimit (%d) specified\n"),
prog, sizelimit );
exit( EXIT_FAILURE );
}
break;
default:
return 0;
}
return 1;
}
static void
private_conn_setup( LDAP *ld )
{
/* this seems prudent for searches below */
int deref = LDAP_DEREF_NEVER;
ldap_set_option( ld, LDAP_OPT_DEREF, &deref );
}
int
main( int argc, char **argv )
{
char buf[ 4096 ];
FILE *fp = NULL;
LDAP *ld;
int rc, retval;
tool_init( TOOL_DELETE );
prog = lutil_progname( "ldapdelete", argc, argv );
tool_args( argc, argv );
if ( infile != NULL ) {
if (( fp = fopen( infile, "r" )) == NULL ) {
perror( optarg );
exit( EXIT_FAILURE );
}
} else {
if ( optind >= argc ) {
fp = stdin;
}
}
ld = tool_conn_setup( 0, &private_conn_setup );
tool_bind( ld );
tool_server_controls( ld, NULL, 0 );
retval = rc = 0;
if ( fp == NULL ) {
for ( ; optind < argc; ++optind ) {
rc = dodelete( ld, argv[ optind ] );
/* Stop on error and no -c option */
if( rc != 0 ) {
retval = rc;
if( contoper == 0 ) break;
}
}
} else {
while ((rc == 0 || contoper) && fgets(buf, sizeof(buf), fp) != NULL) {
buf[ strlen( buf ) - 1 ] = '\0'; /* remove trailing newline */
if ( *buf != '\0' ) {
rc = dodelete( ld, buf );
if ( rc != 0 )
retval = rc;
}
}
if ( fp != stdin )
fclose( fp );
}
tool_exit( ld, retval );
}
static int dodelete(
LDAP *ld,
const char *dn)
{
int id;
int rc, code;
char *matcheddn = NULL, *text = NULL, **refs = NULL;
LDAPControl **ctrls = NULL;
LDAPMessage *res;
int subentries = 0;
if ( verbose ) {
printf( _("%sdeleting entry \"%s\"\n"),
(dont ? "!" : ""), dn );
}
if ( dont ) {
return LDAP_SUCCESS;
}
/* If prune is on, remove a whole subtree. Delete the children of the
* DN recursively, then the DN requested.
*/
if ( prune ) {
retry:;
deletechildren( ld, dn, subentries );
}
rc = ldap_delete_ext( ld, dn, NULL, NULL, &id );
if ( rc != LDAP_SUCCESS ) {
fprintf( stderr, "%s: ldap_delete_ext: %s (%d)\n",
prog, ldap_err2string( rc ), rc );
return rc;
}
for ( ; ; ) {
struct timeval tv;
if ( tool_check_abandon( ld, id ) ) {
return LDAP_CANCELLED;
}
tv.tv_sec = 0;
tv.tv_usec = 100000;
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
return rc;
}
if ( rc != 0 ) {
break;
}
}
rc = ldap_parse_result( ld, res, &code, &matcheddn, &text, &refs, &ctrls, 1 );
switch ( rc ) {
case LDAP_SUCCESS:
break;
case LDAP_NOT_ALLOWED_ON_NONLEAF:
if ( prune && !subentries ) {
subentries = 1;
goto retry;
}
/* fallthru */
default:
fprintf( stderr, "%s: ldap_parse_result: %s (%d)\n",
prog, ldap_err2string( rc ), rc );
return rc;
}
if( code != LDAP_SUCCESS ) {
tool_perror( "ldap_delete", code, NULL, matcheddn, text, refs );
} else if ( verbose &&
((matcheddn && *matcheddn) || (text && *text) || (refs && *refs) ))
{
printf( _("Delete Result: %s (%d)\n"),
ldap_err2string( code ), code );
if( text && *text ) {
printf( _("Additional info: %s\n"), text );
}
if( matcheddn && *matcheddn ) {
printf( _("Matched DN: %s\n"), matcheddn );
}
if( refs ) {
int i;
for( i=0; refs[i]; i++ ) {
printf(_("Referral: %s\n"), refs[i] );
}
}
}
if (ctrls) {
tool_print_ctrls( ld, ctrls );
ldap_controls_free( ctrls );
}
ber_memfree( text );
ber_memfree( matcheddn );
ber_memvfree( (void **) refs );
return code;
}
/*
* Delete all the children of an entry recursively until leaf nodes are reached.
*/
static int deletechildren(
LDAP *ld,
const char *base,
int subentries )
{
LDAPMessage *res, *e;
int entries;
int rc = LDAP_SUCCESS, srch_rc;
static char *attrs[] = { LDAP_NO_ATTRS, NULL };
LDAPControl c, *ctrls[2], **ctrlsp = NULL;
BerElement *ber = NULL;
if ( verbose ) printf ( _("deleting children of: %s\n"), base );
if ( subentries ) {
/*
* Do a one level search at base for subentry children.
*/
if ((ber = ber_alloc_t(LBER_USE_DER)) == NULL) {
return EXIT_FAILURE;
}
rc = ber_printf( ber, "b", 1 );
if ( rc == -1 ) {
ber_free( ber, 1 );
fprintf( stderr, _("Subentries control encoding error!\n"));
return EXIT_FAILURE;
}
if ( ber_flatten2( ber, &c.ldctl_value, 0 ) == -1 ) {
return EXIT_FAILURE;
}
c.ldctl_oid = LDAP_CONTROL_SUBENTRIES;
c.ldctl_iscritical = 1;
ctrls[0] = &c;
ctrls[1] = NULL;
ctrlsp = ctrls;
}
/*
* Do a one level search at base for children. For each, delete its children.
*/
more:;
srch_rc = ldap_search_ext_s( ld, base, LDAP_SCOPE_ONELEVEL, NULL, attrs, 1,
ctrlsp, NULL, NULL, sizelimit, &res );
switch ( srch_rc ) {
case LDAP_SUCCESS:
case LDAP_SIZELIMIT_EXCEEDED:
break;
default:
tool_perror( "ldap_search", srch_rc, NULL, NULL, NULL, NULL );
rc = srch_rc;
srch_rc = 0;
goto leave;
}
entries = ldap_count_entries( ld, res );
if ( entries > 0 ) {
int i;
for (e = ldap_first_entry( ld, res ), i = 0; e != NULL;
e = ldap_next_entry( ld, e ), i++ )
{
char *dn = ldap_get_dn( ld, e );
if( dn == NULL ) {
ldap_get_option( ld, LDAP_OPT_RESULT_CODE, &rc );
tool_perror( "ldap_prune", rc, NULL, NULL, NULL, NULL );
goto leave;
}
rc = deletechildren( ld, dn, 0 );
if ( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_prune", rc, NULL, NULL, NULL, NULL );
ber_memfree( dn );
goto leave;
}
if ( verbose ) {
printf( _("\tremoving %s\n"), dn );
}
rc = ldap_delete_ext_s( ld, dn, NULL, NULL );
if ( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_delete", rc, NULL, NULL, NULL, NULL );
ber_memfree( dn );
goto leave;
}
if ( verbose ) {
printf( _("\t%s removed\n"), dn );
}
ber_memfree( dn );
}
}
leave:
ldap_msgfree( res );
if ( srch_rc == LDAP_SIZELIMIT_EXCEEDED ) {
goto more;
}
return rc;
}
openldap-2.5.16+dfsg/clients/tools/ldapurl.c 0000644 0001750 0001750 00000015400 14461774414 020314 0 ustar sergio sergio /* ldapurl -- a tool for generating LDAP URLs */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 2008-2022 The OpenLDAP Foundation.
* Portions Copyright 2008 Pierangelo Masarati, SysNet
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* Portions Copyright (c) 1992-1996 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.
*/
/* ACKNOWLEDGEMENTS:
* This work was originally developed by Pierangelo Masarati
* for inclusion in OpenLDAP software.
*/
#include "portable.h"
#include
#include
#include
#include
#include "ldap.h"
#include "ldap_pvt.h"
#include "lutil.h"
static int
usage(void)
{
fprintf( stderr, _("usage: %s [options]\n\n"), "ldapurl" );
fprintf( stderr, _("generates RFC 4516 LDAP URL with extensions\n\n" ) );
fprintf( stderr, _("URL options:\n"));
fprintf( stderr, _(" -a attrs comma separated list of attributes\n" ) );
fprintf( stderr, _(" -b base (RFC 4514 LDAP DN)\n" ) );
fprintf( stderr, _(" -E ext (format: \"ext=value\"; multiple occurrences allowed)\n" ) );
fprintf( stderr, _(" -f filter (RFC 4515 LDAP filter)\n" ) );
fprintf( stderr, _(" -h host \n" ) );
fprintf( stderr, _(" -p port (default: 389 for ldap, 636 for ldaps)\n" ) );
fprintf( stderr, _(" -s scope (RFC 4511 searchScope and extensions)\n" ) );
fprintf( stderr, _(" -S scheme (RFC 4516 LDAP URL scheme and extensions)\n" ) );
exit( EXIT_FAILURE );
}
static int
do_uri_create( LDAPURLDesc *lud )
{
char *uri;
if ( lud->lud_scheme == NULL ) {
lud->lud_scheme = "ldap";
}
if ( lud->lud_port == -1 ) {
if ( strcasecmp( lud->lud_scheme, "ldap" ) == 0 ) {
lud->lud_port = LDAP_PORT;
} else if ( strcasecmp( lud->lud_scheme, "ldaps" ) == 0 ) {
lud->lud_port = LDAPS_PORT;
} else if ( strcasecmp( lud->lud_scheme, "ldapi" ) == 0 ) {
lud->lud_port = 0;
} else {
/* forgiving... */
lud->lud_port = 0;
}
}
if ( lud->lud_scope == -1 ) {
lud->lud_scope = LDAP_SCOPE_DEFAULT;
}
uri = ldap_url_desc2str( lud );
if ( lud->lud_attrs != NULL ) {
ldap_charray_free( lud->lud_attrs );
lud->lud_attrs = NULL;
}
if ( lud->lud_exts != NULL ) {
free( lud->lud_exts );
lud->lud_exts = NULL;
}
if ( uri == NULL ) {
fprintf( stderr, "unable to generate URI\n" );
exit( EXIT_FAILURE );
}
printf( "%s\n", uri );
free( uri );
return 0;
}
static int
do_uri_explode( const char *uri )
{
LDAPURLDesc *lud;
int rc;
rc = ldap_url_parse( uri, &lud );
if ( rc != LDAP_URL_SUCCESS ) {
fprintf( stderr, "unable to parse URI \"%s\"\n", uri );
return 1;
}
if ( lud->lud_scheme != NULL && lud->lud_scheme[0] != '\0' ) {
printf( "scheme: %s\n", lud->lud_scheme );
}
if ( lud->lud_host != NULL && lud->lud_host[0] != '\0' ) {
printf( "host: %s\n", lud->lud_host );
}
if ( lud->lud_port != 0 ) {
printf( "port: %d\n", lud->lud_port );
}
if ( lud->lud_dn != NULL && lud->lud_dn[0] != '\0' ) {
printf( "dn: %s\n", lud->lud_dn );
}
if ( lud->lud_attrs != NULL ) {
int i;
for ( i = 0; lud->lud_attrs[i] != NULL; i++ ) {
printf( "selector: %s\n", lud->lud_attrs[i] );
}
}
if ( lud->lud_scope != LDAP_SCOPE_DEFAULT ) {
printf( "scope: %s\n", ldap_pvt_scope2str( lud->lud_scope ) );
}
if ( lud->lud_filter != NULL && lud->lud_filter[0] != '\0' ) {
printf( "filter: %s\n", lud->lud_filter );
}
if ( lud->lud_exts != NULL ) {
int i;
for ( i = 0; lud->lud_exts[i] != NULL; i++ ) {
printf( "extension: %s\n", lud->lud_exts[i] );
}
}
ldap_free_urldesc( lud );
return 0;
}
int
main( int argc, char *argv[])
{
LDAPURLDesc lud = { 0 };
char *uri = NULL;
int gotlud = 0;
int nexts = 0;
lud.lud_port = -1;
lud.lud_scope = -1;
while ( 1 ) {
int opt = getopt( argc, argv, "S:h:p:b:a:s:f:E:H:" );
if ( opt == EOF ) {
break;
}
if ( opt == 'H' ) {
if ( gotlud ) {
fprintf( stderr, "option -H incompatible with previous options\n" );
usage();
}
if ( uri != NULL ) {
fprintf( stderr, "URI already provided\n" );
usage();
}
uri = optarg;
continue;
}
switch ( opt ) {
case 'S':
case 'h':
case 'p':
case 'b':
case 'a':
case 's':
case 'f':
case 'E':
if ( uri != NULL ) {
fprintf( stderr, "option -%c incompatible with -H\n", opt );
usage();
}
gotlud++;
}
switch ( opt ) {
case 'S':
if ( lud.lud_scheme != NULL ) {
fprintf( stderr, "scheme already provided\n" );
usage();
}
lud.lud_scheme = optarg;
break;
case 'h':
if ( lud.lud_host != NULL ) {
fprintf( stderr, "host already provided\n" );
usage();
}
lud.lud_host = optarg;
break;
case 'p':
if ( lud.lud_port != -1 ) {
fprintf( stderr, "port already provided\n" );
usage();
}
if ( lutil_atoi( &lud.lud_port, optarg ) ) {
fprintf( stderr, "unable to parse port \"%s\"\n", optarg );
usage();
}
break;
case 'b':
if ( lud.lud_dn != NULL ) {
fprintf( stderr, "base already provided\n" );
usage();
}
lud.lud_dn = optarg;
break;
case 'a':
if ( lud.lud_attrs != NULL ) {
fprintf( stderr, "attrs already provided\n" );
usage();
}
lud.lud_attrs = ldap_str2charray( optarg, "," );
if ( lud.lud_attrs == NULL ) {
fprintf( stderr, "unable to parse attrs list \"%s\"\n", optarg );
usage();
}
break;
case 's':
if ( lud.lud_scope != -1 ) {
fprintf( stderr, "scope already provided\n" );
usage();
}
lud.lud_scope = ldap_pvt_str2scope( optarg );
if ( lud.lud_scope == -1 ) {
fprintf( stderr, "unable to parse scope \"%s\"\n", optarg );
usage();
}
break;
case 'f':
if ( lud.lud_filter != NULL ) {
fprintf( stderr, "filter already provided\n" );
usage();
}
lud.lud_filter = optarg;
break;
case 'E':
lud.lud_exts = (char **)realloc( lud.lud_exts,
sizeof( char * ) * ( nexts + 2 ) );
lud.lud_exts[ nexts++ ] = optarg;
lud.lud_exts[ nexts ] = NULL;
break;
default:
assert( opt != 'H' );
usage();
}
}
if ( uri != NULL ) {
return do_uri_explode( uri );
}
return do_uri_create( &lud );
}
openldap-2.5.16+dfsg/clients/tools/ldapmodify.c 0000644 0001750 0001750 00000041250 14461774414 021003 0 ustar sergio sergio /* ldapmodify.c - generic program to modify or add entries using LDAP */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* Portions Copyright 2006 Howard Chu.
* Portions Copyright 1998-2003 Kurt D. Zeilenga.
* Portions Copyright 1998-2001 Net Boolean Incorporated.
* Portions Copyright 2001-2003 IBM Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* Portions Copyright (c) 1992-1996 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.
*/
/* ACKNOWLEDGEMENTS:
* This work was originally developed by the University of Michigan
* (as part of U-MICH LDAP). Additional significant contributors
* include:
* Kurt D. Zeilenga
* Norbert Klasen
* Howard Chu
*/
#include "portable.h"
#include
#include
#include
#include
#include
#include
#include
#ifdef HAVE_SYS_STAT_H
#include
#endif
#ifdef HAVE_SYS_FILE_H
#include
#endif
#ifdef HAVE_FCNTL_H
#include
#endif
#include
#include "lutil.h"
#include "lutil_ldap.h"
#include "ldif.h"
#include "ldap_defaults.h"
#include "ldap_pvt.h"
#include "lber_pvt.h"
#include "common.h"
static int ldapadd;
static char *rejfile = NULL;
static LDAP *ld = NULL;
static int process_ldif_rec LDAP_P(( char *rbuf, unsigned long lineno ));
static int domodify LDAP_P((
const struct berval *dn,
LDAPMod **pmods,
LDAPControl **pctrls,
int newentry ));
static int dodelete LDAP_P((
const struct berval *dn,
LDAPControl **pctrls ));
static int dorename LDAP_P((
const struct berval *dn,
const struct berval *newrdn,
const struct berval *newsup,
int deleteoldrdn,
LDAPControl **pctrls ));
static int process_response(
LDAP *ld,
int msgid,
int res,
const struct berval *dn );
static int txn = 0;
static int txnabort = 0;
struct berval *txn_id = NULL;
void
usage( void )
{
fprintf( stderr, _("Add or modify entries from an LDAP server\n\n"));
fprintf( stderr, _("usage: %s [options]\n"), prog);
fprintf( stderr, _(" The list of desired operations are read from stdin"
" or from the file\n"));
fprintf( stderr, _(" specified by \"-f file\".\n"));
fprintf( stderr, _("Add or modify options:\n"));
fprintf( stderr, _(" -a add values (%s)\n"),
(ldapadd ? _("default") : _("default is to replace")));
fprintf( stderr, _(" -c continuous operation mode (do not stop on errors)\n"));
fprintf( stderr, _(" -E [!]ext=extparam modify extensions"
" (! indicate s criticality)\n"));
fprintf( stderr, _(" -f file read operations from `file'\n"));
fprintf( stderr, _(" -M enable Manage DSA IT control (-MM to make critical)\n"));
fprintf( stderr, _(" -P version protocol version (default: 3)\n"));
fprintf( stderr,
_(" [!]txn= (transaction)\n"));
fprintf( stderr, _(" -S file write skipped modifications to `file'\n"));
tool_common_usage();
exit( EXIT_FAILURE );
}
const char options[] = "aE:rS:"
"cd:D:e:f:H:IMnNO:o:P:QR:U:vVw:WxX:y:Y:Z";
int
handle_private_option( int i )
{
char *control, *cvalue;
int crit;
switch ( i ) {
case 'E': /* modify extensions */
if( protocol == LDAP_VERSION2 ) {
fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"),
prog, protocol );
exit( EXIT_FAILURE );
}
/* should be extended to support comma separated list of
* [!]key[=value] parameters, e.g. -E !foo,bar=567
*/
crit = 0;
cvalue = NULL;
if( optarg[0] == '!' ) {
crit = 1;
optarg++;
}
control = optarg;
if ( (cvalue = strchr( control, '=' )) != NULL ) {
*cvalue++ = '\0';
}
if( strcasecmp( control, "txn" ) == 0 ) {
/* Transaction */
if( txn ) {
fprintf( stderr,
_("txn control previously specified\n"));
exit( EXIT_FAILURE );
}
if( cvalue != NULL ) {
if( strcasecmp( cvalue, "abort" ) == 0 ) {
txnabort=1;
} else if( strcasecmp( cvalue, "commit" ) != 0 ) {
fprintf( stderr, _("Invalid value for txn control, %s\n"),
cvalue );
exit( EXIT_FAILURE );
}
}
txn = 1 + crit;
} else
{
fprintf( stderr, _("Invalid modify extension name: %s\n"),
control );
usage();
}
break;
case 'a': /* add */
ldapadd = 1;
break;
case 'r': /* replace (obsolete) */
break;
case 'S': /* skipped modifications to file */
if( rejfile != NULL ) {
fprintf( stderr, _("%s: -S previously specified\n"), prog );
exit( EXIT_FAILURE );
}
rejfile = optarg;
break;
default:
return 0;
}
return 1;
}
int
main( int argc, char **argv )
{
char *rbuf = NULL, *rejbuf = NULL;
FILE *rejfp;
struct LDIFFP *ldiffp = NULL, ldifdummy = {0};
char *matched_msg, *error_msg;
int rc, retval, ldifrc;
int len;
int i = 0, lmax = 0;
unsigned long lineno, nextline = 0;
LDAPControl c[1];
prog = lutil_progname( "ldapmodify", argc, argv );
/* strncmp instead of strcmp since NT binaries carry .exe extension */
ldapadd = ( strncasecmp( prog, "ldapadd", sizeof("ldapadd")-1 ) == 0 );
tool_init( ldapadd ? TOOL_ADD : TOOL_MODIFY );
tool_args( argc, argv );
if ( argc != optind ) usage();
if ( rejfile != NULL ) {
if (( rejfp = fopen( rejfile, "w" )) == NULL ) {
perror( rejfile );
retval = EXIT_FAILURE;
goto fail;
}
} else {
rejfp = NULL;
}
if ( infile != NULL ) {
if (( ldiffp = ldif_open( infile, "r" )) == NULL ) {
perror( infile );
retval = EXIT_FAILURE;
goto fail;
}
} else {
ldifdummy.fp = stdin;
ldiffp = &ldifdummy;
}
if ( debug ) ldif_debug = debug;
ld = tool_conn_setup( dont, 0 );
if ( !dont ) {
tool_bind( ld );
}
if( txn ) {
/* start transaction */
rc = ldap_txn_start_s( ld, NULL, NULL, &txn_id );
if( rc != LDAP_SUCCESS || !txn_id ) {
tool_perror( "ldap_txn_start_s", rc, NULL, NULL, NULL, NULL );
if( txn > 1 ) {
retval = EXIT_FAILURE;
goto fail;
}
txn = 0;
}
}
if( txn ) {
c[i].ldctl_oid = LDAP_CONTROL_TXN_SPEC;
c[i].ldctl_value = *txn_id;
c[i].ldctl_iscritical = 1;
i++;
}
tool_server_controls( ld, c, i );
rc = 0;
retval = 0;
lineno = 1;
while (( rc == 0 || contoper ) && ( ldifrc = ldif_read_record( ldiffp, &nextline,
&rbuf, &lmax )) > 0 )
{
if ( rejfp ) {
len = strlen( rbuf );
if (( rejbuf = (char *)ber_memalloc( len+1 )) == NULL ) {
perror( "malloc" );
retval = EXIT_FAILURE;
goto fail;
}
memcpy( rejbuf, rbuf, len+1 );
}
rc = process_ldif_rec( rbuf, lineno );
lineno = nextline+1;
if ( rc ) retval = rc;
if ( rc && rejfp ) {
fprintf(rejfp, _("# Error: %s (%d)"), ldap_err2string(rc), rc);
matched_msg = NULL;
ldap_get_option(ld, LDAP_OPT_MATCHED_DN, &matched_msg);
if ( matched_msg != NULL ) {
if ( *matched_msg != '\0' ) {
fprintf( rejfp, _(", matched DN: %s"), matched_msg );
}
ldap_memfree( matched_msg );
}
error_msg = NULL;
ldap_get_option(ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, &error_msg);
if ( error_msg != NULL ) {
if ( *error_msg != '\0' ) {
fprintf( rejfp, _(", additional info: %s"), error_msg );
}
ldap_memfree( error_msg );
}
fprintf( rejfp, "\n%s\n", rejbuf );
}
if (rejfp) ber_memfree( rejbuf );
}
ber_memfree( rbuf );
if ( ldifrc < 0 )
retval = LDAP_OTHER;
if( retval == 0 && txn ) {
rc = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, NULL );
if ( rc != LDAP_OPT_SUCCESS ) {
fprintf( stderr, "Could not unset controls for ldap_txn_end\n");
}
/* create transaction */
rc = ldap_txn_end_s( ld, !txnabort, txn_id, NULL, NULL, NULL );
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_txn_end_s", rc, NULL, NULL, NULL, NULL );
retval = rc;
}
}
fail:;
if ( rejfp != NULL ) {
fclose( rejfp );
}
if ( ldiffp != NULL && ldiffp != &ldifdummy ) {
ldif_close( ldiffp );
}
tool_exit( ld, retval );
}
static int
process_ldif_rec( char *rbuf, unsigned long linenum )
{
LDIFRecord lr;
int lrflags = ldapadd ? LDIF_DEFAULT_ADD : 0;
int rc;
struct berval rbuf_bv;
#ifdef TEST_LDIF_API
if ( getenv( "LDIF_ENTRIES_ONLY" ) ) {
lrflags |= LDIF_ENTRIES_ONLY;
}
if ( getenv( "LDIF_NO_CONTROLS" ) ) {
lrflags |= LDIF_NO_CONTROLS;
}
#endif /* TEST_LDIF_API */
rbuf_bv.bv_val = rbuf;
rbuf_bv.bv_len = 0; /* not used */
rc = ldap_parse_ldif_record( &rbuf_bv, linenum, &lr, prog, lrflags );
/* If default controls are set (as with -M option) and controls are
specified in the LDIF file, we must add the default controls to
the list of controls sent with the ldap operation.
*/
if ( rc == 0 ) {
if (lr.lr_ctrls) {
LDAPControl **defctrls = NULL; /* Default server controls */
LDAPControl **newctrls = NULL;
ldap_get_option(ld, LDAP_OPT_SERVER_CONTROLS, &defctrls);
if (defctrls) {
int npc=0; /* Num of LDIF controls */
int ndefc=0; /* Num of default controls */
while (lr.lr_ctrls[npc]) npc++; /* Count LDIF controls */
while (defctrls[ndefc]) ndefc++; /* Count default controls */
newctrls = ber_memrealloc(lr.lr_ctrls,
(npc+ndefc+1)*sizeof(LDAPControl*));
if (newctrls == NULL) {
rc = LDAP_NO_MEMORY;
} else {
int i;
lr.lr_ctrls = newctrls;
for (i=npc; ibv_val == NULL ) ) {
fprintf( stderr, _("%s: no DN specified\n"), prog );
return( LDAP_PARAM_ERROR );
}
if ( pmods == NULL ) {
/* implement "touch" (empty sequence)
* modify operation (note that there
* is no symmetry with the UNIX command,
* since \"touch\" on a non-existent entry
* will fail)*/
printf( "warning: no attributes to %sadd (entry=\"%s\")\n",
newentry ? "" : "change or ", dn->bv_val );
} else {
for ( i = 0; pmods[ i ] != NULL; ++i ) {
op = pmods[ i ]->mod_op & ~LDAP_MOD_BVALUES;
if( op == LDAP_MOD_ADD && ( pmods[i]->mod_bvalues == NULL )) {
fprintf( stderr,
_("%s: attribute \"%s\" has no values (entry=\"%s\")\n"),
prog, pmods[i]->mod_type, dn->bv_val );
return LDAP_PARAM_ERROR;
}
}
if ( verbose ) {
for ( i = 0; pmods[ i ] != NULL; ++i ) {
op = pmods[ i ]->mod_op & ~LDAP_MOD_BVALUES;
printf( "%s %s:\n",
op == LDAP_MOD_REPLACE ? _("replace") :
op == LDAP_MOD_ADD ? _("add") :
op == LDAP_MOD_INCREMENT ? _("increment") :
op == LDAP_MOD_DELETE ? _("delete") :
_("unknown"),
pmods[ i ]->mod_type );
if ( pmods[ i ]->mod_bvalues != NULL ) {
for ( j = 0; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) {
bvp = pmods[ i ]->mod_bvalues[ j ];
notascii = 0;
for ( k = 0; (unsigned long) k < bvp->bv_len; ++k ) {
if ( !isascii( bvp->bv_val[ k ] )) {
notascii = 1;
break;
}
}
if ( notascii ) {
printf( _("\tNOT ASCII (%ld bytes)\n"), bvp->bv_len );
} else {
printf( "\t%s\n", bvp->bv_val );
}
}
}
}
}
}
if ( newentry ) {
printf( "%sadding new entry \"%s\"\n", dont ? "!" : "", dn->bv_val );
} else {
printf( "%smodifying entry \"%s\"\n", dont ? "!" : "", dn->bv_val );
}
if ( !dont ) {
int msgid;
if ( newentry ) {
rc = ldap_add_ext( ld, dn->bv_val, pmods, pctrls, NULL, &msgid );
} else {
rc = ldap_modify_ext( ld, dn->bv_val, pmods, pctrls, NULL, &msgid );
}
if ( rc != LDAP_SUCCESS ) {
/* print error message about failed update including DN */
fprintf( stderr, _("%s: update failed: %s\n"), prog, dn->bv_val );
tool_perror( newentry ? "ldap_add" : "ldap_modify",
rc, NULL, NULL, NULL, NULL );
goto done;
}
rc = process_response( ld, msgid,
newentry ? LDAP_RES_ADD : LDAP_RES_MODIFY, dn );
if ( verbose && rc == LDAP_SUCCESS ) {
printf( _("modify complete\n") );
}
} else {
rc = LDAP_SUCCESS;
}
done:
putchar( '\n' );
return rc;
}
static int
dodelete(
const struct berval *dn,
LDAPControl **pctrls )
{
int rc;
int msgid;
assert( dn != NULL );
assert( dn->bv_val != NULL );
printf( _("%sdeleting entry \"%s\"\n"), dont ? "!" : "", dn->bv_val );
if ( !dont ) {
rc = ldap_delete_ext( ld, dn->bv_val, pctrls, NULL, &msgid );
if ( rc != LDAP_SUCCESS ) {
fprintf( stderr, _("%s: delete failed: %s\n"), prog, dn->bv_val );
tool_perror( "ldap_delete", rc, NULL, NULL, NULL, NULL );
goto done;
}
rc = process_response( ld, msgid, LDAP_RES_DELETE, dn );
if ( verbose && rc == LDAP_SUCCESS ) {
printf( _("delete complete\n") );
}
} else {
rc = LDAP_SUCCESS;
}
done:
putchar( '\n' );
return( rc );
}
static int
dorename(
const struct berval *dn,
const struct berval *newrdn,
const struct berval *newsup,
int deleteoldrdn,
LDAPControl **pctrls )
{
int rc;
int msgid;
assert( dn != NULL );
assert( dn->bv_val != NULL );
assert( newrdn != NULL );
assert( newrdn->bv_val != NULL );
printf( _("%smodifying rdn of entry \"%s\"\n"), dont ? "!" : "", dn->bv_val );
if ( verbose ) {
printf( _("\tnew RDN: \"%s\" (%skeep existing values)\n"),
newrdn->bv_val, deleteoldrdn ? _("do not ") : "" );
}
if ( !dont ) {
rc = ldap_rename( ld, dn->bv_val, newrdn->bv_val,
( newsup && newsup->bv_val ) ? newsup->bv_val : NULL,
deleteoldrdn, pctrls, NULL, &msgid );
if ( rc != LDAP_SUCCESS ) {
fprintf( stderr, _("%s: rename failed: %s\n"), prog, dn->bv_val );
tool_perror( "ldap_rename", rc, NULL, NULL, NULL, NULL );
goto done;
}
rc = process_response( ld, msgid, LDAP_RES_RENAME, dn );
if ( verbose && rc == LDAP_SUCCESS ) {
printf( _("rename complete\n") );
}
} else {
rc = LDAP_SUCCESS;
}
done:
putchar( '\n' );
return( rc );
}
static const char *
res2str( int res ) {
switch ( res ) {
case LDAP_RES_ADD:
return "ldap_add";
case LDAP_RES_DELETE:
return "ldap_delete";
case LDAP_RES_MODIFY:
return "ldap_modify";
case LDAP_RES_MODRDN:
return "ldap_rename";
default:
assert( 0 );
}
return "ldap_unknown";
}
static int process_response(
LDAP *ld,
int msgid,
int op,
const struct berval *dn )
{
LDAPMessage *res;
int rc = LDAP_OTHER, msgtype;
struct timeval tv = { 0, 0 };
int err;
char *text = NULL, *matched = NULL, **refs = NULL;
LDAPControl **ctrls = NULL;
assert( dn != NULL );
for ( ; ; ) {
tv.tv_sec = 0;
tv.tv_usec = 100000;
rc = ldap_result( ld, msgid, LDAP_MSG_ALL, &tv, &res );
if ( tool_check_abandon( ld, msgid ) ) {
return LDAP_CANCELLED;
}
if ( rc == -1 ) {
ldap_get_option( ld, LDAP_OPT_RESULT_CODE, &rc );
tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
return rc;
}
if ( rc != 0 ) {
break;
}
}
msgtype = ldap_msgtype( res );
rc = ldap_parse_result( ld, res, &err, &matched, &text, &refs, &ctrls, 1 );
if ( rc == LDAP_SUCCESS ) rc = err;
if ( rc == LDAP_TXN_SPECIFY_OKAY ) {
rc = LDAP_SUCCESS;
} else if ( rc != LDAP_SUCCESS ) {
tool_perror( res2str( op ), rc, NULL, matched, text, refs );
} else if ( msgtype != op ) {
fprintf( stderr, "%s: msgtype: expected %d got %d\n",
res2str( op ), op, msgtype );
rc = LDAP_OTHER;
}
if ( text ) ldap_memfree( text );
if ( matched ) ldap_memfree( matched );
if ( refs ) ber_memvfree( (void **)refs );
if ( ctrls ) {
tool_print_ctrls( ld, ctrls );
ldap_controls_free( ctrls );
}
return rc;
}
openldap-2.5.16+dfsg/clients/tools/Makefile.in 0000644 0001750 0001750 00000007046 14461774414 020561 0 ustar sergio sergio # Makefile for LDAP tools
# $OpenLDAP$
## This work is part of OpenLDAP Software .
##
## Copyright 1998-2022 The OpenLDAP Foundation.
## All rights reserved.
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted only as authorized by the OpenLDAP
## Public License.
##
## A copy of this license is available in the file LICENSE in the
## top-level directory of the distribution or, alternatively, at
## .
SRCS = ldapsearch.c ldapmodify.c ldapdelete.c ldapmodrdn.c \
ldappasswd.c ldapwhoami.c ldapvc.c ldapcompare.c \
ldapexop.c ldapurl.c common.c
OBJS = ldapsearch.o ldapmodify.o ldapdelete.o ldapmodrdn.o \
ldappasswd.o ldapwhoami.o ldapvc.o ldapcompare.o \
ldapexop.o ldapurl.o common.o
LDAP_INCDIR= ../../include
LDAP_LIBDIR= ../../libraries
MKVOPTS = -s
XLIBS = $(LDAP_L)
XXLIBS = $(SECURITY_LIBS) $(LUTIL_LIBS) $(CLIENT_LIBS)
XSRCS = ldsversion.c ldmversion.c lddversion.c ldrversion.c ldpversion.c \
ldwversion.c ldvversion.c ldcversion.c ldeversion.c lduversion.c
PROGRAMS = ldapsearch ldapmodify ldapdelete ldapmodrdn \
ldappasswd ldapwhoami ldapvc ldapcompare ldapexop ldapurl
ldapsearch: ldsversion.o
$(LTLINK) -o $@ ldapsearch.o common.o ldsversion.o $(LIBS)
ldapmodify: ldmversion.o
$(LTLINK) -o $@ ldapmodify.o common.o ldmversion.o $(LIBS)
ldapdelete: lddversion.o
$(LTLINK) -o $@ ldapdelete.o common.o lddversion.o $(LIBS)
ldapmodrdn: ldrversion.o
$(LTLINK) -o $@ ldapmodrdn.o common.o ldrversion.o $(LIBS)
ldappasswd: ldpversion.o
$(LTLINK) -o $@ ldappasswd.o common.o ldpversion.o $(LIBS)
ldapwhoami: ldwversion.o
$(LTLINK) -o $@ ldapwhoami.o common.o ldwversion.o $(LIBS)
ldapvc: ldvversion.o
$(LTLINK) -o $@ ldapvc.o common.o ldvversion.o $(LIBS)
ldapcompare: ldcversion.o
$(LTLINK) -o $@ ldapcompare.o common.o ldcversion.o $(LIBS)
ldapexop: ldeversion.o
$(LTLINK) -o $@ ldapexop.o common.o ldeversion.o $(LIBS)
ldapurl: lduversion.o
$(LTLINK) -o $@ ldapurl.o lduversion.o $(LIBS)
ldsversion.c: Makefile
@-$(RM) $@
$(MKVERSION) $(MKVOPTS) ldapsearch > $@
ldsversion.o: ldapsearch.o common.o $(XLIBS)
ldmversion.c: Makefile
@-$(RM) $@
$(MKVERSION) $(MKVOPTS) ldapmodify > $@
ldmversion.o: ldapmodify.o common.o $(XLIBS)
lddversion.c: Makefile
@-$(RM) $@
$(MKVERSION) $(MKVOPTS) ldapdelete > $@
lddversion.o: ldapdelete.o common.o $(XLIBS)
ldpversion.c: Makefile
@-$(RM) $@
$(MKVERSION) $(MKVOPTS) ldappasswd > $@
ldpversion.o: ldappasswd.o common.o $(XLIBS)
ldrversion.c: Makefile
@-$(RM) $@
$(MKVERSION) $(MKVOPTS) ldapmodrdn > $@
ldrversion.o: ldapmodrdn.o common.o $(XLIBS)
ldwversion.c: Makefile
@-$(RM) $@
$(MKVERSION) $(MKVOPTS) ldapwhoami > $@
ldwversion.o: ldapwhoami.o common.o $(XLIBS)
ldvversion.c: Makefile
@-$(RM) $@
$(MKVERSION) $(MKVOPTS) ldapvc > $@
ldvversion.o: ldapvc.o common.o $(XLIBS)
ldcversion.c: Makefile
@-$(RM) $@
$(MKVERSION) $(MKVOPTS) ldapcompare > $@
ldcversion.o: ldapcompare.o common.o $(XLIBS)
ldeversion.c: Makefile
@-$(RM) $@
$(MKVERSION) $(MKVOPTS) ldapexop > $@
ldeversion.o: ldapexop.o common.o $(XLIBS)
lduversion.c: Makefile
@-$(RM) $@
$(MKVERSION) $(MKVOPTS) ldapurl > $@
lduversion.o: ldapurl.o $(XLIBS)
install-local: FORCE
-$(MKDIR) $(DESTDIR)$(bindir)
@( \
for prg in $(PROGRAMS); do \
$(LTINSTALL) $(INSTALLFLAGS) $(STRIP_OPTS) -m 755 $$prg$(EXEEXT) \
$(DESTDIR)$(bindir); \
done \
)
$(RM) $(DESTDIR)$(bindir)/ldapadd$(EXEEXT)
$(LN_S) $(DESTDIR)$(bindir)/ldapmodify$(EXEEXT) $(DESTDIR)$(bindir)/ldapadd$(EXEEXT)
openldap-2.5.16+dfsg/clients/tools/ldapcompare.c 0000644 0001750 0001750 00000017643 14461774414 021153 0 ustar sergio sergio /* ldapcompare.c -- LDAP compare tool */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* Portions Copyright 1998-2003 Kurt D. Zeilenga.
* Portions Copyright 1998-2001 Net Boolean Incorporated.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* Portions Copyright (c) 1992-1996 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.
*/
/* Portions Copyright 2002, F5 Networks, Inc, All rights reserved.
* This software is not subject to any license of F5 Networks.
* This is free software; you can redistribute and use it
* under the same terms as OpenLDAP itself.
*/
/* ACKNOWLEDGEMENTS:
* This work was originally developed by Jeff Costlow (F5 Networks)
* based, in part, on existing LDAP tools and adapted for inclusion
* into OpenLDAP Software by Kurt D. Zeilenga.
*/
#include "portable.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef HAVE_FCNTL_H
#include
#endif
#ifdef HAVE_SYS_TYPES_H
#include
#endif
#ifdef HAVE_IO_H
#include
#endif
#include
#include "lutil.h"
#include "lutil_ldap.h"
#include "ldap_defaults.h"
#include "common.h"
static int quiet = 0;
void
usage( void )
{
fprintf( stderr, _("usage: %s [options] DN \n"), prog);
fprintf( stderr, _("where:\n"));
fprintf( stderr, _(" DN\tDistinguished Name\n"));
fprintf( stderr, _(" attr\tassertion attribute\n"));
fprintf( stderr, _(" value\tassertion value\n"));
fprintf( stderr, _(" b64value\tbase64 encoding of assertion value\n"));
fprintf( stderr, _("Compare options:\n"));
fprintf( stderr, _(" -E [!][=] compare extensions (! indicates criticality)\n"));
fprintf( stderr, _(" !dontUseCopy (Don't Use Copy)\n"));
fprintf( stderr, _(" -M enable Manage DSA IT control (-MM to make critical)\n"));
fprintf( stderr, _(" -P version protocol version (default: 3)\n"));
fprintf( stderr, _(" -z Quiet mode,"
" don't print anything, use return values\n"));
tool_common_usage();
exit( EXIT_FAILURE );
}
static int docompare LDAP_P((
LDAP *ld,
char *dn,
char *attr,
struct berval *bvalue,
int quiet,
LDAPControl **sctrls,
LDAPControl **cctrls));
const char options[] = "z"
"Cd:D:e:H:IMnNO:o:P:QR:U:vVw:WxX:y:Y:Z";
#ifdef LDAP_CONTROL_DONTUSECOPY
int dontUseCopy = 0;
#endif
int
handle_private_option( int i )
{
char *control, *cvalue;
int crit;
switch ( i ) {
case 'E': /* compare extensions */
if( protocol == LDAP_VERSION2 ) {
fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"),
prog, protocol );
exit( EXIT_FAILURE );
}
/* should be extended to support comma separated list of
* [!]key[=value] parameters, e.g. -E !foo,bar=567
*/
crit = 0;
cvalue = NULL;
if( optarg[0] == '!' ) {
crit = 1;
optarg++;
}
control = optarg;
if ( (cvalue = strchr( control, '=' )) != NULL ) {
*cvalue++ = '\0';
}
#ifdef LDAP_CONTROL_DONTUSECOPY
if ( strcasecmp( control, "dontUseCopy" ) == 0 ) {
if( dontUseCopy ) {
fprintf( stderr,
_("dontUseCopy control previously specified\n"));
exit( EXIT_FAILURE );
}
if( cvalue != NULL ) {
fprintf( stderr,
_("dontUseCopy: no control value expected\n") );
usage();
}
if( !crit ) {
fprintf( stderr,
_("dontUseCopy: critical flag required\n") );
usage();
}
dontUseCopy = 1 + crit;
} else
#endif
{
fprintf( stderr,
_("Invalid compare extension name: %s\n"), control );
usage();
}
break;
case 'z':
quiet = 1;
break;
default:
return 0;
}
return 1;
}
int
main( int argc, char **argv )
{
char *compdn = NULL, *attrs = NULL;
char *sep;
int rc;
LDAP *ld = NULL;
struct berval bvalue = { 0, NULL };
int i = 0;
LDAPControl c[1];
tool_init( TOOL_COMPARE );
prog = lutil_progname( "ldapcompare", argc, argv );
tool_args( argc, argv );
if ( argc - optind != 2 ) {
usage();
}
compdn = argv[optind++];
attrs = argv[optind++];
/* user passed in only 2 args, the last one better be in
* the form attr:value or attr::b64value
*/
sep = strchr(attrs, ':');
if (!sep) {
usage();
}
*sep++='\0';
if ( *sep != ':' ) {
bvalue.bv_val = strdup( sep );
bvalue.bv_len = strlen( bvalue.bv_val );
} else {
/* it's base64 encoded. */
bvalue.bv_val = malloc( strlen( &sep[1] ));
bvalue.bv_len = lutil_b64_pton( &sep[1],
(unsigned char *) bvalue.bv_val, strlen( &sep[1] ));
if (bvalue.bv_len == (ber_len_t)-1) {
fprintf(stderr, _("base64 decode error\n"));
exit(-1);
}
}
ld = tool_conn_setup( 0, 0 );
tool_bind( ld );
if ( 0
#ifdef LDAP_CONTROL_DONTUSECOPY
|| dontUseCopy
#endif
)
{
#ifdef LDAP_CONTROL_DONTUSECOPY
if ( dontUseCopy ) {
c[i].ldctl_oid = LDAP_CONTROL_DONTUSECOPY;
c[i].ldctl_value.bv_val = NULL;
c[i].ldctl_value.bv_len = 0;
c[i].ldctl_iscritical = dontUseCopy > 1;
i++;
}
#endif
}
tool_server_controls( ld, c, i );
if ( verbose ) {
fprintf( stderr, _("DN:%s, attr:%s, value:%s\n"),
compdn, attrs, sep );
}
rc = docompare( ld, compdn, attrs, &bvalue, quiet, NULL, NULL );
free( bvalue.bv_val );
tool_exit( ld, rc );
}
static int docompare(
LDAP *ld,
char *dn,
char *attr,
struct berval *bvalue,
int quiet,
LDAPControl **sctrls,
LDAPControl **cctrls )
{
int rc, msgid, code;
LDAPMessage *res;
char *matcheddn;
char *text;
char **refs;
LDAPControl **ctrls = NULL;
if ( dont ) {
return LDAP_SUCCESS;
}
rc = ldap_compare_ext( ld, dn, attr, bvalue,
sctrls, cctrls, &msgid );
if ( rc == -1 ) {
return( rc );
}
for ( ; ; ) {
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 100000;
if ( tool_check_abandon( ld, msgid ) ) {
return LDAP_CANCELLED;
}
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
return rc;
}
if ( rc != 0 ) {
break;
}
}
rc = ldap_parse_result( ld, res, &code, &matcheddn, &text, &refs, &ctrls, 1 );
if( rc != LDAP_SUCCESS ) {
fprintf( stderr, "%s: ldap_parse_result: %s (%d)\n",
prog, ldap_err2string( rc ), rc );
return rc;
}
if ( !quiet && ( verbose || ( code != LDAP_SUCCESS && code != LDAP_COMPARE_TRUE && code != LDAP_COMPARE_FALSE )||
(matcheddn && *matcheddn) || (text && *text) || (refs && *refs) ) )
{
printf( _("Compare Result: %s (%d)\n"),
ldap_err2string( code ), code );
if( text && *text ) {
printf( _("Additional info: %s\n"), text );
}
if( matcheddn && *matcheddn ) {
printf( _("Matched DN: %s\n"), matcheddn );
}
if( refs ) {
int i;
for( i=0; refs[i]; i++ ) {
printf(_("Referral: %s\n"), refs[i] );
}
}
}
/* if we were told to be quiet, use the return value. */
if ( !quiet ) {
if ( code == LDAP_COMPARE_TRUE ) {
printf(_("TRUE\n"));
} else if ( code == LDAP_COMPARE_FALSE ) {
printf(_("FALSE\n"));
} else {
printf(_("UNDEFINED\n"));
}
}
if ( ctrls ) {
tool_print_ctrls( ld, ctrls );
ldap_controls_free( ctrls );
}
ber_memfree( text );
ber_memfree( matcheddn );
ber_memvfree( (void **) refs );
return( code );
}
openldap-2.5.16+dfsg/clients/tools/common.c 0000644 0001750 0001750 00000207061 14461774414 020147 0 ustar sergio sergio /* common.c - common routines for the ldap client tools */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* Portions Copyright 2003 Kurt D. Zeilenga.
* Portions Copyright 2003 IBM Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* ACKNOWLEDGEMENTS:
* This file was initially created by Hallvard B. Furuseth based (in
* part) upon argument parsing code for individual tools located in
* this directory. Additional contributors include:
* Kurt D. Zeilenga (additional common argument and control support)
*/
#include "portable.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef HAVE_CYRUS_SASL
#ifdef HAVE_SASL_SASL_H
#include
#else
#include
#endif
#endif
#include
#include "ldif.h"
#include "lutil.h"
#include "lutil_ldap.h"
#include "ldap_defaults.h"
#include "ldap_pvt.h"
#include "lber_pvt.h"
#include "common.h"
/* input-related vars */
/* misc. parameters */
tool_type_t tool_type;
int contoper = 0;
int debug = 0;
char *infile = NULL;
int dont = 0;
int nocanon = 0;
int referrals = 0;
int verbose = 0;
int ldif = 0;
ber_len_t ldif_wrap = 0;
char *prog = NULL;
/* connection */
char *ldapuri = NULL;
int use_tls = 0;
int protocol = -1;
int version = 0;
/* authc/authz */
int authmethod = -1;
char *binddn = NULL;
int want_bindpw = 0;
struct berval passwd = { 0, NULL };
char *pw_file = NULL;
#ifdef HAVE_CYRUS_SASL
unsigned sasl_flags = LDAP_SASL_AUTOMATIC;
char *sasl_realm = NULL;
char *sasl_authc_id = NULL;
char *sasl_authz_id = NULL;
char *sasl_mech = NULL;
char *sasl_secprops = NULL;
#endif
/* controls */
int assertctl;
char *assertion = NULL;
struct berval assertionvalue = BER_BVNULL;
char *authzid = NULL;
int authzcrit = 1;
/* support deprecated early version of proxyAuthz */
#define LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ "2.16.840.1.113730.3.4.12"
#ifdef LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ
char *proxydn = NULL;
#endif /* LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ */
int manageDIT = 0;
int manageDSAit = 0;
int noop = 0;
int ppolicy = 0;
int preread = 0;
static char *preread_attrs = NULL;
int postread = 0;
static char *postread_attrs = NULL;
ber_int_t pr_morePagedResults = 1;
struct berval pr_cookie = { 0, NULL };
#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
int chaining = 0;
static int chainingResolve = -1;
static int chainingContinuation = -1;
#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
#ifdef LDAP_CONTROL_X_SESSION_TRACKING
static int sessionTracking = 0;
static char *sessionTrackingName;
struct berval stValue;
#endif /* LDAP_CONTROL_X_SESSION_TRACKING */
ber_int_t vlvPos;
ber_int_t vlvCount;
struct berval *vlvContext;
static int bauthzid;
LDAPControl *unknown_ctrls = NULL;
int unknown_ctrls_num = 0;
/* options */
struct timeval nettimeout = { -1 , 0 };
typedef int (*print_ctrl_fn)( LDAP *ld, LDAPControl *ctrl );
static int print_preread( LDAP *ld, LDAPControl *ctrl );
static int print_postread( LDAP *ld, LDAPControl *ctrl );
static int print_paged_results( LDAP *ld, LDAPControl *ctrl );
static int print_psearch( LDAP *ld, LDAPControl *ctrl );
#ifdef LDAP_CONTROL_AUTHZID_RESPONSE
static int print_authzid( LDAP *ld, LDAPControl *ctrl );
#endif
#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
static int print_ppolicy( LDAP *ld, LDAPControl *ctrl );
#endif
static int print_sss( LDAP *ld, LDAPControl *ctrl );
static int print_vlv( LDAP *ld, LDAPControl *ctrl );
#ifdef LDAP_CONTROL_X_DEREF
static int print_deref( LDAP *ld, LDAPControl *ctrl );
#endif
#ifdef LDAP_CONTROL_X_WHATFAILED
static int print_whatfailed( LDAP *ld, LDAPControl *ctrl );
#endif
static int print_syncstate( LDAP *ld, LDAPControl *ctrl );
static int print_syncdone( LDAP *ld, LDAPControl *ctrl );
#ifdef LDAP_CONTROL_X_DIRSYNC
static int print_dirsync( LDAP *ld, LDAPControl *ctrl );
#endif
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
static int print_account_usability( LDAP *ld, LDAPControl *ctrl );
#endif
#ifdef LDAP_CONTROL_X_PASSWORD_EXPIRED
static int print_netscape_pwexpired( LDAP *ld, LDAPControl *ctrl );
static int print_netscape_pwexpiring( LDAP *ld, LDAPControl *ctrl );
#endif
static struct tool_ctrls_t {
const char *oid;
unsigned mask;
print_ctrl_fn func;
} tool_ctrl_response[] = {
{ LDAP_CONTROL_PRE_READ, TOOL_ALL, print_preread },
{ LDAP_CONTROL_POST_READ, TOOL_ALL, print_postread },
{ LDAP_CONTROL_PAGEDRESULTS, TOOL_SEARCH, print_paged_results },
{ LDAP_CONTROL_PERSIST_ENTRY_CHANGE_NOTICE, TOOL_SEARCH, print_psearch },
#ifdef LDAP_CONTROL_AUTHZID_RESPONSE
/* this is generally deprecated in favor of LDAP WhoAmI? operation, hence only supported as a VC inner control */
{ LDAP_CONTROL_AUTHZID_RESPONSE, TOOL_VC, print_authzid },
#endif
#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
{ LDAP_CONTROL_PASSWORDPOLICYRESPONSE, TOOL_ALL, print_ppolicy },
#endif
{ LDAP_CONTROL_SORTRESPONSE, TOOL_SEARCH, print_sss },
{ LDAP_CONTROL_VLVRESPONSE, TOOL_SEARCH, print_vlv },
#ifdef LDAP_CONTROL_X_DEREF
{ LDAP_CONTROL_X_DEREF, TOOL_SEARCH, print_deref },
#endif
#ifdef LDAP_CONTROL_X_WHATFAILED
{ LDAP_CONTROL_X_WHATFAILED, TOOL_ALL, print_whatfailed },
#endif
{ LDAP_CONTROL_SYNC_STATE, TOOL_SEARCH, print_syncstate },
{ LDAP_CONTROL_SYNC_DONE, TOOL_SEARCH, print_syncdone },
#ifdef LDAP_CONTROL_X_DIRSYNC
{ LDAP_CONTROL_X_DIRSYNC, TOOL_SEARCH, print_dirsync },
#endif
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
{ LDAP_CONTROL_X_ACCOUNT_USABILITY, TOOL_SEARCH, print_account_usability },
#endif
#ifdef LDAP_CONTROL_X_PASSWORD_EXPIRED
{ LDAP_CONTROL_X_PASSWORD_EXPIRED, TOOL_ALL, print_netscape_pwexpired },
{ LDAP_CONTROL_X_PASSWORD_EXPIRING, TOOL_ALL, print_netscape_pwexpiring },
#endif
{ NULL, 0, NULL }
};
/* "features" */
enum { Intr_None = 0, Intr_Abandon, Intr_Cancel, Intr_Ignore };
static volatile sig_atomic_t gotintr, abcan;
int backlog;
#ifdef LDAP_CONTROL_X_SESSION_TRACKING
static int
st_value( LDAP *ld, struct berval *value )
{
char *ip = NULL, *name = NULL;
struct berval id = { 0 };
char namebuf[ MAXHOSTNAMELEN ];
if ( gethostname( namebuf, sizeof( namebuf ) ) == 0 ) {
struct hostent *h;
struct in_addr addr;
name = namebuf;
h = gethostbyname( name );
if ( h != NULL ) {
AC_MEMCPY( &addr, h->h_addr, sizeof( addr ) );
ip = inet_ntoa( addr );
}
}
if ( sessionTrackingName != NULL ) {
ber_str2bv( sessionTrackingName , 0, 0, &id );
} else
#ifdef HAVE_CYRUS_SASL
if ( sasl_authz_id != NULL ) {
ber_str2bv( sasl_authz_id, 0, 0, &id );
} else if ( sasl_authc_id != NULL ) {
ber_str2bv( sasl_authc_id, 0, 0, &id );
} else
#endif /* HAVE_CYRUS_SASL */
if ( binddn != NULL ) {
ber_str2bv( binddn, 0, 0, &id );
}
if ( ldap_create_session_tracking_value( ld,
ip, name, LDAP_CONTROL_X_SESSION_TRACKING_USERNAME,
&id, &stValue ) )
{
fprintf( stderr, _("Session tracking control encoding error!\n") );
return -1;
}
return 0;
}
#endif /* LDAP_CONTROL_X_SESSION_TRACKING */
RETSIGTYPE
do_sig( int sig )
{
gotintr = abcan;
}
void
tool_init( tool_type_t type )
{
tool_type = type;
ldap_pvt_setlocale(LC_MESSAGES, "");
ldap_pvt_bindtextdomain(OPENLDAP_PACKAGE, LDAP_LOCALEDIR);
ldap_pvt_textdomain(OPENLDAP_PACKAGE);
}
void
tool_destroy( void )
{
static int destroyed;
if ( destroyed++ )
return;
#ifdef HAVE_CYRUS_SASL
sasl_done();
#endif
#ifdef HAVE_TLS
ldap_pvt_tls_destroy();
#endif
if ( ldapuri != NULL ) {
ber_memfree( ldapuri );
ldapuri = NULL;
}
if ( pr_cookie.bv_val != NULL ) {
ber_memfree( pr_cookie.bv_val );
BER_BVZERO( &pr_cookie );
}
if ( passwd.bv_val != NULL ) {
ber_memfree( passwd.bv_val );
BER_BVZERO( &passwd );
}
#ifdef LDAP_CONTROL_X_SESSION_TRACKING
if ( !BER_BVISNULL( &stValue ) ) {
ber_memfree( stValue.bv_val );
BER_BVZERO( &stValue );
}
#endif /* LDAP_CONTROL_X_SESSION_TRACKING */
}
void
tool_common_usage( void )
{
static const char *const descriptions[] = {
N_(" -d level set LDAP debugging level to `level'\n"),
N_(" -D binddn bind DN\n"),
N_(" -e [!][=] general extensions (! indicates criticality)\n")
N_(" [!]assert= (RFC 4528; a RFC 4515 Filter string)\n")
N_(" [!]authzid= (RFC 4370; \"dn:\" or \"u:\")\n")
N_(" [!]bauthzid (RFC 3829)\n")
#ifdef LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ
#if 0
/* non-advertized support for proxyDN */
N_(" [!]proxydn= (a RFC 4514 DN string)\n")
#endif
#endif
#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
N_(" [!]chaining[=[/]]\n")
N_(" one of \"chainingPreferred\", \"chainingRequired\",\n")
N_(" \"referralsPreferred\", \"referralsRequired\"\n")
#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
N_(" [!]manageDSAit (RFC 3296)\n")
N_(" [!]noop\n")
#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
N_(" ppolicy\n")
#endif
N_(" [!]postread[=] (RFC 4527; comma-separated attr list)\n")
N_(" [!]preread[=] (RFC 4527; comma-separated attr list)\n")
N_(" [!]relax\n")
#ifdef LDAP_CONTROL_X_SESSION_TRACKING
N_(" [!]sessiontracking[=]\n")
#endif /* LDAP_CONTROL_X_SESSION_TRACKING */
N_(" abandon, cancel, ignore (SIGINT sends abandon/cancel,\n"
" or ignores response; if critical, doesn't wait for SIGINT.\n"
" not really controls)\n")
N_(" -H URI LDAP Uniform Resource Identifier(s)\n"),
N_(" -I use SASL Interactive mode\n"),
N_(" -n show what would be done but don't actually do it\n"),
N_(" -N do not use reverse DNS to canonicalize SASL host name\n"),
N_(" -O props SASL security properties\n"),
N_(" -o [=] any libldap ldap.conf options, plus\n"),
N_(" ldif_wrap= (in columns, or \"no\" for no wrapping)\n"),
N_(" nettimeout= (in seconds, or \"none\" or \"max\")\n"),
N_(" -Q use SASL Quiet mode\n"),
N_(" -R realm SASL realm\n"),
N_(" -U authcid SASL authentication identity\n"),
N_(" -v run in verbose mode (diagnostics to standard output)\n"),
N_(" -V print version info (-VV only)\n"),
N_(" -w passwd bind password (for simple authentication)\n"),
N_(" -W prompt for bind password\n"),
N_(" -x Simple authentication\n"),
N_(" -X authzid SASL authorization identity (\"dn:\" or \"u:\")\n"),
N_(" -y file Read password from file\n"),
N_(" -Y mech SASL mechanism\n"),
N_(" -Z Start TLS request (-ZZ to require successful response)\n"),
NULL
};
const char *const *cpp;
fputs( _("Common options:\n"), stderr );
for( cpp = descriptions; *cpp != NULL; cpp++ ) {
if( strchr( options, (*cpp)[3] ) || (*cpp)[3] == ' ' ) {
fputs( _(*cpp), stderr );
}
}
tool_destroy();
}
void tool_perror(
const char *func,
int err,
const char *extra,
const char *matched,
const char *info,
char **refs )
{
fprintf( stderr, "%s: %s (%d)%s\n",
func, ldap_err2string( err ), err, extra ? extra : "" );
if ( matched && *matched ) {
fprintf( stderr, _("\tmatched DN: %s\n"), matched );
}
if ( info && *info ) {
fprintf( stderr, _("\tadditional info: %s\n"), info );
}
if ( refs && *refs ) {
int i;
fprintf( stderr, _("\treferrals:\n") );
for( i=0; refs[i]; i++ ) {
fprintf( stderr, "\t\t%s\n", refs[i] );
}
}
}
void
tool_args( int argc, char **argv )
{
int i;
while (( i = getopt( argc, argv, options )) != EOF ) {
int crit, ival;
char *control, *cvalue, *next;
switch( i ) {
case 'c': /* continuous operation mode */
contoper++;
break;
case 'C': /* referrals: obsolete */
referrals++;
break;
case 'd':
ival = strtol( optarg, &next, 10 );
if (next == NULL || next[0] != '\0') {
fprintf( stderr, "%s: unable to parse debug value \"%s\"\n", prog, optarg);
exit(EXIT_FAILURE);
}
debug |= ival;
break;
case 'D': /* bind DN */
if( binddn != NULL ) {
fprintf( stderr, "%s: -D previously specified\n", prog );
exit( EXIT_FAILURE );
}
binddn = optarg;
break;
case 'e': /* general extensions (controls and such) */
/* should be extended to support comma separated list of
* [!]key[=value] parameters, e.g. -e !foo,bar=567
*/
crit = 0;
cvalue = NULL;
while ( optarg[0] == '!' ) {
crit++;
optarg++;
}
control = optarg;
if ( (cvalue = strchr( control, '=' )) != NULL ) {
*cvalue++ = '\0';
}
if ( strcasecmp( control, "assert" ) == 0 ) {
if( assertctl ) {
fprintf( stderr, "assert control previously specified\n");
exit( EXIT_FAILURE );
}
if( cvalue == NULL ) {
fprintf( stderr, "assert: control value expected\n" );
usage();
}
assertctl = 1 + crit;
assert( assertion == NULL );
assertion = cvalue;
} else if ( strcasecmp( control, "authzid" ) == 0 ) {
if( authzid != NULL ) {
fprintf( stderr, "authzid control previously specified\n");
exit( EXIT_FAILURE );
}
#ifdef LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ
if( proxydn != NULL ) {
fprintf( stderr, "authzid control incompatible with proxydn\n");
exit( EXIT_FAILURE );
}
#endif /* LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ */
if( cvalue == NULL ) {
fprintf( stderr, "authzid: control value expected\n" );
usage();
}
if( !crit ) {
fprintf( stderr, "authzid: must be marked critical\n" );
usage();
} else if ( crit > 1 ) {
/* purposely flag proxied authorization
* as non-critical, to test DSA */
authzcrit = 0;
}
assert( authzid == NULL );
authzid = cvalue;
#ifdef LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ
} else if ( strcasecmp( control, "proxydn" ) == 0 ) {
if( proxydn != NULL ) {
fprintf( stderr, "proxydn control previously specified\n");
exit( EXIT_FAILURE );
}
if( authzid != NULL ) {
fprintf( stderr, "proxydn control incompatible with authzid\n");
exit( EXIT_FAILURE );
}
if( cvalue == NULL ) {
fprintf( stderr, "proxydn: control value expected\n" );
usage();
}
if( !crit ) {
fprintf( stderr, "proxydn: must be marked critical\n" );
usage();
} else if ( crit > 1 ) {
/* purposely flag proxied authorization
* as non-critical, to test DSA */
authzcrit = 0;
}
assert( proxydn == NULL );
proxydn = cvalue;
#endif /* LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ */
} else if ( strcasecmp( control, "bauthzid" ) == 0 ) {
if( bauthzid ) {
fprintf( stderr, "bauthzid control previously specified\n");
exit( EXIT_FAILURE );
}
if( cvalue != NULL ) {
fprintf( stderr, "bauthzid: no control value expected\n" );
usage();
}
bauthzid = 1 + crit;
} else if ( ( strcasecmp( control, "relax" ) == 0 ) ||
( strcasecmp( control, "manageDIT" ) == 0 ) )
{
if( manageDIT ) {
fprintf( stderr,
"relax control previously specified\n");
exit( EXIT_FAILURE );
}
if( cvalue != NULL ) {
fprintf( stderr,
"relax: no control value expected\n" );
usage();
}
manageDIT = 1 + crit;
} else if ( strcasecmp( control, "manageDSAit" ) == 0 ) {
if( manageDSAit ) {
fprintf( stderr,
"manageDSAit control previously specified\n");
exit( EXIT_FAILURE );
}
if( cvalue != NULL ) {
fprintf( stderr,
"manageDSAit: no control value expected\n" );
usage();
}
manageDSAit = 1 + crit;
} else if ( strcasecmp( control, "noop" ) == 0 ) {
if( noop ) {
fprintf( stderr, "noop control previously specified\n");
exit( EXIT_FAILURE );
}
if( cvalue != NULL ) {
fprintf( stderr, "noop: no control value expected\n" );
usage();
}
noop = 1 + crit;
#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
} else if ( strcasecmp( control, "ppolicy" ) == 0 ) {
if( ppolicy ) {
fprintf( stderr, "ppolicy control previously specified\n");
exit( EXIT_FAILURE );
}
if( cvalue != NULL ) {
fprintf( stderr, "ppolicy: no control value expected\n" );
usage();
}
if( crit ) {
fprintf( stderr, "ppolicy: critical flag not allowed\n" );
usage();
}
ppolicy = 1;
#endif
} else if ( strcasecmp( control, "preread" ) == 0 ) {
if( preread ) {
fprintf( stderr, "preread control previously specified\n");
exit( EXIT_FAILURE );
}
preread = 1 + crit;
preread_attrs = cvalue;
} else if ( strcasecmp( control, "postread" ) == 0 ) {
if( postread ) {
fprintf( stderr, "postread control previously specified\n");
exit( EXIT_FAILURE );
}
postread = 1 + crit;
postread_attrs = cvalue;
#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
} else if ( strcasecmp( control, "chaining" ) == 0 ) {
if ( chaining ) {
fprintf( stderr, "chaining control previously specified\n");
exit( EXIT_FAILURE );
}
chaining = 1 + crit;
if ( cvalue != NULL ) {
char *continuation;
continuation = strchr( cvalue, '/' );
if ( continuation ) {
/* FIXME: this makes sense only in searches */
*continuation++ = '\0';
if ( strcasecmp( continuation, "chainingPreferred" ) == 0 ) {
chainingContinuation = LDAP_CHAINING_PREFERRED;
} else if ( strcasecmp( continuation, "chainingRequired" ) == 0 ) {
chainingContinuation = LDAP_CHAINING_REQUIRED;
} else if ( strcasecmp( continuation, "referralsPreferred" ) == 0 ) {
chainingContinuation = LDAP_REFERRALS_PREFERRED;
} else if ( strcasecmp( continuation, "referralsRequired" ) == 0 ) {
chainingContinuation = LDAP_REFERRALS_REQUIRED;
} else {
fprintf( stderr,
"chaining behavior control "
"continuation value \"%s\" invalid\n",
continuation );
exit( EXIT_FAILURE );
}
}
if ( strcasecmp( cvalue, "chainingPreferred" ) == 0 ) {
chainingResolve = LDAP_CHAINING_PREFERRED;
} else if ( strcasecmp( cvalue, "chainingRequired" ) == 0 ) {
chainingResolve = LDAP_CHAINING_REQUIRED;
} else if ( strcasecmp( cvalue, "referralsPreferred" ) == 0 ) {
chainingResolve = LDAP_REFERRALS_PREFERRED;
} else if ( strcasecmp( cvalue, "referralsRequired" ) == 0 ) {
chainingResolve = LDAP_REFERRALS_REQUIRED;
} else {
fprintf( stderr,
"chaining behavior control "
"resolve value \"%s\" invalid\n",
cvalue);
exit( EXIT_FAILURE );
}
}
#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
#ifdef LDAP_CONTROL_X_SESSION_TRACKING
} else if ( strcasecmp( control, "sessiontracking" ) == 0 ) {
if ( sessionTracking ) {
fprintf( stderr, "%s: session tracking can be only specified once\n", prog );
exit( EXIT_FAILURE );
}
sessionTracking = 1;
if ( crit ) {
fprintf( stderr, "sessiontracking: critical flag not allowed\n" );
usage();
}
if ( cvalue ) {
sessionTrackingName = cvalue;
}
#endif /* LDAP_CONTROL_X_SESSION_TRACKING */
/* this shouldn't go here, really; but it's a feature... */
} else if ( strcasecmp( control, "abandon" ) == 0 ) {
abcan = Intr_Abandon;
if ( crit ) {
gotintr = abcan;
}
} else if ( strcasecmp( control, "cancel" ) == 0 ) {
abcan = Intr_Cancel;
if ( crit ) {
gotintr = abcan;
}
} else if ( strcasecmp( control, "ignore" ) == 0 ) {
abcan = Intr_Ignore;
if ( crit ) {
gotintr = abcan;
}
} else if ( strcasecmp( control, "backlog" ) == 0 ) {
/* special search: accumulate lots of responses
* but don't read any, force slapd writer to wait.
* Then abandon the search and issue a new one.
*/
backlog = 1;
} else if ( tool_is_oid( control ) ) {
LDAPControl *tmpctrls, ctrl;
if ( unknown_ctrls != NULL ) {
int i;
for ( i = 0; unknown_ctrls[ i ].ldctl_oid != NULL; i++ ) {
if ( strcmp( control, unknown_ctrls[ i ].ldctl_oid ) == 0 ) {
fprintf( stderr, "%s control previously specified\n", control );
exit( EXIT_FAILURE );
}
}
}
tmpctrls = (LDAPControl *)ber_memrealloc( unknown_ctrls,
(unknown_ctrls_num + 1)*sizeof( LDAPControl ) );
if ( tmpctrls == NULL ) {
fprintf( stderr, "%s: no memory?\n", prog );
exit( EXIT_FAILURE );
}
unknown_ctrls = tmpctrls;
ctrl.ldctl_oid = control;
ctrl.ldctl_value.bv_val = NULL;
ctrl.ldctl_value.bv_len = 0;
ctrl.ldctl_iscritical = crit;
if ( cvalue != NULL ) {
struct berval bv;
size_t len = strlen( cvalue );
int retcode;
bv.bv_len = LUTIL_BASE64_DECODE_LEN( len );
bv.bv_val = ber_memalloc( bv.bv_len + 1 );
retcode = lutil_b64_pton( cvalue,
(unsigned char *)bv.bv_val,
bv.bv_len );
if ( retcode == -1 || (unsigned) retcode > bv.bv_len ) {
fprintf( stderr, "Unable to parse value of general control %s\n",
control );
usage();
}
bv.bv_len = retcode;
ctrl.ldctl_value = bv;
}
/* don't free it */
control = NULL;
unknown_ctrls[ unknown_ctrls_num ] = ctrl;
unknown_ctrls_num++;
} else {
fprintf( stderr, "Invalid general control name: %s\n",
control );
usage();
}
break;
case 'f': /* read from file */
if( infile != NULL ) {
fprintf( stderr, "%s: -f previously specified\n", prog );
exit( EXIT_FAILURE );
}
infile = optarg;
break;
case 'H': /* ldap URI */
if( ldapuri != NULL ) {
fprintf( stderr, "%s: -H previously specified\n", prog );
exit( EXIT_FAILURE );
}
ldapuri = ber_strdup( optarg );
break;
case 'I':
#ifdef HAVE_CYRUS_SASL
if( authmethod != -1 && authmethod != LDAP_AUTH_SASL ) {
fprintf( stderr, "%s: incompatible previous "
"authentication choice\n",
prog );
exit( EXIT_FAILURE );
}
authmethod = LDAP_AUTH_SASL;
sasl_flags = LDAP_SASL_INTERACTIVE;
break;
#else
fprintf( stderr, "%s: was not compiled with SASL support\n",
prog );
exit( EXIT_FAILURE );
#endif
case 'M':
/* enable Manage DSA IT */
manageDSAit++;
break;
case 'n': /* print operations, don't actually do them */
dont++;
break;
case 'N':
nocanon++;
break;
case 'o':
control = optarg;
if ( (cvalue = strchr( control, '=' )) != NULL ) {
*cvalue++ = '\0';
}
for ( next=control; *next; next++ ) {
if ( *next == '-' ) {
*next = '_';
}
}
if ( strcasecmp( control, "nettimeout" ) == 0 ) {
if( nettimeout.tv_sec != -1 ) {
fprintf( stderr, "nettimeout option previously specified\n");
exit( EXIT_FAILURE );
}
if( cvalue == NULL || cvalue[0] == '\0' ) {
fprintf( stderr, "nettimeout: option value expected\n" );
usage();
}
if ( strcasecmp( cvalue, "none" ) == 0 ) {
nettimeout.tv_sec = 0;
} else if ( strcasecmp( cvalue, "max" ) == 0 ) {
nettimeout.tv_sec = LDAP_MAXINT;
} else {
ival = strtol( cvalue, &next, 10 );
if ( next == NULL || next[0] != '\0' ) {
fprintf( stderr,
_("Unable to parse network timeout \"%s\"\n"), cvalue );
exit( EXIT_FAILURE );
}
nettimeout.tv_sec = ival;
}
if( nettimeout.tv_sec < 0 || nettimeout.tv_sec > LDAP_MAXINT ) {
fprintf( stderr, _("%s: invalid network timeout (%ld) specified\n"),
prog, (long)nettimeout.tv_sec );
exit( EXIT_FAILURE );
}
} else if ( strcasecmp( control, "ldif_wrap" ) == 0 ) {
if ( cvalue == 0 ) {
ldif_wrap = LDIF_LINE_WIDTH;
} else if ( strcasecmp( cvalue, "no" ) == 0 ) {
ldif_wrap = LDIF_LINE_WIDTH_MAX;
} else {
unsigned int u;
if ( lutil_atou( &u, cvalue ) ) {
fprintf( stderr,
_("Unable to parse ldif_wrap=\"%s\"\n"), cvalue );
exit( EXIT_FAILURE );
}
ldif_wrap = (ber_len_t)u;
}
} else if ( ldap_pvt_conf_option( control, cvalue, 1 ) ) {
fprintf( stderr, "Invalid general option name: %s\n",
control );
usage();
}
break;
case 'O':
#ifdef HAVE_CYRUS_SASL
if( sasl_secprops != NULL ) {
fprintf( stderr, "%s: -O previously specified\n", prog );
exit( EXIT_FAILURE );
}
if( authmethod != -1 && authmethod != LDAP_AUTH_SASL ) {
fprintf( stderr, "%s: incompatible previous "
"authentication choice\n", prog );
exit( EXIT_FAILURE );
}
authmethod = LDAP_AUTH_SASL;
sasl_secprops = optarg;
#else
fprintf( stderr, "%s: not compiled with SASL support\n", prog );
exit( EXIT_FAILURE );
#endif
break;
case 'P':
ival = strtol( optarg, &next, 10 );
if ( next == NULL || next[0] != '\0' ) {
fprintf( stderr, "%s: unable to parse protocol version \"%s\"\n", prog, optarg );
exit( EXIT_FAILURE );
}
switch( ival ) {
case 2:
if( protocol == LDAP_VERSION3 ) {
fprintf( stderr, "%s: -P 2 incompatible with version %d\n",
prog, protocol );
exit( EXIT_FAILURE );
}
protocol = LDAP_VERSION2;
break;
case 3:
if( protocol == LDAP_VERSION2 ) {
fprintf( stderr, "%s: -P 2 incompatible with version %d\n",
prog, protocol );
exit( EXIT_FAILURE );
}
protocol = LDAP_VERSION3;
break;
default:
fprintf( stderr, "%s: protocol version should be 2 or 3\n",
prog );
usage();
}
break;
case 'Q':
#ifdef HAVE_CYRUS_SASL
if( authmethod != -1 && authmethod != LDAP_AUTH_SASL ) {
fprintf( stderr, "%s: incompatible previous "
"authentication choice\n",
prog );
exit( EXIT_FAILURE );
}
authmethod = LDAP_AUTH_SASL;
sasl_flags = LDAP_SASL_QUIET;
break;
#else
fprintf( stderr, "%s: not compiled with SASL support\n",
prog );
exit( EXIT_FAILURE );
#endif
case 'R':
#ifdef HAVE_CYRUS_SASL
if( sasl_realm != NULL ) {
fprintf( stderr, "%s: -R previously specified\n", prog );
exit( EXIT_FAILURE );
}
if( authmethod != -1 && authmethod != LDAP_AUTH_SASL ) {
fprintf( stderr, "%s: incompatible previous "
"authentication choice\n",
prog );
exit( EXIT_FAILURE );
}
authmethod = LDAP_AUTH_SASL;
sasl_realm = optarg;
#else
fprintf( stderr, "%s: not compiled with SASL support\n",
prog );
exit( EXIT_FAILURE );
#endif
break;
case 'U':
#ifdef HAVE_CYRUS_SASL
if( sasl_authc_id != NULL ) {
fprintf( stderr, "%s: -U previously specified\n", prog );
exit( EXIT_FAILURE );
}
if( authmethod != -1 && authmethod != LDAP_AUTH_SASL ) {
fprintf( stderr, "%s: incompatible previous "
"authentication choice\n",
prog );
exit( EXIT_FAILURE );
}
authmethod = LDAP_AUTH_SASL;
sasl_authc_id = optarg;
#else
fprintf( stderr, "%s: not compiled with SASL support\n",
prog );
exit( EXIT_FAILURE );
#endif
break;
case 'v': /* verbose mode */
verbose++;
break;
case 'V': /* version */
version++;
break;
case 'w': /* password */
passwd.bv_val = ber_strdup( optarg );
{
char* p;
for( p = optarg; *p != '\0'; p++ ) {
*p = '\0';
}
}
passwd.bv_len = strlen( passwd.bv_val );
break;
case 'W':
want_bindpw++;
break;
case 'y':
pw_file = optarg;
break;
case 'Y':
#ifdef HAVE_CYRUS_SASL
if( sasl_mech != NULL ) {
fprintf( stderr, "%s: -Y previously specified\n", prog );
exit( EXIT_FAILURE );
}
if( authmethod != -1 && authmethod != LDAP_AUTH_SASL ) {
fprintf( stderr,
"%s: incompatible with authentication choice\n", prog );
exit( EXIT_FAILURE );
}
authmethod = LDAP_AUTH_SASL;
sasl_mech = optarg;
#else
fprintf( stderr, "%s: not compiled with SASL support\n", prog );
exit( EXIT_FAILURE );
#endif
break;
case 'x':
if( authmethod != -1 && authmethod != LDAP_AUTH_SIMPLE ) {
fprintf( stderr, "%s: incompatible with previous "
"authentication choice\n", prog );
exit( EXIT_FAILURE );
}
authmethod = LDAP_AUTH_SIMPLE;
break;
case 'X':
#ifdef HAVE_CYRUS_SASL
if( sasl_authz_id != NULL ) {
fprintf( stderr, "%s: -X previously specified\n", prog );
exit( EXIT_FAILURE );
}
if( authmethod != -1 && authmethod != LDAP_AUTH_SASL ) {
fprintf( stderr, "%s: -X incompatible with "
"authentication choice\n", prog );
exit( EXIT_FAILURE );
}
authmethod = LDAP_AUTH_SASL;
sasl_authz_id = optarg;
#else
fprintf( stderr, "%s: not compiled with SASL support\n", prog );
exit( EXIT_FAILURE );
#endif
break;
case 'Z':
#ifdef HAVE_TLS
use_tls++;
#else
fprintf( stderr, "%s: not compiled with TLS support\n", prog );
exit( EXIT_FAILURE );
#endif
break;
default:
if( handle_private_option( i ) ) break;
fprintf( stderr, "%s: unrecognized option -%c\n",
prog, optopt );
usage();
}
}
{
/* prevent bad linking */
LDAPAPIInfo api;
api.ldapai_info_version = LDAP_API_INFO_VERSION;
if ( ldap_get_option(NULL, LDAP_OPT_API_INFO, &api)
!= LDAP_OPT_SUCCESS )
{
fprintf( stderr, "%s: ldap_get_option(API_INFO) failed\n", prog );
exit( EXIT_FAILURE );
}
if (api.ldapai_info_version != LDAP_API_INFO_VERSION) {
fprintf( stderr, "LDAP APIInfo version mismatch: "
"library %d, header %d\n",
api.ldapai_info_version, LDAP_API_INFO_VERSION );
exit( EXIT_FAILURE );
}
if( api.ldapai_api_version != LDAP_API_VERSION ) {
fprintf( stderr, "LDAP API version mismatch: "
"library %d, header %d\n",
api.ldapai_api_version, LDAP_API_VERSION );
exit( EXIT_FAILURE );
}
if( strcmp(api.ldapai_vendor_name, LDAP_VENDOR_NAME ) != 0 ) {
fprintf( stderr, "LDAP vendor name mismatch: "
"library %s, header %s\n",
api.ldapai_vendor_name, LDAP_VENDOR_NAME );
exit( EXIT_FAILURE );
}
if( api.ldapai_vendor_version != LDAP_VENDOR_VERSION ) {
fprintf( stderr, "LDAP vendor version mismatch: "
"library %d, header %d\n",
api.ldapai_vendor_version, LDAP_VENDOR_VERSION );
exit( EXIT_FAILURE );
}
if (version) {
fprintf( stderr, "%s: %s\t(LDAP library: %s %d)\n",
prog, __Version,
LDAP_VENDOR_NAME, LDAP_VENDOR_VERSION );
if (version > 1) exit( EXIT_SUCCESS );
}
ldap_memfree( api.ldapai_vendor_name );
ber_memvfree( (void **)api.ldapai_extensions );
}
if (protocol == -1)
protocol = LDAP_VERSION3;
if (authmethod == -1 && protocol > LDAP_VERSION2) {
#ifdef HAVE_CYRUS_SASL
if ( binddn != NULL ) {
authmethod = LDAP_AUTH_SIMPLE;
} else {
authmethod = LDAP_AUTH_SASL;
}
#else
authmethod = LDAP_AUTH_SIMPLE;
#endif
}
if( protocol == LDAP_VERSION2 ) {
if( assertctl || authzid || manageDIT || manageDSAit ||
#ifdef LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ
proxydn ||
#endif /* LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ */
#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
chaining ||
#endif
#ifdef LDAP_CONTROL_X_SESSION_TRACKING
sessionTracking ||
#endif /* LDAP_CONTROL_X_SESSION_TRACKING */
noop || ppolicy || preread || postread )
{
fprintf( stderr, "%s: -e/-M incompatible with LDAPv2\n", prog );
exit( EXIT_FAILURE );
}
#ifdef HAVE_TLS
if( use_tls ) {
fprintf( stderr, "%s: -Z incompatible with LDAPv2\n", prog );
exit( EXIT_FAILURE );
}
#endif
#ifdef HAVE_CYRUS_SASL
if( authmethod == LDAP_AUTH_SASL ) {
fprintf( stderr, "%s: -[IOQRUXY] incompatible with LDAPv2\n",
prog );
exit( EXIT_FAILURE );
}
#endif
}
if ( ( pw_file || want_bindpw ) && !BER_BVISNULL( &passwd ) ) {
fprintf( stderr, "%s: -%c incompatible with -w\n",
prog, ( pw_file ? 'y' : 'W' ) );
exit( EXIT_FAILURE );
}
}
LDAP *
tool_conn_setup( int dont, void (*private_setup)( LDAP * ) )
{
LDAP *ld = NULL;
if ( debug ) {
if( ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &debug )
!= LBER_OPT_SUCCESS )
{
fprintf( stderr,
"Could not set LBER_OPT_DEBUG_LEVEL %d\n", debug );
}
if( ldap_set_option( NULL, LDAP_OPT_DEBUG_LEVEL, &debug )
!= LDAP_OPT_SUCCESS )
{
fprintf( stderr,
"Could not set LDAP_OPT_DEBUG_LEVEL %d\n", debug );
}
}
#ifdef SIGPIPE
(void) SIGNAL( SIGPIPE, SIG_IGN );
#endif
if ( abcan ) {
SIGNAL( SIGINT, do_sig );
}
if ( !dont ) {
int rc;
if ( ldapuri != NULL ) {
LDAPURLDesc *ludlist, **ludp;
char **urls = NULL;
int nurls = 0;
rc = ldap_url_parselist( &ludlist, ldapuri );
if ( rc != LDAP_URL_SUCCESS ) {
fprintf( stderr,
"Could not parse LDAP URI(s)=%s (%d)\n",
ldapuri, rc );
exit( EXIT_FAILURE );
}
for ( ludp = &ludlist; *ludp != NULL; ) {
LDAPURLDesc *lud = *ludp;
char **tmp;
if ( lud->lud_dn != NULL && lud->lud_dn[ 0 ] != '\0' &&
( lud->lud_host == NULL || lud->lud_host[0] == '\0' ) )
{
/* if no host but a DN is provided,
* use DNS SRV to gather the host list
* and turn it into a list of URIs
* using the scheme provided */
char *domain = NULL,
*hostlist = NULL,
**hosts = NULL;
int i,
len_proto = strlen( lud->lud_scheme );
if ( ldap_dn2domain( lud->lud_dn, &domain )
|| domain == NULL )
{
fprintf( stderr,
"DNS SRV: Could not turn "
"DN=\"%s\" into a domain\n",
lud->lud_dn );
goto dnssrv_free;
}
rc = ldap_domain2hostlist( domain, &hostlist );
if ( rc ) {
fprintf( stderr,
"DNS SRV: Could not turn "
"domain=%s into a hostlist\n",
domain );
goto dnssrv_free;
}
hosts = ldap_str2charray( hostlist, " " );
if ( hosts == NULL ) {
fprintf( stderr,
"DNS SRV: Could not parse "
"hostlist=\"%s\"\n",
hostlist );
goto dnssrv_free;
}
for ( i = 0; hosts[ i ] != NULL; i++ )
/* count'em */ ;
tmp = (char **)ber_memrealloc( urls, sizeof( char * ) * ( nurls + i + 1 ) );
if ( tmp == NULL ) {
fprintf( stderr,
"DNS SRV: out of memory?\n" );
goto dnssrv_free;
}
urls = tmp;
urls[ nurls ] = NULL;
for ( i = 0; hosts[ i ] != NULL; i++ ) {
size_t len = len_proto
+ STRLENOF( "://" )
+ strlen( hosts[ i ] )
+ 1;
urls[ nurls + i + 1 ] = NULL;
urls[ nurls + i ] = (char *)malloc( sizeof( char ) * len );
if ( urls[ nurls + i ] == NULL ) {
fprintf( stderr,
"DNS SRV: out of memory?\n" );
goto dnssrv_free;
}
snprintf( urls[ nurls + i ], len, "%s://%s",
lud->lud_scheme, hosts[ i ] );
}
nurls += i;
dnssrv_free:;
ber_memvfree( (void **)hosts );
ber_memfree( hostlist );
ber_memfree( domain );
} else {
tmp = (char **)ber_memrealloc( urls, sizeof( char * ) * ( nurls + 2 ) );
if ( tmp == NULL ) {
fprintf( stderr,
"DNS SRV: out of memory?\n" );
break;
}
urls = tmp;
urls[ nurls + 1 ] = NULL;
urls[ nurls ] = ldap_url_desc2str( lud );
if ( urls[ nurls ] == NULL ) {
fprintf( stderr,
"DNS SRV: out of memory?\n" );
break;
}
nurls++;
}
*ludp = lud->lud_next;
lud->lud_next = NULL;
ldap_free_urldesc( lud );
}
if ( ludlist != NULL ) {
ldap_free_urllist( ludlist );
exit( EXIT_FAILURE );
} else if ( urls == NULL ) {
exit( EXIT_FAILURE );
}
ldap_memfree( ldapuri );
ldapuri = ldap_charray2str( urls, " " );
ber_memvfree( (void **)urls );
}
if ( verbose ) {
fprintf( stderr, "ldap_initialize( %s )\n",
ldapuri != NULL ? ldapuri : "" );
}
rc = ldap_initialize( &ld, ldapuri );
if( rc != LDAP_SUCCESS ) {
fprintf( stderr,
"Could not create LDAP session handle for URI=%s (%d): %s\n",
ldapuri, rc, ldap_err2string(rc) );
exit( EXIT_FAILURE );
}
if( private_setup ) private_setup( ld );
/* referrals: obsolete */
if( ldap_set_option( ld, LDAP_OPT_REFERRALS,
referrals ? LDAP_OPT_ON : LDAP_OPT_OFF ) != LDAP_OPT_SUCCESS )
{
fprintf( stderr, "Could not set LDAP_OPT_REFERRALS %s\n",
referrals ? "on" : "off" );
tool_exit( ld, EXIT_FAILURE );
}
#ifdef HAVE_CYRUS_SASL
/* canon */
if( nocanon ) {
if( ldap_set_option( ld, LDAP_OPT_X_SASL_NOCANON,
LDAP_OPT_ON ) != LDAP_OPT_SUCCESS )
{
fprintf( stderr, "Could not set LDAP_OPT_X_SASL_NOCANON on\n" );
tool_exit( ld, EXIT_FAILURE );
}
}
#endif
if( ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &protocol )
!= LDAP_OPT_SUCCESS )
{
fprintf( stderr, "Could not set LDAP_OPT_PROTOCOL_VERSION %d\n",
protocol );
tool_exit( ld, EXIT_FAILURE );
}
if ( use_tls ) {
rc = ldap_start_tls_s( ld, NULL, NULL );
if ( rc != LDAP_SUCCESS ) {
char *msg=NULL;
ldap_get_option( ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void*)&msg);
tool_perror( "ldap_start_tls", rc, NULL, NULL, msg, NULL );
ldap_memfree(msg);
if ( use_tls > 1 || rc < 0 ) {
tool_exit( ld, EXIT_FAILURE );
}
}
}
if ( nettimeout.tv_sec > 0 ) {
if ( ldap_set_option( ld, LDAP_OPT_NETWORK_TIMEOUT, (void *) &nettimeout )
!= LDAP_OPT_SUCCESS )
{
fprintf( stderr, "Could not set LDAP_OPT_NETWORK_TIMEOUT %ld\n",
(long)nettimeout.tv_sec );
tool_exit( ld, EXIT_FAILURE );
}
}
}
return ld;
}
void
tool_bind( LDAP *ld )
{
LDAPControl **sctrlsp = NULL;
LDAPControl *sctrls[4];
LDAPControl sctrl[3];
int nsctrls = 0;
int rc, msgid;
LDAPMessage *result = NULL;
int err;
char *matched = NULL;
char *info = NULL;
char **refs = NULL;
LDAPControl **ctrls = NULL;
char msgbuf[256];
msgbuf[0] = 0;
#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
if ( ppolicy ) {
LDAPControl c;
c.ldctl_oid = LDAP_CONTROL_PASSWORDPOLICYREQUEST;
c.ldctl_value.bv_val = NULL;
c.ldctl_value.bv_len = 0;
c.ldctl_iscritical = 0;
sctrl[nsctrls] = c;
sctrls[nsctrls] = &sctrl[nsctrls];
sctrls[++nsctrls] = NULL;
}
#endif
if ( bauthzid ) {
LDAPControl c;
c.ldctl_oid = LDAP_CONTROL_AUTHZID_REQUEST;
c.ldctl_iscritical = bauthzid > 1;
BER_BVZERO( &c.ldctl_value );
sctrl[nsctrls] = c;
sctrls[nsctrls] = &sctrl[nsctrls];
sctrls[++nsctrls] = NULL;
}
#ifdef LDAP_CONTROL_X_SESSION_TRACKING
if ( sessionTracking ) {
LDAPControl c;
if ( BER_BVISNULL( &stValue) && st_value( ld, &stValue ) ) {
tool_exit( ld, EXIT_FAILURE );
}
c.ldctl_oid = LDAP_CONTROL_X_SESSION_TRACKING;
c.ldctl_iscritical = 0;
c.ldctl_value = stValue;
sctrl[nsctrls] = c;
sctrls[nsctrls] = &sctrl[nsctrls];
sctrls[++nsctrls] = NULL;
}
#endif /* LDAP_CONTROL_X_SESSION_TRACKING */
if ( nsctrls ) {
sctrlsp = sctrls;
}
assert( nsctrls < (int) (sizeof(sctrls)/sizeof(sctrls[0])) );
if ( pw_file || want_bindpw ) {
assert( passwd.bv_val == NULL && passwd.bv_len == 0 );
if ( pw_file ) {
if ( lutil_get_filed_password( pw_file, &passwd ) ) {
tool_exit( ld, EXIT_FAILURE );
}
} else {
char *pw = getpassphrase( _("Enter LDAP Password: ") );
if ( pw ) {
passwd.bv_val = ber_strdup( pw );
passwd.bv_len = strlen( passwd.bv_val );
}
}
}
if ( authmethod == LDAP_AUTH_SASL ) {
#ifdef HAVE_CYRUS_SASL
void *defaults;
const char *rmech = NULL;
if( sasl_secprops != NULL ) {
rc = ldap_set_option( ld, LDAP_OPT_X_SASL_SECPROPS,
(void *) sasl_secprops );
if( rc != LDAP_OPT_SUCCESS ) {
fprintf( stderr,
"Could not set LDAP_OPT_X_SASL_SECPROPS: %s\n",
sasl_secprops );
tool_exit( ld, LDAP_LOCAL_ERROR );
}
}
defaults = lutil_sasl_defaults( ld,
sasl_mech,
sasl_realm,
sasl_authc_id,
passwd.bv_val,
sasl_authz_id );
do {
rc = ldap_sasl_interactive_bind( ld, binddn, sasl_mech,
sctrlsp, NULL, sasl_flags, lutil_sasl_interact, defaults,
result, &rmech, &msgid );
if ( rc != LDAP_SASL_BIND_IN_PROGRESS )
break;
ldap_msgfree( result );
if ( ldap_result( ld, msgid, LDAP_MSG_ALL, NULL, &result ) == -1 || !result ) {
ldap_get_option( ld, LDAP_OPT_RESULT_CODE, (void*)&err );
ldap_get_option( ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void*)&info );
tool_perror( "ldap_sasl_interactive_bind",
err, NULL, NULL, info, NULL );
ldap_memfree( info );
tool_exit( ld, err );
}
} while ( rc == LDAP_SASL_BIND_IN_PROGRESS );
lutil_sasl_freedefs( defaults );
if ( rc != LDAP_SUCCESS ) {
ldap_get_option( ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void*)&info );
tool_perror( "ldap_sasl_interactive_bind",
rc, NULL, NULL, info, NULL );
ldap_memfree( info );
tool_exit( ld, rc );
}
#else
fprintf( stderr, "%s: not compiled with SASL support\n", prog );
tool_exit( ld, LDAP_NOT_SUPPORTED );
#endif
} else {
/* simple bind */
rc = ldap_sasl_bind( ld, binddn, LDAP_SASL_SIMPLE, &passwd,
sctrlsp, NULL, &msgid );
if ( msgid == -1 ) {
tool_perror( "ldap_sasl_bind(SIMPLE)", rc,
NULL, NULL, NULL, NULL );
tool_exit( ld, rc );
}
rc = ldap_result( ld, msgid, LDAP_MSG_ALL, NULL, &result );
if ( rc == -1 ) {
tool_perror( "ldap_result", -1, NULL, NULL, NULL, NULL );
tool_exit( ld, LDAP_LOCAL_ERROR );
}
if ( rc == 0 ) {
tool_perror( "ldap_result", LDAP_TIMEOUT, NULL, NULL, NULL, NULL );
tool_exit( ld, LDAP_LOCAL_ERROR );
}
}
if ( result ) {
rc = ldap_parse_result( ld, result, &err, &matched, &info, &refs,
&ctrls, 1 );
if ( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_bind parse result", rc, NULL, matched, info, refs );
tool_exit( ld, LDAP_LOCAL_ERROR );
}
}
#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
if ( ctrls && ppolicy ) {
LDAPControl *ctrl;
int expire, grace, len = 0;
LDAPPasswordPolicyError pErr = -1;
ctrl = ldap_control_find( LDAP_CONTROL_PASSWORDPOLICYRESPONSE,
ctrls, NULL );
if ( ctrl && ldap_parse_passwordpolicy_control( ld, ctrl,
&expire, &grace, &pErr ) == LDAP_SUCCESS )
{
if ( pErr != PP_noError ){
msgbuf[0] = ';';
msgbuf[1] = ' ';
strcpy( msgbuf+2, ldap_passwordpolicy_err2txt( pErr ));
len = strlen( msgbuf );
}
if ( expire >= 0 ) {
sprintf( msgbuf+len,
" (Password expires in %d seconds)",
expire );
} else if ( grace >= 0 ) {
sprintf( msgbuf+len,
" (Password expired, %d grace logins remain)",
grace );
}
}
}
#endif
if ( ctrls && bauthzid ) {
LDAPControl *ctrl;
ctrl = ldap_control_find( LDAP_CONTROL_AUTHZID_RESPONSE,
ctrls, NULL );
if ( ctrl ) {
LDAPControl *ctmp[2];
ctmp[0] = ctrl;
ctmp[1] = NULL;
tool_print_ctrls( ld, ctmp );
}
}
#ifdef LDAP_CONTROL_X_PASSWORD_EXPIRED
if ( ctrls ) {
LDAPControl *ctrl;
ctrl = ldap_control_find( LDAP_CONTROL_X_PASSWORD_EXPIRED,
ctrls, NULL );
if ( !ctrl )
ctrl = ldap_control_find( LDAP_CONTROL_X_PASSWORD_EXPIRING,
ctrls, NULL );
if ( ctrl ) {
LDAPControl *ctmp[2];
ctmp[0] = ctrl;
ctmp[1] = NULL;
tool_print_ctrls( ld, ctmp );
}
}
#endif
if ( ctrls ) {
ldap_controls_free( ctrls );
}
if ( err != LDAP_SUCCESS
|| msgbuf[0]
|| ( matched && matched[ 0 ] )
|| ( info && info[ 0 ] )
|| refs )
{
tool_perror( "ldap_bind", err, msgbuf, matched, info, refs );
if( matched ) ber_memfree( matched );
if( info ) ber_memfree( info );
if( refs ) ber_memvfree( (void **)refs );
if ( err != LDAP_SUCCESS ) tool_exit( ld, err );
}
}
void
tool_unbind( LDAP *ld )
{
int err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, NULL );
if ( err != LDAP_OPT_SUCCESS ) {
fprintf( stderr, "Could not unset controls\n");
}
(void) ldap_unbind_ext( ld, NULL, NULL );
}
void
tool_exit( LDAP *ld, int status )
{
if ( ld != NULL ) {
tool_unbind( ld );
}
tool_destroy();
exit( status );
}
/* Set server controls. Add controls extra_c[0..count-1], if set. */
void
tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
{
int i = 0, j, crit = 0, err;
LDAPControl c[16], **ctrls;
if ( ! ( assertctl
|| authzid
#ifdef LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ
|| proxydn
#endif /* LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ */
|| manageDIT
|| manageDSAit
|| noop
#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
|| ppolicy
#endif
|| preread
|| postread
#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
|| chaining
#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
#ifdef LDAP_CONTROL_X_SESSION_TRACKING
|| sessionTracking
#endif /* LDAP_CONTROL_X_SESSION_TRACKING */
|| count
|| unknown_ctrls_num ) )
{
return;
}
ctrls = (LDAPControl**) malloc(sizeof(c) + (count + unknown_ctrls_num + 1)*sizeof(LDAPControl*));
if ( ctrls == NULL ) {
fprintf( stderr, "No memory\n" );
tool_exit( ld, EXIT_FAILURE );
}
if ( assertctl ) {
if ( BER_BVISNULL( &assertionvalue ) ) {
err = ldap_create_assertion_control_value( ld,
assertion, &assertionvalue );
if ( err ) {
fprintf( stderr,
"Unable to create assertion value "
"\"%s\" (%d)\n", assertion, err );
}
}
c[i].ldctl_oid = LDAP_CONTROL_ASSERT;
c[i].ldctl_value = assertionvalue;
c[i].ldctl_iscritical = assertctl > 1;
ctrls[i] = &c[i];
i++;
}
if ( authzid ) {
c[i].ldctl_value.bv_val = authzid;
c[i].ldctl_value.bv_len = strlen( authzid );
c[i].ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
c[i].ldctl_iscritical = authzcrit;
ctrls[i] = &c[i];
i++;
}
#ifdef LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ
/* NOTE: doesn't need an extra count because it's incompatible
* with authzid */
if ( proxydn ) {
BerElementBuffer berbuf;
BerElement *ber = (BerElement *)&berbuf;
ber_init2( ber, NULL, LBER_USE_DER );
if ( ber_printf( ber, "s", proxydn ) == -1 ) {
tool_exit( ld, EXIT_FAILURE );
}
if ( ber_flatten2( ber, &c[i].ldctl_value, 0 ) == -1 ) {
tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ;
c[i].ldctl_iscritical = authzcrit;
ctrls[i] = &c[i];
i++;
}
#endif /* LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ */
if ( manageDIT ) {
c[i].ldctl_oid = LDAP_CONTROL_MANAGEDIT;
BER_BVZERO( &c[i].ldctl_value );
c[i].ldctl_iscritical = manageDIT > 1;
ctrls[i] = &c[i];
i++;
}
if ( manageDSAit ) {
c[i].ldctl_oid = LDAP_CONTROL_MANAGEDSAIT;
BER_BVZERO( &c[i].ldctl_value );
c[i].ldctl_iscritical = manageDSAit > 1;
ctrls[i] = &c[i];
i++;
}
if ( noop ) {
c[i].ldctl_oid = LDAP_CONTROL_NOOP;
BER_BVZERO( &c[i].ldctl_value );
c[i].ldctl_iscritical = noop > 1;
ctrls[i] = &c[i];
i++;
}
#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
if ( ppolicy ) {
c[i].ldctl_oid = LDAP_CONTROL_PASSWORDPOLICYREQUEST;
BER_BVZERO( &c[i].ldctl_value );
c[i].ldctl_iscritical = 0;
ctrls[i] = &c[i];
i++;
}
#endif
if ( preread ) {
BerElementBuffer berbuf;
BerElement *ber = (BerElement *)&berbuf;
char **attrs = NULL;
if( preread_attrs ) {
attrs = ldap_str2charray( preread_attrs, "," );
}
ber_init2( ber, NULL, LBER_USE_DER );
if( ber_printf( ber, "{v}", attrs ) == -1 ) {
fprintf( stderr, "preread attrs encode failed.\n" );
tool_exit( ld, EXIT_FAILURE );
}
err = ber_flatten2( ber, &c[i].ldctl_value, 0 );
if( err < 0 ) {
fprintf( stderr, "preread flatten failed (%d)\n", err );
tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_PRE_READ;
c[i].ldctl_iscritical = preread > 1;
ctrls[i] = &c[i];
i++;
if( attrs ) ldap_charray_free( attrs );
}
if ( postread ) {
BerElementBuffer berbuf;
BerElement *ber = (BerElement *)&berbuf;
char **attrs = NULL;
if( postread_attrs ) {
attrs = ldap_str2charray( postread_attrs, "," );
}
ber_init2( ber, NULL, LBER_USE_DER );
if( ber_printf( ber, "{v}", attrs ) == -1 ) {
fprintf( stderr, "postread attrs encode failed.\n" );
tool_exit( ld, EXIT_FAILURE );
}
err = ber_flatten2( ber, &c[i].ldctl_value, 0 );
if( err < 0 ) {
fprintf( stderr, "postread flatten failed (%d)\n", err );
tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_POST_READ;
c[i].ldctl_iscritical = postread > 1;
ctrls[i] = &c[i];
i++;
if( attrs ) ldap_charray_free( attrs );
}
#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
if ( chaining ) {
if ( chainingResolve > -1 ) {
BerElementBuffer berbuf;
BerElement *ber = (BerElement *)&berbuf;
ber_init2( ber, NULL, LBER_USE_DER );
err = ber_printf( ber, "{e" /* } */, chainingResolve );
if ( err == -1 ) {
ber_free( ber, 1 );
fprintf( stderr, _("Chaining behavior control encoding error!\n") );
tool_exit( ld, EXIT_FAILURE );
}
if ( chainingContinuation > -1 ) {
err = ber_printf( ber, "e", chainingContinuation );
if ( err == -1 ) {
ber_free( ber, 1 );
fprintf( stderr, _("Chaining behavior control encoding error!\n") );
tool_exit( ld, EXIT_FAILURE );
}
}
err = ber_printf( ber, /* { */ "N}" );
if ( err == -1 ) {
ber_free( ber, 1 );
fprintf( stderr, _("Chaining behavior control encoding error!\n") );
tool_exit( ld, EXIT_FAILURE );
}
if ( ber_flatten2( ber, &c[i].ldctl_value, 0 ) == -1 ) {
tool_exit( ld, EXIT_FAILURE );
}
} else {
BER_BVZERO( &c[i].ldctl_value );
}
c[i].ldctl_oid = LDAP_CONTROL_X_CHAINING_BEHAVIOR;
c[i].ldctl_iscritical = chaining > 1;
ctrls[i] = &c[i];
i++;
}
#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
#ifdef LDAP_CONTROL_X_SESSION_TRACKING
if ( sessionTracking ) {
if ( BER_BVISNULL( &stValue ) && st_value( ld, &stValue ) ) {
tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_X_SESSION_TRACKING;
c[i].ldctl_iscritical = 0;
c[i].ldctl_value = stValue;
ctrls[i] = &c[i];
i++;
}
#endif /* LDAP_CONTROL_X_SESSION_TRACKING */
while ( count-- ) {
ctrls[i++] = extra_c++;
}
for ( count = 0; count < unknown_ctrls_num; count++ ) {
ctrls[i++] = &unknown_ctrls[count];
}
ctrls[i] = NULL;
err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, ctrls );
if ( err != LDAP_OPT_SUCCESS ) {
for ( j = 0; j < i; j++ ) {
if ( ctrls[j]->ldctl_iscritical ) crit = 1;
}
fprintf( stderr, "Could not set %scontrols\n",
crit ? "critical " : "" );
}
free( ctrls );
if ( crit ) {
tool_exit( ld, EXIT_FAILURE );
}
}
int
tool_check_abandon( LDAP *ld, int msgid )
{
int rc;
LDAPControl *sctrls[1] = { NULL };
switch ( gotintr ) {
case Intr_Cancel:
rc = ldap_cancel_s( ld, msgid, sctrls, NULL );
fprintf( stderr, "got interrupt, cancel got %d: %s\n",
rc, ldap_err2string( rc ) );
return -1;
case Intr_Abandon:
rc = ldap_abandon_ext( ld, msgid, sctrls, NULL );
fprintf( stderr, "got interrupt, abandon got %d: %s\n",
rc, ldap_err2string( rc ) );
return -1;
case Intr_Ignore:
/* just unbind, ignoring the request */
return -1;
}
return 0;
}
static int
print_prepostread( LDAP *ld, LDAPControl *ctrl, struct berval *what)
{
BerElement *ber;
struct berval bv;
tool_write_ldif( LDIF_PUT_COMMENT, "==> ",
what->bv_val, what->bv_len );
ber = ber_init( &ctrl->ldctl_value );
if ( ber == NULL ) {
/* error? */
return 1;
} else if ( ber_scanf( ber, "{m{" /*}}*/, &bv ) == LBER_ERROR ) {
/* error? */
return 1;
} else {
tool_write_ldif( LDIF_PUT_VALUE, "dn", bv.bv_val, bv.bv_len );
while ( ber_scanf( ber, "{m" /*}*/, &bv ) != LBER_ERROR ) {
int i;
BerVarray vals = NULL;
char *str = NULL;
if ( ber_scanf( ber, "[W]", &vals ) == LBER_ERROR ||
vals == NULL )
{
/* error? */
return 1;
}
if ( ldif ) {
char *ptr;
str = malloc( bv.bv_len + STRLENOF(": ") + 1 );
ptr = str;
ptr = lutil_strncopy( ptr, bv.bv_val, bv.bv_len );
ptr = lutil_strcopy( ptr, ": " );
}
for ( i = 0; vals[ i ].bv_val != NULL; i++ ) {
tool_write_ldif(
ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
ldif ? str : bv.bv_val, vals[ i ].bv_val, vals[ i ].bv_len );
}
ber_bvarray_free( vals );
if ( str ) free( str );
}
}
if ( ber != NULL ) {
ber_free( ber, 1 );
}
tool_write_ldif( LDIF_PUT_COMMENT, "<== ",
what->bv_val, what->bv_len );
return 0;
}
static int
print_preread( LDAP *ld, LDAPControl *ctrl )
{
static struct berval what = BER_BVC( "preread" );
return print_prepostread( ld, ctrl, &what );
}
static int
print_postread( LDAP *ld, LDAPControl *ctrl )
{
static struct berval what = BER_BVC( "postread" );
return print_prepostread( ld, ctrl, &what );
}
static int
print_paged_results( LDAP *ld, LDAPControl *ctrl )
{
ber_int_t estimate;
/* note: pr_cookie is being malloced; it's freed
* the next time the control is sent, but the last
* time it's not; we don't care too much, because
* the last time an empty value is returned... */
if ( ldap_parse_pageresponse_control( ld, ctrl, &estimate, &pr_cookie )
!= LDAP_SUCCESS )
{
/* error? */
return 1;
} else {
char buf[ BUFSIZ ], *ptr = buf;
int plen;
if ( estimate > 0 ) {
plen = sprintf( buf, "estimate=%d cookie=", estimate );
} else {
plen = sprintf( buf, "cookie=" );
}
if ( pr_cookie.bv_len > 0 ) {
struct berval bv;
bv.bv_len = LUTIL_BASE64_ENCODE_LEN(
pr_cookie.bv_len ) + 1;
ptr = ber_memalloc( bv.bv_len + 1 + plen );
bv.bv_val = ptr + plen;
strcpy( ptr, buf );
bv.bv_len = lutil_b64_ntop(
(unsigned char *) pr_cookie.bv_val,
pr_cookie.bv_len,
bv.bv_val, bv.bv_len );
pr_morePagedResults = 1;
plen += bv.bv_len;
}
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
ldif ? "pagedresults: " : "pagedresults",
ptr, plen );
if ( ptr != buf )
ber_memfree( ptr );
}
return 0;
}
static int
print_psearch( LDAP *ld, LDAPControl *ctrl )
{
int rc;
int chgtype;
int chgpres;
long chgnum;
struct berval prevdn;
rc = ldap_parse_entrychange_control( ld, ctrl, &chgtype, &prevdn,
&chgpres, &chgnum );
if ( rc == LDAP_SUCCESS ) {
char buf[ BUFSIZ ];
char *ptr = buf;
int blen = sizeof(buf), len;
switch( chgtype ) {
case LDAP_CONTROL_PERSIST_ENTRY_CHANGE_ADD:
len = snprintf( ptr, blen, "add" );
ptr += len;
blen -= len;
break;
case LDAP_CONTROL_PERSIST_ENTRY_CHANGE_DELETE:
len = snprintf( ptr, blen, "delete" );
ptr += len;
blen -= len;
break;
case LDAP_CONTROL_PERSIST_ENTRY_CHANGE_MODIFY:
len = snprintf( ptr, blen, "modify" );
ptr += len;
blen -= len;
break;
case LDAP_CONTROL_PERSIST_ENTRY_CHANGE_RENAME:
len = snprintf( ptr, blen, "moddn" );
ptr += len;
blen -= len;
if ( prevdn.bv_val != NULL ) {
len = snprintf( ptr, blen, " prevdn %s", prevdn.bv_val );
ptr += len;
blen -= len;
}
break;
}
if ( chgpres ) {
len = snprintf( ptr, blen, " changeNumber %ld", chgnum) ;
ptr += len;
blen -= len;
}
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
ldif ? "persistentSearch: " : "persistentSearch", buf, len );
}
return rc;
}
static int
print_sss( LDAP *ld, LDAPControl *ctrl )
{
int rc;
ber_int_t err;
char *attr;
rc = ldap_parse_sortresponse_control( ld, ctrl, &err, &attr );
if ( rc == LDAP_SUCCESS ) {
char buf[ BUFSIZ ];
rc = snprintf( buf, sizeof(buf), "(%d) %s%s%s",
err, ldap_err2string(err), attr ? " " : "", attr ? attr : "" );
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
ldif ? "sortResult: " : "sortResult", buf, rc );
}
return rc;
}
static int
print_vlv( LDAP *ld, LDAPControl *ctrl )
{
int rc;
ber_int_t err;
struct berval bv;
rc = ldap_parse_vlvresponse_control( ld, ctrl, &vlvPos, &vlvCount,
&vlvContext, &err );
if ( rc == LDAP_SUCCESS ) {
char buf[ BUFSIZ ];
if ( vlvContext && vlvContext->bv_len > 0 ) {
bv.bv_len = LUTIL_BASE64_ENCODE_LEN(
vlvContext->bv_len ) + 1;
bv.bv_val = ber_memalloc( bv.bv_len + 1 );
bv.bv_len = lutil_b64_ntop(
(unsigned char *) vlvContext->bv_val,
vlvContext->bv_len,
bv.bv_val, bv.bv_len );
} else {
bv.bv_val = "";
bv.bv_len = 0;
}
rc = snprintf( buf, sizeof(buf), "pos=%d count=%d context=%s (%d) %s",
vlvPos, vlvCount, bv.bv_val,
err, ldap_err2string(err));
if ( bv.bv_len )
ber_memfree( bv.bv_val );
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
ldif ? "vlvResult" : "vlvResult", buf, rc );
}
return rc;
}
#ifdef LDAP_CONTROL_X_DEREF
static int
print_deref( LDAP *ld, LDAPControl *ctrl )
{
LDAPDerefRes *drhead = NULL, *dr;
int rc;
rc = ldap_parse_derefresponse_control( ld, ctrl, &drhead );
if ( rc != LDAP_SUCCESS ) {
return rc;
}
for ( dr = drhead; dr != NULL; dr = dr->next ) {
LDAPDerefVal *dv;
ber_len_t len;
char *buf, *ptr;
len = strlen( dr->derefAttr ) + STRLENOF(": ");
for ( dv = dr->attrVals; dv != NULL; dv = dv->next ) {
if ( dv->vals != NULL ) {
int j;
ber_len_t tlen = strlen(dv->type);
for ( j = 0; dv->vals[ j ].bv_val != NULL; j++ ) {
len += STRLENOF("<:=>;") + tlen + 4*((dv->vals[ j ].bv_len - 1)/3 + 1);
}
}
}
len += dr->derefVal.bv_len + STRLENOF("\n");
buf = ldap_memalloc( len + 1 );
if ( buf == NULL ) {
rc = LDAP_NO_MEMORY;
goto done;
}
ptr = buf;
ptr = lutil_strcopy( ptr, dr->derefAttr );
*ptr++ = ':';
*ptr++ = ' ';
for ( dv = dr->attrVals; dv != NULL; dv = dv->next ) {
if ( dv->vals != NULL ) {
int j;
for ( j = 0; dv->vals[ j ].bv_val != NULL; j++ ) {
int k = ldif_is_not_printable( dv->vals[ j ].bv_val, dv->vals[ j ].bv_len );
*ptr++ = '<';
ptr = lutil_strcopy( ptr, dv->type );
if ( k ) {
*ptr++ = ':';
}
*ptr++ = '=';
if ( k ) {
k = lutil_b64_ntop(
(unsigned char *) dv->vals[ j ].bv_val,
dv->vals[ j ].bv_len,
ptr, buf + len - ptr );
assert( k >= 0 );
ptr += k;
} else {
ptr = lutil_memcopy( ptr, dv->vals[ j ].bv_val, dv->vals[ j ].bv_len );
}
*ptr++ = '>';
*ptr++ = ';';
}
}
}
ptr = lutil_strncopy( ptr, dr->derefVal.bv_val, dr->derefVal.bv_len );
*ptr = '\0';
assert( ptr <= buf + len );
tool_write_ldif( LDIF_PUT_COMMENT, NULL, buf, ptr - buf);
ldap_memfree( buf );
}
rc = LDAP_SUCCESS;
done:;
ldap_derefresponse_free( drhead );
return rc;
}
#endif
#ifdef LDAP_CONTROL_X_WHATFAILED
static int
print_whatfailed( LDAP *ld, LDAPControl *ctrl )
{
BerElement *ber;
ber_tag_t tag;
ber_len_t siz;
BerVarray bva = NULL;
/* Create a BerElement from the berval returned in the control. */
ber = ber_init( &ctrl->ldctl_value );
if ( ber == NULL ) {
return LDAP_NO_MEMORY;
}
siz = sizeof(struct berval);
tag = ber_scanf( ber, "[M]", &bva, &siz, 0 );
if ( tag != LBER_ERROR ) {
int i;
tool_write_ldif( LDIF_PUT_COMMENT, " what failed:", NULL, 0 );
for ( i = 0; bva[i].bv_val != NULL; i++ ) {
tool_write_ldif( LDIF_PUT_COMMENT, NULL, bva[i].bv_val, bva[i].bv_len );
}
ldap_memfree( bva );
}
ber_free( ber, 1 );
return 0;
}
#endif
static int
print_syncstate( LDAP *ld, LDAPControl *ctrl )
{
struct berval syncUUID, syncCookie = BER_BVNULL;
char buf[LDAP_LUTIL_UUIDSTR_BUFSIZE], *uuidstr = "(UUID malformed)";
BerElement *ber;
ber_tag_t tag;
ber_int_t state;
int rc;
if ( ldif ) {
return 0;
}
/* Create a BerElement from the berval returned in the control. */
ber = ber_init( &ctrl->ldctl_value );
if ( ber == NULL ) {
return LDAP_NO_MEMORY;
}
if ( ber_scanf( ber, "{em", &state, &syncUUID ) == LBER_ERROR ) {
ber_free( ber, 1 );
return 1;
}
tag = ber_get_stringbv( ber, &syncCookie, 0 );
rc = lutil_uuidstr_from_normalized(
syncUUID.bv_val, syncUUID.bv_len,
buf, LDAP_LUTIL_UUIDSTR_BUFSIZE );
if ( rc > 0 && rc < LDAP_LUTIL_UUIDSTR_BUFSIZE ) {
uuidstr = buf;
}
switch ( state ) {
case LDAP_SYNC_PRESENT:
printf(_("# SyncState control, UUID %s present\n"), uuidstr);
break;
case LDAP_SYNC_ADD:
printf(_("# SyncState control, UUID %s added\n"), uuidstr);
break;
case LDAP_SYNC_MODIFY:
printf(_("# SyncState control, UUID %s modified\n"), uuidstr);
break;
case LDAP_SYNC_DELETE:
printf(_("# SyncState control, UUID %s deleted\n"), uuidstr);
break;
default:
ber_free( ber, 1 );
return 1;
}
if ( tag != LBER_ERROR ) {
if ( ldif_is_not_printable( syncCookie.bv_val, syncCookie.bv_len ) ) {
struct berval bv;
bv.bv_len = LUTIL_BASE64_ENCODE_LEN( syncCookie.bv_len ) + 1;
bv.bv_val = ber_memalloc( bv.bv_len + 1 );
bv.bv_len = lutil_b64_ntop(
(unsigned char *) syncCookie.bv_val, syncCookie.bv_len,
bv.bv_val, bv.bv_len );
printf(_("# cookie:: %s\n"), bv.bv_val );
ber_memfree( bv.bv_val );
} else {
printf(_("# cookie: %s\n"), syncCookie.bv_val );
}
}
ber_free( ber, 1 );
return 0;
}
static int
print_syncdone( LDAP *ld, LDAPControl *ctrl )
{
BerElement *ber;
struct berval cookie = BER_BVNULL;
ber_len_t len;
ber_int_t refreshDeletes = 0;
if ( ldif ) {
return 0;
}
/* Create a BerElement from the berval returned in the control. */
ber = ber_init( &ctrl->ldctl_value );
if ( ber == NULL ) {
return LDAP_NO_MEMORY;
}
ber_skip_tag( ber, &len );
if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
ber_scanf( ber, "m", &cookie );
}
if ( ber_peek_tag( ber, &len ) == LDAP_TAG_REFRESHDELETES ) {
ber_scanf( ber, "b", &refreshDeletes );
}
printf(_("# SyncDone control refreshDeletes=%d\n"), refreshDeletes ? 1 : 0 );
if ( !BER_BVISNULL( &cookie ) ) {
if ( ldif_is_not_printable( cookie.bv_val, cookie.bv_len ) ) {
struct berval bv;
bv.bv_len = LUTIL_BASE64_ENCODE_LEN( cookie.bv_len ) + 1;
bv.bv_val = ber_memalloc( bv.bv_len + 1 );
bv.bv_len = lutil_b64_ntop(
(unsigned char *) cookie.bv_val, cookie.bv_len,
bv.bv_val, bv.bv_len );
printf(_("# cookie:: %s\n"), bv.bv_val );
ber_memfree( bv.bv_val );
} else {
printf(_("# cookie: %s\n"), cookie.bv_val );
}
}
ber_free( ber, 1 );
return 0;
}
#ifdef LDAP_CONTROL_X_DIRSYNC
static int
print_dirsync( LDAP *ld, LDAPControl *ctrl )
{
int rc, continueFlag;
struct berval cookie;
rc = ldap_parse_dirsync_control( ld, ctrl,
&continueFlag, &cookie );
if ( rc == LDAP_SUCCESS ) {
printf(_("# DirSync control continueFlag=%d\n"), continueFlag );
if ( !BER_BVISNULL( &cookie )) {
if ( ldif_is_not_printable( cookie.bv_val, cookie.bv_len ) ) {
struct berval bv;
bv.bv_len = LUTIL_BASE64_ENCODE_LEN( cookie.bv_len ) + 1;
bv.bv_val = ber_memalloc( bv.bv_len + 1 );
bv.bv_len = lutil_b64_ntop(
(unsigned char *) cookie.bv_val, cookie.bv_len,
bv.bv_val, bv.bv_len );
printf(_("# cookie:: %s\n"), bv.bv_val );
ber_memfree( bv.bv_val );
} else {
printf(_("# cookie: %s\n"), cookie.bv_val );
}
}
}
return rc;
}
#endif
#ifdef LDAP_CONTROL_AUTHZID_RESPONSE
static int
print_authzid( LDAP *ld, LDAPControl *ctrl )
{
if ( ctrl->ldctl_value.bv_len ) {
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
ldif ? "authzid: " : "authzid",
ctrl->ldctl_value.bv_val, ctrl->ldctl_value.bv_len );
} else {
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
ldif ? "authzid: " : "authzid",
"anonymous", STRLENOF("anonymous") );
}
return 0;
}
#endif
#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
static int
print_ppolicy( LDAP *ld, LDAPControl *ctrl )
{
int expire = 0, grace = 0, rc;
LDAPPasswordPolicyError pperr;
rc = ldap_parse_passwordpolicy_control( ld, ctrl,
&expire, &grace, &pperr );
if ( rc == LDAP_SUCCESS ) {
char buf[ BUFSIZ ], *ptr = buf;
if ( expire != -1 ) {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
"expire=%d", expire );
}
if ( grace != -1 ) {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
"%sgrace=%d", ptr == buf ? "" : " ", grace );
}
if ( pperr != PP_noError ) {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
"%serror=%d (%s)", ptr == buf ? "" : " ",
pperr,
ldap_passwordpolicy_err2txt( pperr ) );
}
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
ldif ? "ppolicy: " : "ppolicy", buf, ptr - buf );
}
return rc;
}
#endif
#ifdef LDAP_CONTROL_X_PASSWORD_EXPIRED
static int
print_netscape_pwexpired( LDAP *ld, LDAPControl *ctrl )
{
printf(_("# PasswordExpired control\n") );
return 0;
}
static int
print_netscape_pwexpiring( LDAP *ld, LDAPControl *ctrl )
{
long expiring = 0;
int rc;
rc = ldap_parse_password_expiring_control( ld, ctrl, &expiring );
if ( rc == LDAP_SUCCESS ) {
printf(_("# PasswordExpiring control seconds=%ld\n"), expiring );
}
return rc;
}
#endif
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
static int
print_account_usability( LDAP *ld, LDAPControl *ctrl )
{
LDAPAccountUsability usability;
ber_int_t available = 0;
int rc;
rc = ldap_parse_accountusability_control( ld, ctrl, &available, &usability );
if ( rc == LDAP_SUCCESS ) {
char buf[ BUFSIZ ], *ptr = buf;
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
"%savailable", available ? "" : "not " );
if ( available ) {
if ( usability.seconds_remaining == -1 ) {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
" and does not expire" );
} else {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
" expire=%d", usability.seconds_remaining );
}
} else {
int added = 0;
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
" (" /* ')' */ );
if ( usability.more_info.inactive ) {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
"inactive " );
added++;
}
if ( usability.more_info.reset ) {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
"reset " );
added++;
}
if ( usability.more_info.expired ) {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
"expired " );
added++;
}
if ( added ) {
ptr[-1] = ')';
*ptr++ = ' ';
} else {
*(--ptr) = '\0';
}
if ( usability.more_info.remaining_grace != -1 ) {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
"grace=%d ", usability.more_info.remaining_grace );
}
if ( usability.more_info.seconds_before_unlock != -1 ) {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
"seconds_before_unlock=%d ", usability.more_info.seconds_before_unlock );
}
*(--ptr) = '\0';
}
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
ldif ? "accountUsability: " : "accountUsability", buf, ptr - buf );
}
return rc;
}
#endif
void tool_print_ctrls(
LDAP *ld,
LDAPControl **ctrls )
{
int i;
char *ptr;
for ( i = 0; ctrls[i] != NULL; i++ ) {
/* control: OID criticality base64value */
struct berval b64 = BER_BVNULL;
ber_len_t len;
char *str;
int j;
/* FIXME: there might be cases where a control has NULL OID;
* this makes little sense, especially when returned by the
* server, but libldap happily allows it */
if ( ctrls[i]->ldctl_oid == NULL ) {
continue;
}
len = ldif ? 2 : 0;
len += strlen( ctrls[i]->ldctl_oid );
/* add enough for space after OID and the critical value itself */
len += ctrls[i]->ldctl_iscritical
? sizeof("true") : sizeof("false");
/* convert to base64 */
if ( !BER_BVISNULL( &ctrls[i]->ldctl_value ) ) {
b64.bv_len = LUTIL_BASE64_ENCODE_LEN(
ctrls[i]->ldctl_value.bv_len ) + 1;
b64.bv_val = ber_memalloc( b64.bv_len + 1 );
b64.bv_len = lutil_b64_ntop(
(unsigned char *) ctrls[i]->ldctl_value.bv_val,
ctrls[i]->ldctl_value.bv_len,
b64.bv_val, b64.bv_len );
}
if ( b64.bv_len ) {
len += 1 + b64.bv_len;
}
ptr = str = malloc( len + 1 );
if ( ldif ) {
ptr = lutil_strcopy( ptr, ": " );
}
ptr = lutil_strcopy( ptr, ctrls[i]->ldctl_oid );
ptr = lutil_strcopy( ptr, ctrls[i]->ldctl_iscritical
? " true" : " false" );
if ( b64.bv_len ) {
ptr = lutil_strcopy( ptr, " " );
ptr = lutil_strcopy( ptr, b64.bv_val );
}
if ( ldif < 2 ) {
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
"control", str, len );
}
free( str );
if ( b64.bv_len ) {
ber_memfree( b64.bv_val );
}
/* known controls */
for ( j = 0; tool_ctrl_response[j].oid != NULL; j++ ) {
if ( strcmp( tool_ctrl_response[j].oid, ctrls[i]->ldctl_oid ) == 0 ) {
if ( !(tool_ctrl_response[j].mask & tool_type )) {
/* this control should not appear
* with this tool; warning? */
}
break;
}
}
if ( tool_ctrl_response[j].oid != NULL && tool_ctrl_response[j].func ) {
(void)tool_ctrl_response[j].func( ld, ctrls[i] );
}
}
}
int
tool_write_ldif( int type, char *name, char *value, ber_len_t vallen )
{
char *ldif;
if (( ldif = ldif_put_wrap( type, name, value, vallen, ldif_wrap )) == NULL ) {
return( -1 );
}
fputs( ldif, stdout );
ber_memfree( ldif );
return( 0 );
}
int
tool_is_oid( const char *s )
{
int first = 1;
if ( !isdigit( (unsigned char) s[ 0 ] ) ) {
return 0;
}
for ( ; s[ 0 ]; s++ ) {
if ( s[ 0 ] == '.' ) {
if ( s[ 1 ] == '\0' ) {
return 0;
}
first = 1;
continue;
}
if ( !isdigit( (unsigned char) s[ 0 ] ) ) {
return 0;
}
if ( first == 1 && s[ 0 ] == '0' && s[ 1 ] != '.' ) {
return 0;
}
first = 0;
}
return 1;
}
openldap-2.5.16+dfsg/include/ 0000755 0001750 0001750 00000000000 14461774414 015327 5 ustar sergio sergio openldap-2.5.16+dfsg/include/ldap_schema.h 0000644 0001750 0001750 00000022352 14461774414 017744 0 ustar sergio sergio /* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* ldap-schema.h - Header for basic schema handling functions that can be
* used by both clients and servers.
* these routines should be renamed ldap_x_...
*/
#ifndef _LDAP_SCHEMA_H
#define _LDAP_SCHEMA_H 1
#include
LDAP_BEGIN_DECL
/* Codes for parsing errors */
#define LDAP_SCHERR_OUTOFMEM 1
#define LDAP_SCHERR_UNEXPTOKEN 2
#define LDAP_SCHERR_NOLEFTPAREN 3
#define LDAP_SCHERR_NORIGHTPAREN 4
#define LDAP_SCHERR_NODIGIT 5
#define LDAP_SCHERR_BADNAME 6
#define LDAP_SCHERR_BADDESC 7
#define LDAP_SCHERR_BADSUP 8
#define LDAP_SCHERR_DUPOPT 9
#define LDAP_SCHERR_EMPTY 10
#define LDAP_SCHERR_MISSING 11
#define LDAP_SCHERR_OUT_OF_ORDER 12
typedef struct ldap_schema_extension_item {
char *lsei_name;
char **lsei_values;
} LDAPSchemaExtensionItem;
typedef struct ldap_syntax {
char *syn_oid; /* REQUIRED */
char **syn_names; /* OPTIONAL */
char *syn_desc; /* OPTIONAL */
LDAPSchemaExtensionItem **syn_extensions; /* OPTIONAL */
} LDAPSyntax;
typedef struct ldap_matchingrule {
char *mr_oid; /* REQUIRED */
char **mr_names; /* OPTIONAL */
char *mr_desc; /* OPTIONAL */
int mr_obsolete; /* OPTIONAL */
char *mr_syntax_oid; /* REQUIRED */
LDAPSchemaExtensionItem **mr_extensions; /* OPTIONAL */
} LDAPMatchingRule;
typedef struct ldap_matchingruleuse {
char *mru_oid; /* REQUIRED */
char **mru_names; /* OPTIONAL */
char *mru_desc; /* OPTIONAL */
int mru_obsolete; /* OPTIONAL */
char **mru_applies_oids; /* REQUIRED */
LDAPSchemaExtensionItem **mru_extensions; /* OPTIONAL */
} LDAPMatchingRuleUse;
typedef struct ldap_attributetype {
char *at_oid; /* REQUIRED */
char **at_names; /* OPTIONAL */
char *at_desc; /* OPTIONAL */
int at_obsolete; /* 0=no, 1=yes */
char *at_sup_oid; /* OPTIONAL */
char *at_equality_oid; /* OPTIONAL */
char *at_ordering_oid; /* OPTIONAL */
char *at_substr_oid; /* OPTIONAL */
char *at_syntax_oid; /* OPTIONAL */
int at_syntax_len; /* OPTIONAL */
int at_single_value; /* 0=no, 1=yes */
int at_collective; /* 0=no, 1=yes */
int at_no_user_mod; /* 0=no, 1=yes */
int at_usage; /* 0=userApplications, 1=directoryOperation,
2=distributedOperation, 3=dSAOperation */
LDAPSchemaExtensionItem **at_extensions; /* OPTIONAL */
} LDAPAttributeType;
typedef struct ldap_objectclass {
char *oc_oid; /* REQUIRED */
char **oc_names; /* OPTIONAL */
char *oc_desc; /* OPTIONAL */
int oc_obsolete; /* 0=no, 1=yes */
char **oc_sup_oids; /* OPTIONAL */
int oc_kind; /* 0=ABSTRACT, 1=STRUCTURAL, 2=AUXILIARY */
char **oc_at_oids_must; /* OPTIONAL */
char **oc_at_oids_may; /* OPTIONAL */
LDAPSchemaExtensionItem **oc_extensions; /* OPTIONAL */
} LDAPObjectClass;
typedef struct ldap_contentrule {
char *cr_oid; /* REQUIRED */
char **cr_names; /* OPTIONAL */
char *cr_desc; /* OPTIONAL */
char **cr_sup_oids; /* OPTIONAL */
int cr_obsolete; /* 0=no, 1=yes */
char **cr_oc_oids_aux; /* OPTIONAL */
char **cr_at_oids_must; /* OPTIONAL */
char **cr_at_oids_may; /* OPTIONAL */
char **cr_at_oids_not; /* OPTIONAL */
LDAPSchemaExtensionItem **cr_extensions; /* OPTIONAL */
} LDAPContentRule;
typedef struct ldap_nameform {
char *nf_oid; /* REQUIRED */
char **nf_names; /* OPTIONAL */
char *nf_desc; /* OPTIONAL */
int nf_obsolete; /* 0=no, 1=yes */
char *nf_objectclass; /* REQUIRED */
char **nf_at_oids_must; /* REQUIRED */
char **nf_at_oids_may; /* OPTIONAL */
LDAPSchemaExtensionItem **nf_extensions; /* OPTIONAL */
} LDAPNameForm;
typedef struct ldap_structurerule {
int sr_ruleid; /* REQUIRED */
char **sr_names; /* OPTIONAL */
char *sr_desc; /* OPTIONAL */
int sr_obsolete; /* 0=no, 1=yes */
char *sr_nameform; /* REQUIRED */
int sr_nsup_ruleids;/* number of sr_sup_ruleids */
int *sr_sup_ruleids;/* OPTIONAL */
LDAPSchemaExtensionItem **sr_extensions; /* OPTIONAL */
} LDAPStructureRule;
/*
* Misc macros
*/
#define LDAP_SCHEMA_NO 0
#define LDAP_SCHEMA_YES 1
#define LDAP_SCHEMA_USER_APPLICATIONS 0
#define LDAP_SCHEMA_DIRECTORY_OPERATION 1
#define LDAP_SCHEMA_DISTRIBUTED_OPERATION 2
#define LDAP_SCHEMA_DSA_OPERATION 3
#define LDAP_SCHEMA_ABSTRACT 0
#define LDAP_SCHEMA_STRUCTURAL 1
#define LDAP_SCHEMA_AUXILIARY 2
/*
* Flags that control how liberal the parsing routines are.
*/
#define LDAP_SCHEMA_ALLOW_NONE 0x00U /* Strict parsing */
#define LDAP_SCHEMA_ALLOW_NO_OID 0x01U /* Allow missing oid */
#define LDAP_SCHEMA_ALLOW_QUOTED 0x02U /* Allow bogus extra quotes */
#define LDAP_SCHEMA_ALLOW_DESCR 0x04U /* Allow descr instead of OID */
#define LDAP_SCHEMA_ALLOW_DESCR_PREFIX 0x08U /* Allow descr as OID prefix */
#define LDAP_SCHEMA_ALLOW_OID_MACRO 0x10U /* Allow OID macros in slapd */
#define LDAP_SCHEMA_ALLOW_OUT_OF_ORDER_FIELDS 0x20U /* Allow fields in most any order */
#define LDAP_SCHEMA_ALLOW_ALL 0x3fU /* Be very liberal in parsing */
#define LDAP_SCHEMA_SKIP 0x80U /* Don't malloc any result */
LDAP_F( LDAP_CONST char * )
ldap_syntax2name LDAP_P((
LDAPSyntax * syn ));
LDAP_F( LDAP_CONST char * )
ldap_matchingrule2name LDAP_P((
LDAPMatchingRule * mr ));
LDAP_F( LDAP_CONST char * )
ldap_matchingruleuse2name LDAP_P((
LDAPMatchingRuleUse * mru ));
LDAP_F( LDAP_CONST char * )
ldap_attributetype2name LDAP_P((
LDAPAttributeType * at ));
LDAP_F( LDAP_CONST char * )
ldap_objectclass2name LDAP_P((
LDAPObjectClass * oc ));
LDAP_F( LDAP_CONST char * )
ldap_contentrule2name LDAP_P((
LDAPContentRule * cr ));
LDAP_F( LDAP_CONST char * )
ldap_nameform2name LDAP_P((
LDAPNameForm * nf ));
LDAP_F( LDAP_CONST char * )
ldap_structurerule2name LDAP_P((
LDAPStructureRule * sr ));
LDAP_F( void )
ldap_syntax_free LDAP_P((
LDAPSyntax * syn ));
LDAP_F( void )
ldap_matchingrule_free LDAP_P((
LDAPMatchingRule * mr ));
LDAP_F( void )
ldap_matchingruleuse_free LDAP_P((
LDAPMatchingRuleUse * mr ));
LDAP_F( void )
ldap_attributetype_free LDAP_P((
LDAPAttributeType * at ));
LDAP_F( void )
ldap_objectclass_free LDAP_P((
LDAPObjectClass * oc ));
LDAP_F( void )
ldap_contentrule_free LDAP_P((
LDAPContentRule * cr ));
LDAP_F( void )
ldap_nameform_free LDAP_P((
LDAPNameForm * nf ));
LDAP_F( void )
ldap_structurerule_free LDAP_P((
LDAPStructureRule * sr ));
LDAP_F( LDAPStructureRule * )
ldap_str2structurerule LDAP_P((
LDAP_CONST char * s,
int * code,
LDAP_CONST char ** errp,
LDAP_CONST unsigned flags ));
LDAP_F( LDAPNameForm * )
ldap_str2nameform LDAP_P((
LDAP_CONST char * s,
int * code,
LDAP_CONST char ** errp,
LDAP_CONST unsigned flags ));
LDAP_F( LDAPContentRule * )
ldap_str2contentrule LDAP_P((
LDAP_CONST char * s,
int * code,
LDAP_CONST char ** errp,
LDAP_CONST unsigned flags ));
LDAP_F( LDAPObjectClass * )
ldap_str2objectclass LDAP_P((
LDAP_CONST char * s,
int * code,
LDAP_CONST char ** errp,
LDAP_CONST unsigned flags ));
LDAP_F( LDAPAttributeType * )
ldap_str2attributetype LDAP_P((
LDAP_CONST char * s,
int * code,
LDAP_CONST char ** errp,
LDAP_CONST unsigned flags ));
LDAP_F( LDAPSyntax * )
ldap_str2syntax LDAP_P((
LDAP_CONST char * s,
int * code,
LDAP_CONST char ** errp,
LDAP_CONST unsigned flags ));
LDAP_F( LDAPMatchingRule * )
ldap_str2matchingrule LDAP_P((
LDAP_CONST char * s,
int * code,
LDAP_CONST char ** errp,
LDAP_CONST unsigned flags ));
LDAP_F( LDAPMatchingRuleUse * )
ldap_str2matchingruleuse LDAP_P((
LDAP_CONST char * s,
int * code,
LDAP_CONST char ** errp,
LDAP_CONST unsigned flags ));
LDAP_F( char * )
ldap_structurerule2str LDAP_P((
LDAPStructureRule * sr ));
LDAP_F( struct berval * )
ldap_structurerule2bv LDAP_P((
LDAPStructureRule * sr, struct berval *bv ));
LDAP_F( char * )
ldap_nameform2str LDAP_P((
LDAPNameForm * nf ));
LDAP_F( struct berval * )
ldap_nameform2bv LDAP_P((
LDAPNameForm * nf, struct berval *bv ));
LDAP_F( char * )
ldap_contentrule2str LDAP_P((
LDAPContentRule * cr ));
LDAP_F( struct berval * )
ldap_contentrule2bv LDAP_P((
LDAPContentRule * cr, struct berval *bv ));
LDAP_F( char * )
ldap_objectclass2str LDAP_P((
LDAPObjectClass * oc ));
LDAP_F( struct berval * )
ldap_objectclass2bv LDAP_P((
LDAPObjectClass * oc, struct berval *bv ));
LDAP_F( char * )
ldap_attributetype2str LDAP_P((
LDAPAttributeType * at ));
LDAP_F( struct berval * )
ldap_attributetype2bv LDAP_P((
LDAPAttributeType * at, struct berval *bv ));
LDAP_F( char * )
ldap_syntax2str LDAP_P((
LDAPSyntax * syn ));
LDAP_F( struct berval * )
ldap_syntax2bv LDAP_P((
LDAPSyntax * syn, struct berval *bv ));
LDAP_F( char * )
ldap_matchingrule2str LDAP_P((
LDAPMatchingRule * mr ));
LDAP_F( struct berval * )
ldap_matchingrule2bv LDAP_P((
LDAPMatchingRule * mr, struct berval *bv ));
LDAP_F( char * )
ldap_matchingruleuse2str LDAP_P((
LDAPMatchingRuleUse * mru ));
LDAP_F( struct berval * )
ldap_matchingruleuse2bv LDAP_P((
LDAPMatchingRuleUse * mru, struct berval *bv ));
LDAP_F( char * )
ldap_scherr2str LDAP_P((
int code )) LDAP_GCCATTR((const));
LDAP_END_DECL
#endif
openldap-2.5.16+dfsg/include/lber_pvt.h 0000644 0001750 0001750 00000012507 14461774414 017322 0 ustar sergio sergio /* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/*
* lber_pvt.h - Header for ber_pvt_ functions.
* These are meant to be internal to OpenLDAP Software.
*/
#ifndef _LBER_PVT_H
#define _LBER_PVT_H 1
#include
LDAP_BEGIN_DECL
/* for allocating aligned buffers (on the stack) */
#define LBER_ALIGNED_BUFFER(uname,size) \
union uname { \
char buffer[size]; \
/* force alignment */ \
int ialign; \
long lalign; \
float falign; \
double dalign; \
char* palign; \
}
#define LBER_ELEMENT_SIZEOF (256) /* must be >= sizeof(BerElement) */
typedef LBER_ALIGNED_BUFFER(lber_berelement_u,LBER_ELEMENT_SIZEOF)
BerElementBuffer;
typedef struct sockbuf_buf {
ber_len_t buf_size;
ber_len_t buf_ptr;
ber_len_t buf_end;
char *buf_base;
} Sockbuf_Buf;
/*
* bprint.c
*/
LBER_V( BER_LOG_PRINT_FN ) ber_pvt_log_print;
LBER_F( int )
ber_pvt_log_printf LDAP_P((
int errlvl,
int loglvl,
const char *fmt,
... )) LDAP_GCCATTR((format(printf, 3, 4)));
/*
* sockbuf.c
*/
LBER_F( ber_slen_t )
ber_pvt_sb_do_write LDAP_P(( Sockbuf_IO_Desc *sbiod, Sockbuf_Buf *buf_out ));
LBER_F( void )
ber_pvt_sb_buf_init LDAP_P(( Sockbuf_Buf *buf ));
LBER_F( void )
ber_pvt_sb_buf_destroy LDAP_P(( Sockbuf_Buf *buf ));
LBER_F( int )
ber_pvt_sb_grow_buffer LDAP_P(( Sockbuf_Buf *buf, ber_len_t minsize ));
LBER_F( ber_len_t )
ber_pvt_sb_copy_out LDAP_P(( Sockbuf_Buf *sbb, char *buf, ber_len_t len ));
LBER_F( int )
ber_pvt_socket_set_nonblock LDAP_P(( ber_socket_t sd, int nb ));
/*
* memory.c
*/
LBER_F( void * )
ber_memalloc_x LDAP_P((
ber_len_t s, void *ctx));
LBER_F( void * )
ber_memrealloc_x LDAP_P((
void* p,
ber_len_t s, void *ctx ));
LBER_F( void * )
ber_memcalloc_x LDAP_P((
ber_len_t n,
ber_len_t s, void *ctx ));
LBER_F( void )
ber_memfree_x LDAP_P((
void* p, void *ctx ));
LBER_F( void )
ber_memvfree_x LDAP_P((
void** vector, void *ctx ));
LBER_F( void )
ber_bvfree_x LDAP_P((
struct berval *bv, void *ctx ));
LBER_F( void )
ber_bvecfree_x LDAP_P((
struct berval **bv, void *ctx ));
LBER_F( int )
ber_bvecadd_x LDAP_P((
struct berval ***bvec,
struct berval *bv, void *ctx ));
LBER_F( struct berval * )
ber_dupbv_x LDAP_P((
struct berval *dst, struct berval *src, void *ctx ));
LBER_F( struct berval * )
ber_str2bv_x LDAP_P((
LDAP_CONST char *, ber_len_t len, int dup, struct berval *bv, void *ctx));
LBER_F( struct berval * )
ber_mem2bv_x LDAP_P((
LDAP_CONST char *, ber_len_t len, int dup, struct berval *bv, void *ctx));
LBER_F( char * )
ber_strdup_x LDAP_P((
LDAP_CONST char *, void *ctx ));
LBER_F( struct berval * )
ber_bvreplace_x LDAP_P((
struct berval *dst, LDAP_CONST struct berval *src, void *ctx ));
LBER_F( void )
ber_bvarray_free_x LDAP_P(( BerVarray p, void *ctx ));
LBER_F( int )
ber_bvarray_add_x LDAP_P(( BerVarray *p, BerValue *bv, void *ctx ));
LBER_F( int )
ber_bvarray_dup_x LDAP_P(( BerVarray *dst, BerVarray src, void *ctx ));
#if 0
#define ber_bvstrcmp(v1,v2) \
((v1)->bv_len < (v2)->bv_len \
? -1 : ((v1)->bv_len > (v2)->bv_len \
? 1 : strncmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) ))
#else
/* avoid strncmp() */
#define ber_bvstrcmp(v1,v2) ber_bvcmp((v1),(v2))
#endif
#define ber_bvstrcasecmp(v1,v2) \
((v1)->bv_len < (v2)->bv_len \
? -1 : ((v1)->bv_len > (v2)->bv_len \
? 1 : strncasecmp((v1)->bv_val, (v2)->bv_val, (v1)->bv_len) ))
#define ber_bvccmp(v1,c) \
( (v1)->bv_len == 1 && (v1)->bv_val[0] == (c) )
#define ber_strccmp(s,c) \
( (s)[0] == (c) && (s)[1] == '\0' )
#define ber_bvchr(bv,c) \
((char *) memchr( (bv)->bv_val, (c), (bv)->bv_len ))
#define ber_bvrchr(bv,c) \
((char *) lutil_memrchr( (bv)->bv_val, (c), (bv)->bv_len ))
#define ber_bvchr_post(dst,bv,c) \
do { \
(dst)->bv_val = memchr( (bv)->bv_val, (c), (bv)->bv_len ); \
(dst)->bv_len = (dst)->bv_val ? (bv)->bv_len - ((dst)->bv_val - (bv)->bv_val) : 0; \
} while (0)
#define ber_bvchr_pre(dst,bv,c) \
do { \
(dst)->bv_val = memchr( (bv)->bv_val, (c), (bv)->bv_len ); \
(dst)->bv_len = (dst)->bv_val ? ((dst)->bv_val - (bv)->bv_val) : (bv)->bv_len; \
(dst)->bv_val = (bv)->bv_val; \
} while (0)
#define ber_bvrchr_post(dst,bv,c) \
do { \
(dst)->bv_val = lutil_memrchr( (bv)->bv_val, (c), (bv)->bv_len ); \
(dst)->bv_len = (dst)->bv_val ? (bv)->bv_len - ((dst)->bv_val - (bv)->bv_val) : 0; \
} while (0)
#define ber_bvrchr_pre(dst,bv,c) \
do { \
(dst)->bv_val = lutil_memrchr( (bv)->bv_val, (c), (bv)->bv_len ); \
(dst)->bv_len = (dst)->bv_val ? ((dst)->bv_val - (bv)->bv_val) : (bv)->bv_len; \
(dst)->bv_val = (bv)->bv_val; \
} while (0)
#define BER_STRLENOF(s) (sizeof(s)-1)
#define BER_BVC(s) { BER_STRLENOF(s), (char *)(s) }
#define BER_BVNULL { 0L, NULL }
#define BER_BVZERO(bv) \
do { \
(bv)->bv_len = 0; \
(bv)->bv_val = NULL; \
} while (0)
#define BER_BVSTR(bv,s) \
do { \
(bv)->bv_len = BER_STRLENOF(s); \
(bv)->bv_val = (s); \
} while (0)
#define BER_BVISNULL(bv) ((bv)->bv_val == NULL)
#define BER_BVISEMPTY(bv) ((bv)->bv_len == 0)
LDAP_END_DECL
#endif
openldap-2.5.16+dfsg/include/ldap_utf8.h 0000644 0001750 0001750 00000006614 14461774414 017375 0 ustar sergio sergio /* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* This notice applies to changes, created by or for Novell, Inc.,
* to preexisting works for which notices appear elsewhere in this file.
*
* Copyright (C) 2000 Novell, Inc. All Rights Reserved.
*
* THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.
* USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO VERSION
* 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS AVAILABLE AT
* HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE "LICENSE" IN THE
* TOP-LEVEL DIRECTORY OF THE DISTRIBUTION. ANY USE OR EXPLOITATION OF THIS
* WORK OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP PUBLIC
* LICENSE, OR OTHER PRIOR WRITTEN CONSENT FROM NOVELL, COULD SUBJECT THE
* PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY.
*/
/* Note: A verbatim copy of version 2.0.1 of the OpenLDAP Public License
* can be found in the file "build/LICENSE-2.0.1" in this distribution
* of OpenLDAP Software.
*/
#ifndef _LDAP_UTF8_H
#define _LDAP_UTF8_H
#include /* get ber_*_t */
/*
* UTF-8 Utility Routines
*/
LDAP_BEGIN_DECL
#define LDAP_UCS4_INVALID (0x80000000U)
typedef ber_int_t ldap_ucs4_t;
/* LDAP_MAX_UTF8_LEN is 3 or 6 depending on size of wchar_t */
#define LDAP_MAX_UTF8_LEN ( sizeof(wchar_t) * 3/2 )
/* Unicode conversion routines */
LDAP_F( ldap_ucs4_t ) ldap_x_utf8_to_ucs4( LDAP_CONST char * p );
LDAP_F( int ) ldap_x_ucs4_to_utf8( ldap_ucs4_t c, char *buf );
/*
* Wide Char / UTF-8 Conversion Routines
*/
/* UTF-8 character to Wide Char */
LDAP_F(int) ldap_x_utf8_to_wc LDAP_P((
wchar_t *wchar, LDAP_CONST char *utf8char ));
/* UTF-8 string to Wide Char string */
LDAP_F(int) ldap_x_utf8s_to_wcs LDAP_P((
wchar_t *wcstr, LDAP_CONST char *utf8str, size_t count ));
/* Wide Char to UTF-8 character */
LDAP_F(int) ldap_x_wc_to_utf8 LDAP_P((
char *utf8char, wchar_t wchar, size_t count ));
/* Wide Char string to UTF-8 string */
LDAP_F(int) ldap_x_wcs_to_utf8s LDAP_P((
char *utf8str, LDAP_CONST wchar_t *wcstr, size_t count ));
/*
* MultiByte Char / UTF-8 Conversion Routines
*/
/* UTF-8 character to MultiByte character */
LDAP_F(int) ldap_x_utf8_to_mb LDAP_P((
char *mbchar, LDAP_CONST char *utf8char,
int (*ldap_f_wctomb)( char *mbchar, wchar_t wchar )));
/* UTF-8 string to MultiByte string */
LDAP_F(int) ldap_x_utf8s_to_mbs LDAP_P((
char *mbstr, LDAP_CONST char *utf8str, size_t count,
size_t (*ldap_f_wcstombs)( char *mbstr,
LDAP_CONST wchar_t *wcstr, size_t count) ));
/* MultiByte character to UTF-8 character */
LDAP_F(int) ldap_x_mb_to_utf8 LDAP_P((
char *utf8char, LDAP_CONST char *mbchar, size_t mbsize,
int (*ldap_f_mbtowc)( wchar_t *wchar,
LDAP_CONST char *mbchar, size_t count) ));
/* MultiByte string to UTF-8 string */
LDAP_F(int) ldap_x_mbs_to_utf8s LDAP_P((
char *utf8str, LDAP_CONST char *mbstr, size_t count,
size_t (*ldap_f_mbstowcs)( wchar_t *wcstr,
LDAP_CONST char *mbstr, size_t count) ));
LDAP_END_DECL
#endif /* _LDAP_UTF8_H */
openldap-2.5.16+dfsg/include/getopt-compat.h 0000644 0001750 0001750 00000002034 14461774414 020262 0 ustar sergio sergio /* getopt-compat.h -- getopt(3) compatibility header */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/*
* getopt(3) declarations
*/
#ifndef _GETOPT_COMPAT_H
#define _GETOPT_COMPAT_H
#include
LDAP_BEGIN_DECL
/* change symbols to avoid clashing */
#define optarg lutil_optarg
#define optind lutil_optind
#define opterr lutil_opterr
#define optopt lutil_optopt
#define getopt lutil_getopt
LDAP_LUTIL_V (char *) optarg;
LDAP_LUTIL_V (int) optind, opterr, optopt;
LDAP_LUTIL_F (int) getopt LDAP_P(( int, char * const [], const char *));
LDAP_END_DECL
#endif /* _GETOPT_COMPAT_H */
openldap-2.5.16+dfsg/include/ldap_features.hin 0000644 0001750 0001750 00000002705 14461774414 020651 0 ustar sergio sergio /* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/*
* LDAP Features
*/
#ifndef _LDAP_FEATURES_H
#define _LDAP_FEATURES_H 1
/* OpenLDAP API version macros */
#undef LDAP_VENDOR_VERSION
#undef LDAP_VENDOR_VERSION_MAJOR
#undef LDAP_VENDOR_VERSION_MINOR
#undef LDAP_VENDOR_VERSION_PATCH
/*
** WORK IN PROGRESS!
**
** OpenLDAP reentrancy/thread-safeness should be dynamically
** checked using ldap_get_option().
**
** If built with thread support, the -lldap implementation is:
** LDAP_API_FEATURE_THREAD_SAFE (basic thread safety)
** LDAP_API_FEATURE_SESSION_THREAD_SAFE
** LDAP_API_FEATURE_OPERATION_THREAD_SAFE
**
** The preprocessor flag LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE
** can be used to determine if -lldap is thread safe at compile
** time.
**
*/
/* is -lldap reentrant or not */
#undef LDAP_API_FEATURE_X_OPENLDAP_REENTRANT
/* is -lldap thread safe or not */
#undef LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE
/* LDAP v2 Referrals */
#undef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
#endif /* LDAP_FEATURES */
openldap-2.5.16+dfsg/include/lutil_lockf.h 0000644 0001750 0001750 00000001455 14461774414 020014 0 ustar sergio sergio /* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* File locking methods
*
* lutil_lockf() will block until an exclusive lock is acquired.
*/
#ifndef _LUTIL_LOCKF_H_
#define _LUTIL_LOCKF_H_
LDAP_BEGIN_DECL
LDAP_LUTIL_F( int )
lutil_lockf LDAP_P(( int fd ));
LDAP_LUTIL_F( int )
lutil_unlockf LDAP_P(( int fd ));
LDAP_END_DECL
#endif /* _LUTIL_LOCKF_H_ */
openldap-2.5.16+dfsg/include/openldap.h 0000644 0001750 0001750 00000001704 14461774414 017304 0 ustar sergio sergio /* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 2019-2022 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* openldap.h - Header for openldap specific interfaces. */
#ifndef _OPENLDAP_H
#define _OPENLDAP_H 1
#include
LDAP_BEGIN_DECL
#define LDAP_PROTO_TCP 1 /* ldap:// */
#define LDAP_PROTO_UDP 2 /* reserved */
#define LDAP_PROTO_IPC 3 /* ldapi:// */
#define LDAP_PROTO_EXT 4 /* user-defined socket/sockbuf */
LDAP_F( int )
ldap_init_fd LDAP_P((
ber_socket_t fd,
int proto,
LDAP_CONST char *url,
LDAP **ldp ));
LDAP_END_DECL
#endif /* _OPENLDAP_H */
openldap-2.5.16+dfsg/include/slapi-plugin.h 0000644 0001750 0001750 00000112720 14461774414 020107 0 ustar sergio sergio /* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* Portions Copyright 1997,2002,2003 IBM Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/*
* This header is used in development of SLAPI plugins for
* OpenLDAP slapd(8) and other directory servers supporting
* this interface. Your portability mileage may vary.
*/
#ifndef _SLAPI_PLUGIN_H
#define _SLAPI_PLUGIN_H
#include
typedef struct slapi_pblock Slapi_PBlock;
typedef struct slapi_entry Slapi_Entry;
typedef struct slapi_attr Slapi_Attr;
typedef struct slapi_value Slapi_Value;
typedef struct slapi_valueset Slapi_ValueSet;
typedef struct slapi_filter Slapi_Filter;
typedef struct BackendDB Slapi_Backend;
typedef struct Operation Slapi_Operation;
typedef struct Connection Slapi_Connection;
typedef struct slapi_dn Slapi_DN;
typedef struct slapi_rdn Slapi_RDN;
typedef struct slapi_mod Slapi_Mod;
typedef struct slapi_mods Slapi_Mods;
typedef struct slapi_componentid Slapi_ComponentId;
#define SLAPI_ATTR_UNIQUEID "entryUUID"
#define SLAPI_ATTR_OBJECTCLASS "objectClass"
/* pblock routines */
int slapi_pblock_get( Slapi_PBlock *pb, int arg, void *value );
int slapi_pblock_set( Slapi_PBlock *pb, int arg, void *value );
Slapi_PBlock *slapi_pblock_new( void );
void slapi_pblock_destroy( Slapi_PBlock *pb );
/* entry/attr/dn routines */
Slapi_Entry *slapi_str2entry( char *s, int flags );
#define SLAPI_STR2ENTRY_REMOVEDUPVALS 1
#define SLAPI_STR2ENTRY_ADDRDNVALS 2
#define SLAPI_STR2ENTRY_BIGENTRY 4
#define SLAPI_STR2ENTRY_TOMBSTONE_CHECK 8
#define SLAPI_STR2ENTRY_IGNORE_STATE 16
#define SLAPI_STR2ENTRY_INCLUDE_VERSION_STR 32
#define SLAPI_STR2ENTRY_EXPAND_OBJECTCLASSES 64
#define SLAPI_STR2ENTRY_NOT_WELL_FORMED_LDIF 128
char *slapi_entry2str( Slapi_Entry *e, int *len );
char *slapi_entry_get_dn( Slapi_Entry *e );
int slapi_x_entry_get_id( Slapi_Entry *e );
void slapi_entry_set_dn( Slapi_Entry *e, char *dn );
Slapi_Entry *slapi_entry_dup( Slapi_Entry *e );
int slapi_entry_attr_delete( Slapi_Entry *e, char *type );
Slapi_Entry *slapi_entry_alloc();
void slapi_entry_free( Slapi_Entry *e );
int slapi_entry_attr_merge( Slapi_Entry *e, char *type, struct berval **vals );
int slapi_entry_attr_find( Slapi_Entry *e, char *type, Slapi_Attr **attr );
char *slapi_entry_attr_get_charptr( const Slapi_Entry *e, const char *type );
int slapi_entry_attr_get_int( const Slapi_Entry *e, const char *type );
long slapi_entry_attr_get_long( const Slapi_Entry *e, const char *type );
unsigned int slapi_entry_attr_get_uint( const Slapi_Entry *e, const char *type );
unsigned long slapi_entry_attr_get_ulong( const Slapi_Entry *e, const char *type );
int slapi_attr_get_values( Slapi_Attr *attr, struct berval ***vals );
char *slapi_dn_normalize( char *dn );
char *slapi_dn_normalize_case( char *dn );
int slapi_dn_issuffix( char *dn, char *suffix );
char *slapi_dn_beparent( Slapi_PBlock *pb, const char *dn );
int slapi_dn_isbesuffix( Slapi_PBlock *pb, char *dn );
char *slapi_dn_parent( const char *dn );
int slapi_dn_isparent( const char *parentdn, const char *childdn );
char *slapi_dn_ignore_case( char *dn );
int slapi_rdn2typeval( char *rdn, char **type, struct berval *bv );
char *slapi_dn_plus_rdn(const char *dn, const char *rdn);
/* DS 5.x SLAPI */
int slapi_access_allowed( Slapi_PBlock *pb, Slapi_Entry *e, char *attr, struct berval *val, int access );
int slapi_acl_check_mods( Slapi_PBlock *pb, Slapi_Entry *e, LDAPMod **mods, char **errbuf );
Slapi_Attr *slapi_attr_new( void );
Slapi_Attr *slapi_attr_init( Slapi_Attr *a, const char *type );
void slapi_attr_free( Slapi_Attr **a );
Slapi_Attr *slapi_attr_dup( const Slapi_Attr *attr );
int slapi_attr_add_value( Slapi_Attr *a, const Slapi_Value *v );
int slapi_attr_type2plugin( const char *type, void **pi );
int slapi_attr_get_type( const Slapi_Attr *attr, char **type );
int slapi_attr_get_oid_copy( const Slapi_Attr *attr, char **oidp );
int slapi_attr_get_flags( const Slapi_Attr *attr, unsigned long *flags );
int slapi_attr_flag_is_set( const Slapi_Attr *attr, unsigned long flag );
int slapi_attr_value_cmp( const Slapi_Attr *attr, const struct berval *v1, const struct berval *v2 );
int slapi_attr_value_find( const Slapi_Attr *a, struct berval *v );
#define SLAPI_TYPE_CMP_EXACT 0
#define SLAPI_TYPE_CMP_BASE 1
#define SLAPI_TYPE_CMP_SUBTYPE 2
int slapi_attr_type_cmp( const char *t1, const char *t2, int opt );
int slapi_attr_types_equivalent( const char *t1, const char *t2 );
int slapi_attr_first_value( Slapi_Attr *a, Slapi_Value **v );
int slapi_attr_next_value( Slapi_Attr *a, int hint, Slapi_Value **v );
int slapi_attr_get_numvalues( const Slapi_Attr *a, int *numValues );
int slapi_attr_get_valueset( const Slapi_Attr *a, Slapi_ValueSet **vs );
int slapi_attr_get_bervals_copy( Slapi_Attr *a, struct berval ***vals );
int slapi_entry_attr_hasvalue( Slapi_Entry *e, const char *type, const char *value );
int slapi_entry_attr_merge_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
void slapi_entry_attr_set_charptr(Slapi_Entry* e, const char *type, const char *value);
void slapi_entry_attr_set_int( Slapi_Entry* e, const char *type, int l);
void slapi_entry_attr_set_uint( Slapi_Entry* e, const char *type, unsigned int l);
void slapi_entry_attr_set_long(Slapi_Entry* e, const char *type, long l);
void slapi_entry_attr_set_ulong(Slapi_Entry* e, const char *type, unsigned long l);
int slapi_entry_has_children(const Slapi_Entry *e);
size_t slapi_entry_size(Slapi_Entry *e);
int slapi_is_rootdse( const char *dn );
int slapi_entry_attr_merge_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
int slapi_entry_add_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
int slapi_entry_add_valueset(Slapi_Entry *e, const char *type, Slapi_ValueSet *vs);
int slapi_entry_delete_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
int slapi_entry_merge_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
int slapi_entry_attr_replace_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
int slapi_entry_add_value(Slapi_Entry *e, const char *type, const Slapi_Value *value);
int slapi_entry_add_string(Slapi_Entry *e, const char *type, const char *value);
int slapi_entry_delete_string(Slapi_Entry *e, const char *type, const char *value);
int slapi_entry_first_attr( const Slapi_Entry *e, Slapi_Attr **attr );
int slapi_entry_next_attr( const Slapi_Entry *e, Slapi_Attr *prevattr, Slapi_Attr **attr );
const char *slapi_entry_get_uniqueid( const Slapi_Entry *e );
void slapi_entry_set_uniqueid( Slapi_Entry *e, char *uniqueid );
int slapi_entry_schema_check( Slapi_PBlock *pb, Slapi_Entry *e );
int slapi_entry_rdn_values_present( const Slapi_Entry *e );
int slapi_entry_add_rdn_values( Slapi_Entry *e );
char *slapi_attr_syntax_normalize( const char *s );
Slapi_Value *slapi_value_new( void );
Slapi_Value *slapi_value_new_berval(const struct berval *bval);
Slapi_Value *slapi_value_new_value(const Slapi_Value *v);
Slapi_Value *slapi_value_new_string(const char *s);
Slapi_Value *slapi_value_init(Slapi_Value *v);
Slapi_Value *slapi_value_init_berval(Slapi_Value *v, struct berval *bval);
Slapi_Value *slapi_value_init_string(Slapi_Value *v, const char *s);
Slapi_Value *slapi_value_dup(const Slapi_Value *v);
void slapi_value_free(Slapi_Value **value);
const struct berval *slapi_value_get_berval( const Slapi_Value *value );
Slapi_Value *slapi_value_set_berval( Slapi_Value *value, const struct berval *bval );
Slapi_Value *slapi_value_set_value( Slapi_Value *value, const Slapi_Value *vfrom);
Slapi_Value *slapi_value_set( Slapi_Value *value, void *val, unsigned long len);
int slapi_value_set_string(Slapi_Value *value, const char *strVal);
int slapi_value_set_int(Slapi_Value *value, int intVal);
const char*slapi_value_get_string(const Slapi_Value *value);
int slapi_value_get_int(const Slapi_Value *value);
unsigned int slapi_value_get_uint(const Slapi_Value *value);
long slapi_value_get_long(const Slapi_Value *value);
unsigned long slapi_value_get_ulong(const Slapi_Value *value);
size_t slapi_value_get_length(const Slapi_Value *value);
int slapi_value_compare(const Slapi_Attr *a, const Slapi_Value *v1, const Slapi_Value *v2);
Slapi_ValueSet *slapi_valueset_new( void );
void slapi_valueset_free(Slapi_ValueSet *vs);
void slapi_valueset_init(Slapi_ValueSet *vs);
void slapi_valueset_done(Slapi_ValueSet *vs);
void slapi_valueset_add_value(Slapi_ValueSet *vs, const Slapi_Value *addval);
int slapi_valueset_first_value( Slapi_ValueSet *vs, Slapi_Value **v );
int slapi_valueset_next_value( Slapi_ValueSet *vs, int index, Slapi_Value **v);
int slapi_valueset_count( const Slapi_ValueSet *vs);
void slapi_valueset_set_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2);
/* DNs */
Slapi_DN *slapi_sdn_new( void );
Slapi_DN *slapi_sdn_new_dn_byval( const char *dn );
Slapi_DN *slapi_sdn_new_ndn_byval( const char *ndn );
Slapi_DN *slapi_sdn_new_dn_byref( const char *dn );
Slapi_DN *slapi_sdn_new_ndn_byref( const char *ndn );
Slapi_DN *slapi_sdn_new_dn_passin( const char *dn );
Slapi_DN *slapi_sdn_set_dn_byval( Slapi_DN *sdn, const char *dn );
Slapi_DN *slapi_sdn_set_dn_byref( Slapi_DN *sdn, const char *dn );
Slapi_DN *slapi_sdn_set_dn_passin( Slapi_DN *sdn, const char *dn );
Slapi_DN *slapi_sdn_set_ndn_byval( Slapi_DN *sdn, const char *ndn );
Slapi_DN *slapi_sdn_set_ndn_byref( Slapi_DN *sdn, const char *ndn );
void slapi_sdn_done( Slapi_DN *sdn );
void slapi_sdn_free( Slapi_DN **sdn );
const char * slapi_sdn_get_dn( const Slapi_DN *sdn );
const char * slapi_sdn_get_ndn( const Slapi_DN *sdn );
void slapi_sdn_get_parent( const Slapi_DN *sdn,Slapi_DN *sdn_parent );
void slapi_sdn_get_backend_parent( const Slapi_DN *sdn, Slapi_DN *sdn_parent, const Slapi_Backend *backend );
Slapi_DN * slapi_sdn_dup( const Slapi_DN *sdn );
void slapi_sdn_copy( const Slapi_DN *from, Slapi_DN *to );
int slapi_sdn_compare( const Slapi_DN *sdn1, const Slapi_DN *sdn2 );
int slapi_sdn_isempty( const Slapi_DN *sdn );
int slapi_sdn_issuffix(const Slapi_DN *sdn, const Slapi_DN *suffixsdn );
int slapi_sdn_isparent( const Slapi_DN *parent, const Slapi_DN *child );
int slapi_sdn_isgrandparent( const Slapi_DN *parent, const Slapi_DN *child );
int slapi_sdn_get_ndn_len( const Slapi_DN *sdn );
int slapi_sdn_scope_test( const Slapi_DN *dn, const Slapi_DN *base, int scope );
void slapi_sdn_get_rdn( const Slapi_DN *sdn,Slapi_RDN *rdn );
Slapi_DN *slapi_sdn_set_rdn( Slapi_DN *sdn, const Slapi_RDN *rdn );
Slapi_DN *slapi_sdn_set_parent( Slapi_DN *sdn, const Slapi_DN *parentdn );
int slapi_sdn_is_rdn_component( const Slapi_DN *rdn, const Slapi_Attr *a, const Slapi_Value *v );
char * slapi_moddn_get_newdn( Slapi_DN *dn_olddn, char *newrdn, char *newsuperiordn );
/* RDNs */
Slapi_RDN *slapi_rdn_new( void );
Slapi_RDN *slapi_rdn_new_dn( const char *dn );
Slapi_RDN *slapi_rdn_new_sdn( const Slapi_DN *sdn );
Slapi_RDN *slapi_rdn_new_rdn( const Slapi_RDN *fromrdn );
void slapi_rdn_init( Slapi_RDN *rdn );
void slapi_rdn_init_dn( Slapi_RDN *rdn, const char *dn );
void slapi_rdn_init_sdn( Slapi_RDN *rdn, const Slapi_DN *sdn );
void slapi_rdn_init_rdn( Slapi_RDN *rdn, const Slapi_RDN *fromrdn );
void slapi_rdn_set_dn( Slapi_RDN *rdn, const char *dn );
void slapi_rdn_set_sdn( Slapi_RDN *rdn, const Slapi_DN *sdn );
void slapi_rdn_set_rdn( Slapi_RDN *rdn, const Slapi_RDN *fromrdn );
void slapi_rdn_free( Slapi_RDN **rdn );
void slapi_rdn_done( Slapi_RDN *rdn );
int slapi_rdn_get_first( Slapi_RDN *rdn, char **type, char **value );
int slapi_rdn_get_next( Slapi_RDN *rdn, int index, char **type, char **value );
int slapi_rdn_get_index( Slapi_RDN *rdn, const char *type, const char *value, size_t length );
int slapi_rdn_get_index_attr( Slapi_RDN *rdn, const char *type, char **value );
int slapi_rdn_contains( Slapi_RDN *rdn, const char *type, const char *value,size_t length );
int slapi_rdn_contains_attr( Slapi_RDN *rdn, const char *type, char **value );
int slapi_rdn_add( Slapi_RDN *rdn, const char *type, const char *value );
int slapi_rdn_remove_index( Slapi_RDN *rdn, int atindex );
int slapi_rdn_remove( Slapi_RDN *rdn, const char *type, const char *value, size_t length );
int slapi_rdn_remove_attr( Slapi_RDN *rdn, const char *type );
int slapi_rdn_isempty( const Slapi_RDN *rdn );
int slapi_rdn_get_num_components( Slapi_RDN *rdn );
int slapi_rdn_compare( Slapi_RDN *rdn1, Slapi_RDN *rdn2 );
const char *slapi_rdn_get_rdn( const Slapi_RDN *rdn );
const char *slapi_rdn_get_nrdn( const Slapi_RDN *rdn );
Slapi_DN *slapi_sdn_add_rdn( Slapi_DN *sdn, const Slapi_RDN *rdn );
/* locks and synchronization */
typedef struct slapi_mutex Slapi_Mutex;
typedef struct slapi_condvar Slapi_CondVar;
Slapi_Mutex *slapi_new_mutex( void );
void slapi_destroy_mutex( Slapi_Mutex *mutex );
void slapi_lock_mutex( Slapi_Mutex *mutex );
int slapi_unlock_mutex( Slapi_Mutex *mutex );
Slapi_CondVar *slapi_new_condvar( Slapi_Mutex *mutex );
void slapi_destroy_condvar( Slapi_CondVar *cvar );
int slapi_wait_condvar( Slapi_CondVar *cvar, struct timeval *timeout );
int slapi_notify_condvar( Slapi_CondVar *cvar, int notify_all );
/* thread-safe LDAP connections */
LDAP *slapi_ldap_init( char *ldaphost, int ldapport, int secure, int shared );
void slapi_ldap_unbind( LDAP *ld );
char *slapi_ch_malloc( unsigned long size );
void slapi_ch_free( void **ptr );
void slapi_ch_free_string( char **ptr );
char *slapi_ch_calloc( unsigned long nelem, unsigned long size );
char *slapi_ch_realloc( char *block, unsigned long size );
char *slapi_ch_strdup( const char *s );
void slapi_ch_array_free( char **arrayp );
struct berval *slapi_ch_bvdup(const struct berval *v);
struct berval **slapi_ch_bvecdup(const struct berval **v);
/* LDAP V3 routines */
int slapi_control_present( LDAPControl **controls, char *oid,
struct berval **val, int *iscritical);
void slapi_register_supported_control(char *controloid,
unsigned long controlops);
#define SLAPI_OPERATION_BIND 0x00000001L
#define SLAPI_OPERATION_UNBIND 0x00000002L
#define SLAPI_OPERATION_SEARCH 0x00000004L
#define SLAPI_OPERATION_MODIFY 0x00000008L
#define SLAPI_OPERATION_ADD 0x00000010L
#define SLAPI_OPERATION_DELETE 0x00000020L
#define SLAPI_OPERATION_MODDN 0x00000040L
#define SLAPI_OPERATION_MODRDN SLAPI_OPERATION_MODDN
#define SLAPI_OPERATION_COMPARE 0x00000080L
#define SLAPI_OPERATION_ABANDON 0x00000100L
#define SLAPI_OPERATION_EXTENDED 0x00000200L
#define SLAPI_OPERATION_ANY 0xFFFFFFFFL
#define SLAPI_OPERATION_NONE 0x00000000L
int slapi_get_supported_controls(char ***ctrloidsp, unsigned long **ctrlopsp);
LDAPControl *slapi_dup_control(LDAPControl *ctrl);
void slapi_register_supported_saslmechanism(char *mechanism);
char **slapi_get_supported_saslmechanisms();
char **slapi_get_supported_extended_ops(void);
/* operation */
int slapi_op_abandoned( Slapi_PBlock *pb );
unsigned long slapi_op_get_type(Slapi_Operation * op);
void slapi_operation_set_flag(Slapi_Operation *op, unsigned long flag);
void slapi_operation_clear_flag(Slapi_Operation *op, unsigned long flag);
int slapi_operation_is_flag_set(Slapi_Operation *op, unsigned long flag);
char *slapi_op_type_to_string(unsigned long type);
/* send ldap result back */
void slapi_send_ldap_result( Slapi_PBlock *pb, int err, char *matched,
char *text, int nentries, struct berval **urls );
int slapi_send_ldap_search_entry( Slapi_PBlock *pb, Slapi_Entry *e,
LDAPControl **ectrls, char **attrs, int attrsonly );
int slapi_send_ldap_search_reference( Slapi_PBlock *pb, Slapi_Entry *e,
struct berval **urls, LDAPControl **ectrls, struct berval **v2refs );
/* filter routines */
Slapi_Filter *slapi_str2filter( char *str );
Slapi_Filter *slapi_filter_dup( Slapi_Filter *f );
void slapi_filter_free( Slapi_Filter *f, int recurse );
int slapi_filter_get_choice( Slapi_Filter *f);
int slapi_filter_get_ava( Slapi_Filter *f, char **type, struct berval **bval );
Slapi_Filter *slapi_filter_list_first( Slapi_Filter *f );
Slapi_Filter *slapi_filter_list_next( Slapi_Filter *f, Slapi_Filter *fprev );
int slapi_filter_get_attribute_type( Slapi_Filter *f, char **type );
int slapi_x_filter_set_attribute_type( Slapi_Filter *f, const char *type );
int slapi_filter_get_subfilt( Slapi_Filter *f, char **type, char **initial,
char ***any, char **final );
Slapi_Filter *slapi_filter_join( int ftype, Slapi_Filter *f1, Slapi_Filter *f2);
int slapi_x_filter_append( int choice, Slapi_Filter **pContainingFilter,
Slapi_Filter **pNextFilter, Slapi_Filter *filterToAppend );
int slapi_filter_test( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Filter *f,
int verify_access );
int slapi_filter_test_simple( Slapi_Entry *e, Slapi_Filter *f );
typedef int (*FILTER_APPLY_FN)( Slapi_Filter *f, void *arg );
int slapi_filter_apply( Slapi_Filter *f, FILTER_APPLY_FN fn, void *arg, int *error_code );
#define SLAPI_FILTER_SCAN_STOP -1 /* set by callback */
#define SLAPI_FILTER_SCAN_ERROR -2 /* set by callback */
#define SLAPI_FILTER_SCAN_NOMORE 0 /* set by callback */
#define SLAPI_FILTER_SCAN_CONTINUE 1 /* set by callback */
#define SLAPI_FILTER_UNKNOWN_FILTER_TYPE 2 /* set by slapi_filter_apply() */
/* internal add/delete/search/modify routines */
Slapi_PBlock *slapi_search_internal( char *base, int scope, char *filter,
LDAPControl **controls, char **attrs, int attrsonly );
Slapi_PBlock *slapi_modify_internal( char *dn, LDAPMod **mods,
LDAPControl **controls, int log_change );
Slapi_PBlock *slapi_add_internal( char * dn, LDAPMod **attrs,
LDAPControl **controls, int log_changes );
Slapi_PBlock *slapi_add_entry_internal( Slapi_Entry * e,
LDAPControl **controls, int log_change );
Slapi_PBlock *slapi_delete_internal( char * dn, LDAPControl **controls,
int log_change );
Slapi_PBlock *slapi_modrdn_internal( char * olddn, char * newrdn,
int deloldrdn, LDAPControl **controls,
int log_change );
Slapi_PBlock *slapi_rename_internal( const char * olddn, const char *newrdn,
const char *newsuperior, int deloldrdn,
LDAPControl **controls, int log_change );
void slapi_free_search_results_internal(Slapi_PBlock *pb);
/* new internal add/delete/search/modify routines */
typedef void (*plugin_result_callback)( int rc, void *callback_data );
typedef int (*plugin_referral_entry_callback)( char * referral,
void *callback_data );
typedef int (*plugin_search_entry_callback)( Slapi_Entry *e,
void *callback_data );
void slapi_free_search_results_internal( Slapi_PBlock *pb );
#define SLAPI_OP_FLAG_NEVER_CHAIN 0x0800
int slapi_search_internal_pb( Slapi_PBlock *pb );
int slapi_search_internal_callback_pb( Slapi_PBlock *pb, void *callback_data,
plugin_result_callback prc, plugin_search_entry_callback psec,
plugin_referral_entry_callback prec );
int slapi_add_internal_pb( Slapi_PBlock *pb );
int slapi_modify_internal_pb( Slapi_PBlock *pb );
int slapi_modrdn_internal_pb( Slapi_PBlock *pb );
int slapi_delete_internal_pb( Slapi_PBlock *pb );
int slapi_seq_internal_callback_pb(Slapi_PBlock *pb, void *callback_data,
plugin_result_callback res_callback,
plugin_search_entry_callback srch_callback,
plugin_referral_entry_callback ref_callback);
void slapi_search_internal_set_pb( Slapi_PBlock *pb, const char *base,
int scope, const char *filter, char **attrs, int attrsonly,
LDAPControl **controls, const char *uniqueid,
Slapi_ComponentId *plugin_identity, int operation_flags );
void slapi_add_entry_internal_set_pb( Slapi_PBlock *pb, Slapi_Entry *e,
LDAPControl **controls, Slapi_ComponentId *plugin_identity,
int operation_flags );
int slapi_add_internal_set_pb( Slapi_PBlock *pb, const char *dn,
LDAPMod **attrs, LDAPControl **controls,
Slapi_ComponentId *plugin_identity, int operation_flags );
void slapi_modify_internal_set_pb( Slapi_PBlock *pb, const char *dn,
LDAPMod **mods, LDAPControl **controls, const char *uniqueid,
Slapi_ComponentId *plugin_identity, int operation_flags );
void slapi_rename_internal_set_pb( Slapi_PBlock *pb, const char *olddn,
const char *newrdn, const char *newsuperior, int deloldrdn,
LDAPControl **controls, const char *uniqueid,
Slapi_ComponentId *plugin_identity, int operation_flags );
void slapi_delete_internal_set_pb( Slapi_PBlock *pb, const char *dn,
LDAPControl **controls, const char *uniqueid,
Slapi_ComponentId *plugin_identity, int operation_flags );
void slapi_seq_internal_set_pb( Slapi_PBlock *pb, char *ibase, int type,
char *attrname, char *val, char **attrs, int attrsonly,
LDAPControl **controls, Slapi_ComponentId *plugin_identity,
int operation_flags );
/* connection related routines */
int slapi_is_connection_ssl(Slapi_PBlock *pPB, int *isSSL);
int slapi_get_client_port(Slapi_PBlock *pPB, int *fromPort);
int slapi_get_client_ip(Slapi_PBlock *pb, char **clientIP);
void slapi_free_client_ip(char **clientIP);
/* computed attributes */
typedef struct _computed_attr_context computed_attr_context;
typedef int (*slapi_compute_output_t)(computed_attr_context *c, Slapi_Attr *a, Slapi_Entry *e);
typedef int (*slapi_compute_callback_t)(computed_attr_context *c, char *type, Slapi_Entry *e, slapi_compute_output_t outputfn);
typedef int (*slapi_search_rewrite_callback_t)(Slapi_PBlock *pb);
int slapi_compute_add_evaluator(slapi_compute_callback_t function);
int slapi_compute_add_search_rewriter(slapi_search_rewrite_callback_t function);
int compute_rewrite_search_filter(Slapi_PBlock *pb);
int compute_evaluator(computed_attr_context *c, char *type, Slapi_Entry *e, slapi_compute_output_t outputfn);
int slapi_x_compute_get_pblock(computed_attr_context *c, Slapi_PBlock **pb);
/* backend routines */
void slapi_be_set_readonly( Slapi_Backend *be, int readonly );
int slapi_be_get_readonly( Slapi_Backend *be );
const char *slapi_x_be_get_updatedn( Slapi_Backend *be );
Slapi_Backend *slapi_be_select( const Slapi_DN *sdn );
/* ACL plugins; only SLAPI_PLUGIN_ACL_ALLOW_ACCESS supported now */
typedef int (*slapi_acl_callback_t)(Slapi_PBlock *pb,
Slapi_Entry *e,
const char *attr,
struct berval *berval,
int access,
void *state);
/* object extensions */
typedef void *(*slapi_extension_constructor_fnptr)(void *object, void *parent);
typedef void (*slapi_extension_destructor_fnptr)(void *extension,
void *object, void *parent);
int slapi_register_object_extension( const char *pluginname,
const char *objectname, slapi_extension_constructor_fnptr constructor,
slapi_extension_destructor_fnptr destructor, int *objecttype,
int *extensionhandle);
#define SLAPI_EXT_CONNECTION "Connection"
#define SLAPI_EXT_OPERATION "Operation"
#define SLAPI_EXT_ENTRY "Entry"
#define SLAPI_EXT_MTNODE "Mapping Tree Node"
void *slapi_get_object_extension(int objecttype, void *object,
int extensionhandle);
void slapi_set_object_extension(int objecttype, void *object,
int extensionhandle, void *extension);
int slapi_x_backend_get_flags( const Slapi_Backend *be, unsigned long *flags );
/* parameters currently supported */
/*
* Attribute flags returned by slapi_attr_get_flags()
*/
#define SLAPI_ATTR_FLAG_SINGLE 0x0001
#define SLAPI_ATTR_FLAG_OPATTR 0x0002
#define SLAPI_ATTR_FLAG_READONLY 0x0004
#define SLAPI_ATTR_FLAG_STD_ATTR SLAPI_ATTR_FLAG_READONLY
#define SLAPI_ATTR_FLAG_OBSOLETE 0x0040
#define SLAPI_ATTR_FLAG_COLLECTIVE 0x0080
#define SLAPI_ATTR_FLAG_NOUSERMOD 0x0100
/*
* Backend flags returned by slapi_x_backend_get_flags()
*/
#define SLAPI_BACKEND_FLAG_NOLASTMOD 0x0001U
#define SLAPI_BACKEND_FLAG_NO_SCHEMA_CHECK 0x0002U
#define SLAPI_BACKEND_FLAG_GLUE_INSTANCE 0x0010U /* a glue backend */
#define SLAPI_BACKEND_FLAG_GLUE_SUBORDINATE 0x0020U /* child of a glue hierarchy */
#define SLAPI_BACKEND_FLAG_GLUE_LINKED 0x0040U /* child is connected to parent */
#define SLAPI_BACKEND_FLAG_OVERLAY 0x0080U /* this db struct is an overlay */
#define SLAPI_BACKEND_FLAG_GLOBAL_OVERLAY 0x0100U /* this db struct is a global overlay */
#define SLAPI_BACKEND_FLAG_SHADOW 0x8000U /* a shadow */
#define SLAPI_BACKEND_FLAG_SYNC_SHADOW 0x1000U /* a sync shadow */
#define SLAPI_BACKEND_FLAG_SLURP_SHADOW 0x2000U /* a slurp shadow */
/*
* ACL levels
*/
#define SLAPI_ACL_COMPARE 0x01
#define SLAPI_ACL_SEARCH 0x02
#define SLAPI_ACL_READ 0x04
#define SLAPI_ACL_WRITE 0x08
#define SLAPI_ACL_DELETE 0x10
#define SLAPI_ACL_ADD 0x20
#define SLAPI_ACL_SELF 0x40
#define SLAPI_ACL_PROXY 0x80
#define SLAPI_ACL_ALL 0x7f
/* plugin types supported */
#define SLAPI_PLUGIN_DATABASE 1
#define SLAPI_PLUGIN_EXTENDEDOP 2
#define SLAPI_PLUGIN_PREOPERATION 3
#define SLAPI_PLUGIN_POSTOPERATION 4
#define SLAPI_PLUGIN_MATCHINGRULE 5
#define SLAPI_PLUGIN_SYNTAX 6
#define SLAPI_PLUGIN_AUDIT 7
/* misc params */
#define SLAPI_BACKEND 130
#define SLAPI_CONNECTION 131
#define SLAPI_OPERATION 132
#define SLAPI_REQUESTOR_ISROOT 133
#define SLAPI_BE_MONITORDN 134
#define SLAPI_BE_TYPE 135
#define SLAPI_BE_READONLY 136
#define SLAPI_BE_LASTMOD 137
#define SLAPI_CONN_ID 139
/* operation params */
#define SLAPI_OPINITIATED_TIME 140
#define SLAPI_REQUESTOR_DN 141
#define SLAPI_IS_REPLICATED_OPERATION 142
#define SLAPI_REQUESTOR_ISUPDATEDN SLAPI_IS_REPLICATED_OPERATION
/* connection structure params*/
#define SLAPI_CONN_DN 143
#define SLAPI_CONN_AUTHTYPE 144
#define SLAPI_CONN_CLIENTIP 145
#define SLAPI_CONN_SERVERIP 146
/* OpenLDAP extensions */
#define SLAPI_X_CONN_CLIENTPATH 1300
#define SLAPI_X_CONN_SERVERPATH 1301
#define SLAPI_X_CONN_IS_UDP 1302
#define SLAPI_X_CONN_SSF 1303
#define SLAPI_X_CONN_SASL_CONTEXT 1304
#define SLAPI_X_OPERATION_DELETE_GLUE_PARENT 1305
#define SLAPI_X_RELAX 1306
#define SLAPI_X_MANAGEDIT SLAPI_X_RELAX
#define SLAPI_X_OPERATION_NO_SCHEMA_CHECK 1307
#define SLAPI_X_ADD_STRUCTURAL_CLASS 1308
#define SLAPI_X_OPERATION_NO_SUBORDINATE_GLUE 1309
/* Authentication types */
#define SLAPD_AUTH_NONE "none"
#define SLAPD_AUTH_SIMPLE "simple"
#define SLAPD_AUTH_SSL "SSL"
#define SLAPD_AUTH_SASL "SASL "
/* plugin configuration parmams */
#define SLAPI_PLUGIN 3
#define SLAPI_PLUGIN_PRIVATE 4
#define SLAPI_PLUGIN_TYPE 5
#define SLAPI_PLUGIN_ARGV 6
#define SLAPI_PLUGIN_ARGC 7
#define SLAPI_PLUGIN_VERSION 8
#define SLAPI_PLUGIN_OPRETURN 9
#define SLAPI_PLUGIN_OBJECT 10
#define SLAPI_PLUGIN_DESTROY_FN 11
#define SLAPI_PLUGIN_DESCRIPTION 12
#define SLAPI_PLUGIN_IDENTITY 13
/* internal operations params */
#define SLAPI_PLUGIN_INTOP_RESULT 15
#define SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES 16
#define SLAPI_PLUGIN_INTOP_SEARCH_REFERRALS 17
/* transaction arguments */
#define SLAPI_PARENT_TXN 190
#define SLAPI_TXN 191
/* function pointer params for backends */
#define SLAPI_PLUGIN_DB_BIND_FN 200
#define SLAPI_PLUGIN_DB_UNBIND_FN 201
#define SLAPI_PLUGIN_DB_SEARCH_FN 202
#define SLAPI_PLUGIN_DB_COMPARE_FN 203
#define SLAPI_PLUGIN_DB_MODIFY_FN 204
#define SLAPI_PLUGIN_DB_MODRDN_FN 205
#define SLAPI_PLUGIN_DB_ADD_FN 206
#define SLAPI_PLUGIN_DB_DELETE_FN 207
#define SLAPI_PLUGIN_DB_ABANDON_FN 208
#define SLAPI_PLUGIN_DB_CONFIG_FN 209
#define SLAPI_PLUGIN_CLOSE_FN 210
#define SLAPI_PLUGIN_DB_FLUSH_FN 211
#define SLAPI_PLUGIN_START_FN 212
#define SLAPI_PLUGIN_DB_SEQ_FN 213
#define SLAPI_PLUGIN_DB_ENTRY_FN 214
#define SLAPI_PLUGIN_DB_REFERRAL_FN 215
#define SLAPI_PLUGIN_DB_RESULT_FN 216
#define SLAPI_PLUGIN_DB_LDIF2DB_FN 217
#define SLAPI_PLUGIN_DB_DB2LDIF_FN 218
#define SLAPI_PLUGIN_DB_BEGIN_FN 219
#define SLAPI_PLUGIN_DB_COMMIT_FN 220
#define SLAPI_PLUGIN_DB_ABORT_FN 221
#define SLAPI_PLUGIN_DB_ARCHIVE2DB_FN 222
#define SLAPI_PLUGIN_DB_DB2ARCHIVE_FN 223
#define SLAPI_PLUGIN_DB_NEXT_SEARCH_ENTRY_FN 224
#define SLAPI_PLUGIN_DB_FREE_RESULT_SET_FN 225
#define SLAPI_PLUGIN_DB_SIZE_FN 226
#define SLAPI_PLUGIN_DB_TEST_FN 227
/* functions pointers for LDAP V3 extended ops */
#define SLAPI_PLUGIN_EXT_OP_FN 300
#define SLAPI_PLUGIN_EXT_OP_OIDLIST 301
/* preoperation */
#define SLAPI_PLUGIN_PRE_BIND_FN 401
#define SLAPI_PLUGIN_PRE_UNBIND_FN 402
#define SLAPI_PLUGIN_PRE_SEARCH_FN 403
#define SLAPI_PLUGIN_PRE_COMPARE_FN 404
#define SLAPI_PLUGIN_PRE_MODIFY_FN 405
#define SLAPI_PLUGIN_PRE_MODRDN_FN 406
#define SLAPI_PLUGIN_PRE_ADD_FN 407
#define SLAPI_PLUGIN_PRE_DELETE_FN 408
#define SLAPI_PLUGIN_PRE_ABANDON_FN 409
#define SLAPI_PLUGIN_PRE_ENTRY_FN 410
#define SLAPI_PLUGIN_PRE_REFERRAL_FN 411
#define SLAPI_PLUGIN_PRE_RESULT_FN 412
/* internal preoperation */
#define SLAPI_PLUGIN_INTERNAL_PRE_ADD_FN 420
#define SLAPI_PLUGIN_INTERNAL_PRE_MODIFY_FN 421
#define SLAPI_PLUGIN_INTERNAL_PRE_MODRDN_FN 422
#define SLAPI_PLUGIN_INTERNAL_PRE_DELETE_FN 423
/* backend preoperation */
#define SLAPI_PLUGIN_BE_PRE_ADD_FN 450
#define SLAPI_PLUGIN_BE_PRE_MODIFY_FN 451
#define SLAPI_PLUGIN_BE_PRE_MODRDN_FN 452
#define SLAPI_PLUGIN_BE_PRE_DELETE_FN 453
/* postoperation */
#define SLAPI_PLUGIN_POST_BIND_FN 501
#define SLAPI_PLUGIN_POST_UNBIND_FN 502
#define SLAPI_PLUGIN_POST_SEARCH_FN 503
#define SLAPI_PLUGIN_POST_COMPARE_FN 504
#define SLAPI_PLUGIN_POST_MODIFY_FN 505
#define SLAPI_PLUGIN_POST_MODRDN_FN 506
#define SLAPI_PLUGIN_POST_ADD_FN 507
#define SLAPI_PLUGIN_POST_DELETE_FN 508
#define SLAPI_PLUGIN_POST_ABANDON_FN 509
#define SLAPI_PLUGIN_POST_ENTRY_FN 510
#define SLAPI_PLUGIN_POST_REFERRAL_FN 511
#define SLAPI_PLUGIN_POST_RESULT_FN 512
/* internal postoperation */
#define SLAPI_PLUGIN_INTERNAL_POST_ADD_FN 520
#define SLAPI_PLUGIN_INTERNAL_POST_MODIFY_FN 521
#define SLAPI_PLUGIN_INTERNAL_POST_MODRDN_FN 522
#define SLAPI_PLUGIN_INTERNAL_POST_DELETE_FN 523
/* backend postoperation */
#define SLAPI_PLUGIN_BE_POST_ADD_FN 550
#define SLAPI_PLUGIN_BE_POST_MODIFY_FN 551
#define SLAPI_PLUGIN_BE_POST_MODRDN_FN 552
#define SLAPI_PLUGIN_BE_POST_DELETE_FN 553
#define SLAPI_OPERATION_TYPE 590
#define SLAPI_OPERATION_MSGID 591
#define SLAPI_PLUGIN_MR_FILTER_CREATE_FN 600
#define SLAPI_PLUGIN_MR_INDEXER_CREATE_FN 601
#define SLAPI_PLUGIN_MR_FILTER_MATCH_FN 602
#define SLAPI_PLUGIN_MR_FILTER_INDEX_FN 603
#define SLAPI_PLUGIN_MR_FILTER_RESET_FN 604
#define SLAPI_PLUGIN_MR_INDEX_FN 605
#define SLAPI_PLUGIN_MR_OID 610
#define SLAPI_PLUGIN_MR_TYPE 611
#define SLAPI_PLUGIN_MR_VALUE 612
#define SLAPI_PLUGIN_MR_VALUES 613
#define SLAPI_PLUGIN_MR_KEYS 614
#define SLAPI_PLUGIN_MR_FILTER_REUSABLE 615
#define SLAPI_PLUGIN_MR_QUERY_OPERATOR 616
#define SLAPI_PLUGIN_MR_USAGE 617
#define SLAPI_MATCHINGRULE_NAME 1
#define SLAPI_MATCHINGRULE_OID 2
#define SLAPI_MATCHINGRULE_DESC 3
#define SLAPI_MATCHINGRULE_SYNTAX 4
#define SLAPI_MATCHINGRULE_OBSOLETE 5
#define SLAPI_OP_LESS 1
#define SLAPI_OP_LESS_OR_EQUAL 2
#define SLAPI_OP_EQUAL 3
#define SLAPI_OP_GREATER_OR_EQUAL 4
#define SLAPI_OP_GREATER 5
#define SLAPI_OP_SUBSTRING 6
#define SLAPI_PLUGIN_MR_USAGE_INDEX 0
#define SLAPI_PLUGIN_MR_USAGE_SORT 1
#define SLAPI_PLUGIN_SYNTAX_FILTER_AVA 700
#define SLAPI_PLUGIN_SYNTAX_FILTER_SUB 701
#define SLAPI_PLUGIN_SYNTAX_VALUES2KEYS 702
#define SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_AVA 703
#define SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_SUB 704
#define SLAPI_PLUGIN_SYNTAX_NAMES 705
#define SLAPI_PLUGIN_SYNTAX_OID 706
#define SLAPI_PLUGIN_SYNTAX_FLAGS 707
#define SLAPI_PLUGIN_SYNTAX_COMPARE 708
#define SLAPI_PLUGIN_SYNTAX_FLAG_ORKEYS 1
#define SLAPI_PLUGIN_SYNTAX_FLAG_ORDERING 2
#define SLAPI_PLUGIN_ACL_INIT 730
#define SLAPI_PLUGIN_ACL_SYNTAX_CHECK 731
#define SLAPI_PLUGIN_ACL_ALLOW_ACCESS 732
#define SLAPI_PLUGIN_ACL_MODS_ALLOWED 733
#define SLAPI_PLUGIN_ACL_MODS_UPDATE 734
#define SLAPI_OPERATION_AUTHTYPE 741
#define SLAPI_OPERATION_ID 742
#define SLAPI_CONN_CERT 743
#define SLAPI_CONN_AUTHMETHOD 746
#define SLAPI_IS_INTERNAL_OPERATION 748
#define SLAPI_RESULT_CODE 881
#define SLAPI_RESULT_TEXT 882
#define SLAPI_RESULT_MATCHED 883
/* managedsait control */
#define SLAPI_MANAGEDSAIT 1000
/* audit plugin defines */
#define SLAPI_PLUGIN_AUDIT_DATA 1100
#define SLAPI_PLUGIN_AUDIT_FN 1101
/* backend_group extension */
#define SLAPI_X_PLUGIN_PRE_GROUP_FN 1202
#define SLAPI_X_PLUGIN_POST_GROUP_FN 1203
#define SLAPI_X_GROUP_ENTRY 1250 /* group entry */
#define SLAPI_X_GROUP_ATTRIBUTE 1251 /* member attribute */
#define SLAPI_X_GROUP_OPERATION_DN 1252 /* asserted value */
#define SLAPI_X_GROUP_TARGET_ENTRY 1253 /* target entry */
/* internal preoperation extensions */
#define SLAPI_PLUGIN_INTERNAL_PRE_BIND_FN 1260
#define SLAPI_PLUGIN_INTERNAL_PRE_UNBIND_FN 1261
#define SLAPI_PLUGIN_INTERNAL_PRE_SEARCH_FN 1262
#define SLAPI_PLUGIN_INTERNAL_PRE_COMPARE_FN 1263
#define SLAPI_PLUGIN_INTERNAL_PRE_ABANDON_FN 1264
/* internal postoperation extensions */
#define SLAPI_PLUGIN_INTERNAL_POST_BIND_FN 1270
#define SLAPI_PLUGIN_INTERNAL_POST_UNBIND_FN 1271
#define SLAPI_PLUGIN_INTERNAL_POST_SEARCH_FN 1272
#define SLAPI_PLUGIN_INTERNAL_POST_COMPARE_FN 1273
#define SLAPI_PLUGIN_INTERNAL_POST_ABANDON_FN 1274
/* config stuff */
#define SLAPI_CONFIG_FILENAME 40
#define SLAPI_CONFIG_LINENO 41
#define SLAPI_CONFIG_ARGC 42
#define SLAPI_CONFIG_ARGV 43
/* operational params */
#define SLAPI_TARGET_ADDRESS 48
#define SLAPI_TARGET_UNIQUEID 49
#define SLAPI_TARGET_DN 50
/* server LDAPv3 controls */
#define SLAPI_REQCONTROLS 51
#define SLAPI_RESCONTROLS 55
#define SLAPI_ADD_RESCONTROL 56
#define SLAPI_CONTROLS_ARG 58
/* add params */
#define SLAPI_ADD_TARGET SLAPI_TARGET_DN
#define SLAPI_ADD_ENTRY 60
#define SLAPI_ADD_EXISTING_DN_ENTRY 61
#define SLAPI_ADD_PARENT_ENTRY 62
#define SLAPI_ADD_PARENT_UNIQUEID 63
#define SLAPI_ADD_EXISTING_UNIQUEID_ENTRY 64
/* bind params */
#define SLAPI_BIND_TARGET SLAPI_TARGET_DN
#define SLAPI_BIND_METHOD 70
#define SLAPI_BIND_CREDENTIALS 71
#define SLAPI_BIND_SASLMECHANISM 72
#define SLAPI_BIND_RET_SASLCREDS 73
/* compare params */
#define SLAPI_COMPARE_TARGET SLAPI_TARGET_DN
#define SLAPI_COMPARE_TYPE 80
#define SLAPI_COMPARE_VALUE 81
/* delete params */
#define SLAPI_DELETE_TARGET SLAPI_TARGET_DN
#define SLAPI_DELETE_EXISTING_ENTRY SLAPI_ADD_EXISTING_DN_ENTRY
/* modify params */
#define SLAPI_MODIFY_TARGET SLAPI_TARGET_DN
#define SLAPI_MODIFY_MODS 90
#define SLAPI_MODIFY_EXISTING_ENTRY SLAPI_ADD_EXISTING_DN_ENTRY
/* modrdn params */
#define SLAPI_MODRDN_TARGET SLAPI_TARGET_DN
#define SLAPI_MODRDN_NEWRDN 100
#define SLAPI_MODRDN_DELOLDRDN 101
#define SLAPI_MODRDN_NEWSUPERIOR 102 /* v3 only */
#define SLAPI_MODRDN_EXISTING_ENTRY SLAPI_ADD_EXISTING_DN_ENTRY
#define SLAPI_MODRDN_PARENT_ENTRY 104
#define SLAPI_MODRDN_NEWPARENT_ENTRY 105
#define SLAPI_MODRDN_TARGET_ENTRY 106
#define SLAPI_MODRDN_NEWSUPERIOR_ADDRESS 107
/* search params */
#define SLAPI_SEARCH_TARGET SLAPI_TARGET_DN
#define SLAPI_SEARCH_SCOPE 110
#define SLAPI_SEARCH_DEREF 111
#define SLAPI_SEARCH_SIZELIMIT 112
#define SLAPI_SEARCH_TIMELIMIT 113
#define SLAPI_SEARCH_FILTER 114
#define SLAPI_SEARCH_STRFILTER 115
#define SLAPI_SEARCH_ATTRS 116
#define SLAPI_SEARCH_ATTRSONLY 117
/* abandon params */
#define SLAPI_ABANDON_MSGID 120
/* extended operation params */
#define SLAPI_EXT_OP_REQ_OID 160
#define SLAPI_EXT_OP_REQ_VALUE 161
/* extended operation return codes */
#define SLAPI_EXT_OP_RET_OID 162
#define SLAPI_EXT_OP_RET_VALUE 163
#define SLAPI_PLUGIN_EXTENDED_SENT_RESULT -1
#define SLAPI_FAIL_DISKFULL -2
#define SLAPI_FAIL_GENERAL -1
#define SLAPI_PLUGIN_EXTENDED_NOT_HANDLED -2
#define SLAPI_BIND_SUCCESS 0
#define SLAPI_BIND_FAIL 2
#define SLAPI_BIND_ANONYMOUS 3
/* Search result params */
#define SLAPI_SEARCH_RESULT_SET 193
#define SLAPI_SEARCH_RESULT_ENTRY 194
#define SLAPI_NENTRIES 195
#define SLAPI_SEARCH_REFERRALS 196
/* filter types */
#ifndef LDAP_FILTER_AND
#define LDAP_FILTER_AND 0xa0L
#endif
#ifndef LDAP_FILTER_OR
#define LDAP_FILTER_OR 0xa1L
#endif
#ifndef LDAP_FILTER_NOT
#define LDAP_FILTER_NOT 0xa2L
#endif
#ifndef LDAP_FILTER_EQUALITY
#define LDAP_FILTER_EQUALITY 0xa3L
#endif
#ifndef LDAP_FILTER_SUBSTRINGS
#define LDAP_FILTER_SUBSTRINGS 0xa4L
#endif
#ifndef LDAP_FILTER_GE
#define LDAP_FILTER_GE 0xa5L
#endif
#ifndef LDAP_FILTER_LE
#define LDAP_FILTER_LE 0xa6L
#endif
#ifndef LDAP_FILTER_PRESENT
#define LDAP_FILTER_PRESENT 0x87L
#endif
#ifndef LDAP_FILTER_APPROX
#define LDAP_FILTER_APPROX 0xa8L
#endif
#ifndef LDAP_FILTER_EXT_MATCH
#define LDAP_FILTER_EXT_MATCH 0xa9L
#endif
int slapi_log_error( int severity, char *subsystem, char *fmt, ... );
#define SLAPI_LOG_FATAL 0
#define SLAPI_LOG_TRACE 1
#define SLAPI_LOG_PACKETS 2
#define SLAPI_LOG_ARGS 3
#define SLAPI_LOG_CONNS 4
#define SLAPI_LOG_BER 5
#define SLAPI_LOG_FILTER 6
#define SLAPI_LOG_CONFIG 7
#define SLAPI_LOG_ACL 8
#define SLAPI_LOG_SHELL 9
#define SLAPI_LOG_PARSE 10
#define SLAPI_LOG_HOUSE 11
#define SLAPI_LOG_REPL 12
#define SLAPI_LOG_CACHE 13
#define SLAPI_LOG_PLUGIN 14
#define SLAPI_LOG_TIMING 15
#define SLAPI_PLUGIN_DESCRIPTION 12
typedef struct slapi_plugindesc {
char *spd_id;
char *spd_vendor;
char *spd_version;
char *spd_description;
} Slapi_PluginDesc;
#define SLAPI_PLUGIN_VERSION_01 "01"
#define SLAPI_PLUGIN_VERSION_02 "02"
#define SLAPI_PLUGIN_VERSION_03 "03"
#define SLAPI_PLUGIN_CURRENT_VERSION SLAPI_PLUGIN_VERSION_03
#endif /* _SLAPI_PLUGIN_H */
openldap-2.5.16+dfsg/include/ldap_rq.h 0000644 0001750 0001750 00000003655 14461774414 017133 0 ustar sergio sergio /* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
#ifndef LDAP_RQ_H
#define LDAP_RQ_H 1
#include
LDAP_BEGIN_DECL
typedef struct re_s {
struct timeval next_sched;
struct timeval interval;
LDAP_STAILQ_ENTRY(re_s) tnext; /* it includes running */
LDAP_STAILQ_ENTRY(re_s) rnext;
ldap_pvt_thread_start_t *routine;
void *arg;
char *tname;
char *tspec;
void *pool_cookie;
} re_t;
typedef struct runqueue_s {
LDAP_STAILQ_HEAD(l, re_s) task_list;
LDAP_STAILQ_HEAD(rl, re_s) run_list;
ldap_pvt_thread_mutex_t rq_mutex;
} runqueue_t;
LDAP_F( struct re_s* )
ldap_pvt_runqueue_insert(
struct runqueue_s* rq,
time_t interval,
ldap_pvt_thread_start_t* routine,
void *arg,
char *tname,
char *tspec
);
LDAP_F( struct re_s* )
ldap_pvt_runqueue_find(
struct runqueue_s* rq,
ldap_pvt_thread_start_t* routine,
void *arg
);
LDAP_F( void )
ldap_pvt_runqueue_remove(
struct runqueue_s* rq,
struct re_s* entry
);
LDAP_F( struct re_s* )
ldap_pvt_runqueue_next_sched(
struct runqueue_s* rq,
struct timeval* next_run
);
LDAP_F( void )
ldap_pvt_runqueue_runtask(
struct runqueue_s* rq,
struct re_s* entry
);
LDAP_F( void )
ldap_pvt_runqueue_stoptask(
struct runqueue_s* rq,
struct re_s* entry
);
LDAP_F( int )
ldap_pvt_runqueue_isrunning(
struct runqueue_s* rq,
struct re_s* entry
);
LDAP_F( void )
ldap_pvt_runqueue_resched(
struct runqueue_s* rq,
struct re_s* entry,
int defer
);
LDAP_F( int )
ldap_pvt_runqueue_persistent_backload(
struct runqueue_s* rq
);
LDAP_END_DECL
#endif
openldap-2.5.16+dfsg/include/ldap_defaults.h 0000644 0001750 0001750 00000004627 14461774414 020320 0 ustar sergio sergio /* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
/* Portions Copyright (c) 1994 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.
*/
/*
* This file controls defaults for OpenLDAP package.
* You probably do not need to edit the defaults provided by this file.
*/
#ifndef _LDAP_DEFAULTS_H
#define _LDAP_DEFAULTS_H
#include
#define LDAP_CONF_FILE LDAP_SYSCONFDIR LDAP_DIRSEP "ldap.conf"
#define LDAP_USERRC_FILE "ldaprc"
#define LDAP_ENV_PREFIX "LDAP"
/* default ldapi:// socket */
#define LDAPI_SOCK LDAP_RUNDIR LDAP_DIRSEP "run" LDAP_DIRSEP "ldapi"
/*
* SLAPD DEFINITIONS
*/
/* location of the default slapd config file */
#define SLAPD_DEFAULT_CONFIGFILE LDAP_SYSCONFDIR LDAP_DIRSEP "slapd.conf"
#define SLAPD_DEFAULT_CONFIGDIR LDAP_SYSCONFDIR LDAP_DIRSEP "slapd.d"
#define SLAPD_DEFAULT_DB_DIR LDAP_RUNDIR LDAP_DIRSEP "openldap-data"
#define SLAPD_DEFAULT_DB_MODE 0600
#define SLAPD_DEFAULT_UCDATA LDAP_DATADIR LDAP_DIRSEP "ucdata"
/* default max deref depth for aliases */
#define SLAPD_DEFAULT_MAXDEREFDEPTH 15
/* default sizelimit on number of entries from a search */
#define SLAPD_DEFAULT_SIZELIMIT 500
/* default timelimit to spend on a search */
#define SLAPD_DEFAULT_TIMELIMIT 3600
/* the following DNs must be normalized! */
/* dn of the default subschema subentry */
#define SLAPD_SCHEMA_DN "cn=Subschema"
/* dn of the default "monitor" subentry */
#define SLAPD_MONITOR_DN "cn=Monitor"
/*
* LLOADD DEFINITIONS
*/
#define LLOADD_DEFAULT_CONFIGFILE LDAP_SYSCONFDIR LDAP_DIRSEP "lloadd.conf"
#endif /* _LDAP_CONFIG_H */
openldap-2.5.16+dfsg/include/lutil.h 0000644 0001750 0001750 00000022416 14461774414 016636 0 ustar sergio sergio /* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
#ifndef _LUTIL_H
#define _LUTIL_H 1
#include
#include
#include
#ifdef HAVE_TCPD
# include
# define LUTIL_STRING_UNKNOWN STRING_UNKNOWN
#else /* ! TCP Wrappers */
# define LUTIL_STRING_UNKNOWN "unknown"
#endif /* ! TCP Wrappers */
/*
* Include file for LDAP utility routine
*/
LDAP_BEGIN_DECL
/* n octets encode into ceiling(n/3) * 4 bytes */
/* Avoid floating point math through extra padding */
#define LUTIL_BASE64_ENCODE_LEN(n) (((n)+2)/3 * 4)
#define LUTIL_BASE64_DECODE_LEN(n) ((n)/4*3)
/* ISC Base64 Routines */
/* base64.c */
LDAP_LUTIL_F( int )
lutil_b64_ntop LDAP_P((
unsigned char const *,
size_t,
char *,
size_t));
LDAP_LUTIL_F( int )
lutil_b64_pton LDAP_P((
char const *,
unsigned char *,
size_t));
/* detach.c */
LDAP_LUTIL_F( int )
lutil_detach LDAP_P((
int debug,
int do_close));
/* entropy.c */
LDAP_LUTIL_F( int )
lutil_entropy LDAP_P((
unsigned char *buf,
ber_len_t nbytes ));
/* passfile.c */
struct berval; /* avoid pulling in lber.h */
LDAP_LUTIL_F( int )
lutil_get_filed_password LDAP_P((
const char *filename,
struct berval * ));
/* passwd.c */
struct lutil_pw_scheme;
#define LUTIL_PASSWD_OK (0)
#define LUTIL_PASSWD_ERR (-1)
typedef int (LUTIL_PASSWD_CHK_FUNC)(
const struct berval *scheme,
const struct berval *passwd,
const struct berval *cred,
const char **text );
typedef int (LUTIL_PASSWD_HASH_FUNC) (
const struct berval *scheme,
const struct berval *passwd,
struct berval *hash,
const char **text );
LDAP_LUTIL_F( int )
lutil_passwd_add LDAP_P((
struct berval *scheme,
LUTIL_PASSWD_CHK_FUNC *chk_fn,
LUTIL_PASSWD_HASH_FUNC *hash_fn ));
LDAP_LUTIL_F( void )
lutil_passwd_init LDAP_P(( void ));
LDAP_LUTIL_F( void )
lutil_passwd_destroy LDAP_P(( void ));
LDAP_LUTIL_F( int )
lutil_authpasswd LDAP_P((
const struct berval *passwd, /* stored password */
const struct berval *cred, /* user supplied value */
const char **methods ));
LDAP_LUTIL_F( int )
lutil_authpasswd_hash LDAP_P((
const struct berval *cred,
struct berval **passwd, /* password to store */
struct berval **salt, /* salt to store */
const char *method ));
#ifdef SLAPD_CRYPT
typedef int (lutil_cryptfunc) LDAP_P((
const char *key,
const char *salt,
char **hash ));
LDAP_LUTIL_V (lutil_cryptfunc *) lutil_cryptptr;
#endif
LDAP_LUTIL_F( int )
lutil_passwd LDAP_P((
const struct berval *passwd, /* stored password */
const struct berval *cred, /* user supplied value */
const char **methods,
const char **text )); /* error message */
LDAP_LUTIL_F( int )
lutil_passwd_generate LDAP_P(( struct berval *pw, ber_len_t ));
LDAP_LUTIL_F( int )
lutil_passwd_hash LDAP_P((
const struct berval *passwd,
const char *method,
struct berval *hash,
const char **text ));
LDAP_LUTIL_F( int )
lutil_passwd_scheme LDAP_P((
const char *scheme ));
LDAP_LUTIL_F( int )
lutil_salt_format LDAP_P((
const char *format ));
LDAP_LUTIL_F( int )
lutil_passwd_string64 LDAP_P((
const struct berval *sc,
const struct berval *hash,
struct berval *b64,
const struct berval *salt ));
/* utils.c */
LDAP_LUTIL_F( char* )
lutil_progname LDAP_P((
const char* name,
int argc,
char *argv[] ));
typedef struct lutil_tm {
int tm_sec; /* seconds 0-60 (1 leap second) */
int tm_min; /* minutes 0-59 */
int tm_hour; /* hours 0-23 */
int tm_mday; /* day 1-31 */
int tm_mon; /* month 0-11 */
int tm_year; /* year - 1900 */
int tm_nsec; /* nanoseconds */
int tm_usub; /* submicro */
} lutil_tm;
typedef struct lutil_timet {
unsigned int tt_sec; /* seconds since epoch, 0000 or 1970 */
int tt_gsec; /* seconds since epoch, high 7 bits, maybe sign-flipped */
/* sign flipped to sort properly as unsigned ints */
unsigned int tt_nsec; /* nanoseconds */
} lutil_timet;
/* Parse a timestamp string into a structure */
LDAP_LUTIL_F( int )
lutil_parsetime LDAP_P((
char *atm, struct lutil_tm * ));
/* Convert structured time to time in seconds since 1970 (Unix epoch) */
LDAP_LUTIL_F( int )
lutil_tm2time LDAP_P((
struct lutil_tm *, struct lutil_timet * ));
/* Convert structured time to time in seconds since 0000 (Proleptic Gregorian) */
LDAP_LUTIL_F( int )
lutil_tm2gtime LDAP_P((
struct lutil_tm *, struct lutil_timet * ));
#ifdef _WIN32
LDAP_LUTIL_F( void )
lutil_slashpath LDAP_P(( char* path ));
#define LUTIL_SLASHPATH(p) lutil_slashpath(p)
#else
#define LUTIL_SLASHPATH(p)
#endif
LDAP_LUTIL_F( char* )
lutil_strcopy LDAP_P(( char *dst, const char *src ));
LDAP_LUTIL_F( char* )
lutil_strncopy LDAP_P(( char *dst, const char *src, size_t n ));
LDAP_LUTIL_F( char* )
lutil_memcopy LDAP_P(( char *dst, const char *src, size_t n ));
#define lutil_strbvcopy(a, bv) lutil_memcopy((a),(bv)->bv_val,(bv)->bv_len)
struct tm;
/* use this macro to statically allocate buffer for lutil_gentime */
#define LDAP_LUTIL_GENTIME_BUFSIZE 22
#define lutil_gentime(s,m,t) lutil_localtime((s),(m),(t),0)
LDAP_LUTIL_F( size_t )
lutil_localtime LDAP_P(( char *s, size_t smax, const struct tm *tm,
long delta ));
#ifndef HAVE_MKSTEMP
LDAP_LUTIL_F( int )
mkstemp LDAP_P (( char * template ));
#endif
/* sockpair.c */
LDAP_LUTIL_F( int )
lutil_pair( ber_socket_t sd[2] );
/* uuid.c */
/* use this macro to allocate buffer for lutil_uuidstr */
#define LDAP_LUTIL_UUIDSTR_BUFSIZE 40
LDAP_LUTIL_F( size_t )
lutil_uuidstr( char *buf, size_t len );
LDAP_LUTIL_F( int )
lutil_uuidstr_from_normalized(
char *uuid,
size_t uuidlen,
char *buf,
size_t buflen );
/*
* Sometimes not all declarations in a header file are needed.
* An indicator to this is whether or not the symbol's type has
* been defined. Thus, we don't need to include a symbol if
* its type has not been defined through another header file.
*/
#ifdef HAVE_NT_SERVICE_MANAGER
LDAP_LUTIL_V (int) is_NT_Service;
#ifdef _LDAP_PVT_THREAD_H
LDAP_LUTIL_V (ldap_pvt_thread_cond_t) started_event;
#endif /* _LDAP_PVT_THREAD_H */
/* macros are different between Windows and Mingw */
#if defined(_WINSVC_H) || defined(_WINSVC_)
LDAP_LUTIL_V (SERVICE_STATUS) lutil_ServiceStatus;
LDAP_LUTIL_V (SERVICE_STATUS_HANDLE) hlutil_ServiceStatus;
#endif /* _WINSVC_H */
LDAP_LUTIL_F (void)
lutil_CommenceStartupProcessing( char *serverName, void (*stopper)(int)) ;
LDAP_LUTIL_F (void)
lutil_ReportShutdownComplete( void );
LDAP_LUTIL_F (void *)
lutil_getRegParam( char *svc, char *value );
LDAP_LUTIL_F (int)
lutil_srv_install( char* service, char * displayName, char* filename,
int auto_start );
LDAP_LUTIL_F (int)
lutil_srv_remove ( char* service, char* filename );
#endif /* HAVE_NT_SERVICE_MANAGER */
#ifdef HAVE_NT_EVENT_LOG
LDAP_LUTIL_F (void)
lutil_LogStartedEvent( char *svc, int slap_debug, char *configfile, char *urls );
LDAP_LUTIL_F (void)
lutil_LogStoppedEvent( char *svc );
#endif
#ifdef HAVE_EBCDIC
/* Generally this has only been used to put '\n' to stdout. We need to
* make sure it is output in EBCDIC.
*/
#undef putchar
#undef putc
#define putchar(c) putc((c), stdout)
#define putc(c,fp) do { char x=(c); __atoe_l(&x,1); putc(x,fp); } while(0)
#endif
LDAP_LUTIL_F (int)
lutil_atoix( int *v, const char *s, int x );
LDAP_LUTIL_F (int)
lutil_atoux( unsigned *v, const char *s, int x );
LDAP_LUTIL_F (int)
lutil_atolx( long *v, const char *s, int x );
LDAP_LUTIL_F (int)
lutil_atoulx( unsigned long *v, const char *s, int x );
#define lutil_atoi(v, s) lutil_atoix((v), (s), 10)
#define lutil_atou(v, s) lutil_atoux((v), (s), 10)
#define lutil_atol(v, s) lutil_atolx((v), (s), 10)
#define lutil_atoul(v, s) lutil_atoulx((v), (s), 10)
#ifdef HAVE_LONG_LONG
#if defined(HAVE_STRTOLL) || defined(HAVE_STRTOQ)
LDAP_LUTIL_F (int)
lutil_atollx( long long *v, const char *s, int x );
#define lutil_atoll(v, s) lutil_atollx((v), (s), 10)
#endif /* HAVE_STRTOLL || HAVE_STRTOQ */
#if defined(HAVE_STRTOULL) || defined(HAVE_STRTOUQ)
LDAP_LUTIL_F (int)
lutil_atoullx( unsigned long long *v, const char *s, int x );
#define lutil_atoull(v, s) lutil_atoullx((v), (s), 10)
#endif /* HAVE_STRTOULL || HAVE_STRTOUQ */
#endif /* HAVE_LONG_LONG */
LDAP_LUTIL_F (int)
lutil_str2bin( struct berval *in, struct berval *out, void *ctx );
/* Parse and unparse time intervals */
LDAP_LUTIL_F (int)
lutil_parse_time( const char *in, unsigned long *tp );
LDAP_LUTIL_F (int)
lutil_unparse_time( char *buf, size_t buflen, unsigned long t );
#ifdef timerdiv
#define lutil_timerdiv timerdiv
#else /* ! timerdiv */
/* works inplace (x == t) */
#define lutil_timerdiv(t,d,x) \
do { \
time_t s = (t)->tv_sec; \
assert( d > 0 ); \
(x)->tv_sec = s / d; \
(x)->tv_usec = ( (t)->tv_usec + 1000000 * ( s % d ) ) / d; \
} while ( 0 )
#endif /* ! timerdiv */
#ifdef timermul
#define lutil_timermul timermul
#else /* ! timermul */
/* works inplace (x == t) */
#define lutil_timermul(t,m,x) \
do { \
time_t u = (t)->tv_usec * m; \
assert( m > 0 ); \
(x)->tv_sec = (t)->tv_sec * m + u / 1000000; \
(x)->tv_usec = u % 1000000; \
} while ( 0 );
#endif /* ! timermul */
LDAP_END_DECL
#endif /* _LUTIL_H */
openldap-2.5.16+dfsg/include/portable.hin 0000644 0001750 0001750 00000071525 14461774414 017651 0 ustar sergio sergio /* include/portable.hin. Generated from configure.ac by autoheader. */
/* begin of portable.h.pre */
/* This work is part of OpenLDAP Software .
*
* Copyright 1998-2022 The OpenLDAP Foundation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* .
*/
#ifndef _LDAP_PORTABLE_H
#define _LDAP_PORTABLE_H
/* define this if needed to get reentrant functions */
#ifndef REENTRANT
#undef REENTRANT
#endif
#ifndef _REENTRANT
#undef _REENTRANT
#endif
/* define this if needed to get threadsafe functions */
#ifndef THREADSAFE
#undef THREADSAFE
#endif
#ifndef _THREADSAFE
#undef _THREADSAFE
#endif
#ifndef THREAD_SAFE
#undef THREAD_SAFE
#endif
#ifndef _THREAD_SAFE
#undef _THREAD_SAFE
#endif
#ifndef _SGI_MP_SOURCE
#undef _SGI_MP_SOURCE
#endif
/* end of portable.h.pre */
/* Define if building universal (internal helper macro) */
#undef AC_APPLE_UNIVERSAL_BUILD
/* define to use both and */
#undef BOTH_STRINGS_H
/* define if cross compiling */
#undef CROSS_COMPILING
/* set to the number of arguments ctime_r() expects */
#undef CTIME_R_NARGS
/* define if toupper() requires islower() */
#undef C_UPPER_LOWER
/* define if sys_errlist is not declared in stdio.h or errno.h */
#undef DECL_SYS_ERRLIST
/* define to enable slapi library */
#undef ENABLE_SLAPI
/* defined to be the EXE extension */
#undef EXEEXT
/* set to the number of arguments gethostbyaddr_r() expects */
#undef GETHOSTBYADDR_R_NARGS
/* set to the number of arguments gethostbyname_r() expects */
#undef GETHOSTBYNAME_R_NARGS
/* Define to 1 if `TIOCGWINSZ' requires . */
#undef GWINSZ_IN_SYS_IOCTL
/* define if you have AIX security lib */
#undef HAVE_AIX_SECURITY
/* Define to 1 if you have the header file. */
#undef HAVE_ARGON2_H
/* Define to 1 if you have the header file. */
#undef HAVE_ARPA_INET_H
/* Define to 1 if you have the header file. */
#undef HAVE_ARPA_NAMESER_H
/* Define to 1 if you have the header file. */
#undef HAVE_ASSERT_H
/* Define to 1 if you have the `bcopy' function. */
#undef HAVE_BCOPY
/* Define to 1 if you have the header file. */
#undef HAVE_BITS_TYPES_H
/* Define to 1 if you have the `chroot' function. */
#undef HAVE_CHROOT
/* Define to 1 if you have the `clock_gettime' function. */
#undef HAVE_CLOCK_GETTIME
/* Define to 1 if you have the `closesocket' function. */
#undef HAVE_CLOSESOCKET
/* Define to 1 if you have the header file. */
#undef HAVE_CONIO_H
/* define if crypt(3) is available */
#undef HAVE_CRYPT
/* Define to 1 if you have the header file. */
#undef HAVE_CRYPT_H
/* define if crypt_r() is also available */
#undef HAVE_CRYPT_R
/* Define to 1 if you have the `ctime_r' function. */
#undef HAVE_CTIME_R
/* define if you have Cyrus SASL */
#undef HAVE_CYRUS_SASL
/* define if your system supports /dev/poll */
#undef HAVE_DEVPOLL
/* Define to 1 if you have the header file. */
#undef HAVE_DIRECT_H
/* Define to 1 if you have the header file, and it defines `DIR'.
*/
#undef HAVE_DIRENT_H
/* Define to 1 if you have the header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
#undef HAVE_DOPRNT
/* define if system uses EBCDIC instead of ASCII */
#undef HAVE_EBCDIC
/* Define to 1 if you have the `endgrent' function. */
#undef HAVE_ENDGRENT
/* Define to 1 if you have the `endpwent' function. */
#undef HAVE_ENDPWENT
/* define if your system supports epoll */
#undef HAVE_EPOLL
/* Define to 1 if you have the header file. */
#undef HAVE_ERRNO_H
/* Define to 1 if you have the `fcntl' function. */
#undef HAVE_FCNTL
/* Define to 1 if you have the header file. */
#undef HAVE_FCNTL_H
/* define if you actually have FreeBSD fetch(3) */
#undef HAVE_FETCH
/* Define to 1 if you have the header file. */
#undef HAVE_FILIO_H
/* Define to 1 if you have the `flock' function. */
#undef HAVE_FLOCK
/* Define to 1 if you have the `fmemopen' function. */
#undef HAVE_FMEMOPEN
/* Define to 1 if you have the `fstat' function. */
#undef HAVE_FSTAT
/* Define to 1 if you have the `gai_strerror' function. */
#undef HAVE_GAI_STRERROR
/* Define to 1 if you have the `getaddrinfo' function. */
#undef HAVE_GETADDRINFO
/* Define to 1 if you have the `getdtablesize' function. */
#undef HAVE_GETDTABLESIZE
/* Define to 1 if you have the `geteuid' function. */
#undef HAVE_GETEUID
/* Define to 1 if you have the `getgrgid' function. */
#undef HAVE_GETGRGID
/* Define to 1 if you have the `gethostbyaddr_r' function. */
#undef HAVE_GETHOSTBYADDR_R
/* Define to 1 if you have the `gethostbyname_r' function. */
#undef HAVE_GETHOSTBYNAME_R
/* Define to 1 if you have the `gethostname' function. */
#undef HAVE_GETHOSTNAME
/* Define to 1 if you have the `getnameinfo' function. */
#undef HAVE_GETNAMEINFO
/* Define to 1 if you have the `getopt' function. */
#undef HAVE_GETOPT
/* Define to 1 if you have the header file. */
#undef HAVE_GETOPT_H
/* Define to 1 if you have the `getpassphrase' function. */
#undef HAVE_GETPASSPHRASE
/* Define to 1 if you have the `getpeereid' function. */
#undef HAVE_GETPEEREID
/* Define to 1 if you have the `getpeerucred' function. */
#undef HAVE_GETPEERUCRED
/* Define to 1 if you have the `getpwnam' function. */
#undef HAVE_GETPWNAM
/* Define to 1 if you have the `getpwuid' function. */
#undef HAVE_GETPWUID
/* Define to 1 if you have the `getspnam' function. */
#undef HAVE_GETSPNAM
/* Define to 1 if you have the `gettimeofday' function. */
#undef HAVE_GETTIMEOFDAY
/* Define to 1 if you have the header file. */
#undef HAVE_GMP_H
/* Define to 1 if you have the `gmtime_r' function. */
#undef HAVE_GMTIME_R
/* define if you have GNUtls */
#undef HAVE_GNUTLS
/* Define to 1 if you have the header file. */
#undef HAVE_GNUTLS_GNUTLS_H
/* if you have GNU Pth */
#undef HAVE_GNU_PTH
/* Define to 1 if you have the header file. */
#undef HAVE_GRP_H
/* Define to 1 if you have the `hstrerror' function. */
#undef HAVE_HSTRERROR
/* define to you inet_aton(3) is available */
#undef HAVE_INET_ATON
/* Define to 1 if you have the `inet_ntoa_b' function. */
#undef HAVE_INET_NTOA_B
/* Define to 1 if you have the `inet_ntop' function. */
#undef HAVE_INET_NTOP
/* Define to 1 if you have the `initgroups' function. */
#undef HAVE_INITGROUPS
/* Define to 1 if you have the header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `ioctl' function. */
#undef HAVE_IOCTL
/* Define to 1 if you have the header file. */
#undef HAVE_IO_H
/* define if your system supports kqueue */
#undef HAVE_KQUEUE
/* define if you have libargon2 */
#undef HAVE_LIBARGON2
/* define if you have -levent */
#undef HAVE_LIBEVENT
/* Define to 1 if you have the `gen' library (-lgen). */
#undef HAVE_LIBGEN
/* Define to 1 if you have the `gmp' library (-lgmp). */
#undef HAVE_LIBGMP
/* Define to 1 if you have the `inet' library (-linet). */
#undef HAVE_LIBINET
/* define if you have libtool -ltdl */
#undef HAVE_LIBLTDL
/* Define to 1 if you have the `net' library (-lnet). */
#undef HAVE_LIBNET
/* Define to 1 if you have the `nsl' library (-lnsl). */
#undef HAVE_LIBNSL
/* Define to 1 if you have the `nsl_s' library (-lnsl_s). */
#undef HAVE_LIBNSL_S
/* Define to 1 if you have the `socket' library (-lsocket). */
#undef HAVE_LIBSOCKET
/* define if you have libsodium */
#undef HAVE_LIBSODIUM
/* Define to 1 if you have the header file. */
#undef HAVE_LIBUTIL_H
/* Define to 1 if you have the `V3' library (-lV3). */
#undef HAVE_LIBV3
/* Define to 1 if you have the header file. */
#undef HAVE_LIMITS_H
/* if you have LinuxThreads */
#undef HAVE_LINUX_THREADS
/* Define to 1 if you have the header file. */
#undef HAVE_LOCALE_H
/* Define to 1 if you have the `localtime_r' function. */
#undef HAVE_LOCALTIME_R
/* Define to 1 if you have the `lockf' function. */
#undef HAVE_LOCKF
/* Define to 1 if the system has the type `long long'. */
#undef HAVE_LONG_LONG
/* Define to 1 if you have the header file. */
#undef HAVE_LTDL_H
/* Define to 1 if you have the header file. */
#undef HAVE_MALLOC_H
/* Define to 1 if you have the `memcpy' function. */
#undef HAVE_MEMCPY
/* Define to 1 if you have the `memmove' function. */
#undef HAVE_MEMMOVE
/* Define to 1 if you have the header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `memrchr' function. */
#undef HAVE_MEMRCHR
/* Define to 1 if you have the `mkstemp' function. */
#undef HAVE_MKSTEMP
/* Define to 1 if you have the `mktemp' function. */
#undef HAVE_MKTEMP
/* define this if you have mkversion */
#undef HAVE_MKVERSION
/* Define to 1 if you have the header file, and it defines `DIR'. */
#undef HAVE_NDIR_H
/* Define to 1 if you have the header file. */
#undef HAVE_NETINET_TCP_H
/* define if strerror_r returns char* instead of int */
#undef HAVE_NONPOSIX_STRERROR_R
/* if you have NT Event Log */
#undef HAVE_NT_EVENT_LOG
/* if you have NT Service Manager */
#undef HAVE_NT_SERVICE_MANAGER
/* if you have NT Threads */
#undef HAVE_NT_THREADS
/* define if you have OpenSSL */
#undef HAVE_OPENSSL
/* Define to 1 if you have the header file. */
#undef HAVE_OPENSSL_BN_H
/* Define to 1 if you have the header file. */
#undef HAVE_OPENSSL_CRYPTO_H
/* Define to 1 if you have the header file. */
#undef HAVE_OPENSSL_SSL_H
/* Define to 1 if you have the `pipe' function. */
#undef HAVE_PIPE
/* Define to 1 if you have the `poll' function. */
#undef HAVE_POLL
/* Define to 1 if you have the header file. */
#undef HAVE_POLL_H
/* Define to 1 if you have the header file. */
#undef HAVE_PROCESS_H
/* Define to 1 if you have the header file. */
#undef HAVE_PSAP_H
/* define to pthreads API spec revision */
#undef HAVE_PTHREADS
/* define if you have pthread_detach function */
#undef HAVE_PTHREAD_DETACH
/* Define to 1 if you have the `pthread_getconcurrency' function. */
#undef HAVE_PTHREAD_GETCONCURRENCY
/* Define to 1 if you have the header file. */
#undef HAVE_PTHREAD_H
/* Define to 1 if you have the `pthread_kill' function. */
#undef HAVE_PTHREAD_KILL
/* Define to 1 if you have the `pthread_kill_other_threads_np' function. */
#undef HAVE_PTHREAD_KILL_OTHER_THREADS_NP
/* define if you have pthread_rwlock_destroy function */
#undef HAVE_PTHREAD_RWLOCK_DESTROY
/* Define to 1 if you have the `pthread_setconcurrency' function. */
#undef HAVE_PTHREAD_SETCONCURRENCY
/* Define to 1 if you have the `pthread_yield' function. */
#undef HAVE_PTHREAD_YIELD
/* Define to 1 if you have the header file. */
#undef HAVE_PTH_H
/* Define to 1 if the system has the type `ptrdiff_t'. */
#undef HAVE_PTRDIFF_T
/* Define to 1 if you have the header file. */
#undef HAVE_PWD_H
/* Define to 1 if you have the `read' function. */
#undef HAVE_READ
/* Define to 1 if you have the `recv' function. */
#undef HAVE_RECV
/* Define to 1 if you have the `recvfrom' function. */
#undef HAVE_RECVFROM
/* Define to 1 if you have the header file. */
#undef HAVE_REGEX_H
/* Define to 1 if you have the header file. */
#undef HAVE_RESOLV_H
/* define if you have res_query() */
#undef HAVE_RES_QUERY
/* Define to 1 if you have the header file. */
#undef HAVE_SASL_H
/* Define to 1 if you have the header file. */
#undef HAVE_SASL_SASL_H
/* define if your SASL library has sasl_version() */
#undef HAVE_SASL_VERSION
/* Define to 1 if you have the header file. */
#undef HAVE_SCHED_H
/* Define to 1 if you have the `sched_yield' function. */
#undef HAVE_SCHED_YIELD
/* Define to 1 if you have the `send' function. */
#undef HAVE_SEND
/* Define to 1 if you have the `sendmsg' function. */
#undef HAVE_SENDMSG
/* Define to 1 if you have the `sendto' function. */
#undef HAVE_SENDTO
/* Define to 1 if you have the `setegid' function. */
#undef HAVE_SETEGID
/* Define to 1 if you have the `seteuid' function. */
#undef HAVE_SETEUID
/* Define to 1 if you have the `setgid' function. */
#undef HAVE_SETGID
/* Define to 1 if you have the `setpwfile' function. */
#undef HAVE_SETPWFILE
/* Define to 1 if you have the `setsid' function. */
#undef HAVE_SETSID
/* Define to 1 if you have the `setuid' function. */
#undef HAVE_SETUID
/* Define to 1 if you have the header file. */
#undef HAVE_SGTTY_H
/* Define to 1 if you have the header file. */
#undef HAVE_SHADOW_H
/* Define to 1 if you have the `sigaction' function. */
#undef HAVE_SIGACTION
/* Define to 1 if you have the `signal' function. */
#undef HAVE_SIGNAL
/* Define to 1 if you have the `sigset' function. */
#undef HAVE_SIGSET
/* define if you have -lslp */
#undef HAVE_SLP
/* Define to 1 if you have the header file. */
#undef HAVE_SLP_H
/* Define to 1 if you have the `snprintf' function. */
#undef HAVE_SNPRINTF
/* Define to 1 if you have the header file. */
#undef HAVE_SODIUM_H
/* if you have spawnlp() */
#undef HAVE_SPAWNLP
/* Define to 1 if you have the header file. */
#undef HAVE_SQLEXT_H
/* Define to 1 if you have the header file. */
#undef HAVE_SQL_H
/* Define to 1 if you have the header file. */
#undef HAVE_STDDEF_H
/* Define to 1 if you have the header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the `strdup' function. */
#undef HAVE_STRDUP
/* Define to 1 if you have the `strerror' function. */
#undef HAVE_STRERROR
/* Define to 1 if you have the `strerror_r' function. */
#undef HAVE_STRERROR_R
/* Define to 1 if you have the `strftime' function. */
#undef HAVE_STRFTIME
/* Define to 1 if you have the header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the `strpbrk' function. */
#undef HAVE_STRPBRK
/* Define to 1 if you have the `strrchr' function. */
#undef HAVE_STRRCHR
/* Define to 1 if you have the `strsep' function. */
#undef HAVE_STRSEP
/* Define to 1 if you have the `strspn' function. */
#undef HAVE_STRSPN
/* Define to 1 if you have the `strstr' function. */
#undef HAVE_STRSTR
/* Define to 1 if you have the `strtol' function. */
#undef HAVE_STRTOL
/* Define to 1 if you have the `strtoll' function. */
#undef HAVE_STRTOLL
/* Define to 1 if you have the `strtoq' function. */
#undef HAVE_STRTOQ
/* Define to 1 if you have the `strtoul' function. */
#undef HAVE_STRTOUL
/* Define to 1 if you have the `strtoull' function. */
#undef HAVE_STRTOULL
/* Define to 1 if you have the `strtouq' function. */
#undef HAVE_STRTOUQ
/* Define to 1 if `msg_accrightslen' is a member of `struct msghdr'. */
#undef HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTSLEN
/* Define to 1 if `msg_control' is a member of `struct msghdr'. */
#undef HAVE_STRUCT_MSGHDR_MSG_CONTROL
/* Define to 1 if `pw_gecos' is a member of `struct passwd'. */
#undef HAVE_STRUCT_PASSWD_PW_GECOS
/* Define to 1 if `pw_passwd' is a member of `struct passwd'. */
#undef HAVE_STRUCT_PASSWD_PW_PASSWD
/* Define to 1 if `st_blksize' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_BLKSIZE
/* Define to 1 if `st_fstype' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_FSTYPE
/* define to 1 if st_fstype is char * */
#undef HAVE_STRUCT_STAT_ST_FSTYPE_CHAR
/* define to 1 if st_fstype is int */
#undef HAVE_STRUCT_STAT_ST_FSTYPE_INT
/* Define to 1 if `st_vfstype' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_VFSTYPE
/* Define to 1 if you have the header file. */
#undef HAVE_SYNCH_H
/* Define to 1 if you have the `sysconf' function. */
#undef HAVE_SYSCONF
/* Define to 1 if you have the header file. */
#undef HAVE_SYSEXITS_H
/* Define to 1 if you have the header file. */
#undef HAVE_SYSLOG_H
/* define if you have systemd */
#undef HAVE_SYSTEMD
/* Define to 1 if you have the