passthru.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /*
  42. * passthru.h - Pass Through Authentication shared definitions
  43. *
  44. */
  45. #ifndef _PASSTHRU_H_
  46. #define _PASSTHRU_H_
  47. #include <stdio.h>
  48. #include <string.h>
  49. #include <time.h>
  50. #include <sys/types.h>
  51. #include "portable.h"
  52. #include "slapi-plugin.h"
  53. #include <dirlite_strings.h> /* PLUGIN_MAGIC_VENDOR_STR */
  54. #include "dirver.h"
  55. #include <nspr.h>
  56. /* Private API: to get slapd_pr_strerror() and SLAPI_COMPONENT_NAME_NSPR */
  57. #include "slapi-private.h"
  58. /*
  59. * macros
  60. */
  61. #define PASSTHRU_PLUGIN_SUBSYSTEM "passthru-plugin" /* for logging */
  62. #define PASSTHRU_ASSERT( expr ) PR_ASSERT( expr )
  63. #define PASSTHRU_LDAP_CONN_ERROR( err ) ( (err) == LDAP_SERVER_DOWN || \
  64. (err) == LDAP_CONNECT_ERROR )
  65. #define PASSTHRU_OP_NOT_HANDLED 0
  66. #define PASSTHRU_OP_HANDLED 1
  67. #define PASSTHRU_CONN_TRIES 2
  68. /* #define PASSTHRU_VERBOSE_LOGGING */
  69. /* defaults */
  70. #define PASSTHRU_DEF_SRVR_MAXCONNECTIONS 3
  71. #define PASSTHRU_DEF_SRVR_MAXCONCURRENCY 5
  72. #define PASSTHRU_DEF_SRVR_TIMEOUT 300 /* seconds */
  73. #define PASSTHRU_DEF_SRVR_PROTOCOL_VERSION LDAP_VERSION3
  74. #define PASSTHRU_DEF_SRVR_CONNLIFETIME 0 /* seconds */
  75. #define PASSTHRU_DEF_SRVR_FAILOVERCONNLIFETIME 300 /* seconds */
  76. /*
  77. * structs
  78. */
  79. typedef struct passthrusuffix {
  80. int ptsuffix_len;
  81. char *ptsuffix_normsuffix; /* not case normalized */
  82. struct passthrusuffix *ptsuffix_next;
  83. } PassThruSuffix;
  84. typedef struct passthruconnection {
  85. LDAP *ptconn_ld;
  86. int ptconn_ldapversion;
  87. int ptconn_usecount;
  88. #define PASSTHRU_CONNSTATUS_OK 0
  89. #define PASSTHRU_CONNSTATUS_DOWN 1
  90. #define PASSTHRU_CONNSTATUS_STALE 2
  91. int ptconn_status;
  92. time_t ptconn_opentime;
  93. struct passthruconnection *ptconn_prev;
  94. struct passthruconnection *ptconn_next;
  95. } PassThruConnection;
  96. typedef struct passthruserver {
  97. char *ptsrvr_url; /* copy from argv[i] */
  98. char *ptsrvr_hostname;
  99. int ptsrvr_port;
  100. int ptsrvr_secure; /* use SSL? or TLS == 2 */
  101. int ptsrvr_ldapversion;
  102. int ptsrvr_maxconnections;
  103. int ptsrvr_maxconcurrency;
  104. int ptsrvr_connlifetime; /* in seconds */
  105. struct timeval *ptsrvr_timeout; /* for ldap_result() */
  106. PassThruSuffix *ptsrvr_suffixes;
  107. Slapi_CondVar *ptsrvr_connlist_cv;
  108. Slapi_Mutex *ptsrvr_connlist_mutex; /* protects connlist */
  109. int ptsrvr_connlist_count;
  110. PassThruConnection *ptsrvr_connlist;
  111. struct passthruserver *ptsrvr_next;
  112. } PassThruServer;
  113. typedef struct passthruconfig {
  114. PassThruServer *ptconfig_serverlist;
  115. } PassThruConfig;
  116. /*
  117. * public functions
  118. */
  119. /*
  120. * ptbind.c:
  121. */
  122. int passthru_simple_bind_s( Slapi_PBlock *pb, PassThruServer *srvr, int tries,
  123. char *dn, struct berval *creds, LDAPControl **reqctrls, int *lderrnop,
  124. char **matcheddnp, char **errmsgp, struct berval ***refurlsp,
  125. LDAPControl ***resctrlsp );
  126. /*
  127. * ptconfig.c:
  128. */
  129. int passthru_config( int argc, char **argv );
  130. PassThruConfig *passthru_get_config( void );
  131. /*
  132. * ptconn.c:
  133. */
  134. int passthru_dn2server( PassThruConfig *cfg, char *normdn,
  135. PassThruServer **srvrp );
  136. int passthru_get_connection( PassThruServer *srvr, LDAP **ldp );
  137. void passthru_release_connection( PassThruServer *srvr, LDAP *ld, int dispose );
  138. void passthru_close_all_connections( PassThruConfig *cfg );
  139. /*
  140. * ptutil.c:
  141. */
  142. struct berval **passthru_strs2bervals( char **ss );
  143. char ** passthru_bervals2strs( struct berval **bvs );
  144. void passthru_free_bervals( struct berval **bvs );
  145. char *passthru_urlparse_err2string( int err );
  146. #endif /* _PASSTHRU_H_ */