1 /* search.c - /etc/passwd backend search function */
7 #include <sys/socket.h>
12 extern time_t currenttime;
13 extern pthread_mutex_t currenttime_mutex;
15 static Entry *pw2entry();
38 tlimit = (tlimit > be->be_timelimit || tlimit < 1) ? be->be_timelimit
40 stoptime = op->o_time + tlimit;
41 slimit = (slimit > be->be_sizelimit || slimit < 1) ? be->be_sizelimit
45 if ( be->be_private != NULL ) {
47 (void) setpwfile( (char *) be->be_private );
49 #endif /* HAVE_SETPWFILE */
51 if ( scope == LDAP_SCOPE_BASE ) {
52 if ( (s = strchr( base, '@' )) != NULL ) {
56 if ( (pw = getpwnam( base )) == NULL ) {
57 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
58 s != NULL ? s + 1 : NULL, NULL );
62 e = pw2entry( be, pw );
63 if ( test_filter( be, conn, op, e, filter ) == 0 ) {
64 send_search_entry( be, conn, op, e, attrs, attrsonly );
68 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
73 for ( pw = getpwent(); pw != NULL; pw = getpwent() ) {
74 /* check for abandon */
75 pthread_mutex_lock( &op->o_abandonmutex );
76 if ( op->o_abandon ) {
77 pthread_mutex_unlock( &op->o_abandonmutex );
81 pthread_mutex_unlock( &op->o_abandonmutex );
83 /* check size limit */
84 if ( --slimit == -1 ) {
85 send_ldap_result( conn, op, LDAP_SIZELIMIT_EXCEEDED,
91 /* check time limit */
92 pthread_mutex_lock( ¤ttime_mutex );
94 if ( currenttime > stoptime ) {
95 pthread_mutex_unlock( ¤ttime_mutex );
96 send_ldap_result( conn, op, LDAP_TIMELIMIT_EXCEEDED,
101 pthread_mutex_unlock( ¤ttime_mutex );
103 e = pw2entry( be, pw );
105 if ( test_filter( be, conn, op, e, filter ) == 0 ) {
106 send_search_entry( be, conn, op, e, attrs, attrsonly );
112 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
118 pw2entry( Backend *be, struct passwd *pw )
123 struct berval *vals[2];
129 * from pw we get pw_name and make it uid and cn and sn and
130 * we get pw_gecos and make it cn and we give it an objectclass
134 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
137 sprintf( buf, "%s@%s", pw->pw_name, be->be_suffix[0] );
138 e->e_dn = strdup( buf );
140 val.bv_val = pw->pw_name;
141 val.bv_len = strlen( pw->pw_name );
142 attr_merge( e, "cn", vals );
143 attr_merge( e, "sn", vals );
144 attr_merge( e, "uid", vals );
145 val.bv_val = pw->pw_gecos;
146 val.bv_len = strlen( pw->pw_gecos );
147 attr_merge( e, "cn", vals );
148 val.bv_val = "person";
149 val.bv_len = strlen( val.bv_val );
150 attr_merge( e, "objectclass", vals );