From ecd99f44c4d804b6066da1e3600597cb0193e3ec Mon Sep 17 00:00:00 2001 From: David Nugent Date: Sat, 21 Dec 1996 15:35:45 +0000 Subject: 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. --- pw/fileupd.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'pw/fileupd.c') diff --git a/pw/fileupd.c b/pw/fileupd.c index 0abaac6..e49e407 100644 --- a/pw/fileupd.c +++ b/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 @@ -38,6 +38,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) { @@ -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); -- cgit v1.2.3-56-ge451