示例#1
0
        protected bool IsInContactOUs(CSEntry csentry)
        {
            //
            // Find out if the object is in one of the Contact OUs,
            // meaning it is a canditate for projection
            //
            GALMA  MAConfig  = null;
            string ContactOU = null;

            //
            // To be in a Contact OU, the parent ou of the object must
            // be in the list of Contact OUs
            //
            MAConfig = FindMA(csentry);

            //
            // if contact OU is not defined
            //
            if ((MAConfig.ContactOUs == null))
            {
                return(false);
            }

            foreach (string ContactOU_loopVariable in MAConfig.ContactOUs)
            {
                ContactOU = ContactOU_loopVariable;
                if (csentry.DN.ToString().ToLower().EndsWith(ContactOU.ToString().ToLower()))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#2
0
        private bool ProxyAddressIsInSMTPMailDomain(CSEntry csentry, string ProxyAddress, bool onlyMatchingFirstSuffix, bool hasBeenMigrated)
        {
            GALMA  MAConfig         = null;
            string MailDomainSuffix = null;

            //
            // Find the index of the MA that csentry is in
            //
            MAConfig = FindMA(csentry);

            //
            // if no domain names defined
            //

            if ((MAConfig.MailDomainNames == null) || (MAConfig.MailDomainNames == null))
            {
                throw new TerminateRunException("Mail suffixes are not defined for MA: " + MAConfig.MAName);
            }

            //
            // Check if the given proxy address ends with one the
            // mail domain suffixes for that MA
            //
            foreach (string MailDomainSuffix_loopVariable in MAConfig.MailDomainNames)
            {
                MailDomainSuffix = MailDomainSuffix_loopVariable;

                // AFRIEDRICHSEN 06 Jan 2016 - checking for mail.onmicrosoft.com address first and returning it
                if (hasBeenMigrated && ProxyAddress.ToLower().Contains("mail.onmicrosoft.com"))
                {
                    return(true);
                }

                if (ProxyAddress.ToLower().EndsWith(MailDomainSuffix.ToString().ToLower()))
                {
                    return(true);
                }

                if (onlyMatchingFirstSuffix)
                {
                    return(false);
                }
            }

            return(false);
        }
示例#3
0
        // added bool hasBeenMigrated to use in suffix selection
        protected string FindMatchedDomainSuffix(CSEntry csentry, bool checkMailRouting, bool onlyMatchingFirstSuffix, bool hasBeenMigrated)
        {
            string result = null;

            GALMA MAConfig = null;

            //
            // CheckMailRouting is true if called for Contact,
            // false for user and group.
            //
            // So for contact (true == checkMailRouting), if the MA is
            // configured to use mail routing, then skip finding from
            // matching proxy, the caller will then map the source CS
            // target address to MV directly.
            //
            if (true == checkMailRouting)
            {
                MAConfig = FindMA(csentry);
                if (false == MAConfig.MailRouting)
                {
                    result = null;
                }
            }

            //
            // Check every smtp address in proxy addresses if they end
            // with one of the mail domain suffixes that that forest
            // controls return it
            //
            foreach (Value ProxyAddress in csentry[PROXY_ADDRESSES].Values)
            {
                string ProxyAddressString = ProxyAddress.ToString();

                // AFRIEDRICHSEN 06 Jan 2016 - added hasBeenMigrated to logic for smtp selection in function call
                if (ProxyAddressString.ToUpper().StartsWith(SMTP_PREFIX))
                {
                    if (ProxyAddressIsInSMTPMailDomain(csentry, ProxyAddressString, onlyMatchingFirstSuffix, hasBeenMigrated))
                    {
                        result = "SMTP:" + ProxyAddressString.Split(':')[1].ToLower();
                    }
                }
            }

            return(result);
        }
示例#4
0
        protected bool IsInSynchronizationOU(CSEntry csentry)
        {
            //
            // Find out if the object is in one of the synchronization OUs,
            // meaning we are managing this object
            //
            GALMA MAConfig = null;

            MAConfig = FindMA(csentry);
            //
            // To be in a synchronization OU, the parent ou of the object
            // must be in the list of synchronization OUs
            //
            if ((MAConfig.SynchronizationOU == null) || MAConfig.SynchronizationOU.Equals(""))
            {
                return(false);
            }
            else
            {
                return(csentry.DN.ToString().ToLower().EndsWith(MAConfig.SynchronizationOU.ToString().ToLower()));
            }
        }
示例#5
0
        protected string GetAdminGroup(CSEntry csentry)
        {
            //
            // Find out if the object is in one of the Contact OUs,
            // meaning it is a canditate for projection
            //
            GALMA MAConfig = null;

            //
            // To be in a Contact OU, the parent ou of the object must
            // be in the list of Contact OUs
            //
            MAConfig = FindMA(csentry);

            //
            // if contact OU is not defined
            //
            if ((MAConfig.AdminGroup == null) || MAConfig.AdminGroup.Equals(""))
            {
                return(null);
            }

            return(MAConfig.AdminGroup);
        }
示例#6
0
        protected void GetConfigurationData()
        {
            //
            // do not catch exception
            //
            XmlDocument doc        = new XmlDocument();
            int         i          = 0;
            int         j          = 0;
            XmlNodeList nodeMAList = default(XmlNodeList);
            XmlNode     nodeMA     = default(XmlNode);
            XmlNode     node       = default(XmlNode);

            XmlNode nodeMAs  = default(XmlNode);
            GALMA   MAConfig = null;

            doc.Load(Utils.ExtensionsDirectory + "\\GALSync.xml");

            nodeMAs    = doc.SelectSingleNode("/" + MMS_RULES_EXTENSION + "/" + GAL_SYNC_MAS);
            nodeMAList = nodeMAs.SelectNodes(GAL_SYNC_MA);

            galMAs = new GALMA[nodeMAList.Count];

            for (i = 0; i <= nodeMAList.Count - 1; i++)
            {
                nodeMA = nodeMAList.Item(i);

                galMAs[i]                  = new GALMA();
                MAConfig                   = galMAs[i];
                MAConfig.MAName            = null;
                MAConfig.SynchronizationOU = null;
                MAConfig.MailDomainNames   = null;
                MAConfig.ContactOUs        = null;
                MAConfig.ContactType       = null;
                MAConfig.AdminGroup        = null;
                MAConfig.MailRouting       = false;
                MAConfig.XFDelegation      = false;

                // Find MA Name
                foreach (XmlAttribute maAttribute in nodeMA.Attributes)
                {
                    if ("name" == maAttribute.Name)
                    {
                        MAConfig.MAName = maAttribute.InnerText.Trim();
                        break;                         // TODO: might not be correct. Was : Exit For
                    }
                }

                if ((MAConfig.MAName == null))
                {
                    throw new UnexpectedDataException("No MA name Attribute in configuration XML");
                }

                // Read contact type
                node = nodeMA.SelectSingleNode(GAL_SYNC_MA_CONTACT_TYPE);
                if ((node != null))
                {
                    MAConfig.ContactType = node.InnerText.Trim();
                }

                // Read admin group
                node = nodeMA.SelectSingleNode(GAL_SYNC_MA_ADMIN_GROUP);
                if ((node != null))
                {
                    MAConfig.AdminGroup = node.InnerText.Trim();
                }

                // Read target OU
                node = nodeMA.SelectSingleNode(GAL_SYNC_MA_TARGET_OU);
                if ((node != null))
                {
                    MAConfig.SynchronizationOU = node.InnerText.Trim();
                }

                // Read mail routing
                node = nodeMA.SelectSingleNode(GAL_SYNC_MA_MAIL_ROUTING);
                if ((node != null) && node.InnerText.Trim().ToLower() == "true")
                {
                    MAConfig.MailRouting = true;
                }
                else
                {
                    MAConfig.MailRouting = false;
                }

                // Read mail domains
                node = nodeMA.SelectSingleNode(GAL_SYNC_MA_SMTP_MAIL_DOMAINS);

                if ((node != null) && 0 < node.ChildNodes.Count)
                {
                    MAConfig.MailDomainNames = (string[])Array.CreateInstance(typeof(string), node.ChildNodes.Count);

                    for (j = 0; j <= node.ChildNodes.Count - 1; j++)
                    {
                        if (GAL_SYNC_MA_DOMAIN == node.ChildNodes[j].Name)
                        {
                            MAConfig.MailDomainNames[j] = node.ChildNodes[j].InnerText.Trim();
                        }
                        else
                        {
                            // Since we allocated the array accordingly
                            throw new UnexpectedDataException("Unexpected mail domain");
                        }
                    }
                }

                // Read contact OUs
                node = nodeMA.SelectSingleNode(GAL_SYNC_MA_SOURCE_CONTACT_OUS);

                if ((node != null) && 0 < node.ChildNodes.Count)
                {
                    MAConfig.ContactOUs = (string[])Array.CreateInstance(typeof(string), node.ChildNodes.Count);

                    for (j = 0; j <= node.ChildNodes.Count - 1; j++)
                    {
                        if (GAL_SYNC_MA_OU == node.ChildNodes[j].Name)
                        {
                            MAConfig.ContactOUs[j] = node.ChildNodes[j].InnerText.Trim();
                        }
                        else
                        {
                            // Since we allocated the array accordingly
                            throw new UnexpectedDataException("Unexpected contact ou");
                        }
                    }
                }
                // Read cross forest delgation
                node = nodeMA.SelectSingleNode(GAL_SYNC_MA_XF_DELEGATION);
                if ((node != null) && node.InnerText.Trim().ToLower() == "true")
                {
                    MAConfig.XFDelegation = true;
                }
                else
                {
                    MAConfig.XFDelegation = false;
                }
            }
        }
示例#7
0
        private void AddOrRenameConnector(ref ConnectedMA MA, ref GALMA MAConfig, MVEntry mventry, CSEntry csentry = null)
        {
            //
            // All objects are provisioned as contacts
            //
            string cn                = null;
            int    numberToAppend    = 1;
            bool   successful        = false;
            bool   extendedNameTried = false;
            string extendedName      = null;
            string adminGroup        = null;
            bool   provisioningAdd   = false;
            int    cnLengthMax       = 0;
            string validatedName     = null;

            //
            // Add or Rename if only SynchronizationOU is defined
            //
            if ((MAConfig.SynchronizationOU == null) || MAConfig.SynchronizationOU.Equals(""))
            {
                return;
            }

            if (!mventry[COMMON_NAME].IsPresent || !mventry[MAIL_NICK_NAME].IsPresent || !mventry[TARGET_ADDRESS].IsPresent)
            {
                LogAndThrowUnexpectedDataException("Provisioning without cn, mailNickName or targetAddress");
            }

            if (null == csentry)
            {
                provisioningAdd = true;
            }

            cn = mventry[COMMON_NAME].Value.ToString();

            //
            // Active Directory does not distinguish CNs that differ only in use of diacritical marks (accents) etc.
            // whereas the sync service does. So force uniqueness by appending mailnickname to all CNs with extended
            // chars if doing so does not exceed CN max length.
            //
            IEnumerator cnEnum = cn.GetEnumerator();

            while (cnEnum.MoveNext())
            {
                if (Strings.AscW(cnEnum.Current.ToString()) > 127 && cn.Length + mventry[MAIL_NICK_NAME].Value.ToString().Length + 2 + RDN_TYPE.Length < AD_RDN_MAX_SIZE)
                {
                    cn = cn + "(" + mventry[MAIL_NICK_NAME].Value.ToString() + ")";
                    break;                     // TODO: might not be correct. Was : Exit While
                }
            }

            do
            {
                try {
                    //
                    // Create a DN for the new object, need UPPER case "CN=..."
                    //
                    string         rdn = RDN_TYPE + cn;
                    ReferenceValue dn  = MA.EscapeDNComponent(rdn).Concat(MAConfig.SynchronizationOU);

                    if (rdn.Length > AD_RDN_MAX_SIZE + RDN_TYPE.Length)
                    {
                        LogAndThrowUnexpectedDataException("RDN too long: " + rdn);
                    }

                    if (csentry == null)
                    {
                        //
                        // Try to add the object
                        //
                        //LoggingCs.Log("Adding " + dn.ToString());

                        csentry = ExchangeUtils.CreateMailEnabledContact(MA, dn, mventry[MAIL_NICK_NAME].Value.ToString(), mventry[TARGET_ADDRESS].Value.ToString());

                        adminGroup = GetAdminGroup(csentry);
                        if ((adminGroup != null))
                        {
                            //
                            // LegacyExhangeDN = adminGroup/cn=mailnickname-guid
                            //
                            validatedName = ValidateLegacyExhangeDN(mventry[MAIL_NICK_NAME].Value.ToCharArray());

                            if ((validatedName == null))
                            {
                                csentry[LEGACY_EXCHANGE_DN].Value = adminGroup + "/cn=" + System.Guid.NewGuid().ToString();
                            }
                            else
                            {
                                csentry[LEGACY_EXCHANGE_DN].Value = adminGroup + "/cn=" + validatedName + "-" + System.Guid.NewGuid().ToString();
                            }
                        }
                    }
                    else
                    {
                        //
                        // Try to rename the object
                        //
                        if (!csentry.DN.Equals(dn))
                        {
                            //LoggingCs.Log("Renaming " + dn.ToString());
                            csentry.DN = dn;
                        }
                    }
                    successful = true;
                } catch (MissingParentObjectException ex) {
                    //
                    // Typically the admin has to perform a full/delta import
                    // on the target CD, or disable provisioning until all
                    // forests are imported.
                    //
                    //LoggingCs.Log("Target MA " + MA.Name + " is not imported yet. " + "Please disable provisioning until all forests " + "are imported.");
                    throw ex;
                } catch (ObjectAlreadyExistsException ex) {
                    //
                    // If adding connector, throw away the instance to start over
                    //
                    if (provisioningAdd)
                    {
                        csentry = null;
                    }

                    //
                    // There is a duplicate object in the target AD,
                    // change the cn accordingly to avoid conflict.
                    //
                    if (!extendedNameTried)
                    {
                        extendedNameTried = true;
                        try {
                            if (mventry[DEPARTMENT].IsPresent)
                            {
                                extendedName = mventry[DEPARTMENT].Value;
                            }
                        } catch (NoSuchAttributeInObjectTypeException ex2) {
                        }
                    }

                    cn = null;
                    if (extendedName != null)
                    {
                        cn           = mventry[COMMON_NAME].Value + " (" + extendedName + ")";
                        extendedName = null;

                        if (cn.Length > AD_RDN_MAX_SIZE)
                        {
                            //
                            // If too long, we'll try without it
                            //
                            cn = null;
                        }
                    }


                    if (null == cn)
                    {
                        cn = mventry[COMMON_NAME].Value;

                        //
                        // To make sure that the number appended
                        // will not be truncated.
                        // The 2 spaces reserved is for "()"
                        //
                        cnLengthMax = AD_RDN_MAX_SIZE - (numberToAppend.ToString().Length + 2);
                        //
                        // If it's too long, we are going to truncate the
                        // name and preserve the number appended.
                        //
                        if (cn.Length > cnLengthMax)
                        {
                            cn = cn.Substring(0, cnLengthMax);
                        }

                        cn             = cn + "(" + numberToAppend.ToString() + ")";
                        numberToAppend = numberToAppend + 1;

                        if (numberToAppend > RETRY_NUM_LIMIT)
                        {
                            LogAndThrowUnexpectedDataException("Retry for " + mventry[COMMON_NAME].Value + " exceeds limit " + numberToAppend.ToString());
                        }
                    }
                }
            } while (!successful);
        }