/* Checks whether an entry has a particular attribute type, and optionally returns the value. Only for use with single-valued attributes - it returns the first value it finds. */ int has_attr( Slapi_Entry* target_entry, char* attr_name, char** val ) { Slapi_ValueSet *values = NULL; Slapi_Value* sval; char *actual_type_name = NULL; int type_name_disposition = 0, attr_free_flags = 0, rc = 0; /* Use vattr interface to support virtual attributes, e.g. acctPolicySubentry has a good chance of being supplied by CoS */ if ( slapi_vattr_values_get( target_entry, attr_name, &values, &type_name_disposition, &actual_type_name, 0, &attr_free_flags) == 0) { if( slapi_valueset_first_value( values, &sval ) == -1 ) { rc = 0; } else { rc = 1; if( val ) { /* Caller wants a copy of the found attribute's value */ *val = slapi_ch_strdup( slapi_value_get_string( sval ) ); } } } else { rc = 0; } slapi_vattr_values_free(&values, &actual_type_name, attr_free_flags); return( rc ); }
/* Easier handling for virtual attributes. You must call pwd_values_free() * to free memory allocated here. It must be called before * slapi_free_search_results_internal(entries) or * slapi_pblock_destroy(pb) */ static int pwd_get_values(const Slapi_Entry *ent, const char *attrname, Slapi_ValueSet** results, char** actual_type_name, int *buffer_flags) { int flags=0; int type_name_disposition = 0; int ret; ret = slapi_vattr_values_get((Slapi_Entry *)ent, (char *)attrname, results, &type_name_disposition, actual_type_name, flags, buffer_flags); return ret; }