1998-08-09 08:43:13 +08:00
|
|
|
/* search.c - /etc/passwd backend search function */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-27 09:42:27 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2005-01-02 04:49:32 +08:00
|
|
|
* Copyright 1998-2005 The OpenLDAP Foundation.
|
2003-11-27 09:42:27 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* Portions Copyright (c) 1995 Regents of the University of Michigan.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that this notice is preserved and that due credit is given
|
|
|
|
* to the University of Michigan at Ann Arbor. The name of the University
|
|
|
|
* may not be used to endorse or promote products derived from this
|
|
|
|
* software without specific prior written permission. This software
|
|
|
|
* is provided ``as is'' without express or implied warranty.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was originally developed by the University of Michigan
|
|
|
|
* (as part of U-MICH LDAP). Additional significant contributors
|
|
|
|
* include:
|
|
|
|
* Hallvard B. Furuseth
|
|
|
|
* Howard Chu
|
|
|
|
* Kurt D. Zeilenga
|
2003-05-25 11:56:57 +08:00
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1999-04-29 14:50:00 +08:00
|
|
|
#include <ac/ctype.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <pwd.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "slap.h"
|
2002-05-09 10:26:05 +08:00
|
|
|
#include "back-passwd.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2002-05-15 13:44:46 +08:00
|
|
|
static void pw_start( Backend *be );
|
2002-05-09 10:26:05 +08:00
|
|
|
|
1999-04-29 14:50:00 +08:00
|
|
|
static Entry *pw2entry(
|
|
|
|
Backend *be,
|
2002-01-01 17:49:23 +08:00
|
|
|
struct passwd *pw,
|
|
|
|
const char **text);
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
passwd_back_search(
|
|
|
|
Operation *op,
|
2003-03-30 17:03:54 +08:00
|
|
|
SlapReply *rs )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
struct passwd *pw;
|
|
|
|
Entry *e;
|
|
|
|
char *s;
|
|
|
|
time_t stoptime;
|
1999-07-16 10:45:46 +08:00
|
|
|
|
2003-04-11 09:29:28 +08:00
|
|
|
LDAPRDN rdn = NULL;
|
2004-04-07 12:11:43 +08:00
|
|
|
struct berval parent = BER_BVNULL;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2000-05-25 09:15:09 +08:00
|
|
|
AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
|
|
|
|
|
2004-06-12 19:33:21 +08:00
|
|
|
if (op->ors_tlimit != SLAP_NO_LIMIT ) {
|
|
|
|
stoptime = op->o_time + op->ors_tlimit;
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-04-29 14:50:00 +08:00
|
|
|
/* Handle a query for the base of this backend */
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( be_issuffix( op->o_bd, &op->o_req_ndn ) ) {
|
2002-01-02 21:09:28 +08:00
|
|
|
struct berval vals[2];
|
1999-04-29 14:50:00 +08:00
|
|
|
|
2002-01-02 21:09:28 +08:00
|
|
|
vals[1].bv_val = NULL;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_matched = op->o_req_dn.bv_val;
|
1999-04-29 14:50:00 +08:00
|
|
|
|
2004-03-09 02:12:45 +08:00
|
|
|
if( op->ors_scope != LDAP_SCOPE_ONELEVEL ) {
|
2000-05-25 09:15:09 +08:00
|
|
|
AttributeDescription *desc = NULL;
|
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
/* Create an entry corresponding to the base DN */
|
|
|
|
e = (Entry *) ch_calloc(1, sizeof(Entry));
|
2003-03-30 17:03:54 +08:00
|
|
|
e->e_name.bv_val = ch_strdup( op->o_req_dn.bv_val );
|
|
|
|
e->e_name.bv_len = op->o_req_dn.bv_len;
|
|
|
|
e->e_nname.bv_val = ch_strdup( op->o_req_ndn.bv_val );
|
|
|
|
e->e_nname.bv_len = op->o_req_ndn.bv_len;
|
1999-07-16 10:45:46 +08:00
|
|
|
e->e_attrs = NULL;
|
2001-12-27 06:59:28 +08:00
|
|
|
e->e_private = NULL;
|
2001-11-28 10:23:36 +08:00
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
/* Use the first attribute of the DN
|
|
|
|
* as an attribute within the entry itself.
|
|
|
|
*/
|
2003-03-30 17:03:54 +08:00
|
|
|
if( ldap_bv2rdn( &op->o_req_dn, &rdn, (char **)&rs->sr_text,
|
2002-01-10 02:18:36 +08:00
|
|
|
LDAP_DN_FORMAT_LDAP ) )
|
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_INVALID_DN_SYNTAX;
|
1999-07-16 10:45:46 +08:00
|
|
|
goto done;
|
|
|
|
}
|
1999-04-29 14:50:00 +08:00
|
|
|
|
2003-04-11 09:29:28 +08:00
|
|
|
if( slap_bv2ad( &rdn[0]->la_attr, &desc, &rs->sr_text )) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_NO_SUCH_OBJECT;
|
2002-01-01 17:41:10 +08:00
|
|
|
ldap_rdnfree(rdn);
|
|
|
|
goto done;
|
2000-05-25 09:15:09 +08:00
|
|
|
}
|
|
|
|
|
2003-04-11 09:29:28 +08:00
|
|
|
vals[0] = rdn[0]->la_value;
|
2003-02-27 06:58:46 +08:00
|
|
|
attr_mergeit( e, desc, vals );
|
2000-05-25 09:15:09 +08:00
|
|
|
|
2002-01-01 17:41:10 +08:00
|
|
|
ldap_rdnfree(rdn);
|
1999-07-16 10:45:46 +08:00
|
|
|
rdn = NULL;
|
|
|
|
|
|
|
|
/* Every entry needs an objectclass. We don't really
|
|
|
|
* know if our hardcoded choice here agrees with the
|
|
|
|
* DN that was configured for this backend, but it's
|
|
|
|
* better than nothing.
|
|
|
|
*
|
|
|
|
* should be a configuratable item
|
|
|
|
*/
|
2002-01-02 21:09:28 +08:00
|
|
|
vals[0].bv_val = "organizationalUnit";
|
|
|
|
vals[0].bv_len = sizeof("organizationalUnit")-1;
|
2003-02-27 06:58:46 +08:00
|
|
|
attr_mergeit( e, ad_objectClass, vals );
|
1999-04-29 14:50:00 +08:00
|
|
|
|
2004-03-09 02:12:45 +08:00
|
|
|
if ( test_filter( op, e, op->ors_filter ) == LDAP_COMPARE_TRUE ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_entry = e;
|
2004-03-09 02:12:45 +08:00
|
|
|
rs->sr_attrs = op->ors_attrs;
|
2004-03-17 19:50:15 +08:00
|
|
|
rs->sr_flags = REP_ENTRY_MODIFIABLE;
|
2003-03-30 17:03:54 +08:00
|
|
|
send_search_entry( op, rs );
|
1999-07-16 10:45:46 +08:00
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
2004-03-09 02:12:45 +08:00
|
|
|
if ( op->ors_scope != LDAP_SCOPE_BASE ) {
|
1999-04-29 14:50:00 +08:00
|
|
|
/* check all our "children" */
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2002-05-09 10:26:05 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &passwd_mutex );
|
2003-03-30 17:03:54 +08:00
|
|
|
pw_start( op->o_bd );
|
1999-04-29 14:50:00 +08:00
|
|
|
for ( pw = getpwent(); pw != NULL; pw = getpwent() ) {
|
|
|
|
/* check for abandon */
|
|
|
|
if ( op->o_abandon ) {
|
|
|
|
endpwent();
|
2002-05-09 10:26:05 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &passwd_mutex );
|
1999-04-29 14:50:00 +08:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check time limit */
|
2004-06-12 19:33:21 +08:00
|
|
|
if ( op->ors_tlimit != SLAP_NO_LIMIT
|
|
|
|
&& slap_get_time() > stoptime )
|
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_TIMELIMIT_EXCEEDED, NULL );
|
1999-04-29 14:50:00 +08:00
|
|
|
endpwent();
|
2002-05-09 10:26:05 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &passwd_mutex );
|
1999-04-29 14:50:00 +08:00
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( !(e = pw2entry( op->o_bd, pw, &rs->sr_text )) ) {
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
2002-01-01 17:49:23 +08:00
|
|
|
endpwent();
|
2002-05-09 10:26:05 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &passwd_mutex );
|
2002-01-01 17:49:23 +08:00
|
|
|
goto done;
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2004-03-09 02:12:45 +08:00
|
|
|
if ( test_filter( op, e, op->ors_filter ) == LDAP_COMPARE_TRUE ) {
|
1999-04-29 14:50:00 +08:00
|
|
|
/* check size limit */
|
2004-03-09 02:12:45 +08:00
|
|
|
if ( --op->ors_slimit == -1 ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_SIZELIMIT_EXCEEDED, NULL );
|
1999-04-29 14:50:00 +08:00
|
|
|
endpwent();
|
2002-05-09 10:26:05 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &passwd_mutex );
|
1999-04-29 14:50:00 +08:00
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_entry = e;
|
2004-03-09 02:12:45 +08:00
|
|
|
rs->sr_attrs = op->ors_attrs;
|
2004-03-17 19:50:15 +08:00
|
|
|
rs->sr_flags = REP_ENTRY_MODIFIABLE;
|
2003-03-30 17:03:54 +08:00
|
|
|
send_search_entry( op, rs );
|
1999-04-29 14:50:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
entry_free( e );
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
endpwent();
|
2002-05-09 10:26:05 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &passwd_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-04-29 14:50:00 +08:00
|
|
|
} else {
|
2003-03-30 17:03:54 +08:00
|
|
|
if (! be_issuffix( op->o_bd, &op->o_req_ndn ) ) {
|
|
|
|
dnParent( &op->o_req_ndn, &parent );
|
2002-01-26 14:52:59 +08:00
|
|
|
}
|
1999-04-29 14:50:00 +08:00
|
|
|
|
|
|
|
/* This backend is only one layer deep. Don't answer requests for
|
|
|
|
* anything deeper than that.
|
|
|
|
*/
|
2003-03-30 17:03:54 +08:00
|
|
|
if( !be_issuffix( op->o_bd, &parent ) ) {
|
1999-07-16 10:45:46 +08:00
|
|
|
int i;
|
2003-03-30 17:03:54 +08:00
|
|
|
for( i=0; op->o_bd->be_nsuffix[i].bv_val != NULL; i++ ) {
|
|
|
|
if( dnIsSuffix( &op->o_req_ndn, &op->o_bd->be_nsuffix[i] ) ) {
|
|
|
|
rs->sr_matched = op->o_bd->be_suffix[i].bv_val;
|
1999-07-16 10:45:46 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_NO_SUCH_OBJECT;
|
1999-07-16 10:45:46 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2004-03-09 02:12:45 +08:00
|
|
|
if( op->ors_scope == LDAP_SCOPE_ONELEVEL ) {
|
1999-04-29 14:50:00 +08:00
|
|
|
goto done;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( ldap_bv2rdn( &op->o_req_dn, &rdn, (char **)&rs->sr_text,
|
2002-01-10 02:18:36 +08:00
|
|
|
LDAP_DN_FORMAT_LDAP ))
|
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
1999-04-29 14:50:00 +08:00
|
|
|
goto done;
|
|
|
|
}
|
1998-10-26 11:33:30 +08:00
|
|
|
|
2002-05-09 10:26:05 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &passwd_mutex );
|
2003-03-30 17:03:54 +08:00
|
|
|
pw_start( op->o_bd );
|
2003-04-11 09:29:28 +08:00
|
|
|
if ( (pw = getpwnam( rdn[0]->la_value.bv_val )) == NULL ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_matched = parent.bv_val;
|
|
|
|
rs->sr_err = LDAP_NO_SUCH_OBJECT;
|
2002-05-09 10:26:05 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &passwd_mutex );
|
1999-04-29 14:50:00 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
e = pw2entry( op->o_bd, pw, &rs->sr_text );
|
2002-05-09 10:26:05 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &passwd_mutex );
|
|
|
|
if ( !e ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
2002-01-01 17:49:23 +08:00
|
|
|
goto done;
|
|
|
|
}
|
1999-04-29 14:50:00 +08:00
|
|
|
|
2004-03-09 02:12:45 +08:00
|
|
|
if ( test_filter( op, e, op->ors_filter ) == LDAP_COMPARE_TRUE ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_entry = e;
|
2004-03-09 02:12:45 +08:00
|
|
|
rs->sr_attrs = op->ors_attrs;
|
2004-03-17 19:50:15 +08:00
|
|
|
rs->sr_flags = REP_ENTRY_MODIFIABLE;
|
2003-03-30 17:03:54 +08:00
|
|
|
send_search_entry( op, rs );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
entry_free( e );
|
|
|
|
}
|
1999-04-29 14:50:00 +08:00
|
|
|
|
|
|
|
done:
|
2003-03-30 17:03:54 +08:00
|
|
|
if( rs->sr_err != LDAP_NO_SUCH_OBJECT ) rs->sr_matched = NULL;
|
2003-04-01 12:12:18 +08:00
|
|
|
send_ldap_result( op, rs );
|
1999-04-29 14:50:00 +08:00
|
|
|
|
2002-01-01 17:41:10 +08:00
|
|
|
if( rdn != NULL ) ldap_rdnfree( rdn );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
2002-05-09 10:26:05 +08:00
|
|
|
static void
|
|
|
|
pw_start(
|
|
|
|
Backend *be
|
|
|
|
)
|
|
|
|
{
|
|
|
|
endpwent();
|
|
|
|
|
|
|
|
#ifdef HAVE_SETPWFILE
|
|
|
|
if ( be->be_private != NULL ) {
|
|
|
|
(void) setpwfile( (char *) be->be_private );
|
|
|
|
}
|
|
|
|
#endif /* HAVE_SETPWFILE */
|
|
|
|
}
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
static Entry *
|
2002-01-01 17:49:23 +08:00
|
|
|
pw2entry( Backend *be, struct passwd *pw, const char **text )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
2001-12-28 15:09:12 +08:00
|
|
|
size_t pwlen;
|
1998-08-09 08:43:13 +08:00
|
|
|
Entry *e;
|
2002-01-02 21:09:28 +08:00
|
|
|
struct berval vals[2];
|
2001-12-29 12:48:00 +08:00
|
|
|
struct berval bv;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2000-05-25 09:15:09 +08:00
|
|
|
int rc;
|
|
|
|
|
2001-12-28 15:09:12 +08:00
|
|
|
AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
|
2000-05-25 09:15:09 +08:00
|
|
|
AttributeDescription *ad_cn = NULL;
|
|
|
|
AttributeDescription *ad_sn = NULL;
|
|
|
|
AttributeDescription *ad_uid = NULL;
|
|
|
|
AttributeDescription *ad_description = NULL;
|
|
|
|
|
2002-01-01 17:49:23 +08:00
|
|
|
rc = slap_str2ad( "cn", &ad_cn, text );
|
2000-05-25 09:15:09 +08:00
|
|
|
if(rc != LDAP_SUCCESS) return NULL;
|
2002-01-01 17:49:23 +08:00
|
|
|
rc = slap_str2ad( "sn", &ad_sn, text );
|
2000-05-25 09:15:09 +08:00
|
|
|
if(rc != LDAP_SUCCESS) return NULL;
|
2002-01-01 17:49:23 +08:00
|
|
|
rc = slap_str2ad( "uid", &ad_uid, text );
|
2000-05-25 09:15:09 +08:00
|
|
|
if(rc != LDAP_SUCCESS) return NULL;
|
2002-01-01 17:49:23 +08:00
|
|
|
rc = slap_str2ad( "description", &ad_description, text );
|
2000-05-25 09:15:09 +08:00
|
|
|
if(rc != LDAP_SUCCESS) return NULL;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
1999-04-29 14:50:00 +08:00
|
|
|
* from pw we get pw_name and make it cn
|
|
|
|
* give it an objectclass of person.
|
1998-08-09 08:43:13 +08:00
|
|
|
*/
|
|
|
|
|
2001-12-28 15:09:12 +08:00
|
|
|
pwlen = strlen( pw->pw_name );
|
2002-05-02 02:50:14 +08:00
|
|
|
vals[0].bv_len = (sizeof("uid=,")-1) + ( pwlen + be->be_suffix[0].bv_len );
|
2002-01-02 21:09:28 +08:00
|
|
|
vals[0].bv_val = ch_malloc( vals[0].bv_len + 1 );
|
2001-12-28 15:09:12 +08:00
|
|
|
|
|
|
|
/* rdn attribute type should be a configuratable item */
|
2002-01-02 21:09:28 +08:00
|
|
|
sprintf( vals[0].bv_val, "uid=%s,%s",
|
2002-05-02 02:50:14 +08:00
|
|
|
pw->pw_name, be->be_suffix[0].bv_val );
|
2001-12-28 15:09:12 +08:00
|
|
|
|
2003-05-14 21:58:30 +08:00
|
|
|
rc = dnNormalize( 0, NULL, NULL, vals, &bv, NULL );
|
2001-12-28 15:09:12 +08:00
|
|
|
if( rc != LDAP_SUCCESS ) {
|
2002-01-02 21:09:28 +08:00
|
|
|
free( vals[0].bv_val );
|
2001-12-28 15:09:12 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
e = (Entry *) ch_calloc( 1, sizeof(Entry) );
|
2002-01-02 21:09:28 +08:00
|
|
|
e->e_name = vals[0];
|
2001-12-29 12:48:00 +08:00
|
|
|
e->e_nname = bv;
|
2001-12-28 15:09:12 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
e->e_attrs = NULL;
|
|
|
|
|
2002-01-02 21:09:28 +08:00
|
|
|
vals[1].bv_val = NULL;
|
2001-12-28 15:09:12 +08:00
|
|
|
|
|
|
|
/* objectclasses should be configurable items */
|
2002-01-02 21:09:28 +08:00
|
|
|
vals[0].bv_val = "top";
|
|
|
|
vals[0].bv_len = sizeof("top")-1;
|
2003-02-27 06:58:46 +08:00
|
|
|
attr_mergeit( e, ad_objectClass, vals );
|
2000-05-25 09:15:09 +08:00
|
|
|
|
2002-01-02 21:09:28 +08:00
|
|
|
vals[0].bv_val = "person";
|
|
|
|
vals[0].bv_len = sizeof("person")-1;
|
2003-02-27 06:58:46 +08:00
|
|
|
attr_mergeit( e, ad_objectClass, vals );
|
2000-05-25 09:15:09 +08:00
|
|
|
|
2002-01-02 21:09:28 +08:00
|
|
|
vals[0].bv_val = "uidObject";
|
|
|
|
vals[0].bv_len = sizeof("uidObject")-1;
|
2003-02-27 06:58:46 +08:00
|
|
|
attr_mergeit( e, ad_objectClass, vals );
|
2000-05-25 09:15:09 +08:00
|
|
|
|
2002-01-02 21:09:28 +08:00
|
|
|
vals[0].bv_val = pw->pw_name;
|
|
|
|
vals[0].bv_len = pwlen;
|
2003-02-27 06:58:46 +08:00
|
|
|
attr_mergeit( e, ad_uid, vals ); /* required by uidObject */
|
|
|
|
attr_mergeit( e, ad_cn, vals ); /* required by person */
|
|
|
|
attr_mergeit( e, ad_sn, vals ); /* required by person */
|
1999-04-29 14:50:00 +08:00
|
|
|
|
1999-03-18 06:27:46 +08:00
|
|
|
#ifdef HAVE_PW_GECOS
|
1999-04-29 14:50:00 +08:00
|
|
|
/*
|
|
|
|
* if gecos is present, add it as a cn. first process it
|
|
|
|
* according to standard BSD usage. If the processed cn has
|
|
|
|
* a space, use the tail as the surname.
|
|
|
|
*/
|
|
|
|
if (pw->pw_gecos[0]) {
|
|
|
|
char *s;
|
|
|
|
|
2002-01-02 21:09:28 +08:00
|
|
|
vals[0].bv_val = pw->pw_gecos;
|
|
|
|
vals[0].bv_len = strlen(vals[0].bv_val);
|
2003-02-27 06:58:46 +08:00
|
|
|
attr_mergeit(e, ad_description, vals);
|
1999-04-29 14:50:00 +08:00
|
|
|
|
2002-01-02 21:09:28 +08:00
|
|
|
s = strchr(vals[0].bv_val, ',');
|
2001-12-28 15:30:34 +08:00
|
|
|
if (s) *s = '\0';
|
|
|
|
|
2002-01-02 21:09:28 +08:00
|
|
|
s = strchr(vals[0].bv_val, '&');
|
1999-04-29 14:50:00 +08:00
|
|
|
if (s) {
|
2002-08-27 04:10:45 +08:00
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
if( vals[0].bv_len + pwlen < sizeof(buf) ) {
|
|
|
|
int i = s - vals[0].bv_val;
|
|
|
|
strncpy(buf, vals[0].bv_val, i);
|
|
|
|
s = buf+i;
|
|
|
|
strcpy(s, pw->pw_name);
|
|
|
|
*s = TOUPPER((unsigned char)*s);
|
|
|
|
strcat(s, vals[0].bv_val+i+1);
|
|
|
|
vals[0].bv_val = buf;
|
|
|
|
}
|
1999-04-29 14:50:00 +08:00
|
|
|
}
|
2002-01-02 21:09:28 +08:00
|
|
|
vals[0].bv_len = strlen(vals[0].bv_val);
|
2002-08-27 04:10:45 +08:00
|
|
|
|
|
|
|
if ( vals[0].bv_len && strcasecmp( vals[0].bv_val, pw->pw_name )) {
|
2003-02-27 06:58:46 +08:00
|
|
|
attr_mergeit( e, ad_cn, vals );
|
2002-08-27 04:10:45 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 21:09:28 +08:00
|
|
|
if ( (s=strrchr(vals[0].bv_val, ' '))) {
|
|
|
|
vals[0].bv_val = s + 1;
|
|
|
|
vals[0].bv_len = strlen(vals[0].bv_val);
|
2003-02-27 06:58:46 +08:00
|
|
|
attr_mergeit(e, ad_sn, vals);
|
1999-04-29 14:50:00 +08:00
|
|
|
}
|
|
|
|
}
|
1999-03-18 06:27:46 +08:00
|
|
|
#endif
|
1999-04-29 14:50:00 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
return( e );
|
|
|
|
}
|