1 /* search.c - /etc/passwd backend search function */
15 extern time_t currenttime;
16 extern pthread_mutex_t currenttime_mutex;
18 static Entry *pw2entry();
41 tlimit = (tlimit > be->be_timelimit || tlimit < 1) ? be->be_timelimit
43 stoptime = op->o_time + tlimit;
44 slimit = (slimit > be->be_sizelimit || slimit < 1) ? be->be_sizelimit
48 if ( be->be_private != NULL ) {
50 (void) setpwfile( (char *) be->be_private );
52 #endif /* HAVE_SETPWFILE */
54 if ( scope == LDAP_SCOPE_BASE ) {
55 if ( (s = strchr( base, '@' )) != NULL ) {
59 if ( (pw = getpwnam( base )) == NULL ) {
60 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
61 s != NULL ? s + 1 : NULL, NULL );
65 e = pw2entry( be, pw );
66 if ( test_filter( be, conn, op, e, filter ) == 0 ) {
67 send_search_entry( be, conn, op, e, attrs, attrsonly );
71 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
76 for ( pw = getpwent(); pw != NULL; pw = getpwent() ) {
77 /* check for abandon */
78 pthread_mutex_lock( &op->o_abandonmutex );
79 if ( op->o_abandon ) {
80 pthread_mutex_unlock( &op->o_abandonmutex );
84 pthread_mutex_unlock( &op->o_abandonmutex );
86 /* check time limit */
87 pthread_mutex_lock( ¤ttime_mutex );
89 if ( currenttime > stoptime ) {
90 pthread_mutex_unlock( ¤ttime_mutex );
91 send_ldap_result( conn, op, LDAP_TIMELIMIT_EXCEEDED,
96 pthread_mutex_unlock( ¤ttime_mutex );
98 e = pw2entry( be, pw );
100 if ( test_filter( be, conn, op, e, filter ) == 0 ) {
101 /* check size limit */
102 if ( --slimit == -1 ) {
103 send_ldap_result( conn, op, LDAP_SIZELIMIT_EXCEEDED,
109 send_search_entry( be, conn, op, e, attrs, attrsonly );
115 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
121 pw2entry( Backend *be, struct passwd *pw )
126 struct berval *vals[2];
132 * from pw we get pw_name and make it uid and cn and sn and
133 * we get pw_gecos and make it cn and we give it an objectclass
137 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
140 sprintf( buf, "%s@%s", pw->pw_name, be->be_suffix[0] );
141 e->e_dn = strdup( buf );
143 val.bv_val = pw->pw_name;
144 val.bv_len = strlen( pw->pw_name );
145 attr_merge( e, "cn", vals );
146 attr_merge( e, "sn", vals );
147 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 );
151 val.bv_val = "person";
152 val.bv_len = strlen( val.bv_val );
153 attr_merge( e, "objectclass", vals );