diff options
author | davidn <davidn@FreeBSD.org> | 1996-12-21 15:35:45 +0000 |
---|---|---|
committer | davidn <davidn@FreeBSD.org> | 1996-12-21 15:35:45 +0000 |
commit | ae5c4633974707111deaccca4fce48ed57a8709a (patch) | |
tree | a19b414da205cc5b6cb7bfd7df7d715f90b3c13f /usr.sbin/pw/fileupd.c | |
parent | 705d04d9c464156ec9eec74e0154ef19287ddeca (diff) | |
download | FreeBSD-src-ae5c4633974707111deaccca4fce48ed57a8709a.zip FreeBSD-src-ae5c4633974707111deaccca4fce48ed57a8709a.tar.gz |
1) 200 users per group limitation removed and pw
will handle lines of any length in /etc/group.
2) Fixed bug with usermod -d not updating user's home
directory.
3) Minor formatting display changes/fixes with *show -P.
Diffstat (limited to 'usr.sbin/pw/fileupd.c')
-rw-r--r-- | usr.sbin/pw/fileupd.c | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/usr.sbin/pw/fileupd.c b/usr.sbin/pw/fileupd.c index 0abaac6..e49e407 100644 --- a/usr.sbin/pw/fileupd.c +++ b/usr.sbin/pw/fileupd.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: fileupd.c,v 1.1.1.1 1996/12/09 14:05:35 joerg Exp $ + * $Id: fileupd.c,v 1.1.1.2 1996/12/10 23:58:55 joerg Exp $ */ #include <stdio.h> @@ -39,6 +39,33 @@ #include "pwupd.h" int +extendline(char **buf, int * buflen, int needed) +{ + if (needed > *buflen) { + char *tmp = realloc(*buf, needed); + if (tmp == NULL) + return -1; + *buf = tmp; + *buflen = needed; + } + return *buflen; +} + +int +extendarray(char ***buf, int * buflen, int needed) +{ + if (needed > *buflen) { + char **tmp = realloc(*buf, needed * sizeof(char *)); + if (tmp == NULL) + return -1; + *buf = tmp; + *buflen = needed; + } + return *buflen; +} + + +int fileupdate(char const * filename, mode_t fmode, char const * newline, char const * prefix, int pfxlen, int updmode) { int rc = 0; @@ -67,21 +94,28 @@ fileupdate(char const * filename, mode_t fmode, char const * newline, char const close(outfd); else { int updated = UPD_CREATE; - char line[2048]; + int linesize = PWBUFSZ; + char *line = malloc(linesize); - while (fgets(line, sizeof(line), infp) != NULL) { + nextline: + while (fgets(line, linesize, infp) != NULL) { char *p = strchr(line, '\n'); - if (p == NULL) { /* Line too long */ - int ch; - - fputs(line, outfp); - while ((ch = fgetc(infp)) != EOF) { - fputc(ch, outfp); - if (ch == '\n') - break; + while ((p = strchr(line, '\n')) == NULL) { + int l; + if (extendline(&line, &linesize, linesize + PWBUFSZ) == -1) { + int ch; + fputs(line, outfp); + while ((ch = fgetc(infp)) != EOF) { + fputc(ch, outfp); + if (ch == '\n') + break; + } + goto nextline; } - continue; + l = strlen(line); + if (fgets(line + l, linesize - l, infp) == NULL) + break; } if (*line != '#' && *line != '\n') { if (!updated && strncmp(line, prefix, pfxlen) == 0) { @@ -127,7 +161,7 @@ fileupdate(char const * filename, mode_t fmode, char const * newline, char const */ rewind(infp); rewind(outfp); - while (fgets(line, sizeof(line), outfp) != NULL) + while (fgets(line, linesize, outfp) != NULL) fputs(line, infp); /* @@ -141,6 +175,7 @@ fileupdate(char const * filename, mode_t fmode, char const * newline, char const ftruncate(infd, ftell(infp)); } } + free(line); fclose(outfp); } remove(file); |