- if (mbox_file == NULL) {
- /* error while spooling */
- log_write(0, LOG_MAIN|LOG_PANIC,
- "spam acl condition: error while creating mbox spool file");
- return DEFER;
- };
-
- start = time(NULL);
-
- /* socket does not start with '/' -> network socket */
- if (*spamd_address_work != '/') {
- int num_servers = 0;
- int current_server;
- uschar *address = NULL;
- uschar *spamd_address_list_ptr = spamd_address_work;
- uschar address_buffer[256];
- spamd_address_container * spamd_address_vector[32];
-
- /* Check how many spamd servers we have
- and register their addresses */
- while ((address = string_nextinlist(&spamd_address_list_ptr, &sep,
- address_buffer,
- sizeof(address_buffer))) != NULL) {
-
- /* Potential memory leak as we never free the store. */
- spamd_address_container *this_spamd =
- (spamd_address_container *)store_get(sizeof(spamd_address_container));
-
- /* grok spamd address and port */
- if( sscanf(CS address, "%s %u", this_spamd->tcp_addr, &(this_spamd->tcp_port)) != 2 ) {
- log_write(0, LOG_MAIN,
- "spam acl condition: warning - invalid spamd address: '%s'", address);
- continue;
- };
-
- spamd_address_vector[num_servers] = this_spamd;
- num_servers++;
- if (num_servers > 31)
- break;
- };
-
- /* check if we have at least one server */
- if (!num_servers) {
- log_write(0, LOG_MAIN|LOG_PANIC,
- "spam acl condition: no useable spamd server addresses in spamd_address configuration option.");
- (void)fclose(mbox_file);
- return DEFER;
- };
-
- while ( num_servers > 0 ) {
- int i;
-
- /* Randomly pick a server to try */
- current_server = random_number( num_servers );
-
- debug_printf("trying server %s, port %u\n",
- spamd_address_vector[current_server]->tcp_addr,
- spamd_address_vector[current_server]->tcp_port);
-
- /* contact a spamd */
- if ( (spamd_sock = ip_socket(SOCK_STREAM, AF_INET)) < 0) {
- log_write(0, LOG_MAIN|LOG_PANIC,
- "spam acl condition: error creating IP socket for spamd");
- (void)fclose(mbox_file);
- return DEFER;
- };
-
- if (ip_connect( spamd_sock,
- AF_INET,
- spamd_address_vector[current_server]->tcp_addr,
- spamd_address_vector[current_server]->tcp_port,
- 5 ) > -1) {
- /* connection OK */
- break;
- };