# It is advised if you run postgresql on the same server as libnss-pgsql that you have
# ssl connection turned off in your connection string.
# You can hang your machine attempting to connect to the postgresql database.
# sslmode=disable
#
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=279581
#
# Without a running nscd, PQconnectdb attempts to setup the SSL
# environment and searches for $HOME/.postgresql/server.crt (or similar),
# calling getpwuid to retrieve the home-directory. This obviously causes
# another entrance into libnss-pgsql which results in a hang while waiting
# for the (already owned) lock.
connectionstring        = hostaddr=127.0.0.1 dbname=nss user=nss password=nss connect_timeout=1 sslmode=disable

# you can use anything postgres accepts as table expression

# Must return "usernames", 1 column, list
getgroupmembersbygid    = SELECT username FROM passwd_table JOIN usergroups ug USING (uid) WHERE ug.gid = $1
# Must return passwd_name, passwd_passwd, passwd_gecos, passwd_dir, passwd_shell, passwd_uid, passwd_gid
getpwnam        = SELECT username, passwd, gecos, homedir, shell, uid, gid FROM passwd_table WHERE username = $1
# Must return passwd_name, passwd_passwd, passwd_gecos, passwd_dir, passwd_shell, passwd_uid, passwd_gid
getpwuid        = SELECT username, passwd, gecos, homedir, shell, uid, gid FROM passwd_table WHERE uid = $1
# All users
allusers        = SELECT username, passwd, gecos, homedir, shell, uid, gid FROM passwd_table
# Must return group_name, group_passwd, group_gid
getgrnam        = SELECT groupname, passwd, gid, array_to_string(SELECT username FROM usergroups WHERE usergroups.gid = group_table.gid),chr(10)) as members FROM group_table WHERE groupname = $1
# Must return group_name, group_passwd, group_gid
getgrgid        = SELECT groupname, passwd, gid, array_to_string(SELECT username from usergroups WHERE usergroups.gid = group_table.gid),chr(10)) as members FROM group_table WHERE gid = $1
# Must return gid.  %s MUST appear first for username match in where clause
groups_dyn      = SELECT ug.gid FROM passwd_table JOIN usergroups ug USING (uid) where username = $1 and ug.gid <> $2

# allgroups can use 2 flavours,
# 1. get the group table and requery getgroupmembersbygid for all group members.
#    this produces 1 query per group.
# 2. pass the list of usernames with they query as an aggregate, each username must be split by '\n' or chr(10)
#    the new version is usually faster
#allgroups       = SELECT groupname, passwd, gid FROM group_table
allgroups       = SELECT groupname, passwd, gid, array_to_string(ARRAY(SELECT username FROM usergroups JOIN passwd_table USING (uid) WHERE usergroups.gid = group_table.gid),chr(10)) AS members FROM group_table
