Monday Mar 12, 2012

How I now configure the name switch in Solaris 11

/etc/nsswitch.conf is dead in S11. What I use now to configure the name switch is the following shell script which can take either a nis or ldap argument:

#!/bin/ksh -p

# New way of configuing the name switch.  nsswitch.conf is dead in S11 so the
# following must be edited and run instead of editing that nsswitch.conf.

me=${0##*/}
tmpfile=$(/usr/bin/mktemp -t ${me}.XXXXXX)

case $1 in
	'nis')
cat > $tmpfile <<EOF 
setprop config/password = astring: "files nis [TRYAGAIN=0 UNAVAIL=return NOTFOUND=return]"
setprop config/group =    astring: "files nis [TRYAGAIN=0 UNAVAIL=return NOTFOUND=return]"
setprop config/host =     astring: "files dns"
setprop config/network =  astring: files
setprop config/protocol = astring: files
setprop config/rpc =      astring: files
setprop config/ether =    astring:   files
setprop config/netmask =  astring:   files
setprop config/bootparam = astring:  files
setprop config/publickey = astring:  files
setprop config/netgroup =  astring:  nis
setprop config/automount = astring:  "files nis"
setprop config/alias =     astring:  files
setprop config/service =   astring:  files
setprop config/printer = astring:    "user files"
setprop config/project = astring:    files
setprop config/auth_attr = astring:  files
setprop config/prof_attr = astring:  files
setprop config/tnrhtp = astring:     files
setprop config/tnrhdb = astring:     files
exit
EOF
	;;

	'ldap')
cat > $tmpfile <<EOF 
setprop config/password = astring: "files ldap"
setprop config/group =    astring: "files ldap"
setprop config/host =     astring: "files dns"
setprop config/network =  astring: files
setprop config/protocol = astring: files
setprop config/rpc =      astring: files
setprop config/ether =    astring:   files
setprop config/netmask =  astring:   files
setprop config/bootparam = astring:  files
setprop config/publickey = astring:  files
setprop config/netgroup =  astring:  ldap
setprop config/automount = astring:  "files ldap"
setprop config/alias =     astring:  files
setprop config/service =   astring:  files
setprop config/printer = astring:    "user files ldap"
setprop config/project = astring:    files
setprop config/auth_attr = astring:  files
setprop config/prof_attr = astring:  files
setprop config/tnrhtp = astring:     files
setprop config/tnrhdb = astring:     files
exit
EOF
	;;
esac

svccfg -s svc:/system/name-service/switch -f $tmpfile || exit
rm $tmpfile
svcadm refresh svc:/system/name-service/switch:default
print "Current svc:/system/name-service/switch config:"
svccfg -s svc:/system/name-service/switch listprop 'config/*'

Tuesday Mar 06, 2012

Easy Memory Corruption Checking in Solaris

I've been using a shell script wrapper I wrote several years ago to make using libumem and watchmalloc memory corruption debugging features easy to use. The script is called memdbg and it can be used like so:

memdbg [memdbg options] <program and program args>

Example:

# Start the krb5kdc daemon with memory leak detection on
$ memdbg -l ./krb5kdc

# Check the kinit command for memory corruption
$ memdbg kinit tester
I also created a companion script called show_leaks which can report memory leaks found by libumem on a running process. Here's an example:
# Report memory leaks in kadmind when it's been started with memdbg -l:
$ show_leaks kadmind
CACHE     LEAKED   BUFCTL CALLER
0818aa90     127 081a81b8 libkadm5srv.so.1`decrypt_key_data+0x42
08189710     254 0878ca18 libkdb.so.1`krb5_dbekd_def_decrypt_key_data+0x8d
08189a90     127 081f8998 libkdb.so.1`krb5_dbekd_def_decrypt_key_data+0x8d
0818a010     127 081ca110 libkdb.so.1`krb5_dbekd_def_decrypt_key_data+0x8d
------------------------------------------------------------------------
   Total     635 buffers, 48768 bytes

# See the stacks of all leaked allocs
$ show_leaks -v kadmind
CACHE     LEAKED   BUFCTL CALLER
0818aa90     127 081a81b8 libkadm5srv.so.1`decrypt_key_data+0x42
08189710     254 0878ca18 libkdb.so.1`krb5_dbekd_def_decrypt_key_data+0x8d
08189a90     127 081f8998 libkdb.so.1`krb5_dbekd_def_decrypt_key_data+0x8d
0818a010     127 081ca110 libkdb.so.1`krb5_dbekd_def_decrypt_key_data+0x8d
------------------------------------------------------------------------
   Total     635 buffers, 48768 bytes
======================= 081a81b8::bufctl_audit info ======================
            ADDR          BUFADDR        TIMESTAMP           THREAD
                            CACHE          LASTLOG         CONTENTS
         81a81b8          81ae280    e7d2112af0cb1                1
                          818aa90          815fcfc                0
                 libumem.so.1`umem_cache_alloc_debug+0x157
                 libumem.so.1`umem_cache_alloc+0x157
                 libumem.so.1`umem_alloc+0xd0
                 libumem.so.1`malloc+0x2d
                 libkadm5srv.so.1`decrypt_key_data+0x42
                 libkadm5srv.so.1`kadm5_randkey_principal_3+0x47d
                 chrand_principal3_2_svc+0x248
                 kadm_1+0x381
                 libnsl.so.1`_svc_prog_dispatch+0x18e
                 libnsl.so.1`svc_getreq_common+0xf5
                 libnsl.so.1`svc_getreq_poll+0x65
                 kadm_svc_run+0x169
                 main+0x22a4
                 _start+0x7d

======================= 0878ca18::bufctl_audit info ======================
etc...

I've blogged before about both libumem and watchmalloc (both are part of native Solaris). I will say at this point I use libumem much more because it doesn't slow down a program very much at least when using the default options or -l leak reporting. Every Solaris developer should be using this at some point in testing. I have found numerous memory handling bugs using these tools.

Here are the URLs/links to the scripts mentioned above:
https://blogs.oracle.com/wfiveash/resource/memdbg
https://blogs.oracle.com/wfiveash/resource/show_leaks
To use them, use the "save the link as" function of your browser, chmod u+x memdbg|show_leaks, place them in your PATH, then run. Happy bug hunting!!!
About

user12615206

Search

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