* Requests for permission may be sent to NeoSoft Inc, 1770 St. James Place,
* Suite 500, Houston, TX, 77056.
*
- * $Id$
+ * $Id: neoXldap.c,v 1.4 1999/07/27 05:29:27 kunkee Exp $
*
*/
* Umich-3.3 client code. The UMICH_LDAP define is used to include
* code that will work with the Umich-3.3 LDAP, but not with Netscape's
* SDK. OpenLDAP may support some of these, but they have not been tested.
- * Current support is by Randy Kunkee.
+ * Currently supported by Randy Kunkee (kunkee@OpenLDAP.org).
*/
/*
#define STREQU(str1, str2) \
(((str1) [0] == (str2) [0]) && (strcmp (str1, str2) == 0))
+#define STRNEQU(str1, str2, n) \
+ (((str1) [0] == (str2) [0]) && (strncmp (str1, str2, n) == 0))
/*
* The following section defines some common macros used by the rest
*/
#define ldap_attributefree(p) ldap_memfree(p)
#define ldap_memfree(p) free(p)
+#ifdef LDAP_OPT_ERROR_NUMBER
+#define ldap_get_lderrno(ld) (ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &lderrno), lderrno)
+#else
+#define ldap_get_lderrno(ld) (ld->ld_errno)
+#endif
#define LDAP_ERR_STRING(ld) \
- ldap_err2string(ldap->ld_errno)
+ ldap_err2string(ldap_get_lderrno(ld))
#elif defined( LDAP_OPT_SIZELIMIT )
/*
** Netscape SDK w/ ldap_set_option, ldap_get_option
#define ldap_ber_free(p, n) ber_free(p, n)
#define ldap_value_free_len(bvals) ber_bvecfree(bvals)
#define ldap_attributefree(p)
+#define ldap_get_lderrno(ld) (ld->ld_errno)
#define LDAP_ERR_STRING(ld) \
ldap_err2string(ld->ld_errno)
#endif
+typedef struct ldaptclobj {
+ LDAP *ldap;
+ int flags
+} LDAPTCL;
+
+#define LDAPTCL_INTERRCODES 0x001
+
+#include "ldaptclerr.h"
+static
+LDAP_SetErrorCode(LDAPTCL *ldaptcl, int code, Tcl_Interp *interp)
+{
+ char shortbuf[6];
+ char *errp;
+ int lderrno;
+
+ if (code == -1)
+ code = ldap_get_lderrno(ldaptcl->ldap);
+ if ((ldaptcl->flags & LDAPTCL_INTERRCODES) || code > LDAPTCL_MAXERR ||
+ ldaptclerrorcode[code] == NULL) {
+ sprintf(shortbuf, "0x%03x", code);
+ errp = shortbuf;
+ } else
+ errp = ldaptclerrorcode[code];
+
+ Tcl_SetErrorCode(interp, errp, NULL);
+}
/*-----------------------------------------------------------------------------
* LDAP_ProcessOneSearchResult --
BerElement *ber;
struct berval **bvals;
char *dn;
+ int lderrno;
Tcl_UnsetVar (interp, Tcl_GetStringFromObj (destArrayNameObj, NULL), 0);
*-----------------------------------------------------------------------------
*/
static int
-LDAP_PerformSearch (interp, ldap, base, scope, attrs, filtpatt, value, destArrayNameObj, evalCodeObj, timeout_p)
+LDAP_PerformSearch (interp, ldaptcl, base, scope, attrs, filtpatt, value, destArrayNameObj, evalCodeObj, timeout_p)
Tcl_Interp *interp;
- LDAP *ldap;
+ LDAPTCL *ldaptcl;
char *base;
int scope;
char **attrs;
Tcl_Obj *evalCodeObj;
struct timeval *timeout_p;
{
+ LDAP *ldap = ldaptcl->ldap;
char filter[BUFSIZ];
int resultCode;
int errorCode;
LDAPMessage *entryMessage;
Tcl_Obj *resultObj;
- int lderr;
+ int lderrno;
resultObj = Tcl_GetObjResult (interp);
"LDAP start search error: ",
LDAP_ERR_STRING(ldap),
(char *)NULL);
+ LDAP_SetErrorCode(ldaptcl, -1, interp);
return TCL_ERROR;
}
ldap_err2string(errorCode),
(char *)NULL);
ldap_msgfree(resultMessage);
+ LDAP_SetErrorCode(ldaptcl, errorCode, interp);
return TCL_ERROR;
}
}
"LDAP result search error: ",
LDAP_ERR_STRING(ldap),
(char *)NULL);
+ LDAP_SetErrorCode(ldaptcl, -1, interp);
return TCL_ERROR;
} else
ldap_msgfree(resultMessage);
{
char *command;
char *subCommand;
- LDAP *ldap = (LDAP *)clientData;
+ LDAPTCL *ldaptcl = (LDAPTCL *)clientData;
+ LDAP *ldap = ldaptcl->ldap;
char *dn;
int is_add = 0;
int is_add_or_modify = 0;
"LDAP bind error: ",
ldap_err2string(errcode),
(char *)NULL);
+ LDAP_SetErrorCode(ldaptcl, errcode, interp);
return TCL_ERROR;
}
return TCL_OK;
"LDAP delete error: ",
ldap_err2string(errcode),
(char *)NULL);
+ LDAP_SetErrorCode(ldaptcl, errcode, interp);
return TCL_ERROR;
}
return TCL_OK;
" error: ",
ldap_err2string(errcode),
(char *)NULL);
+ LDAP_SetErrorCode(ldaptcl, errcode, interp);
return TCL_ERROR;
}
return TCL_OK;
" error: ",
ldap_err2string(result),
(char *)NULL);
+ LDAP_SetErrorCode(ldaptcl, result, interp);
return TCL_ERROR;
}
return TCL_OK;
"filter",
0);
if (filterPatternString == (char *)NULL) {
- Tcl_AppendStringsToObj (resultObj,
- "required element \"filter\" ",
- "is missing from ldap control array \"",
- controlArrayName,
- "\"",
- (char *)NULL);
-
- return TCL_ERROR;
+ filterPatternString = "objectclass=*";
}
/* Fetch scope setting from control array.
} else {
if (STREQU(scopeString, "base"))
scope = LDAP_SCOPE_BASE;
- else if (STREQU(scopeString, "onelevel"))
+ else if (STRNEQU(scopeString, "one", 3))
scope = LDAP_SCOPE_ONELEVEL;
- else if (STREQU(scopeString, "subtree"))
+ else if (STRNEQU(scopeString, "sub", 3))
scope = LDAP_SCOPE_SUBTREE;
else {
Tcl_AppendStringsToObj (resultObj,
"\"scope\" element of \"",
controlArrayName,
"\" array is not one of ",
- "\"base\", \"one_level\", ",
+ "\"base\", \"onelevel\", ",
"or \"subtree\"",
(char *) NULL);
return TCL_ERROR;
#endif
return LDAP_PerformSearch (interp,
- ldap,
+ ldaptcl,
baseString,
scope,
attributesArray,
timeout_p);
}
-#if UMICH_LDAP
+#if defined(UMICH_LDAP) || (defined(OPEN_LDAP) && !defined(LDAP_API_VERSION))
if (STREQU (subCommand, "cache")) {
char *cacheCommand;
"LDAP cache enable error: ",
LDAP_ERR_STRING(ldap),
(char *)NULL);
+ LDAP_SetErrorCode(ldaptcl, -1, interp);
return TCL_ERROR;
}
return TCL_OK;
NeoX_LdapObjDeleteCmd(clientData)
ClientData clientData;
{
- LDAP *ldap = (LDAP *)clientData;
+ LDAPTCL *ldaptcl = (LDAPTCL *)clientData;
+ LDAP *ldap = ldaptcl->ldap;
ldap_unbind(ldap);
+ ckfree((char*) ldaptcl);
}
/*-----------------------------------------------------------------------------
char *ldapHost;
int ldapPort = 389;
LDAP *ldap;
+ LDAPTCL *ldaptcl;
Tcl_Obj *resultObj = Tcl_GetObjResult (interp);
ldap->ld_deref = LDAP_DEREF_NEVER; /* Turn off alias dereferencing */
#endif
+ ldaptcl = (LDAPTCL *) ckalloc(sizeof(LDAPTCL));
+ ldaptcl->ldap = ldap;
+ ldaptcl->flags = 0;
+
Tcl_CreateObjCommand (interp,
newCommand,
NeoX_LdapTargetObjCmd,
- (ClientData) ldap,
+ (ClientData) ldaptcl,
NeoX_LdapObjDeleteCmd);
return TCL_OK;
}
NeoX_LdapObjCmd,
(ClientData) NULL,
(Tcl_CmdDeleteProc*) NULL);
- Tcl_PkgProvide(interp, "Ldaptcl", "1.1");
+ Tcl_PkgProvide(interp, "Ldaptcl", VERSION);
return TCL_OK;
}