int attrsonly
)
{
- int sent = 0;
struct passwd *pw;
Entry *e;
char *s;
time_t stoptime;
- int err = LDAP_NO_SUCH_OBJECT;
+
+ int sent = 0;
+ int err = LDAP_SUCCESS;
char *rdn = NULL;
char *parent = NULL;
vals[0] = &val;
vals[1] = NULL;
- /* Create an entry corresponding to the base DN */
- e = (Entry *) ch_calloc(1, sizeof(Entry));
- e->e_attrs = NULL;
- e->e_dn = strdup(base);
+ matched = ch_strdup( base );
- /* Use the first attribute of the DN
- * as an attribute within the entry itself.
- */
- rdn = dn_rdn(NULL, base);
+ if( scope != LDAP_SCOPE_ONELEVEL ) {
+ /* Create an entry corresponding to the base DN */
+ e = (Entry *) ch_calloc(1, sizeof(Entry));
+ e->e_attrs = NULL;
+ e->e_dn = ch_strdup( base );
- if( rdn == NULL || (s = strchr(rdn, '=')) == NULL ) {
- err = LDAP_INVALID_DN_SYNTAX;
- goto done;
- }
+ /* Use the first attribute of the DN
+ * as an attribute within the entry itself.
+ */
+ rdn = dn_rdn(NULL, base);
- val.bv_val = rdn_attr_value(rdn);
- val.bv_len = strlen( val.bv_val );
- attr_merge( e, rdn_attr_type(rdn), vals );
-
- free(rdn);
- rdn = NULL;
+ if( rdn == NULL || (s = strchr(rdn, '=')) == NULL ) {
+ err = LDAP_INVALID_DN_SYNTAX;
+ goto done;
+ }
- /* Every entry needs an objectclass. We don't really
- * know if our hardcoded choice here agrees with the
- * DN that was configured for this backend, but it's
- * better than nothing.
- *
- * should be a configuratable item
- */
- val.bv_val = "organizationalUnit";
- val.bv_len = strlen( val.bv_val );
- attr_merge( e, "objectClass", vals );
+ val.bv_val = rdn_attr_value(rdn);
+ val.bv_len = strlen( val.bv_val );
+ attr_merge( e, rdn_attr_type(rdn), vals );
+
+ free(rdn);
+ rdn = NULL;
+
+ /* Every entry needs an objectclass. We don't really
+ * know if our hardcoded choice here agrees with the
+ * DN that was configured for this backend, but it's
+ * better than nothing.
+ *
+ * should be a configuratable item
+ */
+ val.bv_val = "organizationalUnit";
+ val.bv_len = strlen( val.bv_val );
+ attr_merge( e, "objectClass", vals );
- if ( test_filter( be, conn, op, e, filter ) == 0 ) {
- send_search_entry( be, conn, op, e, attrs, attrsonly );
- matched = strdup( be->be_suffix[0] );
- sent++;
+ if ( test_filter( be, conn, op, e, filter ) == 0 ) {
+ send_search_entry( be, conn, op,
+ e, attrs, attrsonly, NULL );
+ sent++;
+ }
}
if ( scope != LDAP_SCOPE_BASE ) {
/* check time limit */
if ( slap_get_time() > stoptime ) {
send_ldap_result( conn, op, LDAP_TIMELIMIT_EXCEEDED,
- NULL, NULL );
+ NULL, NULL, NULL, NULL );
endpwent();
return( 0 );
}
/* check size limit */
if ( --slimit == -1 ) {
send_ldap_result( conn, op, LDAP_SIZELIMIT_EXCEEDED,
- NULL, NULL );
+ NULL, NULL, NULL, NULL );
endpwent();
return( 0 );
}
- send_search_entry( be, conn, op, e, attrs, attrsonly );
+ send_search_entry( be, conn, op,
+ e, attrs, attrsonly, NULL );
sent++;
}
* anything deeper than that.
*/
if( !be_issuffix( be, parent ) ) {
+ int i;
+ for( i=0; be->be_suffix[i] != NULL; i++ ) {
+ if( dn_issuffix( base, be->be_suffix[i] ) ) {
+ matched = ch_strdup( be->be_suffix[i] );
+ break;
+ }
+ }
+ err = LDAP_NO_SUCH_OBJECT;
+ goto done;
+ }
+
+ if( scope == LDAP_SCOPE_ONELEVEL ) {
goto done;
}
rdn = dn_rdn( NULL, base );
if ( (user = rdn_attr_value(rdn)) == NULL) {
- err = LDAP_INVALID_DN_SYNTAX;
+ err = LDAP_OPERATIONS_ERROR;
goto done;
}
- for( s = user; *s ; s++ ) {
- *s = TOLOWER( *s );
- }
+ user = str2lower( user );
if ( (pw = getpwnam( user )) == NULL ) {
+ matched = parent;
+ parent = NULL;
+ err = LDAP_NO_SUCH_OBJECT;
goto done;
}
e = pw2entry( be, pw, rdn );
if ( test_filter( be, conn, op, e, filter ) == 0 ) {
- send_search_entry( be, conn, op, e, attrs, attrsonly );
+ send_search_entry( be, conn, op,
+ e, attrs, attrsonly, NULL );
sent++;
}
}
done:
- if( sent ) {
- send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
-
- } else {
- send_ldap_result( conn, op, err, matched, NULL );
- }
+ send_ldap_result( conn, op,
+ err, err == LDAP_NO_SUCH_OBJECT ? matched : NULL, NULL,
+ NULL, NULL );
if( matched != NULL ) free( matched );
if( parent != NULL ) free( parent );
/* rdn attribute type should be a configuratable item */
sprintf( buf, "uid=%s,%s", pw->pw_name, be->be_suffix[0] );
e->e_dn = ch_strdup( buf );
- e->e_ndn = dn_normalize_case( ch_strdup( buf ) );
+ e->e_ndn = ch_strdup( buf );
+ (void) dn_normalize_case( e->e_ndn );
val.bv_val = pw->pw_name;
val.bv_len = strlen( pw->pw_name );
strncpy(buf, val.bv_val, i);
s = buf+i;
strcpy(s, pw->pw_name);
- if (islower(*s))
- *s = toupper(*s);
+ *s = TOUPPER(*s);
strcat(s, val.bv_val+i+1);
val.bv_val = buf;
}