+ mods[mod]->mod_op = LDAP_MOD_ADD;
+ mods[mod]->mod_type = strdup("objectclass");
+ mods[mod]->mod_values = object_vals;
+ mod++;
+
+ mods[mod]->mod_op = LDAP_MOD_ADD;
+ mods[mod]->mod_type = strdup(nickserv_conf.ldap_field_account);
+ mods[mod]->mod_values = account_vals;
+ mod++;
+
+ if (password != NULL) {
+ mods[mod]->mod_op = LDAP_MOD_ADD;
+ mods[mod]->mod_type = strdup(nickserv_conf.ldap_field_password);
+ mods[mod]->mod_values = password_vals;
+ mod++;
+ }
+
+ if(nickserv_conf.ldap_field_email && *nickserv_conf.ldap_field_email && email && *email) {
+ mods[mod]->mod_op = LDAP_MOD_ADD;
+ mods[mod]->mod_type = strdup(nickserv_conf.ldap_field_email);
+ mods[mod]->mod_values = email_vals;
+ mod++;
+ }
+ mods[mod] = NULL;
+ *num_mods_ret = num_mods;
+ return mods;
+}
+
+int ldap_do_add(const char *account, const char *crypted, const char *email)
+{
+ char newdn[MAXLEN];
+ LDAPMod **mods;
+ int rc, i;
+ int num_mods;
+ char *passbuf = NULL;
+
+ if(!admin_bind && LDAP_SUCCESS != ( rc = ldap_do_admin_bind())) {
+ log_module(MAIN_LOG, LOG_ERROR, "failed to bind as admin");
+ return rc;
+ }
+
+ if (crypted != NULL)
+ passbuf = make_password(crypted);
+ snprintf(newdn, MAXLEN-1, nickserv_conf.ldap_dn_fmt, account);
+ mods = make_mods_add(account, (crypted != NULL ? passbuf : crypted), email, &num_mods);
+ if(!mods) {
+ log_module(MAIN_LOG, LOG_ERROR, "Error building mods for ldap_add");
+ return LDAP_OTHER;
+ }
+ rc = ldap_add_ext_s(ld, newdn, mods, NULL, NULL);
+ if(rc != LDAP_SUCCESS && rc!= LDAP_ALREADY_EXISTS) {
+ log_module(MAIN_LOG, LOG_ERROR, "Error adding ldap account: %s -- %s", account, ldap_err2string(rc));
+ // return rc;
+ }
+ //ldap_unbind_s(ld);
+ for(i = 0; i < num_mods; i++) {
+ free(mods[i]->mod_type);
+ free(mods[i]);
+ }
+ free(mods);
+ if (crypted != NULL)
+ free(passbuf);
+ return rc;
+}
+
+int ldap_delete_account(char *account)
+{
+ char dn[MAXLEN];
+ int rc;
+
+ if(!admin_bind && LDAP_SUCCESS != ( rc = ldap_do_admin_bind())) {
+ log_module(MAIN_LOG, LOG_ERROR, "failed to bind as admin");
+ return rc;
+ }
+
+ memset(dn, 0, MAXLEN);
+ snprintf(dn, MAXLEN-1, nickserv_conf.ldap_dn_fmt, account);
+ return(ldap_delete_s(ld, dn));
+}
+
+int ldap_rename_account(char *oldaccount, char *newaccount)
+{
+ char dn[MAXLEN], newdn[MAXLEN];
+ int rc;
+
+ if(!admin_bind && LDAP_SUCCESS != ( rc = ldap_do_admin_bind())) {
+ log_module(MAIN_LOG, LOG_ERROR, "failed to bind as admin");
+ return rc;
+ }
+
+ memset(dn, 0, MAXLEN);