altriox

altriox

Hi,

I’m trying to use the eldap module to set a password for a new user in Active Directory. In AD, the default attribute for setting the password is unicodePwd, and uses a UTF-16. When I try to set the attribute using eldap I get an {:error, :unwillingToPerofrm} back. I know I need to encode the password, but I’m not quite sure how.

:application.ensure_all_started(:ssl)

{:ok, handle} = :eldap.open(['example.local'], [{:port,636}, {:ssl, true}])

authenticated = 
  :ok == :eldap.simple_bind(handle, 
    'CN=Administrator Account,CN=Users,DC=example,DC=local', 
    'password')

:eldap.add(handle, 'cn=John K Doe,cn=Users,dc=example,dc=local',
[{'objectclass', ['user']},
 {'displayName', ['John K. Doe']},
 {'givenName', ['John']},
 {'initials', ['K']},
 {'sn', ['Doe']},
 {'sAMAccountName', ['john.k.doe']},
 {'userPrincipalName', ['john.k.doe@example.local]},
 {'cn', ['John K Doe']},
 {'unicodePwd', ['abc@123!']}, # => { :error, :unwillingToPerform }
])

:eldap.close(handle)

I was able to get similar code to work in golang:

	// Encoding password
	utf16 := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
	encoded, err := utf16.NewEncoder().String("\"abc@123!\"")

	// Building Add Request for User Object
	addReq := ldap.AddRequest{
		DN: "CN=John W Doe,CN=Users,DC=example,DC=local",
		Attributes: []ldap.Attribute{
			ldap.Attribute{"objectClass", []string{"user"}},
			ldap.Attribute{"displayName", []string{"John W. Doe"}},
			ldap.Attribute{"givenName", []string{"John"}},
			ldap.Attribute{"sn", []string{"Doe"}},
			ldap.Attribute{"initials", []string{"W"}},
			ldap.Attribute{"sAMAccountName", []string{"john.w.doe"}},
			ldap.Attribute{"userPrincipalName", []string{"john.w.doe@example.local"}},
			ldap.Attribute{"unicodePwd", []string{encoded}},
			ldap.Attribute{"userAccountControl", []string{"512"}},
		},
	}

Any help would be most appreciated.

Showing Posts 1 to 3

jwarlander

jwarlander

It looks like the :unicode module in Erlang should be able to help converting the data, just like your golang example does:

On my phone now, so I can’t experiment with it unfortunately.. :smiling_face_with_sunglasses:

OvermindDL1

OvermindDL1

Also, I made a binary based LDAP module for Elixir, it is read-only currently but I left it open for future development to be expanded if you want to make a PR for it. The interface is quite a bit nicer. :slight_smile:

altriox

altriox OP

Thanks, the :unicode module fixed my problem. Below is what I changed:

encode = :unicode.characters_to_binary(~s("abc@123!"), :utf8, {:utf16, :little})
:eldap.add(handle, 'cn=John K Doe,cn=Users,dc=example,dc=local',
[{'objectclass', ['user']},
 {'displayName', ['John K. Doe']},
 {'givenName', ['John']},
 {'initials', ['K']},
 {'sn', ['Doe']},
 {'sAMAccountName', ['john.k.doe']},
 {'userPrincipalName', ['john.k.doe@example.local']},
 {'cn', ['John K Doe']},
 {'unicodePwd', [encode]},
 {'userAccountControl', ['512']}
])

This creates an account with the password abc@123!, and enables it. I was able to log in using the password. It took me a little longer than I want to admit due to using a simpler password that wasn’t meeting the password policy which also gives you the :unwillingToPerform error.

@OvermindDL1 your module looks awesome. I’ll definitely keep it in mind. I’m very new to Elixir/Erlang and programming in general. This was basically a proof of concept for me, in order to see if I could get Elixir to do what I need. It took me quite a while to figure out how to parse the search results from :eldap. Once I get a few more books on Elixir under my belt, I plan to come back to it.

Thank you both for your help.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New
Stef-Verniers
Hello I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews