passdb: Do not panic in initialize_password_db
authorChristof Schmitt <christof.schmitt@us.ibm.com>
Tue, 24 Apr 2012 21:42:28 +0000 (14:42 -0700)
committerVolker Lendecke <vl@samba.org>
Mon, 30 Apr 2012 09:30:29 +0000 (11:30 +0200)
A call to initialize_password_db leads to smb_panic in case the backend
returns an error. All callers to initialize_password_db check the return
value, so this code path should return the status instead of calling
smb_panic.

Move the call to smb_panic from pdb_get_methods_reload pdb_get_methods
to get it out of the initialize code path.  This allows printing the
proper error message for 'net getlocalsid' which is much nicer than
printing the panic stack trace.

source3/passdb/pdb_interface.c

index c5fe56c87d5ab47494c40b3c8ab5faaba73539ab..e2fc67981e44e248acff0438539094ccb47cfa2d 100644 (file)
@@ -196,27 +196,13 @@ static struct pdb_methods *pdb_get_methods_reload( bool reload )
        if ( pdb && reload ) {
                pdb->free_private_data( &(pdb->private_data) );
                if ( !NT_STATUS_IS_OK( make_pdb_method_name( &pdb, lp_passdb_backend() ) ) ) {
-                       char *msg = NULL;
-                       if (asprintf(&msg, "pdb_get_methods_reload: "
-                                       "failed to get pdb methods for backend %s\n",
-                                       lp_passdb_backend()) > 0) {
-                               smb_panic(msg);
-                       } else {
-                               smb_panic("pdb_get_methods_reload");
-                       }
+                       return NULL;
                }
        }
 
        if ( !pdb ) {
                if ( !NT_STATUS_IS_OK( make_pdb_method_name( &pdb, lp_passdb_backend() ) ) ) {
-                       char *msg = NULL;
-                       if (asprintf(&msg, "pdb_get_methods_reload: "
-                                       "failed to get pdb methods for backend %s\n",
-                                       lp_passdb_backend()) > 0) {
-                               smb_panic(msg);
-                       } else {
-                               smb_panic("pdb_get_methods_reload");
-                       }
+                       return NULL;
                }
        }
 
@@ -225,7 +211,21 @@ static struct pdb_methods *pdb_get_methods_reload( bool reload )
 
 static struct pdb_methods *pdb_get_methods(void)
 {
-       return pdb_get_methods_reload(False);
+       struct pdb_methods *pdb;
+
+       pdb = pdb_get_methods_reload(false);
+       if (!pdb) {
+               char *msg = NULL;
+               if (asprintf(&msg, "pdb_get_methods: "
+                            "failed to get pdb methods for backend %s\n",
+                            lp_passdb_backend()) > 0) {
+                       smb_panic(msg);
+               } else {
+                       smb_panic("pdb_get_methods");
+               }
+       }
+
+       return pdb;
 }
 
 struct pdb_domain_info *pdb_get_domain_info(TALLOC_CTX *mem_ctx)