summaryrefslogtreecommitdiff
path: root/source3/utils/smbpasswd.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/utils/smbpasswd.c')
-rw-r--r--source3/utils/smbpasswd.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c
index bbcefa6b18..c781427474 100644
--- a/source3/utils/smbpasswd.c
+++ b/source3/utils/smbpasswd.c
@@ -375,7 +375,7 @@ static void usage(char *name)
* Open the smbpaswd file XXXX - we need to parse smb.conf to get the
* filename
*/
- if ((fp = fopen(pfile, "r+")) == NULL) {
+ if ((fp = fopen(pfile, "a+")) == NULL) {
err = errno;
fprintf(stderr, "%s: Failed to open password file %s.\n",
argv[0], pfile);
@@ -383,6 +383,10 @@ static void usage(char *name)
perror(argv[0]);
exit(err);
}
+
+ /* position at the start of the file */
+ fseek(fp, 0, SEEK_SET);
+
/* Set read buffer to 16k for effiecient reads */
setvbuf(fp, readbuf, _IOFBF, sizeof(readbuf));
@@ -425,7 +429,7 @@ static void usage(char *name)
if((offpos = lseek(fd, 0, SEEK_END)) == -1) {
fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \
-Error was %d\n", argv[0], pwd->pw_name, pfile, errno);
+Error was %s\n", argv[0], pwd->pw_name, pfile, strerror(errno));
fclose(fp);
pw_file_unlock(lockfd);
exit(1);
@@ -437,7 +441,7 @@ Error was %d\n", argv[0], pwd->pw_name, pfile, errno);
strlen(pwd->pw_shell) + 1;
if((new_entry = (char *)malloc( new_entry_length )) == 0) {
fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \
-Error was %d\n", argv[0], pwd->pw_name, pfile, errno);
+Error was %s\n", argv[0], pwd->pw_name, pfile, strerror(errno));
fclose(fp);
pw_file_unlock(lockfd);
exit(1);
@@ -457,12 +461,12 @@ Error was %d\n", argv[0], pwd->pw_name, pfile, errno);
pwd->pw_dir, pwd->pw_shell);
if(write(fd, new_entry, strlen(new_entry)) != strlen(new_entry)) {
fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \
-Error was %d\n", argv[0], pwd->pw_name, pfile, errno);
+Error was %s\n", argv[0], pwd->pw_name, pfile, strerror(errno));
/* Remove the entry we just wrote. */
if(ftruncate(fd, offpos) == -1) {
fprintf(stderr, "%s: ERROR failed to ftruncate file %s. \
-Error was %d. Password file may be corrupt ! Please examine by hand !\n",
- argv[0], pwd->pw_name, errno);
+Error was %s. Password file may be corrupt ! Please examine by hand !\n",
+ argv[0], pwd->pw_name, strerror(errno));
}
fclose(fp);
pw_file_unlock(lockfd);