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]
This commit is contained in:
parent
302b3764d6
commit
6763aa7bd2
@ -26,6 +26,7 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#define _WITH_GETLINE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -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';
|
||||
|
||||
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;
|
||||
|
@ -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()");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user