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