1 /* search.c - /etc/passwd backend search function */
16 static Entry *pw2entry(Backend *be, struct passwd *pw);
39 tlimit = (tlimit > be->be_timelimit || tlimit < 1) ? be->be_timelimit
41 stoptime = op->o_time + tlimit;
42 slimit = (slimit > be->be_sizelimit || slimit < 1) ? be->be_sizelimit
46 if ( be->be_private != NULL ) {
48 (void) setpwfile( (char *) be->be_private );
50 #endif /* HAVE_SETPWFILE */
52 if ( scope == LDAP_SCOPE_BASE ) {
53 if ( (s = strchr( base, '@' )) != NULL ) {
57 if ( (pw = getpwnam( base )) == NULL ) {
58 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
59 s != NULL ? s + 1 : NULL, NULL );
63 e = pw2entry( be, pw );
64 if ( test_filter( be, conn, op, e, filter ) == 0 ) {
65 send_search_entry( be, conn, op, e, attrs, attrsonly );
69 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
74 for ( pw = getpwent(); pw != NULL; pw = getpwent() ) {
75 /* check for abandon */
76 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
77 if ( op->o_abandon ) {
78 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
82 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
84 /* check time limit */
85 if ( slap_get_time() > stoptime ) {
86 send_ldap_result( conn, op, LDAP_TIMELIMIT_EXCEEDED,
92 e = pw2entry( be, pw );
94 if ( test_filter( be, conn, op, e, filter ) == 0 ) {
95 /* check size limit */
96 if ( --slimit == -1 ) {
97 send_ldap_result( conn, op, LDAP_SIZELIMIT_EXCEEDED,
103 send_search_entry( be, conn, op, e, attrs, attrsonly );
109 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
115 pw2entry( Backend *be, struct passwd *pw )
120 struct berval *vals[2];
126 * from pw we get pw_name and make it uid and cn and sn and
127 * we get pw_gecos and make it cn and we give it an objectclass
131 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
134 sprintf( buf, "%s@%s", pw->pw_name, be->be_suffix[0] );
135 e->e_dn = ch_strdup( buf );
136 e->e_ndn = dn_normalize_case( ch_strdup( buf ) );
138 val.bv_val = pw->pw_name;
139 val.bv_len = strlen( pw->pw_name );
140 attr_merge( e, "cn", vals );
141 attr_merge( e, "sn", vals );
142 attr_merge( e, "uid", vals );
144 val.bv_val = pw->pw_gecos;
145 val.bv_len = strlen( pw->pw_gecos );
146 attr_merge( e, "cn", vals );
148 val.bv_val = "person";
149 val.bv_len = strlen( val.bv_val );
150 attr_merge( e, "objectclass", vals );