Qshell Interpreter (qsh) - FTP Directory Listing - IBM
Qshell Interpreter (qsh) - FTP Directory Listing - IBM
Qshell Interpreter (qsh) - FTP Directory Listing - IBM
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
120 <strong>Qshell</strong> <strong>Interpreter</strong> (<strong>qsh</strong>)<br />
#include /* spawn() */<br />
#include /* close(), read(), etc. */<br />
#include /* exit()*/<br />
#include /* va_start(), va_end() */<br />
#include /* Qp0zInitEnv() */<br />
#include /* QSYGETPH() */<br />
#include /* QWTSETP() */<br />
#include /* QSYRLSPH() */<br />
#include /* Qus_EC_t */<br />
#include /* getpwnam() */<br />
#include /* toupper() */<br />
#include /* ctime(), time() */<br />
#include /* Exception and cancel handling */<br />
#include /* errno and constants */<br />
/**********************************************************************/<br />
/* Constants */<br />
/**********************************************************************/<br />
#define DEFAULT_BUF 4096<br />
#define DEFAULT_PORT 6042<br />
#define NULL_PH “\0\0\0\0\0\0\0\0\0\0\0\0”<br />
#define PH_SIZE 12<br />
#define NAME_SIZE 11<br />
#undef PATH_MAX<br />
#define PATH_MAX 4096<br />
/**********************************************************************/<br />
/* Global Variables */<br />
/**********************************************************************/<br />
/* For logging errors */<br />
FILE *log_fp;<br />
char log_file[] = “/tmp/<strong>qsh</strong>_server.log”;<br />
char log_buffer[DEFAULT_BUF];<br />
/**********************************************************************/<br />
/* Function Prototypes */<br />
/**********************************************************************/<br />
int strtoupper(char *);<br />
int GetString(int, char *, size_t);<br />
void LogError(char *, ...);<br />
void SendError(int, char *, ...);<br />
void CleanupHandler(_CNL_Hndlr_Parms_T *);<br />
int main(int argc, char *argv[])<br />
{<br />
int sfd; /* Server's listening socket */<br />
int cfd; /* Socket connected to client */<br />
int on=1; /* Flag for setsockopt() */<br />
struct sockaddr_in my_addr; /* Address server binds to */<br />
struct sockaddr_in client_addr; /* Addrress of connected client */<br />
int client_addr_len; /* Length of client's socket address */<br />
unsigned short port; /* Server's TCP port */<br />
char server_ph[PH_SIZE+1] = NULL_PH; /* Server's profile handle */<br />
char client_ph[PH_SIZE+1] = NULL_PH; /* Client's profile handle */<br />
char profile[NAME_SIZE]; /* User profile read from client */<br />
char password[NAME_SIZE]; /* Password read from client */<br />
char sy_profile[NAME_SIZE]; /* User profile for AS/400 APIs */<br />
char sy_password[NAME_SIZE]; /* Password for AS/400 APIs */<br />
char server_profile[NAME_SIZE] = “*CURRENT ”;<br />
char no_pwd[NAME_SIZE] = “*NOPWD ”;<br />
struct passwd *cpw; /* User information for client */<br />
Qus_EC_t error = { sizeof(Qus_EC_t), 0 }; /* Error code for SPIs */<br />
/* Parameters for spawn() to shell process */<br />
char <strong>qsh</strong>_pgm[] = “/QSYS.LIB/QSHELL.LIB/QZSHSH.PGM”;<br />
char *args[5]; /* Argument array */<br />
char *envs[10]; /* Environment variable array */<br />
int fd_count; /* Number of descriptors */<br />
int fd_map[3]; /* Map of descriptors */<br />
struct inheritance inherit; /* Inheritance options */<br />
char server_dir[] = “/”; /* Default current working directory */<br />
/* Environment variables */