Correct the way the uucp lock file and the ttyXX.if lock

file get created.  We don't create lock files over non-tty
connections, but we *do* create lock files in -direct mode.
This leaves us capable of adding utmp/wtmp support for
successful pap & chap logins (coming soon).
This commit is contained in:
Brian Somers 1997-09-22 00:46:56 +00:00
parent cec9e91f19
commit 35495bec8d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=29696
4 changed files with 108 additions and 61 deletions

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.c,v 1.82 1997/09/17 23:17:52 brian Exp $
* $Id: command.c,v 1.83 1997/09/21 13:07:57 brian Exp $
*
*/
#include <sys/types.h>
@ -1192,17 +1192,7 @@ SetNBNS(struct cmdtab const * list, int argc, char **argv)
#endif /* MS_EXT */
#define VAR_AUTHKEY 0
#define VAR_DIAL 1
#define VAR_LOGIN 2
#define VAR_AUTHNAME 3
#define VAR_DEVICE 4
#define VAR_ACCMAP 5
#define VAR_PHONE 6
#define VAR_HANGUP 7
#define VAR_ENC 8
static int
int
SetVariable(struct cmdtab const * list, int argc, char **argv, int param)
{
u_long map;
@ -1231,11 +1221,15 @@ SetVariable(struct cmdtab const * list, int argc, char **argv, int param)
VarLoginScript[sizeof(VarLoginScript) - 1] = '\0';
break;
case VAR_DEVICE:
CloseModem();
if (modem != -1)
LogPrintf(LogWARN, "Cannot change device to \"%s\" when \"%s\" is open\n",
arg, VarDevice);
else {
strncpy(VarDevice, arg, sizeof(VarDevice) - 1);
VarDevice[sizeof(VarDevice) - 1] = '\0';
VarBaseDevice = rindex(VarDevice, '/');
VarBaseDevice = VarBaseDevice ? VarBaseDevice + 1 : "";
}
break;
case VAR_ACCMAP:
sscanf(arg, "%lx", &map);

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.h,v 1.4 1997/02/22 16:10:09 peter Exp $
* $Id: command.h,v 1.5 1997/08/25 00:29:09 brian Exp $
*
* TODO:
*/
@ -29,3 +29,15 @@ struct cmdtab {
char *syntax;
void *args;
};
#define VAR_AUTHKEY 0
#define VAR_DIAL 1
#define VAR_LOGIN 2
#define VAR_AUTHNAME 3
#define VAR_DEVICE 4
#define VAR_ACCMAP 5
#define VAR_PHONE 6
#define VAR_HANGUP 7
#define VAR_ENC 8
extern int SetVariable(struct cmdtab const *, int, char **, int var_param);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: main.c,v 1.79 1997/09/18 00:15:25 brian Exp $
* $Id: main.c,v 1.80 1997/09/21 20:26:46 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@ -448,27 +448,6 @@ main(int argc, char **argv)
} else if (mode & MODE_BACKGROUND)
close(BGFiledes[0]);
}
snprintf(pid_filename, sizeof(pid_filename), "%stun%d.pid",
_PATH_VARRUN, tunno);
(void) unlink(pid_filename);
if ((lockfile = fopen(pid_filename, "w")) != NULL) {
fprintf(lockfile, "%d\n", (int) getpid());
fclose(lockfile);
} else
LogPrintf(LogALERT, "Warning: Can't create %s: %s\n",
pid_filename, strerror(errno));
snprintf(if_filename, sizeof if_filename, "%s%s.if",
_PATH_VARRUN, VarBaseDevice);
(void) unlink(if_filename);
if ((lockfile = fopen(if_filename, "w")) != NULL) {
fprintf(lockfile, "tun%d\n", tunno);
fclose(lockfile);
} else
LogPrintf(LogALERT, "Warning: Can't create %s: %s\n",
if_filename, strerror(errno));
VarTerm = 0; /* We know it's currently stdout */
close(1);
@ -488,6 +467,18 @@ main(int argc, char **argv)
TtyInit(0);
TtyCommandMode(1);
}
snprintf(pid_filename, sizeof(pid_filename), "%stun%d.pid",
_PATH_VARRUN, tunno);
(void) unlink(pid_filename);
if ((lockfile = fopen(pid_filename, "w")) != NULL) {
fprintf(lockfile, "%d\n", (int) getpid());
fclose(lockfile);
} else
LogPrintf(LogALERT, "Warning: Can't create %s: %s\n",
pid_filename, strerror(errno));
LogPrintf(LogPHASE, "PPP Started.\n");

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: modem.c,v 1.53 1997/09/18 00:15:25 brian Exp $
* $Id: modem.c,v 1.54 1997/09/21 20:26:47 brian Exp $
*
* TODO:
*/
@ -31,6 +31,7 @@
#include <netdb.h>
#include <errno.h>
#include <time.h>
#include <paths.h>
#ifdef __OpenBSD__
#include <util.h>
#else
@ -42,6 +43,7 @@
#include "modem.h"
#include "loadalias.h"
#include "vars.h"
#include "command.h"
#ifndef O_NONBLOCK
#ifdef O_NDELAY
@ -428,25 +430,18 @@ OpenConnection(char *host, char *port)
return (sock);
}
static struct termios modemios;
extern int tunno;
static char fn[MAXPATHLEN];
int
OpenModem(int mode)
LockModem()
{
struct termios rstio;
int oldflag;
char *host, *cp, *port;
int res;
FILE *lockfile;
if (*VarDevice != '/')
return 0;
if (modem >= 0)
LogPrintf(LogDEBUG, "OpenModem: Modem is already open!\n");
/* We're going back into "term" mode */
else if (mode & MODE_DIRECT) {
LogPrintf(LogDEBUG, "OpenModem(direct): Modem is %sa tty\n",
isatty(0) ? "" : "not ");
return modem = 0;
} else {
if (strncmp(VarDevice, "/dev/", 5) == 0) {
if ((res = uu_lock(VarBaseDevice)) != UU_LOCK_OK) {
if (res == UU_LOCK_INUSE)
LogPrintf(LogPHASE, "Modem %s is in use\n", VarDevice);
@ -455,11 +450,68 @@ OpenModem(int mode)
VarDevice, uu_lockerr(res));
return (-1);
}
snprintf(fn, sizeof fn, "%s%s.if", _PATH_VARRUN, VarBaseDevice);
(void) unlink(fn);
if ((lockfile = fopen(fn, "w")) != NULL) {
fprintf(lockfile, "tun%d\n", tunno);
fclose(lockfile);
} else
LogPrintf(LogALERT, "Warning: Can't create %s: %s\n", fn, strerror(errno));
return 0;
}
void
UnlockModem()
{
if (*VarDevice != '/')
return;
snprintf(fn, sizeof fn, "%s%s.if", _PATH_VARRUN, VarBaseDevice);
if (unlink(fn) == -1)
LogPrintf(LogALERT, "Warning: Can't remove %s: %s\n", fn, strerror(errno));
if (uu_unlock(VarBaseDevice) == -1)
LogPrintf(LogALERT, "Warning: Can't uu_unlock %s\n", fn);
}
static struct termios modemios;
int
OpenModem(int mode)
{
struct termios rstio;
int oldflag;
char *host, *cp, *port;
if (modem >= 0)
LogPrintf(LogDEBUG, "OpenModem: Modem is already open!\n");
/* We're going back into "term" mode */
else if (mode & MODE_DIRECT) {
if (isatty(0)) {
LogPrintf(LogDEBUG, "OpenModem(direct): Modem is a tty\n");
cp = ttyname(0);
SetVariable(0, 1, &cp, VAR_DEVICE);
if (LockModem() == -1) {
close(0);
return -1;
}
} else {
LogPrintf(LogDEBUG, "OpenModem(direct): Modem is not a tty\n");
SetVariable(0, 0, 0, VAR_DEVICE);
}
return modem = 0;
} else {
if (strncmp(VarDevice, "/dev/", 5) == 0) {
if (LockModem() == -1)
return (-1);
modem = open(VarDevice, O_RDWR | O_NONBLOCK);
if (modem < 0) {
LogPrintf(LogERROR, "OpenModem failed: %s: %s\n", VarDevice,
strerror(errno));
(void) uu_unlock(VarBaseDevice);
UnlockModem();
return (-1);
}
LogPrintf(LogDEBUG, "OpenModem: Modem is %s\n", VarDevice);
@ -535,8 +587,8 @@ OpenModem(int mode)
if (ioctl(modem, TIOCMGET, &mbits)) {
LogPrintf(LogERROR, "OpenModem: Cannot get modem status: %s\n",
strerror(errno));
close(modem);
return (modem = -1);
CloseModem();
return (-1);
}
LogPrintf(LogDEBUG, "OpenModem: modem control = %o\n", mbits);
@ -544,8 +596,8 @@ OpenModem(int mode)
if (oldflag < 0) {
LogPrintf(LogERROR, "OpenModem: Cannot get modem flags: %s\n",
strerror(errno));
close(modem);
return (modem = -1);
CloseModem();
return (-1);
}
(void) fcntl(modem, F_SETFL, oldflag & ~O_NONBLOCK);
}
@ -653,10 +705,8 @@ HangupModem(int flag)
DoChat(ScriptBuffer);
tcflush(modem, TCIOFLUSH);
UnrawModem(modem);
close(modem);
CloseModem();
}
modem = -1; /* Mark as modem has closed */
(void) uu_unlock(VarBaseDevice);
} else if (modem >= 0) {
char ScriptBuffer[200];
@ -678,9 +728,9 @@ CloseModem()
{
if (modem >= 0) {
close(modem);
UnlockModem();
modem = -1;
}
(void) uu_unlock(VarBaseDevice);
}
/*