]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libgpo/pygpo: make use of ads_connect_{creds,machine}()
authorStefan Metzmacher <metze@samba.org>
Tue, 5 Mar 2024 16:21:02 +0000 (17:21 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 14 May 2024 10:18:31 +0000 (10:18 +0000)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
libgpo/pygpo.c

index 0f7116313f230d4a186e36cefe98257654946a19..1db83603fba2b38cf0f47d2942015f0a8210c18c 100644 (file)
@@ -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);