*** scheduler/dirsvc.c.orig Mon Sep 11 10:05:12 2006 --- scheduler/dirsvc.c Mon Sep 11 12:50:13 2006 *************** *** 46,51 **** --- 46,52 ---- * process_implicit_classes() - Create/update implicit classes as needed. * send_cups_browse() - Send new browsing information using the * CUPS protocol. + * send_ldap_ou() - Send LDAP ou registrations. * send_ldap_browse() - Send LDAP printer registrations. * send_slp_browse() - Register the specified printer with SLP. * slp_attr_callback() - SLP attribute callback *************** *** 2797,2802 **** --- 2798,2920 ---- #ifdef HAVE_OPENLDAP /* + * 'send_ldap_ou()' - Send LDAP ou registrations. + */ + + static void + send_ldap_ou(char *ou, char *basedn, char *descstring) /* I - ou to register */ + { + int i; /* Looping var... */ + LDAPMod mods[3]; /* The 7 attributes we will be adding */ + LDAPMod *pmods[4]; /* Pointers to the 7 attributes + NULL */ + LDAPMessage *res; /* Search result token */ + int rc; /* LDAP status */ + char dn[1024], /* DN of the organizational unit we are adding */ + filter[256], /* Search filter for possible UPDATEs */ + *desc[2], /* Change records */ + *ou_value[2]; + static const char * const objectClass_values[] = + { /* The 2 objectClass's we use in */ + "top", /* our LDAP entries */ + "organizationalUnit", + NULL + }; + static const char * const ou_attrs[] =/* CUPS LDAP attributes */ + { + "description", + NULL + }; + + cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_ldap_ou: %s\n", ou); + + snprintf(dn, sizeof(dn), "ou=%s, %s", ou, basedn); + cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_ldap_ou: dn=\"%s\"", dn); + + ou_value[0] = ou; + ou_value[1] = NULL; + desc[0] = descstring; + desc[1] = NULL; + + mods[0].mod_type = "ou"; + mods[0].mod_values = ou_value; + mods[1].mod_type = "description"; + mods[1].mod_values = desc; + mods[2].mod_type = "objectClass"; + mods[2].mod_values = (char **)objectClass_values; + + snprintf(filter, sizeof(filter), + "(&(objectclass=organizationalUnit)(ou=%s))", ServerName); + + rc = ldap_search_s(BrowseLDAPHandle, BrowseLDAPDN, LDAP_SCOPE_SUBTREE, + filter, (char **)ou_attrs, 0, &res); + cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_ldap_ou: Searching \"%s\"", + filter); + if ( rc != LDAP_SUCCESS ) { + cupsdLogMessage(CUPSD_LOG_ERROR, + "send_ldap_ou: LDAP search failed with status %d: %s", + rc, ldap_err2string(rc)); + + if ( LDAP_SERVER_DOWN == rc ) + cupsdReconnectLDAP(); + return; + } + + if (ldap_count_entries(BrowseLDAPHandle, res) > 0) + { + /* + * ou has already been registered, modify the current + * registration... + */ + + cupsdLogMessage(CUPSD_LOG_DEBUG2, + "send_ldap_ou: Replacing entry..."); + + for (i = 0; i < 3; i ++) + { + pmods[i] = mods + i; + pmods[i]->mod_op = LDAP_MOD_REPLACE; + } + pmods[i] = NULL; + + if ((rc = ldap_modify_s(BrowseLDAPHandle, dn, pmods)) != LDAP_SUCCESS) + { + cupsdLogMessage(CUPSD_LOG_ERROR, + "LDAP modify for %s failed with status %d: %s", + ou, rc, ldap_err2string(rc)); + if ( LDAP_SERVER_DOWN == rc ) + cupsdReconnectLDAP(); + } + } + else + { + /* + * Printer has never been registered, add the current + * registration... + */ + + cupsdLogMessage(CUPSD_LOG_DEBUG2, + "send_ldap_ou: Adding entry..."); + + for (i = 0; i < 3; i ++) + { + pmods[i] = mods + i; + pmods[i]->mod_op = LDAP_MOD_ADD; + } + pmods[i] = NULL; + + if ((rc = ldap_add_s(BrowseLDAPHandle, dn, pmods)) != LDAP_SUCCESS) + { + cupsdLogMessage(CUPSD_LOG_ERROR, + "LDAP add for %s failed with status %d: %s", + ou, rc, ldap_err2string(rc)); + if ( LDAP_SERVER_DOWN == rc ) + cupsdReconnectLDAP(); + } + } + } + + + /* * 'send_ldap_browse()' - Send LDAP printer registrations. */ *************** *** 2887,2893 **** mods[6].mod_type = "objectClass"; mods[6].mod_values = (char **)objectClass_values; ! snprintf(dn, sizeof(dn), "cn=%s,ou=printers,%s", p->name, BrowseLDAPDN); cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_ldap_browse: dn=\"%s\"", dn); if (ldap_count_entries(BrowseLDAPHandle, res) > 0) --- 3005,3011 ---- mods[6].mod_type = "objectClass"; mods[6].mod_values = (char **)objectClass_values; ! snprintf(dn, sizeof(dn), "cn=%s, ou=%s, %s", p->name, ServerName, BrowseLDAPDN); cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_ldap_browse: dn=\"%s\"", dn); if (ldap_count_entries(BrowseLDAPHandle, res) > 0) *************** *** 3022,3027 **** --- 3140,3147 ---- * Printer has never been registered, add the current * registration... */ + + send_ldap_ou(ServerName, BrowseLDAPDN, "CUPS Server"); cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_ldap_browse: Adding entry...");