From 552818e60eff4a87ece94f98c33424c93354bf6c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Sep 1997 05:43:37 +0000 Subject: - change a lot of occurances of errno to use strerror(errno). We can't assume all our users are programmers :-) - automatically create the smbpasswd file if it doesn't exist when running smbpasswd. (This used to be commit 1d2361bd2dec35bce029699f54c6a61fa739fa4b) --- source3/utils/smbpasswd.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'source3/utils/smbpasswd.c') 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); -- cgit