2007-08-21 [colin] 2.10.0cvs142
[claws.git] / src / ldapupdate.c
index f3a85d4c8d4f94ad45fd5b79fd75b93cd2419a28..d8425c67c357ab7cea127572e5d6dcc8b0b5e99c 100644 (file)
@@ -4,7 +4,7 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 /*
@@ -341,7 +341,7 @@ LDAP *ldapsvr_connect(LdapControl *ctl) {
                        rc = ldap_start_tls_s(ld, NULL, NULL);
                        
                        if (rc != LDAP_SUCCESS) {
-                               fprintf(stderr, "LDAP Error(tls): ldap_simple_bind_s: %s\n",
+                               g_printerr("LDAP Error(tls): ldap_simple_bind_s: %s\n",
                                        ldap_err2string(rc));
                                return NULL;
                        }
@@ -354,8 +354,8 @@ LDAP *ldapsvr_connect(LdapControl *ctl) {
                if (* ctl->bindDN != '\0') {
                        rc = claws_ldap_simple_bind_s(ld, ctl->bindDN, ctl->bindPass);
                        if (rc != LDAP_SUCCESS) {
-                               fprintf(stderr, "bindDN: %s, bindPass: %s\n", ctl->bindDN, ctl->bindPass);
-                               fprintf(stderr, "LDAP Error(bind): ldap_simple_bind_s: %s\n",
+                               g_printerr("bindDN: %s, bindPass: %s\n", ctl->bindDN, ctl->bindPass);
+                               g_printerr("LDAP Error(bind): ldap_simple_bind_s: %s\n",
                                        ldap_err2string(rc));
                                return NULL;
                        }
@@ -673,7 +673,7 @@ void ldapsvr_print_ldapmod(LDAPMod *mods[]) {
        int i;
 
        g_return_if_fail(mods != NULL);
-       fprintf( stderr, "Type\n");
+       g_printerr( "Type\n");
        for (i = 0; NULL != mods[i]; i++) {
                LDAPMod *mod = (LDAPMod *) mods[i];
                gchar **vals;
@@ -683,10 +683,10 @@ void ldapsvr_print_ldapmod(LDAPMod *mods[]) {
                        case LDAP_MOD_DELETE: mod_op = g_strdup("DELETE"); break;
                        default: mod_op = g_strdup("UNKNOWN");
                }
-               fprintf( stderr, "Operation: %s\tType:%s\nValues:\n", mod_op, mod->mod_type);
+               g_printerr( "Operation: %s\tType:%s\nValues:\n", mod_op, mod->mod_type);
                vals = mod->mod_vals.modv_strvals;
                while (*vals) {
-                       fprintf( stderr, "\t%s\n", *vals++);
+                       g_printerr( "\t%s\n", *vals++);
                }
        }
 }
@@ -710,7 +710,7 @@ void ldapsvr_compare_attr(LDAP *ld, gchar *dn, gint cnt, LDAPMod *mods[]) {
                if (!value || strcmp(value, "") == 0)
                        value = g_strdup("thisisonlyadummy");
                rc = ldap_compare_s(ld, dn, mods[i]->mod_type, value);
-               fprintf(stderr, "ldap_compare for (%s:%s)\" failed[0x%x]: %s\n",
+               g_printerr("ldap_compare for (%s:%s)\" failed[0x%x]: %s\n",
                mods[i]->mod_type, value, rc, ldap_err2string(rc));
                g_free(value);
        }
@@ -734,7 +734,7 @@ int ldapsvr_compare_manual_attr(LDAP *ld, LdapServer *server, gchar *dn, char *a
        LdapControl *ctl;
        gchar *filter;
        gchar *attribute;
-       int retVal, i;
+       int retVal = -2, i;
        AttrKeyValue *mail;
 
        g_return_val_if_fail(ld != NULL || server != NULL || attr != NULL, -1);
@@ -747,7 +747,7 @@ int ldapsvr_compare_manual_attr(LDAP *ld, LdapServer *server, gchar *dn, char *a
        if (ctl) {
                rc = ldap_search_s(ld, ctl->baseDN, /*LDAP_SCOPE_SUBTREE*/LDAP_SCOPE_ONELEVEL, filter, NULL, 0, &res);
                if (rc) {
-                       fprintf(stderr, "ldap_search for attr=%s\" failed[0x%x]: %s\n",attr, rc, ldap_err2string(rc));
+                       g_printerr("ldap_search for attr=%s\" failed[0x%x]: %s\n",attr, rc, ldap_err2string(rc));
                        retVal = -2;
                }
                else {
@@ -869,16 +869,18 @@ gboolean ldapsvr_check_search_attributes(char **list, char *attr) {
  */
 void ldapsvr_handle_other_attributes(LDAP *ld, LdapServer *server, char *dn, GHashTable *contact) {
        GList *node;
-       gboolean CHECKED_ATTRIBUTE[ATTRIBUTE_SIZE];
+       gboolean CHECKED_ATTRIBUTE[ATTRIBUTE_SIZE + 1];
        LDAPMod *mods[ATTRIBUTE_SIZE + 1];
        LDAPMod modarr[ATTRIBUTE_SIZE];
        gint cnt = 0;
-       char *attr[] = {NULL, NULL};
+       char *attr[ATTRIBUTE_SIZE + 1][2];
        int mod_op, rc, i;
 
        g_return_if_fail(server != NULL || dn != NULL || contact != NULL);
-       for (i = 0; i < ATTRIBUTE_SIZE; i++)
+       for (i = 0; i <= ATTRIBUTE_SIZE; i++) {
                CHECKED_ATTRIBUTE[i] = FALSE;
+               attr[i][0] = attr[i][1] = NULL;
+       }
        node = g_hash_table_lookup(contact , "attribute");
        while (node) {
                AttrKeyValue *item = node->data;
@@ -920,7 +922,7 @@ void ldapsvr_handle_other_attributes(LDAP *ld, LdapServer *server, char *dn, GHa
                                        */
                                }
                                else {
-                                       SETMOD(mods[cnt], modarr[cnt], mod_op, g_strdup(item->key), attr, g_strdup(item->value));
+                                       SETMOD(mods[cnt], modarr[cnt], mod_op, g_strdup(item->key), attr[cnt], g_strdup(item->value));
                                        cnt++;
                                        CHECKED_ATTRIBUTE[index] = TRUE;
                                }
@@ -928,7 +930,7 @@ void ldapsvr_handle_other_attributes(LDAP *ld, LdapServer *server, char *dn, GHa
                }
                node = g_list_next(node);
        }
-       char **attribs = ldapctl_attribute_array(server->control);
+       char **attribs = ldapctl_full_attribute_array(server->control);
        for (i = 0; i < ATTRIBUTE_SIZE; i++) {
                /* Attributes which holds no information are to be removed */
                if (CHECKED_ATTRIBUTE[i] == FALSE) {
@@ -939,7 +941,7 @@ void ldapsvr_handle_other_attributes(LDAP *ld, LdapServer *server, char *dn, GHa
                        if (ldapsvr_check_search_attributes(attribs, (char *) ATTRIBUTE[i])) {
                                mod_op = ldapsvr_deside_operation(ld, server, dn, (char *) ATTRIBUTE[i], "");
                                if (mod_op == LDAP_MOD_DELETE) {
-                                       SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_DELETE, g_strdup((char *) ATTRIBUTE[i]), attr, NULL);
+                                       SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_DELETE, g_strdup((char *) ATTRIBUTE[i]), attr[cnt], NULL);
                                        cnt++;
                                }
                        }
@@ -957,7 +959,7 @@ void ldapsvr_handle_other_attributes(LDAP *ld, LdapServer *server, char *dn, GHa
                                server->retVal = LDAPRC_ALREADY_EXIST;
                                break;
                        default:
-                               fprintf(stderr, "ldap_modify for dn=%s\" failed[0x%x]: %s\n",dn, rc, ldap_err2string(rc));
+                               g_printerr("ldap_modify for dn=%s\" failed[0x%x]: %s\n",dn, rc, ldap_err2string(rc));
                                if (rc == 0x8)
                                        server->retVal = LDAPRC_STRONG_AUTH;
                                else
@@ -965,11 +967,7 @@ void ldapsvr_handle_other_attributes(LDAP *ld, LdapServer *server, char *dn, GHa
                }
        }
        else {
-               /* Only consider those attributes which is currently part of the search criteria.
-                * If attributes are not part of the search criteria they would seem to hold
-                * no information since their values will not be populated in the GUI
-                */
-               char **attribs = ldapctl_attribute_array(server->control);
+               char **attribs = ldapctl_full_attribute_array(server->control);
                for (i = 0; i < ATTRIBUTE_SIZE; i++) {
                        if (ldapsvr_check_search_attributes(attribs, (char *) ATTRIBUTE[i])) {
                                if (CHECKED_ATTRIBUTE[i] == FALSE) {
@@ -1098,7 +1096,7 @@ void ldapsvr_add_contact(LdapServer *server, GHashTable *contact) {
                                server->retVal = LDAPRC_ALREADY_EXIST;
                                break;
                        default:
-                               fprintf(stderr, "ldap_modify for dn=%s\" failed[0x%x]: %s\n",base_dn, rc, ldap_err2string(rc));
+                               g_printerr("ldap_modify for dn=%s\" failed[0x%x]: %s\n",base_dn, rc, ldap_err2string(rc));
                                if (rc == 0x8)
                                        server->retVal = LDAPRC_STRONG_AUTH;
                                else
@@ -1157,9 +1155,9 @@ void ldapsvr_update_contact(LdapServer *server, GHashTable *contact) {
                                 */
                        }
                        else {
-                               fprintf(stderr, "Current dn: %s\n", dn);
-                               fprintf(stderr, "new dn: %s\n", newRdn);
-                               fprintf(stderr, "LDAP Error(ldap_modrdn2_s) failed[0x%x]: %s\n", rc, ldap_err2string(rc));
+                               g_printerr("Current dn: %s\n", dn);
+                               g_printerr("new dn: %s\n", newRdn);
+                               g_printerr("LDAP Error(ldap_modrdn2_s) failed[0x%x]: %s\n", rc, ldap_err2string(rc));
                                g_free(newRdn);
                                clean_up(ld, server, contact);
                                return;
@@ -1308,7 +1306,7 @@ void ldapsvr_update_contact(LdapServer *server, GHashTable *contact) {
                mods[cnt] = NULL;
                rc = ldap_modify_ext_s(ld, dn, mods, NULL, NULL);
                if (rc) {
-                       fprintf(stderr, "ldap_modify for dn=%s\" failed[0x%x]: %s\n",
+                       g_printerr("ldap_modify for dn=%s\" failed[0x%x]: %s\n",
                     dn, rc, ldap_err2string(rc));
                        server->retVal = LDAPRC_NAMING_VIOLATION;
                }
@@ -1349,7 +1347,7 @@ void ldapsvr_delete_contact(LdapServer *server, GHashTable *contact) {
        server->retVal = LDAPRC_SUCCESS;
        rc = ldap_delete_ext_s(ld, dn, NULL, NULL);
        if (rc) {
-               fprintf(stderr, "ldap_modify for dn=%s\" failed[0x%x]: %s\n",
+               g_printerr("ldap_modify for dn=%s\" failed[0x%x]: %s\n",
                                dn, rc, ldap_err2string(rc));
                server->retVal = LDAPRC_NODN;
        }
@@ -1413,7 +1411,7 @@ void ldapsvr_update_book(LdapServer *server, ItemPerson *item) {
                                        }
                                }
                                else {
-                                       fprintf(stderr, "\t\tpid : ???\n");
+                                       g_printerr("\t\tpid : ???\n");
                                }
                                node = g_list_next(node);
                        }