Exemplo n.º 1
0
int
ldap_connect_to_path(LDAP *ld, Sockbuf *sb, LDAPURLDesc *srv, int async)
{
	struct sockaddr_un	server;
	ber_socket_t		s;
	int			rc;
	const char *path = srv->lud_host;

	oslocal_debug(ld, "ldap_connect_to_path\n",0,0,0);

	s = ldap_pvt_socket( ld );
	if ( s == AC_SOCKET_INVALID ) {
		return -1;
	}

	if ( path == NULL || path[0] == '\0' ) {
		path = LDAPI_SOCK;
	} else {
		if ( strlen(path) > (sizeof( server.sun_path ) - 1) ) {
			ldap_pvt_set_errno( ENAMETOOLONG );
			return -1;
		}
	}

	oslocal_debug(ld, "ldap_connect_to_path: Trying %s\n", path, 0, 0);

	memset( &server, '\0', sizeof(server) );
	server.sun_family = AF_LOCAL;
	strcpy( server.sun_path, path );

	rc = ldap_pvt_connect(ld, s, &server, async);

	if (rc == 0) {
		int err;
		err = ldap_int_connect_cbs( ld, sb, &s, srv, (struct sockaddr *)&server );
		if ( err )
			rc = err;
	}
	if ( rc ) {
		ldap_pvt_close_socket(ld, s);
	}
	return rc;
}
Exemplo n.º 2
0
int
ldap_connect_to_path(LDAP *ld, Sockbuf *sb, const char *path, int async)
{
	struct sockaddr_un	server;
	ber_socket_t		s;
	int			rc;

	oslocal_debug(ld, "ldap_connect_to_path\n",0,0,0);

	s = ldap_pvt_socket( ld );
	if ( s == AC_SOCKET_INVALID ) {
		return -1;
	}

	if ( path == NULL || path[0] == '\0' ) {
		path = LDAPI_SOCK;
	} else {
		if ( strlen(path) > (sizeof( server.sun_path ) - 1) ) {
			ldap_pvt_set_errno( ENAMETOOLONG );
			return -1;
		}
	}

	oslocal_debug(ld, "ldap_connect_to_path: Trying %s\n", path, 0, 0);

	memset( &server, '\0', sizeof(server) );
	server.sun_family = AF_LOCAL;
	strcpy( server.sun_path, path );

	rc = ldap_pvt_connect(ld, s, &server, async);

	if (rc == 0) {
		ber_sockbuf_ctrl( sb, LBER_SB_OPT_SET_FD, (void *)&s );
	} else {
		ldap_pvt_close_socket(ld, s);
	}
	return rc;
}