# HG changeset patch # User František Kučera # Date 1409586420 -7200 # Node ID bb406ad320b6e9f5759924b9b10f5b9cee16a717 # Parent b0bbfff8eca13c795d7774e57f08799fdbdfec9a prototyp: users diff -r b0bbfff8eca1 -r bb406ad320b6 prototyp/prototyp.sql --- a/prototyp/prototyp.sql Mon Sep 01 16:04:59 2014 +0200 +++ b/prototyp/prototyp.sql Mon Sep 01 17:47:00 2014 +0200 @@ -77,10 +77,10 @@ RETURNS SETOF unix_sql_api_groups AS $$ use strict; use warnings; - + use User::grent; - while (my $group = getgrent) { + while (my $group = getgrent()) { return_next({ id => $group->gid, name => $group->name, @@ -88,11 +88,60 @@ }); } + elog(NOTICE, "members field does not contain users who have this group as primary one"); + return undef; $$ LANGUAGE plperlu; CREATE OR REPLACE VIEW groups AS SELECT * FROM groups() ; -COMMENT ON COLUMN groups.members IS 'does not contain users for who have this group as primary one'; +COMMENT ON COLUMN groups.members IS 'does not contain users who have this group as primary one'; + +-- user: --------------------------------------------------------------------- + +DROP VIEW IF EXISTS users; +DROP FUNCTION IF EXISTS users(); +DROP TYPE IF EXISTS unix_sql_api_users; + +CREATE TYPE unix_sql_api_users AS ( + id INTEGER, + gid INTEGER, + name VARCHAR, + -- comment VARCHAR, + gecos VARCHAR[], + home VARCHAR, + shell VARCHAR + -- expire VARCHAR +); + +CREATE OR REPLACE FUNCTION users() +RETURNS SETOF unix_sql_api_users AS $$ + use strict; + use warnings; + + use Encode; # FIXME: see below + use User::pwent; + + while (my $user = getpwent()) { + return_next({ + id => $user->uid, + gid => $user->gid, + name => $user->name, + # comment => $user->comment, + gecos => [split(",", Encode::decode("utf8", $user->gecos))], # FIXME: ugly hack – should be properly decoded in getpwent() + home => $user->dir, + shell => $user->shell, + # expire => $user->expire + + }); + } + + return undef; +$$ LANGUAGE plperlu; + +CREATE OR REPLACE VIEW users AS + SELECT * FROM users() +; +