From bd53e20764bc87cc4c3681106927a3629c3dc257 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 5 Mar 2024 17:21:02 +0100 Subject: [PATCH] libgpo/pygpo: make use of ads_connect_{creds,machine}() Signed-off-by: Stefan Metzmacher Reviewed-by: Andreas Schneider --- libgpo/pygpo.c | 75 ++++++++-------------------------------------------------- 1 file changed, 10 insertions(+), 65 deletions(-) diff --git a/libgpo/pygpo.c b/libgpo/pygpo.c index 0f7116313f2..1db83603fba 100644 --- a/libgpo/pygpo.c +++ b/libgpo/pygpo.c @@ -390,77 +390,22 @@ static PyObject* py_ads_connect(ADS *self, PyErr_SetString(PyExc_RuntimeError, "Uninitialized"); return NULL; } - ADS_TALLOC_CONST_FREE(self->ads_ptr->auth.user_name); - ADS_TALLOC_CONST_FREE(self->ads_ptr->auth.password); - ADS_TALLOC_CONST_FREE(self->ads_ptr->auth.realm); if (self->cli_creds) { - self->ads_ptr->auth.user_name = talloc_strdup(self->ads_ptr, - cli_credentials_get_username(self->cli_creds)); - if (self->ads_ptr->auth.user_name == NULL) { - PyErr_NoMemory(); - goto err; - } - self->ads_ptr->auth.password = talloc_strdup(self->ads_ptr, - cli_credentials_get_password(self->cli_creds)); - if (self->ads_ptr->auth.password == NULL) { - PyErr_NoMemory(); - goto err; - } - self->ads_ptr->auth.realm = talloc_strdup(self->ads_ptr, - cli_credentials_get_realm(self->cli_creds)); - if (self->ads_ptr->auth.realm == NULL) { - PyErr_NoMemory(); + status = ads_connect_creds(self->ads_ptr, self->cli_creds); + if (!ADS_ERR_OK(status)) { + PyErr_Format(PyExc_RuntimeError, + "ads_connect_creds() failed: %s", + ads_errstr(status)); goto err; } - self->ads_ptr->auth.flags |= ADS_AUTH_USER_CREDS; - status = ads_connect_user_creds(self->ads_ptr); } else { - char *passwd = NULL; - - if (!secrets_init()) { - PyErr_SetString(PyExc_RuntimeError, - "secrets_init() failed"); - goto err; - } - - self->ads_ptr->auth.user_name = talloc_asprintf(self->ads_ptr, - "%s$", - lp_netbios_name()); - if (self->ads_ptr->auth.user_name == NULL) { - PyErr_NoMemory(); - goto err; - } - - passwd = secrets_fetch_machine_password( - self->ads_ptr->server.workgroup, NULL, NULL); - if (passwd == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "Failed to fetch the machine account " - "password"); - goto err; - } - - self->ads_ptr->auth.password = talloc_strdup(self->ads_ptr, - passwd); - SAFE_FREE(passwd); - if (self->ads_ptr->auth.password == NULL) { - PyErr_NoMemory(); - goto err; - } - self->ads_ptr->auth.realm = talloc_asprintf_strupper_m( - self->ads_ptr, "%s", self->ads_ptr->server.realm); - if (self->ads_ptr->auth.realm == NULL) { - PyErr_NoMemory(); + status = ads_connect_machine(self->ads_ptr); + if (!ADS_ERR_OK(status)) { + PyErr_Format(PyExc_RuntimeError, + "ads_connect_machine() failed: %s", + ads_errstr(status)); goto err; } - self->ads_ptr->auth.flags |= ADS_AUTH_USER_CREDS; - status = ads_connect(self->ads_ptr); - } - if (!ADS_ERR_OK(status)) { - PyErr_Format(PyExc_RuntimeError, - "ads_connect() failed: %s", - ads_errstr(status)); - goto err; } TALLOC_FREE(frame); -- 2.11.4.GIT