[svn-inject] Installing original source of libnss-mysql-bg
[manu/libnss-mysql-bg.git] / sample / minimal / sample_database.sql
1 #
2 # Minimalist sample libnss-mysql database
3 #
4 # $Id: sample_database.sql,v 1.2 2004/07/21 17:54:15 cinergi Exp $
5 #
6 # sample_database.sql revision      compatible libnss-mysql versions
7 # -------------------------------------------------------------------
8 # 1.1                               0.5+
9 #
10 # Use 'mysql -u root -p < sample_database.sql' to load this example into MySQL
11 #
12 # This particular example stores as little as possible in the MySQL database.
13 # The 'users' table only has username/uid/password in it.  The rest is
14 # 'hard coded' via the configuration files.
15 # The groups database remains unchanged from the main sample as it is
16 # already pretty minimal.  If you do not require MySQL group support,
17 # simply delete the 'groups' and 'grouplist' tables and do not configure
18 # /etc/nsswitch.conf with 'mysql' on the 'group' line
19
20 # This configuration suits something like an ISP where all users may have
21 # the same gid, home directory base, shell, etc.  You can really do
22 # some funky things inside the configuration files if you wanted to, such
23 # as define a different shell depending on the uid returned; that just
24 # takes a bit of SQL query magic...
25
26 create database auth;
27 use auth;
28
29 # The tables ...
30 CREATE TABLE groups (
31   name varchar(16) NOT NULL default '',
32   password varchar(34) NOT NULL default 'x',
33   gid int(11) NOT NULL auto_increment,
34   PRIMARY KEY  (gid)
35 ) TYPE=MyISAM AUTO_INCREMENT=5000;
36
37 CREATE TABLE grouplist (
38   rowid int(11) NOT NULL auto_increment,
39   gid int(11) NOT NULL default '0',
40   username char(16) NOT NULL default '',
41   PRIMARY KEY  (rowid)
42 ) TYPE=MyISAM;
43
44 CREATE TABLE users (
45   username varchar(16) NOT NULL default '',
46   uid int(11) NOT NULL auto_increment,
47   password varchar(34) NOT NULL default 'x',
48   PRIMARY KEY  (uid),
49   UNIQUE KEY username (username),
50   KEY uid (uid)
51 ) TYPE=MyISAM AUTO_INCREMENT=5000;
52
53 # The data ...
54 INSERT INTO users (username,password) VALUES ('cinergi', ENCRYPT('cinergi'));
55 INSERT INTO groups (name) VALUES ('foobaz');
56 INSERT INTO grouplist (gid,username) VALUES (5000,'cinergi');
57
58 # The permissions ...
59 GRANT USAGE ON *.* TO `nss-root`@`localhost` IDENTIFIED BY 'rootpass';
60 GRANT USAGE ON *.* TO `nss-user`@`localhost` IDENTIFIED BY 'userpass';
61
62 GRANT Select (`username`, `uid`, `password`)
63              ON `auth`.`users`
64              TO 'nss-root'@'localhost';
65 GRANT Select (`name`, `password`, `gid`)
66              ON `auth`.`groups`
67              TO 'nss-root'@'localhost';
68
69 GRANT Select (`username`, `uid`)
70              ON `auth`.`users`
71              TO 'nss-user'@'localhost';
72 GRANT Select (`name`, `password`, `gid`)
73              ON `auth`.`groups`
74              TO 'nss-user'@'localhost';
75
76 GRANT Select (`username`, `gid`)
77              ON `auth`.`grouplist`
78              TO 'nss-user'@'localhost';
79 GRANT Select (`username`, `gid`)
80              ON `auth`.`grouplist`
81              TO 'nss-root'@'localhost';
82