2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
7 * The contents of this file are subject to the Netscape Public
8 * License Version 1.1 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of
10 * the License at http://www.mozilla.org/NPL/
12 * Software distributed under the License is distributed on an "AS
13 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * rights and limitations under the License.
17 * The Original Code is Mozilla Communicator client code, released
20 * The Initial Developer of the Original Code is Netscape
21 * Communications Corporation. Portions created by Netscape are
22 * Copyright (C) 1998-1999 Netscape Communications Corporation. All
31 /* XXX:mhein The following is a workaround for the redefinition of */
32 /* const problem on OSF. Fix to be provided by NSS */
33 /* This is a pretty benign workaround for us which */
34 /* should not cause problems in the future even if */
35 /* we forget to take it out :-) */
54 #include <sys/types.h>
58 #define WIN32_LEAN_AND_MEAN
60 extern int getopt (int argc
, char *const *argv
, const char *optstring
);
61 #include <io.h> /* for _mktemp() */
62 #define LDAPTOOL_MKTEMP( p ) _mktemp( p )
67 #define LDAPTOOL_MKTEMP( p ) mktemp( p )
71 #include <getopt.h> /* not always included from unistd.h */
77 #include <sys/types.h>
83 #ifndef SOLARIS_LDAP_CMD
98 #endif /* SOLARIS_LDAP_CMD */
112 * shared macros, structures, etc.
114 #define LDAPTOOL_RESULT_IS_AN_ERROR( rc ) \
115 ( (rc) != LDAP_SUCCESS && (rc) != LDAP_COMPARE_TRUE \
116 && (rc) != LDAP_COMPARE_FALSE )
118 #define LDAPTOOL_DEFSEP "=" /* used by ldapcmp and ldapsearch */
119 #define LDAPTOOL_DEFHOST "localhost"
120 #ifdef SOLARIS_LDAP_CMD
121 #define LDAPTOOL_DEFSSLSTRENGTH LDAPSSL_AUTH_CNCHECK
123 #define LDAPTOOL_DEFSSLSTRENGTH LDAPSSL_AUTH_CERT
124 #endif /* SOLARIS_LDAP_CMD */
125 #define LDAPTOOL_DEFCERTDBPATH "."
126 #define LDAPTOOL_DEFKEYDBPATH "."
127 #define LDAPTOOL_DEFREFHOPLIMIT 5
129 #define LDAPTOOL_SAFEREALLOC( ptr, size ) ( ptr == NULL ? malloc( size ) : \
130 realloc( ptr, size ))
131 /* this defines the max number of control requests for the tools */
132 #define CONTROL_REQUESTS 50
135 * globals (defined in common.c)
137 extern char *ldaptool_host
;
138 extern char *ldaptool_host2
;
139 extern int ldaptool_port
;
140 extern int ldaptool_port2
;
141 extern int ldaptool_verbose
;
142 extern int ldaptool_not
;
143 #ifdef SOLARIS_LDAP_CMD
144 extern int ldaptool_require_binddn
;
145 #endif /* SOLARIS_LDAP_CMD */
146 extern char *ldaptool_progname
;
147 extern FILE *ldaptool_fp
;
148 extern char *ldaptool_charset
;
149 extern char *ldaptool_convdir
;
150 extern LDAPControl
*ldaptool_request_ctrls
[];
154 * function prototypes
156 void ldaptool_common_usage( int two_hosts
);
157 int ldaptool_process_args( int argc
, char **argv
, char *extra_opts
,
158 int two_hosts
, void (*extra_opt_callback
)( int option
, char *optarg
));
159 LDAP
*ldaptool_ldap_init( int second_host
);
160 void ldaptool_bind( LDAP
*ld
);
161 void ldaptool_cleanup( LDAP
*ld
);
162 int ldaptool_print_lderror( LDAP
*ld
, char *msg
, int check4ssl
);
163 #define LDAPTOOL_CHECK4SSL_NEVER 0
164 #define LDAPTOOL_CHECK4SSL_ALWAYS 1
165 #define LDAPTOOL_CHECK4SSL_IF_APPROP 2 /* if appropriate */
166 LDAPControl
*ldaptool_create_manage_dsait_control( void );
167 void ldaptool_print_referrals( char **refs
);
168 int ldaptool_print_extended_response( LDAP
*ld
, LDAPMessage
*res
, char *msg
);
169 LDAPControl
*ldaptool_create_proxyauth_control( LDAP
*ld
);
170 LDAPControl
*ldaptool_create_geteffectiveRights_control ( LDAP
*ld
,
172 const char **attrlist
);
173 void ldaptool_add_control_to_array( LDAPControl
*ctrl
, LDAPControl
**array
);
174 void ldaptool_reset_control_array( LDAPControl
**array
);
175 char *ldaptool_get_tmp_dir( void );
176 char *ldaptool_local2UTF8( const char * );
177 #ifdef SOLARIS_LDAP_CMD
178 char *ldaptool_UTF82local( const char * );
179 #endif /* SOLARIS_LDAP_CMD */
180 int ldaptool_berval_is_ascii( const struct berval
*bvp
);
181 int ldaptool_sasl_bind_s( LDAP
*ld
, const char *dn
, const char *mechanism
,
182 const struct berval
*cred
, LDAPControl
**serverctrls
,
183 LDAPControl
**clientctrls
, struct berval
**servercredp
, char *msg
);
184 int ldaptool_simple_bind_s( LDAP
*ld
, const char *dn
, const char *passwd
,
185 LDAPControl
**serverctrls
, LDAPControl
**clientctrls
, char *msg
);
186 int ldaptool_add_ext_s( LDAP
*ld
, const char *dn
, LDAPMod
**attrs
,
187 LDAPControl
**serverctrls
, LDAPControl
**clientctrls
, char *msg
);
188 int ldaptool_modify_ext_s( LDAP
*ld
, const char *dn
, LDAPMod
**mods
,
189 LDAPControl
**serverctrls
, LDAPControl
**clientctrls
, char *msg
);
190 int ldaptool_delete_ext_s( LDAP
*ld
, const char *dn
, LDAPControl
**serverctrls
,
191 LDAPControl
**clientctrls
, char *msg
);
192 int ldaptool_rename_s( LDAP
*ld
, const char *dn
, const char *newrdn
,
193 const char *newparent
, int deleteoldrdn
, LDAPControl
**serverctrls
,
194 LDAPControl
**clientctrls
, char *msg
);
195 int ldaptool_compare_ext_s( LDAP
*ld
, const char *dn
, const char *attrtype
,
196 const struct berval
*bvalue
, LDAPControl
**serverctrls
,
197 LDAPControl
**clientctrls
, char *msg
);
198 int ldaptool_boolean_str2value ( const char *s
, int strict
);
199 int ldaptool_parse_ctrl_arg ( char *ctrl_arg
, char sep
, char **ctrl_oid
,
200 int *ctrl_criticality
, char **ctrl_value
, int *vlen
);
201 FILE * ldaptool_open_file(const char *filename
, const char *mode
);
202 int ldaptool_check_ferror( FILE * stream
, const int ldap_err
, const char *msg
);
205 /* Definition for list in ldapdelete.c */
207 typedef struct Element
{ /* double-linked list data type */
208 struct Element
*right
;
209 struct Element
*left
;
213 typedef struct { /* generic double-linked list head */
219 void L_Init(Head
*list
);
220 void L_Insert(Element
*Node
, Head
*HeadNode
);
221 void L_Remove(Element
*Node
, Head
*HeadNode
);
227 #endif /* LDAPTOOL_H */