C# -- Active Directory -- accountExpires 属性读取不正确

发布于 2024-12-14 12:55:32 字数 863 浏览 1 评论 0原文

我正在开发一个列出活动目录用户的许多属性的工具。目前,我可以通过向 lastPasswordSet 属性添加 90 天(典型策略)来显示过期日期。但是,某些帐户设置为永不过期。

我做了一些研究并发现,如果该属性在转换为长整数时等于 9223372036854775807 则密码永远不会过期(至少我被告知)。

我遇到的问题是我查找的每个帐户的 accountExpires 值都是 9223372036854775807 。我有 Microsoft AD 工具,可以验证哪些帐户实际上设置为永不过期,哪些帐户将在 90 天后过期。我不确定我做错了什么:

    public bool doesPWExpire(string userDN)
    {
        DirectoryEntry ent = new DirectoryEntry(userDN);
        //get account expires property
        LargeInteger passChanged = ent.Properties["accountExpires"].Value as LargeInteger;

        //convert to data type long
        long int64Value = (long)((uint)passChanged.LowPart | (((long)passChanged.HighPart) << 32));

        if (int64Value == 9223372036854775807)
        {
            return false;
        }
        else
        {
            return true;
        }
    }

I am working on a tool that lists a number of properties of an active directory user. Currently I can show expiration date by adding 90 days (typical policy) to the lastPasswordSet property. However, some accounts are setup to never expire.

I've done some research and figured out that if the property, when converted to a long integer, equals 9223372036854775807 than the password never expires (or so I'm told).

The problem I'm having is that EVERY account I lookup has 9223372036854775807 as the accountExpires value. I have the microsoft AD tool and can verify which accounts are actually set to never expire and which ones expire in 90 days. I'm not sure what I'm doing wrong:

    public bool doesPWExpire(string userDN)
    {
        DirectoryEntry ent = new DirectoryEntry(userDN);
        //get account expires property
        LargeInteger passChanged = ent.Properties["accountExpires"].Value as LargeInteger;

        //convert to data type long
        long int64Value = (long)((uint)passChanged.LowPart | (((long)passChanged.HighPart) << 32));

        if (int64Value == 9223372036854775807)
        {
            return false;
        }
        else
        {
            return true;
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寂寞笑我太脆弱 2024-12-21 12:55:32

你正在变长。MaxValue,“从不”的一个很好的值。您的代码不一致,您正在读取“accountExpires”属性,但分配给名为“passChanged”的变量。这表明您实际上想要读取与密码相关的属性。如“maxPwdAge”和“PasswordLastChanged”。帐户通常不会过期,但密码会过期。

You are getting long.MaxValue, a good value for "never". Your code is inconsistent, you are reading the "accountExpires" property but assigning to a variable named "passChanged". Which suggests that you actually want to read a password related property. Like "maxPwdAge" and "PasswordLastChanged". Accounts don't usually expire, passwords do.

烟火散人牵绊 2024-12-21 12:55:32

我想 DateTime expiry = DateTime.FromFileTime((int)ent.Properties["accountExpires"].Value) 会为你解决问题

I imagine DateTime expiry = DateTime.FromFileTime((int)ent.Properties["accountExpires"].Value) will do the trick for you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文