ldaptool.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is Mozilla Communicator client code, released
  15. * March 31, 1998.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998-1999
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either of the GNU General Public License Version 2 or later (the "GPL"),
  26. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. #ifndef _LDAPTOOL_H
  38. #define _LDAPTOOL_H
  39. /* XXX:mhein The following is a workaround for the redefinition of */
  40. /* const problem on OSF. Fix to be provided by NSS */
  41. /* This is a pretty benign workaround for us which */
  42. /* should not cause problems in the future even if */
  43. /* we forget to take it out :-) */
  44. #ifdef OSF1V4D
  45. #ifndef __STDC__
  46. # define __STDC__
  47. #endif /* __STDC__ */
  48. #endif /* OSF1V4D */
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include <string.h>
  52. #include <errno.h>
  53. #ifdef AIX
  54. #include <strings.h>
  55. #endif
  56. #ifdef SCOOS
  57. #include <sys/types.h>
  58. #endif
  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. #ifdef LINUX
  72. #include <getopt.h> /* not always included from unistd.h */
  73. #endif
  74. #include <ctype.h>
  75. #ifndef SCOOS
  76. #include <sys/types.h>
  77. #endif
  78. #include <sys/stat.h>
  79. #include <fcntl.h>
  80. #if defined(NET_SSL)
  81. #include <ssl.h>
  82. #endif
  83. #include <portable.h>
  84. #include <ldap.h>
  85. #include <ldaplog.h>
  86. #include <ldif.h>
  87. #if defined(NET_SSL)
  88. #include <ldap_ssl.h>
  89. #endif
  90. #include <ldappr.h>
  91. #ifdef __cplusplus
  92. extern "C" {
  93. #endif
  94. /*
  95. * shared macros, structures, etc.
  96. */
  97. #define LDAPTOOL_RESULT_IS_AN_ERROR( rc ) \
  98. ( (rc) != LDAP_SUCCESS && (rc) != LDAP_COMPARE_TRUE \
  99. && (rc) != LDAP_COMPARE_FALSE )
  100. #define LDAPTOOL_DEFSEP "=" /* used by ldapcmp and ldapsearch */
  101. #define LDAPTOOL_DEFHOST "localhost"
  102. #define LDAPTOOL_DEFSSLSTRENGTH LDAPSSL_AUTH_CERT
  103. #define LDAPTOOL_DEFCERTDBPATH "."
  104. #define LDAPTOOL_DEFKEYDBPATH "."
  105. #define LDAPTOOL_DEFREFHOPLIMIT 5
  106. #define LDAPTOOL_SAFEREALLOC( ptr, size ) ( ptr == NULL ? malloc( size ) : \
  107. realloc( ptr, size ))
  108. /* this defines the max number of control requests for the tools */
  109. #define CONTROL_REQUESTS 50
  110. /*
  111. * globals (defined in common.c)
  112. */
  113. extern char *ldaptool_host;
  114. extern char *ldaptool_host2;
  115. extern int ldaptool_port;
  116. extern int ldaptool_port2;
  117. extern int ldaptool_verbose;
  118. extern int ldaptool_not;
  119. extern int ldaptool_nobind;
  120. extern int ldaptool_noconv_passwd;
  121. extern char *ldaptool_progname;
  122. extern FILE *ldaptool_fp;
  123. extern char *ldaptool_charset;
  124. extern LDAPControl *ldaptool_request_ctrls[];
  125. #ifdef LDAP_DEBUG
  126. extern int ldaptool_dbg_lvl;
  127. #define LDAPToolDebug(lvl,fmt,arg1,arg2,arg3) if (lvl & ldaptool_dbg_lvl) { fprintf(stderr,fmt,arg1,arg2,arg3); }
  128. #else
  129. #define LDAPToolDebug(lvl,fmt,arg1,arg2,arg3)
  130. #endif /* LDAP_DEBUG */
  131. /*
  132. * function prototypes
  133. */
  134. void ldaptool_common_usage( int two_hosts );
  135. int ldaptool_process_args( int argc, char **argv, char *extra_opts,
  136. int two_hosts, void (*extra_opt_callback)( int option, char *optarg ));
  137. LDAP *ldaptool_ldap_init( int second_host );
  138. void ldaptool_bind( LDAP *ld );
  139. void ldaptool_cleanup( LDAP *ld );
  140. int ldaptool_print_lderror( LDAP *ld, char *msg, int check4ssl );
  141. #define LDAPTOOL_CHECK4SSL_NEVER 0
  142. #define LDAPTOOL_CHECK4SSL_ALWAYS 1
  143. #define LDAPTOOL_CHECK4SSL_IF_APPROP 2 /* if appropriate */
  144. LDAPControl *ldaptool_create_manage_dsait_control( void );
  145. void ldaptool_print_referrals( char **refs );
  146. int ldaptool_print_extended_response( LDAP *ld, LDAPMessage *res, char *msg );
  147. LDAPControl *ldaptool_create_proxyauth_control( LDAP *ld );
  148. LDAPControl *ldaptool_create_geteffectiveRights_control ( LDAP *ld,
  149. const char *authzid, const char **attrlist );
  150. void ldaptool_add_control_to_array( LDAPControl *ctrl, LDAPControl **array);
  151. void ldaptool_reset_control_array( LDAPControl **array );
  152. char *ldaptool_get_tmp_dir( void );
  153. char *ldaptool_local2UTF8( const char *s, const char *desc );
  154. char *ldaptool_getpass( const char *prompt );
  155. char *ldaptool_read_password( FILE *mod_password_fp );
  156. int ldaptool_berval_is_ascii( const struct berval *bvp );
  157. int ldaptool_sasl_bind_s( LDAP *ld, const char *dn, const char *mechanism,
  158. const struct berval *cred, LDAPControl **serverctrls,
  159. LDAPControl **clientctrls, struct berval **servercredp, char *msg );
  160. int ldaptool_simple_bind_s( LDAP *ld, const char *dn, const char *passwd,
  161. LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg );
  162. int ldaptool_add_ext_s( LDAP *ld, const char *dn, LDAPMod **attrs,
  163. LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg );
  164. int ldaptool_modify_ext_s( LDAP *ld, const char *dn, LDAPMod **mods,
  165. LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg );
  166. int ldaptool_delete_ext_s( LDAP *ld, const char *dn, LDAPControl **serverctrls,
  167. LDAPControl **clientctrls, char *msg );
  168. int ldaptool_rename_s( LDAP *ld, const char *dn, const char *newrdn,
  169. const char *newparent, int deleteoldrdn, LDAPControl **serverctrls,
  170. LDAPControl **clientctrls, char *msg );
  171. int ldaptool_compare_ext_s( LDAP *ld, const char *dn, const char *attrtype,
  172. const struct berval *bvalue, LDAPControl **serverctrls,
  173. LDAPControl **clientctrls, char *msg );
  174. int ldaptool_boolean_str2value ( const char *s, int strict );
  175. int ldaptool_parse_ctrl_arg ( char *ctrl_arg, char sep, char **ctrl_oid,
  176. int *ctrl_criticality, char **ctrl_value, int *vlen);
  177. FILE *ldaptool_open_file ( const char *filename, const char * mode);
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. #endif /* LDAPTOOL_H */