From d55427c85fca8ac7b44e32bdfff344ab573af993 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Sep 1997 06:36:55 +0000 Subject: - 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. (This used to be commit 6e3697ad1218264c85c6c1f4b1521960e21e2a67) --- source3/utils/smbpasswd.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index c781427474..d20ff42c0e 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/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 -- cgit