Mercurial > 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 wrap: on
line diff
--- a/src/permissions.c Mon Oct 27 16:21:27 2008 +0100 +++ b/src/permissions.c Mon Oct 27 16:23:10 2008 +0100 @@ -21,58 +21,60 @@ #include <grp.h> /* is there really no function in libc for this? */ -gboolean is_ingroup(uid_t uid, gid_t gid) +gboolean +is_ingroup(uid_t uid, gid_t gid) { - struct group *grent = getgrgid(gid); + struct group *grent = getgrgid(gid); - if(grent){ - struct passwd *pwent = getpwuid(uid); - if(pwent){ - char *entry; - int i = 0; - while((entry = grent->gr_mem[i++])){ - if(strcmp(pwent->pw_name, entry) == 0) - return TRUE; - } - } - } - return FALSE; + if (grent) { + struct passwd *pwent = getpwuid(uid); + if (pwent) { + char *entry; + int i = 0; + while ((entry = grent->gr_mem[i++])) { + if (strcmp(pwent->pw_name, entry) == 0) + return TRUE; + } + } + } + return FALSE; } -gboolean is_privileged_user(uid_t uid) +gboolean +is_privileged_user(uid_t uid) { - return (uid == 0) || (uid == conf.mail_uid) || (is_ingroup(uid, conf.mail_gid)); + return (uid == 0) || (uid == conf.mail_uid) || (is_ingroup(uid, conf.mail_gid)); } -void set_euidgid(gint uid, gint gid, uid_t *old_uid, gid_t *old_gid) +void +set_euidgid(gint uid, gint gid, uid_t * old_uid, gid_t * old_gid) { - if(old_uid) *old_uid = geteuid(); - if(old_gid) *old_gid = getegid(); - - seteuid(0); + if (old_uid) + *old_uid = geteuid(); + if (old_gid) + *old_gid = getegid(); - if(setegid(gid) != 0){ - logwrite(LOG_ALERT, "could not change gid to %d: %s\n", - gid, strerror(errno)); - exit(EXIT_FAILURE); - } - if(seteuid(uid) != 0){ - logwrite(LOG_ALERT, "could not change uid to %d: %s\n", - uid, strerror(errno)); - exit(EXIT_FAILURE); - } + seteuid(0); + + if (setegid(gid) != 0) { + logwrite(LOG_ALERT, "could not change gid to %d: %s\n", gid, strerror(errno)); + exit(EXIT_FAILURE); + } + if (seteuid(uid) != 0) { + logwrite(LOG_ALERT, "could not change uid to %d: %s\n", uid, strerror(errno)); + exit(EXIT_FAILURE); + } } -void set_identity(uid_t old_uid, gchar *task_name) +void +set_identity(uid_t old_uid, gchar * task_name) { - if(!conf.run_as_user){ - if(!is_privileged_user(old_uid)){ - fprintf(stderr, - "must be root, %s or in group %s for %s.\n", - DEF_MAIL_USER, DEF_MAIL_GROUP, task_name); - exit(EXIT_FAILURE); - } + if (!conf.run_as_user) { + if (!is_privileged_user(old_uid)) { + fprintf(stderr, "must be root, %s or in group %s for %s.\n", DEF_MAIL_USER, DEF_MAIL_GROUP, task_name); + exit(EXIT_FAILURE); + } - set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL); - } + set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL); + } }