1 /* search.c - /etc/passwd backend search function */
9 #include <sys/socket.h>
14 extern time_t currenttime;
15 extern pthread_mutex_t currenttime_mutex;
17 static Entry *pw2entry();
40 tlimit = (tlimit > be->be_timelimit || tlimit < 1) ? be->be_timelimit
42 stoptime = op->o_time + tlimit;
43 slimit = (slimit > be->be_sizelimit || slimit < 1) ? be->be_sizelimit
47 if ( be->be_private != NULL ) {
49 (void) setpwfile( (char *) be->be_private );
51 #endif /* HAVE_SETPWFILE */
53 if ( scope == LDAP_SCOPE_BASE ) {
54 if ( (s = strchr( base, '@' )) != NULL ) {
58 if ( (pw = getpwnam( base )) == NULL ) {
59 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
60 s != NULL ? s + 1 : NULL, NULL );
64 e = pw2entry( be, pw );
65 if ( test_filter( be, conn, op, e, filter ) == 0 ) {
66 send_search_entry( be, conn, op, e, attrs, attrsonly );
70 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
75 for ( pw = getpwent(); pw != NULL; pw = getpwent() ) {
76 /* check for abandon */
77 pthread_mutex_lock( &op->o_abandonmutex );
78 if ( op->o_abandon ) {
79 pthread_mutex_unlock( &op->o_abandonmutex );
83 pthread_mutex_unlock( &op->o_abandonmutex );
85 /* check size limit */
86 if ( --slimit == -1 ) {
87 send_ldap_result( conn, op, LDAP_SIZELIMIT_EXCEEDED,
93 /* check time limit */
94 pthread_mutex_lock( ¤ttime_mutex );
96 if ( currenttime > stoptime ) {
97 pthread_mutex_unlock( ¤ttime_mutex );
98 send_ldap_result( conn, op, LDAP_TIMELIMIT_EXCEEDED,
103 pthread_mutex_unlock( ¤ttime_mutex );
105 e = pw2entry( be, pw );
107 if ( test_filter( be, conn, op, e, filter ) == 0 ) {
108 send_search_entry( be, conn, op, e, attrs, attrsonly );
114 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
120 pw2entry( Backend *be, struct passwd *pw )
125 struct berval *vals[2];
131 * from pw we get pw_name and make it uid and cn and sn and
132 * we get pw_gecos and make it cn and we give it an objectclass
136 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
139 sprintf( buf, "%s@%s", pw->pw_name, be->be_suffix[0] );
140 e->e_dn = 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 );
147 val.bv_val = pw->pw_gecos;
148 val.bv_len = strlen( pw->pw_gecos );
149 attr_merge( e, "cn", vals );
150 val.bv_val = "person";
151 val.bv_len = strlen( val.bv_val );
152 attr_merge( e, "objectclass", vals );