Example: FTP Server Logon exit program in CL code

This is an example of a simple File Transfer Protocol (FTP) Server Logon exit program. It is written in control language (CL).

The following code is not complete, but provides a starting point to help you create your own program.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

(Preformatted text in the following example will flow outside the frame.)


/******************************************************************************/
/*                                                                            */
/*    Example FTP Server Logon exit program.                                  */
/*    Note:  This program is only an example and has not undergone any formal */
/*           review or testing.                                               */
/*                                                                            */
/*  Additional notes:                                                         */
/*  1. When the FTP server logon exit is called, the FTP server job is        */
/*     running under the QTCP user profile.                                   */
/*  2. For the ANONYMOUS case, users can add logging capability (for          */
/*     example, write the E-mail address entered for the password and         */
/*     the client IP address to a log file).                                  */
/*  3. IBM strongly recommends that you create the exit program in a library  */
/*     with *PUBLIC authority set to *EXCLUDE, and give the exit program      */
/*     itself a *PUBLIC authority of *EXCLUDE.  The FTP server adopts         */
/*     authority when it is necessary to resolve and call the exit program.   */
/*                                                                            */
/******************************************************************************/
 
 TSTLOGCL:   PGM        PARM(&APPIDIN &USRIN &USRLENIN &AUTIN &AUTLENIN +
                          &IPADDRIN &IPLENIN &RETCDOUT &USRPRFOUT &PASSWDOUT +
                          &CURLIBOUT)
 
/* Declare input parameters */
             DCL        VAR(&APPIDIN)    TYPE(*CHAR) LEN(4)  /* Application identifier  */
             DCL        VAR(&USRIN)      TYPE(*CHAR) LEN(999)/* User ID                 */
             DCL        VAR(&USRLENIN)   TYPE(*CHAR) LEN(4)  /* Length of user ID       */
             DCL        VAR(&AUTIN)      TYPE(*CHAR) LEN(999)/* Authentication string   */
             DCL        VAR(&AUTLENIN)   TYPE(*CHAR) LEN(4)  /* Length of auth. string  */
             DCL        VAR(&IPADDRIN)   TYPE(*CHAR) LEN(15) /* Client IP address       */
             DCL        VAR(&IPLENIN)    TYPE(*CHAR) LEN(4)  /* IP address length       */
             DCL        VAR(&RETCDOUT)   TYPE(*CHAR) LEN(4)  /* return code (out)       */
             DCL        VAR(&USRPRFOUT)  TYPE(*CHAR) LEN(10) /* user profile (out)      */
             DCL        VAR(&PASSWDOUT)  TYPE(*CHAR) LEN(10) /* password (out)          */
             DCL        VAR(&CURLIBOUT)  TYPE(*CHAR) LEN(10) /* current library (out)   */
 
/* Declare local copies of parameters (in format usable by CL) */
             DCL        VAR(&APPID)      TYPE(*DEC)  LEN(1 0)
             DCL        VAR(&USRLEN)     TYPE(*DEC) LEN(5 0)
             DCL        VAR(&AUTLEN)     TYPE(*DEC) LEN(5 0)
             DCL        VAR(&IPLEN)      TYPE(*DEC) LEN(5 0)
 
/* Assign input parameters to local copies */
             CHGVAR     VAR(&APPID)      VALUE(%BINARY(&APPIDIN))
             CHGVAR     VAR(&USRLEN)     VALUE(%BINARY(&USRLENIN))
             CHGVAR     VAR(&AUTLEN)     VALUE(%BINARY(&AUTLENIN))
             CHGVAR     VAR(&IPLEN)      VALUE(%BINARY(&IPLENIN))
 
/* Check for ANONYMOUS user.  Allow for ANONYMOUSA, etc. as "regular"  */
/* user profile. */
             IF         COND(&USRLEN = 9) THEN(DO)
               IF       COND(%SST(&USRIN 1 9) = 'ANONYMOUS')
THEN(DO)
/* For anonymous user: want to force user profile ANONYMOUS current library to PUBLIC. */
                 CHGVAR VAR(%BINARY(&RETCDOUT))  VALUE(6)
                 CHGVAR VAR(&USRPRFOUT)  VALUE('ANONYMOUS ')
                 CHGVAR VAR(&CURLIBOUT)  VALUE('PUBLIC    ')
               ENDDO
/* Any other user: proceed with normal logon processing. */
               ELSE     CMD(CHGVAR VAR(%BINARY(&RETCDOUT))  VALUE(1))
             ENDDO
             ELSE       CMD(CHGVAR VAR(%BINARY(&RETCDOUT))  VALUE(1))
 
 END:        ENDPGM