Skip to content

Instantly share code, notes, and snippets.

@trevmex
Created February 10, 2010 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevmex/300850 to your computer and use it in GitHub Desktop.
Save trevmex/300850 to your computer and use it in GitHub Desktop.
class ActiveDirectoryUser
require 'restclient'
@authentication_site = 'https://your_server'
@find_site = 'http://your_server'
@authentication_prefix = '/your_auth_page'
@find_prefix = '/cgi-bin/dscl_search.sh?'
# Returns true if the user has the correct password, false otherwise.
def self.authenticate(login, password)
site = RestClient::Resource.new(@authentication_site, :user => login, :password => password)
begin
results = site[@authentication_prefix].get
auth_succeeded = true
rescue
auth_succeeded = false
end
auth_succeeded
end
# Returns the dscl information of the user if they exist, nil otherwise
def self.find(login)
begin
dscl_results = RestClient.get("#{@find_site}#{@find_prefix}#{login}").to_s
if dscl_results.blank?
dscl_results = nil
end
rescue
dscl_results = nil
end
dscl_results
end
end
#!/bin/bash
echo "Content-type: text/plain"
echo
dscl localhost -read /Search/Users/${1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment