]> andersk Git - moira.git/blobdiff - incremental/ldap/winad.c
Update illegal characters and log something when one is found.
[moira.git] / incremental / ldap / winad.c
index cfe818cb0f847a129de2f737c15e204d51ab19c0..e333ef31094f1ffd92fc5503d3af64ea786ba33c 100755 (executable)
@@ -804,7 +804,7 @@ void do_mcntmap(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
   
   if (rc = moira_connect())
     {
-      critical_alert("AD incremental",
+      critical_alert("Ldap incremental",
                     "Error contacting Moira server : %s",
                     error_message(rc));
       return;
@@ -848,7 +848,7 @@ void do_mcntmap(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
 
   if (machine_check(ldap_handle, dn_path, MachineName))
     {
-      com_err(whoami, 0, "Unable to find machine %s (alias %s) in AD.", 
+      com_err(whoami, 0, "Unable to find machine %s (alias %s) in directory.", 
              OriginalMachineName, MachineName);
       moira_disconnect();
       return;
@@ -896,7 +896,7 @@ void do_container(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
 
   if (rc = moira_connect())
     {
-      critical_alert("AD incremental", "Error contacting Moira server : %s",
+      critical_alert("Ldap incremental", "Error contacting Moira server : %s",
                     error_message(rc));
       return;
     }
@@ -1130,7 +1130,7 @@ void do_list(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
 
       if (rc = moira_connect())
         {
-          critical_alert("AD incremental",
+          critical_alert("Ldap incremental",
                          "Error contacting Moira server : %s",
                          error_message(rc));
           return;
@@ -1356,7 +1356,7 @@ void do_member(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
     {
       if (rc = moira_connect())
         {
-          critical_alert("AD incremental",
+          critical_alert("Ldap incremental",
                          "Error contacting Moira server : %s",
                          error_message(rc));
           return;
@@ -1464,7 +1464,7 @@ void do_member(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
        }
 
       if (rc = moira_connect()) {
-       critical_alert("AD incremental",
+       critical_alert("Ldap incremental",
                       "Error contacting Moira server : %s",
                       error_message(rc));              
        return;
@@ -1482,7 +1482,7 @@ void do_member(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
        {
          if (rc = moira_connect())
            {
-             critical_alert("AD incremental",
+             critical_alert("Ldap incremental",
                             "Error contacting Moira server : %s",
                             error_message(rc));
              return;
@@ -1565,7 +1565,7 @@ void do_member(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
         {
           if (rc = moira_connect())
             {
-              critical_alert("AD incremental", 
+              critical_alert("Ldap incremental", 
                              "Error connection to Moira : %s",
                              error_message(rc));
               return;
@@ -1641,7 +1641,7 @@ void do_member(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
     }
 
   if (rc = moira_connect()) {
-    critical_alert("AD incremental",
+    critical_alert("Ldap incremental",
                   "Error contacting Moira server : %s",
                   error_message(rc));              
     return;
@@ -1659,7 +1659,7 @@ void do_member(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
     {
       if (rc = moira_connect())
        {
-         critical_alert("AD incremental",
+         critical_alert("Ldap incremental",
                         "Error contacting Moira server : %s",
                         error_message(rc));
          return;
@@ -1728,7 +1728,8 @@ void do_user(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
     {                                 
       if (atoi(before[U_STATE]) == 0)
         {
-          com_err(whoami, 0, "expunging user %s from AD", before[U_NAME]);
+          com_err(whoami, 0, "expunging user %s from directory", 
+                 before[U_NAME]);
           user_delete(ldap_handle, dn_path, before[U_NAME], before_user_id);
         }
       else
@@ -1749,7 +1750,7 @@ void do_user(LDAP *ldap_handle, char *dn_path, char *ldap_hostname,
 
       if (rc = moira_connect())
         {
-          critical_alert("AD incremental", 
+          critical_alert("Ldap incremental", 
                          "Error connection to Moira : %s",
                          error_message(rc));
           return;
@@ -2256,8 +2257,8 @@ int check_winad(void)
     {
       if (i > 30)
         {
-          critical_alert("AD incremental",
-                         "WINAD incremental failed (%s exists): %s",
+          critical_alert("Ldap incremental",
+                         "Ldap incremental failed (%s exists): %s",
                          STOP_FILE, tbl_buf);
           return(1);
         }
@@ -2408,6 +2409,7 @@ int group_rename(LDAP *ldap_handle, char *dn_path,
   char      *report_to_originator_v[] = {NULL, NULL};
   char      *address_book_v[] = {NULL, NULL};
   char      *legacy_exchange_dn_v[] = {NULL, NULL};
+  char      *null_v[] = {NULL, NULL};
   u_int     groupTypeControl;
   char      groupTypeControlStr[80];
   char      contact_mail[256];
@@ -2488,7 +2490,7 @@ int group_rename(LDAP *ldap_handle, char *dn_path,
   if (group_count != 1)
     {
       com_err(whoami, 0, "Unable to process multiple groups with "
-             "MoiraId = %s exist in the AD", MoiraId);
+             "MoiraId = %s exist in the directory", MoiraId);
       return(AD_MULTIPLE_GROUPS_FOUND);
     }
 
@@ -2612,6 +2614,12 @@ int group_rename(LDAP *ldap_handle, char *dn_path,
        {
          mail_v[0] = contact_mail;
          ADD_ATTR("mail", mail_v, LDAP_MOD_REPLACE);
+
+         if(!ActiveDirectory)
+           {
+             null_v[0] = "/dev/null";
+             ADD_ATTR("mailRoutingAddress", null_v, LDAP_MOD_REPLACE);
+           }
        }
     }
 
@@ -2665,6 +2673,7 @@ int group_create(int ac, char **av, void *ptr)
   char *address_book_v[] = {NULL, NULL};
   char *legacy_exchange_dn_v[] = {NULL, NULL};
   char *gidNumber_v[] = {NULL, NULL};
+  char *null_v[] = {NULL, NULL};
   char groupTypeControlStr[80];
   char group_membership[1];
   int  i;
@@ -2798,6 +2807,12 @@ int group_create(int ac, char **av, void *ptr)
            {
              mail_v[0] = contact_mail;
              ADD_ATTR("mail", mail_v, LDAP_MOD_ADD);
+
+             if(!ActiveDirectory)
+               {
+                 null_v[0] = "/dev/null";
+                 ADD_ATTR("mailRoutingAddress", null_v, LDAP_MOD_ADD);
+               }
            }
        }
       
@@ -2832,7 +2847,7 @@ int group_create(int ac, char **av, void *ptr)
 
       if ((rc != LDAP_SUCCESS) && (rc != LDAP_ALREADY_EXISTS))
         {
-          com_err(whoami, 0, "Unable to create list %s in AD : %s",
+          com_err(whoami, 0, "Unable to create list %s in directory : %s",
                   av[L_NAME], ldap_err2string(rc));
           callback_rc = rc;
           return(rc);
@@ -2947,11 +2962,23 @@ int group_create(int ac, char **av, void *ptr)
            {
              mail_v[0] = contact_mail;
              ADD_ATTR("mail", mail_v, LDAP_MOD_REPLACE);
+
+             if(!ActiveDirectory)
+               {
+                 null_v[0] = "/dev/null";
+                 ADD_ATTR("mailRoutingAddress", null_v, LDAP_MOD_REPLACE);
+               }
            }
          else
            {
              mail_v[0] = NULL;
              ADD_ATTR("mail", mail_v, LDAP_MOD_REPLACE);
+
+             if(!ActiveDirectory)
+               {
+                 null_v[0] = NULL;
+                 ADD_ATTR("mailRoutingAddress", null_v, LDAP_MOD_REPLACE);
+               }
            }
        }
    
@@ -2967,7 +2994,7 @@ int group_create(int ac, char **av, void *ptr)
 
           if (rc != LDAP_SUCCESS)
             {
-              com_err(whoami, 0, "Unable to update list %s in AD : %s",
+              com_err(whoami, 0, "Unable to update list %s in directory : %s",
                       av[L_NAME], ldap_err2string(rc));
               callback_rc = rc;
               return(rc);
@@ -3150,7 +3177,7 @@ int ProcessGroupSecurity(LDAP *ldap_handle, char *dn_path,
   if (AceSidCount == 0)
     {
       com_err(whoami, 0, "Group %s: Administrator: %s, Type: %s - does not "
-             "have an AD SID.", TargetGroupName, AceName, AceType);
+             "have a directory SID.", TargetGroupName, AceName, AceType);
       com_err(whoami, 0, "   Non-admin security group template will be used.");
     }
   else
@@ -3370,7 +3397,7 @@ int group_delete(LDAP *ldap_handle, char *dn_path, char *group_name,
       if ((rc = ldap_delete_s(ldap_handle, group_base->dn)) != LDAP_SUCCESS)
         {
           linklist_free(group_base);
-          com_err(whoami, 0, "Unable to delete list %s from AD : %s",
+          com_err(whoami, 0, "Unable to delete list %s from directory : %s",
                   group_name, ldap_err2string(rc));
           return(rc);
         }
@@ -3379,7 +3406,7 @@ int group_delete(LDAP *ldap_handle, char *dn_path, char *group_name,
   else
     {
       linklist_free(group_base);
-      com_err(whoami, 0, "Unable to find list %s in AD.", group_name);
+      com_err(whoami, 0, "Unable to find list %s in directory.", group_name);
       return(AD_NO_GROUPS_FOUND);
     }
   
@@ -3425,7 +3452,8 @@ int member_list_build(int ac, char **av, void *ptr)
   call_args = ptr;
 
   strcpy(temp, av[ACE_NAME]);
-
+  StringTrim(temp);
+  
   if (!check_string(temp))
     return(0);
 
@@ -3538,7 +3566,7 @@ int member_remove(LDAP *ldap_handle, char *dn_path, char *group_name,
 
   if (group_count != 1)
     {
-      com_err(whoami, 0, "Unable to find list %s in AD",
+      com_err(whoami, 0, "Unable to find list %s in directory",
               group_name);
       linklist_free(group_base);
       group_base = NULL;
@@ -3669,7 +3697,7 @@ int member_add(LDAP *ldap_handle, char *dn_path, char *group_name,
       linklist_free(group_base);
       group_base = NULL;
       group_count = 0;
-      com_err(whoami, 0, "Unable to find list %s %d in AD",
+      com_err(whoami, 0, "Unable to find list %s %d in directory",
               group_name, group_count);
       return(AD_MULTIPLE_GROUPS_FOUND);
     }
@@ -3746,7 +3774,7 @@ int contact_remove_email(LDAP *ld, char *bind_path,
     
     if ((rc != LDAP_SUCCESS) && (rc != LDAP_ALREADY_EXISTS))
       {
-       com_err(whoami, 0, "Unable to modify contact %s in AD : %s",
+       com_err(whoami, 0, "Unable to modify contact %s in directory : %s",
                gPtr->dn, ldap_err2string(rc));
        return(rc);
       }
@@ -4195,7 +4223,7 @@ int user_update(LDAP *ldap_handle, char *dn_path, char *user_name,
 
   if (group_count != 1)
     {
-      com_err(whoami, 0, "Unable to find user %s in AD",
+      com_err(whoami, 0, "Unable to find user %s in directory",
               user_name);
       linklist_free(group_base);
       return(AD_NO_USER_FOUND);
@@ -4210,7 +4238,7 @@ int user_update(LDAP *ldap_handle, char *dn_path, char *user_name,
     {
       if (rc = moira_connect())
        {
-         critical_alert("AD incremental", 
+         critical_alert("Ldap incremental", 
                         "Error contacting Moira server : %s",
                         error_message(rc));
          return;
@@ -4467,7 +4495,7 @@ int user_update(LDAP *ldap_handle, char *dn_path, char *user_name,
     {
       if (rc = moira_connect())
        {
-         critical_alert("AD incremental", 
+         critical_alert("Ldap incremental", 
                         "Error contacting Moira server : %s",
                         error_message(rc));
          return;
@@ -5240,7 +5268,7 @@ int user_create(int ac, char **av, void *ptr)
     {
       if (rc = moira_connect())
        {
-         critical_alert("AD incremental", 
+         critical_alert("Ldap incremental", 
                         "Error contacting Moira server : %s",
                         error_message(rc));
          return;
@@ -5418,7 +5446,7 @@ int user_change_status(LDAP *ldap_handle, char *dn_path,
   if (group_count != 1)
     {
       linklist_free(group_base);
-      com_err(whoami, 0, "Unable to find user %s in AD",
+      com_err(whoami, 0, "Unable to find user %s in directory",
               user_name);
       return(LDAP_NO_SUCH_OBJECT);
     }
@@ -5521,7 +5549,7 @@ int user_delete(LDAP *ldap_handle, char *dn_path,
 
   if (group_count != 1)
     {
-      com_err(whoami, 0, "Unable to find user %s in AD",
+      com_err(whoami, 0, "Unable to find user %s in directory",
               user_name);
       goto cleanup;
     }
@@ -5623,7 +5651,7 @@ static int illegalchars[] = {
 static int illegalchars_ldap[] = {
   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^@ - ^O */
   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^P - ^_ */
-  0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, /* SPACE - / */
+  0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, /* SPACE - / */
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, /* 0 - ? */
   0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* @ - O */
   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, /* P - _ */
@@ -5653,12 +5681,20 @@ int check_string(char *s)
       if(ActiveDirectory)
        {
          if (illegalchars[(unsigned) character])
-           return 0;
+           {
+             com_err(whoami, 0, "Found illegal char '%c' (%d) in string %s",
+                     character, (unsigned) character, s);
+             return 0;
+           }
        }
       else
        {
          if (illegalchars_ldap[(unsigned) character])
-           return 0;
+           {
+             com_err(whoami, 0, "Found illegal char '%c' (%d) in string %s",
+                     character, (unsigned) character, s);
+             return 0;
+           }
        }
     }
 
@@ -5867,8 +5903,10 @@ int ProcessAce(LDAP *ldap_handle, char *dn_path, char *Name, char *Type,
     
       if (rc = mr_query("get_list_info", 1, av, GetAceInfo, AceInfo))
         { 
-          com_err(whoami, 0, "Unable to get ACE info for list %s : %s", 
-                 GroupName, error_message(rc));
+         if(rc != MR_NO_MATCH)
+           com_err(whoami, 0, "Unable to get ACE info for list %s : %s", 
+                   GroupName, error_message(rc));
+
           return(1);
         }
 
@@ -5899,6 +5937,9 @@ int ProcessAce(LDAP *ldap_handle, char *dn_path, char *Name, char *Type,
           if (make_new_group(ldap_handle, dn_path, "", AceName, AceOu, 
                             AceMembership, 0, UpdateGroup, maillist))
             return(1);
+
+         populate_group(ldap_handle, dn_path, AceName, AceOu, AceMembership,
+                        0, "");
         }
       else if (!strcasecmp(AceInfo[0], "USER"))
         {
@@ -6027,6 +6068,9 @@ int populate_group(LDAP *ldap_handle, char *dn_path, char *group_name,
   if (rc = mr_query("get_end_members_of_list", 1, av,
                     member_list_build, call_args))
     {
+      if(rc == MR_LIST)
+       return(0);
+      
       com_err(whoami, 0, "Unable to populate list %s : %s", 
               group_name, error_message(rc));
       return(3);
@@ -6040,6 +6084,9 @@ int populate_group(LDAP *ldap_handle, char *dn_path, char *group_name,
 
       while (ptr != NULL)
         {
+         com_err(whoami, 0, "Processing member %s:%s", ptr->type,
+                 ptr->member);
+
           if (!strcasecmp(ptr->type, "LIST"))
             {
               ptr = ptr->next;
@@ -6114,7 +6161,6 @@ int populate_group(LDAP *ldap_handle, char *dn_path, char *group_name,
                  sprintf(member, "uid=%s,%s,%s", ptr->member, pUserOu, 
                          dn_path);
                }
-
            }
           else if (!strcasecmp(ptr->type, "STRING"))
             {
@@ -6864,7 +6910,7 @@ int container_delete(LDAP *ldap_handle, char *dn_path, int count, char **av)
       if (rc == LDAP_NOT_ALLOWED_ON_NONLEAF)
         container_move_objects(ldap_handle, dn_path, distinguishedName);
       else
-        com_err(whoami, 0, "Unable to delete container %s from AD : %s",
+        com_err(whoami, 0, "Unable to delete container %s from directory : %s",
                 av[CONTAINER_NAME], ldap_err2string(rc));
     }
 
@@ -7542,7 +7588,7 @@ int machine_move_to_ou(LDAP *ldap_handle, char * dn_path,
 
   if (group_count != 1)
     {
-      com_err(whoami, 0, "Unable to find machine %s in AD: %s", 
+      com_err(whoami, 0, "Unable to find machine %s in directory: %s", 
              MoiraMachineName);
       return(1);
     }
@@ -8087,7 +8133,7 @@ int SetHomeDirectory(LDAP *ldap_handle, char *user_name,
     {
       if (rc = moira_connect())
        {
-          critical_alert("AD incremental",
+          critical_alert("Ldap incremental",
                         "Error contacting Moira server : %s",
                         error_message(rc));
          return;
@@ -8158,7 +8204,7 @@ int SetHomeDirectory(LDAP *ldap_handle, char *user_name,
     {
       if (rc = moira_connect())
        {
-          critical_alert("AD incremental",
+          critical_alert("Ldap incremental",
                         "Error contacting Moira server : %s",
                         error_message(rc));
          return;
@@ -8366,7 +8412,7 @@ int attribute_update(LDAP *ldap_handle, char *distinguished_name,
                                  mods)) != LDAP_SUCCESS)
             {
               com_err(whoami, 0, "Unable to change the %s attribute for %s "
-                     "in the AD : %s",
+                     "in the directory : %s",
                       attribute, user_name, ldap_err2string(rc));
             }
         }
@@ -8940,15 +8986,6 @@ char *escape_string(char *s)
 
   q = s;
 
-  /* Replace leading spaces */
-
-  while(isspace(*q)) {
-    string[i++] = '\\';
-    string[i++] = '2';
-    string[i++] = '0';
-    q++;
-  }
-
   /* Escape any special characters */
 
   for(; *q != '\0'; q++) {
This page took 0.067361 seconds and 4 git commands to generate.