aboutsummaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2017-01-31 12:33:47 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2017-01-31 12:33:47 +0000
commit19ca85510bbe080af3faf5e9ae394608428ac953 (patch)
tree117f9a26f0d949b937129ea841578bd2ba4390fa /misc.c
parentab4ec008e7abd1c8098428dbf9642c3685383045 (diff)
downloadsrc-19ca85510bbe080af3faf5e9ae394608428ac953.tar.gz
src-19ca85510bbe080af3faf5e9ae394608428ac953.zip
Vendor import of OpenSSH 7.4p1.vendor/openssh/7.4p1
Notes
Notes: svn path=/vendor-crypto/openssh/dist/; revision=313012 svn path=/vendor-crypto/openssh/7.4p1/; revision=313013; tag=vendor/openssh/7.4p1
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/misc.c b/misc.c
index 9421b4d39651..65c9222aa8b0 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.105 2016/07/15 00:24:30 djm Exp $ */
+/* $OpenBSD: misc.c,v 1.107 2016/11/30 00:28:31 dtucker Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2005,2006 Damien Miller. All rights reserved.
@@ -1243,3 +1243,29 @@ forward_equals(const struct Forward *a, const struct Forward *b)
return 1;
}
+/* returns 1 if bind to specified port by specified user is permitted */
+int
+bind_permitted(int port, uid_t uid)
+{
+ if (port < IPPORT_RESERVED && uid != 0)
+ return 0;
+ return 1;
+}
+
+/* returns 1 if process is already daemonized, 0 otherwise */
+int
+daemonized(void)
+{
+ int fd;
+
+ if ((fd = open(_PATH_TTY, O_RDONLY | O_NOCTTY)) >= 0) {
+ close(fd);
+ return 0; /* have controlling terminal */
+ }
+ if (getppid() != 1)
+ return 0; /* parent is not init */
+ if (getsid(0) != getpid())
+ return 0; /* not session leader */
+ debug3("already daemonized");
+ return 1;
+}