1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
3*0Sstevel@tonic-gate  * Use is subject to license terms.
4*0Sstevel@tonic-gate  */
5*0Sstevel@tonic-gate 
6*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
7*0Sstevel@tonic-gate 
8*0Sstevel@tonic-gate /*
9*0Sstevel@tonic-gate  * The contents of this file are subject to the Netscape Public
10*0Sstevel@tonic-gate  * License Version 1.1 (the "License"); you may not use this file
11*0Sstevel@tonic-gate  * except in compliance with the License. You may obtain a copy of
12*0Sstevel@tonic-gate  * the License at http://www.mozilla.org/NPL/
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * Software distributed under the License is distributed on an "AS
15*0Sstevel@tonic-gate  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
16*0Sstevel@tonic-gate  * implied. See the License for the specific language governing
17*0Sstevel@tonic-gate  * rights and limitations under the License.
18*0Sstevel@tonic-gate  *
19*0Sstevel@tonic-gate  * The Original Code is Mozilla Communicator client code, released
20*0Sstevel@tonic-gate  * March 31, 1998.
21*0Sstevel@tonic-gate  *
22*0Sstevel@tonic-gate  * The Initial Developer of the Original Code is Netscape
23*0Sstevel@tonic-gate  * Communications Corporation. Portions created by Netscape are
24*0Sstevel@tonic-gate  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
25*0Sstevel@tonic-gate  * Rights Reserved.
26*0Sstevel@tonic-gate  *
27*0Sstevel@tonic-gate  * Contributor(s):
28*0Sstevel@tonic-gate  */
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #ifndef _LDAPTOOL_H
31*0Sstevel@tonic-gate #define _LDAPTOOL_H
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate /* XXX:mhein The following is a workaround for the redefinition of */
34*0Sstevel@tonic-gate /*           const problem on OSF.  Fix to be provided by NSS */
35*0Sstevel@tonic-gate /*           This is a pretty benign workaround for us which */
36*0Sstevel@tonic-gate /*           should not cause problems in the future even if */
37*0Sstevel@tonic-gate /*           we forget to take it out :-) */
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate #ifdef OSF1V4D
40*0Sstevel@tonic-gate #ifndef __STDC__
41*0Sstevel@tonic-gate #  define __STDC__
42*0Sstevel@tonic-gate #endif /* __STDC__ */
43*0Sstevel@tonic-gate #endif /* OSF1V4D */
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate #include <stdio.h>
46*0Sstevel@tonic-gate #include <stdlib.h>
47*0Sstevel@tonic-gate #include <string.h>
48*0Sstevel@tonic-gate #include <errno.h>
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate #ifdef AIX
51*0Sstevel@tonic-gate #include <strings.h>
52*0Sstevel@tonic-gate #endif
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate #ifdef SCOOS
56*0Sstevel@tonic-gate #include <sys/types.h>
57*0Sstevel@tonic-gate #endif
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate #ifdef _WINDOWS
60*0Sstevel@tonic-gate #define WIN32_LEAN_AND_MEAN
61*0Sstevel@tonic-gate #include <windows.h>
62*0Sstevel@tonic-gate extern int getopt (int argc, char *const *argv, const char *optstring);
63*0Sstevel@tonic-gate #include <io.h> /* for _mktemp() */
64*0Sstevel@tonic-gate #define	LDAPTOOL_MKTEMP( p )	_mktemp( p )
65*0Sstevel@tonic-gate #else
66*0Sstevel@tonic-gate #include <sys/file.h>
67*0Sstevel@tonic-gate #include <sys/stat.h>
68*0Sstevel@tonic-gate #include <unistd.h>
69*0Sstevel@tonic-gate #define	LDAPTOOL_MKTEMP( p )	mktemp( p )
70*0Sstevel@tonic-gate #endif
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate #ifdef LINUX
73*0Sstevel@tonic-gate #include <getopt.h>       /* not always included from unistd.h */
74*0Sstevel@tonic-gate #endif
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate #include <ctype.h>
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate #ifndef SCOOS
79*0Sstevel@tonic-gate #include <sys/types.h>
80*0Sstevel@tonic-gate #endif
81*0Sstevel@tonic-gate 
82*0Sstevel@tonic-gate #include <sys/stat.h>
83*0Sstevel@tonic-gate #include <fcntl.h>
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate #ifndef SOLARIS_LDAP_CMD
86*0Sstevel@tonic-gate #if defined(NET_SSL)
87*0Sstevel@tonic-gate #include <ssl.h>
88*0Sstevel@tonic-gate #endif
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate #if defined(NET_SSL)
91*0Sstevel@tonic-gate #include <ldap_ssl.h>
92*0Sstevel@tonic-gate #endif
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate #ifndef NO_LIBLCACHE
95*0Sstevel@tonic-gate #include <lcache.h>
96*0Sstevel@tonic-gate #endif
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate #include <ldappr.h>
99*0Sstevel@tonic-gate #include <portable.h>
100*0Sstevel@tonic-gate #endif	/* SOLARIS_LDAP_CMD */
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate #include <ldap.h>
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate #include <ldaplog.h>
105*0Sstevel@tonic-gate #include <ldif.h>
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate #ifdef __cplusplus
109*0Sstevel@tonic-gate extern "C" {
110*0Sstevel@tonic-gate #endif
111*0Sstevel@tonic-gate 
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate /*
114*0Sstevel@tonic-gate  * shared macros, structures, etc.
115*0Sstevel@tonic-gate  */
116*0Sstevel@tonic-gate #define LDAPTOOL_RESULT_IS_AN_ERROR( rc ) \
117*0Sstevel@tonic-gate 		( (rc) != LDAP_SUCCESS && (rc) != LDAP_COMPARE_TRUE \
118*0Sstevel@tonic-gate 		&& (rc) != LDAP_COMPARE_FALSE )
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate #define LDAPTOOL_DEFSEP		"="	/* used by ldapcmp and ldapsearch */
121*0Sstevel@tonic-gate #define LDAPTOOL_DEFHOST	"localhost"
122*0Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD
123*0Sstevel@tonic-gate #define LDAPTOOL_DEFSSLSTRENGTH LDAPSSL_AUTH_CNCHECK
124*0Sstevel@tonic-gate #else
125*0Sstevel@tonic-gate #define	LDAPTOOL_DEFSSLSTRENGTH LDAPSSL_AUTH_CERT
126*0Sstevel@tonic-gate #endif	/* SOLARIS_LDAP_CMD */
127*0Sstevel@tonic-gate #define LDAPTOOL_DEFCERTDBPATH	"."
128*0Sstevel@tonic-gate #define LDAPTOOL_DEFKEYDBPATH	"."
129*0Sstevel@tonic-gate #define LDAPTOOL_DEFREFHOPLIMIT		5
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate #define LDAPTOOL_SAFEREALLOC( ptr, size )  ( ptr == NULL ? malloc( size ) : \
132*0Sstevel@tonic-gate 						realloc( ptr, size ))
133*0Sstevel@tonic-gate /* this defines the max number of control requests for the tools */
134*0Sstevel@tonic-gate #define CONTROL_REQUESTS 50
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate /*
137*0Sstevel@tonic-gate  * globals (defined in common.c)
138*0Sstevel@tonic-gate  */
139*0Sstevel@tonic-gate extern char		*ldaptool_host;
140*0Sstevel@tonic-gate extern char		*ldaptool_host2;
141*0Sstevel@tonic-gate extern int		ldaptool_port;
142*0Sstevel@tonic-gate extern int		ldaptool_port2;
143*0Sstevel@tonic-gate extern int		ldaptool_verbose;
144*0Sstevel@tonic-gate extern int		ldaptool_not;
145*0Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD
146*0Sstevel@tonic-gate extern int		ldaptool_require_binddn;
147*0Sstevel@tonic-gate #endif	/* SOLARIS_LDAP_CMD */
148*0Sstevel@tonic-gate extern char		*ldaptool_progname;
149*0Sstevel@tonic-gate extern FILE		*ldaptool_fp;
150*0Sstevel@tonic-gate extern char		*ldaptool_charset;
151*0Sstevel@tonic-gate extern char		*ldaptool_convdir;
152*0Sstevel@tonic-gate extern LDAPControl	*ldaptool_request_ctrls[];
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate 
155*0Sstevel@tonic-gate /*
156*0Sstevel@tonic-gate  * function prototypes
157*0Sstevel@tonic-gate  */
158*0Sstevel@tonic-gate void ldaptool_common_usage( int two_hosts );
159*0Sstevel@tonic-gate int ldaptool_process_args( int argc, char **argv, char *extra_opts,
160*0Sstevel@tonic-gate 	int two_hosts, void (*extra_opt_callback)( int option, char *optarg ));
161*0Sstevel@tonic-gate LDAP *ldaptool_ldap_init( int second_host );
162*0Sstevel@tonic-gate void ldaptool_bind( LDAP *ld );
163*0Sstevel@tonic-gate void ldaptool_cleanup( LDAP *ld );
164*0Sstevel@tonic-gate int ldaptool_print_lderror( LDAP *ld, char *msg, int check4ssl );
165*0Sstevel@tonic-gate #define LDAPTOOL_CHECK4SSL_NEVER	0
166*0Sstevel@tonic-gate #define LDAPTOOL_CHECK4SSL_ALWAYS	1
167*0Sstevel@tonic-gate #define LDAPTOOL_CHECK4SSL_IF_APPROP	2	/* if appropriate */
168*0Sstevel@tonic-gate LDAPControl *ldaptool_create_manage_dsait_control( void );
169*0Sstevel@tonic-gate void ldaptool_print_referrals( char **refs );
170*0Sstevel@tonic-gate int ldaptool_print_extended_response( LDAP *ld, LDAPMessage *res, char *msg );
171*0Sstevel@tonic-gate LDAPControl *ldaptool_create_proxyauth_control( LDAP *ld );
172*0Sstevel@tonic-gate LDAPControl *ldaptool_create_geteffectiveRights_control ( LDAP *ld,
173*0Sstevel@tonic-gate 													const char *authzid,
174*0Sstevel@tonic-gate 													const char **attrlist );
175*0Sstevel@tonic-gate void ldaptool_add_control_to_array( LDAPControl *ctrl, LDAPControl **array);
176*0Sstevel@tonic-gate void ldaptool_reset_control_array( LDAPControl **array );
177*0Sstevel@tonic-gate char *ldaptool_get_tmp_dir( void );
178*0Sstevel@tonic-gate char *ldaptool_local2UTF8( const char * );
179*0Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD
180*0Sstevel@tonic-gate char *ldaptool_UTF82local( const char * );
181*0Sstevel@tonic-gate #endif	/* SOLARIS_LDAP_CMD */
182*0Sstevel@tonic-gate int ldaptool_berval_is_ascii( const struct berval *bvp );
183*0Sstevel@tonic-gate int ldaptool_sasl_bind_s( LDAP *ld, const char *dn, const char *mechanism,
184*0Sstevel@tonic-gate         const struct berval *cred, LDAPControl **serverctrls,
185*0Sstevel@tonic-gate         LDAPControl **clientctrls, struct berval **servercredp, char *msg );
186*0Sstevel@tonic-gate int ldaptool_simple_bind_s( LDAP *ld, const char *dn, const char *passwd,
187*0Sstevel@tonic-gate 	LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg );
188*0Sstevel@tonic-gate int ldaptool_add_ext_s( LDAP *ld, const char *dn, LDAPMod **attrs,
189*0Sstevel@tonic-gate         LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg );
190*0Sstevel@tonic-gate int ldaptool_modify_ext_s( LDAP *ld, const char *dn, LDAPMod **mods,
191*0Sstevel@tonic-gate         LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg );
192*0Sstevel@tonic-gate int ldaptool_delete_ext_s( LDAP *ld, const char *dn, LDAPControl **serverctrls,
193*0Sstevel@tonic-gate         LDAPControl **clientctrls, char *msg );
194*0Sstevel@tonic-gate int ldaptool_rename_s(  LDAP *ld, const char *dn, const char *newrdn,
195*0Sstevel@tonic-gate         const char *newparent, int deleteoldrdn, LDAPControl **serverctrls,
196*0Sstevel@tonic-gate         LDAPControl **clientctrls, char *msg );
197*0Sstevel@tonic-gate int ldaptool_compare_ext_s( LDAP *ld, const char *dn, const char *attrtype,
198*0Sstevel@tonic-gate 	    const struct berval *bvalue, LDAPControl **serverctrls,
199*0Sstevel@tonic-gate 	    LDAPControl **clientctrls, char *msg );
200*0Sstevel@tonic-gate int ldaptool_boolean_str2value ( const char *s, int strict );
201*0Sstevel@tonic-gate int ldaptool_parse_ctrl_arg ( char *ctrl_arg, char sep, char **ctrl_oid,
202*0Sstevel@tonic-gate 	    int *ctrl_criticality, char **ctrl_value, int *vlen);
203*0Sstevel@tonic-gate FILE * ldaptool_open_file(const char *filename, const char *mode);
204*0Sstevel@tonic-gate 
205*0Sstevel@tonic-gate 
206*0Sstevel@tonic-gate /* Definition for list in ldapdelete.c */
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate typedef struct Element {       /* double-linked list data type */
209*0Sstevel@tonic-gate     struct Element *right;
210*0Sstevel@tonic-gate     struct Element *left;
211*0Sstevel@tonic-gate     char *data;
212*0Sstevel@tonic-gate } Element;
213*0Sstevel@tonic-gate 
214*0Sstevel@tonic-gate typedef struct {                /* generic double-linked list head */
215*0Sstevel@tonic-gate     Element *first;
216*0Sstevel@tonic-gate     Element *last;
217*0Sstevel@tonic-gate     long count;
218*0Sstevel@tonic-gate } Head;
219*0Sstevel@tonic-gate 
220*0Sstevel@tonic-gate void  L_Init(Head *list);
221*0Sstevel@tonic-gate void  L_Insert(Element *Node, Head  *HeadNode);
222*0Sstevel@tonic-gate void  L_Remove(Element *Node, Head *HeadNode);
223*0Sstevel@tonic-gate 
224*0Sstevel@tonic-gate #ifdef __cplusplus
225*0Sstevel@tonic-gate }
226*0Sstevel@tonic-gate #endif
227*0Sstevel@tonic-gate 
228*0Sstevel@tonic-gate #endif /* LDAPTOOL_H */
229