This creates passdb backend files automatically when adding first account.
authorRafal Szczesniak <mimir@samba.org>
Sun, 20 Jul 2003 21:43:41 +0000 (21:43 +0000)
committerRafal Szczesniak <mimir@samba.org>
Sun, 20 Jul 2003 21:43:41 +0000 (21:43 +0000)
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

source/passdb/pdb_smbpasswd.c
source/passdb/pdb_tdb.c

index 055e8e71bac241a5d14656a4de71c6fd57f31482..8171b65adcce106cbae27e59e8e5ae0cfbe44e61 100644 (file)
@@ -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)) {
index 1078a5bd26511be6c7d812d5db0d5f2765e2f954..051a6993573ebd906140ef3553c296e8ab76ad4e 100644 (file)
@@ -180,6 +180,24 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT
 
        /* open the accounts TDB */
        if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDONLY, 0600))) {
+       
+               if (errno == ENOENT) {
+                       /*
+                        * TDB file doesn't exist, so try to create new one. This is useful to avoid
+                        * confusing error msg when adding user account first time
+                        */
+                       if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_CREAT, 0600))) {
+                               DEBUG(0, ("pdb_getsampwnam: TDB passwd (%s) did not exist. File successfully created.\n",
+                                         tdb_state->tdbsam_location));
+                       } else {
+                               DEBUG(0, ("pdb_getsampwnam: TDB passwd (%s) does not exist. Couldn't create new one. Error was: %s\n",
+                                         tdb_state->tdbsam_location, strerror(errno)));
+                       }
+                       
+                       /* requested user isn't there anyway */
+                       nt_status = NT_STATUS_NO_SUCH_USER;
+                       return nt_status;
+               }
                DEBUG(0, ("pdb_getsampwnam: Unable to open TDB passwd (%s)!\n", tdb_state->tdbsam_location));
                return nt_status;
        }
@@ -423,7 +441,7 @@ done:
 /***************************************************************************
  Allocates a new RID and returns it to the caller as a domain sid
 
- NOTE: Use carefullt, do not waste RIDs they are a limited resource!
+ NOTE: Use carefully, do not waste RIDs they are a limited resource!
                                                        - SSS
  ***************************************************************************/