mirror of
https://github.com/samba-team/samba.git
synced 2025-01-18 06:04:06 +03:00
libgpo/pygpo: make use of ads_connect_{creds,machine}()
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
This commit is contained in:
parent
87e7a9488a
commit
bd53e20764
@ -390,78 +390,23 @@ static PyObject* py_ads_connect(ADS *self,
|
|||||||
PyErr_SetString(PyExc_RuntimeError, "Uninitialized");
|
PyErr_SetString(PyExc_RuntimeError, "Uninitialized");
|
||||||
return NULL;
|
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) {
|
if (self->cli_creds) {
|
||||||
self->ads_ptr->auth.user_name = talloc_strdup(self->ads_ptr,
|
status = ads_connect_creds(self->ads_ptr, self->cli_creds);
|
||||||
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();
|
|
||||||
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();
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
self->ads_ptr->auth.flags |= ADS_AUTH_USER_CREDS;
|
|
||||||
status = ads_connect(self->ads_ptr);
|
|
||||||
}
|
|
||||||
if (!ADS_ERR_OK(status)) {
|
if (!ADS_ERR_OK(status)) {
|
||||||
PyErr_Format(PyExc_RuntimeError,
|
PyErr_Format(PyExc_RuntimeError,
|
||||||
"ads_connect() failed: %s",
|
"ads_connect_creds() failed: %s",
|
||||||
ads_errstr(status));
|
ads_errstr(status));
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TALLOC_FREE(frame);
|
TALLOC_FREE(frame);
|
||||||
Py_RETURN_TRUE;
|
Py_RETURN_TRUE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user