blog'o thnet

To content | To menu | To search

Sunday 30 October 2005

Changing user account informations stored in LDAP

This little real-life example will be based on changing the user's login shell for a given account.

  • grills represents the LDAP server (master)

Verify that the user exists in the directory server:

# ldaplist passwd jpeg
dn: uid=jpeg,ou=people,dc=thilelli,dc=net

Get detailed parameters for this account:

# ldaplist -l passwd jpeg
dn: uid=jpeg,ou=people,dc=thilelli,dc=net
        cn: jpeg
        uidNumber: 1000
        gecos: Gabel, Julien
        homeDirectory: /u/jpeg
        gidNumber: 1000
        objectClass: posixAccount
        objectClass: shadowAccount
        objectClass: account
        objectClass: top
        uid: ut0tar
        userPassword: XXXXXXXX
        shadowLastChange: 6445
        shadowFlag: 0
        loginShell: /usr/local/bin/bash

Create the desired modifications using a ldif LDAP file:

# ldaplist -l passwd jpeg > ldapmodifiy.jpeg.ldif
/* Edit and save the ldif file. */
#
# cat ldapmodifiy.jpeg.ldif
dn: uid=jpeg,ou=people,dc=thilelli,dc=net
changetype: modify
replace: loginShell
loginShell: /usr/local/bin/ksh

Inject this modification(s) into the LDAP server:

# ldapmodify -h grills -D "cn=Directory Manager" -f ldapmodifiy.jpeg.ldif
Enter bind password: 
modifying entry uid=jpeg,ou=people,dc=thilelli,dc=net

Verify that the changes are done as expected:

# ldaplist -l passwd jpeg
dn: uid=jpeg,ou=people,dc=thilelli,dc=net
        cn: jpeg
        uidNumber: 1000
        gecos: Gabel, Julien
        homeDirectory: /u/jpeg
        gidNumber: 1000
        objectClass: posixAccount
        objectClass: shadowAccount
        objectClass: account
        objectClass: top
        uid: ut0tar
        userPassword: XXXXXXXX
        shadowLastChange: 6445
        shadowFlag: 0
        loginShell: /usr/local/bin/ksh

The example shown below use the ldaplist(1) and ldapmodify(1) commands line, which use and options may vary between OS versions and/or family. Be warned.

Saturday 27 August 2005

Displaying Self Written Manual Pages

Learning about how to write a well written manual page, just want to point out the examples provided by the FreeBSD Project, located under the base system in /usr/share/examples/mdoc.

For those who are not (yet!) under FreeBSD Operating System, you can browse the publicly available CVS repository via the web interface.

If not already in the system man path or the environmental variable ${MANPATH}, you can display your new manual page using:

$ tbl example.1 | groff -S -Wall -mtty-char -man -Tlatin1 | col | more

Or:

$ zcat example.1.gz | tbl | groff -S -Wall -mtty-char -man -Tlatin1 | col | more

Friday 12 August 2005

Adding a New Plugin Using the NanoBlogger Framework

Discussing how to add a copyright notice at each page automatically on the NanoBlogger mailing list, here are the two propositions i can think of.

It can be done by adding directly the copyright notice in the desired template files (i.e. templates/main_index.htm, etc.):

  1. Either writing it in the corresponding files...
    $ diff -u templates/main_index.htm templates/main_index.htm.hardwritten
    --- templates/main_index.htm Wed Jul 6 14:49:05 2005
    +++ templates/main_index.htm.hardwritten Mon Aug 8 13:12:05 2005
    @@ -29,6 +29,10 @@
    $NB_Entries
    </div>
    
    +<div class="side">
    +All content herein © 2006, Your Company, Inc. All right reserved.
    +</div>
    +
    <div id="menu">
    $NB_PageLinks
    </div>
    
  2. Or writing a little plugin to do that... (based on the plugins/fortune.sh code)
    # cat << EOF > ${NB_INST_PATH}/plugins/copyright.sh
    # NanoBlogger Copyright plugin.
    
    # sample code for templates, based off default stylesheet
    #
    # <div class="side">
    # $NB_Copyright
    # </div>
    
    PLUGIN_OUTFILE="$BLOG_DIR/$PARTS_DIR/copyright.$NB_FILETYPE"
    
    nb_msg "generating copyright ..."
    echo '<div class="copyright">' > "$PLUGIN_OUTFILE"
    echo 'All content herein © 2006, Your Company, Inc. All right reserved.' >> "$PLUGIN_OUTFILE"
    echo '</div>' >> "$PLUGIN_OUTFILE"
    NB_Copyright=$(< "$PLUGIN_OUTFILE")
    EOF
    $
    $ diff -u templates/main_index.htm templates/main_index.htm.plugin
    --- templates/main_index.htm Wed Jul 6 14:49:05 2005
    +++ templates/main_index.htm.plugin Mon Aug 8 13:12:29 2005
    @@ -29,6 +29,10 @@
    $NB_Entries
    </div>
    
    +<div class="side">
    +$NB_Copyright
    +</div>
    +
    <div id="menu">
    $NB_PageLinks
    </div>
    

The advantage of the second proposition is the capability to add a general feature using the NanoBlogger framework, and the use of the CSS to modify the new copyright class.

Thursday 11 August 2005

Change the date of a NanoBlogger Post

Here are the complete steps to change the date of a post, to look as if it had been written on the changed date.

  1. Rename the entry's data file name to the desired date
  2. Rename, accordingly to the entry's data file name, the content of the corresponding cat_X.db file in which the entry reside (it seems not to be updated by nb -u all or anything else)
  3. Eventually correct the date in the DATE field of the entry using nb -e #id, correcting the day name too (thanks to the cal(1) utility)

Hum. I think there may be a better way to do this.

Sunday 31 July 2005

Reversing a File Line-by-Line

Reversing a file line-by-line seems not very interesting, but may be in fact very helpful in a lot of cases, especially under Unix-like systems.

Interestingly, just after reading a very good article on that particular subject from the printed edition of the Sys Admin Magazine, great known NetBSD developer Hubert Feyrer blogged about this issue... growing the proposed solution with a new method not yet given, although very simple.

All the spirit of UNIX can be found here: combined different powerful general tools to achieve a very specific task... sounds great to me.

Monday 25 July 2005

Alter the password of a user in Drupal, directly via the SGBD

Using Drupal as the CMS of choice for time now, there is a little thing assumed by the system at the first time the web site is launched which isn't welcomed in all situation: an already working mail environment.

In fact, when creating the first Drupal user (and so with administrative rights), the password is by default sent to the email address provided... even if there is no working email subsystem in order to take delivery of the random generated password. This can render the freshly installed CMS very... inefficient, don't you think?

So, in order to be able to log in, the password for this account may be directly reset to the SGBD (a MySQL data server in the following case). Here is how this can easily be achieved.

Obtain the checksum of the given string corresponding to the wanted password:

server# md5 -s padawan
MD5 ("padawan") = 9a4b83013501fde3e8864f4f4b5fb7c5

Update the password entry for the administrative account:

server# mysql -u dba_user -p drupal_database
Enter password: ********
mysql> UPDATE users SET pass = '9a4b83013501fde3e8864f4f4b5fb7c5'
    -> WHERE name = 'obiwan'\g\q
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0
Bye

That's all: just log in as usual via the Drupal web portal, using obiwan/padawan as login/password. And be prepared to build a working mail subsystem very soon for next time...

Wednesday 22 June 2005

Using ksh(1) History and Keys in Emacs Mode

In order to map the arrow keys to use history commands under the emacs mode with ksh(1), please put the following lines in the ${HOME}/.kshrc:

# Arrow keys to use history commands under the emacs command edition mode.
alias __A=`echo "\020"`   # mapping arrow key 'up'
alias __B=`echo "\016"`   # mapping arrow key 'down'
alias __C=`echo "\006"`   # mapping arrow key 'right'
alias __D=`echo "\002"`   # mapping arrow key 'left'
alias __H=`echo "\001"`   # mapping arrow key 'home'

There are two underline characters in alias commands.

To be able to get the PageUp and PageDown keys to work in vi(1), edit the ${HOME}/.exrc file and insert the following lines:

" Mapping PageUp & PageDown keys.
map  ^[[5~   ^B
map  ^[[6~   ^F

Note: comment begin with a " in .exrc, not a #.

How to enter the ^[[5~ character? You have to type Control+V, then press the PageUp key.

How to enter the ^B character? You have to type Control+Vn then press the Control+B keys.

As a last tip, here is how to change the prompt using working directory information. Using export PS1='${PWD} $ ', the behavior is as follow:

/home/jpeg $ cd
/home/jpeg $ cd /var/log
/var/log $

Using export PS1='${PWD##*/} $ ', the behavior is as follow:

jpeg $ cd
jpeg $ cd /var/log
log $

page 2 of 2 -