예제 #1
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;
        }