[svn-inject] Installing original source of libnss-mysql-bg
[manu/libnss-mysql-bg.git] / sample / freebsd / sample_database.sql
1 #
2 # $Id: sample_database.sql,v 1.3 2004/07/21 17:53:32 cinergi Exp $
3 #
4 #                THIS DATABASE IS INTENDED FOR FreeBSD
5 #
6 # Use 'mysql -u root -p < sample_database.sql' to load this example into your
7 # MySQL server.
8 # This example will:
9 #   1) create a database called 'auth'
10 #   2) add three tables: 'users', 'groups' and 'grouplist'
11 #   3) add some data to each table
12 #   4) create two MySQL users ('nss-user' and 'nss-root') with appropriate
13 #      SELECT privs.
14 #
15 # With a properly-functioning libnss-mysql, you should be able to log into
16 # the system as 'cinergi' with a password of 'cinergi'.  'cinergi' should be
17 # a member of the group 'foobaz' as well.
18 #
19 # This is intended as an *example* and is perhaps not the best use of
20 # datatypes, space/size, data normalization, etc.
21 #
22
23 create database auth;
24 use auth;
25
26 # The tables ...
27 CREATE TABLE groups (
28   name varchar(16) NOT NULL default '',
29   password varchar(34) NOT NULL default 'x',
30   gid int(11) NOT NULL auto_increment,
31   PRIMARY KEY  (gid)
32 ) TYPE=MyISAM AUTO_INCREMENT=5000;
33
34 CREATE TABLE grouplist (
35   rowid int(11) NOT NULL auto_increment,
36   gid int(11) NOT NULL default '0',
37   username char(16) NOT NULL default '',
38   PRIMARY KEY  (rowid)
39 ) TYPE=MyISAM;
40
41 CREATE TABLE users (
42   username varchar(16) NOT NULL default '',
43   uid int(11) NOT NULL auto_increment,
44   gid int(11) NOT NULL default '5000',
45   pwchange int(11) NOT NULL default '0',
46   class varchar(64) NOT NULL default '',
47   gecos varchar(128) NOT NULL default '',
48   homedir varchar(255) NOT NULL default '',
49   shell varchar(64) NOT NULL default '/bin/sh',
50   password varchar(34) NOT NULL default 'x',
51   expire bigint(20) NOT NULL default '0',
52   PRIMARY KEY  (uid),
53   UNIQUE KEY username (username),
54   KEY uid (uid)
55 ) TYPE=MyISAM AUTO_INCREMENT=5000;
56
57 # The data ...
58 INSERT INTO users (username,gecos,homedir,password)
59     VALUES ('cinergi', 'Ben Goodwin', '/home/cinergi', ENCRYPT('cinergi'));
60 INSERT INTO groups (name)
61     VALUES ('foobaz');
62 INSERT INTO grouplist (gid,username)
63     VALUES (5000,'cinergi');
64
65 # The permissions ...
66 GRANT USAGE ON *.* TO `nss-root`@`localhost` IDENTIFIED BY 'rootpass';
67 GRANT USAGE ON *.* TO `nss-user`@`localhost` IDENTIFIED BY 'userpass';
68
69 GRANT Select (`username`, `uid`, `gid`, `gecos`, `homedir`, `shell`,
70               `pwchange`,`class`,`expire`)
71              ON `auth`.`users`
72              TO 'nss-user'@'localhost';
73 GRANT Select (`username`, `uid`, `gid`, `gecos`, `homedir`, `shell`, `password`,
74               `pwchange`,`class`,`expire`)
75              ON `auth`.`users`
76              TO 'nss-root'@'localhost';
77
78 GRANT Select (`name`, `password`, `gid`)
79              ON `auth`.`groups`
80              TO 'nss-user'@'localhost';
81 GRANT Select (`name`, `password`, `gid`)
82              ON `auth`.`groups`
83              TO 'nss-root'@'localhost';
84
85 GRANT Select (`username`, `gid`)
86              ON `auth`.`grouplist`
87              TO 'nss-user'@'localhost';
88 GRANT Select (`username`, `gid`)
89              ON `auth`.`grouplist`
90              TO 'nss-root'@'localhost';
91