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 ldap_pvt_thread_mutex_lock( ¤ttime_mutex );
87 if ( currenttime > stoptime ) {
88 ldap_pvt_thread_mutex_unlock( ¤ttime_mutex );
89 send_ldap_result( conn, op, LDAP_TIMELIMIT_EXCEEDED,
94 ldap_pvt_thread_mutex_unlock( ¤ttime_mutex );
96 e = pw2entry( be, pw );
98 if ( test_filter( be, conn, op, e, filter ) == 0 ) {
99 /* check size limit */
100 if ( --slimit == -1 ) {
101 send_ldap_result( conn, op, LDAP_SIZELIMIT_EXCEEDED,
107 send_search_entry( be, conn, op, e, attrs, attrsonly );
113 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
119 pw2entry( Backend *be, struct passwd *pw )
124 struct berval *vals[2];
130 * from pw we get pw_name and make it uid and cn and sn and
131 * we get pw_gecos and make it cn and we give it an objectclass
135 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
138 sprintf( buf, "%s@%s", pw->pw_name, be->be_suffix[0] );
139 e->e_dn = ch_strdup( buf );
140 e->e_ndn = dn_normalize_case( ch_strdup( buf ) );
142 val.bv_val = pw->pw_name;
143 val.bv_len = strlen( pw->pw_name );
144 attr_merge( e, "cn", vals );
145 attr_merge( e, "sn", vals );
146 attr_merge( e, "uid", vals );
148 val.bv_val = pw->pw_gecos;
149 val.bv_len = strlen( pw->pw_gecos );
150 attr_merge( e, "cn", vals );
152 val.bv_val = "person";
153 val.bv_len = strlen( val.bv_val );
154 attr_merge( e, "objectclass", vals );