masqmail

diff src/permissions.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/permissions.c	Mon Oct 27 16:21:27 2008 +0100
     1.2 +++ b/src/permissions.c	Mon Oct 27 16:23:10 2008 +0100
     1.3 @@ -21,58 +21,60 @@
     1.4  #include <grp.h>
     1.5  
     1.6  /* is there really no function in libc for this? */
     1.7 -gboolean is_ingroup(uid_t uid, gid_t gid)
     1.8 +gboolean
     1.9 +is_ingroup(uid_t uid, gid_t gid)
    1.10  {
    1.11 -  struct group *grent = getgrgid(gid);
    1.12 +	struct group *grent = getgrgid(gid);
    1.13  
    1.14 -  if(grent){
    1.15 -    struct passwd *pwent = getpwuid(uid);
    1.16 -    if(pwent){
    1.17 -      char *entry;
    1.18 -      int i = 0;
    1.19 -      while((entry = grent->gr_mem[i++])){
    1.20 -	if(strcmp(pwent->pw_name, entry) == 0)
    1.21 -	  return TRUE;
    1.22 -      }
    1.23 -    }
    1.24 -  }
    1.25 -  return FALSE;
    1.26 +	if (grent) {
    1.27 +		struct passwd *pwent = getpwuid(uid);
    1.28 +		if (pwent) {
    1.29 +			char *entry;
    1.30 +			int i = 0;
    1.31 +			while ((entry = grent->gr_mem[i++])) {
    1.32 +				if (strcmp(pwent->pw_name, entry) == 0)
    1.33 +					return TRUE;
    1.34 +			}
    1.35 +		}
    1.36 +	}
    1.37 +	return FALSE;
    1.38  }
    1.39  
    1.40 -gboolean is_privileged_user(uid_t uid)
    1.41 +gboolean
    1.42 +is_privileged_user(uid_t uid)
    1.43  {
    1.44 -  return (uid == 0) || (uid == conf.mail_uid) || (is_ingroup(uid, conf.mail_gid));
    1.45 +	return (uid == 0) || (uid == conf.mail_uid) || (is_ingroup(uid, conf.mail_gid));
    1.46  }
    1.47  
    1.48 -void set_euidgid(gint uid, gint gid, uid_t *old_uid, gid_t *old_gid)
    1.49 +void
    1.50 +set_euidgid(gint uid, gint gid, uid_t * old_uid, gid_t * old_gid)
    1.51  {
    1.52 -  if(old_uid) *old_uid = geteuid();
    1.53 -  if(old_gid) *old_gid = getegid();
    1.54 +	if (old_uid)
    1.55 +		*old_uid = geteuid();
    1.56 +	if (old_gid)
    1.57 +		*old_gid = getegid();
    1.58  
    1.59 -  seteuid(0);
    1.60 +	seteuid(0);
    1.61  
    1.62 -  if(setegid(gid) != 0){
    1.63 -    logwrite(LOG_ALERT, "could not change gid to %d: %s\n",
    1.64 -	     gid, strerror(errno));
    1.65 -    exit(EXIT_FAILURE);
    1.66 -  }
    1.67 -  if(seteuid(uid) != 0){
    1.68 -    logwrite(LOG_ALERT, "could not change uid to %d: %s\n",
    1.69 -	     uid, strerror(errno));
    1.70 -    exit(EXIT_FAILURE);
    1.71 -  }
    1.72 +	if (setegid(gid) != 0) {
    1.73 +		logwrite(LOG_ALERT, "could not change gid to %d: %s\n", gid, strerror(errno));
    1.74 +		exit(EXIT_FAILURE);
    1.75 +	}
    1.76 +	if (seteuid(uid) != 0) {
    1.77 +		logwrite(LOG_ALERT, "could not change uid to %d: %s\n", uid, strerror(errno));
    1.78 +		exit(EXIT_FAILURE);
    1.79 +	}
    1.80  }
    1.81  
    1.82 -void set_identity(uid_t old_uid, gchar *task_name)
    1.83 +void
    1.84 +set_identity(uid_t old_uid, gchar * task_name)
    1.85  {
    1.86 -  if(!conf.run_as_user){
    1.87 -    if(!is_privileged_user(old_uid)){
    1.88 -      fprintf(stderr,
    1.89 -	      "must be root, %s or in group %s for %s.\n",
    1.90 -	      DEF_MAIL_USER, DEF_MAIL_GROUP, task_name);
    1.91 -      exit(EXIT_FAILURE);
    1.92 -    }
    1.93 +	if (!conf.run_as_user) {
    1.94 +		if (!is_privileged_user(old_uid)) {
    1.95 +			fprintf(stderr, "must be root, %s or in group %s for %s.\n", DEF_MAIL_USER, DEF_MAIL_GROUP, task_name);
    1.96 +			exit(EXIT_FAILURE);
    1.97 +		}
    1.98  
    1.99 -    set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL);
   1.100 -  }
   1.101 +		set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL);
   1.102 +	}
   1.103  }