xref: /illumos-gate/usr/src/cmd/ldap/common/ldaptool.h (revision 2983dda76a6d296fdb560c88114fe41caad1b84f)
1 /*
2  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
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/
11  *
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.
16  *
17  * The Original Code is Mozilla Communicator client code, released
18  * March 31, 1998.
19  *
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
23  * Rights Reserved.
24  *
25  * Contributor(s):
26  */
27 
28 #ifndef _LDAPTOOL_H
29 #define _LDAPTOOL_H
30 
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 :-) */
36 
37 #ifdef OSF1V4D
38 #ifndef __STDC__
39 #  define __STDC__
40 #endif /* __STDC__ */
41 #endif /* OSF1V4D */
42 
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #include <errno.h>
47 
48 #ifdef AIX
49 #include <strings.h>
50 #endif
51 
52 
53 #ifdef SCOOS
54 #include <sys/types.h>
55 #endif
56 
57 #ifdef _WINDOWS
58 #define WIN32_LEAN_AND_MEAN
59 #include <windows.h>
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 )
63 #else
64 #include <sys/file.h>
65 #include <sys/stat.h>
66 #include <unistd.h>
67 #define	LDAPTOOL_MKTEMP( p )	mktemp( p )
68 #endif
69 
70 #ifdef LINUX
71 #include <getopt.h>       /* not always included from unistd.h */
72 #endif
73 
74 #include <ctype.h>
75 
76 #ifndef SCOOS
77 #include <sys/types.h>
78 #endif
79 
80 #include <sys/stat.h>
81 #include <fcntl.h>
82 
83 #ifndef SOLARIS_LDAP_CMD
84 #if defined(NET_SSL)
85 #include <ssl.h>
86 #endif
87 
88 #if defined(NET_SSL)
89 #include <ldap_ssl.h>
90 #endif
91 
92 #ifndef NO_LIBLCACHE
93 #include <lcache.h>
94 #endif
95 
96 #include <ldappr.h>
97 #include <portable.h>
98 #endif	/* SOLARIS_LDAP_CMD */
99 
100 #include <ldap.h>
101 
102 #include <ldaplog.h>
103 #include <ldif.h>
104 
105 
106 #ifdef __cplusplus
107 extern "C" {
108 #endif
109 
110 
111 /*
112  * shared macros, structures, etc.
113  */
114 #define LDAPTOOL_RESULT_IS_AN_ERROR( rc ) \
115 		( (rc) != LDAP_SUCCESS && (rc) != LDAP_COMPARE_TRUE \
116 		&& (rc) != LDAP_COMPARE_FALSE )
117 
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
122 #else
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
128 
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
133 
134 /*
135  * globals (defined in common.c)
136  */
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[];
151 
152 
153 /*
154  * function prototypes
155  */
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,
171 													const char *authzid,
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 );
203 
204 
205 /* Definition for list in ldapdelete.c */
206 
207 typedef struct Element {       /* double-linked list data type */
208     struct Element *right;
209     struct Element *left;
210     char *data;
211 } Element;
212 
213 typedef struct {                /* generic double-linked list head */
214     Element *first;
215     Element *last;
216     long count;
217 } Head;
218 
219 void  L_Init(Head *list);
220 void  L_Insert(Element *Node, Head  *HeadNode);
221 void  L_Remove(Element *Node, Head *HeadNode);
222 
223 #ifdef __cplusplus
224 }
225 #endif
226 
227 #endif /* LDAPTOOL_H */
228