public void TestGetCredential()
        {
            // Arrange
            string            expectedNamespace   = "LegacyGeneric";
            string            expectedAttribute   = "target";
            string            expectedTargetAlias = string.Empty;
            string            expectedTargetName  = "Unit Test Demo";
            CredentialType    expectedType        = CredentialType.Generic;
            CredentialPersist expectedPersist     = CredentialPersist.LocalMachine;
            string            expectedUsername    = "******";
            string            expectedPassword    = "******";
            PSCredential      expectedCredential  = new PSCredential(expectedUsername, CredentialHelper.StringToSecureString(expectedPassword));

            // Act
            CredentialEntry actualCredentialEntry = CredentialStore.GetCredential(expectedTargetName, expectedType);

            // Assert
            Assert.AreEqual(expectedNamespace, actualCredentialEntry.Namespace);
            Assert.AreEqual(expectedAttribute, actualCredentialEntry.Attribute);
            Assert.AreEqual(expectedTargetAlias, actualCredentialEntry.TargetAlias);
            Assert.AreEqual(expectedTargetName, actualCredentialEntry.TargetName);
            Assert.AreEqual(expectedType, actualCredentialEntry.Type);
            Assert.AreEqual(expectedPersist, actualCredentialEntry.Persist);
            Assert.AreEqual(expectedUsername, actualCredentialEntry.Credential.UserName);
            Assert.AreEqual(expectedPassword, actualCredentialEntry.Credential.GetNetworkCredential().Password);
        }
示例#2
0
        private bool ProcessMembers(CredentialEntry ce, string domain)
        {
            bool retVal = true;
            uint result = (uint)LUGAPI.WinError.ERROR_SUCCESS;

            for (int i = 0; i < lvMembers.Items.Count; i++)
            {
                try
                {
                    result = LUGAPI.NetAddGroupMember(
                        _hn.hostName,
                        this.GroupName,
                        lvMembers.Items[i].Text
                        );

                    if (result != (uint)LUGAPI.WinError.ERROR_SUCCESS)
                    {
                        container.ShowError(String.Format(
                                                "User \"{0}\" could not be added:\n{1}",
                                                lvMembers.Items[i].Text,
                                                ErrorCodes.WIN32String((int)result)));
                    }
                }
                catch (Exception)
                {
                    retVal = false;
                    container.ShowError(
                        String.Format("Failed to add user {0} to group {1}", lvMembers.Items[i].Text, this.GroupName));
                }
            }
            return(retVal);
        }
示例#3
0
        public static void DeleteShare(IntPtr handle_b, CredentialEntry ce, string sHostname, string sShareName)
        {
            // establish null session
            Session.EnsureNullSession(sHostname, ce);

            try
            {
                int nret = -1;

                Logger.Log(String.Format("NetShareDel(sHostname={0} ,sShareName={1}) called",
                                         sHostname, sShareName), Logger.FileShareManagerLogLevel);

                if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                {
                    nret = NetShareDel(sHostname, sShareName, 0);
                }
                else
                {
                    nret = NetShareDel(handle_b, sHostname, sShareName, 0);
                }

                Logger.Log(String.Format(
                               "NetShareDel(); result={0}",
                               nret));
            }
            catch (Win32Exception we)
            {
                throw new LikewiseAPIException(we);
            }
        }
示例#4
0
        /// <summary>
        /// Gets all groups for the selected user AD Object is member of
        /// Add groups to the Member Of page listview
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="dirnode"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            _servername = servername;
            _dirnode    = dirnode;

            try
            {
                string[] groupDns = UserGroupUtils.GetGroupsforUser(dirnode);

                MemoflistView.Items.Clear();
                //show a list of group names in the member of page
                Logger.Log("user member of contains: ");
                if (groupDns != null && groupDns.Length > 0)
                {
                    //populate the data in usermemberOf page using groupDns
                    foreach (string groupDn in groupDns)
                    {
                        Logger.Log("group: " + groupDn);
                        //CN=Domain Users,CN=Users,DC=qadom,DC=centeris,DC=com
                        // split the groupDns
                        string[]       slvItem   = UserGroupUtils.splitDn(groupDn);
                        string         sLDAPPath = string.Format("LDAP://{0}/{1}", _dirnode.LdapContext.DomainName, groupDn);
                        DirectoryEntry entry     = new DirectoryEntry(sLDAPPath, _dirnode.LdapContext.UserName, _dirnode.LdapContext.Password);
                        if (entry == null)
                        {
                            return;
                        }
                        ListViewItem lvItem = new ListViewItem(slvItem);
                        lvItem.ImageIndex = MemOfPages.GetIndexForADObject(entry);
                        MemoflistView.Items.Add(lvItem);
                        lvItem.Tag = groupDn;

                        if (!slvItem[0].Equals("Domain Users", StringComparison.InvariantCultureIgnoreCase))
                        {
                            MemofDnList.Add(groupDn);
                        }
                    }
                    //settings primary group to user
                    sPrimayGroup = UserGroupUtils.GetPrimaryGroup(_dirnode);
                    string[] Items = UserGroupUtils.splitDn(sPrimayGroup);
                    if (!string.IsNullOrEmpty(Items[0]))
                    {
                        DomainUserlabel.Text = Items[0];
                    }

                    if (MemoflistView.Items.Count > 0)
                    {
                        MemoflistView.Items[0].Selected = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException("UserMemberOfPage.SetData", ex);
            }
        }
示例#5
0
        /// <summary>
        /// Queries and fills the ldap message for the selected group
        /// Gets the attribute list from AD for group schema attribute.
        /// search for the attributes description, cn or name and displays them in a controls
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="dirnode"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            try
            {
                this.dirnode = dirnode;

                DirectoryContext dirContext = dirnode.LdapContext;

                //first obtain the current userAccountControl value
                DirectoryEntry de = new DirectoryEntry(string.Format("LDAP://{0}/{1}", dirContext.DomainName, dirnode.DistinguishedName));

                profilePath   = de.Properties["profilePath"].Value as string;
                scriptPath    = de.Properties["scriptPath"].Value as string;
                homeDirectory = de.Properties["homeDirectory"].Value as string;
                homeDrive     = de.Properties["homeDrive"].Value as string;

                foreach (string ch in Charlist)
                {
                    cbDrive.Items.Add(ch);
                }

                if (homeDrive != null)
                {
                    rbConnect.Checked = true;
                    txtConnect.Text   = homeDirectory;
                    int selectedIndex = 0;
                    if (cbDrive.Items.Contains(homeDrive))
                    {
                        selectedIndex = cbDrive.Items.IndexOf(homeDrive);
                    }
                    else
                    {
                        selectedIndex = cbDrive.Items.Add(homeDrive);
                    }
                    cbDrive.SelectedIndex = selectedIndex;
                }
                else
                {
                    rbLocalPath.Checked   = true;
                    txtLocalPath.Text     = homeDirectory;
                    cbDrive.SelectedIndex = 0;
                }

                txtProfilePath.Text = profilePath;
                txtLogonScript.Text = scriptPath;

                ParentContainer.DataChanged = false;

                ParentContainer.btnApply.Enabled = false;
            }
            catch (Exception e)
            {
                Logger.LogException("UserGeneralEditPage.SetData", e);
            }
        }
示例#6
0
 /// <summary>
 ///
 /// </summary>
 public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
 {
     try
     {
         this.dirnode = dirnode;
         SetControlStatus();
     }
     catch (Exception e)
     {
         Logger.LogException("UserMultiEditPage.SetData", e);
     }
 }
示例#7
0
        public void SetData(CredentialEntry ce, string servername, string group)
        {
            _servername = servername;
            _group      = group;

            Text = String.Format(Text, group);

            foreach (MPPage page in GetPages())
            {
                IPropertiesPage ipp = page as IPropertiesPage;
                ipp.SetData(ce, servername, group);
            }
        }
示例#8
0
 public static bool HasCreds(Hostinfo hn)
 {
     if (hn == null ||
         hn.creds == null ||
         CredentialEntry.IsNullOrEmpty(hn.creds))
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
示例#9
0
        /// <summary>
        /// Queries and initializes the ldapMessage for the selected group
        /// Gets all users and groups those are members for selected group
        /// Fills the list with listview
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="dirnode"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            Dictionary <string, string> members = UserGroupUtils.GetGroupMembers(dirnode);

            foreach (string str in members.Keys)
            {
                OriginalObjects.Add(str);
                ModifiedObjects.Add(str.ToLower());
            }

            _dirnode = dirnode;

            MemoflistView.Items.Clear();
            //show a list of group names in the member of page
            Logger.Log("Group member contains: ");

            foreach (string sDN in members.Keys)
            {
                string[] slvItem = null;
                System.DirectoryServices.DirectoryEntry de = new System.DirectoryServices.DirectoryEntry(sDN, _dirnode.LdapContext.UserName, _dirnode.LdapContext.Password);
                if (members[sDN].Equals("foreignSecurityPrincipal"))
                {
                    byte[] objectSid = de.Properties["objectSid"].Value as byte[];
                    string Sid       = UserGroupUtils.SIDtoString(objectSid);
                    string cn        = UserGroupUtils.GetGroupFromForeignSecurity(Sid, dirnode.LdapContext);
                    if (cn != null)
                    {
                        slvItem = new string[] { cn, "NT AUTHORITY" };
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    slvItem = UserGroupUtils.splitDn(sDN);
                }
                ListViewItem lvItem = new ListViewItem(slvItem);
                lvItem.ImageIndex = MemOfPages.GetIndexForADObject(de);
                MemoflistView.Items.Add(lvItem);
                lvItem.Tag = sDN;
            }

            if (MemoflistView.Items.Count > 0)
            {
                MemoflistView.Items[0].Selected = true;
            }
        }
示例#10
0
        /// <summary>
        /// Constructor will attempt to populate all fields using the command klist (kerberos)
        /// </summary>
        public Hostinfo()
        {
            creds = new CredentialEntry();

            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                //this is commented out, since spinning off a new process
                //will under some circumstances result in an unhandled exception
                //within libdcerpc::rpc__timer_fork_handler which will bring down
                //the application in dcerpc/exc_handling::dce_ptdexc_abort
                //see bug# 4882
                //TODO: this should be re-written to use Kerberos API calls.
                //getUnixKerberosInfoFromKlist();
            }
        }
        /// <summary>
        /// Method to load data to the tab pages while loading
        /// Gets all the tab pages that are of type MPage and gets call the SetData()
        /// Queries the ldap message to the selected node
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="computer"></param>
        /// <param name="dirnode"></param>
        /// <param name="ldapSchemaCache"></param>
        public void SetData(CredentialEntry ce, string servername, string sOU, ADUCDirectoryNode dirnode, LDAPSchemaCache ldapSchemaCache)
        {
            Applied = false;
            _plugin = dirnode.Plugin as ADUCPlugin;

            objInfo = new ObjectPropertyInfo
                          (ce,
                          servername,
                          sOU,
                          dirnode,
                          null);

            threadMain = new Thread(new ThreadStart(AddPagesToThread));
            threadMain.Start();
        }
        /// <summary>
        /// initializes the Mandatory and Optional list objects with respect to the attribute types
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="node"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode node)
        {
            string initialSelectedAttrSyntax = "";

            if (_newAttributesList == null)
            {
                return;
            }

            foreach (AttributeInfo attrInfo in _newAttributesList.Values)
            {
                if (_objectAddDlg.objectInfo.htMandatoryAttrList != null && !_objectAddDlg.objectInfo.htMandatoryAttrList.Contains(attrInfo.sAttributename))
                {
                    if (attrInfo.sAttributeType.Equals("Mandatory", StringComparison.InvariantCultureIgnoreCase))
                    {
                        cbMandProperty.Add(attrInfo.sAttributename);
                        cbBothProperty.Add(attrInfo.sAttributename);
                    }
                    else if (attrInfo.sAttributeType.Equals("Optional", StringComparison.InvariantCultureIgnoreCase))
                    {
                        cbOptionProperty.Add(attrInfo.sAttributename);
                        cbBothProperty.Add(attrInfo.sAttributename);
                    }
                }
            }

            /*foreach (string Attr in _newAttributesList.Keys)
             * {
             *  if (_objectAddDlg.objectInfo.htMandatoryAttrList != null)
             *  {
             *      if (!_objectAddDlg.objectInfo.htMandatoryAttrList.Contains(Attr))
             *          cbProperty.Items.Add(Attr);
             *  }
             *  else
             *      cbProperty.Items.Add(Attr);
             * }*/

            {
                this.chooseMandOrOptionList();
            }

            initialSelectedAttrSyntax = _objectAddDlg.ClassAttributeList[0].AttributeSyntax;

            cbProOptionorMandatory.SelectedIndex = 1;
            lbClass.Text = _objectAddDlg.choosenClass;
        }
示例#13
0
        public static Process RunAddAShareWizard(CredentialEntry ce, string sHostname)
        {
            Process proc;

            try
            {
                Session.EnsureNullSession(sHostname, ce);
                proc = ProcessUtil.Exec(Environment.SystemDirectory, "shrpubw.exe", "/s " + sHostname);
            }
            catch (Exception ex)
            {
                Logger.LogException("SharesAPI.RunAddAShareWizard()", ex);
                proc = null;
            }

            return(proc);
        }
示例#14
0
        public LwioCopy(CredentialEntry creds, string localPath, string remotePath)
        {
            string sRealm = string.Empty;

            Logger.Log(String.Format(
                           "domain={0}, user={1}, localPath={2}, remotePath={3}",
                           creds.Domain,
                           creds.UserName,
                           localPath,
                           remotePath),
                       Logger.LWIOCopy);

            if (!Configurations.SSOFailed)
            {
                string UserID = DetermineUserID();

                sCredsPath = string.Format("/tmp/krb5cc_{0}", UserID);

                Environment.SetEnvironmentVariable("KRB5CCNAME", sCredsPath.Trim());
            }
            else
            {
                //int ret = Krb5CredsCache.BuildCredsContext(creds.UserName,
                //                                           creds.Password,
                //                                           creds.Domain,
                //                                           out CrdesCache);
                uint ret = Krb5CredsCache.Krb5GetDomainPrincipalRealm(creds.Domain, out sRealm);
                if (ret != 0)
                {
                    Logger.Log("Krb5CredsCache.Krb5GetDomainPrincipalRealm failed" + ret.ToString());
                }
                sUserUPN = string.Concat(creds.UserName.ToLower(), "@", String.IsNullOrEmpty(sRealm) ? creds.Domain.ToUpper() : sRealm.ToUpper());
            }

            this.cCreds = creds;

            if (!String.IsNullOrEmpty(this.cCreds.UserName) && this.cCreds.UserName.IndexOf(@"\") >= 0)
            {
                int ibackwhack = this.cCreds.UserName.LastIndexOf(@"\");
                this.cCreds.UserName = this.cCreds.UserName.Substring(ibackwhack + 1);
            }

            this.localPath  = localPath;
            this.remotePath = remotePath;
        }
        /// <summary>
        /// Method to load data to the tab pages while loading
        /// Gets all the tab pages that are of type MPage and gets calls the SetData()
        /// Queries the ldap message to the selected node
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="computer"></param>
        /// <param name="dirnode"></param>
        /// <param name="ldapSchemaCache"></param>
        public void SetData(CredentialEntry ce, string servername, string group, ADUCDirectoryNode dirnode, LDAPSchemaCache ldapSchemaCache)
        {
            Applied   = false;
            _plugin   = dirnode.Plugin as ADUCPlugin;
            this.Text = String.Format(this.Text, group);

            objInfo = new ObjectPropertyInfo(ce,
                                             servername,
                                             group,
                                             dirnode,
                                             null
                                             );

            threadMain = new Thread(new ThreadStart(AddPagesToThread));
            threadMain.Start();

            _plugin.Propertywindowhandles.Add(objInfo.dirnode.DistinguishedName, this);
        }
示例#16
0
        /// <summary>
        /// Method to load data to the tab pages while loading
        /// Gets all the tab pages that are of type MPage and gets calls the SetData()
        /// Queries the ldap message to the selected node
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="computer"></param>
        /// <param name="dirnode"></param>
        /// <param name="ldapSchemaCache"></param>
        public void SetData(CredentialEntry ce, string sharename, object shareInfo)
        {
            Applied = false;

            this.Text = String.Format(Text, sharename);

            ICollection pages = this.GetPages();

            foreach (MPPage page in pages)
            {
                if (page != null)
                {
                    IDirectoryPropertiesPage ipp = page as IDirectoryPropertiesPage;
                    if (ipp != null)
                    {
                        ipp.SetData(ce, sharename, shareInfo);
                    }
                }
            }
        }
示例#17
0
        public void SetData(CredentialEntry ce, string servername, string username)
        {
            _servername = servername;
            _username   = username;

            this.lbUser.Text = String.Format(this.lbUser.Text, username);

            try
            {
                LUGAPI.LUGInfo userInfo;

                if (LUGAPI.NetGetUserInfo(_servername, _username, out userInfo) == 0)
                {
                    GetUserInfoDelegate(userInfo);
                }
            }
            catch (Exception e)
            {
                Logger.LogException("EditUserPage.SetData", e);
            }
        }
        public void SetData(CredentialEntry ce, string sharename, object shareinfo)
        {
            try
            {
                if (shareinfo != null)
                {
                    string[] Shareinfo = shareinfo as string[];
                    if (Shareinfo != null)
                    {
                        this.textBoxSharename.Text = Shareinfo[1];
                        this.textBoxPath.Text      = Shareinfo[2];
                        this.textBoxComment.Text   = Shareinfo[3];
                        if (Shareinfo[5] == "-1")
                        {
                            radioButtonMaxAllowed.Checked = true;
                            radioButtonAllowedNum.Checked = false;
                        }
                        else
                        {
                            radioButtonAllowedNum.Checked = true;
                            radioButtonMaxAllowed.Checked = false;
                            numericUpDown.Enabled         = true;

                            this.numericUpDown.ValueChanged -= new System.EventHandler(this.numericUpDown_ValueChanged);
                            numericUpDown.Value              = Convert.ToDecimal(Shareinfo[5]);
                            this.numericUpDown.ValueChanged += new System.EventHandler(this.numericUpDown_ValueChanged);
                        }
                    }
                }

                this.ParentContainer.DataChanged      = false;
                this.ParentContainer.btnApply.Enabled = false;
            }
            catch (Exception e)
            {
                container.ShowError(e.Message);
            }
        }
示例#19
0
        public void SetData(CredentialEntry ce, string servername, string username)
        {
            Logger.Log(String.Format(
                           "UserPropertiesDlg.SetData({0}, {1}, {2}) called",
                           ce,
                           servername,
                           username),
                       Logger.netAPILogLevel);

            _servername = servername;
            _username   = username;

            this.Text = String.Format(this.Text, username);

            foreach (MPPage page in this.GetPages())
            {
                IPropertiesPage ipp = page as IPropertiesPage;
                if (ipp != null)
                {
                    ipp.SetData(ce, servername, username);
                }
            }
        }
示例#20
0
        public void SetData(CredentialEntry ce, string servername, string subjectname)
        {
            _servername  = servername;
            _subjectname = subjectname;

            this.tbDescription.Text = getSubjectDescription();

            string[] membersArr = getListMembers();

            members        = new Hashtable();
            membersAdded   = new Hashtable();
            membersDeleted = new Hashtable();

            if (membersArr != null)
            {
                foreach (string member in membersArr)
                {
                    if (member != null)
                    {
                        if (members.ContainsKey(member))
                        {
                            Logger.Log(String.Format(
                                           "EditSimpleListPage.SetData: cannot add duplicate member!: {0}",
                                           member),
                                       Logger.LogLevel.Error);
                        }
                        else
                        {
                            members.Add(member, 0);
                        }
                    }
                }
            }

            PopulateListView();
        }
示例#21
0
        /// <summary>
        /// Method to load data to the tab pages while loading
        /// Gets all the tab pages that are of type MPage and gets call the SetData()
        /// Queries the ldap message to the selected node
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="computer"></param>
        /// <param name="dirnode"></param>
        /// <param name="ldapSchemaCache"></param>
        public void SetData(CredentialEntry ce, string servername, string computer, ADUCDirectoryNode dirnode, LDAPSchemaCache ldapSchemaCache)
        {
            string PageTitle = string.Format("cn={0}", _objectAddDlg.objectInfo.htMandatoryAttrList["cn"]);

            if (PageTitle != null)
            {
                this.Text = String.Format(this.Text, PageTitle);
            }

            if (this.GetPages() != null)
            {
                foreach (MPPage page in this.GetPages())
                {
                    if (page != null)
                    {
                        IDirectoryPropertiesPage ipp = page as IDirectoryPropertiesPage;
                        if (ipp != null)
                        {
                            ipp.SetData(ce, servername, computer, dirnode);
                        }
                    }
                }
            }
        }
示例#22
0
        /// <summary>
        /// Queries and fills the ldap message for the selected computer
        /// Gets the attribute list from AD for computer schema attribute.
        /// search for the attributes dNSHostName, cn or name and displays them in a controls
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="dirnode"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            try
            {
                this.dirnode = dirnode;
                int ret = -1;
                List <LdapEntry> ldapEntries = null;

                ret = dirnode.LdapContext.ListChildEntriesSynchronous
                          (dirnode.DistinguishedName,
                          LdapAPI.LDAPSCOPE.BASE,
                          "(objectClass=*)",
                          null,
                          false,
                          out ldapEntries);

                if (ldapEntries == null || ldapEntries.Count == 0)
                {
                    return;
                }

                LdapEntry ldapNextEntry = ldapEntries[0];

                string[] attrsList = ldapNextEntry.GetAttributeNames();

                if (attrsList != null)
                {
                    foreach (string attr in attrsList)
                    {
                        string sValue = "";

                        LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, dirnode.LdapContext);

                        if (attrValues != null && attrValues.Length > 0)
                        {
                            foreach (LdapValue value in attrValues)
                            {
                                sValue = sValue + "," + value.stringData;
                            }
                        }

                        if (sValue.StartsWith(","))
                        {
                            sValue = sValue.Substring(1);
                        }

                        sValue = sValue.Substring(0, sValue.Length);

                        if (string.Compare(sValue, "") == 0)
                        {
                            sValue = "<Not Set>";
                        }

                        if (string.Compare(attr, "cn") == 0)
                        {
                            this.lblComputerName.Text = sValue;
                        }

                        if (string.Compare(attr, "sAMAccountName") == 0)
                        {
                            if (sValue.EndsWith("$"))
                            {
                                this.txtCName.Text = sValue.Substring(0, sValue.Length - 1);
                            }
                            else
                            {
                                this.txtCName.Text = sValue;
                            }
                        }

                        if (string.Compare(attr, "description") == 0)
                        {
                            this.txtDescription.Text = sValue;
                            _editObject.Description  = sValue;
                        }

                        if (string.Compare(attr, "dNSHostName") == 0)
                        {
                            this.txtDNSName.Text = sValue;
                        }

                        if (string.Compare(attr, "userAccountControl") == 0)
                        {
                            int userCtrlVal = 0;
                            if (attrValues != null && attrValues.Length > 0)
                            {
                                userCtrlVal = Convert.ToInt32(attrValues[0].stringData);
                            }
                            string userCtrlBinStr = UserGroupUtils.DecimalToBase(userCtrlVal, 16);
                            _editObject.UserCtrlBinStr = userCtrlVal;

                            this.txtRole.Text = "Workstation or server";
                            if (userCtrlBinStr.Length >= 3)
                            {
                                //Determine role of computer
                                if (userCtrlBinStr.Length == 3)
                                {
                                    //examine the third position from the left (2=NORMAL_ACCOUNT)
                                    if (userCtrlBinStr[0] == '2')
                                    {
                                        this.txtRole.Text = "Normal computer";
                                    }

                                    //examine the third position from the left (2=INTERDOMAIN_TRUST_ACCOUNT)
                                    if (userCtrlBinStr[0] == '8')
                                    {
                                        this.txtRole.Text = "Inter domain trust computer";
                                    }
                                }
                                else
                                {
                                    //examine the forth position from the left (2=WORKSTATION_TRUST_ACCOUNT)
                                    if (userCtrlBinStr[userCtrlBinStr.Length - 4] == '1')
                                    {
                                        this.txtRole.Text = "Workstation or server";
                                    }
                                    //examine the forth position from the left (2=SERVER_TRUST_ACCOUNT)
                                    if (userCtrlBinStr[userCtrlBinStr.Length - 4] == '2')
                                    {
                                        this.txtRole.Text = "Domain controller";
                                    }
                                }
                            }
                            if (userCtrlBinStr.Length >= 5)
                            {
                                //Determine whether this user is TRUSTED_FOR_DELEGATION
                                //examine the fifth position from the left (8=TRUSTED_FOR_DELEGATION, 0=NOT TRUSTED)
                                //TRUSTED_FOR_DELEGATION
                                if (userCtrlBinStr[userCtrlBinStr.Length - 5] == '8')
                                {
                                    this.checkBoxTrust.CheckedChanged -= new System.EventHandler(this.checkBoxTrust_CheckedChanged);
                                    checkBoxTrust.Checked              = true;
                                    this.checkBoxTrust.CheckedChanged += new System.EventHandler(this.checkBoxTrust_CheckedChanged);
                                }
                                else if (userCtrlBinStr[userCtrlBinStr.Length - 5] == '0')
                                {
                                    checkBoxTrust.Checked = false;
                                }
                            }
                            else
                            {
                                checkBoxTrust.Checked = false;
                            }

                            _editObject.DelegateTrust = checkBoxTrust.Checked;
                        }
                    }
                }
                UpdateOriginalData();
                UpdateApplyButton();
            }
            catch (Exception e)
            {
                container.ShowError(e.Message);
            }
        }
        /// <summary>
        /// Queries and fills the ldap message for the selected User
        /// Gets the attribute list from AD for User schema attribute.
        /// search for the attributes givenName, displayName, sAMAccountName,
        /// memberOf, sAMAccountType, userPrincipalName, sn and displays them in a controls
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="dirnode"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            try
            {
                this.dirnode = dirnode;
                SetControlStatus();

                int iOuCount = 0; int iUserCount = 0; int iCompCount = 0; int iGroupCount = 0; int iContactCount = 0;
                int iOtherCount = 0; int iTotalSummary = 0;

                foreach (ADUCDirectoryNode dn in this.parentDlg.ObjectCounts)
                {
                    if (dn != null)
                    {
                        if (dn.ObjectClass.Trim().Equals("OrganizationalUnit", StringComparison.InvariantCultureIgnoreCase))
                        {
                            iOuCount++;
                        }
                        else if (dn.ObjectClass.Trim().Equals("user", StringComparison.InvariantCultureIgnoreCase))
                        {
                            iUserCount++;
                        }
                        else if (dn.ObjectClass.Trim().Equals("group", StringComparison.InvariantCultureIgnoreCase))
                        {
                            iGroupCount++;
                        }
                        else if (dn.ObjectClass.Trim().Equals("computer", StringComparison.InvariantCultureIgnoreCase))
                        {
                            iCompCount++;
                        }
                        else if (dn.ObjectClass.Trim().Equals("contact", StringComparison.InvariantCultureIgnoreCase))
                        {
                            iContactCount++;
                        }
                        else
                        {
                            iOtherCount++;
                        }
                    }
                }
                if (iOuCount != 0)
                {
                    lblOUs.Show();
                    lblOUs.Text    = iOuCount.ToString();
                    iTotalSummary += iOuCount;
                }
                if (iUserCount != 0)
                {
                    lblUsers.Show();
                    iTotalSummary += iUserCount;
                    lblUsers.Text  = iUserCount.ToString();
                }
                if (iGroupCount != 0)
                {
                    lblGroups.Show();
                    iTotalSummary += iGroupCount;
                    lblGroups.Text = iGroupCount.ToString();
                }
                if (iCompCount != 0)
                {
                    lblComputers.Show();
                    iTotalSummary    += iCompCount;
                    lblComputers.Text = iCompCount.ToString();
                }
                if (iContactCount != 0)
                {
                    lblContacts.Show();
                    iTotalSummary   += iContactCount;
                    lblContacts.Text = iContactCount.ToString();
                }
                if (iOtherCount != 0)
                {
                    lblOthers.Show();
                    iTotalSummary += iOtherCount;
                    lblOthers.Text = iOtherCount.ToString();
                }
                lblSummary.Text = iTotalSummary.ToString();
            }
            catch (Exception e)
            {
                Logger.LogException("MultiItemsGeneralEditPage.SetData", e);
            }
        }
示例#24
0
        /// <summary>
        /// Queries and fills the ldap message for the selected group
        /// Gets the attribute list from AD for group schema attribute.
        /// search for the attributes description, cn or name and displays them in a controls
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="dirnode"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            try
            {
                this.dirnode = dirnode;
                int ret = -1;
                List <LdapEntry> ldapEntries = null;
                ret = dirnode.LdapContext.ListChildEntriesSynchronous
                          (dirnode.DistinguishedName,
                          LdapAPI.LDAPSCOPE.BASE,
                          "(objectClass=*)",
                          null,
                          false,
                          out ldapEntries);

                if (ldapEntries == null || ldapEntries.Count == 0)
                {
                    return;
                }

                LdapEntry ldapNextEntry = ldapEntries[0];

                string[] attrsList = ldapNextEntry.GetAttributeNames();

                if (attrsList != null)
                {
                    foreach (string attr in attrsList)
                    {
                        string sValue = "";

                        LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, dirnode.LdapContext);

                        if (attrValues != null && attrValues.Length > 0)
                        {
                            foreach (LdapValue value in attrValues)
                            {
                                sValue = sValue + "," + value.stringData;
                            }
                        }

                        if (sValue.StartsWith(","))
                        {
                            sValue = sValue.Substring(1);
                        }

                        sValue = sValue.Substring(0, sValue.Length);

                        if (string.Compare(sValue, "") == 0)
                        {
                            sValue = "<Not Set>";
                        }

                        if (string.Compare(attr, "cn") == 0)
                        {
                            this.lblGroupName.Text = sValue;
                        }

                        if (string.Compare(attr, "sAMAccountName") == 0)
                        {
                            _editObject.Name         = sValue;
                            this.txtPrewinGroup.Text = sValue;
                        }

                        if (string.Compare(attr, "description") == 0)
                        {
                            this.txtDescription.Text = sValue;
                            _editObject.Description  = sValue;
                        }

                        if (string.Compare(attr, "mail") == 0)
                        {
                            this.txtEmail.Text = sValue;
                            _editObject.Email  = sValue;
                        }

                        if (string.Compare(attr, "groupType") == 0)
                        {
                            EnableCheckBox(sValue);
                            _editObject.GroupType = sValue;
                        }


                        if (string.Compare(attr, "info") == 0)
                        {
                            this.txtNotes.Text = sValue;
                            _editObject.Notes  = sValue;
                        }
                    }
                }
                if (_editObject != null)
                {
                    _originalObject = (GroupGenerelEditObject)_editObject.Clone();
                }
                else
                {
                    _originalObject = new GroupGenerelEditObject();
                }
                UpdateApplyButton();
            }
            catch (Exception e)
            {
                container.ShowError(e.Message);
            }

            // throw new NotImplementedException();
        }
示例#25
0
 public static Process ViewShare(CredentialEntry ce, string sHostname, string sShare)
 {
     Session.EnsureNullSession(sHostname, ce);
     return(ProcessUtil.Exec(Environment.SystemDirectory, "explorer.exe", @"\\" + sHostname + @"\" + sShare));
 }
示例#26
0
 public static Process RunMMC(CredentialEntry ce, string sHostname)
 {
     Session.EnsureNullSession(sHostname, ce);
     return(ProcessUtil.ShellExec(Environment.SystemDirectory, "fsmgmt.msc", "/s /computer=" + sHostname, "open"));
 }
示例#27
0
        /// <summary>
        /// Queries and fills the ldap message for the selected group
        /// Gets the attribute list from AD for group schema attribute.
        /// search for the attributes description, cn or name and displays them in a controls
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="dirnode"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            try
            {
                this.dirnode = dirnode;
                this.plugin  = dirnode.Plugin as ADUCPlugin;
                DirectoryContext dirContext = dirnode.LdapContext;
                Logonname    = "";
                PreLogonname = "";

                //first obtain the current userAccountControl value
                DirectoryEntry de          = new DirectoryEntry(string.Format("LDAP://{0}/{1}", dirContext.DomainName, dirnode.DistinguishedName));
                int            userCtrlInt = Convert.ToInt32(de.Properties["userAccountControl"].Value.ToString());
                long           pwdLastSet  = Convert.ToInt64(de.Properties["pwdLastSet"].Value.ToString());
                sUserWorkStations = de.Properties["userWorkstations"].Value as string;

                if (de.Properties["userPrincipalName"].Value != null)
                {
                    Logonname     = de.Properties["userPrincipalName"].Value as string;
                    Logonname     = Logonname.IndexOf('@') >= 0 ? Logonname.Substring(0, Logonname.IndexOf('@')) : Logonname;
                    txtlogon.Text = Logonname;
                }

                txtpreLogonname.Text = de.Properties["sAMAccountName"].Value as string;
                PreLogonname         = txtpreLogonname.Text.Trim();

                txtDomian.Text = dirContext.DomainName.Substring(0, dirContext.DomainName.IndexOf('.')).ToUpper() + @"\";
                cbDomain.Items.Add(string.Concat("@", dirContext.DomainName.ToUpper()));
                cbDomain.SelectedIndex = 0;

                double accountExpires = Convert.ToInt64(de.Properties["accountExpires"].Value);

                if (accountExpires == 9223372036854775807)
                {
                    rbNever.Checked = true;
                }
                else
                {
                    rbEndOf.Checked = true;
                    ConvertFromUnixTimestamp(accountExpires);
                }
                try
                {
                    string userCtrlBinStr = UserGroupUtils.DecimalToBase(userCtrlInt, 2);

                    if (userCtrlBinStr.Length >= 10 && userCtrlBinStr[userCtrlBinStr.Length - 10] == '1')
                    {
                        bMustChangePwd = true;
                    }
                    if (userCtrlBinStr.Length >= 10 && userCtrlBinStr[userCtrlBinStr.Length - 2] == '1')
                    {
                        bAcountDisable = true;
                    }
                    if (userCtrlBinStr.Length >= 17 && userCtrlBinStr[userCtrlBinStr.Length - 17] == '1')
                    {
                        bNeverExpiresPwd = true;
                        bMustChangePwd   = false;
                    }
                    if (userCtrlBinStr.Length >= 10 && userCtrlBinStr[userCtrlBinStr.Length - 7] == '1' &&
                        pwdLastSet != 0)
                    {
                        bUserCannotChange = true;
                    }
                    if (userCtrlBinStr.Length >= 8 && userCtrlBinStr[userCtrlBinStr.Length - 8] == '1')
                    {
                        bStorePwd = true;
                    }
                    if (userCtrlBinStr.Length >= 19 && userCtrlBinStr[userCtrlBinStr.Length - 19] == '1')
                    {
                        bSmartCardRequired = true;
                    }
                    if (userCtrlBinStr.Length >= 21 && userCtrlBinStr[userCtrlBinStr.Length - 21] == '1')
                    {
                        bAccSensitive = true;
                    }
                    if (userCtrlBinStr.Length >= 22 && userCtrlBinStr[userCtrlBinStr.Length - 22] == '1')
                    {
                        bUseDESDescription = true;
                    }
                    if (userCtrlBinStr.Length >= 23 && userCtrlBinStr[userCtrlBinStr.Length - 23] == '1')
                    {
                        bNotKrbAuthentication = true;
                    }
                }
                catch
                {
                }

                FillUserOptions();

                dateTimePicker.Enabled = rbEndOf.Checked;

                this.ParentContainer.DataChanged      = false;
                this.ParentContainer.btnApply.Enabled = false;
            }
            catch (Exception e)
            {
                Logger.LogException("UserAccountPage.SetData", e);
            }
        }
示例#28
0
        public static Dictionary <int, string[]> EnumShares(IntPtr handle_b, CredentialEntry ce, string sHostname)
        {
            //// establish null session
            //if(!Session.EnsureNullSession(sHostname, ce))
            //{
            //    return null;
            //}

            try
            {
                Dictionary <int, string[]> ShareList = new Dictionary <int, string[]>();

                IntPtr pBuf    = IntPtr.Zero;
                int    cRead   = 0;
                int    cTotal  = 0;
                int    hResume = 0;
                int    maxlen  = -1;
                int    nret    = -1;

                if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                {
                    Logger.Log(String.Format("NetShareEnum(sHostname={0}) called",
                                             sHostname), Logger.FileShareManagerLogLevel);

                    nret = NetShareEnum(sHostname,
                                        2,
                                        ref pBuf,
                                        maxlen,
                                        ref cRead,
                                        ref cTotal,
                                        ref hResume);
                }
                else
                {
                    Logger.Log(String.Format("NetShareEnum(handle_b={0:x},sHostname={1}) called",
                                             handle_b.ToInt32(), sHostname), Logger.FileShareManagerLogLevel);

                    maxlen = 20;

                    nret = NetShareEnum(handle_b,
                                        sHostname,
                                        2,
                                        ref pBuf,
                                        maxlen,
                                        ref cRead,
                                        ref cTotal,
                                        ref hResume);
                }

                Logger.Log(String.Format(
                               "NetShareEnum(); result={0}, pBuf={1}, cRead={2}, cTotal={3}, hResume={4}",
                               nret, pBuf, cRead, cTotal, hResume));

                // now, iterate through the data in pBuf
                IntPtr pCur = pBuf;
                for (int i = 0; i < cRead; i++)
                {
                    // marshal the entry into
                    SHARE_INFO_2 si2 = (SHARE_INFO_2)Marshal.PtrToStructure(pCur, typeof(SHARE_INFO_2));

                    // only allow regular diskshares
                    // TODO: Review this. Should we not display admin shares?
                    if (si2.shi2_type == STYPE_DISKTREE)
                    {
                        string[] sShareInfo = { si2.shi2_netname, si2.shi2_path, si2.shi2_remark, si2.shi2_current_uses.ToString() };
                        ShareList.Add(i, sShareInfo);
                    }

                    // advance to the next entry
                    pCur = (IntPtr)((int)pCur + Marshal.SizeOf(si2));
                }
                if (pBuf != IntPtr.Zero)
                {
                    // free the data
                    if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                    {
                        NetApiBufferFree(pBuf);
                    }
                    else
                    {
                        SrvSvcFreeMemory(pBuf);
                    }
                }
                // all done
                return(ShareList);
            }
            catch (Win32Exception we)
            {
                throw new LikewiseAPIException(we);
            }
        }
示例#29
0
        /// <summary>
        /// Queries and fills the ldap message for the selected OU
        /// Gets the attribute list from AD for OU schema attribute.
        /// search for the attributes description, ou or name and displays them in a controls
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="dirnode"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            try
            {
                InitializeCountryNames();
                _editObject = new OUGenerelEditObject();
                int ret = -1;
                this.dirnode = dirnode;
                List <LdapEntry> ldapEntries = null;

                ret = dirnode.LdapContext.ListChildEntriesSynchronous
                          (dirnode.DistinguishedName,
                          LdapAPI.LDAPSCOPE.BASE,
                          "(objectClass=*)",
                          null,
                          false,
                          out ldapEntries);

                if (ldapEntries == null || ldapEntries.Count == 0)
                {
                    return;
                }

                LdapEntry ldapNextEntry = ldapEntries[0];

                string[] attrsList = ldapNextEntry.GetAttributeNames();

                if (attrsList != null)
                {
                    foreach (string attr in attrsList)
                    {
                        string sValue = "";

                        LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, dirnode.LdapContext);

                        if (attrValues != null && attrValues.Length > 0)
                        {
                            foreach (LdapValue value in attrValues)
                            {
                                sValue = sValue + "," + value.stringData;
                            }
                        }

                        if (sValue.StartsWith(","))
                        {
                            sValue = sValue.Substring(1);
                        }

                        if (string.Compare(sValue, "") == 0)
                        {
                            sValue = "<Not Set>";
                        }

                        if (string.Compare(attr, "description") == 0)
                        {
                            this.txtDescription.Text = sValue;
                            _editObject.Description  = sValue;
                        }

                        if (string.Compare(attr, "street") == 0)
                        {
                            this.rtbStreet.Text = sValue;
                            _editObject.Street  = sValue;
                        }

                        if (string.Compare(attr, "l") == 0)
                        {
                            this.txtCity.Text = sValue;
                            _editObject.City  = sValue;
                        }

                        if (string.Compare(attr, "st") == 0)
                        {
                            this.txtstate.Text = sValue;
                            _editObject.State  = sValue;
                        }

                        if (string.Compare(attr, "postalCode") == 0)
                        {
                            this.txtZip.Text       = sValue;
                            _editObject.PostalCode = sValue;
                        }

                        if (string.Compare(attr, "co") == 0)
                        {
                            bool bEntryFound = false;
                            for (int i = 0; i < cbcountry.Items.Count; i++)
                            {
                                if (sValue.Trim().ToLower().Equals(cbcountry.Items[i].ToString().Trim().ToLower()))
                                {
                                    cbcountry.SelectedIndex = i;
                                    bEntryFound             = true;
                                    break;
                                }
                            }
                            if (!bEntryFound)
                            {
                                cbcountry.Items.Add(sValue);
                                cbcountry.SelectedIndex = cbcountry.Items.Count - 1;
                            }
                            _editObject.Country = sValue;
                        }

                        if (string.Compare(attr, "ou") == 0)
                        {
                            this.userNamelabel.Text = sValue;
                        }
                    }
                }
                if (_editObject != null)
                {
                    _originalObject = (OUGenerelEditObject)_editObject.Clone();
                }
                else
                {
                    _originalObject = new OUGenerelEditObject();
                }
                ParentContainer.DataChanged = false;
                UpdateApplyButton();
            }
            catch (Exception e)
            {
                container.ShowError(e.Message);
            }
            // throw new NotImplementedException();
        }
示例#30
0
        public static Dictionary <int, string[]> EnumFiles(IntPtr pHandle, CredentialEntry ce, string sHostname)
        {
            // establish null session
            //if (!Session.EnsureNullSession(sHostname, ce))
            //{
            //    return null;
            //}

            try
            {
                Dictionary <int, string[]> UserList = new Dictionary <int, string[]>();

                IntPtr pBuf    = IntPtr.Zero;
                int    cRead   = 0;
                int    cTotal  = 0;
                int    hResume = 0;
                int    maxlen  = -1;
                int    nret    = -1;

                Logger.Log(String.Format("NetFileEnum(handle_b={0:x}, sHostname={1}) called",
                                         pHandle.ToInt32(), sHostname), Logger.FileShareManagerLogLevel);

                if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                {
                    nret = NetFileEnum(sHostname,
                                       null,
                                       null,
                                       3,
                                       ref pBuf,
                                       maxlen,
                                       ref cRead,
                                       ref cTotal,
                                       ref hResume);
                }
                else
                {
                    nret = NetFileEnum(pHandle,
                                       sHostname,
                                       null,
                                       null,
                                       3,
                                       ref pBuf,
                                       maxlen,
                                       ref cRead,
                                       ref cTotal,
                                       ref hResume);
                }

                Logger.Log(String.Format(
                               "NetFileEnum(); result={0}, pBuf={1}, cRead={2}, cTotal={3}, hResume={4}",
                               nret, pBuf, cRead, cTotal, hResume));

                // now, iterate through the data in pBuf
                IntPtr pCur = pBuf;
                for (int i = 0; i < cRead; i++)
                {
                    // marshal the entry into
                    FILE_INFO_3 fi3 = (FILE_INFO_3)Marshal.PtrToStructure(pCur, typeof(FILE_INFO_3));

                    // create a row
                    // set the mode
                    int    iMode = fi3.fi3_permission;
                    string sMode = "";
                    if ((iMode & PERM_FILE_READ) == PERM_FILE_READ)
                    {
                        sMode = "Read";
                    }
                    if ((iMode & PERM_FILE_WRITE) == PERM_FILE_WRITE)
                    {
                        if (sMode.Length > 0)
                        {
                            sMode += "+Write";
                        }
                        else
                        {
                            sMode = "Write";
                        }
                    }
                    if ((iMode & PERM_FILE_CREATE) == PERM_FILE_CREATE)
                    {
                        if (sMode.Length > 0)
                        {
                            sMode += "+Create";
                        }
                        else
                        {
                            sMode = "Create";
                        }
                    }
                    string[] sFileInfo = { fi3.fi3_pathname, fi3.fi3_username, fi3.fi3_num_locks.ToString(), sMode, fi3.fi3_id.ToString() };

                    UserList.Add(i, sFileInfo);


                    // advance to the next entry
                    pCur = (IntPtr)((int)pCur + Marshal.SizeOf(fi3));
                }
                if (pBuf != IntPtr.Zero)
                {
                    // free the data
                    if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                    {
                        NetApiBufferFree(pBuf);
                    }
                    else
                    {
                        SrvSvcFreeMemory(pBuf);
                    }
                }

                // all done
                return(UserList);
            }
            catch (Win32Exception we)
            {
                throw new LikewiseAPIException(we);
            }
        }