Allow specification of a umask for local socket

creation in "set server" command.
This commit is contained in:
Brian Somers 1997-06-30 03:03:38 +00:00
parent 6373a10b41
commit 01ec25112c
5 changed files with 30 additions and 14 deletions

View File

@ -17,10 +17,11 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.c,v 1.63 1997/06/25 19:29:59 brian Exp $
* $Id: command.c,v 1.64 1997/06/28 01:34:02 brian Exp $
*
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <termios.h>
#include <sys/wait.h>
@ -847,14 +848,21 @@ char **argv;
{
int res = -1;
if (argc == 1)
if (argc > 0 && argc < 3)
if (strcasecmp(argv[0], "none") == 0) {
ServerClose();
LogPrintf(LogPHASE, "Disabling server port.\n");
res = 0;
} else if (*argv[0] == '/')
res = ServerLocalOpen(argv[0]);
else if (strspn(argv[0], "0123456789") == strlen(argv[0]))
} else if (*argv[0] == '/') {
mode_t mask;
umask(mask = umask(0));
if (argc == 2) {
unsigned m;
if (sscanf(argv[1], "%o", &m) == 1)
mask = m;
}
res = ServerLocalOpen(argv[0], mask);
} else if (strspn(argv[0], "0123456789") == strlen(argv[0]))
res = ServerTcpOpen(atoi(argv[0]));
return res;
@ -1264,7 +1272,7 @@ struct cmdtab const SetCommands[] = {
{ "redial", NULL, SetRedialTimeout, LOCAL_AUTH,
"Set Redial timeout", "set redial value|random[.value|random] [dial_attempts]"},
{ "server", "socket", SetServer, LOCAL_AUTH,
"Set server port", "set server|socket TcpPort|LocalName|none"},
"Set server port", "set server|socket TcpPort|LocalName|none [mask]"},
{ "speed", NULL, SetModemSpeed, LOCAL_AUTH,
"Set modem speed", "set speed value"},
{ "timeout", NULL, SetIdleTimeout, LOCAL_AUTH,

View File

@ -1,4 +1,4 @@
.\" $Id: ppp.8,v 1.41 1997/06/20 23:43:34 brian Exp $
.\" $Id: ppp.8,v 1.42 1997/06/25 19:30:03 brian Exp $
.Dd 20 September 1995
.Os FreeBSD
.Dt PPP 8
@ -1664,7 +1664,7 @@ is taken before starting at the first number again. A value of
.Dq random
may be used here too.
.It set server|socket TcpPort|LocalName|none
.It set server|socket TcpPort|LocalName|none [mask]
Normally, when not in interactive mode,
.Nm
listens to a tcp socket for incoming command connections. The
@ -1679,7 +1679,9 @@ Using this command, you can specify your own port number, a
local domain socket (specified as an absolute file name), or
you can tell
.Nm
not to accept any command connections. See also the use of
not to accept any command connections. If a local domain socket
is specified, you may also specify an octal mask that should be
set before creating the socket. See also the use of
the
.Dv USR1
signal.

View File

@ -1,4 +1,4 @@
.\" $Id: ppp.8,v 1.41 1997/06/20 23:43:34 brian Exp $
.\" $Id: ppp.8,v 1.42 1997/06/25 19:30:03 brian Exp $
.Dd 20 September 1995
.Os FreeBSD
.Dt PPP 8
@ -1664,7 +1664,7 @@ is taken before starting at the first number again. A value of
.Dq random
may be used here too.
.It set server|socket TcpPort|LocalName|none
.It set server|socket TcpPort|LocalName|none [mask]
Normally, when not in interactive mode,
.Nm
listens to a tcp socket for incoming command connections. The
@ -1679,7 +1679,9 @@ Using this command, you can specify your own port number, a
local domain socket (specified as an absolute file name), or
you can tell
.Nm
not to accept any command connections. See also the use of
not to accept any command connections. If a local domain socket
is specified, you may also specify an octal mask that should be
set before creating the socket. See also the use of
the
.Dv USR1
signal.

View File

@ -1,4 +1,5 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/un.h>
@ -20,7 +21,7 @@ static struct sockaddr_un ifsun;
static char *rm;
int
ServerLocalOpen(const char *name)
ServerLocalOpen(const char *name, mode_t mask)
{
int s;
@ -39,7 +40,9 @@ ServerLocalOpen(const char *name)
}
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &s, sizeof s);
mask = umask(mask);
if (bind(s, (struct sockaddr *) &ifsun, sizeof(ifsun)) < 0) {
umask(mask);
LogPrintf(LogERROR, "Local: bind: %s\n", strerror(errno));
if (errno == EADDRINUSE && VarTerm)
fprintf(VarTerm, "Wait for a while, then try again.\n");
@ -47,6 +50,7 @@ ServerLocalOpen(const char *name)
unlink(name);
return 3;
}
umask(mask);
if (listen(s, 5) != 0) {
LogPrintf(LogERROR, "Local: Unable to listen to socket - OS overload?\n");
close(s);

View File

@ -1,6 +1,6 @@
extern int server;
extern int ServerLocalOpen(const char *name);
extern int ServerLocalOpen(const char *name, mode_t mask);
extern int ServerTcpOpen(int);
extern void ServerClose(void);