Author: bapt
Date: Sun May 31 11:23:19 2015
New Revision: 283814
URL: https://svnweb.freebsd.org/changeset/base/283814

Log:
  Make pw_user()/pw_group() more consitent about errors
  
  Some of errors were returned to the main function, some others caused a direct
  exit via err(3).
  
  The main function is only interested in EXIT_SUCCESS, so in all other cases
  replace warn(3) + return err by err(3)

Modified:
  head/usr.sbin/pw/pw_group.c
  head/usr.sbin/pw/pw_user.c

Modified: head/usr.sbin/pw/pw_group.c
==============================================================================
--- head/usr.sbin/pw/pw_group.c Sun May 31 10:51:36 2015        (r283813)
+++ head/usr.sbin/pw/pw_group.c Sun May 31 11:23:19 2015        (r283814)
@@ -135,8 +135,7 @@ pw_group(struct userconf * cnf, int mode
                        if (rc == -1)
                                err(EX_IOERR, "group '%s' not available 
(NIS?)", grp->gr_name);
                        else if (rc != 0) {
-                               warn("group update");
-                               return EX_IOERR;
+                               err(EX_IOERR, "group update");
                        }
                        pw_log(cnf, mode, W_GROUP, "%s(%ld) removed", 
a_name->val, (long) gid);
                        return EXIT_SUCCESS;
@@ -201,10 +200,8 @@ pw_group(struct userconf * cnf, int mode
                                fputc('\n', stdout);
                                fflush(stdout);
                        }
-                       if (b < 0) {
-                               warn("-h file descriptor");
-                               return EX_OSERR;
-                       }
+                       if (b < 0)
+                               err(EX_OSERR, "-h file descriptor");
                        line[b] = '\0';
                        if ((p = strpbrk(line, " \t\r\n")) != NULL)
                                *p = '\0';
@@ -265,16 +262,16 @@ pw_group(struct userconf * cnf, int mode
 
        if (mode == M_ADD && (rc = addgrent(grp)) != 0) {
                if (rc == -1)
-                       warnx("group '%s' already exists", grp->gr_name);
+                       errx(EX_IOERR, "group '%s' already exists",
+                           grp->gr_name);
                else
-                       warn("group update");
-               return EX_IOERR;
+                       err(EX_IOERR, "group update");
        } else if (mode == M_UPDATE && (rc = chggrent(a_name->val, grp)) != 0) {
                if (rc == -1)
-                       warnx("group '%s' not available (NIS?)", grp->gr_name);
+                       errx(EX_IOERR, "group '%s' not available (NIS?)",
+                           grp->gr_name);
                else
-                       warn("group update");
-               return EX_IOERR;
+                       err(EX_IOERR, "group update");
        }
 
        arg = a_newname != NULL ? a_newname : a_name;

Modified: head/usr.sbin/pw/pw_user.c
==============================================================================
--- head/usr.sbin/pw/pw_user.c  Sun May 31 10:51:36 2015        (r283813)
+++ head/usr.sbin/pw/pw_user.c  Sun May 31 11:23:19 2015        (r283814)
@@ -286,8 +286,7 @@ pw_user(struct userconf * cnf, int mode,
                arg = getarg(args, 'C');
                if (write_userconfig(arg ? arg->val : NULL))
                        return EXIT_SUCCESS;
-               warn("config update");
-               return EX_IOERR;
+               err(EX_IOERR, "config udpate");
        }
 
        if (mode == M_PRINT && getarg(args, 'a')) {
@@ -416,10 +415,8 @@ pw_user(struct userconf * cnf, int mode,
                        rc = delpwent(pwd);
                        if (rc == -1)
                                err(EX_IOERR, "user '%s' does not exist", 
pwd->pw_name);
-                       else if (rc != 0) {
-                               warn("passwd update");
-                               return EX_IOERR;
-                       }
+                       else if (rc != 0)
+                               err(EX_IOERR, "passwd update");
 
                        if (cnf->nispasswd && *cnf->nispasswd=='/') {
                                rc = delnispwent(cnf->nispasswd, a_name->val);
@@ -672,11 +669,9 @@ pw_user(struct userconf * cnf, int mode,
                                fputc('\n', stdout);
                                fflush(stdout);
                        }
-                       if (b < 0) {
-                               warn("-%c file descriptor", precrypt ? 'H' :
-                                   'h');
-                               return EX_IOERR;
-                       }
+                       if (b < 0)
+                               err(EX_IOERR, "-%c file descriptor",
+                                   precrypt ? 'H' : 'h');
                        line[b] = '\0';
                        if ((p = strpbrk(line, "\r\n")) != NULL)
                                *p = '\0';
@@ -709,13 +704,11 @@ pw_user(struct userconf * cnf, int mode,
        if (mode == M_ADD) {
                edited = 1;     /* Always */
                rc = addpwent(pwd);
-               if (rc == -1) {
-                       warnx("user '%s' already exists", pwd->pw_name);
-                       return EX_IOERR;
-               } else if (rc != 0) {
-                       warn("passwd file update");
-                       return EX_IOERR;
-               }
+               if (rc == -1)
+                       errx(EX_IOERR, "user '%s' already exists",
+                           pwd->pw_name);
+               else if (rc != 0)
+                       err(EX_IOERR, "passwd file update");
                if (cnf->nispasswd && *cnf->nispasswd=='/') {
                        rc = addnispwent(cnf->nispasswd, pwd);
                        if (rc == -1)
@@ -727,13 +720,10 @@ pw_user(struct userconf * cnf, int mode,
        } else if (mode == M_UPDATE || mode == M_LOCK || mode == M_UNLOCK) {
                if (edited) {   /* Only updated this if required */
                        rc = chgpwent(a_name->val, pwd);
-                       if (rc == -1) {
-                               warnx("user '%s' does not exist (NIS?)", 
pwd->pw_name);
-                               return EX_IOERR;
-                       } else if (rc != 0) {
-                               warn("passwd file update");
-                               return EX_IOERR;
-                       }
+                       if (rc == -1)
+                               errx(EX_IOERR, "user '%s' does not exist 
(NIS?)", pwd->pw_name);
+                       else if (rc != 0)
+                               err(EX_IOERR, "passwd file update");
                        if ( cnf->nispasswd && *cnf->nispasswd=='/') {
                                rc = chgnispwent(cnf->nispasswd, a_name->val, 
pwd);
                                if (rc == -1)
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to