1.1 --- a/prototyp/prototyp.sql Mon Sep 01 16:04:59 2014 +0200
1.2 +++ b/prototyp/prototyp.sql Mon Sep 01 17:47:00 2014 +0200
1.3 @@ -77,10 +77,10 @@
1.4 RETURNS SETOF unix_sql_api_groups AS $$
1.5 use strict;
1.6 use warnings;
1.7 -
1.8 +
1.9 use User::grent;
1.10
1.11 - while (my $group = getgrent) {
1.12 + while (my $group = getgrent()) {
1.13 return_next({
1.14 id => $group->gid,
1.15 name => $group->name,
1.16 @@ -88,11 +88,60 @@
1.17 });
1.18 }
1.19
1.20 + elog(NOTICE, "members field does not contain users who have this group as primary one");
1.21 +
1.22 return undef;
1.23 $$ LANGUAGE plperlu;
1.24
1.25 CREATE OR REPLACE VIEW groups AS
1.26 SELECT * FROM groups()
1.27 ;
1.28 -COMMENT ON COLUMN groups.members IS 'does not contain users for who have this group as primary one';
1.29 +COMMENT ON COLUMN groups.members IS 'does not contain users who have this group as primary one';
1.30
1.31 +
1.32 +-- user: ---------------------------------------------------------------------
1.33 +
1.34 +DROP VIEW IF EXISTS users;
1.35 +DROP FUNCTION IF EXISTS users();
1.36 +DROP TYPE IF EXISTS unix_sql_api_users;
1.37 +
1.38 +CREATE TYPE unix_sql_api_users AS (
1.39 + id INTEGER,
1.40 + gid INTEGER,
1.41 + name VARCHAR,
1.42 + -- comment VARCHAR,
1.43 + gecos VARCHAR[],
1.44 + home VARCHAR,
1.45 + shell VARCHAR
1.46 + -- expire VARCHAR
1.47 +);
1.48 +
1.49 +CREATE OR REPLACE FUNCTION users()
1.50 +RETURNS SETOF unix_sql_api_users AS $$
1.51 + use strict;
1.52 + use warnings;
1.53 +
1.54 + use Encode; # FIXME: see below
1.55 + use User::pwent;
1.56 +
1.57 + while (my $user = getpwent()) {
1.58 + return_next({
1.59 + id => $user->uid,
1.60 + gid => $user->gid,
1.61 + name => $user->name,
1.62 + # comment => $user->comment,
1.63 + gecos => [split(",", Encode::decode("utf8", $user->gecos))], # FIXME: ugly hack – should be properly decoded in getpwent()
1.64 + home => $user->dir,
1.65 + shell => $user->shell,
1.66 + # expire => $user->expire
1.67 +
1.68 + });
1.69 + }
1.70 +
1.71 + return undef;
1.72 +$$ LANGUAGE plperlu;
1.73 +
1.74 +CREATE OR REPLACE VIEW users AS
1.75 + SELECT * FROM users()
1.76 +;
1.77 +