]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/useradd.c: create_mail(): Cosmetic
authorAlejandro Colomar <alx@kernel.org>
Wed, 7 Jun 2023 21:56:30 +0000 (23:56 +0200)
committerSerge Hallyn <serge@hallyn.com>
Sat, 10 Jun 2023 00:04:51 +0000 (19:04 -0500)
-  Invert conditional to reduce indentation.
-  Reduce use of whitespace and newlines while unindenting.
-  Reorder variable declarations.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/useradd.c

index 928ee0d65b0a95ceaa23e454ee2d398ace6fce9e..ebfb477cd44e3b5640075ab23c858b6b721b7bf8 100644 (file)
@@ -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)