118480Sralph #ifndef lint 2*23583Sbloom static char sccsid[] = "@(#)acucntrl.c 5.3 (Berkeley) 06/19/85"; 318480Sralph #endif 418480Sralph 518480Sralph /* acucntrl - turn around tty line between dialin and dialout 618480Sralph * 718480Sralph * Usage: acucntrl {enable,disable} /dev/ttydX 818480Sralph * 918480Sralph * History: 1018480Sralph * First written by Allan Wilkes (fisher!allan) 1118480Sralph * 1218480Sralph * Modified June 8,1983 by W.Sebok (astrovax!wls) to poke kernel rather 1318480Sralph * than use kernel hack to turn on/off modem control, using subroutine 1418480Sralph * stolen from program written by Tsutomu Shimomura 1518480Sralph * {astrovax,escher}!tsutomu 1618480Sralph * 1718480Sralph * Worked over many times by W.Sebok (i.e. hacked to death) 1818480Sralph * 1918480Sralph * Operation: 2018480Sralph * disable (i.e. setup for dialing out) 2118480Sralph * (1) check input arguments 2218480Sralph * (2) look in /etc/utmp to check that the line is not in use by another 2318480Sralph * (3) disable modem control on terminal 2418480Sralph * (4) check for carrier on device 2518480Sralph * (5) change owner of device to real id 2618480Sralph * (6) edit /etc/ttys, changing the first character of the appropriate 2718480Sralph * line to 0 2818480Sralph * (7) send a hangup to process 1 to poke init to disable getty 2918480Sralph * (8) post uid name in capitals in /etc/utmp to let world know device has 3018480Sralph * been grabbed 3118480Sralph * (9) make sure that DTR is on 3218480Sralph * 3318480Sralph * enable (i.e.) restore for dialin 3418480Sralph * (1) check input arguments 3518480Sralph * (2) look in /etc/utmp to check that the line is not in use by another 3618480Sralph * (3) make sure modem control on terminal is disabled 3718480Sralph * (4) turn off DTR to make sure line is hung up 3818480Sralph * (5) condition line: clear exclusive use and set hangup on close modes 3918480Sralph * (6) turn on modem control 4018480Sralph * (7) edit /etc/ttys, changing the first character of the appropriate 4118480Sralph * line to 1 4218480Sralph * (8) send a hangup to process 1 to poke init to enable getty 4318480Sralph * (9) clear uid name for /etc/utmp 4418480Sralph */ 4518480Sralph 4618480Sralph /* #define SENSECARRIER */ 4718480Sralph 4818480Sralph #include "uucp.h" 4918480Sralph #include <sys/buf.h> 5018614Sralph #include <signal.h> 5118480Sralph #include <sys/conf.h> 5218480Sralph #ifdef BSD4_2 53*23583Sbloom #include <vaxuba/ubavar.h> 5418614Sralph #else 5518480Sralph #include <sys/ubavar.h> 5618614Sralph #endif 5718480Sralph #include <sys/stat.h> 5818480Sralph #include <nlist.h> 5918480Sralph #include <sgtty.h> 6018480Sralph #include <utmp.h> 6118480Sralph #include <pwd.h> 6218480Sralph #include <stdio.h> 6318480Sralph 6418480Sralph #define NDZLINE 8 /* lines/dz */ 6518480Sralph #define NDHLINE 16 /* lines/dh */ 6618480Sralph #define NDMFLINE 8 /* lines/dmf */ 6718480Sralph 6818480Sralph #define DZ11 1 6918480Sralph #define DH11 2 7018480Sralph #define DMF 3 7118480Sralph 7218480Sralph #define NLVALUE(val) (nl[val].n_value) 7318480Sralph 7418480Sralph struct nlist nl[] = { 7518480Sralph #define CDEVSW 0 7618480Sralph { "_cdevsw" }, 7718480Sralph 7818480Sralph #define DZOPEN 1 7918480Sralph { "_dzopen" }, 8018480Sralph #define DZINFO 2 8118480Sralph { "_dzinfo" }, 8218480Sralph #define NDZ11 3 8318480Sralph { "_dz_cnt" }, 8418480Sralph #define DZSCAR 4 8518480Sralph { "_dzsoftCAR" }, 8618480Sralph 8718480Sralph #define DHOPEN 5 8818480Sralph { "_dhopen" }, 8918480Sralph #define DHINFO 6 9018480Sralph { "_dhinfo" }, 9118480Sralph #define NDH11 7 9218480Sralph { "_ndh11" }, 9318480Sralph #define DHSCAR 8 9418480Sralph { "_dhsoftCAR" }, 9518480Sralph 9618480Sralph #define DMFOPEN 9 9718480Sralph { "_dmfopen" }, 9818480Sralph #define DMFINFO 10 9918480Sralph { "_dmfinfo" }, 10018480Sralph #define NDMF 11 10118480Sralph { "_ndmf" }, 10218480Sralph #define DMFSCAR 12 10318480Sralph { "_dmfsoftCAR" }, 10418480Sralph 10518480Sralph { "\0" } 10618480Sralph }; 10718480Sralph 10818480Sralph #define ENABLE 1 10918480Sralph #define DISABLE 0 11018480Sralph 11118480Sralph char Etcutmp[] = "/etc/utmp"; 11218480Sralph char Etcttys[] = "/etc/ttys"; 11318480Sralph char Devhome[] = "/dev"; 11418480Sralph 11518480Sralph char usage[] = "Usage: acucntrl {dis|en}able ttydX\n"; 11618480Sralph 11718480Sralph struct utmp utmp; 11818480Sralph char resettty, resetmodem; 11918480Sralph int etcutmp; 12018614Sralph off_t utmploc; 12118614Sralph off_t ttyslnbeg; 12218480Sralph 12318480Sralph #define NAMSIZ sizeof(utmp.ut_name) 12418480Sralph #define LINSIZ sizeof(utmp.ut_line) 12518480Sralph 12618480Sralph main(argc, argv) 12718480Sralph int argc; char *argv[]; 12818480Sralph { 12918480Sralph register char *p; 13018480Sralph register int i; 13118480Sralph char uname[NAMSIZ], Uname[NAMSIZ]; 13218480Sralph int enable ; 13318480Sralph char *device; 13418480Sralph int devfile; 13518480Sralph int uid, gid; 13618614Sralph off_t lseek(); 13718480Sralph struct passwd *getpwuid(); 13818480Sralph char *rindex(); 13918480Sralph extern int errno; 14018480Sralph extern char *sys_errlist[]; 14118480Sralph 14218480Sralph /* check input arguments */ 14318480Sralph if (argc!=3) { 14418480Sralph fprintf(stderr, usage); 14518480Sralph exit(1); 14618480Sralph } 14718480Sralph 14818480Sralph /* interpret command type */ 14918480Sralph if (prefix(argv[1], "disable") || strcmp(argv[1],"dialout")==0) 15018480Sralph enable = 0; 15118480Sralph else if (prefix(argv[1], "enable") || strcmp(argv[1],"dialin")==0) 15218480Sralph enable = 1; 15318480Sralph else { 15418480Sralph fprintf(stderr, usage); 15518480Sralph exit(1); 15618480Sralph } 15718480Sralph 15818480Sralph device = rindex(argv[2],'/'); 15918480Sralph device = (device == NULL) ? argv[2]: device+1; 16018480Sralph 16118480Sralph /* only recognize devices of the form ttydX */ 16218480Sralph if (strncmp(device,"ttyd",4)!=0) { 16318480Sralph fprintf(stderr,"Bad Device Name %s",device); 16418480Sralph exit(1); 16518480Sralph } 16618480Sralph 16718480Sralph opnttys(device); 16818480Sralph 16918480Sralph /* Get nlist info */ 17018480Sralph nlist("/vmunix",nl); 17118480Sralph 17218480Sralph /* Chdir to /dev */ 17318480Sralph if(chdir(Devhome) < 0) { 17418480Sralph fprintf(stderr, "Cannot chdir to %s: %s\r\n", 17518480Sralph Devhome, sys_errlist[errno]); 17618480Sralph exit(1); 17718480Sralph } 17818480Sralph 17918480Sralph /* Get uid information */ 18018480Sralph uid = getuid(); 18118480Sralph gid = getgid(); 18218480Sralph 18318480Sralph p = getpwuid(uid)->pw_name; 18418480Sralph if (p==NULL) { 18518480Sralph fprintf(stderr,"cannot get uid name\n"); 18618480Sralph exit(1); 18718480Sralph } 18818480Sralph 18918480Sralph /* to upper case */ 19018480Sralph i = 0; 19118480Sralph do { 19218480Sralph uname[i] = *p; 19318480Sralph Uname[i] = (*p>='a' && *p<='z') ? (*p - ('a'-'A')) : *p; 19418480Sralph i++; p++; 19518480Sralph } while (*p && i<NAMSIZ); 19618480Sralph 19718480Sralph 19818480Sralph /* check to see if line is being used */ 19918480Sralph if( (etcutmp = open(Etcutmp, 2)) < 0) { 20018480Sralph fprintf(stderr,"On open %s open: %s\n", 20118480Sralph Etcutmp,sys_errlist[errno]); 20218480Sralph exit(1); 20318480Sralph } 20418480Sralph 20518480Sralph (void)lseek(etcutmp,utmploc, 0); 20618480Sralph 20718614Sralph i = read(etcutmp,(char *)&utmp,sizeof(struct utmp)); 20818480Sralph 20918480Sralph if( 21018480Sralph i == sizeof(struct utmp) && 21118480Sralph utmp.ut_line[0] != '\0' && 21218480Sralph utmp.ut_name[0] != '\0' && 21318480Sralph ( 21418480Sralph !upcase(utmp.ut_name,NAMSIZ) || 21518480Sralph ( 21618480Sralph uid != 0 && 21718480Sralph strncmp(utmp.ut_name,Uname,NAMSIZ) != 0 21818480Sralph ) 21918480Sralph ) 22018480Sralph ) { 22118480Sralph fprintf(stderr, "%s in use by %s\n", device, utmp.ut_name); 22218480Sralph exit(2); 22318480Sralph } 22418480Sralph 22518480Sralph /* Disable modem control */ 22618480Sralph if (setmodem(device,DISABLE)<0) { 22718480Sralph fprintf(stderr,"Unable to disable modem control\n"); 22818480Sralph exit(1); 22918480Sralph } 23018480Sralph 23118480Sralph if (enable) { 23218480Sralph if((devfile = open(device, 1)) < 0) { 23318480Sralph fprintf(stderr,"On open of %s: %s\n", 23418480Sralph device, sys_errlist[errno]); 23518480Sralph (void)setmodem(device,resetmodem); 23618480Sralph exit(1); 23718480Sralph } 23818480Sralph /* Try one last time to hang up */ 23918614Sralph if (ioctl(devfile,(int)TIOCCDTR,(char *)0) < 0) 24018480Sralph fprintf(stderr,"On TIOCCDTR ioctl: %s\n", 24118480Sralph sys_errlist[errno]); 24218480Sralph 24318614Sralph if (ioctl(devfile, (int)TIOCNXCL,(char *)0) < 0) 24418480Sralph fprintf(stderr, 24518480Sralph "Cannot clear Exclusive Use on %s: %s\n", 24618480Sralph device, sys_errlist[errno]); 24718480Sralph 24818614Sralph if (ioctl(devfile, (int)TIOCHPCL,(char *)0) < 0) 24918480Sralph fprintf(stderr, 25018480Sralph "Cannot set hangup on close on %s: %s\n", 25118480Sralph device, sys_errlist[errno]); 25218480Sralph 25318480Sralph i = resetmodem; 25418480Sralph 25518480Sralph if (setmodem(device,ENABLE) < 0) { 25618480Sralph fprintf(stderr,"Cannot Enable modem control\n"); 25718480Sralph (void)setmodem(device,i); 25818480Sralph exit(1); 25918480Sralph } 26018480Sralph resetmodem=i; 26118480Sralph 26218614Sralph if (settys(ENABLE)) { 26318614Sralph fprintf(stderr,"%s already enabled\n",device); 26418614Sralph } else { 26518614Sralph pokeinit(device,Uname,enable); 26618614Sralph } 26718480Sralph post(device,""); 26818480Sralph 26918480Sralph } else { 27018480Sralph #if defined(TIOCMGET) && defined(SENSECARRIER) 27118480Sralph if (uid!=0) { 27218480Sralph int linestat = 0; 27318480Sralph 27418480Sralph /* check for presence of carrier */ 27518480Sralph sleep(2); /* need time after modem control turnoff */ 27618480Sralph 27718480Sralph if((devfile = open(device, 1)) < 0) { 27818480Sralph fprintf(stderr,"On open of %s: %s\n", 27918480Sralph device, sys_errlist[errno]); 28018480Sralph (void)setmodem(device,resetmodem); 28118480Sralph exit(1); 28218480Sralph } 28318480Sralph 28418480Sralph (void)ioctl(devfile,TIOCMGET,&linestat); 28518480Sralph 28618480Sralph if (linestat&TIOCM_CAR) { 28718480Sralph fprintf(stderr,"%s is in use (Carrier On)\n", 28818480Sralph device); 28918480Sralph (void)setmodem(device,resetmodem); 29018480Sralph exit(2); 29118480Sralph } 29218480Sralph (void)close(devfile); 29318480Sralph } 29418480Sralph #endif TIOCMGET 29518480Sralph /* chown device */ 29618480Sralph if(chown(device, uid, gid) < 0) 29718480Sralph fprintf(stderr, "Cannot chown %s: %s\n", 29818480Sralph device, sys_errlist[errno]); 29918480Sralph 30018480Sralph 30118480Sralph /* poke init */ 30218614Sralph if(settys(DISABLE)) { 30318614Sralph fprintf(stderr,"%s already disabled\n",device); 30418614Sralph } else { 30518614Sralph pokeinit(device,Uname,enable); 30618614Sralph } 30718480Sralph post(device,Uname); 30818480Sralph if((devfile = open(device, 1)) < 0) { 30918480Sralph fprintf(stderr, "On %s open: %s\n", 31018480Sralph device, sys_errlist[errno]); 31118480Sralph } else { 31218614Sralph if(ioctl(devfile, (int)TIOCSDTR, (char *)0) < 0) 31318480Sralph fprintf(stderr, 31418480Sralph "Cannot set DTR on %s: %s\n", 31518480Sralph device, sys_errlist[errno]); 31618480Sralph } 31718480Sralph } 31818480Sralph 31918480Sralph exit(0); 32018480Sralph } 32118480Sralph 32218480Sralph /* return true if no lower case */ 32318480Sralph upcase(str,len) 32418480Sralph register char *str; 32518480Sralph register int len; 32618480Sralph { 32718480Sralph for (; *str, --len >= 0 ; str++) 32818480Sralph if (*str>='a' && *str<='z') 32918480Sralph return(0); 33018480Sralph return(1); 33118480Sralph } 33218480Sralph 33318480Sralph /* Post name to public */ 33418480Sralph post(device,name) 33518480Sralph char *device, *name; 33618480Sralph { 33718614Sralph (void)time((time_t *)&utmp.ut_time); 338*23583Sbloom strncpy(utmp.ut_line, device, LINSIZ); 339*23583Sbloom strncpy(utmp.ut_name, name, NAMSIZ); 34018480Sralph if (lseek(etcutmp, utmploc, 0)<0) 34118480Sralph fprintf(stderr,"on lseek in /etc/utmp: %s", 34218480Sralph sys_errlist[errno]); 34318480Sralph if (write(etcutmp, (char *)&utmp, sizeof(utmp))<0) 34418480Sralph fprintf(stderr,"on write in /etc/utmp: %s", 34518480Sralph sys_errlist[errno]); 34618480Sralph } 34718480Sralph 34818480Sralph /* poke process 1 and wait for it to do its thing */ 34918480Sralph pokeinit(device,uname,enable) 35018480Sralph char *uname, *device; int enable; 35118480Sralph { 35218480Sralph struct utmp utmp; 35318614Sralph register int i; 35418480Sralph 35518480Sralph post(device, uname); 35618480Sralph 35718480Sralph /* poke init */ 35818480Sralph if (kill(1, SIGHUP)) { 35918480Sralph fprintf(stderr, 36018480Sralph "Cannot send hangup to init process: %s\n", 36118480Sralph sys_errlist[errno]); 36218614Sralph (void)settys(resettty); 36318480Sralph (void)setmodem(device,resetmodem); 36418480Sralph exit(1); 36518480Sralph } 36618480Sralph 36718480Sralph if (enable) 36818480Sralph return; 36918480Sralph 37018480Sralph /* wait till init has responded, clearing the utmp entry */ 37118614Sralph i=100; 37218480Sralph do { 37318480Sralph sleep(1); 37418480Sralph if (lseek(etcutmp,utmploc,0)<0) 37518480Sralph fprintf(stderr,"On lseek in /etc/utmp: %s", 37618480Sralph sys_errlist[errno]); 37718614Sralph if (read(etcutmp,(char *)&utmp,sizeof utmp)<0) 37818480Sralph fprintf(stderr,"On read from /etc/utmp: %s", 37918480Sralph sys_errlist[errno]); 38018614Sralph } while (utmp.ut_name[0] != '\0' && --i > 0); 38118480Sralph } 38218480Sralph 38318480Sralph /* identify terminal line in ttys */ 38418480Sralph opnttys(device) 38518480Sralph char *device; 38618480Sralph { 38718480Sralph register FILE *ttysfile; 38818480Sralph register int ndevice, lnsiz; 38918480Sralph register char *p; 39018480Sralph char *index(); 39118480Sralph char linebuf[100]; 39218480Sralph 39318480Sralph ttysfile = fopen(Etcttys, "r"); 39418480Sralph if(ttysfile == NULL) { 39518480Sralph fprintf(stderr, "Cannot open %s: %s\n", Etcttys, 39618480Sralph sys_errlist[errno]); 39718480Sralph exit(1); 39818480Sralph } 39918480Sralph 40018480Sralph ndevice = strlen(device); 40118480Sralph ttyslnbeg = 0; 40218480Sralph utmploc = 0; 40318480Sralph 40418480Sralph while(fgets(linebuf, sizeof(linebuf) - 1, ttysfile) != NULL) { 40518480Sralph utmploc += sizeof(utmp); 40618480Sralph lnsiz = strlen(linebuf); 40718480Sralph if ((p = index(linebuf,'\n')) != NULL) 40818480Sralph *p = '\0'; 40918480Sralph if(strncmp(device, &linebuf[2], ndevice) == 0) { 41018480Sralph (void)fclose(ttysfile); 41118480Sralph return; 41218480Sralph } 41318480Sralph ttyslnbeg += lnsiz; 41418480Sralph } 41518480Sralph fprintf(stderr, "%s not found in %s\n", device, Etcttys); 41618480Sralph exit(1); 41718480Sralph } 41818480Sralph 41918480Sralph /* modify appropriate line in /etc/ttys to turn on/off the device */ 42018480Sralph settys(enable) 42118480Sralph int enable; 42218480Sralph { 42318480Sralph int ittysfil; 42418480Sralph char out,in; 42518480Sralph 42618480Sralph ittysfil = open(Etcttys, 2); 42718480Sralph if(ittysfil == NULL) { 42818480Sralph fprintf(stderr, "Cannot open %s for output: %s\n", 42918480Sralph Etcttys, sys_errlist[errno]); 43018480Sralph exit(1); 43118480Sralph } 43218614Sralph (void)lseek(ittysfil,ttyslnbeg,0); 43318480Sralph if(read(ittysfil,&in,1)<0) { 43418480Sralph fprintf(stderr,"On %s write: %s\n", 43518480Sralph Etcttys, sys_errlist[errno]); 43618480Sralph exit(1); 43718480Sralph } 43818480Sralph resettty = (in == '1'); 43918480Sralph out = enable ? '1' : '0'; 44018614Sralph (void)lseek(ittysfil,ttyslnbeg,0); 44118480Sralph if(write(ittysfil,&out,1)<0) { 44218480Sralph fprintf(stderr,"On %s write: %s\n", 44318480Sralph Etcttys, sys_errlist[errno]); 44418480Sralph exit(1); 44518480Sralph } 44618480Sralph (void)close(ittysfil); 44718614Sralph return(in==out); 44818480Sralph } 44918480Sralph 45018480Sralph /* 45118480Sralph * Excerpted from (June 8,1983 W.Sebok) 45218480Sralph * > ttymodem.c - enable/disable modem control for tty lines. 45318480Sralph * > 45418480Sralph * > Knows about DZ11s and DH11/DM11s. 45518480Sralph * > 23.3.83 - TS 45618480Sralph * > modified to know about DMF's (hasn't been tested) Nov 8,1984 - WLS 45718480Sralph */ 45818480Sralph 45918480Sralph 46018480Sralph setmodem(ttyline,enable) 46118480Sralph char *ttyline; int enable; 46218480Sralph { 46318480Sralph dev_t dev; 46418480Sralph int kmem; 46518480Sralph int unit,line,nlines,addr,tflags; 46618614Sralph int devtype=0; 46718614Sralph char cflags; short sflags; 46818614Sralph #ifdef BSD4_2 46918614Sralph int flags; 47018614Sralph #else 47118614Sralph short flags; 47218614Sralph #endif 47318480Sralph struct uba_device *ubinfo; 47418480Sralph struct stat statb; 47518480Sralph struct cdevsw cdevsw; 47618480Sralph 47718480Sralph if(nl[CDEVSW].n_type == 0) { 47818480Sralph fprintf(stderr,"No namelist.\n"); 47918480Sralph return(-1); 48018480Sralph } 48118480Sralph 48218480Sralph if((kmem = open("/dev/kmem", 2)) < 0) { 48318480Sralph fprintf(stderr,"/dev/kmem open: %s\n", sys_errlist[errno]); 48418480Sralph return(-1); 48518480Sralph } 48618480Sralph 48718480Sralph if(stat(ttyline,&statb) < 0) { 48818480Sralph fprintf(stderr,"%s stat: %s\n", ttyline, sys_errlist[errno]); 48918480Sralph return(-1); 49018480Sralph } 49118480Sralph 49218614Sralph if((statb.st_mode&S_IFMT) != S_IFCHR) { 49318480Sralph fprintf(stderr,"%s is not a character device.\n",ttyline); 49418480Sralph return(-1); 49518480Sralph } 49618480Sralph 49718480Sralph dev = statb.st_rdev; 49818480Sralph (void)lseek(kmem, 49918614Sralph (off_t) &(((struct cdevsw *)NLVALUE(CDEVSW))[major(dev)]),0); 50018480Sralph (void)read(kmem,(char *) &cdevsw,sizeof cdevsw); 50118480Sralph 50218480Sralph if((int)(cdevsw.d_open) == NLVALUE(DZOPEN)) { 50318480Sralph devtype = DZ11; 50418480Sralph unit = minor(dev) / NDZLINE; 50518480Sralph line = minor(dev) % NDZLINE; 50618480Sralph addr = (int) &(((int *)NLVALUE(DZINFO))[unit]); 50718614Sralph (void)lseek(kmem,(off_t) NLVALUE(NDZ11),0); 50818480Sralph } else if((int)(cdevsw.d_open) == NLVALUE(DHOPEN)) { 50918480Sralph devtype = DH11; 51018480Sralph unit = minor(dev) / NDHLINE; 51118480Sralph line = minor(dev) % NDHLINE; 51218480Sralph addr = (int) &(((int *)NLVALUE(DHINFO))[unit]); 51318614Sralph (void)lseek(kmem,(off_t) NLVALUE(NDH11),0); 51418480Sralph } else if((int)(cdevsw.d_open) == NLVALUE(DMFOPEN)) { 51518480Sralph devtype = DMF; 51618480Sralph unit = minor(dev) / NDMFLINE; 51718480Sralph line = minor(dev) % NDMFLINE; 51818480Sralph addr = (int) &(((int *)NLVALUE(DMFINFO))[unit]); 51918614Sralph (void)lseek(kmem,(off_t) NLVALUE(NDMF),0); 52018480Sralph } else { 52118480Sralph fprintf(stderr,"Device %s (%d/%d) unknown.\n",ttyline, 52218480Sralph major(dev),minor(dev)); 52318480Sralph return(-1); 52418480Sralph } 52518480Sralph 52618480Sralph (void)read(kmem,(char *) &nlines,sizeof nlines); 52718480Sralph if(minor(dev) >= nlines) { 52818480Sralph fprintf(stderr,"Sub-device %d does not exist (only %d).\n", 52918480Sralph minor(dev),nlines); 53018480Sralph return(-1); 53118480Sralph } 53218480Sralph 53318614Sralph (void)lseek(kmem,(off_t)addr,0); 53418480Sralph (void)read(kmem,(char *) &ubinfo,sizeof ubinfo); 53518614Sralph (void)lseek(kmem,(off_t) &(ubinfo->ui_flags),0); 53618480Sralph (void)read(kmem,(char *) &flags,sizeof flags); 53718480Sralph 53818480Sralph tflags = 1<<line; 53918480Sralph resetmodem = ((flags&tflags) == 0); 54018480Sralph flags = enable ? (flags & ~tflags) : (flags | tflags); 54118614Sralph (void)lseek(kmem,(off_t) &(ubinfo->ui_flags),0); 54218480Sralph (void)write(kmem,(char *) &flags, sizeof flags); 54318480Sralph switch(devtype) { 54418480Sralph case DZ11: 54518480Sralph if((addr = NLVALUE(DZSCAR)) == 0) { 54618480Sralph fprintf(stderr,"No dzsoftCAR.\n"); 54718480Sralph return(-1); 54818480Sralph } 54918614Sralph cflags = flags; 55018614Sralph (void)lseek(kmem,(off_t) &(((char *)addr)[unit]),0); 55118614Sralph (void)write(kmem,(char *) &cflags, sizeof cflags); 55218480Sralph break; 55318480Sralph case DH11: 55418480Sralph if((addr = NLVALUE(DHSCAR)) == 0) { 55518480Sralph fprintf(stderr,"No dhsoftCAR.\n"); 55618480Sralph return(-1); 55718480Sralph } 55818614Sralph sflags = flags; 55918614Sralph (void)lseek(kmem,(off_t) &(((short *)addr)[unit]),0); 56018614Sralph (void)write(kmem,(char *) &sflags, sizeof sflags); 56118480Sralph break; 56218480Sralph case DMF: 56318480Sralph if((addr = NLVALUE(DMFSCAR)) == 0) { 56418480Sralph fprintf(stderr,"No dmfsoftCAR.\n"); 56518480Sralph return(-1); 56618480Sralph } 56718614Sralph cflags = flags; 56818614Sralph (void)lseek(kmem,(off_t) &(((char *)addr)[unit]),0); 56918614Sralph (void)write(kmem,(char *) &flags, sizeof cflags); 57018480Sralph break; 57118480Sralph default: 57218480Sralph fprintf(stderr,"Unknown device type\n"); 57318480Sralph return(-1); 57418480Sralph } 57518480Sralph return(0); 57618480Sralph } 57718480Sralph 57818480Sralph prefix(s1, s2) 57918480Sralph register char *s1, *s2; 58018480Sralph { 58118480Sralph register char c; 58218480Sralph 58318480Sralph while ((c = *s1++) == *s2++) 58418480Sralph if (c == '\0') 58518480Sralph return (1); 58618480Sralph return (c == '\0'); 58718480Sralph } 588