mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-24 13:24:56 +08:00
listener:
- use bervals for url and sockname - pass connection_init() the listener struct pointer instead of each value - don't copy them in the Connection struct 'cause they're not going to change - define macros for legacy usage of c_listener_url and c_sockname
This commit is contained in:
parent
26e1043576
commit
956f1d16aa
@ -99,9 +99,8 @@ monitor_subsys_listener_init(
|
|||||||
i,
|
i,
|
||||||
monitor_subsys[SLAPD_MONITOR_LISTENER].mss_dn.bv_val,
|
monitor_subsys[SLAPD_MONITOR_LISTENER].mss_dn.bv_val,
|
||||||
i,
|
i,
|
||||||
l[i]->sl_name,
|
l[i]->sl_name.bv_val,
|
||||||
|
l[i]->sl_url.bv_val );
|
||||||
l[i]->sl_url );
|
|
||||||
|
|
||||||
e = str2entry( buf );
|
e = str2entry( buf );
|
||||||
if ( e == NULL ) {
|
if ( e == NULL ) {
|
||||||
|
@ -320,10 +320,9 @@ static void connection_return( Connection *c )
|
|||||||
|
|
||||||
long connection_init(
|
long connection_init(
|
||||||
ber_socket_t s,
|
ber_socket_t s,
|
||||||
const char* url,
|
Listener *listener,
|
||||||
const char* dnsname,
|
const char* dnsname,
|
||||||
const char* peername,
|
const char* peername,
|
||||||
const char* sockname,
|
|
||||||
int tls_udp_option,
|
int tls_udp_option,
|
||||||
slap_ssf_t ssf,
|
slap_ssf_t ssf,
|
||||||
const char *authid )
|
const char *authid )
|
||||||
@ -333,9 +332,9 @@ long connection_init(
|
|||||||
|
|
||||||
assert( connections != NULL );
|
assert( connections != NULL );
|
||||||
|
|
||||||
|
assert( listener != NULL );
|
||||||
assert( dnsname != NULL );
|
assert( dnsname != NULL );
|
||||||
assert( peername != NULL );
|
assert( peername != NULL );
|
||||||
assert( sockname != NULL );
|
|
||||||
|
|
||||||
#ifndef HAVE_TLS
|
#ifndef HAVE_TLS
|
||||||
assert( tls_udp_option != 1 );
|
assert( tls_udp_option != 1 );
|
||||||
@ -420,14 +419,11 @@ long connection_init(
|
|||||||
c->c_ndn.bv_len = 0;
|
c->c_ndn.bv_len = 0;
|
||||||
c->c_groups = NULL;
|
c->c_groups = NULL;
|
||||||
|
|
||||||
c->c_listener_url.bv_val = NULL;
|
c->c_listener = NULL;
|
||||||
c->c_listener_url.bv_len = 0;
|
|
||||||
c->c_peer_domain.bv_val = NULL;
|
c->c_peer_domain.bv_val = NULL;
|
||||||
c->c_peer_domain.bv_len = 0;
|
c->c_peer_domain.bv_len = 0;
|
||||||
c->c_peer_name.bv_val = NULL;
|
c->c_peer_name.bv_val = NULL;
|
||||||
c->c_peer_name.bv_len = 0;
|
c->c_peer_name.bv_len = 0;
|
||||||
c->c_sock_name.bv_val = NULL;
|
|
||||||
c->c_sock_name.bv_len = 0;
|
|
||||||
|
|
||||||
LDAP_STAILQ_INIT(&c->c_ops);
|
LDAP_STAILQ_INIT(&c->c_ops);
|
||||||
LDAP_STAILQ_INIT(&c->c_pending_ops);
|
LDAP_STAILQ_INIT(&c->c_pending_ops);
|
||||||
@ -462,10 +458,9 @@ long connection_init(
|
|||||||
assert( c->c_dn.bv_val == NULL );
|
assert( c->c_dn.bv_val == NULL );
|
||||||
assert( c->c_ndn.bv_val == NULL );
|
assert( c->c_ndn.bv_val == NULL );
|
||||||
assert( c->c_groups == NULL );
|
assert( c->c_groups == NULL );
|
||||||
assert( c->c_listener_url.bv_val == NULL );
|
assert( c->c_listener == NULL );
|
||||||
assert( c->c_peer_domain.bv_val == NULL );
|
assert( c->c_peer_domain.bv_val == NULL );
|
||||||
assert( c->c_peer_name.bv_val == NULL );
|
assert( c->c_peer_name.bv_val == NULL );
|
||||||
assert( c->c_sock_name.bv_val == NULL );
|
|
||||||
assert( LDAP_STAILQ_EMPTY(&c->c_ops) );
|
assert( LDAP_STAILQ_EMPTY(&c->c_ops) );
|
||||||
assert( LDAP_STAILQ_EMPTY(&c->c_pending_ops) );
|
assert( LDAP_STAILQ_EMPTY(&c->c_pending_ops) );
|
||||||
assert( c->c_sasl_bind_mech.bv_val == NULL );
|
assert( c->c_sasl_bind_mech.bv_val == NULL );
|
||||||
@ -474,10 +469,9 @@ long connection_init(
|
|||||||
assert( c->c_sasl_bindop == NULL );
|
assert( c->c_sasl_bindop == NULL );
|
||||||
assert( c->c_currentber == NULL );
|
assert( c->c_currentber == NULL );
|
||||||
|
|
||||||
ber_str2bv( url, 0, 1, &c->c_listener_url );
|
c->c_listener = listener;
|
||||||
ber_str2bv( dnsname, 0, 1, &c->c_peer_domain );
|
ber_str2bv( dnsname, 0, 1, &c->c_peer_domain );
|
||||||
ber_str2bv( peername, 0, 1, &c->c_peer_name );
|
ber_str2bv( peername, 0, 1, &c->c_peer_name );
|
||||||
ber_str2bv( sockname, 0, 1, &c->c_sock_name );
|
|
||||||
|
|
||||||
c->c_n_ops_received = 0;
|
c->c_n_ops_received = 0;
|
||||||
c->c_n_ops_executing = 0;
|
c->c_n_ops_executing = 0;
|
||||||
@ -633,12 +627,7 @@ connection_destroy( Connection *c )
|
|||||||
c->c_activitytime = c->c_starttime = 0;
|
c->c_activitytime = c->c_starttime = 0;
|
||||||
|
|
||||||
connection2anonymous( c );
|
connection2anonymous( c );
|
||||||
|
c->c_listener = NULL;
|
||||||
if(c->c_listener_url.bv_val != NULL) {
|
|
||||||
free(c->c_listener_url.bv_val);
|
|
||||||
c->c_listener_url.bv_val = NULL;
|
|
||||||
}
|
|
||||||
c->c_listener_url.bv_len = 0;
|
|
||||||
|
|
||||||
if(c->c_peer_domain.bv_val != NULL) {
|
if(c->c_peer_domain.bv_val != NULL) {
|
||||||
free(c->c_peer_domain.bv_val);
|
free(c->c_peer_domain.bv_val);
|
||||||
@ -666,11 +655,6 @@ connection_destroy( Connection *c )
|
|||||||
c->c_peer_name.bv_val = NULL;
|
c->c_peer_name.bv_val = NULL;
|
||||||
}
|
}
|
||||||
c->c_peer_name.bv_len = 0;
|
c->c_peer_name.bv_len = 0;
|
||||||
if(c->c_sock_name.bv_val != NULL) {
|
|
||||||
free(c->c_sock_name.bv_val);
|
|
||||||
c->c_sock_name.bv_val = NULL;
|
|
||||||
}
|
|
||||||
c->c_sock_name.bv_len = 0;
|
|
||||||
|
|
||||||
c->c_sasl_bind_in_progress = 0;
|
c->c_sasl_bind_in_progress = 0;
|
||||||
if(c->c_sasl_bind_mech.bv_val != NULL) {
|
if(c->c_sasl_bind_mech.bv_val != NULL) {
|
||||||
|
@ -588,6 +588,9 @@ static int slap_open_listener(
|
|||||||
int socktype = SOCK_STREAM; /* default to COTS */
|
int socktype = SOCK_STREAM; /* default to COTS */
|
||||||
|
|
||||||
#ifdef LDAP_PF_LOCAL
|
#ifdef LDAP_PF_LOCAL
|
||||||
|
/*
|
||||||
|
* use safe defaults
|
||||||
|
*/
|
||||||
mode_t perms = S_IRWXU;
|
mode_t perms = S_IRWXU;
|
||||||
int crit = 1;
|
int crit = 1;
|
||||||
#endif
|
#endif
|
||||||
@ -607,7 +610,7 @@ static int slap_open_listener(
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
l.sl_url = NULL;
|
l.sl_url.bv_val = NULL;
|
||||||
|
|
||||||
#ifndef HAVE_TLS
|
#ifndef HAVE_TLS
|
||||||
if( ldap_pvt_url_scheme2tls( lud->lud_scheme ) ) {
|
if( ldap_pvt_url_scheme2tls( lud->lud_scheme ) ) {
|
||||||
@ -831,8 +834,10 @@ static int slap_open_listener(
|
|||||||
slap_free_listener_addresses(psal);
|
slap_free_listener_addresses(psal);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
l.sl_name = ch_malloc( strlen(addr) + sizeof("PATH=") );
|
l.sl_name.bv_len = strlen(addr) + sizeof("PATH=") - 1;
|
||||||
sprintf( l.sl_name, "PATH=%s", addr );
|
l.sl_name.bv_val = ber_memalloc( l.sl_name.bv_len + 1 );
|
||||||
|
snprintf( l.sl_name.bv_val, l.sl_name.bv_len + 1,
|
||||||
|
"PATH=%s", addr );
|
||||||
} break;
|
} break;
|
||||||
#endif /* LDAP_PF_LOCAL */
|
#endif /* LDAP_PF_LOCAL */
|
||||||
|
|
||||||
@ -847,9 +852,11 @@ static int slap_open_listener(
|
|||||||
s = inet_ntoa( ((struct sockaddr_in *) *sal)->sin_addr );
|
s = inet_ntoa( ((struct sockaddr_in *) *sal)->sin_addr );
|
||||||
#endif
|
#endif
|
||||||
port = ntohs( ((struct sockaddr_in *)*sal) ->sin_port );
|
port = ntohs( ((struct sockaddr_in *)*sal) ->sin_port );
|
||||||
l.sl_name = ch_malloc( sizeof("IP=255.255.255.255:65535") );
|
l.sl_name.bv_val = ber_memalloc( sizeof("IP=255.255.255.255:65535") );
|
||||||
sprintf( l.sl_name, "IP=%s:%d",
|
snprintf( l.sl_name.bv_val, sizeof("IP=255.255.255.255:65535"),
|
||||||
|
"IP=%s:%d",
|
||||||
s != NULL ? s : "unknown" , port );
|
s != NULL ? s : "unknown" , port );
|
||||||
|
l.sl_name.bv_len = strlen( l.sl_name.bv_val );
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
#ifdef LDAP_PF_INET6
|
#ifdef LDAP_PF_INET6
|
||||||
@ -858,8 +865,11 @@ static int slap_open_listener(
|
|||||||
inet_ntop( AF_INET6, &((struct sockaddr_in6 *)*sal)->sin6_addr,
|
inet_ntop( AF_INET6, &((struct sockaddr_in6 *)*sal)->sin6_addr,
|
||||||
addr, sizeof addr);
|
addr, sizeof addr);
|
||||||
port = ntohs( ((struct sockaddr_in6 *)*sal)->sin6_port );
|
port = ntohs( ((struct sockaddr_in6 *)*sal)->sin6_port );
|
||||||
l.sl_name = ch_malloc( strlen(addr) + sizeof("IP= 65535") );
|
l.sl_name.bv_len = strlen(addr) + sizeof("IP= 65535");
|
||||||
sprintf( l.sl_name, "IP=%s %d", addr, port );
|
l.sl_name.bv_val = ber_memalloc( l.sl_name.bv_len );
|
||||||
|
snprintf( l.sl_name.bv_val, l.sl_name.bv_len, "IP=%s %d",
|
||||||
|
addr, port );
|
||||||
|
l.sl_name.bv_len = strlen( l.sl_name.bv_val );
|
||||||
} break;
|
} break;
|
||||||
#endif /* LDAP_PF_INET6 */
|
#endif /* LDAP_PF_INET6 */
|
||||||
|
|
||||||
@ -876,7 +886,7 @@ static int slap_open_listener(
|
|||||||
}
|
}
|
||||||
|
|
||||||
AC_MEMCPY(&l.sl_sa, *sal, addrlen);
|
AC_MEMCPY(&l.sl_sa, *sal, addrlen);
|
||||||
l.sl_url = ch_strdup( url );
|
ber_str2bv( url, 0, 1, &l.sl_url);
|
||||||
li = ch_malloc( sizeof( Listener ) );
|
li = ch_malloc( sizeof( Listener ) );
|
||||||
*li = l;
|
*li = l;
|
||||||
slap_listeners[*cur] = li;
|
slap_listeners[*cur] = li;
|
||||||
@ -887,7 +897,7 @@ static int slap_open_listener(
|
|||||||
|
|
||||||
slap_free_listener_addresses(psal);
|
slap_free_listener_addresses(psal);
|
||||||
|
|
||||||
if ( l.sl_url == NULL )
|
if ( l.sl_url.bv_val == NULL )
|
||||||
{
|
{
|
||||||
#ifdef NEW_LOGGING
|
#ifdef NEW_LOGGING
|
||||||
LDAP_LOG( CONNECTION, RESULTS,
|
LDAP_LOG( CONNECTION, RESULTS,
|
||||||
@ -901,10 +911,11 @@ static int slap_open_listener(
|
|||||||
|
|
||||||
#ifdef NEW_LOGGING
|
#ifdef NEW_LOGGING
|
||||||
LDAP_LOG( CONNECTION, RESULTS,
|
LDAP_LOG( CONNECTION, RESULTS,
|
||||||
"slap_open_listener: daemon initialized %s\n", l.sl_url, 0, 0 );
|
"slap_open_listener: daemon initialized %s\n",
|
||||||
|
l.sl_url.bv_val, 0, 0 );
|
||||||
#else
|
#else
|
||||||
Debug( LDAP_DEBUG_TRACE, "daemon: initialized %s\n",
|
Debug( LDAP_DEBUG_TRACE, "daemon: initialized %s\n",
|
||||||
l.sl_url, 0, 0 );
|
l.sl_url.bv_val, 0, 0 );
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1071,10 +1082,10 @@ close_listeners(
|
|||||||
#endif /* LDAP_PF_LOCAL */
|
#endif /* LDAP_PF_LOCAL */
|
||||||
slapd_close( slap_listeners[l]->sl_sd );
|
slapd_close( slap_listeners[l]->sl_sd );
|
||||||
}
|
}
|
||||||
if ( slap_listeners[l]->sl_url )
|
if ( slap_listeners[l]->sl_url.bv_val )
|
||||||
free ( slap_listeners[l]->sl_url );
|
ber_memfree( slap_listeners[l]->sl_url.bv_val );
|
||||||
if ( slap_listeners[l]->sl_name )
|
if ( slap_listeners[l]->sl_name.bv_val )
|
||||||
free ( slap_listeners[l]->sl_name );
|
ber_memfree( slap_listeners[l]->sl_name.bv_val );
|
||||||
free ( slap_listeners[l] );
|
free ( slap_listeners[l] );
|
||||||
slap_listeners[l] = NULL;
|
slap_listeners[l] = NULL;
|
||||||
}
|
}
|
||||||
@ -1149,11 +1160,11 @@ slapd_daemon_task(
|
|||||||
#ifdef NEW_LOGGING
|
#ifdef NEW_LOGGING
|
||||||
LDAP_LOG( CONNECTION, ERR,
|
LDAP_LOG( CONNECTION, ERR,
|
||||||
"slapd_daemon_task: listen( %s, 5 ) failed errno=%d (%s)\n",
|
"slapd_daemon_task: listen( %s, 5 ) failed errno=%d (%s)\n",
|
||||||
slap_listeners[l]->sl_url, err, sock_errstr(err) );
|
slap_listeners[l]->sl_url.bv_val, err, sock_errstr(err) );
|
||||||
#else
|
#else
|
||||||
Debug( LDAP_DEBUG_ANY,
|
Debug( LDAP_DEBUG_ANY,
|
||||||
"daemon: listen(%s, 5) failed errno=%d (%s)\n",
|
"daemon: listen(%s, 5) failed errno=%d (%s)\n",
|
||||||
slap_listeners[l]->sl_url, err,
|
slap_listeners[l]->sl_url.bv_val, err,
|
||||||
sock_errstr(err) );
|
sock_errstr(err) );
|
||||||
#endif
|
#endif
|
||||||
return( (void*)-1 );
|
return( (void*)-1 );
|
||||||
@ -1393,9 +1404,8 @@ slapd_daemon_task(
|
|||||||
*/
|
*/
|
||||||
if ( slap_listeners[l]->sl_is_udp < 2 ) {
|
if ( slap_listeners[l]->sl_is_udp < 2 ) {
|
||||||
id = connection_init(
|
id = connection_init(
|
||||||
slap_listeners[l]->sl_sd,
|
slap_listeners[l]->sl_sd,
|
||||||
slap_listeners[l]->sl_url, "", "",
|
slap_listeners[l], "", "",
|
||||||
slap_listeners[l]->sl_name,
|
|
||||||
2, ssf, authid );
|
2, ssf, authid );
|
||||||
slap_listeners[l]->sl_is_udp++;
|
slap_listeners[l]->sl_is_udp++;
|
||||||
}
|
}
|
||||||
@ -1621,10 +1631,9 @@ slapd_daemon_task(
|
|||||||
}
|
}
|
||||||
|
|
||||||
id = connection_init(s,
|
id = connection_init(s,
|
||||||
slap_listeners[l]->sl_url,
|
slap_listeners[l],
|
||||||
dnsname != NULL ? dnsname : "unknown",
|
dnsname != NULL ? dnsname : "unknown",
|
||||||
peername,
|
peername,
|
||||||
slap_listeners[l]->sl_name,
|
|
||||||
#ifdef HAVE_TLS
|
#ifdef HAVE_TLS
|
||||||
slap_listeners[l]->sl_is_tls,
|
slap_listeners[l]->sl_is_tls,
|
||||||
#else
|
#else
|
||||||
@ -1638,24 +1647,29 @@ slapd_daemon_task(
|
|||||||
if( id < 0 ) {
|
if( id < 0 ) {
|
||||||
#ifdef NEW_LOGGING
|
#ifdef NEW_LOGGING
|
||||||
LDAP_LOG( CONNECTION, INFO,
|
LDAP_LOG( CONNECTION, INFO,
|
||||||
"slapd_daemon_task: connection_init(%ld, %s, %s) failed.\n",
|
"slapd_daemon_task: "
|
||||||
(long)s, peername, slap_listeners[l]->sl_name );
|
"connection_init(%ld, %s, %s) "
|
||||||
|
"failed.\n",
|
||||||
|
(long)s, peername,
|
||||||
|
slap_listeners[l]->sl_name.bv_val );
|
||||||
#else
|
#else
|
||||||
Debug( LDAP_DEBUG_ANY,
|
Debug( LDAP_DEBUG_ANY,
|
||||||
"daemon: connection_init(%ld, %s, %s) failed.\n",
|
"daemon: connection_init(%ld, %s, %s) "
|
||||||
|
"failed.\n",
|
||||||
(long) s,
|
(long) s,
|
||||||
peername,
|
peername,
|
||||||
slap_listeners[l]->sl_name );
|
slap_listeners[l]->sl_name.bv_val );
|
||||||
#endif
|
#endif
|
||||||
slapd_close(s);
|
slapd_close(s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Statslog( LDAP_DEBUG_STATS,
|
Statslog( LDAP_DEBUG_STATS,
|
||||||
"daemon: conn=%ld fd=%ld connection from %s (%s) accepted.\n",
|
"daemon: conn=%ld fd=%ld connection from %s "
|
||||||
|
"(%s) accepted.\n",
|
||||||
id, (long) s,
|
id, (long) s,
|
||||||
peername,
|
peername,
|
||||||
slap_listeners[l]->sl_name,
|
slap_listeners[l]->sl_name.bv_val,
|
||||||
0 );
|
0 );
|
||||||
|
|
||||||
slapd_add( s );
|
slapd_add( s );
|
||||||
|
@ -287,10 +287,9 @@ LDAP_SLAPD_F (int) connections_timeout_idle LDAP_P((time_t));
|
|||||||
|
|
||||||
LDAP_SLAPD_F (long) connection_init LDAP_P((
|
LDAP_SLAPD_F (long) connection_init LDAP_P((
|
||||||
ber_socket_t s,
|
ber_socket_t s,
|
||||||
const char* url,
|
Listener* url,
|
||||||
const char* dnsname,
|
const char* dnsname,
|
||||||
const char* peername,
|
const char* peername,
|
||||||
const char* sockname,
|
|
||||||
int use_tls,
|
int use_tls,
|
||||||
slap_ssf_t ssf,
|
slap_ssf_t ssf,
|
||||||
const char *id ));
|
const char *id ));
|
||||||
|
@ -1643,6 +1643,8 @@ typedef struct slap_gacl {
|
|||||||
char ga_ndn[1];
|
char ga_ndn[1];
|
||||||
} GroupAssertion;
|
} GroupAssertion;
|
||||||
|
|
||||||
|
typedef struct slap_listener Listener;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* represents a connection from an ldap client
|
* represents a connection from an ldap client
|
||||||
*/
|
*/
|
||||||
@ -1658,10 +1660,11 @@ typedef struct slap_conn {
|
|||||||
time_t c_activitytime; /* when the connection was last used */
|
time_t c_activitytime; /* when the connection was last used */
|
||||||
unsigned long c_connid; /* id of this connection for stats*/
|
unsigned long c_connid; /* id of this connection for stats*/
|
||||||
|
|
||||||
struct berval c_listener_url; /* listener URL */
|
|
||||||
struct berval c_peer_domain; /* DNS name of client */
|
struct berval c_peer_domain; /* DNS name of client */
|
||||||
struct berval c_peer_name; /* peer name (trans=addr:port) */
|
struct berval c_peer_name; /* peer name (trans=addr:port) */
|
||||||
struct berval c_sock_name; /* sock name (trans=addr:port) */
|
Listener *c_listener;
|
||||||
|
#define c_listener_url c_listener->sl_url /* listener URL */
|
||||||
|
#define c_sock_name c_listener->sl_name /* sock name (trans=addr:port) */
|
||||||
|
|
||||||
/* only can be changed by binding thread */
|
/* only can be changed by binding thread */
|
||||||
int c_sasl_bind_in_progress; /* multi-op bind in progress */
|
int c_sasl_bind_in_progress; /* multi-op bind in progress */
|
||||||
@ -1725,9 +1728,9 @@ typedef struct slap_conn {
|
|||||||
/*
|
/*
|
||||||
* listener; need to access it from monitor backend
|
* listener; need to access it from monitor backend
|
||||||
*/
|
*/
|
||||||
typedef struct slap_listener {
|
struct slap_listener {
|
||||||
char* sl_url;
|
struct berval sl_url;
|
||||||
char* sl_name;
|
struct berval sl_name;
|
||||||
#ifdef HAVE_TLS
|
#ifdef HAVE_TLS
|
||||||
int sl_is_tls;
|
int sl_is_tls;
|
||||||
#endif
|
#endif
|
||||||
@ -1737,7 +1740,7 @@ typedef struct slap_listener {
|
|||||||
ber_socket_t sl_sd;
|
ber_socket_t sl_sd;
|
||||||
Sockaddr sl_sa;
|
Sockaddr sl_sa;
|
||||||
#define sl_addr sl_sa.sa_in_addr
|
#define sl_addr sl_sa.sa_in_addr
|
||||||
} Listener;
|
};
|
||||||
|
|
||||||
#ifdef SLAPD_MONITOR
|
#ifdef SLAPD_MONITOR
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user