masqmail-0.2

changeset 10:26e34ae9a3e3

changed indention and line wrapping to a more consistent style
author meillo@marmaro.de
date Mon, 27 Oct 2008 16:23:10 +0100
parents 31cc8a89cb74
children 24872a9fe6e1
files src/accept.c src/address.c src/alias.c src/base64/base64.c src/base64/base64.h src/base64/base64dec.c src/base64/base64enc.c src/child.c src/conf.c src/connect.c src/deliver.c src/dotlock.c src/dotlock.h src/expand.c src/fail_msg.c src/get.c src/header.c src/interface.c src/libident/id_close.c src/libident/id_open.c src/libident/id_parse.c src/libident/id_query.c src/libident/ident.c src/libident/ident.h src/libident/support.c src/listen.c src/local.c src/log.c src/lookup.c src/lookup.h src/masqmail.c src/masqmail.h src/md5/hmac_md5.c src/md5/hmac_md5.h src/md5/hmactest.c src/md5/md5.h src/md5/md5c.c src/message.c src/mservdetect.c src/mserver.c src/mserver.h src/online.c src/parse.c src/peopen.c src/peopen.h src/permissions.c src/pop3_in.c src/pop3_in.h src/queue.c src/readsock.c src/readsock.h src/readtest.c src/rewrite.c src/route.c src/smtp_in.c src/smtp_out.c src/smtp_out.h src/smtpsend.c src/spool.c src/tables.c src/timeival.c
diffstat 61 files changed, 9351 insertions(+), 9567 deletions(-) [+]
line diff
     1.1 --- a/src/accept.c	Mon Oct 27 16:21:27 2008 +0100
     1.2 +++ b/src/accept.c	Mon Oct 27 16:23:10 2008 +0100
     1.3 @@ -19,41 +19,40 @@
     1.4  #include "masqmail.h"
     1.5  #include "readsock.h"
     1.6  
     1.7 -gchar *prot_names[] =
     1.8 -{
     1.9 -  "local",
    1.10 -  "bsmtp",
    1.11 -  "smtp",
    1.12 -  "esmtp",
    1.13 -  "pop3",
    1.14 -  "apop",
    1.15 -  "(unknown)" /* should not happen, but better than crashing. */
    1.16 +gchar *prot_names[] = {
    1.17 +	"local",
    1.18 +	"bsmtp",
    1.19 +	"smtp",
    1.20 +	"esmtp",
    1.21 +	"pop3",
    1.22 +	"apop",
    1.23 +	"(unknown)"  /* should not happen, but better than crashing. */
    1.24  };
    1.25  
    1.26 -static
    1.27 -gchar *string_base62(gchar *res, guint value, gchar len)
    1.28 +static gchar*
    1.29 +string_base62(gchar * res, guint value, gchar len)
    1.30  {
    1.31 -  static gchar base62_chars[] =
    1.32 -    "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    1.33 -  gchar *p = res + len;
    1.34 -  *p = 0;
    1.35 -  while (p > res){
    1.36 -    *(--p) = base62_chars[value % 62];
    1.37 -    value /= 62;
    1.38 -  }
    1.39 -  return res;
    1.40 +	static gchar base62_chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    1.41 +	gchar *p = res + len;
    1.42 +	*p = 0;
    1.43 +	while (p > res) {
    1.44 +		*(--p) = base62_chars[value % 62];
    1.45 +		value /= 62;
    1.46 +	}
    1.47 +	return res;
    1.48  }
    1.49  
    1.50 -static gint _g_list_addr_isequal(gconstpointer a, gconstpointer b)
    1.51 +static gint
    1.52 +_g_list_addr_isequal(gconstpointer a, gconstpointer b)
    1.53  {
    1.54 -  address *addr1 = (address *)a;
    1.55 -  address *addr2 = (address *)b;
    1.56 -  int ret;
    1.57 +	address *addr1 = (address *) a;
    1.58 +	address *addr2 = (address *) b;
    1.59 +	int ret;
    1.60  
    1.61 -  if((ret = strcasecmp(addr1->domain, addr2->domain)) == 0)
    1.62 -    return strcmp(addr1->local_part, addr2->local_part);
    1.63 -  else
    1.64 -    return ret;
    1.65 +	if ((ret = strcasecmp(addr1->domain, addr2->domain)) == 0)
    1.66 +		return strcmp(addr1->local_part, addr2->local_part);
    1.67 +	else
    1.68 +		return ret;
    1.69  }
    1.70  
    1.71  /* accept message from anywhere.
    1.72 @@ -64,415 +63,392 @@
    1.73     (from To/Cc/Bcc headers if ACC_RCPT_TO is set) rcpt_list.
    1.74  */
    1.75  
    1.76 -accept_error accept_message_stream(FILE *in, message *msg, guint flags)
    1.77 +accept_error
    1.78 +accept_message_stream(FILE * in, message * msg, guint flags)
    1.79  {
    1.80 -  gchar *line, *line1;
    1.81 -  int line_size = MAX_DATALINE;
    1.82 -  gboolean in_headers = TRUE;
    1.83 -  header *hdr = NULL;
    1.84 -  gint line_cnt = 0, data_size = 0;
    1.85 +	gchar *line, *line1;
    1.86 +	int line_size = MAX_DATALINE;
    1.87 +	gboolean in_headers = TRUE;
    1.88 +	header *hdr = NULL;
    1.89 +	gint line_cnt = 0, data_size = 0;
    1.90  
    1.91 -  line = g_malloc(line_size);
    1.92 -  line[0] = 0;
    1.93 +	line = g_malloc(line_size);
    1.94 +	line[0] = 0;
    1.95  
    1.96 -  while(TRUE){
    1.97 -    int len = read_sockline1(in, &line, &line_size, 5*60, READSOCKL_CVT_CRLF);
    1.98 +	while (TRUE) {
    1.99 +		int len = read_sockline1(in, &line, &line_size, 5 * 60, READSOCKL_CVT_CRLF);
   1.100  
   1.101 -    line1 = line;
   1.102 +		line1 = line;
   1.103  
   1.104 -    if((line[0] == '.') && (!(flags & ACC_NODOT_TERM))){
   1.105 -      if(line[1] == '\n'){
   1.106 -	g_free(line);
   1.107 -	break;
   1.108 -      }
   1.109 -      line1++;
   1.110 -    }
   1.111 -    
   1.112 -    if(len <= 0){
   1.113 -      if((len == -1) && ((flags & ACC_NODOT_TERM) || (flags & ACC_NODOT_RELAX))){
   1.114 -	/* we got an EOF, and the last line was not terminated by a CR */
   1.115 -	gint len1 = strlen(line1);
   1.116 -	if(len1 > 0){ /* == 0 is 'normal' (EOF after a CR) */
   1.117 -	  if(line1[len1-1] != '\n'){ /* some mail clients allow unterminated lines */
   1.118 -	    line1[len1] = '\n';
   1.119 -	    line1[len1+1] = 0;
   1.120 -	    msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1));
   1.121 -	    data_size += strlen(line1);
   1.122 -	    line_cnt++;
   1.123 -	  }
   1.124 +		if ((line[0] == '.') && (!(flags & ACC_NODOT_TERM))) {
   1.125 +			if (line[1] == '\n') {
   1.126 +				g_free(line);
   1.127 +				break;
   1.128 +			}
   1.129 +			line1++;
   1.130 +		}
   1.131 +
   1.132 +		if (len <= 0) {
   1.133 +			if ((len == -1) && ((flags & ACC_NODOT_TERM) || (flags & ACC_NODOT_RELAX))) {
   1.134 +				/* we got an EOF, and the last line was not terminated by a CR */
   1.135 +				gint len1 = strlen(line1);
   1.136 +				if (len1 > 0) {  /* == 0 is 'normal' (EOF after a CR) */
   1.137 +					if (line1[len1 - 1] != '\n') {  /* some mail clients allow unterminated lines */
   1.138 +						line1[len1] = '\n';
   1.139 +						line1[len1 + 1] = 0;
   1.140 +						msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1));
   1.141 +						data_size += strlen(line1);
   1.142 +						line_cnt++;
   1.143 +					}
   1.144 +				}
   1.145 +				break;
   1.146 +			} else {
   1.147 +				g_free(line);
   1.148 +				if (len == -1) {
   1.149 +					return AERR_EOF;
   1.150 +				} else if (len == -2) {
   1.151 +					/* should not happen any more */
   1.152 +					return AERR_OVERFLOW;
   1.153 +				} else if (len == -3) {
   1.154 +					return AERR_TIMEOUT;
   1.155 +				} else {
   1.156 +					/* does not happen */
   1.157 +					DEBUG(5) debugf("read_sockline returned %d\n", len);
   1.158 +					return AERR_UNKNOWN;
   1.159 +				}
   1.160 +			}
   1.161 +		} else {
   1.162 +			if (in_headers) {
   1.163 +
   1.164 +				/* some pop servers send the 'From ' line, skip it: */
   1.165 +				if (msg->hdr_list == NULL)
   1.166 +					if (strncmp(line1, "From ", 5) == 0)
   1.167 +						continue;
   1.168 +
   1.169 +				if (line1[0] == ' ' || line1[0] == '\t') {
   1.170 +					/* continuation of 'folded' header: */
   1.171 +					if (hdr) {
   1.172 +						hdr->header =
   1.173 +							g_strconcat(hdr->header, line1, NULL);
   1.174 +					}
   1.175 +
   1.176 +				} else if (line1[0] == '\n') {
   1.177 +					/* an empty line marks end of headers */
   1.178 +					in_headers = FALSE;
   1.179 +				} else {
   1.180 +					/* in all other cases we expect another header */
   1.181 +					if ((hdr = get_header(line1)))
   1.182 +						msg->hdr_list = g_list_append(msg->hdr_list, hdr);
   1.183 +					else {
   1.184 +						/* if get_header() returns NULL, no header was recognized,
   1.185 +						   so this seems to be the first data line of a broken mailer
   1.186 +						   which does not send an empty line after the headers */
   1.187 +						in_headers = FALSE;
   1.188 +						msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1));
   1.189 +					}
   1.190 +				}
   1.191 +			} else {
   1.192 +				msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1));
   1.193 +				data_size += strlen(line1);
   1.194 +				line_cnt++;
   1.195 +			}
   1.196 +		}
   1.197  	}
   1.198 -	break;
   1.199 -      }else{
   1.200 -	g_free(line);
   1.201 -	if(len == -1){
   1.202 -	  return AERR_EOF;
   1.203 -	}else if(len == -2){
   1.204 -	  /* should not happen any more */
   1.205 -	  return AERR_OVERFLOW;
   1.206 -	}else if(len == -3){
   1.207 -	  return AERR_TIMEOUT;
   1.208 -	}else{
   1.209 -	  /* does not happen */
   1.210 -	  DEBUG(5) debugf("read_sockline returned %d\n", len);
   1.211 -	  return AERR_UNKNOWN;
   1.212 -	}
   1.213 -      }
   1.214 -    }
   1.215 -    else{
   1.216 -      if(in_headers){
   1.217  
   1.218 -	/* some pop servers send the 'From ' line, skip it: */
   1.219 -	if(msg->hdr_list == NULL)
   1.220 -	  if(strncmp(line1, "From ", 5) == 0)
   1.221 -	    continue;
   1.222 +	if (msg->data_list != NULL)
   1.223 +		msg->data_list = g_list_reverse(msg->data_list);
   1.224 +	else
   1.225 +		/* make sure data list is not NULL: */
   1.226 +		msg->data_list = g_list_append(NULL, g_strdup(""));
   1.227  
   1.228 -	if(line1[0] == ' ' || line1[0] == '\t'){
   1.229 -	  /* continuation of 'folded' header: */
   1.230 -	  if(hdr){
   1.231 -	    hdr->header = g_strconcat(hdr->header, line1, NULL);
   1.232 -	  }
   1.233 +	DEBUG(4) debugf("received %d lines of data (%d bytes)\n", line_cnt, data_size);
   1.234 +	/* we get here after we succesfully received the mail data */
   1.235  
   1.236 -	}else if(line1[0] == '\n'){
   1.237 -	  /* an empty line marks end of headers */
   1.238 -	  in_headers = FALSE;
   1.239 -	}else{
   1.240 -	  /* in all other cases we expect another header */
   1.241 -	  if((hdr = get_header(line1)))
   1.242 -	    msg->hdr_list = g_list_append(msg->hdr_list, hdr);
   1.243 -	  else{
   1.244 -	    /* if get_header() returns NULL, no header was recognized,
   1.245 -	       so this seems to be the first data line of a broken mailer
   1.246 -	       which does not send an empty line after the headers */
   1.247 -	    in_headers = FALSE;
   1.248 -	    msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1));
   1.249 -	  }
   1.250 -	}
   1.251 -      }else{
   1.252 -	msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1));
   1.253 -	data_size += strlen(line1);
   1.254 -	line_cnt++;
   1.255 -      }
   1.256 -    }
   1.257 -  }
   1.258 +	msg->data_size = data_size;
   1.259 +	msg->received_time = time(NULL);
   1.260  
   1.261 -  if(msg->data_list != NULL)
   1.262 -    msg->data_list = g_list_reverse(msg->data_list);
   1.263 -  else
   1.264 -    /* make sure data list is not NULL: */
   1.265 -    msg->data_list = g_list_append(NULL, g_strdup(""));
   1.266 -
   1.267 -  DEBUG(4) debugf("received %d lines of data (%d bytes)\n",
   1.268 -		  line_cnt, data_size);
   1.269 -  /* we get here after we succesfully
   1.270 -     received the mail data */
   1.271 -
   1.272 -  msg->data_size = data_size;
   1.273 -  msg->received_time = time(NULL);
   1.274 -
   1.275 -  return AERR_OK;
   1.276 +	return AERR_OK;
   1.277  }
   1.278  
   1.279 -accept_error accept_message_prepare(message *msg, guint flags)
   1.280 +accept_error
   1.281 +accept_message_prepare(message * msg, guint flags)
   1.282  {
   1.283 -  struct passwd *passwd = NULL;
   1.284 -  GList *non_rcpt_list = NULL;
   1.285 -  time_t rec_time = time(NULL);
   1.286 +	struct passwd *passwd = NULL;
   1.287 +	GList *non_rcpt_list = NULL;
   1.288 +	time_t rec_time = time(NULL);
   1.289  
   1.290 -  DEBUG(5) debugf("accept_message_prepare()\n");
   1.291 +	DEBUG(5) debugf("accept_message_prepare()\n");
   1.292  
   1.293 -  /* create unique message id */
   1.294 -  msg->uid = g_malloc(14);
   1.295 +	/* create unique message id */
   1.296 +	msg->uid = g_malloc(14);
   1.297  
   1.298 -  string_base62(msg->uid, rec_time, 6);
   1.299 -  msg->uid[6] = '-';
   1.300 -  string_base62(&(msg->uid[7]), getpid(), 3);
   1.301 -  msg->uid[10] = '-';
   1.302 -  string_base62(&(msg->uid[11]), msg->transfer_id, 2);
   1.303 -  msg->uid[13] = 0;
   1.304 +	string_base62(msg->uid, rec_time, 6);
   1.305 +	msg->uid[6] = '-';
   1.306 +	string_base62(&(msg->uid[7]), getpid(), 3);
   1.307 +	msg->uid[10] = '-';
   1.308 +	string_base62(&(msg->uid[11]), msg->transfer_id, 2);
   1.309 +	msg->uid[13] = 0;
   1.310  
   1.311 -  /* if local, get password entry */
   1.312 -  if(msg->received_host == NULL){
   1.313 -    passwd = g_memdup(getpwuid(geteuid()), sizeof(struct passwd));
   1.314 -    msg->ident = g_strdup(passwd->pw_name);
   1.315 -  }
   1.316 +	/* if local, get password entry */
   1.317 +	if (msg->received_host == NULL) {
   1.318 +		passwd = g_memdup(getpwuid(geteuid()), sizeof(struct passwd));
   1.319 +		msg->ident = g_strdup(passwd->pw_name);
   1.320 +	}
   1.321  
   1.322 -  /* set return path if local */
   1.323 -  if(msg->return_path == NULL){
   1.324 +	/* set return path if local */
   1.325 +	if (msg->return_path == NULL) {
   1.326  
   1.327 -    if(msg->received_host == NULL){
   1.328 -      gchar *path = g_strdup_printf("<%s@%s>",
   1.329 -				    passwd->pw_name, conf.host_name);
   1.330 -      DEBUG(3) debugf("setting return_path for local accept: %s\n", path);
   1.331 -      msg->return_path = create_address(path, TRUE);
   1.332 -      g_free(path);
   1.333 -    }
   1.334 -  }
   1.335 +		if (msg->received_host == NULL) {
   1.336 +			gchar *path = g_strdup_printf("<%s@%s>", passwd->pw_name, conf.host_name);
   1.337 +			DEBUG(3) debugf("setting return_path for local accept: %s\n", path);
   1.338 +			msg->return_path = create_address(path, TRUE);
   1.339 +			g_free(path);
   1.340 +		}
   1.341 +	}
   1.342  
   1.343 -  /* -t option */
   1.344 -  if(flags & ACC_DEL_RCPTS){
   1.345 -    non_rcpt_list = msg->rcpt_list;
   1.346 -    msg->rcpt_list = NULL;
   1.347 -  }
   1.348 +	/* -t option */
   1.349 +	if (flags & ACC_DEL_RCPTS) {
   1.350 +		non_rcpt_list = msg->rcpt_list;
   1.351 +		msg->rcpt_list = NULL;
   1.352 +	}
   1.353  
   1.354 -  /* scan headers */
   1.355 -  {
   1.356 -    gboolean has_id = FALSE;
   1.357 -    gboolean has_date = FALSE;
   1.358 -    gboolean has_sender = FALSE;
   1.359 -    gboolean has_from = FALSE;
   1.360 -    gboolean has_rcpt = FALSE;
   1.361 -    gboolean has_to_or_cc = FALSE;
   1.362 -    GList *hdr_node, *hdr_node_next;
   1.363 -    header *hdr;
   1.364 +	/* scan headers */
   1.365 +	{
   1.366 +		gboolean has_id = FALSE;
   1.367 +		gboolean has_date = FALSE;
   1.368 +		gboolean has_sender = FALSE;
   1.369 +		gboolean has_from = FALSE;
   1.370 +		gboolean has_rcpt = FALSE;
   1.371 +		gboolean has_to_or_cc = FALSE;
   1.372 +		GList *hdr_node, *hdr_node_next;
   1.373 +		header *hdr;
   1.374  
   1.375 -    for(hdr_node = g_list_first(msg->hdr_list);
   1.376 -	hdr_node != NULL;
   1.377 -	hdr_node = hdr_node_next){
   1.378 -      hdr_node_next = g_list_next(hdr_node);
   1.379 -      hdr = ((header *)(hdr_node->data));
   1.380 -      DEBUG(5) debugf("scanning headers: %s", hdr->header);
   1.381 -      switch(hdr->id){
   1.382 -      case HEAD_MESSAGE_ID:
   1.383 -	has_id = TRUE; break;
   1.384 -      case HEAD_DATE:
   1.385 -	has_date = TRUE; break;
   1.386 -      case HEAD_FROM:
   1.387 -	has_from = TRUE;
   1.388 -	break;
   1.389 -      case HEAD_SENDER:
   1.390 -	has_sender = TRUE;
   1.391 -	break;
   1.392 -      case HEAD_TO:
   1.393 -      case HEAD_CC:
   1.394 -      case HEAD_BCC:
   1.395 -	has_rcpt = TRUE;
   1.396 -	if(flags & ACC_RCPT_FROM_HEAD){
   1.397 -	  DEBUG(5) debugf("hdr->value = %s\n", hdr->value);
   1.398 -	  if(hdr->value){
   1.399 -	    msg->rcpt_list =
   1.400 -	      addr_list_append_rfc822(msg->rcpt_list, hdr->value, conf.host_name);
   1.401 -	  }
   1.402 +		for (hdr_node = g_list_first(msg->hdr_list);
   1.403 +		     hdr_node != NULL; hdr_node = hdr_node_next) {
   1.404 +			hdr_node_next = g_list_next(hdr_node);
   1.405 +			hdr = ((header *) (hdr_node->data));
   1.406 +			DEBUG(5) debugf("scanning headers: %s", hdr->header);
   1.407 +			switch (hdr->id) {
   1.408 +			case HEAD_MESSAGE_ID:
   1.409 +				has_id = TRUE;
   1.410 +				break;
   1.411 +			case HEAD_DATE:
   1.412 +				has_date = TRUE;
   1.413 +				break;
   1.414 +			case HEAD_FROM:
   1.415 +				has_from = TRUE;
   1.416 +				break;
   1.417 +			case HEAD_SENDER:
   1.418 +				has_sender = TRUE;
   1.419 +				break;
   1.420 +			case HEAD_TO:
   1.421 +			case HEAD_CC:
   1.422 +			case HEAD_BCC:
   1.423 +				has_rcpt = TRUE;
   1.424 +				if (flags & ACC_RCPT_FROM_HEAD) {
   1.425 +					DEBUG(5) debugf("hdr->value = %s\n", hdr->value);
   1.426 +					if (hdr->value) {
   1.427 +						msg->rcpt_list = addr_list_append_rfc822(msg->rcpt_list, hdr->value, conf.host_name);
   1.428 +					}
   1.429 +				}
   1.430 +				if ((flags & ACC_DEL_BCC) && (hdr->id == HEAD_BCC)) {
   1.431 +					DEBUG(3) debugf("removing 'Bcc' header\n");
   1.432 +					msg->hdr_list = g_list_remove_link(msg->hdr_list, hdr_node);
   1.433 +					g_list_free_1(hdr_node);
   1.434 +					destroy_header(hdr);
   1.435 +				} else
   1.436 +					has_to_or_cc = TRUE;
   1.437 +				break;
   1.438 +			case HEAD_ENVELOPE_TO:
   1.439 +				if (flags & ACC_SAVE_ENVELOPE_TO) {
   1.440 +					DEBUG(3) debugf("creating 'X-Orig-Envelope-To' header\n");
   1.441 +					msg->hdr_list = g_list_prepend(msg->hdr_list, create_header(HEAD_UNKNOWN, "X-Orig-Envelope-to: %s", hdr->value));
   1.442 +				}
   1.443 +				DEBUG(3) debugf("removing 'Envelope-To' header\n");
   1.444 +				msg->hdr_list = g_list_remove_link(msg->hdr_list, hdr_node);
   1.445 +				g_list_free_1(hdr_node);
   1.446 +				destroy_header(hdr);
   1.447 +				break;
   1.448 +			case HEAD_RETURN_PATH:
   1.449 +				if (flags & ACC_MAIL_FROM_HEAD) {
   1.450 +					/* usually POP3 accept */
   1.451 +					msg->return_path = create_address_qualified(hdr->value, TRUE, msg->received_host);
   1.452 +					DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path));
   1.453 +				}
   1.454 +				DEBUG(3) debugf("removing 'Return-Path' header\n");
   1.455 +				msg->hdr_list = g_list_remove_link(msg->hdr_list, hdr_node);
   1.456 +				g_list_free_1(hdr_node);
   1.457 +				destroy_header(hdr);
   1.458 +				break;
   1.459 +			default:
   1.460 +				break;  /* make compiler happy */
   1.461 +			}
   1.462 +		}
   1.463 +
   1.464 +		if (msg->return_path == NULL) {
   1.465 +			/* this can happen for pop3 accept only and if no Return-path: header was given */
   1.466 +			GList *hdr_list;
   1.467 +			header *hdr;
   1.468 +
   1.469 +			DEBUG(3) debugf("return_path == NULL\n");
   1.470 +
   1.471 +			hdr_list = find_header(msg->hdr_list, HEAD_SENDER, NULL);
   1.472 +			if (!hdr_list)
   1.473 +				hdr_list = find_header(msg->hdr_list, HEAD_FROM, NULL);
   1.474 +			if (hdr_list) {
   1.475 +				gchar *addr;
   1.476 +				hdr = (header *) (g_list_first(hdr_list)->data);
   1.477 +
   1.478 +				DEBUG(5) debugf("hdr->value = '%s'\n", hdr->value);
   1.479 +
   1.480 +				addr = g_strdup(hdr->value);
   1.481 +				g_strchomp(addr);
   1.482 +
   1.483 +				if ((msg->return_path = create_address_qualified(addr, FALSE, msg->received_host)) != NULL) {
   1.484 +					DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path));
   1.485 +					msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_UNKNOWN, "X-Warning: return path set from %s address\n", hdr->id == HEAD_SENDER ? "Sender:" : "From:"));
   1.486 +				}
   1.487 +				g_free(addr);
   1.488 +			}
   1.489 +			if (msg->return_path == NULL) {  /* no Sender: or From: or create_address_qualified failed */
   1.490 +				msg->return_path = create_address_qualified("postmaster", TRUE, conf.host_name);
   1.491 +				DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path));
   1.492 +				msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_UNKNOWN, "X-Warning: real return path is unkown\n"));
   1.493 +			}
   1.494 +		}
   1.495 +
   1.496 +		if (flags & ACC_DEL_RCPTS) {
   1.497 +			GList *rcpt_node;
   1.498 +			foreach(non_rcpt_list, rcpt_node) {
   1.499 +				address *rcpt = (address *) (rcpt_node->data);
   1.500 +				GList *node;
   1.501 +				if ((node = g_list_find_custom(msg->rcpt_list, rcpt, _g_list_addr_isequal))) {
   1.502 +					DEBUG(3) debugf("removing rcpt address %s\n", addr_string(node->data));
   1.503 +					msg->rcpt_list = g_list_remove_link(msg->rcpt_list, node);
   1.504 +					destroy_address((address *) (node->data));
   1.505 +					g_list_free_1(node);
   1.506 +				}
   1.507 +			}
   1.508 +		}
   1.509 +
   1.510 +		/* here we should have our recipients, fail if not: */
   1.511 +		if (msg->rcpt_list == NULL) {
   1.512 +			logwrite(LOG_WARNING, "no recipients found in message\n");
   1.513 +			return AERR_NORCPT;
   1.514 +		}
   1.515 +
   1.516 +		if (!(has_sender || has_from)) {
   1.517 +			DEBUG(3) debugf("adding 'From' header\n");
   1.518 +			msg->hdr_list = g_list_append(msg->hdr_list,
   1.519 +			                msg->full_sender_name
   1.520 +			                ?
   1.521 +			                  create_header(HEAD_FROM,
   1.522 +			                  "From: \"%s\" <%s@%s>\n",
   1.523 +			                  msg->full_sender_name,
   1.524 +			                  msg->return_path->local_part,
   1.525 +			                  msg->return_path->
   1.526 +			                  domain)
   1.527 +			                :
   1.528 +			                  create_header(HEAD_FROM, "From: <%s@%s>\n",
   1.529 +			                  msg->return_path->local_part,
   1.530 +			                  msg->return_path->domain)
   1.531 +			                );
   1.532 +		}
   1.533 +		if ((flags & ACC_HEAD_FROM_RCPT) && !has_rcpt) {
   1.534 +			GList *node;
   1.535 +			DEBUG(3) debugf("adding 'To' header(s)\n");
   1.536 +			for (node = g_list_first(msg->rcpt_list); node; node = g_list_next(node)) {
   1.537 +				msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_TO, "To: %s\n", addr_string(msg-> return_path)));
   1.538 +			}
   1.539 +		}
   1.540 +		if ((flags & ACC_DEL_BCC) && !has_to_or_cc) {
   1.541 +			/* Bcc headers have been removed, and there are no remaining rcpt headers */
   1.542 +			DEBUG(3) debugf("adding empty 'Bcc:' header\n");
   1.543 +			msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_BCC, "Bcc:\n"));
   1.544 +		}
   1.545 +		if (!has_date) {
   1.546 +			DEBUG(3) debugf("adding 'Date:' header\n");
   1.547 +			msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_DATE, "Date: %s\n", rec_timestamp()));
   1.548 +		}
   1.549 +		if (!has_id) {
   1.550 +			DEBUG(3) debugf("adding 'Message-ID:' header\n");
   1.551 +			msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_MESSAGE_ID, "Message-ID: <%s@%s>\n", msg->uid, conf.host_name));
   1.552 +		}
   1.553  	}
   1.554 -	if((flags & ACC_DEL_BCC) && (hdr->id == HEAD_BCC)){
   1.555 -	  DEBUG(3) debugf("removing 'Bcc' header\n");
   1.556 -	  msg->hdr_list = g_list_remove_link(msg->hdr_list, hdr_node);
   1.557 -	  g_list_free_1(hdr_node);
   1.558 -	  destroy_header(hdr);
   1.559 -	}else
   1.560 -	  has_to_or_cc = TRUE;
   1.561 -	break;
   1.562 -      case HEAD_ENVELOPE_TO:
   1.563 -	if(flags & ACC_SAVE_ENVELOPE_TO){
   1.564 -	  DEBUG(3) debugf("creating 'X-Orig-Envelope-To' header\n");
   1.565 -	  msg->hdr_list =
   1.566 -	    g_list_prepend(msg->hdr_list,
   1.567 -			  create_header(HEAD_UNKNOWN,
   1.568 -					"X-Orig-Envelope-to: %s", hdr->value));
   1.569 +
   1.570 +	/* Received header: */
   1.571 +	/* At this point because we have to know the rcpts for the 'for' part */
   1.572 +	if (!(flags & ACC_NO_RECVD_HDR)) {
   1.573 +		gchar *for_string = NULL;
   1.574 +		header *hdr = NULL;
   1.575 +
   1.576 +		DEBUG(3) debugf("adding 'Received:' header\n");
   1.577 +
   1.578 +		if (g_list_length(msg->rcpt_list) == 1) {
   1.579 +			address *addr = (address *) (g_list_first(msg->rcpt_list)->data);
   1.580 +			for_string = g_strdup_printf(" for %s", addr_string(addr));
   1.581 +		}
   1.582 +
   1.583 +		if (msg->received_host == NULL) {
   1.584 +			hdr = create_header(HEAD_RECEIVED,
   1.585 +			                    "Received: from %s by %s"
   1.586 +			                    " with %s (%s %s) id %s%s;"
   1.587 +			                    " %s\n",
   1.588 +			                    passwd->pw_name, conf.host_name,
   1.589 +			                    prot_names[msg->received_prot],
   1.590 +			                    PACKAGE, VERSION,
   1.591 +			                    msg->uid, for_string ? for_string : "",
   1.592 +			                    rec_timestamp());
   1.593 +		} else {
   1.594 +#ifdef ENABLE_IDENT
   1.595 +			DEBUG(5) debugf("adding 'Received:' header (5)\n");
   1.596 +			hdr = create_header(HEAD_RECEIVED,
   1.597 +			                    "Received: from %s (ident=%s) by %s"
   1.598 +			                    " with %s (%s %s) id %s%s;"
   1.599 +			                    " %s\n",
   1.600 +			                    msg->received_host,
   1.601 +			                    msg->ident ? msg->ident : "unknown",
   1.602 +			                    conf.host_name,
   1.603 +			                    prot_names[msg->received_prot],
   1.604 +			                    PACKAGE, VERSION,
   1.605 +			                    msg->uid, for_string ? for_string : "",
   1.606 +			                    rec_timestamp());
   1.607 +#else
   1.608 +			hdr = create_header(HEAD_RECEIVED,
   1.609 +			                    "Received: from %s by %s"
   1.610 +			                    " with %s (%s %s) id %s%s;"
   1.611 +			                    " %s\n",
   1.612 +			                    msg->received_host,
   1.613 +			                    conf.host_name,
   1.614 +			                    prot_names[msg->received_prot],
   1.615 +			                    PACKAGE, VERSION,
   1.616 +			                    msg->uid, for_string ? for_string : "",
   1.617 +			                    rec_timestamp());
   1.618 +#endif
   1.619 +		}
   1.620 +		header_fold(hdr);
   1.621 +		msg->hdr_list = g_list_prepend(msg->hdr_list, hdr);
   1.622 +
   1.623 +		if (for_string)
   1.624 +			g_free(for_string);
   1.625  	}
   1.626 -	DEBUG(3) debugf("removing 'Envelope-To' header\n");
   1.627 -	msg->hdr_list = g_list_remove_link(msg->hdr_list, hdr_node);
   1.628 -	g_list_free_1(hdr_node);
   1.629 -	destroy_header(hdr);
   1.630 -	break;
   1.631 -      case HEAD_RETURN_PATH:
   1.632 -	if(flags & ACC_MAIL_FROM_HEAD){
   1.633 -	  /* usually POP3 accept */
   1.634 -	  msg->return_path = create_address_qualified(hdr->value, TRUE, msg->received_host);
   1.635 -	  DEBUG(3) debugf("setting return_path to %s\n",
   1.636 -			  addr_string(msg->return_path));
   1.637 -	}
   1.638 -	DEBUG(3) debugf("removing 'Return-Path' header\n");
   1.639 -	msg->hdr_list = g_list_remove_link(msg->hdr_list, hdr_node);
   1.640 -	g_list_free_1(hdr_node);
   1.641 -	destroy_header(hdr);
   1.642 -	break;
   1.643 -      default:
   1.644 -	break; /* make compiler happy */
   1.645 -      }
   1.646 -    }
   1.647  
   1.648 -    if(msg->return_path == NULL){
   1.649 -      /* this can happen for pop3 accept only
   1.650 -	 and if no Return-path: header was given */
   1.651 -      GList *hdr_list;
   1.652 -      header *hdr;
   1.653 -
   1.654 -      DEBUG(3) debugf("return_path == NULL\n");
   1.655 -
   1.656 -      hdr_list = find_header(msg->hdr_list, HEAD_SENDER, NULL);
   1.657 -      if(!hdr_list) hdr_list = find_header(msg->hdr_list, HEAD_FROM, NULL);
   1.658 -      if(hdr_list){
   1.659 -	gchar *addr;
   1.660 -	hdr = (header *)(g_list_first(hdr_list)->data);
   1.661 -
   1.662 -	DEBUG(5) debugf("hdr->value = '%s'\n", hdr->value);
   1.663 -
   1.664 -	addr = g_strdup(hdr->value);
   1.665 -	g_strchomp(addr);
   1.666 -
   1.667 -	if((msg->return_path =
   1.668 -	    create_address_qualified(addr, FALSE, msg->received_host))
   1.669 -	   != NULL){
   1.670 -	  DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path));
   1.671 -	  msg->hdr_list =
   1.672 -	    g_list_append(msg->hdr_list,
   1.673 -			  create_header(HEAD_UNKNOWN,
   1.674 -					"X-Warning: return path set from %s address\n",
   1.675 -					hdr->id == HEAD_SENDER ? "Sender:" : "From:"));
   1.676 -	}
   1.677 -	g_free(addr);
   1.678 -      }
   1.679 -      if(msg->return_path == NULL){ /* no Sender: or From: or create_address_qualified failed */
   1.680 -	msg->return_path = create_address_qualified("postmaster", TRUE, conf.host_name);
   1.681 -	DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path));
   1.682 -	msg->hdr_list =
   1.683 -	  g_list_append(msg->hdr_list,
   1.684 -			create_header(HEAD_UNKNOWN,
   1.685 -				      "X-Warning: real return path is unkown\n"));
   1.686 -      }
   1.687 -    }
   1.688 -
   1.689 -    if(flags & ACC_DEL_RCPTS){
   1.690 -      GList *rcpt_node;
   1.691 -      foreach(non_rcpt_list, rcpt_node){
   1.692 -	address *rcpt = (address *)(rcpt_node->data);
   1.693 -	GList *node;
   1.694 -	if((node = g_list_find_custom(msg->rcpt_list, rcpt,
   1.695 -				     _g_list_addr_isequal))){
   1.696 -	  DEBUG(3) debugf("removing rcpt address %s\n", addr_string(node->data));
   1.697 -
   1.698 -	  msg->rcpt_list = g_list_remove_link(msg->rcpt_list, node);
   1.699 -	  destroy_address((address *)(node->data));
   1.700 -	  g_list_free_1(node);
   1.701 -	}
   1.702 -      }
   1.703 -    }
   1.704 -
   1.705 -    /* here we should have our recipients, fail if not: */
   1.706 -    if(msg->rcpt_list == NULL){
   1.707 -      logwrite(LOG_WARNING, "no recipients found in message\n");
   1.708 -      return AERR_NORCPT;
   1.709 -    }
   1.710 -
   1.711 -    if(!(has_sender || has_from)){
   1.712 -      DEBUG(3) debugf("adding 'From' header\n");
   1.713 -      msg->hdr_list =
   1.714 -	g_list_append(msg->hdr_list,
   1.715 -		      msg->full_sender_name ?
   1.716 -		      create_header(HEAD_FROM, "From: \"%s\" <%s@%s>\n",
   1.717 -				    msg->full_sender_name,
   1.718 -				    msg->return_path->local_part,
   1.719 -				    msg->return_path->domain) :
   1.720 -		      create_header(HEAD_FROM, "From: <%s@%s>\n",
   1.721 -				    msg->return_path->local_part,
   1.722 -				    msg->return_path->domain)
   1.723 -		      );
   1.724 -    }
   1.725 -    if((flags & ACC_HEAD_FROM_RCPT) && !has_rcpt){
   1.726 -      GList *node;
   1.727 -      DEBUG(3) debugf("adding 'To' header(s)\n");
   1.728 -      for(node = g_list_first(msg->rcpt_list);
   1.729 -	  node;
   1.730 -	  node = g_list_next(node)){
   1.731 -	msg->hdr_list =
   1.732 -	  g_list_append(msg->hdr_list,
   1.733 -			create_header(HEAD_TO, "To: %s\n", addr_string(msg->return_path)));
   1.734 -      }
   1.735 -    }
   1.736 -    if((flags & ACC_DEL_BCC) && !has_to_or_cc){
   1.737 -      /* Bcc headers have been removed, and there are no remaining rcpt headers */
   1.738 -      DEBUG(3) debugf("adding empty 'Bcc:' header\n");
   1.739 -      msg->hdr_list =
   1.740 -	g_list_append(msg->hdr_list, create_header(HEAD_BCC, "Bcc:\n"));
   1.741 -    }
   1.742 -    if(!has_date){
   1.743 -      DEBUG(3) debugf("adding 'Date:' header\n");
   1.744 -      msg->hdr_list =
   1.745 -	g_list_append(msg->hdr_list,
   1.746 -		      create_header(HEAD_DATE, "Date: %s\n", rec_timestamp()));
   1.747 -    }
   1.748 -    if(!has_id){
   1.749 -      DEBUG(3) debugf("adding 'Message-ID:' header\n");
   1.750 -      msg->hdr_list =
   1.751 -	g_list_append(msg->hdr_list,
   1.752 -		      create_header(HEAD_MESSAGE_ID,
   1.753 -				    "Message-ID: <%s@%s>\n",
   1.754 -				    msg->uid, conf.host_name));
   1.755 -    }
   1.756 -  }
   1.757 -
   1.758 -  /* Received header: */
   1.759 -  /* At this point because we have to know the rcpts for the 'for' part */
   1.760 -  if(!(flags & ACC_NO_RECVD_HDR)){
   1.761 -    gchar *for_string = NULL;
   1.762 -    header *hdr = NULL;
   1.763 -
   1.764 -    DEBUG(3) debugf("adding 'Received:' header\n");
   1.765 -
   1.766 -    if(g_list_length(msg->rcpt_list) == 1){
   1.767 -      address *addr = (address *)(g_list_first(msg->rcpt_list)->data);
   1.768 -      for_string = g_strdup_printf(" for %s", addr_string(addr));
   1.769 -    }
   1.770 -
   1.771 -    if(msg->received_host == NULL){
   1.772 -      hdr = create_header(HEAD_RECEIVED,
   1.773 -			  "Received: from %s by %s"
   1.774 -			  " with %s (%s %s) id %s%s;"
   1.775 -			  " %s\n",
   1.776 -			  passwd->pw_name, conf.host_name,
   1.777 -			  prot_names[msg->received_prot],
   1.778 -			  PACKAGE, VERSION,
   1.779 -			  msg->uid, for_string ? for_string : "",
   1.780 -			  rec_timestamp());
   1.781 -    }else{
   1.782 -#ifdef ENABLE_IDENT
   1.783 -      DEBUG(5) debugf("adding 'Received:' header (5)\n");
   1.784 -      hdr = create_header(HEAD_RECEIVED,
   1.785 -			  "Received: from %s (ident=%s) by %s"
   1.786 -			  " with %s (%s %s) id %s%s;"
   1.787 -			  " %s\n",
   1.788 -			  msg->received_host,
   1.789 -			  msg->ident ? msg->ident : "unknown",
   1.790 -			  conf.host_name,
   1.791 -			  prot_names[msg->received_prot],
   1.792 -			  PACKAGE, VERSION,
   1.793 -			  msg->uid, for_string ? for_string : "",
   1.794 -			  rec_timestamp());
   1.795 -#else
   1.796 -      hdr = create_header(HEAD_RECEIVED,
   1.797 -			  "Received: from %s by %s"
   1.798 -			  " with %s (%s %s) id %s%s;"
   1.799 -			  " %s\n",
   1.800 -			  msg->received_host,
   1.801 -			  conf.host_name,
   1.802 -			  prot_names[msg->received_prot],
   1.803 -			  PACKAGE, VERSION,
   1.804 -			  msg->uid, for_string ? for_string : "",
   1.805 -			  rec_timestamp());
   1.806 -#endif
   1.807 -    }
   1.808 -    header_fold(hdr);
   1.809 -    msg->hdr_list = g_list_prepend(msg->hdr_list, hdr);
   1.810 -
   1.811 -    if(for_string) g_free(for_string);
   1.812 -  }
   1.813 -
   1.814 -  /* write message to spool: */
   1.815 -  /* accept is no longer responsible for this
   1.816 -  if(!spool_write(msg, TRUE))
   1.817 -    return AERR_NOSPOOL;
   1.818 -  */
   1.819 -  return AERR_OK;
   1.820 +	/* write message to spool: */
   1.821 +	/* accept is no longer responsible for this
   1.822 +	   if(!spool_write(msg, TRUE))
   1.823 +	   return AERR_NOSPOOL;
   1.824 +	 */
   1.825 +	return AERR_OK;
   1.826  }
   1.827  
   1.828 -accept_error accept_message(FILE *in, message *msg, guint flags)
   1.829 +accept_error
   1.830 +accept_message(FILE * in, message * msg, guint flags)
   1.831  {
   1.832 -  accept_error err;
   1.833 +	accept_error err;
   1.834  
   1.835 -  err = accept_message_stream(in, msg, flags);
   1.836 -  if(err == AERR_OK)
   1.837 -    err =  accept_message_prepare(msg, flags);
   1.838 +	err = accept_message_stream(in, msg, flags);
   1.839 +	if (err == AERR_OK)
   1.840 +		err = accept_message_prepare(msg, flags);
   1.841  
   1.842 -  return err;
   1.843 +	return err;
   1.844  }
   1.845 -
     2.1 --- a/src/address.c	Mon Oct 27 16:21:27 2008 +0100
     2.2 +++ b/src/address.c	Mon Oct 27 16:23:10 2008 +0100
     2.3 @@ -19,171 +19,182 @@
     2.4  #include "masqmail.h"
     2.5  #include <fnmatch.h>
     2.6  
     2.7 -address *create_address(gchar *path, gboolean is_rfc821)
     2.8 +address*
     2.9 +create_address(gchar * path, gboolean is_rfc821)
    2.10  {
    2.11 -  address *addr;
    2.12 -  addr = _create_address(path, NULL, is_rfc821);
    2.13 -  
    2.14 -  if(addr != NULL){
    2.15 -    addr_unmark_delivered(addr);
    2.16 -  }
    2.17 -  return addr;
    2.18 +	address *addr;
    2.19 +	addr = _create_address(path, NULL, is_rfc821);
    2.20 +
    2.21 +	if (addr != NULL) {
    2.22 +		addr_unmark_delivered(addr);
    2.23 +	}
    2.24 +	return addr;
    2.25  }
    2.26  
    2.27 -address *create_address_qualified(gchar *path, gboolean is_rfc821,
    2.28 -				  gchar *domain)
    2.29 +address*
    2.30 +create_address_qualified(gchar * path, gboolean is_rfc821, gchar * domain)
    2.31  {
    2.32 -  address *addr = create_address(path, is_rfc821);
    2.33 -  if(addr != NULL){
    2.34 -    if(addr->domain == NULL)
    2.35 -      addr->domain = g_strdup(domain);
    2.36 -  }
    2.37 +	address *addr = create_address(path, is_rfc821);
    2.38 +	if (addr != NULL) {
    2.39 +		if (addr->domain == NULL)
    2.40 +			addr->domain = g_strdup(domain);
    2.41 +	}
    2.42  
    2.43 -  return addr;
    2.44 +	return addr;
    2.45  }
    2.46  
    2.47  /* nothing special about pipes here,
    2.48     but its only called for that purpose */
    2.49 -address *create_address_pipe(gchar *path)
    2.50 +address*
    2.51 +create_address_pipe(gchar * path)
    2.52  {
    2.53 -  address *addr = g_malloc(sizeof(address));
    2.54 +	address *addr = g_malloc(sizeof(address));
    2.55  
    2.56 -  if(addr){
    2.57 -    memset(addr, 0, sizeof(address));
    2.58 -    addr->address = g_strchomp(g_strdup(path));
    2.59 -    addr->local_part = g_strdup(addr->address);
    2.60 -  
    2.61 -    addr->domain = g_strdup("localhost"); /* quick hack */
    2.62 -  }
    2.63 -  return addr;
    2.64 +	if (addr) {
    2.65 +		memset(addr, 0, sizeof(address));
    2.66 +		addr->address = g_strchomp(g_strdup(path));
    2.67 +		addr->local_part = g_strdup(addr->address);
    2.68 +
    2.69 +		addr->domain = g_strdup("localhost");  /* quick hack */
    2.70 +	}
    2.71 +	return addr;
    2.72  }
    2.73  
    2.74 -void destroy_address(address *addr)
    2.75 +void
    2.76 +destroy_address(address * addr)
    2.77  {
    2.78 -  DEBUG(6) debugf("destroy_address entered\n");
    2.79 +	DEBUG(6) debugf("destroy_address entered\n");
    2.80  
    2.81 -  g_free(addr->address);
    2.82 -  g_free(addr->local_part);
    2.83 -  g_free(addr->domain);
    2.84 +	g_free(addr->address);
    2.85 +	g_free(addr->local_part);
    2.86 +	g_free(addr->domain);
    2.87  
    2.88 -  g_free(addr);
    2.89 +	g_free(addr);
    2.90  }
    2.91  
    2.92 -address *copy_modify_address(const address *orig, gchar *l_part, gchar *dom)
    2.93 +address*
    2.94 +copy_modify_address(const address * orig, gchar * l_part, gchar * dom)
    2.95  {
    2.96 -  address *addr = NULL;
    2.97 +	address *addr = NULL;
    2.98  
    2.99 -  if(orig){
   2.100 -    addr = g_malloc(sizeof(address));
   2.101 -    if(addr){
   2.102 -      addr->address = g_strdup(orig->address);
   2.103 +	if (orig) {
   2.104 +		addr = g_malloc(sizeof(address));
   2.105 +		if (addr) {
   2.106 +			addr->address = g_strdup(orig->address);
   2.107  
   2.108 -      if(l_part == NULL)
   2.109 -	addr->local_part = g_strdup(orig->local_part);
   2.110 -      else
   2.111 -	addr->local_part = g_strdup(l_part);
   2.112 +			if (l_part == NULL)
   2.113 +				addr->local_part = g_strdup(orig->local_part);
   2.114 +			else
   2.115 +				addr->local_part = g_strdup(l_part);
   2.116  
   2.117 -      if(dom == NULL)
   2.118 -	addr->domain = g_strdup(orig->domain);
   2.119 -      else
   2.120 -	addr->domain = g_strdup(dom);
   2.121 +			if (dom == NULL)
   2.122 +				addr->domain = g_strdup(orig->domain);
   2.123 +			else
   2.124 +				addr->domain = g_strdup(dom);
   2.125  
   2.126 -      addr->flags = 0;
   2.127 -      addr->children = NULL;
   2.128 -      addr->parent = NULL;
   2.129 -    }
   2.130 -  }
   2.131 -  return addr;
   2.132 +			addr->flags = 0;
   2.133 +			addr->children = NULL;
   2.134 +			addr->parent = NULL;
   2.135 +		}
   2.136 +	}
   2.137 +	return addr;
   2.138  }
   2.139  
   2.140 -gboolean addr_isequal(address *addr1, address *addr2)
   2.141 +gboolean
   2.142 +addr_isequal(address * addr1, address * addr2)
   2.143  {
   2.144 -  return
   2.145 -    (strcmp(addr1->local_part, addr2->local_part) == 0) &&
   2.146 -    (strcasecmp(addr1->domain, addr2->domain) == 0);
   2.147 +	return
   2.148 +		(strcmp(addr1->local_part, addr2->local_part) == 0) &&
   2.149 +		(strcasecmp(addr1->domain, addr2->domain) == 0);
   2.150  }
   2.151  
   2.152  /* searches in ancestors of addr1 */
   2.153 -gboolean addr_isequal_parent(address *addr1, address *addr2)
   2.154 +gboolean
   2.155 +addr_isequal_parent(address * addr1, address * addr2)
   2.156  {
   2.157 -  address *addr;
   2.158 +	address *addr;
   2.159  
   2.160 -  for(addr = addr1; addr; addr = addr->parent)
   2.161 -    if(addr_isequal(addr, addr2))
   2.162 -      return TRUE;
   2.163 +	for (addr = addr1; addr; addr = addr->parent)
   2.164 +		if (addr_isequal(addr, addr2))
   2.165 +			return TRUE;
   2.166  
   2.167 -  return FALSE;
   2.168 +	return FALSE;
   2.169  }
   2.170  
   2.171  /* careful, this is recursive */
   2.172  /* returns TRUE if ALL children have been delivered */
   2.173 -gboolean addr_is_delivered_children(address *addr)
   2.174 +gboolean
   2.175 +addr_is_delivered_children(address * addr)
   2.176  {
   2.177 -  GList *addr_node;
   2.178 +	GList *addr_node;
   2.179  
   2.180 -  if(addr->children == NULL) return addr_is_delivered(addr);
   2.181 +	if (addr->children == NULL)
   2.182 +		return addr_is_delivered(addr);
   2.183  
   2.184 -  foreach(addr->children, addr_node){
   2.185 -    address *addr = (address *)(addr_node->data);
   2.186 -    if(!addr_is_delivered_children(addr))
   2.187 -      return FALSE;
   2.188 -  }
   2.189 -  return TRUE;
   2.190 +	foreach(addr->children, addr_node) {
   2.191 +		address *addr = (address *) (addr_node->data);
   2.192 +		if (!addr_is_delivered_children(addr))
   2.193 +			return FALSE;
   2.194 +	}
   2.195 +	return TRUE;
   2.196  }
   2.197  
   2.198  /* careful, this is recursive */
   2.199  /* returns TRUE if ALL children have been either delivered or have failed */
   2.200 -gboolean addr_is_finished_children(address *addr)
   2.201 +gboolean
   2.202 +addr_is_finished_children(address * addr)
   2.203  {
   2.204 -  GList *addr_node;
   2.205 +	GList *addr_node;
   2.206  
   2.207 -  if(addr->children == NULL) return (addr_is_failed(addr) || addr_is_delivered(addr));
   2.208 +	if (addr->children == NULL)
   2.209 +		return (addr_is_failed(addr) || addr_is_delivered(addr));
   2.210  
   2.211 -  foreach(addr->children, addr_node){
   2.212 -    address *addr = (address *)(addr_node->data);
   2.213 -    if(!addr_is_finished_children(addr))
   2.214 -      return FALSE;
   2.215 -  }
   2.216 -  return TRUE;
   2.217 +	foreach(addr->children, addr_node) {
   2.218 +		address *addr = (address *) (addr_node->data);
   2.219 +		if (!addr_is_finished_children(addr))
   2.220 +			return FALSE;
   2.221 +	}
   2.222 +	return TRUE;
   2.223  }
   2.224  
   2.225  /* find original address */
   2.226 -address *addr_find_ancestor(address *addr)
   2.227 +address*
   2.228 +addr_find_ancestor(address * addr)
   2.229  {
   2.230 -  while(addr->parent) addr = addr->parent;
   2.231 -  return addr;
   2.232 +	while (addr->parent)
   2.233 +		addr = addr->parent;
   2.234 +	return addr;
   2.235  }
   2.236  
   2.237 -gchar *addr_string(address *addr)
   2.238 +gchar*
   2.239 +addr_string(address * addr)
   2.240  {
   2.241 -  static gchar *buffer = NULL;
   2.242 +	static gchar *buffer = NULL;
   2.243  
   2.244 -  if(addr == NULL){
   2.245 -    g_free(buffer);
   2.246 -    buffer = NULL;
   2.247 -    return NULL;
   2.248 -  }
   2.249 -  if(buffer)
   2.250 -    g_free(buffer);
   2.251 +	if (addr == NULL) {
   2.252 +		g_free(buffer);
   2.253 +		buffer = NULL;
   2.254 +		return NULL;
   2.255 +	}
   2.256 +	if (buffer)
   2.257 +		g_free(buffer);
   2.258  
   2.259 -  if(addr->local_part[0] == 0){
   2.260 -    buffer = g_strdup("<>");
   2.261 -  }else{
   2.262 -    buffer = g_strdup_printf("<%s@%s>",
   2.263 -			     addr->local_part ? addr->local_part : "",
   2.264 -			     addr->domain ? addr->domain : "");
   2.265 -  }
   2.266 -  return buffer;
   2.267 +	if (addr->local_part[0] == 0) {
   2.268 +		buffer = g_strdup("<>");
   2.269 +	} else {
   2.270 +		buffer = g_strdup_printf("<%s@%s>", addr->local_part ? addr->local_part : "", addr->domain ? addr->domain : "");
   2.271 +	}
   2.272 +	return buffer;
   2.273  }
   2.274  
   2.275 -gint addr_match(address *addr1, address *addr2)
   2.276 +gint
   2.277 +addr_match(address * addr1, address * addr2)
   2.278  {
   2.279 -  int res;
   2.280 +	int res;
   2.281  
   2.282 -  if((res = fnmatch(addr1->local_part, addr2->local_part, 0)) == 0){
   2.283 -    if((res = fnmatch(addr1->domain, addr2->domain, FNM_CASEFOLD)) == 0)
   2.284 -      return 0;
   2.285 -  }
   2.286 -  return res;
   2.287 +	if ((res = fnmatch(addr1->local_part, addr2->local_part, 0)) == 0) {
   2.288 +		if ((res = fnmatch(addr1->domain, addr2->domain, FNM_CASEFOLD)) == 0)
   2.289 +			return 0;
   2.290 +	}
   2.291 +	return res;
   2.292  }
   2.293 -
     3.1 --- a/src/alias.c	Mon Oct 27 16:21:27 2008 +0100
     3.2 +++ b/src/alias.c	Mon Oct 27 16:23:10 2008 +0100
     3.3 @@ -19,177 +19,179 @@
     3.4  #include "masqmail.h"
     3.5  #include <fnmatch.h>
     3.6  
     3.7 -gboolean addr_is_local(address *addr)
     3.8 +gboolean
     3.9 +addr_is_local(address * addr)
    3.10  {
    3.11 -  GList *dom_node;
    3.12 -  GList *addr_node;
    3.13 -  address *a;
    3.14 +	GList *dom_node;
    3.15 +	GList *addr_node;
    3.16 +	address *a;
    3.17  
    3.18 -  foreach(conf.local_hosts, dom_node){
    3.19 -    if(addr->domain == NULL)
    3.20 -      return TRUE;
    3.21 -    if(fnmatch(dom_node->data, addr->domain, FNM_CASEFOLD) == 0){
    3.22 -      foreach(conf.not_local_addresses,addr_node){
    3.23 -	a = create_address_qualified(addr_node->data, TRUE, conf.host_name);
    3.24 -	if(addr_isequal(a,addr)){
    3.25 -	  destroy_address(a);
    3.26 -	  return FALSE;
    3.27 +	foreach(conf.local_hosts, dom_node) {
    3.28 +		if (addr->domain == NULL)
    3.29 +			return TRUE;
    3.30 +		if (fnmatch(dom_node->data, addr->domain, FNM_CASEFOLD) == 0) {
    3.31 +			foreach(conf.not_local_addresses, addr_node) {
    3.32 +				a = create_address_qualified(addr_node->data, TRUE, conf.host_name);
    3.33 +				if (addr_isequal(a, addr)) {
    3.34 +					destroy_address(a);
    3.35 +					return FALSE;
    3.36 +				}
    3.37 +				destroy_address(a);
    3.38 +			}
    3.39 +			return TRUE;
    3.40 +		}
    3.41  	}
    3.42 -	destroy_address(a);
    3.43 -      }
    3.44 -      return TRUE;
    3.45 -    }
    3.46 -  }
    3.47 -  foreach(conf.local_addresses,addr_node){
    3.48 -    a = create_address_qualified(addr_node->data, TRUE, conf.host_name);
    3.49 -    if(addr_isequal(a,addr)){
    3.50 -      destroy_address(a);
    3.51 -      return TRUE;
    3.52 -    }
    3.53 -    destroy_address(a);
    3.54 -  }
    3.55 -  return FALSE;
    3.56 +	foreach(conf.local_addresses, addr_node) {
    3.57 +		a = create_address_qualified(addr_node->data, TRUE, conf.host_name);
    3.58 +		if (addr_isequal(a, addr)) {
    3.59 +			destroy_address(a);
    3.60 +			return TRUE;
    3.61 +		}
    3.62 +		destroy_address(a);
    3.63 +	}
    3.64 +	return FALSE;
    3.65  }
    3.66  
    3.67 -static
    3.68 -gboolean addr_isequal_alias(address *addr1, address *addr2)
    3.69 +static gboolean
    3.70 +addr_isequal_alias(address * addr1, address * addr2)
    3.71  {
    3.72 -  return
    3.73 -    (conf.alias_local_cmp(addr1->local_part, addr2->local_part) == 0) &&
    3.74 -    (strcasecmp(addr1->domain, addr2->domain) == 0);
    3.75 +	return (conf.alias_local_cmp(addr1->local_part, addr2->local_part) == 0)
    3.76 +	       && (strcasecmp(addr1->domain, addr2->domain) == 0);
    3.77  }
    3.78  
    3.79 -static
    3.80 -GList *parse_list(gchar *line)
    3.81 +static GList*
    3.82 +parse_list(gchar * line)
    3.83  {
    3.84 -  GList *list = NULL;
    3.85 -  gchar buf[256];
    3.86 -  gchar *p, *q;
    3.87 +	GList *list = NULL;
    3.88 +	gchar buf[256];
    3.89 +	gchar *p, *q;
    3.90  
    3.91 -  p = line;
    3.92 -  while(*p != 0){
    3.93 -    q = buf;
    3.94 -    while(isspace(*p)) p++;
    3.95 -    if(*p != '\"'){
    3.96 -      while(*p && (*p != ',') && (q < buf+255))
    3.97 -	*(q++) = *(p++);
    3.98 -      *q = 0;
    3.99 -    }else{
   3.100 -      gboolean escape = FALSE;
   3.101 -      p++;
   3.102 -      while(*p && (*p != '\"' || escape) && (q < buf+255)){
   3.103 -	if((*p == '\\') && !escape)
   3.104 -	  escape = TRUE;
   3.105 -	else{
   3.106 -	  escape = FALSE;
   3.107 -	  *(q++) = *p;
   3.108 +	p = line;
   3.109 +	while (*p != 0) {
   3.110 +		q = buf;
   3.111 +		while (isspace(*p))
   3.112 +			p++;
   3.113 +		if (*p != '\"') {
   3.114 +			while (*p && (*p != ',') && (q < buf + 255))
   3.115 +				*(q++) = *(p++);
   3.116 +			*q = 0;
   3.117 +		} else {
   3.118 +			gboolean escape = FALSE;
   3.119 +			p++;
   3.120 +			while (*p && (*p != '\"' || escape) && (q < buf + 255)) {
   3.121 +				if ((*p == '\\') && !escape)
   3.122 +					escape = TRUE;
   3.123 +				else {
   3.124 +					escape = FALSE;
   3.125 +					*(q++) = *p;
   3.126 +				}
   3.127 +				p++;
   3.128 +			}
   3.129 +			*q = 0;
   3.130 +			while (*p && (*p != ','))
   3.131 +				p++;
   3.132 +		}
   3.133 +		list = g_list_append(list, g_strdup(g_strchomp(buf)));
   3.134 +		if (*p)
   3.135 +			p++;
   3.136  	}
   3.137 -	p++;
   3.138 -      }
   3.139 -      *q = 0;
   3.140 -      while(*p && (*p != ',')) p++;
   3.141 -    }
   3.142 -    list = g_list_append(list, g_strdup(g_strchomp(buf)));
   3.143 -    if(*p) p++;
   3.144 -  }
   3.145 -  return list;
   3.146 +	return list;
   3.147  }
   3.148  
   3.149 -GList *alias_expand(GList *alias_table, GList *rcpt_list, GList *non_rcpt_list)
   3.150 +GList*
   3.151 +alias_expand(GList * alias_table, GList * rcpt_list, GList * non_rcpt_list)
   3.152  {
   3.153 -  GList *done_list = NULL;
   3.154 -  GList *rcpt_node = g_list_copy(rcpt_list);
   3.155 +	GList *done_list = NULL;
   3.156 +	GList *rcpt_node = g_list_copy(rcpt_list);
   3.157  
   3.158 -  while(rcpt_node != NULL){
   3.159 -    address *addr = (address *)(rcpt_node->data);
   3.160 -    DEBUG(5) debugf("alias_expand begin: '%s@%s'\n", addr->local_part, addr->domain);
   3.161 -//    if(addr_is_local(addr) && (addr->local_part[0] != '|') &&
   3.162 -    if(addr_is_local(addr) && 
   3.163 -        !(addr->flags & ADDR_FLAG_NOEXPAND)){
   3.164 -      gchar *val;
   3.165 -      
   3.166 -      /* special handling for postmaster */
   3.167 -      if(strcasecmp(addr->local_part, "postmaster") == 0)
   3.168 -	val = (gchar *)table_find_func(alias_table, addr->local_part, strcasecmp);
   3.169 -      else
   3.170 -	val = (gchar *)table_find_func(alias_table, addr->local_part, conf.alias_local_cmp);
   3.171 +	while (rcpt_node != NULL) {
   3.172 +		address *addr = (address *) (rcpt_node->data);
   3.173 +		DEBUG(5) debugf("alias_expand begin: '%s@%s'\n", addr->local_part, addr->domain);
   3.174 +		/* if(addr_is_local(addr) && (addr->local_part[0] != '|') && */
   3.175 +		if (addr_is_local(addr) && !(addr->flags & ADDR_FLAG_NOEXPAND)) {
   3.176 +			gchar *val;
   3.177  
   3.178 -      DEBUG(5) debugf("alias: '%s' is local\n", addr->local_part);
   3.179 -      if(val != NULL){
   3.180 -	GList *val_list = parse_list(val);
   3.181 -	GList *val_node;
   3.182 -	GList *alias_list = NULL;
   3.183 +			/* special handling for postmaster */
   3.184 +			if (strcasecmp(addr->local_part, "postmaster") == 0)
   3.185 +				val = (gchar *) table_find_func(alias_table, addr->local_part, strcasecmp);
   3.186 +			else
   3.187 +				val = (gchar *) table_find_func(alias_table, addr->local_part, conf.alias_local_cmp);
   3.188  
   3.189 -	DEBUG(5) debugf("alias: '%s' -> '%s'\n", addr->local_part, val);
   3.190 -	foreach(val_list, val_node){
   3.191 -	  gchar *val = (gchar *)(val_node->data);
   3.192 -	  address *alias_addr;
   3.193 -	  address *addr_parent = NULL;
   3.194 +			DEBUG(5) debugf("alias: '%s' is local\n", addr->local_part);
   3.195 +			if (val != NULL) {
   3.196 +				GList *val_list = parse_list(val);
   3.197 +				GList *val_node;
   3.198 +				GList *alias_list = NULL;
   3.199  
   3.200 -	  if(val[0] == '|'){
   3.201 -	    DEBUG(5) debugf("alias: %s is a pipe address\n", val);
   3.202 -	    alias_addr = create_address_pipe(val);
   3.203 -	    DEBUG(5) debugf("alias_pipe: %s is a pipe address\n", alias_addr->local_part);
   3.204 -	  }else if(val[0] == '\\'){
   3.205 -	    DEBUG(5) debugf("alias: shall not be expanded: '%s'\n", val);
   3.206 -	    alias_addr = create_address_qualified(&(val[1]), TRUE, conf.host_name);
   3.207 -	    alias_addr->flags |= ADDR_FLAG_NOEXPAND;
   3.208 -	    DEBUG(5) debugf("alias: not expanded: '%s'\n",alias_addr->local_part);
   3.209 -	  }else{
   3.210 -	    alias_addr = create_address_qualified(val, TRUE, conf.host_name);
   3.211 +				DEBUG(5) debugf("alias: '%s' -> '%s'\n", addr->local_part, val);
   3.212 +				foreach(val_list, val_node) {
   3.213 +					gchar *val = (gchar *) (val_node->data);
   3.214 +					address *alias_addr;
   3.215 +					address *addr_parent = NULL;
   3.216  
   3.217 -	    /* search in parents for loops: */
   3.218 -	    for(addr_parent = addr; addr_parent; addr_parent = addr_parent->parent){
   3.219 -	      if(addr_isequal_alias(alias_addr, addr_parent)){
   3.220 -		logwrite(LOG_ALERT, "detected alias loop, (ignoring): %s@%s -> %s@%s\n",
   3.221 -			 addr_parent->local_part, addr_parent->domain,
   3.222 -			 addr->local_part, addr->domain);
   3.223 -		break;
   3.224 -	      }
   3.225 -	    }
   3.226 -	  }
   3.227 -	  if(!addr_parent){
   3.228 -	    alias_list = g_list_append(alias_list, alias_addr);
   3.229 -	    alias_addr->parent = addr;
   3.230 -	  }
   3.231 -	  g_free(val);
   3.232 +					if (val[0] == '|') {
   3.233 +						DEBUG(5) debugf("alias: %s is a pipe address\n", val);
   3.234 +						alias_addr = create_address_pipe(val);
   3.235 +						DEBUG(5) debugf("alias_pipe: %s is a pipe address\n", alias_addr->local_part);
   3.236 +					} else if (val[0] == '\\') {
   3.237 +						DEBUG(5) debugf("alias: shall not be expanded: '%s'\n", val);
   3.238 +						alias_addr = create_address_qualified(&(val[1]), TRUE, conf.host_name);
   3.239 +						alias_addr->flags |= ADDR_FLAG_NOEXPAND;
   3.240 +						DEBUG(5) debugf("alias: not expanded: '%s'\n", alias_addr->local_part);
   3.241 +					} else {
   3.242 +						alias_addr = create_address_qualified(val, TRUE, conf.host_name);
   3.243 +
   3.244 +						/* search in parents for loops: */
   3.245 +						for (addr_parent = addr; addr_parent; addr_parent = addr_parent->parent) {
   3.246 +							if (addr_isequal_alias (alias_addr, addr_parent)) {
   3.247 +								logwrite(LOG_ALERT,
   3.248 +								         "detected alias loop, (ignoring): %s@%s -> %s@%s\n",
   3.249 +								         addr_parent->local_part,
   3.250 +								         addr_parent->domain,
   3.251 +								         addr->local_part, addr->domain);
   3.252 +								break;
   3.253 +							}
   3.254 +						}
   3.255 +					}
   3.256 +					if (!addr_parent) {
   3.257 +						alias_list = g_list_append(alias_list, alias_addr);
   3.258 +						alias_addr->parent = addr;
   3.259 +					}
   3.260 +					g_free(val);
   3.261 +				}
   3.262 +				g_list_free(val_list);
   3.263 +				addr->children = g_list_copy(alias_list);
   3.264 +				rcpt_node = g_list_concat(rcpt_node, alias_list);
   3.265 +			} else {
   3.266 +				DEBUG(5) debugf("alias: '%s' is completed\n", addr->local_part);
   3.267 +				done_list = g_list_append(done_list, addr);
   3.268 +			}
   3.269 +		} else {
   3.270 +			DEBUG(5) debugf("alias: '%s@%s' is not local\n", addr->local_part, addr->domain);
   3.271 +			done_list = g_list_append(done_list, addr);
   3.272 +		}
   3.273 +		rcpt_node = g_list_next(rcpt_node);
   3.274  	}
   3.275 -	g_list_free(val_list);
   3.276 -	addr->children = g_list_copy(alias_list);
   3.277 -	rcpt_node = g_list_concat(rcpt_node, alias_list);
   3.278 -      }else{
   3.279 -	DEBUG(5) debugf("alias: '%s' is completed\n", addr->local_part);
   3.280 -	done_list = g_list_append(done_list, addr);
   3.281 -      }
   3.282 -    }else{
   3.283 -      DEBUG(5) debugf("alias: '%s@%s' is not local\n", addr->local_part, addr->domain);
   3.284 -      done_list = g_list_append(done_list, addr);
   3.285 -    }
   3.286 -    rcpt_node = g_list_next(rcpt_node);
   3.287 -  }
   3.288  
   3.289 -  /* delete addresses from done_list if they are in the non_rcpt_list */
   3.290 -  if(non_rcpt_list){
   3.291 -    GList *rcpt_node_next;
   3.292 -    for(rcpt_node = g_list_first(done_list);
   3.293 -	 rcpt_node;
   3.294 -	 rcpt_node = rcpt_node_next){
   3.295 -      address *addr = (address *)(rcpt_node->data);
   3.296 -      GList *non_node;
   3.297 +	/* delete addresses from done_list if they are in the non_rcpt_list */
   3.298 +	if (non_rcpt_list) {
   3.299 +		GList *rcpt_node_next;
   3.300 +		for (rcpt_node = g_list_first(done_list); rcpt_node; rcpt_node = rcpt_node_next) {
   3.301 +			address *addr = (address *) (rcpt_node->data);
   3.302 +			GList *non_node;
   3.303  
   3.304 -      rcpt_node_next = g_list_next(rcpt_node);
   3.305 +			rcpt_node_next = g_list_next(rcpt_node);
   3.306  
   3.307 -      foreach(non_rcpt_list, non_node){
   3.308 -	address *non_addr = (address *)(non_node->data);
   3.309 -	if(addr_isequal(addr, non_addr)){
   3.310 -	  done_list = g_list_remove_link(done_list, rcpt_node);
   3.311 -	  g_list_free_1(rcpt_node);
   3.312 -	  addr_mark_delivered(addr); /* this address is still in the children lists
   3.313 -				      of the original address */
   3.314 -	  break;
   3.315 +			foreach(non_rcpt_list, non_node) {
   3.316 +				address *non_addr = (address *) (non_node->data);
   3.317 +				if (addr_isequal(addr, non_addr)) {
   3.318 +					done_list = g_list_remove_link(done_list, rcpt_node);
   3.319 +					g_list_free_1(rcpt_node);
   3.320 +					addr_mark_delivered(addr);  /* this address is still in the children lists of the original address */
   3.321 +					break;
   3.322 +				}
   3.323 +			}
   3.324 +		}
   3.325  	}
   3.326 -      }
   3.327 -    }
   3.328 -  }
   3.329 -  return done_list;
   3.330 +	return done_list;
   3.331  }
     4.1 --- a/src/base64/base64.c	Mon Oct 27 16:21:27 2008 +0100
     4.2 +++ b/src/base64/base64.c	Mon Oct 27 16:23:10 2008 +0100
     4.3 @@ -4,7 +4,7 @@
     4.4   * it under the terms of the GNU General Public License as published by
     4.5   * the Free Software Foundation; either version 2 of the License, or
     4.6   * (at your option) any later version.
     4.7 - * 
     4.8 + *
     4.9   * This program is distributed in the hope that it will be useful,
    4.10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.12 @@ -25,104 +25,109 @@
    4.13  #include <string.h>
    4.14  #include "base64.h"
    4.15  
    4.16 -gchar *base64_encode(guchar *buf, gint len)
    4.17 +gchar*
    4.18 +base64_encode(guchar * buf, gint len)
    4.19  {
    4.20 -  guchar *outbuf, *q;
    4.21 -  gchar enc[64];
    4.22 -  gint i = 0, j = 0;
    4.23 -  guint in0, in1, in2;
    4.24 +	guchar *outbuf, *q;
    4.25 +	gchar enc[64];
    4.26 +	gint i = 0, j = 0;
    4.27 +	guint in0, in1, in2;
    4.28  
    4.29 -  for(; i < 26; i++) enc[i] = (gchar)('A' + j++); j = 0;
    4.30 -  for(; i < 52; i++) enc[i] = (gchar)('a' + j++); j = 0;
    4.31 -  for(; i < 62; i++) enc[i] = (gchar)('0' + j++);
    4.32 -  enc[i++] = '+';
    4.33 -  enc[i++] = '/';
    4.34 +	for (; i < 26; i++)
    4.35 +		enc[i] = (gchar) ('A' + j++);
    4.36 +	j = 0;
    4.37 +	for (; i < 52; i++)
    4.38 +		enc[i] = (gchar) ('a' + j++);
    4.39 +	j = 0;
    4.40 +	for (; i < 62; i++)
    4.41 +		enc[i] = (gchar) ('0' + j++);
    4.42 +	enc[i++] = '+';
    4.43 +	enc[i++] = '/';
    4.44  
    4.45 -  outbuf = g_malloc(((len+3) * 8)/6);
    4.46 -  q = outbuf;
    4.47 +	outbuf = g_malloc(((len + 3) * 8) / 6);
    4.48 +	q = outbuf;
    4.49  
    4.50 -  i = 0;
    4.51 -  while(i < len-2){
    4.52 -    in0 = buf[i++];
    4.53 -    in1 = buf[i++];
    4.54 -    in2 = buf[i++];
    4.55 +	i = 0;
    4.56 +	while (i < len - 2) {
    4.57 +		in0 = buf[i++];
    4.58 +		in1 = buf[i++];
    4.59 +		in2 = buf[i++];
    4.60  
    4.61 -    *(q++) = enc[(in0 >> 2) & 0x3f];
    4.62 -    *(q++) = enc[((in0 << 4) | (in1 >> 4)) & 0x3f];
    4.63 -    *(q++) = enc[((in1 << 2) | (in2 >> 6)) & 0x3f];
    4.64 -    *(q++) = enc[in2 & 0x3f];
    4.65 -  }
    4.66 -  if((len - i) == 1){
    4.67 -    in0 = buf[i++];
    4.68 -    *(q++) = enc[(in0 >> 2) & 0x3f];
    4.69 -    *(q++) = enc[(in0 << 4) & 0x3f];
    4.70 -    *(q++) = '=';
    4.71 -    *(q++) = '=';
    4.72 -  }else if((len - i) == 2){
    4.73 -    in0 = buf[i++];
    4.74 -    in1 = buf[i++];
    4.75 -    *(q++) = enc[(in0 >> 2) & 0x3f];
    4.76 -    *(q++) = enc[((in0 << 4) | (in1 >> 4)) & 0x3f];
    4.77 -    *(q++) = enc[(in1 << 2) & 0x3f];
    4.78 -    *(q++) = '=';
    4.79 -  }
    4.80 -  *q = 0;
    4.81 -  
    4.82 -  return outbuf;
    4.83 -}
    4.84 -    
    4.85 -gchar *base64_decode(gchar *buf, gint *size)
    4.86 -{
    4.87 -  guchar *p = buf, *q;
    4.88 -  guint in[4];
    4.89 -  //  gchar *out = g_malloc(((strlen(buf)+3) * 3) / 4 + 1);
    4.90 -  gchar *out = g_malloc((strlen(buf)+3) + 1);
    4.91 +		*(q++) = enc[(in0 >> 2) & 0x3f];
    4.92 +		*(q++) = enc[((in0 << 4) | (in1 >> 4)) & 0x3f];
    4.93 +		*(q++) = enc[((in1 << 2) | (in2 >> 6)) & 0x3f];
    4.94 +		*(q++) = enc[in2 & 0x3f];
    4.95 +	}
    4.96 +	if ((len - i) == 1) {
    4.97 +		in0 = buf[i++];
    4.98 +		*(q++) = enc[(in0 >> 2) & 0x3f];
    4.99 +		*(q++) = enc[(in0 << 4) & 0x3f];
   4.100 +		*(q++) = '=';
   4.101 +		*(q++) = '=';
   4.102 +	} else if ((len - i) == 2) {
   4.103 +		in0 = buf[i++];
   4.104 +		in1 = buf[i++];
   4.105 +		*(q++) = enc[(in0 >> 2) & 0x3f];
   4.106 +		*(q++) = enc[((in0 << 4) | (in1 >> 4)) & 0x3f];
   4.107 +		*(q++) = enc[(in1 << 2) & 0x3f];
   4.108 +		*(q++) = '=';
   4.109 +	}
   4.110 +	*q = 0;
   4.111  
   4.112 -  q = out;
   4.113 -  *size = 0;
   4.114 -
   4.115 -  *q = 0;
   4.116 -
   4.117 -  while(*p){
   4.118 -    int i = 0;
   4.119 -    while(i < 4){
   4.120 -      if(!*p) break;
   4.121 -      if((*p >= 'A') && (*p <= 'Z'))
   4.122 -	 in[i++] = *p - 'A';
   4.123 -      else if((*p >= 'a') && (*p <= 'z'))
   4.124 -	in[i++] = (*p - 'a') + 26;
   4.125 -      else if((*p >= '0') && (*p <= '9'))
   4.126 -	in[i++] = (*p - '0') + 52;
   4.127 -      else if(*p == '+')
   4.128 -	in[i++] = 62;
   4.129 -      else if(*p == '/')
   4.130 -	in[i++] = 63;
   4.131 -      else if(*p == '='){
   4.132 -	in[i++] = 0;
   4.133 -	p++;
   4.134 -	break;
   4.135 -      }else if((*p != '\r') && (*p != '\n')){
   4.136 -	p++;
   4.137 -	break;
   4.138 -      }
   4.139 -      p++;
   4.140 -    }
   4.141 -    if((i == 4) || (p[-1] == '=')){
   4.142 -      *(q++) = ((in[0] << 2) | (in[1] >> 4));
   4.143 -      *(q++) = ((in[1] << 4) | (in[2] >> 2));
   4.144 -      *(q++) = ((in[2] << 6) | in[3]);
   4.145 -      if(p[-1] == '='){
   4.146 -	if(i == 3){
   4.147 -	  (*size)++;
   4.148 -	}
   4.149 -	else if(i == 4){
   4.150 -	  (*size) += 2;
   4.151 -	}
   4.152 -      }else{
   4.153 -	*size += 3;
   4.154 -      }
   4.155 -    }
   4.156 -  }
   4.157 -  return out;
   4.158 +	return outbuf;
   4.159  }
   4.160  
   4.161 +gchar *base64_decode(gchar * buf, gint * size)
   4.162 +{
   4.163 +	guchar *p = buf, *q;
   4.164 +	guint in[4];
   4.165 +	/* gchar *out = g_malloc(((strlen(buf)+3) * 3) / 4 + 1); */
   4.166 +	gchar *out = g_malloc((strlen(buf) + 3) + 1);
   4.167 +
   4.168 +	q = out;
   4.169 +	*size = 0;
   4.170 +
   4.171 +	*q = 0;
   4.172 +
   4.173 +	while (*p) {
   4.174 +		int i = 0;
   4.175 +		while (i < 4) {
   4.176 +			if (!*p)
   4.177 +				break;
   4.178 +			if ((*p >= 'A') && (*p <= 'Z'))
   4.179 +				in[i++] = *p - 'A';
   4.180 +			else if ((*p >= 'a') && (*p <= 'z'))
   4.181 +				in[i++] = (*p - 'a') + 26;
   4.182 +			else if ((*p >= '0') && (*p <= '9'))
   4.183 +				in[i++] = (*p - '0') + 52;
   4.184 +			else if (*p == '+')
   4.185 +				in[i++] = 62;
   4.186 +			else if (*p == '/')
   4.187 +				in[i++] = 63;
   4.188 +			else if (*p == '=') {
   4.189 +				in[i++] = 0;
   4.190 +				p++;
   4.191 +				break;
   4.192 +			} else if ((*p != '\r') && (*p != '\n')) {
   4.193 +				p++;
   4.194 +				break;
   4.195 +			}
   4.196 +			p++;
   4.197 +		}
   4.198 +		if ((i == 4) || (p[-1] == '=')) {
   4.199 +			*(q++) = ((in[0] << 2) | (in[1] >> 4));
   4.200 +			*(q++) = ((in[1] << 4) | (in[2] >> 2));
   4.201 +			*(q++) = ((in[2] << 6) | in[3]);
   4.202 +			if (p[-1] == '=') {
   4.203 +				if (i == 3) {
   4.204 +					(*size)++;
   4.205 +				} else if (i == 4) {
   4.206 +					(*size) += 2;
   4.207 +				}
   4.208 +			} else {
   4.209 +				*size += 3;
   4.210 +			}
   4.211 +		}
   4.212 +	}
   4.213 +	return out;
   4.214 +}
     5.1 --- a/src/base64/base64.h	Mon Oct 27 16:21:27 2008 +0100
     5.2 +++ b/src/base64/base64.h	Mon Oct 27 16:23:10 2008 +0100
     5.3 @@ -4,7 +4,7 @@
     5.4   * it under the terms of the GNU General Public License as published by
     5.5   * the Free Software Foundation; either version 2 of the License, or
     5.6   * (at your option) any later version.
     5.7 - * 
     5.8 + *
     5.9   * This program is distributed in the hope that it will be useful,
    5.10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.12 @@ -15,5 +15,5 @@
    5.13   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    5.14   */
    5.15  
    5.16 -gchar *base64_encode(guchar *buf, gint len);
    5.17 -gchar *base64_decode(gchar *buf, gint *size);
    5.18 +gchar *base64_encode(guchar * buf, gint len);
    5.19 +gchar *base64_decode(gchar * buf, gint * size);
     6.1 --- a/src/base64/base64dec.c	Mon Oct 27 16:21:27 2008 +0100
     6.2 +++ b/src/base64/base64dec.c	Mon Oct 27 16:23:10 2008 +0100
     6.3 @@ -4,16 +4,17 @@
     6.4  
     6.5  #include "base64.h"
     6.6  
     6.7 -int main()
     6.8 +int
     6.9 +main()
    6.10  {
    6.11 -  gchar line[100];
    6.12 -  gchar *buf;
    6.13 -  gint size;
    6.14 +	gchar line[100];
    6.15 +	gchar *buf;
    6.16 +	gint size;
    6.17  
    6.18 -  while(fgets(line, 100, stdin)){
    6.19 -    buf = base64_decode(line, &size);
    6.20 -    fwrite(buf, size, 1, stdout);
    6.21 -    g_free(buf);
    6.22 -  }
    6.23 -  exit(0);
    6.24 +	while (fgets(line, 100, stdin)) {
    6.25 +		buf = base64_decode(line, &size);
    6.26 +		fwrite(buf, size, 1, stdout);
    6.27 +		g_free(buf);
    6.28 +	}
    6.29 +	exit(0);
    6.30  }
     7.1 --- a/src/base64/base64enc.c	Mon Oct 27 16:21:27 2008 +0100
     7.2 +++ b/src/base64/base64enc.c	Mon Oct 27 16:23:10 2008 +0100
     7.3 @@ -1,24 +1,23 @@
     7.4 -
     7.5  #include <glib.h>
     7.6  #include <stdio.h>
     7.7  #include <stdlib.h>
     7.8  
     7.9  #include "base64.h"
    7.10  
    7.11 -int main()
    7.12 +int
    7.13 +main()
    7.14  {
    7.15 -  gchar in[58];
    7.16 -  gint size;
    7.17 +	gchar in[58];
    7.18 +	gint size;
    7.19  
    7.20 -  do{
    7.21 -    gchar *out;
    7.22 +	do {
    7.23 +		gchar *out;
    7.24  
    7.25 -    size = fread(in, 1, 54, stdin);
    7.26 -    out = base64_encode(in, size);
    7.27 -    fputs(out, stdout);
    7.28 -    putchar('\n');
    7.29 -    g_free(out);
    7.30 -  }while(size == 54);
    7.31 -  exit(0);
    7.32 +		size = fread(in, 1, 54, stdin);
    7.33 +		out = base64_encode(in, size);
    7.34 +		fputs(out, stdout);
    7.35 +		putchar('\n');
    7.36 +		g_free(out);
    7.37 +	} while (size == 54);
    7.38 +	exit(0);
    7.39  }
    7.40 -
     8.1 --- a/src/child.c	Mon Oct 27 16:21:27 2008 +0100
     8.2 +++ b/src/child.c	Mon Oct 27 16:23:10 2008 +0100
     8.3 @@ -4,7 +4,7 @@
     8.4   * it under the terms of the GNU General Public License as published by
     8.5   * the Free Software Foundation; either version 2 of the License, or
     8.6   * (at your option) any later version.
     8.7 - * 
     8.8 + *
     8.9   * This program is distributed in the hope that it will be useful,
    8.10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.12 @@ -29,51 +29,51 @@
    8.13  
    8.14  int volatile sigchild_seen = 0;
    8.15  
    8.16 -static
    8.17 -void sigchild_handler(int sig)
    8.18 +static void
    8.19 +sigchild_handler(int sig)
    8.20  {
    8.21 -  sigchild_seen = 1;
    8.22 -  signal(SIGHUP, sigchild_handler);
    8.23 +	sigchild_seen = 1;
    8.24 +	signal(SIGHUP, sigchild_handler);
    8.25  }
    8.26  
    8.27 -int child(const char *command)
    8.28 +int
    8.29 +child(const char *command)
    8.30  {
    8.31 -  int pipe[2];
    8.32 +	int pipe[2];
    8.33  
    8.34 -  if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipe) == 0){
    8.35 -    pid_t pid;
    8.36 -      
    8.37 -    /*
    8.38 -    sigchild_seen = 0;
    8.39 -    signal(SIGCHLD, sigchild_handler);
    8.40 -    */
    8.41 +	if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipe) == 0) {
    8.42 +		pid_t pid;
    8.43  
    8.44 -    pid = fork();
    8.45 -    if(pid == 0){
    8.46 -      int i, max_fd = sysconf(_SC_OPEN_MAX);
    8.47 -      /* child */
    8.48 -      dup2(pipe[0], 0);
    8.49 -      dup2(pipe[0], 1);
    8.50 -      dup2(pipe[0], 2);
    8.51 +		/*
    8.52 +		   sigchild_seen = 0;
    8.53 +		   signal(SIGCHLD, sigchild_handler);
    8.54 +		 */
    8.55  
    8.56 -      if(max_fd <= 0) max_fd = 64;
    8.57 -      for(i = 3; i < max_fd; i++)
    8.58 -	close(i);
    8.59 +		pid = fork();
    8.60 +		if (pid == 0) {
    8.61 +			int i, max_fd = sysconf(_SC_OPEN_MAX);
    8.62 +			/* child */
    8.63 +			dup2(pipe[0], 0);
    8.64 +			dup2(pipe[0], 1);
    8.65 +			dup2(pipe[0], 2);
    8.66  
    8.67 -      {
    8.68 -	char *argv [] = { "/bin/sh", "-c", (char*) command, NULL };
    8.69 -	execve (*argv, argv, NULL);
    8.70 -      }
    8.71 -      logwrite(LOG_ALERT, "execve failed: %s\n", strerror(errno));
    8.72 -      _exit(EXIT_FAILURE);
    8.73 -    }else if(pid == -1){
    8.74 -      return -1;
    8.75 -    }else{
    8.76 -      close(pipe[0]);
    8.77 -      return pipe[1];
    8.78 -    }
    8.79 -  }
    8.80 -  return -2;
    8.81 +			if (max_fd <= 0)
    8.82 +				max_fd = 64;
    8.83 +			for (i = 3; i < max_fd; i++)
    8.84 +				close(i);
    8.85 +
    8.86 +			{
    8.87 +				char *argv[] = { "/bin/sh", "-c", (char *) command, NULL };
    8.88 +				execve(*argv, argv, NULL);
    8.89 +			}
    8.90 +			logwrite(LOG_ALERT, "execve failed: %s\n", strerror(errno));
    8.91 +			_exit(EXIT_FAILURE);
    8.92 +		} else if (pid == -1) {
    8.93 +			return -1;
    8.94 +		} else {
    8.95 +			close(pipe[0]);
    8.96 +			return pipe[1];
    8.97 +		}
    8.98 +	}
    8.99 +	return -2;
   8.100  }
   8.101 -
   8.102 -      
     9.1 --- a/src/conf.c	Mon Oct 27 16:21:27 2008 +0100
     9.2 +++ b/src/conf.c	Mon Oct 27 16:23:10 2008 +0100
     9.3 @@ -23,973 +23,973 @@
     9.4  
     9.5  masqmail_conf conf;
     9.6  
     9.7 -void init_conf()
     9.8 +void
     9.9 +init_conf()
    9.10  {
    9.11 -  struct passwd *passwd;
    9.12 -  struct group *group;
    9.13 +	struct passwd *passwd;
    9.14 +	struct group *group;
    9.15  
    9.16 -  memset(&conf, 0, sizeof(masqmail_conf));
    9.17 +	memset(&conf, 0, sizeof(masqmail_conf));
    9.18  
    9.19 -  conf.orig_uid = getuid();
    9.20 -  conf.orig_gid = getgid();
    9.21 +	conf.orig_uid = getuid();
    9.22 +	conf.orig_gid = getgid();
    9.23  
    9.24 -  if((passwd = getpwnam(DEF_MAIL_USER)))
    9.25 -    conf.mail_uid = passwd->pw_uid;
    9.26 -  else{
    9.27 -    fprintf(stderr, "user %s not found! (terminating)\n", DEF_MAIL_USER);
    9.28 -    exit(EXIT_FAILURE);
    9.29 -  }
    9.30 -  if((group = getgrnam(DEF_MAIL_GROUP)))
    9.31 -    conf.mail_gid = group->gr_gid;
    9.32 -  else{
    9.33 -    fprintf(stderr, "group %s not found! (terminating)\n", DEF_MAIL_GROUP);
    9.34 -    exit(EXIT_FAILURE);
    9.35 -  }
    9.36 +	if ((passwd = getpwnam(DEF_MAIL_USER)))
    9.37 +		conf.mail_uid = passwd->pw_uid;
    9.38 +	else {
    9.39 +		fprintf(stderr, "user %s not found! (terminating)\n", DEF_MAIL_USER);
    9.40 +		exit(EXIT_FAILURE);
    9.41 +	}
    9.42 +	if ((group = getgrnam(DEF_MAIL_GROUP)))
    9.43 +		conf.mail_gid = group->gr_gid;
    9.44 +	else {
    9.45 +		fprintf(stderr, "group %s not found! (terminating)\n", DEF_MAIL_GROUP);
    9.46 +		exit(EXIT_FAILURE);
    9.47 +	}
    9.48  }
    9.49  
    9.50 -static gchar *true_strings[] =
    9.51 -{
    9.52 -  "yes", "on", "true", NULL
    9.53 +static gchar* true_strings[] = {
    9.54 +	"yes", "on", "true", NULL
    9.55  };
    9.56  
    9.57 -static gchar *false_strings[] =
    9.58 -{
    9.59 -  "no", "off", "false", NULL
    9.60 +static gchar *false_strings[] = {
    9.61 +	"no", "off", "false", NULL
    9.62  };
    9.63  
    9.64 -static
    9.65 -gboolean parse_boolean(gchar *rval)
    9.66 +static gboolean
    9.67 +parse_boolean(gchar * rval)
    9.68  {
    9.69 -  gchar **str;
    9.70 +	gchar **str;
    9.71  
    9.72 -  DEBUG(6) fprintf(stderr, "parse_boolean: %s\n", rval);
    9.73 +	DEBUG(6) fprintf(stderr, "parse_boolean: %s\n", rval);
    9.74  
    9.75 -  str = true_strings;
    9.76 -  while(*str){
    9.77 -    if(strncasecmp(*str, rval, strlen(*str)) == 0)
    9.78 -      return TRUE;
    9.79 -    str++;
    9.80 -  }
    9.81 +	str = true_strings;
    9.82 +	while (*str) {
    9.83 +		if (strncasecmp(*str, rval, strlen(*str)) == 0)
    9.84 +			return TRUE;
    9.85 +		str++;
    9.86 +	}
    9.87  
    9.88 -  str = false_strings;
    9.89 -  while(*str){
    9.90 -    if(strncasecmp(*str, rval, strlen(*str)) == 0)
    9.91 -      return FALSE;
    9.92 -    str++;
    9.93 -  }
    9.94 +	str = false_strings;
    9.95 +	while (*str) {
    9.96 +		if (strncasecmp(*str, rval, strlen(*str)) == 0)
    9.97 +			return FALSE;
    9.98 +		str++;
    9.99 +	}
   9.100  
   9.101 -  fprintf(stderr, "cannot parse value '%s'\n", rval);
   9.102 -  exit(EXIT_FAILURE);
   9.103 +	fprintf(stderr, "cannot parse value '%s'\n", rval);
   9.104 +	exit(EXIT_FAILURE);
   9.105  }
   9.106  
   9.107  /* make a list from each line in a file */
   9.108 -static
   9.109 -GList *parse_list_file(gchar *fname)
   9.110 +static GList*
   9.111 +parse_list_file(gchar * fname)
   9.112  {
   9.113 -  GList *list = NULL;
   9.114 -  FILE *fptr;
   9.115 +	GList *list = NULL;
   9.116 +	FILE *fptr;
   9.117  
   9.118 -  if((fptr = fopen(fname, "rt"))){
   9.119 -    gchar buf[256];
   9.120 +	if ((fptr = fopen(fname, "rt"))) {
   9.121 +		gchar buf[256];
   9.122  
   9.123 -    while(!feof(fptr)){
   9.124 -      fgets(buf, 255, fptr);
   9.125 -      if(buf[0] && (buf[0] != '#') && (buf[0] != '\n')){
   9.126 -	g_strchomp(buf);
   9.127 -	list = g_list_append(list, g_strdup(buf));
   9.128 -      }
   9.129 -    }
   9.130 -    fclose(fptr);
   9.131 -  }else{
   9.132 -    logwrite(LOG_ALERT, "could not open %s for reading: %s\n", fname, strerror(errno));
   9.133 -    exit(EXIT_FAILURE);
   9.134 -  }
   9.135 +		while (!feof(fptr)) {
   9.136 +			fgets(buf, 255, fptr);
   9.137 +			if (buf[0] && (buf[0] != '#') && (buf[0] != '\n')) {
   9.138 +				g_strchomp(buf);
   9.139 +				list = g_list_append(list, g_strdup(buf));
   9.140 +			}
   9.141 +		}
   9.142 +		fclose(fptr);
   9.143 +	} else {
   9.144 +		logwrite(LOG_ALERT, "could not open %s for reading: %s\n", fname, strerror(errno));
   9.145 +		exit(EXIT_FAILURE);
   9.146 +	}
   9.147  
   9.148 -  return list;
   9.149 +	return list;
   9.150  }
   9.151  
   9.152  /* given a semicolon separated string, this function
   9.153     makes a GList out of it.
   9.154  */
   9.155 -GList *parse_list(gchar *line, gboolean read_file)
   9.156 +GList*
   9.157 +parse_list(gchar * line, gboolean read_file)
   9.158  {
   9.159 -  GList *list = NULL;
   9.160 -  gchar buf[256];
   9.161 -  gchar *p, *q;
   9.162 +	GList *list = NULL;
   9.163 +	gchar buf[256];
   9.164 +	gchar *p, *q;
   9.165  
   9.166 -  DEBUG(6) fprintf(stderr, "parsing list %s\n", line);
   9.167 +	DEBUG(6) fprintf(stderr, "parsing list %s\n", line);
   9.168  
   9.169 -  p = line;
   9.170 -  while(*p != 0){
   9.171 -    q = buf;
   9.172 +	p = line;
   9.173 +	while (*p != 0) {
   9.174 +		q = buf;
   9.175  
   9.176 -    while(*p && (*p != ';') && (q < buf+255))
   9.177 -      *(q++) = *(p++);
   9.178 -    *q = 0;
   9.179 +		while (*p && (*p != ';') && (q < buf + 255))
   9.180 +			*(q++) = *(p++);
   9.181 +		*q = 0;
   9.182  
   9.183 -    if((buf[0] == '/') && (read_file))
   9.184 -      /* item is a filename, include its contents */
   9.185 -      list = g_list_concat(list, parse_list_file(buf));
   9.186 -    else
   9.187 -      /* just a normal item */
   9.188 -      list = g_list_append(list, g_strdup(buf));
   9.189 +		if ((buf[0] == '/') && (read_file))
   9.190 +			/* item is a filename, include its contents */
   9.191 +			list = g_list_concat(list, parse_list_file(buf));
   9.192 +		else
   9.193 +			/* just a normal item */
   9.194 +			list = g_list_append(list, g_strdup(buf));
   9.195  
   9.196 -    DEBUG(6) printf("item = %s\n", buf);
   9.197 +		DEBUG(6) printf("item = %s\n", buf);
   9.198  
   9.199 -    if(*p) p++;
   9.200 -  }
   9.201 -  return list;
   9.202 +		if (*p)
   9.203 +			p++;
   9.204 +	}
   9.205 +	return list;
   9.206  }
   9.207  
   9.208 -static
   9.209 -GList *parse_address_list(gchar *line, gboolean read_file)
   9.210 +static GList*
   9.211 +parse_address_list(gchar * line, gboolean read_file)
   9.212  {
   9.213 -  GList *plain_list = parse_list(line, read_file);
   9.214 -  GList *node;
   9.215 -  GList *list = NULL;
   9.216 +	GList *plain_list = parse_list(line, read_file);
   9.217 +	GList *node;
   9.218 +	GList *list = NULL;
   9.219  
   9.220 -  foreach(plain_list, node){
   9.221 -    gchar *item = (gchar *)(node->data);
   9.222 -    address *addr = create_address(item, TRUE);
   9.223 -    if(addr)
   9.224 -      list = g_list_append(list, addr);
   9.225 -    g_free(item);
   9.226 -  }
   9.227 -  g_list_free(plain_list);
   9.228 +	foreach(plain_list, node) {
   9.229 +		gchar *item = (gchar *) (node->data);
   9.230 +		address *addr = create_address(item, TRUE);
   9.231 +		if (addr)
   9.232 +			list = g_list_append(list, addr);
   9.233 +		g_free(item);
   9.234 +	}
   9.235 +	g_list_free(plain_list);
   9.236  
   9.237 -  return list;
   9.238 +	return list;
   9.239  }
   9.240  
   9.241 -static
   9.242 -GList *parse_resolve_list(gchar *line)
   9.243 +static GList*
   9.244 +parse_resolve_list(gchar * line)
   9.245  {
   9.246 -  GList *list;
   9.247 -  GList *list_node;
   9.248 -  GList *res_list = NULL;
   9.249 +	GList *list;
   9.250 +	GList *list_node;
   9.251 +	GList *res_list = NULL;
   9.252  
   9.253 -  list = parse_list(line, FALSE);
   9.254 -  if(list){
   9.255 -    foreach(list, list_node){
   9.256 -      gchar *item = (gchar *)(list_node->data);
   9.257 -      if(strcmp(item, "byname") == 0){
   9.258 -	res_list = g_list_append(res_list, resolve_byname);
   9.259 +	list = parse_list(line, FALSE);
   9.260 +	if (list) {
   9.261 +		foreach(list, list_node) {
   9.262 +			gchar *item = (gchar *) (list_node->data);
   9.263 +			if (strcmp(item, "byname") == 0) {
   9.264 +				res_list = g_list_append(res_list, resolve_byname);
   9.265  #ifdef ENABLE_RESOLVER
   9.266 -      }else if(strcmp(item, "dns_a") == 0){
   9.267 -	res_list = g_list_append(res_list, resolve_dns_a);
   9.268 -      }else if(strcmp(item, "dns_mx") == 0){
   9.269 -	res_list = g_list_append(res_list, resolve_dns_mx);
   9.270 +			} else if (strcmp(item, "dns_a") == 0) {
   9.271 +				res_list = g_list_append(res_list, resolve_dns_a);
   9.272 +			} else if (strcmp(item, "dns_mx") == 0) {
   9.273 +				res_list = g_list_append(res_list, resolve_dns_mx);
   9.274  #endif
   9.275 -      }else{
   9.276 -	logwrite(LOG_ALERT, "unknown resolver %s\n", item);
   9.277 -	exit(EXIT_FAILURE);
   9.278 -      }
   9.279 -      g_free(item);
   9.280 -    }
   9.281 -    g_list_free(list);
   9.282 -  }
   9.283 -  return res_list;
   9.284 +			} else {
   9.285 +				logwrite(LOG_ALERT, "unknown resolver %s\n", item);
   9.286 +				exit(EXIT_FAILURE);
   9.287 +			}
   9.288 +			g_free(item);
   9.289 +		}
   9.290 +		g_list_free(list);
   9.291 +	}
   9.292 +	return res_list;
   9.293  }
   9.294  
   9.295 -static
   9.296 -interface *parse_interface(gchar *line, gint def_port)
   9.297 +static interface*
   9.298 +parse_interface(gchar * line, gint def_port)
   9.299  {
   9.300 -  gchar buf[256];
   9.301 -  gchar *p, *q;
   9.302 -  interface *iface;
   9.303 +	gchar buf[256];
   9.304 +	gchar *p, *q;
   9.305 +	interface *iface;
   9.306  
   9.307 -  DEBUG(6) fprintf(stderr, "parse_interface: %s\n", line);
   9.308 +	DEBUG(6) fprintf(stderr, "parse_interface: %s\n", line);
   9.309  
   9.310 -  p = line;
   9.311 -  q = buf;
   9.312 -  while((*p != 0) && (*p != ':') && (q < buf+255))
   9.313 -    *(q++) = *(p++);
   9.314 -  *q = 0;
   9.315 +	p = line;
   9.316 +	q = buf;
   9.317 +	while ((*p != 0) && (*p != ':') && (q < buf + 255))
   9.318 +		*(q++) = *(p++);
   9.319 +	*q = 0;
   9.320  
   9.321 -  iface = g_malloc(sizeof(interface));
   9.322 -  iface->address = g_strdup(buf);
   9.323 +	iface = g_malloc(sizeof(interface));
   9.324 +	iface->address = g_strdup(buf);
   9.325  
   9.326 -  if(*p){
   9.327 -    p++;
   9.328 -    iface->port = atoi(p);
   9.329 -  }else
   9.330 -    iface->port = def_port;
   9.331 +	if (*p) {
   9.332 +		p++;
   9.333 +		iface->port = atoi(p);
   9.334 +	} else
   9.335 +		iface->port = def_port;
   9.336  
   9.337 -  return iface;
   9.338 +	return iface;
   9.339  }
   9.340  
   9.341 -#ifdef ENABLE_IDENT /* so far used for that only */
   9.342 -static
   9.343 -struct in_addr *parse_network(gchar *line, gint def_port)
   9.344 +#ifdef ENABLE_IDENT  /* so far used for that only */
   9.345 +static struct in_addr*
   9.346 +parse_network(gchar * line, gint def_port)
   9.347  {
   9.348 -  gchar buf[256];
   9.349 -  gchar *p, *q;
   9.350 -  struct in_addr addr, mask_addr, net_addr, *p_net_addr;
   9.351 -  guint n;
   9.352 +	gchar buf[256];
   9.353 +	gchar *p, *q;
   9.354 +	struct in_addr addr, mask_addr, net_addr, *p_net_addr;
   9.355 +	guint n;
   9.356  
   9.357 -  DEBUG(6) fprintf(stderr, "parse_network: %s\n", line);
   9.358 +	DEBUG(6) fprintf(stderr, "parse_network: %s\n", line);
   9.359  
   9.360 -  p = line;
   9.361 -  q = buf;
   9.362 -  while((*p != 0) && (*p != '/') && (q < buf+255))
   9.363 -    *(q++) = *(p++);
   9.364 -  *q = 0;
   9.365 +	p = line;
   9.366 +	q = buf;
   9.367 +	while ((*p != 0) && (*p != '/') && (q < buf + 255))
   9.368 +		*(q++) = *(p++);
   9.369 +	*q = 0;
   9.370  
   9.371 -  if((addr.s_addr = inet_addr(buf)) != INADDR_NONE){
   9.372 -    if(*p){
   9.373 -      guint i;
   9.374 -      p++;
   9.375 -      i = atoi(p);
   9.376 -      if((i >= 0) && (i <= 32))
   9.377 -	n = i ? ~((1 << (32 - i)) - 1) : 0;
   9.378 -      else{
   9.379 -	fprintf(stderr, "'%d' is not a valid net mask (must be >= 0 and <= 32)\n", i);
   9.380 -	exit(EXIT_FAILURE);
   9.381 -      }
   9.382 -    }else
   9.383 -      n = 0;
   9.384 -    
   9.385 -    mask_addr.s_addr = htonl(n);
   9.386 -    net_addr.s_addr = mask_addr.s_addr & addr.s_addr;
   9.387 -  }else{
   9.388 -    fprintf(stderr, "'%s' is not a valid address (must be ip)\n", buf);
   9.389 -    exit(EXIT_FAILURE);
   9.390 -  }
   9.391 +	if ((addr.s_addr = inet_addr(buf)) != INADDR_NONE) {
   9.392 +		if (*p) {
   9.393 +			guint i;
   9.394 +			p++;
   9.395 +			i = atoi(p);
   9.396 +			if ((i >= 0) && (i <= 32))
   9.397 +				n = i ? ~((1 << (32 - i)) - 1) : 0;
   9.398 +			else {
   9.399 +				fprintf(stderr, "'%d' is not a valid net mask (must be >= 0 and <= 32)\n", i);
   9.400 +				exit(EXIT_FAILURE);
   9.401 +			}
   9.402 +		} else
   9.403 +			n = 0;
   9.404  
   9.405 -  p_net_addr = g_malloc(sizeof(struct in_addr));
   9.406 -  p_net_addr->s_addr = net_addr.s_addr;
   9.407 -  return p_net_addr;
   9.408 +		mask_addr.s_addr = htonl(n);
   9.409 +		net_addr.s_addr = mask_addr.s_addr & addr.s_addr;
   9.410 +	} else {
   9.411 +		fprintf(stderr, "'%s' is not a valid address (must be ip)\n", buf);
   9.412 +		exit(EXIT_FAILURE);
   9.413 +	}
   9.414 +
   9.415 +	p_net_addr = g_malloc(sizeof(struct in_addr));
   9.416 +	p_net_addr->s_addr = net_addr.s_addr;
   9.417 +	return p_net_addr;
   9.418  }
   9.419  #endif
   9.420  
   9.421 -static
   9.422 -gboolean eat_comments(FILE *in)
   9.423 +static gboolean
   9.424 +eat_comments(FILE * in)
   9.425  {
   9.426 -  gint c;
   9.427 +	gint c;
   9.428  
   9.429 -  for(c = fgetc(in); (c == '#' || isspace(c)) && c != EOF; c = fgetc(in)){
   9.430 -    if(c == '#'){
   9.431 -      gint c;
   9.432 -      for(c = fgetc(in); (c != '\n') && (c != EOF); c = fgetc(in));
   9.433 -    }
   9.434 -  }
   9.435 -  if(c == EOF) return FALSE;
   9.436 -  ungetc(c, in);
   9.437 -  return TRUE;
   9.438 +	for (c = fgetc(in); (c == '#' || isspace(c)) && c != EOF;
   9.439 +		 c = fgetc(in)) {
   9.440 +		if (c == '#') {
   9.441 +			gint c;
   9.442 +			for (c = fgetc(in); (c != '\n') && (c != EOF); c = fgetc(in));
   9.443 +		}
   9.444 +	}
   9.445 +	if (c == EOF)
   9.446 +		return FALSE;
   9.447 +	ungetc(c, in);
   9.448 +	return TRUE;
   9.449  }
   9.450  
   9.451  /* after parsing, eat trailing character until LF */
   9.452 -static
   9.453 -gboolean eat_line_trailing(FILE *in)
   9.454 +static gboolean
   9.455 +eat_line_trailing(FILE * in)
   9.456  {
   9.457 -  gint c;
   9.458 +	gint c;
   9.459  
   9.460 -  for(c = fgetc(in); c != EOF && c != '\n'; c = fgetc(in));
   9.461 -  if(c == EOF) return FALSE;
   9.462 -  return TRUE;
   9.463 +	for (c = fgetc(in); c != EOF && c != '\n'; c = fgetc(in));
   9.464 +	if (c == EOF)
   9.465 +		return FALSE;
   9.466 +	return TRUE;
   9.467  }
   9.468  
   9.469 -static
   9.470 -gboolean eat_spaces(FILE *in)
   9.471 +static gboolean
   9.472 +eat_spaces(FILE * in)
   9.473  {
   9.474 -  gint c;
   9.475 -  
   9.476 -  for(c = fgetc(in); c != EOF && isspace(c); c = fgetc(in));
   9.477 -  if(c == EOF) return FALSE;
   9.478 -  ungetc(c, in);
   9.479 -  return TRUE;
   9.480 +	gint c;
   9.481 +
   9.482 +	for (c = fgetc(in); c != EOF && isspace(c); c = fgetc(in));
   9.483 +	if (c == EOF)
   9.484 +		return FALSE;
   9.485 +	ungetc(c, in);
   9.486 +	return TRUE;
   9.487  }
   9.488  
   9.489 -static
   9.490 -gboolean read_lval(FILE *in, gchar *buf, gint size)
   9.491 +static gboolean
   9.492 +read_lval(FILE * in, gchar * buf, gint size)
   9.493  {
   9.494 -  gint c;
   9.495 -  gchar *ptr = buf;
   9.496 -  
   9.497 -  DEBUG(6) fprintf(stderr, "read_lval()\n");
   9.498 +	gint c;
   9.499 +	gchar *ptr = buf;
   9.500  
   9.501 -  if(!eat_spaces(in)) return FALSE;
   9.502 +	DEBUG(6) fprintf(stderr, "read_lval()\n");
   9.503  
   9.504 -  c = fgetc(in);
   9.505 -  DEBUG(6) fprintf(stderr, "read_lval() 2\n");
   9.506 -  while((isalnum(c) || c == '_' || c == '-' || c == '.')
   9.507 -	&& (ptr < buf+size-1)
   9.508 -	&& (c != EOF)
   9.509 -	){
   9.510 -    *ptr = c; ptr++;
   9.511 -    c = fgetc(in);
   9.512 -  }
   9.513 -  *ptr = 0;
   9.514 -  ungetc(c, in);
   9.515 +	if (!eat_spaces(in))
   9.516 +		return FALSE;
   9.517  
   9.518 -  if(c == EOF){
   9.519 -    fprintf(stderr, "unexpected EOF after %s\n", buf);
   9.520 -    return FALSE;
   9.521 -  }else if(ptr >= buf+size-1){
   9.522 -    fprintf(stderr, "lval too long\n");
   9.523 -  }
   9.524 +	c = fgetc(in);
   9.525 +	DEBUG(6) fprintf(stderr, "read_lval() 2\n");
   9.526 +	while ((isalnum(c) || c == '_' || c == '-' || c == '.')
   9.527 +	       && (ptr < buf + size - 1)
   9.528 +	       && (c != EOF)) {
   9.529 +		*ptr = c;
   9.530 +		ptr++;
   9.531 +		c = fgetc(in);
   9.532 +	}
   9.533 +	*ptr = 0;
   9.534 +	ungetc(c, in);
   9.535  
   9.536 -  eat_spaces(in);
   9.537 +	if (c == EOF) {
   9.538 +		fprintf(stderr, "unexpected EOF after %s\n", buf);
   9.539 +		return FALSE;
   9.540 +	} else if (ptr >= buf + size - 1) {
   9.541 +		fprintf(stderr, "lval too long\n");
   9.542 +	}
   9.543  
   9.544 -  DEBUG(6) fprintf(stderr, "lval = %s\n", buf);
   9.545 +	eat_spaces(in);
   9.546  
   9.547 -  return buf[0] != 0;
   9.548 +	DEBUG(6) fprintf(stderr, "lval = %s\n", buf);
   9.549 +
   9.550 +	return buf[0] != 0;
   9.551  }
   9.552  
   9.553 -static
   9.554 -gboolean read_rval(FILE *in, gchar *buf, gint size)
   9.555 +static gboolean
   9.556 +read_rval(FILE * in, gchar * buf, gint size)
   9.557  {
   9.558 -  gint c;
   9.559 -  gchar *ptr = buf;
   9.560 -  
   9.561 -  DEBUG(6) fprintf(stderr, "read_rval()\n");
   9.562 +	gint c;
   9.563 +	gchar *ptr = buf;
   9.564  
   9.565 -  if(!eat_spaces(in)) return FALSE;
   9.566 +	DEBUG(6) fprintf(stderr, "read_rval()\n");
   9.567  
   9.568 -  c = fgetc(in);
   9.569 -  if(c != '\"'){
   9.570 -    while((isalnum(c) || c == '_' || c == '-' || c == '.' || c == '/' || c == '@' || c == ';')
   9.571 -	  && (ptr < buf+size-1)
   9.572 -	  && (c != EOF)
   9.573 -	  ){
   9.574 -      *ptr = c; ptr++;
   9.575 -      c = fgetc(in);
   9.576 -    }
   9.577 -    *ptr = 0;
   9.578 -    ungetc(c, in);
   9.579 -  }else{
   9.580 -    gboolean escape = FALSE;
   9.581 -    c = fgetc(in);
   9.582 -    while(((c != '\"') || escape) && (ptr < buf+size-1)){
   9.583 -      if(c != '\n'){ /* ignore line breaks */
   9.584 -	if((c == '\\') && (!escape)){
   9.585 -	  escape = TRUE;
   9.586 -	}else{
   9.587 -	  *ptr = c; ptr++;
   9.588 -	  escape = FALSE;
   9.589 +	if (!eat_spaces(in))
   9.590 +		return FALSE;
   9.591 +
   9.592 +	c = fgetc(in);
   9.593 +	if (c != '\"') {
   9.594 +		while ((isalnum(c) || c == '_' || c == '-' || c == '.' || c == '/'
   9.595 +		       || c == '@' || c == ';')
   9.596 +		       && (ptr < buf + size - 1)
   9.597 +		       && (c != EOF)) {
   9.598 +			*ptr = c;
   9.599 +			ptr++;
   9.600 +			c = fgetc(in);
   9.601 +		}
   9.602 +		*ptr = 0;
   9.603 +		ungetc(c, in);
   9.604 +	} else {
   9.605 +		gboolean escape = FALSE;
   9.606 +		c = fgetc(in);
   9.607 +		while (((c != '\"') || escape) && (ptr < buf + size - 1)) {
   9.608 +			if (c != '\n') {	/* ignore line breaks */
   9.609 +				if ((c == '\\') && (!escape)) {
   9.610 +					escape = TRUE;
   9.611 +				} else {
   9.612 +					*ptr = c;
   9.613 +					ptr++;
   9.614 +					escape = FALSE;
   9.615 +				}
   9.616 +			}
   9.617 +			c = fgetc(in);
   9.618 +		}
   9.619 +		*ptr = 0;
   9.620  	}
   9.621 -      }
   9.622 -      c = fgetc(in);
   9.623 -    }
   9.624 -    *ptr = 0;
   9.625 -  }
   9.626 -  
   9.627 -  eat_line_trailing(in);
   9.628  
   9.629 -  DEBUG(6) fprintf(stderr, "rval = %s\n", buf);
   9.630 +	eat_line_trailing(in);
   9.631  
   9.632 -  return TRUE;
   9.633 +	DEBUG(6) fprintf(stderr, "rval = %s\n", buf);
   9.634 +
   9.635 +	return TRUE;
   9.636  }
   9.637  
   9.638 -static
   9.639 -gboolean read_statement(FILE *in,
   9.640 -			gchar *lval, gint lsize,
   9.641 -			gchar *rval, gint rsize)
   9.642 +static gboolean
   9.643 +read_statement(FILE * in, gchar * lval, gint lsize, gchar * rval, gint rsize)
   9.644  {
   9.645 -  gint c;
   9.646 +	gint c;
   9.647  
   9.648 -  DEBUG(6) fprintf(stderr, "read_statement()\n");
   9.649 +	DEBUG(6) fprintf(stderr, "read_statement()\n");
   9.650  
   9.651 -  /* eat comments and empty lines: */
   9.652 -  if(!eat_comments(in)) return FALSE;
   9.653 +	/* eat comments and empty lines: */
   9.654 +	if (!eat_comments(in))
   9.655 +		return FALSE;
   9.656  
   9.657 -  DEBUG(6) fprintf(stderr, "read_statement() 1\n");
   9.658 +	DEBUG(6) fprintf(stderr, "read_statement() 1\n");
   9.659  
   9.660 -  if(read_lval(in, lval, lsize)){
   9.661 -    DEBUG(6) fprintf(stderr, "lval = %s\n", lval);
   9.662 -    if((c = fgetc(in) == '=')){
   9.663 -      if(read_rval(in, rval, rsize)){
   9.664 -	DEBUG(6) fprintf(stderr, "rval = %s\n", rval);
   9.665 -	return TRUE;
   9.666 -      }
   9.667 -    }else{
   9.668 -      fprintf(stderr, "'=' expected after %s, char was '%c'\n", lval, c);
   9.669 -    }
   9.670 -  }
   9.671 -  return FALSE;
   9.672 +	if (read_lval(in, lval, lsize)) {
   9.673 +		DEBUG(6) fprintf(stderr, "lval = %s\n", lval);
   9.674 +		if ((c = fgetc(in) == '=')) {
   9.675 +			if (read_rval(in, rval, rsize)) {
   9.676 +				DEBUG(6) fprintf(stderr, "rval = %s\n", rval);
   9.677 +				return TRUE;
   9.678 +			}
   9.679 +		} else {
   9.680 +			fprintf(stderr, "'=' expected after %s, char was '%c'\n", lval,
   9.681 +					c);
   9.682 +		}
   9.683 +	}
   9.684 +	return FALSE;
   9.685  }
   9.686  
   9.687 -gboolean read_conf(gchar *filename)
   9.688 +gboolean
   9.689 +read_conf(gchar * filename)
   9.690  {
   9.691 -  FILE *in;
   9.692 +	FILE *in;
   9.693  
   9.694 -  conf.log_max_pri = 7;
   9.695 +	conf.log_max_pri = 7;
   9.696 +	conf.remote_port = 25;
   9.697 +	conf.do_relay = TRUE;
   9.698 +	conf.alias_local_cmp = strcmp;
   9.699 +	conf.max_defer_time = 86400 * 4;  /* 4 days */
   9.700  
   9.701 -  conf.remote_port = 25;
   9.702 +	if ((in = fopen(filename, "r"))) {
   9.703 +		gchar lval[256], rval[2048];
   9.704 +		while (read_statement(in, lval, 256, rval, 2048)) {
   9.705 +			if (strcmp(lval, "debug_level") == 0)
   9.706 +				conf.debug_level = atoi(rval);
   9.707 +			else if (strcmp(lval, "run_as_user") == 0) {
   9.708 +				if (!conf.run_as_user)  /* you should not be able to reset that flag */
   9.709 +					conf.run_as_user = parse_boolean(rval);
   9.710 +			} else if (strcmp(lval, "use_syslog") == 0)
   9.711 +				conf.use_syslog = parse_boolean(rval);
   9.712 +			else if (strcmp(lval, "mail_dir") == 0)
   9.713 +				conf.mail_dir = g_strdup(rval);
   9.714 +			else if (strcmp(lval, "lock_dir") == 0)
   9.715 +				conf.lock_dir = g_strdup(rval);
   9.716 +			else if (strcmp(lval, "spool_dir") == 0)
   9.717 +				conf.spool_dir = g_strdup(rval);
   9.718 +			else if (strcmp(lval, "log_dir") == 0)
   9.719 +				conf.log_dir = g_strdup(rval);
   9.720 +			else if (strcmp(lval, "host_name") == 0) {
   9.721 +				if (rval[0] != '/')
   9.722 +					conf.host_name = g_strdup(rval);
   9.723 +				else {
   9.724 +					char buf[256];
   9.725 +					FILE *fptr = fopen(rval, "rt");
   9.726 +					if (fptr) {
   9.727 +						fgets(buf, 255, fptr);
   9.728 +						g_strchomp(buf);
   9.729 +						conf.host_name = g_strdup(buf);
   9.730 +						fclose(fptr);
   9.731 +					} else {
   9.732 +						fprintf(stderr, "could not open %s: %s\n", rval,
   9.733 +								strerror(errno));
   9.734 +						return FALSE;
   9.735 +					}
   9.736 +				}
   9.737 +			} else if (strcmp(lval, "remote_port") == 0) {
   9.738 +				fprintf(stderr, "the remote_port option is now deprecated. Use 'mail_host' in the\n"
   9.739 +				        "route configuration instead. See man masqmail.route\n");
   9.740 +				conf.remote_port = atoi(rval);
   9.741 +			} else if (strcmp(lval, "local_hosts") == 0)
   9.742 +				conf.local_hosts = parse_list(rval, FALSE);
   9.743 +			else if (strcmp(lval, "local_addresses") == 0)
   9.744 +				conf.local_addresses = parse_list(rval, TRUE);
   9.745 +			else if (strcmp(lval, "not_local_addresses") == 0)
   9.746 +				conf.not_local_addresses = parse_list(rval, TRUE);
   9.747 +			else if (strcmp(lval, "local_nets") == 0)
   9.748 +				conf.local_nets = parse_list(rval, FALSE);
   9.749 +			else if (strcmp(lval, "do_save_envelope_to") == 0)
   9.750 +				conf.do_save_envelope_to = parse_boolean(rval);
   9.751 +			else if (strcmp(lval, "defer_all") == 0)
   9.752 +				conf.defer_all = parse_boolean(rval);
   9.753 +			else if (strcmp(lval, "do_relay") == 0)
   9.754 +				conf.do_relay = parse_boolean(rval);
   9.755 +			else if (strcmp(lval, "alias_file") == 0) {
   9.756 +				conf.alias_file = g_strdup(rval);
   9.757 +			} else if (strcmp(lval, "alias_local_caseless") == 0) {
   9.758 +				conf.alias_local_cmp = parse_boolean(rval) ? strcasecmp : strcmp;
   9.759 +			} else if (strcmp(lval, "mbox_default") == 0) {
   9.760 +				conf.mbox_default = g_strdup(rval);
   9.761 +			} else if (strcmp(lval, "mbox_users") == 0) {
   9.762 +				conf.mbox_users = parse_list(rval, TRUE);
   9.763 +			} else if (strcmp(lval, "mda_users") == 0) {
   9.764 +				conf.mda_users = parse_list(rval, TRUE);
   9.765 +			} else if (strcmp(lval, "maildir_users") == 0) {
   9.766 +				conf.maildir_users = parse_list(rval, TRUE);
   9.767 +			} else if (strcmp(lval, "mda") == 0) {
   9.768 +				conf.mda = g_strdup(rval);
   9.769 +			} else if (strcmp(lval, "mda_fromline") == 0) {
   9.770 +				conf.mda_fromline = parse_boolean(rval);
   9.771 +			} else if (strcmp(lval, "mda_fromhack") == 0) {
   9.772 +				conf.mda_fromhack = parse_boolean(rval);
   9.773 +			} else if (strcmp(lval, "pipe_fromline") == 0) {
   9.774 +				conf.pipe_fromline = parse_boolean(rval);
   9.775 +			} else if (strcmp(lval, "pipe_fromhack") == 0) {
   9.776 +				conf.pipe_fromhack = parse_boolean(rval);
   9.777 +			} else if (strcmp(lval, "listen_addresses") == 0) {
   9.778 +				GList *node;
   9.779 +				GList *tmp_list = parse_list(rval, FALSE);
   9.780  
   9.781 -  conf.do_relay = TRUE;
   9.782 +				conf.listen_addresses = NULL;
   9.783 +				foreach(tmp_list, node) {
   9.784 +					conf.listen_addresses = g_list_append(conf.listen_addresses, parse_interface((gchar *) (node-> data), 25));
   9.785 +					g_free(node->data);
   9.786 +				}
   9.787 +				g_list_free(tmp_list);
   9.788 +			} else if (strcmp(lval, "ident_trusted_nets") == 0) {
   9.789 +#ifdef ENABLE_IDENT
   9.790 +				GList *node;
   9.791 +				GList *tmp_list = parse_list(rval, FALSE);
   9.792  
   9.793 -  conf.alias_local_cmp = strcmp;
   9.794 +				conf.ident_trusted_nets = NULL;
   9.795 +				foreach(tmp_list, node) {
   9.796 +					conf.ident_trusted_nets = g_list_append(conf.ident_trusted_nets, parse_network((gchar *) (node->data), 25));
   9.797 +					g_free(node->data);
   9.798 +				}
   9.799 +				g_list_free(tmp_list);
   9.800 +#else
   9.801 +				fprintf(stderr, "%s ignored: not compiled with ident support\n", lval);
   9.802 +#endif
   9.803 +			} else if ((strncmp(lval, "connect_route.", 14) == 0)
   9.804 +			           || (strncmp(lval, "online_routes.", 14) == 0)) {
   9.805 +				GList *file_list = parse_list(rval, FALSE);
   9.806 +				table_pair *pair = create_pair(&(lval[14]), file_list);
   9.807 +				conf.connect_routes = g_list_append(conf.connect_routes, pair);
   9.808 +			} else if (strcmp(lval, "local_net_route") == 0) {
   9.809 +				conf.local_net_routes = parse_list(rval, FALSE);
   9.810 +			} else if (strcmp(lval, "online_detect") == 0)
   9.811 +				conf.online_detect = g_strdup(rval);
   9.812 +			else if (strcmp(lval, "online_file") == 0)
   9.813 +				conf.online_file = g_strdup(rval);
   9.814 +			else if (strcmp(lval, "online_pipe") == 0)
   9.815 +				conf.online_pipe = g_strdup(rval);
   9.816 +			else if (strcmp(lval, "mserver_iface") == 0)
   9.817 +				conf.mserver_iface = parse_interface(rval, 224);
   9.818 +			else if (strcmp(lval, "do_queue") == 0)
   9.819 +				conf.do_queue = parse_boolean(rval);
   9.820 +			else if (strncmp(lval, "get.", 4) == 0) {
   9.821 +#ifdef ENABLE_POP3
   9.822 +				table_pair *pair = create_pair_string(&(lval[4]), rval);
   9.823 +				conf.get_names = g_list_append(conf.get_names, pair);
   9.824 +#else
   9.825 +				fprintf(stderr, "get.<name> ignored: not compiled with pop support\n");
   9.826 +#endif
   9.827 +			} else if (strncmp(lval, "online_gets.", 12) == 0) {
   9.828 +#ifdef ENABLE_POP3
   9.829 +				GList *file_list = parse_list(rval, FALSE);
   9.830 +				table_pair *pair = create_pair(&(lval[12]), file_list);
   9.831 +				conf.online_gets = g_list_append(conf.online_gets, pair);
   9.832 +#else
   9.833 +				fprintf(stderr, "online_gets.<name> ignored: not compiled with pop support\n");
   9.834 +#endif
   9.835 +			} else if (strcmp(lval, "errmsg_file") == 0)
   9.836 +				conf.errmsg_file = g_strdup(rval);
   9.837 +			else if (strcmp(lval, "warnmsg_file") == 0)
   9.838 +				conf.warnmsg_file = g_strdup(rval);
   9.839 +			else if (strcmp(lval, "warn_intervals") == 0)
   9.840 +				conf.warn_intervals = parse_list(rval, FALSE);
   9.841 +			else if (strcmp(lval, "max_defer_time") == 0) {
   9.842 +				gint dummy;
   9.843 +				gint ival = time_interval(rval, &dummy);
   9.844 +				if (ival < 0)
   9.845 +					fprintf(stderr, "invalid time interval for 'max_defer_time': %s\n", rval);
   9.846 +				else
   9.847 +					conf.max_defer_time = ival;
   9.848 +			} else if (strcmp(lval, "log_user") == 0)
   9.849 +				conf.log_user = g_strdup(rval);
   9.850  
   9.851 -  conf.max_defer_time = 86400*4; /* 4 days */
   9.852 +			else
   9.853 +				fprintf(stderr, "var '%s' not (yet) known, ignored\n", lval);
   9.854 +		}
   9.855 +		fclose(in);
   9.856  
   9.857 -  if((in = fopen(filename, "r"))){
   9.858 -    gchar lval[256], rval[2048];
   9.859 -    while(read_statement(in, lval, 256, rval, 2048)){
   9.860 -      if(strcmp(lval, "debug_level") == 0)
   9.861 -	conf.debug_level = atoi(rval);
   9.862 -      else if(strcmp(lval, "run_as_user") == 0){
   9.863 -	if(!conf.run_as_user) /* you should not be able
   9.864 -				 to reset that flag */
   9.865 -	  conf.run_as_user = parse_boolean(rval);
   9.866 -      }else if(strcmp(lval, "use_syslog") == 0)
   9.867 -	conf.use_syslog = parse_boolean(rval);
   9.868 -      else if(strcmp(lval, "mail_dir") == 0)
   9.869 -	conf.mail_dir = g_strdup(rval);
   9.870 -      else if(strcmp(lval, "lock_dir") == 0)
   9.871 -	conf.lock_dir = g_strdup(rval);
   9.872 -      else if(strcmp(lval, "spool_dir") == 0)
   9.873 -	conf.spool_dir = g_strdup(rval);
   9.874 -      else if(strcmp(lval, "log_dir") == 0)
   9.875 -	conf.log_dir = g_strdup(rval);
   9.876 -      else if(strcmp(lval, "host_name") == 0){
   9.877 -	if(rval[0] != '/')
   9.878 -	  conf.host_name = g_strdup(rval);
   9.879 -	else{
   9.880 -	  char buf[256];
   9.881 -	  FILE *fptr = fopen(rval, "rt");
   9.882 -	  if(fptr){
   9.883 -	    fgets(buf, 255, fptr);
   9.884 -	    g_strchomp(buf);
   9.885 -	    conf.host_name = g_strdup(buf);
   9.886 -	    fclose(fptr);
   9.887 -	  }else{
   9.888 -	    fprintf(stderr, "could not open %s: %s\n", rval, strerror(errno));
   9.889 -	    return FALSE;
   9.890 -	  }
   9.891 -	}
   9.892 -      }
   9.893 -      else if(strcmp(lval, "remote_port") == 0){
   9.894 -	fprintf(stderr,
   9.895 -		"the remote_port option is now deprecated. Use 'mail_host' in the\n"
   9.896 -		"route configuration instead. See man masqmail.route\n");
   9.897 -	conf.remote_port = atoi(rval);
   9.898 -      }else if(strcmp(lval, "local_hosts") == 0)
   9.899 -	conf.local_hosts = parse_list(rval, FALSE);
   9.900 -      else if(strcmp(lval, "local_addresses") == 0)
   9.901 -	conf.local_addresses = parse_list(rval, TRUE);
   9.902 -      else if(strcmp(lval, "not_local_addresses") == 0)
   9.903 -	conf.not_local_addresses = parse_list(rval, TRUE);
   9.904 -      else if(strcmp(lval, "local_nets") == 0)
   9.905 -	conf.local_nets = parse_list(rval, FALSE);
   9.906 -      else if(strcmp(lval, "do_save_envelope_to") == 0)
   9.907 -	conf.do_save_envelope_to = parse_boolean(rval);
   9.908 -      else if(strcmp(lval, "defer_all") == 0)
   9.909 -	conf.defer_all = parse_boolean(rval);
   9.910 -      else if(strcmp(lval, "do_relay") == 0)
   9.911 -	conf.do_relay = parse_boolean(rval);
   9.912 -      else if(strcmp(lval, "alias_file") == 0){
   9.913 -	conf.alias_file = g_strdup(rval);
   9.914 -      }else if(strcmp(lval, "alias_local_caseless") == 0){
   9.915 -	conf.alias_local_cmp = parse_boolean(rval) ? strcasecmp : strcmp;
   9.916 -      }else if(strcmp(lval, "mbox_default") == 0){
   9.917 -	conf.mbox_default = g_strdup(rval);
   9.918 -      }else if(strcmp(lval, "mbox_users") == 0){
   9.919 -	conf.mbox_users = parse_list(rval, TRUE);
   9.920 -      }else if(strcmp(lval, "mda_users") == 0){
   9.921 -	conf.mda_users = parse_list(rval, TRUE);
   9.922 -      }else if(strcmp(lval, "maildir_users") == 0){
   9.923 -	conf.maildir_users = parse_list(rval, TRUE);
   9.924 -      }else if(strcmp(lval, "mda") == 0){
   9.925 -	conf.mda = g_strdup(rval);
   9.926 -      }else if(strcmp(lval, "mda_fromline") == 0){
   9.927 -	conf.mda_fromline = parse_boolean(rval);
   9.928 -      }else if(strcmp(lval, "mda_fromhack") == 0){
   9.929 -	conf.mda_fromhack = parse_boolean(rval);
   9.930 -      }else if(strcmp(lval, "pipe_fromline") == 0){
   9.931 -	conf.pipe_fromline = parse_boolean(rval);
   9.932 -      }else if(strcmp(lval, "pipe_fromhack") == 0){
   9.933 -	conf.pipe_fromhack = parse_boolean(rval);
   9.934 -      }else if(strcmp(lval, "listen_addresses") == 0){
   9.935 -	GList *node;
   9.936 -	GList *tmp_list = parse_list(rval, FALSE);
   9.937 -	    
   9.938 -	conf.listen_addresses = NULL;
   9.939 -	foreach(tmp_list, node){
   9.940 -	  conf.listen_addresses =
   9.941 -	    g_list_append(conf.listen_addresses,
   9.942 -			  parse_interface((gchar *)(node->data), 25));
   9.943 -	  g_free(node->data);
   9.944 -	}
   9.945 -	g_list_free(tmp_list);
   9.946 -      }
   9.947 -      else if(strcmp(lval, "ident_trusted_nets") == 0){
   9.948 -#ifdef ENABLE_IDENT
   9.949 -	GList *node;
   9.950 -	GList *tmp_list = parse_list(rval, FALSE);
   9.951 -	    
   9.952 -	conf.ident_trusted_nets = NULL;
   9.953 -	foreach(tmp_list, node){
   9.954 -	  conf.ident_trusted_nets =
   9.955 -	    g_list_append(conf.ident_trusted_nets,
   9.956 -			  parse_network((gchar *)(node->data), 25));
   9.957 -	  g_free(node->data);
   9.958 -	}
   9.959 -	g_list_free(tmp_list);
   9.960 -#else
   9.961 -	fprintf(stderr, "%s ignored: not compiled with ident support\n", lval);
   9.962 -#endif
   9.963 -      }
   9.964 -      else if((strncmp(lval, "connect_route.", 14) == 0) ||
   9.965 -	      (strncmp(lval, "online_routes.", 14) == 0)){
   9.966 -	GList *file_list = parse_list(rval, FALSE);
   9.967 -	table_pair *pair = create_pair(&(lval[14]), file_list);
   9.968 -	conf.connect_routes = g_list_append(conf.connect_routes, pair);
   9.969 -      }
   9.970 -      else if(strcmp(lval, "local_net_route") == 0){
   9.971 -	conf.local_net_routes = parse_list(rval, FALSE);
   9.972 -      }
   9.973 -      else if(strcmp(lval, "online_detect") == 0)
   9.974 -	conf.online_detect = g_strdup(rval);
   9.975 -      else if(strcmp(lval, "online_file") == 0)
   9.976 -	conf.online_file = g_strdup(rval);
   9.977 -      else if(strcmp(lval, "online_pipe") == 0)
   9.978 -	conf.online_pipe = g_strdup(rval);
   9.979 -      else if(strcmp(lval, "mserver_iface") == 0)
   9.980 -	conf.mserver_iface = parse_interface(rval, 224);
   9.981 -      else if(strcmp(lval, "do_queue") == 0)
   9.982 -	conf.do_queue = parse_boolean(rval);
   9.983 -      else if(strncmp(lval, "get.", 4) == 0){
   9.984 -#ifdef ENABLE_POP3
   9.985 -	table_pair *pair = create_pair_string(&(lval[4]), rval);
   9.986 -	conf.get_names = g_list_append(conf.get_names, pair);
   9.987 -#else
   9.988 -	fprintf(stderr, "get.<name> ignored: not compiled with pop support\n");
   9.989 -#endif
   9.990 -      }
   9.991 -      else if(strncmp(lval, "online_gets.", 12) == 0){
   9.992 -#ifdef ENABLE_POP3
   9.993 -	GList *file_list = parse_list(rval, FALSE);
   9.994 -	table_pair *pair = create_pair(&(lval[12]), file_list);
   9.995 -	conf.online_gets = g_list_append(conf.online_gets, pair);
   9.996 -#else
   9.997 -	fprintf(stderr, "online_gets.<name> ignored: not compiled with pop support\n");
   9.998 -#endif
   9.999 -      }
  9.1000 -      else if(strcmp(lval, "errmsg_file") == 0)
  9.1001 -	conf.errmsg_file = g_strdup(rval);
  9.1002 -      else if(strcmp(lval, "warnmsg_file") == 0)
  9.1003 -	conf.warnmsg_file = g_strdup(rval);
  9.1004 -      else if(strcmp(lval, "warn_intervals") == 0)
  9.1005 -	conf.warn_intervals = parse_list(rval, FALSE);
  9.1006 -      else if(strcmp(lval, "max_defer_time") == 0){
  9.1007 -	gint dummy;
  9.1008 -	gint ival = time_interval(rval, &dummy);
  9.1009 -	if(ival < 0)
  9.1010 -	  fprintf(stderr, "invalid time interval for 'max_defer_time': %s\n", rval);
  9.1011 -	else
  9.1012 -	  conf.max_defer_time = ival;
  9.1013 -      }else if(strcmp(lval, "log_user") == 0)
  9.1014 -	conf.log_user = g_strdup(rval);
  9.1015 +		if (conf.errmsg_file == NULL)
  9.1016 +			conf.errmsg_file = g_strdup(DATA_DIR "/tpl/failmsg.tpl");
  9.1017 +		if (conf.warnmsg_file == NULL)
  9.1018 +			conf.warnmsg_file = g_strdup(DATA_DIR "/tpl/warnmsg.tpl");
  9.1019  
  9.1020 -      else
  9.1021 -	fprintf(stderr, "var '%s' not (yet) known, ignored\n", lval);
  9.1022 -    }
  9.1023 -    fclose(in);
  9.1024 +		if (conf.lock_dir == NULL)
  9.1025 +			conf.lock_dir = g_strdup_printf("%s/lock/", conf.spool_dir);
  9.1026  
  9.1027 -    if(conf.errmsg_file == NULL)
  9.1028 -      conf.errmsg_file = g_strdup(DATA_DIR"/tpl/failmsg.tpl");
  9.1029 -    if(conf.warnmsg_file == NULL)
  9.1030 -      conf.warnmsg_file = g_strdup(DATA_DIR"/tpl/warnmsg.tpl");
  9.1031 +		if (conf.mbox_default == NULL)
  9.1032 +			conf.mbox_default = g_strdup("mbox");
  9.1033  
  9.1034 -    if(conf.lock_dir == NULL)
  9.1035 -      conf.lock_dir = g_strdup_printf("%s/lock/", conf.spool_dir);
  9.1036 +		if (conf.warn_intervals == NULL)
  9.1037 +			conf.warn_intervals = parse_list("1h;4h;8h;1d;2d;3d", FALSE);
  9.1038  
  9.1039 -    if(conf.mbox_default == NULL)
  9.1040 -      conf.mbox_default = g_strdup("mbox");
  9.1041 -
  9.1042 -    if(conf.warn_intervals == NULL)
  9.1043 -      conf.warn_intervals = parse_list("1h;4h;8h;1d;2d;3d", FALSE);
  9.1044 -
  9.1045 -    return TRUE;
  9.1046 -  }else
  9.1047 -    fprintf(stderr, "could not open config file %s: %s\n", filename, strerror(errno));
  9.1048 -  return FALSE;
  9.1049 +		return TRUE;
  9.1050 +	} else
  9.1051 +		fprintf(stderr, "could not open config file %s: %s\n", filename, strerror(errno));
  9.1052 +	return FALSE;
  9.1053  }
  9.1054  
  9.1055 -connect_route *read_route(gchar *filename, gboolean is_local_net)
  9.1056 +connect_route*
  9.1057 +read_route(gchar * filename, gboolean is_local_net)
  9.1058  {
  9.1059 -  gboolean ok = FALSE;
  9.1060 -  FILE *in;
  9.1061 +	gboolean ok = FALSE;
  9.1062 +	FILE *in;
  9.1063  
  9.1064 -  connect_route *route = g_malloc(sizeof(connect_route));
  9.1065 -  memset(route, 0, sizeof(connect_route));
  9.1066 +	connect_route *route = g_malloc(sizeof(connect_route));
  9.1067 +	memset(route, 0, sizeof(connect_route));
  9.1068  
  9.1069 -  DEBUG(5) debugf("read_route, filename = %s\n", filename);
  9.1070 +	DEBUG(5) debugf("read_route, filename = %s\n", filename);
  9.1071  
  9.1072 -  route->filename = g_strdup(filename);
  9.1073 -  route->name = g_strdup(filename); /* quick hack */
  9.1074 +	route->filename = g_strdup(filename);
  9.1075 +	route->name = g_strdup(filename);  /* quick hack */
  9.1076  
  9.1077 -  route->protocol = g_strdup("smtp");
  9.1078 -  route->expand_h_sender_address = TRUE;
  9.1079 +	route->protocol = g_strdup("smtp");
  9.1080 +	route->expand_h_sender_address = TRUE;
  9.1081  
  9.1082 -  route->is_local_net = is_local_net;
  9.1083 +	route->is_local_net = is_local_net;
  9.1084  
  9.1085 -  route->do_pipelining = TRUE;
  9.1086 +	route->do_pipelining = TRUE;
  9.1087  
  9.1088 -  if((in = fopen(route->filename, "r"))){
  9.1089 -    gchar lval[256], rval[2048];
  9.1090 -    while(read_statement(in, lval, 256, rval, 2048)){
  9.1091 -      if(strcmp(lval, "protocol") == 0)
  9.1092 -	route->protocol = g_strdup(rval);
  9.1093 -      else if(strcmp(lval, "mail_host") == 0)
  9.1094 -	route->mail_host = parse_interface(rval, conf.remote_port);
  9.1095 -      else if(strcmp(lval, "helo_name") == 0)
  9.1096 -	route->helo_name = g_strdup(rval);
  9.1097 -      else if(strcmp(lval, "wrapper") == 0)
  9.1098 -	route->wrapper = g_strdup(rval);
  9.1099 -      else if(strcmp(lval, "connect_error_fail") == 0)
  9.1100 -	route->connect_error_fail = parse_boolean(rval);
  9.1101 -      else if(strcmp(lval, "do_correct_helo") == 0)
  9.1102 -	route->do_correct_helo = parse_boolean(rval);
  9.1103 -      else if(strcmp(lval, "do_pipelining") == 0)
  9.1104 -	route->do_pipelining = parse_boolean(rval);
  9.1105 -      else if(strcmp(lval, "allowed_return_paths") == 0)
  9.1106 -	route->allowed_return_paths = parse_address_list(rval, TRUE);
  9.1107 -      else if(strcmp(lval, "allowed_mail_locals") == 0)
  9.1108 -	route->allowed_mail_locals = parse_list(rval, TRUE);
  9.1109 -      else if(strcmp(lval, "not_allowed_return_paths") == 0)
  9.1110 -	route->not_allowed_return_paths = parse_address_list(rval, TRUE);
  9.1111 -      else if(strcmp(lval, "not_allowed_mail_locals") == 0)
  9.1112 -	route->not_allowed_mail_locals = parse_list(rval, TRUE);
  9.1113 -      else if(strcmp(lval, "allowed_rcpt_domains") == 0)
  9.1114 -	route->allowed_rcpt_domains = parse_list(rval, TRUE);
  9.1115 -      else if(strcmp(lval, "not_allowed_rcpt_domains") == 0)
  9.1116 -	route->not_allowed_rcpt_domains = parse_list(rval, TRUE);
  9.1117 -      else if(strcmp(lval, "set_h_from_domain") == 0)
  9.1118 -	route->set_h_from_domain = g_strdup(rval);
  9.1119 -      else if(strcmp(lval, "set_h_reply_to_domain") == 0)
  9.1120 -	route->set_h_reply_to_domain = g_strdup(rval);
  9.1121 -      else if(strcmp(lval, "set_return_path_domain") == 0)
  9.1122 -	route->set_return_path_domain = g_strdup(rval);
  9.1123 -      else if(strcmp(lval, "map_return_path_addresses") == 0){
  9.1124 -	GList *node, *list;
  9.1125 +	if ((in = fopen(route->filename, "r"))) {
  9.1126 +		gchar lval[256], rval[2048];
  9.1127 +		while (read_statement(in, lval, 256, rval, 2048)) {
  9.1128 +			if (strcmp(lval, "protocol") == 0)
  9.1129 +				route->protocol = g_strdup(rval);
  9.1130 +			else if (strcmp(lval, "mail_host") == 0)
  9.1131 +				route->mail_host = parse_interface(rval, conf.remote_port);
  9.1132 +			else if (strcmp(lval, "helo_name") == 0)
  9.1133 +				route->helo_name = g_strdup(rval);
  9.1134 +			else if (strcmp(lval, "wrapper") == 0)
  9.1135 +				route->wrapper = g_strdup(rval);
  9.1136 +			else if (strcmp(lval, "connect_error_fail") == 0)
  9.1137 +				route->connect_error_fail = parse_boolean(rval);
  9.1138 +			else if (strcmp(lval, "do_correct_helo") == 0)
  9.1139 +				route->do_correct_helo = parse_boolean(rval);
  9.1140 +			else if (strcmp(lval, "do_pipelining") == 0)
  9.1141 +				route->do_pipelining = parse_boolean(rval);
  9.1142 +			else if (strcmp(lval, "allowed_return_paths") == 0)
  9.1143 +				route->allowed_return_paths = parse_address_list(rval, TRUE);
  9.1144 +			else if (strcmp(lval, "allowed_mail_locals") == 0)
  9.1145 +				route->allowed_mail_locals = parse_list(rval, TRUE);
  9.1146 +			else if (strcmp(lval, "not_allowed_return_paths") == 0)
  9.1147 +				route->not_allowed_return_paths = parse_address_list(rval, TRUE);
  9.1148 +			else if (strcmp(lval, "not_allowed_mail_locals") == 0)
  9.1149 +				route->not_allowed_mail_locals = parse_list(rval, TRUE);
  9.1150 +			else if (strcmp(lval, "allowed_rcpt_domains") == 0)
  9.1151 +				route->allowed_rcpt_domains = parse_list(rval, TRUE);
  9.1152 +			else if (strcmp(lval, "not_allowed_rcpt_domains") == 0)
  9.1153 +				route->not_allowed_rcpt_domains = parse_list(rval, TRUE);
  9.1154 +			else if (strcmp(lval, "set_h_from_domain") == 0)
  9.1155 +				route->set_h_from_domain = g_strdup(rval);
  9.1156 +			else if (strcmp(lval, "set_h_reply_to_domain") == 0)
  9.1157 +				route->set_h_reply_to_domain = g_strdup(rval);
  9.1158 +			else if (strcmp(lval, "set_return_path_domain") == 0)
  9.1159 +				route->set_return_path_domain = g_strdup(rval);
  9.1160 +			else if (strcmp(lval, "map_return_path_addresses") == 0) {
  9.1161 +				GList *node, *list;
  9.1162  
  9.1163 -	list = parse_list(rval, TRUE);
  9.1164 -	foreach(list, node){
  9.1165 -	  gchar *item = (gchar *)(node->data);
  9.1166 -	  table_pair *pair = parse_table_pair(item, ':');
  9.1167 -	  address *addr = create_address((gchar *)(pair->value), TRUE);
  9.1168 -	  g_free(pair->value);
  9.1169 -	  pair->value = (gpointer *)addr;
  9.1170 -	  route->map_return_path_addresses =
  9.1171 -	    g_list_append(route->map_return_path_addresses, pair);
  9.1172 -	  g_free(item);
  9.1173 +				list = parse_list(rval, TRUE);
  9.1174 +				foreach(list, node) {
  9.1175 +					gchar *item = (gchar *) (node->data);
  9.1176 +					table_pair *pair = parse_table_pair(item, ':');
  9.1177 +					address *addr = create_address((gchar *) (pair->value), TRUE);
  9.1178 +					g_free(pair->value);
  9.1179 +					pair->value = (gpointer *) addr;
  9.1180 +					route->map_return_path_addresses = g_list_append(route->map_return_path_addresses, pair);
  9.1181 +					g_free(item);
  9.1182 +				}
  9.1183 +				g_list_free(list);
  9.1184 +			} else if (strcmp(lval, "map_h_from_addresses") == 0) {
  9.1185 +				GList *list, *node;
  9.1186 +
  9.1187 +				list = parse_list(rval, TRUE);
  9.1188 +				foreach(list, node) {
  9.1189 +					gchar *item = (gchar *) (node->data);
  9.1190 +					table_pair *pair = parse_table_pair(item, ':');
  9.1191 +					route->map_h_from_addresses = g_list_append(route->map_h_from_addresses, pair);
  9.1192 +					g_free(item);
  9.1193 +				}
  9.1194 +				g_list_free(list);
  9.1195 +			} else if (strcmp(lval, "map_h_reply_to_addresses") == 0) {
  9.1196 +				GList *list, *node;
  9.1197 +
  9.1198 +				list = parse_list(rval, TRUE);
  9.1199 +				foreach(list, node) {
  9.1200 +					gchar *item = (gchar *) (node->data);
  9.1201 +					table_pair *pair = parse_table_pair(item, ':');
  9.1202 +					route->map_h_reply_to_addresses = g_list_append(route->map_h_reply_to_addresses, pair);
  9.1203 +					g_free(item);
  9.1204 +				}
  9.1205 +				g_list_free(list);
  9.1206 +			} else if (strcmp(lval, "map_h_mail_followup_to_addresses") == 0) {
  9.1207 +				GList *list, *node;
  9.1208 +
  9.1209 +				list = parse_list(rval, TRUE);
  9.1210 +				foreach(list, node) {
  9.1211 +					gchar *item = (gchar *) (node->data);
  9.1212 +					table_pair *pair = parse_table_pair(item, ':');
  9.1213 +					route->map_h_mail_followup_to_addresses = g_list_append(route->map_h_mail_followup_to_addresses, pair);
  9.1214 +					g_free(item);
  9.1215 +				}
  9.1216 +				g_list_free(list);
  9.1217 +			} else if (strcmp(lval, "expand_h_sender_domain") == 0) {
  9.1218 +				route->expand_h_sender_domain = parse_boolean(rval);
  9.1219 +			} else if (strcmp(lval, "expand_h_sender_address") == 0) {
  9.1220 +				route->expand_h_sender_address = parse_boolean(rval);
  9.1221 +			} else if (strcmp(lval, "resolve_list") == 0)
  9.1222 +				route->resolve_list = parse_resolve_list(rval);
  9.1223 +			else if (strcmp(lval, "do_ssl") == 0) {
  9.1224 +				/* we ignore this. This option is used by sqilconf */
  9.1225 +				;
  9.1226 +			}
  9.1227 +#ifdef ENABLE_AUTH
  9.1228 +			else if (strcmp(lval, "auth_name") == 0) {
  9.1229 +				route->auth_name = g_strdup(rval);
  9.1230 +			} else if (strcmp(lval, "auth_login") == 0) {
  9.1231 +				route->auth_login = g_strdup(rval);
  9.1232 +			} else if (strcmp(lval, "auth_secret") == 0) {
  9.1233 +				route->auth_secret = g_strdup(rval);
  9.1234 +			}
  9.1235 +#else
  9.1236 +			else if ((strcmp(lval, "auth_name") == 0)
  9.1237 +			         || (strcmp(lval, "auth_login") == 0)
  9.1238 +			         || (strcmp(lval, "auth_secret") == 0)) {
  9.1239 +				logwrite(LOG_WARNING, "%s ignored: not compiled with auth support.\n", lval);
  9.1240 +			}
  9.1241 +#endif
  9.1242 +			else if (strcmp(lval, "pop3_login") == 0) {
  9.1243 +#ifdef ENABLE_POP3
  9.1244 +				route->pop3_login = g_strdup(rval);
  9.1245 +#else
  9.1246 +				logwrite(LOG_WARNING, "pop3_login ignored: not compiled with pop support.\n");
  9.1247 +#endif
  9.1248 +			} else if (strcmp(lval, "pipe") == 0) {
  9.1249 +				route->pipe = g_strdup(rval);
  9.1250 +			} else if (strcmp(lval, "pipe_fromline") == 0) {
  9.1251 +				route->pipe_fromline = parse_boolean(rval);
  9.1252 +			} else if (strcmp(lval, "pipe_fromhack") == 0) {
  9.1253 +				route->pipe_fromhack = parse_boolean(rval);
  9.1254 +			} else if (strcmp(lval, "last_route") == 0) {
  9.1255 +				route->last_route = parse_boolean(rval);
  9.1256 +			} else
  9.1257 +				logwrite(LOG_WARNING, "var '%s' not (yet) known, ignored\n", lval);
  9.1258 +		}
  9.1259 +
  9.1260 +		if (route->resolve_list == NULL) {
  9.1261 +			if (is_local_net) {
  9.1262 +				route->resolve_list = g_list_append(NULL, resolve_byname);
  9.1263 +			} else {
  9.1264 +#ifdef ENABLE_RESOLVER
  9.1265 +				route->resolve_list = g_list_append(route->resolve_list, resolve_dns_mx);
  9.1266 +				route->resolve_list = g_list_append(route->resolve_list, resolve_dns_a);
  9.1267 +#endif
  9.1268 +				route->resolve_list = g_list_append(route->resolve_list, resolve_byname);
  9.1269 +			}
  9.1270 +		}
  9.1271 +		fclose(in);
  9.1272 +		ok = TRUE;
  9.1273 +
  9.1274 +		/* warn user about misconfigurations: */
  9.1275 +		if ((route->map_h_from_addresses != NULL)
  9.1276 +		    && (route->set_h_from_domain != NULL)) {
  9.1277 +			logwrite(LOG_WARNING, "'map_h_from_addresses' overrides 'set_h_from_domain'\n");
  9.1278 +			g_free(route->set_h_from_domain);
  9.1279 +			route->set_h_from_domain = NULL;
  9.1280 +		}
  9.1281 +		if ((route->map_h_reply_to_addresses != NULL)
  9.1282 +		    && (route->set_h_reply_to_domain != NULL)) {
  9.1283 +			logwrite(LOG_WARNING, "'map_h_reply_to_addresses' overrides 'set_h_reply_to_domain'\n");
  9.1284 +			g_free(route->set_h_reply_to_domain);
  9.1285 +			route->set_h_reply_to_domain = NULL;
  9.1286 +		}
  9.1287 +	} else {
  9.1288 +		logwrite(LOG_ALERT, "could not open route file %s: %s\n", route->filename, strerror(errno));
  9.1289 +	}
  9.1290 +
  9.1291 +	if (!ok) {
  9.1292 +		g_free(route);
  9.1293 +		route = NULL;
  9.1294 +	}
  9.1295 +
  9.1296 +	return route;
  9.1297 +}
  9.1298 +
  9.1299 +static void
  9.1300 +_g_list_free_all(GList * list)
  9.1301 +{
  9.1302 +	GList *node;
  9.1303 +	if (list) {
  9.1304 +		foreach(list, node)
  9.1305 +			g_free(node->data);
  9.1306 +		g_list_free(list);
  9.1307 +	}
  9.1308 +}
  9.1309 +
  9.1310 +void
  9.1311 +destroy_route(connect_route * r)
  9.1312 +{
  9.1313 +	if (r->filename)
  9.1314 +		g_free(r->filename);
  9.1315 +	if (r->protocol)
  9.1316 +		g_free(r->protocol);
  9.1317 +	if (r->mail_host) {
  9.1318 +		g_free(r->mail_host->address);
  9.1319 +		g_free(r->mail_host);
  9.1320 +	}
  9.1321 +	if (r->wrapper)
  9.1322 +		g_free(r->wrapper);
  9.1323 +	if (r->helo_name)
  9.1324 +		g_free(r->helo_name);
  9.1325 +	_g_list_free_all(r->allowed_mail_locals);
  9.1326 +	_g_list_free_all(r->not_allowed_mail_locals);
  9.1327 +	_g_list_free_all(r->allowed_rcpt_domains);
  9.1328 +	_g_list_free_all(r->not_allowed_rcpt_domains);
  9.1329 +	if (r->set_h_from_domain)
  9.1330 +		g_free(r->set_h_from_domain);
  9.1331 +	if (r->set_h_reply_to_domain)
  9.1332 +		g_free(r->set_h_reply_to_domain);
  9.1333 +	if (r->set_return_path_domain)
  9.1334 +		g_free(r->set_return_path_domain);
  9.1335 +	if (r->map_h_reply_to_addresses)
  9.1336 +		destroy_table(r->map_h_reply_to_addresses);
  9.1337 +	if (r->resolve_list)
  9.1338 +		g_list_free(r->resolve_list);
  9.1339 +#ifdef ENABLE_AUTH
  9.1340 +	if (r->auth_name)
  9.1341 +		g_free(r->auth_name);
  9.1342 +	if (r->auth_login)
  9.1343 +		g_free(r->auth_login);
  9.1344 +	if (r->auth_secret)
  9.1345 +		g_free(r->auth_secret);
  9.1346 +#endif
  9.1347 +#ifdef ENABLE_POP3
  9.1348 +	if (r->pop3_login)
  9.1349 +		g_free(r->pop3_login);
  9.1350 +#endif
  9.1351 +	if (r->pipe)
  9.1352 +		g_free(r->pipe);
  9.1353 +	g_free(r);
  9.1354 +}
  9.1355 +
  9.1356 +GList*
  9.1357 +read_route_list(GList * rf_list, gboolean is_local_net)
  9.1358 +{
  9.1359 +	GList *list = NULL;
  9.1360 +	GList *node;
  9.1361 +	uid_t saved_uid, saved_gid;
  9.1362 +
  9.1363 +	if (!conf.run_as_user) {
  9.1364 +		set_euidgid(0, 0, &saved_uid, &saved_gid);
  9.1365 +	}
  9.1366 +
  9.1367 +	foreach(rf_list, node) {
  9.1368 +		gchar *fname = (gchar *) (node->data);
  9.1369 +		connect_route *route = read_route(fname, is_local_net);
  9.1370 +		if (route)
  9.1371 +			list = g_list_append(list, route);
  9.1372 +		else
  9.1373 +			logwrite(LOG_ALERT, "could not read route configuration %s\n", fname);
  9.1374 +	}
  9.1375 +
  9.1376 +	/* set uid and gid back */
  9.1377 +	if (!conf.run_as_user) {
  9.1378 +		set_euidgid(saved_uid, saved_gid, NULL, NULL);
  9.1379 +	}
  9.1380 +
  9.1381 +	return list;
  9.1382 +}
  9.1383 +
  9.1384 +void
  9.1385 +destroy_route_list(GList * list)
  9.1386 +{
  9.1387 +	GList *node;
  9.1388 +
  9.1389 +	foreach(list, node) {
  9.1390 +		connect_route *route = (connect_route *) (node->data);
  9.1391 +		destroy_route(route);
  9.1392  	}
  9.1393  	g_list_free(list);
  9.1394 -      }
  9.1395 -      else if(strcmp(lval, "map_h_from_addresses") == 0){
  9.1396 -	GList *list, *node;
  9.1397 -
  9.1398 -	list = parse_list(rval, TRUE);
  9.1399 -	foreach(list, node){
  9.1400 -	  gchar *item = (gchar *)(node->data);
  9.1401 -	  table_pair *pair = parse_table_pair(item, ':');
  9.1402 -	  route->map_h_from_addresses = 
  9.1403 -	    g_list_append(route->map_h_from_addresses, pair);
  9.1404 -	  g_free(item);
  9.1405 -	}
  9.1406 -	g_list_free(list);
  9.1407 -      }
  9.1408 -      else if(strcmp(lval, "map_h_reply_to_addresses") == 0){
  9.1409 -	GList *list, *node;
  9.1410 -
  9.1411 -	list = parse_list(rval, TRUE);
  9.1412 -	foreach(list, node){
  9.1413 -	  gchar *item = (gchar *)(node->data);
  9.1414 -	  table_pair *pair = parse_table_pair(item, ':');
  9.1415 -	  route->map_h_reply_to_addresses = 
  9.1416 -	    g_list_append(route->map_h_reply_to_addresses, pair);
  9.1417 -	  g_free(item);
  9.1418 -	}
  9.1419 -	g_list_free(list);
  9.1420 -      }
  9.1421 -      else if(strcmp(lval, "map_h_mail_followup_to_addresses") == 0){
  9.1422 -	GList *list, *node;
  9.1423 -
  9.1424 -	list = parse_list(rval, TRUE);
  9.1425 -	foreach(list, node){
  9.1426 -	  gchar *item = (gchar *)(node->data);
  9.1427 -	  table_pair *pair = parse_table_pair(item, ':');
  9.1428 -	  route->map_h_mail_followup_to_addresses = 
  9.1429 -	    g_list_append(route->map_h_mail_followup_to_addresses, pair);
  9.1430 -	  g_free(item);
  9.1431 -	}
  9.1432 -	g_list_free(list);
  9.1433 -      }
  9.1434 -      else if(strcmp(lval, "expand_h_sender_domain") == 0){
  9.1435 -	route->expand_h_sender_domain = parse_boolean(rval);	    
  9.1436 -      }
  9.1437 -      else if(strcmp(lval, "expand_h_sender_address") == 0){
  9.1438 -	route->expand_h_sender_address = parse_boolean(rval);	    
  9.1439 -      }
  9.1440 -      else if(strcmp(lval, "resolve_list") == 0)
  9.1441 -	route->resolve_list = parse_resolve_list(rval);
  9.1442 -      else if(strcmp(lval, "do_ssl") == 0){
  9.1443 -	/* we ignore this. This option is used by sqilconf */
  9.1444 -	;
  9.1445 -      }
  9.1446 -#ifdef ENABLE_AUTH
  9.1447 -      else if(strcmp(lval, "auth_name") == 0){
  9.1448 -	route->auth_name = g_strdup(rval);
  9.1449 -      }
  9.1450 -      else if(strcmp(lval, "auth_login") == 0){
  9.1451 -	route->auth_login = g_strdup(rval);
  9.1452 -      }
  9.1453 -      else if(strcmp(lval, "auth_secret") == 0){
  9.1454 -	route->auth_secret = g_strdup(rval);
  9.1455 -      }
  9.1456 -#else
  9.1457 -      else if((strcmp(lval, "auth_name") == 0) ||
  9.1458 -	      (strcmp(lval, "auth_login") == 0) ||
  9.1459 -	      (strcmp(lval, "auth_secret") == 0)){
  9.1460 -	logwrite(LOG_WARNING, "%s ignored: not compiled with auth support.\n", lval);
  9.1461 -      }
  9.1462 -#endif
  9.1463 -      else if(strcmp(lval, "pop3_login") == 0){
  9.1464 -#ifdef ENABLE_POP3
  9.1465 -	route->pop3_login = g_strdup(rval);
  9.1466 -#else
  9.1467 -	logwrite(LOG_WARNING, "pop3_login ignored: not compiled with pop support.\n");
  9.1468 -#endif
  9.1469 -      }
  9.1470 -      else if(strcmp(lval, "pipe") == 0){
  9.1471 -	route->pipe = g_strdup(rval);
  9.1472 -      }
  9.1473 -      else if(strcmp(lval, "pipe_fromline") == 0){
  9.1474 -	route->pipe_fromline = parse_boolean(rval);
  9.1475 -      }
  9.1476 -      else if(strcmp(lval, "pipe_fromhack") == 0){
  9.1477 -	route->pipe_fromhack = parse_boolean(rval);
  9.1478 -      }
  9.1479 -      else if(strcmp(lval, "last_route") == 0){
  9.1480 -	route->last_route = parse_boolean(rval);
  9.1481 -      }
  9.1482 -      else
  9.1483 -	logwrite(LOG_WARNING, "var '%s' not (yet) known, ignored\n", lval);
  9.1484 -    }
  9.1485 -
  9.1486 -    if(route->resolve_list == NULL){
  9.1487 -      if(is_local_net){
  9.1488 -	route->resolve_list =
  9.1489 -	  g_list_append(NULL, resolve_byname);
  9.1490 -      }else{
  9.1491 -#ifdef ENABLE_RESOLVER
  9.1492 -	route->resolve_list =
  9.1493 -	  g_list_append(route->resolve_list, resolve_dns_mx);
  9.1494 -	route->resolve_list =
  9.1495 -	  g_list_append(route->resolve_list, resolve_dns_a);
  9.1496 -#endif
  9.1497 -	route->resolve_list =
  9.1498 -	  g_list_append(route->resolve_list, resolve_byname);
  9.1499 -      }
  9.1500 -    }
  9.1501 -    fclose(in);
  9.1502 -    ok = TRUE;
  9.1503 -
  9.1504 -    /* warn user about misconfigurations: */
  9.1505 -    if((route->map_h_from_addresses != NULL) && (route->set_h_from_domain != NULL)){
  9.1506 -      logwrite(LOG_WARNING, "'map_h_from_addresses' overrides 'set_h_from_domain'\n");
  9.1507 -      g_free(route->set_h_from_domain);
  9.1508 -      route->set_h_from_domain = NULL;
  9.1509 -    }
  9.1510 -    if((route->map_h_reply_to_addresses != NULL) && (route->set_h_reply_to_domain != NULL)){
  9.1511 -      logwrite(LOG_WARNING, "'map_h_reply_to_addresses' overrides 'set_h_reply_to_domain'\n");
  9.1512 -      g_free(route->set_h_reply_to_domain);
  9.1513 -      route->set_h_reply_to_domain = NULL;
  9.1514 -    }
  9.1515 -  }else{
  9.1516 -    logwrite(LOG_ALERT, "could not open route file %s: %s\n",
  9.1517 -	     route->filename, strerror(errno));
  9.1518 -  }
  9.1519 -
  9.1520 -  if(!ok){
  9.1521 -    g_free(route);
  9.1522 -    route = NULL;
  9.1523 -  }
  9.1524 -
  9.1525 -  return route;
  9.1526 -}
  9.1527 -
  9.1528 -static
  9.1529 -void _g_list_free_all(GList *list)
  9.1530 -{
  9.1531 -  GList *node;
  9.1532 -  if(list){
  9.1533 -    foreach(list, node)
  9.1534 -      g_free(node->data);
  9.1535 -    g_list_free(list);
  9.1536 -  }
  9.1537 -}
  9.1538 -
  9.1539 -void destroy_route(connect_route *r)
  9.1540 -{
  9.1541 -  if(r->filename) g_free(r->filename);
  9.1542 -  if(r->protocol) g_free(r->protocol);
  9.1543 -  if(r->mail_host){
  9.1544 -    g_free(r->mail_host->address);
  9.1545 -    g_free(r->mail_host);
  9.1546 -  }
  9.1547 -  if(r->wrapper) g_free(r->wrapper);
  9.1548 -  if(r->helo_name) g_free(r->helo_name);
  9.1549 -  _g_list_free_all(r->allowed_mail_locals);
  9.1550 -  _g_list_free_all(r->not_allowed_mail_locals);
  9.1551 -  _g_list_free_all(r->allowed_rcpt_domains);
  9.1552 -  _g_list_free_all(r->not_allowed_rcpt_domains);
  9.1553 -  if(r->set_h_from_domain) g_free(r->set_h_from_domain);
  9.1554 -  if(r->set_h_reply_to_domain) g_free(r->set_h_reply_to_domain);
  9.1555 -  if(r->set_return_path_domain) g_free(r->set_return_path_domain);
  9.1556 -  if(r->map_h_reply_to_addresses) destroy_table(r->map_h_reply_to_addresses);
  9.1557 -  if(r->resolve_list) g_list_free(r->resolve_list);
  9.1558 -#ifdef ENABLE_AUTH
  9.1559 -  if(r->auth_name) g_free(r->auth_name);
  9.1560 -  if(r->auth_login) g_free(r->auth_login);
  9.1561 -  if(r->auth_secret) g_free(r->auth_secret);
  9.1562 -#endif
  9.1563 -#ifdef ENABLE_POP3
  9.1564 -  if(r->pop3_login) g_free(r->pop3_login);
  9.1565 -#endif
  9.1566 -  if(r->pipe) g_free(r->pipe);
  9.1567 -  g_free(r);
  9.1568 -}
  9.1569 -
  9.1570 -GList *read_route_list(GList *rf_list, gboolean is_local_net)
  9.1571 -{
  9.1572 -  GList *list = NULL;
  9.1573 -  GList *node;
  9.1574 -  uid_t saved_uid, saved_gid;
  9.1575 -
  9.1576 -  if(!conf.run_as_user){
  9.1577 -    set_euidgid(0, 0, &saved_uid, &saved_gid);
  9.1578 -  }
  9.1579 -
  9.1580 -  foreach(rf_list, node){
  9.1581 -    gchar *fname = (gchar *)(node->data);
  9.1582 -    connect_route *route = read_route(fname, is_local_net);
  9.1583 -    if(route)
  9.1584 -      list = g_list_append(list, route);
  9.1585 -    else
  9.1586 -      logwrite(LOG_ALERT, "could not read route configuration %s\n", fname);
  9.1587 -  }
  9.1588 -
  9.1589 -  /* set uid and gid back */
  9.1590 -  if(!conf.run_as_user){
  9.1591 -    set_euidgid(saved_uid, saved_gid, NULL, NULL);
  9.1592 -  }
  9.1593 -
  9.1594 -  return list;
  9.1595 -}
  9.1596 -
  9.1597 -void destroy_route_list(GList *list)
  9.1598 -{
  9.1599 -  GList *node;
  9.1600 -
  9.1601 -  foreach(list, node){
  9.1602 -    connect_route *route = (connect_route *)(node->data);
  9.1603 -    destroy_route(route);
  9.1604 -  }
  9.1605 -  g_list_free(list);
  9.1606  }
  9.1607  
  9.1608  #ifdef ENABLE_POP3
  9.1609  
  9.1610 -get_conf *read_get_conf(gchar *filename)
  9.1611 +get_conf*
  9.1612 +read_get_conf(gchar * filename)
  9.1613  {
  9.1614 -  FILE *in;
  9.1615 +	FILE *in;
  9.1616  
  9.1617 -  get_conf *gc = g_malloc(sizeof(get_conf));
  9.1618 -  memset(gc, 0, sizeof(get_conf));
  9.1619 +	get_conf *gc = g_malloc(sizeof(get_conf));
  9.1620 +	memset(gc, 0, sizeof(get_conf));
  9.1621  
  9.1622 -  gc->server_port = 110;
  9.1623 +	gc->server_port = 110;
  9.1624  
  9.1625 -  if((in = fopen(filename, "r"))){
  9.1626 -    gchar lval[256], rval[2048];
  9.1627 -    while(read_statement(in, lval, 256, rval, 2048)){
  9.1628 -      if(strcmp(lval, "protocol") == 0)
  9.1629 -	gc->protocol = g_strdup(rval);
  9.1630 -      else if(strcmp(lval, "server") == 0)
  9.1631 -	gc->server_name = g_strdup(rval);
  9.1632 -      else if(strcmp(lval, "port") == 0)
  9.1633 -	gc->server_port = atoi(rval);
  9.1634 -      else if(strcmp(lval, "wrapper") == 0)
  9.1635 -	gc->wrapper = g_strdup(rval);
  9.1636 -      else if(strcmp(lval, "user") == 0)
  9.1637 -	gc->login_user = g_strdup(rval);
  9.1638 -      else if(strcmp(lval, "pass") == 0)
  9.1639 -	gc->login_pass = g_strdup(rval);
  9.1640 -      else if(strcmp(lval, "address") == 0)
  9.1641 -	gc->address = create_address_qualified(rval, TRUE, conf.host_name);
  9.1642 -      else if(strcmp(lval, "return_path") == 0)
  9.1643 -	gc->return_path = create_address_qualified(rval, TRUE, conf.host_name);
  9.1644 -      else if(strcmp(lval, "do_ssl") == 0)
  9.1645 -	/* we ignore this. This option is used by sqilconf */
  9.1646 -	;
  9.1647 -      else if(strcmp(lval, "do_keep") == 0)
  9.1648 -	gc->do_keep = parse_boolean(rval);
  9.1649 -      else if(strcmp(lval, "do_uidl") == 0)
  9.1650 -	gc->do_uidl = parse_boolean(rval);
  9.1651 -      else if(strcmp(lval, "do_uidl_dele") == 0)
  9.1652 -	gc->do_uidl_dele = parse_boolean(rval);
  9.1653 -      else if(strcmp(lval, "max_size") == 0)
  9.1654 -	gc->max_size = atoi(rval);
  9.1655 -      else if(strcmp(lval, "max_size_delete") == 0)
  9.1656 -	gc->max_size = parse_boolean(rval);
  9.1657 -      else if(strcmp(lval, "max_count") == 0)
  9.1658 -	gc->max_count = atoi(rval);
  9.1659 -      else if(strcmp(lval, "resolve_list") == 0)
  9.1660 -	gc->resolve_list = parse_resolve_list(rval);
  9.1661 -      else
  9.1662 -	logwrite(LOG_WARNING, "var '%s' not (yet) known, ignored\n", lval);
  9.1663 -    }
  9.1664 -    fclose(in);
  9.1665 +	if ((in = fopen(filename, "r"))) {
  9.1666 +		gchar lval[256], rval[2048];
  9.1667 +		while (read_statement(in, lval, 256, rval, 2048)) {
  9.1668 +			if (strcmp(lval, "protocol") == 0)
  9.1669 +				gc->protocol = g_strdup(rval);
  9.1670 +			else if (strcmp(lval, "server") == 0)
  9.1671 +				gc->server_name = g_strdup(rval);
  9.1672 +			else if (strcmp(lval, "port") == 0)
  9.1673 +				gc->server_port = atoi(rval);
  9.1674 +			else if (strcmp(lval, "wrapper") == 0)
  9.1675 +				gc->wrapper = g_strdup(rval);
  9.1676 +			else if (strcmp(lval, "user") == 0)
  9.1677 +				gc->login_user = g_strdup(rval);
  9.1678 +			else if (strcmp(lval, "pass") == 0)
  9.1679 +				gc->login_pass = g_strdup(rval);
  9.1680 +			else if (strcmp(lval, "address") == 0)
  9.1681 +				gc->address = create_address_qualified(rval, TRUE, conf.host_name);
  9.1682 +			else if (strcmp(lval, "return_path") == 0)
  9.1683 +				gc->return_path = create_address_qualified(rval, TRUE, conf.host_name);
  9.1684 +			else if (strcmp(lval, "do_ssl") == 0)
  9.1685 +				/* we ignore this. This option is used by sqilconf */
  9.1686 +				;
  9.1687 +			else if (strcmp(lval, "do_keep") == 0)
  9.1688 +				gc->do_keep = parse_boolean(rval);
  9.1689 +			else if (strcmp(lval, "do_uidl") == 0)
  9.1690 +				gc->do_uidl = parse_boolean(rval);
  9.1691 +			else if (strcmp(lval, "do_uidl_dele") == 0)
  9.1692 +				gc->do_uidl_dele = parse_boolean(rval);
  9.1693 +			else if (strcmp(lval, "max_size") == 0)
  9.1694 +				gc->max_size = atoi(rval);
  9.1695 +			else if (strcmp(lval, "max_size_delete") == 0)
  9.1696 +				gc->max_size = parse_boolean(rval);
  9.1697 +			else if (strcmp(lval, "max_count") == 0)
  9.1698 +				gc->max_count = atoi(rval);
  9.1699 +			else if (strcmp(lval, "resolve_list") == 0)
  9.1700 +				gc->resolve_list = parse_resolve_list(rval);
  9.1701 +			else
  9.1702 +				logwrite(LOG_WARNING, "var '%s' not (yet) known, ignored\n", lval);
  9.1703 +		}
  9.1704 +		fclose(in);
  9.1705  
  9.1706 -    if(gc->resolve_list == NULL){
  9.1707 +		if (gc->resolve_list == NULL) {
  9.1708  #ifdef ENABLE_RESOLVER
  9.1709 -      gc->resolve_list =
  9.1710 -	g_list_append(NULL, resolve_dns_a);
  9.1711 +			gc->resolve_list = g_list_append(NULL, resolve_dns_a);
  9.1712  #endif
  9.1713 -      gc->resolve_list =
  9.1714 -	g_list_append(NULL, resolve_byname);
  9.1715 -    }
  9.1716 -    
  9.1717 -    if(gc->protocol == NULL)
  9.1718 -      gc->protocol = g_strdup("pop3");
  9.1719 -    return gc;
  9.1720 -  }
  9.1721 -  logwrite(LOG_ALERT, "could not open get file %s: %s\n", filename, strerror(errno));
  9.1722 +			gc->resolve_list = g_list_append(NULL, resolve_byname);
  9.1723 +		}
  9.1724  
  9.1725 -  g_free(gc);
  9.1726 -  return NULL;
  9.1727 +		if (gc->protocol == NULL)
  9.1728 +			gc->protocol = g_strdup("pop3");
  9.1729 +		return gc;
  9.1730 +	}
  9.1731 +	logwrite(LOG_ALERT, "could not open get file %s: %s\n", filename, strerror(errno));
  9.1732 +
  9.1733 +	g_free(gc);
  9.1734 +	return NULL;
  9.1735  }
  9.1736  
  9.1737 -void destroy_get_conf(get_conf *gc)
  9.1738 +void
  9.1739 +destroy_get_conf(get_conf * gc)
  9.1740  {
  9.1741 -  if(gc->protocol) g_free(gc->protocol);
  9.1742 -  if(gc->server_name) g_free(gc->server_name);
  9.1743 -  if(gc->login_user) g_free(gc->login_user);
  9.1744 -  if(gc->login_pass) g_free(gc->login_pass);
  9.1745 -  if(gc->wrapper) g_free(gc->wrapper);
  9.1746 -  if(gc->address) destroy_address(gc->address);
  9.1747 -  if(gc->return_path) destroy_address(gc->return_path);
  9.1748 -  if(gc->resolve_list) g_list_free(gc->resolve_list);
  9.1749 -  g_free(gc);
  9.1750 +	if (gc->protocol)
  9.1751 +		g_free(gc->protocol);
  9.1752 +	if (gc->server_name)
  9.1753 +		g_free(gc->server_name);
  9.1754 +	if (gc->login_user)
  9.1755 +		g_free(gc->login_user);
  9.1756 +	if (gc->login_pass)
  9.1757 +		g_free(gc->login_pass);
  9.1758 +	if (gc->wrapper)
  9.1759 +		g_free(gc->wrapper);
  9.1760 +	if (gc->address)
  9.1761 +		destroy_address(gc->address);
  9.1762 +	if (gc->return_path)
  9.1763 +		destroy_address(gc->return_path);
  9.1764 +	if (gc->resolve_list)
  9.1765 +		g_list_free(gc->resolve_list);
  9.1766 +	g_free(gc);
  9.1767  }
  9.1768  
  9.1769  #endif
  9.1770  
  9.1771 -connect_route *create_local_route()
  9.1772 +connect_route*
  9.1773 +create_local_route()
  9.1774  {
  9.1775 -  connect_route *route;
  9.1776 +	connect_route *route;
  9.1777  
  9.1778 -  route = g_malloc(sizeof(connect_route));
  9.1779 -  if(route){
  9.1780 -    memset(route, 0, sizeof(connect_route));
  9.1781 -    route->protocol = g_strdup("smtp");
  9.1782 -    route->is_local_net = TRUE;
  9.1783 -    route->name = g_strdup("local_net (default)");
  9.1784 -    route->expand_h_sender_address = TRUE;
  9.1785 -    route->resolve_list =
  9.1786 -      g_list_append(NULL, resolve_byname);
  9.1787 -    route->connect_error_fail = TRUE;
  9.1788 -  }
  9.1789 -  return route;
  9.1790 +	route = g_malloc(sizeof(connect_route));
  9.1791 +	if (route) {
  9.1792 +		memset(route, 0, sizeof(connect_route));
  9.1793 +		route->protocol = g_strdup("smtp");
  9.1794 +		route->is_local_net = TRUE;
  9.1795 +		route->name = g_strdup("local_net (default)");
  9.1796 +		route->expand_h_sender_address = TRUE;
  9.1797 +		route->resolve_list = g_list_append(NULL, resolve_byname);
  9.1798 +		route->connect_error_fail = TRUE;
  9.1799 +	}
  9.1800 +	return route;
  9.1801  }
    10.1 --- a/src/connect.c	Mon Oct 27 16:21:27 2008 +0100
    10.2 +++ b/src/connect.c	Mon Oct 27 16:23:10 2008 +0100
    10.3 @@ -17,67 +17,63 @@
    10.4  */
    10.5  #include "masqmail.h"
    10.6  
    10.7 -static
    10.8 -GList *resolve_ip(GList *list, gchar *ip)
    10.9 +static GList*
   10.10 +resolve_ip(GList * list, gchar * ip)
   10.11  {
   10.12 -  struct in_addr ia;
   10.13 -  if(inet_aton(ip, &ia)){
   10.14 -    mxip_addr mxip;
   10.15 -    
   10.16 -    mxip.name = g_strdup(ip);
   10.17 -    mxip.pref = 0;
   10.18 -    mxip.ip = (guint32) *(guint32 *)(&ia);
   10.19 -    list = g_list_append(list, g_memdup(&mxip, sizeof(mxip)));
   10.20 -  }
   10.21 -  /* logwrite(LOG_ALERT, "invalid address '%s': inet_aton() failed\n", ip);*/
   10.22 -  return NULL;
   10.23 +	struct in_addr ia;
   10.24 +	if (inet_aton(ip, &ia)) {
   10.25 +		mxip_addr mxip;
   10.26 +
   10.27 +		mxip.name = g_strdup(ip);
   10.28 +		mxip.pref = 0;
   10.29 +		mxip.ip = (guint32) * (guint32 *) (&ia);
   10.30 +		list = g_list_append(list, g_memdup(&mxip, sizeof(mxip)));
   10.31 +	}
   10.32 +	/* logwrite(LOG_ALERT, "invalid address '%s': inet_aton() failed\n", ip); */
   10.33 +	return NULL;
   10.34  }
   10.35  
   10.36 -mxip_addr *connect_hostlist(int *psockfd, gchar *host, guint port,
   10.37 -			  GList *addr_list)
   10.38 +mxip_addr*
   10.39 +connect_hostlist(int *psockfd, gchar * host, guint port, GList * addr_list)
   10.40  {
   10.41 -  GList *addr_node;
   10.42 -  struct sockaddr_in saddr;
   10.43 +	GList *addr_node;
   10.44 +	struct sockaddr_in saddr;
   10.45  
   10.46 -  DEBUG(5) debugf("connect_hostlist entered\n");
   10.47 +	DEBUG(5) debugf("connect_hostlist entered\n");
   10.48  
   10.49 -  for(addr_node = g_list_first(addr_list);
   10.50 -      addr_node;
   10.51 -      addr_node = g_list_next(addr_node)){
   10.52 -    mxip_addr *addr = (mxip_addr *)(addr_node->data);
   10.53 +	for (addr_node = g_list_first(addr_list); addr_node; addr_node = g_list_next(addr_node)) {
   10.54 +		mxip_addr *addr = (mxip_addr *) (addr_node->data);
   10.55  
   10.56 -    *psockfd = socket(PF_INET, SOCK_STREAM, 0);
   10.57 +		*psockfd = socket(PF_INET, SOCK_STREAM, 0);
   10.58  
   10.59 -    memset(&saddr, 0, sizeof(saddr));
   10.60 +		memset(&saddr, 0, sizeof(saddr));
   10.61  
   10.62 -    saddr.sin_family = AF_INET;
   10.63 -    saddr.sin_port = htons(port);
   10.64 +		saddr.sin_family = AF_INET;
   10.65 +		saddr.sin_port = htons(port);
   10.66  
   10.67 -    /* clumsy, but makes compiler happy: */
   10.68 -    saddr.sin_addr = *(struct in_addr*)(&(addr->ip));
   10.69 -    DEBUG(5) debugf("trying ip %s port %d\n", inet_ntoa(saddr.sin_addr), port);
   10.70 -    if(connect(*psockfd, (struct sockaddr *)(&saddr), sizeof(saddr)) == 0){
   10.71 -      DEBUG(5) debugf("connected to %s\n", inet_ntoa(saddr.sin_addr));
   10.72 -      return addr;
   10.73 -    }else{
   10.74 -      int saved_errno = errno;
   10.75 +		/* clumsy, but makes compiler happy: */
   10.76 +		saddr.sin_addr = *(struct in_addr *) (&(addr->ip));
   10.77 +		DEBUG(5) debugf("trying ip %s port %d\n", inet_ntoa(saddr.sin_addr), port);
   10.78 +		if (connect(*psockfd, (struct sockaddr *) (&saddr), sizeof(saddr)) == 0) {
   10.79 +			DEBUG(5) debugf("connected to %s\n", inet_ntoa(saddr.sin_addr));
   10.80 +			return addr;
   10.81 +		} else {
   10.82 +			int saved_errno = errno;
   10.83  
   10.84 -      close(*psockfd);
   10.85 +			close(*psockfd);
   10.86  
   10.87 -      logwrite(LOG_WARNING, "connection to %s failed: %s\n",
   10.88 -	       inet_ntoa(saddr.sin_addr), strerror(errno));
   10.89 +			logwrite(LOG_WARNING, "connection to %s failed: %s\n", inet_ntoa(saddr.sin_addr), strerror(errno));
   10.90  
   10.91 -      errno = saved_errno;
   10.92 +			errno = saved_errno;
   10.93  
   10.94 -      if((saved_errno != ECONNREFUSED) &&
   10.95 -	 (saved_errno != ETIMEDOUT) &&
   10.96 -	 (saved_errno != ENETUNREACH) &&
   10.97 -	 (saved_errno != EHOSTUNREACH))
   10.98 -
   10.99 +			if ((saved_errno != ECONNREFUSED)
  10.100 +			    && (saved_errno != ETIMEDOUT)
  10.101 +			    && (saved_errno != ENETUNREACH)
  10.102 +			    && (saved_errno != EHOSTUNREACH))
  10.103 +				return NULL;
  10.104 +		}
  10.105 +	}
  10.106  	return NULL;
  10.107 -    }
  10.108 -  }
  10.109 -  return NULL;
  10.110  }
  10.111  
  10.112  /* Given a list of resolver functions, this function
  10.113 @@ -89,63 +85,62 @@
  10.114     if attempt failed for one it should not be tried again.
  10.115  */
  10.116  
  10.117 -mxip_addr *connect_resolvelist(int *psockfd, gchar *host, guint port,
  10.118 -			       GList *res_func_list)
  10.119 +mxip_addr*
  10.120 +connect_resolvelist(int *psockfd, gchar * host, guint port, GList * res_func_list)
  10.121  {
  10.122 -  GList *res_node;
  10.123 -  GList *addr_list;
  10.124 +	GList *res_node;
  10.125 +	GList *addr_list;
  10.126  
  10.127 -  DEBUG(5) debugf("connect_resolvelist entered\n");
  10.128 +	DEBUG(5) debugf("connect_resolvelist entered\n");
  10.129  
  10.130 -  h_errno = 0;
  10.131 +	h_errno = 0;
  10.132  
  10.133 -  if(isdigit(host[0])){
  10.134 -    mxip_addr *addr;
  10.135 -    
  10.136 -    addr_list = resolve_ip(NULL, host);
  10.137 -    if(addr_list){
  10.138 -      addr = connect_hostlist(psockfd, host, port, addr_list);
  10.139 -      g_list_free(addr_list);
  10.140 -      return addr;
  10.141 -    }
  10.142 -    /* previous versions complained, until someone tried to use a hostname
  10.143 -       out there that begins with a digit. eg. '3dwars.de'. */
  10.144 -  }
  10.145 +	if (isdigit(host[0])) {
  10.146 +		mxip_addr *addr;
  10.147  
  10.148 -  if(res_func_list == NULL){
  10.149 -    logwrite(LOG_ALERT, "res_funcs == NULL !!!\n");
  10.150 -    exit(EXIT_FAILURE);
  10.151 -  }
  10.152 +		addr_list = resolve_ip(NULL, host);
  10.153 +		if (addr_list) {
  10.154 +			addr = connect_hostlist(psockfd, host, port, addr_list);
  10.155 +			g_list_free(addr_list);
  10.156 +			return addr;
  10.157 +		}
  10.158 +		/* previous versions complained, until someone tried to use a hostname
  10.159 +		   out there that begins with a digit. eg. '3dwars.de'. */
  10.160 +	}
  10.161  
  10.162 -  foreach(res_func_list, res_node){
  10.163 -    resolve_func res_func;
  10.164 -    DEBUG(6) debugf("connect_resolvelist 1a\n");
  10.165 -    res_func = (resolve_func)(res_node->data);
  10.166 -      
  10.167 -    if(res_func == NULL){
  10.168 -      logwrite(LOG_ALERT, "res_func == NULL !!!\n");
  10.169 -      exit(EXIT_FAILURE);
  10.170 -    }
  10.171 -      
  10.172 -    errno = 0;
  10.173 -    if((addr_list = res_func(NULL, host))){
  10.174 -	
  10.175 -      mxip_addr *addr;
  10.176 -      if((addr = connect_hostlist(psockfd, host, port, addr_list)))
  10.177 -	return addr;
  10.178 +	if (res_func_list == NULL) {
  10.179 +		logwrite(LOG_ALERT, "res_funcs == NULL !!!\n");
  10.180 +		exit(EXIT_FAILURE);
  10.181 +	}
  10.182  
  10.183 -      DEBUG(5){
  10.184 -	debugf("connect_hostlist failed: %s\n", strerror(errno));
  10.185 -      }
  10.186 -	
  10.187 -      g_list_free(addr_list);
  10.188 -    }else{
  10.189 -      if(!g_list_next(res_node)){
  10.190 -	logwrite(LOG_ALERT, "could not resolve %s: %s\n", host, hstrerror(h_errno));
  10.191 -      }
  10.192 -    }
  10.193 -  }
  10.194 -  return NULL;
  10.195 +	foreach(res_func_list, res_node) {
  10.196 +		resolve_func res_func;
  10.197 +		DEBUG(6) debugf("connect_resolvelist 1a\n");
  10.198 +		res_func = (resolve_func) (res_node->data);
  10.199 +
  10.200 +		if (res_func == NULL) {
  10.201 +			logwrite(LOG_ALERT, "res_func == NULL !!!\n");
  10.202 +			exit(EXIT_FAILURE);
  10.203 +		}
  10.204 +
  10.205 +		errno = 0;
  10.206 +		if ((addr_list = res_func(NULL, host))) {
  10.207 +
  10.208 +			mxip_addr *addr;
  10.209 +			if ((addr = connect_hostlist(psockfd, host, port, addr_list)))
  10.210 +				return addr;
  10.211 +
  10.212 +			DEBUG(5) {
  10.213 +				debugf("connect_hostlist failed: %s\n", strerror(errno));
  10.214 +			}
  10.215 +
  10.216 +			g_list_free(addr_list);
  10.217 +		} else {
  10.218 +			if (!g_list_next(res_node)) {
  10.219 +				logwrite(LOG_ALERT, "could not resolve %s: %s\n", host, hstrerror(h_errno));
  10.220 +			}
  10.221 +		}
  10.222 +	}
  10.223 +	return NULL;
  10.224  
  10.225  }
  10.226 -
    11.1 --- a/src/deliver.c	Mon Oct 27 16:21:27 2008 +0100
    11.2 +++ b/src/deliver.c	Mon Oct 27 16:23:10 2008 +0100
    11.3 @@ -25,506 +25,484 @@
    11.4  /* collect failed/defered rcpts for failure/warning messages */
    11.5  /* returns TRUE if either there are no failures or a
    11.6     failure message has been successfully sent */
    11.7 -gboolean delivery_failures(message *msg, GList *rcpt_list, gchar *err_fmt, ...)
    11.8 +gboolean
    11.9 +delivery_failures(message * msg, GList * rcpt_list, gchar * err_fmt, ...)
   11.10  {
   11.11 -  gboolean ok_fail = TRUE, ok_warn = TRUE;
   11.12 -  time_t now = time(NULL);
   11.13 +	gboolean ok_fail = TRUE, ok_warn = TRUE;
   11.14 +	time_t now = time(NULL);
   11.15  
   11.16 -  GList *failed_list = NULL, *defered_list = NULL, *rcpt_node;
   11.17 -  va_list args;
   11.18 -  va_start(args, err_fmt);
   11.19 +	GList *failed_list = NULL, *defered_list = NULL, *rcpt_node;
   11.20 +	va_list args;
   11.21 +	va_start(args, err_fmt);
   11.22  
   11.23 -  foreach(rcpt_list, rcpt_node){
   11.24 -    address *rcpt = (address *)(rcpt_node->data);
   11.25 -    
   11.26 -    if(addr_is_defered(rcpt)){
   11.27 -      if((now - msg->received_time) >= conf.max_defer_time){
   11.28 -	addr_mark_failed(rcpt);
   11.29 -      }else
   11.30 -	defered_list = g_list_prepend(defered_list, rcpt);
   11.31 -    }
   11.32 -    if(addr_is_failed(rcpt))
   11.33 -      failed_list = g_list_prepend(failed_list, rcpt);
   11.34 -  }
   11.35 -  if(failed_list != NULL){
   11.36 -    ok_fail = fail_msg(msg, conf.errmsg_file, failed_list, err_fmt, args);
   11.37 -    g_list_free(failed_list);
   11.38 -  }
   11.39 -  if(defered_list != NULL){
   11.40 -    ok_warn = warn_msg(msg, conf.warnmsg_file, defered_list, err_fmt, args);
   11.41 -    g_list_free(defered_list);
   11.42 -  }
   11.43 -  va_end(args);
   11.44 -  return ok_fail && ok_warn;
   11.45 +	foreach(rcpt_list, rcpt_node) {
   11.46 +		address *rcpt = (address *) (rcpt_node->data);
   11.47 +
   11.48 +		if (addr_is_defered(rcpt)) {
   11.49 +			if ((now - msg->received_time) >= conf.max_defer_time) {
   11.50 +				addr_mark_failed(rcpt);
   11.51 +			} else
   11.52 +				defered_list = g_list_prepend(defered_list, rcpt);
   11.53 +		}
   11.54 +		if (addr_is_failed(rcpt))
   11.55 +			failed_list = g_list_prepend(failed_list, rcpt);
   11.56 +	}
   11.57 +	if (failed_list != NULL) {
   11.58 +		ok_fail = fail_msg(msg, conf.errmsg_file, failed_list, err_fmt, args);
   11.59 +		g_list_free(failed_list);
   11.60 +	}
   11.61 +	if (defered_list != NULL) {
   11.62 +		ok_warn = warn_msg(msg, conf.warnmsg_file, defered_list, err_fmt, args);
   11.63 +		g_list_free(defered_list);
   11.64 +	}
   11.65 +	va_end(args);
   11.66 +	return ok_fail && ok_warn;
   11.67  }
   11.68  
   11.69 -static gint _g_list_strcasecmp(gconstpointer a, gconstpointer b)
   11.70 +static gint
   11.71 +_g_list_strcasecmp(gconstpointer a, gconstpointer b)
   11.72  {
   11.73 -  return (gint)strcasecmp(a, b);
   11.74 +	return (gint) strcasecmp(a, b);
   11.75  }
   11.76  
   11.77 -gboolean deliver_local(msg_out *msgout)
   11.78 +gboolean
   11.79 +deliver_local(msg_out * msgout)
   11.80  {
   11.81 -  message *msg = msgout->msg;
   11.82 -  GList *rcpt_list = msgout->rcpt_list;
   11.83 -  GList *rcpt_node;
   11.84 -  gboolean ok = TRUE, flag = FALSE, ok_fail = FALSE;
   11.85 +	message *msg = msgout->msg;
   11.86 +	GList *rcpt_list = msgout->rcpt_list;
   11.87 +	GList *rcpt_node;
   11.88 +	gboolean ok = TRUE, flag = FALSE, ok_fail = FALSE;
   11.89  
   11.90 -  DEBUG(5) debugf("deliver_local entered\n");
   11.91 +	DEBUG(5) debugf("deliver_local entered\n");
   11.92  
   11.93 -  flag = (msg->data_list == NULL);
   11.94 -  if(flag){
   11.95 -    if(!(ok = spool_read_data(msg))){
   11.96 -      logwrite(LOG_ALERT, "could not open data spool file for %s\n",
   11.97 -	       msg->uid);
   11.98 -    }
   11.99 -  }
  11.100 -  if(!ok) return FALSE;
  11.101 +	flag = (msg->data_list == NULL);
  11.102 +	if (flag) {
  11.103 +		if (!(ok = spool_read_data(msg))) {
  11.104 +			logwrite(LOG_ALERT, "could not open data spool file for %s\n", msg->uid);
  11.105 +		}
  11.106 +	}
  11.107 +	if (!ok)
  11.108 +		return FALSE;
  11.109  
  11.110 -  ok = FALSE;
  11.111 -  for(rcpt_node = g_list_first(rcpt_list);
  11.112 -      rcpt_node;
  11.113 -      rcpt_node = g_list_next(rcpt_node)){
  11.114 -    GList *hdr_list;
  11.115 -    address *rcpt = (address *)(rcpt_node->data);
  11.116 -    address *env_addr = addr_find_ancestor(rcpt);
  11.117 -    address *ret_path = msg->return_path;
  11.118 -    header *retpath_hdr, *envto_hdr;
  11.119 +	ok = FALSE;
  11.120 +	for (rcpt_node = g_list_first(rcpt_list); rcpt_node; rcpt_node = g_list_next(rcpt_node)) {
  11.121 +		GList *hdr_list;
  11.122 +		address *rcpt = (address *) (rcpt_node->data);
  11.123 +		address *env_addr = addr_find_ancestor(rcpt);
  11.124 +		address *ret_path = msg->return_path;
  11.125 +		header *retpath_hdr, *envto_hdr;
  11.126  
  11.127 -    /* we need a private copy of the hdr list because we add headers here
  11.128 -       that belong to the rcpt only.
  11.129 -       g_list_copy copies only the nodes, so it is safe to
  11.130 -       g_list_free it
  11.131 -    */
  11.132 -    hdr_list = g_list_copy(msg->hdr_list);
  11.133 -    retpath_hdr = create_header(HEAD_ENVELOPE_TO,
  11.134 -				"Envelope-to: %s\n", addr_string(env_addr));
  11.135 -    envto_hdr = create_header(HEAD_RETURN_PATH,
  11.136 -			      "Return-path: %s\n", addr_string(ret_path));
  11.137 -    
  11.138 -    hdr_list = g_list_prepend(hdr_list, envto_hdr);
  11.139 -    hdr_list = g_list_prepend(hdr_list, retpath_hdr);
  11.140 +		/* we need a private copy of the hdr list because we add headers here
  11.141 +		   that belong to the rcpt only.
  11.142 +		   g_list_copy copies only the nodes, so it is safe to
  11.143 +		   g_list_free it
  11.144 +		 */
  11.145 +		hdr_list = g_list_copy(msg->hdr_list);
  11.146 +		retpath_hdr = create_header(HEAD_ENVELOPE_TO, "Envelope-to: %s\n", addr_string(env_addr));
  11.147 +		envto_hdr = create_header(HEAD_RETURN_PATH, "Return-path: %s\n", addr_string(ret_path));
  11.148  
  11.149 -    if(rcpt->local_part[0] == '|'){
  11.150 -      DEBUG(1) debugf("attempting to deliver %s with pipe\n", msg->uid);
  11.151 -      if(pipe_out(msg, hdr_list, rcpt, &(rcpt->local_part[1]),
  11.152 -		  (conf.pipe_fromline ? MSGSTR_FROMLINE : 0) |
  11.153 -		  (conf.pipe_fromhack ? MSGSTR_FROMHACK : 0))){
  11.154 -	logwrite(LOG_NOTICE, "%s => %s <%s@%s> with pipe\n",
  11.155 -		 msg->uid, rcpt->local_part,
  11.156 -		 env_addr->local_part, env_addr->domain
  11.157 -		 );
  11.158 -	addr_mark_delivered(rcpt);
  11.159 -	ok = TRUE;
  11.160 -      }else{
  11.161 -	if((errno != (1024 + EX_TEMPFAIL)) && (errno != EAGAIN)){
  11.162 -	  addr_mark_failed(rcpt);
  11.163 -	}else{
  11.164 -	  addr_mark_defered(rcpt); /* has no effect yet,
  11.165 -				      except that mail remains in spool */
  11.166 -	}
  11.167 -      }
  11.168 -    }else{
  11.169 -      /* figure out which mailbox type should be used for this user */
  11.170 -      gchar *user = rcpt->local_part;
  11.171 -      gchar *mbox_type = conf.mbox_default;
  11.172 -      
  11.173 -      if(g_list_find_custom(conf.mbox_users, user, _g_list_strcasecmp) != NULL)
  11.174 -	mbox_type = "mbox";
  11.175 -      else if(g_list_find_custom(conf.mda_users, user, _g_list_strcasecmp) != NULL)
  11.176 -	mbox_type = "mda";
  11.177 -      else if(g_list_find_custom(conf.maildir_users, user, _g_list_strcasecmp) != NULL)
  11.178 -	mbox_type = "maildir";
  11.179 +		hdr_list = g_list_prepend(hdr_list, envto_hdr);
  11.180 +		hdr_list = g_list_prepend(hdr_list, retpath_hdr);
  11.181  
  11.182 -      if(strcmp(mbox_type, "mbox") == 0){
  11.183 -	DEBUG(1) debugf("attempting to deliver %s with mbox\n", msg->uid);
  11.184 -	if(append_file(msg, hdr_list, rcpt->local_part)){
  11.185 -	  if(env_addr != rcpt){
  11.186 -	    logwrite(LOG_NOTICE, "%s => %s@%s <%s@%s> with mbox\n",
  11.187 -		     msg->uid, rcpt->local_part, rcpt->domain,
  11.188 -		     env_addr->local_part, env_addr->domain
  11.189 -		     );
  11.190 -	  }else{
  11.191 -	    logwrite(LOG_NOTICE, "%s => <%s@%s> with mbox\n",
  11.192 -		     msg->uid, rcpt->local_part, rcpt->domain);
  11.193 -	  }
  11.194 -	  addr_mark_delivered(rcpt);
  11.195 -	  ok = TRUE;
  11.196 -	}else{
  11.197 -	  if(errno != EAGAIN){ /* prevents 'Resource temporarily unavailable (11)' */
  11.198 -	    addr_mark_failed(rcpt);
  11.199 -	  }else{
  11.200 -	    addr_mark_defered(rcpt);
  11.201 -	  }
  11.202 -	}
  11.203 +		if (rcpt->local_part[0] == '|') {
  11.204 +			DEBUG(1) debugf("attempting to deliver %s with pipe\n", msg->uid);
  11.205 +			if (pipe_out(msg, hdr_list, rcpt, &(rcpt->local_part[1]),
  11.206 +			    (conf.pipe_fromline ? MSGSTR_FROMLINE : 0)
  11.207 +			    | (conf.pipe_fromhack ? MSGSTR_FROMHACK : 0))) {
  11.208 +				logwrite(LOG_NOTICE, "%s => %s <%s@%s> with pipe\n", msg->uid, rcpt->local_part, env_addr->local_part, env_addr->domain);
  11.209 +				addr_mark_delivered(rcpt);
  11.210 +				ok = TRUE;
  11.211 +			} else {
  11.212 +				if ((errno != (1024 + EX_TEMPFAIL)) && (errno != EAGAIN)) {
  11.213 +					addr_mark_failed(rcpt);
  11.214 +				} else {
  11.215 +					addr_mark_defered(rcpt);  /* has no effect yet, except that mail remains in spool */
  11.216 +				}
  11.217 +			}
  11.218 +		} else {
  11.219 +			/* figure out which mailbox type should be used for this user */
  11.220 +			gchar *user = rcpt->local_part;
  11.221 +			gchar *mbox_type = conf.mbox_default;
  11.222  
  11.223 -      }else if(strcmp(mbox_type, "mda") == 0){
  11.224 -	if(conf.mda){
  11.225 -	  gchar *cmd = g_malloc(256);
  11.226 -	  GList *var_table = var_table_rcpt(var_table_msg(NULL, msg), rcpt);
  11.227 -	  
  11.228 -	  DEBUG(1) debugf("attempting to deliver %s with mda\n", msg->uid);
  11.229 -	  
  11.230 -	  if(expand(var_table, conf.mda, cmd, 256)){
  11.231 -	  
  11.232 -	    if(pipe_out(msg, hdr_list, rcpt, cmd,
  11.233 -			(conf.mda_fromline ? MSGSTR_FROMLINE : 0) |
  11.234 -			(conf.mda_fromhack ? MSGSTR_FROMHACK : 0))){
  11.235 -	      logwrite(LOG_NOTICE, "%s => %s@%s with mda (cmd = '%s')\n",
  11.236 -		       msg->uid, rcpt->local_part, rcpt->domain, cmd
  11.237 -		       );
  11.238 -	      addr_mark_delivered(rcpt);
  11.239 -	      ok = TRUE;
  11.240 -	    }else{
  11.241 -	      if((errno != (1024 + EX_TEMPFAIL)) && (errno != EAGAIN)){
  11.242 -		addr_mark_failed(rcpt);
  11.243 -	      }else{
  11.244 -		addr_mark_defered(rcpt); /* has no effect yet,
  11.245 -					    except that mail remains in spool */
  11.246 -	      }
  11.247 -	    }
  11.248 -	  }else
  11.249 -	    logwrite(LOG_ALERT, "could not expand string %s\n", conf.mda);
  11.250 -	  
  11.251 -	  destroy_table(var_table);
  11.252 -	}else
  11.253 -	  logwrite(LOG_ALERT, "mbox type is mda, but no mda command given in configuration\n");
  11.254 +			if (g_list_find_custom (conf.mbox_users, user, _g_list_strcasecmp) != NULL)
  11.255 +				mbox_type = "mbox";
  11.256 +			else if (g_list_find_custom (conf.mda_users, user, _g_list_strcasecmp) != NULL)
  11.257 +				mbox_type = "mda";
  11.258 +			else if (g_list_find_custom (conf.maildir_users, user, _g_list_strcasecmp) != NULL)
  11.259 +				mbox_type = "maildir";
  11.260 +
  11.261 +			if (strcmp(mbox_type, "mbox") == 0) {
  11.262 +				DEBUG(1) debugf("attempting to deliver %s with mbox\n", msg->uid);
  11.263 +				if (append_file(msg, hdr_list, rcpt->local_part)) {
  11.264 +					if (env_addr != rcpt) {
  11.265 +						logwrite(LOG_NOTICE, "%s => %s@%s <%s@%s> with mbox\n",
  11.266 +						         msg->uid, rcpt->local_part, rcpt->domain,
  11.267 +						         env_addr->local_part, env_addr->domain);
  11.268 +					} else {
  11.269 +						logwrite(LOG_NOTICE, "%s => <%s@%s> with mbox\n",
  11.270 +						         msg->uid, rcpt->local_part, rcpt->domain);
  11.271 +					}
  11.272 +					addr_mark_delivered(rcpt);
  11.273 +					ok = TRUE;
  11.274 +				} else {
  11.275 +					if (errno != EAGAIN) {  /* prevents 'Resource temporarily unavailable (11)' */
  11.276 +						addr_mark_failed(rcpt);
  11.277 +					} else {
  11.278 +						addr_mark_defered(rcpt);
  11.279 +					}
  11.280 +				}
  11.281 +
  11.282 +			} else if (strcmp(mbox_type, "mda") == 0) {
  11.283 +				if (conf.mda) {
  11.284 +					gchar *cmd = g_malloc(256);
  11.285 +					GList *var_table = var_table_rcpt(var_table_msg(NULL, msg), rcpt);
  11.286 +
  11.287 +					DEBUG(1) debugf("attempting to deliver %s with mda\n", msg->uid);
  11.288 +
  11.289 +					if (expand(var_table, conf.mda, cmd, 256)) {
  11.290 +
  11.291 +						if (pipe_out(msg, hdr_list, rcpt, cmd, (conf.mda_fromline ? MSGSTR_FROMLINE : 0)
  11.292 +						    | (conf.mda_fromhack ? MSGSTR_FROMHACK : 0))) {
  11.293 +							logwrite(LOG_NOTICE, "%s => %s@%s with mda (cmd = '%s')\n",
  11.294 +							         msg->uid, rcpt->local_part, rcpt->domain, cmd);
  11.295 +							addr_mark_delivered(rcpt);
  11.296 +							ok = TRUE;
  11.297 +						} else {
  11.298 +							if ((errno != (1024 + EX_TEMPFAIL)) && (errno != EAGAIN)) {
  11.299 +								addr_mark_failed(rcpt);
  11.300 +							} else {
  11.301 +								addr_mark_defered(rcpt);  /* has no effect yet, except that mail remains in spool */
  11.302 +							}
  11.303 +						}
  11.304 +					} else
  11.305 +						logwrite(LOG_ALERT, "could not expand string %s\n", conf.mda);
  11.306 +
  11.307 +					destroy_table(var_table);
  11.308 +				} else
  11.309 +					logwrite(LOG_ALERT, "mbox type is mda, but no mda command given in configuration\n");
  11.310  
  11.311  #ifdef ENABLE_MAILDIR
  11.312 -      }else if(strcmp(mbox_type, "maildir") == 0){
  11.313 -	DEBUG(1) debugf("attempting to deliver %s with maildir\n", msg->uid);
  11.314 -	if(maildir_out(msg, hdr_list, rcpt->local_part, 0)){
  11.315 -	  if(env_addr != rcpt){
  11.316 -	    logwrite(LOG_NOTICE, "%s => %s@%s <%s@%s> with local\n",
  11.317 -		     msg->uid, rcpt->local_part, rcpt->domain,
  11.318 -		     env_addr->local_part, env_addr->domain
  11.319 -		     );
  11.320 -	  }else{
  11.321 -	    logwrite(LOG_NOTICE, "%s => <%s@%s> with maildir\n",
  11.322 -		     msg->uid, rcpt->local_part, rcpt->domain);
  11.323 -	  }
  11.324 -	  addr_mark_delivered(rcpt);
  11.325 -	  ok = TRUE;
  11.326 -	}else
  11.327 -	  addr_mark_failed(rcpt);
  11.328 +			} else if (strcmp(mbox_type, "maildir") == 0) {
  11.329 +				DEBUG(1) debugf("attempting to deliver %s with maildir\n", msg->uid);
  11.330 +				if (maildir_out(msg, hdr_list, rcpt->local_part, 0)) {
  11.331 +					if (env_addr != rcpt) {
  11.332 +						logwrite(LOG_NOTICE, "%s => %s@%s <%s@%s> with local\n", msg->uid,
  11.333 +						         rcpt->local_part, rcpt->domain, env_addr->local_part, env_addr->domain);
  11.334 +					} else {
  11.335 +						logwrite(LOG_NOTICE, "%s => <%s@%s> with maildir\n", msg->uid,
  11.336 +						         rcpt->local_part, rcpt->domain);
  11.337 +					}
  11.338 +					addr_mark_delivered(rcpt);
  11.339 +					ok = TRUE;
  11.340 +				} else
  11.341 +					addr_mark_failed(rcpt);
  11.342  #endif
  11.343 -      }else
  11.344 -	logwrite(LOG_ALERT, "unknown mbox type '%s'\n", mbox_type);
  11.345 -    }
  11.346 +			} else
  11.347 +				logwrite(LOG_ALERT, "unknown mbox type '%s'\n", mbox_type);
  11.348 +		}
  11.349  
  11.350 -    destroy_header(retpath_hdr);
  11.351 -    destroy_header(envto_hdr);
  11.352 +		destroy_header(retpath_hdr);
  11.353 +		destroy_header(envto_hdr);
  11.354  
  11.355 -    g_list_free(hdr_list);
  11.356 -  }
  11.357 -  ok_fail = delivery_failures(msg, rcpt_list, "%s (%d)", ext_strerror(errno), errno);
  11.358 +		g_list_free(hdr_list);
  11.359 +	}
  11.360 +	ok_fail = delivery_failures(msg, rcpt_list, "%s (%d)", ext_strerror(errno), errno);
  11.361  
  11.362 -  if(flag) msg_free_data(msg);
  11.363 -  if(ok || ok_fail) deliver_finish(msgout);
  11.364 +	if (flag)
  11.365 +		msg_free_data(msg);
  11.366 +	if (ok || ok_fail)
  11.367 +		deliver_finish(msgout);
  11.368  
  11.369 -  return ok;
  11.370 +	return ok;
  11.371  }
  11.372  
  11.373  /* make a list of rcpt's of a message that are local
  11.374     return a new copy of the list
  11.375  */
  11.376 -void msg_rcptlist_local(GList *rcpt_list, GList **p_local_list, GList **p_nonlocal_list)
  11.377 +void
  11.378 +msg_rcptlist_local(GList * rcpt_list, GList ** p_local_list, GList ** p_nonlocal_list)
  11.379  {
  11.380 -  GList *rcpt_node;
  11.381 +	GList *rcpt_node;
  11.382  
  11.383 -  foreach(rcpt_list, rcpt_node){
  11.384 -    address *rcpt = (address *)(rcpt_node->data);
  11.385 -    GList *dom_node;
  11.386 +	foreach(rcpt_list, rcpt_node) {
  11.387 +		address *rcpt = (address *) (rcpt_node->data);
  11.388 +		GList *dom_node;
  11.389  
  11.390 -    DEBUG(5) debugf("checking address %s\n", rcpt->address);
  11.391 +		DEBUG(5) debugf("checking address %s\n", rcpt->address);
  11.392  
  11.393 -    /* search for local host list: */
  11.394 -    foreach(conf.local_hosts, dom_node){
  11.395 -      if(strcasecmp(dom_node->data, rcpt->domain) == 0){
  11.396 -	*p_local_list = g_list_append(*p_local_list, rcpt);
  11.397 -	DEBUG(5) debugf("<%s@%s> is local\n", rcpt->local_part, rcpt->domain);
  11.398 -	break;
  11.399 -      }else{
  11.400 -	*p_nonlocal_list = g_list_append(*p_nonlocal_list, rcpt);
  11.401 -      }
  11.402 -    }
  11.403 -  }
  11.404 +		/* search for local host list: */
  11.405 +		foreach(conf.local_hosts, dom_node) {
  11.406 +			if (strcasecmp(dom_node->data, rcpt->domain) == 0) {
  11.407 +				*p_local_list = g_list_append(*p_local_list, rcpt);
  11.408 +				DEBUG(5) debugf("<%s@%s> is local\n", rcpt->local_part, rcpt->domain);
  11.409 +				break;
  11.410 +			} else {
  11.411 +				*p_nonlocal_list = g_list_append(*p_nonlocal_list, rcpt);
  11.412 +			}
  11.413 +		}
  11.414 +	}
  11.415  }
  11.416  
  11.417 -gboolean deliver_msglist_host_pipe(connect_route *route, GList *msgout_list, gchar *host, GList *res_list)
  11.418 +gboolean
  11.419 +deliver_msglist_host_pipe(connect_route * route, GList * msgout_list, gchar * host, GList * res_list)
  11.420  {
  11.421 -  gboolean ok = TRUE;
  11.422 -  GList *msgout_node;
  11.423 +	gboolean ok = TRUE;
  11.424 +	GList *msgout_node;
  11.425  
  11.426 -  DEBUG(5) debugf("deliver_msglist_host_pipe entered\n");
  11.427 +	DEBUG(5) debugf("deliver_msglist_host_pipe entered\n");
  11.428  
  11.429 -  if(route->pipe == NULL){
  11.430 -    logwrite(LOG_ALERT, "no pipe command given for route (protocol is pipe!)\n");
  11.431 -    return FALSE;
  11.432 -  }
  11.433 +	if (route->pipe == NULL) {
  11.434 +		logwrite(LOG_ALERT, "no pipe command given for route (protocol is pipe!)\n");
  11.435 +		return FALSE;
  11.436 +	}
  11.437  
  11.438 -  foreach(msgout_list, msgout_node){
  11.439 -    msg_out *msgout = (msg_out *)(msgout_node->data);
  11.440 -    gboolean flag, ok_msg = TRUE, ok_fail = FALSE;
  11.441 -    message *msg = msgout->msg;
  11.442 -    GList *rcpt_node, *rcpt_list = msgout->rcpt_list;
  11.443 +	foreach(msgout_list, msgout_node) {
  11.444 +		msg_out *msgout = (msg_out *) (msgout_node->data);
  11.445 +		gboolean flag, ok_msg = TRUE, ok_fail = FALSE;
  11.446 +		message *msg = msgout->msg;
  11.447 +		GList *rcpt_node, *rcpt_list = msgout->rcpt_list;
  11.448  
  11.449 -    DEBUG(1) debugf("attempting to deliver %s with pipe\n", msg->uid);
  11.450 +		DEBUG(1) debugf("attempting to deliver %s with pipe\n", msg->uid);
  11.451  
  11.452 -    flag = (msg->data_list == NULL);
  11.453 -    if(flag){
  11.454 -      if(!(ok_msg = spool_read_data(msg))){
  11.455 -	logwrite(LOG_ALERT, "could not open data spool file for %s\n",
  11.456 -		 msg->uid);
  11.457 -      }
  11.458 -    }
  11.459 -    if(!ok_msg) continue;
  11.460 +		flag = (msg->data_list == NULL);
  11.461 +		if (flag) {
  11.462 +			if (!(ok_msg = spool_read_data(msg))) {
  11.463 +				logwrite(LOG_ALERT, "could not open data spool file for %s\n", msg->uid);
  11.464 +			}
  11.465 +		}
  11.466 +		if (!ok_msg)
  11.467 +			continue;
  11.468  
  11.469 -    ok = FALSE;
  11.470 -    foreach(rcpt_list, rcpt_node){
  11.471 -      address *rcpt = (address *)(rcpt_node->data);
  11.472 -      gchar *cmd = g_malloc(256);
  11.473 -      GList *var_table = var_table_rcpt(var_table_msg(NULL, msg), rcpt);
  11.474 -      
  11.475 -      DEBUG(1) debugf("attempting to deliver %s to %s@%s with pipe\n",
  11.476 -		      msg->uid, rcpt->local_part, rcpt->domain);
  11.477 -      
  11.478 -      if(expand(var_table, route->pipe, cmd, 256)){
  11.479 -	
  11.480 -	if(pipe_out(msg, msg->hdr_list, rcpt, cmd,
  11.481 -		    (route->pipe_fromline ? MSGSTR_FROMLINE : 0) |
  11.482 -		    (route->pipe_fromhack ? MSGSTR_FROMHACK : 0))){
  11.483 -	  logwrite(LOG_NOTICE, "%s => %s@%s with pipe (cmd = '%s')\n",
  11.484 -		   msg->uid, rcpt->local_part, rcpt->domain, cmd
  11.485 -		   );
  11.486 -	  addr_mark_delivered(rcpt);
  11.487 -	  ok = TRUE;
  11.488 -	}else{
  11.489 -	  logwrite(LOG_ALERT, "pipe_out '%s' failed\n", route->pipe);
  11.490 +		ok = FALSE;
  11.491 +		foreach(rcpt_list, rcpt_node) {
  11.492 +			address *rcpt = (address *) (rcpt_node->data);
  11.493 +			gchar *cmd = g_malloc(256);
  11.494 +			GList *var_table = var_table_rcpt(var_table_msg(NULL, msg), rcpt);
  11.495  
  11.496 -	  if(route->connect_error_fail){
  11.497 -	    addr_mark_failed(rcpt);
  11.498 -	  }else{
  11.499 -	    addr_mark_defered(rcpt);
  11.500 -	  }
  11.501 +			DEBUG(1) debugf("attempting to deliver %s to %s@%s with pipe\n", msg->uid, rcpt->local_part, rcpt->domain);
  11.502 +
  11.503 +			if (expand(var_table, route->pipe, cmd, 256)) {
  11.504 +
  11.505 +				if (pipe_out(msg, msg->hdr_list, rcpt, cmd, (route->pipe_fromline ? MSGSTR_FROMLINE : 0)
  11.506 +				    | (route->pipe_fromhack ? MSGSTR_FROMHACK : 0))) {
  11.507 +					logwrite(LOG_NOTICE, "%s => %s@%s with pipe (cmd = '%s')\n",
  11.508 +					         msg->uid, rcpt->local_part, rcpt->domain, cmd);
  11.509 +					addr_mark_delivered(rcpt);
  11.510 +					ok = TRUE;
  11.511 +				} else {
  11.512 +					logwrite(LOG_ALERT, "pipe_out '%s' failed\n", route->pipe);
  11.513 +
  11.514 +					if (route->connect_error_fail) {
  11.515 +						addr_mark_failed(rcpt);
  11.516 +					} else {
  11.517 +						addr_mark_defered(rcpt);
  11.518 +					}
  11.519 +				}
  11.520 +			} else
  11.521 +				logwrite(LOG_ALERT, "could not expand string %s\n", route->pipe);
  11.522 +
  11.523 +			destroy_table(var_table);
  11.524 +		}
  11.525 +		ok_fail = delivery_failures(msg, rcpt_list, "%s", strerror(errno));
  11.526 +
  11.527 +		if (flag)
  11.528 +			msg_free_data(msg);
  11.529 +
  11.530 +		if (ok || ok_fail)
  11.531 +			deliver_finish(msgout);
  11.532  	}
  11.533 -      }else
  11.534 -	logwrite(LOG_ALERT, "could not expand string %s\n", route->pipe);
  11.535 -      
  11.536 -      destroy_table(var_table);
  11.537 -    }
  11.538 -    ok_fail = delivery_failures(msg, rcpt_list, "%s", strerror(errno));
  11.539  
  11.540 -    if(flag) msg_free_data(msg);
  11.541 -
  11.542 -    if(ok || ok_fail) deliver_finish(msgout);
  11.543 -  }
  11.544 -
  11.545 -  return ok;
  11.546 +	return ok;
  11.547  }
  11.548  
  11.549  /* deliver list of messages to one host
  11.550 -   and finishes them if the message was delivered to at least one
  11.551 -   rcpt.
  11.552 -   Returns TRUE if at least one msg was delivered to at least one
  11.553 -   rcpt.
  11.554 +   and finishes them if the message was delivered to at least one rcpt.
  11.555 +   Returns TRUE if at least one msg was delivered to at least one rcpt.
  11.556  */
  11.557  
  11.558 -gboolean deliver_msglist_host_smtp(connect_route *route, GList *msgout_list, gchar *host, GList *res_list)
  11.559 +gboolean
  11.560 +deliver_msglist_host_smtp(connect_route * route, GList * msgout_list, gchar * host, GList * res_list)
  11.561  {
  11.562 -  gboolean ok = FALSE;
  11.563 -  GList *msgout_node;
  11.564 -  smtp_base *psb;
  11.565 -  gint port;
  11.566 -  
  11.567 -  /* paranoid check: */
  11.568 -  if(msgout_list == NULL){
  11.569 -    logwrite(LOG_ALERT,
  11.570 -	     "Ooops: empty list of messages in deliver_msglist_host()\n");
  11.571 -    return FALSE;
  11.572 -  }
  11.573 +	gboolean ok = FALSE;
  11.574 +	GList *msgout_node;
  11.575 +	smtp_base *psb;
  11.576 +	gint port;
  11.577  
  11.578 -  if(host == NULL){
  11.579 -    host = route->mail_host->address;
  11.580 -    port = route->mail_host->port;
  11.581 -  }else
  11.582 -    port = conf.remote_port;
  11.583 -    
  11.584 +	/* paranoid check: */
  11.585 +	if (msgout_list == NULL) {
  11.586 +		logwrite(LOG_ALERT, "Ooops: empty list of messages in deliver_msglist_host()\n");
  11.587 +		return FALSE;
  11.588 +	}
  11.589 +
  11.590 +	if (host == NULL) {
  11.591 +		host = route->mail_host->address;
  11.592 +		port = route->mail_host->port;
  11.593 +	} else
  11.594 +		port = conf.remote_port;
  11.595 +
  11.596  #ifdef ENABLE_POP3
  11.597 -  if(route->pop3_login){
  11.598 -    if(!(pop_before_smtp(route->pop3_login)))
  11.599 -      return FALSE;
  11.600 -  }
  11.601 +	if (route->pop3_login) {
  11.602 +		if (!(pop_before_smtp(route->pop3_login)))
  11.603 +			return FALSE;
  11.604 +	}
  11.605  #endif
  11.606  
  11.607 -  if((psb = (route->wrapper ?
  11.608 -	     smtp_out_open_child(route->wrapper) :
  11.609 -	     smtp_out_open(host, port, res_list)))){
  11.610 +	if ((psb = (route->wrapper ? smtp_out_open_child(route->wrapper) : smtp_out_open(host, port, res_list)))) {
  11.611  
  11.612 -    if(route->wrapper) psb->remote_host = host;
  11.613 +		if (route->wrapper)
  11.614 +			psb->remote_host = host;
  11.615  
  11.616 -    set_heloname(psb,
  11.617 -		 route->helo_name ? route->helo_name : conf.host_name,
  11.618 -		 route->do_correct_helo);
  11.619 +		set_heloname(psb, route->helo_name ? route->helo_name : conf.host_name, route->do_correct_helo);
  11.620  
  11.621  #ifdef ENABLE_AUTH
  11.622 -    if((route->auth_name) && (route->auth_login) && (route->auth_secret))
  11.623 -      set_auth(psb, route->auth_name, route->auth_login, route->auth_secret);
  11.624 +		if ((route->auth_name) && (route->auth_login)
  11.625 +		    && (route->auth_secret))
  11.626 +			set_auth(psb, route->auth_name, route->auth_login, route->auth_secret);
  11.627  #endif
  11.628 -    if(smtp_out_init(psb)){
  11.629 +		if (smtp_out_init(psb)) {
  11.630  
  11.631 -      if(!route->do_pipelining) psb->use_pipelining = FALSE;
  11.632 +			if (!route->do_pipelining)
  11.633 +				psb->use_pipelining = FALSE;
  11.634  
  11.635 -      foreach(msgout_list, msgout_node){
  11.636 -	msg_out *msgout = (msg_out *)(msgout_node->data);
  11.637 -	gboolean flag, ok_msg = FALSE, ok_fail = FALSE;
  11.638 -	message *msg = msgout->msg;
  11.639 +			foreach(msgout_list, msgout_node) {
  11.640 +				msg_out *msgout = (msg_out *) (msgout_node->data);
  11.641 +				gboolean flag, ok_msg = FALSE, ok_fail = FALSE;
  11.642 +				message *msg = msgout->msg;
  11.643  
  11.644 -	/* we may have to read the data at this point
  11.645 -	   and remember if we did */
  11.646 -	flag = (msg->data_list == NULL);
  11.647 -	if(flag){
  11.648 -	  if(!spool_read_data(msg)){
  11.649 -	    logwrite(LOG_ALERT, "could not open data spool file %s\n",
  11.650 -		     msg->uid);
  11.651 -	    break;
  11.652 -	  }
  11.653 +				/* we may have to read the data at this point
  11.654 +				   and remember if we did */
  11.655 +				flag = (msg->data_list == NULL);
  11.656 +				if (flag) {
  11.657 +					if (!spool_read_data(msg)) {
  11.658 +						logwrite(LOG_ALERT, "could not open data spool file %s\n", msg->uid);
  11.659 +						break;
  11.660 +					}
  11.661 +				}
  11.662 +
  11.663 +				smtp_out_msg(psb, msg, msgout->return_path, msgout->rcpt_list, msgout->hdr_list);
  11.664 +
  11.665 +				ok_fail = delivery_failures(msg, msgout->rcpt_list, "while connected with %s, the server replied\n\t%s", host, psb->buffer);
  11.666 +
  11.667 +				if ((psb->error == smtp_eof)
  11.668 +				    || (psb->error == smtp_timeout)) {
  11.669 +					/* connection lost */
  11.670 +					break;
  11.671 +				} else if (psb->error != smtp_ok) {
  11.672 +					if (g_list_next(msgout_node) != NULL)
  11.673 +						if (!smtp_out_rset(psb))
  11.674 +							break;
  11.675 +				}
  11.676 +				ok_msg = (psb->error == smtp_ok);
  11.677 +
  11.678 +				if (flag)
  11.679 +					msg_free_data(msg);
  11.680 +				if (ok_msg)
  11.681 +					ok = TRUE;
  11.682 +				if (ok_msg || ok_fail) {
  11.683 +					deliver_finish(msgout);
  11.684 +				}
  11.685 +			}
  11.686 +			if (psb->error == smtp_ok || (psb->error == smtp_fail)
  11.687 +			    || (psb->error == smtp_trylater) || (psb->error == smtp_syntax)) {
  11.688 +				smtp_out_quit(psb);
  11.689 +			}
  11.690 +		} else {
  11.691 +			/* smtp_out_init() failed */
  11.692 +			if ((psb->error == smtp_fail) || (psb->error == smtp_trylater) || (psb->error == smtp_syntax)) {
  11.693 +				smtp_out_quit(psb);
  11.694 +
  11.695 +				foreach(msgout_list, msgout_node) {
  11.696 +					msg_out *msgout = (msg_out *) (msgout_node->data);
  11.697 +					smtp_out_mark_rcpts(psb, msgout->rcpt_list);
  11.698 +
  11.699 +					if (delivery_failures(msgout->msg, msgout->rcpt_list,
  11.700 +					    "while connected with %s, the server replied\n\t%s", host, psb->buffer))
  11.701 +						deliver_finish(msgout);
  11.702 +				}
  11.703 +			}
  11.704 +		}
  11.705 +		destroy_smtpbase(psb);
  11.706 +	} else {
  11.707 +		/* smtp_out_open() failed */
  11.708 +		foreach(msgout_list, msgout_node) {
  11.709 +			msg_out *msgout = (msg_out *) (msgout_node->data);
  11.710 +			GList *rcpt_node;
  11.711 +
  11.712 +			for (rcpt_node = g_list_first(msgout->rcpt_list); rcpt_node; rcpt_node = g_list_next(rcpt_node)) {
  11.713 +				address *rcpt = (address *) (rcpt_node->data);
  11.714 +
  11.715 +				addr_unmark_delivered(rcpt);
  11.716 +				if (route->connect_error_fail) {
  11.717 +					addr_mark_failed(rcpt);
  11.718 +				} else {
  11.719 +					addr_mark_defered(rcpt);
  11.720 +				}
  11.721 +				if (route->wrapper
  11.722 +				    ? delivery_failures(msgout->msg, msgout->rcpt_list,
  11.723 +				                        "could not open wrapper:\n\t%s",
  11.724 +				                        strerror(errno))
  11.725 +				    : delivery_failures(msgout->msg, msgout->rcpt_list,
  11.726 +				                        "could not open connection to %s:%d :\n\t%s",
  11.727 +				                        host, port, h_errno != 0 ? hstrerror(h_errno) : strerror(errno)))
  11.728 +					deliver_finish(msgout);
  11.729 +			}
  11.730 +		}
  11.731  	}
  11.732 -    
  11.733 -	smtp_out_msg(psb, msg,
  11.734 -		     msgout->return_path, msgout->rcpt_list, msgout->hdr_list);
  11.735 -
  11.736 -	ok_fail = delivery_failures(msg, msgout->rcpt_list, 
  11.737 -				    "while connected with %s, the server replied\n\t%s",
  11.738 -				    host, psb->buffer);
  11.739 -
  11.740 -	if((psb->error == smtp_eof) ||
  11.741 -	   (psb->error == smtp_timeout)){
  11.742 -	  /* connection lost */
  11.743 -	  break;
  11.744 -	}
  11.745 -	else if(psb->error != smtp_ok){
  11.746 -	  if(g_list_next(msgout_node) != NULL)
  11.747 -	    if(!smtp_out_rset(psb))
  11.748 -	      break;
  11.749 -	}
  11.750 -	ok_msg = (psb->error == smtp_ok);
  11.751 -
  11.752 -	if(flag) msg_free_data(msg);
  11.753 -	if(ok_msg) ok = TRUE;
  11.754 -	if(ok_msg || ok_fail){
  11.755 -	  deliver_finish(msgout);
  11.756 -	}
  11.757 -      }
  11.758 -      if(psb->error == smtp_ok ||
  11.759 -	 (psb->error == smtp_fail) ||
  11.760 -	 (psb->error == smtp_trylater) ||
  11.761 -	 (psb->error == smtp_syntax)){
  11.762 -
  11.763 -	smtp_out_quit(psb);
  11.764 -      }
  11.765 -    }else{
  11.766 -      /* smtp_out_init() failed */
  11.767 -      if((psb->error == smtp_fail) ||
  11.768 -	 (psb->error == smtp_trylater) ||
  11.769 -	 (psb->error == smtp_syntax)){
  11.770 -	smtp_out_quit(psb);
  11.771 -
  11.772 -	foreach(msgout_list, msgout_node){
  11.773 -	  msg_out *msgout = (msg_out *)(msgout_node->data);
  11.774 -	  smtp_out_mark_rcpts(psb, msgout->rcpt_list);
  11.775 -
  11.776 -	  if(delivery_failures(msgout->msg, msgout->rcpt_list, 
  11.777 -			       "while connected with %s, the server replied\n\t%s",
  11.778 -			       host, psb->buffer))
  11.779 -	    deliver_finish(msgout);
  11.780 -	}
  11.781 -      }
  11.782 -    }
  11.783 -    destroy_smtpbase(psb);
  11.784 -  }else{
  11.785 -    /* smtp_out_open() failed */
  11.786 -    foreach(msgout_list, msgout_node){
  11.787 -      msg_out *msgout = (msg_out *)(msgout_node->data);
  11.788 -      GList *rcpt_node;
  11.789 -
  11.790 -      for(rcpt_node = g_list_first(msgout->rcpt_list);
  11.791 -	  rcpt_node;
  11.792 -	  rcpt_node = g_list_next(rcpt_node)){
  11.793 -	address *rcpt = (address *)(rcpt_node->data);
  11.794 -
  11.795 -	addr_unmark_delivered(rcpt);
  11.796 -	if(route->connect_error_fail){
  11.797 -	  addr_mark_failed(rcpt);
  11.798 -	}else{
  11.799 -	  addr_mark_defered(rcpt);
  11.800 -	}
  11.801 -	if(route->wrapper ?
  11.802 -	   delivery_failures(msgout->msg, msgout->rcpt_list,
  11.803 -			     "could not open wrapper:\n\t%s",
  11.804 -			     strerror(errno)) :
  11.805 -	   delivery_failures(msgout->msg, msgout->rcpt_list, 
  11.806 -			     "could not open connection to %s:%d :\n\t%s",
  11.807 -			     host, port, h_errno != 0 ? hstrerror(h_errno) : strerror(errno)))
  11.808 -	  deliver_finish(msgout);
  11.809 -      }
  11.810 -    }
  11.811 -  }
  11.812 -  return ok;
  11.813 +	return ok;
  11.814  }
  11.815  
  11.816 -gboolean deliver_msglist_host(connect_route *route, GList *msgout_list, gchar *host, GList *res_list)
  11.817 +gboolean
  11.818 +deliver_msglist_host(connect_route * route, GList * msgout_list, gchar * host, GList * res_list)
  11.819  {
  11.820 -  DEBUG(5) debugf("protocol = %s\n", route->protocol);
  11.821 +	DEBUG(5) debugf("protocol = %s\n", route->protocol);
  11.822  
  11.823 -  if(strcmp(route->protocol, "pipe") == 0){
  11.824 -    return deliver_msglist_host_pipe(route, msgout_list, host, res_list);
  11.825 -  }else{
  11.826 -    return deliver_msglist_host_smtp(route, msgout_list, host, res_list);
  11.827 -  }
  11.828 +	if (strcmp(route->protocol, "pipe") == 0) {
  11.829 +		return deliver_msglist_host_pipe(route, msgout_list, host, res_list);
  11.830 +	} else {
  11.831 +		return deliver_msglist_host_smtp(route, msgout_list, host, res_list);
  11.832 +	}
  11.833  }
  11.834  
  11.835  /*
  11.836    delivers messages in msgout_list using route
  11.837  */
  11.838 -gboolean deliver_route_msgout_list(connect_route *route, GList *msgout_list)
  11.839 +gboolean
  11.840 +deliver_route_msgout_list(connect_route * route, GList * msgout_list)
  11.841  {
  11.842 -  gboolean ok = FALSE;
  11.843 +	gboolean ok = FALSE;
  11.844  
  11.845 -  DEBUG(5) debugf("deliver_route_msgout_list entered, route->name = %s\n",
  11.846 -		  route->name);
  11.847 +	DEBUG(5)
  11.848 +		debugf("deliver_route_msgout_list entered, route->name = %s\n", route->name);
  11.849  
  11.850 -  if(route->mail_host != NULL){
  11.851 -    /* this is easy... */
  11.852 -    if(deliver_msglist_host(route, msgout_list,
  11.853 -			    NULL, route->resolve_list))
  11.854 -      ok = TRUE;
  11.855 -      
  11.856 -  }else{
  11.857 -    /* this is not easy... */
  11.858 -    GList *mo_ph_list;
  11.859 +	if (route->mail_host != NULL) {
  11.860 +		/* this is easy... */
  11.861 +		if (deliver_msglist_host(route, msgout_list, NULL, route->resolve_list))
  11.862 +			ok = TRUE;
  11.863  
  11.864 -    mo_ph_list = route_msgout_list(route, msgout_list);
  11.865 -    /* okay, now we have ordered our messages by the hosts. */
  11.866 -    if(mo_ph_list != NULL){
  11.867 -      GList *mo_ph_node;
  11.868 -      /* TODO: It would be nice to be able to fork for each host.
  11.869 -	 We cannot do that yet because of complications with finishing the
  11.870 -	 messages. Threads could be a solution because they use the same
  11.871 -	 memory. But we are not thread safe yet...
  11.872 -      */
  11.873 -      foreach(mo_ph_list, mo_ph_node){
  11.874 -	msgout_perhost *mo_ph = (msgout_perhost *)(mo_ph_node->data);
  11.875 -	if(deliver_msglist_host(route, mo_ph->msgout_list,
  11.876 -				mo_ph->host, route->resolve_list))
  11.877 -	  ok = TRUE;
  11.878 +	} else {
  11.879 +		/* this is not easy... */
  11.880 +		GList *mo_ph_list;
  11.881  
  11.882 -	destroy_msgout_perhost(mo_ph);
  11.883 -      }
  11.884 -      g_list_free(mo_ph_list);
  11.885 -    }
  11.886 -  }
  11.887 -  return ok;
  11.888 +		mo_ph_list = route_msgout_list(route, msgout_list);
  11.889 +		/* okay, now we have ordered our messages by the hosts. */
  11.890 +		if (mo_ph_list != NULL) {
  11.891 +			GList *mo_ph_node;
  11.892 +			/* TODO: It would be nice to be able to fork for each host.
  11.893 +			   We cannot do that yet because of complications with finishing the
  11.894 +			   messages. Threads could be a solution because they use the same
  11.895 +			   memory. But we are not thread safe yet...
  11.896 +			 */
  11.897 +			foreach(mo_ph_list, mo_ph_node) {
  11.898 +				msgout_perhost *mo_ph = (msgout_perhost *) (mo_ph_node->data);
  11.899 +				if (deliver_msglist_host (route, mo_ph->msgout_list, mo_ph->host, route->resolve_list))
  11.900 +					ok = TRUE;
  11.901 +
  11.902 +				destroy_msgout_perhost(mo_ph);
  11.903 +			}
  11.904 +			g_list_free(mo_ph_list);
  11.905 +		}
  11.906 +	}
  11.907 +	return ok;
  11.908  }
  11.909  
  11.910  /*
  11.911 @@ -532,85 +510,86 @@
  11.912    delivers messages in msg_list using route
  11.913    by calling deliver_route_msgout_list()
  11.914  */
  11.915 -gboolean deliver_route_msg_list(connect_route *route, GList *msgout_list)
  11.916 +gboolean
  11.917 +deliver_route_msg_list(connect_route * route, GList * msgout_list)
  11.918  {
  11.919 -  GList *msgout_list_deliver = NULL;
  11.920 -  GList *msgout_node;
  11.921 -  gboolean ok = TRUE;
  11.922 +	GList *msgout_list_deliver = NULL;
  11.923 +	GList *msgout_node;
  11.924 +	gboolean ok = TRUE;
  11.925  
  11.926 -  DEBUG(6) debugf("deliver_route_msg_list()\n");
  11.927 +	DEBUG(6) debugf("deliver_route_msg_list()\n");
  11.928  
  11.929 -  foreach(msgout_list, msgout_node){
  11.930 -    msg_out *msgout = (msg_out *)(msgout_node->data);
  11.931 -    msg_out *msgout_cloned = clone_msg_out(msgout);
  11.932 -    GList *rcpt_list_non_delivered = NULL;
  11.933 -    GList *rcpt_node;
  11.934 +	foreach(msgout_list, msgout_node) {
  11.935 +		msg_out *msgout = (msg_out *) (msgout_node->data);
  11.936 +		msg_out *msgout_cloned = clone_msg_out(msgout);
  11.937 +		GList *rcpt_list_non_delivered = NULL;
  11.938 +		GList *rcpt_node;
  11.939  
  11.940 -    /* we have to delete already delivered rcpt's
  11.941 -       because a previous route may have delivered to it */
  11.942 -    foreach(msgout_cloned->rcpt_list, rcpt_node){
  11.943 -      address *rcpt = (address *)(rcpt_node->data);
  11.944 -      /* failed addresses already have been bounced
  11.945 -	 - there should be a better way to handle those.*/
  11.946 -      if(!addr_is_delivered(rcpt) && !addr_is_failed(rcpt) && !(rcpt->flags & ADDR_FLAG_LAST_ROUTE))
  11.947 -	rcpt_list_non_delivered = g_list_append(rcpt_list_non_delivered, rcpt);
  11.948 -    }
  11.949 -    g_list_free(msgout_cloned->rcpt_list);
  11.950 -    msgout_cloned->rcpt_list = rcpt_list_non_delivered;
  11.951 +		/* we have to delete already delivered rcpt's
  11.952 +		   because a previous route may have delivered to it */
  11.953 +		foreach(msgout_cloned->rcpt_list, rcpt_node) {
  11.954 +			address *rcpt = (address *) (rcpt_node->data);
  11.955 +			/* failed addresses already have been bounced
  11.956 +			   - there should be a better way to handle those. */
  11.957 +			if (!addr_is_delivered(rcpt) && !addr_is_failed(rcpt)
  11.958 +			    && !(rcpt->flags & ADDR_FLAG_LAST_ROUTE))
  11.959 +				rcpt_list_non_delivered = g_list_append(rcpt_list_non_delivered, rcpt);
  11.960 +		}
  11.961 +		g_list_free(msgout_cloned->rcpt_list);
  11.962 +		msgout_cloned->rcpt_list = rcpt_list_non_delivered;
  11.963  
  11.964 -    if(msgout_cloned->rcpt_list){
  11.965 -      if(route_is_allowed_mail_local(route, msgout->msg->return_path) && 
  11.966 -	 route_is_allowed_return_path(route, msgout->msg->return_path)){
  11.967 -	GList *rcpt_list_allowed = NULL, *rcpt_list_notallowed = NULL;
  11.968 -	msg_rcptlist_route(route, msgout_cloned->rcpt_list,
  11.969 -			   &rcpt_list_allowed, &rcpt_list_notallowed);
  11.970 -	
  11.971 -	if(rcpt_list_allowed != NULL){
  11.972 -	  logwrite(LOG_NOTICE, "%s using '%s'\n", msgout->msg->uid, route->name);
  11.973 +		if (msgout_cloned->rcpt_list) {
  11.974 +			if (route_is_allowed_mail_local(route, msgout->msg->return_path)
  11.975 +			   && route_is_allowed_return_path(route, msgout->msg-> return_path)) {
  11.976 +				GList *rcpt_list_allowed = NULL, *rcpt_list_notallowed = NULL;
  11.977 +				msg_rcptlist_route(route, msgout_cloned->rcpt_list, &rcpt_list_allowed, &rcpt_list_notallowed);
  11.978  
  11.979 -	  g_list_free(msgout_cloned->rcpt_list);
  11.980 -	  msgout_cloned->rcpt_list = rcpt_list_allowed;
  11.981 -	  
  11.982 -	  if(route->last_route){
  11.983 -	    GList *rcpt_node;
  11.984 -	    foreach(msgout_cloned->rcpt_list, rcpt_node){
  11.985 -	      address *rcpt = (address *)(rcpt_node->data);
  11.986 -	      rcpt->flags |= ADDR_FLAG_LAST_ROUTE;
  11.987 -	    }
  11.988 -	  }
  11.989 +				if (rcpt_list_allowed != NULL) {
  11.990 +					logwrite(LOG_NOTICE, "%s using '%s'\n", msgout->msg->uid, route->name);
  11.991  
  11.992 -	  route_prepare_msgout(route, msgout_cloned);
  11.993 -	  msgout_list_deliver = g_list_append(msgout_list_deliver, msgout_cloned);
  11.994 -	}else
  11.995 -	  destroy_msg_out(msgout_cloned);
  11.996 -      }
  11.997 -      else
  11.998 -	destroy_msg_out(msgout_cloned);
  11.999 -    }else
 11.1000 -      destroy_msg_out(msgout_cloned);
 11.1001 -  }
 11.1002 +					g_list_free(msgout_cloned->rcpt_list);
 11.1003 +					msgout_cloned->rcpt_list = rcpt_list_allowed;
 11.1004  
 11.1005 -  if(msgout_list_deliver != NULL){
 11.1006 -    if(deliver_route_msgout_list(route, msgout_list_deliver))
 11.1007 -      ok = TRUE;
 11.1008 -    destroy_msg_out_list(msgout_list_deliver);
 11.1009 -  }
 11.1010 -  return ok;
 11.1011 +					if (route->last_route) {
 11.1012 +						GList *rcpt_node;
 11.1013 +						foreach(msgout_cloned->rcpt_list, rcpt_node) {
 11.1014 +							address *rcpt = (address *) (rcpt_node->data);
 11.1015 +							rcpt->flags |= ADDR_FLAG_LAST_ROUTE;
 11.1016 +						}
 11.1017 +					}
 11.1018 +
 11.1019 +					route_prepare_msgout(route, msgout_cloned);
 11.1020 +					msgout_list_deliver = g_list_append(msgout_list_deliver, msgout_cloned);
 11.1021 +				} else
 11.1022 +					destroy_msg_out(msgout_cloned);
 11.1023 +			} else
 11.1024 +				destroy_msg_out(msgout_cloned);
 11.1025 +		} else
 11.1026 +			destroy_msg_out(msgout_cloned);
 11.1027 +	}
 11.1028 +
 11.1029 +	if (msgout_list_deliver != NULL) {
 11.1030 +		if (deliver_route_msgout_list(route, msgout_list_deliver))
 11.1031 +			ok = TRUE;
 11.1032 +		destroy_msg_out_list(msgout_list_deliver);
 11.1033 +	}
 11.1034 +	return ok;
 11.1035  }
 11.1036  
 11.1037  /* copy pointers of delivered addresses to the msg's non_rcpt_list,
 11.1038     to make sure that they will not be delivered again.
 11.1039  */
 11.1040 -void update_non_rcpt_list(msg_out *msgout)
 11.1041 +void
 11.1042 +update_non_rcpt_list(msg_out * msgout)
 11.1043  {
 11.1044 -  GList *rcpt_node;
 11.1045 -  message *msg = msgout->msg;
 11.1046 +	GList *rcpt_node;
 11.1047 +	message *msg = msgout->msg;
 11.1048  
 11.1049 -  foreach(msgout->rcpt_list, rcpt_node){
 11.1050 -    address *rcpt = (address *)(rcpt_node->data);
 11.1051 -    if(addr_is_delivered(rcpt) || addr_is_failed(rcpt))
 11.1052 -      msg->non_rcpt_list = g_list_append(msg->non_rcpt_list, rcpt);
 11.1053 -  }
 11.1054 +	foreach(msgout->rcpt_list, rcpt_node) {
 11.1055 +		address *rcpt = (address *) (rcpt_node->data);
 11.1056 +		if (addr_is_delivered(rcpt) || addr_is_failed(rcpt))
 11.1057 +			msg->non_rcpt_list = g_list_append(msg->non_rcpt_list, rcpt);
 11.1058 +	}
 11.1059  }
 11.1060  
 11.1061  /* after delivery attempts, we check if there are any
 11.1062 @@ -621,209 +600,213 @@
 11.1063  
 11.1064     returns TRUE if all went well.
 11.1065  */
 11.1066 -gboolean deliver_finish(msg_out *msgout)
 11.1067 +gboolean
 11.1068 +deliver_finish(msg_out * msgout)
 11.1069  {
 11.1070 -  GList *rcpt_node;
 11.1071 -  gboolean ok = FALSE;
 11.1072 -  message *msg = msgout->msg;
 11.1073 -  gboolean finished = TRUE;
 11.1074 +	GList *rcpt_node;
 11.1075 +	gboolean ok = FALSE;
 11.1076 +	message *msg = msgout->msg;
 11.1077 +	gboolean finished = TRUE;
 11.1078  
 11.1079 -  update_non_rcpt_list(msgout);
 11.1080 +	update_non_rcpt_list(msgout);
 11.1081  
 11.1082 -  /* we NEVER made copies of the addresses, flags affecting addresses
 11.1083 -     were always set on the original address structs */
 11.1084 -  foreach(msg->rcpt_list, rcpt_node){
 11.1085 -    address *rcpt = (address *)(rcpt_node->data);
 11.1086 -    if(!addr_is_finished_children(rcpt))
 11.1087 -      finished = FALSE;
 11.1088 -    else{
 11.1089 -      /* if ALL children have been delivered,
 11.1090 -	 mark parent as delivered.
 11.1091 -	 if there is one or more not delivered,
 11.1092 -	 it must have failed, we mark the parent as failed as well.
 11.1093 -      */
 11.1094 -      if(addr_is_delivered_children(rcpt)){
 11.1095 -	addr_mark_delivered(rcpt);
 11.1096 -      }else{
 11.1097 -	addr_mark_failed(rcpt);
 11.1098 -      }
 11.1099 -    }
 11.1100 -  }
 11.1101 -  
 11.1102 -  if(!finished){
 11.1103 -    /* one not delivered address was found */
 11.1104 -    if(spool_write(msg, FALSE)){
 11.1105 -      ok = TRUE;
 11.1106 -      DEBUG(2) debugf("spool header for %s written back.\n", msg->uid);
 11.1107 -    }else
 11.1108 -      logwrite(LOG_ALERT, "could not write back spool header for %s\n",
 11.1109 -	       msg->uid);
 11.1110 -  }else{
 11.1111 -    ok = spool_delete_all(msg);
 11.1112 -    if(ok)
 11.1113 -      logwrite(LOG_NOTICE, "%s completed.\n", msg->uid);
 11.1114 -  }
 11.1115 -  return ok;
 11.1116 +	/* we NEVER made copies of the addresses, flags affecting addresses
 11.1117 +	   were always set on the original address structs */
 11.1118 +	foreach(msg->rcpt_list, rcpt_node) {
 11.1119 +		address *rcpt = (address *) (rcpt_node->data);
 11.1120 +		if (!addr_is_finished_children(rcpt))
 11.1121 +			finished = FALSE;
 11.1122 +		else {
 11.1123 +			/* if ALL children have been delivered,
 11.1124 +			   mark parent as delivered.
 11.1125 +			   if there is one or more not delivered,
 11.1126 +			   it must have failed, we mark the parent as failed as well.
 11.1127 +			 */
 11.1128 +			if (addr_is_delivered_children(rcpt)) {
 11.1129 +				addr_mark_delivered(rcpt);
 11.1130 +			} else {
 11.1131 +				addr_mark_failed(rcpt);
 11.1132 +			}
 11.1133 +		}
 11.1134 +	}
 11.1135 +
 11.1136 +	if (!finished) {
 11.1137 +		/* one not delivered address was found */
 11.1138 +		if (spool_write(msg, FALSE)) {
 11.1139 +			ok = TRUE;
 11.1140 +			DEBUG(2) debugf("spool header for %s written back.\n", msg->uid);
 11.1141 +		} else
 11.1142 +			logwrite(LOG_ALERT, "could not write back spool header for %s\n", msg->uid);
 11.1143 +	} else {
 11.1144 +		ok = spool_delete_all(msg);
 11.1145 +		if (ok)
 11.1146 +			logwrite(LOG_NOTICE, "%s completed.\n", msg->uid);
 11.1147 +	}
 11.1148 +	return ok;
 11.1149  }
 11.1150  
 11.1151 -gboolean deliver_finish_list(GList *msgout_list)
 11.1152 +gboolean
 11.1153 +deliver_finish_list(GList * msgout_list)
 11.1154  {
 11.1155 -  gboolean ok = TRUE;
 11.1156 -  GList *msgout_node;
 11.1157 -  foreach(msgout_list, msgout_node){
 11.1158 -    msg_out *msgout = (msg_out *)(msgout_node->data);
 11.1159 -    if(!deliver_finish(msgout))
 11.1160 -      ok = FALSE;
 11.1161 -  }
 11.1162 -  return ok;
 11.1163 -}
 11.1164 - 
 11.1165 -gboolean deliver_msgout_list_online(GList *msgout_list)
 11.1166 -{
 11.1167 -  GList *rf_list = NULL;
 11.1168 -  gchar *connect_name = detect_online();
 11.1169 -  gboolean ok = FALSE;
 11.1170 -
 11.1171 -  if(connect_name != NULL){
 11.1172 -    logwrite(LOG_NOTICE, "detected online configuration %s\n", connect_name);
 11.1173 -    /* we are online! */
 11.1174 -    rf_list = (GList *)table_find(conf.connect_routes, connect_name);
 11.1175 -    if(rf_list != NULL){
 11.1176 -      GList *route_list = read_route_list(rf_list, FALSE);
 11.1177 -      if(route_list){
 11.1178 -	GList *route_node;
 11.1179 -	foreach(route_list, route_node){
 11.1180 -	  connect_route *route = (connect_route *)(route_node->data);
 11.1181 -	  ok = deliver_route_msg_list(route, msgout_list);
 11.1182 +	gboolean ok = TRUE;
 11.1183 +	GList *msgout_node;
 11.1184 +	foreach(msgout_list, msgout_node) {
 11.1185 +		msg_out *msgout = (msg_out *) (msgout_node->data);
 11.1186 +		if (!deliver_finish(msgout))
 11.1187 +			ok = FALSE;
 11.1188  	}
 11.1189 -	destroy_route_list(route_list);
 11.1190 -      }
 11.1191 -      else
 11.1192 -	logwrite(LOG_ALERT,
 11.1193 -		 "could not read route list '%s'\n", connect_name);
 11.1194 -    }else{
 11.1195 -      logwrite(LOG_ALERT, "route list with name '%s' not found.\n", connect_name);
 11.1196 -    }
 11.1197 -  }
 11.1198 -  return ok;
 11.1199 +	return ok;
 11.1200  }
 11.1201  
 11.1202 -gboolean deliver_msg_list(GList *msg_list, guint flags){
 11.1203 -  GList *msgout_list = create_msg_out_list(msg_list);
 11.1204 -  GList *local_msgout_list = NULL, *localnet_msgout_list = NULL, *other_msgout_list = NULL;
 11.1205 -  GList *msgout_node;
 11.1206 -  GList *alias_table = NULL;
 11.1207 -  gboolean ok = TRUE;
 11.1208 +gboolean
 11.1209 +deliver_msgout_list_online(GList * msgout_list)
 11.1210 +{
 11.1211 +	GList *rf_list = NULL;
 11.1212 +	gchar *connect_name = detect_online();
 11.1213 +	gboolean ok = FALSE;
 11.1214  
 11.1215 -  if(conf.alias_file){
 11.1216 -    if(!(alias_table = table_read(conf.alias_file, ':')))
 11.1217 -      return FALSE;
 11.1218 -  }
 11.1219 -      
 11.1220 -  /* sort messages for different deliveries */
 11.1221 -  foreach(msgout_list, msgout_node){
 11.1222 -    msg_out *msgout = (msg_out *)(msgout_node->data);
 11.1223 -    GList *rcpt_list;
 11.1224 -    GList *local_rcpt_list = NULL;
 11.1225 -    GList *localnet_rcpt_list = NULL;
 11.1226 -    GList *other_rcpt_list;
 11.1227 +	if (connect_name != NULL) {
 11.1228 +		logwrite(LOG_NOTICE, "detected online configuration %s\n", connect_name);
 11.1229 +		/* we are online! */
 11.1230 +		rf_list = (GList *) table_find(conf.connect_routes, connect_name);
 11.1231 +		if (rf_list != NULL) {
 11.1232 +			GList *route_list = read_route_list(rf_list, FALSE);
 11.1233 +			if (route_list) {
 11.1234 +				GList *route_node;
 11.1235 +				foreach(route_list, route_node) {
 11.1236 +					connect_route *route = (connect_route *) (route_node->data);
 11.1237 +					ok = deliver_route_msg_list(route, msgout_list);
 11.1238 +				}
 11.1239 +				destroy_route_list(route_list);
 11.1240 +			} else
 11.1241 +				logwrite(LOG_ALERT, "could not read route list '%s'\n", connect_name);
 11.1242 +		} else {
 11.1243 +			logwrite(LOG_ALERT, "route list with name '%s' not found.\n", connect_name);
 11.1244 +		}
 11.1245 +	}
 11.1246 +	return ok;
 11.1247 +}
 11.1248  
 11.1249 -    if(!spool_lock(msgout->msg->uid)) continue;
 11.1250 +gboolean
 11.1251 +deliver_msg_list(GList * msg_list, guint flags)
 11.1252 +{
 11.1253 +	GList *msgout_list = create_msg_out_list(msg_list);
 11.1254 +	GList *local_msgout_list = NULL, *localnet_msgout_list = NULL, *other_msgout_list = NULL;
 11.1255 +	GList *msgout_node;
 11.1256 +	GList *alias_table = NULL;
 11.1257 +	gboolean ok = TRUE;
 11.1258  
 11.1259 -    rcpt_list = g_list_copy(msgout->msg->rcpt_list);
 11.1260 -    if(conf.log_user){
 11.1261 -      address *addr = create_address_qualified(conf.log_user, TRUE, conf.host_name);
 11.1262 -      if(addr)
 11.1263 -	rcpt_list = g_list_prepend(rcpt_list, addr);
 11.1264 -    }
 11.1265 -    if(alias_table){
 11.1266 -      GList *aliased_rcpt_list;
 11.1267 -      aliased_rcpt_list = alias_expand(alias_table, rcpt_list,
 11.1268 -				       msgout->msg->non_rcpt_list);
 11.1269 -      g_list_free(rcpt_list);
 11.1270 -      rcpt_list = aliased_rcpt_list;
 11.1271 -    }
 11.1272 +	if (conf.alias_file) {
 11.1273 +		if (!(alias_table = table_read(conf.alias_file, ':')))
 11.1274 +			return FALSE;
 11.1275 +	}
 11.1276  
 11.1277 -    /* local recipients */
 11.1278 -    other_rcpt_list = NULL;
 11.1279 -    rcptlist_with_addr_is_local(rcpt_list, &local_rcpt_list, &other_rcpt_list);
 11.1280 -    
 11.1281 -    if(flags & DLVR_LOCAL){
 11.1282 -      if(local_rcpt_list != NULL){
 11.1283 -	msg_out *local_msgout = clone_msg_out(msgout);
 11.1284 -	local_msgout->rcpt_list = local_rcpt_list;
 11.1285 -	local_msgout_list = g_list_append(local_msgout_list, local_msgout);
 11.1286 -      }
 11.1287 -    }
 11.1288 +	/* sort messages for different deliveries */
 11.1289 +	foreach(msgout_list, msgout_node) {
 11.1290 +		msg_out *msgout = (msg_out *) (msgout_node->data);
 11.1291 +		GList *rcpt_list;
 11.1292 +		GList *local_rcpt_list = NULL;
 11.1293 +		GList *localnet_rcpt_list = NULL;
 11.1294 +		GList *other_rcpt_list;
 11.1295  
 11.1296 -    g_list_free(rcpt_list);
 11.1297 +		if (!spool_lock(msgout->msg->uid))
 11.1298 +			continue;
 11.1299  
 11.1300 -    /* local net recipients */
 11.1301 -    rcpt_list = other_rcpt_list;
 11.1302 -    other_rcpt_list = NULL;
 11.1303 -    rcptlist_with_one_of_hostlist(rcpt_list, conf.local_nets,
 11.1304 -				  &localnet_rcpt_list, &other_rcpt_list);
 11.1305 +		rcpt_list = g_list_copy(msgout->msg->rcpt_list);
 11.1306 +		if (conf.log_user) {
 11.1307 +			address *addr = create_address_qualified(conf.log_user, TRUE, conf.host_name);
 11.1308 +			if (addr)
 11.1309 +				rcpt_list = g_list_prepend(rcpt_list, addr);
 11.1310 +		}
 11.1311 +		if (alias_table) {
 11.1312 +			GList *aliased_rcpt_list;
 11.1313 +			aliased_rcpt_list = alias_expand(alias_table, rcpt_list, msgout->msg->non_rcpt_list);
 11.1314 +			g_list_free(rcpt_list);
 11.1315 +			rcpt_list = aliased_rcpt_list;
 11.1316 +		}
 11.1317  
 11.1318 -    if(flags & DLVR_LAN){
 11.1319 -      if(localnet_rcpt_list != NULL){
 11.1320 -	msg_out *localnet_msgout = clone_msg_out(msgout);
 11.1321 -	localnet_msgout->rcpt_list = localnet_rcpt_list;
 11.1322 -	localnet_msgout_list = g_list_append(localnet_msgout_list, localnet_msgout);
 11.1323 -      }
 11.1324 -    }
 11.1325 +		/* local recipients */
 11.1326 +		other_rcpt_list = NULL;
 11.1327 +		rcptlist_with_addr_is_local(rcpt_list, &local_rcpt_list, &other_rcpt_list);
 11.1328  
 11.1329 -    if(flags & DLVR_ONLINE){
 11.1330 -      /* the rest, this is online delivery */
 11.1331 -      if(other_rcpt_list != NULL){
 11.1332 -	msg_out *other_msgout = clone_msg_out(msgout);
 11.1333 -	other_msgout->rcpt_list = other_rcpt_list;
 11.1334 -	other_msgout_list = g_list_append(other_msgout_list, other_msgout);
 11.1335 -      }
 11.1336 -    }
 11.1337 -  }
 11.1338 +		if (flags & DLVR_LOCAL) {
 11.1339 +			if (local_rcpt_list != NULL) {
 11.1340 +				msg_out *local_msgout = clone_msg_out(msgout);
 11.1341 +				local_msgout->rcpt_list = local_rcpt_list;
 11.1342 +				local_msgout_list = g_list_append(local_msgout_list, local_msgout);
 11.1343 +			}
 11.1344 +		}
 11.1345  
 11.1346 -  if(alias_table)
 11.1347 -    destroy_table(alias_table);
 11.1348 +		g_list_free(rcpt_list);
 11.1349  
 11.1350 -  /* actual delivery */
 11.1351 -  if(local_msgout_list != NULL){
 11.1352 -    foreach(local_msgout_list, msgout_node){
 11.1353 -      msg_out *msgout = (msg_out *)(msgout_node->data);
 11.1354 -      if(!deliver_local(msgout)) ok = FALSE;
 11.1355 -    }
 11.1356 -    destroy_msg_out_list(local_msgout_list);
 11.1357 -  }
 11.1358 +		/* local net recipients */
 11.1359 +		rcpt_list = other_rcpt_list;
 11.1360 +		other_rcpt_list = NULL;
 11.1361 +		rcptlist_with_one_of_hostlist(rcpt_list, conf.local_nets, &localnet_rcpt_list, &other_rcpt_list);
 11.1362  
 11.1363 -  if(localnet_msgout_list != NULL){
 11.1364 -    GList *route_list = NULL;
 11.1365 -    GList *route_node;
 11.1366 +		if (flags & DLVR_LAN) {
 11.1367 +			if (localnet_rcpt_list != NULL) {
 11.1368 +				msg_out *localnet_msgout = clone_msg_out(msgout);
 11.1369 +				localnet_msgout->rcpt_list = localnet_rcpt_list;
 11.1370 +				localnet_msgout_list = g_list_append(localnet_msgout_list, localnet_msgout);
 11.1371 +			}
 11.1372 +		}
 11.1373  
 11.1374 -    if(conf.local_net_routes)
 11.1375 -      route_list = read_route_list(conf.local_net_routes, TRUE);
 11.1376 -    else
 11.1377 -      route_list = g_list_append(NULL, create_local_route());
 11.1378 +		if (flags & DLVR_ONLINE) {
 11.1379 +			/* the rest, this is online delivery */
 11.1380 +			if (other_rcpt_list != NULL) {
 11.1381 +				msg_out *other_msgout = clone_msg_out(msgout);
 11.1382 +				other_msgout->rcpt_list = other_rcpt_list;
 11.1383 +				other_msgout_list = g_list_append(other_msgout_list, other_msgout);
 11.1384 +			}
 11.1385 +		}
 11.1386 +	}
 11.1387  
 11.1388 -    foreach(route_list, route_node){
 11.1389 -      connect_route *route = (connect_route *)(route_node->data);
 11.1390 -      if(!deliver_route_msg_list(route, localnet_msgout_list)) ok = FALSE;
 11.1391 -    }
 11.1392 -    destroy_msg_out_list(localnet_msgout_list);
 11.1393 -    destroy_route_list(route_list);
 11.1394 -  }
 11.1395 +	if (alias_table)
 11.1396 +		destroy_table(alias_table);
 11.1397  
 11.1398 -  if(other_msgout_list != NULL){
 11.1399 -    if(!deliver_msgout_list_online(other_msgout_list)) ok = FALSE;
 11.1400 -    destroy_msg_out_list(other_msgout_list);
 11.1401 -  }
 11.1402 +	/* actual delivery */
 11.1403 +	if (local_msgout_list != NULL) {
 11.1404 +		foreach(local_msgout_list, msgout_node) {
 11.1405 +			msg_out *msgout = (msg_out *) (msgout_node->data);
 11.1406 +			if (!deliver_local(msgout))
 11.1407 +				ok = FALSE;
 11.1408 +		}
 11.1409 +		destroy_msg_out_list(local_msgout_list);
 11.1410 +	}
 11.1411  
 11.1412 -  foreach(msgout_list, msgout_node){
 11.1413 -    msg_out *msgout = (msg_out *)(msgout_node->data);
 11.1414 -    spool_unlock(msgout->msg->uid);
 11.1415 -  }
 11.1416 +	if (localnet_msgout_list != NULL) {
 11.1417 +		GList *route_list = NULL;
 11.1418 +		GList *route_node;
 11.1419  
 11.1420 -  destroy_msg_out_list(msgout_list);
 11.1421 +		if (conf.local_net_routes)
 11.1422 +			route_list = read_route_list(conf.local_net_routes, TRUE);
 11.1423 +		else
 11.1424 +			route_list = g_list_append(NULL, create_local_route());
 11.1425  
 11.1426 -  return ok;
 11.1427 +		foreach(route_list, route_node) {
 11.1428 +			connect_route *route = (connect_route *) (route_node->data);
 11.1429 +			if (!deliver_route_msg_list(route, localnet_msgout_list))
 11.1430 +				ok = FALSE;
 11.1431 +		}
 11.1432 +		destroy_msg_out_list(localnet_msgout_list);
 11.1433 +		destroy_route_list(route_list);
 11.1434 +	}
 11.1435 +
 11.1436 +	if (other_msgout_list != NULL) {
 11.1437 +		if (!deliver_msgout_list_online(other_msgout_list))
 11.1438 +			ok = FALSE;
 11.1439 +		destroy_msg_out_list(other_msgout_list);
 11.1440 +	}
 11.1441 +
 11.1442 +	foreach(msgout_list, msgout_node) {
 11.1443 +		msg_out *msgout = (msg_out *) (msgout_node->data);
 11.1444 +		spool_unlock(msgout->msg->uid);
 11.1445 +	}
 11.1446 +
 11.1447 +	destroy_msg_out_list(msgout_list);
 11.1448 +
 11.1449 +	return ok;
 11.1450  }
 11.1451  
 11.1452  /* This function searches in the list of rcpt addresses
 11.1453 @@ -834,16 +817,14 @@
 11.1454     deliver() is called when a message has just been received and should
 11.1455     be delivered immediately.
 11.1456  */
 11.1457 -gboolean deliver(message *msg)
 11.1458 +gboolean
 11.1459 +deliver(message * msg)
 11.1460  {
 11.1461 -  gboolean ok;
 11.1462 +	gboolean ok;
 11.1463 +	GList *msg_list = g_list_append(NULL, msg);
 11.1464  
 11.1465 -  GList *msg_list = g_list_append(NULL, msg);
 11.1466 +	ok = deliver_msg_list(msg_list, DLVR_ALL);
 11.1467 +	g_list_free(msg_list);
 11.1468  
 11.1469 -  ok = deliver_msg_list(msg_list, DLVR_ALL);
 11.1470 -  
 11.1471 -  g_list_free(msg_list);
 11.1472 -
 11.1473 -  return ok;
 11.1474 +	return ok;
 11.1475  }
 11.1476 -
    12.1 --- a/src/dotlock.c	Mon Oct 27 16:21:27 2008 +0100
    12.2 +++ b/src/dotlock.c	Mon Oct 27 16:23:10 2008 +0100
    12.3 @@ -29,52 +29,52 @@
    12.4  #include "masqmail.h"
    12.5  #include "dotlock.h"
    12.6  
    12.7 -gboolean dot_lock(gchar *lock_name, gchar *hitch_name)
    12.8 +gboolean
    12.9 +dot_lock(gchar * lock_name, gchar * hitch_name)
   12.10  {
   12.11 -  gboolean ok = FALSE;
   12.12 -  int fd;
   12.13 +	gboolean ok = FALSE;
   12.14 +	int fd;
   12.15  
   12.16 -  fd = open(hitch_name, O_WRONLY | O_CREAT | O_EXCL, 0);
   12.17 -  if(fd != -1){
   12.18 -    struct stat stat_buf;
   12.19 +	fd = open(hitch_name, O_WRONLY | O_CREAT | O_EXCL, 0);
   12.20 +	if (fd != -1) {
   12.21 +		struct stat stat_buf;
   12.22  
   12.23 -    close(fd);
   12.24 -    link(hitch_name, lock_name);
   12.25 -    if(stat(hitch_name, &stat_buf) == 0){
   12.26 -      if(stat_buf.st_nlink == 2){
   12.27 -        unlink(hitch_name);
   12.28 -        ok = TRUE;
   12.29 -      }
   12.30 -      else{
   12.31 -        if(stat(lock_name, &stat_buf) == 0){
   12.32 -          if((time(NULL) - stat_buf.st_mtime) > MAX_LOCKAGE){
   12.33 -            /* remove lock if uncredibly old */
   12.34 -            unlink(lock_name);
   12.35 +		close(fd);
   12.36 +		link(hitch_name, lock_name);
   12.37 +		if (stat(hitch_name, &stat_buf) == 0) {
   12.38 +			if (stat_buf.st_nlink == 2) {
   12.39 +				unlink(hitch_name);
   12.40 +				ok = TRUE;
   12.41 +			} else {
   12.42 +				if (stat(lock_name, &stat_buf) == 0) {
   12.43 +					if ((time(NULL) - stat_buf.st_mtime) > MAX_LOCKAGE) {
   12.44 +						/* remove lock if uncredibly old */
   12.45 +						unlink(lock_name);
   12.46  
   12.47 -            link(hitch_name, lock_name);
   12.48 -            if(stat(hitch_name, &stat_buf) == 0){
   12.49 -              if(stat_buf.st_nlink == 2){
   12.50 -                unlink(hitch_name);
   12.51 -                ok = TRUE;
   12.52 -              }
   12.53 -            }
   12.54 -          }
   12.55 -        }
   12.56 -      }
   12.57 -    }
   12.58 -    if(!ok){
   12.59 -      unlink(hitch_name);
   12.60 -    }
   12.61 -  }else
   12.62 -    logwrite(LOG_WARNING, "could not create lock file %s: %s\n",
   12.63 -	     lock_name, strerror(errno));
   12.64 +						link(hitch_name, lock_name);
   12.65 +						if (stat(hitch_name, &stat_buf) == 0) {
   12.66 +							if (stat_buf.st_nlink == 2) {
   12.67 +								unlink(hitch_name);
   12.68 +								ok = TRUE;
   12.69 +							}
   12.70 +						}
   12.71 +					}
   12.72 +				}
   12.73 +			}
   12.74 +		}
   12.75 +		if (!ok) {
   12.76 +			unlink(hitch_name);
   12.77 +		}
   12.78 +	} else
   12.79 +		logwrite(LOG_WARNING, "could not create lock file %s: %s\n", lock_name, strerror(errno));
   12.80  
   12.81 -  return ok;
   12.82 +	return ok;
   12.83  }
   12.84  
   12.85 -gboolean dot_unlock(gchar *lock_name)
   12.86 +gboolean
   12.87 +dot_unlock(gchar * lock_name)
   12.88  {
   12.89 -  unlink(lock_name);
   12.90 +	unlink(lock_name);
   12.91  
   12.92 -  return TRUE;
   12.93 +	return TRUE;
   12.94  }
    13.1 --- a/src/dotlock.h	Mon Oct 27 16:21:27 2008 +0100
    13.2 +++ b/src/dotlock.h	Mon Oct 27 16:23:10 2008 +0100
    13.3 @@ -18,5 +18,5 @@
    13.4  
    13.5  #define MAX_LOCKAGE 300
    13.6  
    13.7 -gboolean dot_lock(gchar *lock_name, gchar *hitch_name);
    13.8 -gboolean dot_unlock(gchar *lock_name);
    13.9 +gboolean dot_lock(gchar * lock_name, gchar * hitch_name);
   13.10 +gboolean dot_unlock(gchar * lock_name);
    14.1 --- a/src/expand.c	Mon Oct 27 16:21:27 2008 +0100
    14.2 +++ b/src/expand.c	Mon Oct 27 16:23:10 2008 +0100
    14.3 @@ -20,106 +20,110 @@
    14.4  
    14.5  #define MAX_VAR 50
    14.6  
    14.7 -GList *var_table_rcpt(GList *var_table, address *rcpt)
    14.8 +GList*
    14.9 +var_table_rcpt(GList * var_table, address * rcpt)
   14.10  {
   14.11 -    gchar *tmp_str;
   14.12 -    
   14.13 -    var_table = g_list_prepend(var_table, create_pair_string("rcpt_local", rcpt->local_part));
   14.14 -    var_table = g_list_prepend(var_table, create_pair_string("rcpt_domain", rcpt->domain));
   14.15 -    
   14.16 -    tmp_str = g_strdup_printf("%s@%s", rcpt->local_part, rcpt->domain);
   14.17 -    var_table = g_list_prepend(var_table, create_pair_string("rcpt", tmp_str));
   14.18 -    g_free(tmp_str);
   14.19 +	gchar *tmp_str;
   14.20  
   14.21 -    return var_table;
   14.22 +	var_table = g_list_prepend(var_table, create_pair_string("rcpt_local", rcpt->local_part));
   14.23 +	var_table = g_list_prepend(var_table, create_pair_string("rcpt_domain", rcpt->domain));
   14.24 +
   14.25 +	tmp_str = g_strdup_printf("%s@%s", rcpt->local_part, rcpt->domain);
   14.26 +	var_table = g_list_prepend(var_table, create_pair_string("rcpt", tmp_str));
   14.27 +	g_free(tmp_str);
   14.28 +
   14.29 +	return var_table;
   14.30  }
   14.31  
   14.32 -GList *var_table_msg(GList *var_table, message *msg)
   14.33 +GList*
   14.34 +var_table_msg(GList * var_table, message * msg)
   14.35  {
   14.36 -    address *ret_path = msg->return_path;
   14.37 -    gchar *tmp_str;
   14.38 -    
   14.39 -    var_table = g_list_prepend(var_table, create_pair_string("uid", msg->uid));
   14.40 -    var_table = g_list_prepend(var_table, create_pair_string("received_host",
   14.41 -							    msg->received_host ? msg->received_host : ""));
   14.42 -    var_table = g_list_prepend(var_table, create_pair_string("ident", msg->ident ? msg->ident : ""));
   14.43 -    var_table = g_list_prepend(var_table, create_pair_string("return_path_local", ret_path->local_part));
   14.44 -    var_table = g_list_prepend(var_table, create_pair_string("return_path_domain", ret_path->domain));
   14.45 -    
   14.46 -    tmp_str = g_strdup_printf("%s@%s", ret_path->local_part, ret_path->domain);
   14.47 -    var_table = g_list_prepend(var_table, create_pair_string("return_path", tmp_str));
   14.48 -    g_free(tmp_str);
   14.49 +	address *ret_path = msg->return_path;
   14.50 +	gchar *tmp_str;
   14.51  
   14.52 -    return var_table;
   14.53 +	var_table = g_list_prepend(var_table, create_pair_string("uid", msg->uid));
   14.54 +	var_table = g_list_prepend(var_table, create_pair_string("received_host", msg->received_host ? msg->received_host : ""));
   14.55 +	var_table = g_list_prepend(var_table, create_pair_string("ident", msg->ident ? msg->ident : ""));
   14.56 +	var_table = g_list_prepend(var_table, create_pair_string("return_path_local", ret_path->local_part));
   14.57 +	var_table = g_list_prepend(var_table, create_pair_string("return_path_domain", ret_path->domain));
   14.58 +
   14.59 +	tmp_str = g_strdup_printf("%s@%s", ret_path->local_part, ret_path->domain);
   14.60 +	var_table = g_list_prepend(var_table, create_pair_string("return_path", tmp_str));
   14.61 +	g_free(tmp_str);
   14.62 +
   14.63 +	return var_table;
   14.64  }
   14.65  
   14.66 -GList *var_table_conf(GList *var_table)
   14.67 +GList*
   14.68 +var_table_conf(GList * var_table)
   14.69  {
   14.70 -    var_table = g_list_prepend(var_table, create_pair_string("host_name", conf.host_name));
   14.71 -    var_table = g_list_prepend(var_table, create_pair_string("package", PACKAGE));
   14.72 -    var_table = g_list_prepend(var_table, create_pair_string("version", VERSION));
   14.73 +	var_table = g_list_prepend(var_table, create_pair_string("host_name", conf.host_name));
   14.74 +	var_table = g_list_prepend(var_table, create_pair_string("package", PACKAGE));
   14.75 +	var_table = g_list_prepend(var_table, create_pair_string("version", VERSION));
   14.76  
   14.77 -    return var_table;
   14.78 +	return var_table;
   14.79  }
   14.80  
   14.81 -gint expand(GList *var_list, gchar *format, gchar *result, gint result_len)
   14.82 +gint
   14.83 +expand(GList * var_list, gchar * format, gchar * result, gint result_len)
   14.84  {
   14.85 -  gchar *p = format, *q = result;
   14.86 -  gchar *vq;
   14.87 -  gint i = 0;
   14.88 -  gboolean escape = FALSE;
   14.89 +	gchar *p = format, *q = result;
   14.90 +	gchar *vq;
   14.91 +	gint i = 0;
   14.92 +	gboolean escape = FALSE;
   14.93  
   14.94 -  while(*p && (i < (result_len -1))){
   14.95 -    if((*p == '$') && !escape){
   14.96 -      gchar *value;
   14.97 -      gchar var[MAX_VAR+1];
   14.98 -      int j = 0;
   14.99 +	while (*p && (i < (result_len - 1))) {
  14.100 +		if ((*p == '$') && !escape) {
  14.101 +			gchar *value;
  14.102 +			gchar var[MAX_VAR + 1];
  14.103 +			int j = 0;
  14.104  
  14.105 -      p++; /* skip '$' */
  14.106 -      vq = var;
  14.107 +			p++;  /* skip '$' */
  14.108 +			vq = var;
  14.109  
  14.110 -      if(*p == '{'){
  14.111 -	/* ${var} style */
  14.112 -	p++; /* skip '{' */
  14.113 -	while(*p && (*p != '}') && (j < MAX_VAR)){
  14.114 -	  *(vq++) = *(p++);
  14.115 -	  j++;
  14.116 +			if (*p == '{') {
  14.117 +				/* ${var} style */
  14.118 +				p++;  /* skip '{' */
  14.119 +				while (*p && (*p != '}') && (j < MAX_VAR)) {
  14.120 +					*(vq++) = *(p++);
  14.121 +					j++;
  14.122 +				}
  14.123 +				p++;
  14.124 +			} else {
  14.125 +				/* $var style */
  14.126 +				while (*p && (isalnum(*p) || (*p == '_') || (*p == '-')) && (j < MAX_VAR)) {
  14.127 +					*(vq++) = *(p++);
  14.128 +					j++;
  14.129 +				}
  14.130 +			}
  14.131 +			*vq = 0;
  14.132 +
  14.133 +			if (j < MAX_VAR) {
  14.134 +				/* search var */
  14.135 +				value = (gchar *) table_find(var_list, var);
  14.136 +				if (value) {
  14.137 +					gchar *vp = value;
  14.138 +					while (*vp && (i < (result_len - 1))) {
  14.139 +						*(q++) = *(vp++);
  14.140 +						i++;
  14.141 +					}
  14.142 +				}
  14.143 +			}
  14.144 +		} else {
  14.145 +			if ((*p == '\\') && (!escape)) {
  14.146 +				escape = TRUE;
  14.147 +			} else {
  14.148 +				*(q++) = *p;
  14.149 +				i++;
  14.150 +				escape = FALSE;
  14.151 +			}
  14.152 +			p++;
  14.153 +		}
  14.154  	}
  14.155 -	p++;
  14.156 -      }else{
  14.157 -	/* $var style */
  14.158 -	while(*p && (isalnum(*p) || (*p == '_') || (*p == '-')) && (j < MAX_VAR)){
  14.159 -	  *(vq++) = *(p++);
  14.160 -	  j++;
  14.161 -	}
  14.162 -      }
  14.163 -      *vq = 0;
  14.164 +	*q = 0;
  14.165  
  14.166 -      if(j < MAX_VAR){
  14.167 -	/* search var */
  14.168 -	value = (gchar *)table_find(var_list, var);
  14.169 -	if(value){
  14.170 -	  gchar *vp = value;
  14.171 -	  while(*vp && (i < (result_len -1))){
  14.172 -	    *(q++) = *(vp++); i++;
  14.173 -	  }
  14.174 -	}
  14.175 -      }
  14.176 -    }else{
  14.177 -      if((*p == '\\') && (!escape)){
  14.178 -	escape = TRUE;
  14.179 -      }else{
  14.180 -	*(q++) = *p; i++;
  14.181 -	escape = FALSE;
  14.182 -      }
  14.183 -      p++;
  14.184 -    }
  14.185 -  }
  14.186 -  *q = 0;
  14.187 +	if (i >= (result_len - 1))
  14.188 +		return -3;
  14.189  
  14.190 -  if(i >= (result_len -1))
  14.191 -    return -3;
  14.192 -
  14.193 -  return i;
  14.194 +	return i;
  14.195  }
  14.196 -
    15.1 --- a/src/fail_msg.c	Mon Oct 27 16:21:27 2008 +0100
    15.2 +++ b/src/fail_msg.c	Mon Oct 27 16:23:10 2008 +0100
    15.3 @@ -5,7 +5,7 @@
    15.4   * it under the terms of the GNU General Public License as published by
    15.5   * the Free Software Foundation; either version 2 of the License, or
    15.6   * (at your option) any later version.
    15.7 - * 
    15.8 + *
    15.9   * This program is distributed in the hope that it will be useful,
   15.10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15.12 @@ -22,109 +22,107 @@
   15.13  #include "peopen.h"
   15.14  #include "readsock.h"
   15.15  
   15.16 -gboolean fail_msg(message *msg, gchar *template,
   15.17 -		  GList *failed_rcpts, gchar *err_fmt, va_list args)
   15.18 +gboolean
   15.19 +fail_msg(message * msg, gchar * template, GList * failed_rcpts, gchar * err_fmt, va_list args)
   15.20  {
   15.21 -  gboolean ok = FALSE;
   15.22 -  address *ret_path = NULL;
   15.23 +	gboolean ok = FALSE;
   15.24 +	address *ret_path = NULL;
   15.25  
   15.26 -  /* do not bounce bounces, send to postmaster instead */
   15.27 -  if(msg->return_path->local_part[0] == 0){
   15.28 -    GList *node;
   15.29 +	/* do not bounce bounces, send to postmaster instead */
   15.30 +	if (msg->return_path->local_part[0] == 0) {
   15.31 +		GList *node;
   15.32  
   15.33 -    ret_path = create_address_qualified("postmaster", TRUE, conf.host_name);
   15.34 -    foreach(failed_rcpts, node){
   15.35 -      address *addr = (address *)(node->data);
   15.36 -      if(addr_isequal_parent(addr, ret_path)){
   15.37 -	logwrite(LOG_ALERT, "%s == %s: postmaster address failed\n",
   15.38 -		 msg->uid, addr_string(ret_path));
   15.39 -	return FALSE;
   15.40 -      }
   15.41 -    }
   15.42 -  }else
   15.43 -    ret_path = copy_address(msg->return_path);
   15.44 +		ret_path = create_address_qualified("postmaster", TRUE, conf.host_name);
   15.45 +		foreach(failed_rcpts, node) {
   15.46 +			address *addr = (address *) (node->data);
   15.47 +			if (addr_isequal_parent(addr, ret_path)) {
   15.48 +				logwrite(LOG_ALERT, "%s == %s: postmaster address failed\n", msg->uid, addr_string(ret_path));
   15.49 +				return FALSE;
   15.50 +			}
   15.51 +		}
   15.52 +	} else
   15.53 +		ret_path = copy_address(msg->return_path);
   15.54  
   15.55 -  DEBUG(1) debugf("sending failure notice to %s.\n", addr_string(ret_path));
   15.56 +	DEBUG(1) debugf("sending failure notice to %s.\n", addr_string(ret_path));
   15.57  
   15.58 -  if(template){
   15.59 -    FILE *file;
   15.60 -    GList *var_table = var_table_conf(var_table_msg(NULL, msg));
   15.61 -    gchar *err_msg = g_strdup_vprintf(err_fmt, args);
   15.62 +	if (template) {
   15.63 +		FILE *file;
   15.64 +		GList *var_table = var_table_conf(var_table_msg(NULL, msg));
   15.65 +		gchar *err_msg = g_strdup_vprintf(err_fmt, args);
   15.66  
   15.67 -    var_table = g_list_prepend(var_table, create_pair_string("err_msg", err_msg));
   15.68 -    g_free(err_msg);
   15.69 +		var_table = g_list_prepend(var_table, create_pair_string("err_msg", err_msg));
   15.70 +		g_free(err_msg);
   15.71  
   15.72 -    if((file = fopen(template, "r"))){
   15.73 -      FILE *out;
   15.74 -      gchar *cmd;
   15.75 -      pid_t pid;
   15.76 +		if ((file = fopen(template, "r"))) {
   15.77 +			FILE *out;
   15.78 +			gchar *cmd;
   15.79 +			pid_t pid;
   15.80  
   15.81 -      //      cmd = g_strdup_printf(SBINDIR"/masqmail -oi -f \"<>\" %s@%s",
   15.82 -      //			    ret_path->local_part, ret_path->domain);
   15.83 -      cmd = g_strdup_printf(SBINDIR"/masqmail -oi -f <> %s@%s",
   15.84 -			    ret_path->local_part, ret_path->domain);
   15.85 -      if((out = peidopen(cmd, "w", environ, &pid, conf.mail_uid, conf.mail_gid))){
   15.86 -	gchar fmt[256], line[256];
   15.87 -	int status, ret;
   15.88 +			//      cmd = g_strdup_printf(SBINDIR"/masqmail -oi -f \"<>\" %s@%s",
   15.89 +			//                ret_path->local_part, ret_path->domain);
   15.90 +			cmd = g_strdup_printf(SBINDIR "/masqmail -oi -f <> %s@%s", ret_path->local_part, ret_path->domain);
   15.91 +			if ((out = peidopen(cmd, "w", environ, &pid, conf.mail_uid, conf.mail_gid))) {
   15.92 +				gchar fmt[256], line[256];
   15.93 +				int status, ret;
   15.94  
   15.95 -	while((ret = read_sockline(file, fmt, 256, 0, 0)) > 0){
   15.96 -	  if(fmt[0] == '@'){
   15.97 -	    GList *node;
   15.98 -	    if(strncmp(fmt, "@failed_rcpts", 13) == 0){
   15.99 -	      foreach(failed_rcpts, node){
  15.100 -		address *rcpt = (address *)(node->data);
  15.101 -		fprintf(out, "\t%s\n", addr_string(rcpt));
  15.102 -	      }
  15.103 -	    }else if(strncmp(fmt, "@msg_headers", 12) == 0){
  15.104 -	      foreach(msg->hdr_list, node){
  15.105 -		header *hdr = (header *)(node->data);
  15.106 -		fputs(hdr->header, out);
  15.107 -	      }
  15.108 -	    }else if(strncmp(fmt, "@msg_body", 9) == 0){
  15.109 -	      /* we may have to read the data at this point
  15.110 -		 and remember if we did */
  15.111 -	      gboolean flag = (msg->data_list == NULL);
  15.112 -	      if(flag){
  15.113 -		if(!spool_read_data(msg)){
  15.114 -		  logwrite(LOG_ALERT, "could not open data spool file %s\n",
  15.115 -			   msg->uid);
  15.116 -		}
  15.117 -	      }
  15.118 -	      foreach(msg->data_list, node){
  15.119 -		gchar *line = (gchar *)(node->data);
  15.120 -		fputs(line, out);
  15.121 -	      }
  15.122 -	      if(flag) msg_free_data(msg);
  15.123 -	    }
  15.124 -	  }else{
  15.125 -	    expand(var_table, fmt, line, 256);
  15.126 -	    fputs(line, out);
  15.127 -	  }
  15.128 +				while ((ret = read_sockline(file, fmt, 256, 0, 0)) > 0) {
  15.129 +					if (fmt[0] == '@') {
  15.130 +						GList *node;
  15.131 +						if (strncmp(fmt, "@failed_rcpts", 13) == 0) {
  15.132 +							foreach(failed_rcpts, node) {
  15.133 +								address *rcpt = (address *) (node->data);
  15.134 +								fprintf(out, "\t%s\n", addr_string(rcpt));
  15.135 +							}
  15.136 +						} else if (strncmp(fmt, "@msg_headers", 12) == 0) {
  15.137 +							foreach(msg->hdr_list, node) {
  15.138 +								header *hdr = (header *) (node->data);
  15.139 +								fputs(hdr->header, out);
  15.140 +							}
  15.141 +						} else if (strncmp(fmt, "@msg_body", 9) == 0) {
  15.142 +							/* we may have to read the data at this point
  15.143 +							   and remember if we did */
  15.144 +							gboolean flag = (msg->data_list == NULL);
  15.145 +							if (flag) {
  15.146 +								if (!spool_read_data(msg)) {
  15.147 +									logwrite(LOG_ALERT, "could not open data spool file %s\n", msg->uid);
  15.148 +								}
  15.149 +							}
  15.150 +							foreach(msg->data_list, node) {
  15.151 +								gchar *line = (gchar *) (node->data);
  15.152 +								fputs(line, out);
  15.153 +							}
  15.154 +							if (flag)
  15.155 +								msg_free_data(msg);
  15.156 +						}
  15.157 +					} else {
  15.158 +						expand(var_table, fmt, line, 256);
  15.159 +						fputs(line, out);
  15.160 +					}
  15.161 +				}
  15.162 +
  15.163 +				fclose(out);
  15.164 +				waitpid(pid, &status, 0);
  15.165 +				if ((WEXITSTATUS(status) != EXIT_SUCCESS) || WIFSIGNALED(status)) {
  15.166 +					if (WEXITSTATUS(status) != EXIT_SUCCESS)
  15.167 +						logwrite(LOG_WARNING, "child returned %d\n", WEXITSTATUS(status));
  15.168 +					if (WIFSIGNALED(status))
  15.169 +						logwrite(LOG_WARNING, "child got signal: %d\n", WTERMSIG(status));
  15.170 +				} else
  15.171 +					ok = TRUE;
  15.172 +			} else {
  15.173 +				logwrite(LOG_ERR, "peopen failed: %s\n", strerror(errno));
  15.174 +			}
  15.175 +			g_free(cmd);
  15.176 +			fclose(file);
  15.177 +		} else
  15.178 +			logwrite(LOG_ALERT, "could not open failure message template %s: %s\n", conf.errmsg_file, strerror(errno));
  15.179 +
  15.180 +		destroy_table(var_table);
  15.181  	}
  15.182  
  15.183 -	fclose(out);
  15.184 -	waitpid(pid, &status, 0);
  15.185 -	if((WEXITSTATUS(status) != EXIT_SUCCESS) || WIFSIGNALED(status)){
  15.186 -	  if(WEXITSTATUS(status) != EXIT_SUCCESS)
  15.187 -	    logwrite(LOG_WARNING, "child returned %d\n", WEXITSTATUS(status));
  15.188 -	  if(WIFSIGNALED(status))
  15.189 -	    logwrite(LOG_WARNING, "child got signal: %d\n", WTERMSIG(status));
  15.190 -	}else ok = TRUE;
  15.191 -      }else{
  15.192 -	logwrite(LOG_ERR, "peopen failed: %s\n", strerror(errno));
  15.193 -      }
  15.194 -      g_free(cmd);
  15.195 -      fclose(file);
  15.196 -    }else
  15.197 -      logwrite(LOG_ALERT, "could not open failure message template %s: %s\n",
  15.198 -	       conf.errmsg_file, strerror(errno));
  15.199 +	destroy_address(ret_path);
  15.200  
  15.201 -    destroy_table(var_table);
  15.202 -  }
  15.203 -    
  15.204 -  destroy_address(ret_path);
  15.205 -
  15.206 -  return ok;
  15.207 +	return ok;
  15.208  }
  15.209  
  15.210  /*
  15.211 @@ -133,45 +131,43 @@
  15.212  result: |nnnyyyynnnnyyyyyyyyyynnnnnnn
  15.213  */
  15.214  
  15.215 -static
  15.216 -gboolean warn_msg_is_due(message *msg)
  15.217 +static gboolean
  15.218 +warn_msg_is_due(message * msg)
  15.219  {
  15.220 -  time_t now = time(NULL);
  15.221 -  gint dummy;
  15.222 -  
  15.223 -  GList *node;
  15.224 -  for(node = g_list_last(conf.warn_intervals); node; node = g_list_previous(node)){
  15.225 -    gchar *str_ival = (gchar *)(node->data);
  15.226 -    gint ival = time_interval(str_ival, &dummy);
  15.227 -    if(ival >= 0){
  15.228 -      DEBUG(5) debugf("ival = %d\n", ival);
  15.229 -      DEBUG(5) debugf("now - msg->received_time = %d\n", now - msg->received_time);
  15.230 -      if((now - msg->received_time) > ival){
  15.231 -	if(msg->warned_time != 0){
  15.232 -	  if((msg->warned_time - msg->received_time) < ival)
  15.233 -	    return TRUE;
  15.234 -	}else
  15.235 -	  return TRUE;
  15.236 -      }
  15.237 -    }else
  15.238 -      logwrite(LOG_WARNING, "invalid time interval: %s\n", str_ival);
  15.239 -  }
  15.240 -  return FALSE;
  15.241 +	time_t now = time(NULL);
  15.242 +	gint dummy;
  15.243 +
  15.244 +	GList *node;
  15.245 +	for (node = g_list_last(conf.warn_intervals); node; node = g_list_previous(node)) {
  15.246 +		gchar *str_ival = (gchar *) (node->data);
  15.247 +		gint ival = time_interval(str_ival, &dummy);
  15.248 +		if (ival >= 0) {
  15.249 +			DEBUG(5) debugf("ival = %d\n", ival);
  15.250 +			DEBUG(5) debugf("now - msg->received_time = %d\n", now - msg->received_time);
  15.251 +			if ((now - msg->received_time) > ival) {
  15.252 +				if (msg->warned_time != 0) {
  15.253 +					if ((msg->warned_time - msg->received_time) < ival)
  15.254 +						return TRUE;
  15.255 +				} else
  15.256 +					return TRUE;
  15.257 +			}
  15.258 +		} else
  15.259 +			logwrite(LOG_WARNING, "invalid time interval: %s\n", str_ival);
  15.260 +	}
  15.261 +	return FALSE;
  15.262  }
  15.263  
  15.264 -gboolean warn_msg(message *msg, gchar *template,
  15.265 -		  GList *defered_rcpts, gchar *err_fmt, va_list args)
  15.266 +gboolean
  15.267 +warn_msg(message * msg, gchar * template, GList * defered_rcpts, gchar * err_fmt, va_list args)
  15.268  {
  15.269 -  time_t now = time(NULL);
  15.270 +	time_t now = time(NULL);
  15.271  
  15.272 -  if(warn_msg_is_due(msg)){
  15.273 -    if(fail_msg(msg, template, defered_rcpts, err_fmt, args)){
  15.274 -      msg->warned_time = now;
  15.275 -      return TRUE;
  15.276 -    }else
  15.277 -      return FALSE;
  15.278 -  }
  15.279 -  return TRUE;
  15.280 +	if (warn_msg_is_due(msg)) {
  15.281 +		if (fail_msg(msg, template, defered_rcpts, err_fmt, args)) {
  15.282 +			msg->warned_time = now;
  15.283 +			return TRUE;
  15.284 +		} else
  15.285 +			return FALSE;
  15.286 +	}
  15.287 +	return TRUE;
  15.288  }
  15.289 -
  15.290 -      
    16.1 --- a/src/get.c	Mon Oct 27 16:21:27 2008 +0100
    16.2 +++ b/src/get.c	Mon Oct 27 16:23:10 2008 +0100
    16.3 @@ -27,384 +27,368 @@
    16.4  
    16.5  static int volatile sighup_seen = 0;
    16.6  
    16.7 -static
    16.8 -void sighup_handler(int sig)
    16.9 +static void
   16.10 +sighup_handler(int sig)
   16.11  {
   16.12 -  sighup_seen = 1;
   16.13 -  signal(SIGHUP, sighup_handler);
   16.14 +	sighup_seen = 1;
   16.15 +	signal(SIGHUP, sighup_handler);
   16.16  }
   16.17  
   16.18 -static
   16.19 -void sigchld_handler(int sig)
   16.20 +static void
   16.21 +sigchld_handler(int sig)
   16.22  {
   16.23 -  pid_t pid;
   16.24 -  int status;
   16.25 -  
   16.26 -  pid = waitpid(0, &status, 0);
   16.27 -  if(pid > 0){
   16.28 -    if(WEXITSTATUS(status) != EXIT_SUCCESS)
   16.29 -      logwrite(LOG_WARNING, "process %d exited with %d\n",
   16.30 -	       pid, WEXITSTATUS(status));
   16.31 -    if(WIFSIGNALED(status))
   16.32 -      logwrite(LOG_WARNING,
   16.33 -	       "process with pid %d got signal: %d\n",
   16.34 -	       pid, WTERMSIG(status));
   16.35 -  }
   16.36 -  signal(SIGCHLD, sigchld_handler);
   16.37 +	pid_t pid;
   16.38 +	int status;
   16.39 +
   16.40 +	pid = waitpid(0, &status, 0);
   16.41 +	if (pid > 0) {
   16.42 +		if (WEXITSTATUS(status) != EXIT_SUCCESS)
   16.43 +			logwrite(LOG_WARNING, "process %d exited with %d\n", pid, WEXITSTATUS(status));
   16.44 +		if (WIFSIGNALED(status))
   16.45 +			logwrite(LOG_WARNING, "process with pid %d got signal: %d\n", pid, WTERMSIG(status));
   16.46 +	}
   16.47 +	signal(SIGCHLD, sigchld_handler);
   16.48  }
   16.49  
   16.50 -static
   16.51 -int get_lock(get_conf *gc)
   16.52 +static int
   16.53 +get_lock(get_conf * gc)
   16.54  {
   16.55  #ifdef USE_DOTLOCK
   16.56 -  gboolean ok = FALSE;
   16.57 -  gchar *hitch_name;
   16.58 -  gchar *lock_name;
   16.59 +	gboolean ok = FALSE;
   16.60 +	gchar *hitch_name;
   16.61 +	gchar *lock_name;
   16.62  
   16.63 -  /* the name of the lock is constructed from the user
   16.64 -     and the server name, to prevent more than one connection at the same time
   16.65 -     to the same server and the same user. This way concurrent connections
   16.66 -     are possible to different servers or different users */
   16.67 -  hitch_name = g_strdup_printf("%s/masqmail-get-%s@%s-%d.lock",
   16.68 -			       conf.lock_dir, gc->login_user,
   16.69 -			       gc->server_name, getpid());
   16.70 -  lock_name = g_strdup_printf("%s/masqmail-get-%s@%s.lock",
   16.71 -			      conf.lock_dir, gc->login_user, gc->server_name);
   16.72 -  
   16.73 -  ok = dot_lock(lock_name, hitch_name);
   16.74 -  if(!ok) logwrite(LOG_WARNING,
   16.75 -		   "getting mail for %s@%s is locked\n",
   16.76 -		   gc->login_user, gc->server_name);
   16.77 +	/* the name of the lock is constructed from the user
   16.78 +	   and the server name, to prevent more than one connection at the same time
   16.79 +	   to the same server and the same user. This way concurrent connections
   16.80 +	   are possible to different servers or different users */
   16.81 +	hitch_name = g_strdup_printf("%s/masqmail-get-%s@%s-%d.lock", conf.lock_dir, gc->login_user, gc->server_name, getpid());
   16.82 +	lock_name = g_strdup_printf("%s/masqmail-get-%s@%s.lock", conf.lock_dir, gc->login_user, gc->server_name);
   16.83  
   16.84 -  g_free(lock_name);
   16.85 -  g_free(hitch_name);
   16.86 +	ok = dot_lock(lock_name, hitch_name);
   16.87 +	if (!ok)
   16.88 +		logwrite(LOG_WARNING, "getting mail for %s@%s is locked\n", gc->login_user, gc->server_name);
   16.89  
   16.90 -  return ok;
   16.91 +	g_free(lock_name);
   16.92 +	g_free(hitch_name);
   16.93 +
   16.94 +	return ok;
   16.95  #else
   16.96 -  gchar *lock_name;
   16.97 -  int fd;
   16.98 +	gchar *lock_name;
   16.99 +	int fd;
  16.100  
  16.101 -  lock_name = g_strdup_printf("%s/masqmail-get-%s@%s.lock",
  16.102 -			      conf.lock_dir, gc->login_user, gc->server_name);
  16.103 +	lock_name = g_strdup_printf("%s/masqmail-get-%s@%s.lock", conf.lock_dir, gc->login_user, gc->server_name);
  16.104  
  16.105 -  if((fd = open(lock_name, O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600)) >= 0){
  16.106 -    if(flock(fd, LOCK_EX|LOCK_NB) != 0){
  16.107 -      close(fd);
  16.108 -      logwrite(LOG_WARNING,
  16.109 -	       "getting mail for %s@%s is locked\n",
  16.110 -	       gc->login_user, gc->server_name);
  16.111 -      fd = -1;
  16.112 -    }
  16.113 -  }else
  16.114 -    logwrite(LOG_WARNING,
  16.115 -	     "could not open lock %s: %s\n", lock_name, strerror(errno));
  16.116 +	if ((fd = open(lock_name, O_WRONLY | O_NDELAY | O_APPEND | O_CREAT, 0600)) >= 0) {
  16.117 +		if (flock(fd, LOCK_EX | LOCK_NB) != 0) {
  16.118 +			close(fd);
  16.119 +			logwrite(LOG_WARNING, "getting mail for %s@%s is locked\n", gc->login_user, gc->server_name);
  16.120 +			fd = -1;
  16.121 +		}
  16.122 +	} else
  16.123 +		logwrite(LOG_WARNING, "could not open lock %s: %s\n", lock_name, strerror(errno));
  16.124  
  16.125 -  g_free(lock_name);
  16.126 +	g_free(lock_name);
  16.127  
  16.128 -  return fd;
  16.129 +	return fd;
  16.130  #endif
  16.131  }
  16.132  
  16.133  #ifdef USE_DOTLOCK
  16.134 -static
  16.135 -gboolean get_unlock(get_conf *gc)
  16.136 +static gboolean
  16.137 +get_unlock(get_conf * gc)
  16.138  {
  16.139 -  gchar *lock_name lock_name =
  16.140 -    g_strdup_printf("%s/masqmail-get-%s@%s.lock",
  16.141 -		    conf.lock_dir, gc->login_user, gc->server_name);
  16.142 -  
  16.143 -  dot_unlock(lock_name);
  16.144 +	gchar *lock_name lock_name = g_strdup_printf("%s/masqmail-get-%s@%s.lock", conf.lock_dir, gc->login_user, gc->server_name);
  16.145  
  16.146 -  g_free(lock_name);
  16.147 +	dot_unlock(lock_name);
  16.148 +	g_free(lock_name);
  16.149  
  16.150 -  return TRUE;
  16.151 +	return TRUE;
  16.152  }
  16.153  #else
  16.154 -static void get_unlock(get_conf *gc, int fd)
  16.155 +static void
  16.156 +get_unlock(get_conf * gc, int fd)
  16.157  {
  16.158 -  gchar *lock_name =
  16.159 -    g_strdup_printf("%s/masqmail-get-%s@%s.lock",
  16.160 -		    conf.lock_dir, gc->login_user, gc->server_name);
  16.161 +	gchar *lock_name = g_strdup_printf("%s/masqmail-get-%s@%s.lock", conf.lock_dir, gc->login_user, gc->server_name);
  16.162  
  16.163 -  flock(fd, LOCK_UN);
  16.164 -  close(fd);
  16.165 +	flock(fd, LOCK_UN);
  16.166 +	close(fd);
  16.167  
  16.168 -  unlink(lock_name);
  16.169 -  g_free(lock_name);
  16.170 +	unlink(lock_name);
  16.171 +	g_free(lock_name);
  16.172  }
  16.173  #endif
  16.174  
  16.175 -gboolean get_from_file(gchar *fname)
  16.176 +gboolean
  16.177 +get_from_file(gchar * fname)
  16.178  {
  16.179 -  guint flags = 0;
  16.180 -  get_conf *gc = read_get_conf(fname);
  16.181 -  gboolean ok = TRUE;
  16.182 -  int lock;
  16.183 +	guint flags = 0;
  16.184 +	get_conf *gc = read_get_conf(fname);
  16.185 +	gboolean ok = TRUE;
  16.186 +	int lock;
  16.187  
  16.188 -  if(gc){
  16.189 -    if(!gc->do_keep) flags |= POP3_FLAG_DELETE;
  16.190 -    if(gc->do_uidl) flags |= POP3_FLAG_UIDL;
  16.191 -    if(gc->do_uidl_dele) flags |= POP3_FLAG_UIDL_DELE;
  16.192 -    
  16.193 -    if(!(gc->server_name)){
  16.194 -      logwrite(LOG_ALERT, "no server name given in %s\n", fname); return FALSE;
  16.195 -    }
  16.196 -    if(!(gc->address)){
  16.197 -      logwrite(LOG_ALERT, "no address given in %s\n", fname); return FALSE;
  16.198 -    }
  16.199 -    if(!(gc->login_user)){
  16.200 -      logwrite(LOG_ALERT, "no user name given in %s\n", fname); return FALSE;
  16.201 -    }
  16.202 -    if(!(gc->login_pass)){
  16.203 -      logwrite(LOG_ALERT, "no password given in %s\n", fname); return FALSE;
  16.204 -    }
  16.205 +	if (gc) {
  16.206 +		if (!gc->do_keep)
  16.207 +			flags |= POP3_FLAG_DELETE;
  16.208 +		if (gc->do_uidl)
  16.209 +			flags |= POP3_FLAG_UIDL;
  16.210 +		if (gc->do_uidl_dele)
  16.211 +			flags |= POP3_FLAG_UIDL_DELE;
  16.212  
  16.213 -    DEBUG(3) debugf("flags = %d\n", flags);
  16.214 -    
  16.215 -    if((strcmp(gc->protocol, "pop3") == 0) || (strcmp(gc->protocol, "apop") == 0)){
  16.216 -      pop3_base *popb = NULL;
  16.217 +		if (!(gc->server_name)) {
  16.218 +			logwrite(LOG_ALERT, "no server name given in %s\n", fname);
  16.219 +			return FALSE;
  16.220 +		}
  16.221 +		if (!(gc->address)) {
  16.222 +			logwrite(LOG_ALERT, "no address given in %s\n", fname);
  16.223 +			return FALSE;
  16.224 +		}
  16.225 +		if (!(gc->login_user)) {
  16.226 +			logwrite(LOG_ALERT, "no user name given in %s\n", fname);
  16.227 +			return FALSE;
  16.228 +		}
  16.229 +		if (!(gc->login_pass)) {
  16.230 +			logwrite(LOG_ALERT, "no password given in %s\n", fname);
  16.231 +			return FALSE;
  16.232 +		}
  16.233  
  16.234 -      if(strcmp(gc->protocol, "apop") == 0){
  16.235 -	flags |= POP3_FLAG_APOP;
  16.236 -	DEBUG(3) debugf("attempting to get mail for user %s at host %s"
  16.237 -			" for %s@%s with apop\n",
  16.238 -			gc->login_user, gc->server_name,
  16.239 -			gc->address->local_part, gc->address->domain);
  16.240 -      }else{
  16.241 -	DEBUG(3) debugf("attempting to get mail for user %s at host %s"
  16.242 -			" for %s@%s with pop3\n",
  16.243 -			gc->login_user, gc->server_name,
  16.244 -			gc->address->local_part, gc->address->domain);
  16.245 -      }
  16.246 +		DEBUG(3) debugf("flags = %d\n", flags);
  16.247 +
  16.248 +		if ((strcmp(gc->protocol, "pop3") == 0) || (strcmp(gc->protocol, "apop") == 0)) {
  16.249 +			pop3_base *popb = NULL;
  16.250 +
  16.251 +			if (strcmp(gc->protocol, "apop") == 0) {
  16.252 +				flags |= POP3_FLAG_APOP;
  16.253 +				DEBUG(3) debugf("attempting to get mail for user %s at host %s for %s@%s with apop\n",
  16.254 +				                gc->login_user, gc->server_name, gc->address->local_part, gc->address->domain);
  16.255 +			} else {
  16.256 +				DEBUG(3) debugf("attempting to get mail for user %s at host %s for %s@%s with pop3\n",
  16.257 +				                gc->login_user, gc->server_name, gc->address->local_part, gc->address->domain);
  16.258 +			}
  16.259  #ifdef USE_DOTLOCK
  16.260 -      if((lock = get_lock(gc))){
  16.261 +			if ((lock = get_lock(gc))) {
  16.262  #else
  16.263 -      if((lock = get_lock(gc)) >= 0){
  16.264 +			if ((lock = get_lock(gc)) >= 0) {
  16.265  #endif
  16.266 -	if(gc->wrapper){
  16.267 -	  popb = pop3_in_open_child(gc->wrapper, flags);
  16.268 -	  /* quick hack */
  16.269 -	  popb->remote_host = gc->server_name;
  16.270 -	}else{
  16.271 -	  popb = pop3_in_open(gc->server_name, gc->server_port,
  16.272 -			      gc->resolve_list, flags);
  16.273 +				if (gc->wrapper) {
  16.274 +					popb = pop3_in_open_child(gc->wrapper, flags);
  16.275 +					/* quick hack */
  16.276 +					popb->remote_host = gc->server_name;
  16.277 +				} else {
  16.278 +					popb = pop3_in_open(gc->server_name, gc->server_port, gc->resolve_list, flags);
  16.279 +				}
  16.280 +				if (popb) {
  16.281 +					ok = pop3_get(popb, gc->login_user, gc->login_pass, gc->address, gc->return_path,
  16.282 +					              gc->max_count, gc->max_size, gc->max_size_delete);
  16.283 +					pop3_in_close(popb);
  16.284 +				} else {
  16.285 +					ok = FALSE;
  16.286 +					logwrite(LOG_ALERT, "failed to connect to host %s\n", gc->server_name);
  16.287 +				}
  16.288 +#ifdef USE_DOTLOCK
  16.289 +				get_unlock(gc);
  16.290 +#else
  16.291 +				get_unlock(gc, lock);
  16.292 +#endif
  16.293 +			}
  16.294 +		} else {
  16.295 +			logwrite(LOG_ALERT, "get protocol %s unknown\n", gc->protocol);
  16.296 +			ok = FALSE;
  16.297 +		}
  16.298 +
  16.299 +		destroy_get_conf(gc);
  16.300  	}
  16.301 -	if(popb){
  16.302 -	  ok = pop3_get(popb, gc->login_user, gc->login_pass,
  16.303 -			gc->address, gc->return_path,
  16.304 -			gc->max_count, gc->max_size, gc->max_size_delete);
  16.305 -	  pop3_in_close(popb);
  16.306 -	}else{
  16.307 -	  ok = FALSE;
  16.308 -	  logwrite(LOG_ALERT, "failed to connect to host %s\n", gc->server_name);
  16.309 -	}
  16.310 -#ifdef USE_DOTLOCK
  16.311 -	get_unlock(gc);
  16.312 -#else
  16.313 -	get_unlock(gc, lock);
  16.314 -#endif
  16.315 -      }
  16.316 -    }else{
  16.317 -      logwrite(LOG_ALERT, "get protocol %s unknown\n", gc->protocol);
  16.318 -      ok = FALSE;
  16.319 -    }
  16.320 -
  16.321 -    destroy_get_conf(gc);
  16.322 -  }
  16.323 -  return ok;
  16.324 +	return ok;
  16.325  }
  16.326  
  16.327 -gboolean get_from_name(gchar *name)
  16.328 +gboolean
  16.329 +get_from_name(gchar * name)
  16.330  {
  16.331 -  gchar *fname = (gchar *)table_find(conf.get_names, name);
  16.332 -  if(fname)
  16.333 -    return get_from_file(fname);
  16.334 -  return FALSE;
  16.335 +	gchar *fname = (gchar *) table_find(conf.get_names, name);
  16.336 +	if (fname)
  16.337 +		return get_from_file(fname);
  16.338 +	return FALSE;
  16.339  }
  16.340  
  16.341 -gboolean get_all()
  16.342 +gboolean
  16.343 +get_all()
  16.344  {
  16.345 -  GList *get_table = conf.get_names;
  16.346 -  GList *get_node;
  16.347 -  void (*old_signal)(int);
  16.348 +	GList *get_table = conf.get_names;
  16.349 +	GList *get_node;
  16.350 +	void (*old_signal) (int);
  16.351  
  16.352 -  old_signal = signal(SIGCHLD, SIG_DFL);
  16.353 +	old_signal = signal(SIGCHLD, SIG_DFL);
  16.354  
  16.355 -  foreach(get_table, get_node){
  16.356 -    table_pair *pair = (table_pair *)(get_node->data);
  16.357 -    gchar *fname = (gchar *)pair->value;
  16.358 -    pid_t pid;
  16.359 +	foreach(get_table, get_node) {
  16.360 +		table_pair *pair = (table_pair *) (get_node->data);
  16.361 +		gchar *fname = (gchar *) pair->value;
  16.362 +		pid_t pid;
  16.363  
  16.364 -    pid = fork();
  16.365 -    if(pid == 0){
  16.366 -      signal(SIGCHLD, old_signal);    
  16.367 -      exit(get_from_file(fname) ? EXIT_SUCCESS : EXIT_FAILURE);
  16.368 -    }else if(pid > 0){
  16.369 -      int status;
  16.370 -      waitpid(pid, &status, 0);
  16.371 -      if(WEXITSTATUS(status) != EXIT_SUCCESS)
  16.372 -	logwrite(LOG_WARNING, "child returned %d\n", WEXITSTATUS(status));
  16.373 -      if(WIFSIGNALED(status))
  16.374 -	logwrite(LOG_WARNING, "child got signal: %d\n", WTERMSIG(status));
  16.375 -    }else
  16.376 -      logwrite(LOG_WARNING, "forking child failed: %s\n", strerror(errno));
  16.377 -  }
  16.378 -    
  16.379 -  signal(SIGCHLD, old_signal);    
  16.380 +		pid = fork();
  16.381 +		if (pid == 0) {
  16.382 +			signal(SIGCHLD, old_signal);
  16.383 +			exit(get_from_file(fname) ? EXIT_SUCCESS : EXIT_FAILURE);
  16.384 +		} else if (pid > 0) {
  16.385 +			int status;
  16.386 +			waitpid(pid, &status, 0);
  16.387 +			if (WEXITSTATUS(status) != EXIT_SUCCESS)
  16.388 +				logwrite(LOG_WARNING, "child returned %d\n", WEXITSTATUS(status));
  16.389 +			if (WIFSIGNALED(status))
  16.390 +				logwrite(LOG_WARNING, "child got signal: %d\n", WTERMSIG(status));
  16.391 +		} else
  16.392 +			logwrite(LOG_WARNING, "forking child failed: %s\n", strerror(errno));
  16.393 +	}
  16.394  
  16.395 -  return TRUE;
  16.396 +	signal(SIGCHLD, old_signal);
  16.397 +
  16.398 +	return TRUE;
  16.399  }
  16.400  
  16.401 -void get_online()
  16.402 +void
  16.403 +get_online()
  16.404  {
  16.405 -  GList *gf_list = NULL;
  16.406 -  gchar *connect_name = detect_online();
  16.407 +	GList *gf_list = NULL;
  16.408 +	gchar *connect_name = detect_online();
  16.409  
  16.410 -  if(connect_name != NULL){
  16.411 -    void (*old_signal)(int);
  16.412 +	if (connect_name != NULL) {
  16.413 +		void (*old_signal) (int);
  16.414  
  16.415 -    old_signal = signal(SIGCHLD, SIG_DFL);
  16.416 +		old_signal = signal(SIGCHLD, SIG_DFL);
  16.417  
  16.418 -    logwrite(LOG_NOTICE, "detected online configuration %s\n", connect_name);
  16.419 -    /* we are online! */
  16.420 -    gf_list = (GList *)table_find(conf.online_gets, connect_name);
  16.421 -    if(gf_list != NULL){
  16.422 -      GList *node;
  16.423 -      foreach(gf_list, node){
  16.424 -	gchar *fname = (gchar *)(node->data);
  16.425 -	pid_t pid;
  16.426 +		logwrite(LOG_NOTICE, "detected online configuration %s\n", connect_name);
  16.427 +		/* we are online! */
  16.428 +		gf_list = (GList *) table_find(conf.online_gets, connect_name);
  16.429 +		if (gf_list != NULL) {
  16.430 +			GList *node;
  16.431 +			foreach(gf_list, node) {
  16.432 +				gchar *fname = (gchar *) (node->data);
  16.433 +				pid_t pid;
  16.434  
  16.435 -	if(fname[0] != '/')
  16.436 -	  fname = (gchar *)table_find(conf.get_names, fname);
  16.437 +				if (fname[0] != '/')
  16.438 +					fname = (gchar *) table_find(conf.get_names, fname);
  16.439  
  16.440 -	if(fname != NULL){
  16.441 -	  pid = fork();
  16.442 -	  if(pid == 0){
  16.443 -	    signal(SIGCHLD, old_signal);    
  16.444 -	    exit(get_from_file(fname) ? EXIT_SUCCESS : EXIT_FAILURE);
  16.445 -	  }else if(pid > 0){
  16.446 -	    int status;
  16.447 -	    waitpid(pid, &status, 0);
  16.448 -	    if(WEXITSTATUS(status) != EXIT_SUCCESS)
  16.449 -	      logwrite(LOG_WARNING, "child returned %d\n", WEXITSTATUS(status));
  16.450 -	    if(WIFSIGNALED(status))
  16.451 -	      logwrite(LOG_WARNING, "child got signal: %d\n", WTERMSIG(status));
  16.452 -	  }else
  16.453 -	    logwrite(LOG_WARNING, "forking child failed: %s\n", strerror(errno));
  16.454 +				if (fname != NULL) {
  16.455 +					pid = fork();
  16.456 +					if (pid == 0) {
  16.457 +						signal(SIGCHLD, old_signal);
  16.458 +						exit(get_from_file(fname) ? EXIT_SUCCESS : EXIT_FAILURE);
  16.459 +					} else if (pid > 0) {
  16.460 +						int status;
  16.461 +						waitpid(pid, &status, 0);
  16.462 +						if (WEXITSTATUS(status) != EXIT_SUCCESS)
  16.463 +							logwrite(LOG_WARNING, "child returned %d\n", WEXITSTATUS(status));
  16.464 +						if (WIFSIGNALED(status))
  16.465 +							logwrite(LOG_WARNING, "child got signal: %d\n", WTERMSIG(status));
  16.466 +					} else
  16.467 +						logwrite(LOG_WARNING, "forking child failed: %s\n", strerror(errno));
  16.468 +				}
  16.469 +			}
  16.470 +		}
  16.471 +		signal(SIGCHLD, old_signal);
  16.472  	}
  16.473 -      }
  16.474 -    }
  16.475 -    signal(SIGCHLD, old_signal);    
  16.476 -  }
  16.477  }
  16.478  
  16.479 -void get_daemon(gint gival, char *argv[])
  16.480 +void
  16.481 +get_daemon(gint gival, char *argv[])
  16.482  {
  16.483 -  struct timeval tm;
  16.484 -  time_t time_before, time_now;
  16.485 -  int sel_ret;
  16.486 +	struct timeval tm;
  16.487 +	time_t time_before, time_now;
  16.488 +	int sel_ret;
  16.489  
  16.490 -  /* setup handler for HUP signal: */
  16.491 -  signal(SIGHUP, sighup_handler);
  16.492 +	/* setup handler for HUP signal: */
  16.493 +	signal(SIGHUP, sighup_handler);
  16.494  
  16.495 -  /* we can give up root privileges */
  16.496 -  if(!conf.run_as_user){
  16.497 -    if(setegid(conf.mail_gid) != 0){
  16.498 -      logwrite(LOG_ALERT, "could not change gid to %d: %s\n",
  16.499 -	       conf.mail_gid, strerror(errno));
  16.500 -      exit(EXIT_FAILURE);
  16.501 -    }
  16.502 -    if(seteuid(conf.mail_uid) != 0){
  16.503 -      logwrite(LOG_ALERT, "could not change uid to %d: %s\n",
  16.504 -	       conf.mail_uid, strerror(errno));
  16.505 -      exit(EXIT_FAILURE);
  16.506 -    }
  16.507 -  }
  16.508 +	/* we can give up root privileges */
  16.509 +	if (!conf.run_as_user) {
  16.510 +		if (setegid(conf.mail_gid) != 0) {
  16.511 +			logwrite(LOG_ALERT, "could not change gid to %d: %s\n", conf.mail_gid, strerror(errno));
  16.512 +			exit(EXIT_FAILURE);
  16.513 +		}
  16.514 +		if (seteuid(conf.mail_uid) != 0) {
  16.515 +			logwrite(LOG_ALERT, "could not change uid to %d: %s\n", conf.mail_uid, strerror(errno));
  16.516 +			exit(EXIT_FAILURE);
  16.517 +		}
  16.518 +	}
  16.519  
  16.520 -  /*  sel_ret = 0;*/
  16.521 -  time(&time_before);
  16.522 -  time_before -= gival;
  16.523 -  sel_ret = -1;
  16.524 +	/*  sel_ret = 0; */
  16.525 +	time(&time_before);
  16.526 +	time_before -= gival;
  16.527 +	sel_ret = -1;
  16.528  
  16.529 -  while (1){
  16.530 -    /* see listen_port() in listen.c */
  16.531 -    if(gival > 0){
  16.532 -      time(&time_now);
  16.533 -      if(sel_ret == 0){ /* we are either just starting or did a queue run */
  16.534 -	tm.tv_sec = gival;
  16.535 -	tm.tv_usec = 0;
  16.536 -	time_before = time_now;
  16.537 -      }else{
  16.538 -	tm.tv_sec = gival - (time_now - time_before);
  16.539 -	tm.tv_usec = 0;
  16.540 +	while (1) {
  16.541 +		/* see listen_port() in listen.c */
  16.542 +		if (gival > 0) {
  16.543 +			time(&time_now);
  16.544 +			if (sel_ret == 0) {	/* we are either just starting or did a queue run */
  16.545 +				tm.tv_sec = gival;
  16.546 +				tm.tv_usec = 0;
  16.547 +				time_before = time_now;
  16.548 +			} else {
  16.549 +				tm.tv_sec = gival - (time_now - time_before);
  16.550 +				tm.tv_usec = 0;
  16.551  
  16.552 -	/* race condition, very unlikely (but possible): */
  16.553 -	if(tm.tv_sec < 0)
  16.554 -	  tm.tv_sec = 0;
  16.555 -      }
  16.556 -    }
  16.557 +				/* race condition, very unlikely (but possible): */
  16.558 +				if (tm.tv_sec < 0)
  16.559 +					tm.tv_sec = 0;
  16.560 +			}
  16.561 +		}
  16.562  
  16.563 -    if ((sel_ret = select(0, NULL, NULL, NULL, &tm)) < 0){
  16.564 -      if(errno != EINTR){
  16.565 -	logwrite(LOG_ALERT, "select: (terminating): %s\n", strerror(errno));
  16.566 -	exit (EXIT_FAILURE);
  16.567 -      }else{
  16.568 -	if(sighup_seen){
  16.569 -	  logwrite(LOG_NOTICE, "HUP signal received. Restarting daemon\n");
  16.570 +		if ((sel_ret = select(0, NULL, NULL, NULL, &tm)) < 0) {
  16.571 +			if (errno != EINTR) {
  16.572 +				logwrite(LOG_ALERT, "select: (terminating): %s\n", strerror(errno));
  16.573 +				exit(EXIT_FAILURE);
  16.574 +			} else {
  16.575 +				if (sighup_seen) {
  16.576 +					logwrite(LOG_NOTICE, "HUP signal received. Restarting daemon\n");
  16.577  
  16.578 -	  if(argv == NULL) exit(EXIT_SUCCESS);
  16.579 +					if (argv == NULL)
  16.580 +						exit(EXIT_SUCCESS);
  16.581  
  16.582 -	  execv(argv[0], &(argv[0]));
  16.583 -	  logwrite(LOG_ALERT, "restarting failed: %s\n", strerror(errno));
  16.584 -	  exit(EXIT_FAILURE);
  16.585 +					execv(argv[0], &(argv[0]));
  16.586 +					logwrite(LOG_ALERT, "restarting failed: %s\n", strerror(errno));
  16.587 +					exit(EXIT_FAILURE);
  16.588  
  16.589 +				}
  16.590 +			}
  16.591 +		} else {
  16.592 +			/* If select returns 0, the interval time has elapsed.
  16.593 +			   We start a new get process */
  16.594 +			int pid;
  16.595 +			signal(SIGCHLD, sigchld_handler);
  16.596 +			if ((pid = fork()) == 0) {
  16.597 +				get_online();
  16.598 +
  16.599 +				_exit(EXIT_SUCCESS);
  16.600 +			} else if (pid < 0) {
  16.601 +				logwrite(LOG_ALERT, "could not fork for get run");
  16.602 +			}
  16.603 +		}
  16.604  	}
  16.605 -      }
  16.606 -    }else{
  16.607 -      /* If select returns 0, the interval time has elapsed.
  16.608 -	 We start a new get process */
  16.609 -      int pid;
  16.610 -      signal(SIGCHLD, sigchld_handler);
  16.611 -      if((pid = fork()) == 0){
  16.612 -	get_online();
  16.613 -
  16.614 -	_exit(EXIT_SUCCESS);
  16.615 -      }
  16.616 -      else if(pid < 0){
  16.617 -	logwrite(LOG_ALERT, "could not fork for get run");
  16.618 -      }
  16.619 -    }
  16.620 -  }
  16.621  }
  16.622  
  16.623 -gboolean pop_before_smtp(gchar *fname)
  16.624 +gboolean
  16.625 +pop_before_smtp(gchar * fname)
  16.626  {
  16.627 -  gboolean ok = FALSE;
  16.628 -  GList *resolve_list = NULL;
  16.629 -  get_conf *gc = read_get_conf(fname);
  16.630 -  guint flags = 0;
  16.631 +	gboolean ok = FALSE;
  16.632 +	GList *resolve_list = NULL;
  16.633 +	get_conf *gc = read_get_conf(fname);
  16.634 +	guint flags = 0;
  16.635  
  16.636  #ifdef ENABLE_RESOLVER
  16.637 -  resolve_list = g_list_append(resolve_list, resolve_dns_a);
  16.638 +	resolve_list = g_list_append(resolve_list, resolve_dns_a);
  16.639  #endif
  16.640 -  resolve_list = g_list_append(resolve_list, resolve_byname);
  16.641 +	resolve_list = g_list_append(resolve_list, resolve_byname);
  16.642  
  16.643 -  if(strcmp(gc->protocol, "pop3") == 0){
  16.644 -    DEBUG(3) debugf("attempting to login for user %s, host = %s with pop3\n",
  16.645 -		    gc->login_user, gc->server_name);
  16.646 -    ok = pop3_login(gc->server_name, gc->server_port, resolve_list,
  16.647 -		    gc->login_user, gc->login_pass,
  16.648 -		    flags);
  16.649 -  }else if(strcmp(gc->protocol, "apop") == 0){
  16.650 -    DEBUG(3) debugf("attempting to login for user %s, host = %s with apop\n",
  16.651 -		    gc->login_user, gc->server_name);
  16.652 -    ok = pop3_login(gc->server_name, gc->server_port, resolve_list,
  16.653 -		    gc->login_user, gc->login_pass,
  16.654 -		    flags | POP3_FLAG_APOP);
  16.655 -  }else{
  16.656 -    logwrite(LOG_ALERT, "get protocol %s unknown\n", gc->protocol);
  16.657 -  }
  16.658 -  return ok;
  16.659 +	if (strcmp(gc->protocol, "pop3") == 0) {
  16.660 +		DEBUG(3) debugf("attempting to login for user %s, host = %s with pop3\n", gc->login_user, gc->server_name);
  16.661 +		ok = pop3_login(gc->server_name, gc->server_port, resolve_list, gc->login_user, gc->login_pass, flags);
  16.662 +	} else if (strcmp(gc->protocol, "apop") == 0) {
  16.663 +		DEBUG(3) debugf ("attempting to login for user %s, host = %s with apop\n", gc->login_user, gc->server_name);
  16.664 +		ok = pop3_login(gc->server_name, gc->server_port, resolve_list, gc->login_user, gc->login_pass, flags | POP3_FLAG_APOP);
  16.665 +	} else {
  16.666 +		logwrite(LOG_ALERT, "get protocol %s unknown\n", gc->protocol);
  16.667 +	}
  16.668 +	return ok;
  16.669  }
  16.670  
  16.671  #endif
    17.1 --- a/src/header.c	Mon Oct 27 16:21:27 2008 +0100
    17.2 +++ b/src/header.c	Mon Oct 27 16:23:10 2008 +0100
    17.3 @@ -17,243 +17,269 @@
    17.4  */
    17.5  #include "masqmail.h"
    17.6  
    17.7 -header_name header_names[] =
    17.8 -{
    17.9 -  { "From", HEAD_FROM, },
   17.10 -  { "Sender", HEAD_SENDER, },
   17.11 -  { "To", HEAD_TO, },
   17.12 -  { "Cc", HEAD_CC, },
   17.13 -  { "Bcc", HEAD_BCC, },
   17.14 -  { "Date", HEAD_DATE, },
   17.15 -  { "Message-Id", HEAD_MESSAGE_ID, },
   17.16 -  { "Reply-To", HEAD_REPLY_TO, },
   17.17 -  { "Subject", HEAD_SUBJECT, },
   17.18 -  { "Return-Path", HEAD_RETURN_PATH, },
   17.19 -  { "Envelope-To", HEAD_ENVELOPE_TO, },
   17.20 -  { "Received", HEAD_RECEIVED },
   17.21 +header_name header_names[] = {
   17.22 +	{"From", HEAD_FROM,}
   17.23 +	,
   17.24 +	{"Sender", HEAD_SENDER,}
   17.25 +	,
   17.26 +	{"To", HEAD_TO,}
   17.27 +	,
   17.28 +	{"Cc", HEAD_CC,}
   17.29 +	,
   17.30 +	{"Bcc", HEAD_BCC,}
   17.31 +	,
   17.32 +	{"Date", HEAD_DATE,}
   17.33 +	,
   17.34 +	{"Message-Id", HEAD_MESSAGE_ID,}
   17.35 +	,
   17.36 +	{"Reply-To", HEAD_REPLY_TO,}
   17.37 +	,
   17.38 +	{"Subject", HEAD_SUBJECT,}
   17.39 +	,
   17.40 +	{"Return-Path", HEAD_RETURN_PATH,}
   17.41 +	,
   17.42 +	{"Envelope-To", HEAD_ENVELOPE_TO,}
   17.43 +	,
   17.44 +	{"Received", HEAD_RECEIVED}
   17.45 +	,
   17.46  };
   17.47  
   17.48  /* this was borrowed from exim and slightly changed */
   17.49 -gchar *rec_timestamp()
   17.50 +gchar*
   17.51 +rec_timestamp()
   17.52  {
   17.53 -  static gchar buf[64];
   17.54 -  int len;
   17.55 -  
   17.56 -  time_t now = time(NULL);
   17.57 -  struct tm *t = localtime(&now);
   17.58 +	static gchar buf[64];
   17.59 +	int len;
   17.60  
   17.61 -  int diff_hour, diff_min;
   17.62 -  struct tm local;
   17.63 -  struct tm *gmt;
   17.64 +	time_t now = time(NULL);
   17.65 +	struct tm *t = localtime(&now);
   17.66  
   17.67 -  memcpy(&local, t, sizeof(struct tm));
   17.68 -  gmt = gmtime(&now);
   17.69 -  diff_min = 60*(local.tm_hour - gmt->tm_hour) + local.tm_min - gmt->tm_min;
   17.70 -  if (local.tm_year != gmt->tm_year)
   17.71 -    diff_min += (local.tm_year > gmt->tm_year)? 1440 : -1440;
   17.72 -  else if (local.tm_yday != gmt->tm_yday)
   17.73 -    diff_min += (local.tm_yday > gmt->tm_yday)? 1440 : -1440;
   17.74 -  diff_hour = diff_min/60;
   17.75 -  diff_min  = abs(diff_min - diff_hour*60);
   17.76 +	int diff_hour, diff_min;
   17.77 +	struct tm local;
   17.78 +	struct tm *gmt;
   17.79  
   17.80 -  len = strftime(buf, sizeof(buf), "%a, ", &local);
   17.81 -  g_snprintf(buf + len, sizeof(buf) - len, "%02d ", local.tm_mday);
   17.82 -  len += strlen(buf + len);
   17.83 -  len += strftime(buf + len, sizeof(buf) - len, "%b %Y %H:%M:%S", &local);
   17.84 -  g_snprintf(buf + len, sizeof(buf) - len, " %+03d%02d", diff_hour, diff_min);
   17.85 +	memcpy(&local, t, sizeof(struct tm));
   17.86 +	gmt = gmtime(&now);
   17.87 +	diff_min = 60 * (local.tm_hour - gmt->tm_hour) + local.tm_min - gmt->tm_min;
   17.88 +	if (local.tm_year != gmt->tm_year)
   17.89 +		diff_min += (local.tm_year > gmt->tm_year) ? 1440 : -1440;
   17.90 +	else if (local.tm_yday != gmt->tm_yday)
   17.91 +		diff_min += (local.tm_yday > gmt->tm_yday) ? 1440 : -1440;
   17.92 +	diff_hour = diff_min / 60;
   17.93 +	diff_min = abs(diff_min - diff_hour * 60);
   17.94  
   17.95 -  return buf;
   17.96 +	len = strftime(buf, sizeof(buf), "%a, ", &local);
   17.97 +	g_snprintf(buf + len, sizeof(buf) - len, "%02d ", local.tm_mday);
   17.98 +	len += strlen(buf + len);
   17.99 +	len += strftime(buf + len, sizeof(buf) - len, "%b %Y %H:%M:%S", &local);
  17.100 +	g_snprintf(buf + len, sizeof(buf) - len, " %+03d%02d", diff_hour, diff_min);
  17.101 +
  17.102 +	return buf;
  17.103  }
  17.104  
  17.105  /* finds list of headers matching id
  17.106     if id == HEAD_UNKNOWN and header == NULL finds all unknown headers
  17.107     else finds all headers matching header
  17.108  */
  17.109 -GList *find_header(GList *hdr_list, header_id id, gchar *hdr_str)
  17.110 +GList*
  17.111 +find_header(GList * hdr_list, header_id id, gchar * hdr_str)
  17.112  {
  17.113 -  GList *found_list = NULL;
  17.114 -  GList *node;
  17.115 +	GList *found_list = NULL;
  17.116 +	GList *node;
  17.117  
  17.118 -  if((id != HEAD_UNKNOWN) || (hdr_str == NULL)){
  17.119 -    foreach(hdr_list, node){
  17.120 -      header *hdr = (header *)(node->data);
  17.121 -      if(hdr->id == id)
  17.122 -        found_list = g_list_append(found_list, hdr);
  17.123 -    }
  17.124 -  }else{
  17.125 -    foreach(hdr_list, node){
  17.126 -      header *hdr = (header *)(node->data);
  17.127 -      gchar buf[64], *q = buf, *p = hdr->header;
  17.128 -      
  17.129 -      while(*p != ':' && q < buf+63 && *p) *(q++) = *(p++);
  17.130 -      *q = 0;
  17.131 -      
  17.132 -      if(strcasecmp(buf, hdr_str) == 0)
  17.133 -        found_list = g_list_append(found_list, hdr);
  17.134 -    }
  17.135 -  }
  17.136 -  return found_list;
  17.137 +	if ((id != HEAD_UNKNOWN) || (hdr_str == NULL)) {
  17.138 +		foreach(hdr_list, node) {
  17.139 +			header *hdr = (header *) (node->data);
  17.140 +			if (hdr->id == id)
  17.141 +				found_list = g_list_append(found_list, hdr);
  17.142 +		}
  17.143 +	} else {
  17.144 +		foreach(hdr_list, node) {
  17.145 +			header *hdr = (header *) (node->data);
  17.146 +			gchar buf[64], *q = buf, *p = hdr->header;
  17.147 +
  17.148 +			while (*p != ':' && q < buf + 63 && *p)
  17.149 +				*(q++) = *(p++);
  17.150 +			*q = 0;
  17.151 +
  17.152 +			if (strcasecmp(buf, hdr_str) == 0)
  17.153 +				found_list = g_list_append(found_list, hdr);
  17.154 +		}
  17.155 +	}
  17.156 +	return found_list;
  17.157  }
  17.158  
  17.159 -void header_unfold(header *hdr)
  17.160 +void
  17.161 +header_unfold(header * hdr)
  17.162  {
  17.163 -  gchar *tmp_hdr = g_malloc(strlen(hdr->header));
  17.164 -  gchar *p = hdr->header, *q = tmp_hdr;
  17.165 -  gboolean flag = FALSE;
  17.166 +	gchar *tmp_hdr = g_malloc(strlen(hdr->header));
  17.167 +	gchar *p = hdr->header, *q = tmp_hdr;
  17.168 +	gboolean flag = FALSE;
  17.169  
  17.170 -  while(*p){
  17.171 -    if(*p != '\n')
  17.172 -      *(q++) = *p;
  17.173 -    else
  17.174 -      flag = TRUE;
  17.175 -    p++;
  17.176 -  }
  17.177 -  *(q++) = '\n';
  17.178 +	while (*p) {
  17.179 +		if (*p != '\n')
  17.180 +			*(q++) = *p;
  17.181 +		else
  17.182 +			flag = TRUE;
  17.183 +		p++;
  17.184 +	}
  17.185 +	*(q++) = '\n';
  17.186  
  17.187 -  if(flag){
  17.188 -    gchar *new_hdr;
  17.189 +	if (flag) {
  17.190 +		gchar *new_hdr;
  17.191  
  17.192 -    g_free(hdr->header);
  17.193 -    new_hdr = g_strdup(tmp_hdr);
  17.194 -    g_free(tmp_hdr);
  17.195 -    hdr->value = new_hdr + (hdr->value - hdr->header);
  17.196 -    hdr->header = new_hdr;
  17.197 -  }
  17.198 +		g_free(hdr->header);
  17.199 +		new_hdr = g_strdup(tmp_hdr);
  17.200 +		g_free(tmp_hdr);
  17.201 +		hdr->value = new_hdr + (hdr->value - hdr->header);
  17.202 +		hdr->header = new_hdr;
  17.203 +	}
  17.204  }
  17.205  
  17.206  #define MAX_HDR_LEN 72
  17.207 -void header_fold(header *hdr)
  17.208 +void
  17.209 +header_fold(header * hdr)
  17.210  {
  17.211 -  gint len = strlen(hdr->header);
  17.212 -  gchar *p, *q;
  17.213 -  /* size is probably overestimated, but so we are on the safe side */
  17.214 -  gchar *tmp_hdr = g_malloc(len + 2*len/MAX_HDR_LEN);
  17.215 +	gint len = strlen(hdr->header);
  17.216 +	gchar *p, *q;
  17.217 +	/* size is probably overestimated, but so we are on the safe side */
  17.218 +	gchar *tmp_hdr = g_malloc(len + 2 * len / MAX_HDR_LEN);
  17.219  
  17.220 -  p = hdr->header;
  17.221 -  q = tmp_hdr;
  17.222 +	p = hdr->header;
  17.223 +	q = tmp_hdr;
  17.224  
  17.225 -  if(p[len-1] == '\n')
  17.226 -    p[len-1] = 0;
  17.227 +	if (p[len - 1] == '\n')
  17.228 +		p[len - 1] = 0;
  17.229  
  17.230 -  while(*p){
  17.231 -    gint i,l;
  17.232 -    gchar *pp;
  17.233 -    
  17.234 -    /* look forward and find potential break points */
  17.235 -    i = 0; l = -1;
  17.236 -    pp = p;
  17.237 -    while(*pp && (i < MAX_HDR_LEN)){
  17.238 -      if((*pp == ' ') || (*pp == '\t'))
  17.239 -	l = i;
  17.240 -      pp++;
  17.241 -      i++;
  17.242 -    }
  17.243 -    if(!*pp) l = pp-p; /* take rest, if EOS found */
  17.244 +	while (*p) {
  17.245 +		gint i, l;
  17.246 +		gchar *pp;
  17.247  
  17.248 -    if(l == -1){
  17.249 -      /* no potential break point was found within MAX_HDR_LEN
  17.250 -       so advance further until the next */
  17.251 -      while(*pp && *pp != ' ' && *pp != '\t'){
  17.252 -	pp++;
  17.253 -	i++;
  17.254 -      }
  17.255 -      l = i;
  17.256 -    }
  17.257 +		/* look forward and find potential break points */
  17.258 +		i = 0;
  17.259 +		l = -1;
  17.260 +		pp = p;
  17.261 +		while (*pp && (i < MAX_HDR_LEN)) {
  17.262 +			if ((*pp == ' ') || (*pp == '\t'))
  17.263 +				l = i;
  17.264 +			pp++;
  17.265 +			i++;
  17.266 +		}
  17.267 +		if (!*pp)
  17.268 +			l = pp - p;  /* take rest, if EOS found */
  17.269  
  17.270 -    /* copy */
  17.271 -    i = 0;
  17.272 -    while(i < l){
  17.273 -      *(q++) = *(p++);
  17.274 -      i++;
  17.275 -    }
  17.276 -    *(q++) = '\n';
  17.277 -    *(q++) = *(p++); /* this is either space, tab or 0 */
  17.278 -  }
  17.279 -  {
  17.280 -    gchar *new_hdr;
  17.281 -    
  17.282 -    g_free(hdr->header);
  17.283 -    new_hdr = g_strdup(tmp_hdr);
  17.284 -    g_free(tmp_hdr);
  17.285 -    hdr->value = new_hdr + (hdr->value - hdr->header);
  17.286 -    hdr->header = new_hdr;
  17.287 -  }
  17.288 +		if (l == -1) {
  17.289 +			/* no potential break point was found within MAX_HDR_LEN so advance further until the next */
  17.290 +			while (*pp && *pp != ' ' && *pp != '\t') {
  17.291 +				pp++;
  17.292 +				i++;
  17.293 +			}
  17.294 +			l = i;
  17.295 +		}
  17.296 +
  17.297 +		/* copy */
  17.298 +		i = 0;
  17.299 +		while (i < l) {
  17.300 +			*(q++) = *(p++);
  17.301 +			i++;
  17.302 +		}
  17.303 +		*(q++) = '\n';
  17.304 +		*(q++) = *(p++);		/* this is either space, tab or 0 */
  17.305 +	}
  17.306 +	{
  17.307 +		gchar *new_hdr;
  17.308 +
  17.309 +		g_free(hdr->header);
  17.310 +		new_hdr = g_strdup(tmp_hdr);
  17.311 +		g_free(tmp_hdr);
  17.312 +		hdr->value = new_hdr + (hdr->value - hdr->header);
  17.313 +		hdr->header = new_hdr;
  17.314 +	}
  17.315  }
  17.316  
  17.317 -header *create_header(header_id id, gchar *fmt, ...)
  17.318 +header*
  17.319 +create_header(header_id id, gchar * fmt, ...)
  17.320  {
  17.321 -  gchar *p;
  17.322 -  header *hdr;
  17.323 -  va_list args;
  17.324 -  va_start(args, fmt);
  17.325 +	gchar *p;
  17.326 +	header *hdr;
  17.327 +	va_list args;
  17.328 +	va_start(args, fmt);
  17.329  
  17.330 -  if((hdr = g_malloc(sizeof(header)))){
  17.331 +	if ((hdr = g_malloc(sizeof(header)))) {
  17.332  
  17.333 -    hdr->id = id;
  17.334 -    hdr->header = g_strdup_vprintf(fmt, args);
  17.335 -    hdr->value = NULL;
  17.336 +		hdr->id = id;
  17.337 +		hdr->header = g_strdup_vprintf(fmt, args);
  17.338 +		hdr->value = NULL;
  17.339  
  17.340 -    p = hdr->header;
  17.341 -    while(*p && *p != ':') p++;
  17.342 -    if(*p)
  17.343 -      hdr->value = p+1;
  17.344 -  }
  17.345 +		p = hdr->header;
  17.346 +		while (*p && *p != ':')
  17.347 +			p++;
  17.348 +		if (*p)
  17.349 +			hdr->value = p + 1;
  17.350 +	}
  17.351  
  17.352 -  va_end(args);
  17.353 -  return hdr;
  17.354 +	va_end(args);
  17.355 +	return hdr;
  17.356  }
  17.357  
  17.358 -void destroy_header(header *hdr)
  17.359 +void
  17.360 +destroy_header(header * hdr)
  17.361  {
  17.362 -  if(hdr){
  17.363 -    if(hdr->header) g_free(hdr->header);
  17.364 -    g_free(hdr);
  17.365 -  }
  17.366 +	if (hdr) {
  17.367 +		if (hdr->header)
  17.368 +			g_free(hdr->header);
  17.369 +		g_free(hdr);
  17.370 +	}
  17.371  }
  17.372  
  17.373 -header *copy_header(header *hdr)
  17.374 +header*
  17.375 +copy_header(header * hdr)
  17.376  {
  17.377 -  header *new_hdr = NULL;
  17.378 +	header *new_hdr = NULL;
  17.379  
  17.380 -  if(hdr){
  17.381 -    if((new_hdr = g_malloc(sizeof(header)))){
  17.382 -      new_hdr->id = hdr->id;
  17.383 -      new_hdr->header = g_strdup(hdr->header);
  17.384 -      new_hdr->value = new_hdr->header + (hdr->value - hdr->header);
  17.385 -    }
  17.386 -  }
  17.387 -  return new_hdr;
  17.388 +	if (hdr) {
  17.389 +		if ((new_hdr = g_malloc(sizeof(header)))) {
  17.390 +			new_hdr->id = hdr->id;
  17.391 +			new_hdr->header = g_strdup(hdr->header);
  17.392 +			new_hdr->value = new_hdr->header + (hdr->value - hdr->header);
  17.393 +		}
  17.394 +	}
  17.395 +	return new_hdr;
  17.396  }
  17.397  
  17.398 -header *get_header(gchar *line)
  17.399 +header*
  17.400 +get_header(gchar * line)
  17.401  {
  17.402 -  gchar *p = line;
  17.403 -  gchar buf[64], *q = buf;
  17.404 -  gint i;
  17.405 -  header *hdr;
  17.406 -  
  17.407 -  while(*p && (*p != ':') && (q < buf+63)) *(q++) = *(p++);
  17.408 -  *q = 0;
  17.409 -  
  17.410 -  if(*p != ':') return NULL;
  17.411 +	gchar *p = line;
  17.412 +	gchar buf[64], *q = buf;
  17.413 +	gint i;
  17.414 +	header *hdr;
  17.415  
  17.416 -  hdr = g_malloc(sizeof(header));
  17.417 +	while (*p && (*p != ':') && (q < buf + 63))
  17.418 +		*(q++) = *(p++);
  17.419 +	*q = 0;
  17.420  
  17.421 -  hdr->value = NULL;
  17.422 -  p++;
  17.423 +	if (*p != ':')
  17.424 +		return NULL;
  17.425  
  17.426 -  while(*p && (*p == ' ' || *p == '\t')) p++;
  17.427 -  hdr->value = p;
  17.428 +	hdr = g_malloc(sizeof(header));
  17.429  
  17.430 -  for(i = 0; i < HEAD_NUM_IDS; i++){
  17.431 -    if(strcasecmp(header_names[i].header, buf) == 0)
  17.432 -      break;
  17.433 -  }
  17.434 -  hdr->id = (header_id)i;
  17.435 -  hdr->header = g_strdup(line);
  17.436 -  hdr->value = hdr->header + (hdr->value - line);
  17.437 +	hdr->value = NULL;
  17.438 +	p++;
  17.439  
  17.440 -  DEBUG(4) debugf("header: %d = %s", hdr->id, hdr->header);
  17.441 +	while (*p && (*p == ' ' || *p == '\t'))
  17.442 +		p++;
  17.443 +	hdr->value = p;
  17.444  
  17.445 -  return hdr;
  17.446 +	for (i = 0; i < HEAD_NUM_IDS; i++) {
  17.447 +		if (strcasecmp(header_names[i].header, buf) == 0)
  17.448 +			break;
  17.449 +	}
  17.450 +	hdr->id = (header_id) i;
  17.451 +	hdr->header = g_strdup(line);
  17.452 +	hdr->value = hdr->header + (hdr->value - line);
  17.453 +
  17.454 +	DEBUG(4) debugf("header: %d = %s", hdr->id, hdr->header);
  17.455 +
  17.456 +	return hdr;
  17.457  }
    18.1 --- a/src/interface.c	Mon Oct 27 16:21:27 2008 +0100
    18.2 +++ b/src/interface.c	Mon Oct 27 16:23:10 2008 +0100
    18.3 @@ -21,79 +21,75 @@
    18.4  /* define if you get problems... */
    18.5  /*#define SOCKADDR_OLD 1*/
    18.6  
    18.7 -gboolean init_sockaddr(struct sockaddr_in *name, interface *iface)
    18.8 +gboolean
    18.9 +init_sockaddr(struct sockaddr_in * name, interface * iface)
   18.10  {
   18.11 -  struct hostent *he;
   18.12 -  struct in_addr ia;
   18.13 -  
   18.14 +	struct hostent *he;
   18.15 +	struct in_addr ia;
   18.16 +
   18.17  #ifdef SOCKADDR_OLD
   18.18 -  /* here I tried to be intelligent and failed. */
   18.19 -  if(isalpha(iface->address[0])){
   18.20 -    if ((he = gethostbyname(iface->address)) == NULL) {
   18.21 -      logwrite(LOG_ALERT,
   18.22 -	       "local address '%s' unknown. (deleting)\n",
   18.23 -	       iface->address);
   18.24 -      return FALSE;
   18.25 -    }
   18.26 -    memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr));
   18.27 -  }else if(isdigit(iface->address[0])){
   18.28 -    if(inet_aton(iface->address, &ia)){
   18.29 -      memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr));
   18.30 -    }else{
   18.31 -      logwrite(LOG_ALERT,
   18.32 -	       "invalid address '%s': inet_aton() failed (deleting)\n",
   18.33 -	       iface->address);
   18.34 -      return FALSE;
   18.35 -    }
   18.36 -  }else{
   18.37 -    logwrite(LOG_ALERT,
   18.38 -	     "invalid address '%s', should begin with a aphanumeric (deleting)\n",
   18.39 -	     iface->address);
   18.40 -    return FALSE;
   18.41 -  }
   18.42 +	/* here I tried to be intelligent and failed. */
   18.43 +	if (isalpha(iface->address[0])) {
   18.44 +		if ((he = gethostbyname(iface->address)) == NULL) {
   18.45 +			logwrite(LOG_ALERT, "local address '%s' unknown. (deleting)\n", iface->address);
   18.46 +			return FALSE;
   18.47 +		}
   18.48 +		memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr));
   18.49 +	} else if (isdigit(iface->address[0])) {
   18.50 +		if (inet_aton(iface->address, &ia)) {
   18.51 +			memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr));
   18.52 +		} else {
   18.53 +			logwrite(LOG_ALERT, "invalid address '%s': inet_aton() failed (deleting)\n", iface->address);
   18.54 +			return FALSE;
   18.55 +		}
   18.56 +	} else {
   18.57 +		logwrite(LOG_ALERT, "invalid address '%s', should begin with a aphanumeric (deleting)\n", iface->address);
   18.58 +		return FALSE;
   18.59 +	}
   18.60  #else
   18.61 -  /* this is how others to it. I follow the crowd... */
   18.62 -  if(inet_aton(iface->address, &ia) != 0){
   18.63 -    /* IP address */
   18.64 -    memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr));
   18.65 -  }else{
   18.66 -    if ((he = gethostbyname(iface->address)) == NULL) {
   18.67 -      logwrite(LOG_ALERT, "local address '%s' unknown. (deleting)\n", iface->address);
   18.68 -      return FALSE;
   18.69 -    }
   18.70 -    memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr));
   18.71 -  }
   18.72 +	/* this is how others to it. I follow the crowd... */
   18.73 +	if (inet_aton(iface->address, &ia) != 0) {
   18.74 +		/* IP address */
   18.75 +		memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr));
   18.76 +	} else {
   18.77 +		if ((he = gethostbyname(iface->address)) == NULL) {
   18.78 +			logwrite(LOG_ALERT, "local address '%s' unknown. (deleting)\n", iface->address);
   18.79 +			return FALSE;
   18.80 +		}
   18.81 +		memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr));
   18.82 +	}
   18.83  #endif
   18.84 -  name->sin_family = AF_INET;
   18.85 -  name->sin_port = htons(iface->port);
   18.86 +	name->sin_family = AF_INET;
   18.87 +	name->sin_port = htons(iface->port);
   18.88  
   18.89 -  return TRUE;
   18.90 +	return TRUE;
   18.91  }
   18.92  
   18.93 -int make_server_socket(interface *iface)
   18.94 +int
   18.95 +make_server_socket(interface * iface)
   18.96  {
   18.97 -  int sock = -1;
   18.98 -  struct sockaddr_in server;
   18.99 -        
  18.100 -  memset(&server, 0, sizeof(struct sockaddr_in));
  18.101 +	int sock = -1;
  18.102 +	struct sockaddr_in server;
  18.103  
  18.104 -  /* Create the socket. */
  18.105 -  sock = socket (PF_INET, SOCK_STREAM, 0);
  18.106 -  if (sock < 0){
  18.107 -    logwrite(LOG_ALERT, "socket: %s\n", strerror(errno));
  18.108 -    return -1;
  18.109 -  }
  18.110 -        
  18.111 -  if(init_sockaddr(&server, iface)){
  18.112 -    /* bind the socket */
  18.113 -    if (bind (sock, (struct sockaddr *) &server, sizeof (server)) < 0){
  18.114 -      logwrite(LOG_ALERT, "bind: %s\n", strerror(errno));
  18.115 -      return -1;
  18.116 -    }
  18.117 -  }else{
  18.118 -    close(sock);
  18.119 -    return -1;
  18.120 -  }
  18.121 -        
  18.122 -  return sock;
  18.123 +	memset(&server, 0, sizeof(struct sockaddr_in));
  18.124 +
  18.125 +	/* Create the socket. */
  18.126 +	sock = socket(PF_INET, SOCK_STREAM, 0);
  18.127 +	if (sock < 0) {
  18.128 +		logwrite(LOG_ALERT, "socket: %s\n", strerror(errno));
  18.129 +		return -1;
  18.130 +	}
  18.131 +
  18.132 +	if (init_sockaddr(&server, iface)) {
  18.133 +		/* bind the socket */
  18.134 +		if (bind(sock, (struct sockaddr *) &server, sizeof(server)) < 0) {
  18.135 +			logwrite(LOG_ALERT, "bind: %s\n", strerror(errno));
  18.136 +			return -1;
  18.137 +		}
  18.138 +	} else {
  18.139 +		close(sock);
  18.140 +		return -1;
  18.141 +	}
  18.142 +
  18.143 +	return sock;
  18.144  }
    19.1 --- a/src/libident/id_close.c	Mon Oct 27 16:21:27 2008 +0100
    19.2 +++ b/src/libident/id_close.c	Mon Oct 27 16:23:10 2008 +0100
    19.3 @@ -16,14 +16,13 @@
    19.4  #define IN_LIBIDENT_SRC
    19.5  #include "ident.h"
    19.6  
    19.7 -int id_close __P1(ident_t *, id)
    19.8 +int
    19.9 +id_close __P1(ident_t *, id)
   19.10  {
   19.11 -    int res;
   19.12 -  
   19.13 -    res = close(id->fd);
   19.14 -    free(id);
   19.15 -    
   19.16 -    return res;
   19.17 +	int res;
   19.18 +
   19.19 +	res = close(id->fd);
   19.20 +	free(id);
   19.21 +
   19.22 +	return res;
   19.23  }
   19.24 -
   19.25 -
    20.1 --- a/src/libident/id_open.c	Mon Oct 27 16:21:27 2008 +0100
    20.2 +++ b/src/libident/id_open.c	Mon Oct 27 16:23:10 2008 +0100
    20.3 @@ -39,129 +39,120 @@
    20.4  
    20.5  
    20.6  /*
    20.7 -ident_t *id_open __P3(struct in_addr *, laddr,
    20.8 -		      struct in_addr *, faddr,
    20.9 -		      struct timeval *, timeout)
   20.10 +ident_t *id_open __P3(struct in_addr *, laddr, struct in_addr *, faddr, struct timeval *, timeout)
   20.11  */
   20.12  
   20.13 -ident_t *id_open __P((	__STRUCT_IN_ADDR_P laddr,
   20.14 -			__STRUCT_IN_ADDR_P faddr,
   20.15 -			__STRUCT_TIMEVAL_P timeout))
   20.16 +ident_t*
   20.17 +id_open __P((__STRUCT_IN_ADDR_P laddr, __STRUCT_IN_ADDR_P faddr, __STRUCT_TIMEVAL_P timeout))
   20.18  {
   20.19 -    ident_t *id;
   20.20 -    int res, tmperrno;
   20.21 -    struct sockaddr_in sin_laddr, sin_faddr;
   20.22 -    fd_set rs, ws, es;
   20.23 +	ident_t *id;
   20.24 +	int res, tmperrno;
   20.25 +	struct sockaddr_in sin_laddr, sin_faddr;
   20.26 +	fd_set rs, ws, es;
   20.27  #ifndef OLD_SETSOCKOPT
   20.28 -    int on = 1;
   20.29 -    struct linger linger;
   20.30 +	int on = 1;
   20.31 +	struct linger linger;
   20.32  #endif
   20.33 -    
   20.34 -    if ((id = (ident_t *) malloc(sizeof(*id))) == 0)
   20.35 -	return 0;
   20.36 -    
   20.37 -    if ((id->fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
   20.38 -    {
   20.39 -	free(id);
   20.40 -	return 0;
   20.41 -    }
   20.42 -    
   20.43 -    if (timeout)
   20.44 -    {
   20.45 -	if ((res = fcntl(id->fd, F_GETFL, 0)) < 0)
   20.46 -	    goto ERROR;
   20.47 +
   20.48 +	if ((id = (ident_t *) malloc(sizeof(*id))) == 0)
   20.49 +		return 0;
   20.50 +
   20.51 +	if ((id->fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
   20.52 +		free(id);
   20.53 +		return 0;
   20.54 +	}
   20.55 +
   20.56 +	if (timeout) {
   20.57 +		if ((res = fcntl(id->fd, F_GETFL, 0)) < 0)
   20.58 +			goto ERROR;
   20.59  
   20.60  #ifndef VMS
   20.61 -	if (fcntl(id->fd, F_SETFL, res | FNDELAY) < 0)
   20.62 -	    goto ERROR;
   20.63 +		if (fcntl(id->fd, F_SETFL, res | FNDELAY) < 0)
   20.64 +			goto ERROR;
   20.65  #endif
   20.66 -    }
   20.67 +	}
   20.68  
   20.69 -    /* We silently ignore errors if we can't change LINGER */
   20.70 +	/* We silently ignore errors if we can't change LINGER */
   20.71  #ifdef OLD_SETSOCKOPT
   20.72 -    /* Old style setsockopt() */
   20.73 -    (void) setsockopt(id->fd, SOL_SOCKET, SO_DONTLINGER);
   20.74 -    (void) setsockopt(id->fd, SOL_SOCKET, SO_REUSEADDR);
   20.75 +	/* Old style setsockopt() */
   20.76 +	(void) setsockopt(id->fd, SOL_SOCKET, SO_DONTLINGER);
   20.77 +	(void) setsockopt(id->fd, SOL_SOCKET, SO_REUSEADDR);
   20.78  #else
   20.79 -    /* New style setsockopt() */
   20.80 -    linger.l_onoff = 0;
   20.81 -    linger.l_linger = 0;
   20.82 -    
   20.83 -    (void) setsockopt(id->fd, SOL_SOCKET, SO_LINGER, (void *) &linger, sizeof(linger));
   20.84 -    (void) setsockopt(id->fd, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on));
   20.85 +	/* New style setsockopt() */
   20.86 +	linger.l_onoff = 0;
   20.87 +	linger.l_linger = 0;
   20.88 +
   20.89 +	(void) setsockopt(id->fd, SOL_SOCKET, SO_LINGER, (void *) &linger, sizeof(linger));
   20.90 +	(void) setsockopt(id->fd, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on));
   20.91  #endif
   20.92 -    
   20.93 -    id->buf[0] = '\0';
   20.94 -    
   20.95 -    bzero((char *)&sin_laddr, sizeof(sin_laddr));
   20.96 -    sin_laddr.sin_family = AF_INET;
   20.97 -    sin_laddr.sin_addr = *laddr;
   20.98 -    sin_laddr.sin_port = 0;
   20.99 -    
  20.100 -    if (bind(id->fd, (struct sockaddr *) &sin_laddr, sizeof(sin_laddr)) < 0)
  20.101 -    {
  20.102 +
  20.103 +	id->buf[0] = '\0';
  20.104 +
  20.105 +	bzero((char *) &sin_laddr, sizeof(sin_laddr));
  20.106 +	sin_laddr.sin_family = AF_INET;
  20.107 +	sin_laddr.sin_addr = *laddr;
  20.108 +	sin_laddr.sin_port = 0;
  20.109 +
  20.110 +	if (bind(id->fd, (struct sockaddr *) &sin_laddr, sizeof(sin_laddr)) < 0) {
  20.111  #ifdef DEBUG
  20.112 -	perror("libident: bind");
  20.113 +		perror("libident: bind");
  20.114  #endif
  20.115 -	goto ERROR;
  20.116 -    }
  20.117 -    
  20.118 -    bzero((char *)&sin_faddr, sizeof(sin_faddr));
  20.119 -    sin_faddr.sin_family = AF_INET;
  20.120 -    sin_faddr.sin_addr = *faddr;
  20.121 -    sin_faddr.sin_port = htons(IDPORT);
  20.122 +		goto ERROR;
  20.123 +	}
  20.124  
  20.125 -    errno = 0;
  20.126 -    res = connect(id->fd, (struct sockaddr *) &sin_faddr, sizeof(sin_faddr));
  20.127 -    if (res < 0 && errno != EINPROGRESS)
  20.128 -    {
  20.129 +	bzero((char *) &sin_faddr, sizeof(sin_faddr));
  20.130 +	sin_faddr.sin_family = AF_INET;
  20.131 +	sin_faddr.sin_addr = *faddr;
  20.132 +	sin_faddr.sin_port = htons(IDPORT);
  20.133 +
  20.134 +	errno = 0;
  20.135 +	res = connect(id->fd, (struct sockaddr *) &sin_faddr, sizeof(sin_faddr));
  20.136 +	if (res < 0 && errno != EINPROGRESS) {
  20.137  #ifdef DEBUG
  20.138 -	perror("libident: connect");
  20.139 +		perror("libident: connect");
  20.140  #endif
  20.141 -	goto ERROR;
  20.142 -    }
  20.143 +		goto ERROR;
  20.144 +	}
  20.145  
  20.146 -    if (timeout)
  20.147 -    {
  20.148 -	FD_ZERO(&rs);
  20.149 -	FD_ZERO(&ws);
  20.150 -	FD_ZERO(&es);
  20.151 -	
  20.152 -	FD_SET(id->fd, &rs);
  20.153 -	FD_SET(id->fd, &ws);
  20.154 -	FD_SET(id->fd, &es);
  20.155 +	if (timeout) {
  20.156 +		FD_ZERO(&rs);
  20.157 +		FD_ZERO(&ws);
  20.158 +		FD_ZERO(&es);
  20.159 +
  20.160 +		FD_SET(id->fd, &rs);
  20.161 +		FD_SET(id->fd, &ws);
  20.162 +		FD_SET(id->fd, &es);
  20.163  
  20.164  #ifdef __hpux
  20.165 -	if ((res = select(FD_SETSIZE, (int *) &rs, (int *) &ws, (int *) &es, timeout)) < 0)
  20.166 +		if ((res = select(FD_SETSIZE, (int *) &rs, (int *) &ws, (int *) &es, timeout)) < 0)
  20.167  #else
  20.168 -	if ((res = select(FD_SETSIZE, &rs, &ws, &es, timeout)) < 0)
  20.169 +		if ((res = select(FD_SETSIZE, &rs, &ws, &es, timeout)) < 0)
  20.170  #endif
  20.171 -	{
  20.172 +		{
  20.173  #ifdef DEBUG
  20.174 -	    perror("libident: select");
  20.175 +			perror("libident: select");
  20.176  #endif
  20.177 -	    goto ERROR;
  20.178 +			goto ERROR;
  20.179 +		}
  20.180 +
  20.181 +		if (res == 0) {
  20.182 +			errno = ETIMEDOUT;
  20.183 +			goto ERROR;
  20.184 +		}
  20.185 +
  20.186 +		if (FD_ISSET(id->fd, &es))
  20.187 +			goto ERROR;
  20.188 +
  20.189 +		if (!FD_ISSET(id->fd, &rs) && !FD_ISSET(id->fd, &ws))
  20.190 +			goto ERROR;
  20.191  	}
  20.192 -	
  20.193 -	if (res == 0)
  20.194 -	{
  20.195 -	    errno = ETIMEDOUT;
  20.196 -	    goto ERROR;
  20.197 -	}
  20.198 -	
  20.199 -	if (FD_ISSET(id->fd, &es))
  20.200 -	    goto ERROR;
  20.201 -	
  20.202 -	if (!FD_ISSET(id->fd, &rs) && !FD_ISSET(id->fd, &ws))
  20.203 -	    goto ERROR;
  20.204 -    }
  20.205 -    
  20.206 -    return id;
  20.207 -    
  20.208 +
  20.209 +	return id;
  20.210 +
  20.211    ERROR:
  20.212 -    tmperrno = errno;		/* Save, so close() won't erase it */
  20.213 -    close(id->fd);
  20.214 -    free(id);
  20.215 -    errno = tmperrno;
  20.216 -    return 0;
  20.217 +	tmperrno = errno;  /* Save, so close() won't erase it */
  20.218 +	close(id->fd);
  20.219 +	free(id);
  20.220 +	errno = tmperrno;
  20.221 +	return 0;
  20.222  }
    21.1 --- a/src/libident/id_parse.c	Mon Oct 27 16:21:27 2008 +0100
    21.2 +++ b/src/libident/id_parse.c	Mon Oct 27 16:23:10 2008 +0100
    21.3 @@ -32,198 +32,184 @@
    21.4  #  include <sys/select.h>
    21.5  #endif
    21.6  #ifdef VMS
    21.7 -#  include <sys/socket.h>     /* for fd_set */
    21.8 +#  include <sys/socket.h>  /* for fd_set */
    21.9  #endif
   21.10  #define IN_LIBIDENT_SRC
   21.11  #include "ident.h"
   21.12  
   21.13  
   21.14  /*
   21.15 -int id_parse __P7(ident_t *, id,
   21.16 -		  struct timeval *, timeout,
   21.17 -		  int *, lport,
   21.18 -		  int *, fport,
   21.19 -		  char **, identifier,
   21.20 -		  char **, opsys,
   21.21 -		  char **, charset)
   21.22 +int
   21.23 +id_parse __P7(ident_t *, id,
   21.24 +              struct timeval *, timeout,
   21.25 +              int *, lport,
   21.26 +              int *, fport,
   21.27 +              char **, identifier,
   21.28 +              char **, opsys,
   21.29 +              char **, charset)
   21.30  */
   21.31  
   21.32 -int id_parse __P((  ident_t *id,               
   21.33 -                    __STRUCT_TIMEVAL_P timeout,
   21.34 -                    int *lport,                
   21.35 -                    int *fport,                
   21.36 -                    char **identifier,         
   21.37 -                    char **opsys,              
   21.38 -                    char **charset))           
   21.39 +int
   21.40 +id_parse __P((ident_t * id,
   21.41 +            __STRUCT_TIMEVAL_P timeout,
   21.42 +            int *lport,
   21.43 +            int *fport,
   21.44 +            char **identifier,
   21.45 +            char **opsys,
   21.46 +            char **charset))
   21.47  {
   21.48 -    char c, *cp, *tmp_charset;
   21.49 -    fd_set rs;
   21.50 -    int pos, res=0, lp, fp;
   21.51 -    
   21.52 -    errno = 0;
   21.53 -    
   21.54 -    tmp_charset = 0;
   21.55 -    
   21.56 -    if (!id)
   21.57 -	return -1;
   21.58 -    if (lport)
   21.59 -	*lport = 0;
   21.60 -    if (fport)
   21.61 -	*fport = 0;
   21.62 -    if (identifier)
   21.63 -	*identifier = 0;
   21.64 -    if (opsys)
   21.65 -	*opsys = 0;
   21.66 -    if (charset)
   21.67 -	*charset = 0;
   21.68 -    
   21.69 -    pos = strlen(id->buf);
   21.70 -    
   21.71 -    if (timeout)
   21.72 -    {
   21.73 -	FD_ZERO(&rs);
   21.74 -	FD_SET(id->fd, &rs);
   21.75 +	char c, *cp, *tmp_charset;
   21.76 +	fd_set rs;
   21.77 +	int pos, res = 0, lp, fp;
   21.78 +
   21.79 +	errno = 0;
   21.80 +
   21.81 +	tmp_charset = 0;
   21.82 +
   21.83 +	if (!id)
   21.84 +		return -1;
   21.85 +	if (lport)
   21.86 +		*lport = 0;
   21.87 +	if (fport)
   21.88 +		*fport = 0;
   21.89 +	if (identifier)
   21.90 +		*identifier = 0;
   21.91 +	if (opsys)
   21.92 +		*opsys = 0;
   21.93 +	if (charset)
   21.94 +		*charset = 0;
   21.95 +
   21.96 +	pos = strlen(id->buf);
   21.97 +
   21.98 +	if (timeout) {
   21.99 +		FD_ZERO(&rs);
  21.100 +		FD_SET(id->fd, &rs);
  21.101  
  21.102  #ifdef __hpux
  21.103 -	if ((res = select(FD_SETSIZE, (int *) &rs, (int *)0, (int *)0, timeout)) < 0)
  21.104 +		if ((res = select(FD_SETSIZE, (int *) &rs, (int *) 0, (int *) 0, timeout)) < 0)
  21.105  #else
  21.106 -	if ((res = select(FD_SETSIZE, &rs, (fd_set *)0, (fd_set *)0, timeout)) < 0)
  21.107 +		if ((res = select(FD_SETSIZE, &rs, (fd_set *) 0, (fd_set *) 0, timeout)) < 0)
  21.108  #endif
  21.109 -	    return -1;
  21.110 -	
  21.111 -	if (res == 0)
  21.112 -	{
  21.113 -	    errno = ETIMEDOUT;
  21.114 -	    return -1;
  21.115 +			return -1;
  21.116 +
  21.117 +		if (res == 0) {
  21.118 +			errno = ETIMEDOUT;
  21.119 +			return -1;
  21.120 +		}
  21.121  	}
  21.122 -    }
  21.123 -    
  21.124 -    /* Every octal value is allowed except 0, \n and \r */
  21.125 -    while (pos < sizeof(id->buf) &&
  21.126 -	   (res = read(id->fd, id->buf + pos, 1)) == 1 &&
  21.127 -	   id->buf[pos] != '\n' && id->buf[pos] != '\r')
  21.128 -	pos++;
  21.129 -    
  21.130 -    if (res < 0)
  21.131 -	return -1;
  21.132 -    
  21.133 -    if (res == 0)
  21.134 -    {
  21.135 -	errno = ENOTCONN;
  21.136 -	return -1;
  21.137 -    }
  21.138 -    
  21.139 -    if (id->buf[pos] != '\n' && id->buf[pos] != '\r')
  21.140 -	return 0;		/* Not properly terminated string */
  21.141 -    
  21.142 -    id->buf[pos++] = '\0';
  21.143 -    
  21.144 -    /*
  21.145 -    ** Get first field (<lport> , <fport>)
  21.146 -    */
  21.147 -    cp = id_strtok(id->buf, ":", &c);
  21.148 -    if (!cp)
  21.149 -	return -2;
  21.150 -    
  21.151 -    if (sscanf(cp, " %d , %d", &lp, &fp) != 2)
  21.152 -    {
  21.153 -	if (identifier)
  21.154 -	{
  21.155 -	    *identifier = id_strdup(cp);
  21.156 -	    if (*identifier == NULL)
  21.157 -	        return -4;
  21.158 +
  21.159 +	/* Every octal value is allowed except 0, \n and \r */
  21.160 +	while (pos < sizeof(id->buf)
  21.161 +	       && (res = read(id->fd, id->buf + pos, 1)) == 1
  21.162 +	       && id->buf[pos] != '\n' && id->buf[pos] != '\r')
  21.163 +		pos++;
  21.164 +
  21.165 +	if (res < 0)
  21.166 +		return -1;
  21.167 +
  21.168 +	if (res == 0) {
  21.169 +		errno = ENOTCONN;
  21.170 +		return -1;
  21.171  	}
  21.172 -	return -2;
  21.173 -    }
  21.174 -    
  21.175 -    if (lport)
  21.176 -	*lport = lp;
  21.177 -    if (fport)
  21.178 -	*fport = fp;
  21.179 -    
  21.180 -    /*
  21.181 -    ** Get second field (USERID or ERROR)
  21.182 -    */
  21.183 -    cp = id_strtok((char *)0, ":", &c);
  21.184 -    if (!cp)
  21.185 -	return -2;
  21.186 -    
  21.187 -    if (strcmp(cp, "ERROR") == 0)
  21.188 -    {
  21.189 -	cp = id_strtok((char *)0, "\n\r", &c);
  21.190 +
  21.191 +	if (id->buf[pos] != '\n' && id->buf[pos] != '\r')
  21.192 +		return 0;  /* Not properly terminated string */
  21.193 +
  21.194 +	id->buf[pos++] = '\0';
  21.195 +
  21.196 +	/*
  21.197 +	 ** Get first field (<lport> , <fport>)
  21.198 +	 */
  21.199 +	cp = id_strtok(id->buf, ":", &c);
  21.200  	if (!cp)
  21.201 -	    return -2;
  21.202 -	
  21.203 -	if (identifier)
  21.204 -	{
  21.205 -	    *identifier = id_strdup(cp);
  21.206 -	    if (*identifier == NULL)
  21.207 -	        return -4;
  21.208 +		return -2;
  21.209 +
  21.210 +	if (sscanf(cp, " %d , %d", &lp, &fp) != 2) {
  21.211 +		if (identifier) {
  21.212 +			*identifier = id_strdup(cp);
  21.213 +			if (*identifier == NULL)
  21.214 +				return -4;
  21.215 +		}
  21.216 +		return -2;
  21.217  	}
  21.218 -	
  21.219 -	return 2;
  21.220 -    }
  21.221 -    else if (strcmp(cp, "USERID") == 0)
  21.222 -    {
  21.223 +
  21.224 +	if (lport)
  21.225 +		*lport = lp;
  21.226 +	if (fport)
  21.227 +		*fport = fp;
  21.228 +
  21.229  	/*
  21.230 -	** Get first subfield of third field <opsys>
  21.231 -	*/
  21.232 -	cp = id_strtok((char *) 0, ",:", &c);
  21.233 +	 ** Get second field (USERID or ERROR)
  21.234 +	 */
  21.235 +	cp = id_strtok((char *) 0, ":", &c);
  21.236  	if (!cp)
  21.237 -	    return -2;
  21.238 -	
  21.239 -	if (opsys)
  21.240 -	{
  21.241 -	    *opsys = id_strdup(cp);
  21.242 -	    if (*opsys == NULL)
  21.243 -	        return -4;
  21.244 +		return -2;
  21.245 +
  21.246 +	if (strcmp(cp, "ERROR") == 0) {
  21.247 +		cp = id_strtok((char *) 0, "\n\r", &c);
  21.248 +		if (!cp)
  21.249 +			return -2;
  21.250 +
  21.251 +		if (identifier) {
  21.252 +			*identifier = id_strdup(cp);
  21.253 +			if (*identifier == NULL)
  21.254 +				return -4;
  21.255 +		}
  21.256 +
  21.257 +		return 2;
  21.258 +	} else if (strcmp(cp, "USERID") == 0) {
  21.259 +		/*
  21.260 +		 ** Get first subfield of third field <opsys>
  21.261 +		 */
  21.262 +		cp = id_strtok((char *) 0, ",:", &c);
  21.263 +		if (!cp)
  21.264 +			return -2;
  21.265 +
  21.266 +		if (opsys) {
  21.267 +			*opsys = id_strdup(cp);
  21.268 +			if (*opsys == NULL)
  21.269 +				return -4;
  21.270 +		}
  21.271 +
  21.272 +		/*
  21.273 +		 ** We have a second subfield (<charset>)
  21.274 +		 */
  21.275 +		if (c == ',') {
  21.276 +			cp = id_strtok((char *) 0, ":", &c);
  21.277 +			if (!cp)
  21.278 +				return -2;
  21.279 +
  21.280 +			tmp_charset = cp;
  21.281 +			if (charset) {
  21.282 +				*charset = id_strdup(cp);
  21.283 +				if (*charset == NULL)
  21.284 +					return -4;
  21.285 +			}
  21.286 +
  21.287 +			/*
  21.288 +			 ** We have even more subfields - ignore them
  21.289 +			 */
  21.290 +			if (c == ',')
  21.291 +				id_strtok((char *) 0, ":", &c);
  21.292 +		}
  21.293 +
  21.294 +		if (tmp_charset && strcmp(tmp_charset, "OCTET") == 0)
  21.295 +			cp = id_strtok((char *) 0, (char *) 0, &c);
  21.296 +		else
  21.297 +			cp = id_strtok((char *) 0, "\n\r", &c);
  21.298 +
  21.299 +		if (identifier) {
  21.300 +			*identifier = id_strdup(cp);
  21.301 +			if (*identifier == NULL)
  21.302 +				return -4;
  21.303 +		}
  21.304 +		return 1;
  21.305 +	} else {
  21.306 +		if (identifier) {
  21.307 +			*identifier = id_strdup(cp);
  21.308 +			if (*identifier == NULL)
  21.309 +				return -4;
  21.310 +		}
  21.311 +		return -3;
  21.312  	}
  21.313 -	
  21.314 -	/*
  21.315 -	** We have a second subfield (<charset>)
  21.316 -	*/
  21.317 -	if (c == ',')
  21.318 -	{
  21.319 -	    cp = id_strtok((char *)0, ":", &c);
  21.320 -	    if (!cp)
  21.321 -		return -2;
  21.322 -	    
  21.323 -	    tmp_charset = cp;
  21.324 -	    if (charset)
  21.325 -	    {
  21.326 -		*charset = id_strdup(cp);
  21.327 -		if (*charset == NULL)
  21.328 -		    return -4;
  21.329 -	    }
  21.330 -	    
  21.331 -	    /*
  21.332 -	    ** We have even more subfields - ignore them
  21.333 -	    */
  21.334 -	    if (c == ',')
  21.335 -		id_strtok((char *)0, ":", &c);
  21.336 -	}
  21.337 -	
  21.338 -	if (tmp_charset && strcmp(tmp_charset, "OCTET") == 0)
  21.339 -	    cp = id_strtok((char *)0, (char *)0, &c);
  21.340 -	else
  21.341 -	    cp = id_strtok((char *)0, "\n\r", &c);
  21.342 -	
  21.343 -	if (identifier)
  21.344 -	{
  21.345 -	    *identifier = id_strdup(cp);
  21.346 -	    if (*identifier == NULL)
  21.347 -	        return -4;
  21.348 -	}
  21.349 -	return 1;
  21.350 -    }
  21.351 -    else
  21.352 -    {
  21.353 -	if (identifier)
  21.354 -	{
  21.355 -	    *identifier = id_strdup(cp);
  21.356 -	    if (*identifier == NULL)
  21.357 -	        return -4;
  21.358 -	}
  21.359 -	return -3;
  21.360 -    }
  21.361  }
    22.1 --- a/src/libident/id_query.c	Mon Oct 27 16:21:27 2008 +0100
    22.2 +++ b/src/libident/id_query.c	Mon Oct 27 16:23:10 2008 +0100
    22.3 @@ -30,59 +30,53 @@
    22.4  #  include <sys/select.h>
    22.5  #endif
    22.6  #ifdef VMS
    22.7 -#  include <sys/socket.h>     /* for fd_set */
    22.8 +#  include <sys/socket.h>  /* for fd_set */
    22.9  #endif
   22.10  #define IN_LIBIDENT_SRC
   22.11  #include "ident.h"
   22.12  
   22.13  
   22.14  /*
   22.15 -int id_query __P4(ident_t *, id,
   22.16 -		  int, lport,
   22.17 -		  int, fport,
   22.18 -		  struct timeval *, timeout)
   22.19 +int
   22.20 +id_query __P4(ident_t *, id, int, lport, int, fport, struct timeval *, timeout)
   22.21  */
   22.22  
   22.23 -int    id_query __P((	ident_t *id,                 
   22.24 -			int lport,                   
   22.25 -			int fport,                   
   22.26 -			__STRUCT_TIMEVAL_P timeout))
   22.27 +int
   22.28 +id_query __P((ident_t * id, int lport, int fport, __STRUCT_TIMEVAL_P timeout))
   22.29  {
   22.30  #ifdef SIGRETURNTYPE
   22.31 -    SIGRETURNTYPE (*old_sig)();
   22.32 +	SIGRETURNTYPE(*old_sig) ();
   22.33  #else
   22.34 -    void (*old_sig) __P((int));
   22.35 +	void (*old_sig) __P((int));
   22.36  #endif
   22.37 -    int res;
   22.38 -    char buf[80];
   22.39 -    fd_set ws;
   22.40 -    
   22.41 -    sprintf(buf, "%d , %d\r\n", lport, fport);
   22.42 -    
   22.43 -    if (timeout)
   22.44 -    {
   22.45 -	FD_ZERO(&ws);
   22.46 -	FD_SET(id->fd, &ws);
   22.47 +	int res;
   22.48 +	char buf[80];
   22.49 +	fd_set ws;
   22.50 +
   22.51 +	sprintf(buf, "%d , %d\r\n", lport, fport);
   22.52 +
   22.53 +	if (timeout) {
   22.54 +		FD_ZERO(&ws);
   22.55 +		FD_SET(id->fd, &ws);
   22.56  
   22.57  #ifdef __hpux
   22.58 -	if ((res = select(FD_SETSIZE, (int *)0, (int *)&ws, (int *)0, timeout)) < 0)
   22.59 +		if ((res = select(FD_SETSIZE, (int *) 0, (int *) &ws, (int *) 0, timeout)) < 0)
   22.60  #else
   22.61 -	if ((res = select(FD_SETSIZE, (fd_set *)0, &ws, (fd_set *)0, timeout)) < 0)
   22.62 +		if ((res = select(FD_SETSIZE, (fd_set *) 0, &ws, (fd_set *) 0, timeout)) < 0)
   22.63  #endif
   22.64 -	    return -1;
   22.65 -	
   22.66 -	if (res == 0)
   22.67 -	{
   22.68 -	    errno = ETIMEDOUT;
   22.69 -	    return -1;
   22.70 +			return -1;
   22.71 +
   22.72 +		if (res == 0) {
   22.73 +			errno = ETIMEDOUT;
   22.74 +			return -1;
   22.75 +		}
   22.76  	}
   22.77 -    }
   22.78  
   22.79 -    old_sig = signal(SIGPIPE, SIG_IGN);
   22.80 -    
   22.81 -    res = write(id->fd, buf, strlen(buf));
   22.82 -    
   22.83 -    signal(SIGPIPE, old_sig);
   22.84 -    
   22.85 -    return res;
   22.86 +	old_sig = signal(SIGPIPE, SIG_IGN);
   22.87 +
   22.88 +	res = write(id->fd, buf, strlen(buf));
   22.89 +
   22.90 +	signal(SIGPIPE, old_sig);
   22.91 +
   22.92 +	return res;
   22.93  }
    23.1 --- a/src/libident/ident.c	Mon Oct 27 16:21:27 2008 +0100
    23.2 +++ b/src/libident/ident.c	Mon Oct 27 16:23:10 2008 +0100
    23.3 @@ -1,5 +1,5 @@
    23.4  /*
    23.5 -** ident.c	High-level calls to the ident lib
    23.6 +** ident.c  High-level calls to the ident lib
    23.7  **
    23.8  ** Author: Pär Emanuelsson <pell@lysator.liu.se>
    23.9  ** Hacked by: Peter Eriksson <pen@lysator.liu.se>
   23.10 @@ -31,125 +31,106 @@
   23.11  
   23.12  /* Do a complete ident query and return result */
   23.13  
   23.14 -IDENT *ident_lookup __P2(int, fd,
   23.15 -			 int, timeout)
   23.16 +IDENT*
   23.17 +ident_lookup __P2(int, fd, int, timeout)
   23.18  {
   23.19 -    struct sockaddr_in localaddr, remoteaddr;
   23.20 -    int len;
   23.21 -    
   23.22 -    len = sizeof(remoteaddr);
   23.23 -    if (getpeername(fd, (struct sockaddr*) &remoteaddr, &len) < 0)
   23.24 -	return 0;
   23.25 -    
   23.26 -    len = sizeof(localaddr);
   23.27 -    if (getsockname(fd, (struct sockaddr *) &localaddr, &len) < 0)
   23.28 -	return 0;
   23.29 +	struct sockaddr_in localaddr, remoteaddr;
   23.30 +	int len;
   23.31  
   23.32 -    return ident_query( &localaddr.sin_addr, &remoteaddr.sin_addr,
   23.33 -		       ntohs(localaddr.sin_port), ntohs(remoteaddr.sin_port),
   23.34 -		       timeout);
   23.35 +	len = sizeof(remoteaddr);
   23.36 +	if (getpeername(fd, (struct sockaddr *) &remoteaddr, &len) < 0)
   23.37 +		return 0;
   23.38 +
   23.39 +	len = sizeof(localaddr);
   23.40 +	if (getsockname(fd, (struct sockaddr *) &localaddr, &len) < 0)
   23.41 +		return 0;
   23.42 +
   23.43 +	return ident_query(&localaddr.sin_addr, &remoteaddr.sin_addr, ntohs(localaddr.sin_port), ntohs(remoteaddr.sin_port), timeout);
   23.44  }
   23.45  
   23.46  
   23.47 -IDENT *ident_query __P5(struct in_addr *, laddr,
   23.48 -			struct in_addr *, raddr,
   23.49 -			int, lport,
   23.50 -			int, rport,
   23.51 -			int, timeout)
   23.52 +IDENT*
   23.53 +ident_query __P5(struct in_addr *, laddr, struct in_addr *, raddr, int, lport, int, rport, int, timeout)
   23.54  {
   23.55 -    int res;
   23.56 -    ident_t *id;
   23.57 -    struct timeval timout;
   23.58 -    IDENT *ident=0;
   23.59 +	int res;
   23.60 +	ident_t *id;
   23.61 +	struct timeval timout;
   23.62 +	IDENT *ident = 0;
   23.63  
   23.64 -    
   23.65 -    timout.tv_sec = timeout;
   23.66 -    timout.tv_usec = 0;
   23.67 -    
   23.68 -    if (timeout)
   23.69 -	id = id_open( laddr, raddr, &timout);
   23.70 -    else
   23.71 -	id = id_open( laddr, raddr, (struct timeval *)0);
   23.72 -    
   23.73 -    if (!id)
   23.74 -    {
   23.75 -	errno = EINVAL;
   23.76 -	return 0;
   23.77 -    }
   23.78 -  
   23.79 -    if (timeout)
   23.80 -	res = id_query(id, rport, lport, &timout);
   23.81 -    else
   23.82 -	res = id_query(id, rport, lport, (struct timeval *) 0);
   23.83 -    
   23.84 -    if (res < 0)
   23.85 -    {
   23.86 +
   23.87 +	timout.tv_sec = timeout;
   23.88 +	timout.tv_usec = 0;
   23.89 +
   23.90 +	if (timeout)
   23.91 +		id = id_open(laddr, raddr, &timout);
   23.92 +	else
   23.93 +		id = id_open(laddr, raddr, (struct timeval *) 0);
   23.94 +
   23.95 +	if (!id) {
   23.96 +		errno = EINVAL;
   23.97 +		return 0;
   23.98 +	}
   23.99 +
  23.100 +	if (timeout)
  23.101 +		res = id_query(id, rport, lport, &timout);
  23.102 +	else
  23.103 +		res = id_query(id, rport, lport, (struct timeval *) 0);
  23.104 +
  23.105 +	if (res < 0) {
  23.106 +		id_close(id);
  23.107 +		return 0;
  23.108 +	}
  23.109 +
  23.110 +	ident = (IDENT *) malloc(sizeof(IDENT));
  23.111 +	if (!ident) {
  23.112 +		id_close(id);
  23.113 +		return 0;
  23.114 +	}
  23.115 +
  23.116 +	if (timeout)
  23.117 +		res = id_parse(id, &timout, &ident->lport, &ident->fport, &ident->identifier, &ident->opsys, &ident->charset);
  23.118 +	else
  23.119 +		res = id_parse(id, (struct timeval *) 0, &ident->lport, &ident->fport, &ident->identifier, &ident->opsys, &ident->charset);
  23.120 +
  23.121 +	if (res != 1) {
  23.122 +		free(ident);
  23.123 +		id_close(id);
  23.124 +		return 0;
  23.125 +	}
  23.126 +
  23.127  	id_close(id);
  23.128 -	return 0;
  23.129 -    }
  23.130 -    
  23.131 -    ident = (IDENT *) malloc(sizeof(IDENT));
  23.132 -    if (!ident) {
  23.133 -	id_close(id);
  23.134 -	return 0;
  23.135 -    }
  23.136 -    
  23.137 -    if (timeout)
  23.138 -	res = id_parse(id, &timout,
  23.139 -		       &ident->lport,
  23.140 -		       &ident->fport,
  23.141 -		       &ident->identifier,
  23.142 -		       &ident->opsys,
  23.143 -		       &ident->charset);
  23.144 -    else
  23.145 -	res = id_parse(id, (struct timeval *) 0,
  23.146 -		       &ident->lport,
  23.147 -		       &ident->fport,
  23.148 -		       &ident->identifier,
  23.149 -		       &ident->opsys,
  23.150 -		       &ident->charset);
  23.151 -    
  23.152 -    if (res != 1)
  23.153 -    {
  23.154 -	free(ident);
  23.155 -	id_close(id);
  23.156 -	return 0;
  23.157 -    }
  23.158 -    
  23.159 -    id_close(id);
  23.160 -    return ident;			/* At last! */
  23.161 +	return ident;  /* At last! */
  23.162  }
  23.163  
  23.164  
  23.165 -char *ident_id __P2(int, fd,
  23.166 -		    int, timeout)
  23.167 +char*
  23.168 +ident_id __P2(int, fd, int, timeout)
  23.169  {
  23.170 -    IDENT *ident;
  23.171 -    char *id=0;
  23.172 -    
  23.173 -    ident = ident_lookup(fd, timeout);
  23.174 -    if (ident && ident->identifier && *ident->identifier)
  23.175 -    {
  23.176 -	id = id_strdup(ident->identifier);
  23.177 -	if (id == NULL)
  23.178 -	    return NULL;
  23.179 -    }
  23.180 +	IDENT *ident;
  23.181 +	char *id = 0;
  23.182  
  23.183 -    ident_free(ident);
  23.184 -    return id;
  23.185 +	ident = ident_lookup(fd, timeout);
  23.186 +	if (ident && ident->identifier && *ident->identifier) {
  23.187 +		id = id_strdup(ident->identifier);
  23.188 +		if (id == NULL)
  23.189 +			return NULL;
  23.190 +	}
  23.191 +
  23.192 +	ident_free(ident);
  23.193 +	return id;
  23.194  }
  23.195  
  23.196  
  23.197 -void ident_free __P1(IDENT *, id)
  23.198 +void
  23.199 +ident_free __P1(IDENT *, id)
  23.200  {
  23.201 -    if (!id)
  23.202 -	return;
  23.203 -    if (id->identifier)
  23.204 -	free(id->identifier);
  23.205 -    if (id->opsys)
  23.206 -	free(id->opsys);
  23.207 -    if (id->charset)
  23.208 -	free(id->charset);
  23.209 -    free(id);
  23.210 +	if (!id)
  23.211 +		return;
  23.212 +	if (id->identifier)
  23.213 +		free(id->identifier);
  23.214 +	if (id->opsys)
  23.215 +		free(id->opsys);
  23.216 +	if (id->charset)
  23.217 +		free(id->charset);
  23.218 +	free(id);
  23.219  }
  23.220 -
    24.1 --- a/src/libident/ident.h	Mon Oct 27 16:21:27 2008 +0100
    24.2 +++ b/src/libident/ident.h	Mon Oct 27 16:23:10 2008 +0100
    24.3 @@ -8,7 +8,7 @@
    24.4  #ifndef __IDENT_H__
    24.5  #define __IDENT_H__
    24.6  
    24.7 -#ifdef	__cplusplus
    24.8 +#ifdef __cplusplus
    24.9  extern "C" {
   24.10  #endif
   24.11  
   24.12 @@ -22,21 +22,21 @@
   24.13  #ifdef __P
   24.14  #  undef __P
   24.15  #endif
   24.16 -    
   24.17 +
   24.18  #ifdef IS_STDC
   24.19 -#  define __P(AL)	                  AL
   24.20 +#  define __P(AL) AL
   24.21  
   24.22  #ifdef IN_LIBIDENT_SRC
   24.23 -    
   24.24 +
   24.25  #  define __P1(t1,a1) \
   24.26      (t1 a1)
   24.27 -    
   24.28 +
   24.29  #  define __P2(t1,a1,t2,a2) \
   24.30      (t1 a1, t2 a2)
   24.31 -	
   24.32 +
   24.33  #  define __P3(t1,a1,t2,a2,t3,a3) \
   24.34      (t1 a1, t2 a2, t3 a3)
   24.35 -	    
   24.36 +
   24.37  #  define __P4(t1,a1,t2,a2,t3,a3,t4,a4) \
   24.38      (t1 a1, t2 a2, t3 a3, t4 a4)
   24.39  
   24.40 @@ -46,13 +46,13 @@
   24.41  #  define __P7(t1,a1,t2,a2,t3,a3,t4,a4,t5,a5,t6,a6,t7,a7) \
   24.42      (t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6, t7 a7)
   24.43  #endif
   24.44 -    
   24.45 +
   24.46  #else
   24.47  
   24.48 -#  define __P(AL)	                  ()
   24.49 +#  define __P(AL) ()
   24.50  
   24.51  #ifdef IN_LIBIDENT_SRC
   24.52 -    
   24.53 +
   24.54  #  define __P1(t1,a1)                     (a1) \
   24.55      t1 a1;
   24.56  #  define __P2(t1,a1,t2,a2)               (a1, a2) \
   24.57 @@ -108,87 +108,74 @@
   24.58   * in function prototypes...
   24.59   */
   24.60  #if defined(__GNUC__) && !defined(INADDR_ANY)
   24.61 -#  define __STRUCT_IN_ADDR_P	void *
   24.62 +#  define __STRUCT_IN_ADDR_P void *
   24.63  #else
   24.64 -#  define __STRUCT_IN_ADDR_P	struct in_addr *
   24.65 +#  define __STRUCT_IN_ADDR_P struct in_addr *
   24.66  #endif
   24.67  
   24.68  #if defined(__GNUC__) && !defined(DST_NONE)
   24.69 -#  define __STRUCT_TIMEVAL_P	void *
   24.70 +#  define __STRUCT_TIMEVAL_P void *
   24.71  #else
   24.72 -#  define __STRUCT_TIMEVAL_P	struct timeval *
   24.73 +#  define __STRUCT_TIMEVAL_P struct timeval *
   24.74  #endif
   24.75  
   24.76  #if defined(__sgi) && defined(_POSIX_SOURCE)
   24.77  #  undef  __STRUCT_TIMEVAL_P
   24.78 -#  define __STRUCT_TIMEVAL_P	void *
   24.79 +#  define __STRUCT_TIMEVAL_P void *
   24.80  #endif
   24.81 -	
   24.82 +
   24.83  #ifndef IDBUFSIZE
   24.84  #  define IDBUFSIZE 2048
   24.85  #endif
   24.86  
   24.87  #ifndef IDPORT
   24.88 -#  define IDPORT	113
   24.89 +#  define IDPORT 113
   24.90  #endif
   24.91  
   24.92 -typedef struct
   24.93 -{
   24.94 -  int fd;
   24.95 -  char buf[IDBUFSIZE];
   24.96 -} ident_t;
   24.97 +	typedef struct {
   24.98 +		int fd;
   24.99 +		char buf[IDBUFSIZE];
  24.100 +	} ident_t;
  24.101  
  24.102 -typedef struct {
  24.103 -  int lport;                    /* Local port */
  24.104 -  int fport;                    /* Far (remote) port */
  24.105 -  char *identifier;             /* Normally user name */
  24.106 -  char *opsys;                  /* OS */
  24.107 -  char *charset;                /* Charset (what did you expect?) */
  24.108 -} IDENT;                        /* For higher-level routines */
  24.109 +	typedef struct {
  24.110 +		int lport;  /* Local port */
  24.111 +		int fport;  /* Far (remote) port */
  24.112 +		char *identifier;  /* Normally user name */
  24.113 +		char *opsys;  /* OS */
  24.114 +		char *charset;  /* Charset (what did you expect?) */
  24.115 +	} IDENT;  /* For higher-level routines */
  24.116  
  24.117  /* Low-level calls and macros */
  24.118 -#define id_fileno(ID)	((ID)->fd)
  24.119 +#define id_fileno(ID) ((ID)->fd)
  24.120  
  24.121 -extern ident_t * id_open __P((__STRUCT_IN_ADDR_P laddr,
  24.122 -			   __STRUCT_IN_ADDR_P faddr,
  24.123 -			   __STRUCT_TIMEVAL_P timeout));
  24.124 -  
  24.125 -extern int    id_close __P((ident_t *id));
  24.126 -  
  24.127 -extern int    id_query __P((ident_t *id,
  24.128 -			    int lport,
  24.129 -			    int fport,
  24.130 -			    __STRUCT_TIMEVAL_P timeout));
  24.131 -  
  24.132 -extern int    id_parse __P((ident_t *id,
  24.133 -			    __STRUCT_TIMEVAL_P timeout,
  24.134 -			    int *lport,
  24.135 -			    int *fport,
  24.136 -			    char **identifier,
  24.137 -			    char **opsys,
  24.138 -			    char **charset));
  24.139 -  
  24.140 +	extern ident_t *id_open __P((__STRUCT_IN_ADDR_P laddr, __STRUCT_IN_ADDR_P faddr, __STRUCT_TIMEVAL_P timeout));
  24.141 +
  24.142 +	extern int id_close __P((ident_t * id));
  24.143 +
  24.144 +	extern int id_query __P((ident_t * id, int lport, int fport, __STRUCT_TIMEVAL_P timeout));
  24.145 +
  24.146 +	extern int id_parse __P((ident_t * id, __STRUCT_TIMEVAL_P timeout, int *lport, int *fport, char **identifier, char **opsys, char **charset));
  24.147 +
  24.148  /* High-level calls */
  24.149  
  24.150 -extern IDENT *ident_lookup __P((int fd, int timeout));
  24.151 +	extern IDENT *ident_lookup __P((int fd, int timeout));
  24.152  
  24.153 -extern char  *ident_id __P((int fd, int timeout));
  24.154 +	extern char *ident_id __P((int fd, int timeout));
  24.155  
  24.156 -extern IDENT *ident_query __P(( __STRUCT_IN_ADDR_P laddr, __STRUCT_IN_ADDR_P raddr, int lport, int rport, int timeout));
  24.157 +	extern IDENT *ident_query __P((__STRUCT_IN_ADDR_P laddr, __STRUCT_IN_ADDR_P raddr, int lport, int rport, int timeout));
  24.158  
  24.159 -extern void   ident_free __P((IDENT *id));
  24.160 +	extern void ident_free __P((IDENT * id));
  24.161  
  24.162 -extern char  id_version[];
  24.163 +	extern char id_version[];
  24.164  
  24.165  #ifdef IN_LIBIDENT_SRC
  24.166  
  24.167 -extern char *id_strdup __P((char *str));
  24.168 -extern char *id_strtok __P((char *cp, char *cs, char *dc));
  24.169 +	extern char *id_strdup __P((char *str));
  24.170 +	extern char *id_strtok __P((char *cp, char *cs, char *dc));
  24.171  
  24.172  #endif
  24.173  
  24.174 -#ifdef	__cplusplus
  24.175 +#ifdef __cplusplus
  24.176  }
  24.177  #endif
  24.178 -
  24.179  #endif
    25.1 --- a/src/libident/support.c	Mon Oct 27 16:21:27 2008 +0100
    25.2 +++ b/src/libident/support.c	Mon Oct 27 16:23:10 2008 +0100
    25.3 @@ -18,69 +18,66 @@
    25.4  #include "ident.h"
    25.5  
    25.6  
    25.7 -char *id_strdup __P1(char *, str)
    25.8 +char*
    25.9 +id_strdup __P1(char *, str)
   25.10  {
   25.11 -    char *cp;
   25.12 +	char *cp;
   25.13  
   25.14 -    cp = (char *) malloc(strlen(str)+1);
   25.15 -    if (cp == NULL)
   25.16 -    {
   25.17 +	cp = (char *) malloc(strlen(str) + 1);
   25.18 +	if (cp == NULL) {
   25.19  #ifdef DEBUG
   25.20 -	perror("libident: malloc");
   25.21 +		perror("libident: malloc");
   25.22  #endif
   25.23 -        return NULL;
   25.24 -    }
   25.25 +		return NULL;
   25.26 +	}
   25.27  
   25.28 -    strcpy(cp, str);
   25.29 +	strcpy(cp, str);
   25.30  
   25.31 -    return cp;
   25.32 +	return cp;
   25.33  }
   25.34  
   25.35  
   25.36 -char *id_strtok __P3(char *, cp,
   25.37 -		      char *, cs,
   25.38 -		      char *, dc)
   25.39 +char*
   25.40 +id_strtok __P3(char *, cp, char *, cs, char *, dc)
   25.41  {
   25.42 -    static char *bp = 0;
   25.43 -    
   25.44 -    if (cp)
   25.45 -	bp = cp;
   25.46 -    
   25.47 -    /*
   25.48 -    ** No delimitor cs - return whole buffer and point at end
   25.49 -    */
   25.50 -    if (!cs)
   25.51 -    {
   25.52 -	while (*bp)
   25.53 -	    bp++;
   25.54 -	return cs;
   25.55 -    }
   25.56 -    
   25.57 -    /*
   25.58 -    ** Skip leading spaces
   25.59 -    */
   25.60 -    while (isspace(*bp))
   25.61 +	static char *bp = 0;
   25.62 +
   25.63 +	if (cp)
   25.64 +		bp = cp;
   25.65 +
   25.66 +	/*
   25.67 +	 ** No delimitor cs - return whole buffer and point at end
   25.68 +	 */
   25.69 +	if (!cs) {
   25.70 +		while (*bp)
   25.71 +			bp++;
   25.72 +		return cs;
   25.73 +	}
   25.74 +
   25.75 +	/*
   25.76 +	 ** Skip leading spaces
   25.77 +	 */
   25.78 +	while (isspace(*bp))
   25.79 +		bp++;
   25.80 +
   25.81 +	/*
   25.82 +	 ** No token found?
   25.83 +	 */
   25.84 +	if (!*bp)
   25.85 +		return 0;
   25.86 +
   25.87 +	cp = bp;
   25.88 +	while (*bp && !strchr(cs, *bp))
   25.89 +		bp++;
   25.90 +
   25.91 +	/*
   25.92 +	 ** Remove trailing spaces
   25.93 +	 */
   25.94 +	*dc = *bp;
   25.95 +	for (dc = bp - 1; dc > cp && isspace(*dc); dc--);
   25.96 +	*++dc = '\0';
   25.97 +
   25.98  	bp++;
   25.99 -    
  25.100 -    /*
  25.101 -    ** No token found?
  25.102 -    */
  25.103 -    if (!*bp)
  25.104 -	return 0;
  25.105 -    
  25.106 -    cp = bp;
  25.107 -    while (*bp && !strchr(cs, *bp))
  25.108 -	bp++;
  25.109 -    
  25.110 -    /*
  25.111 -    ** Remove trailing spaces
  25.112 -    */
  25.113 -    *dc = *bp;
  25.114 -    for (dc = bp-1; dc > cp && isspace(*dc); dc--)
  25.115 -	;
  25.116 -    *++dc = '\0';
  25.117 -    
  25.118 -    bp++;
  25.119 -    
  25.120 -    return cp;
  25.121 +
  25.122 +	return cp;
  25.123  }
    26.1 --- a/src/listen.c	Mon Oct 27 16:21:27 2008 +0100
    26.2 +++ b/src/listen.c	Mon Oct 27 16:23:10 2008 +0100
    26.3 @@ -22,222 +22,205 @@
    26.4  
    26.5  static int volatile sighup_seen = 0;
    26.6  
    26.7 -static
    26.8 -void sighup_handler(int sig)
    26.9 +static void
   26.10 +sighup_handler(int sig)
   26.11  {
   26.12 -  sighup_seen = 1;
   26.13 -  signal(SIGHUP, sighup_handler);
   26.14 +	sighup_seen = 1;
   26.15 +	signal(SIGHUP, sighup_handler);
   26.16  }
   26.17  
   26.18 -static
   26.19 -void sigchld_handler(int sig)
   26.20 +static void
   26.21 +sigchld_handler(int sig)
   26.22  {
   26.23 -  pid_t pid;
   26.24 -  int status;
   26.25 -  
   26.26 -  pid = waitpid(0, &status, 0);
   26.27 -  if(pid > 0){
   26.28 -    if(WEXITSTATUS(status) != EXIT_SUCCESS)
   26.29 -      logwrite(LOG_WARNING, "process %d exited with %d\n",
   26.30 -	       pid, WEXITSTATUS(status));
   26.31 -    if(WIFSIGNALED(status))
   26.32 -      logwrite(LOG_WARNING,
   26.33 -	       "process with pid %d got signal: %d\n",
   26.34 -	       pid, WTERMSIG(status));
   26.35 -  }
   26.36 -  signal(SIGCHLD, sigchld_handler);
   26.37 +	pid_t pid;
   26.38 +	int status;
   26.39 +
   26.40 +	pid = waitpid(0, &status, 0);
   26.41 +	if (pid > 0) {
   26.42 +		if (WEXITSTATUS(status) != EXIT_SUCCESS)
   26.43 +			logwrite(LOG_WARNING, "process %d exited with %d\n", pid, WEXITSTATUS(status));
   26.44 +		if (WIFSIGNALED(status))
   26.45 +			logwrite(LOG_WARNING, "process with pid %d got signal: %d\n", pid, WTERMSIG(status));
   26.46 +	}
   26.47 +	signal(SIGCHLD, sigchld_handler);
   26.48  }
   26.49  
   26.50  #ifdef ENABLE_SMTP_SERVER
   26.51 -void accept_connect(int listen_sock, int sock, struct sockaddr_in* sock_addr)
   26.52 +void
   26.53 +accept_connect(int listen_sock, int sock, struct sockaddr_in *sock_addr)
   26.54  {
   26.55 -  pid_t pid;
   26.56 -  int dup_sock = dup(sock);
   26.57 -  FILE *out, *in;
   26.58 -  gchar *rem_host;
   26.59 -  gchar *ident = NULL;
   26.60 +	pid_t pid;
   26.61 +	int dup_sock = dup(sock);
   26.62 +	FILE *out, *in;
   26.63 +	gchar *rem_host;
   26.64 +	gchar *ident = NULL;
   26.65  
   26.66 -  rem_host = g_strdup(inet_ntoa(sock_addr->sin_addr));
   26.67 +	rem_host = g_strdup(inet_ntoa(sock_addr->sin_addr));
   26.68  #ifdef ENABLE_IDENT
   26.69 -  {
   26.70 -    gchar *id = NULL;
   26.71 -    if((id = (gchar *)ident_id(sock, 60))){
   26.72 -      ident = g_strdup(id);
   26.73 -    }
   26.74 -    logwrite(LOG_NOTICE, "connect from host %s, port %hd ident=%s\n",
   26.75 -	     rem_host,
   26.76 -	     ntohs (sock_addr->sin_port),
   26.77 -	     ident ? ident : "(unknown)");
   26.78 -  }
   26.79 +	{
   26.80 +		gchar *id = NULL;
   26.81 +		if ((id = (gchar *) ident_id(sock, 60))) {
   26.82 +			ident = g_strdup(id);
   26.83 +		}
   26.84 +		logwrite(LOG_NOTICE, "connect from host %s, port %hd ident=%s\n", rem_host,
   26.85 +		         ntohs(sock_addr->sin_port), ident ? ident : "(unknown)");
   26.86 +	}
   26.87  #else
   26.88 -  logwrite(LOG_NOTICE, "connect from host %s, port %hd\n",
   26.89 -	 rem_host,
   26.90 -	 ntohs (sock_addr->sin_port));
   26.91 +	logwrite(LOG_NOTICE, "connect from host %s, port %hd\n", rem_host, ntohs(sock_addr->sin_port));
   26.92  #endif
   26.93  
   26.94 -  // start child for connection:
   26.95 -  signal(SIGCHLD, sigchld_handler);
   26.96 -  pid = fork();
   26.97 -  if(pid == 0){
   26.98 -    close(listen_sock);
   26.99 -    out = fdopen(sock, "w");
  26.100 -    in = fdopen(dup_sock, "r");
  26.101 -    
  26.102 -    smtp_in(in, out, rem_host, ident);
  26.103 +	// start child for connection:
  26.104 +	signal(SIGCHLD, sigchld_handler);
  26.105 +	pid = fork();
  26.106 +	if (pid == 0) {
  26.107 +		close(listen_sock);
  26.108 +		out = fdopen(sock, "w");
  26.109 +		in = fdopen(dup_sock, "r");
  26.110  
  26.111 -    _exit(EXIT_SUCCESS);
  26.112 -  }else if(pid < 0){
  26.113 -    logwrite(LOG_WARNING, "could not fork for incoming smtp connection: %s\n",
  26.114 -	     strerror(errno));
  26.115 -  }
  26.116 +		smtp_in(in, out, rem_host, ident);
  26.117  
  26.118 +		_exit(EXIT_SUCCESS);
  26.119 +	} else if (pid < 0) {
  26.120 +		logwrite(LOG_WARNING, "could not fork for incoming smtp connection: %s\n", strerror(errno));
  26.121 +	}
  26.122  #ifdef ENABLE_IDENT
  26.123 -  if(ident != NULL) g_free(ident);
  26.124 +	if (ident != NULL)
  26.125 +		g_free(ident);
  26.126  #endif
  26.127  
  26.128 -  close(sock);
  26.129 -  close(dup_sock);
  26.130 +	close(sock);
  26.131 +	close(dup_sock);
  26.132  }
  26.133 -#endif /*ifdef ENABLE_SMTP_SERVER*/
  26.134 +#endif  /*ifdef ENABLE_SMTP_SERVER */
  26.135  
  26.136 -void listen_port(GList *iface_list, gint qival, char *argv[])
  26.137 +void
  26.138 +listen_port(GList * iface_list, gint qival, char *argv[])
  26.139  {
  26.140 -  int i;
  26.141 -  fd_set active_fd_set, read_fd_set;
  26.142 -  struct timeval tm;
  26.143 -  time_t time_before, time_now;
  26.144 -  struct sockaddr_in clientname;
  26.145 -  size_t size;
  26.146 -  GList *node, *node_next;
  26.147 -  int sel_ret;
  26.148 +	int i;
  26.149 +	fd_set active_fd_set, read_fd_set;
  26.150 +	struct timeval tm;
  26.151 +	time_t time_before, time_now;
  26.152 +	struct sockaddr_in clientname;
  26.153 +	size_t size;
  26.154 +	GList *node, *node_next;
  26.155 +	int sel_ret;
  26.156  
  26.157 -  /* Create the sockets and set them up to accept connections. */
  26.158 -  FD_ZERO (&active_fd_set);
  26.159 +	/* Create the sockets and set them up to accept connections. */
  26.160 +	FD_ZERO(&active_fd_set);
  26.161  #ifdef ENABLE_SMTP_SERVER
  26.162 -  for(node = g_list_first(iface_list);
  26.163 -      node;
  26.164 -      node = node_next){
  26.165 -    interface *iface = (interface *)(node->data);
  26.166 -    int sock;
  26.167 +	for (node = g_list_first(iface_list); node; node = node_next) {
  26.168 +		interface *iface = (interface *) (node->data);
  26.169 +		int sock;
  26.170  
  26.171 -    node_next=g_list_next(node);
  26.172 -    if ((sock = make_server_socket (iface))<0){
  26.173 -      iface_list= g_list_remove_link(iface_list, node);
  26.174 -      g_list_free_1(node);
  26.175 -      continue;
  26.176 -    }
  26.177 -    if (listen (sock, 1) < 0){
  26.178 -      logwrite(LOG_ALERT, "listen: (terminating): %s\n", strerror(errno));
  26.179 -      exit (EXIT_FAILURE);
  26.180 -    }
  26.181 -    logwrite(LOG_NOTICE, "listening on interface %s:%d\n",
  26.182 -	     iface->address, iface->port);
  26.183 -    DEBUG(5) debugf("sock = %d\n", sock);
  26.184 -    FD_SET (sock, &active_fd_set);
  26.185 -  }
  26.186 +		node_next = g_list_next(node);
  26.187 +		if ((sock = make_server_socket(iface)) < 0) {
  26.188 +			iface_list = g_list_remove_link(iface_list, node);
  26.189 +			g_list_free_1(node);
  26.190 +			continue;
  26.191 +		}
  26.192 +		if (listen(sock, 1) < 0) {
  26.193 +			logwrite(LOG_ALERT, "listen: (terminating): %s\n", strerror(errno));
  26.194 +			exit(EXIT_FAILURE);
  26.195 +		}
  26.196 +		logwrite(LOG_NOTICE, "listening on interface %s:%d\n", iface->address, iface->port);
  26.197 +		DEBUG(5) debugf("sock = %d\n", sock);
  26.198 +		FD_SET(sock, &active_fd_set);
  26.199 +	}
  26.200  #endif
  26.201  
  26.202 -  /* setup handler for HUP signal: */
  26.203 -  signal(SIGHUP, sighup_handler);
  26.204 -  signal(SIGCHLD, sigchld_handler);
  26.205 +	/* setup handler for HUP signal: */
  26.206 +	signal(SIGHUP, sighup_handler);
  26.207 +	signal(SIGCHLD, sigchld_handler);
  26.208  
  26.209 -  /* now that we have our socket(s),
  26.210 -     we can give up root privileges */
  26.211 -  if(!conf.run_as_user){
  26.212 -    if(setegid(conf.mail_gid) != 0){
  26.213 -      logwrite(LOG_ALERT, "could not change gid to %d: %s\n",
  26.214 -	       conf.mail_gid, strerror(errno));
  26.215 -      exit(EXIT_FAILURE);
  26.216 -    }
  26.217 -    if(seteuid(conf.mail_uid) != 0){
  26.218 -      logwrite(LOG_ALERT, "could not change uid to %d: %s\n",
  26.219 -	       conf.mail_uid, strerror(errno));
  26.220 -      exit(EXIT_FAILURE);
  26.221 -    }
  26.222 -  }
  26.223 +	/* now that we have our socket(s),
  26.224 +	   we can give up root privileges */
  26.225 +	if (!conf.run_as_user) {
  26.226 +		if (setegid(conf.mail_gid) != 0) {
  26.227 +			logwrite(LOG_ALERT, "could not change gid to %d: %s\n", conf.mail_gid, strerror(errno));
  26.228 +			exit(EXIT_FAILURE);
  26.229 +		}
  26.230 +		if (seteuid(conf.mail_uid) != 0) {
  26.231 +			logwrite(LOG_ALERT, "could not change uid to %d: %s\n", conf.mail_uid, strerror(errno));
  26.232 +			exit(EXIT_FAILURE);
  26.233 +		}
  26.234 +	}
  26.235  
  26.236 -  /*  sel_ret = 0;*/
  26.237 -  time(&time_before);
  26.238 -  time_before -= qival;
  26.239 -  sel_ret = -1;
  26.240 +	/*  sel_ret = 0; */
  26.241 +	time(&time_before);
  26.242 +	time_before -= qival;
  26.243 +	sel_ret = -1;
  26.244  
  26.245 -  while (1){
  26.246 +	while (1) {
  26.247  
  26.248 -    /* if we were interrupted by an incoming connection (or a signal)
  26.249 -       we have to recalculate the time until the next queue run should
  26.250 -       occur. select may put a value into tm, but doc for select() says
  26.251 -       we should not use it.*/
  26.252 -    if(qival > 0){
  26.253 -      time(&time_now);
  26.254 -      if(sel_ret == 0){ /* we are either just starting or did a queue run */
  26.255 -	tm.tv_sec = qival;
  26.256 -	tm.tv_usec = 0;
  26.257 -	time_before = time_now;
  26.258 -      }else{
  26.259 -	tm.tv_sec = qival - (time_now - time_before);
  26.260 -	tm.tv_usec = 0;
  26.261 +		/* if we were interrupted by an incoming connection (or a signal)
  26.262 +		   we have to recalculate the time until the next queue run should
  26.263 +		   occur. select may put a value into tm, but doc for select() says
  26.264 +		   we should not use it. */
  26.265 +		if (qival > 0) {
  26.266 +			time(&time_now);
  26.267 +			if (sel_ret == 0) {  /* we are either just starting or did a queue run */
  26.268 +				tm.tv_sec = qival;
  26.269 +				tm.tv_usec = 0;
  26.270 +				time_before = time_now;
  26.271 +			} else {
  26.272 +				tm.tv_sec = qival - (time_now - time_before);
  26.273 +				tm.tv_usec = 0;
  26.274  
  26.275 -	/* race condition, very unlikely (but possible): */
  26.276 -	if(tm.tv_sec < 0)
  26.277 -	  tm.tv_sec = 0;
  26.278 -      }
  26.279 -    }
  26.280 -    /* Block until input arrives on one or more active sockets,
  26.281 -       or signal arrives,
  26.282 -       or queuing interval time elapsed (if qival > 0) */
  26.283 -    read_fd_set = active_fd_set;
  26.284 -    if ((sel_ret = select(FD_SETSIZE, &read_fd_set, NULL, NULL,
  26.285 -			  qival > 0 ? &tm : NULL)) < 0){
  26.286 -      if(errno != EINTR){
  26.287 -	logwrite(LOG_ALERT, "select: (terminating): %s\n", strerror(errno));
  26.288 -	exit (EXIT_FAILURE);
  26.289 -      }else{
  26.290 -	if(sighup_seen){
  26.291 -	  logwrite(LOG_NOTICE, "HUP signal received. Restarting daemon\n");
  26.292 +				/* race condition, very unlikely (but possible): */
  26.293 +				if (tm.tv_sec < 0)
  26.294 +					tm.tv_sec = 0;
  26.295 +			}
  26.296 +		}
  26.297 +		/* Block until input arrives on one or more active sockets,
  26.298 +		   or signal arrives,
  26.299 +		   or queuing interval time elapsed (if qival > 0) */
  26.300 +		read_fd_set = active_fd_set;
  26.301 +		if ((sel_ret = select(FD_SETSIZE, &read_fd_set, NULL, NULL, qival > 0 ? &tm : NULL)) < 0) {
  26.302 +			if (errno != EINTR) {
  26.303 +				logwrite(LOG_ALERT, "select: (terminating): %s\n", strerror(errno));
  26.304 +				exit(EXIT_FAILURE);
  26.305 +			} else {
  26.306 +				if (sighup_seen) {
  26.307 +					logwrite(LOG_NOTICE, "HUP signal received. Restarting daemon\n");
  26.308  
  26.309 -	  for(i = 0; i < FD_SETSIZE; i++)
  26.310 -	    if(FD_ISSET(i, &active_fd_set))
  26.311 -	      close(i);
  26.312 +					for (i = 0; i < FD_SETSIZE; i++)
  26.313 +						if (FD_ISSET(i, &active_fd_set))
  26.314 +							close(i);
  26.315  
  26.316 -	  execv(argv[0], &(argv[0]));
  26.317 -	  logwrite(LOG_ALERT, "restarting failed: %s\n", strerror(errno));
  26.318 -	  exit(EXIT_FAILURE);
  26.319 +					execv(argv[0], &(argv[0]));
  26.320 +					logwrite(LOG_ALERT, "restarting failed: %s\n", strerror(errno));
  26.321 +					exit(EXIT_FAILURE);
  26.322 +				}
  26.323 +			}
  26.324 +		} else if (sel_ret > 0) {
  26.325 +#ifdef ENABLE_SMTP_SERVER
  26.326 +			for (i = 0; i < FD_SETSIZE; i++) {
  26.327 +				if (FD_ISSET(i, &read_fd_set)) {
  26.328 +					int sock = i;
  26.329 +					int new;
  26.330 +					size = sizeof(clientname);
  26.331 +					new = accept(sock, (struct sockaddr *) &clientname, &size);
  26.332 +					if (new < 0) {
  26.333 +						logwrite(LOG_ALERT, "accept: (ignoring): %s\n", strerror(errno));
  26.334 +					} else
  26.335 +						accept_connect(sock, new, &clientname);
  26.336 +				}
  26.337 +			}
  26.338 +#else
  26.339 +			;
  26.340 +#endif
  26.341 +		} else {
  26.342 +			/* If select returns 0, the interval time has elapsed.
  26.343 +			   We start a new queue runner process */
  26.344 +			int pid;
  26.345 +			signal(SIGCHLD, sigchld_handler);
  26.346 +			if ((pid = fork()) == 0) {
  26.347 +				queue_run();
  26.348 +
  26.349 +				_exit(EXIT_SUCCESS);
  26.350 +			} else if (pid < 0) {
  26.351 +				logwrite(LOG_ALERT, "could not fork for queue run");
  26.352 +			}
  26.353 +		}
  26.354  	}
  26.355 -      }
  26.356 -    }
  26.357 -    else if(sel_ret > 0){
  26.358 -#ifdef ENABLE_SMTP_SERVER
  26.359 -      for(i = 0; i < FD_SETSIZE; i++){
  26.360 -	if (FD_ISSET (i, &read_fd_set)){
  26.361 -	  int sock = i;
  26.362 -	  int new;
  26.363 -	  size = sizeof (clientname);
  26.364 -	  new = accept (sock,
  26.365 -			(struct sockaddr *) &clientname,
  26.366 -			&size);
  26.367 -	  if (new < 0){
  26.368 -	    logwrite(LOG_ALERT, "accept: (ignoring): %s\n",
  26.369 -		     strerror(errno));
  26.370 -	  }else
  26.371 -	    accept_connect(sock, new, &clientname);
  26.372 -	}
  26.373 -      }
  26.374 -#else
  26.375 -      ;
  26.376 -#endif
  26.377 -    }else{
  26.378 -      /* If select returns 0, the interval time has elapsed.
  26.379 -	 We start a new queue runner process */
  26.380 -      int pid;
  26.381 -      signal(SIGCHLD, sigchld_handler);
  26.382 -      if((pid = fork()) == 0){
  26.383 -	queue_run();
  26.384 -
  26.385 -	_exit(EXIT_SUCCESS);
  26.386 -      }
  26.387 -      else if(pid < 0){
  26.388 -	logwrite(LOG_ALERT, "could not fork for queue run");
  26.389 -      }
  26.390 -    }
  26.391 -  }
  26.392  }
    27.1 --- a/src/local.c	Mon Oct 27 16:21:27 2008 +0100
    27.2 +++ b/src/local.c	Mon Oct 27 16:23:10 2008 +0100
    27.3 @@ -20,347 +20,333 @@
    27.4  #include "peopen.h"
    27.5  #include <sys/wait.h>
    27.6  
    27.7 -static
    27.8 -void message_stream(FILE *out, message *msg, GList *hdr_list, guint flags)
    27.9 +static void
   27.10 +message_stream(FILE * out, message * msg, GList * hdr_list, guint flags)
   27.11  {
   27.12 -  time_t now = time(NULL);
   27.13 -  GList *node;
   27.14 -  
   27.15 -  if(flags & MSGSTR_FROMLINE){
   27.16 -    fprintf(out, "From <%s@%s> %s", msg->return_path->local_part,
   27.17 -	    msg->return_path->domain, ctime(&now));
   27.18 -  }
   27.19 -	  
   27.20 -  foreach(hdr_list, node){
   27.21 -    header *hdr = (header *)(node->data);
   27.22 -    fputs(hdr->header, out);
   27.23 -  }
   27.24 -  putc('\n', out);
   27.25 -  foreach(msg->data_list, node){
   27.26 -    /* From hack: */
   27.27 -    if(flags & MSGSTR_FROMHACK){
   27.28 -      if(strncmp(node->data, "From ", 5) == 0)
   27.29 -	putc('>', out);
   27.30 -    }
   27.31 -    fputs(node->data, out);
   27.32 -  }
   27.33 -  putc('\n', out);
   27.34 +	time_t now = time(NULL);
   27.35 +	GList *node;
   27.36 +
   27.37 +	if (flags & MSGSTR_FROMLINE) {
   27.38 +		fprintf(out, "From <%s@%s> %s", msg->return_path->local_part, msg->return_path->domain, ctime(&now));
   27.39 +	}
   27.40 +
   27.41 +	foreach(hdr_list, node) {
   27.42 +		header *hdr = (header *) (node->data);
   27.43 +		fputs(hdr->header, out);
   27.44 +	}
   27.45 +	putc('\n', out);
   27.46 +	foreach(msg->data_list, node) {
   27.47 +		/* From hack: */
   27.48 +		if (flags & MSGSTR_FROMHACK) {
   27.49 +			if (strncmp(node->data, "From ", 5) == 0)
   27.50 +				putc('>', out);
   27.51 +		}
   27.52 +		fputs(node->data, out);
   27.53 +	}
   27.54 +	putc('\n', out);
   27.55  }
   27.56  
   27.57 -gboolean append_file(message *msg, GList *hdr_list, gchar *user)
   27.58 +gboolean
   27.59 +append_file(message * msg, GList * hdr_list, gchar * user)
   27.60  {
   27.61 -  struct passwd *pw;
   27.62 -  gboolean ok = FALSE;
   27.63 -  
   27.64 -  /* headers may be special for a local delivery */
   27.65 -  if(hdr_list == NULL)
   27.66 -    hdr_list = msg->hdr_list;
   27.67 +	struct passwd *pw;
   27.68 +	gboolean ok = FALSE;
   27.69  
   27.70 -  if((pw = getpwnam(user))){
   27.71 -    uid_t saved_uid = geteuid();
   27.72 -    gid_t saved_gid = getegid();
   27.73 -    gboolean uid_ok = TRUE, gid_ok = TRUE;
   27.74 +	/* headers may be special for a local delivery */
   27.75 +	if (hdr_list == NULL)
   27.76 +		hdr_list = msg->hdr_list;
   27.77  
   27.78 -    if(!conf.run_as_user){
   27.79 -      uid_ok = (seteuid(0) == 0);
   27.80 -      if(uid_ok){
   27.81 -	gid_ok = (setegid(conf.mail_gid) == 0);
   27.82 -	uid_ok = (seteuid(pw->pw_uid) == 0);
   27.83 -      }
   27.84 -    }
   27.85 +	if ((pw = getpwnam(user))) {
   27.86 +		uid_t saved_uid = geteuid();
   27.87 +		gid_t saved_gid = getegid();
   27.88 +		gboolean uid_ok = TRUE, gid_ok = TRUE;
   27.89  
   27.90 -    DEBUG(5) debugf("running as euid %d\n", geteuid());
   27.91 -    DEBUG(5) debugf("running as egid %d\n", getegid());
   27.92 +		if (!conf.run_as_user) {
   27.93 +			uid_ok = (seteuid(0) == 0);
   27.94 +			if (uid_ok) {
   27.95 +				gid_ok = (setegid(conf.mail_gid) == 0);
   27.96 +				uid_ok = (seteuid(pw->pw_uid) == 0);
   27.97 +			}
   27.98 +		}
   27.99  
  27.100 -    if(uid_ok && gid_ok){
  27.101 -      gchar *filename;
  27.102 -      FILE *out;
  27.103 +		DEBUG(5) debugf("running as euid %d\n", geteuid());
  27.104 +		DEBUG(5) debugf("running as egid %d\n", getegid());
  27.105  
  27.106 -      filename = g_strdup_printf("%s/%s", conf.mail_dir, user);
  27.107 -      if((out = fopen(filename, "a"))){
  27.108 +		if (uid_ok && gid_ok) {
  27.109 +			gchar *filename;
  27.110 +			FILE *out;
  27.111 +
  27.112 +			filename = g_strdup_printf("%s/%s", conf.mail_dir, user);
  27.113 +			if ((out = fopen(filename, "a"))) {
  27.114  #ifdef USE_LIBLOCKFILE
  27.115 -        gint err;
  27.116 -        /* lock file using liblockfile */
  27.117 -        err = maillock(user,3);
  27.118 -	if(err == 0){
  27.119 +				gint err;
  27.120 +				/* lock file using liblockfile */
  27.121 +				err = maillock(user, 3);
  27.122 +				if (err == 0) {
  27.123  #else
  27.124 -	/* lock file: */
  27.125 -	struct flock lock;
  27.126 -	lock.l_type = F_WRLCK;
  27.127 -	lock.l_whence = SEEK_END;
  27.128 -	lock.l_start = lock.l_len = 0;
  27.129 -	if(fcntl(fileno(out), F_SETLK, &lock) != -1){
  27.130 +				/* lock file: */
  27.131 +				struct flock lock;
  27.132 +				lock.l_type = F_WRLCK;
  27.133 +				lock.l_whence = SEEK_END;
  27.134 +				lock.l_start = lock.l_len = 0;
  27.135 +				if (fcntl(fileno(out), F_SETLK, &lock) != -1) {
  27.136  #endif
  27.137 -	  fchmod(fileno(out), 0600);
  27.138 -	  
  27.139 -	  message_stream(out, msg, hdr_list, MSGSTR_FROMLINE|MSGSTR_FROMHACK);
  27.140 +					fchmod(fileno(out), 0600);
  27.141  
  27.142 -	  ok = TRUE;
  27.143 -	  
  27.144 -	  /* close when still user */
  27.145 -	  fclose(out);
  27.146 +					message_stream(out, msg, hdr_list, MSGSTR_FROMLINE | MSGSTR_FROMHACK);
  27.147 +
  27.148 +					ok = TRUE;
  27.149 +
  27.150 +					/* close when still user */
  27.151 +					fclose(out);
  27.152  #ifdef USE_LIBLOCKFILE
  27.153 -          mailunlock();
  27.154 +					mailunlock();
  27.155  #endif
  27.156 -	}else{
  27.157 -	  fclose(out);
  27.158 +				} else {
  27.159 +					fclose(out);
  27.160  #ifdef USE_LIBLOCKFILE
  27.161 -	  DEBUG(3) debugf("could not lock file %s: error %d\n",
  27.162 -			  filename, err);
  27.163 -	} /* XEmacs indenting convenience... */
  27.164 +					DEBUG(3) debugf("could not lock file %s: error %d\n", filename, err);
  27.165 +				}  /* XEmacs indenting convenience... */
  27.166  #else
  27.167 -	  DEBUG(3) debugf("could not lock file %s: %s\n",
  27.168 -			  filename, strerror(errno));
  27.169 +					DEBUG(3) debugf("could not lock file %s: %s\n", filename, strerror(errno));
  27.170 +				}
  27.171 +#endif
  27.172 +			} else {
  27.173 +				logwrite(LOG_ALERT, "could not open file %s: %s\n", filename, strerror(errno));
  27.174 +			}
  27.175 +			g_free(filename);
  27.176 +
  27.177 +			if (!conf.run_as_user) {
  27.178 +				uid_ok = (seteuid(0) == 0);
  27.179 +				if (uid_ok) {
  27.180 +					gid_ok = (setegid(saved_gid) == 0);
  27.181 +					uid_ok = (seteuid(saved_uid) == 0);
  27.182 +				}
  27.183 +			}
  27.184 +
  27.185 +			if (!uid_ok || !gid_ok) {
  27.186 +				/* FIXME: if this fails we HAVE to exit, because we shall not run
  27.187 +				   with some users id. But we do not return, and so this message
  27.188 +				   will not be finished, so the user will get the message again
  27.189 +				   next time a delivery is attempted... */
  27.190 +				logwrite(LOG_ALERT, "could not set back uid or gid after local delivery: %s\n", strerror(errno));
  27.191 +				logwrite(LOG_ALERT, "uid=%d, gid=%d, euid=%d, egid=%d, want = %d, %d\n",
  27.192 +				         getuid(), getgid(), geteuid(), getegid(), saved_uid, saved_gid);
  27.193 +				exit(EXIT_FAILURE);
  27.194 +			}
  27.195 +		} else {
  27.196 +			logwrite(LOG_ALERT, "could not set uid or gid for local delivery, uid = %d: %s\n", pw->pw_uid, strerror(errno));
  27.197 +		}
  27.198 +	} else {
  27.199 +		logwrite(LOG_ALERT, "could not find password entry for user %s\n", user);
  27.200 +		errno = ENOENT;  /* getpwnam does not set errno correctly */
  27.201  	}
  27.202 -#endif
  27.203 -      }else{
  27.204 -	logwrite(LOG_ALERT, "could not open file %s: %s\n",
  27.205 -		 filename, strerror(errno));
  27.206 -      }
  27.207 -      g_free(filename);
  27.208  
  27.209 -      if(!conf.run_as_user){
  27.210 -	uid_ok = (seteuid(0) == 0);
  27.211 -	if(uid_ok){
  27.212 -	  gid_ok = (setegid(saved_gid) == 0);
  27.213 -	  uid_ok = (seteuid(saved_uid) == 0);
  27.214 -	}
  27.215 -      }
  27.216 -      
  27.217 -      if(!uid_ok || !gid_ok){
  27.218 -	/* FIXME: if this fails we HAVE to exit, because we shall not run
  27.219 -	   with some users id. But we do not return, and so this message
  27.220 -	   will not be finished, so the user will get the message again
  27.221 -	   next time a delivery is attempted... */
  27.222 -	logwrite(LOG_ALERT,
  27.223 -		 "could not set back uid or gid after local delivery: %s\n",
  27.224 -		 strerror(errno));
  27.225 -	logwrite(LOG_ALERT,
  27.226 -		 "uid=%d, gid=%d, euid=%d, egid=%d, want = %d, %d\n",
  27.227 -		 getuid(), getgid(), geteuid(), getegid(), saved_uid, saved_gid);
  27.228 -	exit(EXIT_FAILURE);
  27.229 -      }
  27.230 -    }else{
  27.231 -      logwrite(LOG_ALERT,
  27.232 -	       "could not set uid or gid for local delivery, uid = %d: %s\n",
  27.233 -	       pw->pw_uid, strerror(errno));
  27.234 -    }
  27.235 -  }else{
  27.236 -    logwrite(LOG_ALERT, "could not find password entry for user %s\n", user);
  27.237 -    errno = ENOENT; /* getpwnam does not set errno correctly */
  27.238 -  }
  27.239 -
  27.240 -  return ok;
  27.241 +	return ok;
  27.242  }
  27.243  
  27.244  #ifdef ENABLE_MAILDIR
  27.245 -gboolean maildir_out(message *msg, GList *hdr_list, gchar *user, guint flags)
  27.246 +gboolean
  27.247 +maildir_out(message * msg, GList * hdr_list, gchar * user, guint flags)
  27.248  {
  27.249 -  struct passwd *pw;
  27.250 -  gboolean ok = FALSE;
  27.251 -  
  27.252 -  /* headers may be special for a local delivery */
  27.253 -  if(hdr_list == NULL)
  27.254 -    hdr_list = msg->hdr_list;
  27.255 +	struct passwd *pw;
  27.256 +	gboolean ok = FALSE;
  27.257  
  27.258 -  if((pw = getpwnam(user))){
  27.259 -    uid_t saved_uid = geteuid();
  27.260 -    gid_t saved_gid = getegid();
  27.261 -    gboolean uid_ok = TRUE, gid_ok = TRUE;
  27.262 +	/* headers may be special for a local delivery */
  27.263 +	if (hdr_list == NULL)
  27.264 +		hdr_list = msg->hdr_list;
  27.265  
  27.266 -    if(!conf.run_as_user){
  27.267 -      uid_ok = (seteuid(0) == 0);
  27.268 -      if(uid_ok){
  27.269 -	gid_ok = (setegid(conf.mail_gid) == 0);
  27.270 -	uid_ok = (seteuid(pw->pw_uid) == 0);
  27.271 -      }
  27.272 -    }
  27.273 +	if ((pw = getpwnam(user))) {
  27.274 +		uid_t saved_uid = geteuid();
  27.275 +		gid_t saved_gid = getegid();
  27.276 +		gboolean uid_ok = TRUE, gid_ok = TRUE;
  27.277  
  27.278 -    DEBUG(5) debugf("running as euid %d\n", geteuid());
  27.279 -    DEBUG(5) debugf("running as egid %d\n", getegid());
  27.280 -    
  27.281 -    if(uid_ok && gid_ok){
  27.282 -      char *path = g_strdup_printf("%s/Maildir", pw->pw_dir);
  27.283 -      struct stat statbuf;
  27.284 -      int ret;
  27.285 +		if (!conf.run_as_user) {
  27.286 +			uid_ok = (seteuid(0) == 0);
  27.287 +			if (uid_ok) {
  27.288 +				gid_ok = (setegid(conf.mail_gid) == 0);
  27.289 +				uid_ok = (seteuid(pw->pw_uid) == 0);
  27.290 +			}
  27.291 +		}
  27.292  
  27.293 -      DEBUG(5) debugf("path = %s\n", path);
  27.294 +		DEBUG(5) debugf("running as euid %d\n", geteuid());
  27.295 +		DEBUG(5) debugf("running as egid %d\n", getegid());
  27.296  
  27.297 -      ok = TRUE;
  27.298 -      ret = stat(path, &statbuf);
  27.299 -      if(ret != 0){
  27.300 -	ok = FALSE;
  27.301 -	if(errno == ENOENT){
  27.302 -	  logwrite(LOG_NOTICE, "directory %s does not exist, creating\n", path);
  27.303 -	  if(mkdir(path, 0700) == 0)
  27.304 -	    ok = TRUE;
  27.305 -	}else
  27.306 -	  logwrite(LOG_ALERT, "stat of %s failed: %s\n", path, strerror(errno));
  27.307 -      }
  27.308 -      if(ok){
  27.309 -	ok = FALSE;
  27.310 -	ret = stat(path, &statbuf);
  27.311 -	if(S_ISDIR(statbuf.st_mode)){
  27.312 -	  gchar *subdirs[] = {"tmp", "new", "cur"};
  27.313 -	  int i;
  27.314 -	  for(i = 0; i < 3; i++){
  27.315 -	    char *path1 = g_strdup_printf("%s/%s", path, subdirs[i]);
  27.316 -	    ret = stat(path1, &statbuf);
  27.317 -	    if(ret != 0){
  27.318 -	      if(errno == ENOENT){
  27.319 -		logwrite(LOG_NOTICE, "directory %s does not exist, creating\n", path1);
  27.320 -		if(mkdir(path1, 0700) != 0) break;
  27.321 -	      }
  27.322 -	    }
  27.323 -	    g_free(path1);
  27.324 -	  }
  27.325 -	  if(i == 3){
  27.326 -	    FILE *out;
  27.327 -	    mode_t saved_mode = umask(066);
  27.328 -	    /* the qmail style unique works only if delivering
  27.329 -	       with different process. We do not fork for each delivery,
  27.330 -	       so our uid is more unique. Hope it is compatible with all
  27.331 -	       MUAs.
  27.332 -	    */
  27.333 -	    gchar *filename = g_strdup_printf("%s/tmp/%s.%s", path, msg->uid, conf.host_name);
  27.334 +		if (uid_ok && gid_ok) {
  27.335 +			char *path = g_strdup_printf("%s/Maildir", pw->pw_dir);
  27.336 +			struct stat statbuf;
  27.337 +			int ret;
  27.338  
  27.339 -	    DEBUG(5) debugf("filename = %s\n", filename);
  27.340 -	    
  27.341 -	    if((out = fopen(filename, "w"))){
  27.342 -	      gchar *newname =
  27.343 -		g_strdup_printf("%s/new/%s.%s", path, msg->uid, conf.host_name);
  27.344 -	      message_stream(out, msg, hdr_list, flags);
  27.345 -	      ok = TRUE;
  27.346 -	      if(fflush(out) == EOF) ok = FALSE;
  27.347 -	      else if(fdatasync(fileno(out)) != 0){
  27.348 -		if(errno != EINVAL) /* some fs do not support this..
  27.349 -				       I hope this also means that it is not necessary */
  27.350 -		  ok = FALSE;
  27.351 -	      }
  27.352 -	      fclose(out);
  27.353 -	      if(rename(filename, newname) != 0){
  27.354 -		ok = FALSE;
  27.355 -		logwrite(LOG_ALERT, "moving %s to %s failed: %s",
  27.356 -			 filename, newname, strerror(errno));
  27.357 -	      }
  27.358 -	      g_free(newname);
  27.359 -	    }
  27.360 -	    umask(saved_mode);
  27.361 -	    g_free(filename);
  27.362 -	  }
  27.363 -	}else{
  27.364 -	  logwrite(LOG_ALERT, "%s is not a directory\n", path);
  27.365 -	  errno = ENOTDIR;
  27.366 +			DEBUG(5) debugf("path = %s\n", path);
  27.367 +
  27.368 +			ok = TRUE;
  27.369 +			ret = stat(path, &statbuf);
  27.370 +			if (ret != 0) {
  27.371 +				ok = FALSE;
  27.372 +				if (errno == ENOENT) {
  27.373 +					logwrite(LOG_NOTICE, "directory %s does not exist, creating\n", path);
  27.374 +					if (mkdir(path, 0700) == 0)
  27.375 +						ok = TRUE;
  27.376 +				} else
  27.377 +					logwrite(LOG_ALERT, "stat of %s failed: %s\n", path, strerror(errno));
  27.378 +			}
  27.379 +			if (ok) {
  27.380 +				ok = FALSE;
  27.381 +				ret = stat(path, &statbuf);
  27.382 +				if (S_ISDIR(statbuf.st_mode)) {
  27.383 +					gchar *subdirs[] = { "tmp", "new", "cur" };
  27.384 +					int i;
  27.385 +					for (i = 0; i < 3; i++) {
  27.386 +						char *path1 = g_strdup_printf("%s/%s", path, subdirs[i]);
  27.387 +						ret = stat(path1, &statbuf);
  27.388 +						if (ret != 0) {
  27.389 +							if (errno == ENOENT) {
  27.390 +								logwrite(LOG_NOTICE, "directory %s does not exist, creating\n", path1);
  27.391 +								if (mkdir(path1, 0700) != 0)
  27.392 +									break;
  27.393 +							}
  27.394 +						}
  27.395 +						g_free(path1);
  27.396 +					}
  27.397 +					if (i == 3) {
  27.398 +						FILE *out;
  27.399 +						mode_t saved_mode = umask(066);
  27.400 +						/* the qmail style unique works only if delivering
  27.401 +						   with different process. We do not fork for each delivery,
  27.402 +						   so our uid is more unique. Hope it is compatible with all
  27.403 +						   MUAs.
  27.404 +						 */
  27.405 +						gchar *filename = g_strdup_printf("%s/tmp/%s.%s", path, msg->uid, conf.host_name);
  27.406 +
  27.407 +						DEBUG(5) debugf("filename = %s\n", filename);
  27.408 +
  27.409 +						if ((out = fopen(filename, "w"))) {
  27.410 +							gchar *newname = g_strdup_printf("%s/new/%s.%s", path, msg->uid, conf.host_name);
  27.411 +							message_stream(out, msg, hdr_list, flags);
  27.412 +							ok = TRUE;
  27.413 +							if (fflush(out) == EOF)
  27.414 +								ok = FALSE;
  27.415 +							else if (fdatasync(fileno(out)) != 0) {
  27.416 +								if (errno != EINVAL)  /* some fs do not support this..  I hope this also means that it is not necessary */
  27.417 +									ok = FALSE;
  27.418 +							}
  27.419 +							fclose(out);
  27.420 +							if (rename(filename, newname) != 0) {
  27.421 +								ok = FALSE;
  27.422 +								logwrite(LOG_ALERT, "moving %s to %s failed: %s", filename, newname, strerror(errno));
  27.423 +							}
  27.424 +							g_free(newname);
  27.425 +						}
  27.426 +						umask(saved_mode);
  27.427 +						g_free(filename);
  27.428 +					}
  27.429 +				} else {
  27.430 +					logwrite(LOG_ALERT, "%s is not a directory\n", path);
  27.431 +					errno = ENOTDIR;
  27.432 +				}
  27.433 +			}
  27.434 +			if (!conf.run_as_user) {
  27.435 +				uid_ok = (seteuid(0) == 0);
  27.436 +				if (uid_ok) {
  27.437 +					gid_ok = (setegid(saved_gid) == 0);
  27.438 +					uid_ok = (seteuid(saved_uid) == 0);
  27.439 +				}
  27.440 +			}
  27.441 +			if (!uid_ok || !gid_ok) {
  27.442 +				/* FIXME: if this fails we HAVE to exit, because we shall not run
  27.443 +				   with some users id. But we do not return, and so this message
  27.444 +				   will not be finished, so the user will get the message again
  27.445 +				   next time a delivery is attempted... */
  27.446 +				logwrite(LOG_ALERT, "could not set back uid or gid after local delivery: %s\n", strerror(errno));
  27.447 +				exit(EXIT_FAILURE);
  27.448 +			}
  27.449 +			g_free(path);
  27.450 +		} else {
  27.451 +			logwrite(LOG_ALERT, "could not set uid or gid for local delivery, uid = %d: %s\n", pw->pw_uid, strerror(errno));
  27.452 +		}
  27.453 +	} else {
  27.454 +		logwrite(LOG_ALERT, "could not find password entry for user %s\n", user);
  27.455 +		errno = ENOENT;  /* getpwnam does not set errno correctly */
  27.456  	}
  27.457 -      }
  27.458 -      if(!conf.run_as_user){
  27.459 -	uid_ok = (seteuid(0) == 0);
  27.460 -	if(uid_ok){
  27.461 -	  gid_ok = (setegid(saved_gid) == 0);
  27.462 -	  uid_ok = (seteuid(saved_uid) == 0);
  27.463 -	}
  27.464 -      }
  27.465 -      if(!uid_ok || !gid_ok){
  27.466 -	/* FIXME: if this fails we HAVE to exit, because we shall not run
  27.467 -	   with some users id. But we do not return, and so this message
  27.468 -	   will not be finished, so the user will get the message again
  27.469 -	   next time a delivery is attempted... */
  27.470 -	logwrite(LOG_ALERT,
  27.471 -		 "could not set back uid or gid after local delivery: %s\n",
  27.472 -		 strerror(errno));
  27.473 -	exit(EXIT_FAILURE);
  27.474 -      }
  27.475 -      g_free(path);
  27.476 -    }else{
  27.477 -      logwrite(LOG_ALERT,
  27.478 -	       "could not set uid or gid for local delivery, uid = %d: %s\n",
  27.479 -	       pw->pw_uid, strerror(errno));
  27.480 -    }
  27.481 -  }else{
  27.482 -    logwrite(LOG_ALERT, "could not find password entry for user %s\n", user);
  27.483 -    errno = ENOENT; /* getpwnam does not set errno correctly */
  27.484 -  }
  27.485 -  return ok;
  27.486 +	return ok;
  27.487  }
  27.488  #endif
  27.489  
  27.490  gboolean
  27.491 -pipe_out(message *msg, GList *hdr_list, address *rcpt, gchar *cmd, guint flags)
  27.492 +pipe_out(message * msg, GList * hdr_list, address * rcpt, gchar * cmd, guint flags)
  27.493  {
  27.494 -  gchar *envp[40];
  27.495 -  FILE *out;
  27.496 -  uid_t saved_uid = geteuid();
  27.497 -  gid_t saved_gid = getegid();
  27.498 -  gboolean ok = FALSE;
  27.499 -  gint i, n;
  27.500 -  pid_t pid;
  27.501 -  void (*old_signal)(int);
  27.502 -  int status;
  27.503 +	gchar *envp[40];
  27.504 +	FILE *out;
  27.505 +	uid_t saved_uid = geteuid();
  27.506 +	gid_t saved_gid = getegid();
  27.507 +	gboolean ok = FALSE;
  27.508 +	gint i, n;
  27.509 +	pid_t pid;
  27.510 +	void (*old_signal) (int);
  27.511 +	int status;
  27.512  
  27.513 -  /* set uid and gid to the mail ids */
  27.514 -  if(!conf.run_as_user){
  27.515 -    set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
  27.516 -  }
  27.517 +	/* set uid and gid to the mail ids */
  27.518 +	if (!conf.run_as_user) {
  27.519 +		set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
  27.520 +	}
  27.521  
  27.522 -  /* set environment */
  27.523 -  {
  27.524 -    gint i = 0;
  27.525 -    address *ancestor = addr_find_ancestor(rcpt);
  27.526 +	/* set environment */
  27.527 +	{
  27.528 +		gint i = 0;
  27.529 +		address *ancestor = addr_find_ancestor(rcpt);
  27.530  
  27.531 -    envp[i++] = g_strdup_printf("SENDER=%s@%s", msg->return_path->local_part, msg->return_path->domain);
  27.532 -    envp[i++] = g_strdup_printf("SENDER_DOMAIN=%s", msg->return_path->domain);
  27.533 -    envp[i++] = g_strdup_printf("SENDER_LOCAL=%s", msg->return_path->local_part);
  27.534 -    envp[i++] = g_strdup_printf("RECEIVED_HOST=%s", msg->received_host ? msg->received_host : "");
  27.535 +		envp[i++] = g_strdup_printf("SENDER=%s@%s", msg->return_path->local_part, msg->return_path->domain);
  27.536 +		envp[i++] = g_strdup_printf("SENDER_DOMAIN=%s", msg->return_path->domain);
  27.537 +		envp[i++] = g_strdup_printf("SENDER_LOCAL=%s", msg->return_path->local_part);
  27.538 +		envp[i++] = g_strdup_printf("RECEIVED_HOST=%s", msg->received_host ? msg->received_host : "");
  27.539  
  27.540 -    envp[i++] = g_strdup_printf("RETURN_PATH=%s@%s",
  27.541 -				msg->return_path->local_part, msg->return_path->domain);
  27.542 -    envp[i++] = g_strdup_printf("DOMAIN=%s", ancestor->domain);
  27.543 +		envp[i++] = g_strdup_printf("RETURN_PATH=%s@%s", msg->return_path->local_part, msg->return_path->domain);
  27.544 +		envp[i++] = g_strdup_printf("DOMAIN=%s", ancestor->domain);
  27.545  
  27.546 -    envp[i++] = g_strdup_printf("LOCAL_PART=%s", ancestor->local_part);
  27.547 -    envp[i++] = g_strdup_printf("USER=%s", ancestor->local_part);
  27.548 -    envp[i++] = g_strdup_printf("LOGNAME=%s", ancestor->local_part);
  27.549 +		envp[i++] = g_strdup_printf("LOCAL_PART=%s", ancestor->local_part);
  27.550 +		envp[i++] = g_strdup_printf("USER=%s", ancestor->local_part);
  27.551 +		envp[i++] = g_strdup_printf("LOGNAME=%s", ancestor->local_part);
  27.552  
  27.553 -    envp[i++] = g_strdup_printf("MESSAGE_ID=%s", msg->uid);
  27.554 -    envp[i++] = g_strdup_printf("QUALIFY_DOMAIN=%s", conf.host_name);
  27.555 +		envp[i++] = g_strdup_printf("MESSAGE_ID=%s", msg->uid);
  27.556 +		envp[i++] = g_strdup_printf("QUALIFY_DOMAIN=%s", conf.host_name);
  27.557  
  27.558 -    envp[i] = NULL;
  27.559 -    n = i;
  27.560 -  }
  27.561 +		envp[i] = NULL;
  27.562 +		n = i;
  27.563 +	}
  27.564  
  27.565 -  old_signal = signal(SIGCHLD, SIG_DFL);
  27.566 +	old_signal = signal(SIGCHLD, SIG_DFL);
  27.567  
  27.568 -  out = peidopen(cmd, "w", envp, &pid, conf.mail_uid, conf.mail_gid);
  27.569 -  if(out != NULL){
  27.570 -    message_stream(out, msg, hdr_list, flags);
  27.571 +	out = peidopen(cmd, "w", envp, &pid, conf.mail_uid, conf.mail_gid);
  27.572 +	if (out != NULL) {
  27.573 +		message_stream(out, msg, hdr_list, flags);
  27.574  
  27.575 -    fclose(out);
  27.576 +		fclose(out);
  27.577  
  27.578 -    waitpid(pid, &status, 0);
  27.579 +		waitpid(pid, &status, 0);
  27.580  
  27.581 -    if(WEXITSTATUS(status) != 0){
  27.582 -      int exstat = WEXITSTATUS(status);
  27.583 -      logwrite(LOG_ALERT, "process returned %d (%s)\n", exstat, ext_strerror(1024 + exstat));
  27.584 -      errno = 1024 + exstat;
  27.585 -    }else if(WIFSIGNALED(status)){
  27.586 -      logwrite(LOG_ALERT, "process got signal %d\n", WTERMSIG(status));
  27.587 -    }else
  27.588 -      ok = TRUE;
  27.589 +		if (WEXITSTATUS(status) != 0) {
  27.590 +			int exstat = WEXITSTATUS(status);
  27.591 +			logwrite(LOG_ALERT, "process returned %d (%s)\n", exstat, ext_strerror(1024 + exstat));
  27.592 +			errno = 1024 + exstat;
  27.593 +		} else if (WIFSIGNALED(status)) {
  27.594 +			logwrite(LOG_ALERT, "process got signal %d\n", WTERMSIG(status));
  27.595 +		} else
  27.596 +			ok = TRUE;
  27.597  
  27.598 -  }else
  27.599 -    logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", cmd, strerror(errno));
  27.600 +	} else
  27.601 +		logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", cmd, strerror(errno));
  27.602  
  27.603 -  signal(SIGCHLD, old_signal);
  27.604 +	signal(SIGCHLD, old_signal);
  27.605  
  27.606 -  /* free environment */
  27.607 -  for(i = 0; i < n; i++){
  27.608 -    g_free(envp[i]);
  27.609 -  }
  27.610 +	/* free environment */
  27.611 +	for (i = 0; i < n; i++) {
  27.612 +		g_free(envp[i]);
  27.613 +	}
  27.614  
  27.615 -  /* set uid and gid back */
  27.616 -  if(!conf.run_as_user){
  27.617 -    set_euidgid(saved_uid, saved_gid, NULL, NULL);
  27.618 -  }
  27.619 +	/* set uid and gid back */
  27.620 +	if (!conf.run_as_user) {
  27.621 +		set_euidgid(saved_uid, saved_gid, NULL, NULL);
  27.622 +	}
  27.623  
  27.624 -  return ok;
  27.625 +	return ok;
  27.626  }
  27.627 -    
    28.1 --- a/src/log.c	Mon Oct 27 16:21:27 2008 +0100
    28.2 +++ b/src/log.c	Mon Oct 27 16:23:10 2008 +0100
    28.3 @@ -21,191 +21,201 @@
    28.4  #include "sysexits.h"
    28.5  
    28.6  static char *_sysexit_strings[] = {
    28.7 -  "command line usage error",
    28.8 -  "data format error",
    28.9 -  "cannot open input",
   28.10 -  "addressee unknown",
   28.11 -  "host name unknown",
   28.12 -  "service unavailable",
   28.13 -  "internal software error",
   28.14 -  "system error (e.g., can't fork)",
   28.15 -  "critical OS file missing",
   28.16 -  "can't create (user) output file",
   28.17 -  "input/output error",
   28.18 -  "temp failure; user is invited to retry",
   28.19 -  "remote error in protocol",
   28.20 -  "permission denied",
   28.21 -  "configuration error"
   28.22 +	"command line usage error",
   28.23 +	"data format error",
   28.24 +	"cannot open input",
   28.25 +	"addressee unknown",
   28.26 +	"host name unknown",
   28.27 +	"service unavailable",
   28.28 +	"internal software error",
   28.29 +	"system error (e.g., can't fork)",
   28.30 +	"critical OS file missing",
   28.31 +	"can't create (user) output file",
   28.32 +	"input/output error",
   28.33 +	"temp failure; user is invited to retry",
   28.34 +	"remote error in protocol",
   28.35 +	"permission denied",
   28.36 +	"configuration error"
   28.37  };
   28.38  
   28.39 -gchar *ext_strerror(int err)
   28.40 +gchar*
   28.41 +ext_strerror(int err)
   28.42  {
   28.43 -  if(err < 1024)
   28.44 -    return strerror(err);
   28.45 -  else
   28.46 -    if(err > 1024 + EX__BASE &&
   28.47 -       (err - 1024 - EX__BASE < sizeof(_sysexit_strings)/sizeof(_sysexit_strings[0])))
   28.48 -      return _sysexit_strings[err - 1024 - EX__BASE];
   28.49 +	if (err < 1024)
   28.50 +		return strerror(err);
   28.51 +	else if (err > 1024 + EX__BASE
   28.52 +	         && (err - 1024 - EX__BASE < sizeof(_sysexit_strings) / sizeof(_sysexit_strings[0])))
   28.53 +		return _sysexit_strings[err - 1024 - EX__BASE];
   28.54  
   28.55 -  return "unknown error";
   28.56 +	return "unknown error";
   28.57  }
   28.58  
   28.59  static FILE *logfile = NULL;
   28.60  static FILE *debugfile = NULL;
   28.61  
   28.62 -gboolean logopen()
   28.63 +gboolean
   28.64 +logopen()
   28.65  {
   28.66 -  gchar *filename;
   28.67 -  mode_t saved_mode = umask(066);
   28.68 +	gchar *filename;
   28.69 +	mode_t saved_mode = umask(066);
   28.70  
   28.71 -  if(conf.use_syslog){
   28.72 -    openlog(PACKAGE, LOG_PID, LOG_MAIL);
   28.73 -  }else{
   28.74 -    uid_t saved_uid;
   28.75 -    gid_t saved_gid;
   28.76 -    
   28.77 -    saved_gid = setegid(conf.mail_gid);
   28.78 -    saved_uid = seteuid(conf.mail_uid);
   28.79 +	if (conf.use_syslog) {
   28.80 +		openlog(PACKAGE, LOG_PID, LOG_MAIL);
   28.81 +	} else {
   28.82 +		uid_t saved_uid;
   28.83 +		gid_t saved_gid;
   28.84  
   28.85 -    filename = g_strdup_printf("%s/masqmail.log", conf.log_dir);
   28.86 -    logfile = fopen(filename, "a");
   28.87 -    if(!logfile){
   28.88 -      fprintf(stderr, "could not open log '%s': %s\n", filename, strerror(errno));
   28.89 -      return FALSE;
   28.90 -    }
   28.91 -    g_free(filename);
   28.92 +		saved_gid = setegid(conf.mail_gid);
   28.93 +		saved_uid = seteuid(conf.mail_uid);
   28.94  
   28.95 -    seteuid(saved_uid);
   28.96 -    setegid(saved_gid);
   28.97 -  }
   28.98 +		filename = g_strdup_printf("%s/masqmail.log", conf.log_dir);
   28.99 +		logfile = fopen(filename, "a");
  28.100 +		if (!logfile) {
  28.101 +			fprintf(stderr, "could not open log '%s': %s\n", filename, strerror(errno));
  28.102 +			return FALSE;
  28.103 +		}
  28.104 +		g_free(filename);
  28.105 +
  28.106 +		seteuid(saved_uid);
  28.107 +		setegid(saved_gid);
  28.108 +	}
  28.109  
  28.110  #ifdef ENABLE_DEBUG
  28.111 -  if(conf.debug_level > 0){
  28.112 -    filename = g_strdup_printf("%s/debug.log", conf.log_dir);
  28.113 -    debugfile = fopen(filename, "a");
  28.114 -    if(!debugfile){
  28.115 -      fprintf(stderr, "could not open debug log '%s'\n", filename);
  28.116 -      return FALSE;
  28.117 -    }
  28.118 -    g_free(filename);
  28.119 -  }
  28.120 +	if (conf.debug_level > 0) {
  28.121 +		filename = g_strdup_printf("%s/debug.log", conf.log_dir);
  28.122 +		debugfile = fopen(filename, "a");
  28.123 +		if (!debugfile) {
  28.124 +			fprintf(stderr, "could not open debug log '%s'\n", filename);
  28.125 +			return FALSE;
  28.126 +		}
  28.127 +		g_free(filename);
  28.128 +	}
  28.129  #endif
  28.130 -  umask(saved_mode);
  28.131 -  return TRUE;
  28.132 +	umask(saved_mode);
  28.133 +	return TRUE;
  28.134  }
  28.135  
  28.136 -void logclose()
  28.137 +void
  28.138 +logclose()
  28.139  {
  28.140 -  if(conf.use_syslog)
  28.141 -    closelog();
  28.142 -  else
  28.143 -    if(logfile) fclose(logfile);
  28.144 -  if(debugfile) fclose(debugfile);
  28.145 +	if (conf.use_syslog)
  28.146 +		closelog();
  28.147 +	else if (logfile)
  28.148 +		fclose(logfile);
  28.149 +	if (debugfile)
  28.150 +		fclose(debugfile);
  28.151  }
  28.152  
  28.153 -void vlogwrite(int pri, const char *fmt, va_list args)
  28.154 +void
  28.155 +vlogwrite(int pri, const char *fmt, va_list args)
  28.156  {
  28.157 -  if((conf.do_verbose && (pri & LOG_VERBOSE)) || (pri == LOG_ALERT) || (pri == LOG_WARNING)){
  28.158 -    va_list args_copy;
  28.159 -    va_copy(args_copy, args);
  28.160 -    vfprintf(stdout, fmt, args_copy);
  28.161 -    va_end(args_copy);
  28.162 -    fflush(stdout); /* is this necessary? */
  28.163 -  }
  28.164 +	if ((conf.do_verbose && (pri & LOG_VERBOSE)) || (pri == LOG_ALERT)
  28.165 +		|| (pri == LOG_WARNING)) {
  28.166 +		va_list args_copy;
  28.167 +		va_copy(args_copy, args);
  28.168 +		vfprintf(stdout, fmt, args_copy);
  28.169 +		va_end(args_copy);
  28.170 +		fflush(stdout);  /* is this necessary? */
  28.171 +	}
  28.172  
  28.173 -  pri &= ~LOG_VERBOSE;
  28.174 -  if(pri){
  28.175 +	pri &= ~LOG_VERBOSE;
  28.176 +	if (pri) {
  28.177  
  28.178 -    if(conf.use_syslog)
  28.179 -      vsyslog(pri, fmt, args);
  28.180 -    else{
  28.181 -      if(pri <= conf.log_max_pri){
  28.182 -	FILE *file = logfile ? logfile : stderr;
  28.183 +		if (conf.use_syslog)
  28.184 +			vsyslog(pri, fmt, args);
  28.185 +		else {
  28.186 +			if (pri <= conf.log_max_pri) {
  28.187 +				FILE *file = logfile ? logfile : stderr;
  28.188 +				time_t now = time(NULL);
  28.189 +				struct tm *t = localtime(&now);
  28.190 +				gchar buf[24];
  28.191 +				uid_t saved_uid;
  28.192 +				gid_t saved_gid;
  28.193 +
  28.194 +				saved_gid = setegid(conf.mail_gid);
  28.195 +				saved_uid = seteuid(conf.mail_uid);
  28.196 +
  28.197 +				strftime(buf, 24, "%Y-%m-%d %H:%M:%S", t);
  28.198 +				fprintf(file, "%s [%d] ", buf, getpid());
  28.199 +
  28.200 +				vfprintf(file, fmt, args);
  28.201 +				fflush(file);
  28.202 +
  28.203 +				seteuid(saved_uid);
  28.204 +				setegid(saved_gid);
  28.205 +			}
  28.206 +		}
  28.207 +	}
  28.208 +}
  28.209 +
  28.210 +#ifdef ENABLE_DEBUG
  28.211 +void
  28.212 +vdebugwrite(int pri, const char *fmt, va_list args)
  28.213 +{
  28.214  	time_t now = time(NULL);
  28.215  	struct tm *t = localtime(&now);
  28.216  	gchar buf[24];
  28.217 -	uid_t saved_uid;
  28.218 -	gid_t saved_gid;
  28.219 +	strftime(buf, 24, "%Y-%m-%d %H:%M:%S", t);
  28.220  
  28.221 -	saved_gid = setegid(conf.mail_gid);
  28.222 -	saved_uid = seteuid(conf.mail_uid);
  28.223 +	if (debugfile) {
  28.224 +		fprintf(debugfile, "%s [%d] ", buf, getpid());
  28.225  
  28.226 -	strftime(buf, 24, "%Y-%m-%d %H:%M:%S", t);
  28.227 -	fprintf(file, "%s [%d] ", buf, getpid());
  28.228 -	
  28.229 -	vfprintf(file, fmt, args);
  28.230 -	fflush(file);
  28.231 -
  28.232 -	seteuid(saved_uid);
  28.233 -	setegid(saved_gid);
  28.234 -      }
  28.235 -    }
  28.236 -  }
  28.237 -}  
  28.238 -
  28.239 -#ifdef ENABLE_DEBUG
  28.240 -void vdebugwrite(int pri, const char *fmt, va_list args)
  28.241 -{
  28.242 -  time_t now = time(NULL);
  28.243 -  struct tm *t = localtime(&now);
  28.244 -  gchar buf[24];
  28.245 -  strftime(buf, 24, "%Y-%m-%d %H:%M:%S", t);
  28.246 -
  28.247 -  if(debugfile){
  28.248 -    fprintf(debugfile, "%s [%d] ", buf, getpid());
  28.249 -  
  28.250 -    vfprintf(debugfile, fmt, args);
  28.251 -    fflush(debugfile);
  28.252 -  }else{
  28.253 -    fprintf(stderr, "no debug file, msg was:\n");
  28.254 -    vfprintf(stderr, fmt, args);
  28.255 -  }
  28.256 +		vfprintf(debugfile, fmt, args);
  28.257 +		fflush(debugfile);
  28.258 +	} else {
  28.259 +		fprintf(stderr, "no debug file, msg was:\n");
  28.260 +		vfprintf(stderr, fmt, args);
  28.261 +	}
  28.262  }
  28.263  #endif
  28.264  
  28.265 -void logwrite(int pri, const char *fmt, ...)
  28.266 +void
  28.267 +logwrite(int pri, const char *fmt, ...)
  28.268  {
  28.269 -  va_list args, args_copy;
  28.270 -  int saved_errno = errno; /* somewhere this is changed to EBADF */
  28.271 +	va_list args, args_copy;
  28.272 +	int saved_errno = errno;  /* somewhere this is changed to EBADF */
  28.273  
  28.274 -  va_start(args, fmt);
  28.275 +	va_start(args, fmt);
  28.276  #ifdef ENABLE_DEBUG
  28.277 -  va_copy(args_copy, args);
  28.278 +	va_copy(args_copy, args);
  28.279  #endif
  28.280 -  vlogwrite(pri, fmt, args);
  28.281 +	vlogwrite(pri, fmt, args);
  28.282  #ifdef ENABLE_DEBUG
  28.283 -  if(debugfile)
  28.284 -    vdebugwrite(pri, fmt, args_copy);
  28.285 -  va_end(args_copy);
  28.286 +	if (debugfile)
  28.287 +		vdebugwrite(pri, fmt, args_copy);
  28.288 +	va_end(args_copy);
  28.289  #endif
  28.290 -  va_end(args);
  28.291 +	va_end(args);
  28.292  
  28.293 -  errno = saved_errno;
  28.294 +	errno = saved_errno;
  28.295  }
  28.296  
  28.297  #ifdef ENABLE_DEBUG
  28.298 -void debugf(const char *fmt, ...)
  28.299 +void
  28.300 +debugf(const char *fmt, ...)
  28.301  {
  28.302 -  va_list args;
  28.303 -  va_start(args, fmt);
  28.304 +	va_list args;
  28.305 +	va_start(args, fmt);
  28.306  
  28.307 -  vdebugwrite(LOG_DEBUG, fmt, args);
  28.308 +	vdebugwrite(LOG_DEBUG, fmt, args);
  28.309  
  28.310 -  va_end(args);
  28.311 +	va_end(args);
  28.312  }
  28.313  
  28.314 -void vdebugf(const char *fmt, va_list args)
  28.315 +void
  28.316 +vdebugf(const char *fmt, va_list args)
  28.317  {
  28.318 -  vdebugwrite(LOG_DEBUG, fmt, args);
  28.319 +	vdebugwrite(LOG_DEBUG, fmt, args);
  28.320  }
  28.321  #endif
  28.322  
  28.323 -void maillog(const char *fmt, ...)
  28.324 +void
  28.325 +maillog(const char *fmt, ...)
  28.326  {
  28.327 -  va_list args;
  28.328 -  va_start(args, fmt);
  28.329 +	va_list args;
  28.330 +	va_start(args, fmt);
  28.331  
  28.332 -  vlogwrite(LOG_NOTICE, fmt, args);
  28.333 +	vlogwrite(LOG_NOTICE, fmt, args);
  28.334  
  28.335 -  va_end(args);
  28.336 +	va_end(args);
  28.337  }
    29.1 --- a/src/lookup.c	Mon Oct 27 16:21:27 2008 +0100
    29.2 +++ b/src/lookup.c	Mon Oct 27 16:23:10 2008 +0100
    29.3 @@ -4,7 +4,7 @@
    29.4   * it under the terms of the GNU General Public License as published by
    29.5   * the Free Software Foundation; either version 2 of the License, or
    29.6   * (at your option) any later version.
    29.7 - * 
    29.8 + *
    29.9   * This program is distributed in the hope that it will be useful,
   29.10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   29.11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   29.12 @@ -33,8 +33,8 @@
   29.13  #ifdef ENABLE_RESOLVER
   29.14  
   29.15  static union {
   29.16 -  HEADER hdr;
   29.17 -  unsigned char buf[PACKETSZ];
   29.18 +	HEADER hdr;
   29.19 +	unsigned char buf[PACKETSZ];
   29.20  } response;
   29.21  static unsigned char *resp_end;
   29.22  static unsigned char *resp_pos;
   29.23 @@ -45,139 +45,143 @@
   29.24  unsigned short rr_type;
   29.25  unsigned short rr_dlen;
   29.26  
   29.27 -static
   29.28 -unsigned short getshort(unsigned char *c)
   29.29 +static unsigned short
   29.30 +getshort(unsigned char *c)
   29.31  {
   29.32 -  unsigned short u;
   29.33 -  u = c[0];
   29.34 -  return (u << 8) + c[1];
   29.35 +	unsigned short u;
   29.36 +	u = c[0];
   29.37 +	return (u << 8) + c[1];
   29.38  }
   29.39  
   29.40 -static
   29.41 -int dns_resolve(char *domain, int type, gboolean do_search)
   29.42 +static int
   29.43 +dns_resolve(char *domain, int type, gboolean do_search)
   29.44  {
   29.45 -  int n;
   29.46 -  int i;
   29.47 +	int n;
   29.48 +	int i;
   29.49  
   29.50 -  int resp_len;
   29.51 -  /*errno = 0;*/
   29.52 +	int resp_len;
   29.53 +	/*errno = 0; */
   29.54  
   29.55 -  /*
   29.56 -  if (!stralloc_copy(&glue,domain)) return DNS_MEM;
   29.57 -  if (!stralloc_0(&glue)) return DNS_MEM;
   29.58 -  */
   29.59 +	/*
   29.60 +	   if (!stralloc_copy(&glue,domain)) return DNS_MEM;
   29.61 +	   if (!stralloc_0(&glue)) return DNS_MEM;
   29.62 +	 */
   29.63  
   29.64 -  //  resp_len = res_query(domain, C_IN, type, response.buf, sizeof(response));
   29.65 -  DEBUG(5) debugf("DNS: before res_search()\n");
   29.66 -  if(do_search)
   29.67 -    resp_len = res_search(domain, C_IN, type, response.buf, sizeof(response));
   29.68 -  else
   29.69 -    resp_len = res_query(domain, C_IN, type, response.buf, sizeof(response));
   29.70 -  DEBUG(5) debugf("DBG: after res_search()\n");
   29.71 +	//  resp_len = res_query(domain, C_IN, type, response.buf, sizeof(response));
   29.72 +	DEBUG(5) debugf("DNS: before res_search()\n");
   29.73 +	if (do_search)
   29.74 +		resp_len = res_search(domain, C_IN, type, response.buf, sizeof(response));
   29.75 +	else
   29.76 +		resp_len = res_query(domain, C_IN, type, response.buf, sizeof(response));
   29.77 +	DEBUG(5) debugf("DBG: after res_search()\n");
   29.78  
   29.79 -  if (resp_len <= 0){
   29.80 -    /*
   29.81 -    if (errno == ECONNREFUSED) return DNS_SOFT;
   29.82 -    if (h_errno == TRY_AGAIN) return DNS_SOFT;
   29.83 -    return DNS_HARD;
   29.84 -    */
   29.85 -    return -1;
   29.86 -  }
   29.87 -  if (resp_len >= sizeof(response))
   29.88 -    resp_len = sizeof(response);
   29.89 +	if (resp_len <= 0) {
   29.90 +		/*
   29.91 +		   if (errno == ECONNREFUSED) return DNS_SOFT;
   29.92 +		   if (h_errno == TRY_AGAIN) return DNS_SOFT;
   29.93 +		   return DNS_HARD;
   29.94 +		 */
   29.95 +		return -1;
   29.96 +	}
   29.97 +	if (resp_len >= sizeof(response))
   29.98 +		resp_len = sizeof(response);
   29.99  
  29.100 -  resp_end = response.buf + resp_len;
  29.101 -  resp_pos = response.buf + sizeof(HEADER);
  29.102 -  n = ntohs(response.hdr.qdcount);
  29.103 +	resp_end = response.buf + resp_len;
  29.104 +	resp_pos = response.buf + sizeof(HEADER);
  29.105 +	n = ntohs(response.hdr.qdcount);
  29.106  
  29.107 -  while (n-- > 0){
  29.108 -    i = dn_expand(response.buf, resp_end, resp_pos, name, MAX_DNSNAME);
  29.109 -    if (i < 0)
  29.110 -      return -1;
  29.111 -    DEBUG(5) debugf("DBG: resolve name = %s\n", name);
  29.112 -    resp_pos += i;
  29.113 -    i = resp_end - resp_pos;
  29.114 -    if (i < QFIXEDSZ)
  29.115 -      return -1;
  29.116 -    resp_pos += QFIXEDSZ;
  29.117 -  }
  29.118 -  num_answers = ntohs(response.hdr.ancount);
  29.119 +	while (n-- > 0) {
  29.120 +		i = dn_expand(response.buf, resp_end, resp_pos, name, MAX_DNSNAME);
  29.121 +		if (i < 0)
  29.122 +			return -1;
  29.123 +		DEBUG(5) debugf("DBG: resolve name = %s\n", name);
  29.124 +		resp_pos += i;
  29.125 +		i = resp_end - resp_pos;
  29.126 +		if (i < QFIXEDSZ)
  29.127 +			return -1;
  29.128 +		resp_pos += QFIXEDSZ;
  29.129 +	}
  29.130 +	num_answers = ntohs(response.hdr.ancount);
  29.131  
  29.132 -  return 0;
  29.133 +	return 0;
  29.134  }
  29.135  
  29.136 -static int dns_next()
  29.137 +static int
  29.138 +dns_next()
  29.139  {
  29.140 -  int i;
  29.141 +	int i;
  29.142  
  29.143 -  if (num_answers <= 0) return 2;
  29.144 -  num_answers--;
  29.145 +	if (num_answers <= 0)
  29.146 +		return 2;
  29.147 +	num_answers--;
  29.148  
  29.149 -  if (resp_pos == resp_end)
  29.150 -    return -1 /* soft */;
  29.151 +	if (resp_pos == resp_end)
  29.152 +		return -1;  /* soft */
  29.153  
  29.154 -  i = dn_expand(response.buf, resp_end, resp_pos, name, 256);
  29.155 -  if (i < 0)
  29.156 -    return -1; /* soft */
  29.157 -  resp_pos += i;
  29.158 +	i = dn_expand(response.buf, resp_end, resp_pos, name, 256);
  29.159 +	if (i < 0)
  29.160 +		return -1;  /* soft */
  29.161 +	resp_pos += i;
  29.162  
  29.163 -  i = resp_end - resp_pos;
  29.164 -  if (i < 4 + 3 * 2)
  29.165 -    return -1; /* soft */
  29.166 -   
  29.167 -  rr_type = getshort(resp_pos);
  29.168 -  rr_dlen = getshort(resp_pos + 8);
  29.169 -  resp_pos += 10;
  29.170 +	i = resp_end - resp_pos;
  29.171 +	if (i < 4 + 3 * 2)
  29.172 +		return -1;  /* soft */
  29.173  
  29.174 -  return 0;
  29.175 +	rr_type = getshort(resp_pos);
  29.176 +	rr_dlen = getshort(resp_pos + 8);
  29.177 +	resp_pos += 10;
  29.178 +
  29.179 +	return 0;
  29.180  }
  29.181  
  29.182 -static
  29.183 -int dns_getip(guint32 *ip)
  29.184 +static int
  29.185 +dns_getip(guint32 * ip)
  29.186  {
  29.187 -  int ret;
  29.188 +	int ret;
  29.189  
  29.190 -  if((ret = dns_next())) return ret;
  29.191 +	if ((ret = dns_next()))
  29.192 +		return ret;
  29.193  
  29.194 -  if (rr_type == T_A){
  29.195 -    if (rr_dlen < 4)
  29.196 -      return -1; /* soft */
  29.197 -    *ip = *(guint32 *)(resp_pos);
  29.198 -    DEBUG(5) debugf("DNS: dns_getip(): ip = %s\n", inet_ntoa(*(struct in_addr*)ip));
  29.199 -    resp_pos += rr_dlen;
  29.200 +	if (rr_type == T_A) {
  29.201 +		if (rr_dlen < 4)
  29.202 +			return -1;  /* soft */
  29.203 +		*ip = *(guint32 *) (resp_pos);
  29.204 +		DEBUG(5) debugf("DNS: dns_getip(): ip = %s\n", inet_ntoa(*(struct in_addr *) ip));
  29.205 +		resp_pos += rr_dlen;
  29.206  
  29.207 -    return 1;
  29.208 -  }
  29.209 -  resp_pos += rr_dlen;
  29.210 -  return 0;
  29.211 +		return 1;
  29.212 +	}
  29.213 +	resp_pos += rr_dlen;
  29.214 +	return 0;
  29.215  }
  29.216  
  29.217 -static
  29.218 -int dns_getmx(int *pref)
  29.219 +static int
  29.220 +dns_getmx(int *pref)