mirror of
https://github.com/samba-team/samba.git
synced 2025-01-25 06:04:04 +03:00
nt_printing: don't leak state_path onto talloc tos
Also check for allocation failures, and close tdbs in nt_printing_tdb_upgrade error paths. Signed-off-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
6d5b8dd70e
commit
2307c3700c
@ -186,17 +186,30 @@ static NTSTATUS migrate_internal(TALLOC_CTX *mem_ctx,
|
|||||||
|
|
||||||
bool nt_printing_tdb_migrate(struct messaging_context *msg_ctx)
|
bool nt_printing_tdb_migrate(struct messaging_context *msg_ctx)
|
||||||
{
|
{
|
||||||
const char *drivers_path = state_path("ntdrivers.tdb");
|
const char *drivers_path;
|
||||||
const char *printers_path = state_path("ntprinters.tdb");
|
const char *printers_path;
|
||||||
const char *forms_path = state_path("ntforms.tdb");
|
const char *forms_path;
|
||||||
bool drivers_exists = file_exist(drivers_path);
|
bool drivers_exists;
|
||||||
bool printers_exists = file_exist(printers_path);
|
bool printers_exists;
|
||||||
bool forms_exists = file_exist(forms_path);
|
bool forms_exists;
|
||||||
struct auth_session_info *session_info;
|
struct auth_session_info *session_info;
|
||||||
struct rpc_pipe_client *winreg_pipe = NULL;
|
struct rpc_pipe_client *winreg_pipe = NULL;
|
||||||
TALLOC_CTX *tmp_ctx = talloc_stackframe();
|
TALLOC_CTX *tmp_ctx = talloc_stackframe();
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
|
|
||||||
|
/* paths talloced on new stackframe */
|
||||||
|
drivers_path = state_path("ntdrivers.tdb");
|
||||||
|
printers_path = state_path("ntprinters.tdb");
|
||||||
|
forms_path = state_path("ntforms.tdb");
|
||||||
|
if ((drivers_path == NULL) || (printers_path == NULL)
|
||||||
|
|| (forms_path == NULL)) {
|
||||||
|
talloc_free(tmp_ctx);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
drivers_exists = file_exist(drivers_path);
|
||||||
|
printers_exists = file_exist(printers_path);
|
||||||
|
forms_exists = file_exist(forms_path);
|
||||||
|
|
||||||
if (!drivers_exists && !printers_exists && !forms_exists) {
|
if (!drivers_exists && !printers_exists && !forms_exists) {
|
||||||
talloc_free(tmp_ctx);
|
talloc_free(tmp_ctx);
|
||||||
return true;
|
return true;
|
||||||
|
@ -339,17 +339,39 @@ static bool upgrade_to_version_5(void)
|
|||||||
|
|
||||||
bool nt_printing_tdb_upgrade(void)
|
bool nt_printing_tdb_upgrade(void)
|
||||||
{
|
{
|
||||||
const char *drivers_path = state_path("ntdrivers.tdb");
|
char *drivers_path;
|
||||||
const char *printers_path = state_path("ntprinters.tdb");
|
char *printers_path;
|
||||||
const char *forms_path = state_path("ntforms.tdb");
|
char *forms_path;
|
||||||
bool drivers_exists = file_exist(drivers_path);
|
bool drivers_exists;
|
||||||
bool printers_exists = file_exist(printers_path);
|
bool printers_exists;
|
||||||
bool forms_exists = file_exist(forms_path);
|
bool forms_exists;
|
||||||
const char *vstring = "INFO/version";
|
const char *vstring = "INFO/version";
|
||||||
int32_t vers_id;
|
int32_t vers_id;
|
||||||
|
bool ret;
|
||||||
|
|
||||||
|
drivers_path = state_path("ntdrivers.tdb");
|
||||||
|
if (drivers_path == NULL) {
|
||||||
|
ret = false;
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
printers_path = state_path("ntprinters.tdb");
|
||||||
|
if (printers_path == NULL) {
|
||||||
|
ret = false;
|
||||||
|
goto err_drvdb_free;
|
||||||
|
}
|
||||||
|
forms_path = state_path("ntforms.tdb");
|
||||||
|
if (forms_path == NULL) {
|
||||||
|
ret = false;
|
||||||
|
goto err_prdb_free;
|
||||||
|
}
|
||||||
|
|
||||||
|
drivers_exists = file_exist(drivers_path);
|
||||||
|
printers_exists = file_exist(printers_path);
|
||||||
|
forms_exists = file_exist(forms_path);
|
||||||
|
|
||||||
if (!drivers_exists && !printers_exists && !forms_exists) {
|
if (!drivers_exists && !printers_exists && !forms_exists) {
|
||||||
return true;
|
ret = true;
|
||||||
|
goto err_formsdb_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
tdb_drivers = tdb_open_log(drivers_path,
|
tdb_drivers = tdb_open_log(drivers_path,
|
||||||
@ -361,7 +383,8 @@ bool nt_printing_tdb_upgrade(void)
|
|||||||
DEBUG(0,("nt_printing_init: Failed to open nt drivers "
|
DEBUG(0,("nt_printing_init: Failed to open nt drivers "
|
||||||
"database %s (%s)\n",
|
"database %s (%s)\n",
|
||||||
drivers_path, strerror(errno)));
|
drivers_path, strerror(errno)));
|
||||||
return false;
|
ret = false;
|
||||||
|
goto err_formsdb_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
tdb_printers = tdb_open_log(printers_path,
|
tdb_printers = tdb_open_log(printers_path,
|
||||||
@ -373,7 +396,8 @@ bool nt_printing_tdb_upgrade(void)
|
|||||||
DEBUG(0,("nt_printing_init: Failed to open nt printers "
|
DEBUG(0,("nt_printing_init: Failed to open nt printers "
|
||||||
"database %s (%s)\n",
|
"database %s (%s)\n",
|
||||||
printers_path, strerror(errno)));
|
printers_path, strerror(errno)));
|
||||||
return false;
|
ret = false;
|
||||||
|
goto err_drvdb_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
tdb_forms = tdb_open_log(forms_path,
|
tdb_forms = tdb_open_log(forms_path,
|
||||||
@ -385,7 +409,8 @@ bool nt_printing_tdb_upgrade(void)
|
|||||||
DEBUG(0,("nt_printing_init: Failed to open nt forms "
|
DEBUG(0,("nt_printing_init: Failed to open nt forms "
|
||||||
"database %s (%s)\n",
|
"database %s (%s)\n",
|
||||||
forms_path, strerror(errno)));
|
forms_path, strerror(errno)));
|
||||||
return false;
|
ret = false;
|
||||||
|
goto err_prdb_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Samba upgrade */
|
/* Samba upgrade */
|
||||||
@ -400,7 +425,8 @@ bool nt_printing_tdb_upgrade(void)
|
|||||||
if ((vers_id == NTDRIVERS_DATABASE_VERSION_1) ||
|
if ((vers_id == NTDRIVERS_DATABASE_VERSION_1) ||
|
||||||
(IREV(vers_id) == NTDRIVERS_DATABASE_VERSION_1)) {
|
(IREV(vers_id) == NTDRIVERS_DATABASE_VERSION_1)) {
|
||||||
if (!upgrade_to_version_3()) {
|
if (!upgrade_to_version_3()) {
|
||||||
return false;
|
ret = false;
|
||||||
|
goto err_formsdb_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_3);
|
tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_3);
|
||||||
@ -420,7 +446,8 @@ bool nt_printing_tdb_upgrade(void)
|
|||||||
|
|
||||||
if (vers_id == NTDRIVERS_DATABASE_VERSION_3) {
|
if (vers_id == NTDRIVERS_DATABASE_VERSION_3) {
|
||||||
if (!upgrade_to_version_4()) {
|
if (!upgrade_to_version_4()) {
|
||||||
return false;
|
ret = false;
|
||||||
|
goto err_formsdb_close;
|
||||||
}
|
}
|
||||||
tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_4);
|
tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_4);
|
||||||
vers_id = NTDRIVERS_DATABASE_VERSION_4;
|
vers_id = NTDRIVERS_DATABASE_VERSION_4;
|
||||||
@ -428,7 +455,8 @@ bool nt_printing_tdb_upgrade(void)
|
|||||||
|
|
||||||
if (vers_id == NTDRIVERS_DATABASE_VERSION_4 ) {
|
if (vers_id == NTDRIVERS_DATABASE_VERSION_4 ) {
|
||||||
if (!upgrade_to_version_5()) {
|
if (!upgrade_to_version_5()) {
|
||||||
return false;
|
ret = false;
|
||||||
|
goto err_formsdb_close;
|
||||||
}
|
}
|
||||||
tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_5);
|
tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_5);
|
||||||
vers_id = NTDRIVERS_DATABASE_VERSION_5;
|
vers_id = NTDRIVERS_DATABASE_VERSION_5;
|
||||||
@ -436,24 +464,33 @@ bool nt_printing_tdb_upgrade(void)
|
|||||||
|
|
||||||
if (vers_id != NTDRIVERS_DATABASE_VERSION_5) {
|
if (vers_id != NTDRIVERS_DATABASE_VERSION_5) {
|
||||||
DEBUG(0,("nt_printing_init: Unknown printer database version [%d]\n", vers_id));
|
DEBUG(0,("nt_printing_init: Unknown printer database version [%d]\n", vers_id));
|
||||||
return false;
|
ret = false;
|
||||||
|
goto err_formsdb_close;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ret = true;
|
||||||
|
|
||||||
if (tdb_drivers) {
|
err_formsdb_close:
|
||||||
tdb_close(tdb_drivers);
|
|
||||||
tdb_drivers = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tdb_printers) {
|
|
||||||
tdb_close(tdb_printers);
|
|
||||||
tdb_printers = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tdb_forms) {
|
if (tdb_forms) {
|
||||||
tdb_close(tdb_forms);
|
tdb_close(tdb_forms);
|
||||||
tdb_forms = NULL;
|
tdb_forms = NULL;
|
||||||
}
|
}
|
||||||
|
err_prdb_close:
|
||||||
return true;
|
if (tdb_printers) {
|
||||||
|
tdb_close(tdb_printers);
|
||||||
|
tdb_printers = NULL;
|
||||||
|
}
|
||||||
|
err_drvdb_close:
|
||||||
|
if (tdb_drivers) {
|
||||||
|
tdb_close(tdb_drivers);
|
||||||
|
tdb_drivers = NULL;
|
||||||
|
}
|
||||||
|
err_formsdb_free:
|
||||||
|
talloc_free(forms_path);
|
||||||
|
err_prdb_free:
|
||||||
|
talloc_free(printers_path);
|
||||||
|
err_drvdb_free:
|
||||||
|
talloc_free(drivers_path);
|
||||||
|
err_out:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user