{"id":696,"date":"2012-01-24T16:37:22","date_gmt":"2012-01-24T23:37:22","guid":{"rendered":"http:\/\/jim-zimmerman.com\/?p=696"},"modified":"2012-01-24T16:37:22","modified_gmt":"2012-01-24T23:37:22","slug":"more-fun-with-ldapsearch-and-active-directory","status":"publish","type":"post","link":"https:\/\/jim-zimmerman.com\/?p=696","title":{"rendered":"More fun with ldapsearch and Active Directory."},"content":{"rendered":"<p>Since I started this little investigation of LDAP today, I decided to look into using the ldapsearch command in linux to display Windows Active Directory attributes and information.  This is a bit of what I came up with:<\/p>\n<p># ldapsearch -x -LLL -E pr=<em>someinteger<\/em>\/noprompt -h <em>host<\/em> -D &#8216;<em>adsuser@mydomain.com<\/em>&#8216; -W -b &#8220;<em>searchbase<\/em>&#8221;<\/p>\n<p>Some explanation:<\/p>\n<p><em>someinteger<\/em>: Because of the &#8220;noprompt&#8221; switch, this number is not really important.  All matching entries will be displayed.  You can set it some integer with a &#8220;prompt&#8221; switch, and only that number of entries will be displayed before you are prompted for more.  The -E option is available in later versions of openldap.  I tested version 2.3. It is not an option in 2.0.<\/p>\n<p><em>adsuser@mydomain.com<\/em>:  This can be any user account in the directory, because they have read only access to the directory.  I used the -W option to prompt me to enter my password, however you can use the -w option and pass it your ADS password on the command line.<\/p>\n<p><em>searchbase<\/em>:  The search base is where things get interesting.  You can use something like the following to search for only users:<\/p>\n<p># ldapsearch -x -LLL -E pr=<em>someinteger<\/em>\/noprompt -h <em>host<\/em> -D &#8216;<em>adsuser@mydomain.com<\/em>&#8216; -W -b &#8220;<em>cn=users,dc=mydomain,dc=com<\/em>&#8221;<\/p>\n<p>Or computers:<br \/>\n# ldapsearch -x -LLL -E pr=<em>someinteger<\/em>\/noprompt -h <em>host<\/em> -D &#8216;<em>adsuser@mydomain.com<\/em>&#8216; -W -b &#8220;<em>cn=computers,dc=mydomain,dc=com<\/em>&#8221;<\/p>\n<p>Or everything under DC=mydomain,DC=com:<\/p>\n<p># ldapsearch -x -LLL -E pr=<em>someinteger<\/em>\/noprompt -h <em>host<\/em> -D &#8216;<em>adsuser@mydomain.com<\/em>&#8216; -W <\/p>\n<p>You can also filter for certain distinguished names:<\/p>\n<p>This will display attributes and values for all relative distinguished names:<\/p>\n<p># ldapsearch -x -LLL -E pr=<em>someinteger<\/em>\/noprompt -h <em>host<\/em> -D &#8216;<em>adsuser@mydomain.com<\/em>&#8216; -W -b &#8220;<em>cn=users,dc=mydomain,dc=com<\/em>&#8221; -s sub &#8220;(cn=*)&#8221;<\/p>\n<p>This will display all relative distinguished names that start with the letter &#8220;z&#8221; under the users distinguished name:<\/p>\n<p># ldapsearch -x -LLL -E pr=<em>someinteger<\/em>\/noprompt -h <em>host<\/em> -D &#8216;<em>adsuser@mydomain.com<\/em>&#8216; -W -b &#8220;<em>cn=users,dc=mydomain,dc=com<\/em>&#8221; -s sub &#8220;(cn=z*)&#8221;<\/p>\n<p>Fun stuff, but not exactly sure what I would do with this information.  Maybe access ADS information without having to login to Windows.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since I started this little investigation of LDAP today, I decided to look into using the ldapsearch command in linux to display Windows Active Directory attributes and information. This is a bit of what I came up with: # ldapsearch -x -LLL -E pr=someinteger\/noprompt -h host -D &#8216;adsuser@mydomain.com&#8216; -W -b &#8220;searchbase&#8221; Some explanation: someinteger: Because [&#038;hellip<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[82,83,245],"class_list":["post-696","post","type-post","status-publish","format-standard","hentry","category-documentation","tag-active-directory","tag-ads","tag-ldap"],"share_on_mastodon":{"url":"","error":""},"_links":{"self":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/696","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=696"}],"version-history":[{"count":1,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/696\/revisions"}],"predecessor-version":[{"id":697,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/696\/revisions\/697"}],"wp:attachment":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}