45typedef struct sasl_interact {
49 const char *defresult;
54#define SASL_CB_USER 0x4001
55#define SASL_CB_AUTHNAME 0x4002
56#define SASL_CB_PASS 0x4004
57#define SASL_CB_ECHOPROMPT 0x4005
58#define SASL_CB_NOECHOPROMPT 0x4006
59#define SASL_CB_GETREALM 0x4008
60#define SASL_CB_LIST_END 0
63#if HAVE_SASL_H || HAVE_SASL_SASL_H || HAVE_SASL_DARWIN
64void *lutil_sasl_defaults(
72LDAP_SASL_INTERACT_PROC lutil_sasl_interact;
74int lutil_sasl_interact(
80void lutil_sasl_freedefs(
87typedef struct lutil_sasl_defaults_s {
106 lutilSASLdefaults *defaults;
108 defaults = (lutilSASLdefaults *)
xmalloc(
sizeof(lutilSASLdefaults));
110 if (defaults ==
nullptr)
113 defaults->mech = mech ?
xstrdup(mech) : nullptr;
114 defaults->realm = realm ?
xstrdup(realm) : nullptr;
115 defaults->authcid = authcid ?
xstrdup(authcid) : nullptr;
116 defaults->passwd = passwd ?
xstrdup(passwd) : nullptr;
117 defaults->authzid = authzid ?
xstrdup(authzid) : nullptr;
119 if (defaults->mech ==
nullptr) {
120 ldap_get_option(
ld, LDAP_OPT_X_SASL_MECH, &defaults->mech);
122 if (defaults->realm ==
nullptr) {
123 ldap_get_option(
ld, LDAP_OPT_X_SASL_REALM, &defaults->realm);
125 if (defaults->authcid ==
nullptr) {
126 ldap_get_option(
ld, LDAP_OPT_X_SASL_AUTHCID, &defaults->authcid);
128 if (defaults->authzid ==
nullptr) {
129 ldap_get_option(
ld, LDAP_OPT_X_SASL_AUTHZID, &defaults->authzid);
131 defaults->resps =
nullptr;
132 defaults->nresps = 0;
140 sasl_interact_t * interact,
141 lutilSASLdefaults * defaults)
143 const char *dflt = interact->defresult;
145 switch (interact->id) {
146 case SASL_CB_GETREALM:
148 dflt = defaults->realm;
150 case SASL_CB_AUTHNAME:
152 dflt = defaults->authcid;
156 dflt = defaults->passwd;
160 dflt = defaults->authzid;
162 case SASL_CB_NOECHOPROMPT:
164 case SASL_CB_ECHOPROMPT:
172 interact->result = (dflt && *dflt) ? dflt :
"";
173 interact->len = (unsigned) strlen((
const char *) interact->result);
185 sasl_interact_t *interact = (sasl_interact_t *) in;
188 return LDAP_PARAM_ERROR;
190 while (interact->id != SASL_CB_LIST_END) {
191 int rc = interaction(flags, interact, (lutilSASLdefaults *) defaults);
205 lutilSASLdefaults *defs = (lutilSASLdefaults *) defaults;
209 xfree(defs->authcid);
211 xfree(defs->authzid);
218tool_sasl_bind(LDAP *
ld,
char *
binddn,
char *ssl)
228 unsigned sasl_flags = LDAP_SASL_INTERACTIVE;
230 unsigned sasl_flags = LDAP_SASL_QUIET;
232 char *sasl_realm =
nullptr;
233 char *sasl_authc_id =
nullptr;
234 char *sasl_authz_id =
nullptr;
235 char *sasl_mech = (
char *)
"GSSAPI";
244 struct berval passwd = {};
246 int rc = LDAP_SUCCESS;
249 sasl_secprops = (
char *)
"maxssf=0";
251 sasl_secprops = (
char *)
"maxssf=56";
255 if (sasl_secprops !=
nullptr) {
256 rc = ldap_set_option(
ld, LDAP_OPT_X_SASL_SECPROPS,
257 (
void *) sasl_secprops);
258 if (rc != LDAP_SUCCESS) {
259 error((
char *)
"%s| %s: ERROR: Could not set LDAP_OPT_X_SASL_SECPROPS: %s: %s\n",
LogTime(),
PROGRAM, sasl_secprops, ldap_err2string(rc));
263 defaults = lutil_sasl_defaults(
ld,
270 rc = ldap_sasl_interactive_bind_s(
ld,
binddn,
271 sasl_mech,
nullptr,
nullptr,
272 sasl_flags, lutil_sasl_interact, defaults);
274 lutil_sasl_freedefs(defaults);
275 if (rc != LDAP_SUCCESS) {
276 error((
char *)
"%s| %s: ERROR: ldap_sasl_interactive_bind_s error: %s\n",
LogTime(),
PROGRAM, ldap_err2string(rc));
285 fprintf(stderr,
"%s| %s: ERROR: Dummy function\n",
LogTime(),
PROGRAM);
void error(char *format,...)
const char * LogTime(void)
static const char * binddn
static unsigned char challenge[NTLM_NONCE_LEN]
Comm::AcceptLimiter dummy