masqmail-0.2

diff src/local.c @ 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 08114f7dcc23
children f671821d8222
line diff
     1.1 --- a/src/local.c	Mon Oct 27 16:21:27 2008 +0100
     1.2 +++ b/src/local.c	Mon Oct 27 16:23:10 2008 +0100
     1.3 @@ -20,347 +20,333 @@
     1.4  #include "peopen.h"
     1.5  #include <sys/wait.h>
     1.6  
     1.7 -static
     1.8 -void message_stream(FILE *out, message *msg, GList *hdr_list, guint flags)
     1.9 +static void
    1.10 +message_stream(FILE * out, message * msg, GList * hdr_list, guint flags)
    1.11  {
    1.12 -  time_t now = time(NULL);
    1.13 -  GList *node;
    1.14 -  
    1.15 -  if(flags & MSGSTR_FROMLINE){
    1.16 -    fprintf(out, "From <%s@%s> %s", msg->return_path->local_part,
    1.17 -	    msg->return_path->domain, ctime(&now));
    1.18 -  }
    1.19 -	  
    1.20 -  foreach(hdr_list, node){
    1.21 -    header *hdr = (header *)(node->data);
    1.22 -    fputs(hdr->header, out);
    1.23 -  }
    1.24 -  putc('\n', out);
    1.25 -  foreach(msg->data_list, node){
    1.26 -    /* From hack: */
    1.27 -    if(flags & MSGSTR_FROMHACK){
    1.28 -      if(strncmp(node->data, "From ", 5) == 0)
    1.29 -	putc('>', out);
    1.30 -    }
    1.31 -    fputs(node->data, out);
    1.32 -  }
    1.33 -  putc('\n', out);
    1.34 +	time_t now = time(NULL);
    1.35 +	GList *node;
    1.36 +
    1.37 +	if (flags & MSGSTR_FROMLINE) {
    1.38 +		fprintf(out, "From <%s@%s> %s", msg->return_path->local_part, msg->return_path->domain, ctime(&now));
    1.39 +	}
    1.40 +
    1.41 +	foreach(hdr_list, node) {
    1.42 +		header *hdr = (header *) (node->data);
    1.43 +		fputs(hdr->header, out);
    1.44 +	}
    1.45 +	putc('\n', out);
    1.46 +	foreach(msg->data_list, node) {
    1.47 +		/* From hack: */
    1.48 +		if (flags & MSGSTR_FROMHACK) {
    1.49 +			if (strncmp(node->data, "From ", 5) == 0)
    1.50 +				putc('>', out);
    1.51 +		}
    1.52 +		fputs(node->data, out);
    1.53 +	}
    1.54 +	putc('\n', out);
    1.55  }
    1.56  
    1.57 -gboolean append_file(message *msg, GList *hdr_list, gchar *user)
    1.58 +gboolean
    1.59 +append_file(message * msg, GList * hdr_list, gchar * user)
    1.60  {
    1.61 -  struct passwd *pw;
    1.62 -  gboolean ok = FALSE;
    1.63 -  
    1.64 -  /* headers may be special for a local delivery */
    1.65 -  if(hdr_list == NULL)
    1.66 -    hdr_list = msg->hdr_list;
    1.67 +	struct passwd *pw;
    1.68 +	gboolean ok = FALSE;
    1.69  
    1.70 -  if((pw = getpwnam(user))){
    1.71 -    uid_t saved_uid = geteuid();
    1.72 -    gid_t saved_gid = getegid();
    1.73 -    gboolean uid_ok = TRUE, gid_ok = TRUE;
    1.74 +	/* headers may be special for a local delivery */
    1.75 +	if (hdr_list == NULL)
    1.76 +		hdr_list = msg->hdr_list;
    1.77  
    1.78 -    if(!conf.run_as_user){
    1.79 -      uid_ok = (seteuid(0) == 0);
    1.80 -      if(uid_ok){
    1.81 -	gid_ok = (setegid(conf.mail_gid) == 0);
    1.82 -	uid_ok = (seteuid(pw->pw_uid) == 0);
    1.83 -      }
    1.84 -    }
    1.85 +	if ((pw = getpwnam(user))) {
    1.86 +		uid_t saved_uid = geteuid();
    1.87 +		gid_t saved_gid = getegid();
    1.88 +		gboolean uid_ok = TRUE, gid_ok = TRUE;
    1.89  
    1.90 -    DEBUG(5) debugf("running as euid %d\n", geteuid());
    1.91 -    DEBUG(5) debugf("running as egid %d\n", getegid());
    1.92 +		if (!conf.run_as_user) {
    1.93 +			uid_ok = (seteuid(0) == 0);
    1.94 +			if (uid_ok) {
    1.95 +				gid_ok = (setegid(conf.mail_gid) == 0);
    1.96 +				uid_ok = (seteuid(pw->pw_uid) == 0);
    1.97 +			}
    1.98 +		}
    1.99  
   1.100 -    if(uid_ok && gid_ok){
   1.101 -      gchar *filename;
   1.102 -      FILE *out;
   1.103 +		DEBUG(5) debugf("running as euid %d\n", geteuid());
   1.104 +		DEBUG(5) debugf("running as egid %d\n", getegid());
   1.105  
   1.106 -      filename = g_strdup_printf("%s/%s", conf.mail_dir, user);
   1.107 -      if((out = fopen(filename, "a"))){
   1.108 +		if (uid_ok && gid_ok) {
   1.109 +			gchar *filename;
   1.110 +			FILE *out;
   1.111 +
   1.112 +			filename = g_strdup_printf("%s/%s", conf.mail_dir, user);
   1.113 +			if ((out = fopen(filename, "a"))) {
   1.114  #ifdef USE_LIBLOCKFILE
   1.115 -        gint err;
   1.116 -        /* lock file using liblockfile */
   1.117 -        err = maillock(user,3);
   1.118 -	if(err == 0){
   1.119 +				gint err;
   1.120 +				/* lock file using liblockfile */
   1.121 +				err = maillock(user, 3);
   1.122 +				if (err == 0) {
   1.123  #else
   1.124 -	/* lock file: */
   1.125 -	struct flock lock;
   1.126 -	lock.l_type = F_WRLCK;
   1.127 -	lock.l_whence = SEEK_END;
   1.128 -	lock.l_start = lock.l_len = 0;
   1.129 -	if(fcntl(fileno(out), F_SETLK, &lock) != -1){
   1.130 +				/* lock file: */
   1.131 +				struct flock lock;
   1.132 +				lock.l_type = F_WRLCK;
   1.133 +				lock.l_whence = SEEK_END;
   1.134 +				lock.l_start = lock.l_len = 0;
   1.135 +				if (fcntl(fileno(out), F_SETLK, &lock) != -1) {
   1.136  #endif
   1.137 -	  fchmod(fileno(out), 0600);
   1.138 -	  
   1.139 -	  message_stream(out, msg, hdr_list, MSGSTR_FROMLINE|MSGSTR_FROMHACK);
   1.140 +					fchmod(fileno(out), 0600);
   1.141  
   1.142 -	  ok = TRUE;
   1.143 -	  
   1.144 -	  /* close when still user */
   1.145 -	  fclose(out);
   1.146 +					message_stream(out, msg, hdr_list, MSGSTR_FROMLINE | MSGSTR_FROMHACK);
   1.147 +
   1.148 +					ok = TRUE;
   1.149 +
   1.150 +					/* close when still user */
   1.151 +					fclose(out);
   1.152  #ifdef USE_LIBLOCKFILE
   1.153 -          mailunlock();
   1.154 +					mailunlock();
   1.155  #endif
   1.156 -	}else{
   1.157 -	  fclose(out);
   1.158 +				} else {
   1.159 +					fclose(out);
   1.160  #ifdef USE_LIBLOCKFILE
   1.161 -	  DEBUG(3) debugf("could not lock file %s: error %d\n",
   1.162 -			  filename, err);
   1.163 -	} /* XEmacs indenting convenience... */
   1.164 +					DEBUG(3) debugf("could not lock file %s: error %d\n", filename, err);
   1.165 +				}  /* XEmacs indenting convenience... */
   1.166  #else
   1.167 -	  DEBUG(3) debugf("could not lock file %s: %s\n",
   1.168 -			  filename, strerror(errno));
   1.169 +					DEBUG(3) debugf("could not lock file %s: %s\n", filename, strerror(errno));
   1.170 +				}
   1.171 +#endif
   1.172 +			} else {
   1.173 +				logwrite(LOG_ALERT, "could not open file %s: %s\n", filename, strerror(errno));
   1.174 +			}
   1.175 +			g_free(filename);
   1.176 +
   1.177 +			if (!conf.run_as_user) {
   1.178 +				uid_ok = (seteuid(0) == 0);
   1.179 +				if (uid_ok) {
   1.180 +					gid_ok = (setegid(saved_gid) == 0);
   1.181 +					uid_ok = (seteuid(saved_uid) == 0);
   1.182 +				}
   1.183 +			}
   1.184 +
   1.185 +			if (!uid_ok || !gid_ok) {
   1.186 +				/* FIXME: if this fails we HAVE to exit, because we shall not run
   1.187 +				   with some users id. But we do not return, and so this message
   1.188 +				   will not be finished, so the user will get the message again
   1.189 +				   next time a delivery is attempted... */
   1.190 +				logwrite(LOG_ALERT, "could not set back uid or gid after local delivery: %s\n", strerror(errno));
   1.191 +				logwrite(LOG_ALERT, "uid=%d, gid=%d, euid=%d, egid=%d, want = %d, %d\n",
   1.192 +				         getuid(), getgid(), geteuid(), getegid(), saved_uid, saved_gid);
   1.193 +				exit(EXIT_FAILURE);
   1.194 +			}
   1.195 +		} else {
   1.196 +			logwrite(LOG_ALERT, "could not set uid or gid for local delivery, uid = %d: %s\n", pw->pw_uid, strerror(errno));
   1.197 +		}
   1.198 +	} else {
   1.199 +		logwrite(LOG_ALERT, "could not find password entry for user %s\n", user);
   1.200 +		errno = ENOENT;  /* getpwnam does not set errno correctly */
   1.201  	}
   1.202 -#endif
   1.203 -      }else{
   1.204 -	logwrite(LOG_ALERT, "could not open file %s: %s\n",
   1.205 -		 filename, strerror(errno));
   1.206 -      }
   1.207 -      g_free(filename);
   1.208  
   1.209 -      if(!conf.run_as_user){
   1.210 -	uid_ok = (seteuid(0) == 0);
   1.211 -	if(uid_ok){
   1.212 -	  gid_ok = (setegid(saved_gid) == 0);
   1.213 -	  uid_ok = (seteuid(saved_uid) == 0);
   1.214 -	}
   1.215 -      }
   1.216 -      
   1.217 -      if(!uid_ok || !gid_ok){
   1.218 -	/* FIXME: if this fails we HAVE to exit, because we shall not run
   1.219 -	   with some users id. But we do not return, and so this message
   1.220 -	   will not be finished, so the user will get the message again
   1.221 -	   next time a delivery is attempted... */
   1.222 -	logwrite(LOG_ALERT,
   1.223 -		 "could not set back uid or gid after local delivery: %s\n",
   1.224 -		 strerror(errno));
   1.225 -	logwrite(LOG_ALERT,
   1.226 -		 "uid=%d, gid=%d, euid=%d, egid=%d, want = %d, %d\n",
   1.227 -		 getuid(), getgid(), geteuid(), getegid(), saved_uid, saved_gid);
   1.228 -	exit(EXIT_FAILURE);
   1.229 -      }
   1.230 -    }else{
   1.231 -      logwrite(LOG_ALERT,
   1.232 -	       "could not set uid or gid for local delivery, uid = %d: %s\n",
   1.233 -	       pw->pw_uid, strerror(errno));
   1.234 -    }
   1.235 -  }else{
   1.236 -    logwrite(LOG_ALERT, "could not find password entry for user %s\n", user);
   1.237 -    errno = ENOENT; /* getpwnam does not set errno correctly */
   1.238 -  }
   1.239 -
   1.240 -  return ok;
   1.241 +	return ok;
   1.242  }
   1.243  
   1.244  #ifdef ENABLE_MAILDIR
   1.245 -gboolean maildir_out(message *msg, GList *hdr_list, gchar *user, guint flags)
   1.246 +gboolean
   1.247 +maildir_out(message * msg, GList * hdr_list, gchar * user, guint flags)
   1.248  {
   1.249 -  struct passwd *pw;
   1.250 -  gboolean ok = FALSE;
   1.251 -  
   1.252 -  /* headers may be special for a local delivery */
   1.253 -  if(hdr_list == NULL)
   1.254 -    hdr_list = msg->hdr_list;
   1.255 +	struct passwd *pw;
   1.256 +	gboolean ok = FALSE;
   1.257  
   1.258 -  if((pw = getpwnam(user))){
   1.259 -    uid_t saved_uid = geteuid();
   1.260 -    gid_t saved_gid = getegid();
   1.261 -    gboolean uid_ok = TRUE, gid_ok = TRUE;
   1.262 +	/* headers may be special for a local delivery */
   1.263 +	if (hdr_list == NULL)
   1.264 +		hdr_list = msg->hdr_list;
   1.265  
   1.266 -    if(!conf.run_as_user){
   1.267 -      uid_ok = (seteuid(0) == 0);
   1.268 -      if(uid_ok){
   1.269 -	gid_ok = (setegid(conf.mail_gid) == 0);
   1.270 -	uid_ok = (seteuid(pw->pw_uid) == 0);
   1.271 -      }
   1.272 -    }
   1.273 +	if ((pw = getpwnam(user))) {
   1.274 +		uid_t saved_uid = geteuid();
   1.275 +		gid_t saved_gid = getegid();
   1.276 +		gboolean uid_ok = TRUE, gid_ok = TRUE;
   1.277  
   1.278 -    DEBUG(5) debugf("running as euid %d\n", geteuid());
   1.279 -    DEBUG(5) debugf("running as egid %d\n", getegid());
   1.280 -    
   1.281 -    if(uid_ok && gid_ok){
   1.282 -      char *path = g_strdup_printf("%s/Maildir", pw->pw_dir);
   1.283 -      struct stat statbuf;
   1.284 -      int ret;
   1.285 +		if (!conf.run_as_user) {
   1.286 +			uid_ok = (seteuid(0) == 0);
   1.287 +			if (uid_ok) {
   1.288 +				gid_ok = (setegid(conf.mail_gid) == 0);
   1.289 +				uid_ok = (seteuid(pw->pw_uid) == 0);
   1.290 +			}
   1.291 +		}
   1.292  
   1.293 -      DEBUG(5) debugf("path = %s\n", path);
   1.294 +		DEBUG(5) debugf("running as euid %d\n", geteuid());
   1.295 +		DEBUG(5) debugf("running as egid %d\n", getegid());
   1.296  
   1.297 -      ok = TRUE;
   1.298 -      ret = stat(path, &statbuf);
   1.299 -      if(ret != 0){
   1.300 -	ok = FALSE;
   1.301 -	if(errno == ENOENT){
   1.302 -	  logwrite(LOG_NOTICE, "directory %s does not exist, creating\n", path);
   1.303 -	  if(mkdir(path, 0700) == 0)
   1.304 -	    ok = TRUE;
   1.305 -	}else
   1.306 -	  logwrite(LOG_ALERT, "stat of %s failed: %s\n", path, strerror(errno));
   1.307 -      }
   1.308 -      if(ok){
   1.309 -	ok = FALSE;
   1.310 -	ret = stat(path, &statbuf);
   1.311 -	if(S_ISDIR(statbuf.st_mode)){
   1.312 -	  gchar *subdirs[] = {"tmp", "new", "cur"};
   1.313 -	  int i;
   1.314 -	  for(i = 0; i < 3; i++){
   1.315 -	    char *path1 = g_strdup_printf("%s/%s", path, subdirs[i]);
   1.316 -	    ret = stat(path1, &statbuf);
   1.317 -	    if(ret != 0){
   1.318 -	      if(errno == ENOENT){
   1.319 -		logwrite(LOG_NOTICE, "directory %s does not exist, creating\n", path1);
   1.320 -		if(mkdir(path1, 0700) != 0) break;
   1.321 -	      }
   1.322 -	    }
   1.323 -	    g_free(path1);
   1.324 -	  }
   1.325 -	  if(i == 3){
   1.326 -	    FILE *out;
   1.327 -	    mode_t saved_mode = umask(066);
   1.328 -	    /* the qmail style unique works only if delivering
   1.329 -	       with different process. We do not fork for each delivery,
   1.330 -	       so our uid is more unique. Hope it is compatible with all
   1.331 -	       MUAs.
   1.332 -	    */
   1.333 -	    gchar *filename = g_strdup_printf("%s/tmp/%s.%s", path, msg->uid, conf.host_name);
   1.334 +		if (uid_ok && gid_ok) {
   1.335 +			char *path = g_strdup_printf("%s/Maildir", pw->pw_dir);
   1.336 +			struct stat statbuf;
   1.337 +			int ret;
   1.338  
   1.339 -	    DEBUG(5) debugf("filename = %s\n", filename);
   1.340 -	    
   1.341 -	    if((out = fopen(filename, "w"))){
   1.342 -	      gchar *newname =
   1.343 -		g_strdup_printf("%s/new/%s.%s", path, msg->uid, conf.host_name);
   1.344 -	      message_stream(out, msg, hdr_list, flags);
   1.345 -	      ok = TRUE;
   1.346 -	      if(fflush(out) == EOF) ok = FALSE;
   1.347 -	      else if(fdatasync(fileno(out)) != 0){
   1.348 -		if(errno != EINVAL) /* some fs do not support this..
   1.349 -				       I hope this also means that it is not necessary */
   1.350 -		  ok = FALSE;
   1.351 -	      }
   1.352 -	      fclose(out);
   1.353 -	      if(rename(filename, newname) != 0){
   1.354 -		ok = FALSE;
   1.355 -		logwrite(LOG_ALERT, "moving %s to %s failed: %s",
   1.356 -			 filename, newname, strerror(errno));
   1.357 -	      }
   1.358 -	      g_free(newname);
   1.359 -	    }
   1.360 -	    umask(saved_mode);
   1.361 -	    g_free(filename);
   1.362 -	  }
   1.363 -	}else{
   1.364 -	  logwrite(LOG_ALERT, "%s is not a directory\n", path);
   1.365 -	  errno = ENOTDIR;
   1.366 +			DEBUG(5) debugf("path = %s\n", path);
   1.367 +
   1.368 +			ok = TRUE;
   1.369 +			ret = stat(path, &statbuf);
   1.370 +			if (ret != 0) {
   1.371 +				ok = FALSE;
   1.372 +				if (errno == ENOENT) {
   1.373 +					logwrite(LOG_NOTICE, "directory %s does not exist, creating\n", path);
   1.374 +					if (mkdir(path, 0700) == 0)
   1.375 +						ok = TRUE;
   1.376 +				} else
   1.377 +					logwrite(LOG_ALERT, "stat of %s failed: %s\n", path, strerror(errno));
   1.378 +			}
   1.379 +			if (ok) {
   1.380 +				ok = FALSE;
   1.381 +				ret = stat(path, &statbuf);
   1.382 +				if (S_ISDIR(statbuf.st_mode)) {
   1.383 +					gchar *subdirs[] = { "tmp", "new", "cur" };
   1.384 +					int i;
   1.385 +					for (i = 0; i < 3; i++) {
   1.386 +						char *path1 = g_strdup_printf("%s/%s", path, subdirs[i]);
   1.387 +						ret = stat(path1, &statbuf);
   1.388 +						if (ret != 0) {
   1.389 +							if (errno == ENOENT) {
   1.390 +								logwrite(LOG_NOTICE, "directory %s does not exist, creating\n", path1);
   1.391 +								if (mkdir(path1, 0700) != 0)
   1.392 +									break;
   1.393 +							}
   1.394 +						}
   1.395 +						g_free(path1);
   1.396 +					}
   1.397 +					if (i == 3) {
   1.398 +						FILE *out;
   1.399 +						mode_t saved_mode = umask(066);
   1.400 +						/* the qmail style unique works only if delivering
   1.401 +						   with different process. We do not fork for each delivery,
   1.402 +						   so our uid is more unique. Hope it is compatible with all
   1.403 +						   MUAs.
   1.404 +						 */
   1.405 +						gchar *filename = g_strdup_printf("%s/tmp/%s.%s", path, msg->uid, conf.host_name);
   1.406 +
   1.407 +						DEBUG(5) debugf("filename = %s\n", filename);
   1.408 +
   1.409 +						if ((out = fopen(filename, "w"))) {
   1.410 +							gchar *newname = g_strdup_printf("%s/new/%s.%s", path, msg->uid, conf.host_name);
   1.411 +							message_stream(out, msg, hdr_list, flags);
   1.412 +							ok = TRUE;
   1.413 +							if (fflush(out) == EOF)
   1.414 +								ok = FALSE;
   1.415 +							else if (fdatasync(fileno(out)) != 0) {
   1.416 +								if (errno != EINVAL)  /* some fs do not support this..  I hope this also means that it is not necessary */
   1.417 +									ok = FALSE;
   1.418 +							}
   1.419 +							fclose(out);
   1.420 +							if (rename(filename, newname) != 0) {
   1.421 +								ok = FALSE;
   1.422 +								logwrite(LOG_ALERT, "moving %s to %s failed: %s", filename, newname, strerror(errno));
   1.423 +							}
   1.424 +							g_free(newname);
   1.425 +						}
   1.426 +						umask(saved_mode);
   1.427 +						g_free(filename);
   1.428 +					}
   1.429 +				} else {
   1.430 +					logwrite(LOG_ALERT, "%s is not a directory\n", path);
   1.431 +					errno = ENOTDIR;
   1.432 +				}
   1.433 +			}
   1.434 +			if (!conf.run_as_user) {
   1.435 +				uid_ok = (seteuid(0) == 0);
   1.436 +				if (uid_ok) {
   1.437 +					gid_ok = (setegid(saved_gid) == 0);
   1.438 +					uid_ok = (seteuid(saved_uid) == 0);
   1.439 +				}
   1.440 +			}
   1.441 +			if (!uid_ok || !gid_ok) {
   1.442 +				/* FIXME: if this fails we HAVE to exit, because we shall not run
   1.443 +				   with some users id. But we do not return, and so this message
   1.444 +				   will not be finished, so the user will get the message again
   1.445 +				   next time a delivery is attempted... */
   1.446 +				logwrite(LOG_ALERT, "could not set back uid or gid after local delivery: %s\n", strerror(errno));
   1.447 +				exit(EXIT_FAILURE);
   1.448 +			}
   1.449 +			g_free(path);
   1.450 +		} else {
   1.451 +			logwrite(LOG_ALERT, "could not set uid or gid for local delivery, uid = %d: %s\n", pw->pw_uid, strerror(errno));
   1.452 +		}
   1.453 +	} else {
   1.454 +		logwrite(LOG_ALERT, "could not find password entry for user %s\n", user);
   1.455 +		errno = ENOENT;  /* getpwnam does not set errno correctly */
   1.456  	}
   1.457 -      }
   1.458 -      if(!conf.run_as_user){
   1.459 -	uid_ok = (seteuid(0) == 0);
   1.460 -	if(uid_ok){
   1.461 -	  gid_ok = (setegid(saved_gid) == 0);
   1.462 -	  uid_ok = (seteuid(saved_uid) == 0);
   1.463 -	}
   1.464 -      }
   1.465 -      if(!uid_ok || !gid_ok){
   1.466 -	/* FIXME: if this fails we HAVE to exit, because we shall not run
   1.467 -	   with some users id. But we do not return, and so this message
   1.468 -	   will not be finished, so the user will get the message again
   1.469 -	   next time a delivery is attempted... */
   1.470 -	logwrite(LOG_ALERT,
   1.471 -		 "could not set back uid or gid after local delivery: %s\n",
   1.472 -		 strerror(errno));
   1.473 -	exit(EXIT_FAILURE);
   1.474 -      }
   1.475 -      g_free(path);
   1.476 -    }else{
   1.477 -      logwrite(LOG_ALERT,
   1.478 -	       "could not set uid or gid for local delivery, uid = %d: %s\n",
   1.479 -	       pw->pw_uid, strerror(errno));
   1.480 -    }
   1.481 -  }else{
   1.482 -    logwrite(LOG_ALERT, "could not find password entry for user %s\n", user);
   1.483 -    errno = ENOENT; /* getpwnam does not set errno correctly */
   1.484 -  }
   1.485 -  return ok;
   1.486 +	return ok;
   1.487  }
   1.488  #endif
   1.489  
   1.490  gboolean
   1.491 -pipe_out(message *msg, GList *hdr_list, address *rcpt, gchar *cmd, guint flags)
   1.492 +pipe_out(message * msg, GList * hdr_list, address * rcpt, gchar * cmd, guint flags)
   1.493  {
   1.494 -  gchar *envp[40];
   1.495 -  FILE *out;
   1.496 -  uid_t saved_uid = geteuid();
   1.497 -  gid_t saved_gid = getegid();
   1.498 -  gboolean ok = FALSE;
   1.499 -  gint i, n;
   1.500 -  pid_t pid;
   1.501 -  void (*old_signal)(int);
   1.502 -  int status;
   1.503 +	gchar *envp[40];
   1.504 +	FILE *out;
   1.505 +	uid_t saved_uid = geteuid();
   1.506 +	gid_t saved_gid = getegid();
   1.507 +	gboolean ok = FALSE;
   1.508 +	gint i, n;
   1.509 +	pid_t pid;
   1.510 +	void (*old_signal) (int);
   1.511 +	int status;
   1.512  
   1.513 -  /* set uid and gid to the mail ids */
   1.514 -  if(!conf.run_as_user){
   1.515 -    set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
   1.516 -  }
   1.517 +	/* set uid and gid to the mail ids */
   1.518 +	if (!conf.run_as_user) {
   1.519 +		set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
   1.520 +	}
   1.521  
   1.522 -  /* set environment */
   1.523 -  {
   1.524 -    gint i = 0;
   1.525 -    address *ancestor = addr_find_ancestor(rcpt);
   1.526 +	/* set environment */
   1.527 +	{
   1.528 +		gint i = 0;
   1.529 +		address *ancestor = addr_find_ancestor(rcpt);
   1.530  
   1.531 -    envp[i++] = g_strdup_printf("SENDER=%s@%s", msg->return_path->local_part, msg->return_path->domain);
   1.532 -    envp[i++] = g_strdup_printf("SENDER_DOMAIN=%s", msg->return_path->domain);
   1.533 -    envp[i++] = g_strdup_printf("SENDER_LOCAL=%s", msg->return_path->local_part);
   1.534 -    envp[i++] = g_strdup_printf("RECEIVED_HOST=%s", msg->received_host ? msg->received_host : "");
   1.535 +		envp[i++] = g_strdup_printf("SENDER=%s@%s", msg->return_path->local_part, msg->return_path->domain);
   1.536 +		envp[i++] = g_strdup_printf("SENDER_DOMAIN=%s", msg->return_path->domain);
   1.537 +		envp[i++] = g_strdup_printf("SENDER_LOCAL=%s", msg->return_path->local_part);
   1.538 +		envp[i++] = g_strdup_printf("RECEIVED_HOST=%s", msg->received_host ? msg->received_host : "");
   1.539  
   1.540 -    envp[i++] = g_strdup_printf("RETURN_PATH=%s@%s",
   1.541 -				msg->return_path->local_part, msg->return_path->domain);
   1.542 -    envp[i++] = g_strdup_printf("DOMAIN=%s", ancestor->domain);
   1.543 +		envp[i++] = g_strdup_printf("RETURN_PATH=%s@%s", msg->return_path->local_part, msg->return_path->domain);
   1.544 +		envp[i++] = g_strdup_printf("DOMAIN=%s", ancestor->domain);
   1.545  
   1.546 -    envp[i++] = g_strdup_printf("LOCAL_PART=%s", ancestor->local_part);
   1.547 -    envp[i++] = g_strdup_printf("USER=%s", ancestor->local_part);
   1.548 -    envp[i++] = g_strdup_printf("LOGNAME=%s", ancestor->local_part);
   1.549 +		envp[i++] = g_strdup_printf("LOCAL_PART=%s", ancestor->local_part);
   1.550 +		envp[i++] = g_strdup_printf("USER=%s", ancestor->local_part);
   1.551 +		envp[i++] = g_strdup_printf("LOGNAME=%s", ancestor->local_part);
   1.552  
   1.553 -    envp[i++] = g_strdup_printf("MESSAGE_ID=%s", msg->uid);
   1.554 -    envp[i++] = g_strdup_printf("QUALIFY_DOMAIN=%s", conf.host_name);
   1.555 +		envp[i++] = g_strdup_printf("MESSAGE_ID=%s", msg->uid);
   1.556 +		envp[i++] = g_strdup_printf("QUALIFY_DOMAIN=%s", conf.host_name);
   1.557  
   1.558 -    envp[i] = NULL;
   1.559 -    n = i;
   1.560 -  }
   1.561 +		envp[i] = NULL;
   1.562 +		n = i;
   1.563 +	}
   1.564  
   1.565 -  old_signal = signal(SIGCHLD, SIG_DFL);
   1.566 +	old_signal = signal(SIGCHLD, SIG_DFL);
   1.567  
   1.568 -  out = peidopen(cmd, "w", envp, &pid, conf.mail_uid, conf.mail_gid);
   1.569 -  if(out != NULL){
   1.570 -    message_stream(out, msg, hdr_list, flags);
   1.571 +	out = peidopen(cmd, "w", envp, &pid, conf.mail_uid, conf.mail_gid);
   1.572 +	if (out != NULL) {
   1.573 +		message_stream(out, msg, hdr_list, flags);
   1.574  
   1.575 -    fclose(out);
   1.576 +		fclose(out);
   1.577  
   1.578 -    waitpid(pid, &status, 0);
   1.579 +		waitpid(pid, &status, 0);
   1.580  
   1.581 -    if(WEXITSTATUS(status) != 0){
   1.582 -      int exstat = WEXITSTATUS(status);
   1.583 -      logwrite(LOG_ALERT, "process returned %d (%s)\n", exstat, ext_strerror(1024 + exstat));
   1.584 -      errno = 1024 + exstat;
   1.585 -    }else if(WIFSIGNALED(status)){
   1.586 -      logwrite(LOG_ALERT, "process got signal %d\n", WTERMSIG(status));
   1.587 -    }else
   1.588 -      ok = TRUE;
   1.589 +		if (WEXITSTATUS(status) != 0) {
   1.590 +			int exstat = WEXITSTATUS(status);
   1.591 +			logwrite(LOG_ALERT, "process returned %d (%s)\n", exstat, ext_strerror(1024 + exstat));
   1.592 +			errno = 1024 + exstat;
   1.593 +		} else if (WIFSIGNALED(status)) {
   1.594 +			logwrite(LOG_ALERT, "process got signal %d\n", WTERMSIG(status));
   1.595 +		} else
   1.596 +			ok = TRUE;
   1.597  
   1.598 -  }else
   1.599 -    logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", cmd, strerror(errno));
   1.600 +	} else
   1.601 +		logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", cmd, strerror(errno));
   1.602  
   1.603 -  signal(SIGCHLD, old_signal);
   1.604 +	signal(SIGCHLD, old_signal);
   1.605  
   1.606 -  /* free environment */
   1.607 -  for(i = 0; i < n; i++){
   1.608 -    g_free(envp[i]);
   1.609 -  }
   1.610 +	/* free environment */
   1.611 +	for (i = 0; i < n; i++) {
   1.612 +		g_free(envp[i]);
   1.613 +	}
   1.614  
   1.615 -  /* set uid and gid back */
   1.616 -  if(!conf.run_as_user){
   1.617 -    set_euidgid(saved_uid, saved_gid, NULL, NULL);
   1.618 -  }
   1.619 +	/* set uid and gid back */
   1.620 +	if (!conf.run_as_user) {
   1.621 +		set_euidgid(saved_uid, saved_gid, NULL, NULL);
   1.622 +	}
   1.623  
   1.624 -  return ok;
   1.625 +	return ok;
   1.626  }
   1.627 -