]> andersk Git - moira.git/blobdiff - incremental/ldap/winad.c
Fix seg fault.
[moira.git] / incremental / ldap / winad.c
index 5aed44660c309d53d3e0397e2ad7cd5b647bb560..092ddd786a463f518b0ffd194ab092983020555f 100755 (executable)
@@ -366,6 +366,9 @@ CN=Services,CN=Configuration,"
 CN=Address Lists Container,CN=Massachusetts Institute of Technology,\
 CN=Microsoft Exchange,CN=Services,CN=Configuration,"
 
+#define X500_PREFIX "X500:/o=Massachusetts Institute of Technology/\
+ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients"
+
 #define ADD_ATTR(t, v, o)              \
   mods[n] = malloc(sizeof(LDAPMod));   \
   mods[n]->mod_op = o;                 \
@@ -757,7 +760,7 @@ int main(int argc, char **argv)
 
       if ((rc) || (ldap_handle == NULL))
        {
-         critical_alert("incremental",
+         critical_alert(whoami, "incremental",
                         "ldap.incr cannot connect to any server in "
                         "domain %s", DomainNames[k]);
          continue;
@@ -826,7 +829,7 @@ void do_mcntmap(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
   
   if (rc = moira_connect())
     {
-      critical_alert("Ldap incremental",
+      critical_alert(whoami, "Ldap incremental",
                     "Error contacting Moira server : %s",
                     error_message(rc));
       return;
@@ -918,7 +921,7 @@ void do_container(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
 
   if (rc = moira_connect())
     {
-      critical_alert("Ldap incremental", "Error contacting Moira server : %s",
+      critical_alert(whoami, "Ldap incremental", "Error contacting Moira server : %s",
                     error_message(rc));
       return;
     }
@@ -1156,7 +1159,7 @@ void do_list(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
 
       if (rc = moira_connect())
         {
-          critical_alert("Ldap incremental",
+          critical_alert(whoami, "Ldap incremental",
                          "Error contacting Moira server : %s",
                          error_message(rc));
           return;
@@ -1386,7 +1389,7 @@ void do_member(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
     {
       if (rc = moira_connect())
         {
-          critical_alert("Ldap incremental",
+          critical_alert(whoami, "Ldap incremental",
                          "Error contacting Moira server : %s",
                          error_message(rc));
           return;
@@ -1460,24 +1463,10 @@ void do_member(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
          if (Exchange) 
            {
              if((s = strchr(member, '@')) == (char *) NULL)
-               { 
-                 strcat(member, "@mit.edu");
-                 
-                 if (ptr[LM_MEMBER] != NULL)
-                   free(ptr[LM_MEMBER]);
-                 ptr[LM_MEMBER] = strdup(member);
-               }
+               return;
          
              if(!strncasecmp(&member[strlen(member) - 6], ".LOCAL", 6)) 
-               {
-                 s = strrchr(member, '.');
-                 *s = '\0';
-                 strcat(s, ".mit.edu");
-                 
-                 if (ptr[LM_MEMBER] != NULL)
-                   free(ptr[LM_MEMBER]);
-                 ptr[LM_MEMBER] = strdup(member);
-               }
+               return;
            }
 
          if (contact_create(ldap_handle, dn_path, ptr[LM_MEMBER], 
@@ -1496,7 +1485,7 @@ void do_member(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
        }
 
       if (rc = moira_connect()) {
-       critical_alert("Ldap incremental",
+       critical_alert(whoami, "Ldap incremental",
                       "Error contacting Moira server : %s",
                       error_message(rc));              
        return;
@@ -1545,24 +1534,10 @@ void do_member(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
       if (Exchange) 
        {
          if((s = strchr(member, '@')) == (char *) NULL)
-           { 
-             strcat(member, "@mit.edu");
-             
-             if (ptr[LM_MEMBER] != NULL)
-               free(ptr[LM_MEMBER]);
-             ptr[LM_MEMBER] = strdup(member);
-           }
+           return;
          
          if(!strncasecmp(&member[strlen(member) - 6], ".LOCAL", 6)) 
-           {
-             s = strrchr(member, '.');
-             *s = '\0';
-             strcat(s, ".mit.edu");
-             
-             if (ptr[LM_MEMBER] != NULL)
-               free(ptr[LM_MEMBER]);
-             ptr[LM_MEMBER] = strdup(member);
-           }
+           return;
        }
       
       if (contact_create(ldap_handle, dn_path, ptr[LM_MEMBER], 
@@ -1586,7 +1561,7 @@ void do_member(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
         {
           if (rc = moira_connect())
             {
-              critical_alert("Ldap incremental", 
+              critical_alert(whoami, "Ldap incremental", 
                              "Error connection to Moira : %s",
                              error_message(rc));
               return;
@@ -1662,7 +1637,7 @@ void do_member(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
     }
 
   if (rc = moira_connect()) {
-    critical_alert("Ldap incremental",
+    critical_alert(whoami, "Ldap incremental",
                   "Error contacting Moira server : %s",
                   error_message(rc));              
     return;
@@ -1758,7 +1733,7 @@ void do_user(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
 
       if (rc = moira_connect())
         {
-          critical_alert("Ldap incremental", 
+          critical_alert(whoami, "Ldap incremental", 
                          "Error connection to Moira : %s",
                          error_message(rc));
           return;
@@ -2266,7 +2241,7 @@ int check_winad(void)
     {
       if (i > 30)
         {
-          critical_alert("Ldap incremental",
+          critical_alert(whoami, "Ldap incremental",
                          "Ldap incremental failed (%s exists): %s",
                          STOP_FILE, tbl_buf);
           return(1);
@@ -3492,16 +3467,10 @@ int member_list_build(int ac, char **av, void *ptr)
       if (Exchange)
        {
          if((s = strchr(temp, '@')) == (char *) NULL) 
-           {
-             strcat(temp, "@mit.edu");
-           }
+           return(0);
          
          if(!strncasecmp(&temp[strlen(temp) - 6], ".LOCAL", 6))
-           {
-             s = strrchr(temp, '.');
-             *s = '\0';
-             strcat(s, ".mit.edu");
-           }
+           return(0);
        }
 
       if (!((int)call_args[3] & MOIRA_STRINGS))
@@ -3649,7 +3618,8 @@ int member_remove(LDAP *ldap_handle, char *dn_path, char *group_name,
       if (Exchange)
        {
          if(!strcmp(UserOu, contact_ou) && 
-            ((s = strstr(user_name, "@mit.edu")) != (char *) NULL))
+            ((s = strstr(user_name, 
+                         "@exchange-forwarding.mit.edu")) != (char *) NULL))
            {
              memset(temp, '\0', sizeof(temp));
              strcpy(temp, user_name);
@@ -3945,6 +3915,9 @@ int contact_create(LDAP *ld, char *bind_path, char *user, char *group_ou)
 
   if (Exchange)
     {
+      if((s = strstr(mail, "@mit.edu")) != (char *) NULL)
+       return(rc);
+
       if (!strcmp(group_ou, contact_ou) && email_isvalid(mail))
        {
          group_count = 0;
@@ -4017,7 +3990,7 @@ int contact_create(LDAP *ld, char *bind_path, char *user, char *group_ou)
                      user);
              return(1);
            }
-
+       
          linklist_free(group_base);
          group_base = NULL;
          group_count = 0;
@@ -4046,6 +4019,50 @@ int contact_create(LDAP *ld, char *bind_path, char *user, char *group_ou)
          group_base = NULL;
          group_count = 0;
 
+         sprintf(filter, "(&(objectClass=user)(proxyAddresses=smtp:%s))", mail);
+         attr_array[0] = "cn";
+         attr_array[1] = NULL;
+
+         if ((rc = linklist_build(ld, bind_path, filter, attr_array,
+                                  &group_base, &group_count, 
+                                  LDAP_SCOPE_SUBTREE)) != 0) 
+           {
+             com_err(whoami, 0, "Unable to process contact %s : %s", 
+                     user, ldap_err2string(rc));
+             return(rc);
+           }
+      
+         if (group_count) 
+           {
+             com_err(whoami, 0, "Object already exists with name %s",
+                     user);
+             return(1);
+           }
+
+         linklist_free(group_base);
+         group_base = NULL;
+         group_count = 0;
+
+         sprintf(filter, "(&(objectClass=group)(proxyAddresses=smtp:%s))", mail);
+         attr_array[0] = "cn";
+         attr_array[1] = NULL;
+
+         if ((rc = linklist_build(ld, bind_path, filter, attr_array,
+                                  &group_base, &group_count, 
+                                  LDAP_SCOPE_SUBTREE)) != 0) 
+           {
+             com_err(whoami, 0, "Unable to process contact %s : %s", 
+                     user, ldap_err2string(rc));
+             return(rc);
+           }
+      
+         if (group_count) 
+           {
+             com_err(whoami, 0, "Object already exists with name %s",
+                     user);
+             return(1);
+           }
+
          ADD_ATTR("mail", email_v, LDAP_MOD_ADD);
          ADD_ATTR("mailNickName", mail_nickname_v, LDAP_MOD_ADD);
          ADD_ATTR("proxyAddresses", proxy_address_external_v, LDAP_MOD_ADD);
@@ -4287,7 +4304,7 @@ int user_update(LDAP *ldap_handle, char *dn_path, char *user_name,
     {
       if (rc = moira_connect())
        {
-         critical_alert("Ldap incremental", 
+         critical_alert(whoami, "Ldap incremental", 
                         "Error contacting Moira server : %s",
                         error_message(rc));
          return;
@@ -4630,7 +4647,7 @@ int user_update(LDAP *ldap_handle, char *dn_path, char *user_name,
     {
       if (rc = moira_connect())
        {
-         critical_alert("Ldap incremental", 
+         critical_alert(whoami, "Ldap incremental", 
                         "Error contacting Moira server : %s",
                         error_message(rc));
          return;
@@ -4814,6 +4831,8 @@ int user_rename(LDAP *ldap_handle, char *dn_path, char *before_user_name,
   char mail[256];
   char contact_mail[256];
   char proxy_address[256];
+  char proxy_address_mit[256];
+  char proxy_address_x500[256];
   char query_base_dn[256];
   char temp[256];
   char *userPrincipalName_v[] = {NULL, NULL};
@@ -4822,7 +4841,7 @@ int user_rename(LDAP *ldap_handle, char *dn_path, char *before_user_name,
   char *samAccountName_v[] = {NULL, NULL};
   char *mail_v[] = {NULL, NULL};
   char *mail_nickname_v[] = {NULL, NULL};
-  char *proxy_address_v[] = {NULL, NULL};
+  char *proxy_address_v[] = {NULL, NULL, NULL, NULL};
   char *query_base_dn_v[] = {NULL, NULL};
   char *principal_v[] = {NULL, NULL};
   char principal[256];
@@ -4857,8 +4876,14 @@ int user_rename(LDAP *ldap_handle, char *dn_path, char *before_user_name,
     sprintf(new_dn, "uid=%s", user_name);
 
   sprintf(mail, "%s@%s", user_name, lowercase(ldap_domain));
-  sprintf(contact_mail, "%s@mit.edu", user_name);
-  sprintf(proxy_address, "SMTP:%s@%s", user_name, lowercase(ldap_domain)); 
+  if(Exchange)
+    sprintf(contact_mail, "%s@exchange-forwarding.mit.edu", user_name);
+  else
+    sprintf(contact_mail, "%s@mit.edu", user_name);
+  sprintf(proxy_address, "smtp:%s@%s", user_name, lowercase(ldap_domain));
+  sprintf(proxy_address_mit, "SMTP:%s@mit.edu", user_name);
+  sprintf(proxy_address_x500, "%s/cn=%s?mit.edu", X500_PREFIX, user_name);
+  
   sprintf(principal, "%s@%s", user_name, PRIMARY_REALM);
 
   if ((rc = ldap_rename_s(ldap_handle, old_dn, new_dn, NULL, TRUE, 
@@ -4871,8 +4896,8 @@ int user_rename(LDAP *ldap_handle, char *dn_path, char *before_user_name,
 
   if (Exchange)
     {
-      sprintf(temp, "cn=%s@mit.edu,%s,%s", before_user_name, contact_ou
-             dn_path);
+      sprintf(temp, "cn=%s@exchange-forwarding.mit.edu,%s,%s", before_user_name
+             contact_ou, dn_path);
 
       if(rc = ldap_delete_s(ldap_handle, temp))
        {
@@ -4896,7 +4921,8 @@ int user_rename(LDAP *ldap_handle, char *dn_path, char *before_user_name,
   samAccountName_v[0] = user_name;
   mail_v[0] = mail;
   mail_nickname_v[0] = user_name;
-  proxy_address_v[0] = proxy_address; 
+  proxy_address_v[0] = proxy_address_mit; 
+  proxy_address_v[1] = proxy_address;
   query_base_dn_v[0] = query_base_dn;
 
   n = 0;
@@ -4918,7 +4944,7 @@ int user_rename(LDAP *ldap_handle, char *dn_path, char *before_user_name,
       ADD_ATTR("msExchQueryBaseDN", query_base_dn_v, LDAP_MOD_REPLACE);
       ADD_ATTR("mailNickName", mail_nickname_v, LDAP_MOD_REPLACE); 
       ADD_ATTR("mail", mail_v, LDAP_MOD_REPLACE); 
-      ADD_ATTR("proxyAddresses", proxy_address_v, LDAP_MOD_REPLACE);
+      ADD_ATTR("proxyAddresses", proxy_address_v, LDAP_MOD_REPLACE); 
     }
   else
     {
@@ -5098,39 +5124,11 @@ int user_create(int ac, char **av, void *ptr)
   }
 
   samAccountName_v[0] = sam_name;
+
   if ((atoi(av[U_STATE]) != US_NO_PASSWD) && 
       (atoi(av[U_STATE]) != US_REGISTERED))
     {
       userAccountControl |= UF_ACCOUNTDISABLE;
-
-      if (Exchange)
-       {
-         hide_address_lists_v[0] = "TRUE";
-
-         ADD_ATTR("msExchHideFromAddressLists", hide_address_lists_v,
-                  LDAP_MOD_ADD);
-
-         /*
-         sprintf(address_book, "%s%s", GLOBAL_ADDRESS_LIST_PREFIX, 
-                 call_args[1]);
-         address_book_v[0] = strdup(address_book);
-         memset(address_book, '\0', sizeof(address_book));
-         sprintf(address_book, "%s%s", ADDRESS_LIST_PREFIX, call_args[1]);
-         address_book_v[1] = strdup(address_book);
-         memset(address_book, '\0', sizeof(address_book));
-         sprintf(address_book, "%s%s", EMAIL_ADDRESS_LIST_PREFIX, 
-                 call_args[1]);
-         address_book_v[2] = strdup(address_book);
-         memset(address_book, '\0', sizeof(address_book));
-         sprintf(address_book, "%s%s", ALL_ADDRESS_LIST_PREFIX, 
-                 call_args[1]);
-         address_book_v[3] = strdup(address_book);
-         memset(address_book, '\0', sizeof(address_book));
-         
-         ADD_ATTR("showInAddressBook", address_book_v,
-                  LDAP_MOD_ADD);
-         */
-       }
     }
 
   sprintf(userAccountControlStr, "%ld", userAccountControl);
@@ -5224,6 +5222,20 @@ int user_create(int ac, char **av, void *ptr)
 
   if (Exchange)
     {
+      if ((atoi(av[U_STATE]) != US_NO_PASSWD) &&
+         (atoi(av[U_STATE]) != US_REGISTERED))
+       {
+         hide_address_lists_v[0] = "TRUE";
+          ADD_ATTR("msExchHideFromAddressLists", hide_address_lists_v,
+                   LDAP_MOD_ADD);
+       } 
+      else 
+       {
+          hide_address_lists_v[0] = "FALSE";
+          ADD_ATTR("msExchHideFromAddressLists", hide_address_lists_v,
+                   LDAP_MOD_ADD);
+       }
+
       ADD_ATTR("msExchQueryBaseDN", query_base_dn_v, LDAP_MOD_ADD);
       ADD_ATTR("mailNickName", mail_nickname_v, LDAP_MOD_ADD);
       ADD_ATTR("homeMDB", homeMDB_v, LDAP_MOD_ADD);
@@ -5476,7 +5488,7 @@ int user_create(int ac, char **av, void *ptr)
     {
       if (rc = moira_connect())
        {
-         critical_alert("Ldap incremental", 
+         critical_alert(whoami, "Ldap incremental", 
                         "Error contacting Moira server : %s",
                         error_message(rc));
          return;
@@ -5822,10 +5834,11 @@ int user_delete(LDAP *ldap_handle, char *dn_path,
     }
 
   /* Need to add code to delete mit.edu contact */
-  
+
   if (Exchange)
     {
-      sprintf(temp, "cn=%s@mit.edu,%s,%s", user_name, contact_ou, dn_path);
+      sprintf(temp, "cn=%s@exchange-forwarding.mit.edu,%s,%s", user_name, 
+             contact_ou, dn_path);
 
       if(rc = ldap_delete_s(ldap_handle, temp))
        {
@@ -8445,7 +8458,7 @@ int SetHomeDirectory(LDAP *ldap_handle, char *user_name,
     {
       if (rc = moira_connect())
        {
-          critical_alert("Ldap incremental",
+          critical_alert(whoami, "Ldap incremental",
                         "Error contacting Moira server : %s",
                         error_message(rc));
          return;
@@ -8516,7 +8529,7 @@ int SetHomeDirectory(LDAP *ldap_handle, char *user_name,
     {
       if (rc = moira_connect())
        {
-          critical_alert("Ldap incremental",
+          critical_alert(whoami, "Ldap incremental",
                         "Error contacting Moira server : %s",
                         error_message(rc));
          return;
@@ -9038,7 +9051,7 @@ int ReadDomainList()
 
   if (Count == 0)
     {
-      critical_alert("incremental", "%s", "ldap.incr cannot run due to a "
+      critical_alert(whoami, "incremental", "%s", "ldap.incr cannot run due to a "
                     "configuration error in ldap.cfg");
       return(1);
     }
This page took 0.062528 seconds and 4 git commands to generate.