From owner-svn-src-head@FreeBSD.ORG Sun May 10 09:11:13 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BB034B30; Sun, 10 May 2015 09:11:13 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 904F5151B; Sun, 10 May 2015 09:11:13 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t4A9BD9P004613; Sun, 10 May 2015 09:11:13 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t4A9BDB1004612; Sun, 10 May 2015 09:11:13 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201505100911.t4A9BDB1004612@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Sun, 10 May 2015 09:11:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r282712 - head/usr.sbin/pw X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 May 2015 09:11:13 -0000 Author: bapt Date: Sun May 10 09:11:12 2015 New Revision: 282712 URL: https://svnweb.freebsd.org/changeset/base/282712 Log: if the check of the pw db fails return the failed value Modified: head/usr.sbin/pw/pwupd.c Modified: head/usr.sbin/pw/pwupd.c ============================================================================== --- head/usr.sbin/pw/pwupd.c Sun May 10 09:09:07 2015 (r282711) +++ head/usr.sbin/pw/pwupd.c Sun May 10 09:11:12 2015 (r282712) @@ -110,45 +110,43 @@ pwdb(char *arg,...) static int pw_update(struct passwd * pwd, char const * user) { - int rc = 0; - - rc = pwdb("-C", (char *)NULL); /* Check only */ - if (rc == 0) { - int pfd, tfd; - struct passwd *pw = NULL; - struct passwd *old_pw = NULL; - - if (pwd != NULL) - pw = pw_dup(pwd); - - if (user != NULL) - old_pw = GETPWNAM(user); - - if (pw_init(pwpath, NULL)) - err(1, "pw_init()"); - if ((pfd = pw_lock()) == -1) { - pw_fini(); - err(1, "pw_lock()"); - } - if ((tfd = pw_tmp(-1)) == -1) { - pw_fini(); - err(1, "pw_tmp()"); - } - if (pw_copy(pfd, tfd, pw, old_pw) == -1) { - pw_fini(); - err(1, "pw_copy()"); - } - /* - * in case of deletion of a user, the whole database - * needs to be regenerated - */ - if (pw_mkdb(pw != NULL ? pw->pw_name : NULL) == -1) { - pw_fini(); - err(1, "pw_mkdb()"); - } - free(pw); + struct passwd *pw = NULL; + struct passwd *old_pw = NULL; + int rc, pfd, tfd; + + if ((rc = pwdb("-C", NULL)) != 0) + return (rc); + + if (pwd != NULL) + pw = pw_dup(pwd); + + if (user != NULL) + old_pw = GETPWNAM(user); + + if (pw_init(pwpath, NULL)) + err(1, "pw_init()"); + if ((pfd = pw_lock()) == -1) { + pw_fini(); + err(1, "pw_lock()"); + } + if ((tfd = pw_tmp(-1)) == -1) { + pw_fini(); + err(1, "pw_tmp()"); + } + if (pw_copy(pfd, tfd, pw, old_pw) == -1) { + pw_fini(); + err(1, "pw_copy()"); + } + /* + * in case of deletion of a user, the whole database + * needs to be regenerated + */ + if (pw_mkdb(pw != NULL ? pw->pw_name : NULL) == -1) { pw_fini(); + err(1, "pw_mkdb()"); } + free(pw); + pw_fini(); return (0); }