📄 xteld.c
字号:
/* * xtel - Emulateur MINITEL sous X11 * * Copyright (C) 1991-1996 Lectra Systemes & Pierre Ficheux * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */static char rcsid[] = "$Id: xteld.c,v 1.27 1997/07/11 10:56:40 pierre Exp $";/* * Demon XTELD (communication avec le MODEM) *//* * Contributions: * * Michel Fingerhut IRCAM Paris * * - Traitement du fichier de log * - Acces proteges aux services * * Pierre Beyssac SYSECA * * - traitement du Minitel 2 * - utilisation de syslog * * Vincent Gillet * * - dialogue avec client Window$ (option -w) * * Eric Delaunay * * - support IAN * */#define EXTERN#include <stdio.h>#include <ctype.h>#include "demon.h"#include "globald.h"#include <errno.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/time.h>#include <time.h>#include <signal.h>#include <string.h>#ifdef USE_SYSLOG#include <syslog.h>#endif /* USE_SYSLOG */#ifdef NO_TERMIO#include <sgtty.h>#else#ifdef USE_TERMIOS#include <sys/ioctl.h>#include <termios.h>#else#include <termio.h>#endif /* USE_TERMIOS */#endif /* NO_TERMIO */#ifdef NO_NETWORK#include <sys/socket.h>#include <sys/un.h>#include <fcntl.h>#ifdef sun#include <sys/termios.h>#endif /* sun */static int sock_service;#define XTELD_INPUT sock_service#define XTELD_OUTPUT sock_service#else#include <netinet/in.h>#define XTELD_INPUT 0#define XTELD_OUTPUT 1#endif /* NO_NETWORK *//* Tableau pour Emulateur sous Windaube */static char tablo_windaube[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 37, 102, 103, 36, 37, 102, 103, 60, 61, 126, 127, 60, 61, 126, 127, 60, 61, 126, 127, 60, 61, 126, 127, 60, 61, 126, 127, 60, 61, 126, 127, 98, 99, 98, 99, 102, 103, 102, 103, 122, 123, 122, 123, 126, 127, 126, 127, 122, 123, 122, 123, 126, 127, 126, 127, 122, 123, 122, 123, 126, 127, 126, 127, 102, 103, 102, 103, 102, 103, 102, 103, 126, 127, 126, 127, 126, 127, 126, 127, 126, 127, 126, 127, 126, 127, 126, 127, 126, 127, 126, 127, 126, 127, 126};static int fin_fils;static int pid_fils;static int nb_services;static fd_set a_lire;static struct timeval timeout;static time_t t_connexion;static char buf[256], buf1[256], service[256], utilisateur[256];static char flag_connexion;static char parite;static Boolean flag_serveur_local, flag_crlf, flag_windaube;static int tuyau_in[2], tuyau_out[2];static int temps_maxi;static int detecte_ian;static int saisie_active;static char fin_connexion = 0;/* Syslog or not syslog ? */#ifdef USE_SYSLOGvoid log_debug (fmt, p1, p2, p3, p4, p5, p6, p7)char *fmt;int p1, p2, p3, p4, p5, p6, p7;{ char msg[256]; sprintf (msg, fmt, p1, p2, p3, p4, p5, p6, p7); syslog(LOG_DEBUG, msg);}void log_err (s)char *s;{ syslog(LOG_ERR, s);}#elsevoid log_debug (fmt, p1, p2, p3, p4, p5, p6, p7)char *fmt;int p1, p2, p3, p4, p5, p6, p7;{ fprintf (fp_console, "xteld[%d] ", getpid()); fprintf (fp_console, fmt, p1, p2, p3, p4, p5, p6, p7); fprintf (fp_console, "\n\r");}#endif /* USE_SYSLOG */static void demande_fin_fils(){#ifdef DEBUG_XTELD log_debug ("Demande la fin du fils");#endif signal (SIGALRM, SIG_IGN); fin_fils = 1;}/* * Transmet une erreur a XTEL * - chaine de caractere terminee par 0 * - errno associe */void erreur_a_xtel (s, code_erreur)char *s;int code_erreur;{ char e = code_erreur; write (XTELD_OUTPUT, CHAINE_REPONSE_DEBUT_ERREUR, 1); write (XTELD_OUTPUT, s, strlen(s)); write (XTELD_OUTPUT, "\0000", 1); write (XTELD_OUTPUT, &e, 1); write (XTELD_OUTPUT, CHAINE_REPONSE_FIN_ERREUR, 1);}/* * Teste si l'utilisateur courant a acces au service demande * * 1 si oui * 0 sinon */intservice_autorise (indice_service, maxtime) int indice_service, *maxtime;{ char *pt, *pt1, *auth = definition_services[indice_service].autorisations; char autorisations[2048]; int default_maxtime = 0; *maxtime = 0; /* Pas de protection ou definition general du temps maxi */ if (*auth == 0) return 1; if (*auth == '=' && !strchr (auth, ':')) { *maxtime = atoi (auth+1); return 1; } strcpy (autorisations, auth); pt = strtok (autorisations, ":"); while (pt != NULL) { /* * Format: nom=temps_maxi (si =temp_maxi, le temps est la valeur * par defaut) */ *maxtime = default_maxtime; if (*pt == '=') { /* nouvelle valeur par defaut */ *maxtime = default_maxtime = atoi (pt+1); } else { if ((pt1 = strchr (pt, '='))) { *pt1 = 0; *maxtime = atoi (pt1+1); } if (strcmp (pt, utilisateur) == 0) { return(1); } } pt = strtok(NULL, ":"); } return(0);}/* * Fonction d'autorisation d'envoi de caract鑢es au modem * (quand connexion restreinte
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -