summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1997-09-15 05:43:37 +0000
committerAndrew Tridgell <tridge@samba.org>1997-09-15 05:43:37 +0000
commit552818e60eff4a87ece94f98c33424c93354bf6c (patch)
treeb5be8d5d2efd9aa4eef8823ea5283a2178385f70 /source3/utils
parentddb2ce9d8100bd2c0475032b99869624db36304c (diff)
downloadsamba-552818e60eff4a87ece94f98c33424c93354bf6c.tar.gz
samba-552818e60eff4a87ece94f98c33424c93354bf6c.tar.bz2
samba-552818e60eff4a87ece94f98c33424c93354bf6c.zip
- 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)
Diffstat (limited to 'source3/utils')
-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);