📄 hdbintf.c
字号:
#if defined(SHARE_DEBUG)#define LOG_UNGETTY#define LOG_HDBDIAL#endif/* #define CHOOSE_DEBUG *//*+------------------------------------------------------------------------- hdbintf.c - HDB UUCP database and /etc/utmp interface routines wht@n4hgf.Mt-Park.GA.US Defined functions: _ungetty_return_line(line) add_to_ungetty_list(line) dialcodes_translate(phone) dialstr_translate(translate_list,to_translate) display_ungetty_list() dvtype_match(typespec,dvtype) enddlent() enddvent() getdlent() getdlentname(name) getdvbaud(baud) getdvent() getdvline(line) getdvtype(type) hdb_choose_Any(baud) hdb_choose_Device(type,baud) hdb_dial(presult) hdb_dial_error_text(errcode) hdb_init() in_ungetty_list(line) malformed_Devices_entry(text,ntokens,tokens) remove_from_ungetty_list(line) reserve_line(line) strip_phone_num(sptr) ugstat_text(ugstat) ungetty_get_line(line) ungetty_return_all_but(line) ungetty_return_line(line)Date: Fri, 23 Aug 91 18:30:06 +0300 (MSD)From: emory!hq.demos.su!ache (Andrew A. Chernov, canton Uri's citizen)1) HDB dialers may return connect speed as return code (!= 0)2) Using HDB Dialcodes file for phone numbers translation now (\D,\T escape sequence)--------------------------------------------------------------------------*//*+:EDITS:*//*:09-14-1992-04:05-wht@n4hgf-rcvr process was not going away reliably *//*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 *//*:09-10-1992-03:35-wht@n4hgf-change the way we flunk a line=="-" *//*:09-04-1992-19:08-wht@n4hgf-harden Devices parsing *//*:08-29-1992-15:37-wht@n4hgf-absolutely prohibit /dev/tty fed to ecuungetty *//*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA *//*:07-21-1992-17:20-wht@n4hgf-hdb_dial of "/=" type bug fixed *//*:07-19-1992-22:12-wht@n4hgf-move old check_utmp here+call it reserve_line *//*:07-19-1992-10:07-wht@n4hgf-add ungetty_return_all_but *//*:07-19-1992-09:11-wht@n4hgf-validate tty line name before ungetty get *//*:06-07-1992-17:05-wht@n4hgf-lock tty before ungetty get *//*:05-13-1992-13:27-wht@n4hgf-active_pde use *//*:05-13-1992-10:30-cma@ifsbd-Add baud rate checking to hdb_dial function *//*:05-04-1992-04:45-wht@n4hgf-wrong sense of strcmp in ,M test for SVR4 *//*:04-28-1992-03:29-wht@n4hgf-more fixes for abend due to line problems *//*:04-27-1992-20:02-wht@n4hgf-add ecuungetty error reporting *//*:04-25-1992-13:02-wht@n4hgf-some exits from hdb_choose_Any omitted enddvent *//*:04-24-1992-21:59-wht@n4hgf-more SCO tty name normalizing *//*:04-19-1992-03:21-jhpb@sarto.budd-lake.nj.us-3.18.37 has ESIX SVR4 *//*:01-18-1992-13:29-root@n4hgf-use proctrace value for expresp_verbosity *//*:11-15-1991-04:02-wht@n4hgf-SCO tty naming now observed in getdvline *//*:09-01-1991-16:20-wht@n4hgf2-generalize HDB configuration files location *//*:09-01-1991-02:27-wht@n4hgf2-dialer gets file name instead of "ECUdial" *//*:08-25-1991-13:07-wht@n4hgf-apply ache@hq.demos.su patches *//*:08-10-1991-17:39-wht@n4hgf-US_WEGOTIT handling *//*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 *//*:06-02-1991-17:42-wht@n4hgf-add getdvtype *//*:06-02-1991-17:27-wht@n4hgf-hdb_choose_Device + move hdb_choose_Any here *//*:10-16-1990-20:43-wht@n4hgf-add SHARE_DEBUG *//*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller *//*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */#include "ecu.h"#include "ecupde.h"#include "esd.h"#include "var.h"#include "termecu.h"#include "utmpstatus.h"#include "ecuungetty.h"#include "dvent.h"#include "dlent.h"#include "dialprog.h"#include <errno.h>#include <utmp.h>char *arg_token();char *skip_ld_break();char *dialcodes_translate();char *strip_phone_num();extern char kbdintr; /* current input INTR */extern ulong colors_current;extern int proctrace;extern int expresp_verbosity;int there_is_hdb_on_this_machine = 0;static FILE *fpdv = (FILE *)0;static FILE *fpdl = (FILE *)0;char *Devices_file = "/usr/lib/uucp/Devices";char *Dialers_file = "/usr/lib/uucp/Dialers";char *Dialcodes_file = "/usr/lib/uucp/Dialcodes";uchar last_ugstat = 0;#define UNGETTY_LIST_MAX 3char *ungetty_list[UNGETTY_LIST_MAX];/*+------------------------------------------------------------------------- display_ungetty_list() - display ungetty list with pputs()--------------------------------------------------------------------------*/#if defined(USE_ECUUNGETTY)voiddisplay_ungetty_list(){ int itmp; int found_one = 0; for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++) { if(*ungetty_list[itmp]) { found_one = 1; break; } } if(!found_one) { pputs("No lines acquired by ecuungetty\n"); return; } pputs("Acquired by ecuungetty: "); for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++) { if(*ungetty_list[itmp]) { pputs(ungetty_list[itmp]); pputs(" "); } } pputs("\n");} /* end of display_ungetty_list */#endif /* defined(USE_ECUUNGETTY) *//*+------------------------------------------------------------------------- in_ungetty_list(line) - check for line present in ungetty list--------------------------------------------------------------------------*/#if defined(USE_ECUUNGETTY)intin_ungetty_list(line)char *line;{ int itmp; for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++) { if(!strcmp(line,ungetty_list[itmp])) return(1); } return(0);} /* end of in_ungetty_list */#endif /* defined(USE_ECUUNGETTY) *//*+------------------------------------------------------------------------- add_to_ungetty_list(line) - add line to ungetty list--------------------------------------------------------------------------*/#if defined(USE_ECUUNGETTY)voidadd_to_ungetty_list(line)char *line;{ int itmp; char *lptr; if(in_ungetty_list(line)) return; for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++) { if(!*(lptr = ungetty_list[itmp])) { strcpy(lptr,line); return; } } ecu_log_event(getpid(),"ungetty_list overflow"); termecu(TERMECU_LOGIC_ERROR); /*NOTREACHED*/} /* end of add_to_ungetty_list */#endif /* defined(USE_ECUUNGETTY) *//*+------------------------------------------------------------------------- remove_from_ungetty_list(line) - remove line from ungetty list--------------------------------------------------------------------------*/#if defined(USE_ECUUNGETTY)voidremove_from_ungetty_list(line)char *line;{ int itmp; char *lptr; for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++) { if(!strcmp((lptr = ungetty_list[itmp]),line)) { *lptr = 0; return; } }#ifdef CHOOSE_DEBUG { char s128[128]; sprintf(s128,"remove_from_ungetty_list failed for %s",line); ecu_log_event(getpid(),s128); }#endif} /* end of remove_from_ungetty_list */#endif /* defined(USE_ECUUNGETTY) *//*+------------------------------------------------------------------------- ugstat_text(ugstat) - text for ecuungetty code--------------------------------------------------------------------------*/char *ugstat_text(ugstat)int ugstat;{ static char errant[32]; switch(ugstat) { case UG_NOTENAB: return("line not enabled"); break; case UG_RESTART: return("restart needed"); break; case UG_FAIL: return("line in use"); break; case UGE_T_LOGIN: return("-t found US_LOGIN"); break; case UGE_T_LOGGEDIN: return("-t found US_LOGGGEDIN"); break; case UGE_T_NOTFOUND: return("not found"); break; case UGE_BADSWITCH: return("usage: bad switch"); break; case UGE_BADARGC: return("usage: bad arg count"); break; case UGE_BADARGV: return("this a valid tty??"); break; case UGE_NOTROOT: return("not setuid root"); break; case UGE_CALLER: return("invalid caller"); break; case UGE_NOUUCP: return("cannot find uucp passwd entry"); break; case UGE_LOGIC: return("logic error"); break; case UGE_BOMB: return("core dumped or killed"); break; case UGE_DNE: return("did not execute"); break; } sprintf(errant,"error %u",ugstat); return(errant);} /* end of ugstat_text *//*+------------------------------------------------------------------------- ungetty_get_line(line) - acquire a line through ecuungetty protocol--------------------------------------------------------------------------*/intungetty_get_line(line)char *line;{#if !defined(USE_ECUUNGETTY) return(0);#else int itmp; int rtn = 0; int we_locked = 0; int ungetty_pid; SIGTYPE (*original_sighdlr)(); int wait_status; char ungetty[128]; char ungetty_log[80]; char bamboozlement[20]; struct stat st; char *bamboozle(); /* * quick check - ecuungetty does a much better job */ if(!strcmp(line,"/dev/tty")) /* some keep getting /dev/tty chown'd! */ return(LINST_INVALID); if(stat(line,&st)) { if(errno == ENOENT) return(LINST_NODEV); return(LINST_OPNFAIL); } if((st.st_mode & S_IFMT) != S_IFCHR) return(LINST_NOTCHR); if(!there_is_hdb_on_this_machine) return(0); if(in_ungetty_list(line)) return(0); /* * lock line before ecuungetty call */ if((itmp = lock_tty(line)) && (itmp != LINST_WEGOTIT)) return(itmp); we_locked = (!itmp); sprintf(ungetty,"%s/ecuungetty",ECULIBDIR); strcpy(bamboozlement,bamboozle(getpid())); if(access(ungetty,1)) { pperror(ungetty); rtn = LINST_ENABLED; goto RETURN; } original_sighdlr = signal(SIGCLD,SIG_DFL); if((ungetty_pid = smart_fork()) == 0) { execl(ungetty,"ungetty",line,bamboozlement,(char *)0); _exit(UGE_DNE); /* did not execute */ } while(((itmp = wait(&wait_status)) != ungetty_pid) && (itmp != -1)) ; signal(SIGCLD,original_sighdlr); if(wait_status & 0xFF) last_ugstat = UGE_BOMB; else last_ugstat = (uchar)(wait_status >> 8); switch(last_ugstat) { case UG_NOTENAB: /* line acquired: not enabled */ break; case UG_RESTART: /* line acquired: need ungetty -r when done */#if defined(LOG_UNGETTY) sprintf(ungetty_log,"UNGETTY acquired %s",shm->Lline); ecu_log_event(getpid(),ungetty_log);#endif add_to_ungetty_list(line); break; case UG_FAIL: /* line in use */ rtn = LINST_ENABLED_IN_USE; break; default: sprintf(ungetty_log,"UNGETTY status 0x%04x: %s", wait_status,ugstat_text(last_ugstat)); ecu_log_event(getpid(),ungetty_log); rtn = (last_ugstat == UGE_BOMB) ? LINST_ECUUNGETTY2 : LINST_ECUUNGETTY; break; }RETURN: ; if(rtn && we_locked) unlock_tty(line); return(rtn);#endif /* !defined(USE_ECUUNGETTY) */} /* end of ungetty_get_line *//*+------------------------------------------------------------------------- reserve_line(line)return 0 if line reserved, else LINST code--------------------------------------------------------------------------*/intreserve_line(line)char *line;{register utstatus;register status = 0; switch(utstatus = utmp_status(line)) { case US_DIALOUT: /* enabled for login, currently dialout */ status = LINST_DIALOUT_IN_USE; break; case US_LOGGEDIN: /* enabled for login, in use */ status = LINST_ENABLED_IN_USE; break; case US_NOTFOUND: /* not in utmp, or getty dead */ break; case US_WEGOTIT: /* we own the line */ status = LINST_WEGOTIT; /* not really an error */ break; case US_LOGIN: /* enabled for login, idle */ status = ungetty_get_line(line); break; }#if defined(LOG_LOCKS) { char s64[64]; sprintf(s64,"UTMPCHK %s st=%d ut=%d",line,status,utstatus); ecu_log_event(getpid(),s64); }#endif return(status);} /* end of reserve_line *//*+------------------------------------------------------------------------- _ungetty_return_line(line) - return line to "getty" status--------------------------------------------------------------------------*/void_ungetty_return_line(line)char *line;{#if !defined(USE_ECUUNGETTY) return;#else int ungetty_pid; int itmp; SIGTYPE (*original_sighdlr)(); int wait_status = 0xDEAD; char ungetty[128];#if defined(LOG_UNGETTY) char ungetty_log[80];#endif char bamboozlement[20]; char *bamboozle(); if(!there_is_hdb_on_this_machine) return; if(!in_ungetty_list(line)) return; sprintf(ungetty,"%s/ecuungetty",ECULIBDIR); strcpy(bamboozlement,bamboozle(getpid())); /* call ungetty to see if we need to switch to dialin */#if 0 /* if in_ungetty_list, trust we need to -r */ if(access(ungetty,1)) { pperror(ungetty); return; } original_sighdlr = signal(SIGCLD,SIG_DFL); if((ungetty_pid = smart_fork()) == 0) { execl(ungetty,"ungetty","-t",line,bamboozlement,(char *)0); ecu_log_event(getpid(),"could not exec ecuungetty -t"); _exit(UGE_DNE); /* did not execute */ } while(((itmp = wait(&wait_status)) != ungetty_pid) && (itmp != -1) ) ; signal(SIGCLD,original_sighdlr);#if defined(LOG_UNGETTY) sprintf(ungetty_log,"UNGETTY -t %s status %04x",line,wait_status); ecu_log_event(getpid(),ungetty_log);#endif switch((uchar)(wait_status >> 8)) { case UG_RESTART: break; default: remove_from_ungetty_list(line); return; }#endif original_sighdlr = signal(SIGCLD,SIG_DFL); if((ungetty_pid = smart_fork()) == 0) { execl(ungetty,"ungetty","-r",line,bamboozlement,(char *)0); ecu_log_event(getpid(),"could not exec ecuungetty -r"); _exit(UGE_DNE); /* did not execute */ } while(((itmp = wait(&wait_status)) != ungetty_pid) && (itmp != -1)) ;#if defined(LOG_UNGETTY) if(wait_status) { sprintf(ungetty_log,"UNGETTY -r %s status 0x%04x", line,wait_status); } else sprintf(ungetty_log,"UNGETTY returned %s",line); ecu_log_event(getpid(),ungetty_log);#endif remove_from_ungetty_list(line);#endif /* !defined(USE_ECUUNGETTY) */} /* end of _ungetty_return_line *//*+------------------------------------------------------------------------- ungetty_return_line(line) - return one or all lines to "getty" status--------------------------------------------------------------------------*/voidungetty_return_line(line)char *line;{#if !defined(USE_ECUUNGETTY) return;#else int itmp; if(line) _ungetty_return_line(line); else { for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++) { if(*(line = ungetty_list[itmp])) _ungetty_return_line(line); } }#endif /* !defined(USE_ECUUNGETTY) */} /* end of ungetty_return_line *//*+------------------------------------------------------------------------- ungetty_return_all_but(line) - return all lines but 'line'--------------------------------------------------------------------------*/voidungetty_return_all_but(line)char *line;{#if !defined(USE_ECUUNGETTY) return;#else int itmp; for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++) { if(ungetty_list[itmp][0] && strcmp(line,ungetty_list[itmp])) _ungetty_return_line(line); }#endif /* !defined(USE_ECUUNGETTY) */} /* end of ungetty_return_all_but *//*+------------------------------------------------------------------------- malformed_Devices_entry(text,ntokens,tokens)--------------------------------------------------------------------------*/voidmalformed_Devices_entry(text,ntokens,tokens)char *text;int ntokens;char **tokens;{ char s512[512]; char *cptr; char *nlptr; static already = 0; extern int tty_not_char_special; sprintf(s512,"malformed Devices entry (%s):\n",text); cptr = s512 + strlen(s512); nlptr = cptr - 1; while(ntokens--) { if(((cptr - s512) + strlen(*tokens) + 2) > sizeof(s512)) break; sprintf(cptr,"%s ",*tokens++); cptr += strlen(cptr); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -