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)
  29.221  {
  29.222 -  int ret;
  29.223 +	int ret;
  29.224  
  29.225 -  if((ret = dns_next())) return ret;
  29.226 +	if ((ret = dns_next()))
  29.227 +		return ret;
  29.228  
  29.229 -  if (rr_type == T_MX){
  29.230 -    if (rr_dlen < 3)
  29.231 -      return -1; /* soft */
  29.232 +	if (rr_type == T_MX) {
  29.233 +		if (rr_dlen < 3)
  29.234 +			return -1;  /* soft */
  29.235  
  29.236 -    *pref = (resp_pos[0] << 8) + resp_pos[1];
  29.237 -    if (dn_expand(response.buf, resp_end, resp_pos + 2, name, MAX_DNSNAME) < 0)
  29.238 -      return -1;
  29.239 -   
  29.240 -    resp_pos += rr_dlen;
  29.241 +		*pref = (resp_pos[0] << 8) + resp_pos[1];
  29.242 +		if (dn_expand(response.buf, resp_end, resp_pos + 2, name, MAX_DNSNAME) < 0)
  29.243 +			return -1;
  29.244  
  29.245 -    return 1;
  29.246 -  }
  29.247 -  resp_pos += rr_dlen;
  29.248 -  return 0;
  29.249 +		resp_pos += rr_dlen;
  29.250 +
  29.251 +		return 1;
  29.252 +	}
  29.253 +	resp_pos += rr_dlen;
  29.254 +	return 0;
  29.255  }
  29.256  
  29.257  /*
  29.258 -static
  29.259 -int dns_getname(int type)
  29.260 +static int
  29.261 +dns_getname(int type)
  29.262  {
  29.263    int ret;
  29.264  
  29.265 @@ -186,7 +190,7 @@
  29.266    if (rr_type == type){
  29.267      if (dn_expand(response.buf, resp_end, resp_pos, name, MAX_DNSNAME) < 0)
  29.268        return -1;
  29.269 -   
  29.270 +
  29.271      resp_pos += rr_dlen;
  29.272  
  29.273      return 1;
  29.274 @@ -196,181 +200,177 @@
  29.275  }
  29.276  */
  29.277  
  29.278 -static
  29.279 -int dns_look_ip(gchar *domain, guint32 *ip)
  29.280 +static int
  29.281 +dns_look_ip(gchar * domain, guint32 * ip)
  29.282  {
  29.283 -  gchar *n = domain;
  29.284 +	gchar *n = domain;
  29.285  
  29.286 -  while(TRUE){
  29.287 -    if(dns_resolve(n, T_A, FALSE) == 0){
  29.288 -      dns_next();
  29.289 -      if(rr_type == T_A){
  29.290 -	if (rr_dlen < 4)
  29.291 -	  return -1; /* soft */
  29.292 -	*ip = *(guint32 *)(resp_pos);
  29.293 -	
  29.294 -	DEBUG(5) debugf("DNS: dns_look_ip(): ip = %s\n",
  29.295 -			inet_ntoa(*(struct in_addr*)ip));
  29.296 -	
  29.297 -	resp_pos += rr_dlen;
  29.298 -	return 0;
  29.299 -      }else if(rr_type == T_CNAME){
  29.300 -	if (dn_expand(response.buf, resp_end, resp_pos, name, MAX_DNSNAME) < 0)
  29.301 -	  return -1;
  29.302 +	while (TRUE) {
  29.303 +		if (dns_resolve(n, T_A, FALSE) == 0) {
  29.304 +			dns_next();
  29.305 +			if (rr_type == T_A) {
  29.306 +				if (rr_dlen < 4)
  29.307 +					return -1;  /* soft */
  29.308 +				*ip = *(guint32 *) (resp_pos);
  29.309  
  29.310 -	DEBUG(5) debugf("DNS: (CNAME) dns_look_ip(): name = %s\n", name);
  29.311 -	
  29.312 -	resp_pos += rr_dlen;
  29.313 -	n = name;
  29.314 -      }else
  29.315 -	return -1;
  29.316 -    }else
  29.317 -      return -1;
  29.318 -  }
  29.319 +				DEBUG(5) debugf("DNS: dns_look_ip(): ip = %s\n", inet_ntoa(*(struct in_addr *) ip));
  29.320 +
  29.321 +				resp_pos += rr_dlen;
  29.322 +				return 0;
  29.323 +			} else if (rr_type == T_CNAME) {
  29.324 +				if (dn_expand(response.buf, resp_end, resp_pos, name, MAX_DNSNAME) < 0)
  29.325 +					return -1;
  29.326 +
  29.327 +				DEBUG(5) debugf("DNS: (CNAME) dns_look_ip(): name = %s\n", name);
  29.328 +
  29.329 +				resp_pos += rr_dlen;
  29.330 +				n = name;
  29.331 +			} else
  29.332 +				return -1;
  29.333 +		} else
  29.334 +			return -1;
  29.335 +	}
  29.336  }
  29.337  
  29.338 -GList *resolve_dns_a(GList *list, gchar *domain)
  29.339 +GList*
  29.340 +resolve_dns_a(GList * list, gchar * domain)
  29.341  {
  29.342 -  int ret;
  29.343 +	int ret;
  29.344  
  29.345 -  DEBUG(5) debugf("DNS: resolve_dns_a entered\n");
  29.346 +	DEBUG(5) debugf("DNS: resolve_dns_a entered\n");
  29.347  
  29.348 -  if(dns_resolve(domain, T_A, TRUE) == 0){
  29.349 -    mxip_addr mxip;
  29.350 -    while((ret = dns_getip(&(mxip.ip))) != 2){
  29.351 -      if(ret == 1){
  29.352 -	mxip.name = g_strdup(name);
  29.353 -	mxip.pref = 0;
  29.354 -	list = g_list_append(list, g_memdup(&mxip, sizeof(mxip)));
  29.355 -      }
  29.356 -    }
  29.357 -  }
  29.358 -  return list;
  29.359 +	if (dns_resolve(domain, T_A, TRUE) == 0) {
  29.360 +		mxip_addr mxip;
  29.361 +		while ((ret = dns_getip(&(mxip.ip))) != 2) {
  29.362 +			if (ret == 1) {
  29.363 +				mxip.name = g_strdup(name);
  29.364 +				mxip.pref = 0;
  29.365 +				list = g_list_append(list, g_memdup(&mxip, sizeof(mxip)));
  29.366 +			}
  29.367 +		}
  29.368 +	}
  29.369 +	return list;
  29.370  }
  29.371  
  29.372 -static
  29.373 -gint _mx_sort_func(gconstpointer aa, gconstpointer bb)
  29.374 +static gint
  29.375 +_mx_sort_func(gconstpointer aa, gconstpointer bb)
  29.376  {
  29.377 -  const mxip_addr *a = (mxip_addr *)aa;
  29.378 -  const mxip_addr *b = (mxip_addr *)bb;
  29.379 +	const mxip_addr *a = (mxip_addr *) aa;
  29.380 +	const mxip_addr *b = (mxip_addr *) bb;
  29.381  
  29.382 -  if(a->pref == b->pref)
  29.383 -    return a->ip - b->ip;
  29.384 -  else
  29.385 -    return a->pref - b->pref;
  29.386 +	if (a->pref == b->pref)
  29.387 +		return a->ip - b->ip;
  29.388 +	else
  29.389 +		return a->pref - b->pref;
  29.390  }
  29.391  
  29.392 -GList *resolve_dns_mx(GList *list, gchar *domain)
  29.393 +GList*
  29.394 +resolve_dns_mx(GList * list, gchar * domain)
  29.395  {
  29.396 -  GList *node;
  29.397 -  int ret;
  29.398 -  int cnt = 0;
  29.399 +	GList *node;
  29.400 +	int ret;
  29.401 +	int cnt = 0;
  29.402  
  29.403 -  DEBUG(5) debugf("DNS: resolve_dns_mx entered\n");
  29.404 +	DEBUG(5) debugf("DNS: resolve_dns_mx entered\n");
  29.405  
  29.406 -  if(dns_resolve(domain, T_MX, TRUE) == 0){
  29.407 -    GList *node_next;
  29.408 -    mxip_addr mxip;
  29.409 -    while((ret = dns_getmx(&(mxip.pref))) != 2){
  29.410 -      if(ret == 1){
  29.411 -	mxip.name = g_strdup(name);
  29.412 -	mxip.ip = rand();
  29.413 -	list = g_list_append(list, g_memdup(&mxip, sizeof(mxip)));
  29.414 -	cnt++;
  29.415 -      }
  29.416 -    }
  29.417 +	if (dns_resolve(domain, T_MX, TRUE) == 0) {
  29.418 +		GList *node_next;
  29.419 +		mxip_addr mxip;
  29.420 +		while ((ret = dns_getmx(&(mxip.pref))) != 2) {
  29.421 +			if (ret == 1) {
  29.422 +				mxip.name = g_strdup(name);
  29.423 +				mxip.ip = rand();
  29.424 +				list = g_list_append(list, g_memdup(&mxip, sizeof(mxip)));
  29.425 +				cnt++;
  29.426 +			}
  29.427 +		}
  29.428  
  29.429 -    DEBUG(5) debugf("DNS: found %d mx records\n", cnt);
  29.430 +		DEBUG(5) debugf("DNS: found %d mx records\n", cnt);
  29.431  
  29.432 -    /* to randomize sequences with equal pref values,
  29.433 -       we temporarily 'misused' the ip field and
  29.434 -       put a random number in it as a secondary sort key.
  29.435 -    */
  29.436 -    list = g_list_sort(list, _mx_sort_func);
  29.437 +		/* to randomize sequences with equal pref values,
  29.438 +		   we temporarily 'misused' the ip field and
  29.439 +		   put a random number in it as a secondary sort key.
  29.440 +		 */
  29.441 +		list = g_list_sort(list, _mx_sort_func);
  29.442  
  29.443 -    /* CNAME resolving has to be added as well. */
  29.444 +		/* CNAME resolving has to be added as well. */
  29.445  
  29.446 -    for(node = g_list_first(list);
  29.447 -	node != NULL;
  29.448 -	node = node_next){
  29.449 +		for (node = g_list_first(list); node != NULL; node = node_next) {
  29.450  
  29.451 -      mxip_addr *p_mxip = (mxip_addr *)(node->data);
  29.452 -      node_next = g_list_next(node);
  29.453 +			mxip_addr *p_mxip = (mxip_addr *) (node->data);
  29.454 +			node_next = g_list_next(node);
  29.455  
  29.456 -      if(dns_look_ip(p_mxip->name, &(p_mxip->ip)) != 0){
  29.457 -	DEBUG(1) debugf("DNS: could not resolve target of mx %s\n", p_mxip->name);
  29.458 -	list = g_list_remove_link(list, node);
  29.459 -	g_free(node->data);
  29.460 -	g_list_free_1(node);
  29.461 -      }
  29.462 -    }
  29.463 -  }
  29.464 -  return list;
  29.465 +			if (dns_look_ip(p_mxip->name, &(p_mxip->ip)) != 0) {
  29.466 +				DEBUG(1) debugf("DNS: could not resolve target of mx %s\n", p_mxip->name);
  29.467 +				list = g_list_remove_link(list, node);
  29.468 +				g_free(node->data);
  29.469 +				g_list_free_1(node);
  29.470 +			}
  29.471 +		}
  29.472 +	}
  29.473 +	return list;
  29.474  }
  29.475  
  29.476  #endif
  29.477  
  29.478  /* now something completely different... */
  29.479  
  29.480 -GList *resolve_byname(GList *list, gchar *domain)
  29.481 +GList*
  29.482 +resolve_byname(GList * list, gchar * domain)
  29.483  {
  29.484 -  struct hostent *hent;
  29.485 +	struct hostent *hent;
  29.486  
  29.487 -  DEBUG(5) debugf("DNS: resolve_byname entered\n");
  29.488 +	DEBUG(5) debugf("DNS: resolve_byname entered\n");
  29.489  
  29.490 -  if((hent = gethostbyname(domain))){
  29.491 -    char *haddr;
  29.492 -    int i = 0;
  29.493 -    while((haddr = hent->h_addr_list[i++])){
  29.494 -      mxip_addr mxip;
  29.495 -      mxip.ip = *(guint32 *)(haddr);
  29.496 -      mxip.pref = 0;
  29.497 -      mxip.name = g_strdup(hent->h_name);
  29.498 -      list = g_list_append(list, g_memdup(&mxip, sizeof(mxip)));
  29.499 -    }
  29.500 -  }
  29.501 -  return list;
  29.502 +	if ((hent = gethostbyname(domain))) {
  29.503 +		char *haddr;
  29.504 +		int i = 0;
  29.505 +		while ((haddr = hent->h_addr_list[i++])) {
  29.506 +			mxip_addr mxip;
  29.507 +			mxip.ip = *(guint32 *) (haddr);
  29.508 +			mxip.pref = 0;
  29.509 +			mxip.name = g_strdup(hent->h_name);
  29.510 +			list = g_list_append(list, g_memdup(&mxip, sizeof(mxip)));
  29.511 +		}
  29.512 +	}
  29.513 +	return list;
  29.514  }
  29.515  
  29.516  #ifdef RESOLV_TEST
  29.517 -int main(int argc, char *argv[])
  29.518 +int
  29.519 +main(int argc, char *argv[])
  29.520  {
  29.521 -  GList *addr_list = NULL, *node;
  29.522 +	GList *addr_list = NULL, *node;
  29.523  
  29.524 -  g_print("starting res_init()\n");
  29.525 +	g_print("starting res_init()\n");
  29.526  
  29.527 -  g_print("retrans = %d, retry = %d\n", _res.retrans, _res.retry);
  29.528 +	g_print("retrans = %d, retry = %d\n", _res.retrans, _res.retry);
  29.529  
  29.530 -  if(res_init() == 0){
  29.531 -    
  29.532 -    addr_list = resolve_dns_a(NULL, argv[1]);
  29.533 -    g_print("A:\n");
  29.534 +	if (res_init() == 0) {
  29.535  
  29.536 -    foreach(addr_list, node){
  29.537 -      mxip_addr *p_mxip = (mxip_addr *)(node->data);
  29.538 -    
  29.539 -      printf("name = %s\n IP = %s\n",
  29.540 -	     p_mxip->name,
  29.541 -	     inet_ntoa(*(struct in_addr *)&(p_mxip->ip)));
  29.542 -    }
  29.543 -    addr_list = resolve_dns_mx(NULL, argv[1]);
  29.544 -    g_print("MX:\n");
  29.545 +		addr_list = resolve_dns_a(NULL, argv[1]);
  29.546 +		g_print("A:\n");
  29.547  
  29.548 -    foreach(addr_list, node){
  29.549 -      mxip_addr *p_mxip = (mxip_addr *)(node->data);
  29.550 -    
  29.551 -      printf("name = %s\n IP = %s pref = %d\n",
  29.552 -	     p_mxip->name,
  29.553 -	     inet_ntoa(*(struct in_addr *)&(p_mxip->ip)),
  29.554 -	     p_mxip->pref);
  29.555 -    }
  29.556 -    {
  29.557 -      guint32 ip;
  29.558 -      dns_look_ip(argv[1], &ip);
  29.559 -      printf("dns_look_ip: %s\n", inet_ntoa(*((struct in_addr *)(&ip))));
  29.560 -    }
  29.561 -  }else
  29.562 -    printf("res_init() failed.\n");
  29.563 -  
  29.564 +		foreach(addr_list, node) {
  29.565 +			mxip_addr *p_mxip = (mxip_addr *) (node->data);
  29.566 +
  29.567 +			printf("name = %s\n IP = %s\n", p_mxip->name, inet_ntoa(*(struct in_addr *) &(p_mxip->ip)));
  29.568 +		}
  29.569 +		addr_list = resolve_dns_mx(NULL, argv[1]);
  29.570 +		g_print("MX:\n");
  29.571 +
  29.572 +		foreach(addr_list, node) {
  29.573 +			mxip_addr *p_mxip = (mxip_addr *) (node->data);
  29.574 +
  29.575 +			printf("name = %s\n IP = %s pref = %d\n", p_mxip->name, inet_ntoa(*(struct in_addr *) &(p_mxip->ip)), p_mxip->pref);
  29.576 +		}
  29.577 +		{
  29.578 +			guint32 ip;
  29.579 +			dns_look_ip(argv[1], &ip);
  29.580 +			printf("dns_look_ip: %s\n", inet_ntoa(*((struct in_addr *) (&ip))));
  29.581 +		}
  29.582 +	} else
  29.583 +		printf("res_init() failed.\n");
  29.584 +
  29.585  }
  29.586  #endif
    30.1 --- a/src/lookup.h	Mon Oct 27 16:21:27 2008 +0100
    30.2 +++ b/src/lookup.h	Mon Oct 27 16:23:10 2008 +0100
    30.3 @@ -5,7 +5,7 @@
    30.4   * it under the terms of the GNU General Public License as published by
    30.5   * the Free Software Foundation; either version 2 of the License, or
    30.6   * (at your option) any later version.
    30.7 - * 
    30.8 + *
    30.9   * This program is distributed in the hope that it will be useful,
   30.10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   30.11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   30.12 @@ -18,16 +18,15 @@
   30.13  
   30.14  #define MAX_DNSNAME MAXDNAME
   30.15  
   30.16 -typedef
   30.17 -struct{
   30.18 -  guint32 ip;
   30.19 -  int pref;
   30.20 -  guchar *name;
   30.21 +typedef struct {
   30.22 +	guint32 ip;
   30.23 +	int pref;
   30.24 +	guchar *name;
   30.25  } mxip_addr;
   30.26  
   30.27  
   30.28 -typedef GList *(*resolve_func)(GList *, gchar *);
   30.29 +typedef GList *(*resolve_func) (GList *, gchar *);
   30.30  
   30.31 -GList *resolve_dns_a(GList *list, gchar *domain);
   30.32 -GList *resolve_dns_mx(GList *list, gchar *domain);
   30.33 -GList *resolve_byname(GList *list, gchar *domain);
   30.34 +GList *resolve_dns_a(GList * list, gchar * domain);
   30.35 +GList *resolve_dns_mx(GList * list, gchar * domain);
   30.36 +GList *resolve_byname(GList * list, gchar * domain);
    31.1 --- a/src/masqmail.c	Mon Oct 27 16:21:27 2008 +0100
    31.2 +++ b/src/masqmail.c	Mon Oct 27 16:23:10 2008 +0100
    31.3 @@ -37,792 +37,783 @@
    31.4     nor a 'queue daemon' mode. These, as well as the distinction beween
    31.5     the two (non exclusive) daemon (queue and listen) modes are handled
    31.6     by flags.*/
    31.7 -typedef enum _mta_mode
    31.8 -{
    31.9 -  MODE_ACCEPT = 0, /* accept message on stdin */
   31.10 -  MODE_DAEMON,     /* run as daemon */
   31.11 -  MODE_RUNQUEUE,   /* single queue run, online or offline */
   31.12 -  MODE_GET_DAEMON, /* run as get (retrieve) daemon */
   31.13 -  MODE_SMTP,       /* accept SMTP on stdin */
   31.14 -  MODE_LIST,       /* list queue */
   31.15 -  MODE_MCMD,       /* do queue manipulation */
   31.16 -  MODE_VERSION,    /* show version */
   31.17 -  MODE_BI,         /* fake ;-) */
   31.18 -  MODE_NONE        /* to prevent default MODE_ACCEPT */    
   31.19 -}mta_mode;
   31.20 +typedef enum _mta_mode {
   31.21 +	MODE_ACCEPT = 0,  /* accept message on stdin */
   31.22 +	MODE_DAEMON,  /* run as daemon */
   31.23 +	MODE_RUNQUEUE,  /* single queue run, online or offline */
   31.24 +	MODE_GET_DAEMON,  /* run as get (retrieve) daemon */
   31.25 +	MODE_SMTP,  /* accept SMTP on stdin */
   31.26 +	MODE_LIST,  /* list queue */
   31.27 +	MODE_MCMD,  /* do queue manipulation */
   31.28 +	MODE_VERSION,  /* show version */
   31.29 +	MODE_BI,  /* fake ;-) */
   31.30 +	MODE_NONE  /* to prevent default MODE_ACCEPT */
   31.31 +} mta_mode;
   31.32  
   31.33  char *pidfile = NULL;
   31.34  volatile int sigterm_in_progress = 0;
   31.35  
   31.36 -static
   31.37 -void sigterm_handler(int sig)
   31.38 +static void
   31.39 +sigterm_handler(int sig)
   31.40  {
   31.41 -  if(sigterm_in_progress)
   31.42 -    raise(sig);
   31.43 -  sigterm_in_progress = 1;
   31.44 +	if (sigterm_in_progress)
   31.45 +		raise(sig);
   31.46 +	sigterm_in_progress = 1;
   31.47  
   31.48 -  if(pidfile){
   31.49 -    uid_t uid;
   31.50 -    uid = seteuid(0);
   31.51 -    if(unlink(pidfile) != 0)
   31.52 -      logwrite(LOG_WARNING, "could not delete pid file %s: %s\n",
   31.53 -	       pidfile, strerror(errno));
   31.54 -    seteuid(uid); /* we exit anyway after this, just to be sure */
   31.55 -  }
   31.56 +	if (pidfile) {
   31.57 +		uid_t uid;
   31.58 +		uid = seteuid(0);
   31.59 +		if (unlink(pidfile) != 0)
   31.60 +			logwrite(LOG_WARNING, "could not delete pid file %s: %s\n", pidfile, strerror(errno));
   31.61 +		seteuid(uid);  /* we exit anyway after this, just to be sure */
   31.62 +	}
   31.63  
   31.64 -  signal(sig, SIG_DFL);
   31.65 -  raise(sig);
   31.66 +	signal(sig, SIG_DFL);
   31.67 +	raise(sig);
   31.68  }
   31.69  
   31.70 -#ifdef ENABLE_IDENT /* so far used for that only */
   31.71 -static
   31.72 -gboolean is_in_netlist(gchar *host, GList *netlist)
   31.73 +#ifdef ENABLE_IDENT  /* so far used for that only */
   31.74 +static gboolean
   31.75 +is_in_netlist(gchar * host, GList * netlist)
   31.76  {
   31.77 -  guint hostip = inet_addr(host);
   31.78 -  struct in_addr addr;
   31.79 +	guint hostip = inet_addr(host);
   31.80 +	struct in_addr addr;
   31.81  
   31.82 -  addr.s_addr = hostip;
   31.83 -  if(addr.s_addr != INADDR_NONE){
   31.84 -    GList *node;
   31.85 -    foreach(netlist, node){
   31.86 -      struct in_addr *net = (struct in_addr *)(node->data);
   31.87 -      if((addr.s_addr & net->s_addr) == net->s_addr)
   31.88 -	return TRUE;
   31.89 -    }
   31.90 -  }
   31.91 -  return FALSE;
   31.92 +	addr.s_addr = hostip;
   31.93 +	if (addr.s_addr != INADDR_NONE) {
   31.94 +		GList *node;
   31.95 +		foreach(netlist, node) {
   31.96 +			struct in_addr *net = (struct in_addr *) (node->data);
   31.97 +			if ((addr.s_addr & net->s_addr) == net->s_addr)
   31.98 +				return TRUE;
   31.99 +		}
  31.100 +	}
  31.101 +	return FALSE;
  31.102  }
  31.103  #endif
  31.104  
  31.105 -gchar *get_optarg(char *argv[], gint argc, gint *argp, gint *pos)
  31.106 +gchar*
  31.107 +get_optarg(char *argv[], gint argc, gint * argp, gint * pos)
  31.108  {
  31.109 -  if(argv[*argp][*pos])
  31.110 -    return &(argv[*argp][*pos]);
  31.111 -  else{
  31.112 -    if(*argp+1 < argc){
  31.113 -      if(argv[(*argp)+1][0] != '-'){
  31.114 -	(*argp)++;
  31.115 -	*pos = 0;
  31.116 -	return &(argv[*argp][*pos]);
  31.117 -      }
  31.118 -    }
  31.119 -  }
  31.120 -  return NULL;
  31.121 -}  
  31.122 -
  31.123 -gchar *get_progname(gchar *arg0)
  31.124 -{
  31.125 -  gchar *p = arg0 + strlen(arg0) - 1;
  31.126 -  while(p > arg0){
  31.127 -    if(*p == '/')
  31.128 -      return p+1;
  31.129 -    p--;
  31.130 -  }
  31.131 -  return p;
  31.132 +	if (argv[*argp][*pos])
  31.133 +		return &(argv[*argp][*pos]);
  31.134 +	else {
  31.135 +		if (*argp + 1 < argc) {
  31.136 +			if (argv[(*argp) + 1][0] != '-') {
  31.137 +				(*argp)++;
  31.138 +				*pos = 0;
  31.139 +				return &(argv[*argp][*pos]);
  31.140 +			}
  31.141 +		}
  31.142 +	}
  31.143 +	return NULL;
  31.144  }
  31.145  
  31.146 -gboolean write_pidfile(gchar *name)
  31.147 +gchar*
  31.148 +get_progname(gchar * arg0)
  31.149  {
  31.150 -  FILE *fptr;
  31.151 -
  31.152 -  if((fptr = fopen(name, "wt"))){
  31.153 -    fprintf(fptr, "%d\n", getpid());
  31.154 -    fclose(fptr);
  31.155 -    pidfile = strdup(name);
  31.156 -    return TRUE;
  31.157 -  }
  31.158 -  logwrite(LOG_WARNING, "could not write pid file: %s\n", strerror(errno));
  31.159 -  return FALSE;
  31.160 +	gchar *p = arg0 + strlen(arg0) - 1;
  31.161 +	while (p > arg0) {
  31.162 +		if (*p == '/')
  31.163 +			return p + 1;
  31.164 +		p--;
  31.165 +	}
  31.166 +	return p;
  31.167  }
  31.168  
  31.169 -static
  31.170 -void mode_daemon(gboolean do_listen, gint queue_interval, char *argv[])
  31.171 +gboolean
  31.172 +write_pidfile(gchar * name)
  31.173  {
  31.174 -  guint pid;
  31.175 +	FILE *fptr;
  31.176  
  31.177 -  /* daemon */
  31.178 -  if(!conf.run_as_user){
  31.179 -    if((conf.orig_uid != 0) && (conf.orig_uid != conf.mail_uid)){
  31.180 -      fprintf(stderr, "must be root or %s for daemon.\n", DEF_MAIL_USER);
  31.181 -      exit(EXIT_FAILURE);
  31.182 -    }
  31.183 -  }
  31.184 +	if ((fptr = fopen(name, "wt"))) {
  31.185 +		fprintf(fptr, "%d\n", getpid());
  31.186 +		fclose(fptr);
  31.187 +		pidfile = strdup(name);
  31.188 +		return TRUE;
  31.189 +	}
  31.190 +	logwrite(LOG_WARNING, "could not write pid file: %s\n", strerror(errno));
  31.191 +	return FALSE;
  31.192 +}
  31.193  
  31.194 -  if((pid = fork()) > 0){
  31.195 -    exit(EXIT_SUCCESS);
  31.196 -  }else if(pid < 0){
  31.197 -    logwrite(LOG_ALERT, "could not fork!");
  31.198 -    exit(EXIT_FAILURE);
  31.199 -  }
  31.200 +static void
  31.201 +mode_daemon(gboolean do_listen, gint queue_interval, char *argv[])
  31.202 +{
  31.203 +	guint pid;
  31.204  
  31.205 -  signal(SIGTERM, sigterm_handler);
  31.206 -  write_pidfile(PIDFILEDIR"/masqmail.pid");
  31.207 +	/* daemon */
  31.208 +	if (!conf.run_as_user) {
  31.209 +		if ((conf.orig_uid != 0) && (conf.orig_uid != conf.mail_uid)) {
  31.210 +			fprintf(stderr, "must be root or %s for daemon.\n", DEF_MAIL_USER);
  31.211 +			exit(EXIT_FAILURE);
  31.212 +		}
  31.213 +	}
  31.214  
  31.215 -  conf.do_verbose = FALSE;
  31.216 +	if ((pid = fork()) > 0) {
  31.217 +		exit(EXIT_SUCCESS);
  31.218 +	} else if (pid < 0) {
  31.219 +		logwrite(LOG_ALERT, "could not fork!");
  31.220 +		exit(EXIT_FAILURE);
  31.221 +	}
  31.222  
  31.223 -  fclose(stdin);
  31.224 -  fclose(stdout);
  31.225 -  fclose(stderr);
  31.226 +	signal(SIGTERM, sigterm_handler);
  31.227 +	write_pidfile(PIDFILEDIR "/masqmail.pid");
  31.228  
  31.229 -  listen_port(do_listen ? conf.listen_addresses : NULL,
  31.230 -	      queue_interval, argv);
  31.231 +	conf.do_verbose = FALSE;
  31.232 +
  31.233 +	fclose(stdin);
  31.234 +	fclose(stdout);
  31.235 +	fclose(stderr);
  31.236 +
  31.237 +	listen_port(do_listen ? conf.listen_addresses : NULL, queue_interval, argv);
  31.238  }
  31.239  
  31.240  #ifdef ENABLE_POP3
  31.241 -static
  31.242 -void mode_get_daemon(gint get_interval, char *argv[])
  31.243 +static void
  31.244 +mode_get_daemon(gint get_interval, char *argv[])
  31.245  {
  31.246 -  guint pid;
  31.247 +	guint pid;
  31.248  
  31.249 -  /* daemon */
  31.250 -  if(!conf.run_as_user){
  31.251 -    if((conf.orig_uid != 0) && (conf.orig_uid != conf.mail_uid)){
  31.252 -      fprintf(stderr, "must be root or %s for daemon.\n", DEF_MAIL_USER);
  31.253 -      exit(EXIT_FAILURE);
  31.254 -    }
  31.255 -  }
  31.256 +	/* daemon */
  31.257 +	if (!conf.run_as_user) {
  31.258 +		if ((conf.orig_uid != 0) && (conf.orig_uid != conf.mail_uid)) {
  31.259 +			fprintf(stderr, "must be root or %s for daemon.\n", DEF_MAIL_USER);
  31.260 +			exit(EXIT_FAILURE);
  31.261 +		}
  31.262 +	}
  31.263  
  31.264 -  if((pid = fork()) > 0){
  31.265 -    exit(EXIT_SUCCESS);
  31.266 -  }else if(pid < 0){
  31.267 -    logwrite(LOG_ALERT, "could not fork!");
  31.268 -    exit(EXIT_FAILURE);
  31.269 -  }
  31.270 +	if ((pid = fork()) > 0) {
  31.271 +		exit(EXIT_SUCCESS);
  31.272 +	} else if (pid < 0) {
  31.273 +		logwrite(LOG_ALERT, "could not fork!");
  31.274 +		exit(EXIT_FAILURE);
  31.275 +	}
  31.276  
  31.277 -  signal(SIGTERM, sigterm_handler);
  31.278 -  write_pidfile(PIDFILEDIR"/masqmail-get.pid");
  31.279 +	signal(SIGTERM, sigterm_handler);
  31.280 +	write_pidfile(PIDFILEDIR "/masqmail-get.pid");
  31.281  
  31.282 -  conf.do_verbose = FALSE;
  31.283 +	conf.do_verbose = FALSE;
  31.284  
  31.285 -  fclose(stdin);
  31.286 -  fclose(stdout);
  31.287 -  fclose(stderr);
  31.288 +	fclose(stdin);
  31.289 +	fclose(stdout);
  31.290 +	fclose(stderr);
  31.291  
  31.292 -  get_daemon(get_interval, argv);
  31.293 +	get_daemon(get_interval, argv);
  31.294  }
  31.295  #endif
  31.296  
  31.297  #ifdef ENABLE_SMTP_SERVER
  31.298 -static void mode_smtp()
  31.299 +static void
  31.300 +mode_smtp()
  31.301  {
  31.302 -  /* accept smtp message on stdin */
  31.303 -  /* write responses to stderr. */
  31.304 +	/* accept smtp message on stdin */
  31.305 +	/* write responses to stderr. */
  31.306  
  31.307 -  struct sockaddr_in saddr;
  31.308 -  gchar *peername = NULL;
  31.309 -  int dummy = sizeof(saddr);
  31.310 +	struct sockaddr_in saddr;
  31.311 +	gchar *peername = NULL;
  31.312 +	int dummy = sizeof(saddr);
  31.313  #ifdef ENABLE_IDENT
  31.314 -  gchar *ident = NULL;
  31.315 +	gchar *ident = NULL;
  31.316  #endif
  31.317  
  31.318 -  conf.do_verbose = FALSE;
  31.319 +	conf.do_verbose = FALSE;
  31.320  
  31.321 -  if(!conf.run_as_user){
  31.322 -    seteuid(conf.orig_uid);
  31.323 -    setegid(conf.orig_gid);
  31.324 -  }
  31.325 +	if (!conf.run_as_user) {
  31.326 +		seteuid(conf.orig_uid);
  31.327 +		setegid(conf.orig_gid);
  31.328 +	}
  31.329  
  31.330 -  DEBUG(5) debugf("accepting smtp message on stdin\n");
  31.331 +	DEBUG(5) debugf("accepting smtp message on stdin\n");
  31.332  
  31.333 -  if(getpeername(0, (struct sockaddr *)(&saddr), &dummy) == 0){
  31.334 -    peername = g_strdup(inet_ntoa(saddr.sin_addr));
  31.335 +	if (getpeername(0, (struct sockaddr *) (&saddr), &dummy) == 0) {
  31.336 +		peername = g_strdup(inet_ntoa(saddr.sin_addr));
  31.337  #ifdef ENABLE_IDENT
  31.338 -    {
  31.339 -      gchar *id = NULL;
  31.340 -      if((id = (gchar *)ident_id(0, 60))){
  31.341 -	ident = g_strdup(id);
  31.342 -      }
  31.343 -    }
  31.344 +		{
  31.345 +			gchar *id = NULL;
  31.346 +			if ((id = (gchar *) ident_id(0, 60))) {
  31.347 +				ident = g_strdup(id);
  31.348 +			}
  31.349 +		}
  31.350  #endif
  31.351 -  }else if(errno != ENOTSOCK)
  31.352 -    exit(EXIT_FAILURE);
  31.353 +	} else if (errno != ENOTSOCK)
  31.354 +		exit(EXIT_FAILURE);
  31.355  
  31.356 -  //smtp_in(stdin, stdout, peername);
  31.357 -  smtp_in(stdin, stderr, peername, NULL);
  31.358 +	//smtp_in(stdin, stdout, peername);
  31.359 +	smtp_in(stdin, stderr, peername, NULL);
  31.360  
  31.361  #ifdef ENABLE_IDENT
  31.362 -  if(ident) g_free(ident);
  31.363 +	if (ident)
  31.364 +		g_free(ident);
  31.365  #endif
  31.366  }
  31.367  #endif
  31.368  
  31.369 -static void mode_accept(address *return_path, gchar *full_sender_name,
  31.370 -			guint accept_flags, char **addresses, int addr_cnt)
  31.371 +static void
  31.372 +mode_accept(address * return_path, gchar * full_sender_name, guint accept_flags, char **addresses, int addr_cnt)
  31.373  {
  31.374 -  /* accept message on stdin */
  31.375 -  accept_error err;
  31.376 -  message *msg = create_message();
  31.377 -  gint i;
  31.378 +	/* accept message on stdin */
  31.379 +	accept_error err;
  31.380 +	message *msg = create_message();
  31.381 +	gint i;
  31.382  
  31.383 -  if(return_path != NULL){
  31.384 -    if((conf.orig_uid != 0) &&
  31.385 -       (conf.orig_uid != conf.mail_uid) &&
  31.386 -       (!is_ingroup(conf.orig_uid, conf.mail_gid))){
  31.387 -      fprintf(stderr,
  31.388 -	      "must be in root, %s or in group %s for setting return path.\n",
  31.389 -	      DEF_MAIL_USER, DEF_MAIL_GROUP);
  31.390 -      exit(EXIT_FAILURE);
  31.391 -    }
  31.392 -  }
  31.393 +	if (return_path != NULL) {
  31.394 +		if ((conf.orig_uid != 0)
  31.395 +		    && (conf.orig_uid != conf.mail_uid)
  31.396 +		    && (!is_ingroup(conf.orig_uid, conf.mail_gid))) {
  31.397 +			fprintf(stderr, "must be in root, %s or in group %s for setting return path.\n", DEF_MAIL_USER, DEF_MAIL_GROUP);
  31.398 +			exit(EXIT_FAILURE);
  31.399 +		}
  31.400 +	}
  31.401  
  31.402 -  if(!conf.run_as_user){
  31.403 -    seteuid(conf.orig_uid);
  31.404 -    setegid(conf.orig_gid);
  31.405 -  }
  31.406 +	if (!conf.run_as_user) {
  31.407 +		seteuid(conf.orig_uid);
  31.408 +		setegid(conf.orig_gid);
  31.409 +	}
  31.410  
  31.411 -  DEBUG(5) debugf("accepting message on stdin\n");
  31.412 +	DEBUG(5) debugf("accepting message on stdin\n");
  31.413  
  31.414 -  msg->received_prot = PROT_LOCAL;
  31.415 -  for(i = 0; i < addr_cnt; i++){
  31.416 -    if(addresses[i][0] != '|')
  31.417 -      msg->rcpt_list =
  31.418 -	g_list_append(msg->rcpt_list,
  31.419 -		      create_address_qualified(addresses[i], TRUE, conf.host_name));
  31.420 -    else{
  31.421 -      logwrite(LOG_ALERT, "no pipe allowed as recipient address: %s\n", addresses[i]);
  31.422 -      exit(EXIT_FAILURE);
  31.423 -    }
  31.424 -  }
  31.425 +	msg->received_prot = PROT_LOCAL;
  31.426 +	for (i = 0; i < addr_cnt; i++) {
  31.427 +		if (addresses[i][0] != '|')
  31.428 +			msg->rcpt_list = g_list_append(msg->rcpt_list, create_address_qualified(addresses[i], TRUE, conf.host_name));
  31.429 +		else {
  31.430 +			logwrite(LOG_ALERT, "no pipe allowed as recipient address: %s\n", addresses[i]);
  31.431 +			exit(EXIT_FAILURE);
  31.432 +		}
  31.433 +	}
  31.434  
  31.435 -  /* -f option */
  31.436 -  msg->return_path = return_path;
  31.437 +	/* -f option */
  31.438 +	msg->return_path = return_path;
  31.439  
  31.440 -  /* -F option */
  31.441 -  msg->full_sender_name = full_sender_name;
  31.442 -    
  31.443 -  if((err = accept_message(stdin, msg, accept_flags)) == AERR_OK){
  31.444 -    if(spool_write(msg, TRUE)){
  31.445 -      pid_t pid;
  31.446 -      logwrite(LOG_NOTICE, "%s <= %s with %s\n",
  31.447 -	       msg->uid, addr_string(msg->return_path),
  31.448 -	       prot_names[PROT_LOCAL]);
  31.449 +	/* -F option */
  31.450 +	msg->full_sender_name = full_sender_name;
  31.451  
  31.452 -      if(!conf.do_queue){
  31.453 +	if ((err = accept_message(stdin, msg, accept_flags)) == AERR_OK) {
  31.454 +		if (spool_write(msg, TRUE)) {
  31.455 +			pid_t pid;
  31.456 +			logwrite(LOG_NOTICE, "%s <= %s with %s\n", msg->uid, addr_string(msg->return_path), prot_names[PROT_LOCAL]);
  31.457  
  31.458 -	if((pid = fork()) == 0){
  31.459 -
  31.460 -	  conf.do_verbose = FALSE;
  31.461 -
  31.462 -	  fclose(stdin);
  31.463 -	  fclose(stdout);
  31.464 -	  fclose(stderr);
  31.465 -
  31.466 -	  if(deliver(msg)){
  31.467 -	    exit(EXIT_SUCCESS);
  31.468 -	  }else
  31.469 -	    exit(EXIT_FAILURE);
  31.470 -	}else if(pid < 0){
  31.471 -	  logwrite(LOG_ALERT, "could not fork for delivery, id = %s",
  31.472 -		   msg->uid);
  31.473 +			if (!conf.do_queue) {
  31.474 +				if ((pid = fork()) == 0) {
  31.475 +					conf.do_verbose = FALSE;
  31.476 +					fclose(stdin);
  31.477 +					fclose(stdout);
  31.478 +					fclose(stderr);
  31.479 +					if (deliver(msg)) {
  31.480 +						exit(EXIT_SUCCESS);
  31.481 +					} else
  31.482 +						exit(EXIT_FAILURE);
  31.483 +				} else if (pid < 0) {
  31.484 +					logwrite(LOG_ALERT, "could not fork for delivery, id = %s", msg->uid);
  31.485 +				}
  31.486 +			}
  31.487 +		} else {
  31.488 +			fprintf(stderr, "Could not write spool file\n");
  31.489 +			exit(EXIT_FAILURE);
  31.490 +		}
  31.491 +	} else {
  31.492 +		switch (err) {
  31.493 +		case AERR_EOF:
  31.494 +			fprintf(stderr, "unexpected EOF.\n");
  31.495 +			exit(EXIT_FAILURE);
  31.496 +		case AERR_NORCPT:
  31.497 +			fprintf(stderr, "no recipients.\n");
  31.498 +			exit(EXIT_FAILURE);
  31.499 +		default:
  31.500 +			/* should never happen: */
  31.501 +			fprintf(stderr, "Unknown error (%d)\r\n", err);
  31.502 +			exit(EXIT_FAILURE);
  31.503 +		}
  31.504 +		exit(EXIT_FAILURE);
  31.505  	}
  31.506 -      }
  31.507 -    }else{
  31.508 -      fprintf(stderr, "Could not write spool file\n");
  31.509 -      exit(EXIT_FAILURE);
  31.510 -    }
  31.511 -  }else{
  31.512 -    switch(err){
  31.513 -    case AERR_EOF:
  31.514 -      fprintf(stderr, "unexpected EOF.\n");
  31.515 -      exit(EXIT_FAILURE);
  31.516 -    case AERR_NORCPT:
  31.517 -      fprintf(stderr, "no recipients.\n");
  31.518 -      exit(EXIT_FAILURE);
  31.519 -    default:
  31.520 -      /* should never happen: */
  31.521 -      fprintf(stderr, "Unknown error (%d)\r\n", err);
  31.522 -      exit(EXIT_FAILURE);
  31.523 -    }
  31.524 -    exit(EXIT_FAILURE);
  31.525 -  }
  31.526  }
  31.527  
  31.528  int
  31.529  main(int argc, char *argv[])
  31.530  {
  31.531 -  /* cmd line flags */
  31.532 -  gchar *conf_file = CONF_FILE;
  31.533 -  gint arg = 1;
  31.534 -  gboolean do_get = FALSE;
  31.535 -  gboolean do_get_online = FALSE;
  31.536 +	/* cmd line flags */
  31.537 +	gchar *conf_file = CONF_FILE;
  31.538 +	gint arg = 1;
  31.539 +	gboolean do_get = FALSE;
  31.540 +	gboolean do_get_online = FALSE;
  31.541  
  31.542 -  gboolean do_listen = FALSE;
  31.543 -  gboolean do_runq = FALSE;
  31.544 -  gboolean do_runq_online = FALSE;
  31.545 +	gboolean do_listen = FALSE;
  31.546 +	gboolean do_runq = FALSE;
  31.547 +	gboolean do_runq_online = FALSE;
  31.548  
  31.549 -  gboolean do_queue = FALSE;
  31.550 +	gboolean do_queue = FALSE;
  31.551  
  31.552 -  gboolean do_verbose = FALSE;
  31.553 -  gint debug_level = -1;
  31.554 +	gboolean do_verbose = FALSE;
  31.555 +	gint debug_level = -1;
  31.556  
  31.557 -  mta_mode mta_mode = MODE_ACCEPT;
  31.558 +	mta_mode mta_mode = MODE_ACCEPT;
  31.559  
  31.560 -  gint queue_interval = 0;
  31.561 -  gint get_interval = 0;
  31.562 -  gboolean opt_t = FALSE;
  31.563 -  gboolean opt_i = FALSE;
  31.564 -  gboolean opt_odb = FALSE;
  31.565 -  gboolean opt_oem = FALSE;
  31.566 -  gboolean exit_failure = FALSE;
  31.567 +	gint queue_interval = 0;
  31.568 +	gint get_interval = 0;
  31.569 +	gboolean opt_t = FALSE;
  31.570 +	gboolean opt_i = FALSE;
  31.571 +	gboolean opt_odb = FALSE;
  31.572 +	gboolean opt_oem = FALSE;
  31.573 +	gboolean exit_failure = FALSE;
  31.574  
  31.575 -  gchar *M_cmd = NULL;
  31.576 +	gchar *M_cmd = NULL;
  31.577  
  31.578 -  gint exit_code = EXIT_SUCCESS;
  31.579 -  gchar *route_name = NULL;
  31.580 -  gchar *get_name = NULL;
  31.581 -  gchar *progname;
  31.582 -  gchar *f_address = NULL;
  31.583 -  gchar *full_sender_name = NULL;
  31.584 -  address *return_path = NULL; /* may be changed by -f option */
  31.585 +	gint exit_code = EXIT_SUCCESS;
  31.586 +	gchar *route_name = NULL;
  31.587 +	gchar *get_name = NULL;
  31.588 +	gchar *progname;
  31.589 +	gchar *f_address = NULL;
  31.590 +	gchar *full_sender_name = NULL;
  31.591 +	address *return_path = NULL;  /* may be changed by -f option */
  31.592  
  31.593 -  progname = get_progname(argv[0]);
  31.594 +	progname = get_progname(argv[0]);
  31.595  
  31.596 -  if(strcmp(progname, "mailq") == 0)
  31.597 -    { mta_mode = MODE_LIST; }
  31.598 -  else if(strcmp(progname, "mailrm") == 0)
  31.599 -    { mta_mode = MODE_MCMD; M_cmd = "rm"; }
  31.600 -  else if(strcmp(progname, "runq") == 0)
  31.601 -    { mta_mode = MODE_RUNQUEUE; do_runq = TRUE; }
  31.602 -  else if(strcmp(progname, "rmail") == 0)
  31.603 -    { mta_mode = MODE_ACCEPT; opt_i = TRUE; }
  31.604 -  else if(strcmp(progname, "smtpd") == 0 || strcmp(progname, "in.smtpd") == 0)
  31.605 -    { mta_mode = MODE_SMTP; }
  31.606 +	if (strcmp(progname, "mailq") == 0) {
  31.607 +		mta_mode = MODE_LIST;
  31.608 +	} else if (strcmp(progname, "mailrm") == 0) {
  31.609 +		mta_mode = MODE_MCMD;
  31.610 +		M_cmd = "rm";
  31.611 +	} else if (strcmp(progname, "runq") == 0) {
  31.612 +		mta_mode = MODE_RUNQUEUE;
  31.613 +		do_runq = TRUE;
  31.614 +	} else if (strcmp(progname, "rmail") == 0) {
  31.615 +		mta_mode = MODE_ACCEPT;
  31.616 +		opt_i = TRUE;
  31.617 +	} else if (strcmp(progname, "smtpd") == 0 || strcmp(progname, "in.smtpd") == 0) {
  31.618 +		mta_mode = MODE_SMTP;
  31.619 +	}
  31.620  
  31.621 -  /* parse cmd line */
  31.622 -  while(arg < argc){
  31.623 -    gint pos = 0;
  31.624 -    if((argv[arg][pos] == '-') && (argv[arg][pos+1] != '-')){
  31.625 -      pos++;
  31.626 -      switch(argv[arg][pos++]){
  31.627 -      case 'b':
  31.628 -	switch(argv[arg][pos++]){
  31.629 -	case 'd':
  31.630 -	  do_listen = TRUE;
  31.631 -	  mta_mode = MODE_DAEMON;
  31.632 -	  break;
  31.633 -	case 'i':
  31.634 -	  /* ignored */
  31.635 -	  mta_mode = MODE_BI;
  31.636 -	  break;
  31.637 -	case 's':
  31.638 -	  mta_mode = MODE_SMTP;
  31.639 -	  break;
  31.640 -	case 'p':
  31.641 -	  mta_mode = MODE_LIST;
  31.642 -	  break;
  31.643 -	case 'V':
  31.644 -	  mta_mode = MODE_VERSION;
  31.645 -	  break;
  31.646 -	default:
  31.647 -	  fprintf(stderr, "unrecognized option '%s'\n", argv[arg]);
  31.648 -	  exit(EXIT_FAILURE);
  31.649 +	/* parse cmd line */
  31.650 +	while (arg < argc) {
  31.651 +		gint pos = 0;
  31.652 +		if ((argv[arg][pos] == '-') && (argv[arg][pos + 1] != '-')) {
  31.653 +			pos++;
  31.654 +			switch (argv[arg][pos++]) {
  31.655 +			case 'b':
  31.656 +				switch (argv[arg][pos++]) {
  31.657 +				case 'd':
  31.658 +					do_listen = TRUE;
  31.659 +					mta_mode = MODE_DAEMON;
  31.660 +					break;
  31.661 +				case 'i':
  31.662 +					/* ignored */
  31.663 +					mta_mode = MODE_BI;
  31.664 +					break;
  31.665 +				case 's':
  31.666 +					mta_mode = MODE_SMTP;
  31.667 +					break;
  31.668 +				case 'p':
  31.669 +					mta_mode = MODE_LIST;
  31.670 +					break;
  31.671 +				case 'V':
  31.672 +					mta_mode = MODE_VERSION;
  31.673 +					break;
  31.674 +				default:
  31.675 +					fprintf(stderr, "unrecognized option '%s'\n", argv[arg]);
  31.676 +					exit(EXIT_FAILURE);
  31.677 +				}
  31.678 +				break;
  31.679 +			case 'B':
  31.680 +				/* we ignore this and throw the argument away */
  31.681 +				get_optarg(argv, argc, &arg, &pos);
  31.682 +				break;
  31.683 +			case 'C':
  31.684 +				if (!(conf_file = get_optarg(argv, argc, &arg, &pos))) {
  31.685 +					fprintf(stderr, "-C requires a filename as argument.\n");
  31.686 +					exit(EXIT_FAILURE);
  31.687 +				}
  31.688 +				break;
  31.689 +			case 'F':
  31.690 +				{
  31.691 +					full_sender_name = get_optarg(argv, argc, &arg, &pos);
  31.692 +					if (!full_sender_name) {
  31.693 +						fprintf(stderr, "-F requires a name as an argument\n");
  31.694 +						exit(EXIT_FAILURE);
  31.695 +					}
  31.696 +				}
  31.697 +				break;
  31.698 +			case 'd':
  31.699 +				if (getuid() == 0) {
  31.700 +					char *lvl = get_optarg(argv, argc, &arg, &pos);
  31.701 +					if (lvl)
  31.702 +						debug_level = atoi(lvl);
  31.703 +					else {
  31.704 +						fprintf(stderr, "-d requires a number as an argument.\n");
  31.705 +						exit(EXIT_FAILURE);
  31.706 +					}
  31.707 +				} else {
  31.708 +					fprintf(stderr, "only root may set the debug level.\n");
  31.709 +					exit(EXIT_FAILURE);
  31.710 +				}
  31.711 +				break;
  31.712 +			case 'f':
  31.713 +				/* set return path */
  31.714 +				{
  31.715 +					gchar *address;
  31.716 +					address = get_optarg(argv, argc, &arg, &pos);
  31.717 +					if (address) {
  31.718 +						f_address = g_strdup(address);
  31.719 +					} else {
  31.720 +						fprintf(stderr, "-f requires an address as an argument\n");
  31.721 +						exit(EXIT_FAILURE);
  31.722 +					}
  31.723 +				}
  31.724 +				break;
  31.725 +			case 'g':
  31.726 +				do_get = TRUE;
  31.727 +				if (!mta_mode)
  31.728 +					mta_mode = MODE_NONE;  /* to prevent default MODE_ACCEPT */
  31.729 +				if (argv[arg][pos] == 'o') {
  31.730 +					pos++;
  31.731 +					do_get_online = TRUE;
  31.732 +					/* can be NULL, then we use online detection method */
  31.733 +					route_name = get_optarg(argv, argc, &arg, &pos);
  31.734 +
  31.735 +					if (route_name != NULL) {
  31.736 +						if (isdigit(route_name[0])) {
  31.737 +							get_interval = time_interval(route_name, &pos);
  31.738 +							route_name = get_optarg(argv, argc, &arg, &pos);
  31.739 +							mta_mode = MODE_GET_DAEMON;
  31.740 +							do_get = FALSE;
  31.741 +						}
  31.742 +					}
  31.743 +				} else {
  31.744 +					if ((optarg = get_optarg(argv, argc, &arg, &pos))) {
  31.745 +						get_name = get_optarg(argv, argc, &arg, &pos);
  31.746 +					}
  31.747 +				}
  31.748 +				break;
  31.749 +			case 'i':
  31.750 +				if (argv[arg][pos] == 0) {
  31.751 +					opt_i = TRUE;
  31.752 +					exit_failure = FALSE;  /* may override -oem */
  31.753 +				} else {
  31.754 +					fprintf(stderr, "unrecognized option '%s'\n", argv[arg]);
  31.755 +					exit(EXIT_FAILURE);
  31.756 +				}
  31.757 +				break;
  31.758 +			case 'M':
  31.759 +				{
  31.760 +					mta_mode = MODE_MCMD;
  31.761 +					M_cmd = g_strdup(&(argv[arg][pos]));
  31.762 +				}
  31.763 +				break;
  31.764 +			case 'o':
  31.765 +				switch (argv[arg][pos++]) {
  31.766 +				case 'e':
  31.767 +					if (argv[arg][pos++] == 'm')  /* -oem */
  31.768 +						if (!opt_i)
  31.769 +							exit_failure = TRUE;
  31.770 +					opt_oem = TRUE;
  31.771 +					break;
  31.772 +				case 'd':
  31.773 +					if (argv[arg][pos] == 'b')  /* -odb */
  31.774 +						opt_odb = TRUE;
  31.775 +					else if (argv[arg][pos] == 'q')  /* -odq */
  31.776 +						do_queue = TRUE;
  31.777 +					break;
  31.778 +				case 'i':
  31.779 +					opt_i = TRUE;
  31.780 +					exit_failure = FALSE;  /* may override -oem */
  31.781 +					break;
  31.782 +				}
  31.783 +				break;
  31.784 +
  31.785 +			case 'q':
  31.786 +				{
  31.787 +					gchar *optarg;
  31.788 +
  31.789 +					do_runq = TRUE;
  31.790 +					mta_mode = MODE_RUNQUEUE;
  31.791 +					if (argv[arg][pos] == 'o') {
  31.792 +						pos++;
  31.793 +						do_runq = FALSE;
  31.794 +						do_runq_online = TRUE;
  31.795 +						/* can be NULL, then we use online detection method */
  31.796 +						route_name = get_optarg(argv, argc, &arg, &pos);
  31.797 +					} else
  31.798 +						if ((optarg = get_optarg(argv, argc, &arg, &pos))) {
  31.799 +						mta_mode = MODE_DAEMON;
  31.800 +						queue_interval = time_interval(optarg, &pos);
  31.801 +					}
  31.802 +				}
  31.803 +				break;
  31.804 +			case 't':
  31.805 +				if (argv[arg][pos] == 0) {
  31.806 +					opt_t = TRUE;
  31.807 +				} else {
  31.808 +					fprintf(stderr, "unrecognized option '%s'\n", argv[arg]);
  31.809 +					exit(EXIT_FAILURE);
  31.810 +				}
  31.811 +				break;
  31.812 +			case 'v':
  31.813 +				do_verbose = TRUE;
  31.814 +				break;
  31.815 +			default:
  31.816 +				fprintf(stderr, "unrecognized option '%s'\n", argv[arg]);
  31.817 +				exit(EXIT_FAILURE);
  31.818 +			}
  31.819 +		} else {
  31.820 +			if (argv[arg][pos + 1] == '-') {
  31.821 +				if (argv[arg][pos + 2] != '\0') {
  31.822 +					fprintf(stderr, "unrecognized option '%s'\n", argv[arg]);
  31.823 +					exit(EXIT_FAILURE);
  31.824 +				}
  31.825 +				arg++;
  31.826 +			}
  31.827 +			break;
  31.828 +		}
  31.829 +		arg++;
  31.830  	}
  31.831 -	break;
  31.832 -      case 'B':
  31.833 -	/* we ignore this and throw the argument away */
  31.834 -	get_optarg(argv, argc, &arg, &pos);
  31.835 -	break;
  31.836 -      case 'C':
  31.837 -	if(!(conf_file = get_optarg(argv, argc, &arg, &pos))){
  31.838 -	  fprintf(stderr, "-C requires a filename as argument.\n");
  31.839 -	  exit(EXIT_FAILURE);
  31.840 -	}
  31.841 -	break;
  31.842 -      case 'F':
  31.843 -	{
  31.844 -	  full_sender_name = get_optarg(argv, argc, &arg, &pos);
  31.845 -	  if(!full_sender_name){
  31.846 -	    fprintf(stderr, "-F requires a name as an argument\n");
  31.847 -	    exit(EXIT_FAILURE);
  31.848 -	  }
  31.849 -	}
  31.850 -	break;
  31.851 -      case 'd':
  31.852 -	if(getuid() == 0){
  31.853 -	  char *lvl = get_optarg(argv, argc, &arg, &pos);
  31.854 -	  if(lvl)
  31.855 -	    debug_level = atoi(lvl);
  31.856 -	  else{
  31.857 -	    fprintf(stderr, "-d requires a number as an argument.\n");
  31.858 -	    exit(EXIT_FAILURE);
  31.859 -	  }
  31.860 -	}else{
  31.861 -	  fprintf(stderr, "only root may set the debug level.\n");
  31.862 -	  exit(EXIT_FAILURE);
  31.863 -	}
  31.864 -	break;
  31.865 -      case 'f':
  31.866 -	/* set return path */
  31.867 -	{
  31.868 -	  gchar *address;
  31.869 -	  address = get_optarg(argv, argc, &arg, &pos);
  31.870 -	  if(address){
  31.871 -	    f_address = g_strdup(address);
  31.872 -	  }else{
  31.873 -	    fprintf(stderr, "-f requires an address as an argument\n");
  31.874 -	    exit(EXIT_FAILURE);
  31.875 -	  }
  31.876 -	}
  31.877 -	break;
  31.878 -      case 'g':
  31.879 -	do_get = TRUE;
  31.880 -	if(!mta_mode) mta_mode = MODE_NONE; /* to prevent default MODE_ACCEPT */
  31.881 -	if(argv[arg][pos] == 'o'){
  31.882 -	  pos++;
  31.883 -	  do_get_online = TRUE;
  31.884 -	  /* can be NULL, then we use online detection method */
  31.885 -	  route_name = get_optarg(argv, argc, &arg, &pos);
  31.886  
  31.887 -	  if(route_name != NULL){
  31.888 -	    if(isdigit(route_name[0])){
  31.889 -	      get_interval = time_interval(route_name, &pos);
  31.890 -	      route_name = get_optarg(argv, argc, &arg, &pos);
  31.891 -	      mta_mode = MODE_GET_DAEMON;
  31.892 -	      do_get = FALSE;
  31.893 -	    }
  31.894 -	  }
  31.895 -	}else{
  31.896 -	  if((optarg = get_optarg(argv, argc, &arg, &pos))){
  31.897 -	    get_name = get_optarg(argv, argc, &arg, &pos);
  31.898 -	  }
  31.899 -	}
  31.900 -	break;
  31.901 -      case 'i':
  31.902 -	if(argv[arg][pos] == 0){
  31.903 -	  opt_i = TRUE;
  31.904 -	  exit_failure = FALSE; /* may override -oem */
  31.905 -	}else{
  31.906 -	  fprintf(stderr, "unrecognized option '%s'\n", argv[arg]);
  31.907 -	  exit(EXIT_FAILURE);
  31.908 -	}
  31.909 -	break;
  31.910 -      case 'M':
  31.911 -	{
  31.912 -	  mta_mode = MODE_MCMD;
  31.913 -	  M_cmd = g_strdup(&(argv[arg][pos]));
  31.914 -	}
  31.915 -	break;
  31.916 -      case 'o':
  31.917 -	switch(argv[arg][pos++]){
  31.918 -	case 'e':
  31.919 -	  if(argv[arg][pos++] == 'm') /* -oem */
  31.920 -	    if(!opt_i) exit_failure = TRUE;
  31.921 -	    opt_oem = TRUE;
  31.922 -	  break;
  31.923 -	case 'd':
  31.924 -	  if(argv[arg][pos] == 'b') /* -odb */
  31.925 -	    opt_odb = TRUE;
  31.926 -	  else if(argv[arg][pos] == 'q') /* -odq */
  31.927 -	    do_queue = TRUE;
  31.928 -	  break;
  31.929 -	case 'i':
  31.930 -	  opt_i = TRUE;
  31.931 -	  exit_failure = FALSE; /* may override -oem */
  31.932 -	  break;
  31.933 -	}
  31.934 -	break;
  31.935 +	if (mta_mode == MODE_VERSION) {
  31.936 +		gchar *with_resolver = "", *with_smtp_server = "", *with_pop3 = "",
  31.937 +		*with_auth = "", *with_maildir = "", *with_ident = "", *with_mserver = "";
  31.938  
  31.939 -      case 'q':
  31.940 -	{
  31.941 -	  gchar *optarg;
  31.942 -
  31.943 -	  do_runq = TRUE;
  31.944 -	  mta_mode = MODE_RUNQUEUE;
  31.945 -	  if(argv[arg][pos] == 'o'){
  31.946 -	    pos++;
  31.947 -	    do_runq = FALSE;
  31.948 -	    do_runq_online = TRUE;
  31.949 -	    /* can be NULL, then we use online detection method */
  31.950 -	    route_name = get_optarg(argv, argc, &arg, &pos);
  31.951 -	  }else if((optarg = get_optarg(argv, argc, &arg, &pos))){
  31.952 -	    mta_mode = MODE_DAEMON;
  31.953 -	    queue_interval = time_interval(optarg, &pos);
  31.954 -	  }
  31.955 -	}
  31.956 -	break;
  31.957 -      case 't':
  31.958 -	if(argv[arg][pos] == 0){
  31.959 -	  opt_t = TRUE;
  31.960 -	}else{
  31.961 -	  fprintf(stderr, "unrecognized option '%s'\n", argv[arg]);
  31.962 -	  exit(EXIT_FAILURE);
  31.963 -	}
  31.964 -	break;
  31.965 -      case 'v':
  31.966 -	do_verbose = TRUE;
  31.967 -	break;
  31.968 -      default:
  31.969 -	fprintf(stderr, "unrecognized option '%s'\n", argv[arg]);
  31.970 -	exit(EXIT_FAILURE);
  31.971 -      }
  31.972 -    }else{
  31.973 -      if(argv[arg][pos+1] == '-'){
  31.974 -        if(argv[arg][pos+2] != '\0'){
  31.975 -	  fprintf(stderr, "unrecognized option '%s'\n", argv[arg]);
  31.976 -	  exit(EXIT_FAILURE);
  31.977 -        }
  31.978 -	arg++;
  31.979 -      }
  31.980 -      break;
  31.981 -    }
  31.982 -    arg++;
  31.983 -  }
  31.984 -
  31.985 -  if(mta_mode == MODE_VERSION){
  31.986 -    gchar *with_resolver = "", *with_smtp_server = "", *with_pop3 = "", *with_auth = "", 
  31.987 -      *with_maildir = "", *with_ident = "", *with_mserver = "";
  31.988 -    
  31.989  #ifdef ENABLE_RESOLVER
  31.990 -    with_resolver = " +resolver";
  31.991 +		with_resolver = " +resolver";
  31.992  #endif
  31.993  #ifdef ENABLE_SMTP_SERVER
  31.994 -    with_smtp_server = " +smtp-server";
  31.995 +		with_smtp_server = " +smtp-server";
  31.996  #endif
  31.997  #ifdef ENABLE_POP3
  31.998 -    with_pop3 = " +pop3";
  31.999 +		with_pop3 = " +pop3";
 31.1000  #endif
 31.1001  #ifdef ENABLE_AUTH
 31.1002 -    with_auth = " +auth";
 31.1003 +		with_auth = " +auth";
 31.1004  #endif
 31.1005  #ifdef ENABLE_MAILDIR
 31.1006 -    with_maildir = " +maildir";
 31.1007 +		with_maildir = " +maildir";
 31.1008  #endif
 31.1009  #ifdef ENABLE_IDENT
 31.1010 -    with_ident = " +ident";
 31.1011 +		with_ident = " +ident";
 31.1012  #endif
 31.1013  #ifdef ENABLE_MSERVER
 31.1014 -    with_mserver = " +mserver";
 31.1015 +		with_mserver = " +mserver";
 31.1016  #endif
 31.1017  
 31.1018 -    printf("%s %s%s%s%s%s%s%s%s\n", PACKAGE, VERSION,
 31.1019 -	   with_resolver, with_smtp_server, with_pop3, with_auth,
 31.1020 -	   with_maildir, with_ident, with_mserver);
 31.1021 -      
 31.1022 -    exit(EXIT_SUCCESS);
 31.1023 -  }
 31.1024 +		printf("%s %s%s%s%s%s%s%s%s\n", PACKAGE, VERSION, with_resolver, with_smtp_server,
 31.1025 +		       with_pop3, with_auth, with_maildir, with_ident, with_mserver);
 31.1026  
 31.1027 -  /* initialize random generator */
 31.1028 -  srand(time(NULL));
 31.1029 -  /* ignore SIGPIPE signal */
 31.1030 -  signal(SIGPIPE, SIG_IGN);
 31.1031 +		exit(EXIT_SUCCESS);
 31.1032 +	}
 31.1033  
 31.1034 -  /* close all possibly open file descriptors */
 31.1035 -  {
 31.1036 -    int i, max_fd = sysconf(_SC_OPEN_MAX);
 31.1037 +	/* initialize random generator */
 31.1038 +	srand(time(NULL));
 31.1039 +	/* ignore SIGPIPE signal */
 31.1040 +	signal(SIGPIPE, SIG_IGN);
 31.1041  
 31.1042 -    if(max_fd <= 0) max_fd = 64;
 31.1043 -    for(i = 3; i < max_fd; i++)
 31.1044 -      close(i);
 31.1045 -  }
 31.1046 +	/* close all possibly open file descriptors */
 31.1047 +	{
 31.1048 +		int i, max_fd = sysconf(_SC_OPEN_MAX);
 31.1049  
 31.1050 -  init_conf();
 31.1051 +		if (max_fd <= 0)
 31.1052 +			max_fd = 64;
 31.1053 +		for (i = 3; i < max_fd; i++)
 31.1054 +			close(i);
 31.1055 +	}
 31.1056  
 31.1057 -  /* if we are not privileged, and the config file was changed we
 31.1058 -     implicetely set the the run_as_user flag and give up all
 31.1059 -     privileges.
 31.1060 +	init_conf();
 31.1061  
 31.1062 -     So it is possible for a user to run his own daemon without
 31.1063 -     breaking security.
 31.1064 -  */
 31.1065 -  if(strcmp(conf_file, CONF_FILE) != 0){
 31.1066 -    if(conf.orig_uid != 0){
 31.1067 -      conf.run_as_user = TRUE;
 31.1068 -      seteuid(conf.orig_uid);
 31.1069 -      setegid(conf.orig_gid);
 31.1070 -      setuid(conf.orig_uid);
 31.1071 -      setgid(conf.orig_gid);
 31.1072 -    }
 31.1073 -  }
 31.1074 +	/* if we are not privileged, and the config file was changed we
 31.1075 +	   implicetely set the the run_as_user flag and give up all
 31.1076 +	   privileges.
 31.1077  
 31.1078 -  read_conf(conf_file);
 31.1079 +	   So it is possible for a user to run his own daemon without
 31.1080 +	   breaking security.
 31.1081 +	 */
 31.1082 +	if (strcmp(conf_file, CONF_FILE) != 0) {
 31.1083 +		if (conf.orig_uid != 0) {
 31.1084 +			conf.run_as_user = TRUE;
 31.1085 +			seteuid(conf.orig_uid);
 31.1086 +			setegid(conf.orig_gid);
 31.1087 +			setuid(conf.orig_uid);
 31.1088 +			setgid(conf.orig_gid);
 31.1089 +		}
 31.1090 +	}
 31.1091  
 31.1092 -  if(do_queue) conf.do_queue = TRUE;
 31.1093 -  if(do_verbose) conf.do_verbose = TRUE;
 31.1094 -  if(debug_level >= 0) /* if >= 0, it was given by argument */
 31.1095 -    conf.debug_level = debug_level;
 31.1096 +	read_conf(conf_file);
 31.1097  
 31.1098 -  chdir("/");
 31.1099 +	if (do_queue)
 31.1100 +		conf.do_queue = TRUE;
 31.1101 +	if (do_verbose)
 31.1102 +		conf.do_verbose = TRUE;
 31.1103 +	if (debug_level >= 0)  /* if >= 0, it was given by argument */
 31.1104 +		conf.debug_level = debug_level;
 31.1105  
 31.1106 -  if(!conf.run_as_user){
 31.1107 -    if(setgid(0) != 0){
 31.1108 -      fprintf(stderr,
 31.1109 -	      "could not set gid to 0. Is the setuid bit set? : %s\n",
 31.1110 -	      strerror(errno));
 31.1111 -      exit(EXIT_FAILURE);
 31.1112 -    }
 31.1113 -    if(setuid(0) != 0){
 31.1114 -      fprintf(stderr,
 31.1115 -	      "could not gain root privileges. Is the setuid bit set? : %s\n",
 31.1116 -	      strerror(errno));
 31.1117 -      exit(EXIT_FAILURE);
 31.1118 -    }
 31.1119 -  }
 31.1120 +	chdir("/");
 31.1121  
 31.1122 -  if(!logopen()){
 31.1123 -    fprintf(stderr, "could not open log file\n");
 31.1124 -    exit(EXIT_FAILURE);
 31.1125 -  }
 31.1126 +	if (!conf.run_as_user) {
 31.1127 +		if (setgid(0) != 0) {
 31.1128 +			fprintf(stderr, "could not set gid to 0. Is the setuid bit set? : %s\n", strerror(errno));
 31.1129 +			exit(EXIT_FAILURE);
 31.1130 +		}
 31.1131 +		if (setuid(0) != 0) {
 31.1132 +			fprintf(stderr, "could not gain root privileges. Is the setuid bit set? : %s\n", strerror(errno));
 31.1133 +			exit(EXIT_FAILURE);
 31.1134 +		}
 31.1135 +	}
 31.1136  
 31.1137 -  DEBUG(1) debugf("masqmail %s starting\n", VERSION);
 31.1138 +	if (!logopen()) {
 31.1139 +		fprintf(stderr, "could not open log file\n");
 31.1140 +		exit(EXIT_FAILURE);
 31.1141 +	}
 31.1142  
 31.1143 -  DEBUG(5){
 31.1144 -    gchar **str = argv;
 31.1145 -    debugf("args: \n");
 31.1146 -    while(*str){
 31.1147 -      debugf("%s \n", *str);
 31.1148 -      str++;
 31.1149 -    }
 31.1150 -  }
 31.1151 -  DEBUG(5) debugf("queue_interval = %d\n", queue_interval);
 31.1152 +	DEBUG(1) debugf("masqmail %s starting\n", VERSION);
 31.1153  
 31.1154 -  if(f_address){
 31.1155 -    return_path = create_address_qualified(f_address, TRUE, conf.host_name);
 31.1156 -    g_free(f_address);
 31.1157 -    if(!return_path){
 31.1158 -      fprintf(stderr, "invalid RFC821 address: %s\n", f_address);
 31.1159 -      exit(EXIT_FAILURE);
 31.1160 -    }
 31.1161 -  }
 31.1162 +	DEBUG(5) {
 31.1163 +		gchar **str = argv;
 31.1164 +		debugf("args: \n");
 31.1165 +		while (*str) {
 31.1166 +			debugf("%s \n", *str);
 31.1167 +			str++;
 31.1168 +		}
 31.1169 +	}
 31.1170 +	DEBUG(5) debugf("queue_interval = %d\n", queue_interval);
 31.1171  
 31.1172 -  if(do_get){
 31.1173 +	if (f_address) {
 31.1174 +		return_path = create_address_qualified(f_address, TRUE, conf.host_name);
 31.1175 +		g_free(f_address);
 31.1176 +		if (!return_path) {
 31.1177 +			fprintf(stderr, "invalid RFC821 address: %s\n", f_address);
 31.1178 +			exit(EXIT_FAILURE);
 31.1179 +		}
 31.1180 +	}
 31.1181 +
 31.1182 +	if (do_get) {
 31.1183  #ifdef ENABLE_POP3
 31.1184 -    if((mta_mode == MODE_NONE) || (mta_mode == MODE_RUNQUEUE)){
 31.1185 +		if ((mta_mode == MODE_NONE) || (mta_mode == MODE_RUNQUEUE)) {
 31.1186 +			set_identity(conf.orig_uid, "getting mail");
 31.1187 +			if (do_get_online) {
 31.1188 +				if (route_name != NULL) {
 31.1189 +					conf.online_detect = g_strdup("argument");
 31.1190 +					set_online_name(route_name);
 31.1191 +				}
 31.1192 +				get_online();
 31.1193 +			} else {
 31.1194 +				if (get_name)
 31.1195 +					get_from_name(get_name);
 31.1196 +				else
 31.1197 +					get_all();
 31.1198 +			}
 31.1199 +		} else {
 31.1200 +			logwrite(LOG_ALERT, "get (-g) only allowed alone or together with queue run (-q)\n");
 31.1201 +		}
 31.1202 +#else
 31.1203 +		fprintf(stderr, "get (pop) support not compiled in\n");
 31.1204 +#endif
 31.1205 +	}
 31.1206  
 31.1207 -      set_identity(conf.orig_uid, "getting mail");
 31.1208 +	switch (mta_mode) {
 31.1209 +	case MODE_DAEMON:
 31.1210 +		mode_daemon(do_listen, queue_interval, argv);
 31.1211 +		break;
 31.1212 +	case MODE_RUNQUEUE:
 31.1213 +		{
 31.1214 +			/* queue runs */
 31.1215 +			set_identity(conf.orig_uid, "queue run");
 31.1216  
 31.1217 -      if(do_get_online){
 31.1218 -	if(route_name != NULL){
 31.1219 -	  conf.online_detect = g_strdup("argument");
 31.1220 -	  set_online_name(route_name);
 31.1221 +			if (do_runq)
 31.1222 +				exit_code = queue_run() ? EXIT_SUCCESS : EXIT_FAILURE;
 31.1223 +
 31.1224 +			if (do_runq_online) {
 31.1225 +				if (route_name != NULL) {
 31.1226 +					conf.online_detect = g_strdup("argument");
 31.1227 +					set_online_name(route_name);
 31.1228 +				}
 31.1229 +				exit_code =
 31.1230 +					queue_run_online() ? EXIT_SUCCESS : EXIT_FAILURE;
 31.1231 +			}
 31.1232 +		}
 31.1233 +		break;
 31.1234 +	case MODE_GET_DAEMON:
 31.1235 +#ifdef ENABLE_POP3
 31.1236 +		if (route_name != NULL) {
 31.1237 +			conf.online_detect = g_strdup("argument");
 31.1238 +			set_online_name(route_name);
 31.1239 +		}
 31.1240 +		mode_get_daemon(get_interval, argv);
 31.1241 +#endif
 31.1242 +		break;
 31.1243 +
 31.1244 +	case MODE_SMTP:
 31.1245 +#ifdef ENABLE_SMTP_SERVER
 31.1246 +		mode_smtp();
 31.1247 +#else
 31.1248 +		fprintf(stderr, "smtp server support not compiled in\n");
 31.1249 +#endif
 31.1250 +		break;
 31.1251 +
 31.1252 +	case MODE_LIST:
 31.1253 +		queue_list();
 31.1254 +		break;
 31.1255 +
 31.1256 +	case MODE_BI:
 31.1257 +		exit(EXIT_SUCCESS);
 31.1258 +		break;  /* well... */
 31.1259 +
 31.1260 +	case MODE_MCMD:
 31.1261 +		if (strcmp(M_cmd, "rm") == 0) {
 31.1262 +			gboolean ok = FALSE;
 31.1263 +
 31.1264 +			set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL);
 31.1265 +
 31.1266 +			if (is_privileged_user(conf.orig_uid)) {
 31.1267 +				for (; arg < argc; arg++) {
 31.1268 +					if (queue_delete(argv[arg]))
 31.1269 +						ok = TRUE;
 31.1270 +				}
 31.1271 +			} else {
 31.1272 +				struct passwd *pw = getpwuid(conf.orig_uid);
 31.1273 +				if (pw) {
 31.1274 +					for (; arg < argc; arg++) {
 31.1275 +						message *msg = msg_spool_read(argv[arg], FALSE);
 31.1276 +#ifdef ENABLE_IDENT
 31.1277 +						if (((msg->received_host == NULL) && (msg->received_prot == PROT_LOCAL))
 31.1278 +						    || is_in_netlist(msg->received_host, conf.ident_trusted_nets)) {
 31.1279 +#else
 31.1280 +						if ((msg->received_host == NULL) && (msg->received_prot == PROT_LOCAL)) {
 31.1281 +#endif
 31.1282 +							if (msg->ident) {
 31.1283 +								if (strcmp(pw->pw_name, msg->ident) == 0) {
 31.1284 +									if (queue_delete(argv[arg]))
 31.1285 +										ok = TRUE;
 31.1286 +								} else {
 31.1287 +									fprintf(stderr, "you do not own message id %s\n", argv[arg]);
 31.1288 +								}
 31.1289 +							} else
 31.1290 +								fprintf(stderr, "message %s does not have an ident.\n", argv[arg]);
 31.1291 +						} else {
 31.1292 +							fprintf(stderr, "message %s was not received locally or from a trusted network.\n", argv[arg]);
 31.1293 +						}
 31.1294 +					}
 31.1295 +				} else {
 31.1296 +					fprintf(stderr, "could not find a passwd entry for uid %d: %s\n", conf.orig_uid, strerror(errno));
 31.1297 +				}
 31.1298 +			}
 31.1299 +			exit(ok ? EXIT_SUCCESS : EXIT_FAILURE);
 31.1300 +		} else {
 31.1301 +			fprintf(stderr, "unknown command %s\n", M_cmd);
 31.1302 +			exit(EXIT_FAILURE);
 31.1303 +		}
 31.1304 +		break;
 31.1305 +
 31.1306 +	case MODE_ACCEPT:
 31.1307 +		{
 31.1308 +			guint accept_flags = (opt_t ? ACC_DEL_RCPTS | ACC_DEL_BCC | ACC_RCPT_FROM_HEAD : ACC_HEAD_FROM_RCPT)
 31.1309 +			                     | (opt_i ? ACC_NODOT_TERM : ACC_NODOT_RELAX);
 31.1310 +			mode_accept(return_path, full_sender_name, accept_flags, &(argv[arg]), argc - arg);
 31.1311 +			exit(exit_failure ? EXIT_FAILURE : EXIT_SUCCESS);
 31.1312 +		}
 31.1313 +		break;
 31.1314 +	case MODE_NONE:
 31.1315 +		break;
 31.1316 +	default:
 31.1317 +		fprintf(stderr, "unknown mode: %d\n", mta_mode);
 31.1318 +		break;
 31.1319  	}
 31.1320 -	get_online();
 31.1321 -      }else{
 31.1322 -	if(get_name)
 31.1323 -	  get_from_name(get_name);
 31.1324 -	else
 31.1325 -	  get_all();
 31.1326 -      }
 31.1327 -    }else{
 31.1328 -      logwrite(LOG_ALERT, "get (-g) only allowed alone or together with queue run (-q)\n");
 31.1329 -    }
 31.1330 -#else
 31.1331 -    fprintf(stderr, "get (pop) support not compiled in\n");
 31.1332 -#endif
 31.1333 -  }
 31.1334  
 31.1335 -  switch(mta_mode){
 31.1336 -  case MODE_DAEMON:
 31.1337 -    mode_daemon(do_listen, queue_interval, argv);
 31.1338 -    break;
 31.1339 -  case MODE_RUNQUEUE:
 31.1340 -    {
 31.1341 -      /* queue runs */
 31.1342 -      set_identity(conf.orig_uid, "queue run");
 31.1343 +	logclose();
 31.1344  
 31.1345 -      if(do_runq)
 31.1346 -	exit_code = queue_run() ? EXIT_SUCCESS : EXIT_FAILURE;
 31.1347 -
 31.1348 -      if(do_runq_online){
 31.1349 -	if(route_name != NULL){
 31.1350 -	  conf.online_detect = g_strdup("argument");
 31.1351 -	  set_online_name(route_name);
 31.1352 -	}
 31.1353 -	exit_code = queue_run_online() ? EXIT_SUCCESS : EXIT_FAILURE;
 31.1354 -      }
 31.1355 -    }
 31.1356 -    break;
 31.1357 -  case MODE_GET_DAEMON:
 31.1358 -#ifdef ENABLE_POP3
 31.1359 -    if(route_name != NULL){
 31.1360 -      conf.online_detect = g_strdup("argument");
 31.1361 -      set_online_name(route_name);
 31.1362 -    }
 31.1363 -    mode_get_daemon(get_interval, argv);
 31.1364 -#endif
 31.1365 -    break;
 31.1366 -
 31.1367 -  case MODE_SMTP:
 31.1368 -#ifdef ENABLE_SMTP_SERVER
 31.1369 -    mode_smtp();
 31.1370 -#else
 31.1371 -    fprintf(stderr, "smtp server support not compiled in\n");
 31.1372 -#endif
 31.1373 -    break;
 31.1374 -  case MODE_LIST:
 31.1375 -
 31.1376 -    queue_list();
 31.1377 -    break;
 31.1378 -
 31.1379 -  case MODE_BI:
 31.1380 -    
 31.1381 -    exit(EXIT_SUCCESS);
 31.1382 -    break; /* well... */
 31.1383 -    
 31.1384 -  case MODE_MCMD:
 31.1385 -    if(strcmp(M_cmd, "rm") == 0){
 31.1386 -      gboolean ok = FALSE;
 31.1387 -
 31.1388 -      set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL);
 31.1389 -
 31.1390 -      if(is_privileged_user(conf.orig_uid)){
 31.1391 -	for(; arg < argc; arg++){
 31.1392 -	  if(queue_delete(argv[arg]))
 31.1393 -	    ok = TRUE;
 31.1394 -	}
 31.1395 -      }else{
 31.1396 -	struct passwd *pw = getpwuid(conf.orig_uid);
 31.1397 -	if(pw){
 31.1398 -	  for(; arg < argc; arg++){
 31.1399 -	    message *msg = msg_spool_read(argv[arg], FALSE);
 31.1400 -#ifdef ENABLE_IDENT
 31.1401 -	    if(((msg->received_host == NULL) && (msg->received_prot == PROT_LOCAL)) ||
 31.1402 -	       is_in_netlist(msg->received_host, conf.ident_trusted_nets)){
 31.1403 -#else
 31.1404 -	      if((msg->received_host == NULL) && (msg->received_prot == PROT_LOCAL)){
 31.1405 -#endif
 31.1406 -	      if(msg->ident){
 31.1407 -		if(strcmp(pw->pw_name, msg->ident) == 0){
 31.1408 -		  if(queue_delete(argv[arg]))
 31.1409 -		    ok = TRUE;
 31.1410 -		}else{
 31.1411 -		  fprintf(stderr, "you do not own message id %s\n", argv[arg]);
 31.1412 -		}
 31.1413 -	      }else
 31.1414 -		fprintf(stderr, "message %s does not have an ident.\n", argv[arg]);
 31.1415 -	    }else{
 31.1416 -	      fprintf(stderr, "message %s was not received locally or from a trusted network.\n", argv[arg]);
 31.1417 -	    }
 31.1418 -	  }
 31.1419 -	}else{
 31.1420 -	  fprintf(stderr, "could not find a passwd entry for uid %d: %s\n", conf.orig_uid, strerror(errno));
 31.1421 -	}
 31.1422 -      }
 31.1423 -      exit(ok ? EXIT_SUCCESS : EXIT_FAILURE);
 31.1424 -    }else{
 31.1425 -      fprintf(stderr, "unknown command %s\n", M_cmd);
 31.1426 -      exit(EXIT_FAILURE);
 31.1427 -    }
 31.1428 -    break;
 31.1429 -
 31.1430 -    case MODE_ACCEPT:
 31.1431 -    {
 31.1432 -      guint accept_flags =
 31.1433 -	(opt_t ? ACC_DEL_RCPTS|ACC_DEL_BCC|ACC_RCPT_FROM_HEAD : ACC_HEAD_FROM_RCPT) |
 31.1434 -	(opt_i ? ACC_NODOT_TERM : ACC_NODOT_RELAX);
 31.1435 -    
 31.1436 -      mode_accept(return_path, full_sender_name, accept_flags, &(argv[arg]), argc - arg);
 31.1437 -
 31.1438 -      exit(exit_failure ? EXIT_FAILURE : EXIT_SUCCESS);
 31.1439 -    }
 31.1440 -    break;
 31.1441 -  case MODE_NONE:
 31.1442 -      break;
 31.1443 -  default:
 31.1444 -      fprintf(stderr, "unknown mode: %d\n", mta_mode);
 31.1445 -      break;
 31.1446 -    }
 31.1447 -    
 31.1448 -  logclose();
 31.1449 -
 31.1450 -  exit(exit_code);
 31.1451 +	exit(exit_code);
 31.1452  }
    32.1 --- a/src/masqmail.h	Mon Oct 27 16:21:27 2008 +0100
    32.2 +++ b/src/masqmail.h	Mon Oct 27 16:23:10 2008 +0100
    32.3 @@ -45,11 +45,9 @@
    32.4  
    32.5  #include "lookup.h"
    32.6  
    32.7 -typedef
    32.8 -struct _interface
    32.9 -{
   32.10 -  gchar *address;
   32.11 -  gint port;
   32.12 +typedef struct _interface {
   32.13 +	gchar *address;
   32.14 +	gint port;
   32.15  } interface;
   32.16  
   32.17  #define ADDR_FLAG_DELIVERED 0x01
   32.18 @@ -58,14 +56,13 @@
   32.19  #define ADDR_FLAG_LAST_ROUTE 0x40
   32.20  #define ADDR_FLAG_NOEXPAND 0x80
   32.21  
   32.22 -typedef struct _address
   32.23 -{
   32.24 -  gchar *address;
   32.25 -  gchar *local_part;
   32.26 -  gchar *domain;
   32.27 -  gint flags;
   32.28 -  GList *children;
   32.29 -  struct _address *parent;
   32.30 +typedef struct _address {
   32.31 +	gchar *address;
   32.32 +	gchar *local_part;
   32.33 +	gchar *domain;
   32.34 +	gint flags;
   32.35 +	GList *children;
   32.36 +	struct _address *parent;
   32.37  } address;
   32.38  
   32.39  #define addr_mark_delivered(addr) { addr->flags |= ADDR_FLAG_DELIVERED; }
   32.40 @@ -80,269 +77,247 @@
   32.41  #define addr_unmark_failed(addr) { addr->flags &= ~ADDR_FLAG_FAILED; }
   32.42  #define addr_is_failed(addr) ((addr->flags & ADDR_FLAG_FAILED) != 0 )
   32.43  
   32.44 -typedef
   32.45 -struct _connect_route
   32.46 -{
   32.47 -  gchar *name;
   32.48 -  gchar *filename;
   32.49 +typedef struct _connect_route {
   32.50 +	gchar *name;
   32.51 +	gchar *filename;
   32.52  
   32.53 -  gchar *protocol;
   32.54 +	gchar *protocol;
   32.55  
   32.56 -  gboolean is_local_net;
   32.57 -  gboolean last_route;
   32.58 +	gboolean is_local_net;
   32.59 +	gboolean last_route;
   32.60  
   32.61 -  GList *allowed_return_paths;
   32.62 -  GList *not_allowed_return_paths;
   32.63 -  GList *allowed_mail_locals;
   32.64 -  GList *not_allowed_mail_locals;
   32.65 -  GList *allowed_rcpt_domains;
   32.66 -  GList *not_allowed_rcpt_domains;
   32.67 +	GList *allowed_return_paths;
   32.68 +	GList *not_allowed_return_paths;
   32.69 +	GList *allowed_mail_locals;
   32.70 +	GList *not_allowed_mail_locals;
   32.71 +	GList *allowed_rcpt_domains;
   32.72 +	GList *not_allowed_rcpt_domains;
   32.73  
   32.74 -  interface *mail_host;
   32.75 -  gchar *wrapper;
   32.76 -  gboolean connect_error_fail;
   32.77 +	interface *mail_host;
   32.78 +	gchar *wrapper;
   32.79 +	gboolean connect_error_fail;
   32.80  
   32.81 -  gchar *helo_name;
   32.82 -  gboolean do_correct_helo;
   32.83 -  gboolean do_pipelining;
   32.84 +	gchar *helo_name;
   32.85 +	gboolean do_correct_helo;
   32.86 +	gboolean do_pipelining;
   32.87  
   32.88 -  gchar *set_h_from_domain;
   32.89 -  gchar *set_h_reply_to_domain;
   32.90 -  gchar *set_return_path_domain;
   32.91 +	gchar *set_h_from_domain;
   32.92 +	gchar *set_h_reply_to_domain;
   32.93 +	gchar *set_return_path_domain;
   32.94  
   32.95 -  GList *map_h_from_addresses;
   32.96 -  GList *map_h_reply_to_addresses;
   32.97 -  GList *map_h_mail_followup_to_addresses;
   32.98 -  GList *map_return_path_addresses;
   32.99 +	GList *map_h_from_addresses;
  32.100 +	GList *map_h_reply_to_addresses;
  32.101 +	GList *map_h_mail_followup_to_addresses;
  32.102 +	GList *map_return_path_addresses;
  32.103  
  32.104 -  gboolean expand_h_sender_domain;
  32.105 -  gboolean expand_h_sender_address;
  32.106 +	gboolean expand_h_sender_domain;
  32.107 +	gboolean expand_h_sender_address;
  32.108  
  32.109 -  GList *resolve_list;
  32.110 +	GList *resolve_list;
  32.111  
  32.112 -  gchar *auth_name;
  32.113 -  gchar *auth_login;
  32.114 -  gchar *auth_secret;
  32.115 +	gchar *auth_name;
  32.116 +	gchar *auth_login;
  32.117 +	gchar *auth_secret;
  32.118  
  32.119 -  gchar *pop3_login;
  32.120 +	gchar *pop3_login;
  32.121  
  32.122 -  gchar *pipe;
  32.123 -  
  32.124 -  gboolean pipe_fromline;
  32.125 -  gboolean pipe_fromhack;
  32.126 +	gchar *pipe;
  32.127 +
  32.128 +	gboolean pipe_fromline;
  32.129 +	gboolean pipe_fromhack;
  32.130  } connect_route;
  32.131  
  32.132 -typedef struct _get_conf
  32.133 -{
  32.134 -  gchar *protocol;
  32.135 -  gchar *server_name;
  32.136 -  guint server_port;
  32.137 -  gchar *wrapper;
  32.138 -  gchar *login_user;
  32.139 -  gchar *login_pass;
  32.140 -  address *address;
  32.141 -  address *return_path;
  32.142 -  gboolean do_keep;
  32.143 -  gboolean do_uidl;
  32.144 -  gboolean do_uidl_dele;
  32.145 -  gint max_size;
  32.146 -  gboolean max_size_delete;
  32.147 -  gint max_count;
  32.148 +typedef struct _get_conf {
  32.149 +	gchar *protocol;
  32.150 +	gchar *server_name;
  32.151 +	guint server_port;
  32.152 +	gchar *wrapper;
  32.153 +	gchar *login_user;
  32.154 +	gchar *login_pass;
  32.155 +	address *address;
  32.156 +	address *return_path;
  32.157 +	gboolean do_keep;
  32.158 +	gboolean do_uidl;
  32.159 +	gboolean do_uidl_dele;
  32.160 +	gint max_size;
  32.161 +	gboolean max_size_delete;
  32.162 +	gint max_count;
  32.163  
  32.164 -  GList *resolve_list;
  32.165 +	GList *resolve_list;
  32.166  
  32.167  } get_conf;
  32.168  
  32.169 -typedef
  32.170 -struct _masqmail_conf
  32.171 -{
  32.172 -  gint mail_uid;
  32.173 -  gint mail_gid;
  32.174 +typedef struct _masqmail_conf {
  32.175 +	gint mail_uid;
  32.176 +	gint mail_gid;
  32.177  
  32.178 -  gint orig_uid;
  32.179 -  gint orig_gid;
  32.180 +	gint orig_uid;
  32.181 +	gint orig_gid;
  32.182  
  32.183 -  gboolean run_as_user;
  32.184 +	gboolean run_as_user;
  32.185  
  32.186 -  gchar *mail_dir;
  32.187 -  gchar *lock_dir;
  32.188 -  gchar *spool_dir;
  32.189 -  gchar *log_dir;
  32.190 +	gchar *mail_dir;
  32.191 +	gchar *lock_dir;
  32.192 +	gchar *spool_dir;
  32.193 +	gchar *log_dir;
  32.194  
  32.195 -  gint debug_level;
  32.196 -  gboolean use_syslog;
  32.197 -  guint log_max_pri;
  32.198 +	gint debug_level;
  32.199 +	gboolean use_syslog;
  32.200 +	guint log_max_pri;
  32.201  
  32.202 -  gchar *host_name;
  32.203 -  GList *local_hosts;
  32.204 -  GList *local_addresses;
  32.205 -  GList *not_local_addresses;
  32.206 -  GList *local_nets;
  32.207 -  GList *listen_addresses;
  32.208 +	gchar *host_name;
  32.209 +	GList *local_hosts;
  32.210 +	GList *local_addresses;
  32.211 +	GList *not_local_addresses;
  32.212 +	GList *local_nets;
  32.213 +	GList *listen_addresses;
  32.214  
  32.215 -  guint remote_port;
  32.216 +	guint remote_port;
  32.217  
  32.218 -  gboolean do_save_envelope_to;
  32.219 +	gboolean do_save_envelope_to;
  32.220  
  32.221 -  gboolean defer_all;
  32.222 -  gboolean do_relay;
  32.223 +	gboolean defer_all;
  32.224 +	gboolean do_relay;
  32.225  
  32.226 -  GList *ident_trusted_nets;
  32.227 +	GList *ident_trusted_nets;
  32.228  
  32.229 -  gboolean do_queue;
  32.230 +	gboolean do_queue;
  32.231  
  32.232 -  gboolean do_verbose;
  32.233 +	gboolean do_verbose;
  32.234  
  32.235 -  gchar *mbox_default;
  32.236 -  GList *mbox_users;
  32.237 -  GList *mda_users;
  32.238 -  GList *maildir_users;
  32.239 +	gchar *mbox_default;
  32.240 +	GList *mbox_users;
  32.241 +	GList *mda_users;
  32.242 +	GList *maildir_users;
  32.243  
  32.244 -  gchar *mda;
  32.245 -  gboolean mda_fromline;
  32.246 -  gboolean mda_fromhack;
  32.247 +	gchar *mda;
  32.248 +	gboolean mda_fromline;
  32.249 +	gboolean mda_fromhack;
  32.250  
  32.251 -  gboolean pipe_fromline;
  32.252 -  gboolean pipe_fromhack;
  32.253 +	gboolean pipe_fromline;
  32.254 +	gboolean pipe_fromhack;
  32.255  
  32.256 -  gchar *alias_file;
  32.257 -  int (*alias_local_cmp)(const char *, const char *);
  32.258 +	gchar *alias_file;
  32.259 +	int (*alias_local_cmp) (const char *, const char *);
  32.260  
  32.261 -  GList *local_net_routes;
  32.262 -  GList *connect_routes; /* list of pairs which point to lists */
  32.263 +	GList *local_net_routes;
  32.264 +	GList *connect_routes;  /* list of pairs which point to lists */
  32.265  
  32.266 -  gchar *online_detect;
  32.267 -  gchar *online_file;
  32.268 -  gchar *online_pipe;
  32.269 -  interface *mserver_iface;
  32.270 +	gchar *online_detect;
  32.271 +	gchar *online_file;
  32.272 +	gchar *online_pipe;
  32.273 +	interface *mserver_iface;
  32.274  
  32.275 -  GList *get_names;
  32.276 -  GList *online_gets; /* list of pairs which point to lists */
  32.277 +	GList *get_names;
  32.278 +	GList *online_gets;  /* list of pairs which point to lists */
  32.279  
  32.280 -  gchar *errmsg_file;
  32.281 -  gchar *warnmsg_file;
  32.282 -  GList *warn_intervals;
  32.283 -  gint max_defer_time;
  32.284 +	gchar *errmsg_file;
  32.285 +	gchar *warnmsg_file;
  32.286 +	GList *warn_intervals;
  32.287 +	gint max_defer_time;
  32.288  
  32.289 -  gchar *log_user;
  32.290 +	gchar *log_user;
  32.291  } masqmail_conf;
  32.292  
  32.293  extern masqmail_conf conf;
  32.294  
  32.295 -typedef
  32.296 -struct _table_pair
  32.297 -{
  32.298 -  gchar *key;
  32.299 -  gpointer *value;
  32.300 +typedef struct _table_pair {
  32.301 +	gchar *key;
  32.302 +	gpointer *value;
  32.303  } table_pair;
  32.304  
  32.305  
  32.306 -typedef
  32.307 -enum _prot_id
  32.308 -{
  32.309 -  PROT_LOCAL = 0,
  32.310 -  PROT_BSMTP,
  32.311 -  PROT_SMTP,
  32.312 -  PROT_ESMTP,
  32.313 -  PROT_POP3,
  32.314 -  PROT_APOP,
  32.315 -  PROT_NUM
  32.316 -}prot_id;
  32.317 +typedef enum _prot_id {
  32.318 +	PROT_LOCAL = 0,
  32.319 +	PROT_BSMTP,
  32.320 +	PROT_SMTP,
  32.321 +	PROT_ESMTP,
  32.322 +	PROT_POP3,
  32.323 +	PROT_APOP,
  32.324 +	PROT_NUM
  32.325 +} prot_id;
  32.326  
  32.327  extern gchar *prot_names[];
  32.328  
  32.329 -typedef
  32.330 -enum _header_id
  32.331 -{
  32.332 -  HEAD_FROM = 0,
  32.333 -  HEAD_SENDER,
  32.334 -  HEAD_TO,
  32.335 -  HEAD_CC,
  32.336 -  HEAD_BCC,
  32.337 -  HEAD_DATE,
  32.338 -  HEAD_MESSAGE_ID,
  32.339 -  HEAD_REPLY_TO,
  32.340 -  HEAD_SUBJECT,
  32.341 -  HEAD_RETURN_PATH,
  32.342 -  HEAD_ENVELOPE_TO,
  32.343 -  HEAD_RECEIVED,
  32.344 -  HEAD_NUM_IDS,
  32.345 -  HEAD_STATUS,
  32.346 -  HEAD_UNKNOWN = HEAD_NUM_IDS,
  32.347 -  HEAD_NONE = -1,
  32.348 -}header_id;
  32.349 +typedef enum _header_id {
  32.350 +	HEAD_FROM = 0,
  32.351 +	HEAD_SENDER,
  32.352 +	HEAD_TO,
  32.353 +	HEAD_CC,
  32.354 +	HEAD_BCC,
  32.355 +	HEAD_DATE,
  32.356 +	HEAD_MESSAGE_ID,
  32.357 +	HEAD_REPLY_TO,
  32.358 +	HEAD_SUBJECT,
  32.359 +	HEAD_RETURN_PATH,
  32.360 +	HEAD_ENVELOPE_TO,
  32.361 +	HEAD_RECEIVED,
  32.362 +	HEAD_NUM_IDS,
  32.363 +	HEAD_STATUS,
  32.364 +	HEAD_UNKNOWN = HEAD_NUM_IDS,
  32.365 +	HEAD_NONE = -1,
  32.366 +} header_id;
  32.367  
  32.368 -typedef
  32.369 -struct _header_name
  32.370 -{
  32.371 -  gchar *header;
  32.372 -  header_id id;
  32.373 -}header_name;
  32.374 +typedef struct _header_name {
  32.375 +	gchar *header;
  32.376 +	header_id id;
  32.377 +} header_name;
  32.378  
  32.379 -typedef
  32.380 -struct _header
  32.381 -{
  32.382 -  header_id id;
  32.383 -  gchar *header;
  32.384 -  gchar *value;
  32.385 -}header;
  32.386 +typedef struct _header {
  32.387 +	header_id id;
  32.388 +	gchar *header;
  32.389 +	gchar *value;
  32.390 +} header;
  32.391  
  32.392  
  32.393 -typedef
  32.394 -struct _message
  32.395 -{
  32.396 -  gchar *uid;
  32.397 +typedef struct _message {
  32.398 +	gchar *uid;
  32.399  
  32.400 -  gchar *received_host;
  32.401 -  prot_id received_prot;
  32.402 -  gchar *ident;
  32.403 -  gint transfer_id; /* for multiple messages per transfer */
  32.404 +	gchar *received_host;
  32.405 +	prot_id received_prot;
  32.406 +	gchar *ident;
  32.407 +	gint transfer_id;  /* for multiple messages per transfer */
  32.408  
  32.409 -  address *return_path;
  32.410 -  GList *rcpt_list;
  32.411 -  GList *non_rcpt_list;
  32.412 +	address *return_path;
  32.413 +	GList *rcpt_list;
  32.414 +	GList *non_rcpt_list;
  32.415  
  32.416 -  GList *hdr_list;
  32.417 -  GList *data_list;
  32.418 +	GList *hdr_list;
  32.419 +	GList *data_list;
  32.420  
  32.421 -  gint data_size;
  32.422 -  time_t received_time;
  32.423 -  time_t warned_time;
  32.424 +	gint data_size;
  32.425 +	time_t received_time;
  32.426 +	time_t warned_time;
  32.427  
  32.428 -  gchar *full_sender_name;
  32.429 -}message;
  32.430 +	gchar *full_sender_name;
  32.431 +} message;
  32.432  
  32.433 -typedef
  32.434 -struct _msg_out
  32.435 -{
  32.436 -  message *msg;
  32.437 -  
  32.438 -  address *return_path;
  32.439 -  GList *rcpt_list;
  32.440 +typedef struct _msg_out {
  32.441 +	message *msg;
  32.442  
  32.443 -  GList *hdr_list;
  32.444 -  GList *xtra_hdr_list;
  32.445 -}msg_out;
  32.446 +	address *return_path;
  32.447 +	GList *rcpt_list;
  32.448  
  32.449 -typedef
  32.450 -struct _msgout_perhost
  32.451 -{
  32.452 -  gchar *host;
  32.453 -  GList *msgout_list;
  32.454 +	GList *hdr_list;
  32.455 +	GList *xtra_hdr_list;
  32.456 +} msg_out;
  32.457 +
  32.458 +typedef struct _msgout_perhost {
  32.459 +	gchar *host;
  32.460 +	GList *msgout_list;
  32.461  } msgout_perhost;
  32.462  
  32.463  /* flags for accept() */
  32.464  /*#define ACC_LOCAL      0x01 (we better use received_host == NULL) */
  32.465 -#define ACC_HEAD_FROM_RCPT 0x01 /* create To: Header from rcpt_list (cmd line) */
  32.466 -#define ACC_DEL_RCPTS      0x02 /* -t option, delete rcpts */
  32.467 -#define ACC_DEL_BCC        0x04 /* -t option, delete Bcc header */
  32.468 -#define ACC_RCPT_FROM_HEAD 0x08 /* -t option, get rcpts from headers */
  32.469 -#define ACC_NODOT_TERM     0x10 /* a dot on a line itself does not end
  32.470 -				   the message (-oi option) */
  32.471 -#define ACC_NO_RECVD_HDR   0x20 /* do not create a Received: header */
  32.472 -#define ACC_MAIL_FROM_HEAD 0x40 /* get return path from header */
  32.473 -#define ACC_NODOT_RELAX    0x80 /* do not be picky if message ist not terminated by a dot on a line */
  32.474 -#define ACC_SAVE_ENVELOPE_TO 0x0100 /* save an existent Envelope-to header as X-Orig-Envelope-to */
  32.475 +#define ACC_HEAD_FROM_RCPT 0x01  /* create To: Header from rcpt_list (cmd line) */
  32.476 +#define ACC_DEL_RCPTS      0x02  /* -t option, delete rcpts */
  32.477 +#define ACC_DEL_BCC        0x04  /* -t option, delete Bcc header */
  32.478 +#define ACC_RCPT_FROM_HEAD 0x08  /* -t option, get rcpts from headers */
  32.479 +#define ACC_NODOT_TERM     0x10  /* a dot on a line itself does not end the message (-oi option) */
  32.480 +#define ACC_NO_RECVD_HDR   0x20  /* do not create a Received: header */
  32.481 +#define ACC_MAIL_FROM_HEAD 0x40  /* get return path from header */
  32.482 +#define ACC_NODOT_RELAX    0x80  /* do not be picky if message ist not terminated by a dot on a line */
  32.483 +#define ACC_SAVE_ENVELOPE_TO 0x0100  /* save an existent Envelope-to header as X-Orig-Envelope-to */
  32.484  
  32.485  #define DLVR_LOCAL 0x01
  32.486  #define DLVR_LAN 0x02
  32.487 @@ -353,192 +328,171 @@
  32.488  #define MSGSTR_FROMLINE 0x01
  32.489  #define MSGSTR_FROMHACK 0x02
  32.490  
  32.491 -typedef
  32.492 -enum _accept_error
  32.493 -{
  32.494 -  AERR_OK = 0,
  32.495 -  AERR_TIMEOUT,
  32.496 -  AERR_EOF,
  32.497 -  AERR_OVERFLOW,
  32.498 -  AERR_SYNTAX,
  32.499 -  AERR_NOSPOOL,
  32.500 -  AERR_NORCPT,
  32.501 -  AERR_UNKNOWN
  32.502 -}accept_error;
  32.503 +typedef enum _accept_error {
  32.504 +	AERR_OK = 0,
  32.505 +	AERR_TIMEOUT,
  32.506 +	AERR_EOF,
  32.507 +	AERR_OVERFLOW,
  32.508 +	AERR_SYNTAX,
  32.509 +	AERR_NOSPOOL,
  32.510 +	AERR_NORCPT,
  32.511 +	AERR_UNKNOWN
  32.512 +} accept_error;
  32.513  
  32.514  #define BUF_LEN 1024
  32.515  #define MAX_ADDRESS 256
  32.516  #define MAX_DATALINE 4096
  32.517  
  32.518 -typedef
  32.519 -enum _smtp_cmd_id
  32.520 -{
  32.521 -  SMTP_HELO = 0,
  32.522 -  SMTP_EHLO,
  32.523 -  SMTP_MAIL_FROM,
  32.524 -  SMTP_RCPT_TO,
  32.525 -  SMTP_DATA,
  32.526 -  SMTP_QUIT,
  32.527 -  SMTP_RSET,
  32.528 -  SMTP_NOOP,
  32.529 -  SMTP_HELP,
  32.530 -  SMTP_NUM_IDS,
  32.531 -  SMTP_EOF = -1,
  32.532 -  SMTP_ERROR = -2,
  32.533 +typedef enum _smtp_cmd_id {
  32.534 +	SMTP_HELO = 0,
  32.535 +	SMTP_EHLO,
  32.536 +	SMTP_MAIL_FROM,
  32.537 +	SMTP_RCPT_TO,
  32.538 +	SMTP_DATA,
  32.539 +	SMTP_QUIT,
  32.540 +	SMTP_RSET,
  32.541 +	SMTP_NOOP,
  32.542 +	SMTP_HELP,
  32.543 +	SMTP_NUM_IDS,
  32.544 +	SMTP_EOF = -1,
  32.545 +	SMTP_ERROR = -2,
  32.546  } smtp_cmd_id;
  32.547  
  32.548 -typedef
  32.549 -struct _smtp_cmd
  32.550 -{
  32.551 -  smtp_cmd_id id;
  32.552 -  gchar *cmd;
  32.553 +typedef struct _smtp_cmd {
  32.554 +	smtp_cmd_id id;
  32.555 +	gchar *cmd;
  32.556  } smtp_cmd;
  32.557  
  32.558 -typedef
  32.559 -struct _smtp_connection
  32.560 -{
  32.561 -  gchar *remote_host;
  32.562 +typedef struct _smtp_connection {
  32.563 +	gchar *remote_host;
  32.564  
  32.565 -  prot_id prot;
  32.566 -  gint next_id;
  32.567 -  
  32.568 -  gboolean helo_seen;
  32.569 -  gboolean from_seen;
  32.570 -  gboolean rcpt_seen;
  32.571 +	prot_id prot;
  32.572 +	gint next_id;
  32.573  
  32.574 -  message *msg;
  32.575 -}smtp_connection;
  32.576 +	gboolean helo_seen;
  32.577 +	gboolean from_seen;
  32.578 +	gboolean rcpt_seen;
  32.579 +
  32.580 +	message *msg;
  32.581 +} smtp_connection;
  32.582  
  32.583  /* alias.c*/
  32.584 -gboolean addr_is_local(address *addr);
  32.585 -GList *alias_expand(GList *alias_table, GList *rcpt_list, GList *non_rcpt_list);
  32.586 +gboolean addr_is_local(address * addr);
  32.587 +GList *alias_expand(GList * alias_table, GList * rcpt_list, GList * non_rcpt_list);
  32.588  
  32.589  /* child.c */
  32.590  int child(const char *command);
  32.591  
  32.592  /* conf.c */
  32.593  void init_conf();
  32.594 -gboolean read_conf(gchar *filename);
  32.595 -connect_route *read_route(gchar *filename, gboolean is_local_net);
  32.596 -GList *read_route_list(GList *rf_list, gboolean is_local_net);
  32.597 -void destroy_route(connect_route *r);
  32.598 -void destroy_route_list(GList *list);
  32.599 -get_conf *read_get_conf(gchar *filename);
  32.600 -void destroy_get_conf(get_conf *gc);
  32.601 +gboolean read_conf(gchar * filename);
  32.602 +connect_route *read_route(gchar * filename, gboolean is_local_net);
  32.603 +GList *read_route_list(GList * rf_list, gboolean is_local_net);
  32.604 +void destroy_route(connect_route * r);
  32.605 +void destroy_route_list(GList * list);
  32.606 +get_conf *read_get_conf(gchar * filename);
  32.607 +void destroy_get_conf(get_conf * gc);
  32.608  connect_route *create_local_route();
  32.609  
  32.610  /* expand.c */
  32.611 -GList *var_table_rcpt(GList *var_table, address *rcpt);
  32.612 -GList *var_table_msg(GList *var_table, message *msg);
  32.613 -GList *var_table_conf(GList *var_table);
  32.614 -gint expand(GList *var_list, gchar *format, gchar *result, gint result_len);
  32.615 +GList *var_table_rcpt(GList * var_table, address * rcpt);
  32.616 +GList *var_table_msg(GList * var_table, message * msg);
  32.617 +GList *var_table_conf(GList * var_table);
  32.618 +gint expand(GList * var_list, gchar * format, gchar * result, gint result_len);
  32.619  
  32.620  /* message.c */
  32.621  message *create_message(void);
  32.622 -void destroy_message(message *msg);
  32.623 -void destroy_msg_list(GList *msg_list);
  32.624 -void msg_free_data(message *msg);
  32.625 -gint msg_calc_size(message *msg, gboolean is_smtp);
  32.626 +void destroy_message(message * msg);
  32.627 +void destroy_msg_list(GList * msg_list);
  32.628 +void msg_free_data(message * msg);
  32.629 +gint msg_calc_size(message * msg, gboolean is_smtp);
  32.630  
  32.631 -msg_out *create_msg_out(message *msg);
  32.632 -msg_out *clone_msg_out(msg_out *msgout_orig);
  32.633 -GList *create_msg_out_list(GList *msg_list);
  32.634 -void destroy_msg_out(msg_out *msgout);
  32.635 -void destroy_msg_out_list(GList *msgout_list);
  32.636 +msg_out *create_msg_out(message * msg);
  32.637 +msg_out *clone_msg_out(msg_out * msgout_orig);
  32.638 +GList *create_msg_out_list(GList * msg_list);
  32.639 +void destroy_msg_out(msg_out * msgout);
  32.640 +void destroy_msg_out_list(GList * msgout_list);
  32.641  
  32.642  /* address.c */
  32.643 -address *create_address(gchar *path, gboolean is_rfc821);
  32.644 -address *create_address_qualified(gchar *path, gboolean is_rfc821,
  32.645 -				  gchar *domain);
  32.646 -address *create_address_pipe(gchar *path);
  32.647 -void destroy_address(address *addr);
  32.648 -address *copy_modify_address(const address *orig, gchar *l_part, gchar *dom);
  32.649 +address *create_address(gchar * path, gboolean is_rfc821);
  32.650 +address *create_address_qualified(gchar * path, gboolean is_rfc821, gchar * domain);
  32.651 +address *create_address_pipe(gchar * path);
  32.652 +void destroy_address(address * addr);
  32.653 +address *copy_modify_address(const address * orig, gchar * l_part, gchar * dom);
  32.654  #define copy_address(addr) copy_modify_address(addr, NULL, NULL)
  32.655 -gboolean addr_isequal(address *addr1, address *addr2);
  32.656 -gboolean addr_isequal_parent(address *addr1, address *addr2);
  32.657 -address *addr_find_ancestor(address *addr);
  32.658 -gboolean addr_is_delivered_children(address *addr);
  32.659 -gboolean addr_is_finished_children(address *addr);
  32.660 -gchar *addr_string(address *addr);
  32.661 -gint addr_match(address *addr1, address *addr2);
  32.662 +gboolean addr_isequal(address * addr1, address * addr2);
  32.663 +gboolean addr_isequal_parent(address * addr1, address * addr2);
  32.664 +address *addr_find_ancestor(address * addr);
  32.665 +gboolean addr_is_delivered_children(address * addr);
  32.666 +gboolean addr_is_finished_children(address * addr);
  32.667 +gchar *addr_string(address * addr);
  32.668 +gint addr_match(address * addr1, address * addr2);
  32.669  
  32.670  /* accept.c */
  32.671 -accept_error accept_message(FILE *in, message *msg,
  32.672 -			    guint flags);
  32.673 -accept_error accept_message_prepare(message *msg, guint flags);
  32.674 +accept_error accept_message(FILE * in, message * msg, guint flags);
  32.675 +accept_error accept_message_prepare(message * msg, guint flags);
  32.676  
  32.677  /* header.c */
  32.678  gchar *rec_timestamp();
  32.679 -GList *find_header(GList *hdr_list, header_id id, gchar *hdr_str);
  32.680 -void header_unfold(header *hdr);
  32.681 -void header_fold(header *hdr);
  32.682 -header *create_header(header_id id, gchar *fmt, ...);
  32.683 -void destroy_header(header *hdr);
  32.684 -header *copy_header(header *hdr);
  32.685 -header *get_header(gchar *line);
  32.686 +GList *find_header(GList * hdr_list, header_id id, gchar * hdr_str);
  32.687 +void header_unfold(header * hdr);
  32.688 +void header_fold(header * hdr);
  32.689 +header *create_header(header_id id, gchar * fmt, ...);
  32.690 +void destroy_header(header * hdr);
  32.691 +header *copy_header(header * hdr);
  32.692 +header *get_header(gchar * line);
  32.693  
  32.694  /* smtp_in.c */
  32.695 -void smtp_in(FILE *in, FILE *out, gchar *remote_host, gchar *ident);
  32.696 +void smtp_in(FILE * in, FILE * out, gchar * remote_host, gchar * ident);
  32.697  
  32.698  /* listen.c */
  32.699 -void listen_port(GList *addr_list, gint qival, char *argv[]);
  32.700 +void listen_port(GList * addr_list, gint qival, char *argv[]);
  32.701  
  32.702  /* parse.c */
  32.703 -gboolean split_address(const gchar *path, gchar **local_part, gchar **domain,
  32.704 -		       gboolean is_rfc821);
  32.705 -gboolean parse_address_rfc822(gchar *string,
  32.706 -		       gchar **local_begin, gchar **local_end,
  32.707 -		       gchar **domain_begin, gchar **domain_end,
  32.708 -			      gchar **address_end);
  32.709 -gboolean parse_address_rfc821(gchar *string,
  32.710 -			      gchar **local_begin, gchar **local_end,
  32.711 -			      gchar **domain_begin, gchar **domain_end,
  32.712 -			      gchar **address_end);
  32.713 -address *_create_address(gchar *string, gchar **end, gboolean is_rfc821);
  32.714 -address *create_address_rfc821(gchar *string, gchar **end);
  32.715 -address *create_address_rfc822(gchar *string, gchar **end);
  32.716 -GList *addr_list_append_rfc822(GList *addr_list, gchar *string, gchar *domain);
  32.717 -gboolean addr_isequal(address *addr1, address *addr2);
  32.718 +gboolean split_address(const gchar * path, gchar ** local_part, gchar ** domain, gboolean is_rfc821);
  32.719 +gboolean parse_address_rfc822(gchar * string, gchar ** local_begin, gchar ** local_end, gchar ** domain_begin, gchar ** domain_end, gchar ** address_end);
  32.720 +gboolean parse_address_rfc821(gchar * string, gchar ** local_begin, gchar ** local_end, gchar ** domain_begin, gchar ** domain_end, gchar ** address_end);
  32.721 +address *_create_address(gchar * string, gchar ** end, gboolean is_rfc821);
  32.722 +address *create_address_rfc821(gchar * string, gchar ** end);
  32.723 +address *create_address_rfc822(gchar * string, gchar ** end);
  32.724 +GList *addr_list_append_rfc822(GList * addr_list, gchar * string, gchar * domain);
  32.725 +gboolean addr_isequal(address * addr1, address * addr2);
  32.726  
  32.727  /* connect.c */
  32.728 -mxip_addr *connect_hostlist(int *psockfd, gchar *host, guint port,
  32.729 -			  GList *addr_list);
  32.730 -mxip_addr *connect_resolvelist(int *psockfd, gchar *host, guint port,
  32.731 -			     GList *res_funcs);
  32.732 +mxip_addr *connect_hostlist(int *psockfd, gchar * host, guint port, GList * addr_list);
  32.733 +mxip_addr *connect_resolvelist(int *psockfd, gchar * host, guint port, GList * res_funcs);
  32.734  
  32.735  /* deliver.c */
  32.736 -void msg_rcptlist_local(GList *rcpt_list, GList **, GList **);
  32.737 -gboolean deliver_local(msg_out *msgout);
  32.738 -gboolean deliver_msglist_host(connect_route *route, GList *msg_list, gchar *host, GList *res_list);
  32.739 -gboolean deliver_route_msgout_list(connect_route *route, GList *msgout_list);
  32.740 -gboolean deliver_route_msg_list(connect_route *route, GList *msgout_list);
  32.741 -gboolean deliver_finish(msg_out *msgout);
  32.742 -gboolean deliver_finish_list(GList *msgout_list);
  32.743 -gboolean deliver_msg_list(GList *msg_list, guint flags);
  32.744 -gboolean deliver(message *msg);
  32.745 +void msg_rcptlist_local(GList * rcpt_list, GList **, GList **);
  32.746 +gboolean deliver_local(msg_out * msgout);
  32.747 +gboolean deliver_msglist_host(connect_route * route, GList * msg_list, gchar * host, GList * res_list);
  32.748 +gboolean deliver_route_msgout_list(connect_route * route, GList * msgout_list);
  32.749 +gboolean deliver_route_msg_list(connect_route * route, GList * msgout_list);
  32.750 +gboolean deliver_finish(msg_out * msgout);
  32.751 +gboolean deliver_finish_list(GList * msgout_list);
  32.752 +gboolean deliver_msg_list(GList * msg_list, guint flags);
  32.753 +gboolean deliver(message * msg);
  32.754  
  32.755  /* fail_msg.c */
  32.756 -gboolean fail_msg(message *msg, gchar *template,
  32.757 -		  GList *failed_rcpts, gchar *err_fmt, va_list args);
  32.758 -gboolean warn_msg(message *msg, gchar *template,
  32.759 -		  GList *failed_rcpts, gchar *err_fmt, va_list args);
  32.760 +gboolean fail_msg(message * msg, gchar * template, GList * failed_rcpts, gchar * err_fmt, va_list args);
  32.761 +gboolean warn_msg(message * msg, gchar * template, GList * failed_rcpts, gchar * err_fmt, va_list args);
  32.762  
  32.763  /* get.c */
  32.764 -gboolean get_from_file(gchar *fname);
  32.765 -gboolean get_from_name(gchar *name);
  32.766 +gboolean get_from_file(gchar * fname);
  32.767 +gboolean get_from_name(gchar * name);
  32.768  gboolean get_all(void);
  32.769  void get_online(void);
  32.770  void get_daemon(gint gival, char *argv[]);
  32.771 -gboolean pop_before_smtp(gchar *fname);
  32.772 +gboolean pop_before_smtp(gchar * fname);
  32.773  
  32.774  /* interface.c */
  32.775 -gboolean init_sockaddr(struct sockaddr_in *name, interface *iface);
  32.776 -int make_server_socket(interface *iface);
  32.777 +gboolean init_sockaddr(struct sockaddr_in *name, interface * iface);
  32.778 +int make_server_socket(interface * iface);
  32.779  
  32.780  /* local.c */
  32.781 -gboolean append_file(message *msg, GList *hdr_list, gchar *user);
  32.782 -gboolean maildir_out(message *msg, GList *hdr_list, gchar *user, guint flags);
  32.783 -gboolean pipe_out(message *msg, GList *hdr_list, address *rcpt, gchar *cmd, guint flags);
  32.784 +gboolean append_file(message * msg, GList * hdr_list, gchar * user);
  32.785 +gboolean maildir_out(message * msg, GList * hdr_list, gchar * user, guint flags);
  32.786 +gboolean pipe_out(message * msg, GList * hdr_list, address * rcpt, gchar * cmd, guint flags);
  32.787  
  32.788  /* log.c */
  32.789  gchar *ext_strerror(int err);
  32.790 @@ -551,63 +505,60 @@
  32.791  void maillog(const char *fmt, ...);
  32.792  
  32.793  /* spool.c */
  32.794 -gboolean spool_read_data(message *msg);
  32.795 -gboolean spool_read_data(message *msg);
  32.796 -message *msg_spool_read(gchar *uid, gboolean do_readdata);
  32.797 -gboolean spool_write(message *msg, gboolean do_writedata);
  32.798 -gboolean spool_lock(gchar *uid);
  32.799 -gboolean spool_unlock(gchar *uid);
  32.800 -gboolean spool_delete_all(message *msg);
  32.801 +gboolean spool_read_data(message * msg);
  32.802 +gboolean spool_read_data(message * msg);
  32.803 +message *msg_spool_read(gchar * uid, gboolean do_readdata);
  32.804 +gboolean spool_write(message * msg, gboolean do_writedata);
  32.805 +gboolean spool_lock(gchar * uid);
  32.806 +gboolean spool_unlock(gchar * uid);
  32.807 +gboolean spool_delete_all(message * msg);
  32.808  
  32.809  /* queue.c */
  32.810  GList *read_queue(gboolean do_readdata);
  32.811  gboolean queue_run(void);
  32.812  gboolean queue_run_online(void);
  32.813  void queue_list(void);
  32.814 -gboolean queue_delete(gchar *uid);
  32.815 +gboolean queue_delete(gchar * uid);
  32.816  
  32.817  /* online.c */
  32.818  gchar *detect_online();
  32.819 -void set_online_name(gchar *name);
  32.820 +void set_online_name(gchar * name);
  32.821  
  32.822  /* permissions.c */
  32.823  gboolean is_ingroup(uid_t uid, gid_t gid);
  32.824 -void set_euidgid(gint uid, gint gid, uid_t *old_uid, gid_t *old_gid);
  32.825 -void set_identity(uid_t old_uid, gchar *task_name);
  32.826 +void set_euidgid(gint uid, gint gid, uid_t * old_uid, gid_t * old_gid);
  32.827 +void set_identity(uid_t old_uid, gchar * task_name);
  32.828  
  32.829  /* rewrite.c */
  32.830 -gboolean set_address_header_domain(header *hdr, gchar *domain);
  32.831 -gboolean map_address_header(header *hdr, GList *table);
  32.832 +gboolean set_address_header_domain(header * hdr, gchar * domain);
  32.833 +gboolean map_address_header(header * hdr, GList * table);
  32.834  
  32.835  /* route.c */
  32.836 -msgout_perhost *create_msgout_perhost(gchar *host);
  32.837 -void destroy_msgout_perhost(msgout_perhost *mo_ph);
  32.838 -void rewrite_headers(msg_out *msgout, connect_route *route);
  32.839 -void rcptlist_with_one_of_hostlist(GList *rcpt_list, GList *host_list,
  32.840 -				     GList **, GList **);
  32.841 -void rcptlist_with_addr_is_local(GList *rcpt_list,
  32.842 -				   GList **p_rcpt_list, GList **p_non_rcpt_list);
  32.843 -gboolean route_strip_msgout(connect_route *route, msg_out *msgout);
  32.844 -msg_out *route_prepare_msgout(connect_route *route, msg_out *msgout);
  32.845 -GList *route_msgout_list(connect_route *route, GList *msgout_list);
  32.846 -gboolean route_is_allowed_return_path(connect_route *route, address *ret_path);
  32.847 -gboolean route_is_allowed_mail_local(connect_route *route, address *ret_path);
  32.848 -void msg_rcptlist_route(connect_route *route, GList *rcpt_list,
  32.849 -			GList **p_rcpt_list, GList **p_non_rcpt_list);
  32.850 +msgout_perhost *create_msgout_perhost(gchar * host);
  32.851 +void destroy_msgout_perhost(msgout_perhost * mo_ph);
  32.852 +void rewrite_headers(msg_out * msgout, connect_route * route);
  32.853 +void rcptlist_with_one_of_hostlist(GList * rcpt_list, GList * host_list, GList **, GList **);
  32.854 +void rcptlist_with_addr_is_local(GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list);
  32.855 +gboolean route_strip_msgout(connect_route * route, msg_out * msgout);
  32.856 +msg_out *route_prepare_msgout(connect_route * route, msg_out * msgout);
  32.857 +GList *route_msgout_list(connect_route * route, GList * msgout_list);
  32.858 +gboolean route_is_allowed_return_path(connect_route * route, address * ret_path);
  32.859 +gboolean route_is_allowed_mail_local(connect_route * route, address * ret_path);
  32.860 +void msg_rcptlist_route(connect_route * route, GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list);
  32.861  
  32.862  /* tables.c */
  32.863 -table_pair *create_pair(gchar *key, gpointer value);
  32.864 -table_pair *create_pair_string(gchar *key, gpointer value);
  32.865 -table_pair *parse_table_pair(gchar *line, char delim);
  32.866 -gpointer *table_find_func(GList *table_list, gchar *key, int (*cmp_func)(const char *, const char *));
  32.867 -gpointer *table_find(GList *table_list, gchar *key);
  32.868 -gpointer *table_find_case(GList *table_list, gchar *key);
  32.869 -gpointer *table_find_fnmatch(GList *table_list, gchar *key);
  32.870 -GList *table_read(gchar *fname, gchar delim);
  32.871 -void destroy_table(GList *table);
  32.872 +table_pair *create_pair(gchar * key, gpointer value);
  32.873 +table_pair *create_pair_string(gchar * key, gpointer value);
  32.874 +table_pair *parse_table_pair(gchar * line, char delim);
  32.875 +gpointer *table_find_func(GList * table_list, gchar * key, int (*cmp_func) (const char *, const char *));
  32.876 +gpointer *table_find(GList * table_list, gchar * key);
  32.877 +gpointer *table_find_case(GList * table_list, gchar * key);
  32.878 +gpointer *table_find_fnmatch(GList * table_list, gchar * key);
  32.879 +GList *table_read(gchar * fname, gchar delim);
  32.880 +void destroy_table(GList * table);
  32.881  
  32.882  /* timeival.c */
  32.883 -gint time_interval(gchar *str, gint *pos);
  32.884 +gint time_interval(gchar * str, gint * pos);
  32.885  
  32.886  /* permissions.c */
  32.887  gboolean is_privileged_user(uid_t uid);
    33.1 --- a/src/md5/hmac_md5.c	Mon Oct 27 16:21:27 2008 +0100
    33.2 +++ b/src/md5/hmac_md5.c	Mon Oct 27 16:23:10 2008 +0100
    33.3 @@ -7,74 +7,66 @@
    33.4  #include "md5.h"
    33.5  #include "hmac_md5.h"
    33.6  
    33.7 -void hmac_md5(unsigned char *text, int text_len,
    33.8 -	      unsigned char* key, int key_len, unsigned char *digest)
    33.9 -     /* text;     pointer to data stream */
   33.10 -     /* text_len; length of data stream */
   33.11 -     /* key;      pointer to authentication key */
   33.12 -     /* key_len;  length of authentication key */
   33.13 -     /* digest;   caller digest to be filled in */
   33.14 +void
   33.15 +hmac_md5(unsigned char *text, int text_len, unsigned char *key, int key_len, unsigned char *digest)
   33.16 +	 /* text;     pointer to data stream */
   33.17 +	 /* text_len; length of data stream */
   33.18 +	 /* key;      pointer to authentication key */
   33.19 +	 /* key_len;  length of authentication key */
   33.20 +	 /* digest;   caller digest to be filled in */
   33.21 +{
   33.22 +	MD5_CTX context;
   33.23 +	unsigned char k_ipad[65];  /* inner padding - key XORd with ipad */
   33.24 +	unsigned char k_opad[65];  /* outer padding - key XORd with opad */
   33.25 +	unsigned char tk[16];
   33.26 +	int i;
   33.27 +	/* if key is longer than 64 bytes reset it to key=MD5(key) */
   33.28 +	if (key_len > 64) {
   33.29  
   33.30 -{
   33.31 -  MD5_CTX context;
   33.32 -  unsigned char k_ipad[65];    /* inner padding -
   33.33 -				* key XORd with ipad
   33.34 -				*/
   33.35 -  unsigned char k_opad[65];    /* outer padding -
   33.36 -				* key XORd with opad
   33.37 -				*/
   33.38 -  unsigned char tk[16];
   33.39 -  int i;
   33.40 -  /* if key is longer than 64 bytes reset it to key=MD5(key) */
   33.41 -  if (key_len > 64) {
   33.42 +		MD5_CTX tctx;
   33.43  
   33.44 -    MD5_CTX      tctx;
   33.45 +		MD5Init(&tctx);
   33.46 +		MD5Update(&tctx, key, key_len);
   33.47 +		MD5Final(tk, &tctx);
   33.48  
   33.49 -    MD5Init(&tctx);
   33.50 -    MD5Update(&tctx, key, key_len);
   33.51 -    MD5Final(tk, &tctx);
   33.52 +		key = tk;
   33.53 +		key_len = 16;
   33.54 +	}
   33.55  
   33.56 -    key = tk;
   33.57 -    key_len = 16;
   33.58 -  }
   33.59 +	/*
   33.60 +	 * the HMAC_MD5 transform looks like:
   33.61 +	 *
   33.62 +	 * MD5(K XOR opad, MD5(K XOR ipad, text))
   33.63 +	 *
   33.64 +	 * where K is an n byte key
   33.65 +	 * ipad is the byte 0x36 repeated 64 times
   33.66 +	 * opad is the byte 0x5c repeated 64 times
   33.67 +	 * and text is the data being protected
   33.68 +	 */
   33.69  
   33.70 -  /*
   33.71 -   * the HMAC_MD5 transform looks like:
   33.72 -   *
   33.73 -   * MD5(K XOR opad, MD5(K XOR ipad, text))
   33.74 -   *
   33.75 -   * where K is an n byte key
   33.76 -   * ipad is the byte 0x36 repeated 64 times
   33.77 -   * opad is the byte 0x5c repeated 64 times
   33.78 -   * and text is the data being protected
   33.79 -   */
   33.80 +	/* start out by storing key in pads */
   33.81 +	bzero(k_ipad, sizeof k_ipad);
   33.82 +	bzero(k_opad, sizeof k_opad);
   33.83 +	bcopy(key, k_ipad, key_len);
   33.84 +	bcopy(key, k_opad, key_len);
   33.85  
   33.86 -  /* start out by storing key in pads */
   33.87 -  bzero( k_ipad, sizeof k_ipad);
   33.88 -  bzero( k_opad, sizeof k_opad);
   33.89 -  bcopy( key, k_ipad, key_len);
   33.90 -  bcopy( key, k_opad, key_len);
   33.91 -
   33.92 -  /* XOR key with ipad and opad values */
   33.93 -  for (i=0; i<64; i++) {
   33.94 -    k_ipad[i] ^= 0x36;
   33.95 -    k_opad[i] ^= 0x5c;
   33.96 -  }
   33.97 -  /*
   33.98 -   * perform inner MD5
   33.99 -   */
  33.100 -  MD5Init(&context);                   /* init context for 1st
  33.101 -					* pass */
  33.102 -  MD5Update(&context, k_ipad, 64);      /* start with inner pad */
  33.103 -  MD5Update(&context, text, text_len); /* then text of datagram */
  33.104 -  MD5Final(digest, &context);          /* finish up 1st pass */
  33.105 -  /*
  33.106 -   * perform outer MD5
  33.107 -   */
  33.108 -  MD5Init(&context);                   /* init context for 2nd
  33.109 -					* pass */
  33.110 -  MD5Update(&context, k_opad, 64);     /* start with outer pad */
  33.111 -  MD5Update(&context, digest, 16);     /* then results of 1st
  33.112 -					* hash */
  33.113 -  MD5Final(digest, &context);          /* finish up 2nd pass */
  33.114 +	/* XOR key with ipad and opad values */
  33.115 +	for (i = 0; i < 64; i++) {
  33.116 +		k_ipad[i] ^= 0x36;
  33.117 +		k_opad[i] ^= 0x5c;
  33.118 +	}
  33.119 +	/*
  33.120 +	 * perform inner MD5
  33.121 +	 */
  33.122 +	MD5Init(&context);  /* init context for 1st pass */
  33.123 +	MD5Update(&context, k_ipad, 64);  /* start with inner pad */
  33.124 +	MD5Update(&context, text, text_len);  /* then text of datagram */
  33.125 +	MD5Final(digest, &context);  /* finish up 1st pass */
  33.126 +	/*
  33.127 +	 * perform outer MD5
  33.128 +	 */
  33.129 +	MD5Init(&context);  /* init context for 2nd pass */
  33.130 +	MD5Update(&context, k_opad, 64);  /* start with outer pad */
  33.131 +	MD5Update(&context, digest, 16);  /* then results of 1st hash */
  33.132 +	MD5Final(digest, &context); /* finish up 2nd pass */
  33.133  }
    34.1 --- a/src/md5/hmac_md5.h	Mon Oct 27 16:21:27 2008 +0100
    34.2 +++ b/src/md5/hmac_md5.h	Mon Oct 27 16:23:10 2008 +0100
    34.3 @@ -1,7 +1,7 @@
    34.4 -void hmac_md5(unsigned char *text, int text_len,
    34.5 -	      unsigned char* key, int key_len, unsigned char *digest);
    34.6 -     /* text;     pointer to data stream */
    34.7 -     /* text_len; length of data stream */
    34.8 -     /* key;      pointer to authentication key */
    34.9 -     /* key_len;  length of authentication key */
   34.10 -     /* digest;   caller digest to be filled in */
   34.11 +void
   34.12 +hmac_md5(unsigned char *text, int text_len, unsigned char *key, int key_len, unsigned char *digest);
   34.13 +	 /* text;     pointer to data stream */
   34.14 +	 /* text_len; length of data stream */
   34.15 +	 /* key;      pointer to authentication key */
   34.16 +	 /* key_len;  length of authentication key */
   34.17 +	 /* digest;   caller digest to be filled in */
    35.1 --- a/src/md5/hmactest.c	Mon Oct 27 16:21:27 2008 +0100
    35.2 +++ b/src/md5/hmactest.c	Mon Oct 27 16:23:10 2008 +0100
    35.3 @@ -6,41 +6,44 @@
    35.4  #include "md5.h"
    35.5  #include "hmac_md5.h"
    35.6  
    35.7 -static
    35.8 -void pad0_copy(char *d, char *s, int sz)
    35.9 +static void
   35.10 +pad0_copy(char *d, char *s, int sz)
   35.11  {
   35.12 -  int i = 0;
   35.13 -  while(*s && (i < sz)) { *(d++) = *(s++); i++; }
   35.14 -  while(i <= sz) { *(d++) = 0; i++; }
   35.15 +	int i = 0;
   35.16 +	while (*s && (i < sz)) {
   35.17 +		*(d++) = *(s++);
   35.18 +		i++;
   35.19 +	}
   35.20 +	while (i <= sz) {
   35.21 +		*(d++) = 0;
   35.22 +		i++;
   35.23 +	}
   35.24  }
   35.25  
   35.26 -int main()
   35.27 +int
   35.28 +main()
   35.29  {
   35.30 -  int i;
   35.31 -  //  unsigned char digest[16];
   35.32 -  char digest[16];
   35.33 -  char *msgid = "<1896.697170952@postoffice.reston.mci.net>";
   35.34 -  char secret[65];
   35.35 +	int i;
   35.36 +	//  unsigned char digest[16];
   35.37 +	char digest[16];
   35.38 +	char *msgid = "<1896.697170952@postoffice.reston.mci.net>";
   35.39 +	char secret[65];
   35.40  
   35.41 -  hmac_md5("<48157.953508124@mail.class-c.net>", 34,
   35.42 -	   "no!SpamAtAll", 12, digest);
   35.43 -  for(i = 0; i < 16; i++)
   35.44 -    printf("%x", (unsigned int)digest[i]);
   35.45 -  printf("\n");
   35.46 +	hmac_md5("<48157.953508124@mail.class-c.net>", 34, "no!SpamAtAll", 12, digest);
   35.47 +	for (i = 0; i < 16; i++)
   35.48 +		printf("%x", (unsigned int) digest[i]);
   35.49 +	printf("\n");
   35.50  
   35.51 -  hmac_md5(msgid, strlen(msgid),
   35.52 -	    "tanstaaftanstaaf", 16, digest);
   35.53 -  for(i = 0; i < 16; i++)
   35.54 -    printf("%x", (unsigned int)digest[i]);
   35.55 -  printf("\n");
   35.56 +	hmac_md5(msgid, strlen(msgid), "tanstaaftanstaaf", 16, digest);
   35.57 +	for (i = 0; i < 16; i++)
   35.58 +		printf("%x", (unsigned int) digest[i]);
   35.59 +	printf("\n");
   35.60  
   35.61 -  pad0_copy(secret, "tanstaaftanstaaf", 64);
   35.62 -  hmac_md5(msgid, strlen(msgid),
   35.63 -	    secret, 64, digest);
   35.64 -  for(i = 0; i < 16; i++)
   35.65 -    printf("%x", (unsigned int)digest[i]);
   35.66 -  printf("\n");
   35.67 +	pad0_copy(secret, "tanstaaftanstaaf", 64);
   35.68 +	hmac_md5(msgid, strlen(msgid), secret, 64, digest);
   35.69 +	for (i = 0; i < 16; i++)
   35.70 +		printf("%x", (unsigned int) digest[i]);
   35.71 +	printf("\n");
   35.72  
   35.73 -  exit(0);
   35.74 +	exit(0);
   35.75  }
   35.76 -
    36.1 --- a/src/md5/md5.h	Mon Oct 27 16:21:27 2008 +0100
    36.2 +++ b/src/md5/md5.h	Mon Oct 27 16:23:10 2008 +0100
    36.3 @@ -25,12 +25,11 @@
    36.4  
    36.5  /* MD5 context. */
    36.6  typedef struct {
    36.7 -  UINT4 state[4];                                   /* state (ABCD) */
    36.8 -  UINT4 count[2];        /* number of bits, modulo 2^64 (lsb first) */
    36.9 -  unsigned char buffer[64];                         /* input buffer */
   36.10 +	UINT4 state[4];  /* state (ABCD) */
   36.11 +	UINT4 count[2];  /* number of bits, modulo 2^64 (lsb first) */
   36.12 +	unsigned char buffer[64];  /* input buffer */
   36.13  } MD5_CTX;
   36.14  
   36.15 -void MD5Init PROTO_LIST ((MD5_CTX *));
   36.16 -void MD5Update PROTO_LIST
   36.17 -  ((MD5_CTX *, unsigned char *, unsigned int));
   36.18 -void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
   36.19 +void MD5Init PROTO_LIST((MD5_CTX *));
   36.20 +void MD5Update PROTO_LIST((MD5_CTX *, unsigned char *, unsigned int));
   36.21 +void MD5Final PROTO_LIST((unsigned char[16], MD5_CTX *));
    37.1 --- a/src/md5/md5c.c	Mon Oct 27 16:21:27 2008 +0100
    37.2 +++ b/src/md5/md5c.c	Mon Oct 27 16:23:10 2008 +0100
    37.3 @@ -45,18 +45,16 @@
    37.4  #define S43 15
    37.5  #define S44 21
    37.6  
    37.7 -static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
    37.8 -static void Encode PROTO_LIST
    37.9 -  ((unsigned char *, UINT4 *, unsigned int));
   37.10 -static void Decode PROTO_LIST
   37.11 -  ((UINT4 *, unsigned char *, unsigned int));
   37.12 -static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
   37.13 -static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
   37.14 +static void MD5Transform PROTO_LIST((UINT4[4], unsigned char[64]));
   37.15 +static void Encode PROTO_LIST((unsigned char *, UINT4 *, unsigned int));
   37.16 +static void Decode PROTO_LIST((UINT4 *, unsigned char *, unsigned int));
   37.17 +static void MD5_memcpy PROTO_LIST((POINTER, POINTER, unsigned int));
   37.18 +static void MD5_memset PROTO_LIST((POINTER, int, unsigned int));
   37.19  
   37.20  static unsigned char PADDING[64] = {
   37.21 -  0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   37.22 -  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   37.23 -  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   37.24 +	0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   37.25 +	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   37.26 +	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   37.27  };
   37.28  
   37.29  /* F, G, H and I are basic MD5 functions.
   37.30 @@ -96,239 +94,239 @@
   37.31  
   37.32  /* MD5 initialization. Begins an MD5 operation, writing a new context.
   37.33   */
   37.34 -void MD5Init (context)
   37.35 -MD5_CTX *context;                                        /* context */
   37.36 +void
   37.37 +MD5Init(context)
   37.38 +MD5_CTX *context;  /* context */
   37.39  {
   37.40 -  context->count[0] = context->count[1] = 0;
   37.41 -  /* Load magic initialization constants.
   37.42 -*/
   37.43 -  context->state[0] = 0x67452301;
   37.44 -  context->state[1] = 0xefcdab89;
   37.45 -  context->state[2] = 0x98badcfe;
   37.46 -  context->state[3] = 0x10325476;
   37.47 +	context->count[0] = context->count[1] = 0;
   37.48 +	/* Load magic initialization constants. */
   37.49 +	context->state[0] = 0x67452301;
   37.50 +	context->state[1] = 0xefcdab89;
   37.51 +	context->state[2] = 0x98badcfe;
   37.52 +	context->state[3] = 0x10325476;
   37.53  }
   37.54  
   37.55  /* MD5 block update operation. Continues an MD5 message-digest
   37.56    operation, processing another message block, and updating the
   37.57    context.
   37.58   */
   37.59 -void MD5Update (context, input, inputLen)
   37.60 -MD5_CTX *context;                                        /* context */
   37.61 -unsigned char *input;                                /* input block */
   37.62 -unsigned int inputLen;                     /* length of input block */
   37.63 +void
   37.64 +MD5Update(context, input, inputLen)
   37.65 +MD5_CTX *context;  /* context */
   37.66 +unsigned char *input;  /* input block */
   37.67 +unsigned int inputLen;  /* length of input block */
   37.68  {
   37.69 -  unsigned int i, index, partLen;
   37.70 +	unsigned int i, index, partLen;
   37.71  
   37.72 -  /* Compute number of bytes mod 64 */
   37.73 -  index = (unsigned int)((context->count[0] >> 3) & 0x3F);
   37.74 +	/* Compute number of bytes mod 64 */
   37.75 +	index = (unsigned int) ((context->count[0] >> 3) & 0x3F);
   37.76  
   37.77 -  /* Update number of bits */
   37.78 -  if ((context->count[0] += ((UINT4)inputLen << 3))
   37.79 -   < ((UINT4)inputLen << 3))
   37.80 - context->count[1]++;
   37.81 -  context->count[1] += ((UINT4)inputLen >> 29);
   37.82 +	/* Update number of bits */
   37.83 +	if ((context->count[0] += ((UINT4) inputLen << 3)) < ((UINT4) inputLen << 3))
   37.84 +		context->count[1]++;
   37.85 +	context->count[1] += ((UINT4) inputLen >> 29);
   37.86  
   37.87 -  partLen = 64 - index;
   37.88 +	partLen = 64 - index;
   37.89  
   37.90 -  /* Transform as many times as possible.
   37.91 -*/
   37.92 -  if (inputLen >= partLen) {
   37.93 - MD5_memcpy
   37.94 -   ((POINTER)&context->buffer[index], (POINTER)input, partLen);
   37.95 - MD5Transform (context->state, context->buffer);
   37.96 +	/* Transform as many times as possible.
   37.97 +	 */
   37.98 +	if (inputLen >= partLen) {
   37.99 +		MD5_memcpy((POINTER) & context->buffer[index], (POINTER) input, partLen);
  37.100 +		MD5Transform(context->state, context->buffer);
  37.101  
  37.102 - for (i = partLen; i + 63 < inputLen; i += 64)
  37.103 -   MD5Transform (context->state, &input[i]);
  37.104 +		for (i = partLen; i + 63 < inputLen; i += 64)
  37.105 +			MD5Transform(context->state, &input[i]);
  37.106  
  37.107 - index = 0;
  37.108 -  }
  37.109 -  else
  37.110 - i = 0;
  37.111 +		index = 0;
  37.112 +	} else
  37.113 +		i = 0;
  37.114  
  37.115 -  /* Buffer remaining input */
  37.116 -  MD5_memcpy
  37.117 - ((POINTER)&context->buffer[index], (POINTER)&input[i],
  37.118 -  inputLen-i);
  37.119 +	/* Buffer remaining input */
  37.120 +	MD5_memcpy((POINTER) & context->buffer[index], (POINTER) & input[i], inputLen - i);
  37.121  }
  37.122  
  37.123  /* MD5 finalization. Ends an MD5 message-digest operation, writing the
  37.124    the message digest and zeroizing the context.
  37.125   */
  37.126 -void MD5Final (digest, context)
  37.127 -unsigned char digest[16];                         /* message digest */
  37.128 -MD5_CTX *context;                                       /* context */
  37.129 +void
  37.130 +MD5Final(digest, context)
  37.131 +unsigned char digest[16];  /* message digest */
  37.132 +MD5_CTX *context;  /* context */
  37.133  {
  37.134 -  unsigned char bits[8];
  37.135 -  unsigned int index, padLen;
  37.136 +	unsigned char bits[8];
  37.137 +	unsigned int index, padLen;
  37.138  
  37.139 -  /* Save number of bits */
  37.140 -  Encode (bits, context->count, 8);
  37.141 +	/* Save number of bits */
  37.142 +	Encode(bits, context->count, 8);
  37.143  
  37.144 -  /* Pad out to 56 mod 64.
  37.145 -*/
  37.146 -  index = (unsigned int)((context->count[0] >> 3) & 0x3f);
  37.147 -  padLen = (index < 56) ? (56 - index) : (120 - index);
  37.148 -  MD5Update (context, PADDING, padLen);
  37.149 +	/* Pad out to 56 mod 64.
  37.150 +	 */
  37.151 +	index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
  37.152 +	padLen = (index < 56) ? (56 - index) : (120 - index);
  37.153 +	MD5Update(context, PADDING, padLen);
  37.154  
  37.155 -  /* Append length (before padding) */
  37.156 -  MD5Update (context, bits, 8);
  37.157 +	/* Append length (before padding) */
  37.158 +	MD5Update(context, bits, 8);
  37.159  
  37.160 -  /* Store state in digest */
  37.161 -  Encode (digest, context->state, 16);
  37.162 +	/* Store state in digest */
  37.163 +	Encode(digest, context->state, 16);
  37.164  
  37.165 -  /* Zeroize sensitive information.
  37.166 -*/
  37.167 -  MD5_memset ((POINTER)context, 0, sizeof (*context));
  37.168 +	/* Zeroize sensitive information.
  37.169 +	 */
  37.170 +	MD5_memset((POINTER) context, 0, sizeof(*context));
  37.171  }
  37.172  
  37.173  /* MD5 basic transformation. Transforms state based on block.
  37.174   */
  37.175 -static void MD5Transform (state, block)
  37.176 +static void
  37.177 +MD5Transform(state, block)
  37.178  UINT4 state[4];
  37.179  unsigned char block[64];
  37.180  {
  37.181 -  UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
  37.182 +	UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
  37.183  
  37.184 -  Decode (x, block, 64);
  37.185 +	Decode(x, block, 64);
  37.186  
  37.187 -  /* Round 1 */
  37.188 -  FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  37.189 -  FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  37.190 -  FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  37.191 -  FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  37.192 -  FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  37.193 -  FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  37.194 -  FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  37.195 -  FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  37.196 -  FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  37.197 -  FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  37.198 -  FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  37.199 -  FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  37.200 -  FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  37.201 -  FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  37.202 -  FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  37.203 -  FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  37.204 +	/* Round 1 */
  37.205 +	FF(a, b, c, d, x[0], S11, 0xd76aa478);  /* 1 */
  37.206 +	FF(d, a, b, c, x[1], S12, 0xe8c7b756);  /* 2 */
  37.207 +	FF(c, d, a, b, x[2], S13, 0x242070db);  /* 3 */
  37.208 +	FF(b, c, d, a, x[3], S14, 0xc1bdceee);  /* 4 */
  37.209 +	FF(a, b, c, d, x[4], S11, 0xf57c0faf);  /* 5 */
  37.210 +	FF(d, a, b, c, x[5], S12, 0x4787c62a);  /* 6 */
  37.211 +	FF(c, d, a, b, x[6], S13, 0xa8304613);  /* 7 */
  37.212 +	FF(b, c, d, a, x[7], S14, 0xfd469501);  /* 8 */
  37.213 +	FF(a, b, c, d, x[8], S11, 0x698098d8);  /* 9 */
  37.214 +	FF(d, a, b, c, x[9], S12, 0x8b44f7af);  /* 10 */
  37.215 +	FF(c, d, a, b, x[10], S13, 0xffff5bb1);  /* 11 */
  37.216 +	FF(b, c, d, a, x[11], S14, 0x895cd7be);  /* 12 */
  37.217 +	FF(a, b, c, d, x[12], S11, 0x6b901122);  /* 13 */
  37.218 +	FF(d, a, b, c, x[13], S12, 0xfd987193);  /* 14 */
  37.219 +	FF(c, d, a, b, x[14], S13, 0xa679438e);  /* 15 */
  37.220 +	FF(b, c, d, a, x[15], S14, 0x49b40821);  /* 16 */
  37.221  
  37.222 - /* Round 2 */
  37.223 -  GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  37.224 -  GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  37.225 -  GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  37.226 -  GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  37.227 -  GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  37.228 -  GG (d, a, b, c, x[10], S22,  0x2441453); /* 22 */
  37.229 -  GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  37.230 -  GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  37.231 -  GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  37.232 -  GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  37.233 -  GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  37.234 -  GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  37.235 -  GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  37.236 -  GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  37.237 -  GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  37.238 -  GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  37.239 +	/* Round 2 */
  37.240 +	GG(a, b, c, d, x[1], S21, 0xf61e2562);  /* 17 */
  37.241 +	GG(d, a, b, c, x[6], S22, 0xc040b340);  /* 18 */
  37.242 +	GG(c, d, a, b, x[11], S23, 0x265e5a51);  /* 19 */
  37.243 +	GG(b, c, d, a, x[0], S24, 0xe9b6c7aa);  /* 20 */
  37.244 +	GG(a, b, c, d, x[5], S21, 0xd62f105d);  /* 21 */
  37.245 +	GG(d, a, b, c, x[10], S22, 0x2441453);  /* 22 */
  37.246 +	GG(c, d, a, b, x[15], S23, 0xd8a1e681);  /* 23 */
  37.247 +	GG(b, c, d, a, x[4], S24, 0xe7d3fbc8);  /* 24 */
  37.248 +	GG(a, b, c, d, x[9], S21, 0x21e1cde6);  /* 25 */
  37.249 +	GG(d, a, b, c, x[14], S22, 0xc33707d6);  /* 26 */
  37.250 +	GG(c, d, a, b, x[3], S23, 0xf4d50d87);  /* 27 */
  37.251 +	GG(b, c, d, a, x[8], S24, 0x455a14ed);  /* 28 */
  37.252 +	GG(a, b, c, d, x[13], S21, 0xa9e3e905);  /* 29 */
  37.253 +	GG(d, a, b, c, x[2], S22, 0xfcefa3f8);  /* 30 */
  37.254 +	GG(c, d, a, b, x[7], S23, 0x676f02d9);  /* 31 */
  37.255 +	GG(b, c, d, a, x[12], S24, 0x8d2a4c8a);  /* 32 */
  37.256  
  37.257 -  /* Round 3 */
  37.258 -  HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  37.259 -  HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  37.260 -  HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  37.261 -  HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  37.262 -  HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  37.263 -  HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  37.264 -  HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  37.265 -  HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  37.266 -  HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  37.267 -  HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  37.268 -  HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  37.269 -  HH (b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */
  37.270 -  HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  37.271 -  HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  37.272 -  HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  37.273 -  HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  37.274 +	/* Round 3 */
  37.275 +	HH(a, b, c, d, x[5], S31, 0xfffa3942);  /* 33 */
  37.276 +	HH(d, a, b, c, x[8], S32, 0x8771f681);  /* 34 */
  37.277 +	HH(c, d, a, b, x[11], S33, 0x6d9d6122);  /* 35 */
  37.278 +	HH(b, c, d, a, x[14], S34, 0xfde5380c);  /* 36 */
  37.279 +	HH(a, b, c, d, x[1], S31, 0xa4beea44);  /* 37 */
  37.280 +	HH(d, a, b, c, x[4], S32, 0x4bdecfa9);  /* 38 */
  37.281 +	HH(c, d, a, b, x[7], S33, 0xf6bb4b60);  /* 39 */
  37.282 +	HH(b, c, d, a, x[10], S34, 0xbebfbc70);  /* 40 */
  37.283 +	HH(a, b, c, d, x[13], S31, 0x289b7ec6);  /* 41 */
  37.284 +	HH(d, a, b, c, x[0], S32, 0xeaa127fa);  /* 42 */
  37.285 +	HH(c, d, a, b, x[3], S33, 0xd4ef3085);  /* 43 */
  37.286 +	HH(b, c, d, a, x[6], S34, 0x4881d05);  /* 44 */
  37.287 +	HH(a, b, c, d, x[9], S31, 0xd9d4d039);  /* 45 */
  37.288 +	HH(d, a, b, c, x[12], S32, 0xe6db99e5);  /* 46 */
  37.289 +	HH(c, d, a, b, x[15], S33, 0x1fa27cf8);  /* 47 */
  37.290 +	HH(b, c, d, a, x[2], S34, 0xc4ac5665);  /* 48 */
  37.291  
  37.292 -  /* Round 4 */
  37.293 -  II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  37.294 -  II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  37.295 -  II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  37.296 -  II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  37.297 -  II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  37.298 -  II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  37.299 -  II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  37.300 -  II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  37.301 -  II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  37.302 -  II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  37.303 -  II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  37.304 -  II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  37.305 -  II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  37.306 -  II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  37.307 -  II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  37.308 -  II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  37.309 +	/* Round 4 */
  37.310 +	II(a, b, c, d, x[0], S41, 0xf4292244);  /* 49 */
  37.311 +	II(d, a, b, c, x[7], S42, 0x432aff97);  /* 50 */
  37.312 +	II(c, d, a, b, x[14], S43, 0xab9423a7);  /* 51 */
  37.313 +	II(b, c, d, a, x[5], S44, 0xfc93a039);  /* 52 */
  37.314 +	II(a, b, c, d, x[12], S41, 0x655b59c3);  /* 53 */
  37.315 +	II(d, a, b, c, x[3], S42, 0x8f0ccc92);  /* 54 */
  37.316 +	II(c, d, a, b, x[10], S43, 0xffeff47d);  /* 55 */
  37.317 +	II(b, c, d, a, x[1], S44, 0x85845dd1);  /* 56 */
  37.318 +	II(a, b, c, d, x[8], S41, 0x6fa87e4f);  /* 57 */
  37.319 +	II(d, a, b, c, x[15], S42, 0xfe2ce6e0);  /* 58 */
  37.320 +	II(c, d, a, b, x[6], S43, 0xa3014314);  /* 59 */
  37.321 +	II(b, c, d, a, x[13], S44, 0x4e0811a1);  /* 60 */
  37.322 +	II(a, b, c, d, x[4], S41, 0xf7537e82);  /* 61 */
  37.323 +	II(d, a, b, c, x[11], S42, 0xbd3af235);  /* 62 */
  37.324 +	II(c, d, a, b, x[2], S43, 0x2ad7d2bb);  /* 63 */
  37.325 +	II(b, c, d, a, x[9], S44, 0xeb86d391);  /* 64 */
  37.326  
  37.327 -  state[0] += a;
  37.328 -  state[1] += b;
  37.329 -  state[2] += c;
  37.330 -  state[3] += d;
  37.331 +	state[0] += a;
  37.332 +	state[1] += b;
  37.333 +	state[2] += c;
  37.334 +	state[3] += d;
  37.335  
  37.336 -  /* Zeroize sensitive information.
  37.337 -*/
  37.338 -  MD5_memset ((POINTER)x, 0, sizeof (x));
  37.339 +	/* Zeroize sensitive information. */
  37.340 +	MD5_memset((POINTER) x, 0, sizeof(x));
  37.341  }
  37.342  
  37.343  /* Encodes input (UINT4) into output (unsigned char). Assumes len is
  37.344    a multiple of 4.
  37.345   */
  37.346 -static void Encode (output, input, len)
  37.347 +static void
  37.348 +Encode(output, input, len)
  37.349  unsigned char *output;
  37.350  UINT4 *input;
  37.351  unsigned int len;
  37.352  {
  37.353 -  unsigned int i, j;
  37.354 +	unsigned int i, j;
  37.355  
  37.356 -  for (i = 0, j = 0; j < len; i++, j += 4) {
  37.357 - output[j] = (unsigned char)(input[i] & 0xff);
  37.358 - output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
  37.359 - output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
  37.360 - output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
  37.361 -  }
  37.362 +	for (i = 0, j = 0; j < len; i++, j += 4) {
  37.363 +		output[j] = (unsigned char) (input[i] & 0xff);
  37.364 +		output[j + 1] = (unsigned char) ((input[i] >> 8) & 0xff);
  37.365 +		output[j + 2] = (unsigned char) ((input[i] >> 16) & 0xff);
  37.366 +		output[j + 3] = (unsigned char) ((input[i] >> 24) & 0xff);
  37.367 +	}
  37.368  }
  37.369  
  37.370  /* Decodes input (unsigned char) into output (UINT4). Assumes len is
  37.371    a multiple of 4.
  37.372   */
  37.373 -static void Decode (output, input, len)
  37.374 +static void
  37.375 +Decode(output, input, len)
  37.376  UINT4 *output;
  37.377  unsigned char *input;
  37.378  unsigned int len;
  37.379  {
  37.380 -  unsigned int i, j;
  37.381 +	unsigned int i, j;
  37.382  
  37.383 -  for (i = 0, j = 0; j < len; i++, j += 4)
  37.384 - output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
  37.385 -   (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
  37.386 +	for (i = 0, j = 0; j < len; i++, j += 4)
  37.387 +		output[i] = ((UINT4) input[j]) | (((UINT4) input[j + 1]) << 8) | (((UINT4) input[j + 2]) << 16) | (((UINT4) input[j + 3]) << 24);
  37.388  }
  37.389  
  37.390  /* Note: Replace "for loop" with standard memcpy if possible.
  37.391   */
  37.392  
  37.393 -static void MD5_memcpy (output, input, len)
  37.394 +static void
  37.395 +MD5_memcpy(output, input, len)
  37.396  POINTER output;
  37.397  POINTER input;
  37.398  unsigned int len;
  37.399  {
  37.400 -  unsigned int i;
  37.401 +	unsigned int i;
  37.402  
  37.403 -  for (i = 0; i < len; i++)
  37.404 -    output[i] = input[i];
  37.405 +	for (i = 0; i < len; i++)
  37.406 +		output[i] = input[i];
  37.407  }
  37.408  
  37.409  /* Note: Replace "for loop" with standard memset if possible.
  37.410   */
  37.411 -static void MD5_memset (output, value, len)
  37.412 +static void
  37.413 +MD5_memset(output, value, len)
  37.414  POINTER output;
  37.415  int value;
  37.416  unsigned int len;
  37.417  {
  37.418 -  unsigned int i;
  37.419 +	unsigned int i;
  37.420  
  37.421 -  for (i = 0; i < len; i++)
  37.422 - ((char *)output)[i] = (char)value;
  37.423 +	for (i = 0; i < len; i++)
  37.424 +		((char *) output)[i] = (char) value;
  37.425  }
    38.1 --- a/src/message.c	Mon Oct 27 16:21:27 2008 +0100
    38.2 +++ b/src/message.c	Mon Oct 27 16:23:10 2008 +0100
    38.3 @@ -18,193 +18,208 @@
    38.4  
    38.5  #include "masqmail.h"
    38.6  
    38.7 -message *create_message()
    38.8 +message*
    38.9 +create_message()
   38.10  {
   38.11 -  message *msg = (message *)g_malloc(sizeof(message));
   38.12 -  if(msg){
   38.13 -    memset(msg, 0, sizeof(message));
   38.14 -    msg->data_size = -1;
   38.15 -  }
   38.16 -  return msg;
   38.17 +	message *msg = (message *) g_malloc(sizeof(message));
   38.18 +	if (msg) {
   38.19 +		memset(msg, 0, sizeof(message));
   38.20 +		msg->data_size = -1;
   38.21 +	}
   38.22 +	return msg;
   38.23  }
   38.24  
   38.25 -gint msg_calc_size(message *msg, gboolean is_smtp)
   38.26 +gint
   38.27 +msg_calc_size(message * msg, gboolean is_smtp)
   38.28  {
   38.29 -  GList *node;
   38.30 -  gint l_cnt = 0, c_cnt = 0;
   38.31 +	GList *node;
   38.32 +	gint l_cnt = 0, c_cnt = 0;
   38.33  
   38.34 -  /* header size */
   38.35 -  if(msg->hdr_list){
   38.36 -    for(node = g_list_first(msg->hdr_list); node; node = g_list_next(node)){
   38.37 -      if(node->data){
   38.38 -	header *hdr = (header *)(node->data);
   38.39 -	if(hdr->header){
   38.40 -	  char *p = hdr->header;
   38.41 -	  while(*p){
   38.42 -	    if(*p++ == '\n') l_cnt++;
   38.43 -	    c_cnt++;
   38.44 -	  }
   38.45 +	/* header size */
   38.46 +	if (msg->hdr_list) {
   38.47 +		for (node = g_list_first(msg->hdr_list); node; node = g_list_next(node)) {
   38.48 +			if (node->data) {
   38.49 +				header *hdr = (header *) (node->data);
   38.50 +				if (hdr->header) {
   38.51 +					char *p = hdr->header;
   38.52 +					while (*p) {
   38.53 +						if (*p++ == '\n')
   38.54 +							l_cnt++;
   38.55 +						c_cnt++;
   38.56 +					}
   38.57 +				}
   38.58 +			}
   38.59 +		}
   38.60  	}
   38.61 -      }
   38.62 -    }
   38.63 -  }
   38.64  
   38.65 -  /* empty line separating headers from data: */
   38.66 -  c_cnt++;
   38.67 -  l_cnt++;
   38.68 +	/* empty line separating headers from data: */
   38.69 +	c_cnt++;
   38.70 +	l_cnt++;
   38.71  
   38.72 -  /* data size */
   38.73 -  if(msg->data_list){
   38.74 -    for(node = g_list_first(msg->data_list); node; node = g_list_next(node)){
   38.75 -      if(node->data){
   38.76 -	char *p = node->data;
   38.77 -	while(*p){
   38.78 -	  if(*p++ == '\n') l_cnt++;
   38.79 -	  c_cnt++;
   38.80 +	/* data size */
   38.81 +	if (msg->data_list) {
   38.82 +		for (node = g_list_first(msg->data_list); node; node = g_list_next(node)) {
   38.83 +			if (node->data) {
   38.84 +				char *p = node->data;
   38.85 +				while (*p) {
   38.86 +					if (*p++ == '\n')
   38.87 +						l_cnt++;
   38.88 +					c_cnt++;
   38.89 +				}
   38.90 +			}
   38.91 +		}
   38.92  	}
   38.93 -      }
   38.94 -    }
   38.95 -  }
   38.96  
   38.97 -  return is_smtp ? c_cnt + l_cnt : c_cnt;
   38.98 +	return is_smtp ? c_cnt + l_cnt : c_cnt;
   38.99  }
  38.100  
  38.101 -void msg_free_data(message *msg)
  38.102 +void
  38.103 +msg_free_data(message * msg)
  38.104  {
  38.105 -  GList *node;
  38.106 +	GList *node;
  38.107  
  38.108 -  if(msg->data_list){
  38.109 -    for(node = g_list_first(msg->data_list); node; node = g_list_next(node)){
  38.110 -      if(node->data)
  38.111 -	g_free(node->data);
  38.112 -    }
  38.113 -    g_list_free(msg->data_list);
  38.114 -    msg->data_list = NULL;
  38.115 -  }
  38.116 +	if (msg->data_list) {
  38.117 +		for (node = g_list_first(msg->data_list); node; node = g_list_next(node)) {
  38.118 +			if (node->data)
  38.119 +				g_free(node->data);
  38.120 +		}
  38.121 +		g_list_free(msg->data_list);
  38.122 +		msg->data_list = NULL;
  38.123 +	}
  38.124  }
  38.125  
  38.126 -void destroy_message(message *msg)
  38.127 +void
  38.128 +destroy_message(message * msg)
  38.129  {
  38.130 -  GList *node;
  38.131 +	GList *node;
  38.132  
  38.133 -  if(msg->uid) g_free(msg->uid);
  38.134 -  if(msg->ident) g_free(msg->ident);
  38.135 -  if(msg->return_path) g_free(msg->return_path);
  38.136 +	if (msg->uid)
  38.137 +		g_free(msg->uid);
  38.138 +	if (msg->ident)
  38.139 +		g_free(msg->ident);
  38.140 +	if (msg->return_path)
  38.141 +		g_free(msg->return_path);
  38.142  
  38.143 -  if(msg->rcpt_list){
  38.144 -    for(node = g_list_first(msg->rcpt_list); node; node = g_list_next(node)){
  38.145 -      if(node->data)
  38.146 -	g_free(node->data);
  38.147 -    }
  38.148 -    g_list_free(msg->rcpt_list);
  38.149 -  }
  38.150 -  if(msg->hdr_list){
  38.151 -    for(node = g_list_first(msg->hdr_list); node; node = g_list_next(node)){
  38.152 -      if(node->data){
  38.153 -	header *hdr = (header *)(node->data);
  38.154 -	if(hdr->header)
  38.155 -	  g_free(hdr->header);
  38.156 -	g_free(node->data);
  38.157 -      }
  38.158 -    }
  38.159 -    g_list_free(msg->hdr_list);
  38.160 -  }
  38.161 +	if (msg->rcpt_list) {
  38.162 +		for (node = g_list_first(msg->rcpt_list); node; node = g_list_next(node)) {
  38.163 +			if (node->data)
  38.164 +				g_free(node->data);
  38.165 +		}
  38.166 +		g_list_free(msg->rcpt_list);
  38.167 +	}
  38.168 +	if (msg->hdr_list) {
  38.169 +		for (node = g_list_first(msg->hdr_list); node; node = g_list_next(node)) {
  38.170 +			if (node->data) {
  38.171 +				header *hdr = (header *) (node->data);
  38.172 +				if (hdr->header)
  38.173 +					g_free(hdr->header);
  38.174 +				g_free(node->data);
  38.175 +			}
  38.176 +		}
  38.177 +		g_list_free(msg->hdr_list);
  38.178 +	}
  38.179  
  38.180 -  if(msg->full_sender_name)
  38.181 -    g_free(msg->full_sender_name);
  38.182 +	if (msg->full_sender_name)
  38.183 +		g_free(msg->full_sender_name);
  38.184  
  38.185 -  msg_free_data(msg);
  38.186 +	msg_free_data(msg);
  38.187  
  38.188 -  g_free(msg);
  38.189 +	g_free(msg);
  38.190  }
  38.191  
  38.192 -void destroy_msg_list(GList *msg_list)
  38.193 +void
  38.194 +destroy_msg_list(GList * msg_list)
  38.195  {
  38.196 -  GList *msg_node;
  38.197 +	GList *msg_node;
  38.198  
  38.199 -  foreach(msg_list, msg_node){
  38.200 -    message *msg = (message *)(msg_node->data);
  38.201 -    destroy_message(msg);
  38.202 -  }
  38.203 -  g_list_free(msg_list);
  38.204 +	foreach(msg_list, msg_node) {
  38.205 +		message *msg = (message *) (msg_node->data);
  38.206 +		destroy_message(msg);
  38.207 +	}
  38.208 +	g_list_free(msg_list);
  38.209  }
  38.210  
  38.211 -msg_out *create_msg_out(message *msg)
  38.212 +msg_out*
  38.213 +create_msg_out(message * msg)
  38.214  {
  38.215 -  msg_out *msgout = NULL;
  38.216 +	msg_out *msgout = NULL;
  38.217  
  38.218 -  msgout = g_malloc(sizeof(msg_out));
  38.219 -  if(msgout){
  38.220 -    msgout->msg = msg;
  38.221 -    msgout->return_path = NULL;
  38.222 -    msgout->rcpt_list = NULL;
  38.223 -    
  38.224 -    msgout->hdr_list = NULL;
  38.225 -    msgout->xtra_hdr_list = NULL;
  38.226 -  }
  38.227 -  return msgout;
  38.228 +	msgout = g_malloc(sizeof(msg_out));
  38.229 +	if (msgout) {
  38.230 +		msgout->msg = msg;
  38.231 +		msgout->return_path = NULL;
  38.232 +		msgout->rcpt_list = NULL;
  38.233 +
  38.234 +		msgout->hdr_list = NULL;
  38.235 +		msgout->xtra_hdr_list = NULL;
  38.236 +	}
  38.237 +	return msgout;
  38.238  }
  38.239  
  38.240 -msg_out *clone_msg_out(msg_out *msgout_orig)
  38.241 +msg_out*
  38.242 +clone_msg_out(msg_out * msgout_orig)
  38.243  {
  38.244 -  if(msgout_orig){
  38.245 -    msg_out *msgout = create_msg_out(msgout_orig->msg);
  38.246 -    if(msgout){
  38.247 -      msgout->msg = msgout_orig->msg;
  38.248 -      if(msgout_orig->return_path)
  38.249 -	msgout->return_path = copy_address(msgout_orig->return_path);
  38.250 -      if(msgout_orig->hdr_list)
  38.251 -	msgout->hdr_list = g_list_copy(msgout_orig->hdr_list);
  38.252 -      /* FIXME: if this lives longer than the original
  38.253 -	 and we access one of the xtra hdrs, we will segfault
  38.254 -	 or cause some weird bugs: */
  38.255 -      msgout->xtra_hdr_list = NULL;
  38.256 -      if(msgout_orig->rcpt_list)
  38.257 -	msgout->rcpt_list = g_list_copy(msgout_orig->rcpt_list);
  38.258 -    }
  38.259 -    return msgout;
  38.260 -  }
  38.261 -  return NULL;
  38.262 +	if (msgout_orig) {
  38.263 +		msg_out *msgout = create_msg_out(msgout_orig->msg);
  38.264 +		if (msgout) {
  38.265 +			msgout->msg = msgout_orig->msg;
  38.266 +			if (msgout_orig->return_path)
  38.267 +				msgout->return_path = copy_address(msgout_orig->return_path);
  38.268 +			if (msgout_orig->hdr_list)
  38.269 +				msgout->hdr_list = g_list_copy(msgout_orig->hdr_list);
  38.270 +			/* FIXME: if this lives longer than the original
  38.271 +			   and we access one of the xtra hdrs, we will segfault
  38.272 +			   or cause some weird bugs: */
  38.273 +			msgout->xtra_hdr_list = NULL;
  38.274 +			if (msgout_orig->rcpt_list)
  38.275 +				msgout->rcpt_list = g_list_copy(msgout_orig->rcpt_list);
  38.276 +		}
  38.277 +		return msgout;
  38.278 +	}
  38.279 +	return NULL;
  38.280  }
  38.281  
  38.282 -GList *create_msg_out_list(GList *msg_list)
  38.283 +GList*
  38.284 +create_msg_out_list(GList * msg_list)
  38.285  {
  38.286 -  GList *msgout_list = NULL;
  38.287 -  GList *msg_node;
  38.288 +	GList *msgout_list = NULL;
  38.289 +	GList *msg_node;
  38.290  
  38.291 -  foreach(msg_list, msg_node){
  38.292 -    message *msg = (message *)(msg_node->data);
  38.293 -    msgout_list = g_list_append(msgout_list, create_msg_out(msg));
  38.294 -  }
  38.295 -  return msgout_list;
  38.296 +	foreach(msg_list, msg_node) {
  38.297 +		message *msg = (message *) (msg_node->data);
  38.298 +		msgout_list = g_list_append(msgout_list, create_msg_out(msg));
  38.299 +	}
  38.300 +	return msgout_list;
  38.301  }
  38.302  
  38.303 -void destroy_msg_out(msg_out *msgout)
  38.304 +void
  38.305 +destroy_msg_out(msg_out * msgout)
  38.306  {
  38.307 -  if(msgout){
  38.308 -    if(msgout->return_path)
  38.309 -      destroy_address(msgout->return_path);
  38.310 -    if(msgout->hdr_list)
  38.311 -      g_list_free(msgout->hdr_list);
  38.312 -    if(msgout->xtra_hdr_list){
  38.313 -      GList *hdr_node;
  38.314 -      foreach(msgout->xtra_hdr_list, hdr_node){
  38.315 -	header *hdr = (header *)(hdr_node->data);
  38.316 -	destroy_header(hdr);
  38.317 -      }
  38.318 -      g_list_free(msgout->xtra_hdr_list);
  38.319 -    }
  38.320 -    g_free(msgout);
  38.321 -  }
  38.322 +	if (msgout) {
  38.323 +		if (msgout->return_path)
  38.324 +			destroy_address(msgout->return_path);
  38.325 +		if (msgout->hdr_list)
  38.326 +			g_list_free(msgout->hdr_list);
  38.327 +		if (msgout->xtra_hdr_list) {
  38.328 +			GList *hdr_node;
  38.329 +			foreach(msgout->xtra_hdr_list, hdr_node) {
  38.330 +				header *hdr = (header *) (hdr_node->data);
  38.331 +				destroy_header(hdr);
  38.332 +			}
  38.333 +			g_list_free(msgout->xtra_hdr_list);
  38.334 +		}
  38.335 +		g_free(msgout);
  38.336 +	}
  38.337  }
  38.338  
  38.339 -void destroy_msg_out_list(GList *msgout_list)
  38.340 +void
  38.341 +destroy_msg_out_list(GList * msgout_list)
  38.342  {
  38.343 -  GList *msgout_node;
  38.344 +	GList *msgout_node;
  38.345  
  38.346 -  foreach(msgout_list, msgout_node){
  38.347 -    msg_out *msgout = (msg_out *)(msgout_node->data);
  38.348 -    destroy_msg_out(msgout);
  38.349 -  }
  38.350 -  g_list_free(msgout_list);
  38.351 +	foreach(msgout_list, msgout_node) {
  38.352 +		msg_out *msgout = (msg_out *) (msgout_node->data);
  38.353 +		destroy_msg_out(msgout);
  38.354 +	}
  38.355 +	g_list_free(msgout_list);
  38.356  }
    39.1 --- a/src/mservdetect.c	Mon Oct 27 16:21:27 2008 +0100
    39.2 +++ b/src/mservdetect.c	Mon Oct 27 16:23:10 2008 +0100
    39.3 @@ -32,45 +32,47 @@
    39.4  #include "masqmail.h"
    39.5  #include "readsock.h"
    39.6  #include "mserver.h"
    39.7 -#endif /* ENABLE_MSERVER */
    39.8 +#endif  /* ENABLE_MSERVER */
    39.9  
   39.10 -void logwrite(int pri, const char *fmt, ...)
   39.11 +void
   39.12 +logwrite(int pri, const char *fmt, ...)
   39.13  {
   39.14 -  va_list args;
   39.15 -  va_start(args, fmt);
   39.16 +	va_list args;
   39.17 +	va_start(args, fmt);
   39.18  
   39.19 -  vfprintf(stdout, fmt, args);
   39.20 +	vfprintf(stdout, fmt, args);
   39.21  
   39.22 -  va_end(args);
   39.23 +	va_end(args);
   39.24  }
   39.25  
   39.26 -void debugf(const char *fmt, ...)
   39.27 +void
   39.28 +debugf(const char *fmt, ...)
   39.29  {
   39.30 -  va_list args;
   39.31 -  va_start(args, fmt);
   39.32 +	va_list args;
   39.33 +	va_start(args, fmt);
   39.34  
   39.35 -  vfprintf(stdout, fmt, args);
   39.36 +	vfprintf(stdout, fmt, args);
   39.37  
   39.38 -  va_end(args);
   39.39 +	va_end(args);
   39.40  }
   39.41  
   39.42 -int main(int argc, char *argv[])
   39.43 +int
   39.44 +main(int argc, char *argv[])
   39.45  {
   39.46 -  if(argc == 3){
   39.47 -    interface iface;
   39.48 -    gchar *name;
   39.49 +	if (argc == 3) {
   39.50 +		interface iface;
   39.51 +		gchar *name;
   39.52  
   39.53 -    iface.address = g_strdup(argv[1]);
   39.54 -    iface.port = atoi(argv[2]);
   39.55 +		iface.address = g_strdup(argv[1]);
   39.56 +		iface.port = atoi(argv[2]);
   39.57  
   39.58 -    name = mserver_detect_online(&iface);
   39.59 +		name = mserver_detect_online(&iface);
   39.60  
   39.61 -    printf("%s\n", name);
   39.62 +		printf("%s\n", name);
   39.63  
   39.64 -    exit(EXIT_SUCCESS);
   39.65 -  }else{
   39.66 -    fprintf(stderr, "usage %s <host> <port>\n", argv[0]);
   39.67 -    exit(EXIT_FAILURE);
   39.68 -  }
   39.69 +		exit(EXIT_SUCCESS);
   39.70 +	} else {
   39.71 +		fprintf(stderr, "usage %s <host> <port>\n", argv[0]);
   39.72 +		exit(EXIT_FAILURE);
   39.73 +	}
   39.74  }
   39.75 -
    40.1 --- a/src/mserver.c	Mon Oct 27 16:21:27 2008 +0100
    40.2 +++ b/src/mserver.c	Mon Oct 27 16:23:10 2008 +0100
    40.3 @@ -22,57 +22,57 @@
    40.4  
    40.5  #ifdef ENABLE_MSERVER
    40.6  
    40.7 -gchar *mserver_detect_online(interface *iface)
    40.8 +gchar*
    40.9 +mserver_detect_online(interface * iface)
   40.10  {
   40.11 -  struct sockaddr_in saddr;
   40.12 -  gchar *ret = NULL;
   40.13 +	struct sockaddr_in saddr;
   40.14 +	gchar *ret = NULL;
   40.15  
   40.16 -  if(init_sockaddr(&saddr, iface)){
   40.17 -    int sock = socket(PF_INET, SOCK_STREAM, 0);
   40.18 -    int dup_sock;
   40.19 -    if(connect(sock, (struct sockaddr *)(&saddr), sizeof(saddr)) == 0){
   40.20 -      FILE *in, *out;
   40.21 -      char buf[256];
   40.22 +	if (init_sockaddr(&saddr, iface)) {
   40.23 +		int sock = socket(PF_INET, SOCK_STREAM, 0);
   40.24 +		int dup_sock;
   40.25 +		if (connect(sock, (struct sockaddr *) (&saddr), sizeof(saddr)) == 0) {
   40.26 +			FILE *in, *out;
   40.27 +			char buf[256];
   40.28  
   40.29 -      dup_sock = dup(sock);
   40.30 -      out = fdopen(sock, "w");
   40.31 -      in = fdopen(dup_sock, "r");
   40.32 +			dup_sock = dup(sock);
   40.33 +			out = fdopen(sock, "w");
   40.34 +			in = fdopen(dup_sock, "r");
   40.35  
   40.36 -      if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){
   40.37 -	if(strncmp(buf, "READY", 5) == 0){
   40.38 -	  fprintf(out, "STAT\n"); fflush(out);
   40.39 -	  if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){
   40.40 -	    if(strncmp(buf, "DOWN", 4) == 0){
   40.41 -	      ret = NULL;
   40.42 -	    }else if(strncmp(buf, "UP", 2) == 0){
   40.43 -	      gchar *p = buf+3;
   40.44 -	      while((*p != ':') && *p) p++;
   40.45 -	      if(*p){
   40.46 -		*p = 0;
   40.47 -		p++;
   40.48 -		if((atoi(p) >= 0) && *p)
   40.49 -		  ret = g_strdup(buf+3);
   40.50 -	      }else
   40.51 -		logwrite(LOG_ALERT,
   40.52 -			 "unexpected response from mserver after STAT cmd: %s",
   40.53 -			 buf);
   40.54 -	    }else{
   40.55 -	      logwrite(LOG_ALERT,
   40.56 -		       "unexpected response from mserver after STAT cmd: %s",
   40.57 -		       buf);
   40.58 -	    }
   40.59 -	  }
   40.60 +			if (read_sockline(in, buf, 256, 15, READSOCKL_CHUG)) {
   40.61 +				if (strncmp(buf, "READY", 5) == 0) {
   40.62 +					fprintf(out, "STAT\n");
   40.63 +					fflush(out);
   40.64 +					if (read_sockline(in, buf, 256, 15, READSOCKL_CHUG)) {
   40.65 +						if (strncmp(buf, "DOWN", 4) == 0) {
   40.66 +							ret = NULL;
   40.67 +						} else if (strncmp(buf, "UP", 2) == 0) {
   40.68 +							gchar *p = buf + 3;
   40.69 +							while ((*p != ':') && *p)
   40.70 +								p++;
   40.71 +							if (*p) {
   40.72 +								*p = 0;
   40.73 +								p++;
   40.74 +								if ((atoi(p) >= 0) && *p)
   40.75 +									ret = g_strdup(buf + 3);
   40.76 +							} else
   40.77 +								logwrite(LOG_ALERT, "unexpected response from mserver after STAT cmd: %s", buf);
   40.78 +						} else {
   40.79 +							logwrite(LOG_ALERT, "unexpected response from mserver after STAT cmd: %s", buf);
   40.80 +						}
   40.81 +					}
   40.82 +				}
   40.83 +				fprintf(out, "QUIT");
   40.84 +				fflush(out);
   40.85 +
   40.86 +				close(sock);
   40.87 +				close(dup_sock);
   40.88 +				fclose(in);
   40.89 +				fclose(out);
   40.90 +			}
   40.91 +		}
   40.92  	}
   40.93 -	fprintf(out, "QUIT"); fflush(out);
   40.94 -
   40.95 -	close(sock);
   40.96 -	close(dup_sock);
   40.97 -	fclose(in);
   40.98 -	fclose(out);
   40.99 -      }
  40.100 -    }
  40.101 -  }
  40.102 -  return ret;
  40.103 +	return ret;
  40.104  }
  40.105  
  40.106  #endif
    41.1 --- a/src/mserver.h	Mon Oct 27 16:21:27 2008 +0100
    41.2 +++ b/src/mserver.h	Mon Oct 27 16:23:10 2008 +0100
    41.3 @@ -16,4 +16,4 @@
    41.4      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    41.5  */
    41.6  
    41.7 -gchar *mserver_detect_online(interface *iface);
    41.8 +gchar *mserver_detect_online(interface * iface);
    42.1 --- a/src/online.c	Mon Oct 27 16:21:27 2008 +0100
    42.2 +++ b/src/online.c	Mon Oct 27 16:23:10 2008 +0100
    42.3 @@ -24,96 +24,91 @@
    42.4  
    42.5  gchar *connection_name;
    42.6  
    42.7 -void set_online_name(gchar *name)
    42.8 +void
    42.9 +set_online_name(gchar * name)
   42.10  {
   42.11 -  connection_name = g_strdup(name);
   42.12 +	connection_name = g_strdup(name);
   42.13  }
   42.14  
   42.15 -static
   42.16 -gchar *detect_online_pipe(const gchar *pipe)
   42.17 +static gchar*
   42.18 +detect_online_pipe(const gchar * pipe)
   42.19  {
   42.20 -  pid_t pid;
   42.21 -  void (*old_signal)(int);
   42.22 -  int status;
   42.23 -  FILE *in;
   42.24 -  gchar *name = NULL;
   42.25 +	pid_t pid;
   42.26 +	void (*old_signal) (int);
   42.27 +	int status;
   42.28 +	FILE *in;
   42.29 +	gchar *name = NULL;
   42.30  
   42.31 -  old_signal = signal(SIGCHLD, SIG_DFL);
   42.32 +	old_signal = signal(SIGCHLD, SIG_DFL);
   42.33  
   42.34 -  in = peopen(pipe, "r", environ, &pid);
   42.35 -  if(in != NULL){
   42.36 -    gchar output[256];
   42.37 -    if(fgets(output, 255, in)){
   42.38 -      g_strchomp(output);
   42.39 -      name = g_strdup(output);
   42.40 -    }
   42.41 -    fclose(in);
   42.42 -    waitpid(pid, &status, 0);
   42.43 -    if(WEXITSTATUS(status) != EXIT_SUCCESS){
   42.44 -      g_free(name);
   42.45 -      name = NULL;
   42.46 -    }
   42.47 -  }else
   42.48 -    logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", pipe, strerror(errno));
   42.49 +	in = peopen(pipe, "r", environ, &pid);
   42.50 +	if (in != NULL) {
   42.51 +		gchar output[256];
   42.52 +		if (fgets(output, 255, in)) {
   42.53 +			g_strchomp(output);
   42.54 +			name = g_strdup(output);
   42.55 +		}
   42.56 +		fclose(in);
   42.57 +		waitpid(pid, &status, 0);
   42.58 +		if (WEXITSTATUS(status) != EXIT_SUCCESS) {
   42.59 +			g_free(name);
   42.60 +			name = NULL;
   42.61 +		}
   42.62 +	} else
   42.63 +		logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", pipe, strerror(errno));
   42.64  
   42.65 -  signal(SIGCHLD, old_signal);
   42.66 +	signal(SIGCHLD, old_signal);
   42.67  
   42.68 -  return name;
   42.69 +	return name;
   42.70  }
   42.71  
   42.72 -gchar *detect_online()
   42.73 +gchar*
   42.74 +detect_online()
   42.75  {
   42.76 -  if(conf.online_detect != NULL){
   42.77 -    if(strcmp(conf.online_detect, "file") == 0){
   42.78 -      DEBUG(3) debugf("online detection method 'file'\n");
   42.79 -      if(conf.online_file != NULL){
   42.80 -	struct stat st;
   42.81 -	if(stat(conf.online_file, &st) == 0){
   42.82 -	  FILE *fptr = fopen(conf.online_file, "r");
   42.83 -	  if(fptr){
   42.84 -	    char buf[256];
   42.85 -	    fgets(buf, 256, fptr);
   42.86 -	    g_strchomp(buf);
   42.87 -	    fclose(fptr);
   42.88 -	    return g_strdup(buf);
   42.89 -	  }else{
   42.90 -	    logwrite(LOG_ALERT, "opening of %s failed: %s\n",
   42.91 -		     conf.online_file, strerror(errno));
   42.92 -	    return NULL;
   42.93 -	  }
   42.94 +	if (conf.online_detect != NULL) {
   42.95 +		if (strcmp(conf.online_detect, "file") == 0) {
   42.96 +			DEBUG(3) debugf("online detection method 'file'\n");
   42.97 +			if (conf.online_file != NULL) {
   42.98 +				struct stat st;
   42.99 +				if (stat(conf.online_file, &st) == 0) {
  42.100 +					FILE *fptr = fopen(conf.online_file, "r");
  42.101 +					if (fptr) {
  42.102 +						char buf[256];
  42.103 +						fgets(buf, 256, fptr);
  42.104 +						g_strchomp(buf);
  42.105 +						fclose(fptr);
  42.106 +						return g_strdup(buf);
  42.107 +					} else {
  42.108 +						logwrite(LOG_ALERT, "opening of %s failed: %s\n", conf.online_file, strerror(errno));
  42.109 +						return NULL;
  42.110 +					}
  42.111 +				} else if (errno == ENOENT) {
  42.112 +					logwrite(LOG_NOTICE, "not online.\n");
  42.113 +					return NULL;
  42.114 +				} else {
  42.115 +					logwrite(LOG_ALERT, "stat of %s failed: %s", conf.online_file, strerror(errno));
  42.116 +					return NULL;
  42.117 +				}
  42.118 +			} else
  42.119 +				logwrite(LOG_ALERT, "online detection mode is 'file', but online_file is undefined\n");
  42.120 +#ifdef ENABLE_MSERVER
  42.121 +		} else if (strcmp(conf.online_detect, "mserver") == 0) {
  42.122 +			DEBUG(3) debugf("connection method 'mserver'\n");
  42.123 +			return mserver_detect_online(conf.mserver_iface);
  42.124 +#endif
  42.125 +		} else if (strcmp(conf.online_detect, "pipe") == 0) {
  42.126 +			DEBUG(3) debugf("connection method 'pipe'\n");
  42.127 +			if (conf.online_pipe)
  42.128 +				return detect_online_pipe(conf.online_pipe);
  42.129 +			else {
  42.130 +				logwrite(LOG_ALERT, "online detection mode is 'pipe', but online_pipe is undefined\n");
  42.131 +				return NULL;
  42.132 +			}
  42.133 +		} else if (strcmp(conf.online_detect, "argument") == 0) {
  42.134 +			return connection_name;
  42.135 +		} else {
  42.136 +			DEBUG(3) debugf("no connection method selected\n");
  42.137 +		}
  42.138  	}
  42.139 -	else if(errno == ENOENT){
  42.140 -	  logwrite(LOG_NOTICE, "not online.\n");
  42.141 -	  return NULL;
  42.142 -	}else{
  42.143 -	  logwrite(LOG_ALERT, "stat of %s failed: %s",
  42.144 -		   conf.online_file, strerror(errno));
  42.145 -	  return NULL;
  42.146 -	}
  42.147 -      }else
  42.148 -	logwrite(LOG_ALERT,
  42.149 -		 "online detection mode is 'file', "
  42.150 -		 "but online_file is undefined\n");
  42.151 -#ifdef ENABLE_MSERVER
  42.152 -    }else if(strcmp(conf.online_detect, "mserver") == 0){
  42.153 -      DEBUG(3) debugf("connection method 'mserver'\n");
  42.154 -      return mserver_detect_online(conf.mserver_iface);
  42.155 -#endif
  42.156 -    }else if(strcmp(conf.online_detect, "pipe") == 0){
  42.157 -      DEBUG(3) debugf("connection method 'pipe'\n");
  42.158 -      if(conf.online_pipe)
  42.159 -	return detect_online_pipe(conf.online_pipe);
  42.160 -      else{
  42.161 -	logwrite(LOG_ALERT,
  42.162 -		 "online detection mode is 'pipe', "
  42.163 -		 "but online_pipe is undefined\n");
  42.164  	return NULL;
  42.165 -      }
  42.166 -    }else if(strcmp(conf.online_detect, "argument") == 0){
  42.167 -      return connection_name;
  42.168 -    }else{
  42.169 -      DEBUG(3) debugf("no connection method selected\n");
  42.170 -    }
  42.171 -  }
  42.172 -  return NULL;
  42.173  }
    43.1 --- a/src/parse.c	Mon Oct 27 16:21:27 2008 +0100
    43.2 +++ b/src/parse.c	Mon Oct 27 16:23:10 2008 +0100
    43.3 @@ -33,320 +33,315 @@
    43.4  
    43.5  char *parse_error = NULL;
    43.6  
    43.7 -static
    43.8 -gchar *skip_comment(gchar *p)
    43.9 +static gchar*
   43.10 +skip_comment(gchar * p)
   43.11  {
   43.12  
   43.13  #ifdef PARSE_TEST
   43.14 -  g_print("skip_comment: %s\n", p);
   43.15 +	g_print("skip_comment: %s\n", p);
   43.16  #endif
   43.17  
   43.18 -  p++;
   43.19 -  while(*p && *p != ')'){
   43.20 -    p++;
   43.21 -    if(*p == '(')
   43.22 -      p = skip_comment(p);
   43.23 -  }
   43.24 -  p++;
   43.25 +	p++;
   43.26 +	while (*p && *p != ')') {
   43.27 +		p++;
   43.28 +		if (*p == '(')
   43.29 +			p = skip_comment(p);
   43.30 +	}
   43.31 +	p++;
   43.32  
   43.33 -  return p;
   43.34 +	return p;
   43.35  }
   43.36  
   43.37 -static
   43.38 -gboolean read_word(gchar *p, gchar **b, gchar **e)
   43.39 +static gboolean
   43.40 +read_word(gchar * p, gchar ** b, gchar ** e)
   43.41  {
   43.42  #ifdef PARSE_TEST
   43.43 -  g_print("read_word: %s\n", p);
   43.44 +	g_print("read_word: %s\n", p);
   43.45  #endif
   43.46 -  /* eat leading spaces */
   43.47 -  while(*p && isspace(*p)) p++;
   43.48 -  
   43.49 -  *b = p;
   43.50 -  /*  b = &p;*/
   43.51 -  if(*p == '\"'){
   43.52 -    /* quoted-string */
   43.53 -    p++;
   43.54 -    while(*p && (*p != '\"')) p++;
   43.55 -    p++;
   43.56 -  }else{
   43.57 -    /* atom */
   43.58 -    while(*p && !strchr(specials, *p) && !iscntrl(*p) && !isspace(*p))
   43.59 -      p++;
   43.60 -  }
   43.61 -  *e = p;
   43.62 -  return TRUE;
   43.63 +	/* eat leading spaces */
   43.64 +	while (*p && isspace(*p))
   43.65 +		p++;
   43.66 +
   43.67 +	*b = p;
   43.68 +	/*  b = &p; */
   43.69 +	if (*p == '\"') {
   43.70 +		/* quoted-string */
   43.71 +		p++;
   43.72 +		while (*p && (*p != '\"'))
   43.73 +			p++;
   43.74 +		p++;
   43.75 +	} else {
   43.76 +		/* atom */
   43.77 +		while (*p && !strchr(specials, *p) && !iscntrl(*p) && !isspace(*p))
   43.78 +			p++;
   43.79 +	}
   43.80 +	*e = p;
   43.81 +	return TRUE;
   43.82  }
   43.83  
   43.84 -static
   43.85 -gboolean read_word_with_dots(gchar *p, gchar **b, gchar **e)
   43.86 +static gboolean
   43.87 +read_word_with_dots(gchar * p, gchar ** b, gchar ** e)
   43.88  {
   43.89 -  gchar *b0 = p;
   43.90 +	gchar *b0 = p;
   43.91  
   43.92  #ifdef PARSE_TEST
   43.93 -  g_print("read_word_with_dots: %s\n", p);
   43.94 +	g_print("read_word_with_dots: %s\n", p);
   43.95  #endif
   43.96 -  while(TRUE){
   43.97 -    if(!read_word(p, b, e))
   43.98 -      return FALSE;
   43.99 -    p = *e;
  43.100 -    if(*p != '.') break;
  43.101 -    p++;
  43.102 -  }
  43.103 -  *b = b0;
  43.104 -  *e = p;
  43.105 -  return TRUE;
  43.106 +	while (TRUE) {
  43.107 +		if (!read_word(p, b, e))
  43.108 +			return FALSE;
  43.109 +		p = *e;
  43.110 +		if (*p != '.')
  43.111 +			break;
  43.112 +		p++;
  43.113 +	}
  43.114 +	*b = b0;
  43.115 +	*e = p;
  43.116 +	return TRUE;
  43.117  }
  43.118  
  43.119 -static
  43.120 -gboolean read_domain(gchar *p, gchar **b, gchar **e)
  43.121 +static gboolean
  43.122 +read_domain(gchar * p, gchar ** b, gchar ** e)
  43.123  {
  43.124  #ifdef PARSE_TEST
  43.125 -  g_print("read_domain: %s\n", p);
  43.126 +	g_print("read_domain: %s\n", p);
  43.127  #endif
  43.128 -  *b = p;
  43.129 -  if(*p != '['){
  43.130 -    while(isalnum(*p) || (*p == '-') || (*p == '.'))
  43.131 -      p++;
  43.132 -  }else{
  43.133 -    p++;
  43.134 -    while(isalpha(*p) || (*p == '.'))
  43.135 -      p++;
  43.136 -    if(*p != ']'){
  43.137 -      parse_error =
  43.138 -	g_strdup_printf("']' expected at end of literal address %s", *b);
  43.139 -      return FALSE;
  43.140 -    }
  43.141 -    p++;
  43.142 -  }
  43.143 -  *e = p;
  43.144 -  return TRUE;
  43.145 +	*b = p;
  43.146 +	if (*p != '[') {
  43.147 +		while (isalnum(*p) || (*p == '-') || (*p == '.'))
  43.148 +			p++;
  43.149 +	} else {
  43.150 +		p++;
  43.151 +		while (isalpha(*p) || (*p == '.'))
  43.152 +			p++;
  43.153 +		if (*p != ']') {
  43.154 +			parse_error = g_strdup_printf("']' expected at end of literal address %s", *b);
  43.155 +			return FALSE;
  43.156 +		}
  43.157 +		p++;
  43.158 +	}
  43.159 +	*e = p;
  43.160 +	return TRUE;
  43.161  }
  43.162  
  43.163 -gboolean parse_address_rfc822(gchar *string,
  43.164 -		       gchar **local_begin, gchar **local_end,
  43.165 -		       gchar **domain_begin, gchar **domain_end,
  43.166 -		       gchar **address_end)
  43.167 +gboolean
  43.168 +parse_address_rfc822(gchar* string, gchar** local_begin, gchar** local_end, gchar** domain_begin, gchar** domain_end, gchar** address_end)
  43.169  {
  43.170 -  gint angle_brackets = 0;
  43.171 +	gint angle_brackets = 0;
  43.172  
  43.173 -  gchar *p = string;
  43.174 -  gchar *b, *e;
  43.175 +	gchar *p = string;
  43.176 +	gchar *b, *e;
  43.177  
  43.178 -  *local_begin = *local_end = NULL;
  43.179 -  *domain_begin = *domain_end = NULL;
  43.180 +	*local_begin = *local_end = NULL;
  43.181 +	*domain_begin = *domain_end = NULL;
  43.182  
  43.183 -  /* might be some memory left from previous call: */
  43.184 -  if(parse_error != NULL){
  43.185 -    g_free(parse_error);
  43.186 -    parse_error = NULL;
  43.187 -  }
  43.188 +	/* might be some memory left from previous call: */
  43.189 +	if (parse_error != NULL) {
  43.190 +		g_free(parse_error);
  43.191 +		parse_error = NULL;
  43.192 +	}
  43.193  
  43.194 -  /* leading spaces and angle brackets */
  43.195 -  while(*p && (isspace(*p) || (*p == '<'))){
  43.196 -    if(*p == '<')
  43.197 -      angle_brackets++;
  43.198 -    p++;
  43.199 -  }
  43.200 - 
  43.201 -  if(*p){
  43.202 -    while(TRUE){
  43.203 -      if(read_word_with_dots(p, &b, &e)){
  43.204 -	p = e;
  43.205 +	/* leading spaces and angle brackets */
  43.206 +	while (*p && (isspace(*p) || (*p == '<'))) {
  43.207 +		if (*p == '<')
  43.208 +			angle_brackets++;
  43.209 +		p++;
  43.210 +	}
  43.211 +
  43.212 +	if (*p) {
  43.213 +		while (TRUE) {
  43.214 +			if (read_word_with_dots(p, &b, &e)) {
  43.215 +				p = e;
  43.216  #ifdef PARSE_TEST
  43.217 -	g_print("after read_word_with_dots: %s\n", p);
  43.218 +				g_print("after read_word_with_dots: %s\n", p);
  43.219  #endif
  43.220 -	/* eat white spaces and comments */
  43.221 -	while((*p && (isspace(*p))) || (*p == '(')){
  43.222 -	  if(*p == '('){
  43.223 -	    if(!(p = skip_comment(p))){
  43.224 -	      parse_error =
  43.225 -		g_strdup("missing right bracket ')'");
  43.226 -	      return FALSE;
  43.227 -	    }
  43.228 -	  }else
  43.229 -	    p++;
  43.230 +				/* eat white spaces and comments */
  43.231 +				while ((*p && (isspace(*p))) || (*p == '(')) {
  43.232 +					if (*p == '(') {
  43.233 +						if (!(p = skip_comment(p))) {
  43.234 +							parse_error = g_strdup("missing right bracket ')'");
  43.235 +							return FALSE;
  43.236 +						}
  43.237 +					} else
  43.238 +						p++;
  43.239 +				}
  43.240 +				/* we now have a non-space char that is not
  43.241 +				   the beginning of a comment */
  43.242 +
  43.243 +				if (*p == '@') {
  43.244 +					/* the last word was the local_part
  43.245 +					   of an addr-spec */
  43.246 +					*local_begin = b;
  43.247 +					*local_end = e;
  43.248 +#ifdef PARSE_TEST
  43.249 +					g_print("found local part: %s\n", *local_begin);
  43.250 +#endif
  43.251 +					if (*p == '@') {
  43.252 +						p++;	/* skip @ */
  43.253 +						/* now the domain */
  43.254 +						if (read_domain(p, &b, &e)) {
  43.255 +							p = e;
  43.256 +							*domain_begin = b;
  43.257 +							*domain_end = e;
  43.258 +						} else
  43.259 +							return FALSE;
  43.260 +					} else {
  43.261 +						/* unqualified? */
  43.262 +						*domain_begin = *domain_end = NULL;
  43.263 +					}
  43.264 +					break;
  43.265 +				} else if (*p == '<') {
  43.266 +					/* addr-spec follows */
  43.267 +					while (isspace(*p) || (*p == '<')) {
  43.268 +						if (*p == '<')
  43.269 +							angle_brackets++;
  43.270 +						p++;
  43.271 +					}
  43.272 +					if (read_word_with_dots(p, &b, &e)) {
  43.273 +						p = e;
  43.274 +						*local_begin = b;
  43.275 +						*local_end = e;
  43.276 +#ifdef PARSE_TEST
  43.277 +						g_print("found local part: %s\n", *local_begin);
  43.278 +#endif
  43.279 +					} else
  43.280 +						return FALSE;
  43.281 +					if (*p == '@') {
  43.282 +						p++;
  43.283 +						if (read_domain(p, &b, &e)) {
  43.284 +							p = e;
  43.285 +							*domain_begin = b;
  43.286 +							*domain_end = e;
  43.287 +						} else
  43.288 +							return FALSE;
  43.289 +					} else {
  43.290 +						/* may be unqualified address */
  43.291 +						*domain_begin = *domain_end = NULL;
  43.292 +					}
  43.293 +					break;
  43.294 +				} else if (!*p || *p == '>') {
  43.295 +					*local_begin = b;
  43.296 +					*local_end = e;
  43.297 +#ifdef PARSE_TEST
  43.298 +					g_print("found local part: %s\n", *local_begin);
  43.299 +#endif
  43.300 +					*domain_begin = *domain_end = NULL;
  43.301 +					break;
  43.302 +				} else if (strchr(specials, *p) || iscntrl(*p) || isspace(*p)) {
  43.303 +					parse_error = g_strdup_printf("unexpected character: %c", *p);
  43.304 +					return FALSE;
  43.305 +				}
  43.306 +			} else
  43.307 +				return FALSE;
  43.308 +		}
  43.309 +		/* trailing spaces and angle brackets */
  43.310 +#ifdef PARSE_TEST
  43.311 +		g_print("down counting trailing '>'\n");
  43.312 +#endif
  43.313 +		while (*p && (isspace(*p) || (*p == '>'))) {
  43.314 +			if (*p == '>')
  43.315 +				angle_brackets--;
  43.316 +			p++;
  43.317 +		}
  43.318 +
  43.319 +		*address_end = p;
  43.320 +
  43.321 +		if (angle_brackets != 0) {
  43.322 +			if (angle_brackets > 0)
  43.323 +				parse_error = g_strdup("missing '>' at end of string");
  43.324 +			else
  43.325 +				parse_error = g_strdup("superfluous '>' at end of string");
  43.326 +			return FALSE;
  43.327 +		} else {
  43.328 +			/* we successfully parsed the address */
  43.329 +			return TRUE;
  43.330 +		}
  43.331 +		/* we never get here */
  43.332  	}
  43.333 -	/* we now have a non-space char that is not
  43.334 -	   the beginning of a comment */
  43.335 -
  43.336 -	if(*p == '@'){
  43.337 -	  /* the last word was the local_part
  43.338 -	     of an addr-spec */
  43.339 -	  *local_begin = b;
  43.340 -	  *local_end = e;
  43.341 -#ifdef PARSE_TEST
  43.342 -	  g_print("found local part: %s\n", *local_begin);
  43.343 -#endif
  43.344 -	  if(*p == '@'){
  43.345 -	    p++; /* skip @ */
  43.346 -	    /* now the domain */
  43.347 -	    if(read_domain(p, &b, &e)){
  43.348 -	      p = e;
  43.349 -	      *domain_begin = b;
  43.350 -	      *domain_end = e;
  43.351 -	    }
  43.352 -	    else
  43.353 -	      return FALSE;
  43.354 -	  }else{
  43.355 -	    /* unqualified? */
  43.356 -	    *domain_begin = *domain_end = NULL;
  43.357 -	  }
  43.358 -	  break;
  43.359 -	}else if(*p == '<'){
  43.360 -	  /* addr-spec follows */
  43.361 -	  while(isspace(*p) || (*p == '<')){
  43.362 -	    if(*p == '<')
  43.363 -	      angle_brackets++;
  43.364 -	    p++;
  43.365 -	  }
  43.366 -	  if(read_word_with_dots(p, &b, &e)){
  43.367 -	    p = e;
  43.368 -	    *local_begin = b;
  43.369 -	    *local_end = e;
  43.370 -#ifdef PARSE_TEST
  43.371 -	  g_print("found local part: %s\n", *local_begin);
  43.372 -#endif
  43.373 -	  }else
  43.374 -	    return FALSE;
  43.375 -	  if(*p == '@'){
  43.376 -	    p++;
  43.377 -	    if(read_domain(p, &b, &e)){
  43.378 -	      p = e;
  43.379 -	      *domain_begin = b;
  43.380 -	      *domain_end = e;
  43.381 -	    }else
  43.382 -	      return FALSE;
  43.383 -	  }else{
  43.384 -	    /* may be unqualified address */
  43.385 -	    *domain_begin = *domain_end = NULL;
  43.386 -	  }
  43.387 -	  break;
  43.388 -	}else if(!*p || *p == '>'){
  43.389 -	  *local_begin = b;
  43.390 -	  *local_end = e;
  43.391 -#ifdef PARSE_TEST
  43.392 -	  g_print("found local part: %s\n", *local_begin);
  43.393 -#endif
  43.394 -	  *domain_begin = *domain_end = NULL;
  43.395 -	  break;
  43.396 -	}else if(strchr(specials, *p) || iscntrl(*p) || isspace(*p)){
  43.397 -	  parse_error = g_strdup_printf("unexpected character: %c", *p);
  43.398 -	  return FALSE;
  43.399 -	}
  43.400 -      }else
  43.401  	return FALSE;
  43.402 -    }
  43.403 -   /* trailing spaces and angle brackets */
  43.404 -#ifdef PARSE_TEST
  43.405 -    g_print("down counting trailing '>'\n");
  43.406 -#endif
  43.407 -    while(*p && (isspace(*p) || (*p == '>'))){
  43.408 -      if(*p == '>')
  43.409 -	angle_brackets--;
  43.410 -      p++;
  43.411 -    }
  43.412 -
  43.413 -    *address_end = p;
  43.414 -
  43.415 -    if(angle_brackets != 0){
  43.416 -      if(angle_brackets > 0)
  43.417 -	parse_error = g_strdup("missing '>' at end of string");
  43.418 -      else
  43.419 -	parse_error = g_strdup("superfluous '>' at end of string");
  43.420 -      return FALSE;
  43.421 -    }else{
  43.422 -      /* we successfully parsed the address */
  43.423 -      return TRUE;
  43.424 -    }
  43.425 -    /* we never get here */
  43.426 -  }
  43.427 -  return FALSE;
  43.428  }
  43.429  
  43.430 -gboolean parse_address_rfc821(gchar *string,
  43.431 -			      gchar **local_begin, gchar **local_end,
  43.432 -			      gchar **domain_begin, gchar **domain_end,
  43.433 -			      gchar **address_end)
  43.434 +gboolean
  43.435 +parse_address_rfc821(gchar* string, gchar** local_begin, gchar** local_end, gchar** domain_begin, gchar** domain_end, gchar** address_end)
  43.436  {
  43.437 -  gint angle_brackets = 0;
  43.438 +	gint angle_brackets = 0;
  43.439  
  43.440 -  gchar *p = string;
  43.441 -  gchar *b, *e;
  43.442 +	gchar *p = string;
  43.443 +	gchar *b, *e;
  43.444  
  43.445 -  *local_begin = *local_end = NULL;
  43.446 -  *domain_begin = *domain_end = NULL;
  43.447 +	*local_begin = *local_end = NULL;
  43.448 +	*domain_begin = *domain_end = NULL;
  43.449  
  43.450 -  /* might be some memory left from previous call: */
  43.451 -  if(parse_error != NULL){
  43.452 -    g_free(parse_error);
  43.453 -    parse_error = NULL;
  43.454 -  }
  43.455 +	/* might be some memory left from previous call: */
  43.456 +	if (parse_error != NULL) {
  43.457 +		g_free(parse_error);
  43.458 +		parse_error = NULL;
  43.459 +	}
  43.460  
  43.461 -  /* leading spaces and angle brackets */
  43.462 -  while(*p && (isspace(*p) || (*p == '<'))){
  43.463 -    if(*p == '<')
  43.464 -      angle_brackets++;
  43.465 -    p++;
  43.466 -  }
  43.467 - 
  43.468 -  if(*p){
  43.469 -    while(TRUE){
  43.470 -      if(read_word_with_dots(p, &b, &e)){
  43.471 -	p = e;
  43.472 +	/* leading spaces and angle brackets */
  43.473 +	while (*p && (isspace(*p) || (*p == '<'))) {
  43.474 +		if (*p == '<')
  43.475 +			angle_brackets++;
  43.476 +		p++;
  43.477 +	}
  43.478 +
  43.479 +	if (*p) {
  43.480 +		while (TRUE) {
  43.481 +			if (read_word_with_dots(p, &b, &e)) {
  43.482 +				p = e;
  43.483  #ifdef PARSE_TEST
  43.484 -	g_print("after read_word_with_dots: %s\n", p);
  43.485 +				g_print("after read_word_with_dots: %s\n", p);
  43.486  #endif
  43.487 -	*local_begin = b;
  43.488 -	*local_end = e;
  43.489 +				*local_begin = b;
  43.490 +				*local_end = e;
  43.491  #ifdef PARSE_TEST
  43.492 -	  g_print("found local part: %s\n", *local_begin);
  43.493 -	  g_print("local_end = %s\n", *local_end);
  43.494 +				g_print("found local part: %s\n", *local_begin);
  43.495 +				g_print("local_end = %s\n", *local_end);
  43.496  #endif
  43.497 -	if(!(*p) || isspace(*p) || (*p == '>')){
  43.498 -	  /* unqualified ?*/
  43.499 -	  domain_begin = domain_end = NULL;
  43.500 -	  break;
  43.501 -	}else if(*p == '@'){
  43.502 -	  p++;
  43.503 -	  if(read_domain(p, &b, &e)){
  43.504 -	    p = e;
  43.505 -	    *domain_begin = b;
  43.506 -	    *domain_end = e;
  43.507 -	  }
  43.508 -	  break;
  43.509 -	}else{
  43.510 -	  parse_error =
  43.511 -	      g_strdup_printf("unexpected character after local part '%c'",*p);
  43.512 -	  return FALSE;
  43.513 +				if (!(*p) || isspace(*p) || (*p == '>')) {
  43.514 +					/* unqualified ? */
  43.515 +					domain_begin = domain_end = NULL;
  43.516 +					break;
  43.517 +				} else if (*p == '@') {
  43.518 +					p++;
  43.519 +					if (read_domain(p, &b, &e)) {
  43.520 +						p = e;
  43.521 +						*domain_begin = b;
  43.522 +						*domain_end = e;
  43.523 +					}
  43.524 +					break;
  43.525 +				} else {
  43.526 +					parse_error = g_strdup_printf ("unexpected character after local part '%c'", *p);
  43.527 +					return FALSE;
  43.528 +				}
  43.529 +			} else
  43.530 +				return FALSE;
  43.531 +		}
  43.532 +
  43.533 +		/* trailing spaces and angle brackets */
  43.534 +#ifdef PARSE_TEST
  43.535 +		g_print("down counting trailing '>'\n");
  43.536 +#endif
  43.537 +		while (*p && (isspace(*p) || (*p == '>'))) {
  43.538 +			if (*p == '>')
  43.539 +				angle_brackets--;
  43.540 +			p++;
  43.541 +		}
  43.542 +		*address_end = p;
  43.543 +
  43.544 +		if (angle_brackets != 0) {
  43.545 +			if (angle_brackets > 0)
  43.546 +				parse_error = g_strdup("missing '>' at end of string");
  43.547 +			else
  43.548 +				parse_error = g_strdup("superfluous '>' at end of string");
  43.549 +			return FALSE;
  43.550 +		} else {
  43.551 +			/* we successfully parsed the address */
  43.552 +			return TRUE;
  43.553 +		}
  43.554 +		/* we never get here */
  43.555  	}
  43.556 -      } else
  43.557 -         return FALSE;
  43.558 -    }
  43.559 -
  43.560 -    /* trailing spaces and angle brackets */
  43.561 -#ifdef PARSE_TEST
  43.562 -    g_print("down counting trailing '>'\n");
  43.563 -#endif
  43.564 -    while(*p && (isspace(*p) || (*p == '>'))){
  43.565 -      if(*p == '>')
  43.566 -	angle_brackets--;
  43.567 -      p++;
  43.568 -    }
  43.569 -    *address_end = p;
  43.570 -
  43.571 -    if(angle_brackets != 0){
  43.572 -      if(angle_brackets > 0)
  43.573 -	parse_error = g_strdup("missing '>' at end of string");
  43.574 -      else
  43.575 -	parse_error = g_strdup("superfluous '>' at end of string");
  43.576 -      return FALSE;
  43.577 -    }else{
  43.578 -      /* we successfully parsed the address */
  43.579 -      return TRUE;
  43.580 -    }
  43.581 -    /* we never get here */
  43.582 -  }
  43.583 -  return FALSE;
  43.584 +	return FALSE;
  43.585  }
  43.586  
  43.587  /*
  43.588 @@ -358,93 +353,98 @@
  43.589    parses both rfc 821 and rfc 822 addresses, depending on flag is_rfc821
  43.590  */
  43.591  
  43.592 -address *_create_address(gchar *string, gchar **end, gboolean is_rfc821)
  43.593 +address*
  43.594 +_create_address(gchar * string, gchar ** end, gboolean is_rfc821)
  43.595  {
  43.596 -  gchar *loc_beg, *loc_end;
  43.597 -  gchar *dom_beg, *dom_end;
  43.598 -  gchar *addr_end;
  43.599 +	gchar *loc_beg, *loc_end;
  43.600 +	gchar *dom_beg, *dom_end;
  43.601 +	gchar *addr_end;
  43.602  
  43.603 -  if (string && (string[0] == 0)) {
  43.604 -    address *addr = g_malloc(sizeof(address));
  43.605 -    addr->address = g_strdup("");
  43.606 -    addr->local_part = g_strdup("");
  43.607 -    addr->domain = g_strdup(""); /* 'NULL' address (failure notice),
  43.608 -        "" makes sure it will not be qualified with a hostname */
  43.609 -    return addr;
  43.610 -  }
  43.611 +	if (string && (string[0] == 0)) {
  43.612 +		address *addr = g_malloc(sizeof(address));
  43.613 +		addr->address = g_strdup("");
  43.614 +		addr->local_part = g_strdup("");
  43.615 +		addr->domain = g_strdup("");  /* 'NULL' address (failure notice), "" makes sure it will not be qualified with a hostname */
  43.616 +		return addr;
  43.617 +	}
  43.618  
  43.619 -  if(is_rfc821 ?
  43.620 -     parse_address_rfc821(string,
  43.621 -			  &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end) :
  43.622 -     parse_address_rfc822(string,
  43.623 -			  &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)){
  43.624 -    address *addr = g_malloc(sizeof(address));
  43.625 -    gchar *p = addr_end;
  43.626 -    
  43.627 +	if (is_rfc821
  43.628 +	    ? parse_address_rfc821(string, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)
  43.629 +	    : parse_address_rfc822(string, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end))
  43.630 +	{
  43.631 +		address *addr = g_malloc(sizeof(address));
  43.632 +		gchar *p = addr_end;
  43.633  
  43.634 -    memset(addr, 0, sizeof(address));
  43.635  
  43.636 -    if(loc_beg[0] == '|'){
  43.637 -      parse_error = g_strdup("no pipe allowed for RFC 822/821 address");
  43.638 -      return NULL;
  43.639 -    }
  43.640 +		memset(addr, 0, sizeof(address));
  43.641  
  43.642 -    while(*p && (*p != ',')) p++;
  43.643 -    addr->address = g_strndup(string, p - string);
  43.644 +		if (loc_beg[0] == '|') {
  43.645 +			parse_error = g_strdup("no pipe allowed for RFC 822/821 address");
  43.646 +			return NULL;
  43.647 +		}
  43.648  
  43.649 -    addr->local_part = g_strndup(loc_beg, loc_end - loc_beg);
  43.650 +		while (*p && (*p != ','))
  43.651 +			p++;
  43.652 +		addr->address = g_strndup(string, p - string);
  43.653 +
  43.654 +		addr->local_part = g_strndup(loc_beg, loc_end - loc_beg);
  43.655  
  43.656  #ifdef PARSE_TEST
  43.657 -    g_print("addr->local_part = %s\n", addr->local_part);
  43.658 +		g_print("addr->local_part = %s\n", addr->local_part);
  43.659  #endif
  43.660  
  43.661 -    if(dom_beg != NULL){
  43.662 -      addr->domain = g_strndup(dom_beg, dom_end - dom_beg);
  43.663 -    }else{
  43.664 -      if(addr->local_part[0] == 0)
  43.665 -	addr->domain = g_strdup(""); /* 'NULL' address (failure notice),
  43.666 -		      "" makes sure it will not be qualified with a hostname */
  43.667 -      else
  43.668 -	addr->domain = NULL;
  43.669 -    }
  43.670 +		if (dom_beg != NULL) {
  43.671 +			addr->domain = g_strndup(dom_beg, dom_end - dom_beg);
  43.672 +		} else {
  43.673 +			if (addr->local_part[0] == 0)
  43.674 +				addr->domain = g_strdup("");  /* 'NULL' address (failure notice), "" makes sure it will not be qualified with a hostname */
  43.675 +			else
  43.676 +				addr->domain = NULL;
  43.677 +		}
  43.678  
  43.679 -    if(end != NULL)
  43.680 -      *end = p;
  43.681 +		if (end != NULL)
  43.682 +			*end = p;
  43.683  
  43.684  #ifndef PARSE_TEST
  43.685 -    addr_unmark_delivered(addr);
  43.686 +		addr_unmark_delivered(addr);
  43.687  #endif
  43.688  
  43.689 -    return addr;
  43.690 -  }
  43.691 -  return NULL;
  43.692 +		return addr;
  43.693 +	}
  43.694 +	return NULL;
  43.695  }
  43.696  
  43.697 -address *create_address_rfc822(gchar *string, gchar **end){
  43.698 -  return _create_address(string, end, FALSE);
  43.699 +address*
  43.700 +create_address_rfc822(gchar * string, gchar ** end)
  43.701 +{
  43.702 +	return _create_address(string, end, FALSE);
  43.703  }
  43.704  
  43.705 -address *create_address_rfc821(gchar *string, gchar **end){
  43.706 -  return _create_address(string, end, TRUE);
  43.707 +address*
  43.708 +create_address_rfc821(gchar * string, gchar ** end)
  43.709 +{
  43.710 +	return _create_address(string, end, TRUE);
  43.711  }
  43.712  
  43.713 -GList *addr_list_append_rfc822(GList *addr_list, gchar *string, gchar *domain)
  43.714 +GList*
  43.715 +addr_list_append_rfc822(GList * addr_list, gchar * string, gchar * domain)
  43.716  {
  43.717 -  gchar *p = string;
  43.718 -  gchar *end;
  43.719 +	gchar *p = string;
  43.720 +	gchar *end;
  43.721  
  43.722 -  while(*p){
  43.723 -    address *addr = _create_address(p, &end, FALSE);
  43.724 -    if(addr){
  43.725 -      if(domain)
  43.726 -	if(addr->domain == NULL)
  43.727 -	  addr->domain = g_strdup(domain);
  43.728 +	while (*p) {
  43.729 +		address *addr = _create_address(p, &end, FALSE);
  43.730 +		if (addr) {
  43.731 +			if (domain)
  43.732 +				if (addr->domain == NULL)
  43.733 +					addr->domain = g_strdup(domain);
  43.734  
  43.735 -      addr_list = g_list_append(addr_list, addr);
  43.736 -      p = end;
  43.737 -    }else
  43.738 -      break;
  43.739 -    while(*p == ',' || isspace(*p)) p++;
  43.740 -  }
  43.741 -  return addr_list;
  43.742 +			addr_list = g_list_append(addr_list, addr);
  43.743 +			p = end;
  43.744 +		} else
  43.745 +			break;
  43.746 +		while (*p == ',' || isspace(*p))
  43.747 +			p++;
  43.748 +	}
  43.749 +	return addr_list;
  43.750  }
    44.1 --- a/src/peopen.c	Mon Oct 27 16:21:27 2008 +0100
    44.2 +++ b/src/peopen.c	Mon Oct 27 16:23:10 2008 +0100
    44.3 @@ -13,124 +13,123 @@
    44.4  
    44.5  #include "masqmail.h"
    44.6  
    44.7 -static
    44.8 -void destroy_argv(char **arr)
    44.9 +static void
   44.10 +destroy_argv(char **arr)
   44.11  {
   44.12 -  char *p = arr[0];
   44.13 -  int i = 0;
   44.14 +	char *p = arr[0];
   44.15 +	int i = 0;
   44.16  
   44.17 -  while(p){
   44.18 -    free(p);
   44.19 -    p = arr[i++];
   44.20 -  }
   44.21 -  free(arr);
   44.22 +	while (p) {
   44.23 +		free(p);
   44.24 +		p = arr[i++];
   44.25 +	}
   44.26 +	free(arr);
   44.27  }
   44.28  
   44.29 -static
   44.30 -char **create_argv(const char *cmd, int count)
   44.31 +static char**
   44.32 +create_argv(const char *cmd, int count)
   44.33  {
   44.34 -  char buf[strlen(cmd)+1];
   44.35 -  char **arr, *q;
   44.36 -  const char *p;
   44.37 -  int i = 0;
   44.38 +	char buf[strlen(cmd) + 1];
   44.39 +	char **arr, *q;
   44.40 +	const char *p;
   44.41 +	int i = 0;
   44.42  
   44.43 -  arr = (char **)malloc(sizeof(char *) * count);
   44.44 -  
   44.45 -  p = cmd;
   44.46 -  while(*p && i < (count-1)){
   44.47 -    while(*p && isspace(*p)) p++;
   44.48 -    q = buf;
   44.49 -    while(*p && !isspace(*p)) *q++ = *p++;
   44.50 -    *q = 0;
   44.51 -    arr[i++] = strdup(buf);
   44.52 -    while(*p && isspace(*p)) p++;
   44.53 -  }
   44.54 -  arr[i] = NULL;
   44.55 +	arr = (char **) malloc(sizeof(char *) * count);
   44.56  
   44.57 -  return arr;
   44.58 +	p = cmd;
   44.59 +	while (*p && i < (count - 1)) {
   44.60 +		while (*p && isspace(*p))
   44.61 +			p++;
   44.62 +		q = buf;
   44.63 +		while (*p && !isspace(*p))
   44.64 +			*q++ = *p++;
   44.65 +		*q = 0;
   44.66 +		arr[i++] = strdup(buf);
   44.67 +		while (*p && isspace(*p))
   44.68 +			p++;
   44.69 +	}
   44.70 +	arr[i] = NULL;
   44.71 +
   44.72 +	return arr;
   44.73  }
   44.74  
   44.75 -FILE* peidopen(const char	*command,
   44.76 -	       const char	*type,
   44.77 -	       char *const envp [],
   44.78 -	       int *ret_pid,
   44.79 -	       uid_t uid, gid_t gid
   44.80 -	     )
   44.81 +FILE*
   44.82 +peidopen(const char *command, const char *type, char *const envp[], int *ret_pid, uid_t uid, gid_t gid)
   44.83  {
   44.84 -  enum { Read, Write } mode;
   44.85 -  int pipe_fd [2];
   44.86 -  pid_t pid;
   44.87 -    
   44.88 -  if (command == NULL || type == NULL) {
   44.89 -    errno = EINVAL;
   44.90 -    return NULL;
   44.91 -  }
   44.92 +	enum { Read, Write } mode;
   44.93 +	int pipe_fd[2];
   44.94 +	pid_t pid;
   44.95  
   44.96 -  if (strcmp (type, "r")) {
   44.97 -    if (strcmp (type, "w")) {
   44.98 -      errno = EINVAL;
   44.99 -      return NULL;
  44.100 -    } else
  44.101 -      mode = Write;
  44.102 -  } else
  44.103 -    mode = Read;
  44.104 +	if (command == NULL || type == NULL) {
  44.105 +		errno = EINVAL;
  44.106 +		return NULL;
  44.107 +	}
  44.108  
  44.109 -  if (pipe (pipe_fd) == -1)
  44.110 -    return NULL;
  44.111 +	if (strcmp(type, "r")) {
  44.112 +		if (strcmp(type, "w")) {
  44.113 +			errno = EINVAL;
  44.114 +			return NULL;
  44.115 +		} else
  44.116 +			mode = Write;
  44.117 +	} else
  44.118 +		mode = Read;
  44.119  
  44.120 -  switch (pid = fork ()) {
  44.121 -  case 0: /* child thread */
  44.122 +	if (pipe(pipe_fd) == -1)
  44.123 +		return NULL;
  44.124  
  44.125 -    {
  44.126 -      int i, max_fd = sysconf(_SC_OPEN_MAX);
  44.127 -      
  44.128 -      if(max_fd <= 0) max_fd = 64;
  44.129 -      for(i = 0; i < max_fd; i++)
  44.130 -	if((i != pipe_fd[0]) && (i != pipe_fd[1])) close(i);
  44.131 -    }
  44.132 -    if (close (pipe_fd [mode == Read ? 0 : 1]) != -1 &&
  44.133 -	dup2 (pipe_fd [mode == Read ? 1 : 0], mode == Read ? STDOUT_FILENO : STDIN_FILENO) != -1) {
  44.134 -      //      char *argv [] = { "/bin/sh", "-c", (char*) command, NULL };
  44.135 -      char **argv = create_argv(command, 10);
  44.136 -      int ret;
  44.137 +	switch (pid = fork()) {
  44.138 +	case 0:  /* child thread */
  44.139  
  44.140 -      if(uid != (uid_t)-1){
  44.141 -	if((ret = seteuid(0)) != 0){
  44.142 -	  exit(EX_NOPERM);
  44.143 +		{
  44.144 +			int i, max_fd = sysconf(_SC_OPEN_MAX);
  44.145 +
  44.146 +			if (max_fd <= 0)
  44.147 +				max_fd = 64;
  44.148 +			for (i = 0; i < max_fd; i++)
  44.149 +				if ((i != pipe_fd[0]) && (i != pipe_fd[1]))
  44.150 +					close(i);
  44.151 +		}
  44.152 +		if (close(pipe_fd[mode == Read ? 0 : 1]) != -1 &&
  44.153 +			dup2(pipe_fd[mode == Read ? 1 : 0],
  44.154 +				 mode == Read ? STDOUT_FILENO : STDIN_FILENO) != -1) {
  44.155 +			//      char *argv [] = { "/bin/sh", "-c", (char*) command, NULL };
  44.156 +			char **argv = create_argv(command, 10);
  44.157 +			int ret;
  44.158 +
  44.159 +			if (uid != (uid_t) - 1) {
  44.160 +				if ((ret = seteuid(0)) != 0) {
  44.161 +					exit(EX_NOPERM);
  44.162 +				}
  44.163 +			}
  44.164 +			if (gid != (gid_t) - 1) {
  44.165 +				if ((ret = setgid(gid)) != 0) {
  44.166 +					exit(EX_NOPERM);
  44.167 +				}
  44.168 +			}
  44.169 +			if (uid != (uid_t) - 1) {
  44.170 +				if ((ret = setuid(uid)) != 0) {
  44.171 +					exit(EX_NOPERM);
  44.172 +				}
  44.173 +			}
  44.174 +			execve(*argv, argv, envp);
  44.175 +		}
  44.176 +
  44.177 +		_exit(errno);
  44.178 +
  44.179 +	default:  /* parent thread */
  44.180 +		*ret_pid = pid;
  44.181 +		close(pipe_fd[mode == Read ? 1 : 0]);
  44.182 +		return fdopen(pipe_fd[mode == Read ? 0 : 1], type);
  44.183 +
  44.184 +	case -1:
  44.185 +		close(pipe_fd[0]);
  44.186 +		close(pipe_fd[1]);
  44.187 +		return NULL;
  44.188  	}
  44.189 -      }
  44.190 -      if(gid != (gid_t)-1){
  44.191 -	if((ret = setgid(gid)) != 0){
  44.192 -	  exit(EX_NOPERM);
  44.193 -	}
  44.194 -      }
  44.195 -      if(uid != (uid_t)-1){
  44.196 -	if((ret = setuid(uid)) != 0){
  44.197 -	  exit(EX_NOPERM);
  44.198 -	}
  44.199 -      }
  44.200 -      execve (*argv, argv, envp);
  44.201 -    }
  44.202 -	    
  44.203 -    _exit (errno);
  44.204 -	    
  44.205 -  default: /* parent thread */
  44.206 -    *ret_pid = pid;
  44.207 -    close (pipe_fd [mode == Read ? 1 : 0]);
  44.208 -    return fdopen (pipe_fd [mode == Read ? 0 : 1], type);
  44.209 -	    
  44.210 -  case -1:
  44.211 -    close (pipe_fd [0]);
  44.212 -    close (pipe_fd [1]);
  44.213 -    return NULL;
  44.214 -  }
  44.215  }
  44.216  
  44.217 -FILE* peopen(const char	*command,
  44.218 -	     const char	*type,
  44.219 -	     char *const envp [],
  44.220 -	     int *ret_pid
  44.221 -	     )
  44.222 +FILE*
  44.223 +peopen(const char *command, const char *type, char *const envp[], int *ret_pid)
  44.224  {
  44.225 -  return peidopen(command, type, envp, ret_pid, -1 ,-1);
  44.226 +	return peidopen(command, type, envp, ret_pid, -1, -1);
  44.227  }
    45.1 --- a/src/peopen.h	Mon Oct 27 16:21:27 2008 +0100
    45.2 +++ b/src/peopen.h	Mon Oct 27 16:23:10 2008 +0100
    45.3 @@ -1,13 +1,3 @@
    45.4 -FILE* peopen(const char	*command,
    45.5 -	     const char	*type,
    45.6 -	     char *const envp [],
    45.7 -	     int *ret_pid
    45.8 -);
    45.9 +FILE *peopen(const char *command, const char *type, char *const envp[], int *ret_pid);
   45.10  
   45.11 -FILE* peidopen(const char	*command,
   45.12 -	       const char	*type,
   45.13 -	       char *const envp [],
   45.14 -	       int *ret_pid,
   45.15 -	       uid_t uid, gid_t gid
   45.16 -);
   45.17 -
   45.18 +FILE *peidopen(const char *command, const char *type, char *const envp[], int *ret_pid, uid_t uid, gid_t gid);
    46.1 --- a/src/permissions.c	Mon Oct 27 16:21:27 2008 +0100
    46.2 +++ b/src/permissions.c	Mon Oct 27 16:23:10 2008 +0100
    46.3 @@ -21,58 +21,60 @@
    46.4  #include <grp.h>
    46.5  
    46.6  /* is there really no function in libc for this? */
    46.7 -gboolean is_ingroup(uid_t uid, gid_t gid)
    46.8 +gboolean
    46.9 +is_ingroup(uid_t uid, gid_t gid)
   46.10  {
   46.11 -  struct group *grent = getgrgid(gid);
   46.12 +	struct group *grent = getgrgid(gid);
   46.13  
   46.14 -  if(grent){
   46.15 -    struct passwd *pwent = getpwuid(uid);
   46.16 -    if(pwent){
   46.17 -      char *entry;
   46.18 -      int i = 0;
   46.19 -      while((entry = grent->gr_mem[i++])){
   46.20 -	if(strcmp(pwent->pw_name, entry) == 0)
   46.21 -	  return TRUE;
   46.22 -      }
   46.23 -    }
   46.24 -  }
   46.25 -  return FALSE;
   46.26 +	if (grent) {
   46.27 +		struct passwd *pwent = getpwuid(uid);
   46.28 +		if (pwent) {
   46.29 +			char *entry;
   46.30 +			int i = 0;
   46.31 +			while ((entry = grent->gr_mem[i++])) {
   46.32 +				if (strcmp(pwent->pw_name, entry) == 0)
   46.33 +					return TRUE;
   46.34 +			}
   46.35 +		}
   46.36 +	}
   46.37 +	return FALSE;
   46.38  }
   46.39  
   46.40 -gboolean is_privileged_user(uid_t uid)
   46.41 +gboolean
   46.42 +is_privileged_user(uid_t uid)
   46.43  {
   46.44 -  return (uid == 0) || (uid == conf.mail_uid) || (is_ingroup(uid, conf.mail_gid));
   46.45 +	return (uid == 0) || (uid == conf.mail_uid) || (is_ingroup(uid, conf.mail_gid));
   46.46  }
   46.47  
   46.48 -void set_euidgid(gint uid, gint gid, uid_t *old_uid, gid_t *old_gid)
   46.49 +void
   46.50 +set_euidgid(gint uid, gint gid, uid_t * old_uid, gid_t * old_gid)
   46.51  {
   46.52 -  if(old_uid) *old_uid = geteuid();
   46.53 -  if(old_gid) *old_gid = getegid();
   46.54 +	if (old_uid)
   46.55 +		*old_uid = geteuid();
   46.56 +	if (old_gid)
   46.57 +		*old_gid = getegid();
   46.58  
   46.59 -  seteuid(0);
   46.60 +	seteuid(0);
   46.61  
   46.62 -  if(setegid(gid) != 0){
   46.63 -    logwrite(LOG_ALERT, "could not change gid to %d: %s\n",
   46.64 -	     gid, strerror(errno));
   46.65 -    exit(EXIT_FAILURE);
   46.66 -  }
   46.67 -  if(seteuid(uid) != 0){
   46.68 -    logwrite(LOG_ALERT, "could not change uid to %d: %s\n",
   46.69 -	     uid, strerror(errno));
   46.70 -    exit(EXIT_FAILURE);
   46.71 -  }
   46.72 +	if (setegid(gid) != 0) {
   46.73 +		logwrite(LOG_ALERT, "could not change gid to %d: %s\n", gid, strerror(errno));
   46.74 +		exit(EXIT_FAILURE);
   46.75 +	}
   46.76 +	if (seteuid(uid) != 0) {
   46.77 +		logwrite(LOG_ALERT, "could not change uid to %d: %s\n", uid, strerror(errno));
   46.78 +		exit(EXIT_FAILURE);
   46.79 +	}
   46.80  }
   46.81  
   46.82 -void set_identity(uid_t old_uid, gchar *task_name)
   46.83 +void
   46.84 +set_identity(uid_t old_uid, gchar * task_name)
   46.85  {
   46.86 -  if(!conf.run_as_user){
   46.87 -    if(!is_privileged_user(old_uid)){
   46.88 -      fprintf(stderr,
   46.89 -	      "must be root, %s or in group %s for %s.\n",
   46.90 -	      DEF_MAIL_USER, DEF_MAIL_GROUP, task_name);
   46.91 -      exit(EXIT_FAILURE);
   46.92 -    }
   46.93 +	if (!conf.run_as_user) {
   46.94 +		if (!is_privileged_user(old_uid)) {
   46.95 +			fprintf(stderr, "must be root, %s or in group %s for %s.\n", DEF_MAIL_USER, DEF_MAIL_GROUP, task_name);
   46.96 +			exit(EXIT_FAILURE);
   46.97 +		}
   46.98  
   46.99 -    set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL);
  46.100 -  }
  46.101 +		set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL);
  46.102 +	}
  46.103  }
    47.1 --- a/src/pop3_in.c	Mon Oct 27 16:21:27 2008 +0100
    47.2 +++ b/src/pop3_in.c	Mon Oct 27 16:23:10 2008 +0100
    47.3 @@ -4,7 +4,7 @@
    47.4   * it under the terms of the GNU General Public License as published by
    47.5   * the Free Software Foundation; either version 2 of the License, or
    47.6   * (at your option) any later version.
    47.7 - * 
    47.8 + *
    47.9   * This program is distributed in the hope that it will be useful,
   47.10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   47.11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   47.12 @@ -36,785 +36,774 @@
   47.13  /* experimental feature */
   47.14  #define DO_WRITE_UIDL_EARLY 1
   47.15  
   47.16 -static
   47.17 -gchar *MD5String (char *string)
   47.18 +static gchar*
   47.19 +MD5String(char *string)
   47.20  {
   47.21 -  MD5_CTX context;
   47.22 -  unsigned char digest[16];
   47.23 -  char str_digest[33];
   47.24 -  int i;
   47.25 +	MD5_CTX context;
   47.26 +	unsigned char digest[16];
   47.27 +	char str_digest[33];
   47.28 +	int i;
   47.29  
   47.30  #ifdef USE_LIB_CRYPTO
   47.31 -  MD5(string, strlen(string), digest);
   47.32 +	MD5(string, strlen(string), digest);
   47.33  #else
   47.34 -  MD5Init(&context);
   47.35 -  MD5Update(&context, string, strlen(string));
   47.36 -  MD5Final(digest, &context);
   47.37 +	MD5Init(&context);
   47.38 +	MD5Update(&context, string, strlen(string));
   47.39 +	MD5Final(digest, &context);
   47.40  #endif
   47.41 -  for (i = 0;  i < 16;  i++) 
   47.42 -    sprintf(str_digest+2*i, "%02x", digest[i]);
   47.43 +	for (i = 0; i < 16; i++)
   47.44 +		sprintf(str_digest + 2 * i, "%02x", digest[i]);
   47.45  
   47.46 -  return g_strdup(str_digest);
   47.47 +	return g_strdup(str_digest);
   47.48  }
   47.49  
   47.50 -static
   47.51 -pop3_base *create_pop3base(gint sock, guint flags)
   47.52 +static pop3_base*
   47.53 +create_pop3base(gint sock, guint flags)
   47.54  {
   47.55 -  gint dup_sock;
   47.56 +	gint dup_sock;
   47.57  
   47.58 -  pop3_base *popb = (pop3_base *)g_malloc(sizeof(pop3_base));
   47.59 -  if(popb){
   47.60 -    memset(popb, 0, sizeof(pop3_base));
   47.61 +	pop3_base *popb = (pop3_base *) g_malloc(sizeof(pop3_base));
   47.62 +	if (popb) {
   47.63 +		memset(popb, 0, sizeof(pop3_base));
   47.64  
   47.65 -    popb->error = pop3_ok;
   47.66 +		popb->error = pop3_ok;
   47.67  
   47.68 -    popb->buffer = (gchar *)g_malloc(POP3_BUF_LEN);
   47.69 +		popb->buffer = (gchar *) g_malloc(POP3_BUF_LEN);
   47.70  
   47.71 -    dup_sock = dup(sock);
   47.72 -    popb->out = fdopen(sock, "w");
   47.73 -    popb->in = fdopen(dup_sock, "r");
   47.74 -    
   47.75 -    popb->flags = flags;
   47.76 -  }
   47.77 -  return popb;
   47.78 +		dup_sock = dup(sock);
   47.79 +		popb->out = fdopen(sock, "w");
   47.80 +		popb->in = fdopen(dup_sock, "r");
   47.81 +
   47.82 +		popb->flags = flags;
   47.83 +	}
   47.84 +	return popb;
   47.85  }
   47.86  
   47.87 -static
   47.88 -void pop3_printf(FILE *out, gchar *fmt, ...)
   47.89 +static void
   47.90 +pop3_printf(FILE * out, gchar * fmt, ...)
   47.91  {
   47.92 -  va_list args;
   47.93 -  va_start(args, fmt);
   47.94 +	va_list args;
   47.95 +	va_start(args, fmt);
   47.96  
   47.97 -  DEBUG(4){
   47.98 -    gchar buf[256];
   47.99 -    va_list args_copy;
  47.100 +	DEBUG(4) {
  47.101 +		gchar buf[256];
  47.102 +		va_list args_copy;
  47.103  
  47.104 -    va_copy(args_copy, args);
  47.105 -    vsnprintf(buf, 255, fmt, args_copy);
  47.106 -    va_end(args_copy);
  47.107 +		va_copy(args_copy, args);
  47.108 +		vsnprintf(buf, 255, fmt, args_copy);
  47.109 +		va_end(args_copy);
  47.110  
  47.111 -    debugf(">>>%s", buf);
  47.112 -  }
  47.113 +		debugf(">>>%s", buf);
  47.114 +	}
  47.115  
  47.116 -  vfprintf(out, fmt, args);  fflush(out);
  47.117 +	vfprintf(out, fmt, args);
  47.118 +	fflush(out);
  47.119  
  47.120 -  va_end(args);
  47.121 +	va_end(args);
  47.122  }
  47.123  
  47.124 -static
  47.125 -gboolean find_uid(pop3_base *popb, gchar *str)
  47.126 +static gboolean
  47.127 +find_uid(pop3_base * popb, gchar * str)
  47.128  {
  47.129 -  GList *node, *node_next;
  47.130 +	GList *node, *node_next;
  47.131  
  47.132 -  for(node = popb->list_uid_old; node; node=node_next){
  47.133 -    gchar *uid = (gchar *)(node->data);
  47.134 -    node_next = node->next;
  47.135 -    if(strcmp(uid, str) == 0){
  47.136 +	for (node = popb->list_uid_old; node; node = node_next) {
  47.137 +		gchar *uid = (gchar *) (node->data);
  47.138 +		node_next = node->next;
  47.139 +		if (strcmp(uid, str) == 0) {
  47.140  #if 1
  47.141 -      popb->list_uid_old = g_list_remove_link(popb->list_uid_old, node);
  47.142 -      g_list_free_1(node);
  47.143 -      g_free(uid);
  47.144 +			popb->list_uid_old = g_list_remove_link(popb->list_uid_old, node);
  47.145 +			g_list_free_1(node);
  47.146 +			g_free(uid);
  47.147  #endif
  47.148 -      return TRUE;
  47.149 -    }
  47.150 -  }
  47.151 -  return FALSE;
  47.152 +			return TRUE;
  47.153 +		}
  47.154 +	}
  47.155 +	return FALSE;
  47.156  }
  47.157  
  47.158 -static
  47.159 -gboolean write_uidl(pop3_base *popb, gchar *user)
  47.160 +static gboolean
  47.161 +write_uidl(pop3_base * popb, gchar * user)
  47.162  {
  47.163 -  gboolean ok = FALSE;
  47.164 -  GList *node;
  47.165 -  gchar *filename = g_strdup_printf("%s/popuidl/%s@%s",
  47.166 -				    conf.spool_dir,
  47.167 -				    user, popb->remote_host);
  47.168 -  gchar *tmpname = g_strdup_printf("%s.tmp", filename);
  47.169 -  FILE *fptr = fopen(tmpname, "wt");
  47.170 +	gboolean ok = FALSE;
  47.171 +	GList *node;
  47.172 +	gchar *filename = g_strdup_printf("%s/popuidl/%s@%s", conf.spool_dir, user, popb->remote_host);
  47.173 +	gchar *tmpname = g_strdup_printf("%s.tmp", filename);
  47.174 +	FILE *fptr = fopen(tmpname, "wt");
  47.175  
  47.176 -  if(fptr){
  47.177 -    foreach(popb->drop_list, node){
  47.178 -      msg_info *info = (msg_info *)(node->data);
  47.179 -      if(info->is_fetched || info->is_in_uidl)
  47.180 -	fprintf(fptr, "%s\n", info->uid);
  47.181 -    }
  47.182 -    fclose(fptr);
  47.183 -    ok = (rename(tmpname, filename) != -1);
  47.184 -  }
  47.185 -  
  47.186 -  g_free(tmpname);
  47.187 -  g_free(filename);
  47.188 -  return ok;
  47.189 +	if (fptr) {
  47.190 +		foreach(popb->drop_list, node) {
  47.191 +			msg_info *info = (msg_info *) (node->data);
  47.192 +			if (info->is_fetched || info->is_in_uidl)
  47.193 +				fprintf(fptr, "%s\n", info->uid);
  47.194 +		}
  47.195 +		fclose(fptr);
  47.196 +		ok = (rename(tmpname, filename) != -1);
  47.197 +	}
  47.198 +
  47.199 +	g_free(tmpname);
  47.200 +	g_free(filename);
  47.201 +	return ok;
  47.202  }
  47.203  
  47.204 -static
  47.205 -gboolean read_uidl_fname(pop3_base *popb, gchar *filename)
  47.206 +static gboolean
  47.207 +read_uidl_fname(pop3_base * popb, gchar * filename)
  47.208  {
  47.209 -  gboolean ok = FALSE;
  47.210 -  FILE *fptr = fopen(filename, "rt");
  47.211 -  gchar buf[256];
  47.212 +	gboolean ok = FALSE;
  47.213 +	FILE *fptr = fopen(filename, "rt");
  47.214 +	gchar buf[256];
  47.215  
  47.216 -  if(fptr){
  47.217 -    popb->list_uid_old = NULL;
  47.218 -    while(fgets(buf, 255, fptr)){
  47.219 -      if(buf[strlen(buf)-1] == '\n'){
  47.220 -	g_strchomp(buf);
  47.221 -	popb->list_uid_old =
  47.222 -	  g_list_append(popb->list_uid_old, g_strdup(buf));
  47.223 -      }else{
  47.224 -	logwrite(LOG_ALERT, "broken uid: %s\n", buf);
  47.225 -	break;
  47.226 -      }
  47.227 -    }
  47.228 -    fclose(fptr);
  47.229 -    ok = TRUE;
  47.230 -  }else
  47.231 -    logwrite(LOG_ALERT, "opening of %s failed: %s", filename, strerror(errno));
  47.232 -  return ok;
  47.233 +	if (fptr) {
  47.234 +		popb->list_uid_old = NULL;
  47.235 +		while (fgets(buf, 255, fptr)) {
  47.236 +			if (buf[strlen(buf) - 1] == '\n') {
  47.237 +				g_strchomp(buf);
  47.238 +				popb->list_uid_old = g_list_append(popb->list_uid_old, g_strdup(buf));
  47.239 +			} else {
  47.240 +				logwrite(LOG_ALERT, "broken uid: %s\n", buf);
  47.241 +				break;
  47.242 +			}
  47.243 +		}
  47.244 +		fclose(fptr);
  47.245 +		ok = TRUE;
  47.246 +	} else
  47.247 +		logwrite(LOG_ALERT, "opening of %s failed: %s", filename, strerror(errno));
  47.248 +	return ok;
  47.249  }
  47.250  
  47.251 -static
  47.252 -gboolean read_uidl(pop3_base *popb, gchar *user)
  47.253 +static gboolean
  47.254 +read_uidl(pop3_base * popb, gchar * user)
  47.255  {
  47.256 -  gboolean ok = FALSE;
  47.257 -  struct stat statbuf;
  47.258 -  gchar *filename = g_strdup_printf("%s/popuidl/%s@%s",
  47.259 -				    conf.spool_dir,
  47.260 -				    user, popb->remote_host);
  47.261 +	gboolean ok = FALSE;
  47.262 +	struct stat statbuf;
  47.263 +	gchar *filename = g_strdup_printf("%s/popuidl/%s@%s", conf.spool_dir, user, popb->remote_host);
  47.264  
  47.265 -  if(stat(filename, &statbuf) == 0){
  47.266 -    ok = read_uidl_fname(popb, filename);
  47.267 -    if(ok){
  47.268 -      GList *drop_node;
  47.269 -      foreach(popb->drop_list, drop_node){
  47.270 -	msg_info *info = (msg_info *)(drop_node->data);
  47.271 -	if(find_uid(popb, info->uid)){
  47.272 -	  DEBUG(5) debugf("msg with uid '%s' already known\n", info->uid);
  47.273 -	  info->is_in_uidl = TRUE;
  47.274 -	  popb->uidl_known_cnt++;
  47.275 -	}else
  47.276 -	  DEBUG(5) debugf("msg with uid '%s' not known\n", info->uid);
  47.277 -      }
  47.278 -    }
  47.279 -  }else{
  47.280 -    logwrite(LOG_DEBUG, "no uidl file '%s' found\n", filename);
  47.281 -    ok = TRUE;
  47.282 -  }
  47.283 +	if (stat(filename, &statbuf) == 0) {
  47.284 +		ok = read_uidl_fname(popb, filename);
  47.285 +		if (ok) {
  47.286 +			GList *drop_node;
  47.287 +			foreach(popb->drop_list, drop_node) {
  47.288 +				msg_info *info = (msg_info *) (drop_node->data);
  47.289 +				if (find_uid(popb, info->uid)) {
  47.290 +					DEBUG(5) debugf("msg with uid '%s' already known\n", info->uid);
  47.291 +					info->is_in_uidl = TRUE;
  47.292 +					popb->uidl_known_cnt++;
  47.293 +				} else
  47.294 +					DEBUG(5) debugf("msg with uid '%s' not known\n", info->uid);
  47.295 +			}
  47.296 +		}
  47.297 +	} else {
  47.298 +		logwrite(LOG_DEBUG, "no uidl file '%s' found\n", filename);
  47.299 +		ok = TRUE;
  47.300 +	}
  47.301  
  47.302 -  g_free(filename);
  47.303 -  return ok; /* return code is irrelevant, do not check... */
  47.304 +	g_free(filename);
  47.305 +	return ok;  /* return code is irrelevant, do not check... */
  47.306  }
  47.307  
  47.308 -static
  47.309 -gboolean read_response(pop3_base *popb, int timeout)
  47.310 +static gboolean
  47.311 +read_response(pop3_base * popb, int timeout)
  47.312  {
  47.313 -  gint len;
  47.314 +	gint len;
  47.315  
  47.316 -  len = read_sockline(popb->in, popb->buffer, POP3_BUF_LEN, timeout, READSOCKL_CHUG);
  47.317 +	len = read_sockline(popb->in, popb->buffer, POP3_BUF_LEN, timeout, READSOCKL_CHUG);
  47.318  
  47.319 -  if(len == -3){
  47.320 -    popb->error = pop3_timeout;
  47.321 -    return FALSE;
  47.322 -  }
  47.323 -  else if(len == -2){
  47.324 -    popb->error = pop3_syntax;
  47.325 -    return FALSE;
  47.326 -  }
  47.327 -  else if(len == -1){
  47.328 -    popb->error = pop3_eof;
  47.329 -    return FALSE;
  47.330 -  }
  47.331 -  
  47.332 -  return TRUE;
  47.333 +	if (len == -3) {
  47.334 +		popb->error = pop3_timeout;
  47.335 +		return FALSE;
  47.336 +	} else if (len == -2) {
  47.337 +		popb->error = pop3_syntax;
  47.338 +		return FALSE;
  47.339 +	} else if (len == -1) {
  47.340 +		popb->error = pop3_eof;
  47.341 +		return FALSE;
  47.342 +	}
  47.343 +
  47.344 +	return TRUE;
  47.345  }
  47.346  
  47.347 -static
  47.348 -gboolean check_response(pop3_base *popb)
  47.349 +static gboolean
  47.350 +check_response(pop3_base * popb)
  47.351  {
  47.352 -  char c = popb->buffer[0];
  47.353 +	char c = popb->buffer[0];
  47.354  
  47.355 -  if(c == '+'){
  47.356 -    popb->error = pop3_ok;
  47.357 -    return TRUE;
  47.358 -  }else if(c == '-')
  47.359 -    popb->error = pop3_fail;
  47.360 -  else
  47.361 -    popb->error = pop3_syntax;
  47.362 -  return FALSE;
  47.363 +	if (c == '+') {
  47.364 +		popb->error = pop3_ok;
  47.365 +		return TRUE;
  47.366 +	} else if (c == '-')
  47.367 +		popb->error = pop3_fail;
  47.368 +	else
  47.369 +		popb->error = pop3_syntax;
  47.370 +	return FALSE;
  47.371  }
  47.372  
  47.373 -static
  47.374 -gboolean strtoi(gchar *p, gchar **pend, gint *val)
  47.375 +static gboolean
  47.376 +strtoi(gchar * p, gchar ** pend, gint * val)
  47.377  {
  47.378 -  gchar buf[12];
  47.379 -  gint i = 0;
  47.380 +	gchar buf[12];
  47.381 +	gint i = 0;
  47.382  
  47.383 -  while(*p && isspace(*p)) p++;
  47.384 -  if(*p){
  47.385 -    while((i < 11) && isdigit(*p))
  47.386 -      buf[i++] = *(p++);
  47.387 -    buf[i] = 0;
  47.388 -    *val = atoi(buf);
  47.389 -    *pend = p;
  47.390 -    return TRUE;
  47.391 -  }
  47.392 -  return FALSE;
  47.393 +	while (*p && isspace(*p))
  47.394 +		p++;
  47.395 +	if (*p) {
  47.396 +		while ((i < 11) && isdigit(*p))
  47.397 +			buf[i++] = *(p++);
  47.398 +		buf[i] = 0;
  47.399 +		*val = atoi(buf);
  47.400 +		*pend = p;
  47.401 +		return TRUE;
  47.402 +	}
  47.403 +	return FALSE;
  47.404  }
  47.405  
  47.406 -static
  47.407 -gboolean check_response_int_int(pop3_base *popb, gint *arg0, gint *arg1)
  47.408 +static gboolean
  47.409 +check_response_int_int(pop3_base * popb, gint * arg0, gint * arg1)
  47.410  {
  47.411 -  if(check_response(popb)){
  47.412 -    gchar *p = &(popb->buffer[3]);
  47.413 -    gchar *pe;
  47.414 +	if (check_response(popb)) {
  47.415 +		gchar *p = &(popb->buffer[3]);
  47.416 +		gchar *pe;
  47.417  
  47.418 -    if(strtoi(p, &pe, arg0)){
  47.419 -      DEBUG(5) debugf("arg0 = %d\n", *arg0);
  47.420 -      p = pe;
  47.421 -      if(strtoi(p, &pe, arg1))
  47.422 -	DEBUG(5) debugf("arg1 = %d\n", *arg1);
  47.423 -	return TRUE;
  47.424 -    }
  47.425 -    popb->error = pop3_syntax;
  47.426 -  }
  47.427 -  return FALSE;
  47.428 +		if (strtoi(p, &pe, arg0)) {
  47.429 +			DEBUG(5) debugf("arg0 = %d\n", *arg0);
  47.430 +			p = pe;
  47.431 +			if (strtoi(p, &pe, arg1))
  47.432 +				DEBUG(5) debugf("arg1 = %d\n", *arg1);
  47.433 +			return TRUE;
  47.434 +		}
  47.435 +		popb->error = pop3_syntax;
  47.436 +	}
  47.437 +	return FALSE;
  47.438  }
  47.439  
  47.440 -static
  47.441 -gboolean get_drop_listing(pop3_base *popb)
  47.442 +static gboolean
  47.443 +get_drop_listing(pop3_base * popb)
  47.444  {
  47.445 -  gchar buf[64];
  47.446 +	gchar buf[64];
  47.447  
  47.448 -  DEBUG(5) debugf("get_drop_listing() entered\n");
  47.449 +	DEBUG(5) debugf("get_drop_listing() entered\n");
  47.450  
  47.451 -  while(1){
  47.452 -    gint len = read_sockline(popb->in, buf, 64, POP3_CMD_TIMEOUT, READSOCKL_CHUG);
  47.453 -    if(len > 0){
  47.454 -      if(buf[0] == '.')
  47.455 -	return TRUE;
  47.456 -      else{
  47.457 -	gint number, msg_size;
  47.458 -	gchar *p = buf, *pe;
  47.459 -	if(strtoi(p, &pe, &number)){
  47.460 -	  p = pe;
  47.461 -	  if(strtoi(p, &pe, &msg_size)){
  47.462 -	    msg_info *info = g_malloc(sizeof(msg_info));
  47.463 -	    info->number = number;
  47.464 -	    info->size = msg_size;
  47.465 +	while (1) {
  47.466 +		gint len = read_sockline(popb->in, buf, 64, POP3_CMD_TIMEOUT, READSOCKL_CHUG);
  47.467 +		if (len > 0) {
  47.468 +			if (buf[0] == '.')
  47.469 +				return TRUE;
  47.470 +			else {
  47.471 +				gint number, msg_size;
  47.472 +				gchar *p = buf, *pe;
  47.473 +				if (strtoi(p, &pe, &number)) {
  47.474 +					p = pe;
  47.475 +					if (strtoi(p, &pe, &msg_size)) {
  47.476 +						msg_info *info = g_malloc(sizeof(msg_info));
  47.477 +						info->number = number;
  47.478 +						info->size = msg_size;
  47.479  
  47.480 -	    DEBUG(5) debugf("get_drop_listing(), number = %d, msg_size = %d\n", number, msg_size);
  47.481 +						DEBUG(5) debugf ("get_drop_listing(), number = %d, msg_size = %d\n", number, msg_size);
  47.482  
  47.483 -	    info->uid = NULL;
  47.484 -	    info->is_fetched = FALSE;
  47.485 -	    info->is_in_uidl = FALSE;
  47.486 -	    popb->drop_list = g_list_append(popb->drop_list, info);
  47.487 -	  }else{
  47.488 -	    popb->error = pop3_syntax;
  47.489 -	    break;
  47.490 -	  }
  47.491 -	}else{
  47.492 -	  popb->error = pop3_syntax;
  47.493 -	  break;
  47.494 +						info->uid = NULL;
  47.495 +						info->is_fetched = FALSE;
  47.496 +						info->is_in_uidl = FALSE;
  47.497 +						popb->drop_list = g_list_append(popb->drop_list, info);
  47.498 +					} else {
  47.499 +						popb->error = pop3_syntax;
  47.500 +						break;
  47.501 +					}
  47.502 +				} else {
  47.503 +					popb->error = pop3_syntax;
  47.504 +					break;
  47.505 +				}
  47.506 +			}
  47.507 +		} else {
  47.508 +			popb->error = (len == -1) ? pop3_eof : pop3_timeout;
  47.509 +			return FALSE;
  47.510 +		}
  47.511  	}
  47.512 -      }
  47.513 -    }else{
  47.514 -      popb->error = (len == -1) ? pop3_eof : pop3_timeout;
  47.515 -      return FALSE;
  47.516 -    }
  47.517 -  }
  47.518 -  return FALSE;
  47.519 +	return FALSE;
  47.520  }
  47.521  
  47.522 -static
  47.523 -gboolean get_uid_listing(pop3_base *popb)
  47.524 +static gboolean
  47.525 +get_uid_listing(pop3_base * popb)
  47.526  {
  47.527 -  gchar buf[64];
  47.528 +	gchar buf[64];
  47.529  
  47.530 -  while(1){
  47.531 -    gint len = read_sockline(popb->in, buf, 64, POP3_CMD_TIMEOUT, READSOCKL_CHUG);
  47.532 -    if(len > 0){
  47.533 -      if(buf[0] == '.')
  47.534 -	return TRUE;
  47.535 -      else{
  47.536 -	gint number;
  47.537 -	gchar *p = buf, *pe;
  47.538 -	if(strtoi(p, &pe, &number)){
  47.539 -	  msg_info *info = NULL;
  47.540 -	  GList *drop_node;
  47.541 +	while (1) {
  47.542 +		gint len = read_sockline(popb->in, buf, 64, POP3_CMD_TIMEOUT, READSOCKL_CHUG);
  47.543 +		if (len > 0) {
  47.544 +			if (buf[0] == '.')
  47.545 +				return TRUE;
  47.546 +			else {
  47.547 +				gint number;
  47.548 +				gchar *p = buf, *pe;
  47.549 +				if (strtoi(p, &pe, &number)) {
  47.550 +					msg_info *info = NULL;
  47.551 +					GList *drop_node;
  47.552  
  47.553 -	  p = pe;
  47.554 -	  while(*p && isspace(*p)) p++;
  47.555 +					p = pe;
  47.556 +					while (*p && isspace(*p))
  47.557 +						p++;
  47.558  
  47.559 -	  foreach(popb->drop_list, drop_node){
  47.560 -	    msg_info *curr_info = (msg_info *)(drop_node->data);
  47.561 -	    if(curr_info->number == number){
  47.562 -	      info = curr_info;
  47.563 -	      break;
  47.564 -	    }
  47.565 -	  }
  47.566 -	  if(info){
  47.567 -	    info->uid = g_strdup(p);
  47.568 -	    g_strchomp(info->uid);
  47.569 -	  }
  47.570 +					foreach(popb->drop_list, drop_node) {
  47.571 +						msg_info *curr_info = (msg_info *) (drop_node->data);
  47.572 +						if (curr_info->number == number) {
  47.573 +							info = curr_info;
  47.574 +							break;
  47.575 +						}
  47.576 +					}
  47.577 +					if (info) {
  47.578 +						info->uid = g_strdup(p);
  47.579 +						g_strchomp(info->uid);
  47.580 +					}
  47.581  
  47.582 -	}else{
  47.583 -	  popb->error = pop3_syntax;
  47.584 -	  break;
  47.585 +				} else {
  47.586 +					popb->error = pop3_syntax;
  47.587 +					break;
  47.588 +				}
  47.589 +			}
  47.590 +		}
  47.591  	}
  47.592 -      }
  47.593 -    }
  47.594 -  }
  47.595 -  return FALSE;
  47.596 +	return FALSE;
  47.597  }
  47.598  
  47.599 -static
  47.600 -gboolean check_init_response(pop3_base *popb)
  47.601 +static gboolean
  47.602 +check_init_response(pop3_base * popb)
  47.603  {
  47.604 -  if(check_response(popb)){
  47.605 -    gchar buf[256];
  47.606 -    gchar *p = popb->buffer;
  47.607 -    gint i = 0;
  47.608 -    if(*p){
  47.609 -      while(*p && (*p != '<')) p++;
  47.610 -      while(*p && (*p != '>') && (i < 254))
  47.611 -	buf[i++] = *(p++);
  47.612 -      buf[i++] = '>';
  47.613 -      buf[i] = 0;
  47.614 +	if (check_response(popb)) {
  47.615 +		gchar buf[256];
  47.616 +		gchar *p = popb->buffer;
  47.617 +		gint i = 0;
  47.618 +		if (*p) {
  47.619 +			while (*p && (*p != '<'))
  47.620 +				p++;
  47.621 +			while (*p && (*p != '>') && (i < 254))
  47.622 +				buf[i++] = *(p++);
  47.623 +			buf[i++] = '>';
  47.624 +			buf[i] = 0;
  47.625  
  47.626 -      popb->timestamp = g_strdup(buf);
  47.627 +			popb->timestamp = g_strdup(buf);
  47.628  
  47.629 -      return TRUE;
  47.630 -    }
  47.631 -  }
  47.632 -  return FALSE;
  47.633 +			return TRUE;
  47.634 +		}
  47.635 +	}
  47.636 +	return FALSE;
  47.637  }
  47.638  
  47.639 -void pop3_in_close(pop3_base *popb)
  47.640 +void
  47.641 +pop3_in_close(pop3_base * popb)
  47.642  {
  47.643 -  GList *node;
  47.644 +	GList *node;
  47.645  
  47.646 -  fclose(popb->in);
  47.647 -  fclose(popb->out);
  47.648 +	fclose(popb->in);
  47.649 +	fclose(popb->out);
  47.650  
  47.651 -  close(popb->sock);
  47.652 +	close(popb->sock);
  47.653  
  47.654 -  foreach(popb->list_uid_old, node){
  47.655 -    gchar *uid = (gchar *)(node->data);
  47.656 -    g_free(uid);
  47.657 -  }
  47.658 -  g_list_free(popb->list_uid_old);
  47.659 +	foreach(popb->list_uid_old, node) {
  47.660 +		gchar *uid = (gchar *) (node->data);
  47.661 +		g_free(uid);
  47.662 +	}
  47.663 +	g_list_free(popb->list_uid_old);
  47.664  
  47.665 -  foreach(popb->drop_list, node){
  47.666 -    msg_info *info = (msg_info *)(node->data);
  47.667 -    if(info->uid) g_free(info->uid);
  47.668 -    g_free(info);
  47.669 -  }
  47.670 -  g_list_free(popb->drop_list);
  47.671 +	foreach(popb->drop_list, node) {
  47.672 +		msg_info *info = (msg_info *) (node->data);
  47.673 +		if (info->uid)
  47.674 +			g_free(info->uid);
  47.675 +		g_free(info);
  47.676 +	}
  47.677 +	g_list_free(popb->drop_list);
  47.678  
  47.679 -  if(popb->buffer) g_free(popb->buffer);
  47.680 -  if(popb->timestamp) g_free(popb->timestamp);
  47.681 +	if (popb->buffer)
  47.682 +		g_free(popb->buffer);
  47.683 +	if (popb->timestamp)
  47.684 +		g_free(popb->timestamp);
  47.685  }
  47.686  
  47.687 -pop3_base *pop3_in_open(gchar *host, gint port, GList *resolve_list, guint flags)
  47.688 +pop3_base*
  47.689 +pop3_in_open(gchar * host, gint port, GList * resolve_list, guint flags)
  47.690  {
  47.691 -  pop3_base *popb;
  47.692 -  gint sock;
  47.693 -  mxip_addr *addr;
  47.694 +	pop3_base *popb;
  47.695 +	gint sock;
  47.696 +	mxip_addr *addr;
  47.697  
  47.698 -  DEBUG(5) debugf("pop3_in_open entered, host = %s\n", host);
  47.699 +	DEBUG(5) debugf("pop3_in_open entered, host = %s\n", host);
  47.700  
  47.701 -  if((addr = connect_resolvelist(&sock, host, port, resolve_list))){
  47.702 -    /* create structure to hold status data: */
  47.703 -    popb = create_pop3base(sock, flags);
  47.704 -    popb->remote_host = addr->name;
  47.705 +	if ((addr = connect_resolvelist(&sock, host, port, resolve_list))) {
  47.706 +		/* create structure to hold status data: */
  47.707 +		popb = create_pop3base(sock, flags);
  47.708 +		popb->remote_host = addr->name;
  47.709  
  47.710 -    DEBUG(5){
  47.711 -      struct sockaddr_in name;
  47.712 -      int len;
  47.713 -      getsockname(sock, (struct sockaddr *)(&name), &len);
  47.714 -      debugf("socket: name.sin_addr = %s\n", inet_ntoa(name.sin_addr));
  47.715 -    }
  47.716 -    return popb;
  47.717 -  }
  47.718 -  return NULL;
  47.719 +		DEBUG(5) {
  47.720 +			struct sockaddr_in name;
  47.721 +			int len;
  47.722 +			getsockname(sock, (struct sockaddr *) (&name), &len);
  47.723 +			debugf("socket: name.sin_addr = %s\n", inet_ntoa(name.sin_addr));
  47.724 +		}
  47.725 +		return popb;
  47.726 +	}
  47.727 +	return NULL;
  47.728  }
  47.729  
  47.730 -pop3_base *pop3_in_open_child(gchar *cmd, guint flags)
  47.731 +pop3_base*
  47.732 +pop3_in_open_child(gchar * cmd, guint flags)
  47.733  {
  47.734 -  pop3_base *popb;
  47.735 -  gint sock;
  47.736 +	pop3_base *popb;
  47.737 +	gint sock;
  47.738  
  47.739 -  DEBUG(5) debugf("pop3_in_open_child entered, cmd = %s\n", cmd);
  47.740 +	DEBUG(5) debugf("pop3_in_open_child entered, cmd = %s\n", cmd);
  47.741  
  47.742 -  sock = child(cmd);
  47.743 +	sock = child(cmd);
  47.744  
  47.745 -  if(sock > 0){
  47.746 +	if (sock > 0) {
  47.747  
  47.748 -    popb = create_pop3base(sock, flags);
  47.749 -    popb->remote_host = NULL;
  47.750 +		popb = create_pop3base(sock, flags);
  47.751 +		popb->remote_host = NULL;
  47.752  
  47.753 -    return popb;
  47.754 -  }
  47.755 -  logwrite(LOG_ALERT, "child failed (sock = %d): %s\n", sock, strerror(errno));
  47.756 +		return popb;
  47.757 +	}
  47.758 +	logwrite(LOG_ALERT, "child failed (sock = %d): %s\n", sock, strerror(errno));
  47.759  
  47.760 -  return NULL;
  47.761 +	return NULL;
  47.762  }
  47.763  
  47.764 -gboolean pop3_in_init(pop3_base *popb)
  47.765 +gboolean
  47.766 +pop3_in_init(pop3_base * popb)
  47.767  {
  47.768 -  gboolean ok;
  47.769 +	gboolean ok;
  47.770  
  47.771 -  if((ok = read_response(popb, POP3_INITIAL_TIMEOUT))){
  47.772 -    ok = check_init_response(popb);
  47.773 -  }
  47.774 -  if(!ok)
  47.775 -    /*    pop3_in_log_failure(popb, NULL);*/
  47.776 -    logwrite(LOG_ALERT, "pop3 failed\n");
  47.777 -  return ok;
  47.778 +	if ((ok = read_response(popb, POP3_INITIAL_TIMEOUT))) {
  47.779 +		ok = check_init_response(popb);
  47.780 +	}
  47.781 +	if (!ok)
  47.782 +		/* pop3_in_log_failure(popb, NULL); */
  47.783 +		logwrite(LOG_ALERT, "pop3 failed\n");
  47.784 +	return ok;
  47.785  }
  47.786  
  47.787 -gboolean pop3_in_login(pop3_base *popb, gchar *user, gchar *pass)
  47.788 +gboolean
  47.789 +pop3_in_login(pop3_base * popb, gchar * user, gchar * pass)
  47.790  {
  47.791 -  if(popb->flags & POP3_FLAG_APOP){
  47.792 +	if (popb->flags & POP3_FLAG_APOP) {
  47.793  
  47.794 -    gchar *string = g_strdup_printf("%s%s", popb->timestamp, pass);
  47.795 -    gchar *digest = MD5String(string);
  47.796 -    pop3_printf(popb->out, "APOP %s %s\r\n", user, digest);
  47.797 -    g_free(string);
  47.798 -    g_free(digest);
  47.799 -    if(read_response(popb, POP3_CMD_TIMEOUT)){
  47.800 -      if(check_response(popb))
  47.801 -	return TRUE;
  47.802 -      else
  47.803 -	popb->error = pop3_login_failure;
  47.804 -    }
  47.805 +		gchar *string = g_strdup_printf("%s%s", popb->timestamp, pass);
  47.806 +		gchar *digest = MD5String(string);
  47.807 +		pop3_printf(popb->out, "APOP %s %s\r\n", user, digest);
  47.808 +		g_free(string);
  47.809 +		g_free(digest);
  47.810 +		if (read_response(popb, POP3_CMD_TIMEOUT)) {
  47.811 +			if (check_response(popb))
  47.812 +				return TRUE;
  47.813 +			else
  47.814 +				popb->error = pop3_login_failure;
  47.815 +		}
  47.816  
  47.817 -  }else{
  47.818 +	} else {
  47.819  
  47.820 -    pop3_printf(popb->out, "USER %s\r\n", user);
  47.821 -    if(read_response(popb, POP3_CMD_TIMEOUT)){
  47.822 -      if(check_response(popb)){
  47.823 -	pop3_printf(popb->out, "PASS %s\r\n", pass);
  47.824 -	if(read_response(popb, POP3_CMD_TIMEOUT)){
  47.825 -	  if(check_response(popb))
  47.826 -	    return TRUE;
  47.827 -	  else
  47.828 -	    popb->error = pop3_login_failure;
  47.829 +		pop3_printf(popb->out, "USER %s\r\n", user);
  47.830 +		if (read_response(popb, POP3_CMD_TIMEOUT)) {
  47.831 +			if (check_response(popb)) {
  47.832 +				pop3_printf(popb->out, "PASS %s\r\n", pass);
  47.833 +				if (read_response(popb, POP3_CMD_TIMEOUT)) {
  47.834 +					if (check_response(popb))
  47.835 +						return TRUE;
  47.836 +					else
  47.837 +						popb->error = pop3_login_failure;
  47.838 +				}
  47.839 +			} else {
  47.840 +				popb->error = pop3_login_failure;
  47.841 +			}
  47.842 +		}
  47.843  	}
  47.844 -      }else{
  47.845 -	popb->error = pop3_login_failure;
  47.846 -      }
  47.847 -    }
  47.848 -  }
  47.849 -  return FALSE;
  47.850 +	return FALSE;
  47.851  }
  47.852  
  47.853 -gboolean pop3_in_stat(pop3_base *popb)
  47.854 +gboolean
  47.855 +pop3_in_stat(pop3_base * popb)
  47.856  {
  47.857 -  pop3_printf(popb->out, "STAT\r\n");
  47.858 -  if(read_response(popb, POP3_CMD_TIMEOUT)){
  47.859 -    gint msg_cnt, mbox_size;
  47.860 -    if(check_response_int_int(popb, &msg_cnt, &mbox_size)){
  47.861 -      popb->msg_cnt = msg_cnt;
  47.862 -      popb->mbox_size = mbox_size;
  47.863 +	pop3_printf(popb->out, "STAT\r\n");
  47.864 +	if (read_response(popb, POP3_CMD_TIMEOUT)) {
  47.865 +		gint msg_cnt, mbox_size;
  47.866 +		if (check_response_int_int(popb, &msg_cnt, &mbox_size)) {
  47.867 +			popb->msg_cnt = msg_cnt;
  47.868 +			popb->mbox_size = mbox_size;
  47.869  
  47.870 -      return TRUE;
  47.871 -    }
  47.872 -  }
  47.873 -  return FALSE;
  47.874 +			return TRUE;
  47.875 +		}
  47.876 +	}
  47.877 +	return FALSE;
  47.878  }
  47.879  
  47.880 -gboolean pop3_in_list(pop3_base *popb)
  47.881 +gboolean
  47.882 +pop3_in_list(pop3_base * popb)
  47.883  {
  47.884 -  pop3_printf(popb->out, "LIST\r\n");
  47.885 -  if(read_response(popb, POP3_CMD_TIMEOUT)){
  47.886 -    if(get_drop_listing(popb)){
  47.887 -      return TRUE;
  47.888 -    }
  47.889 -  }
  47.890 -  return FALSE;
  47.891 +	pop3_printf(popb->out, "LIST\r\n");
  47.892 +	if (read_response(popb, POP3_CMD_TIMEOUT)) {
  47.893 +		if (get_drop_listing(popb)) {
  47.894 +			return TRUE;
  47.895 +		}
  47.896 +	}
  47.897 +	return FALSE;
  47.898  }
  47.899  
  47.900 -gboolean pop3_in_dele(pop3_base *popb, gint number)
  47.901 +gboolean
  47.902 +pop3_in_dele(pop3_base * popb, gint number)
  47.903  {
  47.904 -  pop3_printf(popb->out, "DELE %d\r\n", number);
  47.905 -  if(read_response(popb, POP3_CMD_TIMEOUT)){
  47.906 -    return TRUE;
  47.907 -  }
  47.908 -  return FALSE;
  47.909 +	pop3_printf(popb->out, "DELE %d\r\n", number);
  47.910 +	if (read_response(popb, POP3_CMD_TIMEOUT)) {
  47.911 +		return TRUE;
  47.912 +	}
  47.913 +	return FALSE;
  47.914  }
  47.915  
  47.916 -message *pop3_in_retr(pop3_base *popb, gint number, address *rcpt)
  47.917 +message*
  47.918 +pop3_in_retr(pop3_base * popb, gint number, address * rcpt)
  47.919  {
  47.920 -  accept_error err;
  47.921 +	accept_error err;
  47.922  
  47.923 -  pop3_printf(popb->out, "RETR %d\r\n", number);
  47.924 -  if(read_response(popb, POP3_CMD_TIMEOUT)){
  47.925 -    message *msg = create_message();
  47.926 -    msg->received_host = popb->remote_host;
  47.927 -    msg->received_prot = (popb->flags & POP3_FLAG_APOP) ? PROT_APOP : PROT_POP3;
  47.928 -    msg->transfer_id = (popb->next_id)++;
  47.929 -    msg->rcpt_list = g_list_append(NULL, copy_address(rcpt));
  47.930 +	pop3_printf(popb->out, "RETR %d\r\n", number);
  47.931 +	if (read_response(popb, POP3_CMD_TIMEOUT)) {
  47.932 +		message *msg = create_message();
  47.933 +		msg->received_host = popb->remote_host;
  47.934 +		msg->received_prot = (popb->flags & POP3_FLAG_APOP) ? PROT_APOP : PROT_POP3;
  47.935 +		msg->transfer_id = (popb->next_id)++;
  47.936 +		msg->rcpt_list = g_list_append(NULL, copy_address(rcpt));
  47.937  
  47.938 -    if((err = accept_message(popb->in, msg,
  47.939 -			     ACC_MAIL_FROM_HEAD|(conf.do_save_envelope_to ? ACC_SAVE_ENVELOPE_TO : 0)))
  47.940 -       == AERR_OK)
  47.941 -      return msg;
  47.942 +		if ((err = accept_message(popb->in, msg, ACC_MAIL_FROM_HEAD
  47.943 +		    | (conf.do_save_envelope_to ? ACC_SAVE_ENVELOPE_TO : 0)))
  47.944 +		    == AERR_OK)
  47.945 +			return msg;
  47.946  
  47.947 -    destroy_message(msg);
  47.948 -  }
  47.949 -  return NULL;
  47.950 -}  
  47.951 -
  47.952 -gboolean pop3_in_uidl(pop3_base *popb)
  47.953 -{
  47.954 -  pop3_printf(popb->out, "UIDL\r\n");
  47.955 -  if(read_response(popb, POP3_CMD_TIMEOUT)){
  47.956 -    if(get_uid_listing(popb)){
  47.957 -      return TRUE;
  47.958 -    }
  47.959 -  }
  47.960 -  return FALSE;
  47.961 +		destroy_message(msg);
  47.962 +	}
  47.963 +	return NULL;
  47.964  }
  47.965  
  47.966 -gboolean pop3_in_quit(pop3_base *popb)
  47.967 +gboolean
  47.968 +pop3_in_uidl(pop3_base * popb)
  47.969  {
  47.970 -  pop3_printf(popb->out, "QUIT\r\n");
  47.971 -  
  47.972 -  DEBUG(4) debugf("QUIT\n");
  47.973 +	pop3_printf(popb->out, "UIDL\r\n");
  47.974 +	if (read_response(popb, POP3_CMD_TIMEOUT)) {
  47.975 +		if (get_uid_listing(popb)) {
  47.976 +			return TRUE;
  47.977 +		}
  47.978 +	}
  47.979 +	return FALSE;
  47.980 +}
  47.981  
  47.982 -  signal(SIGALRM, SIG_DFL);
  47.983 +gboolean
  47.984 +pop3_in_quit(pop3_base * popb)
  47.985 +{
  47.986 +	pop3_printf(popb->out, "QUIT\r\n");
  47.987  
  47.988 -  return TRUE;
  47.989 +	DEBUG(4) debugf("QUIT\n");
  47.990 +
  47.991 +	signal(SIGALRM, SIG_DFL);
  47.992 +
  47.993 +	return TRUE;
  47.994  }
  47.995  
  47.996  /* Send a DELE command for each message in (the old) uid listing.
  47.997     This is to prevent mail from to be kept on server, if a previous
  47.998     transaction was interupted. */
  47.999 -gboolean pop3_in_uidl_dele(pop3_base *popb)
 47.1000 +gboolean
 47.1001 +pop3_in_uidl_dele(pop3_base * popb)
 47.1002  {
 47.1003 -  GList *drop_node;
 47.1004 +	GList *drop_node;
 47.1005  
 47.1006 -  foreach(popb->drop_list, drop_node){
 47.1007 -    msg_info *info = (msg_info *)(drop_node->data);
 47.1008 -    /*    if(find_uid(popb, info->uid)){*/
 47.1009 -    if(info->is_in_uidl){
 47.1010 -      if(!pop3_in_dele(popb, info->number))
 47.1011 -	return FALSE;
 47.1012 -      /* TODO: it probably makes sense to also
 47.1013 -	 delete this uid from the listing */
 47.1014 -    }
 47.1015 -  }
 47.1016 -  return TRUE;
 47.1017 +	foreach(popb->drop_list, drop_node) {
 47.1018 +		msg_info *info = (msg_info *) (drop_node->data);
 47.1019 +		/* if(find_uid(popb, info->uid)){ */
 47.1020 +		if (info->is_in_uidl) {
 47.1021 +			if (!pop3_in_dele(popb, info->number))
 47.1022 +				return FALSE;
 47.1023 +			/* TODO: it probably makes sense to also delete this uid from the listing */
 47.1024 +		}
 47.1025 +	}
 47.1026 +	return TRUE;
 47.1027  }
 47.1028  
 47.1029 -gboolean pop3_get(pop3_base *popb,
 47.1030 -		  gchar *user, gchar *pass, address *rcpt, address *return_path,
 47.1031 -		  gint max_count, gint max_size, gboolean max_size_delete)
 47.1032 +gboolean
 47.1033 +pop3_get(pop3_base * popb, gchar * user, gchar * pass, address * rcpt, address * return_path, gint max_count, gint max_size, gboolean max_size_delete)
 47.1034  {
 47.1035 -  gboolean ok = FALSE;
 47.1036 -  gint num_children = 0;
 47.1037 -  
 47.1038 -  DEBUG(5) debugf("rcpt = %s@%s\n", rcpt->local_part, rcpt->domain);
 47.1039 +	gboolean ok = FALSE;
 47.1040 +	gint num_children = 0;
 47.1041  
 47.1042 -  signal(SIGCHLD, SIG_DFL);
 47.1043 +	DEBUG(5) debugf("rcpt = %s@%s\n", rcpt->local_part, rcpt->domain);
 47.1044  
 47.1045 -  if(pop3_in_init(popb)){
 47.1046 -    if(pop3_in_login(popb, user, pass)){
 47.1047 -      if(pop3_in_stat(popb)){
 47.1048 -	if(popb->msg_cnt > 0){
 47.1049 +	signal(SIGCHLD, SIG_DFL);
 47.1050  
 47.1051 -	  logwrite(LOG_NOTICE|LOG_VERBOSE, "%d message(s) for user %s at %s\n",
 47.1052 -		   popb->msg_cnt, user, popb->remote_host);
 47.1053 +	if (pop3_in_init(popb)) {
 47.1054 +		if (pop3_in_login(popb, user, pass)) {
 47.1055 +			if (pop3_in_stat(popb)) {
 47.1056 +				if (popb->msg_cnt > 0) {
 47.1057  
 47.1058 -	  if(pop3_in_list(popb)){
 47.1059 -	    gboolean do_get = !(popb->flags & POP3_FLAG_UIDL);
 47.1060 -	    if(!do_get) do_get = pop3_in_uidl(popb);
 47.1061 -	    if(do_get){
 47.1062 -	      gint count = 0;
 47.1063 -	      GList *drop_node;
 47.1064 +					logwrite(LOG_NOTICE | LOG_VERBOSE, "%d message(s) for user %s at %s\n", popb->msg_cnt, user, popb->remote_host);
 47.1065  
 47.1066 -	      if(popb->flags & POP3_FLAG_UIDL){
 47.1067 -		read_uidl(popb, user);
 47.1068 -		logwrite(LOG_VERBOSE|LOG_NOTICE, "%d message(s) already in uidl.\n",
 47.1069 -			 popb->uidl_known_cnt);
 47.1070 -	      }
 47.1071 -	      if((popb->flags & POP3_FLAG_UIDL) && (popb->flags & POP3_FLAG_UIDL_DELE))
 47.1072 -		pop3_in_uidl_dele(popb);
 47.1073 +					if (pop3_in_list(popb)) {
 47.1074 +						gboolean do_get = !(popb->flags & POP3_FLAG_UIDL);
 47.1075 +						if (!do_get)
 47.1076 +							do_get = pop3_in_uidl(popb);
 47.1077 +						if (do_get) {
 47.1078 +							gint count = 0;
 47.1079 +							GList *drop_node;
 47.1080  
 47.1081 -	      foreach(popb->drop_list, drop_node){
 47.1082 +							if (popb->flags & POP3_FLAG_UIDL) {
 47.1083 +								read_uidl(popb, user);
 47.1084 +								logwrite(LOG_VERBOSE | LOG_NOTICE, "%d message(s) already in uidl.\n", popb->uidl_known_cnt);
 47.1085 +							}
 47.1086 +							if ((popb->flags & POP3_FLAG_UIDL) && (popb->flags & POP3_FLAG_UIDL_DELE))
 47.1087 +								pop3_in_uidl_dele(popb);
 47.1088  
 47.1089 -		msg_info *info = (msg_info *)(drop_node->data);
 47.1090 -		gboolean do_get_this = !(popb->flags & POP3_FLAG_UIDL);
 47.1091 -		/*		if(!do_get_this) do_get_this = !find_uid(popb, info->uid);*/
 47.1092 -		if(!do_get_this) do_get_this = !(info->is_in_uidl);
 47.1093 -		if(do_get_this){
 47.1094 +							foreach(popb->drop_list, drop_node) {
 47.1095  
 47.1096 -		  if((info->size < max_size) || (max_size == 0)){
 47.1097 -		    message *msg;
 47.1098 +								msg_info *info = (msg_info *) (drop_node->data);
 47.1099 +								gboolean do_get_this = !(popb->flags & POP3_FLAG_UIDL);
 47.1100 +								/* if(!do_get_this) do_get_this = !find_uid(popb, info->uid); */
 47.1101 +								if (!do_get_this)
 47.1102 +									do_get_this = !(info->is_in_uidl);
 47.1103 +								if (do_get_this) {
 47.1104  
 47.1105 -		    logwrite(LOG_VERBOSE|LOG_NOTICE, "receiving message %d\n", info->number);
 47.1106 -		    msg = pop3_in_retr(popb, info->number, rcpt);
 47.1107 +									if ((info->size < max_size) || (max_size == 0)) {
 47.1108 +										message *msg;
 47.1109  
 47.1110 -		    if(msg){
 47.1111 -		      if(return_path)
 47.1112 -			msg->return_path = copy_address(return_path);
 47.1113 -		      if(spool_write(msg, TRUE)){
 47.1114 -			pid_t pid;
 47.1115 -			logwrite(LOG_NOTICE, "%s <= %s host=%s with %s\n",
 47.1116 -				 msg->uid,
 47.1117 -				 addr_string(msg->return_path),
 47.1118 -				 popb->remote_host,
 47.1119 -				 (popb->flags & POP3_FLAG_APOP) ?
 47.1120 -				 prot_names[PROT_APOP] : prot_names[PROT_POP3]
 47.1121 -				 );
 47.1122 -			info->is_fetched = TRUE;
 47.1123 -			count++;
 47.1124 +										logwrite(LOG_VERBOSE | LOG_NOTICE, "receiving message %d\n", info->number);
 47.1125 +										msg = pop3_in_retr(popb, info->number, rcpt);
 47.1126 +
 47.1127 +										if (msg) {
 47.1128 +											if (return_path)
 47.1129 +												msg->return_path = copy_address(return_path);
 47.1130 +											if (spool_write(msg, TRUE)) {
 47.1131 +												pid_t pid;
 47.1132 +												logwrite(LOG_NOTICE, "%s <= %s host=%s with %s\n", msg->uid,
 47.1133 +												         addr_string(msg->return_path), popb->remote_host,
 47.1134 +												         (popb->flags & POP3_FLAG_APOP) ? prot_names [PROT_APOP] : prot_names [PROT_POP3]);
 47.1135 +												info->is_fetched = TRUE;
 47.1136 +												count++;
 47.1137  #if DO_WRITE_UIDL_EARLY
 47.1138 -			if(popb->flags & POP3_FLAG_UIDL) write_uidl(popb, user);
 47.1139 +												if (popb->flags & POP3_FLAG_UIDL)
 47.1140 +													write_uidl(popb, user);
 47.1141  #endif
 47.1142 -			if(!conf.do_queue){
 47.1143 +												if (!conf.do_queue) {
 47.1144  
 47.1145 -			  /* wait for child processes. If there are too many,
 47.1146 -			     we wait blocking, before we fork another one */
 47.1147 -			  while(num_children > 0){
 47.1148 -			    int status, options = WNOHANG;
 47.1149 -			    pid_t pid;
 47.1150 +													/* wait for child processes. If there are too many, we wait blocking, before we fork another one */
 47.1151 +													while (num_children > 0) {
 47.1152 +														int status, options = WNOHANG;
 47.1153 +														pid_t pid;
 47.1154  
 47.1155 -			    if(num_children >= POP3_MAX_CHILDREN){
 47.1156 -			      logwrite(LOG_NOTICE, "too many children - waiting\n");
 47.1157 -			      options = 0;
 47.1158 -			    }
 47.1159 -			    if((pid = waitpid(0, &status, options)) > 0){
 47.1160 -			      num_children--;
 47.1161 -			      if(WEXITSTATUS(status) != EXIT_SUCCESS)
 47.1162 -				logwrite(LOG_WARNING,
 47.1163 -					 "delivery process with pid %d returned %d\n",
 47.1164 -					 pid, WEXITSTATUS(status));
 47.1165 -			      if(WIFSIGNALED(status))
 47.1166 -				logwrite(LOG_WARNING,
 47.1167 -					 "delivery process with pid %d got signal: %d\n",
 47.1168 -					 pid, WTERMSIG(status));
 47.1169 -			    }else if(pid < 0){
 47.1170 -			      logwrite(LOG_WARNING, "wait got error: %s\n", strerror(errno));
 47.1171 -			    }
 47.1172 -			  }
 47.1173 +														if (num_children >= POP3_MAX_CHILDREN) {
 47.1174 +															logwrite(LOG_NOTICE, "too many children - waiting\n");
 47.1175 +															options = 0;
 47.1176 +														}
 47.1177 +														if ((pid = waitpid(0, &status, options)) > 0) {
 47.1178 +															num_children--;
 47.1179 +															if (WEXITSTATUS(status) != EXIT_SUCCESS)
 47.1180 +																logwrite(LOG_WARNING, "delivery process with pid %d returned %d\n", pid, WEXITSTATUS (status));
 47.1181 +															if (WIFSIGNALED(status))
 47.1182 +																logwrite(LOG_WARNING, "delivery process with pid %d got signal: %d\n", pid, WTERMSIG (status));
 47.1183 +														} else if (pid < 0) {
 47.1184 +															logwrite(LOG_WARNING, "wait got error: %s\n", strerror(errno));
 47.1185 +														}
 47.1186 +													}
 47.1187  
 47.1188 -			  if((pid = fork()) == 0){
 47.1189 -			    deliver(msg);
 47.1190 -			    _exit(EXIT_SUCCESS);
 47.1191 -			  }else if(pid < 0){
 47.1192 -			    logwrite(LOG_ALERT|LOG_VERBOSE,
 47.1193 -				     "could not fork for delivery, id = %s: %s\n",
 47.1194 -				     msg->uid, strerror(errno));
 47.1195 -			  }else
 47.1196 -			    num_children++;
 47.1197 -			}else{
 47.1198 -			  DEBUG(1) debugf("queuing forced by configuration or option.\n");
 47.1199 -			}
 47.1200 -			if(popb->flags & POP3_FLAG_DELETE)
 47.1201 -			  pop3_in_dele(popb, info->number);
 47.1202 +													if ((pid = fork()) == 0) {
 47.1203 +														deliver(msg);
 47.1204 +														_exit(EXIT_SUCCESS);
 47.1205 +													} else if (pid < 0) {
 47.1206 +														logwrite(LOG_ALERT | LOG_VERBOSE, "could not fork for delivery, id = %s: %s\n", msg->uid, strerror(errno));
 47.1207 +													} else
 47.1208 +														num_children++;
 47.1209 +												} else {
 47.1210 +													DEBUG(1) debugf("queuing forced by configuration or option.\n");
 47.1211 +												}
 47.1212 +												if (popb->flags & POP3_FLAG_DELETE)
 47.1213 +													pop3_in_dele(popb, info->number);
 47.1214  
 47.1215 -			destroy_message(msg);
 47.1216 -		      }/* if(spool_write(msg, TRUE)) */
 47.1217 -		    }else{
 47.1218 -		      logwrite(LOG_ALERT,
 47.1219 -			       "retrieving of message %d failed: %d\n",
 47.1220 -			       info->number, popb->error);
 47.1221 -		    }
 47.1222 -		  }/* if((info->size > max_size) ... */
 47.1223 -		  else{
 47.1224 -		    logwrite(LOG_NOTICE|LOG_VERBOSE, "size of message #%d (%d) > max_size (%d)\n",
 47.1225 -			     info->number, info->size, max_size);
 47.1226 -		    if(max_size_delete)
 47.1227 -			if(popb->flags & POP3_FLAG_DELETE)
 47.1228 -			  pop3_in_dele(popb, info->number);
 47.1229 -		  }
 47.1230 -		}/* if(do_get_this) ... */
 47.1231 -		else{
 47.1232 -		  if(popb->flags & POP3_FLAG_UIDL){
 47.1233 -		    info->is_fetched = TRUE; /* obsolete? */
 47.1234 -		    logwrite(LOG_VERBOSE, "message %d already known\n",
 47.1235 -			     info->number);
 47.1236 -		    DEBUG(1) debugf("message %d (uid = %s) not fetched\n",
 47.1237 -				    info->number, info->uid);
 47.1238 +												destroy_message(msg);
 47.1239 +											}	/* if(spool_write(msg, TRUE)) */
 47.1240 +										} else {
 47.1241 +											logwrite(LOG_ALERT, "retrieving of message %d failed: %d\n", info->number, popb->error);
 47.1242 +										}
 47.1243 +									} /* if((info->size > max_size) ... */
 47.1244 +									else {
 47.1245 +										logwrite(LOG_NOTICE | LOG_VERBOSE, "size of message #%d (%d) > max_size (%d)\n", info->number, info->size, max_size);
 47.1246 +										if (max_size_delete)
 47.1247 +											if (popb->flags & POP3_FLAG_DELETE)
 47.1248 +												pop3_in_dele(popb, info->number);
 47.1249 +									}
 47.1250 +								} /* if(do_get_this) ... */
 47.1251 +								else {
 47.1252 +									if (popb->flags & POP3_FLAG_UIDL) {
 47.1253 +										info->is_fetched = TRUE;  /* obsolete? */
 47.1254 +										logwrite(LOG_VERBOSE, "message %d already known\n", info->number);
 47.1255 +										DEBUG(1) debugf("message %d (uid = %s) not fetched\n", info->number, info->uid);
 47.1256  #if 0
 47.1257  #if DO_WRITE_UIDL_EARLY
 47.1258 -		    write_uidl(popb, user); /* obsolete? */
 47.1259 +										write_uidl(popb, user);  /* obsolete? */
 47.1260  #endif
 47.1261  #endif
 47.1262 -		  }
 47.1263 -		}
 47.1264 -		if((max_count != 0) && (count >= max_count))
 47.1265 -		  break;
 47.1266 -	      }/* foreach() */
 47.1267 +									}
 47.1268 +								}
 47.1269 +								if ((max_count != 0) && (count >= max_count))
 47.1270 +									break;
 47.1271 +							}	/* foreach() */
 47.1272  #if DO_WRITE_UIDL_EARLY
 47.1273  #else
 47.1274 -	      if(popb->flags & POP3_FLAG_UIDL) write_uidl(popb, user);
 47.1275 +							if (popb->flags & POP3_FLAG_UIDL)
 47.1276 +								write_uidl(popb, user);
 47.1277  #endif
 47.1278 -	    }/* if(pop3_in_uidl(popb) ... */
 47.1279 -	  }/* if(pop3_in_list(popb)) */
 47.1280 -	}/* if(popb->msg_cnt > 0) */
 47.1281 -	else{
 47.1282 -	  logwrite(LOG_NOTICE|LOG_VERBOSE,
 47.1283 -		   "no messages for user %s at %s\n", user, popb->remote_host);
 47.1284 +						}  /* if(pop3_in_uidl(popb) ... */
 47.1285 +					}  /* if(pop3_in_list(popb)) */
 47.1286 +				}  /* if(popb->msg_cnt > 0) */
 47.1287 +				else {
 47.1288 +					logwrite(LOG_NOTICE | LOG_VERBOSE, "no messages for user %s at %s\n", user, popb->remote_host);
 47.1289 +				}
 47.1290 +				ok = TRUE;
 47.1291 +			}
 47.1292 +			pop3_in_quit(popb);
 47.1293 +		} else {
 47.1294 +			logwrite(LOG_ALERT | LOG_VERBOSE, "pop3 login failed for user %s, host = %s\n", user, popb->remote_host);
 47.1295 +		}
 47.1296  	}
 47.1297 -	ok = TRUE;
 47.1298 -      }
 47.1299 -      pop3_in_quit(popb);
 47.1300 -    }else{
 47.1301 -      logwrite(LOG_ALERT|LOG_VERBOSE,
 47.1302 -	       "pop3 login failed for user %s, host = %s\n", user, popb->remote_host);
 47.1303 -    }
 47.1304 -  }
 47.1305 -  if(!ok){
 47.1306 -    logwrite(LOG_ALERT|LOG_VERBOSE, "pop3 failed, error = %d\n", popb->error);
 47.1307 -  }
 47.1308 +	if (!ok) {
 47.1309 +		logwrite(LOG_ALERT | LOG_VERBOSE, "pop3 failed, error = %d\n", popb->error);
 47.1310 +	}
 47.1311  
 47.1312 -  while(num_children > 0){
 47.1313 -    int status;
 47.1314 -    pid_t pid;
 47.1315 -    if((pid = wait(&status)) > 0){
 47.1316 -      num_children--;
 47.1317 -      if(WEXITSTATUS(status) != EXIT_SUCCESS)
 47.1318 -	logwrite(LOG_WARNING,
 47.1319 -		 "delivery process with pid %d returned %d\n",
 47.1320 -		 pid, WEXITSTATUS(status));
 47.1321 -      if(WIFSIGNALED(status))
 47.1322 -	logwrite(LOG_WARNING,
 47.1323 -		 "delivery process with pid %d got signal: %d\n",
 47.1324 -		 pid, WTERMSIG(status));
 47.1325 -    }else{
 47.1326 -      logwrite(LOG_WARNING, "wait got error: %s\n", strerror(errno));
 47.1327 -    }
 47.1328 -  }
 47.1329 +	while (num_children > 0) {
 47.1330 +		int status;
 47.1331 +		pid_t pid;
 47.1332 +		if ((pid = wait(&status)) > 0) {
 47.1333 +			num_children--;
 47.1334 +			if (WEXITSTATUS(status) != EXIT_SUCCESS)
 47.1335 +				logwrite(LOG_WARNING, "delivery process with pid %d returned %d\n", pid, WEXITSTATUS(status));
 47.1336 +			if (WIFSIGNALED(status))
 47.1337 +				logwrite(LOG_WARNING, "delivery process with pid %d got signal: %d\n", pid, WTERMSIG(status));
 47.1338 +		} else {
 47.1339 +			logwrite(LOG_WARNING, "wait got error: %s\n", strerror(errno));
 47.1340 +		}
 47.1341 +	}
 47.1342  
 47.1343 -  return ok;
 47.1344 +	return ok;
 47.1345  }
 47.1346  
 47.1347  /* function just to log into a pop server,
 47.1348     for pop_before_smtp (or is it smtp_after_pop?)
 47.1349  */
 47.1350  
 47.1351 -gboolean pop3_login(gchar *host, gint port, GList *resolve_list,
 47.1352 -		    gchar *user, gchar *pass, guint flags)
 47.1353 +gboolean
 47.1354 +pop3_login(gchar * host, gint port, GList * resolve_list, gchar * user, gchar * pass, guint flags)
 47.1355  {
 47.1356 -  gboolean ok = FALSE;
 47.1357 -  pop3_base *popb;
 47.1358 +	gboolean ok = FALSE;
 47.1359 +	pop3_base *popb;
 47.1360  
 47.1361 -  signal(SIGCHLD, SIG_IGN);
 47.1362 +	signal(SIGCHLD, SIG_IGN);
 47.1363  
 47.1364 -  if((popb = pop3_in_open(host, port, resolve_list, flags))){
 47.1365 -    if(pop3_in_init(popb)){
 47.1366 -      if(pop3_in_login(popb, user, pass))
 47.1367 -	ok = TRUE;
 47.1368 -      else
 47.1369 -	logwrite(LOG_ALERT|LOG_VERBOSE,
 47.1370 -		 "pop3 login failed for user %s, host = %s\n", user, host);
 47.1371 -    }
 47.1372 -    pop3_in_close(popb);
 47.1373 -  }
 47.1374 -  return ok;
 47.1375 +	if ((popb = pop3_in_open(host, port, resolve_list, flags))) {
 47.1376 +		if (pop3_in_init(popb)) {
 47.1377 +			if (pop3_in_login(popb, user, pass))
 47.1378 +				ok = TRUE;
 47.1379 +			else
 47.1380 +				logwrite(LOG_ALERT | LOG_VERBOSE, "pop3 login failed for user %s, host = %s\n", user, host);
 47.1381 +		}
 47.1382 +		pop3_in_close(popb);
 47.1383 +	}
 47.1384 +	return ok;
 47.1385  }
 47.1386  
 47.1387  #endif
    48.1 --- a/src/pop3_in.h	Mon Oct 27 16:21:27 2008 +0100
    48.2 +++ b/src/pop3_in.h	Mon Oct 27 16:23:10 2008 +0100
    48.3 @@ -4,7 +4,7 @@
    48.4   * it under the terms of the GNU General Public License as published by
    48.5   * the Free Software Foundation; either version 2 of the License, or
    48.6   * (at your option) any later version.
    48.7 - * 
    48.8 + *
    48.9   * This program is distributed in the hope that it will be useful,
   48.10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   48.11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   48.12 @@ -31,56 +31,52 @@
   48.13  
   48.14  #define POP3_MAX_CHILDREN 2
   48.15  
   48.16 -typedef
   48.17 -enum _pop3_error{
   48.18 -  pop3_ok = 0,
   48.19 -  pop3_fail,
   48.20 -  pop3_eof,
   48.21 -  pop3_timeout,
   48.22 -  pop3_login_failure,
   48.23 -  pop3_syntax
   48.24 +typedef enum _pop3_error {
   48.25 +	pop3_ok = 0,
   48.26 +	pop3_fail,
   48.27 +	pop3_eof,
   48.28 +	pop3_timeout,
   48.29 +	pop3_login_failure,
   48.30 +	pop3_syntax
   48.31  } pop3_error;
   48.32  
   48.33 -typedef struct pop3_base{
   48.34 -  FILE *in;
   48.35 -  FILE *out;
   48.36 -  gint sock;
   48.37 -  gint dup_sock;
   48.38 +typedef struct pop3_base {
   48.39 +	FILE *in;
   48.40 +	FILE *out;
   48.41 +	gint sock;
   48.42 +	gint dup_sock;
   48.43  
   48.44 -  gchar *remote_host;
   48.45 -  gchar *buffer;
   48.46 +	gchar *remote_host;
   48.47 +	gchar *buffer;
   48.48  
   48.49 -  gint next_id;
   48.50 -  gint msg_cnt;
   48.51 -  gint uidl_known_cnt;
   48.52 -  gint mbox_size;
   48.53 +	gint next_id;
   48.54 +	gint msg_cnt;
   48.55 +	gint uidl_known_cnt;
   48.56 +	gint mbox_size;
   48.57  
   48.58 -  GList *list_uid_old;
   48.59 -  GList *drop_list;
   48.60 +	GList *list_uid_old;
   48.61 +	GList *drop_list;
   48.62  
   48.63 -  gchar* timestamp;
   48.64 +	gchar *timestamp;
   48.65  
   48.66 -  guint flags;
   48.67 +	guint flags;
   48.68  
   48.69 -  pop3_error error;
   48.70 +	pop3_error error;
   48.71  } pop3_base;
   48.72  
   48.73 -typedef struct _msg_info{
   48.74 -  gint number;
   48.75 -  gint size;
   48.76 -  gchar *uid;
   48.77 -  gboolean is_fetched;
   48.78 -  gboolean is_in_uidl;
   48.79 +typedef struct _msg_info {
   48.80 +	gint number;
   48.81 +	gint size;
   48.82 +	gchar *uid;
   48.83 +	gboolean is_fetched;
   48.84 +	gboolean is_in_uidl;
   48.85  } msg_info;
   48.86  
   48.87 -pop3_base *pop3_in_open(gchar *host, gint port, GList *resolve_list, guint flags);
   48.88 -pop3_base *pop3_in_open_child(gchar *cmd, guint flags);
   48.89 -void pop3_in_close(pop3_base *popb);
   48.90 -gboolean pop3_get(pop3_base *popb,
   48.91 -		  gchar *user, gchar *pass, address *rcpt, address *return_path,
   48.92 -		  gint max_count, gint max_size, gboolean max_size_delete);
   48.93 -gboolean pop3_login(gchar *host, gint port, GList *resolve_list,
   48.94 -		    gchar *user, gchar *pass, guint flags);
   48.95 +pop3_base *pop3_in_open(gchar * host, gint port, GList * resolve_list, guint flags);
   48.96 +pop3_base *pop3_in_open_child(gchar * cmd, guint flags);
   48.97 +void pop3_in_close(pop3_base * popb);
   48.98 +gboolean pop3_get(pop3_base * popb, gchar * user, gchar * pass, address * rcpt, address * return_path, gint max_count, gint max_size, gboolean max_size_delete);
   48.99 +gboolean pop3_login(gchar * host, gint port, GList * resolve_list, gchar * user, gchar * pass, guint flags);
  48.100  
  48.101  
  48.102  
    49.1 --- a/src/queue.c	Mon Oct 27 16:21:27 2008 +0100
    49.2 +++ b/src/queue.c	Mon Oct 27 16:23:10 2008 +0100
    49.3 @@ -21,204 +21,205 @@
    49.4  #include <sys/stat.h>
    49.5  #include <glob.h>
    49.6  
    49.7 -static
    49.8 -void mix_arr(int *buf, int len)
    49.9 +static void
   49.10 +mix_arr(int *buf, int len)
   49.11  {
   49.12 -  int i;
   49.13 +	int i;
   49.14  
   49.15 -  for(i = 0; i < len; i++)
   49.16 -    buf[i] = i;
   49.17 -  for(i = 0; i < len-1; i++){
   49.18 -    int j = (int)((float)(len-i) * ((float)rand())/(RAND_MAX + 1.0));
   49.19 -    int tmp;
   49.20 +	for (i = 0; i < len; i++)
   49.21 +		buf[i] = i;
   49.22 +	for (i = 0; i < len - 1; i++) {
   49.23 +		int j = (int) ((float) (len - i) * ((float) rand()) / (RAND_MAX + 1.0));
   49.24 +		int tmp;
   49.25  
   49.26 -    if(i != j){
   49.27 -      tmp = buf[i]; buf[i] = buf[j]; buf[j] = tmp;
   49.28 -    }
   49.29 -  }
   49.30 +		if (i != j) {
   49.31 +			tmp = buf[i];
   49.32 +			buf[i] = buf[j];
   49.33 +			buf[j] = tmp;
   49.34 +		}
   49.35 +	}
   49.36  }
   49.37  
   49.38 -GList *read_queue(gboolean do_readdata)
   49.39 +GList*
   49.40 +read_queue(gboolean do_readdata)
   49.41  {
   49.42 -  GList *msg_list = NULL;
   49.43 -  glob_t gl;
   49.44 -  gchar *pattern;
   49.45 -  int i, *idx_arr;
   49.46 +	GList *msg_list = NULL;
   49.47 +	glob_t gl;
   49.48 +	gchar *pattern;
   49.49 +	int i, *idx_arr;
   49.50  
   49.51 -  pattern = g_strdup_printf("%s/input/??????-???-??-H", conf.spool_dir);
   49.52 -  gl.gl_offs = 0;
   49.53 -  glob(pattern, 0, NULL, &gl);
   49.54 +	pattern = g_strdup_printf("%s/input/??????-???-??-H", conf.spool_dir);
   49.55 +	gl.gl_offs = 0;
   49.56 +	glob(pattern, 0, NULL, &gl);
   49.57  
   49.58 -  g_free(pattern);
   49.59 +	g_free(pattern);
   49.60  
   49.61 -  DEBUG(4){
   49.62 -    int i;
   49.63 -    for(i = 0; i < gl.gl_pathc; i++){
   49.64 -      debugf("spoolfile: %s\n", gl.gl_pathv[i]);
   49.65 -    }
   49.66 -  }
   49.67 +	DEBUG(4) {
   49.68 +		int i;
   49.69 +		for (i = 0; i < gl.gl_pathc; i++) {
   49.70 +			debugf("spoolfile: %s\n", gl.gl_pathv[i]);
   49.71 +		}
   49.72 +	}
   49.73  
   49.74 -  idx_arr = g_malloc(sizeof(int) * gl.gl_pathc);
   49.75 -  mix_arr(idx_arr, gl.gl_pathc);
   49.76 +	idx_arr = g_malloc(sizeof(int) * gl.gl_pathc);
   49.77 +	mix_arr(idx_arr, gl.gl_pathc);
   49.78  
   49.79 -  for(i = 0; i < gl.gl_pathc; i++){
   49.80 -    gchar *uid;
   49.81 +	for (i = 0; i < gl.gl_pathc; i++) {
   49.82 +		gchar *uid;
   49.83  
   49.84 -    /* copy 13 chars, offset spooldir path + 7 chars for /input/ */
   49.85 -    /* uid length = 6 chars + '-' + 3 chars + '-' + 2 = 13 chars */
   49.86 -    uid = g_strndup(&(gl.gl_pathv[idx_arr[i]][strlen(conf.spool_dir) + 7]), 13);
   49.87 +		/* copy 13 chars, offset spooldir path + 7 chars for /input/ */
   49.88 +		/* uid length = 6 chars + '-' + 3 chars + '-' + 2 = 13 chars */
   49.89 +		uid = g_strndup(&(gl.gl_pathv[idx_arr[i]][strlen(conf.spool_dir) + 7]), 13);
   49.90  
   49.91 -    DEBUG(5) debugf("uid: %s\n", uid);
   49.92 +		DEBUG(5) debugf("uid: %s\n", uid);
   49.93  
   49.94 -    msg_list = g_list_append(msg_list, msg_spool_read(uid, do_readdata));
   49.95 +		msg_list = g_list_append(msg_list, msg_spool_read(uid, do_readdata));
   49.96  
   49.97 -    DEBUG(5) debugf("after read spool file for %s\n", uid);
   49.98 +		DEBUG(5) debugf("after read spool file for %s\n", uid);
   49.99  
  49.100 -    g_free(uid);
  49.101 -  }
  49.102 -  return msg_list;
  49.103 +		g_free(uid);
  49.104 +	}
  49.105 +	return msg_list;
  49.106  }
  49.107  
  49.108 -gboolean queue_run()
  49.109 +gboolean
  49.110 +queue_run()
  49.111  {
  49.112 -  GList *msg_list;
  49.113 -  gboolean ok = TRUE;
  49.114 +	GList *msg_list;
  49.115 +	gboolean ok = TRUE;
  49.116  
  49.117 -  logwrite(LOG_NOTICE, "Starting queue run.\n");
  49.118 +	logwrite(LOG_NOTICE, "Starting queue run.\n");
  49.119  
  49.120 -  msg_list = read_queue(FALSE);
  49.121 +	msg_list = read_queue(FALSE);
  49.122  
  49.123 -  if(msg_list != NULL){
  49.124 -    ok = deliver_msg_list(msg_list, DLVR_ALL);
  49.125 -    destroy_msg_list(msg_list);
  49.126 -  }
  49.127 -  logwrite(LOG_NOTICE, "Finished queue run.\n");
  49.128 +	if (msg_list != NULL) {
  49.129 +		ok = deliver_msg_list(msg_list, DLVR_ALL);
  49.130 +		destroy_msg_list(msg_list);
  49.131 +	}
  49.132 +	logwrite(LOG_NOTICE, "Finished queue run.\n");
  49.133  
  49.134 -  return ok;
  49.135 +	return ok;
  49.136  }
  49.137  
  49.138 -gboolean queue_run_online()
  49.139 +gboolean
  49.140 +queue_run_online()
  49.141  {
  49.142 -  GList *msg_list = read_queue(FALSE);
  49.143 -  gboolean ok = TRUE;
  49.144 +	GList *msg_list = read_queue(FALSE);
  49.145 +	gboolean ok = TRUE;
  49.146  
  49.147 -  logwrite(LOG_NOTICE, "Starting online queue run.\n");
  49.148 -  if(msg_list != NULL){
  49.149 -    ok = deliver_msg_list(msg_list, DLVR_ONLINE);
  49.150 -    destroy_msg_list(msg_list);
  49.151 -  }
  49.152 -  logwrite(LOG_NOTICE, "Finished online queue run.\n");
  49.153 +	logwrite(LOG_NOTICE, "Starting online queue run.\n");
  49.154 +	if (msg_list != NULL) {
  49.155 +		ok = deliver_msg_list(msg_list, DLVR_ONLINE);
  49.156 +		destroy_msg_list(msg_list);
  49.157 +	}
  49.158 +	logwrite(LOG_NOTICE, "Finished online queue run.\n");
  49.159  
  49.160 -  return ok;
  49.161 +	return ok;
  49.162  }
  49.163  
  49.164 -static
  49.165 -gchar *format_difftime(double secs)
  49.166 +static gchar*
  49.167 +format_difftime(double secs)
  49.168  {
  49.169 -  if(secs > 86400)
  49.170 -    return g_strdup_printf("%.1fd", secs/86400);
  49.171 -  else if(secs > 3600)
  49.172 -    return g_strdup_printf("%.1fh", secs/3600);
  49.173 -  else if(secs > 60)
  49.174 -    return g_strdup_printf("%.1fm", secs/60);
  49.175 -  else
  49.176 -    return g_strdup_printf("%.0fs", secs);
  49.177 -}  
  49.178 +	if (secs > 86400)
  49.179 +		return g_strdup_printf("%.1fd", secs / 86400);
  49.180 +	else if (secs > 3600)
  49.181 +		return g_strdup_printf("%.1fh", secs / 3600);
  49.182 +	else if (secs > 60)
  49.183 +		return g_strdup_printf("%.1fm", secs / 60);
  49.184 +	else
  49.185 +		return g_strdup_printf("%.0fs", secs);
  49.186 +}
  49.187  
  49.188 -void queue_list()
  49.189 +void
  49.190 +queue_list()
  49.191  {
  49.192 -  GList *msg_list;
  49.193 -  GList *msg_node;
  49.194 +	GList *msg_list;
  49.195 +	GList *msg_node;
  49.196  
  49.197 -  msg_list = read_queue(FALSE);
  49.198 +	msg_list = read_queue(FALSE);
  49.199  
  49.200 -  if(msg_list != NULL){
  49.201 -    foreach(msg_list, msg_node){
  49.202 -      message *msg = (message *)(msg_node->data);
  49.203 -      GList *rcpt_node;
  49.204 -      gchar *size_str = NULL;
  49.205 -      gchar *time_str = NULL;
  49.206 -      gchar *host_str = NULL;
  49.207 -      gchar *ident_str = NULL;
  49.208 -    
  49.209 -      if(msg->data_size >= 0)
  49.210 -	size_str = g_strdup_printf(" size=%d", msg->data_size);
  49.211 -      if(msg->received_time > 0){
  49.212 -	gchar *tmp_str;
  49.213 -	time_str =
  49.214 -	  g_strdup_printf(" age=%s",
  49.215 -			  tmp_str = format_difftime(difftime(time(NULL),
  49.216 -							     msg->received_time)));
  49.217 -	g_free(tmp_str);
  49.218 -      }
  49.219 -      if(msg->received_host != NULL)
  49.220 -	host_str = g_strdup_printf(" host=%s", msg->received_host);
  49.221 -      if(msg->ident != NULL)
  49.222 -	ident_str = g_strdup_printf(" ident=%s", msg->ident);
  49.223 +	if (msg_list != NULL) {
  49.224 +		foreach(msg_list, msg_node) {
  49.225 +			message *msg = (message *) (msg_node->data);
  49.226 +			GList *rcpt_node;
  49.227 +			gchar *size_str = NULL;
  49.228 +			gchar *time_str = NULL;
  49.229 +			gchar *host_str = NULL;
  49.230 +			gchar *ident_str = NULL;
  49.231  
  49.232 -      printf("%s <= %s%s%s%s%s\n", msg->uid,
  49.233 -	     addr_string(msg->return_path),
  49.234 -	     size_str ? size_str : "",
  49.235 -	     time_str ? time_str : "",
  49.236 -	     host_str ? host_str : "",
  49.237 -	     ident_str ? ident_str : ""
  49.238 -	     );
  49.239 +			if (msg->data_size >= 0)
  49.240 +				size_str = g_strdup_printf(" size=%d", msg->data_size);
  49.241 +			if (msg->received_time > 0) {
  49.242 +				gchar *tmp_str;
  49.243 +				time_str = g_strdup_printf(" age=%s", tmp_str = format_difftime(difftime(time(NULL), msg->received_time)));
  49.244 +				g_free(tmp_str);
  49.245 +			}
  49.246 +			if (msg->received_host != NULL)
  49.247 +				host_str = g_strdup_printf(" host=%s", msg->received_host);
  49.248 +			if (msg->ident != NULL)
  49.249 +				ident_str = g_strdup_printf(" ident=%s", msg->ident);
  49.250  
  49.251 -      if(size_str) g_free(size_str);
  49.252 -      if(time_str) g_free(time_str);
  49.253 -      if(host_str) g_free(host_str);
  49.254 -      if(ident_str) g_free(ident_str);
  49.255 +			printf("%s <= %s%s%s%s%s\n", msg->uid, addr_string(msg->return_path), size_str ? size_str : "",
  49.256 +			       time_str ? time_str : "", host_str ? host_str : "", ident_str ? ident_str : "");
  49.257  
  49.258 -      foreach(msg->rcpt_list, rcpt_node){
  49.259 -	address *rcpt = (address *)(rcpt_node->data);
  49.260 -      
  49.261 -	printf("              %s %s\n",
  49.262 -	       addr_is_delivered(rcpt) ? "=>" : (addr_is_failed(rcpt) ? "!=" : "=="),
  49.263 -	       addr_string(rcpt));
  49.264 -      }
  49.265 -      g_free(msg);
  49.266 -    }
  49.267 -  }else
  49.268 -    printf("mail queue is empty.\n");
  49.269 -}  
  49.270 +			if (size_str)
  49.271 +				g_free(size_str);
  49.272 +			if (time_str)
  49.273 +				g_free(time_str);
  49.274 +			if (host_str)
  49.275 +				g_free(host_str);
  49.276 +			if (ident_str)
  49.277 +				g_free(ident_str);
  49.278  
  49.279 -gboolean queue_delete(gchar *uid)
  49.280 +			foreach(msg->rcpt_list, rcpt_node) {
  49.281 +				address *rcpt = (address *) (rcpt_node->data);
  49.282 +
  49.283 +				printf("              %s %s\n", addr_is_delivered(rcpt) ? "=>" : (addr_is_failed(rcpt) ? "!=" : "=="), addr_string(rcpt));
  49.284 +			}
  49.285 +			g_free(msg);
  49.286 +		}
  49.287 +	} else
  49.288 +		printf("mail queue is empty.\n");
  49.289 +}
  49.290 +
  49.291 +gboolean
  49.292 +queue_delete(gchar * uid)
  49.293  {
  49.294 -  gboolean hdr_ok = TRUE;
  49.295 -  gboolean dat_ok = TRUE;
  49.296 -  gchar *hdr_name = g_strdup_printf("%s/input/%s-H", conf.spool_dir, uid);
  49.297 -  gchar *dat_name = g_strdup_printf("%s/input/%s-D", conf.spool_dir, uid);
  49.298 -  struct stat stat_buf;
  49.299 +	gboolean hdr_ok = TRUE;
  49.300 +	gboolean dat_ok = TRUE;
  49.301 +	gchar *hdr_name = g_strdup_printf("%s/input/%s-H", conf.spool_dir, uid);
  49.302 +	gchar *dat_name = g_strdup_printf("%s/input/%s-D", conf.spool_dir, uid);
  49.303 +	struct stat stat_buf;
  49.304  
  49.305 -  if(spool_lock(uid)){
  49.306 +	if (spool_lock(uid)) {
  49.307  
  49.308 -    if(stat(hdr_name, &stat_buf) == 0){
  49.309 -      if(unlink(hdr_name) != 0){
  49.310 -	fprintf(stderr, "could not unlink %s: %s\n", hdr_name, strerror(errno));
  49.311 -	hdr_ok = FALSE;
  49.312 -      }
  49.313 -    }else{
  49.314 -      fprintf(stderr, "could not stat file %s: %s\n", hdr_name, strerror(errno));
  49.315 -      hdr_ok = FALSE;
  49.316 -    }
  49.317 -    if(stat(dat_name, &stat_buf) == 0){
  49.318 -      if(unlink(dat_name) != 0){
  49.319 -	fprintf(stderr, "could not unlink %s: %s\n", dat_name, strerror(errno));
  49.320 -	dat_ok = FALSE;
  49.321 -      }
  49.322 -    }else{
  49.323 -      fprintf(stderr, "could not stat file %s: %s\n", dat_name, strerror(errno));
  49.324 -      dat_ok = FALSE;
  49.325 -    }
  49.326 -    printf("message %s deleted\n", uid);
  49.327 +		if (stat(hdr_name, &stat_buf) == 0) {
  49.328 +			if (unlink(hdr_name) != 0) {
  49.329 +				fprintf(stderr, "could not unlink %s: %s\n", hdr_name, strerror(errno));
  49.330 +				hdr_ok = FALSE;
  49.331 +			}
  49.332 +		} else {
  49.333 +			fprintf(stderr, "could not stat file %s: %s\n", hdr_name, strerror(errno));
  49.334 +			hdr_ok = FALSE;
  49.335 +		}
  49.336 +		if (stat(dat_name, &stat_buf) == 0) {
  49.337 +			if (unlink(dat_name) != 0) {
  49.338 +				fprintf(stderr, "could not unlink %s: %s\n", dat_name, strerror(errno));
  49.339 +				dat_ok = FALSE;
  49.340 +			}
  49.341 +		} else {
  49.342 +			fprintf(stderr, "could not stat file %s: %s\n", dat_name, strerror(errno));
  49.343 +			dat_ok = FALSE;
  49.344 +		}
  49.345 +		printf("message %s deleted\n", uid);
  49.346  
  49.347 -    spool_unlock(uid);
  49.348 +		spool_unlock(uid);
  49.349  
  49.350 -  }else{
  49.351 +	} else {
  49.352  
  49.353 -    fprintf(stderr, "message %s is locked.\n", uid);
  49.354 -    return FALSE;
  49.355 -  }
  49.356 +		fprintf(stderr, "message %s is locked.\n", uid);
  49.357 +		return FALSE;
  49.358 +	}
  49.359  
  49.360 -  return (dat_ok && hdr_ok);
  49.361 +	return (dat_ok && hdr_ok);
  49.362  }
    50.1 --- a/src/readsock.c	Mon Oct 27 16:21:27 2008 +0100
    50.2 +++ b/src/readsock.c	Mon Oct 27 16:23:10 2008 +0100
    50.3 @@ -27,156 +27,160 @@
    50.4  
    50.5  jmp_buf jmp_timeout;
    50.6  
    50.7 -static
    50.8 -void sig_timeout_handler(int sig)
    50.9 +static void
   50.10 +sig_timeout_handler(int sig)
   50.11  {
   50.12 -  longjmp(jmp_timeout, 1);
   50.13 +	longjmp(jmp_timeout, 1);
   50.14  }
   50.15  
   50.16  static struct sigaction old_sa_alrm;
   50.17  
   50.18 -static
   50.19 -void alarm_on(int timeout)
   50.20 +static void
   50.21 +alarm_on(int timeout)
   50.22  {
   50.23 -  struct sigaction sa;
   50.24 +	struct sigaction sa;
   50.25  
   50.26 -  sa.sa_handler = sig_timeout_handler;
   50.27 -  sigemptyset(&(sa.sa_mask));
   50.28 -  sa.sa_flags = 0;
   50.29 -  sigaction(SIGALRM, &sa, &old_sa_alrm);
   50.30 +	sa.sa_handler = sig_timeout_handler;
   50.31 +	sigemptyset(&(sa.sa_mask));
   50.32 +	sa.sa_flags = 0;
   50.33 +	sigaction(SIGALRM, &sa, &old_sa_alrm);
   50.34  
   50.35 -  if(timeout > 0)
   50.36 -    alarm(timeout);
   50.37 +	if (timeout > 0)
   50.38 +		alarm(timeout);
   50.39  }
   50.40  
   50.41 -static
   50.42 -void alarm_off()
   50.43 +static void
   50.44 +alarm_off()
   50.45  {
   50.46 -  alarm(0);
   50.47 +	alarm(0);
   50.48  
   50.49 -  sigaction(SIGALRM, &old_sa_alrm, NULL);
   50.50 +	sigaction(SIGALRM, &old_sa_alrm, NULL);
   50.51  }
   50.52  
   50.53 -static
   50.54 -void _read_chug(FILE *in)
   50.55 +static void
   50.56 +_read_chug(FILE * in)
   50.57  {
   50.58 -  int c = 0;
   50.59 +	int c = 0;
   50.60  
   50.61 -  c = fgetc(in);
   50.62 -  while(isspace(c) && (c != EOF)) c = fgetc(in);
   50.63 -  ungetc(c, in);
   50.64 +	c = fgetc(in);
   50.65 +	while (isspace(c) && (c != EOF))
   50.66 +		c = fgetc(in);
   50.67 +	ungetc(c, in);
   50.68  }
   50.69  
   50.70 -static
   50.71 -int _read_line(FILE *in, char *buf, int buf_len, int timeout)
   50.72 +static int
   50.73 +_read_line(FILE * in, char *buf, int buf_len, int timeout)
   50.74  {
   50.75 -  int p = 0;
   50.76 -  int c = 0;
   50.77 +	int p = 0;
   50.78 +	int c = 0;
   50.79  
   50.80 -  c = fgetc(in);
   50.81 -  while((c != '\n') && (c != EOF) && (p < buf_len-1)){
   50.82 -    buf[p++] = c;
   50.83 -    c = fgetc(in);
   50.84 -  }
   50.85 +	c = fgetc(in);
   50.86 +	while ((c != '\n') && (c != EOF) && (p < buf_len - 1)) {
   50.87 +		buf[p++] = c;
   50.88 +		c = fgetc(in);
   50.89 +	}
   50.90  
   50.91 -  buf[p] = 0;
   50.92 +	buf[p] = 0;
   50.93  
   50.94 -  if(c == EOF)
   50.95 -    return -1;
   50.96 -  else if(p >= buf_len){
   50.97 -    ungetc(c, in);
   50.98 -    return -2;
   50.99 -  }
  50.100 +	if (c == EOF)
  50.101 +		return -1;
  50.102 +	else if (p >= buf_len) {
  50.103 +		ungetc(c, in);
  50.104 +		return -2;
  50.105 +	}
  50.106  
  50.107 -  buf[p++] = c; /* \n */
  50.108 -  buf[p] = 0;
  50.109 +	buf[p++] = c;  /* \n */
  50.110 +	buf[p] = 0;
  50.111  
  50.112 -  return p;
  50.113 +	return p;
  50.114  }
  50.115  
  50.116 -int read_sockline(FILE *in, char *buf, int buf_len, int timeout, unsigned int flags)
  50.117 +int
  50.118 +read_sockline(FILE * in, char *buf, int buf_len, int timeout, unsigned int flags)
  50.119  {
  50.120 -  int p = 0;
  50.121 +	int p = 0;
  50.122  
  50.123 -  if(setjmp(jmp_timeout) != 0){
  50.124 -    alarm_off();
  50.125 -    return -3;
  50.126 -  }
  50.127 +	if (setjmp(jmp_timeout) != 0) {
  50.128 +		alarm_off();
  50.129 +		return -3;
  50.130 +	}
  50.131  
  50.132 -  alarm_on(timeout);
  50.133 +	alarm_on(timeout);
  50.134  
  50.135 -  /* strip leading spaces */
  50.136 -  if(flags & READSOCKL_CHUG){
  50.137 -    _read_chug(in);
  50.138 -  }
  50.139 +	/* strip leading spaces */
  50.140 +	if (flags & READSOCKL_CHUG) {
  50.141 +		_read_chug(in);
  50.142 +	}
  50.143  
  50.144 -  p = _read_line(in, buf, buf_len, timeout);
  50.145 +	p = _read_line(in, buf, buf_len, timeout);
  50.146  
  50.147 -  alarm_off();
  50.148 +	alarm_off();
  50.149  
  50.150 -  if(p > 1){
  50.151 -    /* here we are sure that buf[p-1] == '\n' */
  50.152 -    if(flags & READSOCKL_CVT_CRLF){
  50.153 -      if((buf[p-2] == '\r') && (buf[p-1] == '\n')){
  50.154 -	buf[p-2] = '\n';
  50.155 -	buf[p-1] = 0;
  50.156 -	p--;
  50.157 -      }
  50.158 -    }
  50.159 -  }
  50.160 -  return p;
  50.161 +	if (p > 1) {
  50.162 +		/* here we are sure that buf[p-1] == '\n' */
  50.163 +		if (flags & READSOCKL_CVT_CRLF) {
  50.164 +			if ((buf[p - 2] == '\r') && (buf[p - 1] == '\n')) {
  50.165 +				buf[p - 2] = '\n';
  50.166 +				buf[p - 1] = 0;
  50.167 +				p--;
  50.168 +			}
  50.169 +		}
  50.170 +	}
  50.171 +	return p;
  50.172  }
  50.173  
  50.174 -int read_sockline1(FILE *in, char **pbuf, int *buf_len, int timeout, unsigned int flags)
  50.175 +int
  50.176 +read_sockline1(FILE * in, char **pbuf, int *buf_len, int timeout, unsigned int flags)
  50.177  {
  50.178 -  int p = 0, size = *buf_len;
  50.179 -  char *buf;
  50.180 +	int p = 0, size = *buf_len;
  50.181 +	char *buf;
  50.182  
  50.183 -  if(setjmp(jmp_timeout) != 0){
  50.184 -    alarm_off();
  50.185 -    return -3;
  50.186 -  }
  50.187 +	if (setjmp(jmp_timeout) != 0) {
  50.188 +		alarm_off();
  50.189 +		return -3;
  50.190 +	}
  50.191  
  50.192 -  alarm_on(timeout);
  50.193 +	alarm_on(timeout);
  50.194  
  50.195 -  /* strip leading spaces */
  50.196 -  if(flags & READSOCKL_CHUG){
  50.197 -    _read_chug(in);
  50.198 -  }
  50.199 +	/* strip leading spaces */
  50.200 +	if (flags & READSOCKL_CHUG) {
  50.201 +		_read_chug(in);
  50.202 +	}
  50.203  
  50.204 -  if(!*pbuf) *pbuf = malloc(size);
  50.205 -  buf = *pbuf;
  50.206 -  
  50.207 -  while(1){
  50.208 -    int pp;
  50.209 +	if (!*pbuf)
  50.210 +		*pbuf = malloc(size);
  50.211 +	buf = *pbuf;
  50.212  
  50.213 -    pp = _read_line(in, buf, size, timeout);
  50.214 -    if(pp == -2){
  50.215 -      *pbuf = realloc(*pbuf, *buf_len + size);
  50.216 -      buf = *pbuf + *buf_len;
  50.217 -      *buf_len += size;
  50.218 -      p += size;
  50.219 -    }
  50.220 -    else{
  50.221 -      if(pp > 0) p += pp;
  50.222 -      else p = pp;
  50.223 -      break;
  50.224 -    }
  50.225 -  }
  50.226 +	while (1) {
  50.227 +		int pp;
  50.228  
  50.229 -  alarm_off();
  50.230 +		pp = _read_line(in, buf, size, timeout);
  50.231 +		if (pp == -2) {
  50.232 +			*pbuf = realloc(*pbuf, *buf_len + size);
  50.233 +			buf = *pbuf + *buf_len;
  50.234 +			*buf_len += size;
  50.235 +			p += size;
  50.236 +		} else {
  50.237 +			if (pp > 0)
  50.238 +				p += pp;
  50.239 +			else
  50.240 +				p = pp;
  50.241 +			break;
  50.242 +		}
  50.243 +	}
  50.244  
  50.245 -  if(p > 1){
  50.246 -    buf = *pbuf;
  50.247 -    /* here we are sure that buf[p-1] == '\n' */
  50.248 -    if(flags & READSOCKL_CVT_CRLF){
  50.249 -      if((buf[p-2] == '\r') && (buf[p-1] == '\n')){
  50.250 -	buf[p-2] = '\n';
  50.251 -	buf[p-1] = 0;
  50.252 -	p--;
  50.253 -      }
  50.254 -    }
  50.255 -  }
  50.256 -  return p;
  50.257 +	alarm_off();
  50.258 +
  50.259 +	if (p > 1) {
  50.260 +		buf = *pbuf;
  50.261 +		/* here we are sure that buf[p-1] == '\n' */
  50.262 +		if (flags & READSOCKL_CVT_CRLF) {
  50.263 +			if ((buf[p - 2] == '\r') && (buf[p - 1] == '\n')) {
  50.264 +				buf[p - 2] = '\n';
  50.265 +				buf[p - 1] = 0;
  50.266 +				p--;
  50.267 +			}
  50.268 +		}
  50.269 +	}
  50.270 +	return p;
  50.271  }
  50.272 -
    51.1 --- a/src/readsock.h	Mon Oct 27 16:21:27 2008 +0100
    51.2 +++ b/src/readsock.h	Mon Oct 27 16:23:10 2008 +0100
    51.3 @@ -20,5 +20,5 @@
    51.4  #define READSOCKL_CVT_CRLF 0x02
    51.5  
    51.6  
    51.7 -int read_sockline(FILE *in, char *buf, int buf_len, int timeout, unsigned int flags);
    51.8 -int read_sockline1(FILE *in, char **pbuf, int *size, int timeout, unsigned int flags);
    51.9 +int read_sockline(FILE * in, char *buf, int buf_len, int timeout, unsigned int flags);
   51.10 +int read_sockline1(FILE * in, char **pbuf, int *size, int timeout, unsigned int flags);
    52.1 --- a/src/readtest.c	Mon Oct 27 16:21:27 2008 +0100
    52.2 +++ b/src/readtest.c	Mon Oct 27 16:23:10 2008 +0100
    52.3 @@ -2,18 +2,17 @@
    52.4  #include "masqmail.h"
    52.5  #include "readsock.h"
    52.6  
    52.7 -int main()
    52.8 +int
    52.9 +main()
   52.10  {
   52.11 -  char *buf = g_malloc(20);
   52.12 -  int size = 20, ret;
   52.13 +	char *buf = g_malloc(20);
   52.14 +	int size = 20, ret;
   52.15  
   52.16 -  ret = read_sockline1(stdin, &buf, &size, 60, READSOCKL_CVT_CRLF);
   52.17 -  //  ret = read_sockline(stdin, buf, size, 60, READSOCKL_CHUG);
   52.18 +	ret = read_sockline1(stdin, &buf, &size, 60, READSOCKL_CVT_CRLF);
   52.19 +	//  ret = read_sockline(stdin, buf, size, 60, READSOCKL_CHUG);
   52.20  
   52.21 -  printf("%s\n", buf);
   52.22 -  printf("ret = %d, size = %d, strlen = %d\n", ret, size, strlen(buf));
   52.23 +	printf("%s\n", buf);
   52.24 +	printf("ret = %d, size = %d, strlen = %d\n", ret, size, strlen(buf));
   52.25  
   52.26 -  return 0;
   52.27 +	return 0;
   52.28  }
   52.29 -
   52.30 -
    53.1 --- a/src/rewrite.c	Mon Oct 27 16:21:27 2008 +0100
    53.2 +++ b/src/rewrite.c	Mon Oct 27 16:23:10 2008 +0100
    53.3 @@ -20,81 +20,78 @@
    53.4  #include "masqmail.h"
    53.5  #endif
    53.6  
    53.7 -gboolean set_address_header_domain(header *hdr, gchar *domain)
    53.8 +gboolean
    53.9 +set_address_header_domain(header * hdr, gchar * domain)
   53.10  {
   53.11 -  gchar *p = hdr->value;
   53.12 -  gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
   53.13 -  gint tmp;
   53.14 +	gchar *p = hdr->value;
   53.15 +	gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
   53.16 +	gint tmp;
   53.17  
   53.18 -  while(*p){
   53.19 -    gchar *loc_beg, *loc_end;
   53.20 -    gchar *dom_beg, *dom_end;
   53.21 -    gchar *addr_end;
   53.22 -    gchar *rewr_string;
   53.23 +	while (*p) {
   53.24 +		gchar *loc_beg, *loc_end;
   53.25 +		gchar *dom_beg, *dom_end;
   53.26 +		gchar *addr_end;
   53.27 +		gchar *rewr_string;
   53.28  
   53.29 -    if(parse_address_rfc822(p,
   53.30 -			    &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)){
   53.31 -      gchar *left, *right;
   53.32 +		if (parse_address_rfc822(p, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)) {
   53.33 +			gchar *left, *right;
   53.34  
   53.35 -      if(dom_beg != NULL){
   53.36 -	left = g_strndup(p, dom_beg - p);
   53.37 -	right = g_strndup(dom_end, addr_end - dom_end);
   53.38 +			if (dom_beg != NULL) {
   53.39 +				left = g_strndup(p, dom_beg - p);
   53.40 +				right = g_strndup(dom_end, addr_end - dom_end);
   53.41  
   53.42 -	rewr_string = g_strconcat(left, domain, right, NULL);
   53.43 -      }else{
   53.44 -	left = g_strndup(p, loc_end - p);
   53.45 -	right = g_strndup(loc_end, addr_end - loc_end);
   53.46 +				rewr_string = g_strconcat(left, domain, right, NULL);
   53.47 +			} else {
   53.48 +				left = g_strndup(p, loc_end - p);
   53.49 +				right = g_strndup(loc_end, addr_end - loc_end);
   53.50  
   53.51 -	rewr_string = g_strconcat(left, "@", domain, right, NULL);
   53.52 -      }
   53.53 -      g_free(left);
   53.54 -      g_free(right);
   53.55 +				rewr_string = g_strconcat(left, "@", domain, right, NULL);
   53.56 +			}
   53.57 +			g_free(left);
   53.58 +			g_free(right);
   53.59  
   53.60 -      p = addr_end;
   53.61 -      if(*p == ',') p++;
   53.62 +			p = addr_end;
   53.63 +			if (*p == ',')
   53.64 +				p++;
   53.65  
   53.66 -      new_hdr =
   53.67 -	g_strconcat(new_hdr, rewr_string,
   53.68 -		    *p != 0 ? "," : NULL, NULL);
   53.69 +			new_hdr = g_strconcat(new_hdr, rewr_string, *p != 0 ? "," : NULL, NULL);
   53.70  
   53.71 -    }else
   53.72 -      return FALSE;
   53.73 -  }
   53.74 -  tmp = (hdr->value - hdr->header);
   53.75 -  g_free(hdr->header);
   53.76 -  hdr->header = new_hdr;
   53.77 -  hdr->value = hdr->header + tmp;
   53.78 +		} else
   53.79 +			return FALSE;
   53.80 +	}
   53.81 +	tmp = (hdr->value - hdr->header);
   53.82 +	g_free(hdr->header);
   53.83 +	hdr->header = new_hdr;
   53.84 +	hdr->value = hdr->header + tmp;
   53.85  
   53.86 -  return TRUE;
   53.87 +	return TRUE;
   53.88  }
   53.89  
   53.90 -gboolean map_address_header(header *hdr, GList *table)
   53.91 +gboolean
   53.92 +map_address_header(header * hdr, GList * table)
   53.93  {
   53.94 -  GList *addr_list = addr_list_append_rfc822(NULL, hdr->value, conf.host_name);
   53.95 -  GList *addr_node;
   53.96 -  gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
   53.97 -  gboolean did_change = FALSE;
   53.98 +	GList *addr_list = addr_list_append_rfc822(NULL, hdr->value, conf.host_name);
   53.99 +	GList *addr_node;
  53.100 +	gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
  53.101 +	gboolean did_change = FALSE;
  53.102  
  53.103 -  foreach(addr_list, addr_node){
  53.104 -    address *addr = (address *)(addr_node->data);
  53.105 -    gchar *rewr_string = (gchar *)table_find_fnmatch(table, addr->local_part);
  53.106 +	foreach(addr_list, addr_node) {
  53.107 +		address *addr = (address *) (addr_node->data);
  53.108 +		gchar *rewr_string = (gchar *) table_find_fnmatch(table, addr->local_part);
  53.109  
  53.110 -    if(rewr_string == NULL)
  53.111 -      rewr_string = addr->address;
  53.112 -    else
  53.113 -      did_change = TRUE;
  53.114 +		if (rewr_string == NULL)
  53.115 +			rewr_string = addr->address;
  53.116 +		else
  53.117 +			did_change = TRUE;
  53.118  
  53.119 -    if(rewr_string)
  53.120 -      new_hdr =
  53.121 -	g_strconcat(new_hdr, rewr_string,
  53.122 -		    g_list_next(addr_node) ? "," : "\n", NULL);
  53.123 -  }
  53.124 -  if(did_change){
  53.125 -    g_free(hdr->header);
  53.126 -    hdr->header = new_hdr;
  53.127 -  }else
  53.128 -    g_free(new_hdr);
  53.129 +		if (rewr_string)
  53.130 +			new_hdr = g_strconcat(new_hdr, rewr_string, g_list_next(addr_node) ? "," : "\n", NULL);
  53.131 +	}
  53.132 +	if (did_change) {
  53.133 +		g_free(hdr->header);
  53.134 +		hdr->header = new_hdr;
  53.135 +	} else
  53.136 +		g_free(new_hdr);
  53.137  
  53.138 -  return did_change;
  53.139 +	return did_change;
  53.140  }
  53.141 -
    54.1 --- a/src/route.c	Mon Oct 27 16:21:27 2008 +0100
    54.2 +++ b/src/route.c	Mon Oct 27 16:23:10 2008 +0100
    54.3 @@ -19,347 +19,335 @@
    54.4  #include "masqmail.h"
    54.5  #include <fnmatch.h>
    54.6  
    54.7 -msgout_perhost *create_msgout_perhost(gchar *host)
    54.8 +msgout_perhost*
    54.9 +create_msgout_perhost(gchar * host)
   54.10  {
   54.11 -  msgout_perhost *mo_ph = g_malloc(sizeof(msgout_perhost));
   54.12 -  if(mo_ph){
   54.13 -    mo_ph->host = g_strdup(host);
   54.14 -    mo_ph->msgout_list = NULL;
   54.15 -  }
   54.16 -  return mo_ph;
   54.17 +	msgout_perhost *mo_ph = g_malloc(sizeof(msgout_perhost));
   54.18 +	if (mo_ph) {
   54.19 +		mo_ph->host = g_strdup(host);
   54.20 +		mo_ph->msgout_list = NULL;
   54.21 +	}
   54.22 +	return mo_ph;
   54.23  }
   54.24  
   54.25 -void destroy_msgout_perhost(msgout_perhost *mo_ph)
   54.26 +void
   54.27 +destroy_msgout_perhost(msgout_perhost * mo_ph)
   54.28  {
   54.29 -  GList *mo_node;
   54.30 +	GList *mo_node;
   54.31  
   54.32 -  foreach(mo_ph->msgout_list, mo_node){
   54.33 -    msg_out *mo = (msg_out *)(mo_node->data);
   54.34 -    /* the rcpt_list is owned by the msgout's,
   54.35 -       but not the rcpt's themselves */
   54.36 -    g_list_free(mo->rcpt_list);
   54.37 -    g_free(mo);
   54.38 -  }
   54.39 -  g_list_free(mo_ph->msgout_list);
   54.40 -  g_free(mo_ph);
   54.41 +	foreach(mo_ph->msgout_list, mo_node) {
   54.42 +		msg_out *mo = (msg_out *) (mo_node->data);
   54.43 +		/* the rcpt_list is owned by the msgout's, but not the rcpt's themselves */
   54.44 +		g_list_free(mo->rcpt_list);
   54.45 +		g_free(mo);
   54.46 +	}
   54.47 +	g_list_free(mo_ph->msgout_list);
   54.48 +	g_free(mo_ph);
   54.49  }
   54.50  
   54.51 -void rewrite_headers(msg_out *msgout, connect_route *route)
   54.52 +void
   54.53 +rewrite_headers(msg_out * msgout, connect_route * route)
   54.54  {
   54.55 -  /* if set_h_from_domain is set, replace domain in all
   54.56 -     From: headers.
   54.57 -  */
   54.58 -  msgout->hdr_list = g_list_copy(msgout->msg->hdr_list);
   54.59 +	/* if set_h_from_domain is set, replace domain in all
   54.60 +	   From: headers.
   54.61 +	 */
   54.62 +	msgout->hdr_list = g_list_copy(msgout->msg->hdr_list);
   54.63  
   54.64 -  /* map from addresses */
   54.65 -  if(route->map_h_from_addresses != NULL){
   54.66 -    GList *hdr_node;
   54.67 -    foreach(msgout->hdr_list, hdr_node){
   54.68 -      header *hdr = (header *)(hdr_node->data);
   54.69 -      if(hdr->id == HEAD_FROM){
   54.70 -	header *new_hdr = copy_header(hdr);
   54.71 -	if(map_address_header(new_hdr, route->map_h_from_addresses)){
   54.72 -	  hdr_node->data = new_hdr;
   54.73 -	  /* we need this list only to carefully free the extra headers: */
   54.74 -	  msgout->xtra_hdr_list =
   54.75 -	    g_list_append(msgout->xtra_hdr_list, new_hdr);
   54.76 -	}else
   54.77 -	  g_free(new_hdr);
   54.78 -      }
   54.79 -    }
   54.80 -  }else{
   54.81 -    /* replace from domain */
   54.82 -    if(route->set_h_from_domain != NULL){
   54.83 -      GList *hdr_node;
   54.84 -      
   54.85 -      foreach(msgout->hdr_list, hdr_node){
   54.86 -	header *hdr = (header *)(hdr_node->data);
   54.87 -	if(hdr->id == HEAD_FROM){
   54.88 -	  header *new_hdr = copy_header(hdr);
   54.89 -	  
   54.90 -	  DEBUG(5) debugf("setting From: domain to %s\n",
   54.91 -			  route->set_h_from_domain);
   54.92 -	  if(set_address_header_domain(new_hdr, route->set_h_from_domain)){
   54.93 -	    hdr_node->data = new_hdr;
   54.94 -	    /* we need this list only to carefully free the extra headers: */
   54.95 -	    DEBUG(6) debugf("header = %s\n",
   54.96 -			    new_hdr->header);
   54.97 -	    msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
   54.98 -	  }else{
   54.99 -	    logwrite(LOG_ALERT, "error in set_address_header_domain(%s, %s)\n",
  54.100 -		     new_hdr->value, route->set_h_from_domain);
  54.101 -	  }
  54.102 +	/* map from addresses */
  54.103 +	if (route->map_h_from_addresses != NULL) {
  54.104 +		GList *hdr_node;
  54.105 +		foreach(msgout->hdr_list, hdr_node) {
  54.106 +			header *hdr = (header *) (hdr_node->data);
  54.107 +			if (hdr->id == HEAD_FROM) {
  54.108 +				header *new_hdr = copy_header(hdr);
  54.109 +				if (map_address_header(new_hdr, route->map_h_from_addresses)) {
  54.110 +					hdr_node->data = new_hdr;
  54.111 +					/* we need this list only to carefully free the extra headers: */
  54.112 +					msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
  54.113 +				} else
  54.114 +					g_free(new_hdr);
  54.115 +			}
  54.116 +		}
  54.117 +	} else {
  54.118 +		/* replace from domain */
  54.119 +		if (route->set_h_from_domain != NULL) {
  54.120 +			GList *hdr_node;
  54.121 +
  54.122 +			foreach(msgout->hdr_list, hdr_node) {
  54.123 +				header *hdr = (header *) (hdr_node->data);
  54.124 +				if (hdr->id == HEAD_FROM) {
  54.125 +					header *new_hdr = copy_header(hdr);
  54.126 +
  54.127 +					DEBUG(5) debugf("setting From: domain to %s\n", route->set_h_from_domain);
  54.128 +					if (set_address_header_domain(new_hdr, route->set_h_from_domain)) {
  54.129 +						hdr_node->data = new_hdr;
  54.130 +						/* we need this list only to carefully free the extra headers: */
  54.131 +						DEBUG(6) debugf("header = %s\n", new_hdr->header);
  54.132 +						msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
  54.133 +					} else {
  54.134 +						logwrite(LOG_ALERT, "error in set_address_header_domain(%s, %s)\n", new_hdr->value, route->set_h_from_domain);
  54.135 +					}
  54.136 +				}
  54.137 +			}
  54.138 +		}
  54.139  	}
  54.140 -      }
  54.141 -    }
  54.142 -  }
  54.143  
  54.144 -  /* map reply-to addresses */
  54.145 -  if(route->map_h_reply_to_addresses != NULL){
  54.146 -    GList *hdr_node;
  54.147 -    foreach(msgout->hdr_list, hdr_node){
  54.148 -      header *hdr = (header *)(hdr_node->data);
  54.149 -      if(hdr->id == HEAD_REPLY_TO){
  54.150 -	header *new_hdr = copy_header(hdr);
  54.151 -	if(map_address_header(new_hdr, route->map_h_reply_to_addresses)){
  54.152 -	  hdr_node->data = new_hdr;
  54.153 -	  /* we need this list only to carefully free the extra headers: */
  54.154 -	  msgout->xtra_hdr_list =
  54.155 -	    g_list_append(msgout->xtra_hdr_list, new_hdr);
  54.156 -	}else
  54.157 -	  g_free(new_hdr);
  54.158 -      }
  54.159 -    }
  54.160 -  }else{
  54.161 -    /* replace Reply-to domain */
  54.162 -    if(route->set_h_reply_to_domain != NULL){
  54.163 -      GList *hdr_node;
  54.164 -      
  54.165 -      foreach(msgout->hdr_list, hdr_node){
  54.166 -	header *hdr = (header *)(hdr_node->data);
  54.167 -	if(hdr->id == HEAD_REPLY_TO){
  54.168 -	  header *new_hdr = copy_header(hdr);
  54.169 -	  
  54.170 -	  set_address_header_domain(new_hdr, route->set_h_reply_to_domain);
  54.171 -	  hdr_node->data = new_hdr;
  54.172 -	  /* we need this list only to carefully free the extra headers: */
  54.173 -	  msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
  54.174 +	/* map reply-to addresses */
  54.175 +	if (route->map_h_reply_to_addresses != NULL) {
  54.176 +		GList *hdr_node;
  54.177 +		foreach(msgout->hdr_list, hdr_node) {
  54.178 +			header *hdr = (header *) (hdr_node->data);
  54.179 +			if (hdr->id == HEAD_REPLY_TO) {
  54.180 +				header *new_hdr = copy_header(hdr);
  54.181 +				if (map_address_header
  54.182 +					(new_hdr, route->map_h_reply_to_addresses)) {
  54.183 +					hdr_node->data = new_hdr;
  54.184 +					/* we need this list only to carefully free the extra headers: */
  54.185 +					msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
  54.186 +				} else
  54.187 +					g_free(new_hdr);
  54.188 +			}
  54.189 +		}
  54.190 +	} else {
  54.191 +		/* replace Reply-to domain */
  54.192 +		if (route->set_h_reply_to_domain != NULL) {
  54.193 +			GList *hdr_node;
  54.194 +
  54.195 +			foreach(msgout->hdr_list, hdr_node) {
  54.196 +				header *hdr = (header *) (hdr_node->data);
  54.197 +				if (hdr->id == HEAD_REPLY_TO) {
  54.198 +					header *new_hdr = copy_header(hdr);
  54.199 +
  54.200 +					set_address_header_domain(new_hdr, route-> set_h_reply_to_domain);
  54.201 +					hdr_node->data = new_hdr;
  54.202 +					/* we need this list only to carefully free the extra headers: */
  54.203 +					msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
  54.204 +				}
  54.205 +			}
  54.206 +		}
  54.207  	}
  54.208 -      }
  54.209 -    }
  54.210 -  }
  54.211  
  54.212 -  /* map Mail-Followup-To addresses */
  54.213 -  if(route->map_h_mail_followup_to_addresses != NULL){
  54.214 -    GList *hdr_node;
  54.215 -    foreach(msgout->hdr_list, hdr_node){
  54.216 -      header *hdr = (header *)(hdr_node->data);
  54.217 -      if(strncasecmp(hdr->header, "Mail-Followup-To", 16) == 0){
  54.218 -	header *new_hdr = copy_header(hdr);
  54.219 -	if(map_address_header(new_hdr, route->map_h_mail_followup_to_addresses)){
  54.220 -	  hdr_node->data = new_hdr;
  54.221 -	  /* we need this list only to carefully free the extra headers: */
  54.222 -	  msgout->xtra_hdr_list =
  54.223 -	    g_list_append(msgout->xtra_hdr_list, new_hdr);
  54.224 -	}else
  54.225 -	  g_free(new_hdr);
  54.226 -      }
  54.227 -    }
  54.228 -  }
  54.229 +	/* map Mail-Followup-To addresses */
  54.230 +	if (route->map_h_mail_followup_to_addresses != NULL) {
  54.231 +		GList *hdr_node;
  54.232 +		foreach(msgout->hdr_list, hdr_node) {
  54.233 +			header *hdr = (header *) (hdr_node->data);
  54.234 +			if (strncasecmp(hdr->header, "Mail-Followup-To", 16) == 0) {
  54.235 +				header *new_hdr = copy_header(hdr);
  54.236 +				if (map_address_header(new_hdr, route->map_h_mail_followup_to_addresses)) {
  54.237 +					hdr_node->data = new_hdr;
  54.238 +					/* we need this list only to carefully free the extra headers: */
  54.239 +					msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
  54.240 +				} else
  54.241 +					g_free(new_hdr);
  54.242 +			}
  54.243 +		}
  54.244 +	}
  54.245  
  54.246 -  /* set Sender: domain to return_path->domain */
  54.247 -  if(route->expand_h_sender_domain){
  54.248 -    GList *hdr_node;
  54.249 +	/* set Sender: domain to return_path->domain */
  54.250 +	if (route->expand_h_sender_domain) {
  54.251 +		GList *hdr_node;
  54.252  
  54.253 -    foreach(msgout->hdr_list, hdr_node){
  54.254 -      header *hdr = (header *)(hdr_node->data);
  54.255 -      if(hdr->id == HEAD_SENDER){
  54.256 -	header *new_hdr = copy_header(hdr);
  54.257 +		foreach(msgout->hdr_list, hdr_node) {
  54.258 +			header *hdr = (header *) (hdr_node->data);
  54.259 +			if (hdr->id == HEAD_SENDER) {
  54.260 +				header *new_hdr = copy_header(hdr);
  54.261  
  54.262 -	set_address_header_domain(new_hdr, msgout->return_path->domain);
  54.263 -	hdr_node->data = new_hdr;
  54.264 -	/* we need this list only to carefully free the extra headers: */
  54.265 -	msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
  54.266 -      }
  54.267 -    }
  54.268 -  }
  54.269 +				set_address_header_domain(new_hdr, msgout->return_path->domain);
  54.270 +				hdr_node->data = new_hdr;
  54.271 +				/* we need this list only to carefully free the extra headers: */
  54.272 +				msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
  54.273 +			}
  54.274 +		}
  54.275 +	}
  54.276  
  54.277 -  /* set Sender: domain to return_path->domain */
  54.278 -  if(route->expand_h_sender_address){
  54.279 -    GList *hdr_node;
  54.280 +	/* set Sender: domain to return_path->domain */
  54.281 +	if (route->expand_h_sender_address) {
  54.282 +		GList *hdr_node;
  54.283  
  54.284 -    foreach(msgout->hdr_list, hdr_node){
  54.285 -      header *hdr = (header *)(hdr_node->data);
  54.286 -      if(hdr->id == HEAD_SENDER){
  54.287 -	header *new_hdr;
  54.288 +		foreach(msgout->hdr_list, hdr_node) {
  54.289 +			header *hdr = (header *) (hdr_node->data);
  54.290 +			if (hdr->id == HEAD_SENDER) {
  54.291 +				header *new_hdr;
  54.292  
  54.293 -	new_hdr =
  54.294 -	  create_header(HEAD_SENDER, "Sender: %s@%s\n",
  54.295 -			msgout->return_path->local_part, msgout->return_path->domain);
  54.296 -	hdr_node->data = new_hdr;
  54.297 -	/* we need this list only to carefully free the extra headers: */
  54.298 -	msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
  54.299 -      }
  54.300 -    }
  54.301 -  }
  54.302 +				new_hdr = create_header(HEAD_SENDER, "Sender: %s@%s\n", msgout->return_path->local_part, msgout->return_path->domain);
  54.303 +				hdr_node->data = new_hdr;
  54.304 +				/* we need this list only to carefully free the extra headers: */
  54.305 +				msgout->xtra_hdr_list = g_list_append(msgout->xtra_hdr_list, new_hdr);
  54.306 +			}
  54.307 +		}
  54.308 +	}
  54.309  
  54.310 -  if(msgout->xtra_hdr_list == NULL){
  54.311 -    /* nothing was changed */
  54.312 -    g_list_free(msgout->hdr_list);
  54.313 -    msgout->hdr_list = NULL;
  54.314 -  }
  54.315 -  DEBUG(5) debugf("rewrite_headers() returning\n");
  54.316 +	if (msgout->xtra_hdr_list == NULL) {
  54.317 +		/* nothing was changed */
  54.318 +		g_list_free(msgout->hdr_list);
  54.319 +		msgout->hdr_list = NULL;
  54.320 +	}
  54.321 +	DEBUG(5) debugf("rewrite_headers() returning\n");
  54.322  }
  54.323  
  54.324 -void rcptlist_with_one_of_hostlist(GList *rcpt_list, GList *host_list,
  54.325 -				   GList **p_rcpt_list, GList **p_non_rcpt_list)
  54.326 +void
  54.327 +rcptlist_with_one_of_hostlist(GList * rcpt_list, GList * host_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
  54.328  {
  54.329 -  GList *rcpt_node;
  54.330 +	GList *rcpt_node;
  54.331  
  54.332 -  if(rcpt_list == NULL)
  54.333 -    return;
  54.334 +	if (rcpt_list == NULL)
  54.335 +		return;
  54.336  
  54.337 -  foreach(rcpt_list, rcpt_node){
  54.338 -    address *rcpt = (address *)(rcpt_node->data);
  54.339 -    GList *host_node = NULL;
  54.340 +	foreach(rcpt_list, rcpt_node) {
  54.341 +		address *rcpt = (address *) (rcpt_node->data);
  54.342 +		GList *host_node = NULL;
  54.343  
  54.344 -    foreach(host_list, host_node){
  54.345 -      gchar *host = (gchar *)(host_node->data);
  54.346 -      if(fnmatch(host, rcpt->domain, FNM_CASEFOLD) == 0)
  54.347 -	break;
  54.348 -    }
  54.349 -    if(host_node){
  54.350 -      if(p_rcpt_list)
  54.351 -	*p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
  54.352 -    }else{
  54.353 -      if(p_non_rcpt_list)
  54.354 -	*p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt);
  54.355 -    }
  54.356 +		foreach(host_list, host_node) {
  54.357 +			gchar *host = (gchar *) (host_node->data);
  54.358 +			if (fnmatch(host, rcpt->domain, FNM_CASEFOLD) == 0)
  54.359 +				break;
  54.360 +		}
  54.361 +		if (host_node) {
  54.362 +			if (p_rcpt_list)
  54.363 +				*p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
  54.364 +		} else {
  54.365 +			if (p_non_rcpt_list)
  54.366 +				*p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt);
  54.367 +		}
  54.368  
  54.369 -  }
  54.370 +	}
  54.371  }
  54.372  
  54.373 -void rcptlist_with_addr_is_local(GList *rcpt_list,
  54.374 -				 GList **p_rcpt_list, GList **p_non_rcpt_list)
  54.375 +void
  54.376 +rcptlist_with_addr_is_local(GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
  54.377  {
  54.378 -  GList *rcpt_node;
  54.379 +	GList *rcpt_node;
  54.380  
  54.381 -  if(rcpt_list == NULL)
  54.382 -    return;
  54.383 +	if (rcpt_list == NULL)
  54.384 +		return;
  54.385  
  54.386 -  foreach(rcpt_list, rcpt_node){
  54.387 -    address *rcpt = (address *)(rcpt_node->data);
  54.388 -    if(addr_is_local(rcpt)){
  54.389 -      if(p_rcpt_list)
  54.390 -	*p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
  54.391 -    }else{
  54.392 -      if(p_non_rcpt_list)
  54.393 -	*p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt);
  54.394 -    }
  54.395 +	foreach(rcpt_list, rcpt_node) {
  54.396 +		address *rcpt = (address *) (rcpt_node->data);
  54.397 +		if (addr_is_local(rcpt)) {
  54.398 +			if (p_rcpt_list)
  54.399 +				*p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
  54.400 +		} else {
  54.401 +			if (p_non_rcpt_list)
  54.402 +				*p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt);
  54.403 +		}
  54.404  
  54.405 -  }
  54.406 +	}
  54.407  }
  54.408  
  54.409 -static gint _g_list_addrcmp(gconstpointer a, gconstpointer b)
  54.410 +static gint
  54.411 +_g_list_addrcmp(gconstpointer a, gconstpointer b)
  54.412  {
  54.413 -  return addr_match((address *)a, (address *)b);
  54.414 +	return addr_match((address *) a, (address *) b);
  54.415  }
  54.416  
  54.417 -gboolean route_is_allowed_return_path(connect_route *route, address *ret_path)
  54.418 +gboolean
  54.419 +route_is_allowed_return_path(connect_route * route, address * ret_path)
  54.420  {
  54.421 -  if(route->not_allowed_return_paths != NULL){
  54.422 -    if(g_list_find_custom(route->not_allowed_return_paths, ret_path,
  54.423 -			  _g_list_addrcmp) != NULL){
  54.424 -      return FALSE;
  54.425 -    }
  54.426 -  }
  54.427 -  if(route->allowed_return_paths != NULL){
  54.428 -    if(g_list_find_custom(route->allowed_return_paths, ret_path,
  54.429 -			  _g_list_addrcmp) != NULL){
  54.430 -      return TRUE;
  54.431 -    }else{
  54.432 -      return FALSE;
  54.433 -    }
  54.434 -  }
  54.435 -  return TRUE;
  54.436 +	if (route->not_allowed_return_paths != NULL) {
  54.437 +		if (g_list_find_custom(route->not_allowed_return_paths, ret_path, _g_list_addrcmp) != NULL) {
  54.438 +			return FALSE;
  54.439 +		}
  54.440 +	}
  54.441 +	if (route->allowed_return_paths != NULL) {
  54.442 +		if (g_list_find_custom(route->allowed_return_paths, ret_path, _g_list_addrcmp) != NULL) {
  54.443 +			return TRUE;
  54.444 +		} else {
  54.445 +			return FALSE;
  54.446 +		}
  54.447 +	}
  54.448 +	return TRUE;
  54.449  }
  54.450  
  54.451 -static gint _g_list_strcmp(gconstpointer a, gconstpointer b)
  54.452 +static gint
  54.453 +_g_list_strcmp(gconstpointer a, gconstpointer b)
  54.454  {
  54.455 -  return (gint)strcmp(a, b);
  54.456 +	return (gint) strcmp(a, b);
  54.457  }
  54.458  
  54.459 -gboolean route_is_allowed_mail_local(connect_route *route, address *ret_path)
  54.460 +gboolean
  54.461 +route_is_allowed_mail_local(connect_route * route, address * ret_path)
  54.462  {
  54.463 -  gchar *loc_part = ret_path->local_part;
  54.464 +	gchar *loc_part = ret_path->local_part;
  54.465  
  54.466 -  if(route->not_allowed_mail_locals != NULL){
  54.467 -    if(g_list_find_custom(route->not_allowed_mail_locals, loc_part,
  54.468 -			 _g_list_strcmp) != NULL)
  54.469 -      return FALSE;
  54.470 -  }
  54.471 -  if(route->allowed_mail_locals != NULL){
  54.472 -    if(g_list_find_custom(route->allowed_mail_locals, loc_part,
  54.473 -			  _g_list_strcmp) != NULL)
  54.474 -      return TRUE;
  54.475 -    else
  54.476 -      return FALSE;
  54.477 -  }
  54.478 -  return TRUE;
  54.479 +	if (route->not_allowed_mail_locals != NULL) {
  54.480 +		if (g_list_find_custom(route->not_allowed_mail_locals, loc_part, _g_list_strcmp) != NULL)
  54.481 +			return FALSE;
  54.482 +	}
  54.483 +	if (route->allowed_mail_locals != NULL) {
  54.484 +		if (g_list_find_custom(route->allowed_mail_locals, loc_part, _g_list_strcmp) != NULL)
  54.485 +			return TRUE;
  54.486 +		else
  54.487 +			return FALSE;
  54.488 +	}
  54.489 +	return TRUE;
  54.490  }
  54.491  
  54.492 -/* 
  54.493 +/*
  54.494     Make lists of matching/not matching rcpts.
  54.495     Local domains are NOT regared here, these should be sorted out previously
  54.496  */
  54.497 -void msg_rcptlist_route(connect_route *route, GList *rcpt_list,
  54.498 -			GList **p_rcpt_list, GList **p_non_rcpt_list)
  54.499 +void
  54.500 +msg_rcptlist_route(connect_route * route, GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
  54.501  {
  54.502 -  GList *tmp_list = NULL;
  54.503 -  /* sort out those domains that can be sent over this connection: */
  54.504 -  if(route->allowed_rcpt_domains){
  54.505 -    DEBUG(5) debugf("testing for route->allowed_rcpt_domains\n");
  54.506 -    rcptlist_with_one_of_hostlist(rcpt_list, route->allowed_rcpt_domains, &tmp_list, p_non_rcpt_list);
  54.507 -  }else{
  54.508 -    DEBUG(5) debugf("route->allowed_rcpt_domains == NULL\n");
  54.509 -    tmp_list = g_list_copy(rcpt_list);
  54.510 -  }
  54.511 +	GList *tmp_list = NULL;
  54.512 +	/* sort out those domains that can be sent over this connection: */
  54.513 +	if (route->allowed_rcpt_domains) {
  54.514 +		DEBUG(5) debugf("testing for route->allowed_rcpt_domains\n");
  54.515 +		rcptlist_with_one_of_hostlist(rcpt_list, route->allowed_rcpt_domains, &tmp_list, p_non_rcpt_list);
  54.516 +	} else {
  54.517 +		DEBUG(5) debugf("route->allowed_rcpt_domains == NULL\n");
  54.518 +		tmp_list = g_list_copy(rcpt_list);
  54.519 +	}
  54.520  
  54.521 -  /* sort out those domains that cannot be sent over this connection: */
  54.522 -  rcptlist_with_one_of_hostlist(tmp_list, route->not_allowed_rcpt_domains, p_non_rcpt_list, p_rcpt_list);
  54.523 -  g_list_free(tmp_list);
  54.524 +	/* sort out those domains that cannot be sent over this connection: */
  54.525 +	rcptlist_with_one_of_hostlist(tmp_list, route->not_allowed_rcpt_domains, p_non_rcpt_list, p_rcpt_list);
  54.526 +	g_list_free(tmp_list);
  54.527  }
  54.528  
  54.529 -msg_out *route_prepare_msgout(connect_route *route, msg_out *msgout)
  54.530 +msg_out*
  54.531 +route_prepare_msgout(connect_route * route, msg_out * msgout)
  54.532  {
  54.533 -  message *msg = msgout->msg;
  54.534 -  GList *rcpt_list = msgout->rcpt_list;
  54.535 +	message *msg = msgout->msg;
  54.536 +	GList *rcpt_list = msgout->rcpt_list;
  54.537  
  54.538 -  if(rcpt_list != NULL){
  54.539 -    /* found a few */
  54.540 -    DEBUG(5){
  54.541 -      GList *node;
  54.542 -      debugf("rcpts for routed delivery, route = %s, id = %s\n", route->name, msg->uid);
  54.543 -      foreach(rcpt_list, node){
  54.544 -	address *rcpt = (address *)(node->data);
  54.545 -	debugf("rcpt for routed delivery: <%s@%s>\n",
  54.546 -	       rcpt->local_part, rcpt->domain);
  54.547 -      }
  54.548 -    }
  54.549 -      
  54.550 -    /* rewrite return path
  54.551 -       if there is a table, use that
  54.552 -       if an address is found and if it has a domain, use that
  54.553 -    */
  54.554 -    if(route->map_return_path_addresses){
  54.555 -      address *ret_path = NULL;
  54.556 -      DEBUG(5) debugf("looking up %s in map_return_path_addresses\n",
  54.557 -		      msg->return_path->local_part);
  54.558 -      ret_path =
  54.559 -	(address *)table_find_fnmatch(route->map_return_path_addresses,
  54.560 -			      msg->return_path->local_part);
  54.561 -      if(ret_path){
  54.562 -	DEBUG(5) debugf("found <%s@%s>\n",
  54.563 -			ret_path->local_part, ret_path->domain); 
  54.564 -	if(ret_path->domain == NULL)
  54.565 -	  ret_path->domain =
  54.566 -	    route->set_return_path_domain ?
  54.567 -	    route->set_return_path_domain : msg->return_path->domain;
  54.568 -	msgout->return_path = copy_address(ret_path);
  54.569 -      }
  54.570 -    }
  54.571 -    if(msgout->return_path == NULL){
  54.572 -      DEBUG(5) debugf("setting return path to %s\n",
  54.573 -		      route->set_return_path_domain);
  54.574 -      msgout->return_path =
  54.575 -	copy_modify_address(msg->return_path,
  54.576 -			    NULL, route->set_return_path_domain);
  54.577 -    }
  54.578 -    rewrite_headers(msgout, route);
  54.579 +	if (rcpt_list != NULL) {
  54.580 +		/* found a few */
  54.581 +		DEBUG(5) {
  54.582 +			GList *node;
  54.583 +			debugf("rcpts for routed delivery, route = %s, id = %s\n", route->name, msg->uid);
  54.584 +			foreach(rcpt_list, node) {
  54.585 +				address *rcpt = (address *) (node->data);
  54.586 +				debugf("rcpt for routed delivery: <%s@%s>\n", rcpt->local_part, rcpt->domain);
  54.587 +			}
  54.588 +		}
  54.589  
  54.590 -    return msgout;
  54.591 -  }
  54.592 -  return NULL;
  54.593 +		/* rewrite return path
  54.594 +		   if there is a table, use that
  54.595 +		   if an address is found and if it has a domain, use that
  54.596 +		 */
  54.597 +		if (route->map_return_path_addresses) {
  54.598 +			address *ret_path = NULL;
  54.599 +			DEBUG(5) debugf("looking up %s in map_return_path_addresses\n", msg->return_path->local_part);
  54.600 +			ret_path = (address *) table_find_fnmatch(route->map_return_path_addresses, msg->return_path->local_part);
  54.601 +			if (ret_path) {
  54.602 +				DEBUG(5) debugf("found <%s@%s>\n", ret_path->local_part, ret_path->domain);
  54.603 +				if (ret_path->domain == NULL)
  54.604 +					ret_path->domain = route->set_return_path_domain
  54.605 +					                   ? route->set_return_path_domain
  54.606 +					                   : msg->return_path->domain;
  54.607 +				msgout->return_path = copy_address(ret_path);
  54.608 +			}
  54.609 +		}
  54.610 +		if (msgout->return_path == NULL) {
  54.611 +			DEBUG(5) debugf("setting return path to %s\n", route->set_return_path_domain);
  54.612 +			msgout->return_path = copy_modify_address(msg->return_path, NULL, route->set_return_path_domain);
  54.613 +		}
  54.614 +		rewrite_headers(msgout, route);
  54.615 +
  54.616 +		return msgout;
  54.617 +	}
  54.618 +	return NULL;
  54.619  }
  54.620  
  54.621  /* put msgout's is msgout_list into bins (msgout_perhost structs) for each
  54.622 @@ -367,70 +355,66 @@
  54.623     route param is not used, we leave it here because that may change.
  54.624   */
  54.625  
  54.626 -GList *route_msgout_list(connect_route *route, GList *msgout_list)
  54.627 +GList*
  54.628 +route_msgout_list(connect_route * route, GList * msgout_list)
  54.629  {
  54.630 -  GList *mo_ph_list = NULL;
  54.631 -  GList *msgout_node;
  54.632 +	GList *mo_ph_list = NULL;
  54.633 +	GList *msgout_node;
  54.634  
  54.635 -  foreach(msgout_list, msgout_node){
  54.636 -    msg_out *msgout = (msg_out *)(msgout_node->data);
  54.637 -    msg_out *msgout_new;
  54.638 -    GList *rcpt_list = msgout->rcpt_list;
  54.639 -    GList *rcpt_node;
  54.640 +	foreach(msgout_list, msgout_node) {
  54.641 +		msg_out *msgout = (msg_out *) (msgout_node->data);
  54.642 +		msg_out *msgout_new;
  54.643 +		GList *rcpt_list = msgout->rcpt_list;
  54.644 +		GList *rcpt_node;
  54.645  
  54.646 -    foreach(rcpt_list, rcpt_node){
  54.647 -      address *rcpt = rcpt_node->data;
  54.648 -      msgout_perhost *mo_ph = NULL;
  54.649 -      GList *mo_ph_node = NULL;
  54.650 +		foreach(rcpt_list, rcpt_node) {
  54.651 +			address *rcpt = rcpt_node->data;
  54.652 +			msgout_perhost *mo_ph = NULL;
  54.653 +			GList *mo_ph_node = NULL;
  54.654  
  54.655 -      /* search host in mo_ph_list */
  54.656 -      foreach(mo_ph_list, mo_ph_node){
  54.657 -	mo_ph = (msgout_perhost *)(mo_ph_node->data);
  54.658 -	if(strcasecmp(mo_ph->host, rcpt->domain) == 0)
  54.659 -	  break;
  54.660 -      }
  54.661 -      if(mo_ph_node != NULL){
  54.662 -	/* there is already a rcpt for this host */
  54.663 -	msg_out *msgout_last =
  54.664 -	  (msg_out *)((g_list_last(mo_ph->msgout_list))->data);
  54.665 -	if(msgout_last->msg == msgout->msg){
  54.666 -	  /* if it is also the same message, it must be the last one
  54.667 -	     appended to mo_ph->msgout_list (since outer loop goes through
  54.668 -	     msgout_list) */
  54.669 -	  msgout_last->rcpt_list =
  54.670 -	    g_list_append(msgout_last->rcpt_list, rcpt);
  54.671 -	}else{
  54.672 -	  /* if not, we append a new msgout */
  54.673 -	  /* make a copy of msgout */
  54.674 -	  msgout_new = create_msg_out(msgout->msg);
  54.675 -	  msgout_new->return_path = msgout->return_path;
  54.676 -	  msgout_new->hdr_list = msgout->hdr_list;
  54.677 +			/* search host in mo_ph_list */
  54.678 +			foreach(mo_ph_list, mo_ph_node) {
  54.679 +				mo_ph = (msgout_perhost *) (mo_ph_node->data);
  54.680 +				if (strcasecmp(mo_ph->host, rcpt->domain) == 0)
  54.681 +					break;
  54.682 +			}
  54.683 +			if (mo_ph_node != NULL) {
  54.684 +				/* there is already a rcpt for this host */
  54.685 +				msg_out *msgout_last = (msg_out *) ((g_list_last(mo_ph->msgout_list))->data);
  54.686 +				if (msgout_last->msg == msgout->msg) {
  54.687 +					/* if it is also the same message, it must be the last one
  54.688 +					   appended to mo_ph->msgout_list (since outer loop goes through
  54.689 +					   msgout_list) */
  54.690 +					msgout_last->rcpt_list = g_list_append(msgout_last->rcpt_list, rcpt);
  54.691 +				} else {
  54.692 +					/* if not, we append a new msgout */
  54.693 +					/* make a copy of msgout */
  54.694 +					msgout_new = create_msg_out(msgout->msg);
  54.695 +					msgout_new->return_path = msgout->return_path;
  54.696 +					msgout_new->hdr_list = msgout->hdr_list;
  54.697  
  54.698 -	  /* append our rcpt to it */
  54.699 -	  /* It is the 1st rcpt for this msg to this host,
  54.700 -	     therefore we safely give NULL */
  54.701 -	  msgout_new->rcpt_list = g_list_append(NULL, rcpt);
  54.702 -	  mo_ph->msgout_list =
  54.703 -	    g_list_append(mo_ph->msgout_list, msgout_new);
  54.704 -	}
  54.705 -      }else{
  54.706 -	/* this rcpt to goes to another host */
  54.707 -	mo_ph = create_msgout_perhost(rcpt->domain);
  54.708 -	mo_ph_list = g_list_append(mo_ph_list, mo_ph);
  54.709 +					/* append our rcpt to it */
  54.710 +					/* It is the 1st rcpt for this msg to this host, therefore we safely give NULL */
  54.711 +					msgout_new->rcpt_list = g_list_append(NULL, rcpt);
  54.712 +					mo_ph->msgout_list = g_list_append(mo_ph->msgout_list, msgout_new);
  54.713 +				}
  54.714 +			} else {
  54.715 +				/* this rcpt to goes to another host */
  54.716 +				mo_ph = create_msgout_perhost(rcpt->domain);
  54.717 +				mo_ph_list = g_list_append(mo_ph_list, mo_ph);
  54.718  
  54.719 -	/* make a copy of msgout */
  54.720 -	msgout_new = create_msg_out(msgout->msg);
  54.721 -	msgout_new->return_path = msgout->return_path;
  54.722 -	msgout_new->hdr_list = msgout->hdr_list;
  54.723 -	    
  54.724 -	/* append our rcpt to it */
  54.725 -	/* It is the 1st rcpt for this msg to this host,
  54.726 -	   therefore we safely give NULL */
  54.727 -	msgout_new->rcpt_list = g_list_append(NULL, rcpt);
  54.728 -	mo_ph->msgout_list = g_list_append(mo_ph->msgout_list, msgout_new);
  54.729 -      }/* if mo_ph != NULL */
  54.730 -    }/* foreach(rcpt_list, ... */
  54.731 -  }/* foreach(msgout_list, ... */
  54.732 +				/* make a copy of msgout */
  54.733 +				msgout_new = create_msg_out(msgout->msg);
  54.734 +				msgout_new->return_path = msgout->return_path;
  54.735 +				msgout_new->hdr_list = msgout->hdr_list;
  54.736  
  54.737 -  return mo_ph_list;
  54.738 +				/* append our rcpt to it */
  54.739 +				/* It is the 1st rcpt for this msg to this host, therefore we safely give NULL */
  54.740 +				msgout_new->rcpt_list = g_list_append(NULL, rcpt);
  54.741 +				mo_ph->msgout_list = g_list_append(mo_ph->msgout_list, msgout_new);
  54.742 +			}  /* if mo_ph != NULL */
  54.743 +		}  /* foreach(rcpt_list, ... */
  54.744 +	}  /* foreach(msgout_list, ... */
  54.745 +
  54.746 +	return mo_ph_list;
  54.747  }
    55.1 --- a/src/smtp_in.c	Mon Oct 27 16:21:27 2008 +0100
    55.2 +++ b/src/smtp_in.c	Mon Oct 27 16:23:10 2008 +0100
    55.3 @@ -30,329 +30,329 @@
    55.4  
    55.5  #ifdef ENABLE_SMTP_SERVER
    55.6  
    55.7 -smtp_cmd smtp_cmds[] =
    55.8 -{
    55.9 -  { SMTP_HELO, "HELO", },
   55.10 -  { SMTP_EHLO, "EHLO", },
   55.11 -  { SMTP_MAIL_FROM, "MAIL FROM:", },
   55.12 -  { SMTP_RCPT_TO, "RCPT TO:", },
   55.13 -  { SMTP_DATA, "DATA", },
   55.14 -  { SMTP_QUIT, "QUIT", },
   55.15 -  { SMTP_RSET, "RSET", },
   55.16 -  { SMTP_NOOP, "NOOP", },
   55.17 -  { SMTP_HELP, "HELP" },
   55.18 +smtp_cmd smtp_cmds[] = {
   55.19 +	{SMTP_HELO, "HELO",}
   55.20 +	,
   55.21 +	{SMTP_EHLO, "EHLO",}
   55.22 +	,
   55.23 +	{SMTP_MAIL_FROM, "MAIL FROM:",}
   55.24 +	,
   55.25 +	{SMTP_RCPT_TO, "RCPT TO:",}
   55.26 +	,
   55.27 +	{SMTP_DATA, "DATA",}
   55.28 +	,
   55.29 +	{SMTP_QUIT, "QUIT",}
   55.30 +	,
   55.31 +	{SMTP_RSET, "RSET",}
   55.32 +	,
   55.33 +	{SMTP_NOOP, "NOOP",}
   55.34 +	,
   55.35 +	{SMTP_HELP, "HELP"}
   55.36 +	,
   55.37  };
   55.38  
   55.39 -static
   55.40 -smtp_cmd_id get_id(const gchar *line)
   55.41 +static smtp_cmd_id
   55.42 +get_id(const gchar * line)
   55.43  {
   55.44 -  gint i;
   55.45 -  for(i = 0; i < SMTP_NUM_IDS; i++){
   55.46 -    if(strncasecmp(smtp_cmds[i].cmd, line, strlen(smtp_cmds[i].cmd)) == 0)
   55.47 -      return (smtp_cmd_id)i;
   55.48 -  }
   55.49 -  return SMTP_ERROR;
   55.50 +	gint i;
   55.51 +	for (i = 0; i < SMTP_NUM_IDS; i++) {
   55.52 +		if (strncasecmp(smtp_cmds[i].cmd, line, strlen(smtp_cmds[i].cmd)) == 0)
   55.53 +			return (smtp_cmd_id) i;
   55.54 +	}
   55.55 +	return SMTP_ERROR;
   55.56  }
   55.57  
   55.58  /* this is a quick hack: we expect the address to be syntactically correct
   55.59     and containing the mailbox only:
   55.60  */
   55.61  
   55.62 -static
   55.63 -gboolean get_address(gchar *line, gchar *addr)
   55.64 +static gboolean
   55.65 +get_address(gchar * line, gchar * addr)
   55.66  {
   55.67 -  gchar *p = line, *q = addr;
   55.68 +	gchar *p = line, *q = addr;
   55.69  
   55.70 -  /* skip MAIL FROM: and RCPT TO: */
   55.71 -  while(*p && (*p != ':')) p++;
   55.72 -  p++;
   55.73 +	/* skip MAIL FROM: and RCPT TO: */
   55.74 +	while (*p && (*p != ':'))
   55.75 +		p++;
   55.76 +	p++;
   55.77  
   55.78 -  /* skip spaces: */
   55.79 -  while(*p && isspace(*p)) p++;
   55.80 +	/* skip spaces: */
   55.81 +	while (*p && isspace(*p))
   55.82 +		p++;
   55.83  
   55.84 -  /* get address: */
   55.85 -  while(*p && !isspace(*p) && (q < addr+MAX_ADDRESS-1)) *(q++) = *(p++);
   55.86 -  *q = 0;
   55.87 +	/* get address: */
   55.88 +	while (*p && !isspace(*p) && (q < addr + MAX_ADDRESS - 1))
   55.89 +		*(q++) = *(p++);
   55.90 +	*q = 0;
   55.91  
   55.92 -  return TRUE;
   55.93 +	return TRUE;
   55.94  }
   55.95  
   55.96 -static
   55.97 -smtp_connection *create_base(gchar *remote_host)
   55.98 +static smtp_connection*
   55.99 +create_base(gchar * remote_host)
  55.100  {
  55.101 -  smtp_connection *base = g_malloc(sizeof(smtp_connection));
  55.102 -  if(base){
  55.103 -    base->remote_host = g_strdup(remote_host);
  55.104 +	smtp_connection *base = g_malloc(sizeof(smtp_connection));
  55.105 +	if (base) {
  55.106 +		base->remote_host = g_strdup(remote_host);
  55.107  
  55.108 -    base->prot = PROT_SMTP;
  55.109 -    base->next_id = 0;
  55.110 -    base->helo_seen = 0;
  55.111 -    base->from_seen = 0;
  55.112 -    base->rcpt_seen = 0;
  55.113 -    base->msg = NULL;
  55.114 +		base->prot = PROT_SMTP;
  55.115 +		base->next_id = 0;
  55.116 +		base->helo_seen = 0;
  55.117 +		base->from_seen = 0;
  55.118 +		base->rcpt_seen = 0;
  55.119 +		base->msg = NULL;
  55.120  
  55.121 -    return base;
  55.122 -  }
  55.123 -  return NULL;
  55.124 +		return base;
  55.125 +	}
  55.126 +	return NULL;
  55.127  }
  55.128  
  55.129 -static
  55.130 -void smtp_printf(FILE *out, gchar *fmt, ...)
  55.131 +static void
  55.132 +smtp_printf(FILE * out, gchar * fmt, ...)
  55.133  {
  55.134 -  va_list args;
  55.135 -  va_start(args, fmt);
  55.136 +	va_list args;
  55.137 +	va_start(args, fmt);
  55.138  
  55.139 -  DEBUG(4){
  55.140 -    gchar buf[256];
  55.141 -    va_list args_copy;
  55.142 +	DEBUG(4) {
  55.143 +		gchar buf[256];
  55.144 +		va_list args_copy;
  55.145  
  55.146 -    va_copy(args_copy, args);
  55.147 -    vsnprintf(buf, 255, fmt, args_copy);
  55.148 -    va_end(args_copy);
  55.149 +		va_copy(args_copy, args);
  55.150 +		vsnprintf(buf, 255, fmt, args_copy);
  55.151 +		va_end(args_copy);
  55.152  
  55.153 -    debugf(">>>%s", buf);
  55.154 -  }
  55.155 +		debugf(">>>%s", buf);
  55.156 +	}
  55.157  
  55.158 -  vfprintf(out, fmt, args);  fflush(out);
  55.159 +	vfprintf(out, fmt, args);
  55.160 +	fflush(out);
  55.161  
  55.162 -  va_end(args);
  55.163 +	va_end(args);
  55.164  }
  55.165  
  55.166 -void smtp_in(FILE *in, FILE *out, gchar *remote_host, gchar *ident)
  55.167 +void
  55.168 +smtp_in(FILE * in, FILE * out, gchar * remote_host, gchar * ident)
  55.169  {
  55.170 -  gchar *buffer;
  55.171 -  smtp_cmd_id cmd_id;
  55.172 -  message *msg = NULL;
  55.173 -  smtp_connection *psc;
  55.174 -  int len;
  55.175 +	gchar *buffer;
  55.176 +	smtp_cmd_id cmd_id;
  55.177 +	message *msg = NULL;
  55.178 +	smtp_connection *psc;
  55.179 +	int len;
  55.180  
  55.181 -  DEBUG(5) debugf("smtp_in entered, remote_host = %s\n", remote_host);
  55.182 +	DEBUG(5) debugf("smtp_in entered, remote_host = %s\n", remote_host);
  55.183  
  55.184 -  psc = create_base(remote_host);
  55.185 -  psc->msg = msg;
  55.186 +	psc = create_base(remote_host);
  55.187 +	psc->msg = msg;
  55.188  
  55.189 -  buffer = (gchar *)g_malloc(BUF_LEN);
  55.190 -  if(buffer){
  55.191 -    /* send greeting string, containing ESMTP: */
  55.192 -    smtp_printf(out, "220 %s MasqMail %s ESMTP\r\n",
  55.193 -		conf.host_name, VERSION);
  55.194 -    
  55.195 -    while((len = read_sockline(in, buffer, BUF_LEN, 5*60, READSOCKL_CHUG)) >= 0){
  55.196 -      cmd_id = get_id(buffer);
  55.197 -      
  55.198 -      switch(cmd_id){
  55.199 -      case SMTP_EHLO:
  55.200 -	psc->prot = PROT_ESMTP;
  55.201 -	/* fall through */
  55.202 -      case SMTP_HELO:
  55.203 -	psc->helo_seen = TRUE;
  55.204 +	buffer = (gchar *) g_malloc(BUF_LEN);
  55.205 +	if (buffer) {
  55.206 +		/* send greeting string, containing ESMTP: */
  55.207 +		smtp_printf(out, "220 %s MasqMail %s ESMTP\r\n", conf.host_name, VERSION);
  55.208  
  55.209 -	if(!conf.defer_all){ /* I need this to debug delivery failures */
  55.210 -	  if(psc->prot == PROT_ESMTP){
  55.211 -	    smtp_printf(out, "250-%s Nice to meet you with ESMTP\r\n",
  55.212 -			conf.host_name);
  55.213 -	    /* not yet: fprintf(out, "250-SIZE\r\n"); */
  55.214 -	    smtp_printf(out,
  55.215 -			"250-PIPELINING\r\n"
  55.216 -			"250 HELP\r\n");
  55.217 -	  }else{
  55.218 -	    smtp_printf(out, "250 %s pretty old mailer, huh?\r\n",
  55.219 -			conf.host_name);
  55.220 -	  }
  55.221 -	  break;
  55.222 -	}else{
  55.223 -	  smtp_printf(out, "421 %s service temporarily unavailable.\r\n",
  55.224 -		      conf.host_name);
  55.225 +		while ((len = read_sockline(in, buffer, BUF_LEN, 5 * 60, READSOCKL_CHUG)) >= 0) {
  55.226 +			cmd_id = get_id(buffer);
  55.227 +
  55.228 +			switch (cmd_id) {
  55.229 +			case SMTP_EHLO:
  55.230 +				psc->prot = PROT_ESMTP;
  55.231 +				/* fall through */
  55.232 +			case SMTP_HELO:
  55.233 +				psc->helo_seen = TRUE;
  55.234 +
  55.235 +				if (!conf.defer_all) {  /* I need this to debug delivery failures */
  55.236 +					if (psc->prot == PROT_ESMTP) {
  55.237 +						smtp_printf(out, "250-%s Nice to meet you with ESMTP\r\n", conf.host_name);
  55.238 +						/* not yet: fprintf(out, "250-SIZE\r\n"); */
  55.239 +						smtp_printf(out, "250-PIPELINING\r\n" "250 HELP\r\n");
  55.240 +					} else {
  55.241 +						smtp_printf(out, "250 %s pretty old mailer, huh?\r\n", conf.host_name);
  55.242 +					}
  55.243 +					break;
  55.244 +				} else {
  55.245 +					smtp_printf(out, "421 %s service temporarily unavailable.\r\n", conf.host_name);
  55.246 +				}
  55.247 +
  55.248 +			case SMTP_MAIL_FROM:
  55.249 +				if (psc->helo_seen && !psc->from_seen) {
  55.250 +					gchar buf[MAX_ADDRESS];
  55.251 +					address *addr;
  55.252 +
  55.253 +					msg = create_message();
  55.254 +					msg->received_host = remote_host ? g_strdup(remote_host) : NULL;
  55.255 +					msg->received_prot = psc->prot;
  55.256 +					msg->ident = ident ? g_strdup(ident) : NULL;
  55.257 +					/* get transfer id and increment for next one */
  55.258 +					msg->transfer_id = (psc->next_id)++;
  55.259 +
  55.260 +					get_address(buffer, buf);
  55.261 +					if ((addr = remote_host
  55.262 +					    ? create_address(buf, TRUE)
  55.263 +					    : create_address_qualified(buf, TRUE, conf.host_name))) {
  55.264 +						if (addr->domain != NULL) {
  55.265 +							psc->from_seen = TRUE;
  55.266 +							msg->return_path = addr;
  55.267 +							smtp_printf(out, "250 OK %s is a nice guy.\r\n", addr->address);
  55.268 +						} else {
  55.269 +							smtp_printf(out, "501 return path must be qualified.\r\n", buf);
  55.270 +						}
  55.271 +					} else {
  55.272 +						smtp_printf(out, "501 %s: syntax error.\r\n", buf);
  55.273 +					}
  55.274 +				} else {
  55.275 +					if (!psc->helo_seen)
  55.276 +						smtp_printf(out, "503 need HELO or EHLO\r\n");
  55.277 +					else
  55.278 +						smtp_printf(out, "503 MAIL FROM: already given.\r\n");
  55.279 +				}
  55.280 +				break;
  55.281 +
  55.282 +			case SMTP_RCPT_TO:
  55.283 +
  55.284 +				if (psc->helo_seen && psc->from_seen) {
  55.285 +					char buf[MAX_ADDRESS];
  55.286 +					address *addr;
  55.287 +
  55.288 +					get_address(buffer, buf);
  55.289 +					if ((addr = remote_host
  55.290 +					    ? create_address(buf, TRUE)
  55.291 +					    : create_address_qualified(buf, TRUE, conf.host_name))) {
  55.292 +						if (addr->local_part[0] != '|') {
  55.293 +							if (addr->domain != NULL) {
  55.294 +								gboolean do_relay = conf.do_relay;
  55.295 +								if (!do_relay) {
  55.296 +									if ((do_relay = addr_is_local(msg->return_path))) {
  55.297 +									}
  55.298 +									if (!do_relay) {
  55.299 +										do_relay = addr_is_local(addr);
  55.300 +									}
  55.301 +								}
  55.302 +								if (do_relay) {
  55.303 +									psc->rcpt_seen = TRUE;
  55.304 +									msg->rcpt_list = g_list_append(msg->rcpt_list, addr);
  55.305 +									smtp_printf(out, "250 OK %s is our friend.\r\n", addr->address);
  55.306 +								} else {
  55.307 +									smtp_printf(out, "550 relaying to %s denied.\r\n", addr_string(addr));
  55.308 +								}
  55.309 +							} else {
  55.310 +								smtp_printf(out, "501 recipient address must be qualified.\r\n", buf);
  55.311 +							}
  55.312 +						} else
  55.313 +							smtp_printf(out, "501 %s: no pipe allowed for SMTP connections\r\n", buf);
  55.314 +					} else {
  55.315 +						smtp_printf(out, "501 %s: syntax error in address.\r\n", buf);
  55.316 +					}
  55.317 +				} else {
  55.318 +
  55.319 +					if (!psc->helo_seen)
  55.320 +						smtp_printf(out, "503 need HELO or EHLO.\r\n");
  55.321 +					else
  55.322 +						smtp_printf(out, "503 need MAIL FROM: before RCPT TO:\r\n");
  55.323 +				}
  55.324 +				break;
  55.325 +
  55.326 +			case SMTP_DATA:
  55.327 +				if (psc->helo_seen && psc->rcpt_seen) {
  55.328 +					accept_error err;
  55.329 +
  55.330 +					smtp_printf(out, "354 okay, and do not forget the dot\r\n");
  55.331 +
  55.332 +					if ((err = accept_message(in, msg, conf.do_save_envelope_to ? ACC_SAVE_ENVELOPE_TO : 0)) == AERR_OK) {
  55.333 +						if (spool_write(msg, TRUE)) {
  55.334 +							pid_t pid;
  55.335 +							smtp_printf(out, "250 OK id=%s\r\n", msg->uid);
  55.336 +
  55.337 +							if (remote_host != NULL)
  55.338 +								logwrite(LOG_NOTICE, "%s <= <%s@%s> host=%s with %s\n", msg->uid, msg->return_path->local_part,
  55.339 +								         msg->return_path->domain, remote_host, prot_names[psc->prot]);
  55.340 +							else
  55.341 +								logwrite(LOG_NOTICE, "%s <= <%s@%s> with %s\n", msg->uid, msg->return_path->local_part,
  55.342 +								         msg->return_path->domain, prot_names[psc->prot]);
  55.343 +
  55.344 +							if (!conf.do_queue) {
  55.345 +								if ((pid = fork()) == 0) {
  55.346 +
  55.347 +									if (deliver(msg))
  55.348 +										_exit(EXIT_SUCCESS);
  55.349 +									else
  55.350 +										_exit(EXIT_FAILURE);
  55.351 +
  55.352 +								} else if (pid < 0) {
  55.353 +									logwrite(LOG_ALERT, "could not fork for delivery, id = %s", msg->uid);
  55.354 +								}
  55.355 +							} else {
  55.356 +								DEBUG(1) debugf("queuing forced by configuration or option.\n");
  55.357 +							}
  55.358 +						} else {
  55.359 +							smtp_printf(out, "451 Could not write spool file\r\n");
  55.360 +							return;
  55.361 +						}
  55.362 +					} else {
  55.363 +						switch (err) {
  55.364 +						case AERR_TIMEOUT:
  55.365 +							return;
  55.366 +						case AERR_EOF:
  55.367 +							return;
  55.368 +						default:
  55.369 +							/* should never happen: */
  55.370 +							smtp_printf(out, "451 Unknown error\r\n");
  55.371 +							return;
  55.372 +						}
  55.373 +					}
  55.374 +					psc->rcpt_seen = psc->from_seen = FALSE;
  55.375 +					destroy_message(msg);
  55.376 +					msg = NULL;
  55.377 +				} else {
  55.378 +					if (!psc->helo_seen)
  55.379 +						smtp_printf(out, "503 need HELO or EHLO.\r\n");
  55.380 +					else
  55.381 +						smtp_printf(out, "503 need RCPT TO: before DATA\r\n");
  55.382 +				}
  55.383 +				break;
  55.384 +			case SMTP_QUIT:
  55.385 +				smtp_printf(out, "221 goodbye\r\n");
  55.386 +				if (msg != NULL)
  55.387 +					destroy_message(msg);
  55.388 +				return;
  55.389 +			case SMTP_RSET:
  55.390 +				psc->from_seen = psc->rcpt_seen = FALSE;
  55.391 +				if (msg != NULL)
  55.392 +					destroy_message(msg);
  55.393 +				msg = NULL;
  55.394 +				smtp_printf(out, "250 OK\r\n");
  55.395 +				break;
  55.396 +			case SMTP_NOOP:
  55.397 +				smtp_printf(out, "250 OK\r\n");
  55.398 +				break;
  55.399 +			case SMTP_HELP:
  55.400 +				{
  55.401 +					int i;
  55.402 +
  55.403 +					smtp_printf(out, "214-supported commands:\r\n");
  55.404 +					for (i = 0; i < SMTP_NUM_IDS - 1; i++) {
  55.405 +						smtp_printf(out, "214-%s\r\n", smtp_cmds[i].cmd);
  55.406 +					}
  55.407 +					smtp_printf(out, "214 %s\r\n", smtp_cmds[i].cmd);
  55.408 +				}
  55.409 +				break;
  55.410 +			default:
  55.411 +				smtp_printf(out, "501 command not recognized\r\n");
  55.412 +				DEBUG(1) debugf("command not recognized, was '%s'\n", buffer);
  55.413 +				break;
  55.414 +			}
  55.415 +		}
  55.416 +		switch (len) {
  55.417 +		case -3:
  55.418 +			logwrite(LOG_NOTICE, "connection timed out\n");
  55.419 +			break;
  55.420 +		case -2:
  55.421 +			logwrite(LOG_NOTICE, "line overflow\n");
  55.422 +			break;
  55.423 +		case -1:
  55.424 +			logwrite(LOG_NOTICE, "received EOF\n");
  55.425 +			break;
  55.426 +		default:
  55.427 +			break;
  55.428 +		}
  55.429  	}
  55.430 -
  55.431 -      case SMTP_MAIL_FROM:
  55.432 -	if(psc->helo_seen && !psc->from_seen){
  55.433 -	  gchar buf[MAX_ADDRESS];
  55.434 -	  address *addr;
  55.435 -
  55.436 -	  msg = create_message();
  55.437 -	  msg->received_host = remote_host ? g_strdup(remote_host) : NULL;
  55.438 -	  msg->received_prot = psc->prot;
  55.439 -	  msg->ident = ident ? g_strdup(ident) : NULL;
  55.440 -	  /* get transfer id and increment for next one */
  55.441 -	  msg->transfer_id = (psc->next_id)++;
  55.442 -
  55.443 -	  get_address(buffer, buf);
  55.444 -	  if((addr = remote_host ?
  55.445 -	     create_address(buf, TRUE) :
  55.446 -	      create_address_qualified(buf, TRUE, conf.host_name))){
  55.447 -	    if(addr->domain != NULL){
  55.448 -	      psc->from_seen = TRUE;
  55.449 -	      msg->return_path = addr;
  55.450 -		smtp_printf(out, "250 OK %s is a nice guy.\r\n", addr->address);
  55.451 -	    }else{
  55.452 -	      smtp_printf(out,
  55.453 -			  "501 return path must be qualified.\r\n", buf);
  55.454 -	    }
  55.455 -	  }else{
  55.456 -	    smtp_printf(out, "501 %s: syntax error.\r\n", buf);
  55.457 -	  }
  55.458 -	}else{
  55.459 -	  if(!psc->helo_seen)
  55.460 -	    smtp_printf(out, "503 need HELO or EHLO\r\n");
  55.461 -	  else
  55.462 -	    smtp_printf(out, "503 MAIL FROM: already given.\r\n");
  55.463 -	}
  55.464 -	break;
  55.465 -
  55.466 -      case SMTP_RCPT_TO:
  55.467 -
  55.468 -	if(psc->helo_seen && psc->from_seen){
  55.469 -	  char buf[MAX_ADDRESS];
  55.470 -	  address *addr;
  55.471 -
  55.472 -	  get_address(buffer, buf);
  55.473 -	  if((addr = remote_host ?
  55.474 -	      create_address(buf, TRUE) :
  55.475 -	      create_address_qualified(buf, TRUE, conf.host_name))){
  55.476 -	    if(addr->local_part[0] != '|'){
  55.477 -	      if(addr->domain != NULL){
  55.478 -		gboolean do_relay = conf.do_relay;
  55.479 -		if(!do_relay){
  55.480 -		  if((do_relay = addr_is_local(msg->return_path)));
  55.481 -		  if(!do_relay){
  55.482 -		    do_relay = addr_is_local(addr);
  55.483 -		  }
  55.484 -		}
  55.485 -		if(do_relay){
  55.486 -		  psc->rcpt_seen = TRUE;
  55.487 -		  msg->rcpt_list = g_list_append(msg->rcpt_list, addr);
  55.488 -		  smtp_printf(out, "250 OK %s is our friend.\r\n", addr->address);
  55.489 -		}else{
  55.490 -		  smtp_printf(out, "550 relaying to %s denied.\r\n",
  55.491 -			      addr_string(addr));
  55.492 -		}
  55.493 -	      }else{
  55.494 -		smtp_printf(out,
  55.495 -			    "501 recipient address must be qualified.\r\n", buf);
  55.496 -	      }
  55.497 -	    }else
  55.498 -	      smtp_printf(out, "501 %s: no pipe allowed for SMTP connections\r\n", buf);
  55.499 -	  }else{
  55.500 -	    smtp_printf(out, "501 %s: syntax error in address.\r\n", buf);
  55.501 -	  }
  55.502 -	}else{
  55.503 -
  55.504 -	  if(!psc->helo_seen)
  55.505 -	    smtp_printf(out, "503 need HELO or EHLO.\r\n");
  55.506 -	  else
  55.507 -	    smtp_printf(out, "503 need MAIL FROM: before RCPT TO:\r\n");
  55.508 -	}
  55.509 -	break;
  55.510 -	  
  55.511 -      case SMTP_DATA:
  55.512 -	if(psc->helo_seen && psc->rcpt_seen){
  55.513 -	  accept_error err;
  55.514 -
  55.515 -	  smtp_printf(out, "354 okay, and do not forget the dot\r\n");
  55.516 -
  55.517 -	  if((err = accept_message(in, msg, conf.do_save_envelope_to ? ACC_SAVE_ENVELOPE_TO : 0))
  55.518 -	     == AERR_OK){
  55.519 -	    if(spool_write(msg, TRUE)){
  55.520 -	      pid_t pid;
  55.521 -	      smtp_printf(out, "250 OK id=%s\r\n", msg->uid);
  55.522 -	      
  55.523 -	      if(remote_host != NULL)
  55.524 -		logwrite(LOG_NOTICE, "%s <= <%s@%s> host=%s with %s\n",
  55.525 -			 msg->uid, msg->return_path->local_part,
  55.526 -			 msg->return_path->domain, remote_host,
  55.527 -			 prot_names[psc->prot]);
  55.528 -	      else
  55.529 -		logwrite(LOG_NOTICE, "%s <= <%s@%s> with %s\n",
  55.530 -			 msg->uid, msg->return_path->local_part,
  55.531 -			 msg->return_path->domain,
  55.532 -			 prot_names[psc->prot]);
  55.533 -	      
  55.534 -	      if(!conf.do_queue){
  55.535 -		if((pid = fork()) == 0){
  55.536 -		  
  55.537 -		  if(deliver(msg))
  55.538 -		    _exit(EXIT_SUCCESS);
  55.539 -		  else
  55.540 -		    _exit(EXIT_FAILURE);
  55.541 -		  
  55.542 -		}else if(pid < 0){
  55.543 -		  logwrite(LOG_ALERT, "could not fork for delivery, id = %s",
  55.544 -			   msg->uid);
  55.545 -		}
  55.546 -	      }else{
  55.547 -		DEBUG(1) debugf("queuing forced by configuration or option.\n");
  55.548 -	      }
  55.549 -	    }else{
  55.550 -	      smtp_printf(out, "451 Could not write spool file\r\n");
  55.551 -	      return;
  55.552 -	    }
  55.553 -	  }else{
  55.554 -	    switch(err){
  55.555 -	    case AERR_TIMEOUT:
  55.556 -	      return;
  55.557 -	    case AERR_EOF:
  55.558 -	      return;
  55.559 -	    default:
  55.560 -	      /* should never happen: */
  55.561 -	      smtp_printf(out, "451 Unknown error\r\n");
  55.562 -	      return;
  55.563 -	    }
  55.564 -	  }
  55.565 -	  psc->rcpt_seen = psc->from_seen = FALSE;
  55.566 -	  destroy_message(msg);
  55.567 -	  msg = NULL;
  55.568 -	}else{
  55.569 -	  if(!psc->helo_seen)
  55.570 -	    smtp_printf(out, "503 need HELO or EHLO.\r\n");
  55.571 -	  else
  55.572 -	    smtp_printf(out, "503 need RCPT TO: before DATA\r\n");
  55.573 -	}
  55.574 -	break;
  55.575 -      case SMTP_QUIT:
  55.576 -	smtp_printf(out, "221 goodbye\r\n");
  55.577 -	if(msg != NULL) destroy_message(msg);
  55.578 -	return;
  55.579 -      case SMTP_RSET:
  55.580 -	psc->from_seen = psc->rcpt_seen = FALSE;
  55.581 -	if(msg != NULL)
  55.582 -	  destroy_message(msg);
  55.583 -	msg = NULL;
  55.584 -	smtp_printf(out, "250 OK\r\n");
  55.585 -	break;
  55.586 -      case SMTP_NOOP:
  55.587 -	smtp_printf(out, "250 OK\r\n");
  55.588 -	break;
  55.589 -      case SMTP_HELP:
  55.590 -	{
  55.591 -	  int i;
  55.592 -
  55.593 -	  smtp_printf(out, "214-supported commands:\r\n");
  55.594 -	  for(i = 0; i < SMTP_NUM_IDS-1; i++){
  55.595 -	    smtp_printf(out, "214-%s\r\n", smtp_cmds[i].cmd);
  55.596 -	  }
  55.597 -	  smtp_printf(out, "214 %s\r\n", smtp_cmds[i].cmd);
  55.598 -	}
  55.599 -	break;
  55.600 -      default:
  55.601 -	smtp_printf(out, "501 command not recognized\r\n");
  55.602 -	DEBUG(1) debugf("command not recognized, was '%s'\n", buffer);
  55.603 -	break;
  55.604 -      }
  55.605 -    }
  55.606 -    switch(len){
  55.607 -    case -3:
  55.608 -      logwrite(LOG_NOTICE, "connection timed out\n");
  55.609 -      break;
  55.610 -    case -2:
  55.611 -      logwrite(LOG_NOTICE, "line overflow\n");
  55.612 -      break;
  55.613 -    case -1:
  55.614 -      logwrite(LOG_NOTICE, "received EOF\n");
  55.615 -      break;
  55.616 -    default:
  55.617 -      break;
  55.618 -    }
  55.619 -  }
  55.620  }
  55.621  #endif
    56.1 --- a/src/smtp_out.c	Mon Oct 27 16:21:27 2008 +0100
    56.2 +++ b/src/smtp_out.c	Mon Oct 27 16:23:10 2008 +0100
    56.3 @@ -4,7 +4,7 @@
    56.4   * it under the terms of the GNU General Public License as published by
    56.5   * the Free Software Foundation; either version 2 of the License, or
    56.6   * (at your option) any later version.
    56.7 - * 
    56.8 + *
    56.9   * This program is distributed in the hope that it will be useful,
   56.10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   56.11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   56.12 @@ -47,872 +47,860 @@
   56.13  #include "base64/base64.h"
   56.14  #endif
   56.15  
   56.16 -void destroy_smtpbase(smtp_base *psb)
   56.17 +void
   56.18 +destroy_smtpbase(smtp_base * psb)
   56.19  {
   56.20 -  fclose(psb->in);
   56.21 -  fclose(psb->out);
   56.22 +	fclose(psb->in);
   56.23 +	fclose(psb->out);
   56.24  
   56.25 -  close(psb->sock);
   56.26 +	close(psb->sock);
   56.27  
   56.28 -  if(psb->helo_name) g_free(psb->helo_name);
   56.29 -  if(psb->buffer) g_free(psb->buffer);
   56.30 -  if(psb->auth_names) g_strfreev(psb->auth_names);
   56.31 +	if (psb->helo_name)
   56.32 +		g_free(psb->helo_name);
   56.33 +	if (psb->buffer)
   56.34 +		g_free(psb->buffer);
   56.35 +	if (psb->auth_names)
   56.36 +		g_strfreev(psb->auth_names);
   56.37  
   56.38 -  if(psb->auth_name) g_free(psb->auth_name);
   56.39 -  if(psb->auth_login) g_free(psb->auth_login);
   56.40 -  if(psb->auth_secret) g_free(psb->auth_secret);
   56.41 +	if (psb->auth_name)
   56.42 +		g_free(psb->auth_name);
   56.43 +	if (psb->auth_login)
   56.44 +		g_free(psb->auth_login);
   56.45 +	if (psb->auth_secret)
   56.46 +		g_free(psb->auth_secret);
   56.47  }
   56.48  
   56.49 -gchar *set_heloname(smtp_base *psb, gchar *default_name, gboolean do_correct)
   56.50 +gchar*
   56.51 +set_heloname(smtp_base * psb, gchar * default_name, gboolean do_correct)
   56.52  {
   56.53 -  struct sockaddr_in sname;
   56.54 -  int len = sizeof(struct sockaddr_in);
   56.55 -  struct hostent *host_entry;
   56.56 +	struct sockaddr_in sname;
   56.57 +	int len = sizeof(struct sockaddr_in);
   56.58 +	struct hostent *host_entry;
   56.59  
   56.60 -  if(do_correct){
   56.61 -    getsockname(psb->sock, (struct sockaddr *)(&sname), &len);
   56.62 -    DEBUG(5) debugf("socket: name.sin_addr = %s\n", inet_ntoa(sname.sin_addr));
   56.63 -    host_entry =
   56.64 -      gethostbyaddr((const char *)&(sname.sin_addr),
   56.65 -		    sizeof(sname.sin_addr), AF_INET);
   56.66 -    if(host_entry){
   56.67 -      psb->helo_name = g_strdup(host_entry->h_name);
   56.68 -    }else{
   56.69 -      /* we failed to look up our own name. Instead of giving our local hostname,
   56.70 -	 we may give our IP number to show the server that we are at least
   56.71 -	 willing to be honest. For the really picky ones.*/
   56.72 -      DEBUG(5) debugf("failed to look up own host name.\n");
   56.73 -      psb->helo_name = g_strdup_printf("[%s]", inet_ntoa(sname.sin_addr));
   56.74 -    }
   56.75 -    DEBUG(5) debugf("helo_name = %s\n", psb->helo_name);
   56.76 -  }
   56.77 -  if(psb->helo_name == NULL){
   56.78 -    psb->helo_name = g_strdup(default_name);
   56.79 -  }
   56.80 -  return psb->helo_name;
   56.81 -} 
   56.82 +	if (do_correct) {
   56.83 +		getsockname(psb->sock, (struct sockaddr *) (&sname), &len);
   56.84 +		DEBUG(5) debugf("socket: name.sin_addr = %s\n", inet_ntoa(sname.sin_addr));
   56.85 +		host_entry = gethostbyaddr((const char *) &(sname.sin_addr), sizeof(sname.sin_addr), AF_INET);
   56.86 +		if (host_entry) {
   56.87 +			psb->helo_name = g_strdup(host_entry->h_name);
   56.88 +		} else {
   56.89 +			/* we failed to look up our own name. Instead of giving our local hostname,
   56.90 +			   we may give our IP number to show the server that we are at least
   56.91 +			   willing to be honest. For the really picky ones. */
   56.92 +			DEBUG(5) debugf("failed to look up own host name.\n");
   56.93 +			psb->helo_name = g_strdup_printf("[%s]", inet_ntoa(sname.sin_addr));
   56.94 +		}
   56.95 +		DEBUG(5) debugf("helo_name = %s\n", psb->helo_name);
   56.96 +	}
   56.97 +	if (psb->helo_name == NULL) {
   56.98 +		psb->helo_name = g_strdup(default_name);
   56.99 +	}
  56.100 +	return psb->helo_name;
  56.101 +}
  56.102  
  56.103  #ifdef ENABLE_AUTH
  56.104  
  56.105 -gboolean set_auth(smtp_base *psb, gchar *name, gchar *login, gchar *secret)
  56.106 +gboolean
  56.107 +set_auth(smtp_base * psb, gchar * name, gchar * login, gchar * secret)
  56.108  {
  56.109 -  if((strcasecmp(name, "CRAM-MD5") == 0) ||
  56.110 -     (strcasecmp(name, "LOGIN") == 0)) {
  56.111 -    psb->auth_name = g_strdup(name);
  56.112 -    psb->auth_login = g_strdup(login);
  56.113 -    psb->auth_secret = g_strdup(secret);
  56.114 -    
  56.115 -    return TRUE;
  56.116 -  }
  56.117 -  return FALSE;
  56.118 +	if ((strcasecmp(name, "CRAM-MD5") == 0) || (strcasecmp(name, "LOGIN") == 0)) {
  56.119 +		psb->auth_name = g_strdup(name);
  56.120 +		psb->auth_login = g_strdup(login);
  56.121 +		psb->auth_secret = g_strdup(secret);
  56.122 +
  56.123 +		return TRUE;
  56.124 +	}
  56.125 +	return FALSE;
  56.126  }
  56.127  
  56.128  #endif
  56.129  
  56.130 -static
  56.131 -smtp_base *create_smtpbase(gint sock)
  56.132 +static smtp_base*
  56.133 +create_smtpbase(gint sock)
  56.134  {
  56.135 -  gint dup_sock;
  56.136 +	gint dup_sock;
  56.137  
  56.138 -  smtp_base *psb = (smtp_base *)g_malloc(sizeof(smtp_base));
  56.139 +	smtp_base *psb = (smtp_base *) g_malloc(sizeof(smtp_base));
  56.140  
  56.141 -  psb->sock = sock;
  56.142 +	psb->sock = sock;
  56.143  
  56.144 -  psb->use_esmtp = FALSE;
  56.145 -  psb->use_size = FALSE;
  56.146 -  psb->use_pipelining = FALSE;
  56.147 -  psb->use_auth = FALSE;
  56.148 +	psb->use_esmtp = FALSE;
  56.149 +	psb->use_size = FALSE;
  56.150 +	psb->use_pipelining = FALSE;
  56.151 +	psb->use_auth = FALSE;
  56.152  
  56.153 -  psb->max_size = 0;
  56.154 -  psb->auth_names = NULL;
  56.155 +	psb->max_size = 0;
  56.156 +	psb->auth_names = NULL;
  56.157  
  56.158 -  psb->buffer = (gchar *)g_malloc(SMTP_BUF_LEN);
  56.159 +	psb->buffer = (gchar *) g_malloc(SMTP_BUF_LEN);
  56.160  
  56.161 -  dup_sock = dup(sock);
  56.162 -  psb->out = fdopen(sock, "w");
  56.163 -  psb->in = fdopen(dup_sock, "r");
  56.164 +	dup_sock = dup(sock);
  56.165 +	psb->out = fdopen(sock, "w");
  56.166 +	psb->in = fdopen(dup_sock, "r");
  56.167  
  56.168 -  psb->error = smtp_ok;
  56.169 +	psb->error = smtp_ok;
  56.170  
  56.171 -  psb->helo_name = NULL;
  56.172 -  
  56.173 -  psb->auth_name = psb->auth_login = psb->auth_secret = NULL;
  56.174 +	psb->helo_name = NULL;
  56.175  
  56.176 -  return psb;
  56.177 +	psb->auth_name = psb->auth_login = psb->auth_secret = NULL;
  56.178 +
  56.179 +	return psb;
  56.180  }
  56.181  
  56.182 -static
  56.183 -gboolean read_response(smtp_base *psb, int timeout)
  56.184 +static gboolean
  56.185 +read_response(smtp_base * psb, int timeout)
  56.186  {
  56.187 -  gint buf_pos = 0;
  56.188 -  gchar code[5];
  56.189 -  gint i, len;
  56.190 +	gint buf_pos = 0;
  56.191 +	gchar code[5];
  56.192 +	gint i, len;
  56.193  
  56.194 -  do{
  56.195 -    len = read_sockline(psb->in, &(psb->buffer[buf_pos]),
  56.196 -			SMTP_BUF_LEN - buf_pos, timeout, READSOCKL_CHUG);
  56.197 -    if(len == -3){
  56.198 -      psb->error = smtp_timeout;
  56.199 -      return FALSE;
  56.200 -    }
  56.201 -    else if(len == -2){
  56.202 -      psb->error = smtp_syntax;
  56.203 -      return FALSE;
  56.204 -    }
  56.205 -    else if(len == -1){
  56.206 -      psb->error = smtp_eof;
  56.207 -      return FALSE;
  56.208 -    }
  56.209 -    for(i = 0; i < 4; i++)
  56.210 -      code[i] = psb->buffer[buf_pos+i];
  56.211 -    code[i] = 0;
  56.212 -    psb->last_code = atoi(code);
  56.213 +	do {
  56.214 +		len = read_sockline(psb->in, &(psb->buffer[buf_pos]), SMTP_BUF_LEN - buf_pos, timeout, READSOCKL_CHUG);
  56.215 +		if (len == -3) {
  56.216 +			psb->error = smtp_timeout;
  56.217 +			return FALSE;
  56.218 +		} else if (len == -2) {
  56.219 +			psb->error = smtp_syntax;
  56.220 +			return FALSE;
  56.221 +		} else if (len == -1) {
  56.222 +			psb->error = smtp_eof;
  56.223 +			return FALSE;
  56.224 +		}
  56.225 +		for (i = 0; i < 4; i++)
  56.226 +			code[i] = psb->buffer[buf_pos + i];
  56.227 +		code[i] = 0;
  56.228 +		psb->last_code = atoi(code);
  56.229  
  56.230 -    buf_pos += len;
  56.231 +		buf_pos += len;
  56.232  
  56.233 -  }while(code[3] == '-');
  56.234 +	} while (code[3] == '-');
  56.235  
  56.236 -  return TRUE;
  56.237 +	return TRUE;
  56.238  }
  56.239  
  56.240 -static
  56.241 -gboolean check_response(smtp_base *psb, gboolean after_data)
  56.242 +static gboolean
  56.243 +check_response(smtp_base * psb, gboolean after_data)
  56.244  {
  56.245 -  char c = psb->buffer[0];
  56.246 +	char c = psb->buffer[0];
  56.247  
  56.248 -  if(((c == '2') && !after_data) || ((c == '3') && after_data)){
  56.249 -    psb->error = smtp_ok;
  56.250 -    DEBUG(6) debugf("response OK:'%s' after_date = %d\n", psb->buffer, (int)after_data);
  56.251 -    return TRUE;
  56.252 -  }else{
  56.253 -    if(c == '4')
  56.254 -      psb->error = smtp_trylater;
  56.255 -    else if(c == '5')
  56.256 -      psb->error = smtp_fail;
  56.257 -    else
  56.258 -      psb->error = smtp_syntax;
  56.259 -    DEBUG(6) debugf("response failure:'%s' after_date = %d\n", psb->buffer, (int)after_data);
  56.260 -    return FALSE;
  56.261 -  }
  56.262 +	if (((c == '2') && !after_data) || ((c == '3') && after_data)) {
  56.263 +		psb->error = smtp_ok;
  56.264 +		DEBUG(6) debugf("response OK:'%s' after_date = %d\n", psb->buffer, (int) after_data);
  56.265 +		return TRUE;
  56.266 +	} else {
  56.267 +		if (c == '4')
  56.268 +			psb->error = smtp_trylater;
  56.269 +		else if (c == '5')
  56.270 +			psb->error = smtp_fail;
  56.271 +		else
  56.272 +			psb->error = smtp_syntax;
  56.273 +		DEBUG(6) debugf("response failure:'%s' after_date = %d\n", psb->buffer, (int) after_data);
  56.274 +		return FALSE;
  56.275 +	}
  56.276  }
  56.277  
  56.278 -static
  56.279 -gboolean check_init_response(smtp_base *psb)
  56.280 +static gboolean
  56.281 +check_init_response(smtp_base * psb)
  56.282  {
  56.283 -  if(check_response(psb, FALSE)){
  56.284 -    psb->use_esmtp = (strstr(psb->buffer, "ESMTP") != NULL);
  56.285 +	if (check_response(psb, FALSE)) {
  56.286 +		psb->use_esmtp = (strstr(psb->buffer, "ESMTP") != NULL);
  56.287  
  56.288 -    DEBUG(4) debugf(psb->use_esmtp ? "uses esmtp\n" : "no esmtp\n");
  56.289 +		DEBUG(4) debugf(psb->use_esmtp ? "uses esmtp\n" : "no esmtp\n");
  56.290  
  56.291 -    return TRUE;
  56.292 -  }
  56.293 -  return FALSE;
  56.294 +		return TRUE;
  56.295 +	}
  56.296 +	return FALSE;
  56.297  }
  56.298  
  56.299 -static
  56.300 -gchar *get_response_arg(gchar *response)
  56.301 +static gchar*
  56.302 +get_response_arg(gchar * response)
  56.303  {
  56.304 -  gchar buf[SMTP_BUF_LEN];
  56.305 -  gchar *p = response, *q = buf;
  56.306 +	gchar buf[SMTP_BUF_LEN];
  56.307 +	gchar *p = response, *q = buf;
  56.308  
  56.309 -  while(*p && (*p != '\n') && isspace(*p)) p++;
  56.310 -  if(*p && (*p != '\n')){
  56.311 -    while(*p && (*p != '\n') && (*p != '\r') && (q < buf+SMTP_BUF_LEN-1)) *(q++) = *(p++);
  56.312 -    *q = 0;
  56.313 -    return g_strdup(buf);
  56.314 -  }
  56.315 -  return NULL;
  56.316 +	while (*p && (*p != '\n') && isspace(*p))
  56.317 +		p++;
  56.318 +	if (*p && (*p != '\n')) {
  56.319 +		while (*p && (*p != '\n') && (*p != '\r') && (q < buf + SMTP_BUF_LEN - 1))
  56.320 +			*(q++) = *(p++);
  56.321 +		*q = 0;
  56.322 +		return g_strdup(buf);
  56.323 +	}
  56.324 +	return NULL;
  56.325  }
  56.326  
  56.327 -static
  56.328 -gboolean check_helo_response(smtp_base *psb)
  56.329 +static gboolean
  56.330 +check_helo_response(smtp_base * psb)
  56.331  {
  56.332 -  gchar *ptr = psb->buffer;
  56.333 +	gchar *ptr = psb->buffer;
  56.334  
  56.335 -  if(!check_response(psb, FALSE))
  56.336 -    return FALSE;
  56.337 +	if (!check_response(psb, FALSE))
  56.338 +		return FALSE;
  56.339  
  56.340 -  while(*ptr){
  56.341 -    if(strncasecmp(&(ptr[4]), "SIZE", 4) == 0){
  56.342 -      gchar *arg;
  56.343 -      psb->use_size = TRUE;
  56.344 -      arg = get_response_arg(&(ptr[8]));
  56.345 -      if(arg){
  56.346 -	psb->max_size = atoi(arg);
  56.347 -	g_free(arg);
  56.348 -      }
  56.349 -    }
  56.350 +	while (*ptr) {
  56.351 +		if (strncasecmp(&(ptr[4]), "SIZE", 4) == 0) {
  56.352 +			gchar *arg;
  56.353 +			psb->use_size = TRUE;
  56.354 +			arg = get_response_arg(&(ptr[8]));
  56.355 +			if (arg) {
  56.356 +				psb->max_size = atoi(arg);
  56.357 +				g_free(arg);
  56.358 +			}
  56.359 +		}
  56.360  
  56.361 -    if(strncasecmp(&(ptr[4]), "PIPELINING", 10) == 0)
  56.362 -      psb->use_pipelining = TRUE;
  56.363 +		if (strncasecmp(&(ptr[4]), "PIPELINING", 10) == 0)
  56.364 +			psb->use_pipelining = TRUE;
  56.365  
  56.366 -    if(strncasecmp(&(ptr[4]), "AUTH", 4) == 0){
  56.367 -      if((ptr[8] == ' ') || (ptr[8] == '=') || (ptr[8] == '\t')){ /* not sure about '\t' */
  56.368 -	gchar *arg;
  56.369 -	psb->use_auth = TRUE;
  56.370 -	arg = get_response_arg(&(ptr[9])); /* after several years I finally learnt to count */
  56.371 -	if(arg){
  56.372 -	  psb->auth_names = g_strsplit(arg, " " , 0);
  56.373 -	  g_free(arg);
  56.374 -	  
  56.375 -	  DEBUG(4){
  56.376 -	    gint i = 0;
  56.377 -	    while(psb->auth_names[i]){
  56.378 -	      debugf("offered AUTH %s\n", psb->auth_names[i]);
  56.379 -	      i++;
  56.380 -	    }
  56.381 -	  }
  56.382 +		if (strncasecmp(&(ptr[4]), "AUTH", 4) == 0) {
  56.383 +			if ((ptr[8] == ' ') || (ptr[8] == '=') || (ptr[8] == '\t')) {  /* not sure about '\t' */
  56.384 +				gchar *arg;
  56.385 +				psb->use_auth = TRUE;
  56.386 +				arg = get_response_arg(&(ptr[9]));  /* after several years I finally learnt to count */
  56.387 +				if (arg) {
  56.388 +					psb->auth_names = g_strsplit(arg, " ", 0);
  56.389 +					g_free(arg);
  56.390 +
  56.391 +					DEBUG(4) {
  56.392 +						gint i = 0;
  56.393 +						while (psb->auth_names[i]) {
  56.394 +							debugf("offered AUTH %s\n", psb->auth_names[i]);
  56.395 +							i++;
  56.396 +						}
  56.397 +					}
  56.398 +				}
  56.399 +			}
  56.400 +		}
  56.401 +
  56.402 +		while (*ptr != '\n')
  56.403 +			ptr++;
  56.404 +		ptr++;
  56.405  	}
  56.406 -      }
  56.407 -    }
  56.408  
  56.409 -    while(*ptr != '\n') ptr++;
  56.410 -    ptr++;
  56.411 -  }
  56.412 +	DEBUG(4) {
  56.413 +		debugf(psb->use_size ? "uses SIZE\n" : "no size\n");
  56.414 +		debugf(psb->use_pipelining ? "uses PIPELINING\n" : "no pipelining\n");
  56.415 +		debugf(psb->use_auth ? "uses AUTH\n" : "no auth\n");
  56.416 +	}
  56.417  
  56.418 -  DEBUG(4){
  56.419 -    debugf(psb->use_size ? "uses SIZE\n" : "no size\n");
  56.420 -    debugf(psb->use_pipelining ? "uses PIPELINING\n" : "no pipelining\n");
  56.421 -    debugf(psb->use_auth ? "uses AUTH\n" : "no auth\n");
  56.422 -  }
  56.423 -
  56.424 -  return TRUE;
  56.425 +	return TRUE;
  56.426  }
  56.427  
  56.428 -static
  56.429 -gboolean smtp_helo(smtp_base *psb, gchar *helo)
  56.430 +static gboolean
  56.431 +smtp_helo(smtp_base * psb, gchar * helo)
  56.432  {
  56.433 -  while(TRUE){
  56.434 -    if(psb->use_esmtp){
  56.435 -      fprintf(psb->out, "EHLO %s\r\n", helo); fflush(psb->out);
  56.436 +	while (TRUE) {
  56.437 +		if (psb->use_esmtp) {
  56.438 +			fprintf(psb->out, "EHLO %s\r\n", helo);
  56.439 +			fflush(psb->out);
  56.440  
  56.441 -      DEBUG(4) debugf("EHLO %s\r\n", helo);
  56.442 +			DEBUG(4) debugf("EHLO %s\r\n", helo);
  56.443  
  56.444 -    }else{
  56.445 -      fprintf(psb->out, "HELO %s\r\n", helo); fflush(psb->out);
  56.446 +		} else {
  56.447 +			fprintf(psb->out, "HELO %s\r\n", helo);
  56.448 +			fflush(psb->out);
  56.449  
  56.450 -      DEBUG(4) debugf("HELO %s\r\n", helo);
  56.451 +			DEBUG(4) debugf("HELO %s\r\n", helo);
  56.452  
  56.453 -    }
  56.454 -    
  56.455 -    if(!read_response(psb, SMTP_CMD_TIMEOUT))
  56.456 -      return FALSE;
  56.457 +		}
  56.458  
  56.459 -    if(check_helo_response(psb))
  56.460 -      return TRUE;
  56.461 -    else{
  56.462 -      if(psb->error == smtp_fail){
  56.463 -	if(psb->use_esmtp){
  56.464 -	  /* our guess that server understands EHLO was wrong,
  56.465 -	     try again with HELO
  56.466 -	  */
  56.467 -	  psb->use_esmtp = FALSE;
  56.468 -	}else{
  56.469 -	  /* what sort of server ist THAT ?!
  56.470 -	     give up...
  56.471 -	  */
  56.472 -	  return FALSE;
  56.473 +		if (!read_response(psb, SMTP_CMD_TIMEOUT))
  56.474 +			return FALSE;
  56.475 +
  56.476 +		if (check_helo_response(psb))
  56.477 +			return TRUE;
  56.478 +		else {
  56.479 +			if (psb->error == smtp_fail) {
  56.480 +				if (psb->use_esmtp) {
  56.481 +					/* our guess that server understands EHLO was wrong, try again with HELO */
  56.482 +					psb->use_esmtp = FALSE;
  56.483 +				} else {
  56.484 +					/* what sort of server ist THAT ?!  give up...  */
  56.485 +					return FALSE;
  56.486 +				}
  56.487 +			} else
  56.488 +				return FALSE;
  56.489 +		}
  56.490  	}
  56.491 -      }else
  56.492 -	return FALSE;
  56.493 -    }
  56.494 -  }
  56.495  }
  56.496  
  56.497 -static
  56.498 -void smtp_cmd_mailfrom(smtp_base *psb, address *return_path, guint size)
  56.499 +static void
  56.500 +smtp_cmd_mailfrom(smtp_base * psb, address * return_path, guint size)
  56.501  {
  56.502 -  if(psb->use_size){
  56.503 -    fprintf(psb->out, "MAIL FROM:%s SIZE=%d\r\n",
  56.504 -	    addr_string(return_path), size);
  56.505 -    fflush(psb->out);
  56.506 +	if (psb->use_size) {
  56.507 +		fprintf(psb->out, "MAIL FROM:%s SIZE=%d\r\n", addr_string(return_path), size);
  56.508 +		fflush(psb->out);
  56.509  
  56.510 -    DEBUG(4) debugf("MAIL FROM:%s SIZE=%d\r\n",
  56.511 -		    addr_string(return_path), size);
  56.512 +		DEBUG(4) debugf("MAIL FROM:%s SIZE=%d\r\n", addr_string(return_path), size);
  56.513  
  56.514 -  }else{
  56.515 -    fprintf(psb->out, "MAIL FROM:%s\r\n", addr_string(return_path));
  56.516 -    fflush(psb->out);
  56.517 +	} else {
  56.518 +		fprintf(psb->out, "MAIL FROM:%s\r\n", addr_string(return_path));
  56.519 +		fflush(psb->out);
  56.520  
  56.521 -    DEBUG(4) debugf("MAIL FROM:%s\r\n", addr_string(return_path));
  56.522 -  }
  56.523 +		DEBUG(4) debugf("MAIL FROM:%s\r\n", addr_string(return_path));
  56.524 +	}
  56.525  }
  56.526  
  56.527 -static
  56.528 -void smtp_cmd_rcptto(smtp_base *psb, address *rcpt)
  56.529 +static void
  56.530 +smtp_cmd_rcptto(smtp_base * psb, address * rcpt)
  56.531  {
  56.532 -  fprintf(psb->out, "RCPT TO:%s\r\n", addr_string(rcpt));
  56.533 -  fflush(psb->out);
  56.534 -  DEBUG(4) debugf("RCPT TO:%s\n", addr_string(rcpt));
  56.535 +	fprintf(psb->out, "RCPT TO:%s\r\n", addr_string(rcpt));
  56.536 +	fflush(psb->out);
  56.537 +	DEBUG(4) debugf("RCPT TO:%s\n", addr_string(rcpt));
  56.538  }
  56.539  
  56.540 -static
  56.541 -void send_data_line(smtp_base *psb, gchar *data)
  56.542 +static void
  56.543 +send_data_line(smtp_base * psb, gchar * data)
  56.544  {
  56.545 -  /* According to RFC 821 each line should be terminated with CRLF.
  56.546 -     Since a dot on a line itself marks the end of data, each line
  56.547 -     beginning with a dot is prepended with another dot.
  56.548 -  */
  56.549 -  gchar *ptr;
  56.550 -  gboolean new_line = TRUE; /* previous versions assumed that each item was
  56.551 -			       exactly one line. This is no longer the case */
  56.552 +	/* According to RFC 821 each line should be terminated with CRLF.
  56.553 +	   Since a dot on a line itself marks the end of data, each line
  56.554 +	   beginning with a dot is prepended with another dot.
  56.555 +	 */
  56.556 +	gchar *ptr;
  56.557 +	gboolean new_line = TRUE;  /* previous versions assumed that each item was exactly one line. This is no longer the case */
  56.558  
  56.559 -  ptr = data;
  56.560 -  while(*ptr){
  56.561 -    int c = (int)(*ptr);
  56.562 -    if(c == '.')
  56.563 -      if(new_line)
  56.564 -	putc('.', psb->out);
  56.565 -    if(c == '\n'){
  56.566 -      putc('\r', psb->out);
  56.567 -      putc('\n', psb->out);
  56.568 -      new_line = TRUE;
  56.569 -    }else{
  56.570 -      putc(c, psb->out);
  56.571 -      new_line = FALSE;
  56.572 -    }
  56.573 -    ptr++;
  56.574 -  }
  56.575 +	ptr = data;
  56.576 +	while (*ptr) {
  56.577 +		int c = (int) (*ptr);
  56.578 +		if (c == '.')
  56.579 +			if (new_line)
  56.580 +				putc('.', psb->out);
  56.581 +		if (c == '\n') {
  56.582 +			putc('\r', psb->out);
  56.583 +			putc('\n', psb->out);
  56.584 +			new_line = TRUE;
  56.585 +		} else {
  56.586 +			putc(c, psb->out);
  56.587 +			new_line = FALSE;
  56.588 +		}
  56.589 +		ptr++;
  56.590 +	}
  56.591  }
  56.592  
  56.593 -static
  56.594 -void send_header(smtp_base *psb, GList *hdr_list)
  56.595 +static void
  56.596 +send_header(smtp_base * psb, GList * hdr_list)
  56.597  {
  56.598 -  GList *node;
  56.599 -  gint num_hdrs = 0;
  56.600 +	GList *node;
  56.601 +	gint num_hdrs = 0;
  56.602  
  56.603 -  /* header */
  56.604 -  if(hdr_list){
  56.605 -    foreach(hdr_list, node){
  56.606 -      if(node->data){
  56.607 -	header *hdr = (header *)(node->data);
  56.608 -	if(hdr->header){
  56.609 -	  send_data_line(psb, hdr->header);
  56.610 -	  num_hdrs++;
  56.611 +	/* header */
  56.612 +	if (hdr_list) {
  56.613 +		foreach(hdr_list, node) {
  56.614 +			if (node->data) {
  56.615 +				header *hdr = (header *) (node->data);
  56.616 +				if (hdr->header) {
  56.617 +					send_data_line(psb, hdr->header);
  56.618 +					num_hdrs++;
  56.619 +				}
  56.620 +			}
  56.621 +		}
  56.622  	}
  56.623 -      }
  56.624 -    }
  56.625 -  }
  56.626  
  56.627 -  /* empty line separating headers from data: */
  56.628 -  putc('\r', psb->out);
  56.629 -  putc('\n', psb->out);
  56.630 +	/* empty line separating headers from data: */
  56.631 +	putc('\r', psb->out);
  56.632 +	putc('\n', psb->out);
  56.633  
  56.634 -  DEBUG(4) debugf("sent %d headers\n", num_hdrs);
  56.635 +	DEBUG(4) debugf("sent %d headers\n", num_hdrs);
  56.636  }
  56.637  
  56.638 -static
  56.639 -void send_data(smtp_base *psb, message *msg)
  56.640 +static void
  56.641 +send_data(smtp_base * psb, message * msg)
  56.642  {
  56.643 -  GList *node;
  56.644 -  gint num_lines = 0;
  56.645 +	GList *node;
  56.646 +	gint num_lines = 0;
  56.647  
  56.648 -  /* data */
  56.649 -  if(msg->data_list){
  56.650 -    for(node = g_list_first(msg->data_list); node; node = g_list_next(node)){
  56.651 -      if(node->data){
  56.652 -	send_data_line(psb, node->data);
  56.653 -	num_lines++;
  56.654 -      }
  56.655 -    }
  56.656 -  }
  56.657 +	/* data */
  56.658 +	if (msg->data_list) {
  56.659 +		for (node = g_list_first(msg->data_list); node; node = g_list_next(node)) {
  56.660 +			if (node->data) {
  56.661 +				send_data_line(psb, node->data);
  56.662 +				num_lines++;
  56.663 +			}
  56.664 +		}
  56.665 +	}
  56.666  
  56.667 -  DEBUG(4) debugf("sent %d lines of data\n", num_lines);
  56.668 +	DEBUG(4) debugf("sent %d lines of data\n", num_lines);
  56.669  
  56.670 -  fprintf(psb->out, ".\r\n");
  56.671 -  fflush(psb->out);
  56.672 +	fprintf(psb->out, ".\r\n");
  56.673 +	fflush(psb->out);
  56.674  }
  56.675  
  56.676 -void smtp_out_mark_rcpts(smtp_base *psb, GList *rcpt_list)
  56.677 +void
  56.678 +smtp_out_mark_rcpts(smtp_base * psb, GList * rcpt_list)
  56.679  {
  56.680 -  GList *rcpt_node;
  56.681 -  for(rcpt_node = g_list_first(rcpt_list);
  56.682 -      rcpt_node;
  56.683 -      rcpt_node = g_list_next(rcpt_node)){
  56.684 -    address *rcpt = (address *)(rcpt_node->data);
  56.685 +	GList *rcpt_node;
  56.686 +	for (rcpt_node = g_list_first(rcpt_list); rcpt_node; rcpt_node = g_list_next(rcpt_node)) {
  56.687 +		address *rcpt = (address *) (rcpt_node->data);
  56.688  
  56.689 -    addr_unmark_delivered(rcpt);
  56.690 +		addr_unmark_delivered(rcpt);
  56.691  
  56.692 -    if((psb->error == smtp_trylater) || (psb->error == smtp_timeout) ||
  56.693 -       (psb->error == smtp_eof)){
  56.694 -      addr_mark_defered(rcpt);
  56.695 -    }else{
  56.696 -      addr_mark_failed(rcpt);
  56.697 -    }
  56.698 -  }
  56.699 +		if ((psb->error == smtp_trylater) || (psb->error == smtp_timeout) || (psb->error == smtp_eof)) {
  56.700 +			addr_mark_defered(rcpt);
  56.701 +		} else {
  56.702 +			addr_mark_failed(rcpt);
  56.703 +		}
  56.704 +	}
  56.705  }
  56.706  
  56.707 -void smtp_out_log_failure(smtp_base *psb, message *msg)
  56.708 +void
  56.709 +smtp_out_log_failure(smtp_base * psb, message * msg)
  56.710  {
  56.711 -  gchar *err_str;
  56.712 +	gchar *err_str;
  56.713  
  56.714 -  if(psb->error == smtp_timeout)
  56.715 -    err_str = g_strdup("connection timed out.");
  56.716 -  else if(psb->error == smtp_eof)
  56.717 -    err_str = g_strdup("connection terminated prematurely.");
  56.718 -  else if(psb->error == smtp_syntax)
  56.719 -    err_str = g_strdup_printf("got unexpected response: %s", psb->buffer);
  56.720 -  else if(psb->error == smtp_cancel)
  56.721 -    err_str = g_strdup("delivery was canceled.\n");
  56.722 -  else
  56.723 -    /* error message should still be in the buffer */
  56.724 -    err_str = g_strdup_printf("failed: %s\n", psb->buffer);
  56.725 +	if (psb->error == smtp_timeout)
  56.726 +		err_str = g_strdup("connection timed out.");
  56.727 +	else if (psb->error == smtp_eof)
  56.728 +		err_str = g_strdup("connection terminated prematurely.");
  56.729 +	else if (psb->error == smtp_syntax)
  56.730 +		err_str = g_strdup_printf("got unexpected response: %s", psb->buffer);
  56.731 +	else if (psb->error == smtp_cancel)
  56.732 +		err_str = g_strdup("delivery was canceled.\n");
  56.733 +	else
  56.734 +		/* error message should still be in the buffer */
  56.735 +		err_str = g_strdup_printf("failed: %s\n", psb->buffer);
  56.736  
  56.737 -  if(msg == NULL)
  56.738 -    logwrite(LOG_NOTICE, "host=%s %s\n",
  56.739 -	     psb->remote_host, err_str);
  56.740 -  else
  56.741 -    logwrite(LOG_NOTICE, "%s == host=%s %s\n",
  56.742 -	     msg->uid, psb->remote_host, err_str);
  56.743 +	if (msg == NULL)
  56.744 +		logwrite(LOG_NOTICE, "host=%s %s\n", psb->remote_host, err_str);
  56.745 +	else
  56.746 +		logwrite(LOG_NOTICE, "%s == host=%s %s\n", msg->uid, psb->remote_host, err_str);
  56.747  
  56.748 -  g_free(err_str);
  56.749 +	g_free(err_str);
  56.750  }
  56.751  
  56.752 -smtp_base *smtp_out_open(gchar *host, gint port, GList *resolve_list)
  56.753 +smtp_base*
  56.754 +smtp_out_open(gchar * host, gint port, GList * resolve_list)
  56.755  {
  56.756 -  smtp_base *psb;
  56.757 -  gint sock;
  56.758 -  mxip_addr *addr;
  56.759 +	smtp_base *psb;
  56.760 +	gint sock;
  56.761 +	mxip_addr *addr;
  56.762  
  56.763 -  DEBUG(5) debugf("smtp_out_open entered, host = %s\n", host);
  56.764 +	DEBUG(5) debugf("smtp_out_open entered, host = %s\n", host);
  56.765  
  56.766 -  if((addr = connect_resolvelist(&sock, host, port, resolve_list))){
  56.767 -    /* create structure to hold status data: */
  56.768 -    psb = create_smtpbase(sock);
  56.769 -    psb->remote_host = addr->name;
  56.770 +	if ((addr = connect_resolvelist(&sock, host, port, resolve_list))) {
  56.771 +		/* create structure to hold status data: */
  56.772 +		psb = create_smtpbase(sock);
  56.773 +		psb->remote_host = addr->name;
  56.774  
  56.775 -    DEBUG(5){
  56.776 -      struct sockaddr_in name;
  56.777 -      int len = sizeof(struct sockaddr);
  56.778 -      getsockname(sock, (struct sockaddr *)(&name), &len);
  56.779 -      debugf("socket: name.sin_addr = %s\n", inet_ntoa(name.sin_addr));
  56.780 -    }
  56.781 -    return psb;
  56.782 -  }else{
  56.783 -    DEBUG(5) debugf("connect_resolvelist failed: %s %s\n", strerror(errno), hstrerror(h_errno));
  56.784 -  }
  56.785 +		DEBUG(5) {
  56.786 +			struct sockaddr_in name;
  56.787 +			int len = sizeof(struct sockaddr);
  56.788 +			getsockname(sock, (struct sockaddr *) (&name), &len);
  56.789 +			debugf("socket: name.sin_addr = %s\n", inet_ntoa(name.sin_addr));
  56.790 +		}
  56.791 +		return psb;
  56.792 +	} else {
  56.793 +		DEBUG(5) debugf("connect_resolvelist failed: %s %s\n", strerror(errno), hstrerror(h_errno));
  56.794 +	}
  56.795  
  56.796 -  return NULL;
  56.797 +	return NULL;
  56.798  }
  56.799  
  56.800 -smtp_base *smtp_out_open_child(gchar *cmd)
  56.801 +smtp_base*
  56.802 +smtp_out_open_child(gchar * cmd)
  56.803  {
  56.804 -  smtp_base *psb;
  56.805 -  gint sock;
  56.806 +	smtp_base *psb;
  56.807 +	gint sock;
  56.808  
  56.809 -  DEBUG(5) debugf("smtp_out_open_child entered, cmd = %s\n", cmd);
  56.810 +	DEBUG(5) debugf("smtp_out_open_child entered, cmd = %s\n", cmd);
  56.811  
  56.812 -  sock = child(cmd);
  56.813 +	sock = child(cmd);
  56.814  
  56.815 -  if(sock > 0){
  56.816 -    psb = create_smtpbase(sock);
  56.817 -    psb->remote_host = NULL;
  56.818 +	if (sock > 0) {
  56.819 +		psb = create_smtpbase(sock);
  56.820 +		psb->remote_host = NULL;
  56.821  
  56.822 -    return psb;
  56.823 -  }
  56.824 +		return psb;
  56.825 +	}
  56.826  
  56.827 -  return NULL;
  56.828 +	return NULL;
  56.829  }
  56.830  
  56.831 -gboolean smtp_out_rset(smtp_base *psb)
  56.832 +gboolean
  56.833 +smtp_out_rset(smtp_base * psb)
  56.834  {
  56.835 -  gboolean ok;
  56.836 -  
  56.837 -  fprintf(psb->out, "RSET\r\n"); fflush(psb->out);
  56.838 -  DEBUG(4) debugf("RSET\n");
  56.839 +	gboolean ok;
  56.840  
  56.841 -  if((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
  56.842 -    if(check_response(psb, FALSE))
  56.843 -      return TRUE;
  56.844 +	fprintf(psb->out, "RSET\r\n");
  56.845 +	fflush(psb->out);
  56.846 +	DEBUG(4) debugf("RSET\n");
  56.847  
  56.848 -  smtp_out_log_failure(psb, NULL);
  56.849 +	if ((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
  56.850 +		if (check_response(psb, FALSE))
  56.851 +			return TRUE;
  56.852  
  56.853 -  return FALSE;
  56.854 +	smtp_out_log_failure(psb, NULL);
  56.855 +
  56.856 +	return FALSE;
  56.857  }
  56.858  
  56.859  #ifdef ENABLE_AUTH
  56.860  
  56.861 -static
  56.862 -gboolean smtp_out_auth_cram_md5(smtp_base *psb)
  56.863 +static gboolean
  56.864 +smtp_out_auth_cram_md5(smtp_base * psb)
  56.865  {
  56.866 -  gboolean ok = FALSE;
  56.867 +	gboolean ok = FALSE;
  56.868  
  56.869 -  fprintf(psb->out, "AUTH CRAM-MD5\r\n"); fflush(psb->out);
  56.870 -  DEBUG(4) debugf("AUTH CRAM-MD5\n");
  56.871 -  if((ok = read_response(psb, SMTP_CMD_TIMEOUT))){
  56.872 -    if((ok = check_response(psb, TRUE))){
  56.873 -      gchar *chall64 = get_response_arg(&(psb->buffer[4]));
  56.874 -      gint chall_size;
  56.875 -      gchar *chall = base64_decode(chall64, &chall_size);
  56.876 -      guchar digest[16], *reply64, *reply;
  56.877 -      gchar digest_string[33];
  56.878 -      gint i;
  56.879 +	fprintf(psb->out, "AUTH CRAM-MD5\r\n");
  56.880 +	fflush(psb->out);
  56.881 +	DEBUG(4) debugf("AUTH CRAM-MD5\n");
  56.882 +	if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
  56.883 +		if ((ok = check_response(psb, TRUE))) {
  56.884 +			gchar *chall64 = get_response_arg(&(psb->buffer[4]));
  56.885 +			gint chall_size;
  56.886 +			gchar *chall = base64_decode(chall64, &chall_size);
  56.887 +			guchar digest[16], *reply64, *reply;
  56.888 +			gchar digest_string[33];
  56.889 +			gint i;
  56.890  #ifdef USE_LIB_CRYPTO
  56.891 -      unsigned int digest_len;
  56.892 +			unsigned int digest_len;
  56.893  #endif
  56.894 -      
  56.895 -      DEBUG(5) debugf("encoded challenge = %s\n", chall64);
  56.896 -      DEBUG(5) debugf("decoded challenge = %s, size = %d\n", chall, chall_size);
  56.897 -      
  56.898 -      DEBUG(5) debugf("secret = %s\n", psb->auth_secret);
  56.899 -      
  56.900 +
  56.901 +			DEBUG(5) debugf("encoded challenge = %s\n", chall64);
  56.902 +			DEBUG(5) debugf("decoded challenge = %s, size = %d\n", chall, chall_size);
  56.903 +
  56.904 +			DEBUG(5) debugf("secret = %s\n", psb->auth_secret);
  56.905 +
  56.906  #ifdef USE_LIB_CRYPTO
  56.907 -      HMAC(EVP_md5(), psb->auth_secret, strlen(psb->auth_secret), chall, chall_size, digest, &digest_len);
  56.908 +			HMAC(EVP_md5(), psb->auth_secret, strlen(psb->auth_secret), chall, chall_size, digest, &digest_len);
  56.909  #else
  56.910 -      hmac_md5(chall, chall_size, psb->auth_secret, strlen(psb->auth_secret), digest);
  56.911 +			hmac_md5(chall, chall_size, psb->auth_secret, strlen(psb->auth_secret), digest);
  56.912  #endif
  56.913 -      
  56.914 -      for(i = 0; i < 16; i++)
  56.915 -	sprintf(&(digest_string[i+i]), "%02x", (unsigned int)(digest[i]));
  56.916 -      digest_string[32] = 0;
  56.917 -      
  56.918 -      DEBUG(5) debugf("digest = %s\n", digest_string);
  56.919 -      
  56.920 -      reply = g_strdup_printf("%s %s", psb->auth_login, digest_string);
  56.921 -      DEBUG(5) debugf("unencoded reply = %s\n", reply);
  56.922 -      
  56.923 -      reply64 = base64_encode(reply, strlen(reply));
  56.924 -      DEBUG(5) debugf("encoded reply = %s\n", reply64);
  56.925 -          
  56.926 -      fprintf(psb->out, "%s\r\n", reply64); fflush(psb->out);
  56.927 -      DEBUG(4) debugf("%s\n", reply64);
  56.928 -          
  56.929 -      if((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
  56.930 -	ok = check_response(psb, FALSE);
  56.931 -          
  56.932 -      g_free(reply64);
  56.933 -      g_free(reply);
  56.934 -      g_free(chall);
  56.935 -      g_free(chall64);
  56.936 -    }
  56.937 -  }
  56.938 -  return ok;
  56.939 +
  56.940 +			for (i = 0; i < 16; i++)
  56.941 +				sprintf(&(digest_string[i + i]), "%02x", (unsigned int) (digest[i]));
  56.942 +			digest_string[32] = 0;
  56.943 +
  56.944 +			DEBUG(5) debugf("digest = %s\n", digest_string);
  56.945 +
  56.946 +			reply = g_strdup_printf("%s %s", psb->auth_login, digest_string);
  56.947 +			DEBUG(5) debugf("unencoded reply = %s\n", reply);
  56.948 +
  56.949 +			reply64 = base64_encode(reply, strlen(reply));
  56.950 +			DEBUG(5) debugf("encoded reply = %s\n", reply64);
  56.951 +
  56.952 +			fprintf(psb->out, "%s\r\n", reply64);
  56.953 +			fflush(psb->out);
  56.954 +			DEBUG(4) debugf("%s\n", reply64);
  56.955 +
  56.956 +			if ((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
  56.957 +				ok = check_response(psb, FALSE);
  56.958 +
  56.959 +			g_free(reply64);
  56.960 +			g_free(reply);
  56.961 +			g_free(chall);
  56.962 +			g_free(chall64);
  56.963 +		}
  56.964 +	}
  56.965 +	return ok;
  56.966  }
  56.967  
  56.968 -static
  56.969 -gboolean smtp_out_auth_login(smtp_base *psb)
  56.970 +static gboolean
  56.971 +smtp_out_auth_login(smtp_base * psb)
  56.972  {
  56.973 -  gboolean ok = FALSE;
  56.974 -  fprintf(psb->out, "AUTH LOGIN\r\n"); fflush(psb->out);
  56.975 -  if((ok = read_response(psb, SMTP_CMD_TIMEOUT))){
  56.976 -    if((ok = check_response(psb, TRUE))){
  56.977 -      gchar *resp64;
  56.978 -      guchar *resp;
  56.979 -      gint resp_size;
  56.980 -      gchar *reply64;
  56.981 -      
  56.982 -      resp64 = get_response_arg(&(psb->buffer[4]));
  56.983 -      DEBUG(5) debugf("encoded response = %s\n", resp64);
  56.984 -      resp = base64_decode(resp64, &resp_size);
  56.985 -      g_free(resp64);
  56.986 -      DEBUG(5) debugf("decoded response = %s, size = %d\n", 
  56.987 -                                        resp, resp_size);
  56.988 -      g_free(resp);
  56.989 -      reply64 = base64_encode(psb->auth_login,
  56.990 -			      strlen(psb->auth_login));
  56.991 -      fprintf(psb->out, "%s\r\n", reply64); fflush(psb->out);
  56.992 -      g_free(reply64);
  56.993 -      if((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
  56.994 -	if ((ok = check_response(psb, TRUE))) {
  56.995 -	  resp64 = get_response_arg(&(psb->buffer[4]));
  56.996 -	  DEBUG(5) debugf("encoded response = %s\n", resp64);
  56.997 -	  resp = base64_decode(resp64, &resp_size);
  56.998 -	  g_free(resp64);
  56.999 -	  DEBUG(5) debugf("decoded response = %s, size = %d\n", 
 56.1000 -			  resp, resp_size);
 56.1001 -	  g_free(resp);
 56.1002 -	  reply64 = base64_encode(psb->auth_secret,
 56.1003 -				  strlen(psb->auth_secret));
 56.1004 -	  fprintf(psb->out, "%s\r\n", reply64); fflush(psb->out);
 56.1005 -	  g_free(reply64);
 56.1006 -	  if((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
 56.1007 -	    ok = check_response(psb, FALSE);
 56.1008 +	gboolean ok = FALSE;
 56.1009 +	fprintf(psb->out, "AUTH LOGIN\r\n");
 56.1010 +	fflush(psb->out);
 56.1011 +	if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
 56.1012 +		if ((ok = check_response(psb, TRUE))) {
 56.1013 +			gchar *resp64;
 56.1014 +			guchar *resp;
 56.1015 +			gint resp_size;
 56.1016 +			gchar *reply64;
 56.1017 +
 56.1018 +			resp64 = get_response_arg(&(psb->buffer[4]));
 56.1019 +			DEBUG(5) debugf("encoded response = %s\n", resp64);
 56.1020 +			resp = base64_decode(resp64, &resp_size);
 56.1021 +			g_free(resp64);
 56.1022 +			DEBUG(5) debugf("decoded response = %s, size = %d\n", resp, resp_size);
 56.1023 +			g_free(resp);
 56.1024 +			reply64 = base64_encode(psb->auth_login, strlen(psb->auth_login));
 56.1025 +			fprintf(psb->out, "%s\r\n", reply64);
 56.1026 +			fflush(psb->out);
 56.1027 +			g_free(reply64);
 56.1028 +			if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
 56.1029 +				if ((ok = check_response(psb, TRUE))) {
 56.1030 +					resp64 = get_response_arg(&(psb->buffer[4]));
 56.1031 +					DEBUG(5) debugf("encoded response = %s\n", resp64);
 56.1032 +					resp = base64_decode(resp64, &resp_size);
 56.1033 +					g_free(resp64);
 56.1034 +					DEBUG(5) debugf("decoded response = %s, size = %d\n", resp, resp_size);
 56.1035 +					g_free(resp);
 56.1036 +					reply64 = base64_encode(psb->auth_secret, strlen(psb->auth_secret));
 56.1037 +					fprintf(psb->out, "%s\r\n", reply64);
 56.1038 +					fflush(psb->out);
 56.1039 +					g_free(reply64);
 56.1040 +					if ((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
 56.1041 +						ok = check_response(psb, FALSE);
 56.1042 +				}
 56.1043 +			}
 56.1044 +		}
 56.1045  	}
 56.1046 -      }          
 56.1047 -    }
 56.1048 -  }
 56.1049 -  return ok;
 56.1050 +	return ok;
 56.1051  }
 56.1052  
 56.1053 -gboolean smtp_out_auth(smtp_base *psb)
 56.1054 +gboolean
 56.1055 +smtp_out_auth(smtp_base * psb)
 56.1056  {
 56.1057 -  gboolean ok = FALSE;
 56.1058 -  gint i = 0;
 56.1059 -  while(psb->auth_names[i]){
 56.1060 -    if(strcasecmp(psb->auth_names[i], psb->auth_name) == 0)
 56.1061 -      break;
 56.1062 -    i++;
 56.1063 -  }
 56.1064 -  if(psb->auth_names[i]){
 56.1065 -    if(strcasecmp(psb->auth_name, "cram-md5") == 0){
 56.1066 -      smtp_out_auth_cram_md5(psb);
 56.1067 -    }else if(strcasecmp(psb->auth_name, "login") == 0){
 56.1068 -      smtp_out_auth_login(psb);
 56.1069 -    }else{
 56.1070 -      logwrite(LOG_ERR, "auth method %s not supported\n",  psb->auth_name);
 56.1071 -    }
 56.1072 -  }else{
 56.1073 -    logwrite(LOG_ERR, "no auth method %s found.\n", psb->auth_name);
 56.1074 -  }
 56.1075 -  return ok;
 56.1076 +	gboolean ok = FALSE;
 56.1077 +	gint i = 0;
 56.1078 +	while (psb->auth_names[i]) {
 56.1079 +		if (strcasecmp(psb->auth_names[i], psb->auth_name) == 0)
 56.1080 +			break;
 56.1081 +		i++;
 56.1082 +	}
 56.1083 +	if (psb->auth_names[i]) {
 56.1084 +		if (strcasecmp(psb->auth_name, "cram-md5") == 0) {
 56.1085 +			smtp_out_auth_cram_md5(psb);
 56.1086 +		} else if (strcasecmp(psb->auth_name, "login") == 0) {
 56.1087 +			smtp_out_auth_login(psb);
 56.1088 +		} else {
 56.1089 +			logwrite(LOG_ERR, "auth method %s not supported\n", psb->auth_name);
 56.1090 +		}
 56.1091 +	} else {
 56.1092 +		logwrite(LOG_ERR, "no auth method %s found.\n", psb->auth_name);
 56.1093 +	}
 56.1094 +	return ok;
 56.1095  }
 56.1096  
 56.1097  #endif
 56.1098  
 56.1099 -gboolean smtp_out_init(smtp_base *psb)
 56.1100 +gboolean
 56.1101 +smtp_out_init(smtp_base * psb)
 56.1102  {
 56.1103 -  gboolean ok;
 56.1104 +	gboolean ok;
 56.1105  
 56.1106 -  if((ok = read_response(psb, SMTP_INITIAL_TIMEOUT))){
 56.1107 -    if((ok = check_init_response(psb))){
 56.1108 - 
 56.1109 -      if((ok = smtp_helo(psb, psb->helo_name))){
 56.1110 +	if ((ok = read_response(psb, SMTP_INITIAL_TIMEOUT))) {
 56.1111 +		if ((ok = check_init_response(psb))) {
 56.1112 +
 56.1113 +			if ((ok = smtp_helo(psb, psb->helo_name))) {
 56.1114  #ifdef ENABLE_AUTH
 56.1115 -	if(psb->auth_name && psb->use_auth){
 56.1116 -	  /* we completely disregard the response of server here. If
 56.1117 -             authentication fails, the server will complain later
 56.1118 -             anyway. I know, this is not polite... */
 56.1119 -	  smtp_out_auth(psb);
 56.1120 +				if (psb->auth_name && psb->use_auth) {
 56.1121 +					/* we completely disregard the response of server here. If
 56.1122 +					   authentication fails, the server will complain later
 56.1123 +					   anyway. I know, this is not polite... */
 56.1124 +					smtp_out_auth(psb);
 56.1125 +				}
 56.1126 +#endif
 56.1127 +			}
 56.1128 +		}
 56.1129  	}
 56.1130 -#endif
 56.1131 -      }
 56.1132 -    }
 56.1133 -  }
 56.1134 -  if(!ok)
 56.1135 -    smtp_out_log_failure(psb, NULL);
 56.1136 -  return ok;
 56.1137 +	if (!ok)
 56.1138 +		smtp_out_log_failure(psb, NULL);
 56.1139 +	return ok;
 56.1140  }
 56.1141  
 56.1142 -gint smtp_out_msg(smtp_base *psb,
 56.1143 -		  message *msg, address *return_path, GList *rcpt_list,
 56.1144 -		  GList *hdr_list)
 56.1145 +gint
 56.1146 +smtp_out_msg(smtp_base * psb, message * msg, address * return_path, GList * rcpt_list, GList * hdr_list)
 56.1147  {
 56.1148 -  gint i, size;
 56.1149 -  gboolean ok = TRUE;
 56.1150 -  int rcpt_cnt;
 56.1151 -  int rcpt_accept = 0;
 56.1152 +	gint i, size;
 56.1153 +	gboolean ok = TRUE;
 56.1154 +	int rcpt_cnt;
 56.1155 +	int rcpt_accept = 0;
 56.1156  
 56.1157 -  DEBUG(5) debugf("smtp_out_msg entered\n");
 56.1158 +	DEBUG(5) debugf("smtp_out_msg entered\n");
 56.1159  
 56.1160 -  /* defaults: */
 56.1161 -  if(return_path == NULL)
 56.1162 -    return_path = msg->return_path;
 56.1163 -  if(hdr_list == NULL)
 56.1164 -    hdr_list = msg->hdr_list;
 56.1165 -  if(rcpt_list == NULL)
 56.1166 -    rcpt_list = msg->rcpt_list;
 56.1167 -  rcpt_cnt = g_list_length(rcpt_list);
 56.1168 +	/* defaults: */
 56.1169 +	if (return_path == NULL)
 56.1170 +		return_path = msg->return_path;
 56.1171 +	if (hdr_list == NULL)
 56.1172 +		hdr_list = msg->hdr_list;
 56.1173 +	if (rcpt_list == NULL)
 56.1174 +		rcpt_list = msg->rcpt_list;
 56.1175 +	rcpt_cnt = g_list_length(rcpt_list);
 56.1176  
 56.1177 -  size = msg_calc_size(msg, TRUE);
 56.1178 +	size = msg_calc_size(msg, TRUE);
 56.1179  
 56.1180 -  /* respect maximum size given by server: */
 56.1181 -  if((psb->max_size > 0) && (size > psb->max_size)){
 56.1182 -    logwrite(LOG_WARNING,
 56.1183 -	     "%s == host=%s message size (%d) > fixed maximum message size of server (%d)",
 56.1184 -	     msg->uid, psb->remote_host, size, psb->max_size);
 56.1185 -    psb->error = smtp_cancel;
 56.1186 -    ok = FALSE;
 56.1187 -  }
 56.1188 +	/* respect maximum size given by server: */
 56.1189 +	if ((psb->max_size > 0) && (size > psb->max_size)) {
 56.1190 +		logwrite(LOG_WARNING, "%s == host=%s message size (%d) > fixed maximum message size of server (%d)",
 56.1191 +		         msg->uid, psb->remote_host, size, psb->max_size);
 56.1192 +		psb->error = smtp_cancel;
 56.1193 +		ok = FALSE;
 56.1194 +	}
 56.1195  
 56.1196 -  if(ok){
 56.1197 -    smtp_cmd_mailfrom(psb, return_path,
 56.1198 -		      psb->use_size ? 
 56.1199 -		      size + SMTP_SIZE_ADD : 0);
 56.1200 -    
 56.1201 -    if(!psb->use_pipelining){
 56.1202 -      if((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
 56.1203 -	ok = check_response(psb, FALSE);
 56.1204 -    }
 56.1205 -  }
 56.1206 -  if(ok){
 56.1207 -    GList *rcpt_node;
 56.1208 -    rcpt_accept = 0;
 56.1209 +	if (ok) {
 56.1210 +		smtp_cmd_mailfrom(psb, return_path, psb->use_size ? size + SMTP_SIZE_ADD : 0);
 56.1211  
 56.1212 -    for(rcpt_node = g_list_first(rcpt_list);
 56.1213 -	rcpt_node != NULL;
 56.1214 -	rcpt_node = g_list_next(rcpt_node)){
 56.1215 -      address *rcpt = (address *)(rcpt_node->data);
 56.1216 -      smtp_cmd_rcptto(psb, rcpt);
 56.1217 -      if(!psb->use_pipelining){
 56.1218 -	if((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
 56.1219 -	  if(check_response(psb, FALSE)){
 56.1220 -	    rcpt_accept++;
 56.1221 -	    addr_mark_delivered(rcpt);
 56.1222 -	  }
 56.1223 -	  else{
 56.1224 -	    /* if server returned an error for one recp. we
 56.1225 -	       may still try the others. But if it is a timeout, eof
 56.1226 -	       or unexpected response, it is more serious and we should
 56.1227 -	       give up. */
 56.1228 -	    if((psb->error != smtp_trylater) &&
 56.1229 -	       (psb->error != smtp_fail)){
 56.1230 -	      ok = FALSE;
 56.1231 -	      break;
 56.1232 -	    }else{
 56.1233 -	      logwrite(LOG_NOTICE, "%s == %s host=%s failed: %s",
 56.1234 -		       msg->uid, addr_string(rcpt),
 56.1235 -		       psb->remote_host, psb->buffer);
 56.1236 -	      if(psb->error == smtp_trylater){
 56.1237 -		addr_mark_defered(rcpt);
 56.1238 -	      }else{
 56.1239 -		addr_mark_failed(rcpt);
 56.1240 -	      }
 56.1241 -	    }
 56.1242 -	  }
 56.1243 -	else
 56.1244 -	  break;
 56.1245 -      }
 56.1246 -    }
 56.1247 +		if (!psb->use_pipelining) {
 56.1248 +			if ((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
 56.1249 +				ok = check_response(psb, FALSE);
 56.1250 +		}
 56.1251 +	}
 56.1252 +	if (ok) {
 56.1253 +		GList *rcpt_node;
 56.1254 +		rcpt_accept = 0;
 56.1255  
 56.1256 -    /* There is no point in going on if no recp.s were accpted.
 56.1257 -       But we can check that at this point only if not pipelining: */
 56.1258 -    ok = (ok && (psb->use_pipelining || (rcpt_accept > 0)));
 56.1259 -    if(ok){
 56.1260 +		for (rcpt_node = g_list_first(rcpt_list); rcpt_node != NULL; rcpt_node = g_list_next(rcpt_node)) {
 56.1261 +			address *rcpt = (address *) (rcpt_node->data);
 56.1262 +			smtp_cmd_rcptto(psb, rcpt);
 56.1263 +			if (!psb->use_pipelining) {
 56.1264 +				if ((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
 56.1265 +					if (check_response(psb, FALSE)) {
 56.1266 +						rcpt_accept++;
 56.1267 +						addr_mark_delivered(rcpt);
 56.1268 +					} else {
 56.1269 +						/* if server returned an error for one recp. we
 56.1270 +						   may still try the others. But if it is a timeout, eof
 56.1271 +						   or unexpected response, it is more serious and we should
 56.1272 +						   give up. */
 56.1273 +						if ((psb->error != smtp_trylater) && (psb->error != smtp_fail)) {
 56.1274 +							ok = FALSE;
 56.1275 +							break;
 56.1276 +						} else {
 56.1277 +							logwrite(LOG_NOTICE, "%s == %s host=%s failed: %s", msg->uid, addr_string(rcpt), psb->remote_host, psb->buffer);
 56.1278 +							if (psb->error == smtp_trylater) {
 56.1279 +								addr_mark_defered(rcpt);
 56.1280 +							} else {
 56.1281 +								addr_mark_failed(rcpt);
 56.1282 +							}
 56.1283 +						}
 56.1284 +				} else
 56.1285 +					break;
 56.1286 +			}
 56.1287 +		}
 56.1288  
 56.1289 -      fprintf(psb->out, "DATA\r\n"); fflush(psb->out);
 56.1290 +		/* There is no point in going on if no recp.s were accpted.
 56.1291 +		   But we can check that at this point only if not pipelining: */
 56.1292 +		ok = (ok && (psb->use_pipelining || (rcpt_accept > 0)));
 56.1293 +		if (ok) {
 56.1294  
 56.1295 -      DEBUG(4) debugf("DATA\r\n");
 56.1296 -	
 56.1297 -      if(psb->use_pipelining){
 56.1298 -	/* the first pl'ed command was MAIL FROM
 56.1299 -	   the last was DATA, whose response can be handled by the 'normal' code
 56.1300 -	   all in between were RCPT TO:
 56.1301 -	*/
 56.1302 -	/* response to MAIL FROM: */
 56.1303 -	if((ok = read_response(psb, SMTP_CMD_TIMEOUT))){
 56.1304 -	  if((ok = check_response(psb, FALSE))){
 56.1305 +			fprintf(psb->out, "DATA\r\n");
 56.1306 +			fflush(psb->out);
 56.1307  
 56.1308 -	    /* response(s) to RCPT TO:
 56.1309 -	       this is very similar to the sequence above for no pipeline
 56.1310 -	    */
 56.1311 -	    for(i = 0; i < rcpt_cnt; i++){
 56.1312 -	      if((ok = read_response(psb, SMTP_CMD_TIMEOUT))){
 56.1313 -		address *rcpt = g_list_nth_data(rcpt_list, i);
 56.1314 -		if(check_response(psb, FALSE)){
 56.1315 -		  rcpt_accept++;
 56.1316 -		  addr_mark_delivered(rcpt);
 56.1317 +			DEBUG(4) debugf("DATA\r\n");
 56.1318 +
 56.1319 +			if (psb->use_pipelining) {
 56.1320 +				/* the first pl'ed command was MAIL FROM
 56.1321 +				   the last was DATA, whose response can be handled by the 'normal' code
 56.1322 +				   all in between were RCPT TO:
 56.1323 +				 */
 56.1324 +				/* response to MAIL FROM: */
 56.1325 +				if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
 56.1326 +					if ((ok = check_response(psb, FALSE))) {
 56.1327 +
 56.1328 +						/* response(s) to RCPT TO:
 56.1329 +						   this is very similar to the sequence above for no pipeline
 56.1330 +						 */
 56.1331 +						for (i = 0; i < rcpt_cnt; i++) {
 56.1332 +							if ((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
 56.1333 +								address *rcpt = g_list_nth_data(rcpt_list, i);
 56.1334 +								if (check_response(psb, FALSE)) {
 56.1335 +									rcpt_accept++;
 56.1336 +									addr_mark_delivered(rcpt);
 56.1337 +								} else {
 56.1338 +									/* if server returned an error 4xx or 5xx for one recp. we
 56.1339 +									   may still try the others. But if it is a timeout, eof
 56.1340 +									   or unexpected response, it is more serious and we
 56.1341 +									   should give up. */
 56.1342 +									if ((psb->error != smtp_trylater) &&
 56.1343 +										(psb->error != smtp_fail)) {
 56.1344 +										ok = FALSE;
 56.1345 +										break;
 56.1346 +									} else {
 56.1347 +										logwrite(LOG_NOTICE, "%s == %s host=%s failed: %s", msg->uid,
 56.1348 +										         addr_string(rcpt), psb->remote_host, psb->buffer);
 56.1349 +										if (psb->error == smtp_trylater) {
 56.1350 +											addr_mark_defered(rcpt);
 56.1351 +										} else {
 56.1352 +											addr_mark_failed(rcpt);
 56.1353 +										}
 56.1354 +									}
 56.1355 +								}
 56.1356 +							} else {
 56.1357 +								DEBUG(5) debugf("check_response failed after RCPT TO\n");
 56.1358 +								break;
 56.1359 +							}
 56.1360 +						}
 56.1361 +						if (rcpt_accept == 0)
 56.1362 +							ok = FALSE;
 56.1363 +					} else {
 56.1364 +						DEBUG(5) debugf("check_response failed after MAIL FROM\n");
 56.1365 +					}
 56.1366 +				} else {
 56.1367 +					DEBUG(5)
 56.1368 +						debugf("read_response failed after MAIL FROM\n");
 56.1369 +				}
 56.1370 +			}
 56.1371 +
 56.1372 +			/* if(psb->use_pipelining) */
 56.1373 +			/* response to the DATA cmd */
 56.1374 +			if (ok) {
 56.1375 +				if (read_response(psb, SMTP_DATA_TIMEOUT)) {
 56.1376 +					if (check_response(psb, TRUE)) {
 56.1377 +						send_header(psb, hdr_list);
 56.1378 +						send_data(psb, msg);
 56.1379 +
 56.1380 +						if (read_response(psb, SMTP_FINAL_TIMEOUT))
 56.1381 +							ok = check_response(psb, FALSE);
 56.1382 +					}
 56.1383 +				}
 56.1384 +			}
 56.1385  		}
 56.1386 -		else{
 56.1387 -		  /* if server returned an error 4xx or 5xx for one recp. we
 56.1388 -		     may still try the others. But if it is a timeout, eof
 56.1389 -		     or unexpected response, it is more serious and we
 56.1390 -		     should give up. */
 56.1391 -		  if((psb->error != smtp_trylater) &&
 56.1392 -		     (psb->error != smtp_fail)){
 56.1393 -		    ok = FALSE;
 56.1394 -		    break;
 56.1395 -		  }else{
 56.1396 -		    logwrite(LOG_NOTICE, "%s == %s host=%s failed: %s",
 56.1397 -			     msg->uid, addr_string(rcpt),
 56.1398 -			     psb->remote_host, psb->buffer);
 56.1399 -		    if(psb->error == smtp_trylater){
 56.1400 -		      addr_mark_defered(rcpt);
 56.1401 -		    }else{
 56.1402 -		      addr_mark_failed(rcpt);
 56.1403 -		    }
 56.1404 -		  }
 56.1405 +	}
 56.1406 +
 56.1407 +	DEBUG(5) {
 56.1408 +		debugf("psb->error = %d\n", psb->error);
 56.1409 +		debugf("ok = %d\n", ok);
 56.1410 +		debugf("rcpt_accept = %d\n", rcpt_accept);
 56.1411 +	}
 56.1412 +
 56.1413 +	if (psb->error == smtp_ok) {
 56.1414 +		GList *rcpt_node;
 56.1415 +		for (rcpt_node = g_list_first(rcpt_list); rcpt_node; rcpt_node = g_list_next(rcpt_node)) {
 56.1416 +			address *rcpt = (address *) (rcpt_node->data);
 56.1417 +			if (addr_is_delivered(rcpt))
 56.1418 +				logwrite(LOG_NOTICE, "%s => %s host=%s with %s\n", msg->uid, addr_string(rcpt),
 56.1419 +				         psb->remote_host, psb->use_esmtp ? "esmtp" : "smtp");
 56.1420  		}
 56.1421 -	      }else{
 56.1422 -		DEBUG(5) debugf("check_response failed after RCPT TO\n");
 56.1423 -		break;
 56.1424 -	      }
 56.1425 -	    }
 56.1426 -	    if(rcpt_accept == 0)
 56.1427 -	      ok = FALSE;
 56.1428 -	  }else{
 56.1429 -	    DEBUG(5) debugf("check_response failed after MAIL FROM\n");
 56.1430 -	  }
 56.1431 -	}else{
 56.1432 -	  DEBUG(5) debugf("read_response failed after MAIL FROM\n");
 56.1433 +	} else {
 56.1434 +		/* if something went wrong,
 56.1435 +		   we have to unmark the rcpts prematurely marked as delivered
 56.1436 +		   and mark the status */
 56.1437 +		smtp_out_mark_rcpts(psb, rcpt_list);
 56.1438 +
 56.1439 +		/* log the failure: */
 56.1440 +		smtp_out_log_failure(psb, msg);
 56.1441  	}
 56.1442 -      } /* if(psb->use_pipelining) */
 56.1443 -
 56.1444 -      /* response to the DATA cmd */
 56.1445 -      if(ok){
 56.1446 -	if(read_response(psb, SMTP_DATA_TIMEOUT)){
 56.1447 -	  if(check_response(psb, TRUE)){
 56.1448 -	    send_header(psb, hdr_list);
 56.1449 -	    send_data(psb, msg);
 56.1450 -	      
 56.1451 -	    if(read_response(psb, SMTP_FINAL_TIMEOUT))
 56.1452 -	      ok = check_response(psb, FALSE);
 56.1453 -	  }
 56.1454 -	}
 56.1455 -      }
 56.1456 -    }
 56.1457 -  }
 56.1458 -
 56.1459 -  DEBUG(5){
 56.1460 -    debugf("psb->error = %d\n", psb->error);
 56.1461 -    debugf("ok = %d\n", ok);
 56.1462 -    debugf("rcpt_accept = %d\n", rcpt_accept);
 56.1463 -  }
 56.1464 -
 56.1465 -  if(psb->error == smtp_ok){
 56.1466 -    GList *rcpt_node;
 56.1467 -    for(rcpt_node = g_list_first(rcpt_list);
 56.1468 -	rcpt_node;
 56.1469 -	rcpt_node = g_list_next(rcpt_node)){
 56.1470 -      address *rcpt = (address *)(rcpt_node->data);
 56.1471 -      if(addr_is_delivered(rcpt))
 56.1472 -	logwrite(LOG_NOTICE, "%s => %s host=%s with %s\n",
 56.1473 -		 msg->uid, addr_string(rcpt), psb->remote_host,
 56.1474 -		 psb->use_esmtp ? "esmtp" : "smtp");
 56.1475 -    }
 56.1476 -  }else{
 56.1477 -    /* if something went wrong,
 56.1478 -       we have to unmark the rcpts prematurely marked as delivered
 56.1479 -       and mark the status */
 56.1480 -    smtp_out_mark_rcpts(psb, rcpt_list);
 56.1481 -
 56.1482 -    /* log the failure: */
 56.1483 -    smtp_out_log_failure(psb, msg);
 56.1484 -  }
 56.1485 -  return rcpt_accept;
 56.1486 +	return rcpt_accept;
 56.1487  }
 56.1488  
 56.1489 -gboolean smtp_out_quit(smtp_base *psb)
 56.1490 +gboolean
 56.1491 +smtp_out_quit(smtp_base * psb)
 56.1492  {
 56.1493 -  fprintf(psb->out, "QUIT\r\n"); fflush(psb->out);
 56.1494 -  
 56.1495 -  DEBUG(4) debugf("QUIT\n");
 56.1496 +	fprintf(psb->out, "QUIT\r\n");
 56.1497 +	fflush(psb->out);
 56.1498  
 56.1499 -  signal(SIGALRM, SIG_DFL);
 56.1500 +	DEBUG(4) debugf("QUIT\n");
 56.1501  
 56.1502 -  return TRUE;
 56.1503 +	signal(SIGALRM, SIG_DFL);
 56.1504 +
 56.1505 +	return TRUE;
 56.1506  }
 56.1507 -  
 56.1508 -gint smtp_deliver(gchar *host, gint port, GList *resolve_list,
 56.1509 -		  message *msg,
 56.1510 -		  address *return_path,
 56.1511 -		  GList *rcpt_list)
 56.1512 +
 56.1513 +gint
 56.1514 +smtp_deliver(gchar * host, gint port, GList * resolve_list, message * msg, address * return_path, GList * rcpt_list)
 56.1515  {
 56.1516 -  smtp_base *psb;
 56.1517 -  smtp_error err;
 56.1518 +	smtp_base *psb;
 56.1519 +	smtp_error err;
 56.1520  
 56.1521 -  DEBUG(5) debugf("smtp_deliver entered\n");
 56.1522 +	DEBUG(5) debugf("smtp_deliver entered\n");
 56.1523  
 56.1524 -  if(return_path == NULL)
 56.1525 -    return_path = msg->return_path;
 56.1526 +	if (return_path == NULL)
 56.1527 +		return_path = msg->return_path;
 56.1528  
 56.1529 -  if((psb = smtp_out_open(host, port, resolve_list))){
 56.1530 -    set_heloname(psb, return_path->domain, TRUE);
 56.1531 -    /* initiate connection, send message and quit: */
 56.1532 -    if(smtp_out_init(psb)){
 56.1533 -      smtp_out_msg(psb, msg, return_path, rcpt_list, NULL);
 56.1534 -      if(psb->error == smtp_ok ||
 56.1535 -	 (psb->error == smtp_fail) ||
 56.1536 -	 (psb->error == smtp_trylater) ||
 56.1537 -	 (psb->error == smtp_syntax) ||
 56.1538 -	 (psb->error == smtp_cancel))
 56.1539 -	
 56.1540 -	smtp_out_quit(psb);
 56.1541 -    }
 56.1542 -    
 56.1543 -    err = psb->error;
 56.1544 -    destroy_smtpbase(psb);
 56.1545 -    
 56.1546 -    return err;
 56.1547 -  }
 56.1548 -  return -1;
 56.1549 +	if ((psb = smtp_out_open(host, port, resolve_list))) {
 56.1550 +		set_heloname(psb, return_path->domain, TRUE);
 56.1551 +		/* initiate connection, send message and quit: */
 56.1552 +		if (smtp_out_init(psb)) {
 56.1553 +			smtp_out_msg(psb, msg, return_path, rcpt_list, NULL);
 56.1554 +			if (psb->error == smtp_ok || (psb->error == smtp_fail) || (psb->error == smtp_trylater)
 56.1555 +			    || (psb->error == smtp_syntax) || (psb->error == smtp_cancel))
 56.1556 +				smtp_out_quit(psb);
 56.1557 +		}
 56.1558 +
 56.1559 +		err = psb->error;
 56.1560 +		destroy_smtpbase(psb);
 56.1561 +
 56.1562 +		return err;
 56.1563 +	}
 56.1564 +	return -1;
 56.1565  }
    57.1 --- a/src/smtp_out.h	Mon Oct 27 16:21:27 2008 +0100
    57.2 +++ b/src/smtp_out.h	Mon Oct 27 16:23:10 2008 +0100
    57.3 @@ -4,7 +4,7 @@
    57.4   * it under the terms of the GNU General Public License as published by
    57.5   * the Free Software Foundation; either version 2 of the License, or
    57.6   * (at your option) any later version.
    57.7 - * 
    57.8 + *
    57.9   * This program is distributed in the hope that it will be useful,
   57.10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   57.11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   57.12 @@ -30,62 +30,55 @@
   57.13  #define SMTP_DATA_TIMEOUT 5*60
   57.14  #define SMTP_FINAL_TIMEOUT 10*60
   57.15  
   57.16 -typedef
   57.17 -enum _smtp_error{
   57.18 -  smtp_ok = 0,   /* mail was delivered to at least one recpient */
   57.19 -  smtp_trylater, /* server responded with 4xx */
   57.20 -  smtp_fail,     /* server responded with 5xx */
   57.21 -  smtp_timeout,  /* connection timed out */
   57.22 -  smtp_eof,      /* got unexpected EOF */
   57.23 -  smtp_syntax,   /* unexpected response */
   57.24 -  smtp_cancel    /* we gave up (eg. size) */
   57.25 +typedef enum _smtp_error {
   57.26 +	smtp_ok = 0,  /* mail was delivered to at least one recpient */
   57.27 +	smtp_trylater,  /* server responded with 4xx */
   57.28 +	smtp_fail,  /* server responded with 5xx */
   57.29 +	smtp_timeout,  /* connection timed out */
   57.30 +	smtp_eof,  /* got unexpected EOF */
   57.31 +	smtp_syntax,  /* unexpected response */
   57.32 +	smtp_cancel  /* we gave up (eg. size) */
   57.33  } smtp_error;
   57.34  
   57.35  
   57.36 -typedef
   57.37 -struct _smtp_base{
   57.38 -  FILE *in;
   57.39 -  FILE *out;
   57.40 +typedef struct _smtp_base {
   57.41 +	FILE *in;
   57.42 +	FILE *out;
   57.43  
   57.44 -  gint sock;
   57.45 -  gint dup_sock;
   57.46 +	gint sock;
   57.47 +	gint dup_sock;
   57.48  
   57.49 -  gchar *remote_host;
   57.50 -  gchar *helo_name;
   57.51 +	gchar *remote_host;
   57.52 +	gchar *helo_name;
   57.53  
   57.54 -  gchar *buffer;
   57.55 -  gint last_code;
   57.56 +	gchar *buffer;
   57.57 +	gint last_code;
   57.58  
   57.59 -  gboolean use_esmtp;
   57.60 -  gboolean use_size;
   57.61 -  gboolean use_pipelining;
   57.62 -  gboolean use_auth;
   57.63 -  
   57.64 -  gint max_size;
   57.65 +	gboolean use_esmtp;
   57.66 +	gboolean use_size;
   57.67 +	gboolean use_pipelining;
   57.68 +	gboolean use_auth;
   57.69  
   57.70 -  gchar **auth_names;
   57.71 +	gint max_size;
   57.72  
   57.73 -  gchar *auth_name;
   57.74 -  gchar *auth_login;
   57.75 -  gchar *auth_secret;
   57.76 +	gchar **auth_names;
   57.77  
   57.78 -  smtp_error error;
   57.79 +	gchar *auth_name;
   57.80 +	gchar *auth_login;
   57.81 +	gchar *auth_secret;
   57.82 +
   57.83 +	smtp_error error;
   57.84  
   57.85  } smtp_base;
   57.86  
   57.87 -gchar *set_heloname(smtp_base *psb, gchar *default_name, gboolean do_correct);
   57.88 -gboolean set_auth(smtp_base *psb, gchar *name, gchar *login, gchar *secret);
   57.89 -void destroy_smtpbase(smtp_base *psb);
   57.90 -smtp_base *smtp_out_open(gchar *host, gint port, GList *resolve_list);
   57.91 -smtp_base *smtp_out_open_child(gchar *cmd);
   57.92 -gboolean smtp_out_rset(smtp_base *psb);
   57.93 -gboolean smtp_out_init(smtp_base *psb);
   57.94 -gint smtp_out_msg(smtp_base *psb,
   57.95 -		  message *msg, address *return_path,
   57.96 -		  GList *rcpt_list, GList *hdr_list);
   57.97 -gboolean smtp_out_quit(smtp_base *psb);
   57.98 +gchar *set_heloname(smtp_base * psb, gchar * default_name, gboolean do_correct);
   57.99 +gboolean set_auth(smtp_base * psb, gchar * name, gchar * login, gchar * secret);
  57.100 +void destroy_smtpbase(smtp_base * psb);
  57.101 +smtp_base *smtp_out_open(gchar * host, gint port, GList * resolve_list);
  57.102 +smtp_base *smtp_out_open_child(gchar * cmd);
  57.103 +gboolean smtp_out_rset(smtp_base * psb);
  57.104 +gboolean smtp_out_init(smtp_base * psb);
  57.105 +gint smtp_out_msg(smtp_base * psb, message * msg, address * return_path, GList * rcpt_list, GList * hdr_list);
  57.106 +gboolean smtp_out_quit(smtp_base * psb);
  57.107  
  57.108 -gint smtp_deliver(gchar *host, gint port, GList *resolve_list,
  57.109 -		  message *msg,
  57.110 -		  address *return_path,
  57.111 -		  GList *rcpt_list);
  57.112 +gint smtp_deliver(gchar * host, gint port, GList * resolve_list, message * msg, address * return_path, GList * rcpt_list);
    58.1 --- a/src/smtpsend.c	Mon Oct 27 16:21:27 2008 +0100
    58.2 +++ b/src/smtpsend.c	Mon Oct 27 16:23:10 2008 +0100
    58.3 @@ -32,83 +32,83 @@
    58.4  extern char *optarg;
    58.5  extern int optind, opterr, optopt;
    58.6  
    58.7 -void logwrite(int pri, const char *fmt, ...)
    58.8 +void
    58.9 +logwrite(int pri, const char *fmt, ...)
   58.10  {
   58.11 -  va_list args;
   58.12 -  va_start(args, fmt);
   58.13 +	va_list args;
   58.14 +	va_start(args, fmt);
   58.15  
   58.16 -  vfprintf(stdout, fmt, args);
   58.17 +	vfprintf(stdout, fmt, args);
   58.18  
   58.19 -  va_end(args);
   58.20 +	va_end(args);
   58.21  }
   58.22  
   58.23 -void debugf(const char *fmt, ...)
   58.24 +void
   58.25 +debugf(const char *fmt, ...)
   58.26  {
   58.27 -  va_list args;
   58.28 -  va_start(args, fmt);
   58.29 +	va_list args;
   58.30 +	va_start(args, fmt);
   58.31  
   58.32 -  vfprintf(stdout, fmt, args);
   58.33 +	vfprintf(stdout, fmt, args);
   58.34  
   58.35 -  va_end(args);
   58.36 +	va_end(args);
   58.37  }
   58.38  
   58.39  int
   58.40  main(int argc, char *argv[])
   58.41  {
   58.42 -  gchar *helo_name = g_malloc(64);
   58.43 -  gchar *server_name = g_strdup("localhost");
   58.44 -  gint server_port = 25;
   58.45 -  GList *resolve_list = g_list_append(NULL, resolve_byname);
   58.46 +	gchar *helo_name = g_malloc(64);
   58.47 +	gchar *server_name = g_strdup("localhost");
   58.48 +	gint server_port = 25;
   58.49 +	GList *resolve_list = g_list_append(NULL, resolve_byname);
   58.50  
   58.51 -  gethostname(helo_name, 63);
   58.52 +	gethostname(helo_name, 63);
   58.53  
   58.54 -  conf.host_name = g_strdup(helo_name);
   58.55 +	conf.host_name = g_strdup(helo_name);
   58.56  
   58.57 -  while(1){
   58.58 -    int c;
   58.59 -    c = getopt(argc, argv, "d:p:s:H:");
   58.60 -    if(c == -1)
   58.61 -      break;
   58.62 -    switch(c){
   58.63 -    case 'd':
   58.64 -      conf.debug_level = atoi(optarg);
   58.65 -      break;
   58.66 -    case 'p':
   58.67 -      server_port = atoi(optarg);
   58.68 -      break;
   58.69 -    case 's':
   58.70 -      g_free(server_name);
   58.71 -      server_name = g_strdup(optarg);
   58.72 -      break;
   58.73 -    case 'H':
   58.74 -      g_free(helo_name);
   58.75 -      helo_name = g_strdup(optarg);
   58.76 -      break;
   58.77 -    default:
   58.78 -      break;
   58.79 -    }
   58.80 -  }
   58.81 +	while (1) {
   58.82 +		int c;
   58.83 +		c = getopt(argc, argv, "d:p:s:H:");
   58.84 +		if (c == -1)
   58.85 +			break;
   58.86 +		switch (c) {
   58.87 +		case 'd':
   58.88 +			conf.debug_level = atoi(optarg);
   58.89 +			break;
   58.90 +		case 'p':
   58.91 +			server_port = atoi(optarg);
   58.92 +			break;
   58.93 +		case 's':
   58.94 +			g_free(server_name);
   58.95 +			server_name = g_strdup(optarg);
   58.96 +			break;
   58.97 +		case 'H':
   58.98 +			g_free(helo_name);
   58.99 +			helo_name = g_strdup(optarg);
  58.100 +			break;
  58.101 +		default:
  58.102 +			break;
  58.103 +		}
  58.104 +	}
  58.105  
  58.106 -  if (optind < argc){
  58.107 -    gint ret;
  58.108 -    message *msg = create_message();
  58.109 +	if (optind < argc) {
  58.110 +		gint ret;
  58.111 +		message *msg = create_message();
  58.112  
  58.113 -    while (optind < argc){
  58.114 -      msg->rcpt_list =
  58.115 -	g_list_append(msg->rcpt_list,
  58.116 -		      create_address_qualified(argv[optind++], TRUE, conf.host_name));
  58.117 -    }
  58.118 -    
  58.119 -    if((ret = accept_message(stdin, msg, ACC_NODOT_TERM|ACC_HEAD_FROM_RCPT)) == AERR_OK){
  58.120 -      if((ret = smtp_deliver(server_name, server_port, resolve_list, msg, NULL, NULL)) == smtp_ok){
  58.121 -	exit(EXIT_SUCCESS);
  58.122 -      }
  58.123 -      fprintf(stderr, "deliver failed: %d\n", ret);
  58.124 -    }
  58.125 -    fprintf(stderr, "accept failed: %d\n", ret);
  58.126 -    exit(ret);
  58.127 -  }else{
  58.128 -    fprintf(stderr, "no recipients given.\n");
  58.129 -    exit(-1);
  58.130 -  }
  58.131 +		while (optind < argc) {
  58.132 +			msg->rcpt_list = g_list_append(msg->rcpt_list, create_address_qualified(argv[optind++], TRUE, conf.host_name));
  58.133 +		}
  58.134 +
  58.135 +		if ((ret = accept_message(stdin, msg, ACC_NODOT_TERM | ACC_HEAD_FROM_RCPT)) == AERR_OK) {
  58.136 +			if ((ret = smtp_deliver(server_name, server_port, resolve_list, msg, NULL, NULL)) == smtp_ok) {
  58.137 +				exit(EXIT_SUCCESS);
  58.138 +			}
  58.139 +			fprintf(stderr, "deliver failed: %d\n", ret);
  58.140 +		}
  58.141 +		fprintf(stderr, "accept failed: %d\n", ret);
  58.142 +		exit(ret);
  58.143 +	} else {
  58.144 +		fprintf(stderr, "no recipients given.\n");
  58.145 +		exit(-1);
  58.146 +	}
  58.147  }
    59.1 --- a/src/spool.c	Mon Oct 27 16:21:27 2008 +0100
    59.2 +++ b/src/spool.c	Mon Oct 27 16:23:10 2008 +0100
    59.3 @@ -20,418 +20,416 @@
    59.4  #include <sys/stat.h>
    59.5  #include "dotlock.h"
    59.6  
    59.7 -static
    59.8 -gint read_line(FILE *in, gchar *buf, gint buf_len)
    59.9 +static gint
   59.10 +read_line(FILE * in, gchar * buf, gint buf_len)
   59.11  {
   59.12 -  gint p = 0;
   59.13 -  gint c;
   59.14 +	gint p = 0;
   59.15 +	gint c;
   59.16  
   59.17 -  while((c = getc(in)) != '\n' && (c != EOF)){
   59.18 -    if(p >= buf_len-1) { return 0; }
   59.19 -    buf[p++] = c;
   59.20 -  }
   59.21 +	while ((c = getc(in)) != '\n' && (c != EOF)) {
   59.22 +		if (p >= buf_len - 1) {
   59.23 +			return 0;
   59.24 +		}
   59.25 +		buf[p++] = c;
   59.26 +	}
   59.27  
   59.28 -  if(c == EOF){
   59.29 -    return -1;
   59.30 -  }
   59.31 -  if((p > 0) && (buf[p-1] == '\r'))
   59.32 -    p--;
   59.33 -  buf[p++] = '\n';
   59.34 -  buf[p] = 0;
   59.35 +	if (c == EOF) {
   59.36 +		return -1;
   59.37 +	}
   59.38 +	if ((p > 0) && (buf[p - 1] == '\r'))
   59.39 +		p--;
   59.40 +	buf[p++] = '\n';
   59.41 +	buf[p] = 0;
   59.42  
   59.43 -  return p;
   59.44 +	return p;
   59.45  }
   59.46  
   59.47 -static
   59.48 -void spool_write_rcpt(FILE *out, address *rcpt)
   59.49 +static void
   59.50 +spool_write_rcpt(FILE * out, address * rcpt)
   59.51  {
   59.52 -  gchar dlvrd_char = addr_is_delivered(rcpt) ? 'X' : (addr_is_failed(rcpt) ? 'F' : ' ');
   59.53 +	gchar dlvrd_char = addr_is_delivered(rcpt) ? 'X' : (addr_is_failed(rcpt) ? 'F' : ' ');
   59.54  
   59.55 -  if(rcpt->local_part[0] != '|'){
   59.56 -    /* this is a paranoid check, in case it slipped through: */
   59.57 -    /* if this happens, it is a bug */
   59.58 -    if(rcpt->domain == NULL){
   59.59 -      logwrite(LOG_WARNING, "BUG: null domain for address %s, setting to %s\n",
   59.60 -	       rcpt->local_part, conf.host_name);
   59.61 -      logwrite(LOG_WARNING, "please report this bug.\n");
   59.62 -      rcpt->domain = g_strdup(conf.host_name);
   59.63 -    }
   59.64 -    fprintf(out, "RT:%c%s\n", dlvrd_char, addr_string(rcpt));
   59.65 -  }else{
   59.66 -    fprintf(out, "RT:%c%s\n", dlvrd_char, rcpt->local_part);
   59.67 -  }
   59.68 +	if (rcpt->local_part[0] != '|') {
   59.69 +		/* this is a paranoid check, in case it slipped through: */
   59.70 +		/* if this happens, it is a bug */
   59.71 +		if (rcpt->domain == NULL) {
   59.72 +			logwrite(LOG_WARNING, "BUG: null domain for address %s, setting to %s\n", rcpt->local_part, conf.host_name);
   59.73 +			logwrite(LOG_WARNING, "please report this bug.\n");
   59.74 +			rcpt->domain = g_strdup(conf.host_name);
   59.75 +		}
   59.76 +		fprintf(out, "RT:%c%s\n", dlvrd_char, addr_string(rcpt));
   59.77 +	} else {
   59.78 +		fprintf(out, "RT:%c%s\n", dlvrd_char, rcpt->local_part);
   59.79 +	}
   59.80  }
   59.81  
   59.82 -static
   59.83 -address *spool_scan_rcpt(gchar *line)
   59.84 +static address*
   59.85 +spool_scan_rcpt(gchar * line)
   59.86  {
   59.87 -  address *rcpt = NULL;
   59.88 +	address *rcpt = NULL;
   59.89  
   59.90 -  if(line[3] != 0){
   59.91 -    if(line[4] != '|'){
   59.92 -      rcpt = create_address(&(line[4]), TRUE);
   59.93 -    }else{
   59.94 -      rcpt = create_address_pipe(&(line[4]));
   59.95 -    }
   59.96 -    if(line[3] == 'X'){
   59.97 -      addr_mark_delivered(rcpt);
   59.98 -    }else if(line[3] == 'F'){
   59.99 -      addr_mark_failed(rcpt);
  59.100 -    }
  59.101 -  }
  59.102 -  return rcpt;
  59.103 +	if (line[3] != 0) {
  59.104 +		if (line[4] != '|') {
  59.105 +			rcpt = create_address(&(line[4]), TRUE);
  59.106 +		} else {
  59.107 +			rcpt = create_address_pipe(&(line[4]));
  59.108 +		}
  59.109 +		if (line[3] == 'X') {
  59.110 +			addr_mark_delivered(rcpt);
  59.111 +		} else if (line[3] == 'F') {
  59.112 +			addr_mark_failed(rcpt);
  59.113 +		}
  59.114 +	}
  59.115 +	return rcpt;
  59.116  }
  59.117  
  59.118 -gboolean spool_read_data(message *msg)
  59.119 +gboolean
  59.120 +spool_read_data(message * msg)
  59.121  {
  59.122 -  FILE *in;
  59.123 -  gboolean ok = FALSE;
  59.124 -  gchar *spool_file;
  59.125 +	FILE *in;
  59.126 +	gboolean ok = FALSE;
  59.127 +	gchar *spool_file;
  59.128  
  59.129 -  DEBUG(5) debugf("spool_read_data entered\n");
  59.130 -  spool_file = g_strdup_printf("%s/input/%s-D", conf.spool_dir, msg->uid);
  59.131 -  DEBUG(5) debugf("reading data spool file '%s'\n", spool_file);
  59.132 -  if((in = fopen(spool_file, "r"))){
  59.133 -    char buf[MAX_DATALINE];
  59.134 -    int len;
  59.135 -    
  59.136 -    /* msg uid */
  59.137 -    read_line(in, buf, MAX_DATALINE);
  59.138 -      
  59.139 -    /* data */
  59.140 -    msg->data_list = NULL;
  59.141 -    while((len = read_line(in, buf, MAX_DATALINE)) > 0){
  59.142 -      msg->data_list = g_list_prepend(msg->data_list, g_strdup(buf));
  59.143 -    }
  59.144 -    msg->data_list = g_list_reverse(msg->data_list);
  59.145 -    fclose(in);
  59.146 -    ok = TRUE;
  59.147 -  }else
  59.148 -    logwrite(LOG_ALERT, "could not open spool data file %s: %s\n",
  59.149 -	     spool_file, strerror(errno));
  59.150 -  return ok;
  59.151 +	DEBUG(5) debugf("spool_read_data entered\n");
  59.152 +	spool_file = g_strdup_printf("%s/input/%s-D", conf.spool_dir, msg->uid);
  59.153 +	DEBUG(5) debugf("reading data spool file '%s'\n", spool_file);
  59.154 +	if ((in = fopen(spool_file, "r"))) {
  59.155 +		char buf[MAX_DATALINE];
  59.156 +		int len;
  59.157 +
  59.158 +		/* msg uid */
  59.159 +		read_line(in, buf, MAX_DATALINE);
  59.160 +
  59.161 +		/* data */
  59.162 +		msg->data_list = NULL;
  59.163 +		while ((len = read_line(in, buf, MAX_DATALINE)) > 0) {
  59.164 +			msg->data_list = g_list_prepend(msg->data_list, g_strdup(buf));
  59.165 +		}
  59.166 +		msg->data_list = g_list_reverse(msg->data_list);
  59.167 +		fclose(in);
  59.168 +		ok = TRUE;
  59.169 +	} else
  59.170 +		logwrite(LOG_ALERT, "could not open spool data file %s: %s\n", spool_file, strerror(errno));
  59.171 +	return ok;
  59.172  }
  59.173  
  59.174 -gboolean spool_read_header(message *msg)
  59.175 +gboolean
  59.176 +spool_read_header(message * msg)
  59.177  {
  59.178 -  FILE *in;
  59.179 -  gboolean ok = FALSE;
  59.180 -  gchar *spool_file;
  59.181 +	FILE *in;
  59.182 +	gboolean ok = FALSE;
  59.183 +	gchar *spool_file;
  59.184  
  59.185 -  /* header spool: */
  59.186 -  spool_file = g_strdup_printf("%s/input/%s-H", conf.spool_dir, msg->uid);
  59.187 -  if((in = fopen(spool_file, "r"))){
  59.188 -    header *hdr = NULL;
  59.189 -    char buf[MAX_DATALINE];
  59.190 -    int len;
  59.191 +	/* header spool: */
  59.192 +	spool_file = g_strdup_printf("%s/input/%s-H", conf.spool_dir, msg->uid);
  59.193 +	if ((in = fopen(spool_file, "r"))) {
  59.194 +		header *hdr = NULL;
  59.195 +		char buf[MAX_DATALINE];
  59.196 +		int len;
  59.197  
  59.198 -    /* msg uid */
  59.199 -    read_line(in, buf, MAX_DATALINE);
  59.200 -    
  59.201 -    /* envelope header */
  59.202 -    while((len = read_line(in, buf, MAX_DATALINE)) > 0){
  59.203 -      if(buf[0] == '\n')
  59.204 -	break;
  59.205 -      else if(strncasecmp(buf, "MF:", 3) == 0){
  59.206 -	msg->return_path = create_address(&(buf[3]), TRUE);
  59.207 -	DEBUG(3) debugf("spool_read: MAIL FROM: %s",
  59.208 -			msg->return_path->address);
  59.209 -      }else if(strncasecmp(buf, "RT:", 3) == 0){
  59.210 -	address *addr;
  59.211 -	addr = spool_scan_rcpt(buf);
  59.212 -	if(!addr_is_delivered(addr) && !addr_is_failed(addr)){
  59.213 -	  msg->rcpt_list = g_list_append(msg->rcpt_list, addr);
  59.214 -	}else{
  59.215 -	  msg->non_rcpt_list = g_list_append(msg->non_rcpt_list, addr);
  59.216 -	}
  59.217 -      }else if(strncasecmp(buf, "PR:", 3) == 0){
  59.218 -	prot_id i;
  59.219 -	for(i = 0; i < PROT_NUM; i++){
  59.220 -	  if(strncasecmp(prot_names[i], &(buf[3]),
  59.221 -			 strlen(prot_names[i])) == 0){
  59.222 -	    break;
  59.223 -	  }
  59.224 -	}
  59.225 -	msg->received_prot = i;
  59.226 -      }else if(strncasecmp(buf, "RH:", 3) == 0){
  59.227 -	g_strchomp(buf);
  59.228 -	msg->received_host = g_strdup(&(buf[3]));
  59.229 -      }else if(strncasecmp(buf, "ID:", 3) == 0){
  59.230 -	g_strchomp(buf);
  59.231 -	msg->ident = g_strdup(&(buf[3]));
  59.232 -      }else if(strncasecmp(buf, "DS:", 3) == 0){
  59.233 -	msg->data_size = atoi(&(buf[3]));
  59.234 -      }else if(strncasecmp(buf, "TR:", 3) == 0){
  59.235 -	msg->received_time = (time_t)(atoi(&(buf[3])));
  59.236 -      }else if(strncasecmp(buf, "TW:", 3) == 0){
  59.237 -	msg->warned_time = (time_t)(atoi(&(buf[3])));
  59.238 -      }
  59.239 -      /* so far ignore other tags */
  59.240 -    }
  59.241 -    
  59.242 -    /* mail headers */
  59.243 -    while((len = read_line(in, buf, MAX_DATALINE)) > 0){
  59.244 -      if(strncasecmp(buf, "HD:", 3) == 0){
  59.245 -	hdr = get_header(&(buf[3]));
  59.246 -	msg->hdr_list = g_list_append(msg->hdr_list, hdr);
  59.247 -      }else if((buf[0] == ' ' || buf[0] == '\t') && hdr){
  59.248 -	char *tmp = hdr->header;
  59.249 -	/* header continuation */
  59.250 -	hdr->header = g_strconcat(hdr->header, buf, NULL);
  59.251 -	hdr->value = hdr->header + (hdr->value - tmp);
  59.252 -      }else
  59.253 -	break;
  59.254 -    }
  59.255 -    fclose(in);
  59.256 -    ok = TRUE;
  59.257 -  }else
  59.258 -    logwrite(LOG_ALERT, "could not open spool header file %s: %s\n",
  59.259 -	     spool_file, strerror(errno));
  59.260 -  return ok;
  59.261 +		/* msg uid */
  59.262 +		read_line(in, buf, MAX_DATALINE);
  59.263 +
  59.264 +		/* envelope header */
  59.265 +		while ((len = read_line(in, buf, MAX_DATALINE)) > 0) {
  59.266 +			if (buf[0] == '\n')
  59.267 +				break;
  59.268 +			else if (strncasecmp(buf, "MF:", 3) == 0) {
  59.269 +				msg->return_path = create_address(&(buf[3]), TRUE);
  59.270 +				DEBUG(3) debugf("spool_read: MAIL FROM: %s", msg->return_path->address);
  59.271 +			} else if (strncasecmp(buf, "RT:", 3) == 0) {
  59.272 +				address *addr;
  59.273 +				addr = spool_scan_rcpt(buf);
  59.274 +				if (!addr_is_delivered(addr) && !addr_is_failed(addr)) {
  59.275 +					msg->rcpt_list = g_list_append(msg->rcpt_list, addr);
  59.276 +				} else {
  59.277 +					msg->non_rcpt_list = g_list_append(msg->non_rcpt_list, addr);
  59.278 +				}
  59.279 +			} else if (strncasecmp(buf, "PR:", 3) == 0) {
  59.280 +				prot_id i;
  59.281 +				for (i = 0; i < PROT_NUM; i++) {
  59.282 +					if (strncasecmp(prot_names[i], &(buf[3]), strlen(prot_names[i])) == 0) {
  59.283 +						break;
  59.284 +					}
  59.285 +				}
  59.286 +				msg->received_prot = i;
  59.287 +			} else if (strncasecmp(buf, "RH:", 3) == 0) {
  59.288 +				g_strchomp(buf);
  59.289 +				msg->received_host = g_strdup(&(buf[3]));
  59.290 +			} else if (strncasecmp(buf, "ID:", 3) == 0) {
  59.291 +				g_strchomp(buf);
  59.292 +				msg->ident = g_strdup(&(buf[3]));
  59.293 +			} else if (strncasecmp(buf, "DS:", 3) == 0) {
  59.294 +				msg->data_size = atoi(&(buf[3]));
  59.295 +			} else if (strncasecmp(buf, "TR:", 3) == 0) {
  59.296 +				msg->received_time = (time_t) (atoi(&(buf[3])));
  59.297 +			} else if (strncasecmp(buf, "TW:", 3) == 0) {
  59.298 +				msg->warned_time = (time_t) (atoi(&(buf[3])));
  59.299 +			}
  59.300 +			/* so far ignore other tags */
  59.301 +		}
  59.302 +
  59.303 +		/* mail headers */
  59.304 +		while ((len = read_line(in, buf, MAX_DATALINE)) > 0) {
  59.305 +			if (strncasecmp(buf, "HD:", 3) == 0) {
  59.306 +				hdr = get_header(&(buf[3]));
  59.307 +				msg->hdr_list = g_list_append(msg->hdr_list, hdr);
  59.308 +			} else if ((buf[0] == ' ' || buf[0] == '\t') && hdr) {
  59.309 +				char *tmp = hdr->header;
  59.310 +				/* header continuation */
  59.311 +				hdr->header = g_strconcat(hdr->header, buf, NULL);
  59.312 +				hdr->value = hdr->header + (hdr->value - tmp);
  59.313 +			} else
  59.314 +				break;
  59.315 +		}
  59.316 +		fclose(in);
  59.317 +		ok = TRUE;
  59.318 +	} else
  59.319 +		logwrite(LOG_ALERT, "could not open spool header file %s: %s\n", spool_file, strerror(errno));
  59.320 +	return ok;
  59.321  }
  59.322  
  59.323 -message *msg_spool_read(gchar *uid, gboolean do_readdata)
  59.324 +message*
  59.325 +msg_spool_read(gchar * uid, gboolean do_readdata)
  59.326  {
  59.327 -  message *msg;
  59.328 -  gboolean ok = FALSE;
  59.329 -  
  59.330 -  msg = create_message();
  59.331 -  msg->uid = g_strdup(uid);
  59.332 +	message *msg;
  59.333 +	gboolean ok = FALSE;
  59.334  
  59.335 -  /* header spool: */
  59.336 -  ok = spool_read_header(msg);
  59.337 -  if(ok && do_readdata){
  59.338 -    /* data spool: */
  59.339 -    ok = spool_read_data(msg);
  59.340 -  }
  59.341 -  return msg;
  59.342 +	msg = create_message();
  59.343 +	msg->uid = g_strdup(uid);
  59.344 +
  59.345 +	/* header spool: */
  59.346 +	ok = spool_read_header(msg);
  59.347 +	if (ok && do_readdata) {
  59.348 +		/* data spool: */
  59.349 +		ok = spool_read_data(msg);
  59.350 +	}
  59.351 +	return msg;
  59.352  }
  59.353  
  59.354  /* write header. uid and gid should already be set to the
  59.355     mail ids. Better call spool_write(msg, FALSE).
  59.356  */
  59.357 -static
  59.358 -gboolean spool_write_header(message *msg)
  59.359 +static gboolean
  59.360 +spool_write_header(message * msg)
  59.361  {
  59.362 -  GList *node;
  59.363 -  gchar *spool_file, *tmp_file;
  59.364 -  FILE *out;
  59.365 -  gboolean ok = TRUE;
  59.366 +	GList *node;
  59.367 +	gchar *spool_file, *tmp_file;
  59.368 +	FILE *out;
  59.369 +	gboolean ok = TRUE;
  59.370  
  59.371 -  /* header spool: */
  59.372 -  tmp_file = g_strdup_printf("%s/input/%d-H.tmp", conf.spool_dir, getpid());
  59.373 -  DEBUG(4) debugf("tmp_file = %s\n", tmp_file);
  59.374 +	/* header spool: */
  59.375 +	tmp_file = g_strdup_printf("%s/input/%d-H.tmp", conf.spool_dir, getpid());
  59.376 +	DEBUG(4) debugf("tmp_file = %s\n", tmp_file);
  59.377  
  59.378 -  if((out = fopen(tmp_file, "w"))){
  59.379 -    DEBUG(6) debugf("opened tmp_file %s\n", tmp_file);
  59.380 +	if ((out = fopen(tmp_file, "w"))) {
  59.381 +		DEBUG(6) debugf("opened tmp_file %s\n", tmp_file);
  59.382  
  59.383 -    fprintf(out, "%s\n", msg->uid);
  59.384 -    fprintf(out, "MF:%s\n", addr_string(msg->return_path));
  59.385 +		fprintf(out, "%s\n", msg->uid);
  59.386 +		fprintf(out, "MF:%s\n", addr_string(msg->return_path));
  59.387  
  59.388 -    DEBUG(6) debugf("after MF\n");
  59.389 -    foreach(msg->rcpt_list, node){
  59.390 -      address *rcpt = (address *)(node->data);
  59.391 -      spool_write_rcpt(out, rcpt);
  59.392 -    }
  59.393 -    foreach(msg->non_rcpt_list, node){
  59.394 -      address *rcpt = (address *)(node->data);
  59.395 -      spool_write_rcpt(out, rcpt);
  59.396 -    }
  59.397 -    DEBUG(6) debugf("after RT\n");
  59.398 -    fprintf(out, "PR:%s\n", prot_names[msg->received_prot]);
  59.399 -    if(msg->received_host != NULL)
  59.400 -      fprintf(out, "RH:%s\n", msg->received_host);
  59.401 +		DEBUG(6) debugf("after MF\n");
  59.402 +		foreach(msg->rcpt_list, node) {
  59.403 +			address *rcpt = (address *) (node->data);
  59.404 +			spool_write_rcpt(out, rcpt);
  59.405 +		}
  59.406 +		foreach(msg->non_rcpt_list, node) {
  59.407 +			address *rcpt = (address *) (node->data);
  59.408 +			spool_write_rcpt(out, rcpt);
  59.409 +		}
  59.410 +		DEBUG(6) debugf("after RT\n");
  59.411 +		fprintf(out, "PR:%s\n", prot_names[msg->received_prot]);
  59.412 +		if (msg->received_host != NULL)
  59.413 +			fprintf(out, "RH:%s\n", msg->received_host);
  59.414  
  59.415 -    if(msg->ident != NULL)
  59.416 -      fprintf(out, "ID:%s\n", msg->ident);
  59.417 +		if (msg->ident != NULL)
  59.418 +			fprintf(out, "ID:%s\n", msg->ident);
  59.419  
  59.420 -    if(msg->data_size >= 0)
  59.421 -      fprintf(out, "DS: %d\n", msg->data_size);
  59.422 +		if (msg->data_size >= 0)
  59.423 +			fprintf(out, "DS: %d\n", msg->data_size);
  59.424  
  59.425 -    if(msg->received_time > 0)
  59.426 -      fprintf(out, "TR: %u\n", (int)(msg->received_time));
  59.427 +		if (msg->received_time > 0)
  59.428 +			fprintf(out, "TR: %u\n", (int) (msg->received_time));
  59.429  
  59.430 -    if(msg->warned_time > 0)
  59.431 -      fprintf(out, "TW: %u\n", (int)(msg->warned_time));
  59.432 +		if (msg->warned_time > 0)
  59.433 +			fprintf(out, "TW: %u\n", (int) (msg->warned_time));
  59.434  
  59.435 -    DEBUG(6) debugf("after RH\n");
  59.436 -    fprintf(out, "\n");
  59.437 +		DEBUG(6) debugf("after RH\n");
  59.438 +		fprintf(out, "\n");
  59.439  
  59.440 -    foreach(msg->hdr_list, node){
  59.441 -      header *hdr = (header *)(node->data);
  59.442 -      fprintf(out, "HD:%s", hdr->header);
  59.443 -    }
  59.444 -    if(fflush(out) == EOF) ok = FALSE;
  59.445 -    else if(fdatasync(fileno(out)) != 0){
  59.446 -      if(errno != EINVAL) /* some fs do not support this..
  59.447 -			     I hope this also means that it is not necessary */
  59.448 -	ok = FALSE;
  59.449 -    }
  59.450 -    fclose(out);
  59.451 -    if(ok){
  59.452 -      spool_file = g_strdup_printf("%s/input/%s-H", conf.spool_dir, msg->uid);
  59.453 -      DEBUG(4) debugf("spool_file = %s\n", spool_file);
  59.454 -      ok = (rename(tmp_file, spool_file) != -1);
  59.455 -      g_free(spool_file);
  59.456 -    }
  59.457 -  }else{
  59.458 -    logwrite(LOG_ALERT, "could not open temporary header spool file '%s': %s\n", tmp_file, strerror(errno));
  59.459 -    DEBUG(1) debugf("euid = %d, egid = %d\n", geteuid(), getegid());
  59.460 -    ok = FALSE;
  59.461 -  }
  59.462 +		foreach(msg->hdr_list, node) {
  59.463 +			header *hdr = (header *) (node->data);
  59.464 +			fprintf(out, "HD:%s", hdr->header);
  59.465 +		}
  59.466 +		if (fflush(out) == EOF)
  59.467 +			ok = FALSE;
  59.468 +		else if (fdatasync(fileno(out)) != 0) {
  59.469 +			if (errno != EINVAL)  /* some fs do not support this..  I hope this also means that it is not necessary */
  59.470 +				ok = FALSE;
  59.471 +		}
  59.472 +		fclose(out);
  59.473 +		if (ok) {
  59.474 +			spool_file = g_strdup_printf("%s/input/%s-H", conf.spool_dir, msg->uid);
  59.475 +			DEBUG(4) debugf("spool_file = %s\n", spool_file);
  59.476 +			ok = (rename(tmp_file, spool_file) != -1);
  59.477 +			g_free(spool_file);
  59.478 +		}
  59.479 +	} else {
  59.480 +		logwrite(LOG_ALERT, "could not open temporary header spool file '%s': %s\n", tmp_file, strerror(errno));
  59.481 +		DEBUG(1) debugf("euid = %d, egid = %d\n", geteuid(), getegid());
  59.482 +		ok = FALSE;
  59.483 +	}
  59.484  
  59.485 -  g_free(tmp_file);
  59.486 +	g_free(tmp_file);
  59.487  
  59.488 -  return ok;
  59.489 +	return ok;
  59.490  }
  59.491  
  59.492 -gboolean spool_write(message *msg, gboolean do_write_data)
  59.493 +gboolean
  59.494 +spool_write(message * msg, gboolean do_write_data)
  59.495  {
  59.496 -  GList *list;
  59.497 -  gchar *spool_file, *tmp_file;
  59.498 -  FILE *out;
  59.499 -  gboolean ok = TRUE;
  59.500 -  uid_t saved_uid, saved_gid;
  59.501 -  /* user can read/write, group can read, others cannot do anything: */
  59.502 -  mode_t saved_mode = saved_mode = umask(026);
  59.503 +	GList *list;
  59.504 +	gchar *spool_file, *tmp_file;
  59.505 +	FILE *out;
  59.506 +	gboolean ok = TRUE;
  59.507 +	uid_t saved_uid, saved_gid;
  59.508 +	/* user can read/write, group can read, others cannot do anything: */
  59.509 +	mode_t saved_mode = saved_mode = umask(026);
  59.510  
  59.511 -  /* set uid and gid to the mail ids */
  59.512 -  if(!conf.run_as_user){
  59.513 -    set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
  59.514 -  }
  59.515 -
  59.516 -  /* header spool: */
  59.517 -  ok = spool_write_header(msg);
  59.518 -
  59.519 -  if(ok){
  59.520 -
  59.521 -    if(do_write_data){
  59.522 -      /* data spool: */
  59.523 -      tmp_file = g_strdup_printf("%s/input/%d-D.tmp",
  59.524 -				 conf.spool_dir, getpid());
  59.525 -      DEBUG(4) debugf("tmp_file = %s\n", tmp_file);
  59.526 -
  59.527 -      if((out = fopen(tmp_file, "w"))){
  59.528 -	fprintf(out, "%s\n", msg->uid);
  59.529 -	for(list = g_list_first(msg->data_list);
  59.530 -	    list != NULL;
  59.531 -	    list = g_list_next(list)){
  59.532 -	  fprintf(out, "%s", (gchar *)(list->data));
  59.533 +	/* set uid and gid to the mail ids */
  59.534 +	if (!conf.run_as_user) {
  59.535 +		set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
  59.536  	}
  59.537  
  59.538 -	/* possibly paranoid ;-) */
  59.539 -	if(fflush(out) == EOF) ok = FALSE;
  59.540 -	else if(fdatasync(fileno(out)) != 0){
  59.541 -	  if(errno != EINVAL) /* some fs do not support this..
  59.542 -				 I hope this also means that it is not necessary */
  59.543 -	    ok = FALSE;
  59.544 +	/* header spool: */
  59.545 +	ok = spool_write_header(msg);
  59.546 +
  59.547 +	if (ok) {
  59.548 +
  59.549 +		if (do_write_data) {
  59.550 +			/* data spool: */
  59.551 +			tmp_file = g_strdup_printf("%s/input/%d-D.tmp", conf.spool_dir, getpid());
  59.552 +			DEBUG(4) debugf("tmp_file = %s\n", tmp_file);
  59.553 +
  59.554 +			if ((out = fopen(tmp_file, "w"))) {
  59.555 +				fprintf(out, "%s\n", msg->uid);
  59.556 +				for (list = g_list_first(msg->data_list); list != NULL; list = g_list_next(list)) {
  59.557 +					fprintf(out, "%s", (gchar *) (list->data));
  59.558 +				}
  59.559 +
  59.560 +				/* possibly paranoid ;-) */
  59.561 +				if (fflush(out) == EOF)
  59.562 +					ok = FALSE;
  59.563 +				else if (fdatasync(fileno(out)) != 0) {
  59.564 +					if (errno != EINVAL)  /* some fs do not support this..  I hope this also means that it is not necessary */
  59.565 +						ok = FALSE;
  59.566 +				}
  59.567 +				fclose(out);
  59.568 +				if (ok) {
  59.569 +					spool_file = g_strdup_printf("%s/input/%s-D", conf.spool_dir, msg->uid);
  59.570 +					DEBUG(4) debugf("spool_file = %s\n", spool_file);
  59.571 +					ok = (rename(tmp_file, spool_file) != -1);
  59.572 +					g_free(spool_file);
  59.573 +				}
  59.574 +			} else {
  59.575 +				logwrite(LOG_ALERT, "could not open temporary data spool file: %s\n", strerror(errno));
  59.576 +				ok = FALSE;
  59.577 +			}
  59.578 +			g_free(tmp_file);
  59.579 +		}
  59.580  	}
  59.581 -	fclose(out);
  59.582 -	if(ok){
  59.583 -	  spool_file = g_strdup_printf("%s/input/%s-D",
  59.584 -				       conf.spool_dir, msg->uid);
  59.585 -	  DEBUG(4) debugf("spool_file = %s\n", spool_file);
  59.586 -	  ok = (rename(tmp_file, spool_file) != -1);
  59.587 -	  g_free(spool_file);
  59.588 +
  59.589 +	/* set uid and gid back */
  59.590 +	if (!conf.run_as_user) {
  59.591 +		set_euidgid(saved_uid, saved_gid, NULL, NULL);
  59.592  	}
  59.593 -      }else{
  59.594 -	logwrite(LOG_ALERT, "could not open temporary data spool file: %s\n",
  59.595 -		 strerror(errno));
  59.596 -	ok = FALSE;
  59.597 -      }
  59.598 -      g_free(tmp_file);
  59.599 -    }
  59.600 -  }
  59.601  
  59.602 -  /* set uid and gid back */
  59.603 -  if(!conf.run_as_user){
  59.604 -    set_euidgid(saved_uid, saved_gid, NULL, NULL);
  59.605 -  }
  59.606 +	umask(saved_mode);
  59.607  
  59.608 -  umask(saved_mode);
  59.609 -
  59.610 -  return ok;
  59.611 +	return ok;
  59.612  }
  59.613  
  59.614  #define MAX_LOCKAGE 300
  59.615  
  59.616 -gboolean spool_lock(gchar *uid)
  59.617 +gboolean
  59.618 +spool_lock(gchar * uid)
  59.619  {
  59.620 -  uid_t saved_uid, saved_gid;
  59.621 -  gchar *hitch_name;
  59.622 -  gchar *lock_name;
  59.623 -  gboolean ok = FALSE;
  59.624 +	uid_t saved_uid, saved_gid;
  59.625 +	gchar *hitch_name;
  59.626 +	gchar *lock_name;
  59.627 +	gboolean ok = FALSE;
  59.628  
  59.629 -  hitch_name = g_strdup_printf("%s/%s-%d.lock", conf.lock_dir, uid, getpid());
  59.630 -  lock_name = g_strdup_printf("%s/%s.lock", conf.lock_dir, uid);
  59.631 +	hitch_name = g_strdup_printf("%s/%s-%d.lock", conf.lock_dir, uid, getpid());
  59.632 +	lock_name = g_strdup_printf("%s/%s.lock", conf.lock_dir, uid);
  59.633  
  59.634 -  /* set uid and gid to the mail ids */
  59.635 -  if(!conf.run_as_user){
  59.636 -    set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
  59.637 -  }
  59.638 +	/* set uid and gid to the mail ids */
  59.639 +	if (!conf.run_as_user) {
  59.640 +		set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
  59.641 +	}
  59.642  
  59.643 -  ok = dot_lock(lock_name, hitch_name);
  59.644 -  if(!ok) logwrite(LOG_WARNING, "spool file %s is locked\n", uid);
  59.645 +	ok = dot_lock(lock_name, hitch_name);
  59.646 +	if (!ok)
  59.647 +		logwrite(LOG_WARNING, "spool file %s is locked\n", uid);
  59.648  
  59.649 -  /* set uid and gid back */
  59.650 -  if(!conf.run_as_user){
  59.651 -    set_euidgid(saved_uid, saved_gid, NULL, NULL);
  59.652 -  }
  59.653 +	/* set uid and gid back */
  59.654 +	if (!conf.run_as_user) {
  59.655 +		set_euidgid(saved_uid, saved_gid, NULL, NULL);
  59.656 +	}
  59.657  
  59.658 -  g_free(lock_name);
  59.659 -  g_free(hitch_name);
  59.660 +	g_free(lock_name);
  59.661 +	g_free(hitch_name);
  59.662  
  59.663 -  return ok;
  59.664 +	return ok;
  59.665  }
  59.666  
  59.667 -gboolean spool_unlock(gchar *uid)
  59.668 +gboolean
  59.669 +spool_unlock(gchar * uid)
  59.670  {
  59.671 -  uid_t saved_uid, saved_gid;
  59.672 -  gchar *lock_name;
  59.673 +	uid_t saved_uid, saved_gid;
  59.674 +	gchar *lock_name;
  59.675  
  59.676 -  /* set uid and gid to the mail ids */
  59.677 -  if(!conf.run_as_user){
  59.678 -    set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
  59.679 -  }
  59.680 +	/* set uid and gid to the mail ids */
  59.681 +	if (!conf.run_as_user) {
  59.682 +		set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
  59.683 +	}
  59.684  
  59.685 -  lock_name = g_strdup_printf("%s/%s.lock", conf.lock_dir, uid);
  59.686 -  dot_unlock(lock_name);
  59.687 -  g_free(lock_name);
  59.688 +	lock_name = g_strdup_printf("%s/%s.lock", conf.lock_dir, uid);
  59.689 +	dot_unlock(lock_name);
  59.690 +	g_free(lock_name);
  59.691  
  59.692 -  /* set uid and gid back */
  59.693 -  if(!conf.run_as_user){
  59.694 -    set_euidgid(saved_uid, saved_gid, NULL, NULL);
  59.695 -  }
  59.696 -  return TRUE;
  59.697 +	/* set uid and gid back */
  59.698 +	if (!conf.run_as_user) {
  59.699 +		set_euidgid(saved_uid, saved_gid, NULL, NULL);
  59.700 +	}
  59.701 +	return TRUE;
  59.702  }
  59.703  
  59.704 -gboolean spool_delete_all(message *msg)
  59.705 +gboolean
  59.706 +spool_delete_all(message * msg)
  59.707  {
  59.708 -  uid_t saved_uid, saved_gid;
  59.709 -  gchar *spool_file;
  59.710 +	uid_t saved_uid, saved_gid;
  59.711 +	gchar *spool_file;
  59.712  
  59.713 -  /* set uid and gid to the mail ids */
  59.714 -  if(!conf.run_as_user){
  59.715 -    set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
  59.716 -  }
  59.717 +	/* set uid and gid to the mail ids */
  59.718 +	if (!conf.run_as_user) {
  59.719 +		set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
  59.720 +	}
  59.721  
  59.722 -  /* header spool: */
  59.723 -  spool_file = g_strdup_printf("%s/input/%s-H", conf.spool_dir, msg->uid);
  59.724 -  if(unlink(spool_file) != 0)
  59.725 -    logwrite(LOG_ALERT, "could not delete spool file %s: %s\n",
  59.726 -	     spool_file, strerror(errno));
  59.727 -  g_free(spool_file);
  59.728 +	/* header spool: */
  59.729 +	spool_file = g_strdup_printf("%s/input/%s-H", conf.spool_dir, msg->uid);
  59.730 +	if (unlink(spool_file) != 0)
  59.731 +		logwrite(LOG_ALERT, "could not delete spool file %s: %s\n", spool_file, strerror(errno));
  59.732 +	g_free(spool_file);
  59.733  
  59.734 -  /* data spool: */
  59.735 -  spool_file = g_strdup_printf("%s/input/%s-D", conf.spool_dir, msg->uid);
  59.736 -  if(unlink(spool_file) != 0)
  59.737 -    logwrite(LOG_ALERT, "could not delete spool file %s: %s\n",
  59.738 -	     spool_file, strerror(errno));
  59.739 -  g_free(spool_file);
  59.740 +	/* data spool: */
  59.741 +	spool_file = g_strdup_printf("%s/input/%s-D", conf.spool_dir, msg->uid);
  59.742 +	if (unlink(spool_file) != 0)
  59.743 +		logwrite(LOG_ALERT, "could not delete spool file %s: %s\n", spool_file, strerror(errno));
  59.744 +	g_free(spool_file);
  59.745  
  59.746 -  /* set uid and gid back */
  59.747 -  if(!conf.run_as_user){
  59.748 -    set_euidgid(saved_uid, saved_gid, NULL, NULL);
  59.749 -  }
  59.750 -  return TRUE;
  59.751 +	/* set uid and gid back */
  59.752 +	if (!conf.run_as_user) {
  59.753 +		set_euidgid(saved_uid, saved_gid, NULL, NULL);
  59.754 +	}
  59.755 +	return TRUE;
  59.756  }
    60.1 --- a/src/tables.c	Mon Oct 27 16:21:27 2008 +0100
    60.2 +++ b/src/tables.c	Mon Oct 27 16:23:10 2008 +0100
    60.3 @@ -19,120 +19,128 @@
    60.4  #include "masqmail.h"
    60.5  #include <fnmatch.h>
    60.6  
    60.7 -table_pair *create_pair(gchar *key, gpointer value)
    60.8 +table_pair*
    60.9 +create_pair(gchar * key, gpointer value)
   60.10  {
   60.11 -  table_pair *pair;
   60.12 -  
   60.13 -  pair = g_malloc(sizeof(table_pair));
   60.14 -  pair->key = g_strdup(key);
   60.15 -  pair->value = value;
   60.16 +	table_pair *pair;
   60.17  
   60.18 -  return pair;
   60.19 +	pair = g_malloc(sizeof(table_pair));
   60.20 +	pair->key = g_strdup(key);
   60.21 +	pair->value = value;
   60.22 +
   60.23 +	return pair;
   60.24  }
   60.25  
   60.26 -table_pair *create_pair_string(gchar *key, gpointer value)
   60.27 +table_pair*
   60.28 +create_pair_string(gchar * key, gpointer value)
   60.29  {
   60.30 -  table_pair *pair;
   60.31 -  
   60.32 -  pair = g_malloc(sizeof(table_pair));
   60.33 -  pair->key = g_strdup(key);
   60.34 -  pair->value = (gpointer)(g_strdup(value));
   60.35 +	table_pair *pair;
   60.36  
   60.37 -  return pair;
   60.38 +	pair = g_malloc(sizeof(table_pair));
   60.39 +	pair->key = g_strdup(key);
   60.40 +	pair->value = (gpointer) (g_strdup(value));
   60.41 +
   60.42 +	return pair;
   60.43  }
   60.44  
   60.45 -table_pair *parse_table_pair(gchar *line, char delim)
   60.46 +table_pair*
   60.47 +parse_table_pair(gchar * line, char delim)
   60.48  {
   60.49 -  gchar buf[256];
   60.50 -  gchar *p, *q;
   60.51 -  table_pair *pair;
   60.52 +	gchar buf[256];
   60.53 +	gchar *p, *q;
   60.54 +	table_pair *pair;
   60.55  
   60.56 -  p = line;
   60.57 -  q = buf;
   60.58 -  while((*p != 0) && (*p != delim) && q < buf+255)
   60.59 -    *(q++) = *(p++);
   60.60 -  *q = 0;
   60.61 +	p = line;
   60.62 +	q = buf;
   60.63 +	while ((*p != 0) && (*p != delim) && q < buf + 255)
   60.64 +		*(q++) = *(p++);
   60.65 +	*q = 0;
   60.66  
   60.67 -  pair = g_malloc(sizeof(table_pair));
   60.68 -  pair->key = g_strdup(g_strstrip(buf));
   60.69 +	pair = g_malloc(sizeof(table_pair));
   60.70 +	pair->key = g_strdup(g_strstrip(buf));
   60.71  
   60.72 -  if(*p){
   60.73 -    p++;
   60.74 -    /*    while(isspace(*p)) p++; */
   60.75 -    pair->value = (gpointer *)(g_strdup(g_strstrip(p)));
   60.76 -  }else
   60.77 -    pair->value = (gpointer *)g_strdup("");
   60.78 +	if (*p) {
   60.79 +		p++;
   60.80 +		/*    while(isspace(*p)) p++; */
   60.81 +		pair->value = (gpointer *) (g_strdup(g_strstrip(p)));
   60.82 +	} else
   60.83 +		pair->value = (gpointer *) g_strdup("");
   60.84  
   60.85 -  return pair;
   60.86 +	return pair;
   60.87  }
   60.88  
   60.89 -gpointer *table_find_func(GList *table_list, gchar *key, int (*cmp_func)(const char *, const char *))
   60.90 +gpointer*
   60.91 +table_find_func(GList * table_list, gchar * key, int (*cmp_func) (const char *, const char *))
   60.92  {
   60.93 -  GList *node;
   60.94 +	GList *node;
   60.95  
   60.96 -  foreach(table_list, node){
   60.97 -    table_pair *pair = (table_pair *)(node->data);
   60.98 -    if(cmp_func(pair->key, key) == 0)
   60.99 -      return pair->value;
  60.100 -  }
  60.101 -  return NULL;
  60.102 +	foreach(table_list, node) {
  60.103 +		table_pair *pair = (table_pair *) (node->data);
  60.104 +		if (cmp_func(pair->key, key) == 0)
  60.105 +			return pair->value;
  60.106 +	}
  60.107 +	return NULL;
  60.108  }
  60.109  
  60.110 -gpointer *table_find(GList *table_list, gchar *key)
  60.111 +gpointer*
  60.112 +table_find(GList * table_list, gchar * key)
  60.113  {
  60.114 -  return table_find_func(table_list, key, strcmp);
  60.115 +	return table_find_func(table_list, key, strcmp);
  60.116  }
  60.117  
  60.118 -gpointer *table_find_case(GList *table_list, gchar *key)
  60.119 +gpointer*
  60.120 +table_find_case(GList * table_list, gchar * key)
  60.121  {
  60.122 -  return table_find_func(table_list, key, strcasecmp);
  60.123 +	return table_find_func(table_list, key, strcasecmp);
  60.124  }
  60.125  
  60.126 -static
  60.127 -int fnmatch0(const char *pattern, const char *string)
  60.128 +static int
  60.129 +fnmatch0(const char *pattern, const char *string)
  60.130  {
  60.131 -  return fnmatch(pattern, string, 0);
  60.132 +	return fnmatch(pattern, string, 0);
  60.133  }
  60.134  
  60.135 -gpointer *table_find_fnmatch(GList *table_list, gchar *key)
  60.136 +gpointer*
  60.137 +table_find_fnmatch(GList * table_list, gchar * key)
  60.138  {
  60.139 -  return table_find_func(table_list, key, fnmatch0);
  60.140 +	return table_find_func(table_list, key, fnmatch0);
  60.141  }
  60.142  
  60.143 -GList *table_read(gchar *fname, gchar delim)
  60.144 +GList*
  60.145 +table_read(gchar * fname, gchar delim)
  60.146  {
  60.147 -  GList *list = NULL;
  60.148 -  FILE *fptr;
  60.149 +	GList *list = NULL;
  60.150 +	FILE *fptr;
  60.151  
  60.152 -  if((fptr = fopen(fname, "rt"))){
  60.153 -    gchar buf[256];
  60.154 +	if ((fptr = fopen(fname, "rt"))) {
  60.155 +		gchar buf[256];
  60.156  
  60.157 -    while(fgets(buf, 255, fptr)){
  60.158 -      if(buf[0] && (buf[0] != '#') && (buf[0] != '\n')){
  60.159 -	table_pair *pair;
  60.160 -	g_strchomp(buf);
  60.161 -	pair = parse_table_pair(buf, delim);
  60.162 -	list = g_list_append(list, pair);
  60.163 -      }
  60.164 -    }
  60.165 -    fclose(fptr);
  60.166 -    return list;
  60.167 -  }
  60.168 -  logwrite(LOG_ALERT, "could not open table file %s: %s\n", fname, strerror(errno));
  60.169 +		while (fgets(buf, 255, fptr)) {
  60.170 +			if (buf[0] && (buf[0] != '#') && (buf[0] != '\n')) {
  60.171 +				table_pair *pair;
  60.172 +				g_strchomp(buf);
  60.173 +				pair = parse_table_pair(buf, delim);
  60.174 +				list = g_list_append(list, pair);
  60.175 +			}
  60.176 +		}
  60.177 +		fclose(fptr);
  60.178 +		return list;
  60.179 +	}
  60.180 +	logwrite(LOG_ALERT, "could not open table file %s: %s\n", fname, strerror(errno));
  60.181  
  60.182 -  return NULL;
  60.183 +	return NULL;
  60.184  }
  60.185  
  60.186 -void destroy_table(GList *table)
  60.187 +void
  60.188 +destroy_table(GList * table)
  60.189  {
  60.190 -  GList *node;
  60.191 +	GList *node;
  60.192  
  60.193 -  foreach(table, node){
  60.194 -    table_pair *p = (table_pair *)(node->data);
  60.195 -    g_free(p->key);
  60.196 -    g_free(p->value);
  60.197 -    g_free(p);
  60.198 -  }
  60.199 -  g_list_free(table);
  60.200 +	foreach(table, node) {
  60.201 +		table_pair *p = (table_pair *) (node->data);
  60.202 +		g_free(p->key);
  60.203 +		g_free(p->value);
  60.204 +		g_free(p);
  60.205 +	}
  60.206 +	g_list_free(table);
  60.207  }
  60.208 -
    61.1 --- a/src/timeival.c	Mon Oct 27 16:21:27 2008 +0100
    61.2 +++ b/src/timeival.c	Mon Oct 27 16:23:10 2008 +0100
    61.3 @@ -21,34 +21,35 @@
    61.4  
    61.5  #include "masqmail.h"
    61.6  
    61.7 -gint time_interval(gchar *str, gint *pos)
    61.8 +gint
    61.9 +time_interval(gchar * str, gint * pos)
   61.10  {
   61.11 -  gchar buf[16];
   61.12 -  gchar *p = str, *q = buf;
   61.13 -  gint factor = 1, val;
   61.14 +	gchar buf[16];
   61.15 +	gchar *p = str, *q = buf;
   61.16 +	gint factor = 1, val;
   61.17  
   61.18 -  while(*p && isdigit(*p) && (q < buf+15)){
   61.19 -    *(q++) = *(p++);
   61.20 -    (*pos)++;
   61.21 -  }
   61.22 -  (*pos)++;
   61.23 -  *q = 0;
   61.24 -  val = atoi(buf);
   61.25 -  
   61.26 -  /* fall through: */
   61.27 -  switch(*p){
   61.28 -  case 'w':
   61.29 -    factor *= 7;
   61.30 -  case 'd':
   61.31 -    factor *= 24;
   61.32 -  case 'h':
   61.33 -    factor *= 60;
   61.34 -  case 'm':
   61.35 -    factor *= 60;
   61.36 -  case 's':
   61.37 -    break;
   61.38 -  default:
   61.39 -    return -1;
   61.40 -  }
   61.41 -  return val * factor;
   61.42 +	while (*p && isdigit(*p) && (q < buf + 15)) {
   61.43 +		*(q++) = *(p++);
   61.44 +		(*pos)++;
   61.45 +	}
   61.46 +	(*pos)++;
   61.47 +	*q = 0;
   61.48 +	val = atoi(buf);
   61.49 +
   61.50 +	/* fall through: */
   61.51 +	switch (*p) {
   61.52 +	case 'w':
   61.53 +		factor *= 7;
   61.54 +	case 'd':
   61.55 +		factor *= 24;
   61.56 +	case 'h':
   61.57 +		factor *= 60;
   61.58 +	case 'm':
   61.59 +		factor *= 60;
   61.60 +	case 's':
   61.61 +		break;
   61.62 +	default:
   61.63 +		return -1;
   61.64 +	}
   61.65 +	return val * factor;
   61.66  }