mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
Initial s390-tools-2.0.0 import
This commit is based on the s390-tools-1.39.0 version. Changes on top of s390-tools-1.39.0: - Add MIT license to all source files - Add LICENSE file - Transform REAMDE to README.md (markdown) - Add AUTHORS.md file - Add CONTRIBUTING.md file - Move changelog from README to CHANGELOG.md file Reviewed-by: Stefan Haberland <sth@linux.vnet.ibm.com> Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright IBM Corp. 2006, 2017
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
* IUCV protocol stack for Linux on zSeries
|
||||
* Version 1.0
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __AFIUCV_H
|
||||
#define __AFIUCV_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifndef AF_IUCV
|
||||
# define AF_IUCV 32
|
||||
# define PF_IUCV AF_IUCV
|
||||
#endif
|
||||
|
||||
/* IUCV socket address */
|
||||
struct sockaddr_iucv {
|
||||
sa_family_t siucv_family;
|
||||
unsigned short siucv_port; /* Reserved */
|
||||
unsigned int siucv_addr; /* Reserved */
|
||||
char siucv_nodeid[8]; /* Reserved */
|
||||
char siucv_user_id[8]; /* Guest User Id */
|
||||
char siucv_name[8]; /* Application Name */
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* iucvtty / iucvconn - IUCV Terminal Applications
|
||||
*
|
||||
* Configuration structure and command line processing function
|
||||
*
|
||||
* Copyright IBM Corp. 2008, 2017
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
#ifndef __IUCVTTY_CONFIG_H_
|
||||
#define __IUCVTTY_CONFIG_H_
|
||||
|
||||
enum iucvterm_prg {
|
||||
PROG_IUCV_TTY = 0,
|
||||
PROG_IUCV_CONN = 1,
|
||||
};
|
||||
|
||||
struct iucvterm_cfg {
|
||||
char client_re[129]; /* Regexp to match incoming clients */
|
||||
char host[9]; /* IUCV target host name */
|
||||
char service[9]; /* IUCV service name */
|
||||
char **cmd_parms; /* ptr to commandline parms */
|
||||
char *sessionlog; /* ptr to session log file path */
|
||||
unsigned char esc_char; /* Escape character */
|
||||
unsigned int flags; /* Configuration flags */
|
||||
};
|
||||
|
||||
/* configuration flags */
|
||||
#define CFG_F_CHKCLNT 0x0001 /* Check for permitted clients */
|
||||
|
||||
/* configuration macros */
|
||||
#define CFG_CHKCLNT(c) ((c)->flags & CFG_F_CHKCLNT)
|
||||
|
||||
|
||||
extern void parse_options(enum iucvterm_prg, struct iucvterm_cfg *,
|
||||
int, char **);
|
||||
|
||||
#endif /* __IUCVTTY_CONFIG_H_ */
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* iucvtty / iucvconn - IUCV Terminal Applications
|
||||
*
|
||||
* Definition of common functions
|
||||
*
|
||||
* Copyright IBM Corp. 2008, 2017
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
#ifndef __FUNCTIONS_H_
|
||||
#define __FUNCTIONS_H_
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "af_iucv.h"
|
||||
#include "inttypes.h"
|
||||
#include "iucvterm/config.h"
|
||||
#include "iucvterm/proto.h"
|
||||
|
||||
/* Message buffer: message header + 4096 bytes of data */
|
||||
#define MSG_BUFFER_SIZE (MSG_DATA_OFFSET + (4096))
|
||||
|
||||
/* Error macros */
|
||||
#define print_error(s) program_error(PRG_COMPONENT, (s))
|
||||
#define iucvtty_error(m) \
|
||||
do { \
|
||||
uint32_t *err = (uint32_t *) (m)->data; \
|
||||
iucv_msg_error(PRG_COMPONENT, *err); \
|
||||
} while (0);
|
||||
|
||||
/* Error codes */
|
||||
/* Unable to fork new process */
|
||||
#define ERR_FORK 105
|
||||
/* Cannot execute login program */
|
||||
#define ERR_CANNOT_EXEC_LOGIN 106
|
||||
/* Cannot set up terminal as a login terminal */
|
||||
#define ERR_SETUP_LOGIN_TTY 107
|
||||
/* Client (vm guest) is not authorized */
|
||||
#define ERR_NOT_AUTHORIZED 110
|
||||
|
||||
|
||||
extern int iucvtty_handle_req(int);
|
||||
|
||||
extern int iucvtty_socket(struct sockaddr_iucv *,
|
||||
const char *, const char *);
|
||||
|
||||
extern int iucvtty_tx_termenv(int, char *);
|
||||
extern int iucvtty_rx_termenv(int, void *, size_t);
|
||||
extern int iucvtty_tx_winsize(int, int);
|
||||
extern int iucvtty_tx_data(int, int, struct iucvtty_msg *, size_t);
|
||||
extern int iucvtty_tx_error(int, uint32_t);
|
||||
extern int iucvtty_copy_data(int, struct iucvtty_msg *);
|
||||
extern int iucvtty_read_data(int, struct iucvtty_msg *, size_t);
|
||||
|
||||
extern int iucvtty_read_msg(int, struct iucvtty_msg *, size_t, size_t *);
|
||||
extern int iucvtty_write_msg(int, struct iucvtty_msg *);
|
||||
extern void iucvtty_skip_msg_residual(int, size_t *);
|
||||
|
||||
extern ssize_t __write(int, const void*, size_t);
|
||||
|
||||
extern int strmatch(const char *, const char *);
|
||||
extern int is_regex_valid(const char *);
|
||||
extern int is_client_allowed(const char *, const struct iucvterm_cfg *);
|
||||
extern void userid_cpy(char [8], const char [8]);
|
||||
|
||||
extern void iucv_msg_error(const char *, uint32_t);
|
||||
extern void program_error(const char *, const char *);
|
||||
|
||||
/* Audit/session log */
|
||||
extern int open_session_log(const char *);
|
||||
extern ssize_t write_session_log(const void*, size_t);
|
||||
extern void write_session_info(const char *, ...);
|
||||
extern void close_session_log(void);
|
||||
|
||||
#endif /* __FUNCTIONS_H_ */
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* iucvtty / iucvconn - IUCV Terminal Applications
|
||||
*
|
||||
* National language support (NLS) functions
|
||||
*
|
||||
* Copyright IBM Corp. 2008, 2017
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
#ifndef __IUCVTTY_GETTEXT_H_
|
||||
#define __IUCVTTY_GETTEXT_H_
|
||||
|
||||
#ifdef USE_NLS
|
||||
# include <locale.h>
|
||||
# include <libintl.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* Gettext constants (should be supplied from Makefile) */
|
||||
#ifndef GETTEXT_TEXTDOMAIN
|
||||
# define GETTEXT_TEXTDOMAIN "iucvterm"
|
||||
#endif
|
||||
#ifndef GETTEXT_NLS_PATH
|
||||
# define GETTEXT_NLS_PATH "/usr/share/locale"
|
||||
#endif
|
||||
|
||||
|
||||
/* Gettext macros */
|
||||
#ifdef USE_NLS
|
||||
# define _(translatable) gettext(translatable)
|
||||
#else
|
||||
# define _(translatable) (translatable)
|
||||
#endif
|
||||
|
||||
#define N_(translatable) (translatable)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* gettext_setup_locale() - Init gettext text domain using a specific locale
|
||||
* @locale: Locale to be set.
|
||||
*
|
||||
* The function sets the program locale for LC_MESSAGES and then initializes
|
||||
* gettext.
|
||||
*
|
||||
* The @locale parameter is directly passed to the setlocale() function.
|
||||
* If @locale is "", LC_MESSAGES is set according to the environment variable.
|
||||
*/
|
||||
static inline int gettext_init_locale(const char *locale)
|
||||
{
|
||||
#ifdef USE_NLS
|
||||
if (setlocale(LC_MESSAGES, locale) == NULL)
|
||||
return -1;
|
||||
if (bindtextdomain(GETTEXT_TEXTDOMAIN, GETTEXT_NLS_PATH) == NULL)
|
||||
return -1;
|
||||
if (textdomain(GETTEXT_TEXTDOMAIN) == NULL)
|
||||
return -1;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* gettext_setup() - Initialize gettext text domain
|
||||
*
|
||||
* Calls gettext_setup_locale() with "" as locale parameter value.
|
||||
*/
|
||||
static inline int gettext_init(void)
|
||||
{
|
||||
#ifdef USE_NLS
|
||||
return gettext_init_locale("");
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif /* __IUCVTTY_GETTEXT_H_ */
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* iucvtty / iucvconn - IUCV Terminal Applications
|
||||
*
|
||||
* Structure and function definitions for the IUCV terminal message protocol
|
||||
*
|
||||
* Copyright IBM Corp. 2008, 2017
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
#ifndef __IUCVTTY_PROTO_H_
|
||||
#define __IUCVTTY_PROTO_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lib/util_base.h"
|
||||
|
||||
/* Standard macros */
|
||||
#ifndef offsetof
|
||||
# define offsetof(type, member) ((size_t) &((type *)0)->member)
|
||||
#endif
|
||||
|
||||
/* Packet version magic */
|
||||
#define MSG_VERSION 0x02
|
||||
/* Message types */
|
||||
#define MSG_TYPE_ERROR 0x01 /* Error message. */
|
||||
#define MSG_TYPE_TERMENV 0x02 /* Terminal environment variable. */
|
||||
#define MSG_TYPE_TERMIOS 0x04 /* Terminal IO struct update. */
|
||||
#define MSG_TYPE_WINSIZE 0x08 /* Terminal window size update. */
|
||||
#define MSG_TYPE_DATA 0x10 /* Terminal data. */
|
||||
|
||||
|
||||
struct iucvtty_msg {
|
||||
uint8_t version; /* Message version */
|
||||
uint8_t type; /* Message type */
|
||||
uint16_t datalen; /* Number of bytes in payload */
|
||||
uint8_t data[]; /* Payload buffer */
|
||||
} __attribute__((packed));
|
||||
#define MSG_DATA_OFFSET (offsetof(struct iucvtty_msg, data))
|
||||
#define msg_size(m) (MSG_DATA_OFFSET + (m)->datalen)
|
||||
|
||||
/**
|
||||
* msg_cpy_from() - Copy data to message
|
||||
* @msg: IUCV terminal message
|
||||
* @src: Pointer to source data buffer
|
||||
* @len: Length of source data buffer
|
||||
*
|
||||
* Copies @len bytes from @src to the message data buffer. The caller must
|
||||
* ensure not to overwrite the message data buffer.
|
||||
* Finally, the message datalen is set to @len
|
||||
*/
|
||||
static inline void msg_cpy_from(struct iucvtty_msg *msg, const void *src,
|
||||
size_t len)
|
||||
{
|
||||
memcpy(msg->data, src, len);
|
||||
msg->datalen = len;
|
||||
}
|
||||
|
||||
/**
|
||||
* msg_cpy_to() - Copy data from a message
|
||||
* @msg: IUCV terminal message
|
||||
* @dst: Destination buffer
|
||||
* @len: Destination buffer length.
|
||||
*
|
||||
* Copies up to min(@len, message datalen) number of bytes from the IUCV
|
||||
* terminal message to the destination buffer.
|
||||
*/
|
||||
static inline void msg_cpy_to(const struct iucvtty_msg *msg, void *dst,
|
||||
size_t len)
|
||||
{
|
||||
memcpy(dst, msg->data, MIN(msg->datalen, len));
|
||||
}
|
||||
|
||||
/**
|
||||
* msg_alloc() - Allocates a new iucv terminal message.
|
||||
* @type: Message type
|
||||
* @size: Message data size
|
||||
*
|
||||
* The function allocates a new iucv terminal message with the given data size
|
||||
* @size. (The total message size is @size plus MSG_DATA_OFFSET.)
|
||||
* The new message is initialized with the specific @type.
|
||||
*/
|
||||
static inline struct iucvtty_msg *msg_alloc(uint8_t type, uint16_t size)
|
||||
{
|
||||
struct iucvtty_msg *m;
|
||||
|
||||
m = malloc(size + MSG_DATA_OFFSET);
|
||||
if (m != NULL) {
|
||||
m->version = MSG_VERSION;
|
||||
m->type = type;
|
||||
m->datalen = size;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* msg_free() - free an allocated iucv tty message
|
||||
*/
|
||||
static inline void msg_free(struct iucvtty_msg *m)
|
||||
{
|
||||
free(m);
|
||||
}
|
||||
|
||||
#endif /* __IUCVTTY_PROTO_H_ */
|
||||
Reference in New Issue
Block a user