Chris Quenelle's Weblog
Thoughts on developer tools.

All | Dbx | Development Tools | Life in General | OpenSolaris | plus | Software Philosophy | Sun Studio

fav comics

Main | Next page »
20090226 Thursday February 26, 2009

Blog relocation

This blog is moving to a new home.  Please give it a try.  The new site is using WordPress, and I'm still a WordPress newbie.  So if you have any WordPress tips or tricks, let me know.

My blog's new home

Posted by Chris Quenelle ( Feb 26 2009, 05:48:07 PM PST ) - Permalink - -

20070418 Wednesday April 18, 2007

Using LDAP inside Sun


If you're inside Sun (or other companies that deploy LDAP name services) you may have tried to use the ldap_client utility from the command line, but found it too low level.  I made up a little shell function that I've been using for a few years now, and it's served me well.  You can get some of the same information using the Address Book in Thunderbird, or whatever mailer you might be using, but if you want more fields to be available, it's better to drill down the raw LDAP database.  If you remove the list of fields from the command line to ldap_client, it will show all the available fields.  The finger command at the end of my script doesn't do much anymore since Solaris leaves the finger daemon off by default.


name_lookup() {

# 'l' means location I guess
fields="uid host telephonenumber preferredrfc822recipient"
fields="$fields photourl l rfc822recipient globallocation roomnumber"

if [ $# = 2 ];
then
# Xyz's givenname=xyz nickname=123
# filter="(&(|()(givenname=$1*))(surname=$2*))"
filter="(&(|(givenname=$1*)(nickname=$1*))(surname=$2*))"
elif [ $# = 1 ];
then
filter="uid=$1"
else
echo Too many arguments, use one or two.
fi

# echo ldapsearch -h sun-ds -b dc=sun,dc=com $filter ${fields}
output="$(ldapsearch -h sun-ds -b dc=sun,dc=com $filter ${fields})"
output="$(echo "$output" | \
sed -e 's/preferredrfc822recipient/email/' \
-e 's/^cn=\([^(]*\).*/\1/' \
)"
echo
echo "$output"
host=$(echo "$output" | grep 'host=' | sed 's/host=//' )
# host=$(echo "$output" | sed 's/.*host=\([^ ]*\).*/\1/')
echo host is $host
finger @$host
echo

}
name() { name_lookup "$@"; }


Here's the output for me (phone number xxx'ed out, natch).  And my host
name is a few years out of date.  I need to update it in netadmin....




% name chr quen

version: 1
dn: cn=Christopher Quenelle (23484),ou=people,dc=sun,dc=com
uid: quenelle
host: veldt.eng.Sun.COM
telephonenumber: x8xxxx/650-786-XXXX
email: Chris.Quenelle@Sun.COM
photourl: http://dptwiki.sfbay/~quenelle/web-head.jpg
l: MENLO PARK,UNITED STATES
rfc822recipient: Chris.Quenelle@Sun.COM
rfc822recipient: Chris.Quenelle@SFBay.Sun.COM
globallocation: mpk16
roomnumber: 3148
host is
unknown host:


Posted by Chris Quenelle ( Apr 18 2007, 06:03:00 PM PDT ) - Permalink - -

Older blog entries:

mug shot Chris Quenelle is a tools developer at Sun Microsystems. He's worked on performance and debugging tools at Sun for more than 10 years. He reads comic books and science fiction, and has more tivos than he can keep track of.

Calendar

RSS Feeds

Search

Links

Navigation

Referers