ldaptool.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <string.h>
  47. #include <errno.h>
  48. #include <sys/file.h>
  49. #include <sys/stat.h>
  50. #include <unistd.h>
  51. #define LDAPTOOL_MKTEMP( p ) mktemp( p )
  52. #ifdef LINUX
  53. #include <getopt.h> /* not always included from unistd.h */
  54. #endif
  55. #include <ctype.h>
  56. #include <sys/types.h>
  57. #include <sys/stat.h>
  58. #include <fcntl.h>
  59. #if defined(NET_SSL)
  60. #include <ssl.h>
  61. #endif
  62. #include <portable.h>
  63. #include <ldap.h>
  64. #include <ldaplog.h>
  65. #include <ldif.h>
  66. #ifdef __cplusplus
  67. extern "C" {
  68. #endif
  69. /*
  70. * shared macros, structures, etc.
  71. */
  72. #define LDAPTOOL_RESULT_IS_AN_ERROR( rc ) \
  73. ( (rc) != LDAP_SUCCESS && (rc) != LDAP_COMPARE_TRUE \
  74. && (rc) != LDAP_COMPARE_FALSE )
  75. #define LDAPTOOL_DEFSEP "=" /* used by ldapcmp and ldapsearch */
  76. #define LDAPTOOL_DEFHOST "localhost"
  77. #define LDAPTOOL_DEFCERTDBPATH "."
  78. #define LDAPTOOL_DEFKEYDBPATH "."
  79. #define LDAPTOOL_DEFREFHOPLIMIT 5
  80. #define LDAPTOOL_SAFEREALLOC( ptr, size ) ( ptr == NULL ? malloc( size ) : \
  81. realloc( ptr, size ))
  82. /* this defines the max number of control requests for the tools */
  83. #define CONTROL_REQUESTS 50
  84. /*
  85. * globals (defined in common.c)
  86. */
  87. extern char *ldaptool_host;
  88. extern char *ldaptool_host2;
  89. extern int ldaptool_port;
  90. extern int ldaptool_port2;
  91. extern int ldaptool_verbose;
  92. extern int ldaptool_not;
  93. extern int ldaptool_nobind;
  94. extern int ldaptool_noconv_passwd;
  95. extern char *ldaptool_progname;
  96. extern FILE *ldaptool_fp;
  97. extern char *ldaptool_charset;
  98. extern LDAPControl *ldaptool_request_ctrls[];
  99. #ifdef LDAP_DEBUG
  100. extern int ldaptool_dbg_lvl;
  101. #define LDAPToolDebug(lvl,fmt,arg1,arg2,arg3) if (lvl & ldaptool_dbg_lvl) { fprintf(stderr,fmt,arg1,arg2,arg3); }
  102. #else
  103. #define LDAPToolDebug(lvl,fmt,arg1,arg2,arg3)
  104. #endif /* LDAP_DEBUG */
  105. /*
  106. * function prototypes
  107. */
  108. void ldaptool_common_usage( int two_hosts );
  109. int ldaptool_process_args( int argc, char **argv, char *extra_opts,
  110. int two_hosts, void (*extra_opt_callback)( int option, char *optarg ));
  111. LDAP *ldaptool_ldap_init( int second_host );
  112. void ldaptool_bind( LDAP *ld );
  113. void ldaptool_cleanup( LDAP *ld );
  114. int ldaptool_print_lderror( LDAP *ld, char *msg, int check4ssl );
  115. #define LDAPTOOL_CHECK4SSL_NEVER 0
  116. #define LDAPTOOL_CHECK4SSL_ALWAYS 1
  117. #define LDAPTOOL_CHECK4SSL_IF_APPROP 2 /* if appropriate */
  118. LDAPControl *ldaptool_create_manage_dsait_control( void );
  119. void ldaptool_print_referrals( char **refs );
  120. int ldaptool_print_extended_response( LDAP *ld, LDAPMessage *res, char *msg );
  121. LDAPControl *ldaptool_create_proxyauth_control( LDAP *ld );
  122. LDAPControl *ldaptool_create_geteffectiveRights_control ( LDAP *ld,
  123. const char *authzid, const char **attrlist );
  124. void ldaptool_add_control_to_array( LDAPControl *ctrl, LDAPControl **array);
  125. void ldaptool_reset_control_array( LDAPControl **array );
  126. char *ldaptool_get_tmp_dir( void );
  127. char *ldaptool_local2UTF8( const char *s, const char *desc );
  128. char *ldaptool_getpass( const char *prompt );
  129. char *ldaptool_read_password( FILE *mod_password_fp );
  130. int ldaptool_berval_is_ascii( const struct berval *bvp );
  131. int ldaptool_sasl_bind_s( LDAP *ld, const char *dn, const char *mechanism,
  132. const struct berval *cred, LDAPControl **serverctrls,
  133. LDAPControl **clientctrls, struct berval **servercredp, char *msg );
  134. int ldaptool_simple_bind_s( LDAP *ld, const char *dn, const char *passwd,
  135. LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg );
  136. int ldaptool_add_ext_s( LDAP *ld, const char *dn, LDAPMod **attrs,
  137. LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg );
  138. int ldaptool_modify_ext_s( LDAP *ld, const char *dn, LDAPMod **mods,
  139. LDAPControl **serverctrls, LDAPControl **clientctrls, char *msg );
  140. int ldaptool_delete_ext_s( LDAP *ld, const char *dn, LDAPControl **serverctrls,
  141. LDAPControl **clientctrls, char *msg );
  142. int ldaptool_rename_s( LDAP *ld, const char *dn, const char *newrdn,
  143. const char *newparent, int deleteoldrdn, LDAPControl **serverctrls,
  144. LDAPControl **clientctrls, char *msg );
  145. int ldaptool_compare_ext_s( LDAP *ld, const char *dn, const char *attrtype,
  146. const struct berval *bvalue, LDAPControl **serverctrls,
  147. LDAPControl **clientctrls, char *msg );
  148. int ldaptool_boolean_str2value ( const char *s, int strict );
  149. int ldaptool_parse_ctrl_arg ( char *ctrl_arg, char sep, char **ctrl_oid,
  150. int *ctrl_criticality, char **ctrl_value, int *vlen);
  151. FILE *ldaptool_open_file ( const char *filename, const char * mode);
  152. #ifdef __cplusplus
  153. }
  154. #endif
  155. #endif /* LDAPTOOL_H */