svn commit: r268346 - stable/10/usr.sbin/pw
Baptiste Daroussin
bapt at FreeBSD.org
Sun Jul 6 23:24:07 UTC 2014
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 at 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
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()");
}
More information about the svn-src-stable-10
mailing list