diff options
author | brian <brian@FreeBSD.org> | 1997-06-30 03:03:38 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1997-06-30 03:03:38 +0000 |
commit | ef60b19dcaace9c184fff55869ae9f9a7a110d31 (patch) | |
tree | ee15160bdfecab36ae85204a2b33cf221517e1ab | |
parent | 0a91728bd30aa3a8c095b9aaccd62ee440e4f096 (diff) | |
download | FreeBSD-src-ef60b19dcaace9c184fff55869ae9f9a7a110d31.zip FreeBSD-src-ef60b19dcaace9c184fff55869ae9f9a7a110d31.tar.gz |
Allow specification of a umask for local socket
creation in "set server" command.
-rw-r--r-- | usr.sbin/ppp/command.c | 20 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp.8 | 8 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp.8.m4 | 8 | ||||
-rw-r--r-- | usr.sbin/ppp/server.c | 6 | ||||
-rw-r--r-- | usr.sbin/ppp/server.h | 2 |
5 files changed, 30 insertions, 14 deletions
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index 5afead5..1fbe8b3 100644 --- a/usr.sbin/ppp/command.c +++ b/usr.sbin/ppp/command.c @@ -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, diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8 index 8f01215..94b19d9 100644 --- a/usr.sbin/ppp/ppp.8 +++ b/usr.sbin/ppp/ppp.8 @@ -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. diff --git a/usr.sbin/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp.8.m4 index 8f01215..94b19d9 100644 --- a/usr.sbin/ppp/ppp.8.m4 +++ b/usr.sbin/ppp/ppp.8.m4 @@ -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. diff --git a/usr.sbin/ppp/server.c b/usr.sbin/ppp/server.c index d6bd5d6..ddff807 100644 --- a/usr.sbin/ppp/server.c +++ b/usr.sbin/ppp/server.c @@ -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); diff --git a/usr.sbin/ppp/server.h b/usr.sbin/ppp/server.h index ae420b7..8421fe8 100644 --- a/usr.sbin/ppp/server.h +++ b/usr.sbin/ppp/server.h @@ -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); |