diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/password.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/password.c b/lib/password.c index b9cc1346..432905cc 100644 --- a/lib/password.c +++ b/lib/password.c @@ -110,8 +110,9 @@ int update_password(char *filename, char* username, char* entry) char *filenamesfx = NULL, *namesfx = NULL, *shadow = NULL, *sfx = NULL, *line = NULL; FILE *exfp, *newfp; - int ret = -1, found = 0; + int ret = -1, found = 0, n; struct flock lock; + size_t allocated_length; shadow = strstr(filename, "shadow"); filenamesfx = xmprintf("%s+", filename); @@ -149,8 +150,8 @@ int update_password(char *filename, char* username, char* entry) ret = 0; namesfx = xmprintf("%s:",username); - while ((line = get_line(fileno(exfp))) != NULL) - { + while ((n = getline(&line, &allocated_length, exfp)) > 0) { + line[n-1] = 0; if (strncmp(line, namesfx, strlen(namesfx))) fprintf(newfp, "%s\n", line); else if (entry) { @@ -175,8 +176,8 @@ int update_password(char *filename, char* username, char* entry) fprintf(newfp, "%s\n", entry); } } - free(line); } + free(line); free(namesfx); if (!found && entry) fprintf(newfp, "%s\n", entry); fcntl(fileno(exfp), F_SETLK, &lock); |