Beispiel #1
0
        /// <summary>
        /// Shows the Manage form and directs it at a particular
        /// machine.
        /// </summary>
        /// <param name="sHostname">The machine to manage</param>
        /// <param name="viewStyle">The style of list view to use, if a listview is used</param>
        /// <returns>TRUE if was able to manage the given machine. FALSE if a
        ///          network or credential error occured. </returns>
        public bool ManageHost(string sHostname, StandardPage.ViewStyle viewStyle)
        {
            // first, normalize the incoming hostname
            Hostinfo hn = new Hostinfo(sHostname);

            // now, set the host type
            if (!CheckHostInfo(hn))
            {
                string sMsg = string.Format(Resources.Error_InvalidComputerType, sHostname);
                ShowError(sMsg, MessageBoxButtons.OK);
                return(false);
            }

            // do this first so that we can do any slow stuff before we start
            // changing pages
            if (!controlManage.ManageHost(hn))
            {
                return(false);
            }

            SetViewStyle(viewStyle);

            // show the management control
            ShowManage();

            string str = String.Format(Resources.Connected_As,
                                       hn.creds.UserName,
                                       hn.hostName);

            controlManage.SetStatusMesaage(str, 1);

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Determines whether a machine is a Windows machine, Linux, etc.
        /// </summary>
        /// <param name="hn">The machine to test</param>
        /// <returns>The machine type</returns>
        private static bool CheckHostInfo(Hostinfo hn)
        {
            // First, let's get an IP address for it.
            try
            {
                // if we can't resolve the name, give up
                // TODO: do this async so that we can abort it
                IPAddress[] arips = Dns.GetHostAddresses(hn.hostName);
                if (arips.Length == 0)
                {
                    return(false);
                }

                IPAddress addr = arips[0];

                // set this up front for later
                hn.IsSmbAvailable = checkPort(addr, 445);

                // see if we can open up port 22
                hn.IsSSHAvailable = checkPort(addr, 22);

                // check netbios port
                hn.IsNetBiosAvailable = checkPort(addr, 139);
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
    public NewGroupDlg(IPlugInContainer container, StandardPage parentPage,Hostinfo hn, IPlugIn plugin)
    : base(container, parentPage)
    {
        InitializeComponent();
        
        // Create an instance of a ListView column sorter and assign it
        // to the ListView control.
        lvwColumnSorter = new ListViewColumnSorter();
        this.lvMembers.ListViewItemSorter = lvwColumnSorter;
        
        this.ButtonCancel.Text = "Cancel";
        
        this.ButtonOK.Text = "Create";
        
        this.SetAllValueChangedHandlers(this);
        
        localParent = (LUGPage)parentPage;
        
        if (localParent == null)
        {
            throw new ArgumentException("NewGroupDlg constructor: (LUGPage) parentPage == null");
        }

        this._hn = hn;
        this._plugin = (LUGPlugIn)plugin;

        ((EditDialog)this).btnApply.Visible = false;
        users = new Hashtable();
        
        this.tbGroupName.Select();
        
    }
 public ObjectSelectDlg(IPlugInContainer container, StandardPage parentPage, Hostinfo hn, IPlugIn plugin)
     : this()
 {
     this.IPlugInContainer = container;
     //this.AddPage(new DomainConnectPage(this, hn, plugin, container));
     this.AddPage(new ObjectSelectPage(this, plugin, container));
 }
        public static void GetPluginCredentials(IPlugIn plugin, Hostinfo hn)
        {
            _plugin = plugin;
            _hn = hn;

            if (IsConnectSetBefore(plugin))
                GetConnectedHostInfoFromIni(_plugin, _hn);
            else
                SetDefaultCredentails();
        }
        public SharePropertiesDlg(IPlugInContainer container, StandardPage parentPage, FileShareManagerIPlugIn plugin, Hostinfo hn)
            : base(container, parentPage)
        {
            InitializeComponent();

            this.Text = "{0} Properties";
            this._hn = hn;
            _plugin = plugin;
            _container = container;
            InitializePages();
        }
Beispiel #7
0
 public static bool HasCreds(Hostinfo hn)
 {
     if (hn == null ||
         hn.creds == null ||
         CredentialEntry.IsNullOrEmpty(hn.creds))
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Beispiel #8
0
        public Hostinfo Clone()
        {
            Hostinfo result = new Hostinfo(this.hostName);

            result.domainName = this.domainName;

            result.IsSmbAvailable     = this.IsSmbAvailable;
            result.IsSSHAvailable     = this.IsSSHAvailable;
            result.IsNetBiosAvailable = this.IsNetBiosAvailable;

            if (this.creds != null)
            {
                result.creds = this.creds.Clone();
            }

            return(result);
        }
        public static void SetDefaultCredentails()
        {
            if (_hn == null)
                _hn = new Hostinfo();

            if (String.IsNullOrEmpty(_hn.creds.Domain) && !String.IsNullOrEmpty(System.Environment.UserDomainName)) {
                _hn.creds.Domain = System.Environment.UserDomainName;
            }

            if (String.IsNullOrEmpty(_hn.creds.UserName) && !String.IsNullOrEmpty(System.Environment.UserName)) {
                _hn.creds.UserName = System.Environment.UserName;
            }

            if (String.IsNullOrEmpty(_hn.hostName) && !String.IsNullOrEmpty(System.Environment.MachineName)) {
                _hn.hostName = System.Environment.MachineName;
                _hn.creds.MachineName = System.Environment.MachineName;
            }
        }
Beispiel #10
0
    public void SetContext(IContext ctx)
    {
        Hostinfo hn = ctx as Hostinfo;

        Logger.Log(String.Format("LUGPlugin.SetHost(hn: {0})",
        hn == null ? "null" : hn.hostName), Logger.manageLogLevel);
        
        _hn = hn;
        
        if (_hn == null)
        {
            _hn = new Hostinfo();
        }

        if (_pluginNode != null &&
           (!String.IsNullOrEmpty(hn.hostName)))
        {
            uint result = LUGAPI.NetAddConnection(
                _hn.hostName,
                _hn.creds.UserName,
                _hn.creds.Password);

            if (Configurations.currentPlatform != LikewiseTargetPlatform.Windows &&
                result == (uint)LUGAPI.WinError.ERROR_FILE_NOT_FOUND)
            {
                result = (uint)LUGAPI.WinError.ERROR_SUCCESS;
            }

            hn.IsConnectionSuccess = false;
            if (result == (uint)LUGAPI.WinError.ERROR_SUCCESS)
            {
                hn.IsConnectionSuccess = true;
            }

            _pluginNode.SetContext(_hn);
        }
    }
Beispiel #11
0
        /// <summary>
        /// Called when picker or some other interface (Welcome
        /// form, e.g.) indicates that the user wants to manage
        /// a particular machine.
        /// </summary>
        /// <param name="hn">A Hostinfo object that identifies the
        ///                  machine to be managed.</param>
        /// <returns>False if user cancelled out of creds form</returns>
        public bool ManageHost(Hostinfo hn)
        {
            Logger.Log(String.Format("Manage.ManageHost: hn: {0}", hn == null ? "null" : hn.hostName), Logger.manageLogLevel);

            string saveLdapPath = this.sLDAPPath;

#if !QUARTZ
            this.sLDAPPath = Util.GetLdapDomainPath(null, null);

            try
            {
                string server, protocol, dc, cn;
                String rootDomainPath = Util.GetLdapRootDomainPath(GetDomainName(), GetCredentials());
                Util.CrackPath(rootDomainPath, out protocol, out server, out cn, out dc);
                this.rootDomain = Util.DNToDomainName(dc).ToLower();
            }
            catch (Exception e)
            {
                this.sLDAPPath = saveLdapPath;
                throw e;
            }
#endif

            if (hn == null)
            {
                Logger.LogMsgBox("Manage::ManageHost(hn): hn == null");
                return false;
            }

            _hn = hn;

            LACTreeNode rootNode = LoadPlugins();

            foreach (LACTreeNode treeNode in rootNode.Nodes)
            {
                treeNode.Expand();
            }

#if !QUARTZ
            sLDAPPath = Util.GetLdapDomainPath(_hn.domainName, null);
#else
            sLDAPPath = _hn.domainName;
#endif
            return true;
        }
    public void SetContext(IContext ctx)
    {
        Hostinfo hn = ctx as Hostinfo;
        Logger.Log(String.Format("EventlogPlugin.SetHost(hn: {0}\n)",
        hn == null ? "<null>" : hn.ToString()), Logger.eventLogLogLevel);

        bool deadTree = false;

        if (_pluginNode != null &&
            _pluginNode.Nodes != null &&
            _hn != null &&
            hn != null &&
            hn.hostName !=
            _hn.hostName)
        {
            foreach (TreeNode node in _pluginNode.Nodes)
            {
                _pluginNode.Nodes.Remove(node);
            }
            deadTree = true;
        }

        _hn = hn;

        if (HostInfo == null)
        {
            _hn = new Hostinfo();
        }

        if (_pluginNode != null && _pluginNode.Nodes.Count == 0 && _hn.IsConnectionSuccess)
        {
            BuildLogNodes();
        }

        if (deadTree && _pluginNode != null)
        {
            _pluginNode.SetContext(_hn);
        }
    }
        public SelectComputerDialog()
        {
            InitializeComponent();

            _hn = new Hostinfo();
        }
Beispiel #14
0
 /// <summary>
 /// Method that creates and initializes the ADUC Rootnode
 /// </summary>
 /// <returns></returns>
 private LACTreeNode GetADUCRootNode()
 {
     Logger.Log("ADUCPlugin.GetADUCRootNode", Logger.manageLogLevel);
     
     if (_pluginNode == null)
     {
         _hn = new Hostinfo();            
         _pluginNode = Manage.CreateIconNode(Resources.ADUCTitle,
         Resources.ADUC,
         typeof(ADUCPage),
         this);
         _pluginNode.IsPluginNode = true;
     }
     _pluginNode.ImageIndex = (int)Manage.ManageImageType.Generic;
     _pluginNode.SelectedImageIndex = (int)Manage.ManageImageType.Generic;
     
     
     return _pluginNode;
 }
Beispiel #15
0
    /// <summary>
    /// If Host information is not null then refreshes the ADUC plugin for each domain on mouse left click
    /// Else reinitializes the ADUC plugin node
    /// </summary>
    /// <param name="hn"></param>
    public void SetContext(IContext ctx)
    {
        Hostinfo hn = ctx as Hostinfo;
        
        Logger.Log(String.Format("ADUCPlugin.SetHost(hn: {0})",
        hn == null ? "null" : hn.ToString()), Logger.manageLogLevel);
        
        _hn = hn;
        
        if (_hn != null &&
        !String.IsNullOrEmpty(_hn.domainName) &&
        !(_usingSimpleBind && !Hostinfo.HasCreds(_hn)))
        {            
            Logger.Log("ADUCPlugin.SetHost: connecting to domain");
           
            ConnectToDomain();
            
            if (!_usingSimpleBind && !_hn.IsConnectionSuccess)
            {
                _usingSimpleBind = true;
            }

            //sethost on all the extension plugins
            if (_extPlugins != null)
            {
                foreach (IPlugIn extPlugin in _extPlugins)
                    extPlugin.SetContext(_hn);
            }
        }
    }
        /// <summary>
        /// Determines whether a machine is a Windows machine, Linux, etc.
        /// </summary>
        /// <param name="hn">The machine to test</param>
        /// <returns>The machine type</returns>
        private static bool CheckHostInfo(Hostinfo hn)
        {
            // First, let's get an IP address for it.
            try
            {
                // if we can't resolve the name, give up
                // TODO: do this async so that we can abort it
                IPAddress[] arips = Dns.GetHostAddresses(hn.hostName);
                if (arips.Length == 0)
                    return false;

                IPAddress addr = arips[0];

                // set this up front for later
                hn.IsSmbAvailable = checkPort(addr, 445);

                // see if we can open up port 22
                hn.IsSSHAvailable = checkPort(addr, 22);

                // check netbios port
                hn.IsNetBiosAvailable = checkPort(addr, 139);
            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }
Beispiel #17
0
        public Hostinfo Clone()
        {
            Hostinfo result = new Hostinfo(this.hostName);

            result.domainName = this.domainName;

            result.IsSmbAvailable = this.IsSmbAvailable;
            result.IsSSHAvailable = this.IsSSHAvailable;
            result.IsNetBiosAvailable = this.IsNetBiosAvailable;

            if (this.creds != null)
            {
                result.creds = this.creds.Clone();
            }

            return result;
        }
        /// <summary>
        /// Reads the target machine info for the current plugin from credentilas ini and assign to Hostinfo
        /// </summary>
        /// <param name="requestor"></param>
        /// <param name="_hn"></param>
        public static void GetConnectedHostInfoFromIni(IPlugIn requestor, Hostinfo _hn)
        {
            string sPlugInName = requestor.GetName();

            bool IsFileExists = !string.IsNullOrEmpty(sCredentialsFilePath) && Path.IsPathRooted(sCredentialsFilePath) && File.Exists(sCredentialsFilePath);

            if (!IsFileExists)
                return;

            StreamReader reader = new StreamReader(sCredentialsFilePath);

            while (!reader.EndOfStream)
            {
                string currentLine = reader.ReadLine();
                if (currentLine != null && currentLine.Trim().Equals(sPlugInName))
                {
                    currentLine = reader.ReadLine();

                    int index = 0;
                    if (currentLine != null && currentLine.Trim().IndexOf("hostname=") >= 0 &&
                        String.IsNullOrEmpty(_hn.hostName))
                    {
                        currentLine = currentLine.Trim();
                        index = (currentLine.IndexOf('=') + 1);
                        _hn.hostName = currentLine.Substring(index, (currentLine.Length - index));
                        currentLine = reader.ReadLine();
                    }

                    if (currentLine != null && currentLine.Trim().IndexOf("username="******"domainFQDN=") >= 0 &&
                        String.IsNullOrEmpty(_hn.domainName))
                    {
                        currentLine = currentLine.Trim();
                        index = (currentLine.IndexOf('=') + 1);
                        _hn.domainName = currentLine.Substring(index, (currentLine.Length - index));
                        currentLine = reader.ReadLine();
                    }

                    if (currentLine != null && currentLine.IndexOf("domainShort=") >= 0 &&
                        String.IsNullOrEmpty(_hn.creds.Domain))
                    {
                        currentLine = currentLine.Trim();
                        index = (currentLine.IndexOf('=') + 1);
                        _hn.creds.Domain = currentLine.Substring(index, (currentLine.Length - index));
                    }
                    break;
                }
            }
            reader.Close();
        }
Beispiel #19
0
        public string GetRootDomainName()
        {
            if (_hn == null || _hn.domainName == null || _hn.domainName == "")
            {
                _hn = new Hostinfo();

                try
                {
#if !QUARTZ
                    // get the root domain name
                    string server, protocol, dc, cn;
                    String rootDomainPath = Util.GetLdapRootDomainPath(GetDomainName(), GetCredentials());
                    server = protocol = dc = cn = null;
                    Util.CrackPath(rootDomainPath, out protocol, out server, out cn, out dc);
                    _hn.domainName = Util.DNToDomainName(dc).ToLower();
#endif
                }
                catch (Exception ex)
                {
                    Logger.Log("Unable to determine root domain name for " + GetDomainName() + ". " + ex.Message);
                    _hn.domainName = GetDomainName();
                }
            }

            return _hn.domainName;
        }
        /// <summary>
        /// Method to store the plugin's host info to ini file.
        /// </summary>
        /// <param name="_hn"></param>
        private void SaveTargetMachineInfoToIni(Hostinfo _hn, IPlugIn plugin)
        {
            Logger.Log(String.Format(
                "LMCCredentials.SaveTargetMachineInfoToIni: saving the target machine info to ini: _hn =\n {0}",
                _hn == null ? "<null>" : _hn.ToString()),
                Logger.manageLogLevel);

            string sPath = Path.Combine(Application.UserAppDataPath, @"Temp.ini");

            CreateCredentialsIni(sCredentialsFilePath);

            StreamReader reader = new StreamReader(sCredentialsFilePath);
            FileStream fStream = new FileStream(sPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
            StreamWriter writer = new StreamWriter(fStream);

            string sPlugInName = plugin.GetName();

            Logger.Log(String.Format(
                "LMCCredentials.SaveTargetMachineInfoToIni: plugin name={0}",
                sPlugInName == null ? "<null>" : sPlugInName),
                Logger.manageLogLevel);

            if (!String.IsNullOrEmpty(sPlugInName))
            {
                string currentLine = reader.ReadLine();

                while (!(currentLine != null && currentLine.Trim().Equals(sPlugInName)) &&
                       !reader.EndOfStream)
                {
                    writer.WriteLine(currentLine);
                    currentLine = reader.ReadLine();
                }

                writer.WriteLine(sPlugInName);
                if (!String.IsNullOrEmpty(_hn.hostName))
                {
                    writer.WriteLine("hostname=" + _hn.hostName.Trim());
                }
                if (_hn.creds != null && !String.IsNullOrEmpty(_hn.creds.UserName))
                {
                    writer.WriteLine("username="******"domainFQDN=" + _hn.domainName.Trim());
                }
                if (_hn.creds != null && !String.IsNullOrEmpty(_hn.creds.Domain))
                {
                    writer.WriteLine("domainShort=" + _hn.creds.Domain.Trim());
                }
                writer.WriteLine("");

                //make sure the remainder of the old file is present in the new one.
                currentLine = reader.ReadLine();
                while (!(currentLine != null && currentLine.Trim().Length > 0 && currentLine.Trim()[0] == '[') &&
                        !reader.EndOfStream)
                {
                    currentLine = reader.ReadLine();
                }
                while (!reader.EndOfStream)
                {
                    writer.WriteLine(currentLine);
                    currentLine = reader.ReadLine();
                }
                if (reader.EndOfStream)
                {
                    writer.WriteLine("");
                }
            }
            writer.Flush();

            writer.Close();
            reader.Close();
            fStream.Close();
            fStream.Dispose();

            if (File.Exists(sCredentialsFilePath) && File.Exists(sPath))
            {
                File.Delete(sCredentialsFilePath);
                File.Move(sPath, sCredentialsFilePath);
            }
        }
Beispiel #21
0
        private bool GetMachineInfoDelegate(string[] fields, Object context)
        {
            uint fieldsRequested = (uint)((UInt32)context);

            Logger.Log(String.Format(
                "Manage.GetMachineInfoDelegate: fieldsRequested=0x{0:x}",
                fieldsRequested),
                Logger.manageLogLevel);

            string shortHostName = null;
            string fullyQualifiedHostName = null;
            string FQDN = null;
            string fullyQualifiedDCName = null;
            string shortDomainName = null;
            string userName = null;
            string password = null;
            string errorMessage = null;
            bool result = true;

            int fieldIndex = 0;

            _hn = new Hostinfo();
            _hn.creds = new CredentialEntry();

            if (((uint)Hostinfo.FieldBitmaskBits.SHORT_HOSTNAME & fieldsRequested) > 0)
            {
                shortHostName = fields[fieldIndex++];
                if (!Hostinfo.ValidateHostName(shortHostName, out errorMessage))
                {
                    result = false;
                    Logger.Log("GetMachineInfoDelegate: invalid SHORT_HOSTNAME: " + errorMessage, Logger.manageLogLevel);
                }
                else
                {
                    _hn.hostName = shortHostName;
                    Logger.Log("GetMachineInfoDelegate: assigned SHORT_HOSTNAME:\n" + _hn.ToString(), Logger.manageLogLevel);
                }

            }

            if (result && ((uint)Hostinfo.FieldBitmaskBits.FQ_HOSTNAME & fieldsRequested) > 0)
            {
                fullyQualifiedHostName = fields[fieldIndex++];
                if (!Hostinfo.ValidateFullyQualifiedHostName(fullyQualifiedHostName, out errorMessage))
                {
                    result = false;
                    Logger.Log("GetMachineInfoDelegate: invalid FQ_HOSTNAME: " + errorMessage, Logger.manageLogLevel);
                }
                else
                {
                    _hn.hostName = fullyQualifiedHostName;
                    Logger.Log("GetMachineInfoDelegate: assigned FQ_HOSTNAME:\n" + _hn.ToString(), Logger.manageLogLevel);
                }
            }

            if (result && ((uint)Hostinfo.FieldBitmaskBits.FQDN & fieldsRequested) > 0)
            {
                FQDN = fields[fieldIndex++];
                if (!Hostinfo.ValidateFQDN(FQDN, out errorMessage))
                {
                    result = false;
                    Logger.Log("GetMachineInfoDelegate: invalid FQDN: " + errorMessage, Logger.manageLogLevel);
                }
                else
                {
                    _hn.domainName = FQDN;
                    Logger.Log("GetMachineInfoDelegate: assigned FQDN:\n" + _hn.ToString(), Logger.manageLogLevel);
                }
            }

            if (result && ((uint)Hostinfo.FieldBitmaskBits.FQ_DCNAME & fieldsRequested) > 0)
            {
                fullyQualifiedDCName = fields[fieldIndex++];
                if (!Hostinfo.ValidateFullyQualifiedDCName(fullyQualifiedDCName, out errorMessage))
                {
                    result = false;
                    Logger.Log("GetMachineInfoDelegate: invalid FQ_DCNAME: " + errorMessage, Logger.manageLogLevel);
                }
                else if (String.IsNullOrEmpty(_hn.hostName))
                {
                    _hn.domainControllerName = fullyQualifiedDCName;
                    Logger.Log("GetMachineInfoDelegate: assigned FQ_DCNAME:\n" + _hn.ToString(), Logger.manageLogLevel);
                }
            }

            if (result && ((uint)Hostinfo.FieldBitmaskBits.CREDS_NT4DOMAIN & fieldsRequested) > 0)
            {
                shortDomainName = fields[fieldIndex++];
                if (!Hostinfo.ValidateShortDomainName(shortDomainName, out errorMessage))
                {
                    result = false;
                    Logger.Log("GetMachineInfoDelegate: invalid CREDS_NT4DOMAIN: " + errorMessage, Logger.manageLogLevel);
                }
                else
                {
                    _hn.creds.Domain = shortDomainName;
                    Logger.Log("GetMachineInfoDelegate: assigned CREDS_NT4DOMAIN:\n" + _hn.ToString(), Logger.manageLogLevel);
                }
            }

            if (result && ((uint)Hostinfo.FieldBitmaskBits.CREDS_USERNAME & fieldsRequested) > 0)
            {
                userName = fields[fieldIndex++];
                if (!Hostinfo.ValidateUserName(userName, out errorMessage))
                {
                    result = false;
                    Logger.Log("GetMachineInfoDelegate: invalid CREDS_USERNAME: "******"GetMachineInfoDelegate: assigned CREDS_USERNAME:\n" + _hn.ToString(), Logger.manageLogLevel);
                }
            }

            if (result && ((uint)Hostinfo.FieldBitmaskBits.CREDS_PASSWORD & fieldsRequested) > 0)
            {
                password = fields[fieldIndex++];
                if (!Hostinfo.ValidatePassword(password, password, out errorMessage))
                {
                    result = false;
                    Logger.Log("GetMachineInfoDelegate: invalid CREDS_PASSWORD: "******"GetMachineInfoDelegate: assigned CREDS_PASSWORD:\n" + _hn.ToString(), Logger.manageLogLevel);
                }
            }

            if (!result)
            {
                sc.ShowError(errorMessage);
                return false;
            }

            _hn.creds.MachineName = _hn.hostName;

            if (String.IsNullOrEmpty(_hn.domainControllerName) &&
              !String.IsNullOrEmpty(_hn.domainName))
            {
                try
                {
                    CNetlogon.LWNET_DC_INFO DCInfo;
                    uint netlogonError = CNetlogon.GetDCName(_hn.domainName, 0, out DCInfo);
                    if (netlogonError == 0 && !String.IsNullOrEmpty(DCInfo.DomainControllerName))
                    {
                        _hn.domainControllerName = DCInfo.DomainControllerName;
                        if (String.IsNullOrEmpty(_hn.creds.Domain))
                        {
                            _hn.creds.Domain = DCInfo.NetBIOSDomainName;
                        }
                    }
                    else
                    {
                        _hn.domainControllerName = _hn.domainName;
                    }
                    if (netlogonError == 0 && !String.IsNullOrEmpty(DCInfo.NetBIOSDomainName))
                    {
                        if (shortDomainName != null)
                        {
                            if (!shortDomainName.Trim().ToUpper().Equals(DCInfo.NetBIOSDomainName.Trim().ToUpper()))
                            {
                                errorMessage = "Invalid NT4-Style Domain Name";

                                sc.ShowError(errorMessage);
                                return false;
                            }
                        }
                        else
                        {
                            _hn.creds.Domain = DCInfo.NetBIOSDomainName;
                        }
                    }
                }
                catch(Exception ex)
                {
                    Logger.Log("Exception occured while getting DCInfo ," + ex.Message);
                    return false;
                }
            }

            SaveTargetMachineInfoToIni(_hn);

            getTargetMachineRequestor.SetContext(_hn);

            if (_hn.IsConnectionSuccess == false)
            {
                return false;
            }

            return true;
        }
        // <summary>
        // This method queries the indicated server and sets up various data in the Hostinfo structure.
        // It also establishes a set of working credentials for the machine
        // </summary>
        // <returns>FALSE if unable to manage the machine</returns>
        private void GetMachineInfo()
        {
            Hostinfo hn = ctx as Hostinfo;
            Logger.Log(String.Format(
            "GetMachineInfo called for EventViewerControl.  hn: {0}",
            !Hostinfo.HasCreds(hn) ? "empty" : hn.hostName),
            Logger.manageLogLevel);

            Hostinfo defaultHostInfo = null;

            //if Hostinfo is empty, attempt to retrieve details using kerberos
            if (!Hostinfo.HasCreds(hn))
            {
                defaultHostInfo = new Hostinfo();
            }
            else
            {
                defaultHostInfo = hn.Clone();
            }

            uint requestedFields = (uint)Hostinfo.FieldBitmaskBits.FQ_HOSTNAME;

            if (!this.container.GetTargetMachineInfo(this.pi, defaultHostInfo, requestedFields))
            {
                Logger.Log(
                "Could find information about target machine",
                Logger.netAPILogLevel);
                //hn = null;
            }

            lblCaption.Text = string.Format("EventViewer for {0}", hn.hostName);
        }
        /// <summary>
        /// Shows the Manage form and directs it at a particular
        /// machine.
        /// </summary>
        /// <param name="sHostname">The machine to manage</param>
        /// <param name="viewStyle">The style of list view to use, if a listview is used</param>
        /// <returns>TRUE if was able to manage the given machine. FALSE if a
        ///          network or credential error occured. </returns>
        public bool ManageHost(string sHostname, StandardPage.ViewStyle viewStyle)
        {

            // first, normalize the incoming hostname
            Hostinfo hn = new Hostinfo(sHostname);

            // now, set the host type
            if (!CheckHostInfo(hn))
            {

                string sMsg = string.Format(Resources.Error_InvalidComputerType, sHostname);
                ShowError(sMsg, MessageBoxButtons.OK);
                return false;
            }

            // do this first so that we can do any slow stuff before we start
            // changing pages
            if (!controlManage.ManageHost(hn))
                return false;

            SetViewStyle(viewStyle);

            // show the management control
            ShowManage();

            string str = String.Format(Resources.Connected_As,
                                       hn.creds.UserName,
                                       hn.hostName);

            controlManage.SetStatusMesaage(str, 1);

            return true;
        }
Beispiel #24
0
        public static bool HasCreds(Hostinfo hn)
        {

            if (hn == null ||
                hn.creds == null ||
                CredentialEntry.IsNullOrEmpty(hn.creds))
            {
                return false;
            }
            else
            {
                return true;
            }

        }
Beispiel #25
0
        private bool GetTargetMachineInfoHostInfo(IPlugIn requestor, Hostinfo hn, uint fieldsRequested)
        {
            string caption = "Set Target Machine";
            string groupBoxCaption = requestor.GetName();
            string[] descriptions, hints, fieldContents;
            int numFields = 0;
            int fieldIndex = 0;
            int securityFieldIndex = 0;
            bool okWithoutModify = true;
            uint fieldsFilled = 0;

            Logger.Log(String.Format("Manage.GetTargetMachineInfo: requestor: {0} fields: 0x{1:x}",
                requestor == null ? "null" : requestor.GetName(),
                fieldsRequested),
                Logger.manageLogLevel);

            getTargetMachineRequestor = requestor;

            if (fieldsRequested == Hostinfo.FieldBitmaskBits.FQDN)
            {
                requestor.SetSingleSignOn(true);
            }

            if (hn == null)
            {
                hn = new Hostinfo();
            }

            if (String.IsNullOrEmpty(hn.creds.Domain) && !String.IsNullOrEmpty(System.Environment.UserDomainName))
            {
                hn.creds.Domain = System.Environment.UserDomainName;
                fieldsFilled |= (uint)Hostinfo.FieldBitmaskBits.CREDS_NT4DOMAIN;
            }

            if (String.IsNullOrEmpty(hn.creds.UserName) && !String.IsNullOrEmpty(System.Environment.UserName))
            {
                hn.creds.UserName = System.Environment.UserName;
                fieldsFilled |= (uint)Hostinfo.FieldBitmaskBits.CREDS_USERNAME;
            }

            if (String.IsNullOrEmpty(hn.hostName) && !String.IsNullOrEmpty(System.Environment.MachineName))
            {
                hn.hostName = System.Environment.MachineName;
                hn.creds.MachineName = System.Environment.MachineName;
                fieldsFilled |= (uint)Hostinfo.FieldBitmaskBits.SHORT_HOSTNAME;
            }

            try
            {
                if (!GetConnectionInfoFromNetlogon(requestor, hn, fieldsRequested, out fieldsFilled))
                {
                    bSSOFailed = true;
                }
                else
                {
                    //if all fields requested were filled
                    if ((fieldsRequested & (~fieldsFilled)) == 0 ||
                        (fieldsRequested & (~fieldsFilled)) == 4)
                    {
                        Logger.Log(String.Format(
                            "GetConnectionInfoFromNetlogon: requested: {0}  filled: {1}  hn: {2}",
                            fieldsRequested, fieldsFilled, hn.ToString()), Logger.manageLogLevel);

                        if (((uint)Hostinfo.FieldBitmaskBits.FORCE_USER_PROMPT & fieldsRequested) == 0)
                        {
                            requestor.SetContext(hn);
                            if (hn.IsConnectionSuccess)
                            {
                                return true;
                            }
                            else
                            {
                                bSSOFailed = true;
                                requestor.SetSingleSignOn(false);
                            }
                        }
                    }
                }

                if (bSSOFailed)
                {
                    bSSOFailed = false;
                    Configurations.SSOFailed = true;

                    string errMsg = "Single sign-on failed.  Please make sure you have joined the domain," +
                              "and that you have cached kerberos credentials on your system.  " +
                              "Click OK for manual authentication.";
                    sc.ShowError(errMsg);

                    return false;
                }

                //this won't overwrite existing values in hn.
                GetConnectedHostInfoFromIni(requestor, hn);

                if (((uint)Hostinfo.FieldBitmaskBits.SHORT_HOSTNAME & fieldsRequested) > 0) { numFields++; }
                if (((uint)Hostinfo.FieldBitmaskBits.FQ_HOSTNAME & fieldsRequested) > 0) { numFields++; }
                if (((uint)Hostinfo.FieldBitmaskBits.FQDN & fieldsRequested) > 0) { numFields++; }
                if (((uint)Hostinfo.FieldBitmaskBits.FQ_DCNAME & fieldsRequested) > 0) { numFields++; }
                if (((uint)Hostinfo.FieldBitmaskBits.CREDS_NT4DOMAIN & fieldsRequested) > 0) { numFields++; }
                if (((uint)Hostinfo.FieldBitmaskBits.CREDS_USERNAME & fieldsRequested) > 0) { numFields++; }
                if (((uint)Hostinfo.FieldBitmaskBits.CREDS_PASSWORD & fieldsRequested) > 0) { numFields++; }

                descriptions = new string[numFields];
                hints = new string[numFields];
                fieldContents = new string[numFields];

                if (((uint)Hostinfo.FieldBitmaskBits.SHORT_HOSTNAME & fieldsRequested) > 0)
                {
                    descriptions[fieldIndex] = "Short Hostname";
                    fieldContents[fieldIndex] = hn.shortName;
                    hints[fieldIndex++] = "ex: mycomputer";
                }

                if (((uint)Hostinfo.FieldBitmaskBits.FQ_HOSTNAME & fieldsRequested) > 0)
                {
                    descriptions[fieldIndex] = "Fully Qualified Hostname";
                    fieldContents[fieldIndex] = hn.hostName;
                    hints[fieldIndex++] = "ex: mycomputer.mycorp.com";
                }

                if (((uint)Hostinfo.FieldBitmaskBits.FQDN & fieldsRequested) > 0)
                {
                    descriptions[fieldIndex] = "Fully Qualified Domain Name";
                    fieldContents[fieldIndex] = hn.domainName;
                    hints[fieldIndex++] = "ex: mycorp.com";
                }

                if (((uint)Hostinfo.FieldBitmaskBits.FQ_DCNAME & fieldsRequested) > 0)
                {
                    descriptions[fieldIndex] = "Domain Controller FQDN";
                    fieldContents[fieldIndex] = hn.domainControllerName;
                    hints[fieldIndex++] = "ex: dc-2.mycorp.com";
                }

                if (((uint)Hostinfo.FieldBitmaskBits.CREDS_NT4DOMAIN & fieldsRequested) > 0)
                {
                    descriptions[fieldIndex] = "NT4-style Domain Name";
                    fieldContents[fieldIndex] = hn.creds.Domain;
                    hints[fieldIndex++] = "ex: CORP";
                }

                if (((uint)Hostinfo.FieldBitmaskBits.CREDS_USERNAME & fieldsRequested) > 0)
                {
                    descriptions[fieldIndex] = "Username";
                    fieldContents[fieldIndex] = hn.creds.UserName;
                    hints[fieldIndex++] = "ex: flastname3";
                }

                if (((uint)Hostinfo.FieldBitmaskBits.CREDS_PASSWORD & fieldsRequested) > 0)
                {
                    securityFieldIndex = fieldIndex;
                    fieldContents[fieldIndex] = hn.creds.Password;
                    descriptions[fieldIndex] = "Password";
                    hints[fieldIndex++] = "";
                }

                StringRequestDialog dlg = new StringRequestDialog(
                    GetMachineInfoDelegate,
                    caption,
                    groupBoxCaption,
                    descriptions,
                    hints,
                    fieldContents,
                    (UInt32)fieldsRequested);

                dlg.allowOKWithoutModify = okWithoutModify;
                if (securityFieldIndex > 0)
                {
                    dlg.SetSecurityStatus(securityFieldIndex, true);
                }

                dlg.ShowDialog();

                if(!dlg.bDialogResult)
                {
                    hn.IsConnectionSuccess = false;
                    return false;
                }
            }
            catch
            {
                hn.IsConnectionSuccess = false;
                return true;
            }

            return true;
        }
Beispiel #26
0
 public WorkerInfo(Hostinfo hi)
 {
     this.hi = hi;
 }
Beispiel #27
0
 /// <summary>
 /// If HostInfo is not null,lists the all child nodes on click of any node in left hand pane of ADUC
 /// </summary>
 /// <param name="parentNode"></param>
 public void EnumChildren(LACTreeNode parentNode)
 {
     Logger.Log("ADUCPlugin.EnumChildren", Logger.manageLogLevel);
     
     if (!Hostinfo.HasCreds(_hn))
     {
         //attempt to retrieve host info information from kerberos
         Hostinfo defaultHostInfo = new Hostinfo();
         
         //assume for now that the AD hostname is the same as the LDAP domain
         defaultHostInfo.creds.MachineName = defaultHostInfo.domainName;
         defaultHostInfo.hostName = defaultHostInfo.domainName;
         
         Logger.Log(defaultHostInfo.domainName, Logger.manageLogLevel);
         
         //LDAP is not yet kerberized, so set password to null to make sure the user gets prompted
         defaultHostInfo.creds.Password = null;
     }
 }
Beispiel #28
0
        private static void Main(string[] args)
        {
           // LdapTest.testing();

            string sConsoleFile = null;

            if (args.Length == 1 && !args[0].StartsWith("--"))
                sConsoleFile = args[0];

            // Enable themes
            Application.EnableVisualStyles();

            // Set the user interface to display in the
            // same culture as that set in Control Panel.
            Thread.CurrentThread.CurrentUICulture =
                Thread.CurrentThread.CurrentCulture;

            try
            {
                // process command line args
                if (args.Length>0 && args[0].StartsWith("--"))
                    parseCommandLineArgs(args, out sConsoleFile);

                if (Configurations.currentPlatform == LikewiseTargetPlatform.Unknown) {
                    Configurations.determineTargetPlatform();
                }
                Configurations.setPlatformFeatures();
                Configurations.verifyEnvironment();

                Logger.Log("Likewise Management Console started");
                Logger.Log("Current LogLevel = " + Logger.currentLogLevel);

                //make sure a local, persistent, user-writeable data path exists.
                if (! System.IO.Directory.Exists(Application.UserAppDataPath))
                {
                    System.IO.Directory.CreateDirectory(Application.UserAppDataPath);
                }

                Hostinfo hnTemp = new Hostinfo();

                // create a mainform, show it and peg it
                LMCMainForm mf = new LMCMainForm(sConsoleFile);

                // Display the real form
                mf.TopLevel = true;
                mf.Show();

                // hide the splash window since we're getting ready to show a real one
                mf.Activate();

                // start running
                Application.Run(mf);
            }
            catch (ShowUsageException)
            {
            }
            catch (DllNotFoundException ex)
            {
                Logger.LogMsgBox(String.Format(
                    "Likewise Management Console encountered a fatal error: Could not find DLL: {0}",
                    ex.Message));
                Logger.Log(String.Format("EXCEPTION (caught in LMCAppMain.cs): \n{0}",
                     ex), Logger.LogLevel.Panic);
            }
            catch (Exception ex)
            {
                int ex_id = 0;
                MessageBox.Show("Likewise Management Console encountered a fatal error.",
                    CommonResources.GetString("Caption_Console"),
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Logger.Log(String.Format("EXCEPTION #{0} (caught in LMCAppMain.cs): \n{1}",
                    ex_id++, ex), Logger.LogLevel.Panic);

                for (Exception in_ex = ex.InnerException; in_ex != null; in_ex = in_ex.InnerException)
                {
                    Logger.Log(String.Format(
                        "\n\nEXCEPTION #{0}: \n{1}", ex_id++, in_ex), Logger.LogLevel.Panic);
                }
            }

            //Only in the debug build, make sure all the unmanaged objects have been freed
#if DEBUG
            Likewise.LMC.Utilities.DebugMarshal.CheckAllFreed();
#endif

            return;
        }
        public void SetContext(
            IContext ctx
            )
        {
            Hostinfo hn = ctx as Hostinfo;

            if (_pluginNode != null &&
                _pluginNode.Nodes != null &&
                _hn != null &&
                hn != null &&
                hn.hostName !=
                _hn.hostName)
            {
                foreach (TreeNode node in _pluginNode.Nodes)
                {
                    _pluginNode.Nodes.Remove(node);
                }
            }

            _hn = hn;

            if (HostInfo == null)
            {
                _hn = new Hostinfo();
            }

            if (_pluginNode != null && _pluginNode.Nodes.Count == 0)
            {
                BuildNodesToPlugin();
            }

            if (_pluginNode != null)
            {
                _pluginNode.SetContext(_hn);
            }
        }
Beispiel #30
0
        public static void DeserializeHostInfo(XmlNode node, ref LACTreeNode pluginNode, string nodepath, ref Hostinfo hn, bool bIsGPOPlugin)
        {
            XmlNode hostnode = node.SelectSingleNode("HostInfo");

            if (hostnode == null) return;

            if (hn == null)
                hn = new Hostinfo();

            foreach (XmlNode child in hostnode.ChildNodes)
            {
                if (child.Name.Trim().Equals("DomainFQDN"))
                {
                    hn.domainName = child.InnerXml;
                    hn.domainControllerName = child.InnerXml;
                    // split the provided name into parts
                    string[] aparts = child.InnerXml.Split(new char[] { '.' });
                    hn.creds.Domain = aparts[0];
                }
                else if (child.Name.Trim().Equals("DomainShort"))
                {
                    hn.shortName = child.InnerXml;
                }
                else if (child.Name.Trim().Equals("HostName"))
                {
                    hn.hostName = child.InnerXml;
                }
                else if (child.Name.Trim().Equals("UserName"))
                {
                    hn.creds.UserName = child.InnerXml;
                }
                else if (bIsGPOPlugin && child.Name.Trim().Equals("GPOInfo"))
                {
                    string sDN = null;
                    string sDisplayname = null;
                    foreach (XmlNode gpoNode in child.ChildNodes)
                    {
                        if (gpoNode.Name.Trim().Equals("GPODistinguishedName"))
                        {
                            sDN = gpoNode.InnerXml;
                        }
                        else if (gpoNode.Name.Trim().Equals("GPODisplayName"))
                        {
                            sDisplayname = gpoNode.InnerXml;
                        }
                    }
                    GPObjectInfo gpoInfo = new GPObjectInfo(null, sDN, sDisplayname);
                    hn.Tag = gpoInfo;
                }
            }
            pluginNode.Tag = hn;
        }
Beispiel #31
0
        public bool GetConnectionInfoFromNetlogon(
                        IPlugIn requestor,
                        Hostinfo hn,
                        uint fieldsRequested,
                        out uint fieldsFilled)
        {
            uint error = 0;

            fieldsFilled = 0;
            bool result = true;

            Logger.Log("Manage.GetConnectionInfoFromNetlogon");

            if (!String.IsNullOrEmpty(hn.domainName))
            {
                return result;
            }

            error = CNetlogon.GetCurrentDomain(out hn.domainName);

            if (error == 0 && !String.IsNullOrEmpty(hn.domainName))
            {
                fieldsFilled |= (uint)Hostinfo.FieldBitmaskBits.FQDN;
                CNetlogon.LWNET_DC_INFO DCInfo;

                uint netlogonError = CNetlogon.GetDCName(hn.domainName, 0, out DCInfo);

                if (netlogonError == 0)
                {
                    if (!String.IsNullOrEmpty(DCInfo.DomainControllerName))
                    {
                        hn.domainControllerName = DCInfo.DomainControllerName;
                        fieldsFilled |= (uint)Hostinfo.FieldBitmaskBits.FQ_DCNAME;
                    }

                    if (!String.IsNullOrEmpty(DCInfo.NetBIOSDomainName))
                    {
                        hn.creds.Domain = DCInfo.NetBIOSDomainName;
                        fieldsFilled |= (uint)Hostinfo.FieldBitmaskBits.CREDS_NT4DOMAIN;
                    }
                    if (!String.IsNullOrEmpty(DCInfo.FullyQualifiedDomainName))
                    {
                        hn.domainName = DCInfo.FullyQualifiedDomainName;
                        fieldsFilled |= (uint)Hostinfo.FieldBitmaskBits.FQDN;
                    }
                }
                else
                {
                    hn.domainControllerName = hn.domainName;
                    result = false;
                }
            }

            Logger.Log(String.Format(
                "Manage.GetConnectionInfoFromNetlogon returning {0}",
                result),
                Logger.manageLogLevel);

            return result;

        }
Beispiel #32
0
        public static void CreateAppendHostInfoElement(Hostinfo hn, ref XmlElement parentElement, out XmlElement HostInfoElement)
        {
            HostInfoElement = parentElement.OwnerDocument.CreateElement("HostInfo");

            if (hn == null)
                return;

            XmlElement DomainShortEle, DomainFQDNEle, HostnameEle, usernameEle;

            if (!String.IsNullOrEmpty(hn.domainName))
            {
                DomainFQDNEle = HostInfoElement.OwnerDocument.CreateElement("DomainFQDN");
                DomainFQDNEle.InnerXml = hn.domainName;
                HostInfoElement.AppendChild(DomainFQDNEle);
            }
            if (!String.IsNullOrEmpty(hn.shortName))
            {
                DomainShortEle = HostInfoElement.OwnerDocument.CreateElement("DomainShort");
                DomainShortEle.InnerXml = hn.shortName;
                HostInfoElement.AppendChild(DomainShortEle);
            }
            if (!String.IsNullOrEmpty(hn.hostName))
            {
                HostnameEle = HostInfoElement.OwnerDocument.CreateElement("HostName");
                HostnameEle.InnerXml = hn.hostName;
                HostInfoElement.AppendChild(HostnameEle);
            }
            if (!String.IsNullOrEmpty(hn.creds.UserName))
            {
                usernameEle = HostInfoElement.OwnerDocument.CreateElement("UserName");
                usernameEle.InnerXml = hn.creds.UserName;
                HostInfoElement.AppendChild(usernameEle);
            }

            parentElement.AppendChild(HostInfoElement);
        }
    private void cm_OnConnect(object sender, EventArgs e)
    {
        //check if we are joined to a domain -- if not, use simple bind
        uint requestedFields = (uint)Hostinfo.FieldBitmaskBits.FQ_HOSTNAME;
        //string domainFQDN = null;

        if (_hn == null)
        {
            _hn = new Hostinfo();
        }

        //TODO: kerberize eventlog, so that creds are meaningful.
        //for now, there's no reason to attempt single sign-on
        requestedFields |= (uint)Hostinfo.FieldBitmaskBits.FORCE_USER_PROMPT;


        if (_hn != null)
        {
            if (!_container.GetTargetMachineInfo(this, _hn, requestedFields))
            {
                Logger.Log(
                "Could not find information about target machine",
                Logger.eventLogLogLevel);
                if (eventLogHandle != null)
                    _hn.IsConnectionSuccess = true;
            }
            else
            {
                if (_pluginNode != null && !String.IsNullOrEmpty(_hn.hostName))
                {
                    logs = null;

                    if (eventLogHandle == null)
                    {
                        _container.ShowError("Unable to open the event log; eventlog server may be disabled");
                        _pluginNode.sc.ShowControl(_pluginNode);
                    }
                }
            }
        }
    }
Beispiel #34
0
        public string GetDomainName()
        {
            if (_hn == null || _hn.domainName == null || _hn.domainName == "")
            {
                _hn = new Hostinfo();

                if (sLDAPPath != null && sLDAPPath != "")
                {
#if !QUARTZ
                    string protocol, server, cn, dc;
                    Util.CrackPath(sLDAPPath, out protocol, out server, out cn, out dc);
                    _hn.domainName = Util.DNToDomainName(dc);
#endif
                }
            }

            return _hn.domainName;
        }