ldap_be.c revision c051ec69a66f3d5c6ae611262ed639c31f93e88e
/*
SSSD
LDAP Backend Module
Authors:
Sumit Bose <sbose@redhat.com>
Copyright (C) 2008 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef WITH_MOZLDAP
#define LDAP_OPT_SUCCESS LDAP_SUCCESS
#endif
#include <errno.h>
#include <ldap.h>
#include <security/pam_modules.h>
#include "providers/dp_backend.h"
#include "../sss_client/sss_cli.h"
struct sdap_ctx {
char *ldap_uri;
char *default_bind_dn;
char *user_search_base;
char *user_name_attribute;
char *user_object_class;
char *default_authtok_type;
char *default_authtok;
int network_timeout;
int opt_timeout;
};
struct sdap_ops;
struct sdap_req;
struct sdap_ops {
};
enum sdap_int_ops {
SDAP_NOOP = 0x0000,
SDAP_OP_INIT = 0x0001,
};
struct sdap_req {
char *user_dn;
enum sdap_int_ops next_op;
int msgid;
};
{
int ret;
struct tevent_timer *te;
if (ret == -1) {
return ret;
}
return EIO;
}
return EOK;
}
{
int ret;
int fd;
if (ret != LDAP_OPT_SUCCESS) {
return ret;
}
return EIO;
}
return EOK;
}
{
int ret;
int pam_status=PAM_SUCCESS;
int msgid;
int ldap_ret;
return PAM_SYSTEM_ERR;
}
if (ret == -1) {
goto cleanup;
}
if (ret == -1) {
goto cleanup;
}
if (ret != LDAP_SUCCESS) {
goto cleanup;
}
if (ret == -1) {
goto cleanup;
}
NULL, 0);
if (ret != LDAP_SUCCESS) {
goto cleanup;
}
ber_bvfree(bv);
return pam_status;
}
{
int ret;
int ldap_vers = LDAP_VERSION3;
int msgid;
struct timeval network_timeout;
struct timeval opt_timeout;
if (ret != LDAP_SUCCESS) {
return EIO;
}
/* LDAPv3 is needed for TLS */
if (ret != LDAP_OPT_SUCCESS) {
goto cleanup;
}
network_timeout.tv_usec = 0;
opt_timeout.tv_usec = 0;
if (ret != LDAP_OPT_SUCCESS) {
goto cleanup;
}
if (ret != LDAP_OPT_SUCCESS) {
goto cleanup;
}
/* For now TLS is forced. Maybe it would be necessary to make this
* configurable to allow people to expose their passwords over the
* network. */
if (ret != LDAP_SUCCESS) {
ldap_err2string(ret)));
if (ret == LDAP_SERVER_DOWN) {
} else {
}
goto cleanup;
}
return EOK;
return status;
}
{
int ret;
int msgid;
}
}
&msgid);
return LDAP_OTHER;
}
return LDAP_SUCCESS;
}
{
int ret;
int pam_status=PAM_SUCCESS;
int ldap_ret;
struct timeval no_timeout={0, 0};
/* FIXME: user timeout form config */
case SDAP_OP_INIT:
} else {
}
goto done;
}
case SDAP_CHECK_INIT_RESULT:
if (ret == -1) {
goto done;
}
if (ret == 0) {
goto done;
}
return;
}
if (ret != LDAP_SUCCESS) {
goto done;
}
if (ldap_ret != LDAP_SUCCESS) {
goto done;
}
/* FIXME: take care that ldap_install_tls might block */
if (ret != LDAP_SUCCESS) {
goto done;
}
if (ret != LDAP_SUCCESS) {
goto done;
}
case SDAP_CHECK_STD_BIND:
if (ret == -1) {
goto done;
}
if (ret == 0) {
goto done;
}
return;
}
if (ret != LDAP_SUCCESS) {
goto done;
}
if (ldap_ret != LDAP_SUCCESS) {
goto done;
}
"(&(%s=%s)(objectclass=%s))",
TRUE,
NULL,
NULL,
NULL,
0,
if (ret != LDAP_SUCCESS) {
goto done;
}
if (ret == -1) {
goto done;
}
if (ret == 0) {
goto done;
}
return;
}
goto done;
}
do {
switch ( ldap_msgtype(msg) ) {
case LDAP_RES_SEARCH_ENTRY:
filter));
goto done;
}
goto done;
}
goto done;
}
break;
default:
}
case SSS_PAM_AUTHENTICATE:
case SSS_PAM_CHAUTHTOK:
break;
case SSS_PAM_ACCT_MGMT:
case SSS_PAM_SETCRED:
case SSS_PAM_OPEN_SESSION:
case SSS_PAM_CLOSE_SESSION:
goto done;
break;
default:
goto done;
}
if (ret != LDAP_SUCCESS) {
goto done;
}
case SDAP_CHECK_USER_BIND:
if (ret == -1) {
goto done;
}
if (ret == 0) {
goto done;
}
return;
}
if (ret != LDAP_SUCCESS) {
goto done;
}
switch (ldap_ret) {
case LDAP_SUCCESS:
break;
case LDAP_INVALID_CREDENTIALS:
goto done;
break;
default:
goto done;
}
case SSS_PAM_AUTHENTICATE:
break;
case SSS_PAM_CHAUTHTOK:
break;
case SSS_PAM_ACCT_MGMT:
case SSS_PAM_SETCRED:
case SSS_PAM_OPEN_SESSION:
case SSS_PAM_CLOSE_SESSION:
break;
default:
}
break;
default:
}
done:
}
{
int ret;
int pam_status;
} else {
}
goto done;
}
goto done;
}
return;
done:
}
{
int ret;
int pam_status=PAM_SUCCESS;
goto done;
}
return;
done:
}
{
/* TODO: Clean up any internal data */
}
struct be_auth_ops sdap_mod_ops = {
};
struct be_auth_ops **ops,
void **pvt_data)
{
char *ldap_uri;
char *default_bind_dn;
char *default_authtok_type;
char *default_authtok;
char *user_search_base;
char *user_name_attribute;
char *user_object_class;
int network_timeout;
int opt_timeout;
int ret;
if (!ctx) {
return ENOMEM;
}
/* TODO: add validation checks for ldapUri, user_search_base,
* user_name_attribute, etc */
if (user_search_base == NULL) {
goto done;
}
"userObjectClass", "posixAccount",
/* TODO: better to have a blob object than a string here */
*ops = &sdap_mod_ops;
done:
}
return ret;
}