.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 2000-2005 SAP AG$$Page %$
.tm 12
.hm 6
.hs 3
.TT 1 $SQL$Project Distributed Database System$VAK19$
.tt 2 $$$
.TT 3 $ThomasA$AK_usertab_tools$1999-10-08$
***********************************************************
.nf
 
 .nf
 
    ========== licence begin  GPL
    Copyright (c) 2000-2005 SAP AG
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end
.fo
 
 
.fo
.nf
.sp
MODULE  : AK_usertab_tools
=========
.sp
Purpose : Methods manipulating catalog records of type
          tak_usertabrecord.
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :
 
        PROCEDURE
              a19all_del_usertab  (VAR acv : tak_all_command_glob;
                    buf : tak_sysbufferaddress);
 
        PROCEDURE
              a19add_usertab  (VAR acv : tak_all_command_glob;
                    VAR user       : tgg00_Surrogate;
                    VAR surrogate  : tgg00_Surrogate;
                    surrogate_desc : tak_usertab_descriptor);
 
        PROCEDURE
              a19adddefaultroletab  (VAR acv : tak_all_command_glob;
                    VAR user       : tgg00_Surrogate;
                    VAR role_id    : tgg00_Surrogate);
 
        PROCEDURE
              a19addroletab  (VAR acv : tak_all_command_glob;
                    VAR user       : tgg00_Surrogate;
                    VAR role_id    : tgg00_Surrogate);
 
        PROCEDURE
              a19AddSystemTab  (VAR acv : tak_all_command_glob;
                    VAR surrogate  : tgg00_Surrogate;
                    surrogate_desc : tak_usertab_descriptor);
 
        PROCEDURE
              a19DelSystemTab  (VAR acv : tak_all_command_glob;
                    VAR surrogate  : tgg00_Surrogate);
 
        PROCEDURE
              a19change_usertab  (VAR acv : tak_all_command_glob;
                    operation         : integer;
                    VAR user          : tgg00_Surrogate;
                    VAR surrogate     : tgg00_Surrogate;
                    VAR new_surrogate : tgg00_Surrogate);
 
        PROCEDURE
              a19del_usertab  (VAR acv : tak_all_command_glob;
                    VAR user      : tgg00_Surrogate;
                    VAR surrogate : tgg00_Surrogate);
 
        PROCEDURE
              a19deldefault_roles  (VAR acv : tak_all_command_glob;
                    VAR user_id : tgg00_Surrogate);
 
        PROCEDURE
              a19delroletab  (VAR acv : tak_all_command_glob;
                    VAR user      : tgg00_Surrogate;
                    VAR role_id   : tgg00_Surrogate);
 
        FUNCTION
              a19IsDefaultRole (VAR acv : tak_all_command_glob;
                    VAR user_id : tgg00_Surrogate;
                    VAR role_id : tgg00_Surrogate) : boolean;
 
        PROCEDURE
              a19set_default_context (VAR acv : tak_all_command_glob;
                    role_cnt : integer);
 
        FUNCTION
              a19user_knows_role (VAR acv : tak_all_command_glob;
                    VAR user_id : tgg00_Surrogate;
                    VAR role_id : tgg00_Surrogate) : boolean;
 
.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :
 
        FROM
              AK_universal_semantic_tools : VAK06;
 
        FUNCTION
              a06role_exist (
                    VAR acv          : tak_all_command_glob;
                    VAR role_name    : tsp00_KnlIdentifier;
                    dstate           : tak_directory_state;
                    VAR role_rec_ptr : tak_sysbufferaddress) : boolean;
 
        PROCEDURE
              a06inc_linkage (VAR linkage : tsp00_C2);
 
        PROCEDURE
              a06userid_get (VAR acv : tak_all_command_glob;
                    VAR userid : tgg00_Surrogate;
                    VAR ok     : boolean);
 
      ------------------------------ 
 
        FROM
              Systeminfo_cache   : VAK10;
 
        PROCEDURE
              a10del_sysinfo (VAR acv : tak_all_command_glob;
                    VAR syskey   : tgg00_SysInfoKey;
                    VAR b_err    : tgg00_BasisError);
 
        PROCEDURE
              a10table_cache_delete (VAR acv : tak_all_command_glob;
                    VAR tableid : tgg00_Surrogate);
 
        PROCEDURE
              a10_key_del  (VAR acv : tak_all_command_glob;
                    VAR syskey : tgg00_SysInfoKey);
 
        PROCEDURE
              a10_add_repl_sysinfo (VAR acv : tak_all_command_glob;
                    VAR syspoint : tak_sysbufferaddress;
                    add_sysinfo  : boolean;
                    VAR b_err    : tgg00_BasisError);
 
        PROCEDURE
              a10_fix_len_get_sysinfo (VAR acv : tak_all_command_glob;
                    VAR syskey   : tgg00_SysInfoKey;
                    dstate       : tak_directory_state;
                    required_len : integer;
                    plus         : integer;
                    VAR syspoint : tak_sysbufferaddress;
                    VAR b_err    : tgg00_BasisError);
 
        PROCEDURE
              a10new (VAR acv : tak_all_command_glob;
                    obj_size : tsp00_Int4;
                    VAR p    : tak_role_context_ptr);
 
        PROCEDURE
              a10get_sysinfo (VAR acv : tak_all_command_glob;
                    VAR syskey   : tgg00_SysInfoKey;
                    dstate       : tak_directory_state;
                    VAR syspoint : tak_sysbufferaddress;
                    VAR b_err    : tgg00_BasisError);
 
        PROCEDURE
              a10next_sysinfo (VAR acv : tak_all_command_glob;
                    VAR syskey   : tgg00_SysInfoKey;
                    stop_prefix  : integer;
                    dstate       : tak_directory_state;
                    reckind      : tsp00_C2;
                    VAR syspoint : tak_sysbufferaddress;
                    VAR b_err    : tgg00_BasisError);
 
        PROCEDURE
              a10repl_sysinfo (VAR acv : tak_all_command_glob;
                    VAR syspoint : tak_sysbufferaddress;
                    VAR b_err    : tgg00_BasisError);
 
      ------------------------------ 
 
        FROM
              Scanner : VAK01;
 
        VAR
              a01defaultkey : tgg00_SysInfoKey;
              a01_i_dbarole : tsp00_KnlIdentifier;
 
      ------------------------------ 
 
        FROM
              AK_error_handling : VAK07;
 
        PROCEDURE
              a07ak_system_error (VAR acv : tak_all_command_glob;
                    modul_no : integer;
                    id       : integer);
 
        PROCEDURE
              a07_b_put_error (VAR acv : tak_all_command_glob;
                    b_err : tgg00_BasisError;
                    err_code : tsp00_Int4);
&       ifdef trace
 
      ------------------------------ 
 
        FROM
              Test_Procedures  : VTA01;
 
        PROCEDURE
              t01surrogate (
                    debug     : tgg00_Debug;
                    nam       : tsp00_Sname (*ptocSynonym const char**);
                    VAR tabid : tgg00_Surrogate);
&       endif
 
.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :
 
        PROCEDURE
              a10new;
 
              tak_sysbufferaddress tak_role_context_ptr
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : ThomasA
.sp
.cp 3
Created : 1979-06-07
.sp
.cp 3
.sp
.cp 3
Release :      Date : 1999-10-08
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:
 
PROCEDURE  A19_ADD_USERTAB
                  VAR acv     : all_command_glob;
                  VAR user    : user_id;
                  VAR authid  : user_id;
                  VAR tablen  : name;
                  owner       : boolean);
.sp 2;.cp 17
The table 'authid.tablen' is entered in the catalog information of type
tusertabrecord of the user 'user'. It is not checked whether the table has
already been entered, because this was already checked in the individual
commands. The table is inserted into the first free component of the Usertab
record. When entries have been made in all components in all tusertabrecords of
the user 'User', a follow-up record is created.
.sp 4;.cp 13;.nf
PROCEDURE  A19DEL_USERTAB
                  VAR acv     : all_command_glob;
                  VAR user    : user_id;
                  VAR authid  : user_id;
                  VAR tablen  : name);
.sp;.fo
The table authid.tablen is deleted from the catalog information of type
tusertabrecord of the user 'user'. A search is made until the table is found in
a tusertabrecord or until all records have been searched. All empty entries at
the end of the record are removed. If this results in the entire record
becoming empty, it is still not deleted, because the setting of new pointers
for the usertabrecords would be too expensive.
.sp 4;.cp 8;.nf
PROCEDURE  A19_REPL_USERTAB
                  VAR acv     : all_command_glob;
                  VAR user    : user_id;
                  VAR authid  : user_id;
                  VAR tablen  : name;
                  owner       : boolean);
.sp;.fo
The 'owner' entry in a table authid.tablen is altered in the tusertabrecord of
the user 'user'. The first entry that is found is altered in the
usertabrecords.
.sp 4;.cp 6;.nf
PROCEDURE  A19_ALL_DEL_USERTAB:
                  VAR acv         : all_command_glob;
                  VAR authid      : user_id;
                  VAR tablen      : name;
                  del_in_ownerrec : boolean);
.sp;.fo
The table authid.tablen is removed from all catalog information of type
tusertabrecord. By means of a19del_usertab, the table is first of all deleted
from the tusertabrecords of the user PUBLIC. If the table
is also to be deleted from the tusertabrecord of the owner of the table
(del_in_ownerrec = TRUE), this is also handled by a19_del_usertab. All other
users who contain the table in their tusertabrecords must have a privilege on
the table. For each catalog record of type tprivrecord that is
found, a19del_usertab is called with the respective user.
.sp 2
.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:
 
.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:
 
.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
 
 
CONST
      c_is_system_id = true;
 
 
(*------------------------------*) 
 
PROCEDURE
      a19add_usertab  (VAR acv : tak_all_command_glob;
            VAR user       : tgg00_Surrogate;
            VAR surrogate  : tgg00_Surrogate;
            surrogate_desc : tak_usertab_descriptor);
 
BEGIN
ak19add_usertab (acv, NOT c_is_system_id, cak_eusertab, chr(0),
      user, surrogate, surrogate_desc)
END; { a19add_usertab }
 
(*------------------------------*) 
 
PROCEDURE
      a19adddefaultroletab  (VAR acv : tak_all_command_glob;
            VAR user       : tgg00_Surrogate;
            VAR role_id    : tgg00_Surrogate);
 
BEGIN
ak19add_usertab (acv, NOT c_is_system_id, cak_eroletab, chr(128),
      user, role_id, ut_role)
END;
 
(*------------------------------*) 
 
PROCEDURE
      a19addroletab  (VAR acv : tak_all_command_glob;
            VAR user       : tgg00_Surrogate;
            VAR role_id    : tgg00_Surrogate);
 
BEGIN
ak19add_usertab (acv, NOT c_is_system_id, cak_eroletab, chr(0),
      user, role_id, ut_role)
END;
 
(*------------------------------*) 
 
PROCEDURE
      a19AddSystemTab  (VAR acv : tak_all_command_glob;
            VAR surrogate  : tgg00_Surrogate;
            surrogate_desc : tak_usertab_descriptor);
 
VAR
      systemId : tgg00_Surrogate;
 
BEGIN
systemId := cgg_zero_id;
ak19add_usertab (acv, c_is_system_id, cak_eusertab, chr(0), systemId, surrogate, surrogate_desc)
END;
 
(*------------------------------*) 
 
PROCEDURE
      a19DelSystemTab  (VAR acv : tak_all_command_glob;
            VAR surrogate  : tgg00_Surrogate);
 
VAR
      systemId : tgg00_Surrogate;
 
BEGIN
(* PTS 1133300 TA 2005-01-11 new *)
systemId := cgg_zero_id;
a19change_usertab  (acv, cak_i_system, systemId, surrogate, surrogate)
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak19add_usertab  (VAR acv : tak_all_command_glob;
            isSystemId     : boolean;
            entrytype      : tsp00_C2;
            linkage_1      : char;
            VAR user       : tgg00_Surrogate;
            VAR surrogate  : tgg00_Surrogate;
            surrogate_desc : tak_usertab_descriptor);
      (*===============================================*)
      (* inserts the surrogate into the tusertab       *)
      (* record of then use identified by the userid   *)
      (* <user>. tab_loc is the location, where the    *)
      (* catalog information of <tabid> can be found.  *)
      (* owner is true, if <user> is owner of <tabid>  *)
      (*===============================================*)
 
VAR
      inserted       : boolean;
      next_exist     : boolean;
      ok             : boolean;
      repl_sysinfo   : boolean;
      b_err          : tgg00_BasisError;
      i              : integer;
      tab_pos        : integer;
      userbuf        : tak_sysbufferaddress;
      userkey        : tgg00_SysInfoKey;
 
BEGIN
IF  acv.a_returncode = 0
THEN
    BEGIN
    IF  isSystemId OR (user = cak_public_id) OR (entrytype = cak_eroletab)
    THEN
        repl_sysinfo := true
    ELSE
        BEGIN
        IF  user = cak_replication_usertab_id
        THEN
            ok := true
        ELSE
            a06userid_get (acv, user, ok);
        (*ENDIF*) 
        IF  ok
        THEN
            repl_sysinfo := false
        ELSE
            a07ak_system_error (acv, 19, 3)
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  acv.a_returncode = 0
THEN
    BEGIN
    userkey := a01defaultkey;
    WITH userkey DO
        BEGIN
        sauthid   := user;
        sentrytyp := entrytype;
        IF  repl_sysinfo AND
            (user <> cak_public_id) AND (sentrytyp <> cak_eroletab)
        THEN
            slinkage[ 1 ] := chr (128)
        ELSE
            slinkage[ 1 ] := linkage_1
        (*ENDIF*) 
        END;
    (*ENDWITH*) 
    inserted := false;
    REPEAT
        b_err      := e_ok;
        next_exist := false;
        a10_fix_len_get_sysinfo (acv, userkey, d_release,
              cak_sysbufferoffset+mxak_usertabdef+mxak_usertab_offset,
              mxak_usertabdef, userbuf, b_err);
        IF  acv.a_returncode = 0
        THEN
            BEGIN
            WITH userbuf^, susertab DO
                BEGIN
                IF  b_err = e_sysinfo_not_found
                THEN
                    BEGIN (* User has no usertab record *)
                    IF  repl_sysinfo
                    THEN
                        usertabsegmentid  := cak00_public_segment_id
                    ELSE
                        usertabsegmentid  := cak00_local_segment_id;
                    (*ENDIF*) 
                    usertabfiller     := 0;
                    usertabnext_exist := false;
                    usertabfull       := false;
                    usertabcount      := 0;
                    b_sl := cak_sysbufferoffset + mxak_usertab_offset
                    END;
                (*ENDIF*) 
                IF  usertabfull AND NOT inserted
                THEN
                    BEGIN
                    IF  NOT usertabnext_exist
                    THEN
                        BEGIN (* prepare successor record *)
                        usertabnext_exist := true;
                        a10repl_sysinfo (acv, userbuf, b_err);
                        END
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
                next_exist := usertabnext_exist;
                tab_pos := 0;
                i       := 1;
                WHILE i <= usertabcount DO
                    WITH usertabdef[ i ] DO
                        BEGIN
                        IF  ut_empty (* PTS 1114164 *)
                        THEN
                            BEGIN
                            IF  NOT inserted AND (tab_pos = 0)
                            THEN
                                tab_pos := i
                            (*ENDIF*) 
                            END
                        ELSE
                            IF  ut_surrogate = surrogate
                            THEN
                                a07ak_system_error (acv, 19, 1);
                            (*ENDIF*) 
                        (*ENDIF*) 
                        i := succ(i);
                        END;
                    (*ENDWITH*) 
                (*ENDWHILE*) 
                IF  NOT (usertabfull) AND NOT (inserted)
                THEN
                    BEGIN
                    IF  tab_pos = 0
                    THEN
                        BEGIN
                        usertabcount := usertabcount + 1;
                        b_sl         := b_sl + mxak_usertabdef;
                        tab_pos      := usertabcount;
                        END;
                    (*ENDIF*) 
                    IF  usertabcount = cak_max_usertab
                    THEN
                        usertabfull := true;
                    (*ENDIF*) 
                    WITH usertabdef [ tab_pos ] DO
                        BEGIN
                        ut_surrogate := surrogate;
                        ut_empty     := false;
                        ut_kind      := surrogate_desc;
                        inserted     := true;
                        FOR i := 1 TO usertabcount DO
                            IF  usertabdef[ i ].ut_empty
                            THEN
                                usertabfull := false;
                            (*ENDIF*) 
                        (*ENDFOR*) 
                        a10_add_repl_sysinfo (acv, userbuf,
                              b_err = e_sysinfo_not_found, b_err)
                        END;
                    (*ENDWITH*) 
                    END;
                (*ENDIF*) 
                END;
            (*ENDWITH*) 
            END;
        (*ENDIF*) 
        a06inc_linkage (userkey.slinkage);
        IF  b_err <> e_ok
        THEN
            a07_b_put_error (acv, b_err, 1);
        (*ENDIF*) 
    UNTIL
        (NOT(next_exist)) OR (acv.a_returncode <> 0);
    (*ENDREPEAT*) 
    END;
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a19change_usertab  (VAR acv : tak_all_command_glob;
            operation         : integer;
            VAR user          : tgg00_Surrogate;
            VAR surrogate     : tgg00_Surrogate;
            VAR new_surrogate : tgg00_Surrogate);
      (*============================================================*)
      (* Deletes or updates the entry of the tableid or procedureid *)
      (* (surrogate) from the tusertab record of user <user>        *)
      (*============================================================*)
 
VAR
      ok             : boolean;
      stop           : boolean;
      found          : boolean;
      b_err          : tgg00_BasisError;
      i              : integer;
      userbuf        : tak_sysbufferaddress;
      userkey        : tgg00_SysInfoKey;
 
BEGIN
IF  acv.a_returncode = 0
THEN
    BEGIN
    ok := true; (* PTS 1133300 TA 2005-01-11 *)
&   ifdef trace
    t01surrogate (ak_sem, 'userid      ', user);
    t01surrogate (ak_sem, 'surrogate   ', surrogate);
&   endif
    IF  (user = cak_public_id) OR (user = cak_replication_usertab_id)
    THEN
        ok := true
    ELSE
        IF  operation <> cak_i_system (* PTS 1133300 TA 2005-01-11 *)
        THEN
            BEGIN
            a06userid_get (acv, user, ok);
            IF  NOT ok
            THEN
                a07ak_system_error (acv, 19, 2)
            (*ENDIF*) 
            END;
        (*ENDIF*) 
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  (acv.a_returncode = 0) AND ok
THEN
    BEGIN
    userkey := a01defaultkey;
    WITH userkey DO
        BEGIN
        sauthid   := user;
        IF  operation in [cak_i_role, cak_i_default]
        THEN
            sentrytyp := cak_eroletab
        ELSE
            sentrytyp := cak_eusertab;
        (*ENDIF*) 
        IF  operation in [cak_i_default, cak_i_system] (* PTS 1133300 TA 2005-01-11 *)
        THEN (* delete in default roles *)
            slinkage[1] := chr(128);
        (*ENDIF*) 
        END;
    (*ENDWITH*) 
    found := false;
    REPEAT
        a10get_sysinfo (acv, userkey, d_release,
              userbuf, b_err);
        IF  b_err = e_ok
        THEN
            BEGIN
            i := 1;
            WHILE (NOT found) AND
                  (i <= userbuf^.susertab.usertabcount) DO
                BEGIN
                WITH userbuf^.susertab.usertabdef[ i ] DO
                    BEGIN
                    IF  NOT ut_empty
                    THEN
                        IF  ut_surrogate = surrogate
                        THEN
                            BEGIN
                            found := true;
                            IF  (operation = cak_i_delete ) OR
                                (operation = cak_i_role   ) OR
                                (operation = cak_i_default) OR
                                (operation = cak_i_system ) (* PTS 1133300 TA 2005-01-11 *)
                            THEN
                                BEGIN
                                ut_empty    := true;
                                userbuf^.susertab.usertabfull :=
                                      false;
                                END
                            ELSE
                                ut_surrogate := new_surrogate;
                            (*ENDIF*) 
                            END;
                        (*ENDIF*) 
                    (*ENDIF*) 
                    END;
                (*ENDWITH*) 
                i := i + 1;
                END;
            (*ENDWHILE*) 
            IF  found
            THEN
                BEGIN (* Table found on current usertab record *)
                i     := userbuf^.susertab.usertabcount;
                stop  := (operation = cak_i_delete) OR
                      (operation = cak_i_role) OR (operation = cak_i_default);
                WHILE NOT(stop) DO
                    IF  i > 0
                    THEN
                        IF  userbuf^.susertab.usertabdef[ i ].ut_empty
                        THEN
                            i := pred(i)
                        ELSE
                            stop := true
                        (*ENDIF*) 
                    ELSE
                        stop := true;
                    (*ENDIF*) 
                (*ENDWHILE*) 
                userbuf^.susertab.usertabcount := i;
                userbuf^.b_sl := i * mxak_usertabdef +
                      cak_sysbufferoffset + mxak_usertab_offset;
                a10repl_sysinfo (acv, userbuf, b_err);
                IF  b_err <> e_ok
                THEN
                    a07_b_put_error (acv, b_err, 1);
                (*ENDIF*) 
                END
            ELSE (* Table not found on current usertab record *)
                IF  userbuf^.susertab.usertabnext_exist
                THEN (* search table on successor record *)
                    a06inc_linkage (userkey.slinkage)
                ELSE
                    b_err := e_sysinfo_not_found
                (*ENDIF*) 
            (*ENDIF*) 
            END
        ELSE
            IF  b_err <> e_sysinfo_not_found
            THEN
                a07_b_put_error (acv, b_err, 1);
            (*ENDIF*) 
        (*ENDIF*) 
    UNTIL
        (found) OR (b_err <> e_ok);
    (*ENDREPEAT*) 
    END;
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a19deldefault_roles  (VAR acv : tak_all_command_glob;
            VAR user_id : tgg00_Surrogate);
 
VAR
      b_err   : tgg00_BasisError;
      sysk    : tgg00_SysInfoKey;
 
BEGIN
sysk             := a01defaultkey;
sysk.sauthid     := user_id;
sysk.sentrytyp   := cak_eroletab;
sysk.slinkage[1] := chr(128);
a10del_sysinfo (acv, sysk, b_err);
IF  b_err <> e_ok
THEN
    a07_b_put_error (acv, b_err, 1)
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a19del_usertab  (VAR acv : tak_all_command_glob;
            VAR user      : tgg00_Surrogate;
            VAR surrogate : tgg00_Surrogate);
      (*=========================================*)
      (* Deletes the tableid or procedureid      *)
      (* (surrogate) from the tusertab record of *)
      (* user <user>                             *)
      (*=========================================*)
 
BEGIN
a19change_usertab  (acv,
      cak_i_delete, user, surrogate, surrogate)
END;
 
(*------------------------------*) 
 
PROCEDURE
      a19delroletab  (VAR acv : tak_all_command_glob;
            VAR user      : tgg00_Surrogate;
            VAR role_id   : tgg00_Surrogate);
 
BEGIN
a19change_usertab  (acv,
      cak_i_role, user, role_id, role_id);
a19change_usertab  (acv,
      cak_i_default, user, role_id, role_id)
END;
 
(*------------------------------*) 
 
PROCEDURE
      a19all_del_usertab  (VAR acv : tak_all_command_glob;
            buf : tak_sysbufferaddress);
      (*===================================================*)
      (* Deletes the table identified by buf from the      *)
      (* tusertab records of all users                     *)
      (*===================================================*)
 
VAR
      b_err     : tgg00_BasisError;
      privbuf   : tak_sysbufferaddress;
      user      : tgg00_Surrogate;
      privkey   : tgg00_SysInfoKey;
 
BEGIN
WITH acv DO
    IF  a_returncode = 0
    THEN
        WITH buf^, syskey, sbase DO
            BEGIN
            IF  (bpriv_all_set <> []) OR (bpriv_col_exist <> [])
            THEN
                BEGIN
                user := cak_public_id;
                a19del_usertab (acv, user, stableid)
                END;
            (*ENDIF*) 
            IF  (bschema <> bauthid) AND (a_returncode = 0)
            THEN
                a19del_usertab (acv, bauthid, stableid);
            (*ENDIF*) 
            b_err             := e_ok;
            privkey           := buf^.syskey;
            privkey.sentrytyp := cak_epriv;
            WHILE (b_err = e_ok) AND (a_returncode = 0) DO
                BEGIN
                a10next_sysinfo (acv, privkey, SURROGATE_MXGG00+2,
                      d_release, cak_epriv, privbuf, b_err);
                IF  b_err = e_ok
                THEN
                    IF  privbuf^.syskey.suserid <> bauthid
                    THEN
                        BEGIN
                        user := privbuf^.syskey.suserid;
                        a19del_usertab (acv, user, stableid)
                        END;
                    (*ENDIF*) 
                (*ENDIF*) 
                END;
            (*ENDWHILE*) 
            IF  b_err <> e_no_next_record
            THEN
                a07_b_put_error (acv, b_err, 1);
            (*ENDIF*) 
            END;
        (*ENDWITH*) 
    (*ENDIF*) 
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a19set_default_context (VAR acv : tak_all_command_glob;
            role_cnt : integer);
 
VAR
      b_err       : tgg00_BasisError;
      p           : tak_role_context_ptr;
      ix          : integer;
      roletab_ptr : tak_sysbufferaddress;
      sysk        : tgg00_SysInfoKey;
 
BEGIN
a10new (acv, sizeof (tsp00_Int4) + role_cnt * sizeof (tgg00_Surrogate), p);
IF  p <> NIL
THEN
    BEGIN
    p^.rctxt_cnt := 0;
    IF  acv.a_current_user_kind in [udba, usysdba]
    THEN
        BEGIN
        IF  a06role_exist (acv, a01_i_dbarole, d_release, roletab_ptr)
        THEN
            BEGIN
            p^.rctxt_cnt := p^.rctxt_cnt + 1;
            p^.rctxt_roles[p^.rctxt_cnt] := roletab_ptr^.suser.usurrogate;
            END
        ELSE
            role_cnt := role_cnt - 1;
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    sysk             := a01defaultkey;
    sysk.sauthid     := acv.a_curr_user_id;
    sysk.sentrytyp   := cak_eroletab;
    sysk.slinkage[1] := chr(128);
    REPEAT;
        a10get_sysinfo (acv, sysk, d_release,
              roletab_ptr, b_err);
        IF  b_err = e_ok
        THEN
            WITH roletab_ptr^.susertab DO
                BEGIN
                FOR ix := 1 TO usertabcount DO
                    IF  NOT usertabdef[ix].ut_empty
                    THEN
                        IF  p^.rctxt_cnt < role_cnt
                        THEN
                            BEGIN
                            p^.rctxt_cnt := p^.rctxt_cnt + 1;
                            p^.rctxt_roles[p^.rctxt_cnt] :=
                                  usertabdef[ix].ut_surrogate
                            END;
                        (*ENDIF*) 
                    (*ENDIF*) 
                (*ENDFOR*) 
                IF  usertabnext_exist
                THEN
                    a06inc_linkage (sysk.slinkage)
                ELSE
                    b_err := e_sysinfo_not_found
                (*ENDIF*) 
                END;
            (*ENDWITH*) 
        (*ENDIF*) 
    UNTIL
        b_err <> e_ok;
    (*ENDREPEAT*) 
    IF  b_err = e_sysinfo_not_found
    THEN
        acv.a_role_ptr := p
    ELSE
        a07_b_put_error (acv, b_err, 1)
    (*ENDIF*) 
    END;
(*ENDIF*) 
END;
 
(* PTS 1104069 *)
(*------------------------------*) 
 
FUNCTION
      a19IsDefaultRole (VAR acv : tak_all_command_glob;
            VAR user_id : tgg00_Surrogate;
            VAR role_id : tgg00_Surrogate) : boolean;
 
BEGIN
a19IsDefaultRole := ak19FindInUserRoles (acv, user_id, role_id, true);
END;
 
(*------------------------------*) 
 
FUNCTION
      a19user_knows_role (VAR acv : tak_all_command_glob;
            VAR user_id : tgg00_Surrogate;
            VAR role_id : tgg00_Surrogate) : boolean;
 
VAR
      userKnownsRole : boolean;
      pRole          : tak_sysbufferaddress;
 
BEGIN
userKnownsRole := false;
IF  acv.a_current_user_kind in [udba, usysdba]
THEN
    IF  a06role_exist (acv, a01_i_dbarole, d_release, pRole)
    THEN
        userKnownsRole := pRole^.suser.usurrogate = role_id;
    (*ENDIF*) 
(*ENDIF*) 
IF  NOT userKnownsRole
THEN
    userKnownsRole := ak19FindInUserRoles (acv, user_id, role_id, false); (* PTS 1104069 *)
(*ENDIF*) 
a19user_knows_role := userKnownsRole;
END;
 
(* PTS 1104069 *)
(*------------------------------*) 
 
FUNCTION
      ak19FindInUserRoles (VAR acv : tak_all_command_glob;
            VAR user_id        : tgg00_Surrogate;
            VAR role_id        : tgg00_Surrogate;
            findInDefaultRoles : boolean) : boolean;
 
VAR
      found       : boolean;
      b_err       : tgg00_BasisError;
      ix          : integer;
      roletab_ptr : tak_sysbufferaddress;
      rolekey     : tgg00_SysInfoKey;
 
BEGIN
found             := false;
rolekey           := a01defaultkey;
rolekey.sauthid   := user_id;
rolekey.sentrytyp := cak_eroletab;
IF  findInDefaultRoles
THEN
    rolekey.slinkage[1] := chr(128);
(*ENDIF*) 
REPEAT
    a10get_sysinfo (acv, rolekey, d_release, roletab_ptr, b_err);
    IF  b_err = e_ok
    THEN
        WITH roletab_ptr^.susertab DO
            BEGIN
            ix := 1;
            WHILE ix <= usertabcount DO
                WITH usertabdef[ix] DO
                    IF  NOT ut_empty AND (ut_surrogate = role_id)
                    THEN
                        BEGIN
                        found := true;
                        ix    := usertabcount + 1;
                        END
                    ELSE
                        ix := ix + 1;
                    (*ENDIF*) 
                (*ENDWITH*) 
            (*ENDWHILE*) 
            IF  usertabnext_exist AND NOT found
            THEN
                a06inc_linkage (rolekey.slinkage)
            ELSE
                b_err := e_sysinfo_not_found
            (*ENDIF*) 
            END;
        (*ENDWITH*) 
    (*ENDIF*) 
    IF  NOT found                          AND
        (b_err = e_sysinfo_not_found     ) AND
        NOT findInDefaultRoles             AND
        (rolekey.sauthid <> cak_public_id)
    THEN
        BEGIN
        b_err            := e_ok;
        rolekey.sauthid  := cak_public_id;
        rolekey.slinkage := cak_init_linkage
        END;
    (*ENDIF*) 
UNTIL
    b_err <> e_ok;
(*ENDREPEAT*) 
ak19FindInUserRoles := found
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
.PA 
