]> jfr.im git - irc/evilnet/x3.git/commitdiff
Fixed LDAP support to register an account with X3 if a user is authed to that account...
authorMatthew Beeching <redacted>
Mon, 3 Jun 2013 19:28:17 +0000 (20:28 +0100)
committerMatthew Beeching <redacted>
Mon, 3 Jun 2013 19:28:17 +0000 (20:28 +0100)
src/nickserv.c
src/x3ldap.c
src/x3ldap.h

index 7b446a33762d6cdc27f9e3eb656048b84aeb7da4..7566dea4856e15f63f37b637f42ca155e402df39 100644 (file)
@@ -1135,7 +1135,7 @@ nickserv_register(struct userNode *user, struct userNode *settee, const char *ha
 {
     struct handle_info *hi;
     struct nick_info *ni;
-    char crypted[MD5_CRYPT_LENGTH];
+    char crypted[MD5_CRYPT_LENGTH] = "";
 
     if ((hi = dict_find(nickserv_handle_dict, handle, NULL))) {
         if(user)
@@ -1150,14 +1150,17 @@ nickserv_register(struct userNode *user, struct userNode *settee, const char *ha
         return 0;
     }
 
-    if (!is_secure_password(handle, passwd, user))
-        return 0;
+    if (passwd)
+    {
+        if (!is_secure_password(handle, passwd, user))
+            return 0;
 
-    cryptpass(passwd, crypted);
+        cryptpass(passwd, crypted);
+    }
 #ifdef WITH_LDAP
     if(nickserv_conf.ldap_enable && nickserv_conf.ldap_admin_dn) {
         int rc;
-        rc = ldap_do_add(handle, (no_auth ? NULL : crypted), NULL);
+        rc = ldap_do_add(handle, (no_auth || !passwd ? NULL : crypted), NULL);
         if(LDAP_SUCCESS != rc && LDAP_ALREADY_EXISTS != rc ) {
            if(user)
              send_message(user, nickserv, "NSMSG_LDAP_FAIL", ldap_err2string(rc));
@@ -5428,6 +5431,39 @@ ctime(&hi->registered));
     log_module(MAIN_LOG, LOG_WARNING, "Using non-P10 code in accounts, not tested at all!");
 #endif
 
+#ifdef WITH_LDAP
+    if(!hi && nickserv_conf.ldap_enable && nickserv_conf.ldap_autocreate &&
+       (ldap_user_exists(stamp) == LDAP_SUCCESS)) {
+        int rc = 0;
+        int cont = 1;
+        char *email = NULL;
+        char *mask;
+
+        /* First attempt to get the email address from LDAP */
+        if((rc = ldap_get_user_info(stamp, &email) != LDAP_SUCCESS))
+            if(nickserv_conf.email_required)
+                cont = 0;
+
+        /* Now try to register the handle */
+        if (cont && (hi = nickserv_register(user, user, stamp, NULL, 1))) {
+            if(nickserv_conf.default_hostmask)
+                mask = "*@*";
+            else
+                mask = generate_hostmask(user, GENMASK_OMITNICK|GENMASK_NO_HIDING|GENMASK_ANY_IDENT);
+
+            if(mask) {
+                char* mask_canonicalized = canonicalize_hostmask(strdup(mask));
+                string_list_append(hi->masks, mask_canonicalized);
+            }
+
+            if(email) {
+                nickserv_set_email_addr(hi, email);
+                free(email);
+            }
+        }
+    }
+#endif
+
     if (hi) {
         if (HANDLE_FLAGGED(hi, SUSPENDED)) {
             return;
index 1739e67effb0b9e882d593329802c1e463f116be..f707aefa281a917dca05eb94c163c022f76180e7 100644 (file)
@@ -126,7 +126,7 @@ unsigned int ldap_check_auth( const char *account, const char *pass)
 
 }
 
-int ldap_search_user(char *account, LDAPMessage **entry)
+int ldap_search_user(const char *account, LDAPMessage **entry)
 {
 
    char filter[MAXLEN+1];
@@ -726,4 +726,19 @@ void ldap_close()
    ldap_unbind_ext(ld, NULL, NULL);
 }
 
+/* queries the ldap server for account..
+ * returns LDAP_SUCCESS if a match is found
+ * returns LDAP_OTHER if no match is found
+ * on error returns the proper ldap error
+ */
+int ldap_user_exists(const char *account)
+{
+  int rc;
+  LDAPMessage *res;
+
+  rc = ldap_search_user(account, &res);
+
+  return rc;
+}
+
 #endif
index 6d1bb27a712877fe203f7ab9d2981122a6d6e41a..56afe89c3c60dd5c7420f2553ea18090b391c2ed 100644 (file)
@@ -33,7 +33,7 @@ int ldap_do_modify(const char *account, const char *password, const char *email)
 int ldap_get_user_info(const char *account, char **email);
 int ldap_delfromgroup(char *account, const char *group);
 int ldap_add2group(char *account, const char *group);
-
+int ldap_user_exists(const char *account);
 
 void ldap_close();