<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Supporting Open Source weblog: Category code snippets</title>
    <link>http://blog.sos.be/articles/category/code-snippets</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Ruby: aanmaken eerste paswoord</title>
      <description>&lt;p&gt;Voor het aanmaken van de paswoorden van een groep nieuwe gebruikers.&lt;/p&gt;


	&lt;p&gt;Dit script genereert de ldif (STDOUT) voor het aanmaken van het &lt;code&gt;userPassword&lt;/code&gt; voor alle gebruikers (volgens filter). Het paswoord is hetzelfde als de &lt;code&gt;uid&lt;/code&gt;.&lt;/p&gt;&lt;pre&gt;
#!/usr/bin/env ruby

require 'ldap'
require 'ldap/ldif'
require 'digest/sha1'
require 'base64'

filter = "(objectClass=uidObject)" 

#attrs = ['uid','givenname','sn','cn','uidnumber','gidnumber','mail','homedirectory','objectclass']
attrs = ['uid']

conn = LDAP::Conn.new('localhost', 389).bind
conn.perror("bind")

begin
  conn.search("dc=blabla, dc=be",
  LDAP::LDAP_SCOPE_SUBTREE,
  filter,
  attrs) do |e|
    uid = e.vals("uid")[0]
    npaswoord = "{SHA}" + Base64.encode64(Digest::SHA1.new(uid).digest).chomp
    printf("dn: %s\n", e.get_dn)
    printf("changetype: modify\nreplace: userPassword\n")
    printf("userPassword: %s\n\n",npaswoord)
  end
    rescue LDAP::ResultError =&amp;gt; msg
    $stderr.print(msg)
end
&lt;/pre&gt;</description>
      <pubDate>Wed, 17 Jan 2007 14:31:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:aa744454-72f5-4fd5-8886-4eb1613211b3</guid>
      <author>Paul Verreth</author>
      <link>http://blog.sos.be/articles/2007/01/17/ruby-aanmaken-eerste-paswoord</link>
      <category>code snippets</category>
      <category>ruby</category>
      <category>ldap</category>
    </item>
    <item>
      <title>Ruby: resetten ldap paswoord</title>
      <description>&lt;p&gt;Ruby script voor het resetten van een ldap paswoord&lt;/p&gt;&lt;pre&gt;
#!/usr/bin/env ruby

require 'ldap'
require 'ldap/ldif'
require 'digest/sha1'
require 'base64'
require 'readline'
require 'curses'
include Readline
include LDAP
include Curses

ldapserver = 'ldap.blabla.be'
deeldn = 'ou=People,dc=blabla,dc=be'
admindn = 'cn=admin,dc=blabla,dc=be'

init_screen

addstr("Geef de uid: ")
refresh
uid = getstr()

addstr("Geef het administrator paswoord: ")
refresh
noecho
adminpw = getstr()
close_screen

puts uid
puts adminpw

dn = "uid=" + uid + "," + deeldn
npaswoord = "{SHA}" + Base64.encode64(Digest::SHA1.new(uid).digest).chomp

puts uid
puts "Nieuw gegenereerd paswoord voor #{uid}: #{npaswoord}" 
puts "dn= #{dn}" 

attrs = {
'objectclass' =&amp;gt; ["top","inetorgperson","uidobject","dada"],
'uid' =&amp;gt; [uid],
'userpassword' =&amp;gt; [npaswoord]
}

conn = LDAP::Conn.new(ldapserver, 389).bind(admindn,adminpw)
conn.perror("Boodschap van bind:")

begin
conn.modify(dn,attrs)
conn.perror("Boodschap van modify:")
puts "---" 
rescue LDAP::ResultError =&amp;gt; msg
$stderr.print(msg)
end
&lt;/pre&gt;</description>
      <pubDate>Wed, 17 Jan 2007 14:23:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:fc30b09e-a736-4f2c-8b3c-2183a8c6a8ab</guid>
      <author>Paul Verreth</author>
      <link>http://blog.sos.be/articles/2007/01/17/ruby-resetten-ldap-paswoord</link>
      <category>code snippets</category>
      <category>ruby</category>
      <category>ldap</category>
    </item>
  </channel>
</rss>
