Esempio n. 1
0
        /// <summary>
        /// Sets HomeServer for this DN, which is nearest
        /// </summary>
        /// <param name="Dn">DN of user</param>
        /// <returns>HomeServer if succesful, else null</returns>
        public HostNode SetUserHomeServer(string Dn)
        {
            HostNode hostnode = null;
            Member   member   = domain.GetMemberByDN(Dn);

            hostnode = checkUserProvisionedByDN(Dn);
            log.Debug(String.Format("SetUserHomeServer {0}", Dn));
            if (hostnode == null)
            {
                if (Dn.ToLower().IndexOf("ou") >= 0)
                {
                    foreach (HostEntry hentry in hosts)
                    {
                        //Org Unit to machine name mapping is to be done...
                        string orgUnit = "";
                        string pubUrl  = hentry.Host.PublicUrl;
                        if (pubUrl.IndexOf(orgUnit) >= 0)
                        {
                            log.Debug(String.Format("Setting the home server for {0} to {1}", Dn,
                                                    orgUnit));
                            hostnode = hentry.Host;
                            hentry.AddMember(domain, member);
                            return(hostnode);
                        }
                    }
                }
                else
                {
                    //Check groups and then provision the user.
                    string groupList = String.Empty;
                    try
                    {
                        groupList = member.Properties.GetSingleProperty("UserGroups").Value as string;
                    }
                    catch {}
                    if (groupList != String.Empty && groupList != "")
                    {
                        string[] groupArray = groupList.Split(new char[] { ';' });
                        foreach (string group in groupArray)
                        {
                            hostnode = SetUserHomeServer(group);
                            if (hostnode != null)
                            {
                                log.Debug(String.Format("Setting the home server for {0} to {1}'s homeserver ", Dn, group));
                                HostEntry hentry = new HostEntry(hostnode);
                                hentry.AddMember(domain, member);
                                return(hostnode);
                            }
                        }
                    }
                }
            }
            return(hostnode);
        }
Esempio n. 2
0
        /// <summary>
        /// Sets user home server based on LdapHomeAttribute
        /// </summary>
        /// <param name="Dn">User's DN</param>
        /// <returns>HostNode if set successfully otherwise null</returns>
        public HostNode SetUserHomeServer(string Dn)
        {
            HostNode hostnode = null;
            Member   member   = domain.GetMemberByDN(Dn);

            hostnode = checkUserProvisionedByDN(Dn);
            log.Debug(String.Format("In SetUserHomeServer {0}", Dn));
            if (hostnode == null)
            {
                string ldapHome = String.Empty;
                try
                {
                    ldapHome = member.Properties.GetSingleProperty("LdapHomeAttribute").Value as string;
                }
                catch {}
                if (ldapHome != String.Empty && ldapHome != "")
                {
                    IPHostEntry ldapIPHostEntry = null;
                    try
                    {
                        ldapIPHostEntry = Dns.Resolve(ldapHome);
                    }
                    catch {}

                    foreach (HostEntry hentry in hosts)
                    {
                        Uri         publicUri      = new Uri(hentry.Host.PublicUrl);
                        IPHostEntry pubIPHostEntry = null;
                        try
                        {
                            pubIPHostEntry = Dns.Resolve(publicUri.Host);
                        }
                        catch {}
                        if (String.Compare(publicUri.Host, ldapHome) == 0 ||
                            String.Compare(publicUri.Host, ldapIPHostEntry.HostName) == 0 ||
                            String.Compare(pubIPHostEntry.HostName, ldapHome) == 0 ||
                            String.Compare(pubIPHostEntry.HostName, ldapIPHostEntry.HostName) == 0)
                        {
                            log.Debug(String.Format("Setting the home server for {0} to {1} {2}",
                                                    Dn, ldapIPHostEntry.HostName, pubIPHostEntry.HostName));
                            hostnode = hentry.Host;
                            hentry.AddMember(domain, member);
                            return(hostnode);
                        }
                        else
                        {
                            foreach (IPAddress ip in ldapIPHostEntry.AddressList)
                            {
                                foreach (IPAddress pubip in pubIPHostEntry.AddressList)
                                {
                                    if (ip.Equals(pubip) == true)
                                    {
                                        log.Debug(String.Format(
                                                      "Setting the home server for {0} to {1} {2}",
                                                      Dn, ip.ToString(), pubip.ToString()));
                                        hostnode = hentry.Host;
                                        hentry.AddMember(domain, member);
                                        return(hostnode);
                                    }
                                }
                            }

/*
 *                                                      // Alias name check is not required as of now, As of now it gets
 *                                                      // resolved with DNS name and IP. In case of alias check we can make
 *                                                      // use of this code.
 *                                                      foreach (string alias in ldapIPHostEntry.Aliases)
 *                                                      {
 *                                                          foreach (string pubalias in pubIPHostEntry.Aliases)
 *                                                          {
 *                                                              if(String.Compare(publicUri.Host, alias) == 0 ||
 *                                                              String.Compare(pubIPHostEntry.HostName,alias) == 0 ||
 *                                                              String.Compare(pubalias,alias ) == 0  )
 *                                                              {
 *                                                                      log.Debug(String.Format(
 *                                                                              "Setting the home server for {0} to {1} ",
 *                                                                              Dn,alias));
 *                                                                      hostnode = hentry.Host;
 *                                                                      hentry.AddMember( domain, member );
 *                                                                      return hostnode;
 *                                                              }
 *                                                          }
 *                                                      }
 */
                        }
                    }
                }
                else
                {
                    //Check groups and then provision the user.
                    string groupList = String.Empty;
                    try
                    {
                        groupList = member.Properties.GetSingleProperty("UserGroups").Value as string;
                    }
                    catch {}
                    if (groupList != String.Empty && groupList != "")
                    {
                        string[] groupArray = groupList.Split(new char[] { ';' });
                        foreach (string group in groupArray)
                        {
                            hostnode = SetUserHomeServer(group);
                            if (hostnode != null)
                            {
                                log.Debug(String.Format("Setting the home server for {0} to {1}'s homeserver ", Dn, group));
                                HostEntry hentry = new HostEntry(hostnode);
                                hentry.AddMember(domain, member);
                                return(hostnode);
                            }
                        }
                    }
                }
            }
            return(hostnode);
        }