summaryrefslogtreecommitdiffstats
path: root/pw/fileupd.c
diff options
context:
space:
mode:
authorDavid Nugent <davidn@FreeBSD.org>1996-12-21 15:35:45 +0000
committerDavid Nugent <davidn@FreeBSD.org>1996-12-21 15:35:45 +0000
commit0c9f365da25caa3b04bcfe82b70ee49aab96e619 (patch)
tree3307dfadeecd6d5dccb408b4e3ae778dfc80b56f /pw/fileupd.c
parent16a21e7a7bdcc33504a9ee08c9af57d1c8dc874f (diff)
downloadpw-darwin-0c9f365da25caa3b04bcfe82b70ee49aab96e619.tar.gz
pw-darwin-0c9f365da25caa3b04bcfe82b70ee49aab96e619.tar.zst
pw-darwin-0c9f365da25caa3b04bcfe82b70ee49aab96e619.zip
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 'pw/fileupd.c')
-rw-r--r--pw/fileupd.c61
1 files changed, 48 insertions, 13 deletions
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 <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);