Last active
June 29, 2022 08:17
-
-
Save NielsLiisberg/4fe2a49a31dada717709645dda19be51 to your computer and use it in GitHub Desktop.
SQL re-enable net user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Enable netserver user | |
-- This also showcase how to integrate the C code directly into your UDTF | |
-- | |
-- Simply paste this gist into ACS SQL and step through the example. | |
-- | |
-- It is a cool example how far you can go with SQL: Have fun 😀 | |
-- (C) Niels Liisberg 2022 | |
-- | |
-- This gist is distributed on an "as is" basis, without warranties | |
-- or conditions of any kind, either express or implied. | |
---------------------------------------------------------------------------------------------- | |
call qsys2.ifs_write( | |
path_name => '/tmp/main.c' , | |
file_ccsid => 1208, | |
overwrite => 'REPLACE', | |
line =>' | |
{ | |
#include <QSYSINC/H/QZLSCHSI> | |
char req [14]; | |
char err [8]; | |
int reqlen = sizeof(req); | |
memset ( err , 0 , sizeof(err)); | |
memcpy (req + 4 , ENABLE_NETSERVER_USER.USER_ID , 10); | |
*(long *) req = reqlen ; | |
QZLSCHSI (req , &reqlen , "ZLSS0200" , err); | |
} | |
'); | |
create or replace function qusrsys.enable_netserver_user ( | |
user_id char(10) | |
) | |
returns int | |
set option output=*print, commit=*none, dbgview = *source --list | |
main:begin | |
include '/tmp/main.c'; | |
return 0; | |
end; | |
-- unit test: | |
-- The caller of this scalar funciton needs to have authorization to use the QZLSCHSI api - net server api | |
values ( | |
qusrsys.enable_netserver_user ( 'THEUSER') | |
); | |
-- List all users and netserver status >= 7.3: | |
Select | |
authorization_name , | |
netserver_disabled | |
from qsys2.user_info_basic | |
where netserver_disabled = 'YES'; | |
-- List and re-enable all netserver disabled users by using our new scalar function | |
Select | |
authorization_name , | |
qusrsys.enable_netserver_user ( authorization_name) re_enabled | |
from qsys2.user_info_basic | |
where netserver_disabled = 'YES'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment