10Sstevel@tonic-gate /* 2*8097SSreedhar.Chalamalasetti@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 30Sstevel@tonic-gate * Use is subject to license terms. 40Sstevel@tonic-gate */ 50Sstevel@tonic-gate 60Sstevel@tonic-gate /* 70Sstevel@tonic-gate * The contents of this file are subject to the Netscape Public 80Sstevel@tonic-gate * License Version 1.1 (the "License"); you may not use this file 90Sstevel@tonic-gate * except in compliance with the License. You may obtain a copy of 100Sstevel@tonic-gate * the License at http://www.mozilla.org/NPL/ 110Sstevel@tonic-gate * 120Sstevel@tonic-gate * Software distributed under the License is distributed on an "AS 130Sstevel@tonic-gate * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 140Sstevel@tonic-gate * implied. See the License for the specific language governing 150Sstevel@tonic-gate * rights and limitations under the License. 160Sstevel@tonic-gate * 170Sstevel@tonic-gate * The Original Code is Mozilla Communicator client code, released 180Sstevel@tonic-gate * March 31, 1998. 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * The Initial Developer of the Original Code is Netscape 210Sstevel@tonic-gate * Communications Corporation. Portions created by Netscape are 220Sstevel@tonic-gate * Copyright (C) 1998-1999 Netscape Communications Corporation. All 230Sstevel@tonic-gate * Rights Reserved. 240Sstevel@tonic-gate * 250Sstevel@tonic-gate * Contributor(s): 260Sstevel@tonic-gate */ 270Sstevel@tonic-gate 280Sstevel@tonic-gate #ifndef _LDAPTOOL_H 290Sstevel@tonic-gate #define _LDAPTOOL_H 300Sstevel@tonic-gate 310Sstevel@tonic-gate /* XXX:mhein The following is a workaround for the redefinition of */ 320Sstevel@tonic-gate /* const problem on OSF. Fix to be provided by NSS */ 330Sstevel@tonic-gate /* This is a pretty benign workaround for us which */ 340Sstevel@tonic-gate /* should not cause problems in the future even if */ 350Sstevel@tonic-gate /* we forget to take it out :-) */ 360Sstevel@tonic-gate 370Sstevel@tonic-gate #ifdef OSF1V4D 380Sstevel@tonic-gate #ifndef __STDC__ 390Sstevel@tonic-gate # define __STDC__ 400Sstevel@tonic-gate #endif /* __STDC__ */ 410Sstevel@tonic-gate #endif /* OSF1V4D */ 420Sstevel@tonic-gate 430Sstevel@tonic-gate #include <stdio.h> 440Sstevel@tonic-gate #include <stdlib.h> 450Sstevel@tonic-gate #include <string.h> 460Sstevel@tonic-gate #include <errno.h> 470Sstevel@tonic-gate 480Sstevel@tonic-gate #ifdef AIX 490Sstevel@tonic-gate #include <strings.h> 500Sstevel@tonic-gate #endif 510Sstevel@tonic-gate 520Sstevel@tonic-gate 530Sstevel@tonic-gate #ifdef SCOOS 540Sstevel@tonic-gate #include <sys/types.h> 550Sstevel@tonic-gate #endif 560Sstevel@tonic-gate 570Sstevel@tonic-gate #ifdef _WINDOWS 580Sstevel@tonic-gate #define WIN32_LEAN_AND_MEAN 590Sstevel@tonic-gate #include <windows.h> 600Sstevel@tonic-gate extern int getopt (int argc, char *const *argv, const char *optstring); 610Sstevel@tonic-gate #include <io.h> /* for _mktemp() */ 620Sstevel@tonic-gate #define LDAPTOOL_MKTEMP( p ) _mktemp( p ) 630Sstevel@tonic-gate #else 640Sstevel@tonic-gate #include <sys/file.h> 650Sstevel@tonic-gate #include <sys/stat.h> 660Sstevel@tonic-gate #include <unistd.h> 670Sstevel@tonic-gate #define LDAPTOOL_MKTEMP( p ) mktemp( p ) 680Sstevel@tonic-gate #endif 690Sstevel@tonic-gate 700Sstevel@tonic-gate #ifdef LINUX 710Sstevel@tonic-gate #include <getopt.h> /* not always included from unistd.h */ 720Sstevel@tonic-gate #endif 730Sstevel@tonic-gate 740Sstevel@tonic-gate #include <ctype.h> 750Sstevel@tonic-gate 760Sstevel@tonic-gate #ifndef SCOOS 770Sstevel@tonic-gate #include <sys/types.h> 780Sstevel@tonic-gate #endif 790Sstevel@tonic-gate 800Sstevel@tonic-gate #include <sys/stat.h> 810Sstevel@tonic-gate #include <fcntl.h> 820Sstevel@tonic-gate 830Sstevel@tonic-gate #ifndef SOLARIS_LDAP_CMD 840Sstevel@tonic-gate #if defined(NET_SSL) 850Sstevel@tonic-gate #include <ssl.h> 860Sstevel@tonic-gate #endif 870Sstevel@tonic-gate 880Sstevel@tonic-gate #if defined(NET_SSL) 890Sstevel@tonic-gate #include <ldap_ssl.h> 900Sstevel@tonic-gate #endif 910Sstevel@tonic-gate 920Sstevel@tonic-gate #ifndef NO_LIBLCACHE 930Sstevel@tonic-gate #include <lcache.h> 940Sstevel@tonic-gate #endif 950Sstevel@tonic-gate 960Sstevel@tonic-gate #include <ldappr.h> 970Sstevel@tonic-gate #include <portable.h> 980Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 990Sstevel@tonic-gate 1000Sstevel@tonic-gate #include <ldap.h> 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate #include <ldaplog.h> 1030Sstevel@tonic-gate #include <ldif.h> 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate #ifdef __cplusplus 1070Sstevel@tonic-gate extern "C" { 1080Sstevel@tonic-gate #endif 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate /* 1120Sstevel@tonic-gate * shared macros, structures, etc. 1130Sstevel@tonic-gate */ 1140Sstevel@tonic-gate #define LDAPTOOL_RESULT_IS_AN_ERROR( rc ) \ 1150Sstevel@tonic-gate ( (rc) != LDAP_SUCCESS && (rc) != LDAP_COMPARE_TRUE \ 1160Sstevel@tonic-gate && (rc) != LDAP_COMPARE_FALSE ) 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate #define LDAPTOOL_DEFSEP "=" /* used by ldapcmp and ldapsearch */ 1190Sstevel@tonic-gate #define LDAPTOOL_DEFHOST "localhost" 1200Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 1210Sstevel@tonic-gate #define LDAPTOOL_DEFSSLSTRENGTH LDAPSSL_AUTH_CNCHECK 1220Sstevel@tonic-gate #else 1230Sstevel@tonic-gate #define LDAPTOOL_DEFSSLSTRENGTH LDAPSSL_AUTH_CERT 1240Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 1250Sstevel@tonic-gate #define LDAPTOOL_DEFCERTDBPATH "." 1260Sstevel@tonic-gate #define LDAPTOOL_DEFKEYDBPATH "." 1270Sstevel@tonic-gate #define LDAPTOOL_DEFREFHOPLIMIT 5 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate #define LDAPTOOL_SAFEREALLOC( ptr, size ) ( ptr == NULL ? malloc( size ) : \ 1300Sstevel@tonic-gate realloc( ptr, size )) 1310Sstevel@tonic-gate /* this defines the max number of control requests for the tools */ 1320Sstevel@tonic-gate #define CONTROL_REQUESTS 50 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate /* 1350Sstevel@tonic-gate * globals (defined in common.c) 1360Sstevel@tonic-gate */ 1370Sstevel@tonic-gate extern char *ldaptool_host; 1380Sstevel@tonic-gate extern char *ldaptool_host2; 1390Sstevel@tonic-gate extern int ldaptool_port; 1400Sstevel@tonic-gate extern int ldaptool_port2; 1410Sstevel@tonic-gate extern int ldaptool_verbose; 1420Sstevel@tonic-gate extern int ldaptool_not; 1430Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 1440Sstevel@tonic-gate extern int ldaptool_require_binddn; 1450Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 1460Sstevel@tonic-gate extern char *ldaptool_progname; 1470Sstevel@tonic-gate extern FILE *ldaptool_fp; 1480Sstevel@tonic-gate extern char *ldaptool_charset; 1490Sstevel@tonic-gate extern char *ldaptool_convdir; 1500Sstevel@tonic-gate extern LDAPControl *ldaptool_request_ctrls[]; 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate /* 1540Sstevel@tonic-gate * function prototypes 1550Sstevel@tonic-gate */ 1560Sstevel@tonic-gate void ldaptool_common_usage( int two_hosts ); 1570Sstevel@tonic-gate int ldaptool_process_args( int argc, char **argv, char *extra_opts, 1580Sstevel@tonic-gate int two_hosts, void (*extra_opt_callback)( int option, char *optarg )); 1590Sstevel@tonic-gate LDAP *ldaptool_ldap_init( int second_host ); 1600Sstevel@tonic-gate void ldaptool_bind( LDAP *ld ); 1610Sstevel@tonic-gate void ldaptool_cleanup( LDAP *ld ); 1620Sstevel@tonic-gate int ldaptool_print_lderror( LDAP *ld, char *msg, int check4ssl ); 1630Sstevel@tonic-gate #define LDAPTOOL_CHECK4SSL_NEVER 0 1640Sstevel@tonic-gate #define LDAPTOOL_CHECK4SSL_ALWAYS 1 1650Sstevel@tonic-gate #define LDAPTOOL_CHECK4SSL_IF_APPROP 2 /* if appropriate */ 1660Sstevel@tonic-gate LDAPControl *ldaptool_create_manage_dsait_control( void ); 1670Sstevel@tonic-gate void ldaptool_print_referrals( char **refs ); 1680Sstevel@tonic-gate int ldaptool_print_extended_response( LDAP *ld, LDAPMessage *res, char *msg ); 1690Sstevel@tonic-gate LDAPControl *ldaptool_create_proxyauth_control( LDAP *ld ); 1700Sstevel@tonic-gate LDAPControl *ldaptool_create_geteffectiveRights_control ( LDAP *ld, 1710Sstevel@tonic-gate const char *authzid, 1720Sstevel@tonic-gate const char **attrlist ); 1730Sstevel@tonic-gate void ldaptool_add_control_to_array( LDAPControl *ctrl, LDAPControl **array); 1740Sstevel@tonic-gate void ldaptool_reset_control_array( LDAPControl **array ); 1750Sstevel@tonic-gate char *ldaptool_get_tmp_dir( void ); 1760Sstevel@tonic-gate char *ldaptool_local2UTF8( const char * ); 1770Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 1780Sstevel@tonic-gate char *ldaptool_UTF82local( const char * ); 1790Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 1800Sstevel@tonic-gate int ldaptool_berval_is_ascii( const struct berval *bvp ); 1810Sstevel@tonic-gate int ldaptool_sasl_bind_s( LDAP *ld, const char *dn, const char *mechanism, 1820Sstevel@tonic-gate const struct berval *cred, LDAPControl **serverctrls, 1830Sstevel@tonic-gate LDAPControl **clientctrls, struct berval **servercredp, char *msg ); 1840Sstevel@tonic-gate int ldaptool_simple_bind_s( LDAP *ld, const char *dn, const char *passwd, 1850Sstevel@tonic-gate LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg ); 1860Sstevel@tonic-gate int ldaptool_add_ext_s( LDAP *ld, const char *dn, LDAPMod **attrs, 1870Sstevel@tonic-gate LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg ); 1880Sstevel@tonic-gate int ldaptool_modify_ext_s( LDAP *ld, const char *dn, LDAPMod **mods, 1890Sstevel@tonic-gate LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg ); 1900Sstevel@tonic-gate int ldaptool_delete_ext_s( LDAP *ld, const char *dn, LDAPControl **serverctrls, 1910Sstevel@tonic-gate LDAPControl **clientctrls, char *msg ); 1920Sstevel@tonic-gate int ldaptool_rename_s( LDAP *ld, const char *dn, const char *newrdn, 1930Sstevel@tonic-gate const char *newparent, int deleteoldrdn, LDAPControl **serverctrls, 1940Sstevel@tonic-gate LDAPControl **clientctrls, char *msg ); 1950Sstevel@tonic-gate int ldaptool_compare_ext_s( LDAP *ld, const char *dn, const char *attrtype, 1960Sstevel@tonic-gate const struct berval *bvalue, LDAPControl **serverctrls, 1970Sstevel@tonic-gate LDAPControl **clientctrls, char *msg ); 1980Sstevel@tonic-gate int ldaptool_boolean_str2value ( const char *s, int strict ); 1990Sstevel@tonic-gate int ldaptool_parse_ctrl_arg ( char *ctrl_arg, char sep, char **ctrl_oid, 2000Sstevel@tonic-gate int *ctrl_criticality, char **ctrl_value, int *vlen); 2010Sstevel@tonic-gate FILE * ldaptool_open_file(const char *filename, const char *mode); 202*8097SSreedhar.Chalamalasetti@Sun.COM int ldaptool_check_ferror( FILE * stream, const int ldap_err, const char *msg ); 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate /* Definition for list in ldapdelete.c */ 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate typedef struct Element { /* double-linked list data type */ 2080Sstevel@tonic-gate struct Element *right; 2090Sstevel@tonic-gate struct Element *left; 2100Sstevel@tonic-gate char *data; 2110Sstevel@tonic-gate } Element; 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate typedef struct { /* generic double-linked list head */ 2140Sstevel@tonic-gate Element *first; 2150Sstevel@tonic-gate Element *last; 2160Sstevel@tonic-gate long count; 2170Sstevel@tonic-gate } Head; 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate void L_Init(Head *list); 2200Sstevel@tonic-gate void L_Insert(Element *Node, Head *HeadNode); 2210Sstevel@tonic-gate void L_Remove(Element *Node, Head *HeadNode); 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate #ifdef __cplusplus 2240Sstevel@tonic-gate } 2250Sstevel@tonic-gate #endif 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate #endif /* LDAPTOOL_H */ 228