net ldap problem?

P

Piotr Talarczyk

Hi!
I have server with Active Directory.
I wanted to do somethink like thet:

def changelogonhours(name,ldap)
filtr = Net::LDAP::Filter.eq("cn",name)
ldap.search:)base => "dc=example,dc=local", :filter => filtr){|ut|
p ut[:dn]
p ut[:logonhours]
ut1,ut2 = Marshal.dump(ut[:logonhours]).split("\032")
ut1 = ut1 + "\032"
ut2, ut3 = ut2.split("\006:")
ut3 = "\006:" + ut3
ut2a=[]
(0..6).each{|g|
ut2a[g] = ut2[g*3..g*3+2]
}
tmp=ut2a[1]
(2..6).each{|g|
ut2a[g-1]=ut2a[g]
}
ut2a[6]=tmp
ut_new = ut1 + ut2a.join + ut3
# here begins my problem
ldap.replace_attribute ut[:dn], :logonhours, Marshal.load(ut_new)
p ut[:logonhours]
}
end

Ruby responds:

["CN=Tom Bombadil,OU=Users,DC=exmple,DC=local"]
["\300\377\017\000\000\000\000\000\000\000\000\b\000\000\004\000\000\001\000\000\000"]
/var/lib/gems/1.8/gems/net-ldap-0.1.1/lib/net/ldap.rb:1502:in `modify':
response missing or invalid (Net::LDAP::LdapError)
from
/var/lib/gems/1.8/gems/net-ldap-0.1.1/lib/net/ldap.rb:912:in `modify'
from
/var/lib/gems/1.8/gems/net-ldap-0.1.1/lib/net/ldap.rb:962:in
`replace_attribute'
from or.rb:24:in `trova_orari'
from
/var/lib/gems/1.8/gems/net-ldap-0.1.1/lib/net/ldap.rb:630:in `search'
from
/var/lib/gems/1.8/gems/net-ldap-0.1.1/lib/net/ldap.rb:1426:in `search'
from
/var/lib/gems/1.8/gems/net-ldap-0.1.1/lib/net/ldap.rb:1385:in `loop'
from
/var/lib/gems/1.8/gems/net-ldap-0.1.1/lib/net/ldap.rb:1385:in `search'
from
/var/lib/gems/1.8/gems/net-ldap-0.1.1/lib/net/ldap.rb:628:in `search'
from or.rb:6:in `trova_orari'
from or.rb:38
from or.rb:37:in `each'
from or.rb:37
from
/var/lib/gems/1.8/gems/net-ldap-0.1.1/lib/net/ldap.rb:534:in `open'
from or.rb:36

If you have some idea how to fix it i will be grateful.

Piotr

P.S. of course this code run after authentication where i use user that
can change logon howers through "Active Directory Users and Computers"

ldap = Net::LDAP.new
ldap.host = "192.168.0.2"
ldap.port = 389
ldap.auth "CN=User for Maintenance,OU=Other Users,DC=example,DC=local",
"pass"

if ldap.bind
ldap.open{|ldap|
changelogonhours("Tom Bombadil",ldap)
}
else
puts "nooooooo"
end
 
P

Piotr Talarczyk

Is u2 getting set?

irb(main):124:0> u1,u2 =
"\300\377\017\000\000\000\000\000\000\000\000\b\000\000\004\000\000\001\000\000\000".split("\032")
=>
["\300\377\017\000\000\000\000\000\000\000\000\b\000\000\004\000\000\001\000\000\000"]
irb(main):125:0> u1
=>
"\300\377\017\000\000\000\000\000\000\000\000\b\000\000\004\000\000\001\000\000\000"
irb(main):126:0> u2
=> nil
irb(main):127:0>


________________________________
From: Piotr Talarczyk <[email protected]>
Reply-To: <[email protected]>
Date: Tue, 31 Aug 2010 11:47:57 -0500
To: ruby-talk ML <[email protected]>
Subject: net ldap problem?
....
ut1,ut2 = Marshal.dump(ut[:logonhours]).split("\032")
ut1 = ut1 + "\032"
ut2, ut3 = ut2.split("\006:")
ut3 = "\006:" + ut3
ut2a=[]
...

I didn't see that i can convert ut[:logonhours]
(Net::BER::BerIdentifiedArray) to string. Cuting it with "\032" make
sense only with Marshal.dump.
Now my code is more simple:

p ut[:logonhours]
utstr = ut[:logonhours].to_s
utarr=[]
(0..6).each{|g|
utarr[g] = utstr[g*3..g*3+2]
} # divide by day
tmp=utarr[1]
(2..6).each{|g|
utarr[g-1]=utarr[g]
}
utarr[6]=tmp
ldap.replace_attribute ut[:dn], :logonhours, utarr.join.to_ber
p ut[:logonhours]

But i still have problem with replace_attribute that give me the same
error as written above
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top