diff options
author | Andrew Tridgell <tridge@samba.org> | 1997-09-15 06:36:55 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1997-09-15 06:36:55 +0000 |
commit | 6e3697ad1218264c85c6c1f4b1521960e21e2a67 (patch) | |
tree | 5eded02955adc4e73468e83da813d5455dc2361d /source/utils | |
parent | 1d2361bd2dec35bce029699f54c6a61fa739fa4b (diff) | |
download | samba-6e3697ad1218264c85c6c1f4b1521960e21e2a67.tar.gz samba-6e3697ad1218264c85c6c1f4b1521960e21e2a67.tar.xz samba-6e3697ad1218264c85c6c1f4b1521960e21e2a67.zip |
- if the user already exists then ignore the -add command
- change the way the smbpasswd file is auto-created if it doesn't
exist. It didn't work under IRIX for some unknown reason
The smbpasswd.c code is really a bit of a mess. We should probably
rewrite it sometime.
Diffstat (limited to 'source/utils')
-rw-r--r-- | source/utils/smbpasswd.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/source/utils/smbpasswd.c b/source/utils/smbpasswd.c index c781427474e..d20ff42c0e8 100644 --- a/source/utils/smbpasswd.c +++ b/source/utils/smbpasswd.c @@ -375,18 +375,24 @@ static void usage(char *name) * Open the smbpaswd file XXXX - we need to parse smb.conf to get the * filename */ - if ((fp = fopen(pfile, "a+")) == NULL) { - err = errno; - fprintf(stderr, "%s: Failed to open password file %s.\n", - argv[0], pfile); - errno = err; - perror(argv[0]); - exit(err); + fp = fopen(pfile, "r+"); + if (!fp && errno == ENOENT) { + fp = fopen(pfile, "w"); + if (fp) { + fprintf(fp, "# Samba SMB password file\n"); + fclose(fp); + fp = fopen(pfile, "r+"); + } + } + if (!fp) { + err = errno; + fprintf(stderr, "%s: Failed to open password file %s.\n", + argv[0], pfile); + errno = err; + 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)); @@ -477,6 +483,9 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n", pw_file_unlock(lockfd); exit(0); } + } else { + /* the entry already existed */ + add_user = False; } /* If we are root or the password is 'NO PASSWORD' then |