1 -- CREATE SCHEMA unix_sql_api;
3 SET search_path TO unix_sql_api;
6 -- fstab: --------------------------------------------------------------------
8 DROP VIEW IF EXISTS fstab;
9 DROP FUNCTION IF EXISTS fstab();
10 DROP TYPE IF EXISTS unix_sql_api_fstab;
12 CREATE TYPE unix_sql_api_fstab AS (
24 CREATE OR REPLACE FUNCTION fstab()
25 RETURNS SETOF unix_sql_api_fstab AS $$
29 open(FSTAB, "<", "/etc/fstab") or die $!;
32 if (/^([^\s#]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+(\d+)\s+(\d+)\s*$/) {
35 my $device_spec_value;
37 if ($1 =~ /([^=]+)=(.*)/) {
38 ($device_spec_type, $device_spec_value) = ($1, $2);
44 device_type => $device_spec_type,
45 device_value => $device_spec_value,
48 types => [split(",", $3)],
49 options => [split(",", $4)],
59 CREATE OR REPLACE VIEW fstab AS
64 -- user groups: --------------------------------------------------------------
66 DROP VIEW IF EXISTS groups;
67 DROP FUNCTION IF EXISTS groups();
68 DROP TYPE IF EXISTS unix_sql_api_groups;
70 CREATE TYPE unix_sql_api_groups AS (
76 CREATE OR REPLACE FUNCTION groups()
77 RETURNS SETOF unix_sql_api_groups AS $$
83 while (my $group = getgrent()) {
87 members => [@{$group->members}]
91 elog(NOTICE, "members field does not contain users who have this group as primary one");
96 CREATE OR REPLACE VIEW groups AS
97 SELECT * FROM groups()
99 COMMENT ON COLUMN groups.members IS 'does not contain users who have this group as primary one';
102 -- user: ---------------------------------------------------------------------
104 DROP VIEW IF EXISTS users;
105 DROP FUNCTION IF EXISTS users();
106 DROP TYPE IF EXISTS unix_sql_api_users;
108 CREATE TYPE unix_sql_api_users AS (
119 CREATE OR REPLACE FUNCTION users()
120 RETURNS SETOF unix_sql_api_users AS $$
124 use Encode; # FIXME: see below
127 while (my $user = getpwent()) {
132 # comment => $user->comment,
133 gecos => [split(",", Encode::decode("utf8", $user->gecos))], # FIXME: ugly hack – should be properly decoded in getpwent()
135 shell => $user->shell,
136 # expire => $user->expire
144 CREATE OR REPLACE VIEW users AS
145 SELECT * FROM users()