/*
   QUSERID EXEC (for VM (IBM mainframe) host)
   Jim Dutton - 21 Mar 2000, 24 Mar 2000, 30 Mar 2000, 11 Apr 2000
                20 Apr 2000, 03 May 2000
   Perform authorized connection to IP host "<LDAP host>" and
   execute the QUSERID command available there with userid passed here
*/
Address 'COMMAND'; parse arg parms 1 attrname "=" attrvalue1 "at" attrvalue2
'VMFCLEAR'
If parms = ""  then
  Do
    say 'Parameters are indicated by angle brackets,',
         'optional items by square brackets:'
    say; say 'QUSERID <VM/MVS userid>'
    say "QUSERID mail=<userid> at <mailhost>"
    say "QUSERID sn=<lastname>"
    say "QUSERID cn='[*]<firstname>[*] [*]<lastname>[*]'"
    say; say; say "Examples:"; say
    say "  quserid {VM userid sample}"
    say "  quserid mail={userid sample} at {remote mail host sample}"
    say "  quserid sn={lastname sample}"
    say "  quserid cn='{firstname lastname sample}'"
    say "  quserid cn='{firstname substr}* {lastname substr}*'"
    say; say; say "Notes:"; say
    say "Using either the sn (surname) or cn (common name) version",
        "will probably return"
    say "MORE than one entry, since you are asking for ALL entries",
        "with the indicated"
    say "value(s)."; say
    say "The asterisk is a 'wild card' (character) indicator/marker."
    say; Exit
  End
Else  parms = strip(parms)
 
upper attrname
/* "@" is/may be special VM console character, */
/* hence "at" required in command line parms   */
If attrname = "MAIL"  then
  parms = "mail="strip(attrvalue1)||'@'||strip(attrvalue2)

/* get VM userid information and remove extraneous blanks */ 
'IDENTIFY ( STACK'; parse pull w1 w2 w3 w4 w5 w6 w7 w8 w9 .
identify_string = w1 w2 w3 w4 w5 w6 w7 w8 w9
/* use UNIX logger command to log VM userid requesting search   */
/* normal logging only shows remote hostname, not remote userid */
logcmd = "logger -p auth.notice '"identify_string"'"

userauth = "-l <remote userid> -p <remote password>"
queryhost = "<LDAP server>"; querycmd = "quserid" parms
/*
  NOTE: YOU are responsible for host, user, and network security and
        monitoring (e.g. TCP_Wrappers, etc.)!! Do NOT blindly enable
        REXECD (on the remote host)!! You have been warned!
*/
'REXEC' userauth queryhost logcmd";"querycmd
Exit rc
