From owner-svn-src-all@FreeBSD.ORG Sun Jul 6 23:24:07 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8D4188A1; Sun, 6 Jul 2014 23:24:07 +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 79C8C2FE1; Sun, 6 Jul 2014 23:24:07 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s66NO77c087455; Sun, 6 Jul 2014 23:24:07 GMT (envelope-from bapt@svn.freebsd.org) Received: (from bapt@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s66NO6Hl087451; Sun, 6 Jul 2014 23:24:06 GMT (envelope-from bapt@svn.freebsd.org) Message-Id: <201407062324.s66NO6Hl087451@svn.freebsd.org> From: Baptiste Daroussin Date: Sun, 6 Jul 2014 23:24:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r268346 - stable/10/usr.sbin/pw X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Jul 2014 23:24:07 -0000 Author: bapt Date: Sun Jul 6 23:24:06 2014 New Revision: 268346 URL: http://svnweb.freebsd.org/changeset/base/268346 Log: MFH: r264781, r267669, r267670 Simplify reading pw.conf(5) by using getline(3) Removed compatibility with pre FreeBSD 2.2 pw_mkdb command [1] Fix some broken indentattion [1] Fix changing the username [2] PR: 189172 [1], 189173 [2] Submitted by: fullermd@over-yonder.net [1][2] Modified: stable/10/usr.sbin/pw/pw.h stable/10/usr.sbin/pw/pw_conf.c stable/10/usr.sbin/pw/pwupd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.sbin/pw/pw.h ============================================================================== --- stable/10/usr.sbin/pw/pw.h Sun Jul 6 23:23:01 2014 (r268345) +++ stable/10/usr.sbin/pw/pw.h Sun Jul 6 23:24:06 2014 (r268346) @@ -26,6 +26,7 @@ * $FreeBSD$ */ +#define _WITH_GETLINE #include #include #include Modified: stable/10/usr.sbin/pw/pw_conf.c ============================================================================== --- stable/10/usr.sbin/pw/pw_conf.c Sun Jul 6 23:23:01 2014 (r268345) +++ stable/10/usr.sbin/pw/pw_conf.c Sun Jul 6 23:24:06 2014 (r268346) @@ -226,35 +226,21 @@ newstr(char const * p) struct userconf * read_userconfig(char const * file) { - FILE *fp; + FILE *fp; + char *buf, *p; + size_t linecap; + ssize_t linelen; + + buf = NULL; + linecap = 0; extendarray(&config.groups, &config.numgroups, 200); memset(config.groups, 0, config.numgroups * sizeof(char *)); if (file == NULL) file = _PATH_PW_CONF; - if ((fp = fopen(file, "r")) != NULL) { - int buflen = LNBUFSZ; - char *buf = malloc(buflen); - - nextline: - while (fgets(buf, buflen, fp) != NULL) { - char *p; - - while ((p = strchr(buf, '\n')) == NULL) { - int l; - if (extendline(&buf, &buflen, buflen + LNBUFSZ) == -1) { - int ch; - while ((ch = fgetc(fp)) != '\n' && ch != EOF); - goto nextline; /* Ignore it */ - } - l = strlen(buf); - if (fgets(buf + l, buflen - l, fp) == NULL) - break; /* Unterminated last line */ - } - - if (p != NULL) - *p = '\0'; + if ((fp = fopen(file, "r")) != NULL) { + while ((linelen = getline(&buf, &linecap, fp)) > 0) { if (*buf && (p = strtok(buf, " \t\r\n=")) != NULL && *p != '#') { static char const toks[] = " \t\r\n,="; char *q = strtok(NULL, toks); @@ -368,7 +354,8 @@ read_userconfig(char const * file) } } } - free(buf); + if (linecap > 0) + free(buf); fclose(fp); } return &config; Modified: stable/10/usr.sbin/pw/pwupd.c ============================================================================== --- stable/10/usr.sbin/pw/pwupd.c Sun Jul 6 23:23:01 2014 (r268345) +++ stable/10/usr.sbin/pw/pwupd.c Sun Jul 6 23:24:06 2014 (r268346) @@ -45,9 +45,6 @@ static const char rcsid[] = #include "pwupd.h" -#define HAVE_PWDB_C 1 -#define HAVE_PWDB_U 1 - static char pathpwd[] = _PATH_PWD; static char * pwpath = pathpwd; @@ -112,22 +109,14 @@ pw_update(struct passwd * pwd, char cons { int rc = 0; - /* - * First, let's check the see if the database is alright - * Note: -C is only available in FreeBSD 2.2 and above - */ -#ifdef HAVE_PWDB_C rc = pwdb("-C", (char *)NULL); /* Check only */ if (rc == 0) { -#else - { /* No -C */ -#endif int pfd, tfd; struct passwd *pw = NULL; struct passwd *old_pw = NULL; - if (pwd != NULL) - pw = pw_dup(pwd); + if (pwd != NULL) + pw = pw_dup(pwd); if (user != NULL) old_pw = GETPWNAM(user); @@ -150,7 +139,7 @@ pw_update(struct passwd * pwd, char cons * in case of deletion of a user, the whole database * needs to be regenerated */ - if (pw_mkdb(pw != NULL ? user : NULL) == -1) { + if (pw_mkdb(pw != NULL ? pw->pw_name : NULL) == -1) { pw_fini(); err(1, "pw_mkdb()"); }