summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorbapt <bapt@FreeBSD.org>2014-07-06 23:24:06 +0000
committerbapt <bapt@FreeBSD.org>2014-07-06 23:24:06 +0000
commit6763aa7bd25f654b3dc700a96e9e409f4c692dcd (patch)
tree8ef5220b4aba4f0144e7c56dcf8dc37bcac68890 /usr.sbin
parent302b3764d6b807bf0f5ea610145ac630d9621afd (diff)
downloadFreeBSD-src-6763aa7bd25f654b3dc700a96e9e409f4c692dcd.zip
FreeBSD-src-6763aa7bd25f654b3dc700a96e9e409f4c692dcd.tar.gz
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]
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pw/pw.h1
-rw-r--r--usr.sbin/pw/pw_conf.c35
-rw-r--r--usr.sbin/pw/pwupd.c17
3 files changed, 15 insertions, 38 deletions
diff --git a/usr.sbin/pw/pw.h b/usr.sbin/pw/pw.h
index 1ff69a6..a1ed0c4 100644
--- a/usr.sbin/pw/pw.h
+++ b/usr.sbin/pw/pw.h
@@ -26,6 +26,7 @@
* $FreeBSD$
*/
+#define _WITH_GETLINE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/usr.sbin/pw/pw_conf.c b/usr.sbin/pw/pw_conf.c
index edeb015..1289b3e 100644
--- a/usr.sbin/pw/pw_conf.c
+++ b/usr.sbin/pw/pw_conf.c
@@ -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;
diff --git a/usr.sbin/pw/pwupd.c b/usr.sbin/pw/pwupd.c
index 22662db..c2a9a53 100644
--- a/usr.sbin/pw/pwupd.c
+++ b/usr.sbin/pw/pwupd.c
@@ -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 const * user)
{
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 const * user)
* 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()");
}
OpenPOWER on IntegriCloud