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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
|
<?xml version="1.0"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<book id="nsspampgsql">
<bookinfo>
<title>NSS/PAM PgSQL</title>
<authorgroup>
<author>
<firstname>Jörg</firstname>
<surname>Wendland</surname>
<affiliation>
<address>
<email>jorgland@sol.wohnheim.uni-ulm.de</email>
</address>
</affiliation>
</author>
<author>
<firstname>Bret</firstname>
<surname>Mogilefsky</surname>
<affiliation>
<address>
<email>mogul-sysauth-pgsql@gelatinous.com</email>
</address>
</affiliation>
</author>
<author>
<firstname>Wichert</firstname>
<surname>Akkerman</surname>
<affiliation>
<address>
<email>wichert@wiggy.net</email>
</address>
</affiliation>
</author>
<author>
<firstname>Christian</firstname>
<surname>Bayle</surname>
<affiliation>
<address>
<email>bayle@debian.org</email>
</address>
</affiliation>
</author>
<author>
<firstname>Russell</firstname>
<surname>Smith</surname>
<affiliation>
<address>
<email>mr-russ@pws.com.au</email>
</address>
</affiliation>
</author>
</authorgroup>
<copyright>
<year>2001</year>
<year>2004</year>
<year>2005</year>
<holder>Jörg Wendland</holder>
<holder>Wichert Akkerman</holder>
<holder>Russell Smith</holder>
</copyright>
<legalnotice>
<para>
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation. There
are no invariant sections. A copy of the license is included in the
section entitled "GNU Free Documentation License".
</para>
</legalnotice>
</bookinfo>
<preface id="preface">
<title>Preface</title>
<para>
This document covers setup and use of the Name Service Switch (NSS)
Module <filename>libnss-pgsql.so</filename>. Its purpose is replace the
flatfile user, group and shadow databases in <filename>/etc</filename> with a
relational database on a PostgreSQL server. It is highly configurable to
fit onto most existing databases.
</para>
</preface>
<toc/>
<chapter id="prerequisites">
<title>Prerequisites</title>
<para>
For installation instructions please see the files
<filename>README</filename> and <filename>INSTALL</filename> in the
source distribution.
</para>
<para>
To use this module you will need a PostgreSQL database containing some
sort of user account information. See <xref linkend="dbschema"/> for an
example database.
</para>
</chapter>
<chapter>
<title>Module and Database Setup</title>
<section id="dbstructure">
<title>required database structure</title>
<para>
To use this module with a database you will need at least three tables
in that database. One for account data (the information usually stored
in <filename>/etc/passwd</filename>), one for group data
(<filename>/etc/group</filename>) and another one storing information
about groupmembership (there is a m:n relation between passwd and group
so you need this weak entity). If you have an existing database you do
not want to modify you can use views or table expressions (see
<xref linkend="conffile"/>), of course. You can also optionally store
shadow information (<filename>/etc/shadow</filename>) in the database
as well. Depending on your security requirements another table or view
may be needed.
</para>
<section id="tables">
<title>tables and fields</title>
<para>
There have to be some required fields in those tables. They are
described below.
</para>
<variablelist>
<varlistentry>
<term>passwd table (see <citerefentry>
<refentrytitle>getpwnam</refentrytitle>
<manvolnum>3</manvolnum></citerefentry>
for more information)</term>
<listitem>
<itemizedlist>
<listitem>
<para>login name</para>
</listitem>
<listitem>
<para>password</para>
</listitem>
<listitem>
<para>numerical user id (uid)</para>
</listitem>
<listitem>
<para>numerical primary group id (gid)</para>
</listitem>
<listitem>
<para>login shell</para>
</listitem>
<listitem>
<para>description (gecos)</para>
</listitem>
<listitem>
<para>home directory</para>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>group table (see <citerefentry>
<refentrytitle>getgrnam</refentrytitle>
<manvolnum>3</manvolnum></citerefentry>)</term>
<listitem>
<itemizedlist>
<listitem>
<para>group name</para>
</listitem>
<listitem>
<para>group password</para>
</listitem>
<listitem>
<para>numerical group id (gid)</para>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
</variablelist>
<para>
An example database schema can be found in <xref
linkend="dbschema"/>. See there for how to construct the
groupmember table.
</para>
</section>
</section>
</chapter>
<chapter id="configuration">
<title>configuring the module</title>
<para>
Having a working database, you must write your configfile
<filename>/etc/nss-pgsql.conf</filename>. If you also want shadow
support, you must write a second config file
<filename>/etc/nss-pgsql-root.conf</filename>
These files have a simple syntax:
</para>
<informalexample>
<programlisting>
LINE := COMMENT | EMPTY | STATEMENT
COMMENT := '#' <text>
EMPTY := ''
STATEMENT := KEYWORD '=' <value>
</programlisting>
</informalexample>
<para>
With <command>KEYWORD</command> being one of the following (all are
required):
</para>
<variablelist>
<varlistentry>
<term>connectionstring</term>
<listitem>
<para>The connection string to connect to the server. You can include any valid PostgreSQL options.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>getpwnam</term>
<listitem>
<para>A query that returns passwd_name, passwd_passwd, passwd_gecos, passwd_dir, passwd_shell, passwd_uid, passwd_gid for a given username</para>
</listitem>
</varlistentry>
<varlistentry>
<term>getpwuid</term>
<listitem>
<para>A query that returns passwd_name, passwd_passwd, passwd_gecos, passwd_dir, passwd_shell, passwd_uid, passwd_gid for a given uid</para>
</listitem>
</varlistentry>
<varlistentry>
<term>getgrnam</term>
<listitem>
<para>A query that returns group_name, group_passwd, group_gid for a given group name</para>
</listitem>
</varlistentry>
<varlistentry>
<term>getgrgid</term>
<listitem>
<para>A query that returns group_name, group_passwd, group_gid for a given gid</para>
</listitem>
</varlistentry>
<varlistentry>
<term>allusers</term>
<listitem>
<para>A query that returns username, password, gecos, home_dir, shell, uid, primarygid for every user</para>
</listitem>
</varlistentry>
<varlistentry>
<term>allgroups</term>
<listitem>
<para>A query that returns group_name, group_passwd, group_gid for every group</para>
</listitem>
</varlistentry>
<varlistentry>
<term>groups_dyn</term>
<listitem>
<para>A query that returns a list of gid's a particular user is in. excluding their primary group.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>getgroupmembersbygid</term>
<listitem>
<para>A query that returns a list of usernames for a given gid</para>
</listitem>
</varlistentry>
<varlistentry>
<term>shadowbyname</term>
<listitem>
<para>A query returning shadow_name, shadow_passwd, shadow_lstchg, shadow_min, shadow_max, shadow_warn, shadow_inact, shadow_expire, shadow_flag
for a given username</para>
</listitem>
</varlistentry>
<varlistentry>
<term>shadow</term>
<listitem>
<para>A query returning shadow_name, shadow_passwd, shadow_lstchg, shadow_min, shadow_max, shadow_warn, shadow_inact, shadow_expire, shadow_flag
for all users</para>
</listitem>
</varlistentry>
</variablelist>
</chapter>
<chapter id="nss-setup">
<title>Name Service Switch Setup</title>
<caution>
<para>
You can do serious damage to your system if you do not know what you
are doing! If you are trying changes in the Name Service Switch for the
very first time, consider doing that in a chroot environment or a test
machine. Have at least an editor with
<filename>/etc/nsswitch.conf</filename> open to revert your changes
easily. You have been warned!
</para>
</caution>
<para>
Setting up the Name Service Switch is fairly easy, given a
working installation of the libnss-pgsql module. Just add an
entry <command>pgsql</command> the <command>passwd</command> and
<command>group</command> lines of
<filename>/etc/nsswitch.conf</filename>. You can tune the behaviour with
options between the entries to get a fully working system. Useful lines
in <filename>/etc/nsswitch.conf</filename> would look like these:
</para>
<informalexample>
<programlisting>
passwd: files [SUCCESS=continue] pgsql
group: files [SUCCESS=continue] pgsql
shadow: files [SUCCESS=continue] pgsql
</programlisting>
</informalexample>
<para>
This will make your libc look into the standard
<filename>passwd</filename> and <filename>group</filename> files first
and then use libnss-pgsql. The option
<command>[SUCCESS=continue]</command> ensures that all accounts or groups
are retrieved when using the iteration functions
<citerefentry>
<refentrytitle>getpwent</refentrytitle>
<manvolnum>3</manvolnum>
</citerefentry> and
<citerefentry>
<refentrytitle>getgrent</refentrytitle>
<manvolnum>3</manvolnum>
</citerefentry>.
</para>
</chapter>
<appendix id="appendix">
<title>Examples</title>
<example id="dbschema">
<title>Database schema</title>
<programlisting>
-- Default table setup for nss-pgsql
CREATE SEQUENCE group_id MINVALUE 1000 MAXVALUE 2147483647 NO CYCLE;
CREATE SEQUENCE user_id MINVALUE 1000 MAXVALUE 2147483647 NO CYCLE;
CREATE TABLE "group_table" (
"gid" int4 NOT NULL DEFAULT nextval('group_id'),
"groupname" character varying(16) NOT NULL,
"descr" character varying,
"passwd" character varying(20),
PRIMARY KEY ("gid")
);
CREATE TABLE "passwd_table" (
"username" character varying(64) NOT NULL,
"passwd" character varying(128) NOT NULL,
"uid" int4 NOT NULL DEFAULT nextval('user_id'),
"gid" int4 NOT NULL,
"gecos" character varying(128),
"homedir" character varying(256) NOT NULL,
"shell" character varying DEFAULT '/bin/bash' NOT NULL,
PRIMARY KEY ("username")
);
CREATE TABLE "usergroups" (
"gid" int4 NOT NULL,
"uid" int4 NOT NULL,
PRIMARY KEY ("gid", "uid"),
CONSTRAINT "ug_gid_fkey" FOREIGN KEY ("gid") REFERENCES "group_table"("gid"),
CONSTRAINT "ug_uid_fkey" FOREIGN KEY ("uid") REFERENCES "passwd_table"("uid")
);
CREATE TABLE "shadow_table" (
"username" character varying(64) NOT NULL,
"passwd" character varying(128) NOT NULL,
"lastchange" int4 NOT NULL,
"min" int4 NOT NULL,
"max" int4 NOT NULL,
"warn" int4 NOT NULL,
"inact" int4 NOT NULL,
"expire" int4 NOT NULL,
"flag" int4 NOT NULL,
PRIMARY KEY ("username")
);
</programlisting>
</example>
<example id="conffile">
<title>Configuration file</title>
<programlisting>
connectionstring = hostaddr=127.0.0.1 dbname=unix user=postgres password=XXX connect_timeout=1
# you can use anything postgres accepts as table expression
# Must return "usernames", 1 column, list
getgroupmembersbygid = SELECT username FROM passwd_table WHERE 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 FROM group_table WHERE groupname = $1
# Must return group_name, group_passwd, group_gid
getgrgid = SELECT groupname, passwd, gid 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 USING (uid) where username = $1 and ug.gid <> $2
allgroups = SELECT groupname, passwd, gid FROM group_table
</programlisting>
<programlisting>
# example configfile for PostgreSQL NSS module
# this file must be readable for root only
shadowconnectionstring = hostaddr=127.0.0.1 dbname=unix user=postgres connect_timeout=1
#Query in the following format
#shadow_name, shadow_passwd, shadow_lstchg, shadow_min, shadow_max, shadow_warn, shadow_inact, shadow_expire, shadow_flag
shadowbyname = SELECT * FROM shadow_table WHERE username = $1
shadow = SELECT * FROM shadow_table
</programlisting>
</example>
</appendix>
</book>
<!-- vi: sw=2
-->
|