Back to index

lightning-sunbird  0.9+nobinonly
ldaptool.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla Communicator client code, released
00015  * March 31, 1998.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _LDAPTOOL_H
00039 #define _LDAPTOOL_H
00040 
00041 /* XXX:mhein The following is a workaround for the redefinition of */
00042 /*           const problem on OSF.  Fix to be provided by NSS */
00043 /*           This is a pretty benign workaround for us which */
00044 /*           should not cause problems in the future even if */
00045 /*           we forget to take it out :-) */
00046 
00047 #ifdef OSF1V4D
00048 #ifndef __STDC__
00049 #  define __STDC__
00050 #endif /* __STDC__ */
00051 #endif /* OSF1V4D */
00052 
00053 #include <stdio.h>
00054 #include <stdlib.h>
00055 #include <string.h>
00056 #include <errno.h>
00057 
00058 #ifdef AIX
00059 #include <strings.h>
00060 #endif
00061 
00062 
00063 #ifdef SCOOS
00064 #include <sys/types.h>
00065 #endif
00066 
00067 #ifdef _WINDOWS
00068 #define WIN32_LEAN_AND_MEAN
00069 #include <windows.h>
00070 extern int getopt (int argc, char *const *argv, const char *optstring);
00071 #else
00072 #include <sys/file.h>
00073 #include <sys/stat.h>
00074 #include <unistd.h>
00075 #endif
00076 
00077 #include <ctype.h>
00078 
00079 #ifndef SCOOS
00080 #include <sys/types.h>
00081 #endif
00082 
00083 #include <sys/stat.h>
00084 #include <fcntl.h>
00085 
00086 #if defined(NET_SSL)
00087 #include <ssl.h>
00088 #endif
00089 
00090 
00091 #include <portable.h>
00092 
00093 #include <ldap.h>
00094 #ifndef NO_LIBLCACHE
00095 #include <lcache.h>
00096 #endif
00097 
00098 #include <ldaplog.h>
00099 #include <ldif.h>
00100 
00101 #if defined(NET_SSL)
00102 #include <ldap_ssl.h>
00103 #endif
00104 
00105 #include <ldappr.h>
00106 
00107 #ifdef __cplusplus
00108 extern "C" {
00109 #endif
00110 
00111 
00112 /*
00113  * shared macros, structures, etc.
00114  */
00115 #define LDAPTOOL_RESULT_IS_AN_ERROR( rc ) \
00116               ( (rc) != LDAP_SUCCESS && (rc) != LDAP_COMPARE_TRUE \
00117               && (rc) != LDAP_COMPARE_FALSE )
00118 
00119 #define LDAPTOOL_DEFSEP            "="    /* used by ldapcmp and ldapsearch */
00120 #define LDAPTOOL_DEFHOST    "localhost"
00121 #define LDAPTOOL_DEFCERTDBPATH     "."
00122 #define LDAPTOOL_DEFKEYDBPATH      "."
00123 #define LDAPTOOL_DEFREFHOPLIMIT           5
00124 
00125 #define LDAPTOOL_SAFEREALLOC( ptr, size )  ( ptr == NULL ? malloc( size ) : \
00126                                           realloc( ptr, size ))
00127 /* this defines the max number of control requests for the tools */
00128 #define CONTROL_REQUESTS 50
00129 
00130 /*
00131  * globals (defined in common.c)
00132  */
00133 extern char          *ldaptool_host;
00134 extern char          *ldaptool_host2;
00135 extern int           ldaptool_port;
00136 extern int           ldaptool_port2;
00137 extern int           ldaptool_verbose;
00138 extern int           ldaptool_not;
00139 extern char          *ldaptool_progname;
00140 extern FILE          *ldaptool_fp;
00141 extern char          *ldaptool_charset;
00142 extern char          *ldaptool_convdir;
00143 extern LDAPControl   *ldaptool_request_ctrls[];
00144 
00145 
00146 /*
00147  * function prototypes
00148  */
00149 void ldaptool_common_usage( int two_hosts );
00150 int ldaptool_process_args( int argc, char **argv, char *extra_opts,
00151        int two_hosts, void (*extra_opt_callback)( int option, char *optarg ));
00152 LDAP *ldaptool_ldap_init( int second_host );
00153 void ldaptool_bind( LDAP *ld );
00154 void ldaptool_cleanup( LDAP *ld );
00155 int ldaptool_print_lderror( LDAP *ld, char *msg, int check4ssl );
00156 #define LDAPTOOL_CHECK4SSL_NEVER   0
00157 #define LDAPTOOL_CHECK4SSL_ALWAYS  1
00158 #define LDAPTOOL_CHECK4SSL_IF_APPROP      2      /* if appropriate */
00159 LDAPControl *ldaptool_create_manage_dsait_control( void );
00160 void ldaptool_print_referrals( char **refs );
00161 int ldaptool_print_extended_response( LDAP *ld, LDAPMessage *res, char *msg );
00162 LDAPControl *ldaptool_create_proxyauth_control( LDAP *ld );
00163 void ldaptool_add_control_to_array( LDAPControl *ctrl, LDAPControl **array);
00164 void ldaptool_reset_control_array( LDAPControl **array );
00165 char *ldaptool_get_tmp_dir( void );
00166 char *ldaptool_local2UTF8( const char * );
00167 int ldaptool_berval_is_ascii( const struct berval *bvp );
00168 int ldaptool_sasl_bind_s( LDAP *ld, const char *dn, const char *mechanism,
00169         const struct berval *cred, LDAPControl **serverctrls,
00170         LDAPControl **clientctrls, struct berval **servercredp, char *msg );
00171 int ldaptool_simple_bind_s( LDAP *ld, const char *dn, const char *passwd,
00172        LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg );
00173 int ldaptool_add_ext_s( LDAP *ld, const char *dn, LDAPMod **attrs,
00174         LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg );
00175 int ldaptool_modify_ext_s( LDAP *ld, const char *dn, LDAPMod **mods,
00176         LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg );
00177 int ldaptool_delete_ext_s( LDAP *ld, const char *dn, LDAPControl **serverctrls,
00178         LDAPControl **clientctrls, char *msg );
00179 int ldaptool_rename_s(  LDAP *ld, const char *dn, const char *newrdn,
00180         const char *newparent, int deleteoldrdn, LDAPControl **serverctrls,
00181         LDAPControl **clientctrls, char *msg );
00182 int ldaptool_compare_ext_s( LDAP *ld, const char *dn, const char *attrtype,
00183            const struct berval *bvalue, LDAPControl **serverctrls,
00184            LDAPControl **clientctrls, char *msg );
00185 int ldaptool_boolean_str2value ( const char *s, int strict );
00186 int ldaptool_parse_ctrl_arg ( char *ctrl_arg, char sep, char **ctrl_oid, 
00187            int *ctrl_criticality, char **ctrl_value, int *vlen);
00188 
00189 
00190 #ifdef __cplusplus
00191 }
00192 #endif
00193 
00194 #endif /* LDAPTOOL_H */