home *** CD-ROM | disk | FTP | other *** search
- /*
- * Pcomm is a public domain telecommunication program for Unix that
- * is designed to operate similar to the MSDOS program, ProComm.
- * ProComm (TM) is copyrighted by Datastorm Technologies, Inc.
- *
- * Emmet P. Gray US Army, HQ III Corps & Fort Hood
- * ...!uunet!uiucuxc!fthood!egray Attn: AFZF-DE-ENV
- * Directorate of Engineering & Housing
- * Environmental Management Office
- * Fort Hood, TX 76544-5057
- *
- * Release v1.0 12 Mar 88
- * patch #1 22 Mar 88
- * patch #2 26 Mar 88
- * patch #3 3 Apr 88
- * patch #4 14 Apr 88
- * patch #5 25 May 88
- * Release v1.1 21 Aug 88
- */
-
- #include <stdio.h>
- #include <signal.h>
- #include <curses.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include "config.h"
- #ifndef OLDCURSES
- #include <term.h>
- #endif /* OLDCURSES */
- #define MAIN
- #include "dial_dir.h"
- #include "modem.h"
- #include "param.h"
- #include "status.h"
-
- #ifdef OLDCURSES
- char tcbuf[1024], *TI, *VS;
- #define cbreak crmode
- #endif /* OLDCURSES */
-
- #ifdef SHAREDMEM
- int shm_id;
- #endif /* SHAREDMEM */
-
- struct PARAM *param;
- struct DIAL_DIR *dir;
- struct STATUS *status;
- struct MODEM *modem;
-
- int fd = -1; /* file descriptor for port */
- int xmc; /* magic cookie terminal */
- int msg_status; /* read/write permissions on TTY */
- char *null_ptr = ""; /* generic null pointer */
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- extern char *optarg;
- int c, ret_code, i, code, quit();
- char *mytty, *ttyname(), *term, *getenv(), *short_cut, *strdup();
- char *extra_dir, buf[80], message[80];
- struct PARAM *read_param();
- struct DIAL_DIR *read_dir();
- struct STATUS *init();
- struct MODEM *read_modem();
- struct stat stbuf;
- void exit(), error_win(), free_ptr();
- #ifdef OLDCURSES
- char *tgetstr(), *t, tb[1024];
- t = tcbuf;
- #endif /* OLDCURSES */
-
- signal(SIGINT, SIG_IGN);
- signal(SIGQUIT, SIG_IGN);
- signal(SIGTERM, quit);
- signal(SIGHUP, quit);
-
- short_cut = NULL;
- extra_dir = NULL;
- /* the command line */
- while ((c = getopt(argc, argv, "d:f:")) != EOF) {
- switch (c) {
- case 'd': /* the extra directory to search */
- extra_dir = strdup(optarg);
- break;
- case 'f': /* the index into the dialing dir */
- short_cut = strdup(optarg);
- break;
- case '?': /* default */
- fprintf(stderr, "Usage: pcomm [-d directory] [-f index]\n");
- exit(1);
- break;
- }
- }
- /* get terminal type */
- term = getenv("TERM");
- if (term == NULL || *term == NULL) {
- fprintf(stderr, "Windows not supported (TERM not defined)\n");
- exit(1);
- }
- /* see if terminfo entry exists */
- #ifdef OLDCURSES
- ret_code = tgetent(tb, term);
- #else /* OLDCURSES */
- setupterm(term, 1, &ret_code);
- #endif /* OLDCURSES */
- if (ret_code != 1) {
- fprintf(stderr, "Windows not supported (no terminfo data for '%s')\n", term);
- exit(1);
- }
- /* minimum screen size */
- #ifdef OLDCURSES
- if (tgetnum("co") < 80 || tgetnum("li") < 24) {
- #else /* OLDCURSES */
- if (columns < 80 || lines < 24) {
- #endif /* OLDCURSES */
- fprintf(stderr, "Windows not supported (minimum 80x24 screen required)\n");
- exit(1);
- }
- /* must have cursor movement */
- #ifdef OLDCURSES
- if (tgetstr("cm", &t) == NULL) {
- #else /* OLDCURSES */
- if (cursor_address == NULL) {
- #endif /* OLDCURSES */
- fprintf(stderr, "Windows not supported (terminal too dumb)\n");
- exit(1);
- }
- /* load magic cookie variable */
- #ifdef OLDCURSES
- xmc = tgetnum("sg");
- TI = tgetstr("ti", &t);
- VS = tgetstr("vs", &t);
- #else /* OLDCURSES */
- xmc = magic_cookie_glitch;
- #endif /* OLDCURSES */
- /* ok... now lets go! */
- initscr();
- nonl();
- cbreak();
- noecho();
-
- param = (struct PARAM *) NULL;
- modem = (struct MODEM *) NULL;
- dir = (struct DIAL_DIR *) NULL;
- /* show the herald, return status */
- status = init(short_cut);
- /* get "msgs" status */
- mytty = ttyname(0);
- stat(mytty, &stbuf);
- chmod(mytty, 0600);
- msg_status = stbuf.st_mode & 0777;
- /* read the support files */
- param = read_param(extra_dir);
- dir = read_dir(extra_dir);
- modem = read_modem(extra_dir);
- free_ptr(extra_dir);
- /* warning about screen size */
- if (LINES > MAX_ROW || COLS > MAX_COL)
- error_win(0, "Your screen size exceeds an internal Pcomm limit",
- "The edges of the screen may contain garbage");
-
- /* short-cut to dialing window? */
- code = 0;
- if (short_cut != NULL) {
- for (i=1; i<dir->d_entries+1; i++) {
- if (!strcmp(dir->index[i], short_cut)) {
- dir->q_num[0] = i;
- dir->d_cur = i;
- break;
- }
- }
- /* if match is found */
- if (dir->q_num[0] != -1)
- code = dial_win();
- else {
- sprintf(buf, "Can't find index '%s' in dialing directory", short_cut);
- sprintf(message, "file '%s'", dir->d_path);
- error_win(0, buf, message);
- }
- free_ptr(short_cut);
- }
- /* start terminal dialogue */
- terminal(code);
- exit(0);
- }
-
- /*
- * Something dreadful happened... Clean up the mess we made with the
- * TTY driver and release the phone line.
- */
-
- int
- quit()
- {
- void cleanup();
-
- cleanup(1);
- /* never returns... */
- return(0);
- }
-
- /*
- * Check write permission with the real UID and GID. Returns a 0 on
- * permission denied, 1 on OK, and 2 on OK-but the file already exists.
- */
-
- int
- can_write(file)
- char *file;
- {
- char *p, path[200], *strcpy(), *strrchr();
-
- p = strcpy(path, file);
- /* dissect the path component */
- if (p = strrchr(path, '/'))
- *(p++) = NULL;
- else
- strcpy(path, ".");
- /* if it already exists */
- if (!access(file, 0)) {
- if (!access(file, 2))
- return(2);
- return(0);
- }
- /* if path is writable */
- if (!access(path, 2))
- return(1);
- return(0);
- }
-
- /*
- * Check the read and write permissions before opening a file. This
- * is a horrible kludge to work around that fact that a lot of systems
- * that claim to be SVID compatible don't treat setuid(2) and setgid(2)
- * properly. For example, on a Masscomp, you can't flip-flop back and
- * forth between the real and effective UID/GID.
- */
-
- FILE *
- my_fopen(file, mode)
- char *file, *mode;
- {
- #ifdef SETUGID
- switch (*mode) {
- case 'a':
- case 'w':
- if (!can_write(file))
- return(NULL);
- break;
- case 'r':
- if (access(file, 4))
- return(NULL);
- break;
- }
- #endif /* SETUGID */
- return ((FILE *) fopen(file, mode));
- }
-