本文整理汇总了C++中ldap_value_free函数的典型用法代码示例。如果您正苦于以下问题:C++ ldap_value_free函数的具体用法?C++ ldap_value_free怎么用?C++ ldap_value_free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ldap_value_free函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: smbldap_get_single_attribute
BOOL smbldap_get_single_attribute (LDAP * ldap_struct, LDAPMessage * entry,
const char *attribute, char *value,
int max_len)
{
char **values;
if ( !attribute )
return False;
value[0] = '\0';
if ((values = ldap_get_values (ldap_struct, entry, attribute)) == NULL) {
DEBUG (10, ("smbldap_get_single_attribute: [%s] = [<does not exist>]\n", attribute));
return False;
}
if (convert_string(CH_UTF8, CH_UNIX,values[0], -1, value, max_len, False) == (size_t)-1) {
DEBUG(1, ("smbldap_get_single_attribute: string conversion of [%s] = [%s] failed!\n",
attribute, values[0]));
ldap_value_free(values);
return False;
}
ldap_value_free(values);
#ifdef DEBUG_PASSWORDS
DEBUG (100, ("smbldap_get_single_attribute: [%s] = [%s]\n", attribute, value));
#endif
return True;
}
示例2: ads_sasl_bind
ADS_STATUS ads_sasl_bind(ADS_STRUCT *ads)
{
const char *attrs[] = {"supportedSASLMechanisms", NULL};
char **values;
ADS_STATUS status;
int i, j;
LDAPMessage *res;
/* get a list of supported SASL mechanisms */
status = ads_do_search(ads, "", LDAP_SCOPE_BASE, "(objectclass=*)", attrs, &res);
if (!ADS_ERR_OK(status)) return status;
values = ldap_get_values(ads->ld, res, "supportedSASLMechanisms");
/* try our supported mechanisms in order */
for (i=0;sasl_mechanisms[i].name;i++) {
/* see if the server supports it */
for (j=0;values && values[j];j++) {
if (strcmp(values[j], sasl_mechanisms[i].name) == 0) {
DEBUG(4,("Found SASL mechanism %s\n", values[j]));
status = sasl_mechanisms[i].fn(ads);
ldap_value_free(values);
ldap_msgfree(res);
return status;
}
}
}
ldap_value_free(values);
ldap_msgfree(res);
return ADS_ERROR(LDAP_AUTH_METHOD_NOT_SUPPORTED);
}
示例3: gfarm_generic_info_get_foreach
/* XXX - this is for a stopgap implementation of gfs_opendir() */
char *
gfarm_generic_info_get_foreach(
char *dn,
int scope, /* LDAP_SCOPE_ONELEVEL or LDAP_SCOPE_SUBTREE */
char *query,
void *tmp_info, /* just used as a work area */
void (*callback)(void *, void *),
void *closure,
const struct gfarm_generic_info_ops *ops)
{
LDAPMessage *res, *e;
int i, rv;
char *a;
BerElement *ptr;
char **vals;
/* search for entries, return all attrs */
rv = ldap_search_s(gfarm_ldap_server, dn, scope, query, NULL, 0, &res);
if (rv != LDAP_SUCCESS) {
if (rv == LDAP_NO_SUCH_OBJECT)
return (GFARM_ERR_NO_SUCH_OBJECT);
return (ldap_err2string(rv));
}
/* step through each entry returned */
for (i = 0, e = ldap_first_entry(gfarm_ldap_server, res); e != NULL;
e = ldap_next_entry(gfarm_ldap_server, e)) {
ops->clear(tmp_info);
for (a = ldap_first_attribute(gfarm_ldap_server, e, &ptr);
a != NULL;
a = ldap_next_attribute(gfarm_ldap_server, e, ptr)) {
vals = ldap_get_values(gfarm_ldap_server, e, a);
if (vals[0] == NULL) {
ldap_value_free(vals);
continue;
}
ops->set_field(tmp_info, a, vals);
ldap_value_free(vals);
}
if (!ops->validate(tmp_info)) {
/* invalid record */
ops->free(tmp_info);
continue;
}
(*callback)(closure, tmp_info);
ops->free(tmp_info);
i++;
}
/* free the search results */
ldap_msgfree(res);
if (i == 0)
return (GFARM_ERR_NO_SUCH_OBJECT);
return (NULL);
}
示例4: address_from_ldap
ADDRESS *
address_from_ldap(LDAP_CHOOSE_S *winning_e)
{
ADDRESS *ret_a = NULL;
if(winning_e){
char *a;
BerElement *ber;
ret_a = mail_newaddr();
for(a = ldap_first_attribute(winning_e->ld, winning_e->selected_entry, &ber);
a != NULL;
a = ldap_next_attribute(winning_e->ld, winning_e->selected_entry, ber)){
int i;
char *p;
char **vals;
dprint((9, "attribute: %s\n", a ? a : "?"));
if(!ret_a->personal &&
strcmp(a, winning_e->info_used->cnattr) == 0){
dprint((9, "Got cnattr:"));
vals = ldap_get_values(winning_e->ld, winning_e->selected_entry, a);
for(i = 0; vals[i] != NULL; i++)
dprint((9, " %s\n",
vals[i] ? vals[i] : "?"));
if(vals && vals[0])
ret_a->personal = cpystr(vals[0]);
ldap_value_free(vals);
}
else if(!ret_a->mailbox &&
strcmp(a, winning_e->info_used->mailattr) == 0){
dprint((9, "Got mailattr:"));
vals = ldap_get_values(winning_e->ld, winning_e->selected_entry, a);
for(i = 0; vals[i] != NULL; i++)
dprint((9, " %s\n",
vals[i] ? vals[i] : "?"));
/* use first one */
if(vals && vals[0]){
if((p = strindex(vals[0], '@')) != NULL){
ret_a->host = cpystr(p+1);
*p = '\0';
}
ret_a->mailbox = cpystr(vals[0]);
}
ldap_value_free(vals);
}
our_ldap_memfree(a);
}
}
return(ret_a);
}
示例5: gfarm_generic_info_get
char *
gfarm_generic_info_get(
void *key,
void *info,
const struct gfarm_generic_info_ops *ops)
{
LDAPMessage *res, *e;
int n, rv;
char *a;
BerElement *ptr;
char **vals;
char *dn = ops->make_dn(key);
if (dn == NULL)
return (GFARM_ERR_NO_MEMORY);
rv = ldap_search_s(gfarm_ldap_server, dn,
LDAP_SCOPE_BASE, ops->query_type, NULL, 0, &res);
free(dn);
if (rv != LDAP_SUCCESS) {
if (rv == LDAP_NO_SUCH_OBJECT)
return (GFARM_ERR_NO_SUCH_OBJECT);
return (ldap_err2string(rv));
}
n = ldap_count_entries(gfarm_ldap_server, res);
if (n == 0) {
/* free the search results */
ldap_msgfree(res);
return (GFARM_ERR_NO_SUCH_OBJECT);
}
ops->clear(info);
e = ldap_first_entry(gfarm_ldap_server, res);
for (a = ldap_first_attribute(gfarm_ldap_server, e, &ptr); a != NULL;
a = ldap_next_attribute(gfarm_ldap_server, e, ptr)) {
vals = ldap_get_values(gfarm_ldap_server, e, a);
if (vals[0] == NULL) {
ldap_value_free(vals);
continue;
}
ops->set_field(info, a, vals);
ldap_value_free(vals);
}
/* free the search results */
ldap_msgfree(res);
/* should check all fields are filled */
if (!ops->validate(info)) {
ops->free(info);
/* XXX - different error code is better ? */
return (GFARM_ERR_NO_SUCH_OBJECT);
}
return (NULL); /* success */
}
示例6: ads_sasl_bind
ADS_STATUS ads_sasl_bind(ADS_STRUCT *ads)
{
const char *attrs[] = {"supportedSASLMechanisms", NULL};
char **values;
ADS_STATUS status;
int i, j;
LDAPMessage *res;
struct ads_saslwrap *wrap = &ads->ldap_wrap_data;
/* get a list of supported SASL mechanisms */
status = ads_do_search(ads, "", LDAP_SCOPE_BASE, "(objectclass=*)", attrs, &res);
if (!ADS_ERR_OK(status)) return status;
values = ldap_get_values(ads->ldap.ld, res, "supportedSASLMechanisms");
if (ads->auth.flags & ADS_AUTH_SASL_SEAL) {
wrap->wrap_type = ADS_SASLWRAP_TYPE_SEAL;
} else if (ads->auth.flags & ADS_AUTH_SASL_SIGN) {
wrap->wrap_type = ADS_SASLWRAP_TYPE_SIGN;
} else {
wrap->wrap_type = ADS_SASLWRAP_TYPE_PLAIN;
}
/* try our supported mechanisms in order */
for (i=0;sasl_mechanisms[i].name;i++) {
/* see if the server supports it */
for (j=0;values && values[j];j++) {
if (strcmp(values[j], sasl_mechanisms[i].name) == 0) {
DEBUG(4,("Found SASL mechanism %s\n", values[j]));
retry:
status = sasl_mechanisms[i].fn(ads);
if (status.error_type == ENUM_ADS_ERROR_LDAP &&
status.err.rc == LDAP_STRONG_AUTH_REQUIRED &&
wrap->wrap_type == ADS_SASLWRAP_TYPE_PLAIN)
{
DEBUG(3,("SASL bin got LDAP_STRONG_AUTH_REQUIRED "
"retrying with signing enabled\n"));
wrap->wrap_type = ADS_SASLWRAP_TYPE_SIGN;
goto retry;
}
ldap_value_free(values);
ldap_msgfree(res);
return status;
}
}
}
ldap_value_free(values);
ldap_msgfree(res);
return ADS_ERROR(LDAP_AUTH_METHOD_NOT_SUPPORTED);
}
示例7: ads_user_info
static int ads_user_info(int argc, const char **argv)
{
ADS_STRUCT *ads;
ADS_STATUS rc;
void *res;
const char *attrs[] = {"memberOf", NULL};
char *searchstring=NULL;
char **grouplist;
char *escaped_user = escape_ldap_string_alloc(argv[0]);
if (argc < 1) {
return net_ads_user_usage(argc, argv);
}
if (!(ads = ads_startup())) {
return -1;
}
if (!escaped_user) {
d_printf("ads_user_info: failed to escape user %s\n", argv[0]);
ads_destroy(&ads);
return -1;
}
asprintf(&searchstring, "(sAMAccountName=%s)", escaped_user);
rc = ads_search(ads, &res, searchstring, attrs);
safe_free(searchstring);
if (!ADS_ERR_OK(rc)) {
d_printf("ads_search: %s\n", ads_errstr(rc));
ads_destroy(&ads);
return -1;
}
grouplist = ldap_get_values(ads->ld, res, "memberOf");
if (grouplist) {
int i;
char **groupname;
for (i=0;grouplist[i];i++) {
groupname = ldap_explode_dn(grouplist[i], 1);
d_printf("%s\n", groupname[0]);
ldap_value_free(groupname);
}
ldap_value_free(grouplist);
}
ads_msgfree(ads, res);
ads_destroy(&ads);
return 0;
}
示例8: ldap_search_ext_s
/**
* Attempt to discover the base DN for a server using LDAP version 3.
* \param ld LDAP handle for a connected server.
* \param tov Timeout value (seconds), or 0 for none, default 30 secs.
* \return List of Base DN's, or NULL if could not read. List should be
* g_free() when done.
*/
static GList *ldaputil_test_v3( LDAP *ld, gint tov ) {
GList *baseDN = NULL;
gint rc, i;
LDAPMessage *result, *e;
gchar *attribs[2];
BerElement *ber;
gchar *attribute;
gchar **vals;
struct timeval timeout;
/* Set timeout */
timeout.tv_usec = 0L;
if( tov > 0 ) {
timeout.tv_sec = tov;
}
else {
timeout.tv_sec = 30L;
}
/* Test for LDAP version 3 */
attribs[0] = SYLDAP_V3_TEST_ATTR;
attribs[1] = NULL;
rc = ldap_search_ext_s(
ld, SYLDAP_SEARCHBASE_V3, LDAP_SCOPE_BASE, SYLDAP_TEST_FILTER,
attribs, 0, NULL, NULL, &timeout, 0, &result );
if( rc == LDAP_SUCCESS ) {
/* Process entries */
for( e = ldap_first_entry( ld, result );
e != NULL;
e = ldap_next_entry( ld, e ) )
{
/* Process attributes */
for( attribute = ldap_first_attribute( ld, e, &ber );
attribute != NULL;
attribute = ldap_next_attribute( ld, e, ber ) )
{
if( strcasecmp(
attribute, SYLDAP_V3_TEST_ATTR ) == 0 )
{
vals = ldap_get_values( ld, e, attribute );
if( vals != NULL ) {
for( i = 0; vals[i] != NULL; i++ ) {
baseDN = g_list_append(
baseDN, g_strdup( vals[i] ) );
}
}
ldap_value_free( vals );
}
ldap_memfree( attribute );
}
if( ber != NULL ) {
ber_free( ber, 0 );
}
ber = NULL;
}
}
ldap_msgfree( result );
return baseDN;
}
示例9: __ns_ldap_freeCookie
static ns_ldap_return_code
__ns_ldap_freeCookie (ns_ldap_cookie_t ** pCookie)
{
ns_ldap_cookie_t *cookie;
cookie = *pCookie;
if (cookie != NULL)
{
if (cookie->map != NULL)
free (cookie->map);
if (cookie->filter != NULL)
free (cookie->filter);
if (cookie->attribute != NULL)
ldap_value_free (cookie->attribute);
if (cookie->state != NULL)
{
_nss_ldap_ent_context_release (&(cookie->state));
}
if (cookie->mapped_filter != NULL)
free (cookie->mapped_filter);
if (cookie->mapped_attribute != NULL)
free (cookie->mapped_attribute);
_nss_ldap_am_context_free (&cookie->am_state);
__ns_ldap_freeResult (&cookie->result);
free (cookie);
}
*pCookie = NULL;
return NS_LDAP_SUCCESS;
}
示例10: __ns_ldap_unmapObjectClasses
static ns_ldap_return_code
__ns_ldap_unmapObjectClasses (ns_ldap_cookie_t * cookie, char **mappedClasses,
char ***pOrigClasses)
{
char **origClasses = NULL;
int count, i;
count = ldap_count_values (mappedClasses);
origClasses = (char **) calloc (count + 1, sizeof (char *));
if (origClasses == NULL)
{
return NS_LDAP_MEMORY;
}
for (i = 0; i < count; i++)
{
origClasses[i] =
strdup (_nss_ldap_unmap_oc (cookie->sel, mappedClasses[i]));
if (origClasses[i] == NULL)
{
ldap_value_free (origClasses);
return NS_LDAP_MEMORY;
}
}
origClasses[i] = NULL;
*pOrigClasses = origClasses;
return NS_LDAP_SUCCESS;
}
示例11: LwLdapGetString
DWORD
LwLdapGetString(
HANDLE hDirectory,
LDAPMessage* pMessage,
PCSTR pszFieldName,
PSTR* ppszValue
)
{
DWORD dwError = LW_ERROR_SUCCESS;
PLW_LDAP_DIRECTORY_CONTEXT pDirectory = NULL;
PSTR *ppszValues = NULL;
PSTR pszValue = NULL;
pDirectory = (PLW_LDAP_DIRECTORY_CONTEXT)hDirectory;
ppszValues = (PSTR*)ldap_get_values(pDirectory->ld, pMessage, pszFieldName);
if (ppszValues && ppszValues[0]) {
dwError = LwAllocateString(ppszValues[0], &pszValue);
BAIL_ON_LW_ERROR(dwError);
}
*ppszValue = pszValue;
cleanup:
if (ppszValues) {
ldap_value_free(ppszValues);
}
return dwError;
error:
*ppszValue = NULL;
LW_SAFE_FREE_STRING(pszValue);
goto cleanup;
}
示例12: ads_dump
/*
dump a record from LDAP on stdout
used for debugging
*/
void ads_dump(ADS_STRUCT *ads, LDAPMessage *res)
{
char *field;
LDAPMessage *msg;
BerElement *b;
char *this_dn;
for (msg = ldap_first_entry(ads->ld, res);
msg; msg = ldap_next_entry(ads->ld, msg)) {
this_dn = ldap_get_dn(ads->ld, res);
if (this_dn) {
printf("Dumping: %s\n", this_dn);
}
ldap_memfree(this_dn);
for (field = ldap_first_attribute(ads->ld, msg, &b);
field;
field = ldap_next_attribute(ads->ld, msg, b)) {
char **values, **p;
values = ldap_get_values(ads->ld, msg, field);
for (p = values; *p; p++) {
printf("%s: %s\n", field, *p);
}
ldap_value_free(values);
ldap_memfree(field);
}
ber_free(b, 1);
printf("\n");
}
}
示例13: tcp_mapper_ldap_search
/**
* @name tcp_mapper_ldap_query
* @description Issue a query to a LDAP instance
* @param LDAP *ldap
* @return int numrows
*/
int tcp_mapper_ldap_search(LDAP *ldap, char *search, char *result){
LDAPMessage *ldap_result, *entry;
int numentries = 0;
int err;
char **val;
if(err = ldap_search_s(ldap, cfg.ldap_base, LDAP_SCOPE_SUBTREE, search,
NULL, 0, &ldap_result) != LDAP_SUCCESS ) {
printf("%s\n", ldap_err2string(err));
return -1;
}
numentries = ldap_count_entries(ldap, ldap_result);
if(numentries != 0) {
/* just firts entry. We don't need any other */
entry = ldap_first_entry(ldap, ldap_result);
val = ldap_get_values(ldap, entry, cfg.ldap_result_attr);
if(val == NULL) {
return 0;
}
snprintf(result, strlen(val[0])+1, "%s", (char *) val[0]);
ldap_value_free(val);
}
return numentries;
}
示例14: ldap_dump
static void ldap_dump(LDAP *ld,LDAPMessage *res)
{
LDAPMessage *e;
for (e = ldap_first_entry(ld, res); e; e = ldap_next_entry(ld, e)) {
BerElement *b;
char *attr;
char *dn = ldap_get_dn(ld, res);
if (dn)
printf("dn: %s\n", dn);
ldap_memfree(dn);
for (attr = ldap_first_attribute(ld, e, &b);
attr;
attr = ldap_next_attribute(ld, e, b)) {
char **values, **p;
values = ldap_get_values(ld, e, attr);
for (p = values; *p; p++) {
printf("%s: %s\n", attr, *p);
}
ldap_value_free(values);
ldap_memfree(attr);
}
ber_free(b, 1);
printf("\n");
}
}
示例15: rb_ldap_explode_dn
VALUE
rb_ldap_explode_dn (VALUE self, VALUE dn, VALUE notypes)
{
char **c_arr, **p;
char *c_dn;
VALUE ary;
if (dn == Qnil)
{
return Qnil;
}
c_dn = StringValueCStr (dn);
if ((c_arr = ldap_explode_dn (c_dn, RTEST (notypes) ? 1 : 0)))
{
ary = rb_ary_new ();
for (p = c_arr; *p != NULL; p++)
{
rb_ary_push (ary, rb_tainted_str_new2 (*p));
}
ldap_value_free (c_arr);
return ary;
}
else
{
return Qnil;
}
}