Thursday Feb 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

Wednesday Apr 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:


About

Chris Quenelle

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today