コード例 #1
0
        /// <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();
        }
コード例 #2
0
        private static bool IsConnectSetBefore(IPlugIn requestor)
        {
            bool IsSetBefore = false;
            bool IsFileExists = !string.IsNullOrEmpty(sCredentialsFilePath) && Path.IsPathRooted(sCredentialsFilePath) && File.Exists(sCredentialsFilePath);

            if (!IsFileExists)
                return IsSetBefore;

            StreamReader reader = new StreamReader(sCredentialsFilePath);

            if (!reader.EndOfStream)
            {
                string fileContent = reader.ReadToEnd();
                if (fileContent != null && fileContent.Trim().Contains(requestor.GetName())) {
                    IsSetBefore = true;
                }
            }
            reader.Close();

            return IsSetBefore;
        }
コード例 #3
0
        private static bool IsConnectSetBefore(IPlugIn requestor)
        {
            bool IsSetBefore  = false;
            bool IsFileExists = !string.IsNullOrEmpty(sCredentialsFilePath) && Path.IsPathRooted(sCredentialsFilePath) && File.Exists(sCredentialsFilePath);

            if (!IsFileExists)
            {
                return(IsSetBefore);
            }

            StreamReader reader = new StreamReader(sCredentialsFilePath);

            if (!reader.EndOfStream)
            {
                string fileContent = reader.ReadToEnd();
                if (fileContent != null && fileContent.Trim().Contains(requestor.GetName()))
                {
                    IsSetBefore = true;
                }
            }
            reader.Close();

            return(IsSetBefore);
        }
コード例 #4
0
        /// <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);
            }
        }
コード例 #5
0
        /// <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();
        }
コード例 #6
0
        /// <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);
            }
        }
コード例 #7
0
ファイル: Manage.cs プロジェクト: numberer6/likewise-open-1
        /// <summary>
        /// Gets the current plugin name
        /// </summary>
        /// <param name="requestor"></param>
        /// <returns></returns>
        private string GetPlugInName(IPlugIn requestor)
        {
            string sPlugInName = requestor.GetName();

            switch (sPlugInName.Trim())
            {
                case "Active Directory Users & Computers":
                    sPlugInName = "[ADUC]";
                    break;
                case "Local Users and Groups":
                    sPlugInName = "[LUG]";
                    break;
                case "File and Print":
                    sPlugInName = "[File and Print]";
                    break;
                case "Likewise Cell Manager":
                    sPlugInName = "[Likewise Cell Manager]";
                    break;
                case "Event Viewer":
                    sPlugInName = "[Event Viewer]";
                    break;
                case "Group Policy Management":
                    sPlugInName = "[GPMC]";
                    break;
                case "Group Policy Object Editor":
                    sPlugInName = "[GPOE]";
                    break;
            }
            return sPlugInName;
        }
コード例 #8
0
ファイル: Manage.cs プロジェクト: numberer6/likewise-open-1
        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;
        }