]> granicus.if.org Git - shadow/commitdiff
* libmisc/chowntty.c: Avoid assignments in comparisons.
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Fri, 13 Jun 2008 18:29:02 +0000 (18:29 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Fri, 13 Jun 2008 18:29:02 +0000 (18:29 +0000)
* libmisc/chowntty.c: Avoid implicit conversion of pointers to
booleans.
* libmisc/chowntty.c: Add brackets and parenthesis.

ChangeLog
libmisc/chowntty.c

index e9740bdfd14a95bd390bfc24ce94f7ee5d6f78d4..e7129ef8c32a2b63e9c0384768961204e4426a50 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-06-13  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * libmisc/chowntty.c: Avoid assignments in comparisons.
+       * libmisc/chowntty.c: Avoid implicit conversion of pointers to
+       booleans.
+       * libmisc/chowntty.c: Add brackets and parenthesis.
+
 2008-06-13  Nicolas François  <nicolas.francois@centraliens.net>
 
        * libmisc/audit_help.c: Add brackets.
index fe949c7eff50a8478eae807199d47d51ede18e85..0a68e337ee2ca0e44d4c76130e306029cb58c14f 100644 (file)
@@ -78,21 +78,26 @@ void chown_tty (const char *tty, const struct passwd *info)
         * ID.  Otherwise, use the user's primary group ID.
         */
 
-       if (!(group = getdef_str ("TTYGROUP")))
-               gid = info->pw_gid;
-       else if (group[0] >= '0' && group[0] <= '9')
-               gid = atoi (group);
-       else if ((grent = getgrnam (group))) /* local, no need for xgetgrnam */
-               gid = grent->gr_gid;
-       else
+       group = getdef_str ("TTYGROUP");
+       if (NULL == group) {
                gid = info->pw_gid;
+       } else if ((group[0] >= '0') && (group[0] <= '9')) {
+               gid = (gid_t) atol (group);
+       } else {
+               grent = getgrnam (group); /* local, no need for xgetgrnam */
+               if (NULL != grent) {
+                       gid = grent->gr_gid;
+               } else {
+                       gid = info->pw_gid;
+               }
+       }
 
        /*
         * Change the permissions on the TTY to be owned by the user with
         * the group as determined above.
         */
 
-       if (*tty != '/') {
+       if ('/' != *tty) {
                snprintf (full_tty, sizeof full_tty, "/dev/%s", tty);
                tty = full_tty;
        }
@@ -104,8 +109,8 @@ void chown_tty (const char *tty, const struct passwd *info)
                exit (1);
        }
 
-       if ((chown (tty, info->pw_uid, gid) != 0)||
-           (chmod (tty, getdef_num ("TTYPERM", 0600)) != 0)) {
+       if (   (chown (tty, info->pw_uid, gid) != 0)
+           || (chmod (tty, getdef_num ("TTYPERM", 0600)) != 0)) {
                int err = errno;
 
                snprintf (buf, sizeof buf, _("Unable to change tty %s"), tty);
@@ -115,8 +120,9 @@ void chown_tty (const char *tty, const struct passwd *info)
                         info->pw_name));
                closelog ();
 
-               if (err != EROFS)
+               if (EROFS != err) {
                        exit (1);
+               }
        }
 #ifdef __linux__
        /*