17c478bd9Sstevel@tonic-gate /* 2*ffc33b84SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 37c478bd9Sstevel@tonic-gate * Use is subject to license terms. 47c478bd9Sstevel@tonic-gate */ 57c478bd9Sstevel@tonic-gate 67c478bd9Sstevel@tonic-gate /* 77c478bd9Sstevel@tonic-gate * The contents of this file are subject to the Netscape Public 87c478bd9Sstevel@tonic-gate * License Version 1.1 (the "License"); you may not use this file 97c478bd9Sstevel@tonic-gate * except in compliance with the License. You may obtain a copy of 107c478bd9Sstevel@tonic-gate * the License at http://www.mozilla.org/NPL/ 117c478bd9Sstevel@tonic-gate * 127c478bd9Sstevel@tonic-gate * Software distributed under the License is distributed on an "AS 137c478bd9Sstevel@tonic-gate * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 147c478bd9Sstevel@tonic-gate * implied. See the License for the specific language governing 157c478bd9Sstevel@tonic-gate * rights and limitations under the License. 167c478bd9Sstevel@tonic-gate * 177c478bd9Sstevel@tonic-gate * The Original Code is Mozilla Communicator client code, released 187c478bd9Sstevel@tonic-gate * March 31, 1998. 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * The Initial Developer of the Original Code is Netscape 217c478bd9Sstevel@tonic-gate * Communications Corporation. Portions created by Netscape are 227c478bd9Sstevel@tonic-gate * Copyright (C) 1998-1999 Netscape Communications Corporation. All 237c478bd9Sstevel@tonic-gate * Rights Reserved. 247c478bd9Sstevel@tonic-gate * 257c478bd9Sstevel@tonic-gate * Contributor(s): 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #ifndef _LDAPTOOL_H 297c478bd9Sstevel@tonic-gate #define _LDAPTOOL_H 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate /* XXX:mhein The following is a workaround for the redefinition of */ 327c478bd9Sstevel@tonic-gate /* const problem on OSF. Fix to be provided by NSS */ 337c478bd9Sstevel@tonic-gate /* This is a pretty benign workaround for us which */ 347c478bd9Sstevel@tonic-gate /* should not cause problems in the future even if */ 357c478bd9Sstevel@tonic-gate /* we forget to take it out :-) */ 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #ifdef OSF1V4D 387c478bd9Sstevel@tonic-gate #ifndef __STDC__ 397c478bd9Sstevel@tonic-gate # define __STDC__ 407c478bd9Sstevel@tonic-gate #endif /* __STDC__ */ 417c478bd9Sstevel@tonic-gate #endif /* OSF1V4D */ 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #include <stdio.h> 447c478bd9Sstevel@tonic-gate #include <stdlib.h> 457c478bd9Sstevel@tonic-gate #include <string.h> 467c478bd9Sstevel@tonic-gate #include <errno.h> 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #ifdef AIX 497c478bd9Sstevel@tonic-gate #include <strings.h> 507c478bd9Sstevel@tonic-gate #endif 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #ifdef SCOOS 547c478bd9Sstevel@tonic-gate #include <sys/types.h> 557c478bd9Sstevel@tonic-gate #endif 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate #ifdef _WINDOWS 587c478bd9Sstevel@tonic-gate #define WIN32_LEAN_AND_MEAN 597c478bd9Sstevel@tonic-gate #include <windows.h> 607c478bd9Sstevel@tonic-gate extern int getopt (int argc, char *const *argv, const char *optstring); 617c478bd9Sstevel@tonic-gate #include <io.h> /* for _mktemp() */ 627c478bd9Sstevel@tonic-gate #define LDAPTOOL_MKTEMP( p ) _mktemp( p ) 637c478bd9Sstevel@tonic-gate #else 647c478bd9Sstevel@tonic-gate #include <sys/file.h> 657c478bd9Sstevel@tonic-gate #include <sys/stat.h> 667c478bd9Sstevel@tonic-gate #include <unistd.h> 677c478bd9Sstevel@tonic-gate #define LDAPTOOL_MKTEMP( p ) mktemp( p ) 687c478bd9Sstevel@tonic-gate #endif 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate #ifdef LINUX 717c478bd9Sstevel@tonic-gate #include <getopt.h> /* not always included from unistd.h */ 727c478bd9Sstevel@tonic-gate #endif 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate #include <ctype.h> 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate #ifndef SCOOS 777c478bd9Sstevel@tonic-gate #include <sys/types.h> 787c478bd9Sstevel@tonic-gate #endif 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate #include <sys/stat.h> 817c478bd9Sstevel@tonic-gate #include <fcntl.h> 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate #ifndef SOLARIS_LDAP_CMD 847c478bd9Sstevel@tonic-gate #if defined(NET_SSL) 857c478bd9Sstevel@tonic-gate #include <ssl.h> 867c478bd9Sstevel@tonic-gate #endif 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate #if defined(NET_SSL) 897c478bd9Sstevel@tonic-gate #include <ldap_ssl.h> 907c478bd9Sstevel@tonic-gate #endif 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate #ifndef NO_LIBLCACHE 937c478bd9Sstevel@tonic-gate #include <lcache.h> 947c478bd9Sstevel@tonic-gate #endif 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate #include <ldappr.h> 977c478bd9Sstevel@tonic-gate #include <portable.h> 987c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate #include <ldap.h> 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate #include <ldaplog.h> 1037c478bd9Sstevel@tonic-gate #include <ldif.h> 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1077c478bd9Sstevel@tonic-gate extern "C" { 1087c478bd9Sstevel@tonic-gate #endif 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate /* 1127c478bd9Sstevel@tonic-gate * shared macros, structures, etc. 1137c478bd9Sstevel@tonic-gate */ 1147c478bd9Sstevel@tonic-gate #define LDAPTOOL_RESULT_IS_AN_ERROR( rc ) \ 1157c478bd9Sstevel@tonic-gate ( (rc) != LDAP_SUCCESS && (rc) != LDAP_COMPARE_TRUE \ 1167c478bd9Sstevel@tonic-gate && (rc) != LDAP_COMPARE_FALSE ) 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate #define LDAPTOOL_DEFSEP "=" /* used by ldapcmp and ldapsearch */ 1197c478bd9Sstevel@tonic-gate #define LDAPTOOL_DEFHOST "localhost" 1207c478bd9Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 1217c478bd9Sstevel@tonic-gate #define LDAPTOOL_DEFSSLSTRENGTH LDAPSSL_AUTH_CNCHECK 1227c478bd9Sstevel@tonic-gate #else 1237c478bd9Sstevel@tonic-gate #define LDAPTOOL_DEFSSLSTRENGTH LDAPSSL_AUTH_CERT 1247c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 1257c478bd9Sstevel@tonic-gate #define LDAPTOOL_DEFCERTDBPATH "." 1267c478bd9Sstevel@tonic-gate #define LDAPTOOL_DEFKEYDBPATH "." 1277c478bd9Sstevel@tonic-gate #define LDAPTOOL_DEFREFHOPLIMIT 5 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate #define LDAPTOOL_SAFEREALLOC( ptr, size ) ( ptr == NULL ? malloc( size ) : \ 1307c478bd9Sstevel@tonic-gate realloc( ptr, size )) 1317c478bd9Sstevel@tonic-gate /* this defines the max number of control requests for the tools */ 1327c478bd9Sstevel@tonic-gate #define CONTROL_REQUESTS 50 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate /* 1357c478bd9Sstevel@tonic-gate * globals (defined in common.c) 1367c478bd9Sstevel@tonic-gate */ 1377c478bd9Sstevel@tonic-gate extern char *ldaptool_host; 1387c478bd9Sstevel@tonic-gate extern char *ldaptool_host2; 1397c478bd9Sstevel@tonic-gate extern int ldaptool_port; 1407c478bd9Sstevel@tonic-gate extern int ldaptool_port2; 1417c478bd9Sstevel@tonic-gate extern int ldaptool_verbose; 1427c478bd9Sstevel@tonic-gate extern int ldaptool_not; 1437c478bd9Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 1447c478bd9Sstevel@tonic-gate extern int ldaptool_require_binddn; 1457c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 1467c478bd9Sstevel@tonic-gate extern char *ldaptool_progname; 1477c478bd9Sstevel@tonic-gate extern FILE *ldaptool_fp; 1487c478bd9Sstevel@tonic-gate extern char *ldaptool_charset; 1497c478bd9Sstevel@tonic-gate extern char *ldaptool_convdir; 1507c478bd9Sstevel@tonic-gate extern LDAPControl *ldaptool_request_ctrls[]; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate /* 1547c478bd9Sstevel@tonic-gate * function prototypes 1557c478bd9Sstevel@tonic-gate */ 1567c478bd9Sstevel@tonic-gate void ldaptool_common_usage( int two_hosts ); 1577c478bd9Sstevel@tonic-gate int ldaptool_process_args( int argc, char **argv, char *extra_opts, 1587c478bd9Sstevel@tonic-gate int two_hosts, void (*extra_opt_callback)( int option, char *optarg )); 1597c478bd9Sstevel@tonic-gate LDAP *ldaptool_ldap_init( int second_host ); 1607c478bd9Sstevel@tonic-gate void ldaptool_bind( LDAP *ld ); 1617c478bd9Sstevel@tonic-gate void ldaptool_cleanup( LDAP *ld ); 1627c478bd9Sstevel@tonic-gate int ldaptool_print_lderror( LDAP *ld, char *msg, int check4ssl ); 1637c478bd9Sstevel@tonic-gate #define LDAPTOOL_CHECK4SSL_NEVER 0 1647c478bd9Sstevel@tonic-gate #define LDAPTOOL_CHECK4SSL_ALWAYS 1 1657c478bd9Sstevel@tonic-gate #define LDAPTOOL_CHECK4SSL_IF_APPROP 2 /* if appropriate */ 1667c478bd9Sstevel@tonic-gate LDAPControl *ldaptool_create_manage_dsait_control( void ); 1677c478bd9Sstevel@tonic-gate void ldaptool_print_referrals( char **refs ); 1687c478bd9Sstevel@tonic-gate int ldaptool_print_extended_response( LDAP *ld, LDAPMessage *res, char *msg ); 1697c478bd9Sstevel@tonic-gate LDAPControl *ldaptool_create_proxyauth_control( LDAP *ld ); 1707c478bd9Sstevel@tonic-gate LDAPControl *ldaptool_create_geteffectiveRights_control ( LDAP *ld, 1717c478bd9Sstevel@tonic-gate const char *authzid, 1727c478bd9Sstevel@tonic-gate const char **attrlist ); 1737c478bd9Sstevel@tonic-gate void ldaptool_add_control_to_array( LDAPControl *ctrl, LDAPControl **array); 1747c478bd9Sstevel@tonic-gate void ldaptool_reset_control_array( LDAPControl **array ); 1757c478bd9Sstevel@tonic-gate char *ldaptool_get_tmp_dir( void ); 1767c478bd9Sstevel@tonic-gate char *ldaptool_local2UTF8( const char * ); 1777c478bd9Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 1787c478bd9Sstevel@tonic-gate char *ldaptool_UTF82local( const char * ); 1797c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 1807c478bd9Sstevel@tonic-gate int ldaptool_berval_is_ascii( const struct berval *bvp ); 1817c478bd9Sstevel@tonic-gate int ldaptool_sasl_bind_s( LDAP *ld, const char *dn, const char *mechanism, 1827c478bd9Sstevel@tonic-gate const struct berval *cred, LDAPControl **serverctrls, 1837c478bd9Sstevel@tonic-gate LDAPControl **clientctrls, struct berval **servercredp, char *msg ); 1847c478bd9Sstevel@tonic-gate int ldaptool_simple_bind_s( LDAP *ld, const char *dn, const char *passwd, 1857c478bd9Sstevel@tonic-gate LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg ); 1867c478bd9Sstevel@tonic-gate int ldaptool_add_ext_s( LDAP *ld, const char *dn, LDAPMod **attrs, 1877c478bd9Sstevel@tonic-gate LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg ); 1887c478bd9Sstevel@tonic-gate int ldaptool_modify_ext_s( LDAP *ld, const char *dn, LDAPMod **mods, 1897c478bd9Sstevel@tonic-gate LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg ); 1907c478bd9Sstevel@tonic-gate int ldaptool_delete_ext_s( LDAP *ld, const char *dn, LDAPControl **serverctrls, 1917c478bd9Sstevel@tonic-gate LDAPControl **clientctrls, char *msg ); 1927c478bd9Sstevel@tonic-gate int ldaptool_rename_s( LDAP *ld, const char *dn, const char *newrdn, 1937c478bd9Sstevel@tonic-gate const char *newparent, int deleteoldrdn, LDAPControl **serverctrls, 1947c478bd9Sstevel@tonic-gate LDAPControl **clientctrls, char *msg ); 1957c478bd9Sstevel@tonic-gate int ldaptool_compare_ext_s( LDAP *ld, const char *dn, const char *attrtype, 1967c478bd9Sstevel@tonic-gate const struct berval *bvalue, LDAPControl **serverctrls, 1977c478bd9Sstevel@tonic-gate LDAPControl **clientctrls, char *msg ); 1987c478bd9Sstevel@tonic-gate int ldaptool_boolean_str2value ( const char *s, int strict ); 1997c478bd9Sstevel@tonic-gate int ldaptool_parse_ctrl_arg ( char *ctrl_arg, char sep, char **ctrl_oid, 2007c478bd9Sstevel@tonic-gate int *ctrl_criticality, char **ctrl_value, int *vlen); 2017c478bd9Sstevel@tonic-gate FILE * ldaptool_open_file(const char *filename, const char *mode); 202*ffc33b84SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India int ldaptool_check_ferror( FILE * stream, const int ldap_err, const char *msg ); 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate /* Definition for list in ldapdelete.c */ 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate typedef struct Element { /* double-linked list data type */ 2087c478bd9Sstevel@tonic-gate struct Element *right; 2097c478bd9Sstevel@tonic-gate struct Element *left; 2107c478bd9Sstevel@tonic-gate char *data; 2117c478bd9Sstevel@tonic-gate } Element; 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate typedef struct { /* generic double-linked list head */ 2147c478bd9Sstevel@tonic-gate Element *first; 2157c478bd9Sstevel@tonic-gate Element *last; 2167c478bd9Sstevel@tonic-gate long count; 2177c478bd9Sstevel@tonic-gate } Head; 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate void L_Init(Head *list); 2207c478bd9Sstevel@tonic-gate void L_Insert(Element *Node, Head *HeadNode); 2217c478bd9Sstevel@tonic-gate void L_Remove(Element *Node, Head *HeadNode); 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2247c478bd9Sstevel@tonic-gate } 2257c478bd9Sstevel@tonic-gate #endif 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate #endif /* LDAPTOOL_H */ 228