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