From: Alejandro Colomar Date: Wed, 7 Jun 2023 21:56:30 +0000 (+0200) Subject: src/useradd.c: create_mail(): Cosmetic X-Git-Tag: 4.14.0-rc1~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e69d556b63f202680a47a40a974046140a3cff15;p=thirdparty%2Fshadow.git src/useradd.c: create_mail(): Cosmetic - Invert conditional to reduce indentation. - Reduce use of whitespace and newlines while unindenting. - Reorder variable declarations. Signed-off-by: Alejandro Colomar --- diff --git a/src/useradd.c b/src/useradd.c index 928ee0d65..ebfb477cd 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -2406,76 +2406,78 @@ static void create_home (void) */ static void create_mail (void) { - if (strcasecmp (create_mail_spool, "yes") == 0) { - const char *spool; - char *file; - size_t size; - int fd; - struct group *gr; - gid_t gid; - mode_t mode; - - spool = getdef_str ("MAIL_DIR"); + int fd; + char *file; + gid_t gid; + mode_t mode; + size_t size; + const char *spool; + struct group *gr; + + if (strcasecmp(create_mail_spool, "yes") != 0) + return; + + spool = getdef_str("MAIL_DIR"); #ifdef MAIL_SPOOL_DIR - if ((NULL == spool) && (getdef_str ("MAIL_FILE") == NULL)) { - spool = MAIL_SPOOL_DIR; - } + if ((NULL == spool) && (getdef_str("MAIL_FILE") == NULL)) { + spool = MAIL_SPOOL_DIR; + } #endif /* MAIL_SPOOL_DIR */ - if (NULL == spool) { - return; - } - size = strlen(prefix) + strlen(spool) + strlen(user_name) + 3; - file = XMALLOC(size, char); - if (prefix[0]) - sprintf (file, "%s/%s/%s", prefix, spool, user_name); - else - sprintf (file, "%s/%s", spool, user_name); + if (NULL == spool) { + return; + } + size = strlen(prefix) + strlen(spool) + strlen(user_name) + 3; + file = XMALLOC(size, char); + if (prefix[0]) + sprintf(file, "%s/%s/%s", prefix, spool, user_name); + else + sprintf(file, "%s/%s", spool, user_name); #ifdef WITH_SELINUX - if (set_selinux_file_context (file, S_IFREG) != 0) { - fprintf (stderr, - _("%s: cannot set SELinux context for mailbox file %s\n"), - Prog, file); - fail_exit (E_MAILBOXFILE); - } + if (set_selinux_file_context(file, S_IFREG) != 0) { + fprintf(stderr, + _("%s: cannot set SELinux context for mailbox file %s\n"), + Prog, file); + fail_exit(E_MAILBOXFILE); + } #endif - fd = open (file, O_CREAT | O_WRONLY | O_TRUNC | O_EXCL, 0); - free(file); + fd = open(file, O_CREAT | O_WRONLY | O_TRUNC | O_EXCL, 0); + free(file); - if (fd < 0) { - perror (_("Creating mailbox file")); - return; - } + if (fd < 0) { + perror(_("Creating mailbox file")); + return; + } - gr = prefix_getgrnam ("mail"); /* local, no need for xgetgrnam */ - if (NULL == gr) { - fputs (_("Group 'mail' not found. Creating the user mailbox file with 0600 mode.\n"), - stderr); - gid = user_gid; - mode = 0600; - } else { - gid = gr->gr_gid; - mode = 0660; - } + gr = prefix_getgrnam("mail"); /* local, no need for xgetgrnam */ + if (NULL == gr) { + fputs(_("Group 'mail' not found. Creating the user mailbox file with 0600 mode.\n"), + stderr); + gid = user_gid; + mode = 0600; + } else { + gid = gr->gr_gid; + mode = 0660; + } - if ( (fchown (fd, user_id, gid) != 0) - || (fchmod (fd, mode) != 0)) { - perror (_("Setting mailbox file permissions")); - } + if (fchown(fd, user_id, gid) != 0 + || fchmod(fd, mode) != 0) + { + perror(_("Setting mailbox file permissions")); + } - fsync (fd); - close (fd); + fsync(fd); + close(fd); #ifdef WITH_SELINUX - /* Reset SELinux to create files with default contexts */ - if (reset_selinux_file_context () != 0) { - fprintf (stderr, - _("%s: cannot reset SELinux file creation context\n"), - Prog); - fail_exit (E_MAILBOXFILE); - } -#endif + /* Reset SELinux to create files with default contexts */ + if (reset_selinux_file_context() != 0) { + fprintf(stderr, + _("%s: cannot reset SELinux file creation context\n"), + Prog); + fail_exit(E_MAILBOXFILE); } +#endif } static void check_uid_range(int rflg, uid_t user_id)