char sccsid
[] = "@(#)configttys.c 4.4 (Berkeley) %G%";
* configttys - configure "tty" ports
#define exists(file) (access(file, 0) == 0)
char *etc_ttys
= "/etc/ttys"; /* active port speed table */
char *etc_ttytype
= "/etc/ttytype"; /* terminal type table */
char *etc_conf
= "/etc/ttyconf"; /* master config file */
char *lockfile
= "/etc/ttyconf.lock"; /* interlock file */
char ty_active
; /* active login port */
char ty_speed
; /* speed table character */
char ty_port
[32]; /* port name */
char tp_term
[64]; /* terminal type name */
char tp_port
[32]; /* port name */
char conformat
[] = "%s\t%s\t%s\t%s\n";
int debug
= 0; /* debug mode */
int backup
= 0; /* create backup copies of old data */
int interactive
= 1; /* interactive mode */
char *speedname(); /* port speed code name */
char speedchar(); /* getty table name */
char *termname(); /* name of terminal on this port */
struct ttytype
*type(); /* find ttytype for port */
if (**++argv
== '-') switch (*++*argv
)
case 'n': /* non-interactive */
case 'b': /* backup old databases */
fprintf(stderr
, "unknown option %c\n", **argv
);
etc_ttys
= rindex(etc_ttys
, '/') + 1;
etc_ttytype
= rindex(etc_ttytype
, '/') + 1;
etc_conf
= rindex(etc_conf
, '/') + 1;
lockfile
= rindex(lockfile
, '/') + 1;
* create backup copies of the databases?
sprintf(buf
, "/bin/cp %s %s.bak", etc_ttys
, etc_ttys
);
sprintf(buf
, "/bin/cp %s %s.bak", etc_ttytype
, etc_ttytype
);
sprintf(buf
, "/bin/cp %s %s.bak", etc_conf
, etc_conf
);
* always read ttys file for comparison
* It is afterall what really counts!
* read old ttytypes if necessary
if ((tpf
= fopen(etc_ttytype
, "r")) == NULL
)
while (fgets(buf
, sizeof buf
, tpf
))
if (sscanf(buf
, "%s %s", tp
->tp_term
, tp
->tp_port
) == 2)
fprintf(stderr
, "bad line %d in %s: %s",
lineno
, etc_ttytype
, buf
);
* create master config file
if ((conf
= fopen(etc_conf
, "w")) == NULL
)
fprintf(conf
, conformat
, "port", "login", "speed\t", "terminal type");
fprintf(conf
, conformat
, "----", "-----", "-----\t", "-------------");
for (ty
= ttys
; ty
->ty_active
; ty
++)
fprintf(conf
, conformat
, ty
->ty_port
,
ty
->ty_active
== '1'? "active":"-",
* open master config file
if ((conf
= fopen(etc_conf
, "r")) == NULL
)
while (fgets(buf
, sizeof buf
, conf
)) /* skip heading */
while (fgets(buf
, sizeof buf
, conf
))
if (sscanf(buf
, "%s %s %s %s", port
, active
, speed
, term
) < 4)
fprintf(stderr
, "line %d: field(s) missing: %s",
if (strcmp(port
, ty
->ty_port
) != 0)
if (! ty
->ty_active
|| renamed
)
strcpy(ty
->ty_port
, port
);
fprintf(stderr
, "line %d: port name changed! %s -> %s\n",
lineno
, ty
->ty_port
, port
);
fprintf(stderr
, "Are you sure this is OK? ");
strcpy(ty
->ty_port
, port
);
if (strcmp(active
, "active") == 0)
if (c
= speedchar(speed
))
fprintf(stderr
, "line %d: speed name not known: %s\n",
strcpy(tp
->tp_term
, term
);
fprintf(stderr
, "%s empty??\n", etc_conf
);
fprintf(stderr
, "re-edit? ");
fprintf(stderr
, "Files not modified.\n");
register struct ttys
*ty
;
if ((tyf
= fopen(etc_ttys
, "r")) == NULL
)
return (0); /* hope user has it together! */
while (fgets(buf
, sizeof buf
, tyf
))
if (sscanf(buf
, "%c%c%s",
&ty
->ty_active
, &ty
->ty_speed
, ty
->ty_port
) == 3)
fprintf(stderr
, "bad line %d in %s: %s",
register struct ttys
*ty
;
sprintf(temp
, "%s.tmp", etc_ttys
);
if ((tyf
= fopen(temp
, "w")) == NULL
)
for (ty
= ttys
; ty
->ty_active
; ty
++)
ty
->ty_active
, ty
->ty_speed
, ty
->ty_port
);
if (rename(temp
, etc_ttys
) != 0)
fprintf(stderr
, "Can't rename %s\n", temp
);
sprintf(temp
, "%s.tmp", etc_ttytype
);
if ((tpf
= fopen(temp
, "w")) == NULL
)
for (ty
= ttys
; ty
->ty_active
; ty
++) /* same ports! */
type(ty
->ty_port
)->tp_term
, ty
->ty_port
);
if (rename(temp
, etc_ttytype
) != 0)
fprintf(stderr
, "Can't rename %s\n", temp
);
if ((child
= fork()) == 0)
execl("/usr/ucb/vi", "vi", etc_conf
, 0);
execl("/bin/ed", "ed", etc_conf
, 0);
perror("can't fork editor");
while (wait(&status
) >= 0)
strcpy(locktmp
, lockfile
);
if (p
= rindex(locktmp
, '/'))
strcpy(p
, "confttysXXXXXX");
if ((fd
= creat(locktmp
, 0600)) < 0)
if (link(locktmp
, lockfile
) < 0)
char *sp_name
; /* human readable name */
char sp_table
; /* getty table name */
{ "dialup", GT_DIALUP
}, /* normal dialup rotation */
{ "selector", GT_SELECTOR
}, /* port selector pseudo-table autobaud*/
{ "b110", GT_B110
}, /* 110 baud */
{ "b134", GT_B134
}, /* 134.5 baud selectric */
{ "b150", GT_B150
}, /* 150 baud */
{ "b300", GT_B300
}, /* 300 baud */
{ "b600", GT_B600
}, /* 600 baud */
{ "b1200", GT_B1200
}, /* 1200 baud */
{ "b2400", GT_B2400
}, /* 2400 baud */
{ "b4800", GT_B4800
}, /* 4800 baud */
{ "b9600", GT_B9600
}, /* 9600 baud */
{ "dw2console", GT_DW2CONSOLE
},/* Decwriter Console - 300 baud */
{ "fastdialup", GT_FASTDIALUP
},/* 1200-300 baud rotation for dialup */
{ "fastdialup1",GT_FASTDIALUP1
},/* 300-1200 " " " " */
{ "crt", GT_CRT_HCPY
}, /* 9600-300 CRT + hardcopy rotation */
{ "hardcopy", GT_HCPY_CRT
}, /* 300-9600 " " " */
{ "plugboard", GT_PLUGBOARD
}, /* 9600-300-1200 rotation */
{ "plugboard1", GT_PLUGBOARD2
},/* 300-1200-9600 rotation */
{ "plugboard2", GT_PLUGBOARD2
},/* 1200-9600-300 rotation */
{ "interdata", GT_INTERDATA
}, /* Interdata Console */
{ "chess", GT_CHESS
}, /* LSI Chess Terminal */
{ "tty33", GT_TTY33
}, /* 110 baud Model 33 TTY */
{ "network", GT_NETWORK
}, /* network port */
for (sp
= speeds
; sp
->sp_table
; sp
++)
strcpy(sbuf
, sp
->sp_name
);
register struct ttytype
*tp
;
for (tp
= ttytype
; tp
->tp_term
[0]; tp
++)
if (strcmp(port
, tp
->tp_port
) == 0)
if (tp
< &ttytype
[(sizeof ttytype
/ sizeof (struct ttytype
)) -1])
strcpy(tp
->tp_port
, port
);
strcpy(tp
->tp_term
, "unknown");
(++tp
)->tp_term
[0] = '\0';
register struct speeds
*sp
;
for (sp
= speeds
; sp
->sp_table
; sp
++)
if (strcmp(sp
->sp_name
, speed
) == 0)
register struct ttytype
*tp
;
for (tp
= ttytype
; tp
->tp_term
[0]; tp
++)
if (strcmp(tp
->tp_port
, port
) == 0)
if (tp
< &ttytype
[(sizeof ttytype
/ sizeof (struct ttytype
)) -1])
strcpy(tp
->tp_port
, port
);
strcpy(tp
->tp_term
, "unknown");
return((struct ttytype
*)0);