summaryrefslogtreecommitdiff
path: root/source3/passdb/pdb_smbpasswd.c
diff options
context:
space:
mode:
authorRafal Szczesniak <mimir@samba.org>2003-07-20 21:43:41 +0000
committerRafal Szczesniak <mimir@samba.org>2003-07-20 21:43:41 +0000
commitb3064ac5d64f54562e4f2d7d1b021374def1352d (patch)
treebf8e2e90cdf9f95736663cd1746cd9a1a643c45c /source3/passdb/pdb_smbpasswd.c
parentbbd4c98b06a3a60b93f43f9dc2a824d76138a300 (diff)
downloadsamba-b3064ac5d64f54562e4f2d7d1b021374def1352d.tar.gz
samba-b3064ac5d64f54562e4f2d7d1b021374def1352d.tar.bz2
samba-b3064ac5d64f54562e4f2d7d1b021374def1352d.zip
This creates passdb backend files automatically when adding first account.
An extra message notifying that needed file didn't exist is displayed. There's still a little catch with tdb backend, but it's better than it was, from end-user's point of view. This fixes #198 rafal (This used to be commit b0be700605c289ce8e9dd3abe49d78ac77256911)
Diffstat (limited to 'source3/passdb/pdb_smbpasswd.c')
-rw-r--r--source3/passdb/pdb_smbpasswd.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/source3/passdb/pdb_smbpasswd.c b/source3/passdb/pdb_smbpasswd.c
index 055e8e71ba..8171b65adc 100644
--- a/source3/passdb/pdb_smbpasswd.c
+++ b/source3/passdb/pdb_smbpasswd.c
@@ -179,8 +179,25 @@ static FILE *startsmbfilepwent(const char *pfile, enum pwf_access_type type, int
DEBUG(10, ("startsmbfilepwent_internal: opening file %s\n", pfile));
if((fp = sys_fopen(pfile, open_mode)) == NULL) {
- DEBUG(0, ("startsmbfilepwent_internal: unable to open file %s. Error was %s\n", pfile, strerror(errno) ));
- return NULL;
+
+ /*
+ * If smbpasswd file doesn't exist, then create new one. This helps to avoid
+ * confusing error msg when adding user account first time.
+ */
+ if (errno == ENOENT) {
+ if ((fp = sys_fopen(pfile, "a+")) != NULL) {
+ DEBUG(0, ("startsmbfilepwent_internal: file %s did not exist. File successfully created.\n", pfile));
+
+ } else {
+ DEBUG(0, ("startsmbfilepwent_internal: file %s did not exist. Couldn't create new one. Error was: %s",
+ pfile, strerror(errno)));
+ return NULL;
+ }
+
+ } else {
+ DEBUG(0, ("startsmbfilepwent_internal: unable to open file %s. Error was: %s\n", pfile, strerror(errno)));
+ return NULL;
+ }
}
if (!pw_file_lock(fileno(fp), lock_type, 5, lock_depth)) {